GroupsController.cs 1.5 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518
  1. using Aspose.Cells;
  2. using Aspose.Words;
  3. using Aspose.Words.Drawing;
  4. using Aspose.Words.Tables;
  5. using DiffMatchPatch;
  6. using Dm.util;
  7. using Humanizer;
  8. using iTextSharp.text.pdf;
  9. using Microsoft.AspNetCore.SignalR;
  10. using NPOI.SS.Formula.Functions;
  11. using NPOI.SS.UserModel;
  12. using NPOI.SS.Util;
  13. using NPOI.XSSF.UserModel;
  14. using OASystem.API.Middlewares;
  15. using OASystem.API.OAMethodLib;
  16. using OASystem.API.OAMethodLib.APNs;
  17. using OASystem.API.OAMethodLib.DeepSeekAPI;
  18. using OASystem.API.OAMethodLib.File;
  19. using OASystem.API.OAMethodLib.GenericSearch;
  20. using OASystem.API.OAMethodLib.Hub.HubClients;
  21. using OASystem.API.OAMethodLib.Hub.Hubs;
  22. using OASystem.API.OAMethodLib.JuHeAPI;
  23. using OASystem.API.OAMethodLib.KiMiApi;
  24. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  25. using OASystem.Domain.AesEncryption;
  26. using OASystem.Domain.Attributes;
  27. using OASystem.Domain.Dtos.CRM;
  28. using OASystem.Domain.Dtos.FileDto;
  29. using OASystem.Domain.Dtos.Financial;
  30. using OASystem.Domain.Dtos.Groups;
  31. using OASystem.Domain.Entities.Customer;
  32. using OASystem.Domain.Entities.Financial;
  33. using OASystem.Domain.Entities.Groups;
  34. using OASystem.Domain.ViewModels.Financial;
  35. using OASystem.Domain.ViewModels.Groups;
  36. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  37. using OASystem.Domain.ViewModels.OCR;
  38. using OASystem.Infrastructure.Logging;
  39. using OASystem.Infrastructure.Repositories.CRM;
  40. using OASystem.Infrastructure.Repositories.Financial;
  41. using OASystem.Infrastructure.Repositories.Groups;
  42. using Quartz.Util;
  43. using SqlSugar.Extensions;
  44. using System.Collections;
  45. using System.ComponentModel.DataAnnotations;
  46. using System.Data;
  47. using System.Diagnostics;
  48. using System.Globalization;
  49. using System.IO.Compression;
  50. using System.Linq.Expressions;
  51. using System.Text.Json;
  52. using System.Web;
  53. using static OASystem.API.OAMethodLib.JWTHelper;
  54. using static OASystem.Infrastructure.Repositories.Groups.AirTicketResRepository;
  55. using Bookmark = Aspose.Words.Bookmark;
  56. using Cell = Aspose.Words.Tables.Cell;
  57. using Table = Aspose.Words.Tables.Table;
  58. namespace OASystem.API.Controllers
  59. {
  60. /// <summary>
  61. /// 团组相关
  62. /// </summary>
  63. //[Authorize]
  64. [Route("api/[controller]/[action]")]
  65. public class GroupsController : ControllerBase
  66. {
  67. private readonly ILogger<GroupsController> _logger;
  68. private readonly ITextFileLogger _eec_textLogger;
  69. private readonly IGroupTextFileLogger _groupTextLogger;
  70. private readonly GrpScheduleRepository _grpScheduleRep;
  71. private readonly IMapper _mapper;
  72. private readonly DelegationInfoRepository _groupRepository;
  73. private readonly TaskAssignmentRepository _taskAssignmentRep;
  74. private readonly AirTicketResRepository _airTicketResRep;
  75. private readonly DecreasePaymentsRepository _decreasePaymentsRep;
  76. private readonly InvitationOfficialActivitiesRepository _InvitationOfficialActivitiesRep;
  77. private readonly DelegationEnDataRepository _delegationEnDataRep;
  78. private readonly DelegationVisaRepository _delegationVisaRep;
  79. private readonly VisaPriceRepository _visaPriceRep;
  80. private readonly CarTouristGuideGroundRepository _carTouristGuideGroundRep;
  81. private readonly HotelPriceRepository _hotelPriceRep;
  82. private readonly CustomersRepository _customersRep;
  83. private readonly MessageRepository _message;
  84. private readonly SqlSugarClient _sqlSugar;
  85. private readonly TourClientListRepository _tourClientListRep;
  86. private readonly TeamRateRepository _teamRateRep;
  87. #region 成本相关
  88. private readonly CheckBoxsRepository _checkBoxs;
  89. private readonly GroupCostRepository _GroupCostRepository;
  90. private readonly CostTypeHotelNumberRepository _CostTypeHotelNumberRepository;
  91. private readonly GroupCostParameterRepository _GroupCostParameterRepository;
  92. #endregion
  93. private readonly SetDataRepository _setDataRep;
  94. private string url;
  95. private string path;
  96. private readonly EnterExitCostRepository _enterExitCostRep;
  97. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  98. private readonly UsersRepository _usersRep;
  99. private readonly IJuHeApiService _juHeApi;
  100. private readonly InvertedListRepository _invertedListRep;
  101. private readonly VisaFeeInfoRepository _visaFeeInfoRep;
  102. private readonly TicketBlackCodeRepository _ticketBlackCodeRep;
  103. private readonly ThreeCodeRepository _threeCodeRepository;
  104. private readonly HotelInquiryRepository _hotelInquiryRep;
  105. private readonly FeeAuditRepository _feeAuditRep;
  106. private readonly VisaCommissionRepository _visaCommissionRep;
  107. private readonly ForeignReceivablesRepository _ffrRep; //对外收款账单仓库
  108. private readonly OpinionaireRepository _opinionaireRep; //对外收款账单仓库
  109. private readonly List<CurrencyInfo> _currencyInit;
  110. private readonly List<int> _portTypeData;
  111. private readonly TableOperationRecordRepository _tableorRep;
  112. private readonly EnterExitCostDraftRepository _enterExitCostDraftRep;
  113. private readonly RestaurantRepository _restaurantRep;
  114. private readonly EnterExitCostQuoteRepository _enterExitCostQuoteRep;
  115. private readonly GroupOrderPreInfoRepository _grpOrderPreInfoRep;
  116. private readonly VisaProcessRepository _visaProcessRep;
  117. private readonly ProcessOverviewRepository _processOverviewRep;
  118. private readonly IDeepSeekService _deepSeekService;
  119. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  120. /// <summary>
  121. /// 接送机默认报价系数
  122. /// </summary>
  123. public const decimal Def_AirportTransferCoeff = 2.50M;
  124. /// <summary>
  125. /// 接送机默认服务次数
  126. /// </summary>
  127. public const int Def_ServiceCount = 1;
  128. /// <summary>
  129. /// 火车默认报价系数
  130. /// </summary>
  131. public const decimal Def_TrainCoeff = 2.50M;
  132. /// <summary>
  133. /// 拉扯默认报价系数
  134. /// </summary>
  135. public const decimal Def_PullCartCoeff = 2.50M;
  136. /// <summary>
  137. /// 城市机票默认报价系数
  138. /// </summary>
  139. public const decimal Def_CityFlightCoeff = 2.50M;
  140. /// <summary>
  141. /// 初始化岗位对应负责的数据类型
  142. ///
  143. /// 岗位ID
  144. /// 24 机票、25 酒店、26 签证、27 商邀、28 OP
  145. ///
  146. /// 费用类型ID
  147. /// 76 酒店预订、79 车/导游地接、80 签证、81 邀请/公务活动、82 团组客户保险、85 机票预订、98 其他款项
  148. /// </summary>
  149. private readonly Dictionary<int, List<int>> _dataInit = new() {
  150. { 24, new List<int> { 85 } }, // 机票 -> 机票预订
  151. { 25, new List<int> { 76 } }, // 酒店 -> 酒店预订
  152. { 26, new List<int> { 80, 82 } }, // 签证 -> 签证, 团组客户保险
  153. { 27, new List<int> { 81 } }, // 地接 -> 邀请/公务活动
  154. { 28, new List<int> { 79 } } // 商邀 -> 车/导游地接
  155. };
  156. /// <summary>
  157. /// 构造函数
  158. /// </summary>
  159. /// <param name="logger"></param>
  160. /// <param name="eec_textLogger"></param>
  161. /// <param name="groupTextLogger"></param>
  162. /// <param name="mapper"></param>
  163. /// <param name="hubContext"></param>
  164. /// <param name="sqlSugar"></param>
  165. /// <param name="grpScheduleRep"></param>
  166. /// <param name="groupRepository"></param>
  167. /// <param name="taskAssignmentRep"></param>
  168. /// <param name="airTicketResRep"></param>
  169. /// <param name="decreasePaymentsRep"></param>
  170. /// <param name="InvitationOfficialActivitiesRep"></param>
  171. /// <param name="delegationEnDataRep"></param>
  172. /// <param name="enterExitCostRep"></param>
  173. /// <param name="delegationVisaRep"></param>
  174. /// <param name="message"></param>
  175. /// <param name="visaPriceRep"></param>
  176. /// <param name="carTouristGuideGroundRep"></param>
  177. /// <param name="checkBoxs"></param>
  178. /// <param name="GroupCostRepository"></param>
  179. /// <param name="CostTypeHotelNumberRepository"></param>
  180. /// <param name="GroupCostParameterRepository"></param>
  181. /// <param name="hotelPriceRep"></param>
  182. /// <param name="customersRep"></param>
  183. /// <param name="setDataRep"></param>
  184. /// <param name="tourClientListRep"></param>
  185. /// <param name="teamRateRep"></param>
  186. /// <param name="usersRep"></param>
  187. /// <param name="juHeApi"></param>
  188. /// <param name="invertedListRep"></param>
  189. /// <param name="visaFeeInfoRep"></param>
  190. /// <param name="ticketBlackCodeRep"></param>
  191. /// <param name="hotelInquiryRep"></param>
  192. /// <param name="threeCodeRepository"></param>
  193. /// <param name="feeAuditRep"></param>
  194. /// <param name="visaCommissionRep"></param>
  195. /// <param name="ffrRep"></param>
  196. /// <param name="opinionaireRep"></param>
  197. /// <param name="tableorRep"></param>
  198. /// <param name="enterExitCostDraftRep"></param>
  199. /// <param name="restaurantRep"></param>
  200. /// <param name="enterExitCostQuoteRep"></param>
  201. /// <param name="grpOrderPreInfoRep"></param>
  202. /// <param name="visaProcessRep"></param>
  203. /// <param name="processOverviewRep"></param>
  204. /// <param name="groupSearchService"></param>
  205. public GroupsController(
  206. ILogger<GroupsController> logger,
  207. ITextFileLogger eec_textLogger,
  208. IGroupTextFileLogger groupTextLogger,
  209. IMapper mapper,
  210. IHubContext<ChatHub, IChatClient> hubContext,
  211. SqlSugarClient sqlSugar,
  212. GrpScheduleRepository grpScheduleRep,
  213. DelegationInfoRepository groupRepository,
  214. TaskAssignmentRepository taskAssignmentRep,
  215. AirTicketResRepository airTicketResRep,
  216. DecreasePaymentsRepository decreasePaymentsRep,
  217. InvitationOfficialActivitiesRepository InvitationOfficialActivitiesRep,
  218. DelegationEnDataRepository delegationEnDataRep,
  219. EnterExitCostRepository enterExitCostRep,
  220. DelegationVisaRepository delegationVisaRep,
  221. MessageRepository message,
  222. VisaPriceRepository visaPriceRep,
  223. CarTouristGuideGroundRepository carTouristGuideGroundRep,
  224. CheckBoxsRepository checkBoxs,
  225. GroupCostRepository GroupCostRepository,
  226. CostTypeHotelNumberRepository CostTypeHotelNumberRepository,
  227. GroupCostParameterRepository GroupCostParameterRepository,
  228. HotelPriceRepository hotelPriceRep,
  229. CustomersRepository customersRep,
  230. SetDataRepository setDataRep,
  231. TourClientListRepository tourClientListRep,
  232. TeamRateRepository teamRateRep,
  233. UsersRepository usersRep,
  234. IJuHeApiService juHeApi,
  235. InvertedListRepository invertedListRep,
  236. VisaFeeInfoRepository visaFeeInfoRep,
  237. TicketBlackCodeRepository ticketBlackCodeRep,
  238. HotelInquiryRepository hotelInquiryRep,
  239. ThreeCodeRepository threeCodeRepository,
  240. FeeAuditRepository feeAuditRep,
  241. VisaCommissionRepository visaCommissionRep,
  242. ForeignReceivablesRepository ffrRep,
  243. OpinionaireRepository opinionaireRep,
  244. TableOperationRecordRepository tableorRep,
  245. EnterExitCostDraftRepository enterExitCostDraftRep,
  246. RestaurantRepository restaurantRep,
  247. EnterExitCostQuoteRepository enterExitCostQuoteRep,
  248. GroupOrderPreInfoRepository grpOrderPreInfoRep,
  249. VisaProcessRepository visaProcessRep,
  250. ProcessOverviewRepository processOverviewRep,
  251. DynamicSearchService<Grp_DelegationInfo> groupSearchService
  252. )
  253. {
  254. _logger = logger;
  255. _eec_textLogger = eec_textLogger;
  256. _groupTextLogger = groupTextLogger;
  257. _mapper = mapper;
  258. _grpScheduleRep = grpScheduleRep;
  259. _groupRepository = groupRepository;
  260. _taskAssignmentRep = taskAssignmentRep;
  261. _airTicketResRep = airTicketResRep;
  262. _sqlSugar = sqlSugar;
  263. url = AppSettingsHelper.Get("ExcelBaseUrl");
  264. path = AppSettingsHelper.Get("ExcelBasePath");
  265. if (!System.IO.Directory.Exists(path))
  266. {
  267. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  268. }
  269. _decreasePaymentsRep = decreasePaymentsRep;
  270. _InvitationOfficialActivitiesRep = InvitationOfficialActivitiesRep;
  271. _delegationEnDataRep = delegationEnDataRep;
  272. _enterExitCostRep = enterExitCostRep;
  273. _delegationVisaRep = delegationVisaRep;
  274. _message = message;
  275. _visaPriceRep = visaPriceRep;
  276. _carTouristGuideGroundRep = carTouristGuideGroundRep;
  277. _checkBoxs = checkBoxs;
  278. _GroupCostRepository = GroupCostRepository;
  279. _CostTypeHotelNumberRepository = CostTypeHotelNumberRepository;
  280. _GroupCostParameterRepository = GroupCostParameterRepository;
  281. _hotelPriceRep = hotelPriceRep;
  282. _customersRep = customersRep;
  283. _setDataRep = setDataRep;
  284. _tourClientListRep = tourClientListRep;
  285. _teamRateRep = teamRateRep;
  286. _hubContext = hubContext;
  287. _usersRep = usersRep;
  288. _juHeApi = juHeApi;
  289. _invertedListRep = invertedListRep;
  290. _visaFeeInfoRep = visaFeeInfoRep;
  291. _ticketBlackCodeRep = ticketBlackCodeRep;
  292. _hotelInquiryRep = hotelInquiryRep;
  293. _threeCodeRepository = threeCodeRepository;
  294. _feeAuditRep = feeAuditRep;
  295. _visaCommissionRep = visaCommissionRep;
  296. _ffrRep = ffrRep;
  297. _opinionaireRep = opinionaireRep;
  298. _currencyInit = new List<CurrencyInfo>()
  299. {
  300. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  301. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  302. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  303. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  304. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  305. };
  306. _portTypeData = new List<int>() { 2, 3 };
  307. _tableorRep = tableorRep;
  308. _enterExitCostDraftRep = enterExitCostDraftRep;
  309. _restaurantRep = restaurantRep;
  310. _enterExitCostQuoteRep = enterExitCostQuoteRep;
  311. _grpOrderPreInfoRep = grpOrderPreInfoRep;
  312. _visaProcessRep = visaProcessRep;
  313. _processOverviewRep = processOverviewRep;
  314. _groupSearchService = groupSearchService;
  315. }
  316. #region 页面加载弹窗信息
  317. /// <summary>
  318. /// 提示用户录入团组费用信息
  319. /// 根据用户ID获取分配权限内团组名称
  320. /// </summary>
  321. /// <param name="currUserId">用户Id</param>
  322. /// <param name="daysAgo">往前推的天数</param>
  323. /// <returns></returns>
  324. [HttpGet]
  325. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  326. public async Task<IActionResult> GetGroupNamesByUserId(int currUserId, int daysAgo = 5)
  327. {
  328. var stopwatch = Stopwatch.StartNew();
  329. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  330. .Where(x => x.Id == currUserId && x.IsDel == 0)
  331. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  332. .FirstAsync();
  333. if (userInfo == null)
  334. {
  335. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  336. }
  337. var jobId = userInfo.JobPostId;
  338. var feeTypeIds = new List<int>() { };
  339. if (_dataInit.TryGetValue(jobId, out var values))
  340. {
  341. feeTypeIds = values;
  342. }
  343. /*
  344. * 获取今天时间往前推5天查询团组c表里有没有费用
  345. */
  346. var today_startDate = DateTime.Now.Date.AddDays(-daysAgo);
  347. //var today_endDate = DateTime.Now.Date.AddDays(-daysAgo).AddDays(1).AddSeconds(-1);
  348. var today_endDate = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
  349. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  350. .Where(di => di.IsDel == 0)
  351. .Where(di => di.VisitDate >= today_startDate && di.VisitDate <= today_endDate)
  352. // 存在任务分配记录
  353. .Where(di => SqlFunc.Subqueryable<Grp_GroupsTaskAssignment>()
  354. .Where(gta => gta.DIId == di.Id && gta.IsDel == 0 && feeTypeIds.Contains(gta.CTId))
  355. .Any())
  356. // 不存在费用记录
  357. .Where(di => !SqlFunc.Subqueryable<Grp_CreditCardPayment>()
  358. .Where(ccp => ccp.DIId == di.Id && ccp.IsDel == 0 && feeTypeIds.Contains(ccp.CTable))
  359. .Any())
  360. // 新增条件:不在确认记录表中(排除已确认的团组)
  361. .Where(di => !SqlFunc.Subqueryable<Grp_FeeEntryAcknowledge>()
  362. .Where(ack => ack.GroupId == di.Id && ack.IsDel == 0 && ack.UserId == currUserId)
  363. .Where(ack => feeTypeIds.Contains(ack.FeeTypeId))
  364. .Where(ack => ack.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged) // 只排除已确认的记录
  365. .Any())
  366. .Select(di => new
  367. {
  368. di.Id,
  369. di.TeamName,
  370. di.VisitDate
  371. })
  372. .OrderBy(di => di.VisitDate)
  373. .ToListAsync();
  374. stopwatch.Stop();
  375. return Ok(JsonView(true, $"操作成功!【耗时:{stopwatch.ElapsedMilliseconds}ms】", new
  376. {
  377. isTips = groupNames.Any(),
  378. groupNames = groupNames.Select(x => new { x.Id, GroupName = x.TeamName, x.VisitDate }).ToList()
  379. }));
  380. }
  381. /// <summary>
  382. /// 提示用户录入团组费用信息
  383. /// 已知晓确认操作记录(添加) 批量
  384. /// </summary>
  385. /// <param name="dto">请求体</param>
  386. /// <returns></returns>
  387. [HttpPost]
  388. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  389. public async Task<IActionResult> FeeEntryAcknowledgeCrate(FeeEntryAcknowledgeCrateDto dto)
  390. {
  391. // 1. 参数验证
  392. if (dto?.GroupIds == null || !dto.GroupIds.Any())
  393. return Ok(JsonView(false, "请选择需要确认的团组!"));
  394. if (dto.GroupIds.Count > 100)
  395. return Ok(JsonView(false, "一次性确认团组数量不能超过100个!"));
  396. if (dto.CurrUserId <= 0)
  397. return Ok(JsonView(false, "用户ID无效!"));
  398. // 2. 验证用户存在性
  399. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  400. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  401. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  402. .FirstAsync();
  403. if (userInfo == null)
  404. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  405. // 3. 获取费用类型
  406. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  407. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  408. // 4. 验证团组存在性
  409. var validGroupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  410. .Where(x => dto.GroupIds.Contains(x.Id) && x.IsDel == 0)
  411. .Select(x => x.Id)
  412. .ToListAsync();
  413. if (!validGroupIds.Any())
  414. return Ok(JsonView(false, "未找到有效的团组信息!"));
  415. // 5. 检查团组费用表中是否存在对应费用类型的数据
  416. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  417. .Where(x => validGroupIds.Contains(x.DIId) && x.IsDel == 0)
  418. .Where(x => feeTypeIds.Contains(x.CTable))
  419. .Select(x => new { GroupId = x.DIId, FeeTypeId = x.CTable })
  420. .ToListAsync();
  421. if (existingFeeRecords.Count > 0)
  422. {
  423. // 找出有问题的团组和费用类型
  424. var problematicGroups = existingFeeRecords
  425. .GroupBy(x => x.GroupId)
  426. .Select(g => new
  427. {
  428. GroupId = g.Key,
  429. FeeTypeIds = string.Join(",", g.Select(x => x.FeeTypeId).Distinct())
  430. })
  431. .ToList();
  432. var errorMessage = $"以下团组的费用表中已存在费用数据,不可添加确认记录:";
  433. foreach (var group in problematicGroups)
  434. {
  435. errorMessage += $"\n团组 {group.GroupId} - 费用类型ID: [{group.FeeTypeIds}]";
  436. }
  437. return Ok(JsonView(false, errorMessage));
  438. }
  439. // 6. 检查是否已存在确认记录(避免重复确认)
  440. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  441. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  442. .Where(x => validGroupIds.Contains(x.GroupId))
  443. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  444. .Select(x => new { x.GroupId, x.FeeTypeId })
  445. .ToListAsync();
  446. // 7. 准备插入数据(过滤已存在的记录)
  447. var recordsToInsert = new List<Grp_FeeEntryAcknowledge>();
  448. foreach (var groupId in validGroupIds)
  449. {
  450. foreach (var feeTypeId in feeTypeIds)
  451. {
  452. // 检查是否已存在相同记录
  453. var exists = existingAcknowledgeRecords.Any(x => x.GroupId == groupId && x.FeeTypeId == feeTypeId);
  454. if (!exists)
  455. {
  456. recordsToInsert.Add(new Grp_FeeEntryAcknowledge()
  457. {
  458. GroupId = groupId,
  459. UserId = dto.CurrUserId,
  460. JobPostId = userInfo.JobPostId,
  461. FeeTypeId = feeTypeId,
  462. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  463. AcknowledgeTime = DateTime.Now,
  464. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  465. CreateUserId = 4, // 系统创建
  466. CreateTime = DateTime.Now
  467. });
  468. }
  469. }
  470. }
  471. if (!recordsToInsert.Any())
  472. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  473. // 8. 批量插入数据
  474. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  475. if (successCount <= 0)
  476. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  477. // 9. 记录操作日志
  478. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 批量确认了 {GroupCount} 个团组的费用类型,共添加 {RecordCount} 条确认记录",
  479. userInfo.CnName, dto.CurrUserId, validGroupIds.Count, successCount);
  480. // 10. 操作成功 返回成功视图
  481. var result = await GetGroupNamesByUserId(dto.CurrUserId, dto.DaysAgo);
  482. if (result is OkObjectResult okObjectResult)
  483. {
  484. return Ok(okObjectResult.Value);
  485. }
  486. //return Ok(result);
  487. return Ok(JsonView(true, $"操作成功!共为 {validGroupIds.Count} 个团组添加了 {successCount} 条确认记录"));
  488. }
  489. /// <summary>
  490. /// 提示用户录入团组费用信息
  491. /// 已知晓确认操作记录(添加) 单个
  492. /// </summary>
  493. /// <param name="dto">请求体</param>
  494. /// <returns></returns>
  495. [HttpPost]
  496. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  497. public async Task<IActionResult> FeeEntryAcknowledgeSingleCreate(FeeEntryAcknowledgeSingleDto dto)
  498. {
  499. // 1. 参数验证
  500. if (dto.GroupId <= 0)
  501. return Ok(JsonView(false, "请选择有效的团组ID!"));
  502. if (dto.CurrUserId <= 0)
  503. return Ok(JsonView(false, "用户ID无效!"));
  504. // 2. 验证用户存在性
  505. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  506. .Where(x => x.Id == dto.CurrUserId && x.IsDel == 0)
  507. .Select(x => new { x.Id, x.JobPostId, x.CnName })
  508. .FirstAsync();
  509. if (userInfo == null)
  510. return Ok(JsonView(false, "用户不存在或已被禁用!"));
  511. // 3. 获取费用类型
  512. if (!_dataInit.TryGetValue(userInfo.JobPostId, out var feeTypeIds) || feeTypeIds?.Count == 0)
  513. return Ok(JsonView(false, "当前用户岗位无对应的费用类型配置!"));
  514. // 4. 验证团组存在性
  515. var groupExists = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  516. .AnyAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  517. if (!groupExists)
  518. return Ok(JsonView(false, "未找到有效的团组信息!"));
  519. // 5. 检查团组费用表中是否存在对应费用类型的数据
  520. var existingFeeRecords = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  521. .Where(x => x.DIId == dto.GroupId && x.IsDel == 0)
  522. .Where(x => feeTypeIds.Contains(x.CTable))
  523. .Select(x => new { x.CTable })
  524. .ToListAsync();
  525. if (existingFeeRecords.Count > 0)
  526. {
  527. var existingFeeTypeNames = existingFeeRecords.Select(x => x.CTable).Distinct().ToList();
  528. return Ok(JsonView(false, $"团组费用表中已存在费用类型ID [{string.Join(",", existingFeeTypeNames)}] 的数据,不可添加确认无费用记录!"));
  529. }
  530. // 6. 检查已存在的确认记录
  531. var existingAcknowledgeRecords = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  532. .Where(x => x.UserId == dto.CurrUserId && x.IsDel == 0)
  533. .Where(x => x.GroupId == dto.GroupId)
  534. .Where(x => feeTypeIds.Contains(x.FeeTypeId))
  535. .Select(x => new { x.FeeTypeId })
  536. .ToListAsync();
  537. var existingAcknowledgeFeeTypeIds = existingAcknowledgeRecords.Select(x => x.FeeTypeId).ToHashSet();
  538. // 7. 准备插入数据(过滤已存在的记录)
  539. var recordsToInsert = feeTypeIds
  540. .Where(feeTypeId => !existingAcknowledgeFeeTypeIds.Contains(feeTypeId))
  541. .Select(feeTypeId => new Grp_FeeEntryAcknowledge
  542. {
  543. GroupId = dto.GroupId,
  544. UserId = dto.CurrUserId,
  545. JobPostId = userInfo.JobPostId,
  546. FeeTypeId = feeTypeId,
  547. IsAcknowledged = Domain.Enums.AcknowledgeStatusEnum.Acknowledged,
  548. AcknowledgeTime = DateTime.Now,
  549. AcknowledgeType = Domain.Enums.AcknowledgeTypeEnum.WebConfirm,
  550. CreateUserId = 4, // 系统创建
  551. CreateTime = DateTime.Now
  552. })
  553. .ToList();
  554. if (recordsToInsert.Count == 0)
  555. return Ok(JsonView(true, "所选团组已确认,无需重复操作!"));
  556. // 8. 批量插入数据
  557. var successCount = await _sqlSugar.Insertable(recordsToInsert).ExecuteCommandAsync();
  558. if (successCount <= 0)
  559. return Ok(JsonView(false, "操作失败,未能保存确认记录!"));
  560. // 9. 记录操作日志(可选)
  561. _logger.LogInformation("用户 {UserName}(ID:{UserId}) 确认了团组 {GroupId} 的费用类型",
  562. userInfo.CnName, dto.CurrUserId, dto.GroupId);
  563. return Ok(JsonView(true, $"操作成功!"));
  564. }
  565. #endregion
  566. #region 流程管控
  567. /// <summary>
  568. /// 获取团组流程管控信息
  569. /// </summary>
  570. /// <param name="_jsonDto">查询参数</param>
  571. /// <returns></returns>
  572. [HttpPost]
  573. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  574. public async Task<IActionResult> PostSearchGrpSchedule(JsonDtoBase _jsonDto)
  575. {
  576. if (string.IsNullOrEmpty(_jsonDto.Paras))
  577. {
  578. return Ok(JsonView(false, "参数为空"));
  579. }
  580. Grp_ScheduleDto _ScheduleDto = JsonConvert.DeserializeObject<Grp_ScheduleDto>(_jsonDto.Paras);
  581. if (_ScheduleDto != null)
  582. {
  583. if (_ScheduleDto.SearchType == 2)//获取列表
  584. {
  585. List<Grp_ScheduleView> _grpScheduleViewList = await _grpScheduleRep.GetViewList_GrpSchedule(_ScheduleDto);
  586. return Ok(JsonView(_grpScheduleViewList));
  587. }
  588. else//获取对象
  589. {
  590. Grp_ScheduleCombinView _grpScheduleView = await _grpScheduleRep.GetView_GrpSchedule(_ScheduleDto);
  591. if (_grpScheduleView != null)
  592. {
  593. return Ok(JsonView(_grpScheduleView));
  594. }
  595. }
  596. }
  597. else
  598. {
  599. return Ok(JsonView(false, "参数反序列化失败"));
  600. }
  601. return Ok(JsonView(false, "暂无数据!"));
  602. }
  603. /// <summary>
  604. /// 修改团组流程管控详细表数据
  605. /// </summary>
  606. /// <param name="dto"></param>
  607. /// <returns></returns>
  608. [HttpPost]
  609. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  610. public async Task<IActionResult> PostUpdateGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  611. {
  612. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  613. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  614. .SetColumns(it => it.Duty == _detail.Duty)
  615. .SetColumns(it => it.ExpectBeginDt == _detail.ExpectBeginDt)
  616. .SetColumns(it => it.ExpectEndDt == _detail.ExpectEndDt)
  617. .SetColumns(it => it.JobContent == _detail.JobContent)
  618. .SetColumns(it => it.Remark == _detail.Remark)
  619. .SetColumns(it => it.StepStatus == _detail.StepStatus)
  620. .Where(s => s.Id == dto.Id)
  621. //.UpdateColumns(s => new { s.Duty, s.ExpectBeginDt, s.ExpectEndDt, s.JobContent, s.Remark, s.StepStatus })
  622. .ExecuteCommandAsync();
  623. if (result > 0)
  624. {
  625. return Ok(JsonView(true, "保存成功!"));
  626. }
  627. return Ok(JsonView(false, "保存失败!"));
  628. }
  629. /// <summary>
  630. /// 删除团组流程管控详细表数据,删除人Id请放在Duty
  631. /// </summary>
  632. /// <param name="dto"></param>
  633. /// <returns></returns>
  634. [HttpPost]
  635. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  636. public async Task<ActionResult> PostDeleteGrpScheduleDetail(Grp_ScheduleDetailUpdDto dto)
  637. {
  638. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  639. _detail.IsDel = 1;
  640. _detail.DeleteUserId = dto.Duty;
  641. _detail.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  642. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_ScheduleDetailInfo>()
  643. .SetColumns(it => it.IsDel == _detail.IsDel)
  644. .SetColumns(it => it.DeleteUserId == _detail.DeleteUserId)
  645. .SetColumns(it => it.DeleteTime == _detail.DeleteTime)
  646. .Where(it => it.Id == dto.Id)
  647. //.UpdateColumns(s => new { s.IsDel, s.DeleteUserId, s.DeleteTime })
  648. //.WhereColumns(s => s.Id == dto.Id)
  649. .ExecuteCommandAsync();
  650. if (result > 0)
  651. {
  652. return Ok(JsonView(true, "删除成功!"));
  653. }
  654. return Ok(JsonView(false, "删除失败!"));
  655. }
  656. /// <summary>
  657. /// 增加团组流程管控详细表数据
  658. /// </summary>
  659. /// <param name="dto"></param>
  660. /// <returns></returns>
  661. [HttpPost]
  662. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  663. public async Task<ActionResult> PostInsertGrpScheduleDetail(Grp_ScheduleDetailInsertDto dto)
  664. {
  665. Grp_ScheduleDetailInfo _detail = _mapper.Map<Grp_ScheduleDetailInfo>(dto);
  666. if (DateTime.Now < _detail.ExpectBeginDt)
  667. {
  668. _detail.StepStatus = 0;
  669. }
  670. else
  671. {//若大于设置时间,不考虑设置的预计结束日期,统一视为进行中
  672. _detail.StepStatus = 1;
  673. }
  674. var result = await _grpScheduleRep._sqlSugar.Insertable(_detail).ExecuteReturnIdentityAsync();
  675. if (result > 0)
  676. {
  677. Grp_ScheduleDetailView _result = await _grpScheduleRep.GetInsertBackData(result);
  678. return Ok(JsonView(true, "添加成功!", _result));
  679. }
  680. return Ok(JsonView(false, "添加失败!"));
  681. }
  682. #endregion
  683. #region 团组前期信息
  684. /// <summary>
  685. /// 团组前期信息H5-URL(员工对应地址)
  686. /// </summary>
  687. /// <param name="name">用户名称</param>
  688. /// <returns></returns>
  689. [HttpGet]
  690. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  691. public async Task<IActionResult> GroupOrderPreInfoH5URLList([FromQuery] string name)
  692. {
  693. var userURLs = await _sqlSugar.Queryable<Sys_Users>()
  694. .Where(x => x.IsDel == 0)
  695. .WhereIF(!string.IsNullOrEmpty(name), x => x.CnName.Contains(name))
  696. .OrderBy(x => x.Id)
  697. .Select(x => new
  698. {
  699. name = x.CnName,
  700. url = $"http://oa.pan-american-intl.com:4399/#/MarketplacePick?userid={x.Id}",
  701. })
  702. .ToListAsync();
  703. return Ok(JsonView(true, "操作成功!", userURLs, userURLs.Count));
  704. }
  705. /// <summary>
  706. /// 团组前期信息 List
  707. /// </summary>
  708. /// <returns></returns>
  709. [HttpPost]
  710. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  711. public async Task<IActionResult> GroupOrderPreInfoList(GroupOrderPreInfoListDto dto)
  712. {
  713. var search = dto.Search;
  714. int[] nameTempIds = new int[] { 1, 12, 28 },
  715. countryTempIds = new int[] { 2, 13, 29 },
  716. daysTempIds = new int[] { 4, 15, 31 },
  717. ppNumTempIds = new int[] { 6 };
  718. var list = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
  719. .LeftJoin<Sys_Users>((opi, u) => opi.CreateUserId == u.Id)
  720. .Where((opi, u) => opi.IsDel == 0)
  721. .OrderByDescending((opi, u) => opi.CreateTime)
  722. .Select((opi, u) => new GroupOrderPreInfoListView()
  723. {
  724. Id = opi.Id,
  725. Name = opi.Name,
  726. UnitName = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && nameTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  727. VisitCountryVal = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && countryTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  728. VisitDays = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && daysTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  729. VisiPpNum = SqlFunc.Subqueryable<Grp_OrderPreItem>().Where(x => x.ParentId == opi.Id && ppNumTempIds.Contains(x.FormTempId)).Select(x => x.Value),
  730. Operator = u.CnName,
  731. OperationTime = opi.CreateTime
  732. })
  733. //.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search))
  734. //.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  735. .ToListAsync();
  736. var listPageData = list.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search) || x.UnitName.Contains(search) || x.VisitCountrys.Contains(search)).ToList();
  737. int total = list.Count;
  738. int totalPageCount = (int)Math.Ceiling(list.Count / (double)dto.PageSize);
  739. var listPageData1 = listPageData
  740. .Skip((dto.PageIndex - 1) * dto.PageSize)
  741. .Take(dto.PageSize)
  742. .ToList();
  743. var infoIds = listPageData1.Select(x => x.Id).ToList();
  744. var typeDatas = await _sqlSugar.Queryable<Sys_SetData>()
  745. .Where(x => x.IsDel == 0 && x.STid == 109)
  746. .ToArrayAsync();
  747. var items = await _sqlSugar.Queryable<Grp_OrderPreItem>()
  748. .LeftJoin<Sys_FormTemp>((opi, ft) => opi.FormTempId == ft.Id)
  749. .Where((opi, ft) => opi.IsDel == 0 && infoIds.Contains(opi.ParentId))
  750. .Select((opi, ft) => new { opi.ParentId, opi.FormTempId, ft.TempId })
  751. .ToListAsync();
  752. foreach (var item in listPageData1)
  753. {
  754. var typeDatas1 = typeDatas.Select(x => new
  755. {
  756. x.Id,
  757. x.Name,
  758. IsNull = !items.Any(x1 => item.Id == x1.ParentId && x.Id == x1.TempId)
  759. }).ToArray();
  760. item.VersionDetails = typeDatas1;
  761. }
  762. return Ok(JsonView(listPageData1, listPageData1.Count));
  763. }
  764. /// <summary>
  765. /// 团组前期信息 Init
  766. /// </summary>
  767. /// <returns></returns>
  768. [HttpGet("{userId}")]
  769. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  770. public async Task<IActionResult> GroupOrderPreInfo(int userId)
  771. {
  772. return Ok(await _grpOrderPreInfoRep.DataInit(userId));
  773. }
  774. /// <summary>
  775. /// 国家数据源
  776. /// </summary>
  777. /// <param name="pageIndex">当前页码</param>
  778. /// <param name="pageSize">每页条数</param>
  779. /// <param name="search">查询条件</param>
  780. /// <returns></returns>
  781. [HttpGet]
  782. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  783. public async Task<IActionResult> CountryInit([FromQuery] int pageIndex, [FromQuery] int pageSize, [FromQuery] string search)
  784. {
  785. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => x.Country).Distinct().ToListAsync();
  786. if (pageIndex == 0 && pageSize == 0)
  787. {
  788. //所有数据
  789. return Ok(JsonView(countrys, countrys.Count));
  790. }
  791. //分页
  792. int skip = (pageIndex - 1) * pageSize;
  793. int take = pageSize;
  794. if (!string.IsNullOrEmpty(search))
  795. {
  796. IEnumerable<char> charSequence = search.Select(c => c);
  797. var pageResult1 = countrys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  798. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  799. return Ok(JsonView(pageData, pageResult1.Count));
  800. }
  801. var pageResult2 = countrys.Skip(skip).Take(take).ToList();
  802. return Ok(JsonView(pageResult2, countrys.Count));
  803. }
  804. /// <summary>
  805. /// 城市数据源
  806. /// </summary>
  807. /// <param name="countryLabel">国家名称 多个使用英文逗号隔开</param>
  808. /// <param name="pageIndex">当前页码</param>
  809. /// <param name="pageSize">每页条数</param>
  810. /// <param name="search">查询条件</param>
  811. /// <returns></returns>
  812. [HttpGet("{countryLabel}")]
  813. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  814. public async Task<IActionResult> CityByCountry(
  815. string countryLabel,
  816. [FromQuery] int pageIndex,
  817. [FromQuery] int pageSize,
  818. [FromQuery] string search)
  819. {
  820. countryLabel = HttpUtility.UrlDecode(countryLabel);
  821. var countryList = countryLabel.Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
  822. var citys = Array.Empty<string?>();
  823. if (countryList.Any())
  824. {
  825. var cityDatas = await _sqlSugar
  826. .Queryable<Grp_NationalTravelFee>()
  827. .Where(x => x.IsDel == 0 && countryList.Contains(x.Country) && !string.IsNullOrEmpty(x.City))
  828. .ToArrayAsync();
  829. foreach (var item in cityDatas)
  830. {
  831. if (item.City.Contains("城市"))
  832. {
  833. item.City = item.Country + "-所有城市";
  834. }
  835. }
  836. var cityDatas1 = cityDatas.OrderBy(x => x.Country);
  837. citys = cityDatas1.Select(x => x.City).Distinct().ToArray();
  838. }
  839. if (pageIndex == 0 && pageSize == 0)
  840. {
  841. //所有数据
  842. return Ok(JsonView(citys, citys?.Length ?? 0));
  843. }
  844. //分页
  845. int skip = (pageIndex - 1) * pageSize;
  846. int take = pageSize;
  847. if (!string.IsNullOrEmpty(search))
  848. {
  849. IEnumerable<char> charSequence = search.Select(c => c);
  850. var pageResult1 = citys.Where(x => charSequence.All(x1 => x.Contains(x1))).ToList();
  851. var pageData = pageResult1.Skip(skip).Take(take).ToList();
  852. return Ok(JsonView(pageData, pageResult1.Count));
  853. }
  854. var pageResult2 = citys.Skip(skip).Take(take).ToList();
  855. return Ok(JsonView(pageResult2, citys?.Length ?? 0));
  856. }
  857. /// <summary>
  858. /// 团组前期信息 Info
  859. /// </summary>
  860. /// <param name="dto">Id</param>
  861. /// <returns></returns>
  862. [HttpGet("{Id}/{TempId}")]
  863. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  864. public async Task<IActionResult> GroupOrderPreInfo([FromRoute] GroupOrderPreInfoDto dto)
  865. {
  866. return Ok(await _grpOrderPreInfoRep.InfoAsync(dto.Id, dto.TempId));
  867. }
  868. /// <summary>
  869. /// 团组前期信息 移动端 Info
  870. /// </summary>
  871. /// <param name="dto">Id</param>
  872. /// <returns></returns>
  873. [HttpGet("{Id}/{TempId}")]
  874. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  875. public async Task<IActionResult> GroupOrderPreMobileInfo([FromRoute] GroupOrderPreInfoDto dto)
  876. {
  877. return Ok(await _grpOrderPreInfoRep.MobileInfoAsync(dto.Id, dto.TempId));
  878. }
  879. /// <summary>
  880. /// 团组前期信息 Save
  881. /// </summary>
  882. /// <param name="dto">Id</param>
  883. /// <returns></returns>
  884. [HttpPost]
  885. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  886. public async Task<IActionResult> GroupOrderPreInfoSave(GroupOrderPreInfoOpDto dto)
  887. {
  888. return Ok(await _grpOrderPreInfoRep.OpAsync(dto));
  889. }
  890. /// <summary>
  891. /// 团组前期信息 Del
  892. /// </summary>
  893. /// <param name="dto">Id</param>
  894. /// <returns></returns>
  895. [HttpPost]
  896. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  897. public async Task<IActionResult> GroupOrderPreInfoDel(GroupOrderPreInfoDelDto dto)
  898. {
  899. return Ok(await _grpOrderPreInfoRep.DelAsync(dto));
  900. }
  901. /// <summary>
  902. /// 团组前期信息 文件下载
  903. /// </summary>
  904. /// <param name="dto">Id</param>
  905. /// <returns></returns>
  906. [HttpGet("{Id}/{TempId}")]
  907. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  908. public async Task<IActionResult> GroupOrderPreInfoFileDownload([FromRoute] GroupOrderPreInfoDto dto)
  909. {
  910. int id = dto.Id, tempId = dto.TempId;
  911. var view = await _grpOrderPreInfoRep.InfoAsync(id, tempId);
  912. var data = view.Data as GrpOrderPreInfoView;
  913. #region Excel
  914. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  915. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  916. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "GroupOrderPreInfo/";
  917. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "GroupOrderPreInfo/";
  918. var fileNamePrefix = string.Empty;
  919. if (tempId == 1405)
  920. {
  921. tempPath += $"前期需客户提供信息_无商邀版Temp.xlsx";
  922. fileNamePrefix = $"{data.Name}_无商邀版";
  923. }
  924. else if (tempId == 1406)
  925. {
  926. tempPath += $"前期需客户提供信息_有商邀版Temp.xlsx";
  927. fileNamePrefix = $"{data.Name}_有商邀版";
  928. }
  929. else
  930. {
  931. //tempId == 1404 默认下载
  932. tempPath += $"前期需客户提供信息_单接送机Temp.xlsx";
  933. fileNamePrefix = $"{data.Name}_单接送机";
  934. }
  935. foreach (var item in data.Items)
  936. {
  937. var obj = item.NewValue;
  938. if (obj == null) item.OriginVal = "";
  939. else if (obj.Equals("有") || obj.Equals("无"))
  940. {
  941. item.OriginVal = obj.ToString();
  942. }
  943. else if (obj is object[] objArray)
  944. {
  945. string[] stringArray = Array.ConvertAll(objArray, item => item?.ToString() ?? string.Empty);
  946. item.OriginVal = string.Join("、", stringArray);
  947. }
  948. else if (obj is string[] stringArray)
  949. {
  950. item.OriginVal = string.Join("、", stringArray);
  951. }
  952. else if (obj.Equals("-"))
  953. {
  954. item.OriginVal = "";
  955. }
  956. }
  957. var fileName = $"{fileNamePrefix}{CommonFun.GUID}.xlsx";
  958. fileName = CommonFun.ValidFileName(fileName);
  959. //载入模板
  960. var designer = new WorkbookDesigner
  961. {
  962. Workbook = new Workbook(tempPath)
  963. };
  964. if (tempId == 1406)
  965. {
  966. var view1 = data.Items.Where(x => x.Index < 11).ToArray();
  967. var view2 = data.Items.Where(x => x.Index > 10).ToArray();
  968. for (int i = 1; i <= view2.Length; i++)
  969. {
  970. view2[i - 1].Index = i;
  971. }
  972. designer.SetDataSource("View1", view1);
  973. designer.SetDataSource("View2", view2);
  974. }
  975. else
  976. {
  977. designer.SetDataSource("View", data.Items);
  978. }
  979. designer.Process();
  980. if (!Directory.Exists(savePath))
  981. {
  982. Directory.CreateDirectory(savePath);
  983. }
  984. string serverPath = $"{savePath}{fileName}";
  985. designer.Workbook.Save(serverPath);
  986. string rst = $"{servicePath}{ftpPath}{fileName}";
  987. #endregion
  988. return Ok(JsonView(new { url = rst }));
  989. }
  990. #endregion
  991. #region 团组基本信息
  992. /// <summary>
  993. /// 接团信息列表
  994. /// </summary>
  995. /// <param name="dto">团组列表请求dto</param>
  996. /// <returns></returns>
  997. [HttpPost]
  998. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  999. public async Task<IActionResult> GetGroupList(GroupListDto dto)
  1000. {
  1001. var groupData = await _groupRepository.GetGroupList(dto);
  1002. if (groupData.Code != 0)
  1003. {
  1004. return Ok(JsonView(false, groupData.Msg));
  1005. }
  1006. return Ok(JsonView(groupData.Data));
  1007. }
  1008. /// <summary>
  1009. /// 分页查询团组列表
  1010. /// </summary>
  1011. /// <param name="dto"></param>
  1012. /// <returns></returns>
  1013. [HttpPost]
  1014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1015. public async Task<IActionResult> QueryGroupListOffset(QueryGroupListOffsetDto dto)
  1016. {
  1017. var watch = new Stopwatch();
  1018. watch.Start();
  1019. RefAsync<int> total = 0;
  1020. var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  1021. .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
  1022. .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
  1023. .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
  1024. .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate, di.TourCode })
  1025. .Distinct()
  1026. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1027. watch.Stop();
  1028. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  1029. }
  1030. /// <summary>
  1031. /// 接团信息列表 Page Init
  1032. /// </summary>
  1033. /// <returns></returns>
  1034. [HttpPost]
  1035. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1036. public async Task<IActionResult> PostGroupPageListInit()
  1037. {
  1038. var depDatas = await GeneralMethod.GroupOpAffiliationBranchInit();
  1039. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new { x.Id, x.Name }).ToListAsync();
  1040. rankDatas.Insert(0, new { Id = 0, Name = "全部" });
  1041. var _view = new
  1042. {
  1043. depData = depDatas,
  1044. rankData = rankDatas
  1045. };
  1046. return Ok(JsonView(true, "查询成功!", _view));
  1047. }
  1048. /// <summary>
  1049. /// 接团信息列表 关键字输入提示
  1050. /// </summary>
  1051. /// <param name="keyword">关键字</param>
  1052. /// <returns></returns>
  1053. [HttpGet]
  1054. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1055. public async Task<IActionResult> GroupItemNativeKeywordSearch(string keyword)
  1056. {
  1057. var jw = JsonView(true, "暂无数据");
  1058. if (string.IsNullOrEmpty(keyword)) return Ok(jw);
  1059. var expression = Expressionable
  1060. .Create<Grp_DelegationInfo>()
  1061. .And(x => x.IsDel == 0);
  1062. string field = "TeamName,ClientUnit,ClientName";
  1063. var groupData = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1064. .Where(expression.ToExpression())
  1065. .Select(field)
  1066. .ToList();
  1067. var keywordArray = keyword.ToCharArray();
  1068. var matches = groupData
  1069. .Where(fullString => !string.IsNullOrWhiteSpace(fullString.TeamName) &&
  1070. keywordArray.All(keyword => fullString.TeamName.Contains(keyword)))
  1071. .Select(x => new
  1072. {
  1073. x.TeamName,
  1074. x.ClientUnit,
  1075. x.ClientName
  1076. })
  1077. .DistinctBy(x => x.TeamName)
  1078. .ToList();
  1079. if (matches.Any())
  1080. {
  1081. jw.Code = StatusCodes.Status200OK;
  1082. jw.Msg = "搜索成功";
  1083. jw.Data = matches;
  1084. jw.Count = matches.Count;
  1085. }
  1086. return Ok(jw);
  1087. }
  1088. /// <summary>
  1089. /// 接团信息列表 关键字输入提示(智能版)
  1090. /// </summary>
  1091. /// <param name="keyword">关键字</param>
  1092. /// <returns></returns>
  1093. [HttpGet]
  1094. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1095. public async Task<IActionResult> GroupItemKeywordSearch(string keyword)
  1096. {
  1097. try
  1098. {
  1099. // 验证请求参数
  1100. if (string.IsNullOrEmpty(keyword))
  1101. {
  1102. return Ok(JsonView(true, $"暂无数据!"));
  1103. }
  1104. var searchRequest = new DynamicSearchRequest
  1105. {
  1106. Keyword = keyword,
  1107. RequireAllSingleChars = true,
  1108. PageIndex = 1,
  1109. PageSize = 999999,
  1110. FieldWeights = new Dictionary<string, int>
  1111. {
  1112. { "TeamName", 10 }
  1113. },
  1114. Filters = new List<SearchFilter>()
  1115. {
  1116. new(){Field = "IsDel",Operator="eq",Value="0" }
  1117. },
  1118. OrderBy = "VisitDate",
  1119. ReturnFields = new List<string>() { "TeamName", "ClientUnit", "ClientName" }
  1120. };
  1121. // 验证字段配置
  1122. var validation = _groupSearchService.ValidateFieldConfig(
  1123. searchRequest.FieldWeights,
  1124. searchRequest.ReturnFields);
  1125. if (!validation.IsValid)
  1126. {
  1127. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  1128. }
  1129. var result = await _groupSearchService.SearchAsync(searchRequest);
  1130. if (result.Success)
  1131. {
  1132. var data = new List<dynamic>();
  1133. foreach (var item in result.Items)
  1134. {
  1135. data.Add(new
  1136. {
  1137. item.Data.TeamName,
  1138. item.Data.ClientUnit,
  1139. item.Data.ClientName,
  1140. //item.Data.VisitDate
  1141. });
  1142. }
  1143. return Ok(JsonView(true, result.Message, data, data.Count));
  1144. }
  1145. return Ok(JsonView(true, result.Message));
  1146. }
  1147. catch (Exception ex)
  1148. {
  1149. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  1150. }
  1151. }
  1152. /// <summary>
  1153. /// 接团信息列表 Page
  1154. /// </summary>
  1155. /// <param name="dto">团组列表请求dto</param>
  1156. /// <returns></returns>
  1157. [HttpPost]
  1158. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1159. public async Task<IActionResult> PostGroupPageList(GroupPageListDto dto)
  1160. {
  1161. // 创建Stopwatch实例
  1162. var stopwatch = new Stopwatch();
  1163. stopwatch.Start();
  1164. #region 参数验证
  1165. if (dto.UserId < 1)
  1166. return Ok(JsonView(false, "员工Id为空"));
  1167. if (dto.PageId < 1)
  1168. return Ok(JsonView(false, "页面Id为空"));
  1169. #region 页面操作权限验证
  1170. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1171. if (pageFunAuthView.CheckAuth == 0)
  1172. return Ok(JsonView(false, "您没有查看权限"));
  1173. #endregion
  1174. #endregion
  1175. //if (dto.PortType != 1 && dto.PortType != 2) // web/Android
  1176. // return Ok(JsonView(false, "不支持的端口类型"));
  1177. // 构建查询条件
  1178. var sqlWhereBuilder = new StringBuilder(" WHERE gdi.IsDel = 0");
  1179. var parameters = new List<SugarParameter>();
  1180. // 完成状态筛选
  1181. if (dto.IsSure == 0 || dto.IsSure == 1)
  1182. {
  1183. sqlWhereBuilder.Append(" AND gdi.IsSure = @IsSure");
  1184. parameters.Add(new SugarParameter("@IsSure", dto.IsSure));
  1185. }
  1186. // 搜索条件
  1187. if (!string.IsNullOrWhiteSpace(dto.SearchCriteria))
  1188. {
  1189. var searchParam = $"%{dto.SearchCriteria.Trim()}%";
  1190. sqlWhereBuilder.Append(@"
  1191. AND (ssd.Name LIKE @SearchCriteria
  1192. OR gdi.TeamName LIKE @SearchCriteria
  1193. OR gdi.ClientName LIKE @SearchCriteria
  1194. OR su.CnName LIKE @SearchCriteria)");
  1195. parameters.Add(new SugarParameter("@SearchCriteria", searchParam));
  1196. }
  1197. // 等级筛选
  1198. if (int.TryParse(dto.Rank, out int rankId) && rankId > 0)
  1199. {
  1200. sqlWhereBuilder.Append(" AND gdi.TeamLevSId = @RankId");
  1201. parameters.Add(new SugarParameter("@RankId", rankId));
  1202. }
  1203. // 部门筛选
  1204. var departmentWhere = string.Empty;
  1205. if (!string.IsNullOrWhiteSpace(dto.Department) && !dto.Department.Equals("全部"))
  1206. {
  1207. departmentWhere = " WHERE Department = @Department";
  1208. parameters.Add(new SugarParameter("@Department", dto.Department));
  1209. }
  1210. // 构建SQL查询
  1211. string sql = $@"
  1212. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType, Department,
  1213. TeamLevId, TeamLev, TeamName, ClientName, ClientUnit,
  1214. VisitDate, VisitDays, VisitPNumber, JietuanOperatorId,
  1215. JietuanOperator, IsSure, CreateTime, IsBid, Step,
  1216. CONVERT(VARCHAR(19), StepOperationTime, 20) AS StepOperationTime
  1217. FROM (
  1218. SELECT ROW_NUMBER() OVER(ORDER BY gdi.VisitStartDate DESC) AS Row_Number,
  1219. CASE
  1220. WHEN gdi.JietuanOperator IN (4, 21) THEN '国交部'
  1221. ELSE (SELECT DepName FROM OA2023DB.dbo.Sys_Department WHERE Id = su.DepId)
  1222. END AS 'Department',
  1223. gdi.Id, SalesQuoteNo, TourCode, ssd.Id AS TeamTypeId, ssd.Name AS TeamType, gdi.Step,
  1224. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev, TeamName, ClientName, ClientUnit,
  1225. VisitDate, VisitDays, VisitPNumber, JietuanOperator AS JietuanOperatorId,
  1226. su.CnName AS JietuanOperator, IsSure, gdi.CreateTime, gdi.IsBid,StepOperationTime
  1227. FROM Grp_DelegationInfo gdi
  1228. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  1229. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  1230. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  1231. {sqlWhereBuilder}
  1232. ) temp {departmentWhere}";
  1233. // 执行分页查询
  1234. RefAsync<int> total = 0;
  1235. var delegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  1236. .AddParameters(parameters)
  1237. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1238. if (!delegationList.Any())
  1239. {
  1240. var emptyView = new
  1241. {
  1242. PageFuncAuth = pageFunAuthView,
  1243. Data = delegationList
  1244. };
  1245. return Ok(JsonView(true, "查询成功,暂无数据", emptyView, total));
  1246. }
  1247. // 批量处理团组模块实际操作人和背景颜色设置
  1248. await ProcessDelegationListData(delegationList);
  1249. var resultView = new
  1250. {
  1251. PageFuncAuth = pageFunAuthView,
  1252. Data = delegationList
  1253. };
  1254. stopwatch.Stop();
  1255. return Ok(JsonView(true, $"查询成功!耗时:{stopwatch.Elapsed.TotalSeconds:F3}s", resultView, total));
  1256. }
  1257. /// <summary>
  1258. /// 批量处理团组数据
  1259. /// </summary>
  1260. private async Task ProcessDelegationListData(List<DelegationListView> delegationList)
  1261. {
  1262. var groupIds = delegationList.Select(x => x.Id).ToList();
  1263. // 批量查询信用卡支付记录
  1264. var creditCardPayments = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  1265. .Where(y => groupIds.Contains(y.DIId) && y.IsDel == 0)
  1266. .Select(y => y.DIId)
  1267. .Distinct()
  1268. .ToListAsync();
  1269. // 批量查询费用确认记录
  1270. var feeAcknowledgements = await _sqlSugar.Queryable<Grp_FeeEntryAcknowledge>()
  1271. .Where(y => groupIds.Contains(y.GroupId) && y.IsDel == 0)
  1272. .Where(y => y.IsAcknowledged == AcknowledgeStatusEnum.Acknowledged)
  1273. .Select(y => y.GroupId)
  1274. .Distinct()
  1275. .ToListAsync();
  1276. var creditCardPaymentSet = creditCardPayments.ToHashSet();
  1277. var feeAcknowledgementSet = feeAcknowledgements.ToHashSet();
  1278. // 并行处理每个团组
  1279. var tasks = delegationList.Select(async x =>
  1280. {
  1281. // 处理团组模块实际操作人
  1282. var operators = GeneralMethod.GetGroupModuleOperators(x.Id);
  1283. var operatorNames = new StringBuilder();
  1284. if (operators.Any())
  1285. {
  1286. foreach (var operatorInfo in operators)
  1287. {
  1288. string label = operatorInfo.OperationUsers.Any()
  1289. ? string.Join('、', operatorInfo.OperationUsers.Select(u => u.UserName))
  1290. : "暂未指定";
  1291. operatorNames.AppendLine($"{operatorInfo.CTableName}:{label}");
  1292. operatorNames.AppendLine();
  1293. }
  1294. }
  1295. x.OperatorLabel = operatorNames.ToString().TrimEnd('\n', '\r');
  1296. // 设置背景颜色为红色
  1297. // C表没数据并且没点提醒确认按钮(无成本费用按钮)的团组该行显示红色
  1298. bool hasCreditCardPayment = creditCardPaymentSet.Contains(x.Id);
  1299. bool hasFeeAcknowledgement = feeAcknowledgementSet.Contains(x.Id);
  1300. x.UseRedBackground = !hasCreditCardPayment && !hasFeeAcknowledgement;
  1301. });
  1302. await Task.WhenAll(tasks);
  1303. }
  1304. /// <summary>
  1305. /// 团组列表
  1306. /// </summary>
  1307. /// <returns></returns>
  1308. [HttpPost]
  1309. public async Task<IActionResult> GetGroupListByWhere(GroupListByWhere dto)
  1310. {
  1311. #region 参数验证
  1312. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1313. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  1314. #region 页面操作权限验证
  1315. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1316. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  1317. #endregion
  1318. #endregion
  1319. if (dto.PortType != 1 && dto.PortType != 2)
  1320. {
  1321. return Ok(JsonView(false, "查询失败!"));
  1322. }
  1323. string orderbyStr = "order by gdi.CreateTime Desc";
  1324. string sqlWhere = string.Empty;
  1325. if (dto.IsSure == 0) //未完成
  1326. {
  1327. sqlWhere += string.Format(@" And IsSure = 0");
  1328. }
  1329. else if (dto.IsSure == 1) //已完成
  1330. {
  1331. sqlWhere += string.Format(@" And IsSure = 1");
  1332. }
  1333. //团组类型
  1334. if (dto.TeamDid > 0)
  1335. {
  1336. sqlWhere += string.Format(@"And TeamDid = {0} ", dto.TeamDid);
  1337. }
  1338. //团组名称
  1339. if (!string.IsNullOrEmpty(dto.TeamName))
  1340. {
  1341. sqlWhere += string.Format(@"And TeamName Like '%{0}%'", dto.TeamName);
  1342. }
  1343. //客户名称
  1344. if (!string.IsNullOrEmpty(dto.ClientName))
  1345. {
  1346. sqlWhere += string.Format(@"And ClientName Like '%{0}%'", dto.ClientName);
  1347. }
  1348. //客户单位
  1349. if (!string.IsNullOrEmpty(dto.ClientUnit))
  1350. {
  1351. sqlWhere += string.Format(@"And ClientUnit Like '%{0}%'", dto.ClientUnit);
  1352. }
  1353. //出访时间
  1354. if (!string.IsNullOrEmpty(dto.visitDataTime))
  1355. {
  1356. sqlWhere += string.Format(@"And VisitDate >= '{0}'", dto.visitDataTime);
  1357. orderbyStr = "order by gdi.VisitDate";
  1358. }
  1359. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  1360. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  1361. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  1362. JietuanOperator,IsSure,CreateTime
  1363. From (
  1364. Select row_number() over({0}) as Row_Number,
  1365. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  1366. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  1367. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  1368. su.CnName JietuanOperator,IsSure,gdi.CreateTime
  1369. From Grp_DelegationInfo gdi
  1370. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  1371. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  1372. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  1373. Where gdi.IsDel = 0 {1}
  1374. ) temp ", orderbyStr, sqlWhere);
  1375. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  1376. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  1377. #region 处理所属部门
  1378. /*
  1379. * 1.sq 和 gyy 等显示 市场部
  1380. * 2.王鸽和主管及张总还有管理员号统一国交部
  1381. * 2-1. 4 管理员 ,21 张海麟
  1382. */
  1383. var userIds = _DelegationList.Select(it => it.JietuanOperatorId).ToList();
  1384. var userIds1 = new List<int>() { 4, 21 };
  1385. var UserDepDatas = _sqlSugar.Queryable<Sys_Users>()
  1386. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1387. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  1388. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  1389. .ToList();
  1390. foreach (var item in _DelegationList)
  1391. {
  1392. item.Department = UserDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  1393. }
  1394. #endregion
  1395. var _view = new
  1396. {
  1397. PageFuncAuth = pageFunAuthView,
  1398. Data = _DelegationList
  1399. };
  1400. return Ok(JsonView(true, $"查询成功!", _view, total));
  1401. }
  1402. /// <summary>
  1403. /// 接团信息详情
  1404. /// </summary>
  1405. /// <param name="dto">团组info请求dto</param>
  1406. /// <returns></returns>
  1407. [HttpPost]
  1408. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1409. public async Task<IActionResult> GetGroupInfo(GroupInfoDto dto)
  1410. {
  1411. var groupData = await _groupRepository.GetGroupInfo(dto);
  1412. if (groupData.Code != 0)
  1413. {
  1414. return Ok(JsonView(false, groupData.Msg));
  1415. }
  1416. return Ok(JsonView(groupData.Data));
  1417. }
  1418. /// <summary>
  1419. /// 接团信息 编辑添加
  1420. /// 基础信息数据源
  1421. /// </summary>
  1422. /// <param name="dto"></param>
  1423. /// <returns></returns>
  1424. [HttpPost]
  1425. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1426. public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
  1427. {
  1428. var groupData = await _groupRepository.GroupEditBasicSource(dto);
  1429. if (groupData.Code != 0)
  1430. {
  1431. return Ok(JsonView(false, groupData.Msg));
  1432. }
  1433. return Ok(JsonView(groupData.Data));
  1434. }
  1435. /// <summary>
  1436. /// 成本修改团组信息
  1437. /// </summary>
  1438. /// <param name="dto"></param>
  1439. /// <returns></returns>
  1440. [HttpPost]
  1441. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1442. public async Task<IActionResult> GroupCostEditGroupInfo(GroupCostEditGroupInfoDto dto)
  1443. {
  1444. var jw = JsonView(false, "操作失败");
  1445. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  1446. if (di == null)
  1447. {
  1448. jw.Msg = "参数有误!";
  1449. return Ok(jw);
  1450. }
  1451. #region 添加出访起止时间
  1452. var startTime = new DateTime();
  1453. var endTime = new DateTime();
  1454. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1455. {
  1456. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1457. }
  1458. else
  1459. {
  1460. jw.Msg = "参数有误!";
  1461. return Ok(jw);
  1462. }
  1463. #endregion
  1464. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1465. if (!startTime.ToString("yyyy-MM-dd").Equals(di.VisitDate.ToString("yyyy-MM-dd")))
  1466. {
  1467. var msg = "团组成本模块修改出访时间,删除倒推表重新生成";
  1468. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1469. .SetColumns(x => x.IsDel == 1)
  1470. .SetColumns(x => x.DeleteUserId == 4)
  1471. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1472. .SetColumns(x => x.Remark == msg)
  1473. .Where(x => x.DiId == dto.Diid)
  1474. .ExecuteCommandAsync();
  1475. //默认创建倒推表
  1476. await _invertedListRep.Create(4, dto.Diid, msg);
  1477. }
  1478. #endregion
  1479. di.VisitDate = startTime;
  1480. di.VisitPNumber = dto.VisitPNumber;
  1481. di.VisitDays = dto.VisitDays;
  1482. di.VisitStartDate = startTime;
  1483. di.VisitEndDate = endTime;
  1484. var count = _sqlSugar.Updateable(di)
  1485. .UpdateColumns(x => new { x.VisitDate, x.VisitPNumber, x.VisitDays, x.VisitStartDate, x.VisitEndDate })
  1486. .ExecuteCommand();
  1487. return Ok(count > 0 ? JsonView(true, "操作成功") : jw);
  1488. }
  1489. /// <summary>
  1490. /// 接团信息 编辑添加
  1491. /// 省份-城市 基础信息数据源
  1492. /// </summary>
  1493. /// <param name="dto"></param>
  1494. /// <returns></returns>
  1495. [HttpPost]
  1496. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1497. public async Task<IActionResult> GroupProvCityBasicSource(GroupProvCityBasicSourceDto dto)
  1498. {
  1499. int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
  1500. string search = dto.Search;
  1501. var data = await _groupRepository.CityBasicSource();
  1502. int total = data.Length;
  1503. data = data.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search))
  1504. .Skip((pageIndex - 1) * pageSize)
  1505. .Take(pageSize)
  1506. .ToArray();
  1507. return Ok(JsonView(data, total));
  1508. }
  1509. /// <summary>
  1510. /// 接团信息 操作(增改)
  1511. /// </summary>
  1512. /// <param name="dto"></param>
  1513. /// <returns></returns>
  1514. [HttpPost]
  1515. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1516. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1517. public async Task<IActionResult> GroupOperation(GroupOperationDto dto)
  1518. {
  1519. // 创建 Stopwatch 实例
  1520. Stopwatch stopwatch = Stopwatch.StartNew();
  1521. decimal ffrPrice = 0.00M;
  1522. DateTime? visitDt = null;
  1523. if (dto.Status == 2)
  1524. {
  1525. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1526. if (groupInfo != null)
  1527. {
  1528. ffrPrice = groupInfo.PaymentMoney;
  1529. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1530. #region 验证出访时间是否有变化 有变化则重新生成倒推表
  1531. if (DateTime.TryParse(dto.VisitDate, out DateTime startTime))
  1532. {
  1533. if (!startTime.ToString("yyyy-MM-dd").Equals(groupInfo.VisitDate.ToString("yyyy-MM-dd")))
  1534. {
  1535. var msg = "团组信息模块修改出访时间,删除倒推表重新生成";
  1536. var softDel = await _sqlSugar.Updateable<Grp_InvertedList>()
  1537. .SetColumns(x => x.IsDel == 1)
  1538. .SetColumns(x => x.DeleteUserId == 4)
  1539. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1540. .SetColumns(x => x.Remark == msg)
  1541. .Where(x => x.DiId == dto.Id)
  1542. .ExecuteCommandAsync();
  1543. //默认创建倒推表
  1544. await _invertedListRep.Create(dto.UserId, dto.Id, msg);
  1545. }
  1546. }
  1547. #endregion
  1548. }
  1549. }
  1550. var groupData = await _groupRepository.GroupOperation(dto);
  1551. if (groupData.Code != 0)
  1552. {
  1553. return Ok(JsonView(false, groupData.Msg));
  1554. }
  1555. int diId = 0;
  1556. try
  1557. {
  1558. //添加时 默认加入团组汇率
  1559. if (dto.Status == 1) //添加
  1560. {
  1561. diId = groupData.Data;
  1562. //添加默认币种
  1563. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1564. //默认分配权限
  1565. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1566. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1567. var _managerIds = new List<int>() { 22, 32, 21 };
  1568. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1569. if (userIds.Count > 0)
  1570. {
  1571. userIds.Add(208);
  1572. //创建团组管控
  1573. GroupStepForDelegation.CreateWorkStep(diId);
  1574. //发送消息
  1575. string groupName = dto.TeamName;
  1576. string createGroupUser = string.Empty;
  1577. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1578. if (userInfo != null) createGroupUser = userInfo.CnName;
  1579. string title = $"系统通知";
  1580. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1581. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1582. }
  1583. //默认创建倒推表
  1584. await _invertedListRep.Create(dto.UserId, diId);
  1585. //默认创建签证流程
  1586. await _visaProcessRep.Create(dto.UserId, diId);
  1587. //默认创建团组流程总览信息
  1588. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1589. }
  1590. else if (dto.Status == 2)
  1591. {
  1592. diId = dto.Id;
  1593. }
  1594. #region 签证人员团组时间通知
  1595. #region 计算出访起止时间
  1596. var startTime = new DateTime();
  1597. var endTime = new DateTime();
  1598. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1599. {
  1600. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1601. }
  1602. #endregion
  1603. #endregion
  1604. #region 团组操作默认添加/修改收款账单
  1605. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1606. {
  1607. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1608. .Where(x => x.IsDel == 0 &&
  1609. x.Diid == diId &&
  1610. x.Remark.Equals("预付款")
  1611. )
  1612. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1613. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1614. .FirstAsync();
  1615. ffrInfo = new Fin_ForeignReceivables()
  1616. {
  1617. Diid = diId,
  1618. PriceName = dto.ClientUnit,
  1619. Price = dto.PaymentMoney,
  1620. Count = 1,
  1621. Unit = $"元",
  1622. ItemSumPrice = dto.PaymentMoney,
  1623. Rate = 1.0000M,
  1624. Currency = 836,
  1625. AddingWay = 0,
  1626. CreateUserId = dto.UserId,
  1627. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1628. Remark = $"预付款"
  1629. };
  1630. if (ffrInfo == null) //Add
  1631. {
  1632. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1633. }
  1634. else //修改
  1635. {
  1636. await _sqlSugar.Updateable(ffrInfo)
  1637. .UpdateColumns(x => new
  1638. {
  1639. x.PriceName,
  1640. x.Price,
  1641. x.ItemSumPrice,
  1642. x.CreateTime,
  1643. x.CreateUserId
  1644. })
  1645. .WhereColumns(x => x.Id)
  1646. .ExecuteCommandAsync();
  1647. }
  1648. }
  1649. #endregion
  1650. if (diId > 0)
  1651. {
  1652. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1653. }
  1654. // 停止计时
  1655. stopwatch.Stop();
  1656. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1657. }
  1658. catch (Exception ex)
  1659. {
  1660. // 停止计时
  1661. stopwatch.Stop();
  1662. Logs("[response]" + JsonConvert.SerializeObject(dto));
  1663. Logs(ex.Message);
  1664. //return Ok(JsonView(false, $"{ex.Message}[{stopwatch.ElapsedMilliseconds}ms]"));
  1665. }
  1666. // 停止计时
  1667. stopwatch.Stop();
  1668. return Ok(JsonView(true, $"操作成功!{stopwatch.ElapsedMilliseconds}ms", diId));
  1669. }
  1670. /// <summary>
  1671. /// 接团流程操作(增改)
  1672. /// 安卓端使用 建团时添加客户名单
  1673. /// </summary>
  1674. /// <param name="dto"></param>
  1675. /// <returns></returns>
  1676. [HttpPost]
  1677. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1678. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1679. public async Task<IActionResult> GroupProcessOperation(GroupProcessOperationDto dto)
  1680. {
  1681. #region 参数验证
  1682. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1683. #region 页面操作权限验证
  1684. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1685. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1686. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1687. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1688. #endregion
  1689. #endregion
  1690. try
  1691. {
  1692. //_sqlSugar.BeginTran();
  1693. decimal ffrPrice = 0.00M;
  1694. DateTime? visitDt = null;
  1695. if (dto.Status == 2)
  1696. {
  1697. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1698. if (groupInfo != null)
  1699. {
  1700. ffrPrice = groupInfo.PaymentMoney;
  1701. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1702. }
  1703. }
  1704. var _dto = new GroupOperationDto();
  1705. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1706. var groupData = await _groupRepository.GroupOperation(_dto);
  1707. if (groupData.Code != 0)
  1708. {
  1709. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1710. }
  1711. int diId = 0;
  1712. //添加时 默认加入团组汇率
  1713. if (dto.Status == 1) //添加
  1714. {
  1715. diId = groupData.Data;
  1716. //添加默认币种
  1717. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1718. //默认分配权限
  1719. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1720. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1721. var _managerIds = new List<int>() { 21, 22, 32 };
  1722. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1723. if (userIds.Count > 0)
  1724. {
  1725. userIds.Add(208);
  1726. //创建团组管控
  1727. GroupStepForDelegation.CreateWorkStep(diId);
  1728. //发送消息
  1729. string groupName = dto.TeamName;
  1730. string createGroupUser = string.Empty;
  1731. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1732. if (userInfo != null) createGroupUser = userInfo.CnName;
  1733. string title = $"系统通知";
  1734. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1735. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1736. }
  1737. #region 应用推送
  1738. try
  1739. {
  1740. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1741. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1742. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1743. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1744. {
  1745. var userList = new List<string>() { users.QiyeChatUserId };
  1746. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1747. }
  1748. }
  1749. catch (Exception ex)
  1750. {
  1751. }
  1752. #endregion
  1753. //默认创建倒推表
  1754. await _invertedListRep.Create(dto.UserId, diId);
  1755. //默认创建签证流程
  1756. await _visaProcessRep.Create(dto.UserId, diId);
  1757. //默认创建团组流程总览信息
  1758. await _processOverviewRep.ProcessInitAsync(diId, dto.UserId);
  1759. }
  1760. if (dto.Status == 2)
  1761. {
  1762. diId = dto.Id;
  1763. if (diId == 0)
  1764. {
  1765. //_sqlSugar.RollbackTran();
  1766. return Ok(JsonView(false, "修改失败! 未添加团组id" + groupData.Msg));
  1767. }
  1768. }
  1769. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1770. if (viewData.Code != 0)
  1771. {
  1772. //_sqlSugar.RollbackTran();
  1773. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1774. }
  1775. #region 团组操作默认添加/修改收款账单
  1776. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1777. {
  1778. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1779. .Where(x => x.IsDel == 0 &&
  1780. x.Diid == diId &&
  1781. x.Remark.Equals("预付款")
  1782. )
  1783. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1784. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1785. .FirstAsync();
  1786. ffrInfo = new Fin_ForeignReceivables()
  1787. {
  1788. Diid = diId,
  1789. PriceName = dto.ClientUnit,
  1790. Price = dto.PaymentMoney,
  1791. Count = 1,
  1792. Unit = $"元",
  1793. ItemSumPrice = dto.PaymentMoney,
  1794. Rate = 1.0000M,
  1795. Currency = 836,
  1796. AddingWay = 0,
  1797. CreateUserId = dto.UserId,
  1798. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1799. Remark = $"预付款"
  1800. };
  1801. if (ffrInfo == null) //Add
  1802. {
  1803. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1804. }
  1805. else //修改
  1806. {
  1807. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1808. .UpdateColumns(x => new
  1809. {
  1810. x.PriceName,
  1811. x.Price,
  1812. x.ItemSumPrice,
  1813. x.CreateTime,
  1814. x.CreateUserId
  1815. })
  1816. .WhereColumns(x => x.Id)
  1817. .ExecuteCommandAsync();
  1818. }
  1819. }
  1820. #endregion
  1821. #region 签证人员团组时间通知
  1822. #region 计算出访起止时间
  1823. var startTime = new DateTime();
  1824. var endTime = new DateTime();
  1825. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1826. {
  1827. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  1828. }
  1829. #endregion
  1830. if (diId > 0)
  1831. {
  1832. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  1833. }
  1834. #endregion
  1835. //_sqlSugar.CommitTran();
  1836. return Ok(JsonView(true, "添加成功"));
  1837. }
  1838. catch (Exception ex)
  1839. {
  1840. _sqlSugar.RollbackTran();
  1841. return Ok(JsonView(false, ex.Message));
  1842. }
  1843. }
  1844. /// <summary>
  1845. /// 接团流程操作(增改)
  1846. /// 安卓端使用 建团时添加客户名单
  1847. /// </summary>
  1848. /// <param name="dto"></param>
  1849. /// <returns></returns>
  1850. [HttpPost]
  1851. [ApiLog("Grp_DelegationInfo", OperationEnum.Edit)]
  1852. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1853. public async Task<IActionResult> GroupProcessOperation1(GroupProcessOperationDto dto)
  1854. {
  1855. #region 参数验证
  1856. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  1857. #region 页面操作权限验证
  1858. //pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 104);
  1859. //if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "客户名单您没有添加权限!"));
  1860. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, 27);
  1861. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "团组操作您没有添加权限!"));
  1862. #endregion
  1863. #endregion
  1864. _sqlSugar.BeginTran();
  1865. decimal ffrPrice = 0.00M;
  1866. DateTime? visitDt = null;
  1867. if (dto.Status == 2)
  1868. {
  1869. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.Id && x.IsDel == 0);
  1870. if (groupInfo != null)
  1871. {
  1872. ffrPrice = groupInfo.PaymentMoney;
  1873. visitDt = groupInfo.VisitDate.AddDays(-groupInfo.PayDay);
  1874. }
  1875. }
  1876. var _dto = new GroupOperationDto();
  1877. _dto = _mapper.Map<GroupProcessOperationDto, GroupOperationDto>(dto);
  1878. var groupData = await _groupRepository.GroupOperation(_dto);
  1879. if (groupData.Code != 0)
  1880. {
  1881. _sqlSugar.RollbackTran();
  1882. return Ok(JsonView(false, "团组操作添加失败!" + groupData.Msg));
  1883. }
  1884. try
  1885. {
  1886. int diId = 0;
  1887. //添加时 默认加入团组汇率
  1888. if (dto.Status == 1) //添加
  1889. {
  1890. diId = groupData.Data;
  1891. //添加默认币种
  1892. await GeneralMethod.PostGroupRateAddInit(dto.UserId, diId);
  1893. //默认分配权限
  1894. await GeneralMethod.PostGroupAuthAddInit(dto.UserId, diId);
  1895. //消息提示 王鸽 主管号 2024-10-21 新增LZ UID
  1896. var _managerIds = new List<int>() { 21, 22, 32 };
  1897. var userIds = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && _managerIds.Contains(it.JobPostId)).Select(it => it.Id).ToList();
  1898. if (userIds.Count > 0)
  1899. {
  1900. userIds.Add(208);
  1901. //创建团组管控
  1902. GroupStepForDelegation.CreateWorkStep(diId);
  1903. //发送消息
  1904. string groupName = dto.TeamName;
  1905. string createGroupUser = string.Empty;
  1906. var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  1907. if (userInfo != null) createGroupUser = userInfo.CnName;
  1908. string title = $"系统通知";
  1909. string content = $"团组[{groupName}(创建人:{createGroupUser})]创建成功,请前往页面进行下一步操作!";
  1910. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  1911. }
  1912. #region 应用推送
  1913. try
  1914. {
  1915. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(diId, QiyeWeChatEnum.CompanyCRMChat);
  1916. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == dto.UserId).First();
  1917. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  1918. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  1919. {
  1920. var userList = new List<string>() { users.QiyeChatUserId };
  1921. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(diId, userList);
  1922. }
  1923. }
  1924. catch (Exception ex)
  1925. {
  1926. _sqlSugar.CommitTran();
  1927. return Ok(JsonView(true, "操作成功! 应用推送异常:" + groupData.Msg));
  1928. }
  1929. #endregion
  1930. //默认创建倒推表
  1931. await _invertedListRep.Create(dto.UserId, diId);
  1932. }
  1933. else if (dto.Status == 2)
  1934. {
  1935. diId = dto.Id;
  1936. if (diId == 0)
  1937. {
  1938. _sqlSugar.RollbackTran();
  1939. return Ok(JsonView(false, "操作失败! 未添加团组id" + groupData.Msg));
  1940. }
  1941. }
  1942. var viewData = await _tourClientListRep.OperMultiple(dto.TourClientListInfos, diId, dto.UserId);
  1943. if (viewData.Code != 0)
  1944. {
  1945. _sqlSugar.RollbackTran();
  1946. return Ok(JsonView(false, "客户名单添加失败!" + viewData.Msg));
  1947. }
  1948. #region 团组操作默认添加/修改收款账单
  1949. if (dto.PayDay > 0 && dto.PaymentMoney > 0)
  1950. {
  1951. var ffrInfo = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  1952. .Where(x => x.IsDel == 0 &&
  1953. x.Diid == diId &&
  1954. x.Remark.Equals("预付款")
  1955. )
  1956. .WhereIF(ffrPrice > 0, x => x.ItemSumPrice == ffrPrice)
  1957. .WhereIF(visitDt != null, x => x.CreateTime == visitDt)
  1958. .FirstAsync();
  1959. ffrInfo = new Fin_ForeignReceivables()
  1960. {
  1961. Diid = diId,
  1962. PriceName = dto.ClientUnit,
  1963. Price = dto.PaymentMoney,
  1964. Count = 1,
  1965. Unit = $"元",
  1966. ItemSumPrice = dto.PaymentMoney,
  1967. Rate = 1.0000M,
  1968. Currency = 836,
  1969. AddingWay = 0,
  1970. CreateUserId = dto.UserId,
  1971. CreateTime = Convert.ToDateTime(dto.VisitDate).AddDays(-dto.PayDay),
  1972. Remark = $"预付款"
  1973. };
  1974. if (ffrInfo == null) //Add
  1975. {
  1976. await _sqlSugar.Insertable(ffrInfo).ExecuteCommandAsync();
  1977. }
  1978. else //修改
  1979. {
  1980. await _sqlSugar.Updateable<Fin_ForeignReceivables>(ffrInfo)
  1981. .UpdateColumns(x => new
  1982. {
  1983. x.PriceName,
  1984. x.Price,
  1985. x.ItemSumPrice,
  1986. x.CreateTime,
  1987. x.CreateUserId
  1988. })
  1989. .WhereColumns(x => x.Id)
  1990. .ExecuteCommandAsync();
  1991. }
  1992. }
  1993. #endregion
  1994. #region 签证人员团组时间通知
  1995. #region 计算出访起止时间
  1996. var startTime = new DateTime();
  1997. var endTime = new DateTime();
  1998. if (DateTime.TryParse(dto.VisitDate, out startTime))
  1999. {
  2000. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  2001. }
  2002. #endregion
  2003. if (diId > 0)
  2004. {
  2005. await AppNoticeLibrary.SendUserMsg_GroupTimeInfo_ToVisaUser(diId, startTime.ToString("yyyy-MM-dd"), endTime.ToString("yyyy-MM-dd"));
  2006. }
  2007. #endregion
  2008. _sqlSugar.CommitTran();
  2009. return Ok(JsonView(true));
  2010. }
  2011. catch (Exception ex)
  2012. {
  2013. _sqlSugar.RollbackTran();
  2014. return Ok(JsonView(false, ex.Message));
  2015. }
  2016. }
  2017. /// <summary>
  2018. /// 接团信息 操作(删除)
  2019. /// </summary>
  2020. /// <param name="dto"></param>
  2021. /// <returns></returns>
  2022. [HttpPost]
  2023. [ApiLog("Grp_DelegationInfo", OperationEnum.Del)]
  2024. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2025. public async Task<IActionResult> GroupDel(GroupDelDto dto)
  2026. {
  2027. var diId = dto.Id;
  2028. if (diId < 1) return Ok(JsonView(false, MsgTips.Id));
  2029. #region 删除 验证
  2030. /*
  2031. * 1、收款账单数据:0 条
  2032. * 2、收款退还数据:0 条
  2033. * 3、机票费用数据:0 条
  2034. * 4、签证费用数据:0 条
  2035. * 5、保险费用数据:0 条
  2036. * 6、酒店费用数据:0 条
  2037. * 7、公务出访数据:1 条
  2038. * 8、邀请公务活动费用数据:1 条
  2039. * 9、OP费用数据:5 条
  2040. * 10、其他费用数据:0 条
  2041. * 11、团组日付报销费用数据:0 条
  2042. *
  2043. * 温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!
  2044. */
  2045. //收款账单
  2046. int frCount = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(x => x.IsDel == 0 && x.Diid == diId).Count();
  2047. //收款退还
  2048. int fraomCount = _sqlSugar.Queryable<Fin_PaymentRefundAndOtherMoney>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2049. //机票费用
  2050. int arCount = _sqlSugar.Queryable<Grp_AirTicketReservations>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2051. //签证费用
  2052. int viCount = _sqlSugar.Queryable<Grp_VisaInfo>().Where(x => x.IsDel == 0 && x.DIId == diId).Count();
  2053. //保险费用
  2054. int cCount = _sqlSugar.Queryable<Grp_Customers>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2055. //酒店费用
  2056. int hrCount = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2057. //公务出访
  2058. int oaCount = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2059. //邀请公务活动费用
  2060. int ioaCount = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2061. //OP费用
  2062. int ctggrCount = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2063. //其他费用
  2064. int dpCount = _sqlSugar.Queryable<Grp_DecreasePayments>().Where(x => x.IsDel == 0 && x.DiId == diId).Count();
  2065. //团组日付报销费用
  2066. int dfpCount = _sqlSugar.Queryable<Fin_DailyFeePayment>().Where(x => x.IsDel == 0 && x.GroupId == diId).Count();
  2067. var feeCount = frCount + fraomCount + arCount + viCount + cCount + hrCount + oaCount + ioaCount + ctggrCount + dpCount + dfpCount;
  2068. if (feeCount > 0)
  2069. {
  2070. var delMsgTips = new StringBuilder();
  2071. delMsgTips.AppendLine($"1、收款账单数据:{frCount} 条");
  2072. delMsgTips.AppendLine($"2、收款退换数据:{fraomCount} 条");
  2073. delMsgTips.AppendLine($"3、机票费用数据:{arCount} 条");
  2074. delMsgTips.AppendLine($"4、签证费用数据:{viCount} 条");
  2075. delMsgTips.AppendLine($"5、保险费用数据:{cCount} 条");
  2076. delMsgTips.AppendLine($"6、酒店费用数据:{hrCount} 条");
  2077. delMsgTips.AppendLine($"7、公务出访数据:{oaCount} 条");
  2078. delMsgTips.AppendLine($"8、邀请公务活动费用数据:{ioaCount} 条");
  2079. delMsgTips.AppendLine($"9、OP费用数据:{ctggrCount} 条");
  2080. delMsgTips.AppendLine($"10、其他费用数据:{dpCount} 条");
  2081. delMsgTips.AppendLine($"11、团组日付报销费用数据:{dfpCount} 条");
  2082. delMsgTips.AppendLine($"");
  2083. delMsgTips.AppendLine($"温馨提示:该团组已产生费用,不允许删除;如需删除,请先删除对应版块费用,谢谢!");
  2084. return Ok(JsonView(false, delMsgTips.ToString()));
  2085. }
  2086. #endregion
  2087. var groupData = await _groupRepository.GroupDel(dto);
  2088. if (groupData.Code != 0)
  2089. {
  2090. return Ok(JsonView(false, groupData.Msg));
  2091. }
  2092. return Ok(JsonView(true));
  2093. }
  2094. /// <summary>
  2095. /// 获取团组销售报价号
  2096. /// 团组添加时 使用
  2097. /// </summary>
  2098. /// <returns></returns>
  2099. [HttpPost]
  2100. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2101. public async Task<IActionResult> GetGroupSalesQuoteNo()
  2102. {
  2103. var groupData = await _groupRepository.GetGroupSalesQuoteNo();
  2104. if (groupData.Code != 0)
  2105. {
  2106. return Ok(JsonView(false, groupData.Msg));
  2107. }
  2108. object salesQuoteNo = new
  2109. {
  2110. SalesQuoteNo = groupData.Data
  2111. };
  2112. return Ok(JsonView(salesQuoteNo));
  2113. }
  2114. /// <summary>
  2115. /// 设置确认出团
  2116. /// </summary>
  2117. /// <param name="dto"></param>
  2118. /// <returns></returns>
  2119. [HttpPost]
  2120. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2121. public async Task<IActionResult> SetConfirmationGroup(ConfirmationGroupDto dto)
  2122. {
  2123. var groupData = await _groupRepository.ConfirmationGroup(dto);
  2124. if (groupData.Code != 0)
  2125. {
  2126. return Ok(JsonView(false, groupData.Msg));
  2127. }
  2128. var groupInfo = _groupRepository.Query(s => s.Id == dto.GroupId).First();
  2129. #region OA消息推送
  2130. try
  2131. {
  2132. string groupName = groupInfo.TeamName;
  2133. var userIds = _airTicketResRep.Query<Sys_Users>(s => s.DepId == 7 && s.IsDel == 0).Select(x => x.Id).ToList();
  2134. string title = $"系统通知";
  2135. string content = $"团组[{groupName}]已确认出团!";
  2136. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, dto.GroupId);
  2137. }
  2138. catch (Exception ex)
  2139. {
  2140. }
  2141. #endregion
  2142. #region 应用推送
  2143. try
  2144. {
  2145. await AppNoticeLibrary.SendChatMsg_GroupStatus_Create(dto.GroupId, QiyeWeChatEnum.CompanyCRMChat);
  2146. Sys_Users users = _airTicketResRep.Query<Sys_Users>(s => s.Id == groupInfo.JietuanOperator).First();
  2147. Sys_Department department = _airTicketResRep.Query<Sys_Department>(s => s.Id == users.DepId).First();
  2148. if (department.Id == 6 && !string.IsNullOrEmpty(users.QiyeChatUserId))
  2149. {
  2150. var userList = new List<string>() { users.QiyeChatUserId };
  2151. await AppNoticeLibrary.SendUserMsg_GroupStatus_Create(dto.GroupId, userList);
  2152. }
  2153. }
  2154. catch (Exception ex)
  2155. {
  2156. }
  2157. #endregion
  2158. GroupStepForDelegation.CreateWorkStep(dto.GroupId); //创建管控流程
  2159. return Ok(JsonView(true, "操作成功!", groupData.Data));
  2160. }
  2161. /// <summary>
  2162. /// 获取团组名称data And 签证国别Data
  2163. /// </summary>
  2164. /// <param name="dto"></param>
  2165. /// <returns></returns>
  2166. [HttpPost]
  2167. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2168. public async Task<IActionResult> GetGroupNameAndVisaNationality(GroupNameDto dto)
  2169. {
  2170. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  2171. Where TeamName != '' And IsDel = 0
  2172. Order By VisitDate Desc");
  2173. var groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  2174. var data = new
  2175. {
  2176. groupNameData = groupNameList,
  2177. visaNationalityData = _visaTypeInit.ToList()
  2178. };
  2179. return Ok(JsonView(data));
  2180. }
  2181. /// <summary>
  2182. /// 根据CTable类型返回对应的团组名称及简单数据(APP端)
  2183. /// </summary>
  2184. /// <returns></returns>
  2185. [HttpPost]
  2186. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2187. public async Task<IActionResult> PostGroupNameAndEasy(DecreasePaymentsDto dto)
  2188. {
  2189. try
  2190. {
  2191. Result groupData = await _decreasePaymentsRep.PostGroupNameAndEasy(dto);
  2192. if (groupData.Code != 0)
  2193. {
  2194. return Ok(JsonView(false, groupData.Msg));
  2195. }
  2196. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  2197. }
  2198. catch (Exception ex)
  2199. {
  2200. return Ok(JsonView(false, ex.Message));
  2201. throw;
  2202. }
  2203. }
  2204. /// <summary>
  2205. /// 团组清单 Excel
  2206. /// </summary>
  2207. /// <param name="beginDt">开始时间 EG:“2024-01-01”</param>
  2208. /// <param name="endDt">结束时间 EG;“2024-12-31”</param>
  2209. /// <returns></returns>
  2210. [HttpGet]
  2211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2212. public async Task<IActionResult> GroupListFile([FromQuery] string beginDt, [FromQuery] string endDt)
  2213. {
  2214. bool beginBool = DateTime.TryParse($"{beginDt} 00:00:00", out DateTime _beginDt),
  2215. endBool = DateTime.TryParse($"{endDt} 23:59:59", out DateTime _endDt);
  2216. if (!beginBool && !endBool)
  2217. {
  2218. return Ok(JsonView(false, "开始或结束时间不正确!"));
  2219. }
  2220. string sql = string.Format(@"
  2221. SELECT
  2222. ROW_NUMBER,
  2223. Id,
  2224. SalesQuoteNo,
  2225. TourCode,
  2226. TeamTypeId,
  2227. TeamType,
  2228. TeamLevId,
  2229. TeamLev,
  2230. TeamName,
  2231. ClientName,
  2232. ClientUnit,
  2233. VisitDate,
  2234. VisitDays,
  2235. VisitPNumber,
  2236. JietuanOperatorId,
  2237. JietuanOperator,
  2238. IsSure,
  2239. CreateUserName,
  2240. IsBid
  2241. FROM
  2242. (
  2243. SELECT
  2244. ROW_NUMBER() OVER(
  2245. ORDER BY
  2246. gdi.VisitDate Desc
  2247. ) AS ROW_NUMBER,
  2248. gdi.Id,
  2249. SalesQuoteNo,
  2250. TourCode,
  2251. ssd.Id TeamTypeId,
  2252. ssd.Name TeamType,
  2253. ssd1.Id TeamLevId,
  2254. ssd1.Name TeamLev,
  2255. TeamName,
  2256. ClientName,
  2257. ClientUnit,
  2258. VisitDate,
  2259. VisitDays,
  2260. VisitPNumber,
  2261. JietuanOperator JietuanOperatorId,
  2262. su.CnName JietuanOperator,
  2263. IsSure,
  2264. gdi.CreateTime,
  2265. su1.CnName As CreateUserName,
  2266. gdi.IsBid
  2267. FROM
  2268. Grp_DelegationInfo gdi
  2269. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  2270. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  2271. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  2272. LEFT JOIN Sys_Users su1 ON gdi.CreateUserId = su1.Id
  2273. WHERE
  2274. gdi.IsDel = 0
  2275. AND gdi.IsBid = 0
  2276. AND gdi.VisitDate BETWEEN '{0}' AND '{1}'
  2277. ) temp", _beginDt.ToString("yyyy-MM-dd HH:mm:ss"), _endDt.ToString("yyyy-MM-dd HH:mm:ss"));
  2278. var groupList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  2279. #region 处理所属部门
  2280. /*
  2281. * 1.sq 和 gyy 等显示 市场部
  2282. * 2.王鸽和主管及张总还有管理员号统一国交部
  2283. * 2-1. 4 管理员 ,21 张海麟
  2284. */
  2285. var userIds = groupList.Select(it => it.JietuanOperatorId).ToList();
  2286. var userIds1 = new List<int>() { 4, 21 };
  2287. var userDepDatas = await _sqlSugar.Queryable<Sys_Users>()
  2288. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2289. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2290. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2291. .ToListAsync();
  2292. var droupIds = groupList.Select(it => it.Id).ToList();
  2293. var deleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  2294. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  2295. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  2296. .Where((tcl, dc, cc) => tcl.IsDel == 0 && droupIds.Contains(tcl.DiId))
  2297. .Select((tcl, dc, cc) => new ClientInfoInfo_Group
  2298. {
  2299. DiId = tcl.DiId,
  2300. LastName = dc.LastName,
  2301. FirstName = dc.FirstName,
  2302. Sex = dc.Sex,
  2303. Birthday = dc.BirthDay,
  2304. Company = cc.CompanyFullName,
  2305. Job = dc.Job,
  2306. CreateTime = tcl.CreateTime,
  2307. })
  2308. .ToList();
  2309. foreach (var item in groupList)
  2310. {
  2311. item.Department = userDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
  2312. string groupFirstName = "";
  2313. var currDatas = deleClientList.Where(x => x.DiId == item.Id).ToList();
  2314. if (currDatas.Any())
  2315. {
  2316. groupFirstName = AesEncryptionHelper.Decrypt(currDatas[0].LastName) + AesEncryptionHelper.Decrypt(currDatas[0].FirstName);
  2317. }
  2318. item.GroupFirst = groupFirstName;
  2319. }
  2320. #endregion
  2321. #region Excel
  2322. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  2323. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  2324. var savePath = AppSettingsHelper.Get("GrpListFileBasePath");
  2325. var ftpPath = AppSettingsHelper.Get("GrpListFileFtpPath");
  2326. var fileName = $"团组清单({beginDt}~{endDt}){DateTime.Now:yyyyMMddHHmmss}.xlsx";
  2327. //载入模板
  2328. var designer = new WorkbookDesigner
  2329. {
  2330. Workbook = new Workbook($"{tempPath}团组清单模板.xlsx")
  2331. };
  2332. designer.SetDataSource("Titel", $"团组清单({beginDt}~{endDt})");
  2333. DataTable dt = CommonFun.GetDataTableFromIList<DelegationListView>(groupList); ;
  2334. dt.TableName = "GroupList";
  2335. designer.SetDataSource(dt);
  2336. designer.Process();
  2337. if (!Directory.Exists(savePath))
  2338. {
  2339. Directory.CreateDirectory(savePath);
  2340. }
  2341. string serverPath = $"{savePath}{fileName}";
  2342. designer.Workbook.Save(serverPath);
  2343. string rst = $"{servicePath}{ftpPath}{fileName}";
  2344. #endregion
  2345. return Ok(JsonView(true, "操作成功!", rst));
  2346. }
  2347. /// <summary>
  2348. /// 团组合同下载(1.付款80% 2.付全款)
  2349. /// </summary>
  2350. /// <param name="dto"></param>
  2351. /// <returns></returns>
  2352. /// <exception cref="Exception"></exception>
  2353. [HttpPost]
  2354. public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
  2355. {
  2356. var jw = JsonView(false);
  2357. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  2358. .FirstAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
  2359. if (di == null)
  2360. {
  2361. jw.Msg = "团组Id有误!";
  2362. return Ok(jw);
  2363. }
  2364. #region 权限校验
  2365. var allDownFile = new List<int>() { 21 };
  2366. try
  2367. {
  2368. var setting = _sqlSugar.Queryable<Sys_SetData>()
  2369. .First(x => x.Id == 1418 && x.IsDel == 0);
  2370. allDownFile.AddRange(JsonConvert.DeserializeObject<List<int>>(setting.Remark));
  2371. }
  2372. catch (Exception)
  2373. { }
  2374. var guojiaoDownFile = new List<int>() { 330, 383 };
  2375. var shichangDownFile = new List<int>() { 95 };
  2376. if (allDownFile.Contains(dto.UserId))
  2377. {
  2378. }
  2379. else if (guojiaoDownFile.Contains(dto.UserId))
  2380. {
  2381. var guojiaobuDi = new List<int>() { 4, 21 };
  2382. var departmentStr = _sqlSugar.Queryable<Sys_Department>()
  2383. .LeftJoin<Sys_Users>((d, u) => d.Id == u.DepId && u.IsDel == 0)
  2384. .Where((d, u) => u.Id == di.JietuanOperator)
  2385. .Select((d, u) => d.DepName)
  2386. .First();
  2387. if (!guojiaobuDi.Contains(di.JietuanOperator) && departmentStr != "策划部" && departmentStr != "国交部")
  2388. {
  2389. jw.Msg = "暂无下载权限!";
  2390. return Ok(jw);
  2391. }
  2392. }
  2393. else if (shichangDownFile.Contains(dto.UserId))
  2394. {
  2395. var dic = new Dictionary<int, int[]>()
  2396. {
  2397. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 , 359 , 361, 368, 364, 366, 369} }
  2398. };
  2399. try
  2400. {
  2401. var sqSetting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1417);
  2402. if (sqSetting != null)
  2403. {
  2404. Dictionary<int, int[]> result = JsonConvert.DeserializeObject<Dictionary<int, int[]>>(sqSetting.Remark);
  2405. foreach (var item in result.Keys)
  2406. {
  2407. if (dic.ContainsKey(item))
  2408. {
  2409. int[] dilatation = new int[dic[item].Length + result[item].Length];
  2410. Array.Copy(dic[item], dilatation, dic[item].Length);
  2411. Array.Copy(result[item], 0, dilatation, dic[item].Length, result[item].Length);
  2412. dic[item] = dilatation;
  2413. }
  2414. else
  2415. {
  2416. dic.Add(item, result[item]);
  2417. }
  2418. }
  2419. }
  2420. if (!dic[95].Contains(di.CreateUserId))
  2421. {
  2422. jw.Msg = "暂无下载权限!";
  2423. return Ok(jw);
  2424. }
  2425. }
  2426. catch (Exception)
  2427. { }
  2428. }
  2429. else if (dto.UserId == di.CreateUserId)
  2430. {
  2431. }
  2432. else
  2433. {
  2434. jw.Msg = "暂无下载权限!";
  2435. return Ok(jw);
  2436. }
  2437. #endregion
  2438. var blackCodeList = await _sqlSugar.Queryable<Air_TicketBlackCode>()
  2439. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  2440. .ToListAsync();
  2441. if (!blackCodeList.Any())
  2442. {
  2443. jw.Msg = "该团无机票行程代码!";
  2444. return Ok(jw);
  2445. }
  2446. var groupEnterExitCost = await _sqlSugar.Queryable<Grp_EnterExitCost>()
  2447. .FirstAsync(x => x.DiId == dto.GroupId && x.IsDel == 0);
  2448. if (groupEnterExitCost == null)
  2449. {
  2450. jw.Msg = "暂无三公费用信息!";
  2451. return Ok(jw);
  2452. }
  2453. var rateList = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(groupEnterExitCost.CurrencyRemark);
  2454. rateList ??= new List<CurrencyInfo>();
  2455. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == di.Id).ToList();
  2456. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  2457. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  2458. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  2459. .Where((x, a, b) => x.IsDel == 0 && x.Diid == di.Id)
  2460. .Select((x, a, b) => new
  2461. {
  2462. x.Index,
  2463. itemName = a.Name,
  2464. CurrencyStr = b.Name,
  2465. x.Cost,
  2466. x.SubTotal,
  2467. x.Remark
  2468. })
  2469. .OrderBy((x) => x.Index)
  2470. .ToList();
  2471. decimal stayFeeTotal = groupEnterExitCost.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  2472. decimal mealsFeeTotal = groupEnterExitCost.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  2473. decimal miscellaneousFeeTotal = groupEnterExitCost.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  2474. decimal tainFeeTotal = groupEnterExitCost.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  2475. decimal otherPriceTotal = groupEnterExitCost.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  2476. decimal insidePayTotal = groupEnterExitCost.ChoiceOne == 1 ? groupEnterExitCost.InsidePay : 0.00M;
  2477. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  2478. decimal subJJC = 0.00M,
  2479. subGWC = 0.00M,
  2480. subTDC = 0.00M;
  2481. //经济舱
  2482. if (groupEnterExitCost.SumJJC == 1)
  2483. {
  2484. subJJC = otherFeeTotal + groupEnterExitCost.OutsideJJPay;
  2485. }
  2486. //公务舱
  2487. if (groupEnterExitCost.SumGWC == 1)
  2488. {
  2489. subGWC = otherFeeTotal + groupEnterExitCost.OutsideGWPay;
  2490. }
  2491. //头等舱
  2492. if (groupEnterExitCost.SumTDC == 1)
  2493. {
  2494. subTDC = otherFeeTotal + groupEnterExitCost.OutsideTDPay;
  2495. }
  2496. var groupClints = await _sqlSugar.Queryable<Grp_TourClientList>()
  2497. .LeftJoin<Sys_SetData>((x, s) => s.Id == x.ShippingSpaceTypeId && s.IsDel == 0)
  2498. .LeftJoin<Crm_DeleClient>((x, s, dc) => x.ClientId == dc.Id && dc.IsDel == 0)
  2499. .LeftJoin<Crm_CustomerCompany>((x, s, dc, cc) => dc.CrmCompanyId == cc.Id && cc.IsDel == 0)
  2500. .Where((x, s, dc, cc) => x.DiId == dto.GroupId && x.IsDel == 0)
  2501. .Select((x, s, dc, cc) => new GroupClints
  2502. {
  2503. Id = x.Id,
  2504. Name = s.Name,
  2505. IsAccompany = x.IsAccompany,
  2506. CompanyFullName = cc.CompanyFullName
  2507. })
  2508. .ToListAsync();
  2509. groupClints.ForEach(x => x.CompanyFullName = AesEncryptionHelper.Decrypt(x.CompanyFullName));
  2510. //获取舱位人数
  2511. var cabinCount = groupClints.Where(x => x.IsAccompany != 2 && !x.CompanyFullName.Contains("泛美国际"))
  2512. .GroupBy(x => x.Name)
  2513. .Select(x => new { Cabin = x.Key, Count = x.Count() })
  2514. .ToList();
  2515. string cityPath = string.Empty;
  2516. string startCity = string.Empty;
  2517. string endCity = string.Empty;
  2518. foreach (var item in blackCodeList)
  2519. {
  2520. string city = GeneralMethod.GetGroupCityLine(item, "-");
  2521. cityPath += city + "\r\n";
  2522. if (item.Equals(blackCodeList.First()))
  2523. {
  2524. var sp = city.Split('-');
  2525. startCity = sp[0];
  2526. endCity = sp[^1];
  2527. }
  2528. }
  2529. di.VisitCountry = Regex.Replace(di.VisitCountry, @"[|-]", "、");
  2530. var bookMarkDic = new Dictionary<string, string>
  2531. {
  2532. { "ClientUnit", di.ClientUnit },
  2533. { "VisitCountry", di.VisitCountry },
  2534. { "VisitDate", di.VisitDate.ToString("yyyy年MM月dd日") },
  2535. { "VisitPNumber", di.VisitPNumber.ToString() },
  2536. { "CityPath", cityPath },
  2537. { "StartCity", startCity },
  2538. { "EndCity", endCity },
  2539. { "StayDays", $"{di.VisitDays}天{di.VisitDays - 1}晚" }
  2540. };
  2541. Document doc = null;
  2542. var percentage = 0.8M;
  2543. var fileNameadd = "预付";
  2544. if (dto.FileType == 1)
  2545. {
  2546. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
  2547. }
  2548. else if (dto.FileType == 2)
  2549. {
  2550. doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同全款无表格.doc");
  2551. percentage = 1;
  2552. fileNameadd = "全款";
  2553. }
  2554. else
  2555. {
  2556. throw new Exception("FileType有误!");
  2557. }
  2558. var builder = new DocumentBuilder(doc);
  2559. decimal totalPrice = 0.00M;
  2560. Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
  2561. if (firstTable != null)
  2562. {
  2563. // 遍历表格的行和单元格
  2564. foreach (Aspose.Words.Tables.Row row in firstTable.Rows)
  2565. {
  2566. for (int i = 0; i < row.Cells.Count; i++)
  2567. {
  2568. var cell = row.Cells[i];
  2569. // 读取单元格内容
  2570. string cellTextFirst = row.Cells[0].FirstParagraph.ToString(Aspose.Words.SaveFormat.Text).Trim();
  2571. if (cellTextFirst.Contains("舱位"))
  2572. {
  2573. break;
  2574. }
  2575. if (cellTextFirst == "经济舱" || cellTextFirst == "公务舱")
  2576. {
  2577. if (i == 2)
  2578. {
  2579. if (cellTextFirst == "经济舱")
  2580. {
  2581. // 设置单元格内容
  2582. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2583. cell.FirstParagraph.AppendChild(new Run(doc, subJJC.ToString())); // 添加
  2584. }
  2585. else
  2586. {
  2587. // 设置单元格内容
  2588. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2589. cell.FirstParagraph.AppendChild(new Run(doc, subGWC.ToString())); // 添加
  2590. }
  2591. }
  2592. if (i == 3)
  2593. {
  2594. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2595. if (count != null)
  2596. {
  2597. // 设置单元格内容
  2598. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2599. cell.FirstParagraph.AppendChild(new Run(doc, count.ToString())); // 添加
  2600. }
  2601. }
  2602. if (i == 4)
  2603. {
  2604. var rowPrice = 0.00M;
  2605. var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
  2606. count ??= 0;
  2607. if (cellTextFirst == "经济舱")
  2608. {
  2609. rowPrice = subJJC * (int)count;
  2610. }
  2611. else
  2612. {
  2613. rowPrice = subGWC * (int)count;
  2614. }
  2615. totalPrice += rowPrice;
  2616. // 设置单元格内容
  2617. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2618. cell.FirstParagraph.AppendChild(new Run(doc, rowPrice.ToString())); // 添加
  2619. }
  2620. }
  2621. }
  2622. }
  2623. }
  2624. bookMarkDic.Add("TotalPrice", (totalPrice).ToString("#0.00"));
  2625. bookMarkDic.Add("TotalPrice1", (totalPrice * percentage).ToString("#0.00"));
  2626. bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
  2627. //--合同表格部分
  2628. bookMarkDic.Add("TimeNowDate", DateTime.Now.ToString("yyyy年MM月dd日"));
  2629. bookMarkDic.Add("ClientUnit1", di.ClientUnit);
  2630. bookMarkDic.Add("VisitCountry1", di.VisitCountry);
  2631. bookMarkDic.Add("DayCount", di.VisitDays.ToString());
  2632. bookMarkDic.Add("VisitingArea", di.VisitDate.ToString("yyyy年MM月dd日") + "-" + di.VisitEndDate.ToString("yyyy年MM月dd日"));
  2633. bookMarkDic.Add("CityPath1", cityPath);
  2634. bookMarkDic.Add("CityPath2", cityPath);
  2635. Table contractTable = (Table)doc.GetChild(NodeType.Table, 1, true);
  2636. if (contractTable != null)
  2637. {
  2638. //数据源
  2639. var _DayAndCostsAndCity = _sqlSugar.Queryable<Grp_DayAndCost>()
  2640. .LeftJoin<Grp_NationalTravelFee>((it, y) => it.NationalTravelFeeId == y.Id && y.IsDel == 0)
  2641. .LeftJoin<Sys_SetData>((it, y, s) => s.IsDel == 0 && s.Id == it.Currency)
  2642. .Where((it, y, s) => it.IsDel == 0 && it.DiId == di.Id)
  2643. .Select((it, y, s) => new
  2644. {
  2645. it.Cost,
  2646. it.SubTotal,
  2647. it.Type,
  2648. y.Id,
  2649. y.City,
  2650. s.Name,
  2651. CurrencyCodeCn = s.Remark
  2652. })
  2653. .ToList()
  2654. .Select(x => new
  2655. {
  2656. CurrencyCode = x.Name,
  2657. CityId = x.Id,
  2658. x.City,
  2659. di.VisitPNumber,
  2660. x.Type,
  2661. x.Cost,
  2662. x.SubTotal,
  2663. rateList.Find(y => y.CurrencyCode == x.Name)?.Rate,
  2664. x.CurrencyCodeCn,
  2665. });
  2666. var dac1 = _DayAndCostsAndCity.Where(it => it.Type == 1).GroupBy(x => x.CityId).ToList(); //住宿费
  2667. var dac2 = _DayAndCostsAndCity.Where(it => it.Type == 2).GroupBy(x => x.CityId).ToList(); //伙食费
  2668. var dac3 = _DayAndCostsAndCity.Where(it => it.Type == 3).GroupBy(x => x.CityId).ToList(); //公杂费
  2669. var dac4 = _DayAndCostsAndCity.Where(it => it.Type == 4).GroupBy(x => x.CityId).ToList(); //培训费
  2670. var tableSettings = new List<tableSetting>()
  2671. {
  2672. new(){ Index = 1 , Property = "City"},
  2673. new(){ Index = 2 , Property = "CurrencyCodeCn"},
  2674. new(){ Index = 3 , Property = "Cost"},
  2675. new(){ Index = 4 , Property = "VisitPNumber"},
  2676. //new tableSetting{ Index = 5 , Property = ""},
  2677. //new tableSetting{ Index = 6 , Property = ""},
  2678. new(){ Index = 7 , Property = "Rate"},
  2679. //new tableSetting{ Index = 8 , Property = ""},
  2680. };
  2681. //1.住宿费
  2682. int cloneRow = 8;
  2683. int startDayPrice = 8; //写入index
  2684. decimal ZSPriceSum = 0.00M, HSPriceSum = 0.00M, GZPriceSum = 0.00M;
  2685. foreach (var dac in dac1)
  2686. {
  2687. var first = dac.First();
  2688. var dayCount = dac.Count();
  2689. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2690. for (int i = 1; i < row.Cells.Count; i++)
  2691. {
  2692. var cell = row.Cells[i];
  2693. var findProperty = tableSettings.Find(x => x.Index == i);
  2694. if (findProperty != null)
  2695. {
  2696. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2697. // 设置单元格内容
  2698. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2699. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2700. }
  2701. else
  2702. {
  2703. switch (i)
  2704. {
  2705. case 5:
  2706. cell.FirstParagraph.Runs.Clear();
  2707. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2708. break;
  2709. case 6:
  2710. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2711. cell.FirstParagraph.Runs.Clear();
  2712. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2713. break;
  2714. case 8:
  2715. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2716. cell.FirstParagraph.Runs.Clear();
  2717. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2718. ZSPriceSum += xiaojiRMB;
  2719. break;
  2720. default:
  2721. break;
  2722. }
  2723. }
  2724. }
  2725. startDayPrice++;
  2726. if (!dac1.Last().Equals(dac))
  2727. {
  2728. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2729. // 将克隆的行追加到原行后面
  2730. contractTable.Rows.Insert(startDayPrice, newRow);
  2731. }
  2732. else
  2733. {
  2734. cloneRow += dac1.Count + 1;
  2735. startDayPrice = cloneRow;
  2736. }
  2737. }
  2738. //2.伙食费
  2739. foreach (var dac in dac2)
  2740. {
  2741. var first = dac.First();
  2742. var dayCount = dac.Count();
  2743. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2744. for (int i = 1; i < row.Cells.Count; i++)
  2745. {
  2746. var cell = row.Cells[i];
  2747. var findProperty = tableSettings.Find(x => x.Index == i);
  2748. if (findProperty != null)
  2749. {
  2750. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2751. // 设置单元格内容
  2752. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2753. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2754. }
  2755. else
  2756. {
  2757. switch (i)
  2758. {
  2759. case 5:
  2760. cell.FirstParagraph.Runs.Clear();
  2761. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2762. break;
  2763. case 6:
  2764. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2765. cell.FirstParagraph.Runs.Clear();
  2766. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2767. break;
  2768. case 8:
  2769. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2770. cell.FirstParagraph.Runs.Clear();
  2771. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2772. HSPriceSum += xiaojiRMB;
  2773. break;
  2774. default:
  2775. break;
  2776. }
  2777. }
  2778. }
  2779. startDayPrice++;
  2780. if (!dac2.Last().Equals(dac))
  2781. {
  2782. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2783. // 将克隆的行追加到原行后面
  2784. contractTable.Rows.Insert(startDayPrice, newRow);
  2785. }
  2786. else
  2787. {
  2788. cloneRow += dac2.Count + 1;
  2789. startDayPrice = cloneRow;
  2790. }
  2791. }
  2792. //3.公杂费
  2793. foreach (var dac in dac3)
  2794. {
  2795. var first = dac.First();
  2796. var dayCount = dac.Count();
  2797. Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
  2798. for (int i = 1; i < row.Cells.Count; i++)
  2799. {
  2800. var cell = row.Cells[i];
  2801. var findProperty = tableSettings.Find(x => x.Index == i);
  2802. if (findProperty != null)
  2803. {
  2804. string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
  2805. // 设置单元格内容
  2806. cell.FirstParagraph.Runs.Clear(); // 清除原有内容
  2807. cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
  2808. }
  2809. else
  2810. {
  2811. switch (i)
  2812. {
  2813. case 5:
  2814. cell.FirstParagraph.Runs.Clear();
  2815. cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
  2816. break;
  2817. case 6:
  2818. var xiaoji = dayCount * first.VisitPNumber * first.Cost;
  2819. cell.FirstParagraph.Runs.Clear();
  2820. cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
  2821. break;
  2822. case 8:
  2823. var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
  2824. cell.FirstParagraph.Runs.Clear();
  2825. cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
  2826. GZPriceSum += xiaojiRMB;
  2827. break;
  2828. default:
  2829. break;
  2830. }
  2831. }
  2832. }
  2833. startDayPrice++;
  2834. if (!dac3.Last().Equals(dac))
  2835. {
  2836. Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
  2837. // 将克隆的行追加到原行后面
  2838. contractTable.Rows.Insert(startDayPrice, newRow);
  2839. }
  2840. else
  2841. {
  2842. cloneRow += dac3.Count + 1;
  2843. startDayPrice = cloneRow;
  2844. }
  2845. }
  2846. //合并单元格
  2847. for (int i = 8; i < contractTable.Rows.Count - 1; i++)
  2848. {
  2849. var currentRow = contractTable.Rows[i];
  2850. var nextRow = contractTable.Rows[i + 1];
  2851. // 获取当前行和下一行的第一个单元格
  2852. Cell currentCell = currentRow.Cells[0];
  2853. Cell nextCell = nextRow.Cells[0];
  2854. // 检查单元格内容是否一致(去除尾部的换行符)
  2855. string currentText = currentCell.GetText().Trim();
  2856. string nextText = nextCell.GetText().Trim();
  2857. if (currentText == nextText)
  2858. {
  2859. // 如果当前单元格已经被合并,找到合并的起始单元格
  2860. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2861. {
  2862. // 找到合并的起始单元格
  2863. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2864. // 将下一行的单元格设置为合并的后续单元格
  2865. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2866. }
  2867. else
  2868. {
  2869. // 如果当前单元格是合并的起始单元格
  2870. currentCell.CellFormat.VerticalMerge = CellMerge.First;
  2871. // 将下一行的单元格设置为合并的后续单元格
  2872. nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
  2873. }
  2874. }
  2875. else
  2876. {
  2877. // 如果内容不一致,重置当前单元格的合并属性
  2878. if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
  2879. {
  2880. // 如果当前单元格是合并的后续单元格,找到合并的起始单元格并重置
  2881. int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
  2882. contractTable.Rows[mergeStartIndex].Cells[0].CellFormat.VerticalMerge = CellMerge.First;
  2883. }
  2884. else
  2885. {
  2886. currentCell.CellFormat.VerticalMerge = CellMerge.None;
  2887. }
  2888. }
  2889. }
  2890. bookMarkDic.Add("ZSPriceSum", ZSPriceSum.ToString("F2"));
  2891. bookMarkDic.Add("HSPriceSum", HSPriceSum.ToString("F2"));
  2892. bookMarkDic.Add("GZPriceSum", GZPriceSum.ToString("F2"));
  2893. }
  2894. foreach (var bookmarkName in bookMarkDic.Keys)
  2895. {
  2896. Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
  2897. if (bookmark != null)
  2898. {
  2899. if (bookmarkName == "ClientUnit")
  2900. {
  2901. // 移动到书签位置
  2902. builder.MoveTo(bookmark.BookmarkStart);
  2903. // 设置字体样式为下划线
  2904. builder.Font.Underline = Aspose.Words.Underline.Single;
  2905. // 插入书签值
  2906. builder.Write(bookMarkDic[bookmarkName]);
  2907. // 清除字体格式,避免影响后续文本
  2908. builder.Font.ClearFormatting();
  2909. }
  2910. else
  2911. {
  2912. builder.MoveToBookmark(bookmarkName);
  2913. builder.Write(bookMarkDic[bookmarkName]);
  2914. }
  2915. }
  2916. }
  2917. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_{fileNameadd}版本合同文件.doc";
  2918. doc.Save(savePaht);
  2919. jw.Msg = "生成成功!";
  2920. jw.Code = 200;
  2921. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  2922. return Ok(jw);
  2923. }
  2924. static int FindMergeStartRowIndex(Table table, int rowIndex)
  2925. {
  2926. int index = rowIndex;
  2927. while (index > 0 && table.Rows[index].Cells[0].CellFormat.VerticalMerge == CellMerge.Previous)
  2928. {
  2929. index--;
  2930. }
  2931. return index;
  2932. }
  2933. /// <summary>
  2934. /// 报批完成企微通知
  2935. /// </summary>
  2936. /// <param name="dto"></param>
  2937. /// <returns></returns>
  2938. [HttpPost]
  2939. public async Task<IActionResult> EnterpriseWeChatNotificationAsyncBaoPi(EnterpriseWeChatNotificationAsyncBaoPiDto dto)
  2940. {
  2941. int currUserId = dto.currUserId;
  2942. int diid = dto.diid;
  2943. var jw = JsonView(true);
  2944. var users = new List<string>();
  2945. var ssd = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1460);
  2946. //时间格式验证
  2947. if (!DateTime.TryParse(dto.stepOperationTime, out DateTime dt))
  2948. {
  2949. return Ok(JsonView(false, "请传入有效的时间格式!(例如:2026-01-06 15:45:02)"));
  2950. }
  2951. try
  2952. {
  2953. users = JsonConvert.DeserializeObject<List<string>>(ssd.Remark);
  2954. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(dto.diid);
  2955. //添加分配人员
  2956. // 79 车/导游地接
  2957. // 80 签证
  2958. // 81 邀请/公务活动
  2959. var setdataids = new List<int>() { 79, 81 };
  2960. foreach (var groupModule in groupModuleOperators)
  2961. {
  2962. if (setdataids.Contains(groupModule.CTableId))
  2963. {
  2964. users.AddRange(groupModule.OperationUsers.Select(x => x.UserId.ToString()));
  2965. }
  2966. }
  2967. var res = await AppNoticeLibrary.SendUserMsg_BaoPi_ToUser(users, diid);
  2968. //消息通知成功 更改团组step、记录日志
  2969. if (res)
  2970. {
  2971. var groupStep = 0; //0-新建 1-企微消息通知
  2972. //更改团组step
  2973. var updStatus = await _sqlSugar.Updateable<Grp_DelegationInfo>()
  2974. .SetColumns(x => new Grp_DelegationInfo()
  2975. {
  2976. Step = 2,
  2977. StepOperationTime = dt
  2978. })
  2979. .Where(x => x.Id == diid && x.IsDel == 0)
  2980. .ExecuteCommandAsync();
  2981. if (updStatus > 0) groupStep = 2;
  2982. string groupStepLabel = groupStep switch
  2983. {
  2984. 1 => "新建",
  2985. 2 => "企微消息通知(报批)",
  2986. _ => "未设置"
  2987. };
  2988. //记录日志
  2989. var teamName = _sqlSugar.Queryable<Grp_DelegationInfo>()
  2990. .Where(x => x.Id == diid && x.IsDel == 0)
  2991. .Select(x => x.TeamName)
  2992. .First() ?? "-";
  2993. var operationName = _sqlSugar.Queryable<Sys_Users>()
  2994. .Where(x => x.Id == currUserId && x.IsDel == 0)
  2995. .Select(x => x.CnName)
  2996. .First() ?? "-";
  2997. _groupTextLogger.LogInformation("团组:【{teamName}({groupId})】 操作人:【{operationName}】 操作时间:【{operationTime}】{logContent}", teamName, diid, operationName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), groupStepLabel);
  2998. //设置 签证流程初始值
  2999. await _visaProcessRep.UpdateBatchTop4Step(dto.diid, dto.currUserId);
  3000. }
  3001. }
  3002. catch (Exception ex)
  3003. {
  3004. return Ok(JsonView(false, ex.Message));
  3005. }
  3006. return Ok(jw);
  3007. }
  3008. #endregion
  3009. #region 团组&签证
  3010. #region 团组&签证 New
  3011. /// <summary>
  3012. /// 团组&签证 New
  3013. /// DeepSeek API:测试API连通性
  3014. /// </summary>
  3015. /// <param name="file">请求dto</param>
  3016. /// <returns></returns>
  3017. [HttpPost]
  3018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3019. public async Task<IActionResult> TestDeepSeekApiConnectivityAsync()
  3020. {
  3021. return Ok(JsonView(await _deepSeekService.TestApiConnectivityAsync()));
  3022. }
  3023. /// <summary>
  3024. /// 团组&签证 New
  3025. /// DeepSeek API:检查可用端点
  3026. /// </summary>
  3027. /// <param name="file">请求dto</param>
  3028. /// <returns></returns>
  3029. [HttpPost]
  3030. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3031. public async Task<IActionResult> DiscoverAvailableEndpointsAsync()
  3032. {
  3033. return Ok(JsonView(await _deepSeekService.DiscoverAvailableEndpointsAsync()));
  3034. }
  3035. /// <summary>
  3036. /// 团组&签证 New
  3037. /// 上传签证文件(客户填写签证文件),新增或更新 签证信息
  3038. /// </summary>
  3039. /// <param name="visaFile">文件</param>
  3040. /// </param>
  3041. /// <returns></returns>
  3042. [HttpPost]
  3043. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3044. public async Task<IActionResult> VisaFileUploadAndUpdate(IFormFile visaFile)
  3045. {
  3046. //文件验证
  3047. if (visaFile.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  3048. //var visaFiles = new VisaUploadFileTypeView();
  3049. //var filetypes = VisaUploadFileTypeView.GetVisaUploadFileTypeViewItemInit();
  3050. //if (!filetypes.Any(x => x.FileId == fileTypeId)) return Ok(JsonView(false, "请选择文件类型!"));
  3051. //服务器存储文件
  3052. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Uploads";
  3053. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  3054. var filePath = Path.Combine(fileServerPath, visaFile.FileName);
  3055. using (var stream = new FileStream(filePath, FileMode.Create))
  3056. {
  3057. await visaFile.CopyToAsync(stream);
  3058. }
  3059. //日志记录-上传文件
  3060. _logger.LogInformation("【签证上传文件操作信息】签证文件存储成功!路径:{fileServerPath} 文件名称:{fileName}", fileServerPath, visaFile.FileName);
  3061. #region kimi API
  3062. //kimi AI 识别文档返回json结果
  3063. var KiMiApi = new KiMiApiClient();
  3064. var files = new List<IFormFile>() { visaFile };
  3065. var seedConter = await KiMiApi.UploadFilesAsync(files);
  3066. if (seedConter.Count == 0) return Ok(JsonView(false, "Kimi AI 文件上传结果为空!"));
  3067. var seedMessage = string.Format(@"你是领事馆电子材料审核员,只关注 Word 里的表格,正文、页眉页脚、水印、批注全部忽略。
  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. - 是否曾被美国拒签:请提取文档中的“是否曾被美国拒签”。
  3178. - 美国拒签日期:请提取文档中的“美国拒签日期”。
  3179. - 美国拒签原因:请提取文档中的“美国拒签原因”。
  3180. - 代办人姓名:请提取文档中的“代办人姓名”。
  3181. - 代办人手机号码:请提取文档中的“代办人手机号码”。
  3182. - 代办人现居住地址:请提取文档中的“代办人现居住地址”。
  3183. 把表格里的每个可填字段转换成“标题:值”的键值对,值用原文,不翻译。
  3184. 注:日期格式:YYYY-MM-DD、值为空时空字符串
  3185. 只返回json结果,不需要其他内容,json内容去掉换行。");
  3186. var messages = new List<SeedMessages>
  3187. {
  3188. new() { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长识别文件为Json格式的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  3189. new() { Role = KimiRole.user, Content = seedMessage }
  3190. };
  3191. messages.InsertRange(1, seedConter);
  3192. string jsonString = "";
  3193. dynamic jsonData = null;
  3194. bool isJson = false;
  3195. while (!isJson)
  3196. {
  3197. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  3198. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  3199. var newJsonString = kimiApiResult_JObject["content"].ToString();
  3200. string startStr = "```json", endStr = "```";
  3201. // 判断并清除开头部分
  3202. if (newJsonString.StartsWith(startStr))
  3203. {
  3204. newJsonString = newJsonString.Replace(startStr, "");
  3205. }
  3206. // 判断并清除结尾部分
  3207. if (newJsonString.EndsWith(endStr))
  3208. {
  3209. newJsonString = newJsonString.Replace(endStr, "");
  3210. }
  3211. jsonString += newJsonString;
  3212. //验证json格式是否正确
  3213. try
  3214. {
  3215. jsonData = JsonDocument.Parse(jsonString);
  3216. isJson = true; // 如果解析成功,则是json格式
  3217. }
  3218. catch (Exception)
  3219. {
  3220. messages.Add(new() { Role = KimiRole.user, Content = "请接着续写未完成的json格式内容。" });
  3221. }
  3222. }
  3223. if (jsonData == null)
  3224. {
  3225. return Ok(JsonView(false, "kimi识别json转换失败。"));
  3226. }
  3227. var info = new Crm_DeleClient();
  3228. var company = new Crm_CustomerCompany();
  3229. var certs = new List<Crm_CustomerCert>();
  3230. var familys = new List<Crm_VisaCustomerFamily>();
  3231. var schools = new List<Crm_VisaCustomerSchool>();
  3232. var works = new List<Crm_VisaCustomerCompany>();
  3233. var refusalRecords = new List<VisaRefusalRecord>(); //拒签记录
  3234. var travelHistories = new List<TravelHistory>(); //出行历史
  3235. var militaries = new List<MilitaryInfo>(); //军事信息
  3236. var countryVisiteds = new List<CountryVisited>(); //已出访的国家
  3237. var schengenVisaRecords = new List<SchengenVisaRecord>(); //申根签证记录
  3238. var socialAccounts = new List<SocialAccount>(); //社交账号
  3239. var personInfos = new List<PersonInfo>(); //亲属朋友信息
  3240. try
  3241. {
  3242. using (JsonDocument document = JsonDocument.Parse(jsonString))
  3243. {
  3244. JsonElement root = document.RootElement;
  3245. if (root.ValueKind == JsonValueKind.Object)
  3246. {
  3247. if (root.TryGetProperty("个人信息", out JsonElement userInfo))
  3248. {
  3249. if (TryGetNonEmptyStringProperty(userInfo, "姓名", out string name))
  3250. {
  3251. info.LastName = name.Substring(0, 1);
  3252. info.FirstName = name.Substring(1, name.Length - 1);
  3253. }
  3254. if (TryGetNonEmptyStringProperty(userInfo, "曾用名", out string oldName))
  3255. info.OldName = oldName;
  3256. if (TryGetNonEmptyStringProperty(userInfo, "拼音名", out string pinyin))
  3257. info.Pinyin = pinyin;
  3258. if (TryGetNonEmptyStringProperty(userInfo, "性别", out string gender))
  3259. info.Sex = gender switch
  3260. {
  3261. "男" => 0,
  3262. "女" => 1,
  3263. _ => -1
  3264. };
  3265. if (TryGetNonEmptyDateTimeProperty(userInfo, "出生日期", out DateTime? birthDay))
  3266. info.BirthDay = birthDay;
  3267. if (TryGetNonEmptyStringProperty(userInfo, "出生地省", out string birthProvince))
  3268. info.BirthProvince = birthProvince;
  3269. if (TryGetNonEmptyStringProperty(userInfo, "出生地市", out string birthCity))
  3270. info.BirthCity = birthCity;
  3271. if (TryGetNonEmptyStringProperty(userInfo, "国籍", out string nationality))
  3272. { }
  3273. if (TryGetNonEmptyStringProperty(userInfo, "身份证号码", out string idNo))
  3274. certs.Add(new() { PassportType = 74, CertNo = idNo, Country = nationality });
  3275. if (TryGetNonEmptyStringProperty(userInfo, "婚姻状况", out string marital_status))
  3276. info.Marriage = marital_status switch
  3277. {
  3278. "未婚" => 1,
  3279. "已婚" => 2,
  3280. "离异" => 3,
  3281. "丧偶" => 4,
  3282. _ => 0
  3283. };
  3284. if (TryGetNonEmptyStringProperty(userInfo, "离婚原因", out string DivorceRsn))
  3285. info.DivorceRsn = DivorceRsn;
  3286. }
  3287. if (root.TryGetProperty("家庭信息", out JsonElement familyInfo))
  3288. {
  3289. if (TryGetNonEmptyStringProperty(familyInfo, "家庭地址", out string address))
  3290. info.Address = address;
  3291. if (TryGetNonEmptyStringProperty(familyInfo, "家庭电话", out string tel))
  3292. info.Tel = tel;
  3293. if (TryGetNonEmptyStringProperty(familyInfo, "移动电话", out string phone))
  3294. info.Phone = phone;
  3295. if (TryGetNonEmptyStringProperty(familyInfo, "电子邮箱", out string email))
  3296. info.Email = email;
  3297. if (familyInfo.TryGetProperty("家庭成员", out JsonElement family_members))
  3298. {
  3299. foreach (JsonElement family_member in family_members.EnumerateArray())
  3300. {
  3301. var familyInfo1 = new Crm_VisaCustomerFamily();
  3302. if (TryGetNonEmptyStringProperty(family_member, "关系", out string gx))
  3303. familyInfo1.Appellation = gx;
  3304. if (TryGetNonEmptyStringProperty(family_member, "姓名", out string family_name))
  3305. familyInfo1.Name = family_name;
  3306. if (TryGetNonEmptyDateTimeProperty(family_member, "出生日期", out DateTime? family_date_of_birth))
  3307. familyInfo1.BirthDay = family_date_of_birth;
  3308. if (TryGetNonEmptyStringProperty(family_member, "婚姻状况", out string marital_status))
  3309. familyInfo1.MaritalStatus = marital_status;
  3310. if (TryGetNonEmptyStringProperty(family_member, "现国籍", out string currentNationality))
  3311. familyInfo1.CurrentNationality = currentNationality;
  3312. if (TryGetNonEmptyStringProperty(family_member, "出生国", out string countryOfBirth))
  3313. familyInfo1.CountryOfBirth = countryOfBirth;
  3314. if (TryGetNonEmptyStringProperty(family_member, "现居住国", out string currentResidenceCountry))
  3315. familyInfo1.CurrentResidenceCountry = currentResidenceCountry;
  3316. if (TryGetNonEmptyStringProperty(family_member, "现职务", out string currentOccupation))
  3317. familyInfo1.CurrentOccupation = currentOccupation;
  3318. familys.Add(familyInfo1);
  3319. }
  3320. }
  3321. }
  3322. if (root.TryGetProperty("工作信息", out JsonElement workInfo))
  3323. {
  3324. if (TryGetNonEmptyStringProperty(workInfo, "工作单位名称", out string workName))
  3325. company.CompanyFullName = workName;
  3326. if (TryGetNonEmptyStringProperty(workInfo, "工作单位电话", out string workPhone))
  3327. info.ClientPhone = workPhone;
  3328. if (TryGetNonEmptyStringProperty(workInfo, "工作单位地址", out string address))
  3329. company.Address = address;
  3330. if (TryGetNonEmptyStringProperty(workInfo, "职位", out string job))
  3331. info.Job = job;
  3332. if (TryGetNonEmptyStringProperty(workInfo, "月薪", out string wage))
  3333. info.Wage = wage;
  3334. if (workInfo.TryGetProperty("工作经历", out JsonElement workExp))
  3335. {
  3336. foreach (JsonElement work in workExp.EnumerateArray())
  3337. {
  3338. var workInfo1 = new Crm_VisaCustomerCompany();
  3339. if (TryGetNonEmptyStringProperty(work, "单位名称", out string unit_name))
  3340. workInfo1.Company = unit_name;
  3341. if (TryGetNonEmptyStringProperty(work, "单位地址", out string unit_address))
  3342. workInfo1.CompanyAddress = unit_address;
  3343. if (TryGetNonEmptyStringProperty(work, "职务", out string work_position))
  3344. workInfo1.Job = work_position;
  3345. if (TryGetNonEmptyStringProperty(work, "上级领导姓名", out string superior_leader_name))
  3346. workInfo1.LeaderName = superior_leader_name;
  3347. if (TryGetNonEmptyDateTimeProperty(work, "入职时间", out DateTime? start_date))
  3348. workInfo1.WorkStart = start_date;
  3349. if (TryGetNonEmptyDateTimeProperty(work, "离职时间", out DateTime? end_date))
  3350. workInfo1.WorkEnd = end_date;
  3351. workInfo1.WorkState = "";
  3352. works.Add(workInfo1);
  3353. }
  3354. }
  3355. }
  3356. if (root.TryGetProperty("教育经历", out JsonElement eduInfo))
  3357. {
  3358. if (eduInfo.TryGetProperty("教育经历", out JsonElement educations))
  3359. {
  3360. foreach (JsonElement edu in educations.EnumerateArray())
  3361. {
  3362. var schoolInfo = new Crm_VisaCustomerSchool();
  3363. if (TryGetNonEmptyStringProperty(edu, "学校名称", out string school_name))
  3364. schoolInfo.School = school_name;
  3365. if (TryGetNonEmptyStringProperty(edu, "学校地址", out string school_address))
  3366. schoolInfo.Address = school_address;
  3367. if (TryGetNonEmptyStringProperty(edu, "专业", out string degree))
  3368. schoolInfo.Subject = degree;
  3369. if (TryGetNonEmptyStringProperty(edu, "学位", out string major))
  3370. schoolInfo.Education = major;
  3371. if (TryGetNonEmptyDateTimeProperty(edu, "入学时间", out DateTime? enrollment_date))
  3372. schoolInfo.StudyStart = enrollment_date;
  3373. if (TryGetNonEmptyDateTimeProperty(edu, "毕业时间", out DateTime? graduation_date))
  3374. schoolInfo.StudyEnd = graduation_date;
  3375. schools.Add(schoolInfo);
  3376. }
  3377. }
  3378. }
  3379. if (root.TryGetProperty("签证与旅行记录", out JsonElement visaTravelRecs))
  3380. {
  3381. if (visaTravelRecs.TryGetProperty("拒签记录", out JsonElement rejectRecs))
  3382. {
  3383. foreach (JsonElement rejectRec in rejectRecs.EnumerateArray())
  3384. {
  3385. var visaRefusalRecordInfo = new VisaRefusalRecord();
  3386. if (TryGetNonEmptyStringProperty(rejectRec, "国家", out string country))
  3387. visaRefusalRecordInfo.Country = country;
  3388. if (TryGetNonEmptyDateTimeProperty(rejectRec, "拒签日期", out DateTime? refusal_date))
  3389. visaRefusalRecordInfo.Date = refusal_date;
  3390. if (TryGetNonEmptyStringProperty(rejectRec, "申请签证类别", out string visaType))
  3391. visaRefusalRecordInfo.VisaType = visaType;
  3392. if (TryGetNonEmptyStringProperty(rejectRec, "地点", out string address))
  3393. visaRefusalRecordInfo.Address = address;
  3394. if (TryGetNonEmptyStringProperty(rejectRec, "拒签原因", out string refusal_reason))
  3395. visaRefusalRecordInfo.Reason = refusal_reason;
  3396. refusalRecords.Add(visaRefusalRecordInfo);
  3397. }
  3398. info.RefusalRecords = refusalRecords;
  3399. }
  3400. if (visaTravelRecs.TryGetProperty("旅行历史", out JsonElement travelHist))
  3401. {
  3402. foreach (JsonElement travel in travelHist.EnumerateArray())
  3403. {
  3404. var travelHistoryInfo = new TravelHistory();
  3405. if (TryGetNonEmptyStringProperty(travel, "国家", out string country))
  3406. travelHistoryInfo.Country = country;
  3407. if (TryGetNonEmptyDateTimeProperty(travel, "到达日期", out DateTime? arrival_date))
  3408. travelHistoryInfo.ArrivalDate = arrival_date;
  3409. if (TryGetNonEmptyDateTimeProperty(travel, "离开日期", out DateTime? departure_date))
  3410. travelHistoryInfo.DepartureDate = departure_date;
  3411. if (TryGetNonEmptyStringProperty(travel, "visa_type", out string visa_type))
  3412. travelHistoryInfo.VisaType = visa_type;
  3413. travelHistories.Add(travelHistoryInfo);
  3414. }
  3415. info.TravelHistories = travelHistories;
  3416. }
  3417. if (visaTravelRecs.TryGetProperty("服役历史", out JsonElement militaryHist))
  3418. {
  3419. foreach (JsonElement military in militaryHist.EnumerateArray())
  3420. {
  3421. var militaryInfo = new MilitaryInfo();
  3422. if (TryGetNonEmptyStringProperty(military, "军种", out string military_branch))
  3423. militaryInfo.MilBranch = military_branch;
  3424. if (TryGetNonEmptyStringProperty(military, "军衔", out string military_rank))
  3425. militaryInfo.MilRank = military_rank;
  3426. if (TryGetNonEmptyStringProperty(military, "服役时间范围", out string service_duration))
  3427. militaryInfo.ServeDuration = service_duration;
  3428. militaries.Add(militaryInfo);
  3429. }
  3430. info.Militaries = militaries;
  3431. }
  3432. if (visaTravelRecs.TryGetProperty("去过的国家", out JsonElement visitedCountries))
  3433. {
  3434. foreach (JsonElement country in visitedCountries.EnumerateArray())
  3435. {
  3436. var countryVisitedInfo = new CountryVisited();
  3437. if (TryGetNonEmptyStringProperty(country, "国家名称", out string visit_country))
  3438. countryVisitedInfo.Country = visit_country;
  3439. if (TryGetNonEmptyStringProperty(country, "访问日期范围", out string visit_date_range))
  3440. countryVisitedInfo.VisitDate = visit_date_range;
  3441. countryVisiteds.Add(countryVisitedInfo);
  3442. }
  3443. info.CountryVisiteds = countryVisiteds;
  3444. }
  3445. if (visaTravelRecs.TryGetProperty("申根签证记录", out JsonElement schengenVisaRecs))
  3446. {
  3447. foreach (JsonElement schengenVisaRec in schengenVisaRecs.EnumerateArray())
  3448. {
  3449. var schengenVisaRecInfo = new SchengenVisaRecord();
  3450. if (TryGetNonEmptyStringProperty(schengenVisaRec, "签证类型", out string visaType))
  3451. schengenVisaRecInfo.VisaType = visaType;
  3452. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "签发日期", out DateTime? issueDate))
  3453. schengenVisaRecInfo.IssueDate = issueDate;
  3454. if (TryGetNonEmptyDateTimeProperty(schengenVisaRec, "有效期", out DateTime? expiryDate))
  3455. schengenVisaRecInfo.ExpiryDate = expiryDate;
  3456. schengenVisaRecords.Add(schengenVisaRecInfo);
  3457. }
  3458. info.SchengenVisaRecords = schengenVisaRecords;
  3459. }
  3460. }
  3461. if (root.TryGetProperty("其他信息", out JsonElement otherInfo))
  3462. {
  3463. if (otherInfo.TryGetProperty("社交账号", out JsonElement socialAccountss))
  3464. {
  3465. foreach (JsonElement socialAccount in socialAccountss.EnumerateArray())
  3466. {
  3467. var socialAccount1 = new SocialAccount();
  3468. if (TryGetNonEmptyStringProperty(socialAccount, "平台名称", out string platform))
  3469. socialAccount1.Platform = platform;
  3470. if (TryGetNonEmptyStringProperty(socialAccount, "账号名称", out string account))
  3471. socialAccount1.Account = account;
  3472. socialAccounts.Add(socialAccount1);
  3473. }
  3474. info.SocialAccounts = socialAccounts;
  3475. }
  3476. if (TryGetNonEmptyStringProperty(otherInfo, "旅行目的", out string usaPurpose))
  3477. info.USAPurpose = usaPurpose;
  3478. if (TryGetNonEmptyStringProperty(otherInfo, "旅费支付方", out string payer))
  3479. info.CostBearers = payer;
  3480. if (TryGetNonEmptyStringProperty(otherInfo, "是否持有因公护照", out string isUSAVia))
  3481. info.IsUSAVia = isUSAVia switch
  3482. {
  3483. "是" => 1,
  3484. _ => 0
  3485. };
  3486. if (TryGetNonEmptyDateTimeProperty(otherInfo, "因公护照有效期", out DateTime? GetUSAVisaDate))
  3487. info.GetUSAVisaDate = GetUSAVisaDate;
  3488. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照类型", out string USAVisaCate))
  3489. info.USAVisaCate = USAVisaCate;
  3490. if (TryGetNonEmptyStringProperty(otherInfo, "因公护照号码", out string USAVisaCode))
  3491. info.USAVisaCode = USAVisaCode;
  3492. if (otherInfo.TryGetProperty("亲属、朋友及联系人信息", out JsonElement personInfos1))
  3493. {
  3494. foreach (JsonElement personInfo in personInfos1.EnumerateArray())
  3495. {
  3496. var personInfo1 = new PersonInfo();
  3497. if (TryGetNonEmptyStringProperty(personInfo, "类型", out string type))
  3498. personInfo1.Type = type;
  3499. if (TryGetNonEmptyStringProperty(personInfo, "姓名", out string name))
  3500. personInfo1.Name = name;
  3501. if (TryGetNonEmptyDateTimeProperty(personInfo, "出生日期", out DateTime? birthDay))
  3502. personInfo1.BirthDay = birthDay;
  3503. if (TryGetNonEmptyStringProperty(personInfo, "地址", out string address))
  3504. personInfo1.Address = address;
  3505. if (TryGetNonEmptyStringProperty(personInfo, "联系方式", out string contactInfo))
  3506. personInfo1.ContactInfo = contactInfo;
  3507. personInfos.Add(personInfo1);
  3508. }
  3509. info.PersonInfos = personInfos;
  3510. }
  3511. if (TryGetNonEmptyStringProperty(otherInfo, "是否有指纹记录", out string IsFinger))
  3512. info.IsFinger = IsFinger switch
  3513. {
  3514. "是" => 1,
  3515. _ => 0
  3516. };
  3517. if (TryGetNonEmptyDateTimeProperty(otherInfo, "指纹记录日期", out DateTime? FingerDate))
  3518. info.FingerDate = FingerDate;
  3519. if (TryGetNonEmptyStringProperty(otherInfo, "美国驾照号码", out string USA_DLNo))
  3520. info.USA_DLNo = USA_DLNo;
  3521. if (TryGetNonEmptyStringProperty(otherInfo, "指纹记录日期", out string USA_DLPlace))
  3522. info.USA_DLPlace = USA_DLPlace;
  3523. if (TryGetNonEmptyStringProperty(otherInfo, "美国社会安全号", out string USA_SSNOrITIN))
  3524. info.USA_SSNOrITIN = USA_SSNOrITIN;
  3525. if (TryGetNonEmptyStringProperty(otherInfo, "是否是其他国家的永久居民", out string Resident))
  3526. info.Resident = Resident;
  3527. if (TryGetNonEmptyStringProperty(otherInfo, "抵达美国时间", out string USAHadArrival‌))
  3528. info.USAHadArrival‌ = USAHadArrival‌;
  3529. if (TryGetNonEmptyStringProperty(otherInfo, "在美停留时间", out string USAHadDays‌))
  3530. info.USAHadDays‌ = USAHadDays‌;
  3531. if (TryGetNonEmptyStringProperty(otherInfo, "代办人姓名", out string TableOpName))
  3532. info.TableOpName = TableOpName;
  3533. if (TryGetNonEmptyStringProperty(otherInfo, "代办人手机号码", out string TableOpTel))
  3534. info.TableOpTel = TableOpTel;
  3535. if (TryGetNonEmptyStringProperty(otherInfo, "代办人现居住地址", out string TableOpAddress))
  3536. { }
  3537. }
  3538. }
  3539. }
  3540. }
  3541. catch (Exception ex)
  3542. {
  3543. return Ok(JsonView(false, "信息提取失败:" + ex.Message));
  3544. }
  3545. #region 数据提交
  3546. _sqlSugar.BeginTran();
  3547. try
  3548. {
  3549. var infos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0).Select(x => new { x.Id, x.FirstName, x.LastName, x.Phone }).ToListAsync();
  3550. var infoDecrypts = new List<dynamic>();
  3551. foreach (var item in infos)
  3552. {
  3553. infoDecrypts.Add(new
  3554. {
  3555. Id = item.Id,
  3556. FirstName = AesEncryptionHelper.Decrypt(item.FirstName),
  3557. LastName = AesEncryptionHelper.Decrypt(item.LastName),
  3558. Phone = AesEncryptionHelper.Decrypt(item.Phone),
  3559. });
  3560. }
  3561. var infoVaild = infoDecrypts.Where(x =>
  3562. info.FirstName.Equals(x.FirstName) &&
  3563. info.LastName.Equals(x.LastName) &&
  3564. info.Phone.Equals(x.Phone))
  3565. .FirstOrDefault();
  3566. var compnayInfos = await _sqlSugar.Queryable<Crm_CustomerCompany>()
  3567. .Where(x => x.IsDel == 0)
  3568. .ToListAsync();
  3569. foreach (var company1 in compnayInfos)
  3570. {
  3571. company1.CompanyFullName = AesEncryptionHelper.Decrypt(company1.CompanyFullName);
  3572. }
  3573. var compnayInfo = compnayInfos.FirstOrDefault(x => x.CompanyFullName == company.CompanyFullName);
  3574. if (compnayInfo == null)
  3575. {
  3576. company.CompanyFullName = AesEncryptionHelper.Encrypt(company.CompanyFullName);
  3577. compnayInfo = await _sqlSugar.Insertable(company).ExecuteReturnEntityAsync();
  3578. if (compnayInfo == null)
  3579. {
  3580. _sqlSugar.RollbackTran();
  3581. return Ok(JsonView(false, "公司信息添加失败!"));
  3582. }
  3583. }
  3584. if (infoVaild == null) //添加
  3585. {
  3586. info.CrmCompanyId = compnayInfo.Id;
  3587. EncryptionProcessor.EncryptProperties(info);
  3588. var insertId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  3589. if (insertId < 1)
  3590. {
  3591. _sqlSugar.RollbackTran();
  3592. return Ok(JsonView(false, "信息添加失败!"));
  3593. }
  3594. if (familys.Any())
  3595. {
  3596. foreach (var family in familys)
  3597. {
  3598. family.DcId = insertId;
  3599. }
  3600. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3601. if (familyInsert < 1)
  3602. {
  3603. _sqlSugar.RollbackTran();
  3604. return Ok(JsonView(false, "家庭信息添加失败!"));
  3605. }
  3606. }
  3607. if (schools.Any())
  3608. {
  3609. foreach (var school in schools)
  3610. {
  3611. school.DcId = insertId;
  3612. }
  3613. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3614. if (schoolInsert < 1)
  3615. {
  3616. _sqlSugar.RollbackTran();
  3617. return Ok(JsonView(false, "学校信息添加失败!"));
  3618. }
  3619. }
  3620. if (works.Any())
  3621. {
  3622. foreach (var work in works)
  3623. {
  3624. work.DcId = insertId;
  3625. }
  3626. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3627. if (workInsert < 1)
  3628. {
  3629. _sqlSugar.RollbackTran();
  3630. return Ok(JsonView(false, "工作信息添加失败!"));
  3631. }
  3632. }
  3633. }
  3634. //修改
  3635. else
  3636. {
  3637. int id = infoVaild?.Id ?? 0;
  3638. var updInfo = await _sqlSugar.Queryable<Crm_DeleClient>().FirstAsync(x => x.Id == id);
  3639. EncryptionProcessor.DecryptProperties(updInfo);
  3640. foreach (var prop in info.GetType().GetProperties())
  3641. {
  3642. var currentVal = prop.GetValue(updInfo);
  3643. var newValue = prop.GetValue(info);
  3644. // 检查当前值是否为 null 或空字符串
  3645. if (currentVal == null || (currentVal is string && string.IsNullOrEmpty((string)currentVal)))
  3646. {
  3647. // 如果新值不为 null 或空字符串,则更新
  3648. if (newValue != null && !(newValue is string && string.IsNullOrEmpty((string)newValue)))
  3649. {
  3650. prop.SetValue(updInfo, newValue);
  3651. }
  3652. }
  3653. }
  3654. EncryptionProcessor.EncryptProperties(updInfo);
  3655. var upd = await _sqlSugar.Updateable(updInfo).ExecuteCommandAsync();
  3656. if (upd < 1)
  3657. {
  3658. _sqlSugar.RollbackTran();
  3659. return Ok(JsonView(false, "个人信息更新失败!"));
  3660. }
  3661. int parentId = updInfo.Id;
  3662. if (familys.Any())
  3663. {
  3664. await _sqlSugar.Updateable<Crm_VisaCustomerFamily>()
  3665. .SetColumns(x => x.IsDel == 0)
  3666. .SetColumns(x => x.DeleteUserId == 4)
  3667. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3668. .Where(x => x.DcId == parentId)
  3669. .ExecuteCommandAsync();
  3670. foreach (var family in familys)
  3671. {
  3672. family.DcId = parentId;
  3673. }
  3674. var familyInsert = await _sqlSugar.Insertable(familys).ExecuteCommandAsync();
  3675. if (familyInsert < 1)
  3676. {
  3677. _sqlSugar.RollbackTran();
  3678. return Ok(JsonView(false, "家庭信息添加失败!"));
  3679. }
  3680. }
  3681. if (schools.Any())
  3682. {
  3683. await _sqlSugar.Updateable<Crm_VisaCustomerSchool>()
  3684. .SetColumns(x => x.IsDel == 0)
  3685. .SetColumns(x => x.DeleteUserId == 4)
  3686. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3687. .Where(x => x.DcId == parentId)
  3688. .ExecuteCommandAsync();
  3689. foreach (var school in schools)
  3690. {
  3691. school.DcId = parentId;
  3692. }
  3693. var schoolInsert = await _sqlSugar.Insertable(schools).ExecuteCommandAsync();
  3694. if (schoolInsert < 1)
  3695. {
  3696. _sqlSugar.RollbackTran();
  3697. return Ok(JsonView(false, "学校信息添加失败!"));
  3698. }
  3699. }
  3700. if (works.Any())
  3701. {
  3702. await _sqlSugar.Updateable<Crm_VisaCustomerCompany>()
  3703. .SetColumns(x => x.IsDel == 0)
  3704. .SetColumns(x => x.DeleteUserId == 4)
  3705. .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  3706. .Where(x => x.DcId == parentId)
  3707. .ExecuteCommandAsync();
  3708. foreach (var work in works)
  3709. {
  3710. work.DcId = parentId;
  3711. }
  3712. var workInsert = await _sqlSugar.Insertable(works).ExecuteCommandAsync();
  3713. if (workInsert < 1)
  3714. {
  3715. _sqlSugar.RollbackTran();
  3716. return Ok(JsonView(false, "工作信息添加失败!"));
  3717. }
  3718. }
  3719. }
  3720. }
  3721. catch (Exception ex)
  3722. {
  3723. _sqlSugar.RollbackTran();
  3724. return Ok(JsonView(false, ex.Message));
  3725. }
  3726. _sqlSugar.CommitTran();
  3727. #endregion
  3728. #endregion
  3729. return Ok(JsonView(true));
  3730. }
  3731. private static bool TryGetNonEmptyStringProperty(JsonElement root, string propertyName, out string value)
  3732. {
  3733. value = null;
  3734. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3735. {
  3736. string stringValue = propertyElement.GetString();
  3737. if (stringValue != null && stringValue != "null" && stringValue != "")
  3738. {
  3739. value = stringValue;
  3740. return true;
  3741. }
  3742. }
  3743. return false;
  3744. }
  3745. private static bool TryGetNonEmptyDateTimeProperty(JsonElement root, string propertyName, out DateTime? value)
  3746. {
  3747. value = null; // 初始化为null
  3748. if (root.TryGetProperty(propertyName, out JsonElement propertyElement))
  3749. {
  3750. string stringValue = propertyElement.GetString();
  3751. if (stringValue != null && stringValue != "null" && stringValue != "")
  3752. {
  3753. if (DateTime.TryParse(stringValue, out DateTime parsedValue))
  3754. {
  3755. value = parsedValue; // 将解析结果赋值给value
  3756. return true;
  3757. }
  3758. }
  3759. }
  3760. return false;
  3761. }
  3762. #region 扩展处理
  3763. // 从 Expression<Func<T,object>> 里取出属性名
  3764. static string GetPropName<T>(Expression<Func<T, object>> expr)
  3765. {
  3766. if (expr.Body is UnaryExpression ue) expr = Expression.Lambda<Func<T, object>>(ue.Operand, expr.Parameters);
  3767. return ((MemberExpression)expr.Body).Member.Name;
  3768. }
  3769. /// <summary>
  3770. /// 5.1.4.193 可用:存在更新(非NULL非空串),不存在插入,返回主键ID
  3771. /// </summary>
  3772. public int UpsertReturnId<T>(T entity, Expression<Func<T, object>> whereExpr) where T : class, new()
  3773. {
  3774. // 1. 空字符串→NULL,让后续忽略
  3775. foreach (var pi in typeof(T).GetProperties())
  3776. if (pi.PropertyType == typeof(string) &&
  3777. pi.GetValue(entity) is string s &&
  3778. string.IsNullOrWhiteSpace(s))
  3779. pi.SetValue(entity, null);
  3780. // 2. 从表达式里拿属性名
  3781. string propName = GetPropName(whereExpr);
  3782. var propValue = typeof(T).GetProperty(propName)?.GetValue(entity);
  3783. // 3. 判断存在
  3784. bool exists = _sqlSugar.Queryable<T>().Where(propName, propValue).Any();
  3785. // 4. 执行 Upsert
  3786. if (exists)
  3787. {
  3788. _sqlSugar.Updateable(entity)
  3789. .WhereColumns(propName) // 指定条件列
  3790. .IgnoreColumns(ignoreAllNullColumns: true) // 忽略 NULL
  3791. .ExecuteCommand();
  3792. }
  3793. else
  3794. {
  3795. _sqlSugar.Insertable(entity).ExecuteReturnIdentity();
  3796. }
  3797. // 5. 返回主键值(自增/雪花已回填)
  3798. var idProp = typeof(T).GetProperties()
  3799. .First(p => p.GetCustomAttributes<SugarColumn>()
  3800. .Any(a => a.IsPrimaryKey));
  3801. return (int)idProp.GetValue(entity)!;
  3802. }
  3803. /// <summary>
  3804. /// 地址喊邮编 相关处理
  3805. /// </summary>
  3806. public static (string address, string zipCode) SplitAddressZip(string? s)
  3807. {
  3808. if (string.IsNullOrWhiteSpace(s))
  3809. return ("", "");
  3810. ReadOnlySpan<char> src = s.AsSpan();
  3811. int i = src.IndexOf("邮编".AsSpan());
  3812. if (i < 0) // 没有“邮编”字样
  3813. return (src.Trim().ToString(), "");
  3814. ReadOnlySpan<char> addr = src[..i].TrimEnd();
  3815. ReadOnlySpan<char> zip = src[(i + 3)..].Trim(); // 跳过“邮编:”
  3816. // 可能只有“邮编:”而没有数字
  3817. return (addr.IsEmpty ? "" : addr.ToString(),
  3818. zip.IsEmpty ? "" : zip.ToString());
  3819. }
  3820. /// <summary>
  3821. /// 驾照相 关处理
  3822. /// </summary>
  3823. /// <param name="raw"></param>
  3824. /// <returns></returns>
  3825. public static (bool hasLicense, string number, string place) LicenseParser(string? raw)
  3826. {
  3827. if (string.IsNullOrWhiteSpace(raw))
  3828. return (false, "", "");
  3829. // 1. 是否持有
  3830. bool has = raw.StartsWith("是", System.StringComparison.OrdinalIgnoreCase) ||
  3831. raw.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3832. // 2. 去掉前缀,按空格切
  3833. ReadOnlySpan<char> s = raw.AsSpan();
  3834. int colon = s.IndexOf(':');
  3835. ReadOnlySpan<char> after = colon < 0 ? s : s[(colon + 1)..];
  3836. after = after.Trim();
  3837. int space = after.IndexOf(' ');
  3838. ReadOnlySpan<char> num = space < 0 ? after : after[..space];
  3839. ReadOnlySpan<char> st = space < 0 ? ReadOnlySpan<char>.Empty : after[(space + 1)..];
  3840. return (has, num.ToString().Trim(), st.ToString().Trim());
  3841. }
  3842. /// <summary>
  3843. /// 美国社会安全号或者纳税ID号 相关处理
  3844. /// </summary>
  3845. /// <param name="raw"></param>
  3846. /// <returns></returns>
  3847. public static (bool hasSsnItin, string number) SsnItinParser(string? raw)
  3848. {
  3849. if (string.IsNullOrWhiteSpace(raw))
  3850. return (false, "");
  3851. ReadOnlySpan<char> s = raw.AsSpan();
  3852. // 1. 是否持有
  3853. bool has = s.StartsWith("是", System.StringComparison.Ordinal) ||
  3854. s.StartsWith("Y", System.StringComparison.OrdinalIgnoreCase);
  3855. // 2. 取号码(去掉前缀和空格)
  3856. int colon = s.IndexOf(':');
  3857. ReadOnlySpan<char> num = colon < 0
  3858. ? ReadOnlySpan<char>.Empty
  3859. : s[(colon + 1)..].Trim();
  3860. return (has, num.ToString());
  3861. }
  3862. /// <summary>
  3863. /// 取消开始的“是:”或者“是”或者“ :”
  3864. /// </summary>
  3865. /// <param name="raw"></param>
  3866. /// <returns></returns>
  3867. public static string CleanPrefix(string? raw)
  3868. {
  3869. if (string.IsNullOrWhiteSpace(raw)) return "";
  3870. // 跳过第一个“是”或“Y”
  3871. ReadOnlySpan<char> s = raw.AsSpan();
  3872. int start = 0;
  3873. if (s.StartsWith("是") || s.StartsWith("Y", StringComparison.OrdinalIgnoreCase))
  3874. start = 1;
  3875. // 跳过连续 : 或空格
  3876. while (start < s.Length && (s[start] == ':' || s[start] == ' '))
  3877. start++;
  3878. return s[start..].Trim().ToString();
  3879. }
  3880. /// <summary>
  3881. /// 婚姻起止时间处理
  3882. /// </summary>
  3883. /// <param name="raw"></param>
  3884. /// <returns></returns>
  3885. public static (DateTime? fromDate, DateTime? toDate) WeddingParser(string? raw)
  3886. {
  3887. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3888. Regex _clean = new(@"[\s~至]+", RegexOptions.Compiled);
  3889. // 1. 把所有“空格~至”统一成 '-'
  3890. string normalized = _clean.Replace(raw, "-");
  3891. // 2. 切两段
  3892. string[] parts = normalized.Split('-', StringSplitOptions.RemoveEmptyEntries);
  3893. if (parts.Length != 2) return (null, null);
  3894. // 3. 解析
  3895. bool ff = DateTime.TryParse(parts[0].Trim(), out var from);
  3896. bool tf = DateTime.TryParse(parts[1].Trim(), out var to);
  3897. return (tf ? from : null, tf ? to : null);
  3898. }
  3899. /// <summary>
  3900. /// 出行日期和天数处理
  3901. /// </summary>
  3902. /// <param name="raw"></param>
  3903. /// <returns></returns>
  3904. public static (DateTime? travelDate, int? days) TravelParser(string? raw)
  3905. {
  3906. if (string.IsNullOrWhiteSpace(raw)) return (null, null);
  3907. // 切成两段:第一段日期,第二段天数
  3908. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3909. string[] parts = sep.Split(raw.Trim());
  3910. if (parts.Length < 2) return (null, null);
  3911. bool okDate = DateTime.TryParse(parts[0], out DateTime date);
  3912. bool okDays = int.TryParse(parts[1], out int days) && days > 0;
  3913. return (okDate ? date : null, okDays ? days : null);
  3914. }
  3915. /// <summary>
  3916. /// 是否曾抵达过美国
  3917. /// </summary>
  3918. /// <param name="raw"></param>
  3919. /// <returns></returns>
  3920. public static (bool hasTravel, string date, string days) TravelHadFlagParser(string? raw)
  3921. {
  3922. if (string.IsNullOrWhiteSpace(raw)) return (false, string.Empty, string.Empty);
  3923. Regex sep = new(@"[^0-9./-]+", RegexOptions.Compiled);
  3924. // 1. 是否持有
  3925. bool has = raw.AsSpan().TrimStart().StartsWith("是") ||
  3926. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3927. // 2. 用非数字分隔符切成三段:第一段空,第二段日期,第三段天数
  3928. string[] parts = sep.Split(raw.Trim());
  3929. if (parts.Length < 3) return (has, string.Empty, string.Empty);
  3930. return (has, parts[1], parts[2]);
  3931. }
  3932. /// <summary>
  3933. /// 是否有被美国拒发签证的经历
  3934. /// </summary>
  3935. /// <param name="raw"></param>
  3936. /// <returns></returns>
  3937. public static (bool wasDenied, DateTime? date, string place, string visaType) VisaDenialParser(string? raw)
  3938. {
  3939. if (string.IsNullOrWhiteSpace(raw)) return (false, null, "", "");
  3940. bool denied = raw.AsSpan().TrimStart().StartsWith("有") ||
  3941. raw.AsSpan().TrimStart().StartsWith("Y", StringComparison.OrdinalIgnoreCase);
  3942. var parts = Regex.Split(raw.Trim(), @"[^0-9A-Za-z-]+");
  3943. if (parts.Length < 4) return (denied, null, "", "");
  3944. DateTime.TryParse(parts[1], out var dt); // ← 这里改为 DateTime
  3945. return (denied, dt, parts[2], parts[3]);
  3946. }
  3947. /// <summary>
  3948. /// 在美直系、旁系 处理
  3949. /// </summary>
  3950. /// <param name="raw"></param>
  3951. /// <returns></returns>
  3952. public static (bool flag, string name, string rel, string stat) FourFieldParser(string? raw)
  3953. {
  3954. if (string.IsNullOrWhiteSpace(raw)) return (false, "", "", "");
  3955. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3956. if (parts.Length < 4) return (false, "", "", "");
  3957. bool flag = parts[0] is "有" or "是" or "Y" or "Yes";
  3958. string name = parts[1];
  3959. string rel = parts[2];
  3960. string stat = parts[3];
  3961. return (flag, name, rel, stat);
  3962. }
  3963. /// <summary>
  3964. /// 服役时间处理
  3965. /// </summary>
  3966. /// <param name="raw"></param>
  3967. /// <returns></returns>
  3968. public static (bool hasService, string branch, string rank, string specialty, (DateTime? start, DateTime? end) period) MilitaryParser(string? raw)
  3969. {
  3970. const string fmt = "yyyy年MM月dd日";
  3971. if (string.IsNullOrWhiteSpace(raw))
  3972. return (false, "", "", "", (null, null));
  3973. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  3974. if (parts.Length < 5) return (false, "", "", "", (null, null));
  3975. bool has = parts[0] is "是" or "Y" or "Yes";
  3976. string branch = parts[1];
  3977. string rank = parts[2];
  3978. string specialty = parts[3];
  3979. // 拼回时间字符串
  3980. string periodRaw = string.Join(" ", parts[4..]);
  3981. var span = periodRaw.AsSpan();
  3982. int zhi = span.IndexOf("至");
  3983. if (zhi < 0) return (has, branch, rank, specialty, (null, null));
  3984. var startStr = span.Slice(0, zhi).Trim();
  3985. var endStr = span.Slice(zhi + 1).Trim();
  3986. bool okStart = DateTime.TryParseExact(startStr.ToString(), fmt, null, DateTimeStyles.None, out var start);
  3987. bool okEnd = DateTime.TryParseExact(endStr.ToString(), fmt, null, DateTimeStyles.None, out var end);
  3988. return (has, branch, rank, specialty, (okStart ? start : null, okEnd ? end : null));
  3989. }
  3990. /// <summary>
  3991. /// 申请人父母信息
  3992. /// </summary>
  3993. /// <param name="raw"></param>
  3994. /// <returns></returns>
  3995. public static (string fatherName, DateTime? fatherDob, string motherName, DateTime? motherDob) ParentParser(string? raw)
  3996. {
  3997. const string fmt = "yyyy年MM月dd日";
  3998. if (string.IsNullOrWhiteSpace(raw)) return ("", null, "", null);
  3999. // 按空格切,去掉空元素
  4000. var parts = raw.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
  4001. if (parts.Length < 4) return ("", null, "", null);
  4002. // 父亲
  4003. string fName = parts[0];
  4004. DateTime.TryParseExact(parts[1], fmt, null, DateTimeStyles.None, out var fDob);
  4005. // 母亲
  4006. string mName = parts[2];
  4007. DateTime.TryParseExact(parts[3], fmt, null, DateTimeStyles.None, out var mDob);
  4008. return (fName, fDob, mName, mDob);
  4009. }
  4010. public class VisaDetailsView
  4011. {
  4012. /// <summary>
  4013. /// 客户资料表
  4014. /// </summary>
  4015. public Crm_DeleClient ClientInfo { get; set; }
  4016. /// <summary>
  4017. /// 客户家庭表
  4018. /// </summary>
  4019. public List<Crm_VisaCustomerFamily> ClientFamilys { get; set; }
  4020. /// <summary>
  4021. /// 客户公司表
  4022. /// </summary>
  4023. public Crm_CustomerCompany ClientCompany { get; set; }
  4024. /// <summary>
  4025. /// 客户证件表
  4026. /// </summary>
  4027. public List<Crm_CustomerCert> ClientCerts { get; set; }
  4028. /// <summary>
  4029. /// 客户学历表
  4030. /// </summary>
  4031. public List<Crm_VisaCustomerSchool> ClientSchools { get; set; }
  4032. }
  4033. private int GetSuccessCount(List<FileUploadResult> results)
  4034. {
  4035. var count = 0;
  4036. foreach (var result in results)
  4037. {
  4038. if (result.Success) count++;
  4039. }
  4040. return count;
  4041. }
  4042. #endregion
  4043. #region 文件下载
  4044. /// <summary>
  4045. /// 签证下载类型初始化
  4046. /// </summary>
  4047. private readonly static Dictionary<int, string> _visaTypeInit = new()
  4048. {
  4049. { 1, "美国" },
  4050. { 2, "日本" },
  4051. { 3, "韩国" },
  4052. { 4, "瑞典" },
  4053. { 5, "波兰" },
  4054. };
  4055. /// <summary>
  4056. /// 申根国
  4057. /// </summary>
  4058. private readonly static string[] _shenGenGuos = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "冰岛", "意大利", "希腊", "卢森堡", "荷兰", "挪威", "葡萄牙", "西班牙",
  4059. "瑞典", "匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4060. /// <summary>
  4061. /// 欧盟国家
  4062. /// </summary>
  4063. private readonly static string[] _eucountries = new string[] { "奥地利", "比利时", "丹麦", "芬兰", "法国", "德国", "意大利", "希腊", "卢森堡", "荷兰", "葡萄牙", "西班牙","爱尔兰","罗马尼亚",
  4064. "保加利亚","匈牙利", "捷克", "斯洛伐克", "斯洛文尼亚","波兰","爱沙尼亚","拉脱维亚","立陶宛","马耳他","瑞士","列支敦士登" };
  4065. /// <summary>
  4066. /// 欧洲国家
  4067. /// </summary>
  4068. private readonly static string[] _aBC = new string[] { "英国", "爱尔兰" };
  4069. /// <summary>
  4070. /// 团组&签证 New
  4071. /// 签证文申请表下载
  4072. /// </summary>
  4073. /// <param name="groupId">
  4074. /// <param name="fileTypeId">
  4075. /// </param>
  4076. /// <returns></returns>
  4077. [HttpGet]
  4078. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4079. public async Task<IActionResult> VisaFileDownload(int groupId, int fileTypeId)
  4080. {
  4081. if (!_visaTypeInit.TryGetValue(fileTypeId, out _))
  4082. {
  4083. return Ok(JsonView(false, "请选择正确的文件类型!"));
  4084. }
  4085. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == groupId).First();
  4086. if (groupInfo == null)
  4087. {
  4088. return Ok(JsonView(false, "团组信息不存在!"));
  4089. }
  4090. //访问路径
  4091. var serverPath = $"http://132.232.92.186:24/Office/Word/VisaClientData/Downloads/{groupInfo.TeamName}/";
  4092. //模板存储位置
  4093. var tempPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Template/";
  4094. //服务器存储文件位置
  4095. var fileServerPath = $"D:/FTP/File/OA2023/Office/Word/VisaClientData/Downloads/{groupInfo.TeamName}/";
  4096. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(fileServerPath);
  4097. //文件生成路径
  4098. string url = string.Empty;
  4099. //基础数据
  4100. //团组客户名单
  4101. var groupClients = await _sqlSugar.Queryable<Grp_TourClientList>()
  4102. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4103. .Select(x => x.ClientId)
  4104. .ToListAsync();
  4105. if (groupClients.Count < 1)
  4106. {
  4107. return Ok(JsonView(false, "该团组下暂无团组名单!"));
  4108. }
  4109. //团组客户详细信息
  4110. var groupCustInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && groupClients.Contains(x.Id)).ToList();
  4111. //家庭成员资料
  4112. var familyInfos = _sqlSugar.Queryable<Crm_VisaCustomerFamily>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4113. //公司资料
  4114. var companyInfo‌‌s = _sqlSugar.Queryable<Crm_VisaCustomerCompany>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4115. //学校资料
  4116. var schoolInfos = _sqlSugar.Queryable<Crm_VisaCustomerSchool>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4117. /* 证件类型
  4118. *
  4119. * 773 身份证
  4120. * 774 护照
  4121. * 775 学生证
  4122. * 776 军人证
  4123. * 777 回乡证
  4124. * 778 台胞证
  4125. * 779 港澳通行证
  4126. * 780 国际海员证
  4127. * 781 外国人永久居留证
  4128. * 782 旅行证
  4129. * 783 台湾通行证
  4130. * 784 港澳台居住证
  4131. * 785 其他
  4132. */
  4133. //证件资料
  4134. var certInfos = _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && groupClients.Contains(x.DcId)).ToList();
  4135. //利用字典创建书签与书签的值的键值对,第一个string为键,第二个string为值
  4136. var applyDate = DateTime.Now.ToString("yyyy-MM-dd");
  4137. var filePaths = new List<string>();
  4138. var visaTypeName = string.Empty;
  4139. var currTempPath = string.Empty;
  4140. switch (fileTypeId)
  4141. {
  4142. case 1: // 美国
  4143. visaTypeName = $"美国签证申请表";
  4144. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4145. var usaSavePath = $"{fileServerPath}{visaTypeName}/";
  4146. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(usaSavePath);
  4147. foreach (var custInfo in groupCustInfos)
  4148. {
  4149. //解密
  4150. EncryptionProcessor.DecryptProperties(custInfo);
  4151. Dictionary<string, string> dics = new();
  4152. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4153. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4154. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4155. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4156. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4157. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4158. #region 美国签证模板书签值处理
  4159. dics.Add("LastNameEn", custInfo?.LastName ?? "");//名拼音
  4160. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//姓拼音
  4161. dics.Add("LastName", custInfo?.LastName ?? "");//名
  4162. dics.Add("FirstName", custInfo?.FirstName ?? "");//姓
  4163. dics.Add("OldNameEn", custInfo?.OldName ?? "");//曾用姓名拼音
  4164. dics.Add("OldName", custInfo?.FirstName ?? "");//曾用姓名
  4165. //未设置、未婚、已婚、离异、丧偶
  4166. var marriage = custInfo.Marriage switch
  4167. {
  4168. 0 => "未设置",
  4169. 1 => "未婚",
  4170. 2 => "已婚",
  4171. 3 => "离异",
  4172. 4 => "丧偶",
  4173. _ => "未知"
  4174. };
  4175. dics.Add("Marriage", marriage);//婚姻状况
  4176. dics.Add("Phone", custInfo?.Phone ?? "");//家庭电话
  4177. dics.Add("BirthCity", custInfo?.BirthCity ?? "");//出生城市
  4178. dics.Add("BirthProvince", custInfo?.BirthProvince ?? "");//出生省份
  4179. string m_idCard = idInfo?.CertNo ?? "";
  4180. string m_birthday = string.Empty;
  4181. if (!string.IsNullOrEmpty(m_idCard))
  4182. {
  4183. string m_year = m_idCard.Substring(6, 4);
  4184. string m_month = m_idCard.Substring(10, 2);
  4185. string m_day = m_idCard.Substring(12, 2);
  4186. m_birthday = m_year + "." + m_month + "." + m_day;
  4187. }
  4188. dics.Add("BirthDay", m_birthday);//出生日期
  4189. dics.Add("Tel", custInfo?.Tel ?? "");//移动电话
  4190. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4191. dics.Add("IdCard", m_idCard);//身份证号码
  4192. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4193. dics.Add("PostCodes", custInfo?.PostCodes ?? "");//邮编
  4194. dics.Add("Client", clinetInfo?.Company ?? "");//单位名称
  4195. dics.Add("ClientAddress", clinetInfo?.CompanyAddress ?? "");//单位地址
  4196. dics.Add("ClientPostCodes", custInfo?.PostCodes ?? "");//单位邮编
  4197. dics.Add("Job", custInfo?.Job ?? "");//职务
  4198. dics.Add("WorkDate", custInfo?.WorkDate ?? "");//入职时间
  4199. dics.Add("Wage", custInfo?.Wage ?? "");//月薪
  4200. dics.Add("ClientPhone", custInfo?.ClientPhone ?? "");//单位电话
  4201. dics.Add("ClientFax", custInfo?.ClientFax ?? "");//单位传真
  4202. dics.Add("ClientEmail", custInfo?.ClientEmail ?? "");//单位邮箱
  4203. dics.Add("ClientLeader", custInfo?.ClientLeader ?? "");//单位主管姓名
  4204. dics.Add("ClientLeaderJob", custInfo?.ClientLeaderJob ?? "");//单位主管职务
  4205. dics.Add("WorkState", custInfo?.WorkState ?? "");//工作内容简单介绍
  4206. dics.Add("IsGetSchengen", custInfo?.IsGetSchengen == 0 ? "否" : "是");//是否有获批的申根签证
  4207. dics.Add("StartTime", custInfo?.StartTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期开始
  4208. dics.Add("EndTime", custInfo?.EndTime.ToString("yyyy-MM-dd") ?? "");//申根签证有效期结束
  4209. dics.Add("IsFinger", custInfo.IsFinger == 0 ? "否" : "是");//申根签证是否有指纹记录
  4210. dics.Add("FingerDate", custInfo?.FingerDate?.ToString("yyyy-MM-dd") ?? "");//申根签指纹采集时间
  4211. dics.Add("TableOpName", custInfo?.TableOpName ?? "");//填表经办人
  4212. dics.Add("TableOpTel", custInfo?.TableOpTel ?? "");//填表经办人联系电话
  4213. dics.Add("TableDate", custInfo?.TableDate.ToString("yyyy-MM-dd") ?? "");//填表日期
  4214. dics.Add("Party", custInfo?.Party ?? "");//所属党派或宗教
  4215. dics.Add("Nationality", custInfo?.Nationality ?? "");//国籍
  4216. var sex = custInfo.Sex switch
  4217. {
  4218. 0 => "男",
  4219. 1 => "女",
  4220. _ => "未知"
  4221. };
  4222. dics.Add("Sex", sex);//性别
  4223. dics.Add("WeddingDate", custInfo?.WeddingDate?.ToString("yyyy-MM-dd") ?? "");//结婚日期
  4224. dics.Add("DivorceDate", custInfo?.DivorceDate?.ToString("yyyy-MM-dd") ?? "");//离婚日期
  4225. dics.Add("MateName", custInfo?.MateName ?? "");//配偶姓名
  4226. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd") ?? "");//配偶出生日期
  4227. dics.Add("MateBirthCity", custInfo?.MateBirthCity ?? "");//配偶出生城市
  4228. dics.Add("MateBirthCountry", custInfo?.MateBirthCountry ?? "");//配偶出生省份
  4229. dics.Add("MateAddress", custInfo?.MateAddress ?? "");//配偶住址
  4230. dics.Add("MateClient", custInfo?.MateClient ?? "");//配偶工作单位名称
  4231. dics.Add("MateClientAddress", custInfo?.MateClientAddress ?? "");//配偶工作单位地址
  4232. dics.Add("MateJob", custInfo?.MateJob ?? "");//配偶职务
  4233. dics.Add("VisitCountry", custInfo?.VisitCountry ?? "");//因公出访的国家
  4234. dics.Add("Paper", custInfo?.Paper ?? "");//发表的期刊、论文
  4235. dics.Add("Papent", custInfo?.Papent ?? "");//专利
  4236. dics.Add("PhD", custInfo?.PhD ?? "");//博士论文
  4237. dics.Add("IsVisitUC", custInfo?.IsVisitUC == 0 ? "否" : "是" ?? "");//是否因公去过美国/加拿大
  4238. dics.Add("USADate", custInfo?.USADate?.ToString("yyyy-MM-dd") ?? "");//美国抵达日期
  4239. dics.Add("USADays", custInfo?.USADays.ToString() ?? "");//美国停留天数
  4240. dics.Add("CanDate", custInfo?.CanDate.ToString("yyyy-MM-dd") ?? "");//加拿大抵达日期
  4241. dics.Add("CanDays", custInfo?.CanDays.ToString() ?? "");//加拿大停留天数
  4242. dics.Add("IsUSAVia", custInfo?.IsUSAVia == 0 ? "否" : "是" ?? "");//是否获得过因公美国签证
  4243. dics.Add("GetUSAVisaDate", custInfo?.GetUSAVisaDate?.ToString("yyyy-MM-dd") ?? "");//因公美国签证时间
  4244. dics.Add("GetUPPlace", custInfo?.GetUPPlace ?? "");//因公美国签证地点
  4245. dics.Add("USAVisaCate", custInfo?.USAVisaCate ?? "");//因公美国签证种类
  4246. dics.Add("USAVisaCode", custInfo?.USAVisaCode ?? "");//因公美国签证编码
  4247. dics.Add("USAFinger", custInfo?.USAFinger == 0 ? "否" : "是" ?? "");//是否在使馆留过十指的指纹
  4248. dics.Add("IsRejected", custInfo?.IsRejected == 0 ? "否" : "是" ?? "");//是否被拒
  4249. dics.Add("RejectedDate", custInfo?.RejectedDate?.ToString("yyyy-MM-dd") ?? "");//被拒时间
  4250. dics.Add("RejectedPlace", custInfo?.RejectedPlace ?? "");//被拒地点
  4251. dics.Add("RejectedVisa", custInfo?.RejectedVisa ?? "");//被拒签证种类
  4252. dics.Add("IsRevoke", custInfo?.IsRevoke == 0 ? "否" : "是" ?? "");//美国签证是否被吊销
  4253. dics.Add("IsLose", custInfo?.IsLose == 0 ? "否" : "是" ?? "");//护照是否丢失
  4254. dics.Add("LoseDate", custInfo?.LoseDate.ToString("yyyy-MM-dd") ?? "");//丢失的护照时间
  4255. dics.Add("LoseCode", custInfo?.LoseCode ?? "");//丢失的护照号码
  4256. dics.Add("IsUSAVisa", custInfo?.IsUSAVisa == 0 ? "否" : "是" ?? "");//丢失的护照是否有美国签证
  4257. dics.Add("MateUSA", custInfo?.MateUSA == 0 ? "否" : "是" ?? "");//夫/妻是否已在美国
  4258. dics.Add("MateIden", custInfo?.MateIden ?? "");//夫/妻身份
  4259. dics.Add("WHUSA", custInfo?.WHUSA == 0 ? "否" : "是" ?? "");//未婚夫/妻是否已在美国
  4260. dics.Add("WHIden", custInfo?.WHIden ?? "");//未婚夫/妻身份
  4261. dics.Add("ParentUSA", custInfo?.ParentUSA == 0 ? "否" : "是" ?? "");//父/母是否已在美国
  4262. dics.Add("ParentIden", custInfo?.ParentIden ?? "");//父/母身份
  4263. dics.Add("ChildUSA", custInfo?.ChildUSA == 0 ? "否" : "是" ?? "");//儿子/女儿是否已在美国
  4264. dics.Add("ChildIden", custInfo?.ChildIden ?? "");//儿子/女儿身份
  4265. dics.Add("BroUSA", custInfo?.BroUSA == 0 ? "否" : "是" ?? "");//兄弟/姐妹是否已在美国
  4266. dics.Add("BroIden", custInfo?.BroIden ?? "");//兄弟/姐妹身份
  4267. dics.Add("Social", custInfo?.Social ?? "");//所属/捐助/工作过的职业协会、社会团体和慈善机构
  4268. dics.Add("IsArmy", custInfo?.IsArmy == 0 ? "否" : "是" ?? "");//是否参军
  4269. dics.Add("ArmyState", custInfo?.ArmyState ?? "");//参军详情
  4270. dics.Add("ApplyDate", applyDate);//申请日期
  4271. //公司信息书签
  4272. if (currCompanyInfos.Count > 0)
  4273. {
  4274. for (int i = 0; i < currCompanyInfos.Count; i++)
  4275. {
  4276. var compnayInfo = currCompanyInfos[i];
  4277. if (!string.IsNullOrEmpty(compnayInfo.Company))
  4278. {
  4279. dics.Add("Company", compnayInfo?.Company ?? "");//公司名称
  4280. dics.Add("CompanyAddress", compnayInfo?.CompanyAddress ?? "");//公司地址
  4281. dics.Add("CompanyPhone", compnayInfo?.Phone ?? "");//公司电话
  4282. dics.Add("CompanyJob", compnayInfo?.Job ?? "");//职务
  4283. dics.Add("CompanyLeaderName", compnayInfo?.LeaderName ?? "");//主管名字
  4284. dics.Add("CompanyWorkStart", compnayInfo?.WorkStart?.ToString("yyyy-MM-dd") ?? "");//雇佣起始年月日
  4285. dics.Add("CompanyWorkEnd", compnayInfo?.WorkEnd?.ToString("yyyy-MM-dd") ?? "");//雇佣结束年月日
  4286. dics.Add("CompanyWorkState", compnayInfo?.WorkState ?? "");//工作职责及内容简述
  4287. }
  4288. else break;
  4289. }
  4290. }
  4291. //学校信息书签
  4292. if (currSchoolInfos.Count > 0)
  4293. {
  4294. for (int i = 0; i < currSchoolInfos.Count; i++)
  4295. {
  4296. var schoolInfo = currSchoolInfos[i];
  4297. if (!string.IsNullOrEmpty(schoolInfo.School))
  4298. {
  4299. dics.Add("School", schoolInfo?.School ?? "");//学校名称和学历
  4300. dics.Add("SchoolAddress", schoolInfo?.Address ?? "");//学校地址
  4301. dics.Add("SchoolTeacher", schoolInfo?.Teacher ?? "");//指导老师
  4302. dics.Add("SchoolSubject", schoolInfo?.Subject ?? "");//所学课程或专业名称
  4303. dics.Add("SchoolStudyStart", schoolInfo?.StudyStart?.ToString("yyyy-MM-dd") ?? "");//就读起始日
  4304. dics.Add("SchoolStudyEnd", schoolInfo?.StudyEnd?.ToString("yyyy-MM-dd") ?? "");//就读结束日
  4305. }
  4306. else break;
  4307. }
  4308. }
  4309. //家人信息书签
  4310. if (currFamilyInfos.Count > 0)
  4311. {
  4312. for (int i = 0; i < currFamilyInfos.Count; i++)
  4313. {
  4314. var familyInfo = currFamilyInfos[i];
  4315. if (!string.IsNullOrEmpty(familyInfo.Appellation))
  4316. {
  4317. dics.Add("FamilyAppellation", familyInfo?.Appellation ?? "");//家庭成员称谓
  4318. dics.Add("FamilyName", familyInfo?.Name ?? "");//家庭成员姓名
  4319. dics.Add("FamilyBirthDay", familyInfo?.BirthDay?.ToString("yyyy-MM-dd") ?? "");//家庭成员出生日期
  4320. dics.Add("FamilyBirthPlace", familyInfo?.BirthPlace ?? "");// 家庭成员出生地
  4321. dics.Add("FamilyPolitics", familyInfo?.Politics ?? "");//家庭成员政治面貌
  4322. dics.Add("FamilyClient", familyInfo?.Client ?? "");//家庭成员工作单位
  4323. dics.Add("FamilyAddress", familyInfo?.Address ?? "");// 家庭地址
  4324. dics.Add("IsEu", familyInfo?.IsEu == 0 ? "No" : "Yes" ?? "");// 欧盟公民
  4325. dics.Add("FamilyNameSnd", familyInfo?.NameSnd ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员姓名
  4326. dics.Add("FamilyBirthDaySnd", familyInfo?.BirthDaySnd.ToString("yyyy-MM-dd") ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员生日
  4327. dics.Add("FamilyNationality", familyInfo?.Nationality ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员国籍
  4328. dics.Add("FamilyIDCard", familyInfo?.IDCard ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员旅行证件编号或身份证号码
  4329. dics.Add("FamilyReletionship", familyInfo?.Reletionship ?? "");//拥有欧盟、欧洲经济区或瑞士公民身份的家庭成员与申请人的关系
  4330. dics.Add("IsUSA", familyInfo?.IsUSA == 1 ? "是" : "否" ?? "");// 家庭成员是否在美国
  4331. }
  4332. else break;
  4333. }
  4334. }
  4335. #endregion
  4336. #region 生成文件
  4337. try
  4338. {
  4339. _logger.LogInformation("模板位置:{currTempPath}", currTempPath);
  4340. Document doc = new(currTempPath);
  4341. Aspose.Words.DocumentBuilder builder = new(doc);
  4342. string strTemp = "";
  4343. //循环键值对
  4344. foreach (var key in dics.Keys)
  4345. {
  4346. //将光标移入书签的位置
  4347. builder.MoveToBookmark(key);
  4348. //判断书签值是否为空
  4349. if (!string.IsNullOrEmpty(dics[key]))
  4350. {
  4351. strTemp = dics[key];
  4352. }
  4353. else strTemp = "";
  4354. //填充书签
  4355. builder.Write(strTemp.Replace("\\N", "\n"));
  4356. }
  4357. var custName = custInfo.LastName + custInfo.FirstName;
  4358. string fileName = $"{custName}_{visaTypeName}.doc";
  4359. var currFilePath = $"{usaSavePath}{fileName}";
  4360. doc.Save(currFilePath);
  4361. filePaths.Add(currFilePath);
  4362. }
  4363. catch (Exception ex)
  4364. {
  4365. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4366. }
  4367. #endregion
  4368. }
  4369. break;
  4370. case 2: // 日本
  4371. visaTypeName = $"新办日本申请表";
  4372. currTempPath = $"{tempPath}/{visaTypeName}.pdf";
  4373. var jpnSavePath = $"{fileServerPath}/{visaTypeName}/";
  4374. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(jpnSavePath);
  4375. foreach (var custInfo in groupCustInfos)
  4376. {
  4377. EncryptionProcessor.DecryptProperties(custInfo);
  4378. Dictionary<string, string> dics = new();
  4379. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4380. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4381. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4382. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4383. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4384. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4385. #region 生成文件
  4386. PdfReader reader = null;
  4387. FileStream templateStream = null;
  4388. FileStream outputStream = null;
  4389. PdfStamper stamper = null;
  4390. try
  4391. {
  4392. string outputPath = $"{jpnSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4393. //读取模板文件
  4394. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4395. reader = new PdfReader(templateStream);
  4396. //创建输出文件
  4397. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4398. stamper = new PdfStamper(reader, outputStream);
  4399. AcroFields formFields = stamper.AcroFields;
  4400. #region 设置文本值
  4401. SetFieldValue(formFields, "surname_en", CommonFun.ConvertToPinyin(custInfo?.LastName?.Trim() ?? "")?.ToLower() ?? ""); // 姓 英文
  4402. SetFieldValue(formFields, "name_en", CommonFun.ConvertToPinyin(custInfo?.FirstName?.Trim() ?? "")?.ToLower() ?? ""); // 名 英文
  4403. SetFieldValue(formFields, "surname_cn", custInfo?.LastName ?? ""); // 姓 中文
  4404. SetFieldValue(formFields, "name_cn", custInfo?.FirstName ?? ""); // 名 中文
  4405. if (!string.IsNullOrEmpty(custInfo.OldName))
  4406. {
  4407. SetFieldValue(formFields, "formername_en", CommonFun.ConvertToPinyin(custInfo?.OldName?.Trim() ?? "")?.ToLower() ?? ""); // 出生时姓氏
  4408. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4409. }
  4410. else
  4411. {
  4412. SetFieldValue(formFields, "formername_cn", custInfo.OldName); // 出生时姓氏
  4413. }
  4414. // 出生日期(日-月-年)
  4415. string idCard = idInfo?.CertNo?.Trim() ?? "";
  4416. string birthday = string.Empty;
  4417. if (!string.IsNullOrEmpty(idCard))
  4418. {
  4419. string year = idCard.Substring(6, 4);
  4420. string month = idCard.Substring(10, 2);
  4421. string day = idCard.Substring(12, 2);
  4422. birthday = day + "-" + month + "-" + year;
  4423. }
  4424. SetFieldValue(formFields, "birthday", birthday);
  4425. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  4426. SetFieldValue(formFields, "birthplace", currentNationality); // 出生地
  4427. SetFieldValue(formFields, "nationality", "中国"); // 出生国
  4428. SetFieldValue(formFields, "previous_nationality", "中国"); // 现国籍
  4429. SetFieldValue(formFields, "IdNo", idCard); // 身份证号码
  4430. #region 性别处理
  4431. //清除性别
  4432. SetFieldValue(formFields, "sex_man", "Off"); // 性别 - 男
  4433. SetFieldValue(formFields, "sex_woman", "Off"); // 性别 - 女
  4434. //设置性别
  4435. if (custInfo.Sex == 0) //男
  4436. {
  4437. SetFieldValue(formFields, "sex_man", "Yes"); // 性别 - 男
  4438. }
  4439. else if (custInfo.Sex == 1) //女
  4440. {
  4441. SetFieldValue(formFields, "sex_woman", "Yes"); // 性别 - 女
  4442. }
  4443. #endregion
  4444. #region 婚姻状况处理
  4445. //清除婚姻状况
  4446. SetFieldValue(formFields, "marriage_single", "Off"); // 婚姻状况 - 未婚
  4447. SetFieldValue(formFields, "marriage_married", "Off"); // 婚姻状况 - 已婚
  4448. SetFieldValue(formFields, "marriage_divorce", "Off"); // 婚姻状况 - 离婚
  4449. SetFieldValue(formFields, "marriage_widowedw", "Off"); // 婚姻状况 - 丧偶
  4450. //设置婚姻状况
  4451. switch (custInfo.Marriage)
  4452. {
  4453. case 1: // 未婚
  4454. SetFieldValue(formFields, "marriage_single", "Yes");
  4455. break;
  4456. case 2: // 已婚
  4457. SetFieldValue(formFields, "marriage_married", "Yes");
  4458. break;
  4459. case 3: // 离异
  4460. SetFieldValue(formFields, "marriage_divorce", "Yes");
  4461. break;
  4462. case 4: // 离异
  4463. SetFieldValue(formFields, "marriage_widowedw", "Yes");
  4464. break;
  4465. }
  4466. #endregion
  4467. #region 护照(旅行证件类型)
  4468. //清除值
  4469. SetFieldValue(formFields, "passport_diplomacy", "Off"); // 旅行证件类型 - 外交护照
  4470. SetFieldValue(formFields, "passport_official", "Off"); // 旅行证件类型 - 公务护照
  4471. SetFieldValue(formFields, "passport_ordinary", "Off"); // 旅行证件类型 - 普通护照
  4472. SetFieldValue(formFields, "passport_other", "Off"); // 旅行证件类型 - 其它
  4473. //设置值
  4474. if (passportInfo != null)
  4475. {
  4476. // 签证类型
  4477. var visatypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.Id == passportInfo.PassportType);
  4478. if (visatypeInfo != null)
  4479. {
  4480. string visaName = visatypeInfo?.Name ?? "-";
  4481. if (visaName.contains("外交")) SetFieldValue(formFields, "passport_diplomacy", "Yes"); // 旅行证件类型 - 外交护照
  4482. else if (visaName.contains("公务")) SetFieldValue(formFields, "passport_official", "Yes"); // 旅行证件类型 - 公务护照
  4483. else if (visaName.contains("普通")) SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4484. else if (visaName.contains("其它")) SetFieldValue(formFields, "passport_other", "Yes"); // 旅行证件类型 - 其它
  4485. else SetFieldValue(formFields, "passport_ordinary", "Yes"); // 旅行证件类型 - 普通护照
  4486. }
  4487. SetFieldValue(formFields, "passport_no", passportInfo.CertNo); // 签证编号
  4488. SetFieldValue(formFields, "passport_issuplice", passportInfo.Country + passportInfo.Area); // 签发 国、地区
  4489. SetFieldValue(formFields, "passport_issuauthority", ""); // 签发机关
  4490. SetFieldValue(formFields, "passport_issudate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); // 签发日期
  4491. SetFieldValue(formFields, "passport_validdate", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 有效期至
  4492. }
  4493. #endregion
  4494. SetFieldValue(formFields, "certification_number", ""); // 再留资格认证证书编号
  4495. SetFieldValue(formFields, "residentialstatus_purposetojapan", groupInfo?.VisitPurpose ?? ""); // 居住身份、赴日目的
  4496. // 签证国家下的城市
  4497. string city = "";
  4498. string county = "";
  4499. #region 入境信息
  4500. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4501. if (atbc != null)
  4502. {
  4503. string startTime = string.Empty; // 开始停留时间
  4504. string endTime = string.Empty; // 离开时间
  4505. string three = string.Empty; // 航司
  4506. string threeCode = string.Empty; // 入境口岸
  4507. for (int i = 0; i < atbc.Rows.Count; i++)
  4508. {
  4509. if (i == 0) //得到抵达日期
  4510. {
  4511. three = atbc.Rows[i]["Fliagtcode"].ToString();
  4512. startTime = atbc.Rows[i]["Day"].ToString();
  4513. threeCode = atbc.Rows[i]["Three"].ToString();
  4514. continue;
  4515. }
  4516. if (i == 1)
  4517. endTime = atbc.Rows[i]["Day"].ToString();
  4518. }
  4519. dics.Add("japandate_stay", startTime); // 预计逗留日期 起
  4520. dics.Add("japandate_end", endTime); // 预计逗留日期 止
  4521. dics.Add("japanduring", startTime); // 预计逗留期间
  4522. if (!string.IsNullOrEmpty(three))
  4523. {
  4524. //查询航司名称
  4525. var threeCodeTwo = three.Substring(0, 2);
  4526. var ac = _sqlSugar.Queryable<Res_AirCompany>().Where(x => x.ShortCode == threeCodeTwo).First();
  4527. if (ac != null)
  4528. {
  4529. dics.Add("shiporairlinename", $"{ac?.EnName ?? ""} {three}"); // 航司名称
  4530. }
  4531. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  4532. if (tc != null)
  4533. {
  4534. county = tc.Country;
  4535. city = tc.City;
  4536. dics.Add("portentry", tc?.City ?? ""); // 入境口岸
  4537. }
  4538. }
  4539. }
  4540. #endregion
  4541. #region 申请人酒店信息
  4542. if (!string.IsNullOrEmpty(city))
  4543. {
  4544. //得到当前国家下的城市酒店信息
  4545. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4546. .Where(x => x.DiId == groupId)
  4547. .Where(x => x.City.contains(city))
  4548. .First();
  4549. //酒店住址
  4550. if (hotelInfo != null)
  4551. {
  4552. dics.Add("hotelorfriend_name", hotelInfo?.HotelName ?? ""); // 酒店名称
  4553. dics.Add("hotelorfriend_tel", hotelInfo?.HotelAddress ?? ""); // 酒店地址
  4554. dics.Add("hotelorfriend_address", hotelInfo?.HotelTel ?? ""); // 酒店电话
  4555. }
  4556. }
  4557. #endregion
  4558. SetFieldValue(formFields, "japanduring_lasttime", ""); // 上次赴日日期及停留时间
  4559. #region 家庭信息
  4560. SetFieldValue(formFields, "family_address", custInfo.Address); // 地址
  4561. SetFieldValue(formFields, "family_tel", custInfo.Tel); // 电话
  4562. SetFieldValue(formFields, "family_phone", custInfo.Phone); // 手机
  4563. SetFieldValue(formFields, "family_email", custInfo.Email); // 电子邮件
  4564. #endregion
  4565. #region 工作单位信息
  4566. SetFieldValue(formFields, "company_name", companyInfos?.FirstOrDefault()?.Company ?? ""); // 名称
  4567. SetFieldValue(formFields, "company_tel", companyInfos?.FirstOrDefault()?.Phone ?? ""); // 电话
  4568. SetFieldValue(formFields, "family_address", companyInfos?.FirstOrDefault()?.CompanyAddress ?? "");// 地址
  4569. SetFieldValue(formFields, "company_job", custInfo?.Job ?? ""); // 职位
  4570. #endregion
  4571. SetFieldValue(formFields, "spouseorparents_job", custInfo?.MateJob ?? ""); // 配偶职业(如果是未成年人请填写服务的职业)
  4572. #region 担保人、邀请人 信息
  4573. if (!string.IsNullOrEmpty(county) && !string.IsNullOrEmpty(city))
  4574. {
  4575. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4576. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4577. .Where(x => x.Country.Contains(county))
  4578. .Where(x => x.Area.Contains(city))
  4579. .First();
  4580. //邀请 接待单位
  4581. if (oa != null)
  4582. {
  4583. dics.Add("guarantor_name_en", CommonFun.ConvertToPinyin(oa?.Contact?.Trim() ?? "")?.ToLower() ?? ""); // 担保人姓名(英文)
  4584. dics.Add("guarantor_name_cn", oa?.Contact ?? ""); // 担保人姓名(中文)
  4585. dics.Add("guarantor_tel", oa?.Tel ?? ""); // 担保人电话
  4586. dics.Add("guarantor_address_en", CommonFun.ConvertToPinyin(oa?.Address?.Trim() ?? "")?.ToLower() ?? ""); //担保人地址(英文)
  4587. dics.Add("guarantor_address_cn", oa?.Address ?? ""); // 担保人地址(中文)
  4588. dics.Add("guarantor_occuandposition", oa?.Job ?? ""); // 担保人职务
  4589. dics.Add("guarantor_relationship", "邀请方"); // 和申请人关系
  4590. dics.Add("guarantor_birthday", ""); // 出生日期
  4591. dics.Add("guarantor_sex_woman", "Off"); // 性别 女
  4592. dics.Add("guarantor_sex_man", "Off"); // 性别 男
  4593. dics.Add("guarantor_nationalityandvisatype", "日本"); // 邀请方 国家
  4594. dics.Add("inviter_name", "同上"); // 邀请人 姓名
  4595. dics.Add("inviter_tel", "同上"); // 邀请人 电话
  4596. dics.Add("inviter_addres", "同上"); // 邀请人 地址
  4597. dics.Add("inviter_birthday", "同上"); // 邀请人 出生日期
  4598. dics.Add("inviter_sex_man", "Off"); // 邀请人 性别 女
  4599. dics.Add("inviter_sex_woman", "Off"); // 邀请人 性别 男
  4600. dics.Add("inviter_relationship", "同上"); // 邀请人 与申请人关系
  4601. dics.Add("inviter_occuandposition", "同上"); // 邀请人 职业、职务
  4602. dics.Add("inviter_nationalityandvisatype", "同上"); // 邀请人 国籍
  4603. dics.Add("inviter_remark", ""); // 邀请人 备注
  4604. }
  4605. }
  4606. #endregion
  4607. #region 犯罪信息
  4608. // 在任何国家曾被判决有罪
  4609. dics.Add("criminal_conviction_yes", "Off");
  4610. dics.Add("criminal_conviction_no", "Off");
  4611. // 在任何国家曾被判处一年或一年以上徒刑
  4612. dics.Add("felony_conviction_yes", "Off");
  4613. dics.Add("felony_conviction_no", "Off");
  4614. // 在任何国家曾因非法滞留或违反改过法律法规而被驱逐出镜
  4615. dics.Add("deportation_order_yes", "Off");
  4616. dics.Add("deportation_order_no", "Off");
  4617. // 因违反毒品相关法律被判刑
  4618. dics.Add("drug_conviction_yes", "Off");
  4619. dics.Add("drug_conviction_no", "Off");
  4620. // 从事或参与卖淫相关活动
  4621. dics.Add("prostitution_involvement_yes", "Off");
  4622. dics.Add("prostitution_involvement_no", "Off");
  4623. // 贩卖人口相关犯罪经历
  4624. dics.Add("human_trafficking_offense_yes", "Off");
  4625. dics.Add("human_trafficking_offense_no", "Off");
  4626. //备注
  4627. dics.Add("yes_remark", "");
  4628. #endregion
  4629. SetFieldValue(formFields, "application_date", DateTime.Now.ToString("dd/MM/yyyy")); // 申请日期
  4630. #endregion
  4631. filePaths.Add(outputPath);
  4632. //return outputPath;
  4633. }
  4634. catch (Exception ex)
  4635. {
  4636. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  4637. }
  4638. finally
  4639. {
  4640. // 按正确顺序关闭资源
  4641. stamper?.Close();
  4642. reader?.Close();
  4643. templateStream?.Close();
  4644. outputStream?.Close();
  4645. }
  4646. #endregion
  4647. }
  4648. break;
  4649. case 3: // 韩国
  4650. visaTypeName = $"韩国签证申请表";
  4651. currTempPath = $"{tempPath}{visaTypeName}.doc";
  4652. var korSavePath = $"{fileServerPath}{visaTypeName}/";
  4653. if (!Directory.Exists(fileServerPath)) Directory.CreateDirectory(korSavePath);
  4654. foreach (var custInfo in groupCustInfos)
  4655. {
  4656. EncryptionProcessor.DecryptProperties(custInfo);
  4657. Dictionary<string, string> dics = new();
  4658. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4659. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4660. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4661. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4662. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4663. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4664. #region 韩国签证模板书签
  4665. dics.Add("LastNameEn", custInfo?.LastName ?? "");//姓
  4666. dics.Add("FirstNameEn", custInfo?.FirstName ?? "");//名
  4667. var userName = $"{custInfo?.LastName ?? ""}{custInfo?.FirstName ?? ""}";
  4668. dics.Add("User", userName);//姓名
  4669. //判断性别
  4670. if (custInfo.Sex == 0)
  4671. dics.Add("SexMale", "√");
  4672. else if (custInfo.Sex == 1)
  4673. dics.Add("SexFemale", "√");
  4674. string idCard = idInfo.CertNo;
  4675. string birthday = string.Empty;
  4676. if (!string.IsNullOrEmpty(idCard))
  4677. {
  4678. string year = idCard.Substring(6, 4);
  4679. string month = idCard.Substring(10, 2);
  4680. string day = idCard.Substring(12, 2);
  4681. birthday = year + "/" + month + "/" + day;
  4682. }
  4683. dics.Add("BirthDay", birthday);//出生日期
  4684. dics.Add("Nationality", "中国");//国籍
  4685. dics.Add("NationalityCountry", "中国");//出生国
  4686. dics.Add("IdCard", idCard);//身份证号码
  4687. dics.Add("OtherPassProt", "√"); //默认没有其他护照
  4688. //判断是否否曾用名 是否申请过该国家
  4689. string isGetSchengenStr = custInfo.IsGetSchengen == 0 ? "否" : "是";
  4690. if (!string.IsNullOrEmpty(custInfo.OldName) && isGetSchengenStr.equals("是"))
  4691. {
  4692. dics.Add("IsGetSchengenYes", "√");
  4693. string oldName = custInfo?.OldName ?? "";
  4694. if (!string.IsNullOrEmpty(oldName))
  4695. {
  4696. dics.Add("OldLastName", oldName.Substring(0, 1));
  4697. dics.Add("OldFirstName", oldName.Remove(0, 1));
  4698. }
  4699. }
  4700. else
  4701. dics.Add("IsGetSchengenNo", "√");
  4702. dics.Add("IsDoubleNationality", "√"); //默认没有双重国籍
  4703. //护照
  4704. if (passportInfo != null)
  4705. {
  4706. dics.Add("PassprotNo", passportInfo?.CertNo ?? ""); // 护照編號
  4707. dics.Add("PassprotCountry", passportInfo?.Country ?? ""); // 护照签发国
  4708. dics.Add("PassprotIssuePlase", passportInfo?.Area ?? ""); // 护照签发地
  4709. dics.Add("PassprotStartTime", passportInfo?.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //护照开始时间
  4710. dics.Add("PassprotEndTime", passportInfo?.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); // 护照过期时间
  4711. }
  4712. dics.Add("Address", custInfo?.Address ?? "");//现居家庭地址
  4713. dics.Add("Tel1", custInfo?.Tel ?? "");//移动电话 /家庭电话 /电子信箱
  4714. //dics.Add("Tel2", );//电子信箱
  4715. dics.Add("Email", custInfo?.Email ?? "");//电子信箱
  4716. //判断婚姻状况
  4717. var marriage = custInfo.Marriage switch
  4718. {
  4719. 1 => "未婚",
  4720. 2 => "已婚",
  4721. 3 => "离异",
  4722. 4 => "丧偶",
  4723. _ => "未设置"
  4724. };
  4725. if (marriage.Contains("未婚") || marriage == null || marriage == "")
  4726. dics.Add("Single", "√");
  4727. else if (marriage == "已婚")
  4728. dics.Add("Married", "√");
  4729. else if (marriage == "离婚" || marriage == "离异")
  4730. dics.Add("Divorced", "√");
  4731. //判断是否已婚 已婚则输出配偶信息
  4732. if (marriage == "已婚")
  4733. {
  4734. string mateName = custInfo?.MateName ?? "";
  4735. if (!string.IsNullOrEmpty(mateName))
  4736. {
  4737. try
  4738. {
  4739. string mateFirstName = mateName.Remove(0, 1);
  4740. dics.Add("MateLastName", mateName.Substring(0, 1)); //配偶姓
  4741. dics.Add("MateFirstName", mateFirstName); //配偶名
  4742. //dics.Add("MateLastName", MateName.Substring(0, 1)); //配偶姓
  4743. //dics.Add("MateFirstName", MateName.Substring(1, MateName.Length - 1)); //配偶名
  4744. }
  4745. catch { }
  4746. dics.Add("MateBirthDay", custInfo?.MateBirthDay.ToString("yyyy-MM-dd")); //配偶生日
  4747. //dics.Add("MateNationality", custInfo.ma.ToString()); //配偶国籍
  4748. //dics.Add("MateTel", custInfo..ToString()); //配偶联系电话
  4749. dics.Add("MateAddress", custInfo.MateAddress.ToString()); //配偶居住地址
  4750. //家人信息书签
  4751. if (currFamilyInfos.Count > 0)
  4752. {
  4753. //定义接受子女人数
  4754. int children = currFamilyInfos.Where(x => x.Appellation.contains("儿子") || x.Appellation.contains("女儿")).ToList().Count;
  4755. //判断子女人数
  4756. if (children == 0) //无子女
  4757. dics.Add("NoChildren", "√"); //未查询出 则无子女
  4758. else
  4759. {
  4760. dics.Add("HaveChildren", "√");
  4761. dics.Add("ChildrenNum", children.ToString());//有子女则输出人数
  4762. }
  4763. }
  4764. else
  4765. dics.Add("NoChildren", "√"); //未查询出 则无子女
  4766. }
  4767. }
  4768. else
  4769. dics.Add("NoChildren", "√"); //未婚则无子女
  4770. //学历
  4771. if (custInfo.HighestEducation.Contains("硕士") || custInfo.HighestEducation.Contains("博士"))
  4772. dics.Add("Master", "√");
  4773. else if (custInfo.HighestEducation.Contains("学士"))
  4774. dics.Add("Bachelor", "√");
  4775. else if (custInfo.HighestEducation.Contains("高中"))
  4776. dics.Add("HighSchool", "√");
  4777. else
  4778. {
  4779. dics.Add("Other", "√");
  4780. dics.Add("OtherDetails", custInfo.HighestEducation.Trim());
  4781. }
  4782. //dics.Add("Job", custInfo.Job.ToString()); ;//职业
  4783. dics.Add("Company", companyInfos.FirstOrDefault()?.Company ?? "");//单位名称
  4784. dics.Add("jobs", companyInfos.FirstOrDefault()?.Job ?? ""); //职务
  4785. dics.Add("CompanyAddress", companyInfos.FirstOrDefault()?.CompanyAddress ?? "");//单位地址
  4786. dics.Add("CompanyTel", companyInfos.FirstOrDefault()?.Phone ?? "");//单位电话
  4787. string day1 = ""; //得到抵达日期
  4788. string day2 = ""; //得到离开日期
  4789. string country = groupInfo.VisitCountry; //国家名
  4790. string HG_City = ""; //城市
  4791. string HG_Country = "";//国家
  4792. string[] HG_countryName = new string[] { };
  4793. if (!string.IsNullOrEmpty(country))
  4794. {
  4795. //处理国家名
  4796. if (country.Contains(" "))
  4797. HG_countryName = country.Split(' ');
  4798. else if (country.Contains(","))
  4799. HG_countryName = country.Split(',');
  4800. else if (country.Contains(","))
  4801. HG_countryName = country.Split(',');
  4802. else if (country.Contains("、"))
  4803. HG_countryName = country.Split('、');
  4804. }
  4805. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  4806. int k = 0;
  4807. for (int i = 0; i < HG_countryName.Length; i++)
  4808. {
  4809. for (int j = 0; j < atbc.Rows.Count; j++)
  4810. {
  4811. string HL_Three = atbc.Rows[j]["Three"].ToString();
  4812. if (!string.IsNullOrEmpty(HL_Three))
  4813. {
  4814. var hl_three = HL_Three.Substring(3);
  4815. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == hl_three).First();
  4816. if (tc != null)
  4817. {
  4818. HG_Country = HG_countryName[i];
  4819. HG_City = tc.City; //得到当前国家 城市名
  4820. day1 = atbc.Rows[j]["Day"].ToString(); //得到抵达日期
  4821. k = j + 1;
  4822. }
  4823. }
  4824. if (k == j)
  4825. day2 = atbc.Rows[j]["Day"].ToString(); //离开航班起飞时间
  4826. }
  4827. }
  4828. if (atbc != null)
  4829. {
  4830. if (day2 != null && day1 != null)
  4831. {
  4832. try
  4833. {
  4834. int Han_day = (Convert.ToDateTime(day2) - Convert.ToDateTime(day1)).Days; //得到天数
  4835. dics.Add("Days", Han_day.ToString() + "天");//滞留天数
  4836. dics.Add("EntryTime", day1.ToString());//入境日期 TemporaryAddress
  4837. }
  4838. catch (Exception) { }
  4839. }
  4840. }
  4841. //得到当前国家下的城市酒店信息
  4842. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  4843. .Where(x => x.DiId == groupId)
  4844. .Where(x => x.City.contains(HG_City))
  4845. .First();
  4846. //访问信息
  4847. if (hotelInfo != null)
  4848. {
  4849. dics.Add("TemporaryAddress", hotelInfo?.HotelAddress ?? "");//停留酒店地址 TATel
  4850. dics.Add("TATel", hotelInfo?.HotelTel ?? ""); //停留酒店联系电话
  4851. }
  4852. if (!string.IsNullOrEmpty(HG_Country) && !string.IsNullOrEmpty(HG_City))
  4853. {
  4854. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  4855. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  4856. .Where(x => x.Country.Contains(HG_Country))
  4857. .Where(x => x.Area.Contains(HG_City))
  4858. .First();
  4859. //在韩邀请方信息
  4860. if (oa != null)
  4861. {
  4862. dics.Add("IsYes", "√");
  4863. dics.Add("TT", oa?.Contact ?? ""); //联系人
  4864. dics.Add("TTAddress", oa?.Address ?? ""); //联系地址
  4865. dics.Add("TTtel", oa?.Tel ?? ""); //联系电话
  4866. dics.Add("TTGuanxi", "BY INVITED"); //和在邀联系人关系
  4867. }
  4868. else
  4869. dics.Add("IsNo", "√");
  4870. }
  4871. //费用信息
  4872. if (groupInfo != null)
  4873. {
  4874. //dics.Add("Payer", "Unit"); //在外期间费用承担
  4875. dics.Add("Team1", groupInfo.ClientUnit); //客户单位名称
  4876. dics.Add("Team12", "雇佣"); //与申请人关系 BY INVITED
  4877. dics.Add("PriceType", "Payment By Unit"); //资金类型
  4878. dics.Add("TeamNameTel", custInfo.ClientPhone); //联系方式
  4879. }
  4880. //是否有协助填表人
  4881. if (!string.IsNullOrEmpty(custInfo.TableOpName))
  4882. dics.Add("WirteTableNo", "√");
  4883. else
  4884. {
  4885. dics.Add("WirteTableYes", "√");
  4886. dics.Add("OpTableName", custInfo.TableOpName.ToString()); //协助填表人姓名
  4887. //dics.Add("OpTableDateTime",custInfo.OpDate.ToString()); //填表时间
  4888. dics.Add("OpTableTel", custInfo.TableOpTel.ToString()); //协助人联系电话
  4889. dics.Add("OpTableGuanXi", "雇佣"); //和协助人关系
  4890. }
  4891. dics.Add("NowDateTime", DateTime.Now.ToString("yyyy/MM/dd")); //获取当前系统时间
  4892. dics.Add("ApplicantName", custInfo.LastName + " " + custInfo.FirstName); //申请人
  4893. #endregion
  4894. #region 生成文件
  4895. try
  4896. {
  4897. Document doc = new(currTempPath);
  4898. Aspose.Words.DocumentBuilder builder = new(doc);
  4899. string strTemp = "";
  4900. //循环键值对
  4901. foreach (var key in dics.Keys)
  4902. {
  4903. //将光标移入书签的位置
  4904. builder.MoveToBookmark(key);
  4905. //判断书签值是否为空
  4906. if (!string.IsNullOrEmpty(dics[key]))
  4907. {
  4908. strTemp = dics[key];
  4909. }
  4910. else strTemp = "";
  4911. //填充书签
  4912. builder.Write(strTemp.Replace("\\N", "\n"));
  4913. }
  4914. var custName = custInfo.LastName + custInfo.FirstName;
  4915. string fileName = $"{custName}_{visaTypeName}.doc";
  4916. var currFilePath = $"{korSavePath}{fileName}";
  4917. doc.Save(currFilePath);
  4918. filePaths.Add(currFilePath);
  4919. }
  4920. catch (Exception ex)
  4921. {
  4922. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4923. }
  4924. #endregion
  4925. }
  4926. break;
  4927. case 4: // 瑞典
  4928. visaTypeName = $"瑞典签证申请表";
  4929. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  4930. var swedenSavePath = $"{fileServerPath}{visaTypeName}/";
  4931. if (!Directory.Exists(swedenSavePath)) Directory.CreateDirectory(swedenSavePath);
  4932. if (!System.IO.File.Exists(currTempPath))
  4933. {
  4934. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  4935. }
  4936. foreach (var custInfo in groupCustInfos)
  4937. {
  4938. EncryptionProcessor.DecryptProperties(custInfo);
  4939. var idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773);
  4940. var passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774);
  4941. var clinetInfo = companyInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.Id == custInfo.CrmCompanyId);
  4942. var currSchoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4943. var currFamilyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4944. var currCompanyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList();
  4945. #region 生成文件
  4946. PdfReader reader = null;
  4947. FileStream templateStream = null;
  4948. FileStream outputStream = null;
  4949. PdfStamper stamper = null;
  4950. try
  4951. {
  4952. string outputPath = $"{swedenSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  4953. //读取模板文件
  4954. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  4955. reader = new PdfReader(templateStream);
  4956. //创建输出文件
  4957. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  4958. stamper = new PdfStamper(reader, outputStream);
  4959. AcroFields formFields = stamper.AcroFields;
  4960. #region 设置文本值
  4961. SetFieldValue(formFields, "LastName", custInfo.LastName); //姓
  4962. SetFieldValue(formFields, "BirthLastName", custInfo.LastName); // 出生时姓氏
  4963. SetFieldValue(formFields, "FirstName", custInfo.FirstName); // 名
  4964. // 出生日期(日-月-年)
  4965. string idCard = idInfo.CertNo;
  4966. string birthday = string.Empty;
  4967. if (!string.IsNullOrEmpty(idCard))
  4968. {
  4969. string year = idCard.Substring(6, 4);
  4970. string month = idCard.Substring(10, 2);
  4971. string day = idCard.Substring(12, 2);
  4972. birthday = day + "-" + month + "-" + year;
  4973. }
  4974. SetFieldValue(formFields, "Birthday", birthday);
  4975. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  4976. SetFieldValue(formFields, "CurrentNationality", currentNationality); // 出生地
  4977. SetFieldValue(formFields, "CountryBirth", "中国"); // 出生国
  4978. SetFieldValue(formFields, "CurrentNationalityCountry", "中国"); // 现国籍
  4979. SetFieldValue(formFields, "NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  4980. SetFieldValue(formFields, "OtherNationalities", ""); // 其他国籍
  4981. #region 性别处理
  4982. //清除性别
  4983. SetFieldValue(formFields, "Male", "Off"); // 性别 - 男
  4984. SetFieldValue(formFields, "Female", "Off"); // 性别 - 女
  4985. //设置性别
  4986. if (custInfo.Sex == 0) //男
  4987. {
  4988. SetFieldValue(formFields, "Male", "Yes"); // 性别 - 男
  4989. }
  4990. else if (custInfo.Sex == 1) //女
  4991. {
  4992. SetFieldValue(formFields, "Female", "Yes"); // 性别 - 女
  4993. }
  4994. #endregion
  4995. #region 婚姻状况处理
  4996. //清除婚姻状况
  4997. SetFieldValue(formFields, "Single", "Off"); // 婚姻状况 - 未婚
  4998. SetFieldValue(formFields, "Married", "Off"); // 婚姻状况 - 已婚
  4999. SetFieldValue(formFields, "RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  5000. SetFieldValue(formFields, "Separated", "Off"); // 婚姻状况 - 分居
  5001. SetFieldValue(formFields, "Divorced", "Off"); // 婚姻状况 - 离婚
  5002. SetFieldValue(formFields, "Widow(er)", "Off"); // 婚姻状况 - 丧偶
  5003. SetFieldValue(formFields, "OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  5004. SetFieldValue(formFields, "CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  5005. //设置婚姻状况
  5006. switch (custInfo.Marriage)
  5007. {
  5008. case 1: // 未婚
  5009. SetFieldValue(formFields, "Single", "Yes");
  5010. break;
  5011. case 2: // 已婚
  5012. SetFieldValue(formFields, "Married", "Yes");
  5013. break;
  5014. case 3: // 离异
  5015. SetFieldValue(formFields, "Divorced", "Yes");
  5016. break;
  5017. case 4: // 离异
  5018. SetFieldValue(formFields, "Widow(er)", "Yes");
  5019. break;
  5020. }
  5021. #endregion
  5022. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  5023. SetFieldValue(formFields, "ParentalAuthority", "");
  5024. SetFieldValue(formFields, "NationalIdentityNumber", idCard); //公民身份证号码
  5025. #region 护照(旅行证件类型)处理
  5026. //清除值
  5027. SetFieldValue(formFields, "OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  5028. SetFieldValue(formFields, "DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  5029. SetFieldValue(formFields, "ServicePassport", "Off"); //旅行证件类型 - 公务护照
  5030. SetFieldValue(formFields, "OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  5031. SetFieldValue(formFields, "SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  5032. SetFieldValue(formFields, "OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  5033. SetFieldValue(formFields, "OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  5034. //设置值
  5035. SetFieldValue(formFields, "OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  5036. if (passportInfo != null)
  5037. {
  5038. SetFieldValue(formFields, "TravelNumber", passportInfo.CertNo); //旅行证件编号
  5039. SetFieldValue(formFields, "IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  5040. SetFieldValue(formFields, "ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  5041. SetFieldValue(formFields, "IssuedCountry", passportInfo.Country); //签发(国)
  5042. }
  5043. #endregion
  5044. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  5045. SetFieldValue(formFields, "LastName_om", ""); //姓
  5046. SetFieldValue(formFields, "FirstName_om", ""); //名
  5047. SetFieldValue(formFields, "BirthDate_om", ""); //出生日期(日-月-年)
  5048. SetFieldValue(formFields, "Nationality_om", ""); //国籍
  5049. SetFieldValue(formFields, "TravelNuber_om", ""); //旅行证件或身分证编号
  5050. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  5051. SetFieldValue(formFields, "Spouse_om", ""); //配偶
  5052. SetFieldValue(formFields, "RegisteredPartnership_om", ""); //注册伴侣
  5053. SetFieldValue(formFields, "Child_om", ""); //子女
  5054. SetFieldValue(formFields, "DependentAscendant_om", ""); //受养人
  5055. SetFieldValue(formFields, "Grandchild_om", ""); //孙子女
  5056. SetFieldValue(formFields, "FamilyOther_om", ""); //其他
  5057. SetFieldValue(formFields, "FamilyOtherDesc_om", ""); //其他(说明)
  5058. //申请人住址及电子邮件
  5059. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  5060. SetFieldValue(formFields, "ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  5061. SetFieldValue(formFields, "TelephoneNo", custInfo.Tel); //电话号码
  5062. //是否居住在现时国籍以外的国家
  5063. SetFieldValue(formFields, "AnotherCountryNo", "Yes"); //否
  5064. SetFieldValue(formFields, "AnotherCountryYes", ""); //是。
  5065. SetFieldValue(formFields, "ResidencePermit", ""); //居住许可或同等证
  5066. SetFieldValue(formFields, "Number", ""); //编号
  5067. SetFieldValue(formFields, "ValidUntils", ""); //有效期至
  5068. SetFieldValue(formFields, "CurrentOccupation", custInfo.Job); //当前职业
  5069. //工作单位名称,地址和电话,学生填写学校名称及地址
  5070. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  5071. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  5072. SetFieldValue(formFields, "EmployerInfo", employerInfoStr);
  5073. #region 旅行的目的
  5074. //清空值
  5075. SetFieldValue(formFields, "Tourism", "Off"); //旅游
  5076. SetFieldValue(formFields, "Business", "Off"); //商务
  5077. SetFieldValue(formFields, "VisitingFamily", "Off"); //探亲访友
  5078. SetFieldValue(formFields, "Cultural", "Off"); //文化
  5079. SetFieldValue(formFields, "Sports", "Off"); //体育
  5080. SetFieldValue(formFields, "OfficialVisit", "Off"); //官方访问
  5081. SetFieldValue(formFields, "MedicalReasons", "Off"); //医疗
  5082. SetFieldValue(formFields, "Study", "Off"); //学习
  5083. SetFieldValue(formFields, "AirportTransit", "Off"); //机场过境
  5084. SetFieldValue(formFields, "Other", "Off"); //其它
  5085. SetFieldValue(formFields, "OtherDesc", ""); //其它 (请注明)
  5086. //设置值
  5087. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "Tourism", "Yes"); //旅游
  5088. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "Business", "Yes"); //商务
  5089. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "VisitingFamily", "Yes"); //探亲访友
  5090. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "Cultural", "Yes"); //文化
  5091. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "Sports", "Yes"); //体育
  5092. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "OfficialVisit", "Yes"); //官方访问
  5093. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "MedicalReasons", "Yes"); //医疗
  5094. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "Study", "Yes"); //学习
  5095. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "AirportTransit", "Yes"); //机场过境
  5096. #endregion
  5097. SetFieldValue(formFields, "AdditionalInfo", ""); //有关停留原因的补充信息
  5098. string[] RD_country = new string[] { }; //接收处理的国家
  5099. string firstEntryLabel = string.Empty; //首入申根国标签
  5100. string membeDescLabel = string.Empty; //申根国目的地
  5101. string stopDays = string.Empty; //停留天数
  5102. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5103. {
  5104. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5105. if (groupInfo.VisitCountry.Contains(","))
  5106. RD_country = groupInfo.VisitCountry.Split(',');
  5107. else if (groupInfo.VisitCountry.Contains(' '))
  5108. RD_country = groupInfo.VisitCountry.Split(' ');
  5109. else if (groupInfo.VisitCountry.Contains(","))
  5110. RD_country = groupInfo.VisitCountry.Split(',');
  5111. else if (groupInfo.VisitCountry.Contains("、"))
  5112. RD_country = groupInfo.VisitCountry.Split('、');
  5113. else if (groupInfo.VisitCountry.Contains("|"))
  5114. RD_country = groupInfo.VisitCountry.Split('|');
  5115. //判断是否是申根国家
  5116. for (int i = 0; i < RD_country.Length; i++)
  5117. {
  5118. if (RD_country[i].ToString() != null)
  5119. {
  5120. //在申根国家中筛选 该国家是否是申根国家
  5121. for (int j = 0; j < _shenGenGuos.Length; j++)
  5122. {
  5123. if (RD_country[i] == _shenGenGuos[j])
  5124. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5125. }
  5126. }
  5127. }
  5128. //目的地国是否有申根国
  5129. if (SGGNames.Count > 0)
  5130. {
  5131. firstEntryLabel = SGGNames.First();
  5132. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5133. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5134. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5135. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5136. for (int i = 0; i < SGGNames.Count; i++)
  5137. {
  5138. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5139. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5140. //ResidenceTime1 机票三字码信息
  5141. if (atbc != null)
  5142. {
  5143. string HL_Three = ""; //三字码 Three
  5144. for (int j = 0; j < atbc.Rows.Count; j++)
  5145. {
  5146. HL_Three = atbc.Rows[j]["Three"].ToString();
  5147. if (!string.IsNullOrEmpty(HL_Three))
  5148. {
  5149. string threeCodeTwo = HL_Three.Substring(3);
  5150. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5151. if (tc != null)
  5152. {
  5153. //首入申根国时间
  5154. if (SGGNames[i] == tc.Country)
  5155. {
  5156. SSGDetails SSGDetails = new SSGDetails()
  5157. {
  5158. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5159. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5160. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5161. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5162. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5163. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5164. };
  5165. ListSSGDetails.Add(SSGDetails);
  5166. }
  5167. }
  5168. }
  5169. }
  5170. }
  5171. }
  5172. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5173. //得到并计算出入境时间
  5174. if (ListSSGDetails != null)
  5175. {
  5176. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5177. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5178. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5179. }
  5180. }
  5181. }
  5182. SetFieldValue(formFields, "MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5183. SetFieldValue(formFields, "FirstEntry", firstEntryLabel); //首入申根国
  5184. //申请入境次数
  5185. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5186. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5187. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5188. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5189. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5190. //以往申根国签证是否有指纹记录
  5191. SetFieldValue(formFields, "28.No", ""); //否
  5192. SetFieldValue(formFields, "28.Yes", ""); //是
  5193. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5194. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5195. //最后目的地之入境许可
  5196. SetFieldValue(formFields, "29.Issued", ""); //签发机关
  5197. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5198. SetFieldValue(formFields, "29.Until", ""); //至
  5199. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5200. //得到当前国家下的城市酒店信息
  5201. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5202. .Where(x => x.DiId == groupId)
  5203. //.Where(x => x.City.contains(city))
  5204. .First();
  5205. //酒店住址
  5206. if (hotelInfo != null)
  5207. {
  5208. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5209. var otherInfo = $"{hotelInfo.HotelAddress}";
  5210. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5211. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5212. }
  5213. //邀请公司或机构的名称及地址
  5214. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5215. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5216. //.Where(x => x.Country.Contains(county))
  5217. //.Where(x => x.Area.Contains(city))
  5218. .First();
  5219. if (oa != null)
  5220. {
  5221. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5222. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5223. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5224. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5225. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5226. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5227. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5228. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5229. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5230. }
  5231. //申请人的旅费以及在国外停留期间的生活费用
  5232. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5233. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5234. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5235. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5236. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5237. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5238. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5239. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5240. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5241. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5242. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5243. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5244. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5245. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5246. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5247. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5248. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5249. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5250. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5251. SetFieldValue(formFields, "33.PlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5252. #endregion
  5253. filePaths.Add(outputPath);
  5254. //return outputPath;
  5255. }
  5256. catch (Exception ex)
  5257. {
  5258. return Ok(JsonView(false, $"生成PDF文件时出错:{ex.Message}"));
  5259. }
  5260. finally
  5261. {
  5262. // 按正确顺序关闭资源
  5263. stamper?.Close();
  5264. reader?.Close();
  5265. templateStream?.Close();
  5266. outputStream?.Close();
  5267. }
  5268. #endregion
  5269. }
  5270. break;
  5271. case 5: // 波兰
  5272. visaTypeName = $"波兰签证申请表";
  5273. currTempPath = $"{tempPath}{visaTypeName}.pdf";
  5274. var polandSavePath = $"{fileServerPath}{visaTypeName}/";
  5275. if (!Directory.Exists(polandSavePath)) Directory.CreateDirectory(polandSavePath);
  5276. if (!System.IO.File.Exists(currTempPath))
  5277. {
  5278. return Ok(JsonView(false, $"{currTempPath}模板不存在!"));
  5279. }
  5280. foreach (var custInfo in groupCustInfos)
  5281. {
  5282. EncryptionProcessor.DecryptProperties(custInfo);
  5283. var visaData = new VisaDateView()
  5284. {
  5285. groupInfo = groupInfo,
  5286. idInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 773),
  5287. passportInfo = certInfos.FirstOrDefault(x => x.DcId == custInfo.Id && x.PassportType == 774),
  5288. custInfo = custInfo,
  5289. schoolInfos = schoolInfos.Where(x => x.DcId == custInfo.Id).ToList(),
  5290. familyInfos = familyInfos.Where(x => x.DcId == custInfo.Id).ToList(),
  5291. companyInfos = companyInfos.Where(x => x.DcId == custInfo.Id).ToList()
  5292. };
  5293. //生成文件
  5294. string outFilePath = CreatePolandVisaPdf(visaData, polandSavePath, currTempPath);
  5295. filePaths.Add(outFilePath);
  5296. }
  5297. break;
  5298. default:
  5299. return Ok(JsonView(false, "正在开发中,请等待。。。"));
  5300. }
  5301. // 压缩文件
  5302. var zipFilePathName = $"{groupInfo.TeamName}({visaTypeName}).zip";
  5303. var zipFilePath = $"{fileServerPath}{zipFilePathName}";
  5304. // 关键修复:先获取压缩文件的上级目录,检查并创建(如果不存在)
  5305. string zipDirectory = Path.GetDirectoryName(zipFilePath);
  5306. if (!Directory.Exists(zipDirectory))
  5307. {
  5308. // CreateDirectory会自动创建所有不存在的上级目录,无需手动逐层创建
  5309. Directory.CreateDirectory(zipDirectory);
  5310. }
  5311. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  5312. {
  5313. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  5314. {
  5315. foreach (string filePath in filePaths)
  5316. {
  5317. // 增加空值/空字符串校验,提升代码健壮性
  5318. if (!string.IsNullOrEmpty(filePath) && System.IO.File.Exists(filePath))
  5319. {
  5320. // 获取文件名
  5321. string fileName = Path.GetFileName(filePath);
  5322. // 将文件添加到ZIP归档中
  5323. zipArchive.CreateEntryFromFile(filePath, fileName);
  5324. }
  5325. }
  5326. }
  5327. }
  5328. url = $"{serverPath}{zipFilePathName}";
  5329. if (!string.IsNullOrEmpty(url))
  5330. {
  5331. return Ok(JsonView(true, "操作成功", url));
  5332. }
  5333. return Ok(JsonView(false, "操作失败!"));
  5334. }
  5335. #region iTextSharp pdf 设置值辅助方法
  5336. /// <summary>
  5337. /// 设置文本值
  5338. /// 辅助方法
  5339. /// </summary>
  5340. /// <param name="formFields"></param>
  5341. /// <param name="fieldName"></param>
  5342. /// <param name="value"></param>
  5343. private static void SetFieldValue(AcroFields formFields, string fieldName, string value)
  5344. {
  5345. if (formFields.Fields.ContainsKey(fieldName) && !string.IsNullOrEmpty(value))
  5346. {
  5347. formFields.SetField(fieldName, value);
  5348. }
  5349. }
  5350. /// <summary>
  5351. /// 创建PDF
  5352. /// </summary>
  5353. /// <param name="data"></param>
  5354. /// <param name="currSavePath"></param>
  5355. /// <param name="currTempPath"></param>
  5356. /// <returns></returns>
  5357. /// <exception cref="Exception"></exception>
  5358. private string CreatePolandVisaPdf(VisaDateView data, string currSavePath, string currTempPath)
  5359. {
  5360. var groupInfo = data.groupInfo;
  5361. var groupId = groupInfo.Id;
  5362. var idInfo = data.idInfo;
  5363. var passportInfo = data.passportInfo;
  5364. var custInfo = data.custInfo;
  5365. var currSchoolInfos = data.schoolInfos;
  5366. var currFamilyInfos = data.familyInfos;
  5367. var currCompanyInfos = data.companyInfos;
  5368. string outputPath = $"{currSavePath}{custInfo.LastName}{custInfo.FirstName}.pdf";
  5369. PdfReader reader = null;
  5370. FileStream templateStream = null;
  5371. FileStream outputStream = null;
  5372. PdfStamper stamper = null;
  5373. try
  5374. {
  5375. //读取模板文件
  5376. templateStream = new FileStream(currTempPath, FileMode.Open, FileAccess.Read, FileShare.Read);
  5377. reader = new PdfReader(templateStream);
  5378. //创建输出文件
  5379. outputStream = new FileStream(outputPath, FileMode.Create, FileAccess.Write);
  5380. stamper = new PdfStamper(reader, outputStream);
  5381. AcroFields formFields = stamper.AcroFields;
  5382. #region 设置文本值
  5383. SetFieldValue(formFields, "1.LastName", custInfo.LastName); //姓
  5384. SetFieldValue(formFields, "2.BirthLastName", custInfo.LastName); // 出生时姓氏
  5385. SetFieldValue(formFields, "3.FirstName", custInfo.FirstName); // 名
  5386. // 出生日期(日-月-年)
  5387. string idCard = idInfo.CertNo;
  5388. string birthday = string.Empty;
  5389. if (!string.IsNullOrEmpty(idCard))
  5390. {
  5391. string year = idCard.Substring(6, 4);
  5392. string month = idCard.Substring(10, 2);
  5393. string day = idCard.Substring(12, 2);
  5394. birthday = day + "-" + month + "-" + year;
  5395. }
  5396. SetFieldValue(formFields, "4.Birthday", birthday);
  5397. string currentNationality = custInfo.BirthProvince + custInfo.BirthCity;
  5398. SetFieldValue(formFields, "5.CurrentNationality", currentNationality); // 出生地
  5399. SetFieldValue(formFields, "6.CountryBirth", "中国"); // 出生国
  5400. SetFieldValue(formFields, "7.CurrentNationalityCountry", "中国"); // 现国籍
  5401. SetFieldValue(formFields, "7.NationalityBirth", ""); // 出生时国籍,如与现国籍不同
  5402. SetFieldValue(formFields, "7.OtherNationalities", ""); // 其他国籍
  5403. #region 性别处理
  5404. //清除性别
  5405. SetFieldValue(formFields, "8.Male", "Off"); // 性别 - 男
  5406. SetFieldValue(formFields, "8.Female", "Off"); // 性别 - 女
  5407. SetFieldValue(formFields, "8.Other", "Off"); // 性别 - 其他
  5408. //设置性别
  5409. if (custInfo.Sex == 0) //男
  5410. {
  5411. SetFieldValue(formFields, "8.Male", "Yes"); // 性别 - 男
  5412. }
  5413. else if (custInfo.Sex == 1) //女
  5414. {
  5415. SetFieldValue(formFields, "8.Female", "Yes"); // 性别 - 女
  5416. }
  5417. else //其他
  5418. {
  5419. SetFieldValue(formFields, "8.Other", "Yes"); // 性别 - 其他
  5420. }
  5421. #endregion
  5422. #region 婚姻状况处理
  5423. //清除婚姻状况
  5424. SetFieldValue(formFields, "9.Single", "Off"); // 婚姻状况 - 未婚
  5425. SetFieldValue(formFields, "9.Married", "Off"); // 婚姻状况 - 已婚
  5426. SetFieldValue(formFields, "9.RegisteredPartnership", "Off"); // 婚姻状况 - 注册伴侣关系
  5427. SetFieldValue(formFields, "9.Separated", "Off"); // 婚姻状况 - 分居
  5428. SetFieldValue(formFields, "9.Divorced", "Off"); // 婚姻状况 - 离婚
  5429. SetFieldValue(formFields, "9.Widow(er)", "Off"); // 婚姻状况 - 丧偶
  5430. SetFieldValue(formFields, "9.OtherCivilStatus", "Off"); // 婚姻状况 - 其它
  5431. SetFieldValue(formFields, "9.CivilStatusOther", ""); // 婚姻状况 - 其它(请注明)
  5432. //设置婚姻状况
  5433. switch (custInfo.Marriage)
  5434. {
  5435. case 1: // 未婚
  5436. SetFieldValue(formFields, "9.Single", "Yes");
  5437. break;
  5438. case 2: // 已婚
  5439. SetFieldValue(formFields, "9.Married", "Yes");
  5440. break;
  5441. case 3: // 离异
  5442. SetFieldValue(formFields, "9.Divorced", "Yes");
  5443. break;
  5444. case 4: // 离异
  5445. SetFieldValue(formFields, "9.Widow(er)", "Yes");
  5446. break;
  5447. }
  5448. #endregion
  5449. //亲权人(如是未成年申请人 )/合法监护人(姓名、住址,如与申请人不同) 电话号码、电子邮件及国籍
  5450. SetFieldValue(formFields, "10.ParentalAuthority", "");
  5451. SetFieldValue(formFields, "11.NationalIdentityNumber", idCard); //公民身份证号码
  5452. #region 护照(旅行证件类型)处理
  5453. //清除值
  5454. SetFieldValue(formFields, "12.OrdinaryPassport", "Off"); //旅行证件类型 - 普通护照
  5455. SetFieldValue(formFields, "12.DiplomaticPassport", "Off"); //旅行证件类型 - 外交护照
  5456. SetFieldValue(formFields, "12.ServicePassport", "Off"); //旅行证件类型 - 公务护照
  5457. SetFieldValue(formFields, "12.OfficialPassport", "Off"); //旅行证件类型 - 因公护照
  5458. SetFieldValue(formFields, "12.SpecialPassport", "Off"); //旅行证件类型 - 特殊护照
  5459. SetFieldValue(formFields, "12.OtherTravel", "Off"); //旅行证件类型 - 其它旅行证件
  5460. SetFieldValue(formFields, "12.OtherTravelDesc", ""); //旅行证件类型 - 其它旅行证件(请注明)
  5461. //设置值
  5462. SetFieldValue(formFields, "12.OrdinaryPassport", "Yes"); //旅行证件类型 - 普通护照
  5463. if (passportInfo != null)
  5464. {
  5465. SetFieldValue(formFields, "13.TravelNumber", passportInfo.CertNo); //旅行证件编号
  5466. SetFieldValue(formFields, "14.IssueDate", passportInfo.IssueDt?.ToString("yyyy-MM-dd") ?? ""); //签发日期
  5467. SetFieldValue(formFields, "15.ValidUntil", passportInfo.ExpiryDt?.ToString("yyyy-MM-dd") ?? ""); //有效期至
  5468. SetFieldValue(formFields, "16.IssuedCountry", passportInfo.Country); //签发(国)
  5469. }
  5470. #endregion
  5471. //如有家庭成员为欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的,请填写该家庭成员的个人信息
  5472. SetFieldValue(formFields, "17.LastName_om", ""); //姓
  5473. SetFieldValue(formFields, "17.FirstName_om", ""); //名
  5474. SetFieldValue(formFields, "17.BirthDate_om", ""); //出生日期(日-月-年)
  5475. SetFieldValue(formFields, "17.Nationality_om", ""); //国籍
  5476. SetFieldValue(formFields, "17.TravelNuber_om", ""); //旅行证件或身分证编号
  5477. //申请人与欧盟、欧洲经济区、瑞士或受益于退欧协议的英国公民的关系
  5478. SetFieldValue(formFields, "18.Spouse_om", ""); //配偶
  5479. SetFieldValue(formFields, "18.RegisteredPartnership_om", ""); //注册伴侣
  5480. SetFieldValue(formFields, "18.Child_om", ""); //子女
  5481. SetFieldValue(formFields, "18.DependentAscendant_om", ""); //受养人
  5482. SetFieldValue(formFields, "18.Grandchild_om", ""); //孙子女
  5483. SetFieldValue(formFields, "18.FamilyOther_om", ""); //其他
  5484. SetFieldValue(formFields, "18.FamilyOtherDesc_om", ""); //其他(说明)
  5485. //申请人住址及电子邮件
  5486. string applicantHomeAddress = $"{custInfo.Address} {custInfo.Email}";
  5487. SetFieldValue(formFields, "19.ApplicantHomeAddress", applicantHomeAddress); //申请人住址及电子邮件
  5488. SetFieldValue(formFields, "19.TelephoneNo", custInfo.Tel); //电话号码
  5489. //是否居住在现时国籍以外的国家
  5490. SetFieldValue(formFields, "20.AnotherCountryNo", "Yes"); //否
  5491. SetFieldValue(formFields, "20.AnotherCountryYes", ""); //是
  5492. SetFieldValue(formFields, "20.ResidencePermit", ""); //居住许可或同等证
  5493. SetFieldValue(formFields, "20.Number", ""); //编号
  5494. SetFieldValue(formFields, "20.ValidUntils", ""); //有效期至
  5495. SetFieldValue(formFields, "21.CurrentOccupation", custInfo.Job); //当前职业
  5496. //工作单位名称,地址和电话,学生填写学校名称及地址
  5497. var currCompanyInfo = currCompanyInfos.FirstOrDefault();
  5498. string employerInfoStr = $"{currCompanyInfo?.Company ?? ""} {currCompanyInfo?.CompanyAddress ?? ""} {currCompanyInfo?.Phone ?? ""}";
  5499. SetFieldValue(formFields, "22.EmployerInfo", employerInfoStr);
  5500. #region 旅行的目的
  5501. //清空值
  5502. SetFieldValue(formFields, "23.Tourism", "Off"); // 旅游
  5503. SetFieldValue(formFields, "23.Business", "Off"); // 商务
  5504. SetFieldValue(formFields, "23.VisitingFamily", "Off"); // 探亲访友
  5505. SetFieldValue(formFields, "23.Cultural", "Off"); // 文化
  5506. SetFieldValue(formFields, "23.Sports", "Off"); // 体育
  5507. SetFieldValue(formFields, "23.OfficialVisit", "Off"); // 官方访问
  5508. SetFieldValue(formFields, "23.MedicalReasons", "Off"); // 医疗
  5509. SetFieldValue(formFields, "23.Study", "Off"); // 学习
  5510. SetFieldValue(formFields, "23.AirportTransit", "Off"); // 机场过境
  5511. SetFieldValue(formFields, "23.Other", "Off"); // 其它
  5512. SetFieldValue(formFields, "23.OtherDesc", ""); // 其它 (请注明)
  5513. //设置值
  5514. if (groupInfo.VisitPurpose.contains("旅游")) SetFieldValue(formFields, "23.Tourism", "Yes"); //旅游
  5515. if (groupInfo.VisitPurpose.contains("商务")) SetFieldValue(formFields, "23.Business", "Yes"); //商务
  5516. if (groupInfo.VisitPurpose.contains("探亲访友")) SetFieldValue(formFields, "23.VisitingFamily", "Yes"); //探亲访友
  5517. if (groupInfo.VisitPurpose.contains("文化")) SetFieldValue(formFields, "23.Cultural", "Yes"); //文化
  5518. if (groupInfo.VisitPurpose.contains("体育")) SetFieldValue(formFields, "23.Sports", "Yes"); //体育
  5519. if (groupInfo.VisitPurpose.contains("官方访问")) SetFieldValue(formFields, "23.OfficialVisit", "Yes"); //官方访问
  5520. if (groupInfo.VisitPurpose.contains("医疗")) SetFieldValue(formFields, "23.MedicalReasons", "Yes"); //医疗
  5521. if (groupInfo.VisitPurpose.contains("学习")) SetFieldValue(formFields, "23.Study", "Yes"); //学习
  5522. if (groupInfo.VisitPurpose.contains("机场过境")) SetFieldValue(formFields, "23.AirportTransit", "Yes"); //机场过境
  5523. #endregion
  5524. SetFieldValue(formFields, "24.AdditionalInfo", ""); //有关停留原因的补充信息
  5525. string[] RD_country = new string[] { }; //接收处理的国家
  5526. string firstEntryLabel = string.Empty; //首入申根国标签
  5527. string membeDescLabel = string.Empty; //申根国目的地
  5528. string stopDays = string.Empty; //停留天数
  5529. if (!string.IsNullOrEmpty(groupInfo.VisitCountry))
  5530. {
  5531. List<string> SGGNames = new List<string>();//接收处理后的国家 是申根国
  5532. if (groupInfo.VisitCountry.Contains(","))
  5533. RD_country = groupInfo.VisitCountry.Split(',');
  5534. else if (groupInfo.VisitCountry.Contains(' '))
  5535. RD_country = groupInfo.VisitCountry.Split(' ');
  5536. else if (groupInfo.VisitCountry.Contains(","))
  5537. RD_country = groupInfo.VisitCountry.Split(',');
  5538. else if (groupInfo.VisitCountry.Contains("、"))
  5539. RD_country = groupInfo.VisitCountry.Split('、');
  5540. else if (groupInfo.VisitCountry.Contains("|"))
  5541. RD_country = groupInfo.VisitCountry.Split('|');
  5542. //判断是否是申根国家
  5543. for (int i = 0; i < RD_country.Length; i++)
  5544. {
  5545. if (RD_country[i].ToString() != null)
  5546. {
  5547. //在申根国家中筛选 该国家是否是申根国家
  5548. for (int j = 0; j < _shenGenGuos.Length; j++)
  5549. {
  5550. if (RD_country[i] == _shenGenGuos[j])
  5551. SGGNames.Add(_shenGenGuos[j]); //添加申根国
  5552. }
  5553. }
  5554. }
  5555. //目的地国是否有申根国
  5556. if (SGGNames.Count > 0)
  5557. {
  5558. firstEntryLabel = SGGNames.First();
  5559. membeDescLabel = string.Join(",", SGGNames.ToArray());
  5560. //接收生根国详细信息 存储顺序 起飞日期:Day 起飞时刻:StartTime 抵达日期:ArrivedDate 到达时刻:EndTime
  5561. List<SSGDetails> ListSSGDetails = new List<SSGDetails>();
  5562. //处理申根国家 预定到达时间 预定离开时间 预定停留天数
  5563. for (int i = 0; i < SGGNames.Count; i++)
  5564. {
  5565. //在相同的国家下 得到该航班的信息 //抵达时间 起飞日期:Day 起飞时刻:StartTime 到达时刻:EndTime 抵达日期:ArrivedDate 飞行时间:FlightTime 航司 Fliagtcode 入境口岸
  5566. var atbc = GeneralMethod.GetTableByBlackCode(groupId);
  5567. //ResidenceTime1 机票三字码信息
  5568. if (atbc != null)
  5569. {
  5570. string HL_Three = ""; //三字码 Three
  5571. for (int j = 0; j < atbc.Rows.Count; j++)
  5572. {
  5573. HL_Three = atbc.Rows[j]["Three"].ToString();
  5574. if (!string.IsNullOrEmpty(HL_Three))
  5575. {
  5576. string threeCodeTwo = HL_Three.Substring(3);
  5577. var tc = _sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.Three == threeCodeTwo).First();
  5578. if (tc != null)
  5579. {
  5580. //首入申根国时间
  5581. if (SGGNames[i] == tc.Country)
  5582. {
  5583. SSGDetails SSGDetails = new SSGDetails()
  5584. {
  5585. Three = atbc.Rows[j]["Three"].ToString(), //三字码
  5586. Fliagtcode = atbc.Rows[j]["Fliagtcode"].ToString(), //航司
  5587. startDate = atbc.Rows[j]["Day"].ToString(), //整理起飞日期
  5588. startTime = atbc.Rows[j]["StartTime"].ToString(), //整理起飞时刻
  5589. endDate = atbc.Rows[j]["ArrivedDate"].ToString(), //整理抵达日期
  5590. endTime = atbc.Rows[j]["EndTime"].ToString() //整理抵达时刻
  5591. };
  5592. ListSSGDetails.Add(SSGDetails);
  5593. }
  5594. }
  5595. }
  5596. }
  5597. }
  5598. }
  5599. ListSSGDetails.Sort((a, b) => a.startDate.CompareTo(b.startDate));
  5600. //得到并计算出入境时间
  5601. if (ListSSGDetails != null)
  5602. {
  5603. string RuJingTime = ListSSGDetails.First().endDate + " " + ListSSGDetails.First().endTime.Substring(0, 2) + ":" + ListSSGDetails.First().endTime.Substring(2); //入境时间
  5604. string LiJingTime = ListSSGDetails[ListSSGDetails.Count - 1].startDate + " " + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(0, 2) + ":" + ListSSGDetails[ListSSGDetails.Count - 1].endTime.Substring(2); //离境时间
  5605. stopDays = Convert.ToDateTime(LiJingTime).Subtract(Convert.ToDateTime(RuJingTime)).Days.ToString();
  5606. }
  5607. }
  5608. }
  5609. SetFieldValue(formFields, "25.MembeDesc", membeDescLabel); //主要申根目的地 (以及其他申根目的地,如适用)
  5610. SetFieldValue(formFields, "26.FirstEntry", firstEntryLabel); //首入申根国
  5611. //申请入境次数
  5612. SetFieldValue(formFields, "27.SingleEntry", ""); //单次
  5613. SetFieldValue(formFields, "27.TwoEntries", ""); //两次
  5614. SetFieldValue(formFields, "27.MultipleEntries", ""); //多次
  5615. SetFieldValue(formFields, "27.IntendedDateIn", ""); //在申根地区预计首次停留的预计抵达日期
  5616. SetFieldValue(formFields, "27.IntendedDateOut", ""); //在申根地区预计首次停留之后的预计离开日期
  5617. //以往申根国签证是否有指纹记录
  5618. SetFieldValue(formFields, "28.No", ""); //否
  5619. SetFieldValue(formFields, "28.Yes", ""); //是
  5620. SetFieldValue(formFields, "28.KnownDate", ""); //如有,请写明日期
  5621. SetFieldValue(formFields, "28.KnownVisanumber", ""); //如有,请写明签证贴纸号码
  5622. //最后目的地之入境许可
  5623. SetFieldValue(formFields, "29.Issued", ""); //签发机关 Entry permit for the final country of destination, where applicable
  5624. SetFieldValue(formFields, "29.ValidFrom", ""); //有效期由
  5625. SetFieldValue(formFields, "29.Until", ""); //至
  5626. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5627. //得到当前国家下的城市酒店信息
  5628. var hotelInfo = _sqlSugar.Queryable<Grp_HotelReservations>()
  5629. .Where(x => x.DiId == groupId)
  5630. //.Where(x => x.City.contains(city))
  5631. .First();
  5632. //酒店住址
  5633. if (hotelInfo != null)
  5634. {
  5635. SetFieldValue(formFields, "30.SurnameFirstName", hotelInfo?.HotelName ?? ""); //申根国的酒店
  5636. var otherInfo = $"{hotelInfo.HotelAddress}";
  5637. SetFieldValue(formFields, "30.HotelInfo", otherInfo); //邀请人/酒店/暂住居所的地址及电子邮件
  5638. SetFieldValue(formFields, "30.TelephoneNo", hotelInfo?.HotelTel ?? ""); //电话号码
  5639. }
  5640. //邀请公司或机构的名称及地址
  5641. var oa = _sqlSugar.Queryable<Res_OfficialActivities>()
  5642. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  5643. //.Where(x => x.Country.Contains(county))
  5644. //.Where(x => x.Area.Contains(city))
  5645. .First();
  5646. if (oa != null)
  5647. {
  5648. //申根国的邀请人姓名。如无邀请人,请填写申根国的酒店或暂住居所名称
  5649. SetFieldValue(formFields, "30.SurnameFirstName", oa?.Contact ?? ""); //申根国的酒店
  5650. SetFieldValue(formFields, "30.HotelInfo", oa?.Address ?? ""); //邀请人/酒店/暂住居所的地址及电子邮件
  5651. SetFieldValue(formFields, "30.TelephoneNo", oa?.Tel ?? ""); //电话号码
  5652. string nameAddressLabel = $"{oa.Client} {oa.Address}";
  5653. SetFieldValue(formFields, "31.NameAddress", nameAddressLabel); //邀请公司或机构的名称及地址
  5654. string surnameLabel = $"{oa.Contact} {oa.Tel}";
  5655. SetFieldValue(formFields, "31.Surname", surnameLabel); //邀请公司或机构的联系人姓名、地址、电话号码及电子邮件
  5656. SetFieldValue(formFields, "31.TelephoneNo", oa?.Tel ?? ""); //邀请公司或机构的电话
  5657. }
  5658. //申请人的旅费以及在国外停留期间的生活费用
  5659. SetFieldValue(formFields, "32.Applicant", ""); //由申请人支付
  5660. SetFieldValue(formFields, "32.Cash", ""); //支付方式 - 现金
  5661. SetFieldValue(formFields, "32.Traveller", ""); //支付方式 - 旅行支票
  5662. SetFieldValue(formFields, "32.CreditCard", ""); //支付方式 - 信用卡
  5663. SetFieldValue(formFields, "32.Prepaid", ""); //支付方式 - 预缴住宿
  5664. SetFieldValue(formFields, "32.Prepaid1", ""); //支付方式 - 预缴交通
  5665. SetFieldValue(formFields, "32.OtherMeans", ""); //支付方式 - 其它
  5666. SetFieldValue(formFields, "32.OtherMeansDesc", ""); //支付方式 - 其它(请注明)
  5667. SetFieldValue(formFields, "32.Sponsor", ""); //由赞助方(邀请人、公司或机构)支付,请注明
  5668. SetFieldValue(formFields, "32.Referred", ""); //参见第 30 及 31 项
  5669. SetFieldValue(formFields, "32.ReferredDesc", ""); //参见第 30 及 31 项(请注明)
  5670. SetFieldValue(formFields, "32.OtherSponsor", ""); //其它
  5671. SetFieldValue(formFields, "32.OtherSponsorDesc", ""); //其它(请注明)
  5672. SetFieldValue(formFields, "32.SponsorCash", ""); //赞助方式 - 现金
  5673. SetFieldValue(formFields, "32.SponsorAccommodation", ""); //赞助方式 - 提供住宿
  5674. SetFieldValue(formFields, "32.SponsorExpenses", ""); //赞助方式 - 支付旅程期间所有开支
  5675. SetFieldValue(formFields, "32.SponsorPrepaid", ""); //赞助方式 - 预缴交通
  5676. SetFieldValue(formFields, "32.ponsorOther", ""); //赞助方式 - 其它
  5677. SetFieldValue(formFields, "32.ponsorOtherDesc", ""); //赞助方式 - 其它(请注明)
  5678. //填表人与申请人不同
  5679. SetFieldValue(formFields, "33.WriteTableName", ""); //姓名
  5680. SetFieldValue(formFields, "33.WriteTableAddress", ""); //住址
  5681. SetFieldValue(formFields, "33.WriteTableTel", ""); //电话
  5682. SetFieldValue(formFields, "EndPlaceAndDate", DateTime.Now.ToString("yyyy-MM-dd")); //地点及日期
  5683. #endregion
  5684. }
  5685. catch (Exception ex)
  5686. {
  5687. throw new Exception($"生成PDF文件时出错: {ex.Message}", ex);
  5688. }
  5689. finally
  5690. {
  5691. // 按正确顺序关闭资源
  5692. stamper?.Close();
  5693. reader?.Close();
  5694. templateStream?.Close();
  5695. outputStream?.Close();
  5696. }
  5697. return outputPath;
  5698. }
  5699. #endregion
  5700. #region 文档下载辅助实体类
  5701. private class VisaDateView
  5702. {
  5703. /// <summary>
  5704. /// 团组信息
  5705. /// </summary>
  5706. public Grp_DelegationInfo groupInfo { get; set; }
  5707. /// <summary>
  5708. /// 身份证信息
  5709. /// </summary>
  5710. public Crm_CustomerCert idInfo { get; set; }
  5711. /// <summary>
  5712. /// 护照信息
  5713. /// </summary>
  5714. public Crm_CustomerCert passportInfo { get; set; }
  5715. /// <summary>
  5716. /// 客户信息
  5717. /// </summary>
  5718. public Crm_DeleClient custInfo { get; set; }
  5719. /// <summary>
  5720. /// 学校资料
  5721. /// </summary>
  5722. public List<Crm_VisaCustomerSchool> schoolInfos { get; set; }
  5723. /// <summary>
  5724. /// 家庭成员资料
  5725. /// </summary>
  5726. public List<Crm_VisaCustomerFamily> familyInfos { get; set; }
  5727. /// <summary>
  5728. /// 公司资料
  5729. /// </summary>
  5730. public List<Crm_VisaCustomerCompany> companyInfos { get; set; }
  5731. }
  5732. private class SSGDetails
  5733. {
  5734. public string Three { get; set; } //三字码
  5735. public string Fliagtcode { get; set; } //航司
  5736. public string startDate { get; set; } //首入申根国日期
  5737. public string startTime { get; set; } //首入申根国时间
  5738. public string endDate { get; set; } //离开申根国日期
  5739. public string endTime { get; set; } //离开申根国时间
  5740. }
  5741. #endregion
  5742. #endregion
  5743. /// <summary>
  5744. /// 根据团组Id获取签证客户信息List
  5745. /// </summary>
  5746. /// <param name="dto">请求dto</param>
  5747. /// <returns></returns>
  5748. [HttpPost]
  5749. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5750. public async Task<IActionResult> GetCrmByGroupId(ClientByGroupIdDto dto)
  5751. {
  5752. var data = await _groupRepository.GetCrmByGroupId(dto);
  5753. return Ok(JsonView(data.Code == 0, data.Code != 0 ? "暂无信息" : "操作成功", data.Data));
  5754. }
  5755. /// <summary>
  5756. /// IOS获取团组签证拍照上传进度01(团组列表)
  5757. /// </summary>
  5758. /// <param name="dto">请求dto</param>
  5759. /// <returns></returns>
  5760. [HttpPost]
  5761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5762. public async Task<IActionResult> PostIOSVisaProgress(IOS_VisaDto dto)
  5763. {
  5764. if (dto == null)
  5765. {
  5766. return Ok(JsonView(false, "参数为空"));
  5767. }
  5768. DelegationVisaViewList visaList = _delegationVisaRep.GetDelegationList(dto);
  5769. return Ok(JsonView(visaList));
  5770. }
  5771. /// <summary>
  5772. /// IOS获取团组签证拍照上传进度02(团组签证详情\人员列表\国家)
  5773. /// </summary>
  5774. /// <returns></returns>
  5775. [HttpPost]
  5776. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5777. public async Task<ActionResult> PostIOSVisaProgressContent(IOS_VisaCustomerListDto dto)
  5778. {
  5779. if (dto == null)
  5780. {
  5781. return Ok(JsonView(false, "请求错误:"));
  5782. }
  5783. List<DelegationVisaProgressView> list = _delegationVisaRep.GetDelegationProgressList(dto.diId);
  5784. return Ok(JsonView(list));
  5785. }
  5786. /// <summary>
  5787. /// IOS获取团组签证拍照上传进度03(相册)
  5788. /// </summary>
  5789. /// <returns></returns>
  5790. [HttpPost]
  5791. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5792. public async Task<ActionResult> PostIOSVisaProgressImageList(IOS_VisaImageListDto dto)
  5793. {
  5794. if (dto == null)
  5795. {
  5796. return Ok(JsonView(false, "请求错误:"));
  5797. }
  5798. List<VisaProgressImageView> list = _delegationVisaRep.GetVisaProgressImageList(dto.visaProgressCustomerId, dto.picType);
  5799. string url = AppSettingsHelper.Get("VisaProgressImageBaseUrl") + AppSettingsHelper.Get("VisaProgressImageFtpPath");
  5800. list.ForEach(s => s.url = url);
  5801. return Ok(JsonView(list));
  5802. }
  5803. /// <summary>
  5804. /// IOS获取团组签证拍照上传进度04(图片上传)
  5805. /// </summary>
  5806. /// <param name="dto"></param>
  5807. /// <returns></returns>
  5808. [HttpPost]
  5809. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5810. public async Task<ActionResult> PostIOSVisaProgressUploadImage(IOS_VisaUploadImageDto dto)
  5811. {
  5812. //string result = decodeBase64ToImage(dto.base64DataURL, dto.imageName);
  5813. //if (!string.IsNullOrEmpty(result))
  5814. //{
  5815. //}
  5816. //else {
  5817. // return Ok(JsonView(false, "上传失败"));
  5818. //}
  5819. var dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
  5820. int sucNum = 0;
  5821. try
  5822. {
  5823. foreach (var item in dto.base64DataList)
  5824. {
  5825. string imageName = dto.imageName + ((DateTime.Now.Ticks - dt1970.Ticks) / 10000).ToString();
  5826. string result = DecodeBase64ToImage(item, imageName);
  5827. if (!string.IsNullOrEmpty(result))
  5828. {
  5829. var pic = new Grp_VisaProgressCustomerPicture
  5830. {
  5831. CreateUserId = dto.CreateUserId,
  5832. PicName = imageName,
  5833. PicPath = result,
  5834. VisaProgressCustomerId = dto.visaProgressCustomerId
  5835. };
  5836. int insertResult = await _delegationVisaRep.AddAsync<Grp_VisaProgressCustomerPicture>(pic);
  5837. if (insertResult > 0)
  5838. {
  5839. sucNum++;
  5840. }
  5841. }
  5842. }
  5843. }
  5844. catch (Exception ex)
  5845. {
  5846. return Ok(JsonView(false, ex.Message));
  5847. }
  5848. string msg = string.Format(@"成功上传{0}张", sucNum);
  5849. return Ok(JsonView(true, msg));
  5850. }
  5851. private string DecodeBase64ToImage(string base64DataURL, string imgName)
  5852. {
  5853. string filename = "";//声明一个string类型的相对路径
  5854. String base64 = base64DataURL.Substring(base64DataURL.IndexOf(",") + 1); //将‘,’以前的多余字符串删除
  5855. System.Drawing.Bitmap bitmap = null;//定义一个Bitmap对象,接收转换完成的图片
  5856. try//会有异常抛出,try,catch一下
  5857. {
  5858. byte[] arr = Convert.FromBase64String(base64);//将纯净资源Base64转换成等效的8位无符号整形数组
  5859. var ms = new System.IO.MemoryStream(arr);//转换成无法调整大小的MemoryStream对象
  5860. bitmap = new System.Drawing.Bitmap(ms);//将MemoryStream对象转换成Bitmap对象
  5861. var fileDir = AppSettingsHelper.Get("VisaProgressImageBasePath");
  5862. //文件名称
  5863. filename = "VisaProgress_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + imgName + ".jpeg";//所要保存的相对路径及名字
  5864. //上传的文件的路径
  5865. string filePath = "";
  5866. if (!Directory.Exists(fileDir))
  5867. {
  5868. Directory.CreateDirectory(fileDir);
  5869. }
  5870. //上传的文件的路径
  5871. filePath = fileDir + filename;
  5872. //string url = HttpRuntime.AppDomainAppPath.ToString();
  5873. //string tmpRootDir = System.Web.HttpContext.Current.Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString()); //获取程序根目录
  5874. //string imagesurl2 = tmpRootDir + filename; //转换成绝对路径
  5875. bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);//保存到服务器路径
  5876. //bitmap.Save(filePath + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
  5877. //bitmap.Save(filePath + ".gif", System.Drawing.Imaging.ImageFormat.Gif);
  5878. //bitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Png);
  5879. ms.Close();//关闭当前流,并释放所有与之关联的资源
  5880. bitmap.Dispose();
  5881. }
  5882. catch (Exception e)
  5883. {
  5884. string massage = e.Message;
  5885. Logs("IOS图片上传Error:" + massage);
  5886. //filename = e.Message;
  5887. }
  5888. return filename;//返回相对路径
  5889. }
  5890. /// <summary>
  5891. /// IOS获取团组签证拍照上传进度05(修改签证状态/通知)
  5892. /// </summary>
  5893. /// <param name="dto"></param>
  5894. /// <returns></returns>
  5895. [HttpPost]
  5896. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5897. public async Task<ActionResult> PostIOSVisaProgressChangeStatus(IOS_VisaChangeStatusDto dto)
  5898. {
  5899. if (dto == null)
  5900. {
  5901. return Ok(JsonView(false, "请求错误:"));
  5902. }
  5903. string msg = "参数错误";
  5904. if (dto.diId > 0 && dto.visaStatus > 0 && dto.visaStatus < 4)
  5905. {
  5906. try
  5907. {
  5908. //_delegationVisaRep.BeginTran();
  5909. var updCount = await _delegationVisaRep._sqlSugar.Updateable<Grp_VisaProgressCustomer>()
  5910. .SetColumns(it => it.WorkStatus == dto.visaStatus)
  5911. .Where(s => s.Id == dto.visaProgressCustomerId)
  5912. .ExecuteCommandAsync();
  5913. if (updCount > 0 && dto.publishCode == 1)
  5914. {
  5915. _delegationVisaRep.ChangeDataBase(DBEnum.OA2014DB); //切换到新OA后删除
  5916. string sqlDelegation = string.Format(@" Select * From DelegationInfo With(Nolock) Where Id = {0} ", dto.diId);
  5917. OA2021_DelegationInfo groupData = _sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sqlDelegation).First();
  5918. //GroupInfoDto grpDto = new GroupInfoDto() { Id = dto.diId };
  5919. //var groupData = await _groupRepository.GetGroupInfo(grpDto);
  5920. _delegationVisaRep.ChangeDataBase(DBEnum.OA2023DB); //切换到新OA后删除
  5921. if (groupData == null)
  5922. {
  5923. _delegationVisaRep.RollbackTran();
  5924. }
  5925. string title = string.Format(@"[签证进度更新]");
  5926. string content = string.Format(@"测试文本");
  5927. bool rst = await _message.AddMsg(new MessageDto()
  5928. {
  5929. Type = MessageTypeEnum.GroupVisaProgressUpdate,
  5930. IssuerId = dto.publisher,
  5931. Title = title,
  5932. Content = content,
  5933. ReleaseTime = DateTime.Now,
  5934. UIdList = new List<int> {
  5935. 234
  5936. }
  5937. });
  5938. if (rst)
  5939. {
  5940. return Ok(JsonView(true, "发送通知成功"));
  5941. }
  5942. }
  5943. //_delegationVisaRep.CommitTran();
  5944. }
  5945. catch (Exception)
  5946. {
  5947. //_delegationVisaRep.RollbackTran();
  5948. }
  5949. }
  5950. return Ok(JsonView(true, msg));
  5951. }
  5952. #endregion
  5953. #endregion
  5954. #region 团组任务分配
  5955. /// <summary>
  5956. /// 团组任务分配初始化
  5957. /// </summary>
  5958. /// <returns></returns>
  5959. [HttpPost]
  5960. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5961. public async Task<IActionResult> GetTaskAssignmen()
  5962. {
  5963. var groupData = await _taskAssignmentRep.GetTaskAssignmen();
  5964. if (groupData.Code != 0)
  5965. {
  5966. return Ok(JsonView(false, groupData.Msg));
  5967. }
  5968. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  5969. }
  5970. /// <summary>
  5971. /// 团组任务分配查询
  5972. /// </summary>
  5973. /// <param name="dto"></param>
  5974. /// <returns></returns>
  5975. [HttpPost]
  5976. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5977. public async Task<IActionResult> TaskAssignmenQuery(TaskAssignmenQueryDto dto)
  5978. {
  5979. var groupData = await _taskAssignmentRep.TaskAssignmenQuery(dto);
  5980. if (groupData.Code != 0)
  5981. {
  5982. return Ok(JsonView(false, groupData.Msg));
  5983. }
  5984. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  5985. }
  5986. /// <summary>
  5987. /// 团组任务分配操作
  5988. /// </summary>
  5989. /// <param name="dto"></param>
  5990. /// <returns></returns>
  5991. [HttpPost]
  5992. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  5993. public async Task<IActionResult> GetTaskAssignmenOp(TaskAssignmenDto dto)
  5994. {
  5995. Result groupData = await _taskAssignmentRep.GetTaskAssignmenOp(dto);
  5996. if (groupData.Code != 0)
  5997. {
  5998. return Ok(JsonView(false, groupData.Msg));
  5999. }
  6000. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  6001. }
  6002. /// <summary>
  6003. /// 团组任务分配
  6004. /// 批量分配
  6005. /// 查询团组
  6006. /// </summary>
  6007. /// <param name="dto"></param>
  6008. /// <returns></returns>
  6009. [HttpPost]
  6010. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6011. public async Task<IActionResult> TaskAllocationGroupSelect(TaskAllocationGroupSelectDto dto)
  6012. {
  6013. //参数验证
  6014. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  6015. if (!DateTime.TryParse(dto.VisitBeginDt, out _) || !DateTime.TryParse(dto.VisitEndDt, out _))
  6016. return Ok(JsonView(false, "团组出访开始/结束日期格式不正确!"));
  6017. return Ok(await _taskAssignmentRep.TaskAllocationGroupSelect(dto));
  6018. }
  6019. /// <summary>
  6020. /// 团组任务分配
  6021. /// 批量分配
  6022. /// </summary>
  6023. /// <param name="dto"></param>
  6024. /// <returns></returns>
  6025. [HttpPost]
  6026. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6027. public async Task<IActionResult> TaskAllocationBulkAdd(TaskAllocationBulkAddDto dto)
  6028. {
  6029. //参数验证
  6030. if (dto.UserIds.Length < 1) return Ok(JsonView(false, $"请选择分配人员!"));
  6031. if (dto.PermissionTypeIds.Length < 1) return Ok(JsonView(false, $"请选择分配类型!"));
  6032. if (dto.GroupIds.Length < 1) return Ok(JsonView(false, "请选择分配团组Id"));
  6033. if (dto.CurrUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId数组参数"));
  6034. return Ok(await _taskAssignmentRep.TaskAllocationBulkAdd(dto));
  6035. }
  6036. #endregion
  6037. #region 团组费用审核
  6038. /// <summary>
  6039. /// 费用审核
  6040. /// 团组列表 Page
  6041. /// </summary>
  6042. /// <param name="dto">团组列表请求dto</param>
  6043. /// <returns></returns>
  6044. [HttpPost]
  6045. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6046. public async Task<IActionResult> PostExpenseAuditGroupPageItems(ExpenseAuditGroupPageItemsDto dto)
  6047. {
  6048. #region 参数验证
  6049. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  6050. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  6051. #region 页面操作权限验证
  6052. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  6053. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  6054. #endregion
  6055. #endregion
  6056. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android/IOS
  6057. {
  6058. string sqlWhere = "WHERE gdi.IsDel = 0";
  6059. var parameters = new List<SugarParameter>();
  6060. // 状态条件(保持不变)
  6061. if (dto.IsSure >= 0)
  6062. {
  6063. sqlWhere += $" AND IsSure = {dto.IsSure}";
  6064. }
  6065. // 搜索条件
  6066. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  6067. {
  6068. // 将搜索词按空格分割为多个关键字(支持多关键字检索)
  6069. var keywords = dto.SearchCriteria.Split(new[] { ' ', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
  6070. if (keywords.Length > 0)
  6071. {
  6072. var searchConditions = new List<string>();
  6073. foreach (var keyword in keywords)
  6074. {
  6075. if (!string.IsNullOrWhiteSpace(keyword))
  6076. {
  6077. // 对每个关键字构建多字段检索条件
  6078. var keywordConditions = new List<string>
  6079. {
  6080. $"ssd.Name LIKE '%{keyword}%'",
  6081. $"gdi.TeamName LIKE '%{keyword}%'",
  6082. $"gdi.ClientName LIKE '%{keyword}%'",
  6083. $"su.CnName LIKE '%{keyword}%'",
  6084. $"gdi.SalesQuoteNo LIKE '%{keyword}%'",
  6085. $"gdi.TourCode LIKE '%{keyword}%'",
  6086. $"gdi.ClientUnit LIKE '%{keyword}%'",
  6087. $"ssd1.Name LIKE '%{keyword}%'"
  6088. };
  6089. // 将多个字段条件用 OR 连接
  6090. searchConditions.Add($"({string.Join(" OR ", keywordConditions)})");
  6091. }
  6092. }
  6093. // 将多个关键字条件用 AND 连接(实现多关键字AND搜索)
  6094. if (searchConditions.Count > 0)
  6095. {
  6096. sqlWhere += $" AND ({string.Join(" AND ", searchConditions)})";
  6097. }
  6098. }
  6099. }
  6100. // 基础查询sql
  6101. string sql = $@"
  6102. SELECT Row_Number, Id, SalesQuoteNo, TourCode, TeamTypeId, TeamType,
  6103. TeamName, ClientName, ClientUnit, TeamLevId, TeamLev, VisitDate,
  6104. VisitDays, VisitPNumber, JietuanOperator, IsSure, CreateTime
  6105. FROM (
  6106. SELECT ROW_NUMBER() OVER (ORDER BY gdi.VisitDate DESC) AS Row_Number,
  6107. gdi.Id, gdi.SalesQuoteNo, gdi.TourCode,
  6108. ssd1.Id AS TeamLevId, ssd1.Name AS TeamLev,
  6109. gdi.TeamName, gdi.ClientName, gdi.ClientUnit,
  6110. ssd.Id AS TeamTypeId, ssd.Name AS TeamType,
  6111. gdi.VisitDate, gdi.VisitDays, gdi.VisitPNumber,
  6112. su.CnName AS JietuanOperator, gdi.IsSure, gdi.CreateTime
  6113. FROM Grp_DelegationInfo gdi
  6114. LEFT JOIN Sys_SetData ssd ON gdi.TeamDid = ssd.Id
  6115. LEFT JOIN Sys_SetData ssd1 ON gdi.TeamLevSId = ssd1.Id
  6116. LEFT JOIN Sys_Users su ON gdi.JietuanOperator = su.Id
  6117. {sqlWhere}
  6118. ) AS temp";
  6119. RefAsync<int> total = 0;
  6120. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql)
  6121. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  6122. var _view = new
  6123. {
  6124. PageFuncAuth = pageFunAuthView,
  6125. Data = _DelegationList
  6126. };
  6127. return Ok(JsonView(true, "查询成功!", _view, total));
  6128. }
  6129. else
  6130. {
  6131. return Ok(JsonView(false, "查询失败"));
  6132. }
  6133. }
  6134. /// <summary>
  6135. /// 获取团组费用审核
  6136. /// </summary>
  6137. /// <param name="_dto"></param>
  6138. /// <returns></returns>
  6139. [HttpPost]
  6140. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6141. public async Task<IActionResult> PostSearchGrpCreditCardPayment(Search_GrpCreditCardPaymentDto _dto)
  6142. {
  6143. try
  6144. {
  6145. #region 参数验证
  6146. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  6147. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  6148. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  6149. #region 页面操作权限验证
  6150. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  6151. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  6152. #endregion
  6153. #endregion
  6154. var _view = new Grp_CreditCardPaymentView();
  6155. var clientNameList = GetSimplClientList(_dto.DiId);
  6156. #region 费用清单
  6157. var exp = Expressionable.Create<Grp_CreditCardPayment>();
  6158. exp.AndIF(_dto.AuditStatus != -1, it => it.IsAuditGM == _dto.AuditStatus);
  6159. exp.AndIF(_dto.Label != -1, it => it.CTable == _dto.Label);
  6160. var entityList = _groupRepository.Query<Grp_CreditCardPayment>(s => s.DIId == _dto.DiId && s.IsDel == 0 && s.CreateUserId > 0).Where(exp.ToExpression()).ToList();
  6161. var detailList = new List<Grp_CreditCardPaymentDetailView>();
  6162. var ccpCurrencyPrices = new List<CreditCardPaymentCurrencyPriceItem>();
  6163. /*
  6164. * 76://酒店预订
  6165. */
  6166. var _HotelReservations = await _groupRepository.Query<Grp_HotelReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6167. var _HotelReservationsContents = await _groupRepository.Query<Grp_HotelReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6168. /*
  6169. * 79://车/导游地接
  6170. */
  6171. var _CarTouristGuideGroundReservations = await _groupRepository.Query<Grp_CarTouristGuideGroundReservations>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6172. var _CarTouristGuideGroundReservationsContent = await _groupRepository.Query<Grp_CarTouristGuideGroundReservationsContent>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6173. /*
  6174. * 80: //签证
  6175. */
  6176. var _VisaInfos = await _groupRepository.Query<Grp_VisaInfo>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6177. /*
  6178. *81: //邀请/公务活动
  6179. */
  6180. var _InvitationOfficialActivities = await _groupRepository.Query<Grp_InvitationOfficialActivities>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6181. /*
  6182. * 82: //团组客户保险
  6183. */
  6184. var _Customers = await _groupRepository.Query<Grp_Customers>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6185. /*
  6186. * Lable = 85 机票预订
  6187. */
  6188. var p_AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6189. /*
  6190. * 85 机票预定
  6191. */
  6192. var _AirTicketReservations = await _groupRepository.Query<Grp_AirTicketReservations>(s => s.DIId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6193. /*
  6194. * 98 其他款项
  6195. */
  6196. var _DecreasePayments = await _groupRepository.Query<Grp_DecreasePayments>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6197. /*
  6198. * 285:收款退还
  6199. */
  6200. var _PaymentRefundAndOtherMoneys = await _groupRepository.Query<Fin_PaymentRefundAndOtherMoney>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6201. /*
  6202. * 1015: //超支费用
  6203. */
  6204. var _GroupExtraCosts = await _groupRepository.Query<Fin_GroupExtraCost>(s => s.DiId == _dto.DiId && s.IsDel == 0).ToListAsync();
  6205. var initDatas = await _groupRepository.Query<Sys_SetData>(s => s.IsDel == 0).ToListAsync();
  6206. /*
  6207. * 币种信息
  6208. */
  6209. var currencyItems = initDatas.Where(s => s.STid == 66).ToList();
  6210. /*
  6211. * 车/导游地接 费用类型
  6212. */
  6213. var carFeeTypeItems = initDatas.Where(s => s.STid == 17).ToList();
  6214. /*
  6215. * 车/导游地接 费用类型
  6216. */
  6217. var carFeeItems = initDatas.Where(s => s.STid == 83).ToList();
  6218. var cityData = await _groupRepository.Query<Grp_NationalTravelFee>(s => s.IsDel == 0).ToListAsync();
  6219. /*
  6220. * 用户信息
  6221. */
  6222. var userItems = await _groupRepository._sqlSugar.Queryable<Sys_Users>().ToListAsync();
  6223. /*
  6224. * 费用模块
  6225. */
  6226. var sdPriceName = initDatas.Where(s => s.Id == _dto.Label).First();
  6227. string priceModule = string.Empty;
  6228. if (sdPriceName != null)
  6229. {
  6230. priceModule = sdPriceName.Name;
  6231. }
  6232. /*
  6233. * 成本信息
  6234. */
  6235. var groupCost = _groupRepository.Query<Grp_GroupCostParameter>(s => s.DiId == _dto.DiId && s.IsDel == 0).First();
  6236. decimal _groupRate = 0.0000M;
  6237. string _groupCurrencyCode = "-";
  6238. if (groupCost != null)
  6239. {
  6240. _groupRate = groupCost.Rate;
  6241. if (int.TryParse(groupCost.Currency, out int _currency))
  6242. {
  6243. _groupCurrencyCode = currencyItems.Find(it => it.Id == _currency)?.Name ?? "-";
  6244. }
  6245. else _groupCurrencyCode = groupCost.Currency;
  6246. }
  6247. string costContentSql = $"Select * From Grp_GroupCost";
  6248. var groupCostDetails = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == _dto.DiId).ToList();
  6249. //处理日期为空的天数
  6250. for (int i = 0; i < groupCostDetails.Count; i++)
  6251. if (i != 0)
  6252. if (string.IsNullOrEmpty(groupCostDetails[i].Date))
  6253. groupCostDetails[i].Date = groupCostDetails[i - 1].Date;
  6254. /*
  6255. * 处理详情数据
  6256. */
  6257. foreach (var entity in entityList)
  6258. {
  6259. var _detail = new Grp_CreditCardPaymentDetailView
  6260. {
  6261. Id = entity.Id,
  6262. PriceName = priceModule,
  6263. PayType = initDatas.Find(it => it.Id == entity.PayDId)?.Name ?? "-"
  6264. };
  6265. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  6266. else _detail.CardType = initDatas.Find(it => it.Id == entity.CTDId)?.Name ?? "-";
  6267. //处理金额
  6268. if (entity.CTable == 1015)
  6269. {
  6270. var czInfo = _GroupExtraCosts.Find(x => entity.CId == x.Id);
  6271. if (czInfo != null)
  6272. {
  6273. entity.PayMoney = czInfo.Price * czInfo.PriceCount;
  6274. entity.RMBPrice = czInfo.Price * czInfo.PriceCount * entity.DayRate;
  6275. }
  6276. }
  6277. /*
  6278. * 应付款金额
  6279. */
  6280. var sdPaymentCurrency_WaitPay = currencyItems.Where(s => s.Id == entity.PaymentCurrency).FirstOrDefault();
  6281. string PaymentCurrency_WaitPay = "Unknown";
  6282. string hotelCurrncyCode = "Unknown";
  6283. string hotelCurrncyName = "Unknown";
  6284. if (sdPaymentCurrency_WaitPay != null)
  6285. {
  6286. PaymentCurrency_WaitPay = sdPaymentCurrency_WaitPay.Name;
  6287. hotelCurrncyCode = sdPaymentCurrency_WaitPay.Name;
  6288. hotelCurrncyName = sdPaymentCurrency_WaitPay.Remark;
  6289. if (hotelCurrncyCode.Equals("CNY"))
  6290. {
  6291. entity.DayRate = 1.0000M;
  6292. }
  6293. }
  6294. _detail.WaitPay = entity.PayMoney.ConvertToDecimal1().ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  6295. /*
  6296. * 此次付款金额
  6297. */
  6298. decimal CurrPayStr = 0.00M,
  6299. OriginalCurrPay = 0.00M;
  6300. if (entity.PayPercentage == 0)
  6301. {
  6302. if (entity.PayThenMoney != 0)
  6303. CurrPayStr = (entity.PayThenMoney * entity.DayRate).ConvertToDecimal1();
  6304. }
  6305. else
  6306. {
  6307. if (entity.PayMoney != 0)
  6308. {
  6309. CurrPayStr = (entity.PayMoney * entity.PayPercentage / 100 * entity.DayRate).ConvertToDecimal1();
  6310. }
  6311. }
  6312. //if (_dto.Label == 79)
  6313. //{
  6314. // string original = string.Empty;
  6315. // if (hotelCurrncyCode.Equals("CNY"))
  6316. // {
  6317. // OriginalCurrPay = CurrPayStr;
  6318. // _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6319. // }
  6320. // else
  6321. // {
  6322. // OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  6323. // //760 EUR(7600.00 CNY)
  6324. // _detail.CurrPay = $"{OriginalCurrPay.ToString("#0.00")} {hotelCurrncyCode}({CurrPayStr.ToString("#0.00")} CNY)";
  6325. // }
  6326. //}
  6327. //else _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6328. string original = string.Empty;
  6329. if (hotelCurrncyCode.Equals("CNY"))
  6330. {
  6331. OriginalCurrPay = CurrPayStr;
  6332. _detail.CurrPay = CurrPayStr.ToString("#0.00") + " CNY";
  6333. }
  6334. else
  6335. {
  6336. OriginalCurrPay = ((entity.PayMoney / 100) * entity.PayPercentage).ConvertToDecimal1();
  6337. //760 EUR(7600.00 CNY)
  6338. _detail.CurrPay = $"{OriginalCurrPay:#0.00} {hotelCurrncyCode}({CurrPayStr:#0.00} CNY)";
  6339. }
  6340. /*
  6341. * 剩余尾款
  6342. */
  6343. decimal BalanceStr = 0;
  6344. if (CurrPayStr != 0)
  6345. {
  6346. if (entity.PayMoney - (CurrPayStr / entity.DayRate) < 0.01M)
  6347. BalanceStr = 0;
  6348. else
  6349. BalanceStr = (entity.PayMoney - CurrPayStr / entity.DayRate).ConvertToDecimal1();
  6350. }
  6351. _detail.Balance = BalanceStr.ToString("#0.00") + " " + PaymentCurrency_WaitPay;
  6352. /*
  6353. * Bus名称
  6354. */
  6355. _detail.BusName = "待增加";
  6356. /*
  6357. *费用所属
  6358. */
  6359. switch (entity.CTable)
  6360. {
  6361. case 76://酒店预订
  6362. Grp_HotelReservations hotelReservations = _HotelReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6363. if (hotelReservations != null)
  6364. {
  6365. DateTime checkIn = Convert.ToDateTime(hotelReservations.CheckInDate),
  6366. checkOut = Convert.ToDateTime(hotelReservations.CheckOutDate);
  6367. int hotel_days = (int)(checkOut - checkIn).TotalDays;
  6368. string roomFeeStr = "", roomFeestr1 = "";
  6369. //是否比较房型价格
  6370. //bool __isSingle = false, __isDouble = false, __isSuite = false, __isOther = false;
  6371. //roomFeeStr += $"<br/><span style='width:70px;display: inline-block;'></span>";
  6372. roomFeeStr += $"<br/>";
  6373. var roomTotal = 0.00M;
  6374. if (hotelReservations.SingleRoomPrice > 0)
  6375. {
  6376. var fee = hotelReservations.SingleRoomPrice * hotelReservations.SingleRoomCount * hotel_days;
  6377. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>单间:{hotelReservations.SingleRoomPrice:#0.00} * {hotelReservations.SingleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6378. //__isSingle = true;
  6379. roomTotal += fee;
  6380. }
  6381. if (hotelReservations.DoubleRoomPrice > 0)
  6382. {
  6383. var fee = hotelReservations.DoubleRoomPrice * hotelReservations.DoubleRoomCount * hotel_days;
  6384. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>双人间:{hotelReservations.DoubleRoomPrice:#0.00} * {hotelReservations.DoubleRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6385. // __isDouble = true;
  6386. roomTotal += fee;
  6387. }
  6388. if (hotelReservations.SuiteRoomPrice > 0)
  6389. {
  6390. var fee = hotelReservations.SuiteRoomPrice * hotelReservations.SuiteRoomCount * hotel_days;
  6391. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>套房:{hotelReservations.SuiteRoomPrice:#0.00} * {hotelReservations.SuiteRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6392. //__isSuite = true;
  6393. roomTotal += fee;
  6394. }
  6395. if (hotelReservations.OtherRoomPrice > 0)
  6396. {
  6397. var fee = hotelReservations.OtherRoomPrice * hotelReservations.OtherRoomCount * hotel_days;
  6398. roomFeestr1 += $"<span style='width:70px;display: inline-block;'></span>其他:{hotelReservations.OtherRoomPrice:#0.00} * {hotelReservations.OtherRoomCount}间 * {hotel_days}晚 = {fee:#0.00}<br/>";
  6399. //__isOther = true;
  6400. roomTotal += fee;
  6401. }
  6402. if (roomFeestr1.Length > 0) roomFeeStr += roomFeestr1 + $"<span style='width:70px;display: inline-block;'></span>房费总金额:{roomTotal:#0.00}";
  6403. else roomFeeStr += " 0.00 * 0";
  6404. decimal governmentRentFee = 0.00M, cityTaxFee = 0.00M, breakfastFee = 0.00M, roomFee = 0.00M;
  6405. string governmentRentBool = "否", cityTaxBool = "否", breakfastBool = "否", roomBool = "否";
  6406. string governmentRentCode = "", governmentRentName = "", cityTaxCode = "", cityTaxName = "", breakfastCode = "", breakfastName = "", roomCode = "", roomName = "";
  6407. var _HotelReservationsContents1 = _HotelReservationsContents.Where(it => it.HrId == hotelReservations.Id).ToList();
  6408. /*
  6409. * 费用类型
  6410. * 1:房费
  6411. * 2:早餐
  6412. * 3:地税
  6413. * 4:城市税
  6414. * </summary>
  6415. */
  6416. //地税
  6417. var governmentRentData = _HotelReservationsContents1.Find(it => it.PriceType == 3);
  6418. if (governmentRentData != null)
  6419. {
  6420. governmentRentBool = governmentRentData.IsOppay == 1 ? "是" : "否";
  6421. governmentRentFee = governmentRentData.Price;
  6422. var governmentRentCurrData = currencyItems.Find(s => s.Id == governmentRentData.Currency);
  6423. if (governmentRentCurrData != null)
  6424. {
  6425. governmentRentCode = governmentRentCurrData.Name;
  6426. governmentRentName = $"({governmentRentCurrData.Remark})";
  6427. }
  6428. }
  6429. //城市税
  6430. var cityTaxData = _HotelReservationsContents1.Find(it => it.PriceType == 4);
  6431. if (cityTaxData != null)
  6432. {
  6433. cityTaxBool = cityTaxData.IsOppay == 1 ? "是" : "否";
  6434. cityTaxFee = cityTaxData.Price;
  6435. var cityTaxCurrData = currencyItems.Find(s => s.Id == cityTaxData.Currency);
  6436. if (cityTaxCurrData != null)
  6437. {
  6438. cityTaxCode = cityTaxCurrData.Name;
  6439. cityTaxName = $"({cityTaxCurrData.Remark})";
  6440. }
  6441. }
  6442. //酒店早餐
  6443. var breakfastData = _HotelReservationsContents1.Find(it => it.PriceType == 2);
  6444. if (breakfastData != null)
  6445. {
  6446. breakfastBool = breakfastData.IsOppay == 1 ? "是" : "否";
  6447. breakfastFee = breakfastData.Price;
  6448. var breakfastCurrData = currencyItems.Find(s => s.Id == breakfastData.Currency);
  6449. if (breakfastCurrData != null)
  6450. {
  6451. breakfastCode = breakfastCurrData.Name;
  6452. breakfastName = $"({breakfastCurrData.Remark})";
  6453. }
  6454. }
  6455. //房间费用
  6456. var roomData = _HotelReservationsContents1.Find(it => it.PriceType == 1);
  6457. if (roomData != null)
  6458. {
  6459. _detail.PayType = initDatas.Find(it => it.Id == roomData.PayDId)?.Name ?? "-";
  6460. if (_detail.PayType.Equals("现金")) _detail.CardType = "-";
  6461. else _detail.CardType = initDatas.Find(it => it.Id == roomData.CTDId)?.Name ?? "-";
  6462. roomBool = roomData.IsOppay == 1 ? "是" : "否";
  6463. roomFee = roomData.Price;
  6464. var roomCurrData = currencyItems.Find(s => s.Id == roomData.Currency);
  6465. if (roomCurrData != null)
  6466. {
  6467. roomCode = roomCurrData.Name;
  6468. roomName = $"({roomCurrData.Remark})";
  6469. }
  6470. }
  6471. string hotelCostTitalStr = "<span style='font-weight:800;'>成本信息</span><br/>";
  6472. string hotelCostStr = "";
  6473. decimal hotelCsotTotal = 0.00M;
  6474. if (groupCost != null)
  6475. {
  6476. if (int.TryParse(groupCost.Currency, out int currencyId)) groupCost.Currency = currencyItems.Find(s => s.Id == currencyId)?.Name ?? "-";
  6477. hotelCostStr += $"{groupCost.Currency}(汇率:{groupCost.Rate:#0.0000})<br/>";
  6478. }
  6479. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1);
  6480. var hotelCostDetails = groupCostDetails.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  6481. string hotelCost_day = "";
  6482. var hotelCostDetails1 = hotelCostDetails.GroupBy(x => x.Date);
  6483. foreach (var item in hotelCostDetails1)
  6484. {
  6485. hotelCsotTotal += item.Sum(x => x.HotelSingleRoomFee) + item.Sum(x => x.HotelDoubleRoomFee) + item.Sum(x => x.HotelSuiteRoomFee) + item.Sum(x => x.HotelSuiteFee);
  6486. hotelCost_day += @$"{item.First()?.Date ?? "-"}";
  6487. if (item.Sum(x => x.HotelSingleRoomFee) != 0) hotelCost_day += @$" 单间:{item.Sum(x => x.HotelSingleRoomFee):#0.00}";
  6488. //else { if (__isSingle) hotelCost_day += @$" 单间:0.00"; }
  6489. if (item.Sum(x => x.HotelDoubleRoomFee) != 0) hotelCost_day += @$" 双人间:{item.Sum(x => x.HotelDoubleRoomFee):#0.00}";
  6490. //else { if (__isDouble) hotelCost_day += @$" 双人间:0.00"; }
  6491. if (item.Sum(x => x.HotelSuiteRoomFee) != 0) hotelCost_day += @$" 小套房/豪华套房:{item.Sum(x => x.HotelSuiteRoomFee):#0.00}";
  6492. //else { if (__isSuite) hotelCost_day += @$" 小套房/豪华套房:0.00"; }
  6493. if (item.Sum(x => x.HotelSuiteFee) != 0) hotelCost_day += @$" 套房:{item.Sum(x => x.HotelSuiteFee):#0.00}";
  6494. //else { if (__isOther) hotelCost_day += @$" 套房:0.00"; }
  6495. hotelCost_day += @$"<br/>";
  6496. }
  6497. string hotelBreakfastStr = "", hotelGovernmentRentStr = "", hotelCityTaxStr = "";
  6498. if (breakfastFee > 0) hotelBreakfastStr = $"酒店早餐: {breakfastFee:#0.00} {breakfastCode} {breakfastName} 当时汇率 {breakfastData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{breakfastBool}<br/><br/>";
  6499. if (governmentRentFee > 0) hotelGovernmentRentStr = $"地税: {governmentRentFee:#0.00} {governmentRentCode} {governmentRentName} 当时汇率 {governmentRentData?.Rate:#0.0000} <br/>是否由地接或其他人代付:{governmentRentBool}<br/><br/>";
  6500. if (cityTaxFee > 0) hotelCityTaxStr = $"城市税: {cityTaxFee:#0.00} {cityTaxCode} {cityTaxName} 当时汇率 {cityTaxData?.Rate:#0.0000)} <br/>是否由地接或其他人代付:{cityTaxBool}<br/>";
  6501. string hotelCostTotalStr = "";// $"&nbsp;&nbsp;成本合计:{hotelCsotTotal.ToString("#0.00")}<br/>";
  6502. _detail.PriceMsgContent = $"{hotelCostTitalStr}{hotelCostStr}{hotelCostTotalStr}{hotelCost_day}<br/>" +
  6503. $"<span style='font-weight:800;'>{hotelReservations.HotelName} [{hotelReservations.CheckInDate} - {hotelReservations.CheckOutDate}]</span><br/>" +
  6504. $"酒店费用总额:{_detail.WaitPay} ({hotelCurrncyName})<br/>" +
  6505. $"房间说明: {hotelReservations.Remark} <br/>" +
  6506. $"房间费用: {roomCode} {roomName} 当时汇率:{roomData?.Rate.ToString("#0.0000")}{roomFeeStr} <br/>是否由地接或其他人代付:{roomBool}<br/><br/>" +
  6507. $"{hotelBreakfastStr}" +
  6508. $"{hotelGovernmentRentStr}" +
  6509. $"{hotelCityTaxStr}";
  6510. _detail.PriceNameContent = hotelReservations.HotelName;
  6511. }
  6512. break;
  6513. case 79://车/导游地接
  6514. Grp_CarTouristGuideGroundReservations touristGuideGroundReservations = _CarTouristGuideGroundReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6515. if (touristGuideGroundReservations != null)
  6516. {
  6517. if (!string.IsNullOrEmpty(touristGuideGroundReservations.BusName))
  6518. {
  6519. _detail.BusName = touristGuideGroundReservations.BusName;
  6520. }
  6521. _detail.PriceNameContent = touristGuideGroundReservations.PriceName;
  6522. //bool isInt = int.TryParse(touristGuideGroundReservations.Area, out int cityId);
  6523. //if (isInt)
  6524. //{
  6525. // var cityInfo = cityData.Find(it => it.Id == cityId);
  6526. // if (cityInfo != null)
  6527. // {
  6528. // string nameContent = $@"{cityInfo.Country}-{cityInfo.City}";
  6529. // var carFeeItem = carFeeItems.Find(it => it.Id == touristGuideGroundReservations.PriceType);
  6530. // if (carFeeItem != null)
  6531. // {
  6532. // nameContent += $@"({carFeeItem.Name})";
  6533. // }
  6534. // _detail.PriceNameContent = nameContent;
  6535. // }
  6536. //}
  6537. //else
  6538. //{
  6539. // _detail.PriceNameContent = touristGuideGroundReservations.Area;
  6540. //}
  6541. var touristGuideGroundReservationsContents =
  6542. _CarTouristGuideGroundReservationsContent.Where(s => s.CTGGRId == touristGuideGroundReservations.Id && s.IsDel == 0 && s.Price != 0).ToList();
  6543. var opContent_sb = new StringBuilder();
  6544. string contetTitle = $"<span style='font-weight:800;'>{touristGuideGroundReservations.PriceName}({touristGuideGroundReservations.ServiceStartTime} - {touristGuideGroundReservations.ServiceEndTime})</span><br/>";
  6545. opContent_sb.AppendLine(contetTitle);
  6546. foreach (var item in touristGuideGroundReservationsContents)
  6547. {
  6548. string typeName = "Unknown";
  6549. string carCurrencyCode = "Unknown";
  6550. string carCurrencyName = "Unknown";
  6551. var carTypeData = carFeeTypeItems.Where(s => s.Id == item.SId && s.IsDel == 0).FirstOrDefault();
  6552. if (carTypeData != null) typeName = carTypeData.Name;
  6553. var currencyData = currencyItems.Where(s => s.Id == item.Currency && s.IsDel == 0).FirstOrDefault();
  6554. if (currencyData != null)
  6555. {
  6556. carCurrencyCode = currencyData.Name;
  6557. carCurrencyName = currencyData.Remark;
  6558. }
  6559. //op、成本 币种是否一致 (币种一致只比较金额:2025-04-18)
  6560. bool IsCurrencyAgreement = false;
  6561. if (carCurrencyCode.Equals(_groupCurrencyCode)) IsCurrencyAgreement = true;
  6562. string opCostStr = string.Empty;
  6563. decimal opCostTypePrice = 0.00M;
  6564. #region 处理成本各项费用
  6565. var opDate = item.DatePrice?.ToString("yyyy-MM-dd");
  6566. var opCost = groupCostDetails.Where(x => x.Date.Equals(opDate)).ToList();
  6567. decimal aduitOPFeeCNY = 0.00M, //费用审核 op费用
  6568. costOPFeeCNY = 0.00M, //团组成本 op费用
  6569. opPayPercentage = entity.PayPercentage == 0.00M ? 1.00M : entity.PayPercentage / 100M; //费用审核 op付款百分比
  6570. if (opCost.Count > 0)
  6571. {
  6572. switch (item.SId)
  6573. {
  6574. case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //91车费
  6575. //case 982: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //982 车超时费 -- 暂无
  6576. case 92: opCostTypePrice = opCost.Sum(x => x.GuideFee); break; //92 导游费
  6577. case 94: opCostTypePrice = opCost.Sum(x => x.GuideScenicFee); break; //94 导游景点费
  6578. case 95: opCostTypePrice = opCost.Sum(x => x.GuideTipFee); break; //95 导游小费
  6579. case 983: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //983 导游餐补
  6580. case 984: opCostTypePrice = opCost.Sum(x => x.GuideMealFee); break; //984 导游房补
  6581. case 985: opCostTypePrice = opCost.Sum(x => x.GuideRoomFee); break; //985 导游交通
  6582. //case 96: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //96 接送机费 -- 暂无
  6583. //case 97: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //97 其他费用 -- 暂无
  6584. case 979: opCostTypePrice = opCost.Sum(x => x.DriverFee); break; //979 司机工资
  6585. case 980: opCostTypePrice = opCost.Sum(x => x.DriverTipFee); break; //980 司机小费
  6586. case 981: opCostTypePrice = opCost.Sum(x => x.DriverMealFee); break; //981 司机餐补
  6587. case 988: opCostTypePrice = opCost.Sum(x => x.ClientBreakfastFee); break; //988 客户早餐费用
  6588. case 93: opCostTypePrice = opCost.Sum(x => x.ClientDinnerFee); break; //93 客户午餐费用
  6589. case 989: opCostTypePrice = opCost.Sum(x => x.ClientLunchFee); break; //989 客户晚餐费用
  6590. case 990: opCostTypePrice = opCost.Sum(x => x.ScenicTicketFee); break; //990 景点门票费
  6591. case 991: opCostTypePrice = opCost.Sum(x => x.DrinkSnackFruitFee); break; //991 饮料/零食/水果
  6592. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //992 住补费用 -- 暂无
  6593. case 994: opCostTypePrice = opCost.Sum(x => x.TranslatorFee); break; //994 翻译费
  6594. case 1059: opCostTypePrice = opCost.Sum(x => x.GuideOverTimeFee); break; //1059 导游超时费用
  6595. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1070 尾款金额
  6596. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1071 其他额外费用
  6597. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1073 翻译超时费
  6598. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1074 早餐超支费用
  6599. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1075 午餐超支费用
  6600. //case 91: opCostTypePrice = opCost.Sum(x => x.CarFee); break; //1076 晚餐超支费用
  6601. }
  6602. opCostStr = $"&nbsp;&nbsp;/&nbsp;&nbsp;成本:{opCostTypePrice:#0.00} {_groupCurrencyCode}(汇率:{_groupRate:#0.0000})";
  6603. costOPFeeCNY = opCostTypePrice * _groupRate;
  6604. if (!IsCurrencyAgreement) opCostStr += $" ≈ {costOPFeeCNY:#0.00} CNY";
  6605. }
  6606. #endregion
  6607. string opTypeStr = $"{typeName}:{item.Price:#0.00} {carCurrencyCode}(汇率:{entity.DayRate:#0.0000})";
  6608. aduitOPFeeCNY = item.Price * entity.DayRate;
  6609. if (!IsCurrencyAgreement) opTypeStr += $" ≈ {aduitOPFeeCNY:#0.0000} CNY";
  6610. var opContent = $"日期:{item.DatePrice?.ToString("yyyy-MM-dd") ?? "-"}<br/>" +
  6611. $"{opTypeStr} {opCostStr}<br/>" +
  6612. $"明细:{item.PriceContent ?? "-"}<br/>" +
  6613. $"备注:{item.Remark ?? "-"}<br/><br/>";
  6614. if (entity.IsAuditGM != 3) //状态 != 自动审核
  6615. {
  6616. if (IsCurrencyAgreement)
  6617. {
  6618. if (item.Price > opCostTypePrice)
  6619. {
  6620. opContent_sb.Append("<span style='color:red;'>");
  6621. opContent_sb.Append(opContent);
  6622. opContent_sb.Append("</span>");
  6623. opContent_sb.AppendLine();
  6624. }
  6625. else
  6626. {
  6627. opContent_sb.Append(opContent);
  6628. opContent_sb.AppendLine();
  6629. }
  6630. }
  6631. else
  6632. {
  6633. //验证是否超成本 按付款比例计算
  6634. if (aduitOPFeeCNY * opPayPercentage > costOPFeeCNY * opPayPercentage)
  6635. {
  6636. opContent_sb.Append("<span style='color:red;'>");
  6637. opContent_sb.Append(opContent);
  6638. opContent_sb.Append("</span>");
  6639. opContent_sb.AppendLine();
  6640. }
  6641. else
  6642. {
  6643. opContent_sb.Append(opContent);
  6644. opContent_sb.AppendLine();
  6645. }
  6646. }
  6647. }
  6648. else
  6649. {
  6650. opContent_sb.Append(opContent);
  6651. opContent_sb.AppendLine();
  6652. }
  6653. }
  6654. _detail.PriceMsgContent = opContent_sb.ToString();
  6655. }
  6656. break;
  6657. case 80: //签证
  6658. Grp_VisaInfo visaInfo = _VisaInfos.Where(s => s.Id == entity.CId).FirstOrDefault();
  6659. if (visaInfo != null)
  6660. {
  6661. string visaName = GetClientNameStr1(clientNameList, visaInfo.VisaClient);
  6662. _detail.PriceNameContent = visaInfo.VisaDescription;
  6663. _detail.PriceMsgContent = $"签证描述:{visaName}<br/> 备注:{visaInfo.Remark}";
  6664. }
  6665. break;
  6666. case 81: //邀请/公务活动
  6667. Grp_InvitationOfficialActivities _ioa = _InvitationOfficialActivities.Where(s => s.Id == entity.CId).FirstOrDefault();
  6668. if (_ioa != null)
  6669. {
  6670. string inviteCurrName = "Unknown", //邀请费用币种 Name
  6671. inviteCurrCode = "Unknown", //邀请费用币种 Code
  6672. sendCurrName = "Unknown", //快递费用币种 Name
  6673. sendCurrCode = "Unknown", //快递费用币种 Code
  6674. eventsCurrName = "Unknown", //公务活动费币种 Name
  6675. eventsCurrCode = "Unknown", //公务活动费币种 Code
  6676. translateCurrName = "Unknown", //公务翻译费 Name
  6677. translateCurrCode = "Unknown"; //公务翻译费 Code
  6678. #region 处理费用币种
  6679. var inviteCurrData = currencyItems.Where(s => s.Id == _ioa.InviteCurrency && s.IsDel == 0).FirstOrDefault();
  6680. if (inviteCurrData != null)
  6681. {
  6682. inviteCurrName = inviteCurrData.Remark;
  6683. inviteCurrCode = inviteCurrData.Name;
  6684. }
  6685. var sendCurrData = currencyItems.Where(s => s.Id == _ioa.SendCurrency && s.IsDel == 0).FirstOrDefault();
  6686. if (sendCurrData != null)
  6687. {
  6688. sendCurrName = sendCurrData.Remark;
  6689. sendCurrCode = sendCurrData.Name;
  6690. }
  6691. var eventsCurrData = currencyItems.Where(s => s.Id == _ioa.EventsCurrency && s.IsDel == 0).FirstOrDefault();
  6692. if (eventsCurrData != null)
  6693. {
  6694. eventsCurrName = eventsCurrData.Remark;
  6695. eventsCurrCode = eventsCurrData.Name;
  6696. }
  6697. var translateCurrData = currencyItems.Where(s => s.Id == _ioa.TranslateCurrency && s.IsDel == 0).FirstOrDefault();
  6698. if (translateCurrData != null)
  6699. {
  6700. translateCurrName = translateCurrData.Remark;
  6701. translateCurrCode = translateCurrData.Name;
  6702. }
  6703. #endregion
  6704. _detail.PriceNameContent = _ioa.InviterArea;
  6705. //2025-09-08 商邀费用名称更改:单项费用不等于0,则在名称后面最加费用类型名称。
  6706. List<string> priceExpNames = new List<string>();
  6707. if (_ioa.InviteCost != 0.00M) priceExpNames.Add("邀请费");
  6708. if (_ioa.SendCost != 0.00M) priceExpNames.Add("快递费");
  6709. if (_ioa.EventsCost != 0.00M) priceExpNames.Add("公务活动费");
  6710. if (_ioa.TranslateCost != 0.00M) priceExpNames.Add("公务翻译费");
  6711. if (priceExpNames != null && priceExpNames.Count > 0)
  6712. {
  6713. _detail.PriceNameContent += $"({string.Join("+", priceExpNames)})";
  6714. }
  6715. _detail.PriceMsgContent = $@"邀请费用:{_ioa.InviteCost:#0.00} {inviteCurrCode}({inviteCurrName})<br/>" +
  6716. $@"快递费用:{_ioa.SendCost:#0.00} {sendCurrCode}({sendCurrName})<br/>" +
  6717. $@"公务活动费:{_ioa.EventsCost:#0.00} {eventsCurrCode}({eventsCurrName})<br/>" +
  6718. $@"公务翻译费:{_ioa.TranslateCost:#0.00} {translateCurrCode}({translateCurrName})<br/>" +
  6719. $@"备注:" + _ioa.Remark + "<br/>";
  6720. }
  6721. break;
  6722. case 82: //团组客户保险
  6723. Grp_Customers customers = _Customers.Where(s => s.Id == entity.CId && s.IsDel == 0).FirstOrDefault();
  6724. if (customers != null)
  6725. {
  6726. _detail.PriceNameContent = GetClientNameStr(clientNameList, customers.ClientName);
  6727. _detail.PriceMsgContent = "备注:" + customers.Remark + "<br/>";
  6728. }
  6729. break;
  6730. case 85: //机票预订
  6731. Grp_AirTicketReservations jpRes = _AirTicketReservations.Where(s => s.Id == entity.CId).FirstOrDefault();
  6732. if (jpRes != null)
  6733. {
  6734. string FlightsDescription = jpRes.FlightsDescription;
  6735. string PriceDescription = jpRes.PriceDescription;
  6736. _detail.PriceMsgContent = "航班号:" + jpRes.FlightsCode + "<br/>城市A-B:" + jpRes.FlightsCity + "<br/>航班描述:" + FlightsDescription.Replace("\r\n", "<br />") + "<br/>" + "价格描述:" + PriceDescription;
  6737. _detail.PriceNameContent = "(" + jpRes.FlightsCode + ")";
  6738. }
  6739. break;
  6740. case 98://其他款项
  6741. Grp_DecreasePayments gdpRes = _DecreasePayments.Where(s => s.Id == entity.CId).FirstOrDefault();
  6742. if (gdpRes != null)
  6743. {
  6744. //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/";
  6745. //if (!string.IsNullOrEmpty(gdpRes.FilePath))
  6746. //{
  6747. // _detail.FileUrl = $"{urlBase}{gdpRes.FilePath}";
  6748. //}
  6749. _detail.PriceMsgContent = "备注:" + gdpRes.Remark;
  6750. _detail.PriceNameContent = gdpRes.PriceName;
  6751. }
  6752. break;
  6753. case 285://收款退还
  6754. Fin_PaymentRefundAndOtherMoney refundAndOtherMoney = _PaymentRefundAndOtherMoneys.Where(s => s.Id == entity.CId).FirstOrDefault();
  6755. if (refundAndOtherMoney != null)
  6756. {
  6757. _detail.PriceMsgContent = "备注:" + refundAndOtherMoney.Remark;
  6758. _detail.PriceNameContent = refundAndOtherMoney.PriceName;
  6759. }
  6760. break;
  6761. case 751://酒店早餐
  6762. break;
  6763. case 1015://超支费用
  6764. Fin_GroupExtraCost groupExtraCost = _GroupExtraCosts.Where(s => s.Id == entity.CId).FirstOrDefault();
  6765. if (groupExtraCost != null)
  6766. {
  6767. _detail.PriceNameContent = groupExtraCost.PriceName;
  6768. _detail.PriceMsgContent = "备注:" + groupExtraCost.Remark;
  6769. }
  6770. break;
  6771. default:
  6772. break;
  6773. }
  6774. /*
  6775. * 申请人
  6776. */
  6777. string operatorName = " - ";
  6778. var _opUser = userItems.Where(s => s.Id == entity.CreateUserId).FirstOrDefault();
  6779. if (_opUser != null)
  6780. {
  6781. operatorName = _opUser.CnName;
  6782. }
  6783. _detail.OperatorName = operatorName;
  6784. /*
  6785. * 审核人
  6786. */
  6787. string auditOperatorName = " - ";
  6788. if (entity.IsAuditGM != 0)
  6789. {
  6790. if (entity.AuditGMOperate == 0) auditOperatorName = " - ";
  6791. else if (entity.AuditGMOperate == 4) auditOperatorName = "自动审核";
  6792. else
  6793. {
  6794. var _adUser = userItems.Where(s => s.Id == entity.AuditGMOperate).FirstOrDefault();
  6795. if (_adUser != null)
  6796. {
  6797. auditOperatorName = _adUser.CnName;
  6798. }
  6799. }
  6800. }
  6801. _detail.AuditOperatorName = auditOperatorName;
  6802. /*
  6803. * 超预算比例
  6804. */
  6805. string overBudgetStr = "";
  6806. if (entity.ExceedBudget == -1) overBudgetStr = sdPriceName.Name + "尚无预算";
  6807. else if (entity.ExceedBudget == 0)
  6808. {
  6809. if (entity.CTable == 76 || entity.CTable == 79)
  6810. {
  6811. if (entity.IsAuditGM == 3) overBudgetStr = "未超预算";
  6812. else overBudgetStr = _feeAuditRep.IsOverBudget(entity.CTable, entity.DIId, entity.CId);
  6813. }
  6814. else
  6815. {
  6816. overBudgetStr = "未超预算";
  6817. }
  6818. }
  6819. else overBudgetStr = entity.ExceedBudget.ToString("P");
  6820. _detail.OverBudget = overBudgetStr;
  6821. decimal auditFee = 0.00M; //已审核金额 人名币
  6822. decimal auditedFeeOriginal = 0.00M; ////已审核金额 原始
  6823. decimal unAuditFeeCNY = 0.00M; //未审核款项 原始
  6824. decimal unAuditFeeOriginal = 0.00M; //未审核款项 人名币
  6825. if (entity.IsAuditGM == 1 || entity.IsAuditGM == 3)
  6826. {
  6827. auditedFeeOriginal = entity.PayMoney;
  6828. auditFee = CurrPayStr;
  6829. }
  6830. else if (entity.IsAuditGM == 0)
  6831. {
  6832. unAuditFeeCNY = CurrPayStr;
  6833. unAuditFeeOriginal = OriginalCurrPay;
  6834. OriginalCurrPay = 0.00M;
  6835. }
  6836. /*
  6837. * 费用总计
  6838. */
  6839. ccpCurrencyPrices.Add(new CreditCardPaymentCurrencyPriceItem()
  6840. {
  6841. CurrencyId = entity.PaymentCurrency,
  6842. CurrencyName = PaymentCurrency_WaitPay,
  6843. AmountPayable = entity.PayMoney,
  6844. ThisPayment = OriginalCurrPay,
  6845. BalancePayment = BalanceStr,
  6846. AuditedFunds = auditFee,
  6847. AuditedFundsOriginal = auditedFeeOriginal,
  6848. UnAuditFundsCNY = unAuditFeeCNY,
  6849. UnAuditFundsOriginal = unAuditFeeOriginal
  6850. });
  6851. _detail.IsAuditGM = entity.IsAuditGM;
  6852. detailList.Add(_detail);
  6853. }
  6854. #endregion
  6855. _view.DetailList = new List<Grp_CreditCardPaymentDetailView>(detailList);
  6856. /*
  6857. * 下方描述处理
  6858. */
  6859. var nonDuplicat = ccpCurrencyPrices.Where((x, i) => ccpCurrencyPrices.FindIndex(z => z.CurrencyId == x.CurrencyId) == i).ToList();//Lambda表达式去重
  6860. var ccpCurrencyPrice = nonDuplicat.Where(it => it.CurrencyId == 836).FirstOrDefault();
  6861. if (ccpCurrencyPrice != null)
  6862. {
  6863. int CNYIndex = nonDuplicat.IndexOf(ccpCurrencyPrice);
  6864. nonDuplicat.MoveItemAtIndexToFront(CNYIndex);
  6865. }
  6866. else
  6867. {
  6868. nonDuplicat = nonDuplicat.OrderBy(it => it.CurrencyId).ToList();
  6869. }
  6870. string amountPayableStr = string.Format(@"应付款总金额: ");
  6871. string thisPaymentStr = string.Format(@"此次付款总金额: ");
  6872. string balancePaymentStr = string.Format(@"目前剩余尾款总金额: ");
  6873. string auditedFundsStr = string.Format(@"已审费用总额: ");
  6874. string unAuditedFundsStr = string.Format(@"未审费用总额: ");
  6875. foreach (var item in nonDuplicat)
  6876. {
  6877. var currencyName = item.CurrencyName;
  6878. var strs = ccpCurrencyPrices.Where(it => it.CurrencyId == item.CurrencyId).ToList();
  6879. if (strs.Count > 0)
  6880. {
  6881. decimal amountPayable = strs.Sum(it => it.AmountPayable);
  6882. decimal thisPayment = ccpCurrencyPrices.Sum(it => it.ThisPayment);
  6883. decimal balancePayment = strs.Sum(it => it.BalancePayment);
  6884. amountPayableStr += string.Format(@"{0}{1}&nbsp;|", amountPayable.ToString("#0.00"), currencyName);
  6885. //单独处理此次付款金额
  6886. thisPaymentStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  6887. balancePaymentStr += string.Format(@"{0}{1}&nbsp;|", balancePayment.ToString("#0.00"), currencyName);
  6888. //单独处理已审核费用
  6889. //if (item.CurrencyId == 836) //人民币
  6890. //{
  6891. // decimal auditedFunds = ccpCurrencyPrices.Sum(it => it.AuditedFunds);
  6892. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", auditedFunds.ToString("#0.00"), currencyName);
  6893. //}
  6894. //else
  6895. //{
  6896. // auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.AmountPayable), currencyName);
  6897. //}
  6898. if (currencyName.Equals("CNY"))
  6899. {
  6900. //已审核费用
  6901. auditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.ThisPayment).ToString("#0.00"), currencyName);
  6902. //未审核费用
  6903. unAuditedFundsStr += string.Format(@"{0}{1}&nbsp;|", strs.Sum(x => x.UnAuditFundsOriginal).ToString("#0.00"), currencyName);
  6904. }
  6905. else
  6906. {
  6907. //已审核费用
  6908. 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"));
  6909. //未审核费用
  6910. 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"));
  6911. }
  6912. }
  6913. }
  6914. _view.TotalStr1 = amountPayableStr[..^1];
  6915. _view.TotalStr2 = thisPaymentStr[..^1];
  6916. _view.TotalStr3 = balancePaymentStr[..^1];
  6917. _view.TotalStr4 = $"{auditedFundsStr[..^1]}<br/>{unAuditedFundsStr[..^1]}";
  6918. //_view.TotalStr5 = unAuditedFundsStr.Substring(0, unAuditedFundsStr.Length - 1);
  6919. var _view1 = new
  6920. {
  6921. PageFuncAuth = pageFunAuthView,
  6922. Data = _view
  6923. };
  6924. return Ok(JsonView(_view1));
  6925. }
  6926. catch (Exception ex)
  6927. {
  6928. return Ok(JsonView(false, ex.Message));
  6929. }
  6930. }
  6931. /// <summary>
  6932. /// 费用审核
  6933. /// 修改团组费用审核状态
  6934. /// </summary>
  6935. /// <param name="_dto">参数Json字符串</param>
  6936. /// <returns></returns>
  6937. [HttpPost]
  6938. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  6939. public async Task<IActionResult> PostAuditGrpCreditCardPayment(Edit_GrpCreditCardPaymentDto _dto)
  6940. {
  6941. #region 参数验证
  6942. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  6943. if (_dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  6944. #endregion
  6945. #region 页面操作权限验证
  6946. var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  6947. if (pageFunAuthView.AuditAuth == 0) return Ok(JsonView(false, "您没有审核权限"));
  6948. #endregion
  6949. List<string> idList = _dto.CreditIdStr.Split(',').ToList();
  6950. Grp_CreditCardPayment _detail = _mapper.Map<Grp_CreditCardPayment>(_dto);
  6951. DateTime dtNow = DateTime.Now;
  6952. _groupRepository.BeginTran();
  6953. int rst = 0;
  6954. var creditDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && idList.Contains(it.Id.ToString())).ToList();
  6955. var creditTypeDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  6956. var creditCurrencyDatas = _grpScheduleRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  6957. var groupDatas = _grpScheduleRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).ToList();
  6958. var msgDatas = new List<dynamic>();
  6959. var dic_ccp_user = new Dictionary<int, int>() { };
  6960. foreach (var item in idList)
  6961. {
  6962. int CreditId = int.Parse(item);
  6963. var result = await _grpScheduleRep._sqlSugar.Updateable<Grp_CreditCardPayment>()
  6964. .SetColumns(it => it.IsAuditGM == _dto.AuditCode)
  6965. .SetColumns(it => it.AuditGMOperate == _dto.UserId)
  6966. .SetColumns(it => it.AuditGMDate == dtNow.ToString("yyyy-MM-dd HH:mm:ss"))
  6967. .Where(s => s.Id == CreditId)
  6968. .ExecuteCommandAsync();
  6969. if (result < 1)
  6970. {
  6971. rst = -1;
  6972. _groupRepository.RollbackTran();
  6973. return Ok(JsonView(false, "操作失败并回滚!"));
  6974. }
  6975. var creditData = creditDatas.Where(it => it.Id == CreditId).FirstOrDefault();
  6976. if (creditData != null)
  6977. {
  6978. #region 应用通知配置
  6979. try
  6980. {
  6981. dic_ccp_user.Add(creditData.Id, creditData.CreateUserId);
  6982. }
  6983. catch (Exception ex)
  6984. {
  6985. }
  6986. #endregion
  6987. string auditStr = _dto.AuditCode == 1 ? "已通过" : _dto.AuditCode == 2 ? "未通过" : "未审核";
  6988. string groupNameStr = string.Empty;
  6989. var groupData = groupDatas.Where(it => it.Id == creditData.DIId).FirstOrDefault();
  6990. if (groupData != null) groupNameStr = groupData.TeamName;
  6991. string creditTypeStr = string.Empty;
  6992. var creditTypeData = creditTypeDatas.Where(it => it.Id == creditData.CTable).FirstOrDefault();
  6993. if (creditTypeData != null) creditTypeStr = creditTypeData.Name;
  6994. string creditCurrency = string.Empty;
  6995. var creditCurrencyData = creditCurrencyDatas.Where(it => it.Id == creditData.PaymentCurrency).FirstOrDefault();
  6996. if (creditCurrencyData != null) creditCurrency = creditCurrencyData.Name;
  6997. if (creditCurrency.Equals("CNY"))
  6998. {
  6999. creditData.DayRate = 1.0000M;
  7000. }
  7001. if (creditData.PayPercentage == 0.00M)
  7002. {
  7003. creditData.PayPercentage = 100M;
  7004. }
  7005. decimal CNYPrice = (creditData.PayMoney * (creditData.PayPercentage / 100)) * creditData.DayRate;
  7006. string msgTitle = $"[{groupNameStr}({creditTypeStr})]的费用申请";
  7007. string msgContent = "";
  7008. if (creditCurrency.Equals("CNY"))
  7009. {
  7010. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY) {auditStr}!";
  7011. }
  7012. else
  7013. {
  7014. msgContent = $"[{groupNameStr}({creditTypeStr})]费用申请(金额:{CNYPrice:0.00} CNY({creditData.PayMoney:0.00} {creditCurrency})) {auditStr}!";
  7015. }
  7016. msgDatas.Add(new { DiId = creditData.DIId, UserId = creditData.CreateUserId, MsgTitle = msgTitle, MsgContent = msgContent });
  7017. }
  7018. }
  7019. if (rst == 0)
  7020. {
  7021. _groupRepository.CommitTran();
  7022. foreach (var item in msgDatas)
  7023. {
  7024. //发送消息
  7025. GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupExpenseAudit, item.MsgTitle, item.MsgContent, new List<int>() { item.UserId }, item.DiId);
  7026. }
  7027. #region 应用推送
  7028. try
  7029. {
  7030. foreach (var ccpId in dic_ccp_user.Keys)
  7031. {
  7032. var templist = new List<string>() { dic_ccp_user[ccpId].ToString() };
  7033. await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(ccpId, templist, QiyeWeChatEnum.CaiWuChat);
  7034. }
  7035. }
  7036. catch (Exception)
  7037. {
  7038. }
  7039. #endregion
  7040. return Ok(JsonView(true, "操作成功!"));
  7041. }
  7042. return Ok(JsonView(false, "操作失败!"));
  7043. }
  7044. /// <summary>
  7045. /// 费用审核
  7046. /// 其他款项 文件下载
  7047. /// </summary>
  7048. /// <param name="id">其他款项 主键编号</param>
  7049. /// <returns></returns>
  7050. [HttpGet("{id}")]
  7051. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7052. public async Task<IActionResult> FeeAuditOtherFileDownlaod([Range(1, int.MaxValue, ErrorMessage = "请传入有效的ID")] int id)
  7053. {
  7054. //网站域名
  7055. 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/";
  7056. var otherInfo = await _decreasePaymentsRep._sqlSugar
  7057. .Queryable<Grp_DecreasePayments>()
  7058. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.Id == id)
  7059. .Where(((x, y) => x.IsDel == 0 && y.IsDel == 0))
  7060. .Select((x, y) => new
  7061. {
  7062. x.Id,
  7063. x.FilePath
  7064. })
  7065. .FirstAsync();
  7066. if (otherInfo != null && !string.IsNullOrEmpty(otherInfo.FilePath.Trim()))
  7067. {
  7068. var url = $"{baseUrl}{otherInfo.FilePath}";
  7069. return Ok(JsonView(true, "操作成功!", url));
  7070. }
  7071. return Ok(JsonView(false, "暂无附件"));
  7072. }
  7073. #endregion
  7074. #region 机票费用录入
  7075. /// <summary>
  7076. /// 机票录入当前登录人可操作团组
  7077. /// </summary>
  7078. /// <param name="dto"></param>
  7079. /// <returns></returns>
  7080. [HttpPost]
  7081. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7082. public async Task<IActionResult> AirTicketResSelect(AirTicketResDto dto)
  7083. {
  7084. try
  7085. {
  7086. Result groupData = await _airTicketResRep.AirTicketResSelect(dto);
  7087. if (groupData.Code != 0)
  7088. {
  7089. return Ok(JsonView(false, groupData.Msg));
  7090. }
  7091. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7092. }
  7093. catch (Exception ex)
  7094. {
  7095. return Ok(JsonView(false, ex.Message));
  7096. }
  7097. }
  7098. /// <summary>
  7099. /// 机票费用录入列表
  7100. /// </summary>
  7101. /// <param name="dto"></param>
  7102. /// <returns></returns>
  7103. [HttpPost]
  7104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7105. public async Task<IActionResult> AirTicketResList(AirTicketResDto dto)
  7106. {
  7107. try
  7108. {
  7109. Result groupData = await _airTicketResRep.AirTicketResList(dto);
  7110. if (groupData.Code != 0)
  7111. {
  7112. return Ok(JsonView(false, groupData.Msg));
  7113. }
  7114. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7115. }
  7116. catch (Exception ex)
  7117. {
  7118. return Ok(JsonView(false, ex.Message));
  7119. throw;
  7120. }
  7121. }
  7122. /// <summary>
  7123. /// 根据id查询费用录入信息
  7124. /// </summary>
  7125. /// <param name="dto"></param>
  7126. /// <returns></returns>
  7127. [HttpPost]
  7128. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7129. public async Task<IActionResult> AirTicketResById(AirTicketResByIdDto dto)
  7130. {
  7131. Result groupData = await _airTicketResRep.AirTicketResById(dto);
  7132. if (groupData.Code != 0)
  7133. {
  7134. return Ok(JsonView(false, groupData.Msg));
  7135. }
  7136. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7137. }
  7138. /// <summary>
  7139. /// 机票费用录入操作(Status:1.新增,2.修改)
  7140. /// </summary>
  7141. /// <param name="dto"></param>
  7142. /// <returns></returns>
  7143. [HttpPost]
  7144. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7145. public async Task<IActionResult> OpAirTicketRes(AirTicketResOpDto dto)
  7146. {
  7147. //验证
  7148. if (dto.Status == 2)
  7149. {
  7150. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.AirTicketResOpData.Id, 85);
  7151. if (!valid) return Ok(JsonView(false, msg));
  7152. }
  7153. Result groupData = await _airTicketResRep.OpAirTicketRes(dto, _setDataRep.PostCurrencyByDiid);
  7154. if (groupData.Code != 0)
  7155. {
  7156. return Ok(JsonView(false, groupData.Msg));
  7157. }
  7158. #region 应用推送
  7159. try
  7160. {
  7161. var diId = dto.AirTicketResOpData.DiId;
  7162. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  7163. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  7164. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  7165. //自动审核
  7166. //var autoAdit1 = await _feeAuditRep.FeeAutomaticAudit(5, diId, dataId); //机票费用合计方式
  7167. (bool status, string auditMsg) = await AirTicketResAutoAudit(diId, dataId); //KIMI-AI识别INIT方式
  7168. _logger.LogInformation("【机票费用自动审核(KIMI-AI识别INIT)】请求参数:{RequstData} 返回结果:是否执行:{IsExecute}; 结果消息:{ResponseMsg};",
  7169. $"GroupId:{diId};airId:{dataId};",
  7170. status,
  7171. auditMsg);
  7172. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  7173. //2024-10-21 新增LZ UID
  7174. var userIds = new List<int>() { 21 };
  7175. string title = $"系统通知";
  7176. string content = "";
  7177. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  7178. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  7179. if (dto.Status == 1) content = $"[新增-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  7180. else if (dto.Status == 2) content = $"[更新-机票费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  7181. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  7182. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "85" };
  7183. await APNsTools.iOS_PushNotifications1("051", $"机票费用审核", "", content, true, "ExpenseAuditWebView", h5);
  7184. }
  7185. catch (Exception ex)
  7186. {
  7187. }
  7188. #endregion
  7189. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  7190. }
  7191. /// <summary>
  7192. /// 机票费用自动审核 AI识别方式
  7193. /// </summary>
  7194. /// <returns></returns>
  7195. private async Task<(bool, string)> AirTicketResAutoAudit(int diId, int dataId)
  7196. {
  7197. var ecoTypeIds = new List<int>() {
  7198. 459, //超经舱
  7199. 460, //经济舱
  7200. 1430, //公务舱(实际经济舱)
  7201. 1432, //头等舱(实际经济舱)
  7202. };
  7203. var bizTypeIds = new List<int>() {
  7204. 457, //头等舱
  7205. 458, //公务舱
  7206. 1431, //头等舱(实际公务舱)
  7207. };
  7208. var auditFeeTypeIds = new List<int>() { };
  7209. auditFeeTypeIds.AddRange(ecoTypeIds);
  7210. auditFeeTypeIds.AddRange(bizTypeIds);
  7211. int currModule = 85;
  7212. var airInfo = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  7213. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == currModule && y.IsDel == 0)
  7214. .Where((x, y) => x.Id == dataId && x.IsDel == 0 && auditFeeTypeIds.Contains(x.CType))
  7215. .Select((x, y) => new
  7216. {
  7217. x.Id,
  7218. CcpId = y.Id,
  7219. x.FlightsDate,
  7220. x.PrePrice,
  7221. x.CType,
  7222. x.ClientNum,
  7223. x.DIId
  7224. })
  7225. .FirstAsync();
  7226. if (airInfo == null) return (false, "机票信息为空或费用类型不在自动审核范围内,不可自动审核!");
  7227. var groupDetails = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == diId);
  7228. if (groupDetails == null) return (false, "团组信息为空,不可自动审核!");
  7229. var groupCostInfo = await _sqlSugar.Queryable<Grp_GroupCostParameter>().FirstAsync(x => x.IsDel == 0 && x.DiId == diId);
  7230. if (groupCostInfo == null) return (false, "团组成本信息未填写!");
  7231. var groupCostContents = await _sqlSugar
  7232. .SqlQueryable<GroupCostAuditView>($"Select * From Grp_GroupCost")
  7233. .Where(x => x.IsDel == 0 && x.Diid == diId)
  7234. .ToListAsync();
  7235. if (groupCostContents.Count < 1) return (false, "团组成本信息未填写!");
  7236. //处理 成本详细信息日期为空 填装费用信息
  7237. var airFeeLabel = new StringBuilder();
  7238. airFeeLabel.AppendLine("费用成本:");
  7239. for (int i = 0; i < groupCostContents.Count; i++)
  7240. {
  7241. if (string.IsNullOrEmpty(groupCostContents[i].Date))
  7242. {
  7243. int index = i - 1;
  7244. if (index >= 0)
  7245. {
  7246. groupCostContents[i].Date = groupCostContents[index].Date;
  7247. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  7248. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  7249. }
  7250. }
  7251. else
  7252. {
  7253. var dtBool = DateTime.TryParse(groupCostContents[i].Date, out DateTime _dateTime);
  7254. if (dtBool) groupCostContents[i].CurrTime = _dateTime;
  7255. }
  7256. var item = groupCostContents[i];
  7257. airFeeLabel.AppendLine($"{item.Date}");
  7258. airFeeLabel.AppendLine($"{item.ITIN.Replace("\n", " ")}");
  7259. }
  7260. airFeeLabel.AppendLine($"注:费用:位置:航班号或者航班时间后面; 组成:经济舱/公务舱;");
  7261. airFeeLabel.AppendLine($"取出“{airInfo.FlightsDate}”费用金额,按照经济舱/公务舱格式返回,如果不存在的话则返回0.00/0.00,只返回金额格式文本;不需要其他文字描述;");
  7262. //访问Kimi AI 返回价格结果
  7263. var msgs = new List<SeedMessages>()
  7264. {
  7265. new ()
  7266. {
  7267. Role = KimiRole.user,
  7268. Content = airFeeLabel.ToString()
  7269. }
  7270. };
  7271. var client = new KiMiApiClient();
  7272. var kimiApiResult = await client.SeedMessage(msgs);
  7273. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  7274. string clients = kimiApiResult_JObject["content"].ToString();
  7275. decimal ecoPri_kimiAI = 0.00M,
  7276. bizPri_kimiAI = 0.00M;
  7277. //单个价格: 经济舱价格
  7278. if (decimal.TryParse(clients, out ecoPri_kimiAI)) { }
  7279. //价格文本包含/:/前经济舱价格 /后公务舱价格
  7280. if (clients.Contains('/'))
  7281. {
  7282. var priArray = clients.Split('/');
  7283. decimal.TryParse(priArray[0], out ecoPri_kimiAI); //
  7284. decimal.TryParse(priArray[1], out bizPri_kimiAI); //经济舱价格
  7285. }
  7286. else return (false, "价格文本不存在价格或KIMI-AI未识别出价格,不可自动审核!");
  7287. var isAutoAudit = false;
  7288. //价格验证处理
  7289. //经济舱
  7290. if (ecoTypeIds.Contains(airInfo.CType))
  7291. {
  7292. if (airInfo.PrePrice <= ecoPri_kimiAI) isAutoAudit = true;
  7293. }
  7294. //公务舱
  7295. else if (bizTypeIds.Contains(airInfo.CType))
  7296. {
  7297. if (airInfo.PrePrice <= bizPri_kimiAI) isAutoAudit = true;
  7298. }
  7299. else return (false, "该舱位类型不在自动审核范围内,不可自动审核!");
  7300. //是否执行自动审核
  7301. if (isAutoAudit)
  7302. {
  7303. var auditStatus = await _sqlSugar.Updateable<Grp_CreditCardPayment>()
  7304. .SetColumns(x => x.IsAuditGM == 3)
  7305. .SetColumns(x => x.AuditGMOperate == 4)
  7306. .SetColumns(x => x.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  7307. .Where(x => x.Id == airInfo.CcpId)
  7308. .ExecuteCommandAsync();
  7309. if (auditStatus > 0) return (true, "机票自动审核(KIMI-AI识别方式)执行成功!");
  7310. }
  7311. return (false, "当前费用超过成本费用,不可自动审核!");
  7312. }
  7313. /// <summary>
  7314. /// 机票费用录入
  7315. /// 自动审核测试 - AI 识别
  7316. /// </summary>
  7317. /// <param name="groupId"></param>
  7318. /// <param name="Id"></param>
  7319. /// <returns></returns>
  7320. [HttpPost]
  7321. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7322. public async Task<IActionResult> AirTicketResAutoAuditTest(int groupId, int Id)
  7323. {
  7324. (bool status, string msg) = await AirTicketResAutoAudit(groupId, Id);
  7325. return Ok(JsonView(status, msg));
  7326. }
  7327. /// <summary>
  7328. /// 根据舱位类型查询接团客户名单信息
  7329. /// </summary>
  7330. /// <param name="dto"></param>
  7331. /// <returns></returns>
  7332. [HttpPost]
  7333. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7334. public async Task<IActionResult> TankType(AirTicketResByIdDto dto)
  7335. {
  7336. try
  7337. {
  7338. List<Crm_GroupCustomer> crm_Groups = _sqlSugar.Queryable<Crm_GroupCustomer>().Where(a => a.IsDel == 0 && a.AirType == dto.Id).ToList();
  7339. if (crm_Groups.Count != 0)
  7340. {
  7341. var Customer = new List<dynamic>();
  7342. foreach (var item in crm_Groups)
  7343. {
  7344. var data = new
  7345. {
  7346. item.Id,
  7347. item.Pinyin,
  7348. Name = item.LastName + item.FirstName
  7349. };
  7350. Customer.Add(data);
  7351. }
  7352. return Ok(JsonView(true, "查询成功!", Customer));
  7353. }
  7354. return Ok(JsonView(true, "暂无数据", crm_Groups));
  7355. }
  7356. catch (Exception ex)
  7357. {
  7358. return Ok(JsonView(false, "程序错误!"));
  7359. throw;
  7360. }
  7361. }
  7362. /// <summary>
  7363. /// 根据团号获取客户信息
  7364. /// </summary>
  7365. /// <param name="dto"></param>
  7366. /// <returns></returns>
  7367. [HttpPost]
  7368. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7369. public IActionResult QueryClientInfoByDIID(QueryClientInfoByDIIDDto dto)
  7370. {
  7371. var jw = JsonView(false);
  7372. if (dto.DIID < 1)
  7373. {
  7374. jw.Msg += "请输入正确的diid";
  7375. return Ok(jw);
  7376. }
  7377. var arr = GetSimplClientList(dto.DIID);
  7378. jw = JsonView(true, "获取成功!", arr);
  7379. return Ok(jw);
  7380. }
  7381. private List<SimplClientInfo> GetSimplClientList(int diId)
  7382. {
  7383. 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);
  7384. List<SimplClientInfo> arr = _sqlSugar.SqlQueryable<SimplClientInfo>(sql).ToList();
  7385. foreach (var item in arr)
  7386. {
  7387. EncryptionProcessor.DecryptProperties(item);
  7388. }
  7389. return arr;
  7390. }
  7391. private static string GetClientNameStr(List<SimplClientInfo> list, string origin)
  7392. {
  7393. string result = origin;
  7394. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  7395. {
  7396. string[] temparr = origin.Split(',');
  7397. string fistrStr = temparr[0];
  7398. int count = temparr.Length;
  7399. bool success = int.TryParse(fistrStr, out int tempId);
  7400. if (success)
  7401. {
  7402. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  7403. if (tempInfo != null)
  7404. {
  7405. if (count > 1)
  7406. {
  7407. result = string.Format(@"{0}{1}等{2}人", tempInfo.LastName, tempInfo.FirstName, count);
  7408. }
  7409. else
  7410. {
  7411. result = string.Format(@"{0}{1}", tempInfo.LastName, tempInfo.FirstName);
  7412. }
  7413. }
  7414. }
  7415. }
  7416. return result;
  7417. }
  7418. private static string GetClientNameStr1(List<SimplClientInfo> list, string origin)
  7419. {
  7420. string result = origin;
  7421. if (Regex.Match(origin, @"\d+,?").Value.Length > 0)
  7422. {
  7423. string[] temparr = origin.Split(',');
  7424. result = "";
  7425. foreach (var item in temparr)
  7426. {
  7427. bool success = int.TryParse(item, out int tempId);
  7428. if (success)
  7429. {
  7430. SimplClientInfo tempInfo = list.FirstOrDefault(s => s.Id == tempId);
  7431. if (tempInfo != null)
  7432. {
  7433. result += string.Format(@"{0}{1}、", tempInfo.LastName, tempInfo.FirstName);
  7434. }
  7435. }
  7436. }
  7437. }
  7438. if (result.Length > 0) result = result.Substring(0, result.Length - 1);
  7439. return result;
  7440. }
  7441. /// <summary>
  7442. /// 机票费用录入,删除
  7443. /// </summary>
  7444. /// <param name="dto"></param>
  7445. /// <returns></returns>
  7446. [HttpPost]
  7447. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7448. public async Task<IActionResult> DelAirTicketRes(DelBaseDto dto)
  7449. {
  7450. try
  7451. {
  7452. //验证
  7453. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 85);
  7454. if (!valid) return Ok(JsonView(false, msg));
  7455. var res = await _airTicketResRep.SoftDeleteByIdAsync<Grp_AirTicketReservations>(dto.Id.ToString(), dto.DeleteUserId);
  7456. if (res)
  7457. {
  7458. var result = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.CTable == 85).SetColumns(a => new Grp_CreditCardPayment()
  7459. {
  7460. IsDel = 1,
  7461. DeleteUserId = dto.DeleteUserId,
  7462. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  7463. }).ExecuteCommandAsync();
  7464. return Ok(JsonView(true, "删除成功!"));
  7465. }
  7466. return Ok(JsonView(false, "删除失败!"));
  7467. }
  7468. catch (Exception ex)
  7469. {
  7470. return Ok(JsonView(false, "程序错误!"));
  7471. }
  7472. }
  7473. /// <summary>
  7474. /// 导出机票录入报表
  7475. /// </summary>
  7476. /// <param name="dto"></param>
  7477. /// <returns></returns>
  7478. [HttpPost]
  7479. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7480. public async Task<IActionResult> DeriveAirTicketRes(AirTicketResDto dto)
  7481. {
  7482. try
  7483. {
  7484. Result groupData = await _airTicketResRep.DeriveAirTicketRes(dto);
  7485. if (groupData.Code != 0)
  7486. {
  7487. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  7488. }
  7489. else
  7490. {
  7491. List<AirTicketReservationsPayView> AirTicketReservations = groupData.Data.GetType().GetProperty("AirTicketRes").GetValue(groupData.Data);
  7492. if (AirTicketReservations.Count != 0)
  7493. {
  7494. Grp_DelegationInfo DelegationInfo = groupData.Data.GetType().GetProperty("Delegation").GetValue(groupData.Data);
  7495. Sys_Users _Users = groupData.Data.GetType().GetProperty("Users").GetValue(groupData.Data);
  7496. string diCode = DelegationInfo != null ? DelegationInfo.TourCode : "XXX";
  7497. string diName = DelegationInfo != null ? DelegationInfo.TeamName : "XXX";
  7498. var designer = new WorkbookDesigner
  7499. {
  7500. Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/机票预订费用报表模板.xlsx")
  7501. };
  7502. decimal countCost = 0;
  7503. foreach (var item in AirTicketReservations)
  7504. {
  7505. #region 处理客人姓名
  7506. string clientNames = _tourClientListRep.ResolveCustomerName(item.ClientName);
  7507. item.ClientName = clientNames;
  7508. #endregion
  7509. if (item.BankType == "其他")
  7510. {
  7511. item.BankNo = "--";
  7512. }
  7513. else
  7514. {
  7515. if (!string.IsNullOrEmpty(item.BankType))
  7516. {
  7517. item.BankNo = $"{item.BankType}:{item.BankNo?[..3]}";
  7518. }
  7519. }
  7520. item.PrePrice = System.Decimal.Round(item.PrePrice, 2);
  7521. item.Price = System.Decimal.Round(item.Price, 2);
  7522. countCost += Convert.ToDecimal(item.Price);
  7523. }
  7524. designer.SetDataSource("Export", AirTicketReservations);
  7525. designer.SetDataSource("ExportDiCode", diCode);
  7526. designer.SetDataSource("ExportDiName", diName);
  7527. designer.SetDataSource("ExportOpUserName", _Users.CnName);
  7528. designer.SetDataSource("ExportCountCost", countCost + "(" + AirTicketReservations[0].CurrencyStr);
  7529. designer.Process();
  7530. string fileName = ("AirfareStatement/" + diName + "机票费用报表" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx").Replace(":", "");
  7531. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + fileName);
  7532. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  7533. return Ok(JsonView(true, "成功", url = rst));
  7534. }
  7535. else
  7536. {
  7537. return Ok(JsonView(StatusCodes.Status400BadRequest, "暂无数据!", ""));
  7538. }
  7539. }
  7540. }
  7541. catch (Exception ex)
  7542. {
  7543. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  7544. throw;
  7545. }
  7546. }
  7547. private Dictionary<string, string> transDic = new Dictionary<string, string>();
  7548. /// <summary>
  7549. /// 行程单导出
  7550. /// </summary>
  7551. /// <param name="dto"></param>
  7552. /// <returns></returns>
  7553. [HttpPost]
  7554. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  7555. public async Task<IActionResult> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  7556. {
  7557. try
  7558. {
  7559. Result groupData = await _airTicketResRep.ItineraryAirTicketRes(dto);
  7560. if (groupData.Code != 0)
  7561. {
  7562. return Ok(JsonView(StatusCodes.Status400BadRequest, groupData.Msg, ""));
  7563. }
  7564. else
  7565. {
  7566. List<AirTicketReservationsView> _AirTicketReservations = groupData.Data;
  7567. if (dto.Language == "CN")
  7568. {
  7569. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_CN.docx");
  7570. var builder = new DocumentBuilder(doc);
  7571. int tableIndex = 0;//表格索引
  7572. //得到文档中的第一个表格
  7573. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  7574. foreach (var item in _AirTicketReservations)
  7575. {
  7576. #region 处理固定数据
  7577. string[] FlightsCode = item.FlightsCode.Split('/');
  7578. if (FlightsCode.Length != 0)
  7579. {
  7580. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7581. if (_AirCompany != null)
  7582. {
  7583. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  7584. }
  7585. else
  7586. {
  7587. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7588. }
  7589. }
  7590. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7591. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7592. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7593. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7594. string name = "";
  7595. foreach (string clientName in nameArray)
  7596. {
  7597. if (!name.Contains(clientName))
  7598. {
  7599. name += clientName + ",";
  7600. }
  7601. }
  7602. if (!string.IsNullOrWhiteSpace(name))
  7603. {
  7604. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  7605. }
  7606. else
  7607. {
  7608. table.Range.Bookmarks["ClientName"].Text = "--";
  7609. }
  7610. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7611. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7612. table.Range.Bookmarks["JointTicket"].Text = "--";
  7613. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7614. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7615. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7616. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7617. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7618. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7619. #endregion
  7620. #region 循环数据处理
  7621. var airs = new List<AirInfo>();
  7622. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7623. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7624. for (int i = 0; i < FlightsCode.Length; i++)
  7625. {
  7626. var air = new AirInfo();
  7627. string[] tempstr = DayArray[i]
  7628. .Replace("\r\n", string.Empty)
  7629. .Replace("\\r\\n", string.Empty)
  7630. .TrimStart().TrimEnd()
  7631. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7632. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7633. string starCity = "";
  7634. if (star_Three != null)
  7635. {
  7636. starCity = star_Three.AirPort;
  7637. }
  7638. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7639. string EndCity = "";
  7640. if (End_Three != null)
  7641. {
  7642. EndCity = End_Three.AirPort;
  7643. }
  7644. air.Destination = starCity + "/" + EndCity;
  7645. air.Flight = FlightsCode[i];
  7646. air.SeatingClass = item.CTypeName;
  7647. string dateTime = tempstr[2];
  7648. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  7649. air.FlightDate = DateTemp;
  7650. air.DepartureTime = tempstr[5];
  7651. air.LandingTime = tempstr[6];
  7652. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  7653. air.TicketStatus = "--";
  7654. air.Luggage = "--";
  7655. air.DepartureTerminal = "--";
  7656. air.LandingTerminal = "--";
  7657. airs.Add(air);
  7658. }
  7659. int row = 13;
  7660. for (int i = 0; i < airs.Count; i++)
  7661. {
  7662. if (airs.Count > 2)
  7663. {
  7664. for (int j = 0; j < airs.Count - 2; j++)
  7665. {
  7666. var CopyRow = table.Rows[12].Clone(true);
  7667. table.Rows.Add(CopyRow);
  7668. }
  7669. }
  7670. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  7671. int index = 0;
  7672. foreach (PropertyInfo property in properties)
  7673. {
  7674. string value = property.GetValue(airs[i]).ToString();
  7675. Cell ishcel0 = table.Rows[row].Cells[index];
  7676. var p = new Paragraph(doc);
  7677. string s = value;
  7678. p.AppendChild(new Run(doc, s));
  7679. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  7680. ishcel0.AppendChild(p);
  7681. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  7682. index++;
  7683. }
  7684. row++;
  7685. }
  7686. #endregion
  7687. var lastParagraph = new Paragraph(doc);
  7688. //第一个表格末尾加段落
  7689. table.ParentNode.InsertAfter(lastParagraph, table);
  7690. //复制第一个表格
  7691. Table cloneTable = (Table)table.Clone(true);
  7692. //在文档末尾段落后面加入复制的表格
  7693. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  7694. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  7695. {
  7696. int rownewsIndex = 13;
  7697. for (int i = 0; i < 2; i++)
  7698. {
  7699. var CopyRow = table.Rows[12].Clone(true);
  7700. table.Rows.RemoveAt(13);
  7701. table.Rows.Add(CopyRow);
  7702. rownewsIndex++;
  7703. }
  7704. }
  7705. else
  7706. {
  7707. table.Rows.RemoveAt(12);
  7708. }
  7709. cloneTable.Rows.RemoveAt(12);
  7710. }
  7711. if (_AirTicketReservations.Count != 0)
  7712. {
  7713. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  7714. if (FlightsCode.Length != 0)
  7715. {
  7716. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7717. if (_AirCompany != null)
  7718. {
  7719. table.Range.Bookmarks["AirlineCompany"].Text = _AirCompany.CnName;
  7720. }
  7721. else
  7722. {
  7723. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7724. }
  7725. }
  7726. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7727. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7728. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7729. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7730. string name = "";
  7731. foreach (string clientName in nameArray)
  7732. {
  7733. if (!name.Contains(clientName))
  7734. {
  7735. name += clientName + ",";
  7736. }
  7737. }
  7738. if (!string.IsNullOrWhiteSpace(name))
  7739. {
  7740. table.Range.Bookmarks["ClientName"].Text = name.Substring(0, name.Length - 1);
  7741. }
  7742. else
  7743. {
  7744. table.Range.Bookmarks["ClientName"].Text = "--";
  7745. }
  7746. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7747. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7748. table.Range.Bookmarks["JointTicket"].Text = "--";
  7749. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7750. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7751. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7752. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7753. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7754. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7755. }
  7756. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  7757. //保存合并后的文档
  7758. string fileName = "AirItinerary/电子客票中文行程单_CN.docx";
  7759. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  7760. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  7761. return Ok(JsonView(true, "成功!", rst));
  7762. }
  7763. else
  7764. {
  7765. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/电子客票行程单模板_EN.docx");
  7766. var builder = new DocumentBuilder(doc);
  7767. int tableIndex = 0;//表格索引
  7768. //得到文档中的第一个表格
  7769. Table table = (Table)doc.GetChild(NodeType.Table, tableIndex, true);
  7770. var texts = new List<string>();
  7771. foreach (var item in _AirTicketReservations)
  7772. {
  7773. string[] FlightsCode = item.FlightsCode.Split('/');
  7774. if (FlightsCode.Length != 0)
  7775. {
  7776. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7777. if (_AirCompany != null)
  7778. {
  7779. if (!transDic.ContainsKey(_AirCompany.CnName))
  7780. {
  7781. transDic.Add(_AirCompany.CnName, _AirCompany.EnName);
  7782. }
  7783. }
  7784. else
  7785. {
  7786. if (!transDic.ContainsKey("--"))
  7787. {
  7788. transDic.Add("--", "--");
  7789. }
  7790. }
  7791. }
  7792. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7793. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7794. string name = "";
  7795. foreach (string clientName in nameArray)
  7796. {
  7797. name += clientName + ",";
  7798. }
  7799. if (!texts.Contains(name))
  7800. {
  7801. texts.Add(name);
  7802. }
  7803. var airs = new List<AirInfo>();
  7804. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7805. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7806. for (int i = 0; i < FlightsCode.Length; i++)
  7807. {
  7808. var air = new AirInfo();
  7809. string[] tempstr = DayArray[i]
  7810. .Replace("\r\n", string.Empty)
  7811. .Replace("\\r\\n", string.Empty)
  7812. .TrimStart().TrimEnd()
  7813. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7814. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7815. if (star_Three != null)
  7816. {
  7817. if (!transDic.ContainsKey(star_Three.AirPort))
  7818. {
  7819. transDic.Add(star_Three.AirPort, star_Three.AirPort_En);
  7820. }
  7821. }
  7822. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7823. if (End_Three != null)
  7824. {
  7825. if (!transDic.ContainsKey(End_Three.AirPort))
  7826. {
  7827. transDic.Add(End_Three.AirPort, End_Three.AirPort_En);
  7828. }
  7829. }
  7830. if (!texts.Contains(item.CTypeName))
  7831. {
  7832. texts.Add(item.CTypeName);
  7833. }
  7834. }
  7835. }
  7836. List<TranslateResult> transData = await _airTicketResRep.ReTransBatch(texts, "en");
  7837. if (transData.Count > 0)
  7838. {
  7839. foreach (TranslateResult item in transData)
  7840. {
  7841. if (!transDic.ContainsKey(item.Query))
  7842. {
  7843. transDic.Add(item.Query, item.Translation);
  7844. }
  7845. }
  7846. }
  7847. foreach (var item in _AirTicketReservations)
  7848. {
  7849. #region 处理固定数据
  7850. string[] FlightsCode = item.FlightsCode.Split('/');
  7851. if (FlightsCode.Length != 0)
  7852. {
  7853. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  7854. if (_AirCompany != null)
  7855. {
  7856. string str = "--";
  7857. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  7858. if (!string.IsNullOrEmpty(translateResult))
  7859. {
  7860. str = translateResult;
  7861. str = _airTicketResRep.Processing(str);
  7862. }
  7863. table.Range.Bookmarks["AirlineCompany"].Text = str;
  7864. }
  7865. else
  7866. {
  7867. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  7868. }
  7869. }
  7870. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  7871. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  7872. string[] nameArray = Regex.Split(item.ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  7873. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  7874. string names = "";
  7875. foreach (string clientName in nameArray)
  7876. {
  7877. names += clientName + ",";
  7878. }
  7879. if (!string.IsNullOrWhiteSpace(names))
  7880. {
  7881. string str = "--";
  7882. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  7883. if (!string.IsNullOrEmpty(translateResult))
  7884. {
  7885. str = translateResult;
  7886. str = _airTicketResRep.Processing(str);
  7887. }
  7888. table.Range.Bookmarks["ClientName"].Text = str;
  7889. }
  7890. else
  7891. {
  7892. table.Range.Bookmarks["ClientName"].Text = "--";
  7893. }
  7894. table.Range.Bookmarks["TicketNumber"].Text = "--";
  7895. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  7896. table.Range.Bookmarks["JointTicket"].Text = "--";
  7897. table.Range.Bookmarks["TimeIssue"].Text = "--";
  7898. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  7899. table.Range.Bookmarks["NavigationCode"].Text = "--";
  7900. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  7901. table.Range.Bookmarks["AgentPhone"].Text = "--";
  7902. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  7903. #endregion
  7904. #region 循环数据处理
  7905. var airs = new List<AirInfo>();
  7906. string[] DayArray = Regex.Split(item.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase);
  7907. DayArray = DayArray.Where(s => s != " " && s != "" && !string.IsNullOrEmpty(s)).ToArray();
  7908. for (int i = 0; i < FlightsCode.Length; i++)
  7909. {
  7910. var air = new AirInfo();
  7911. string[] tempstr = DayArray[i]
  7912. .Replace("\r\n", string.Empty)
  7913. .Replace("\\r\\n", string.Empty)
  7914. .TrimStart().TrimEnd()
  7915. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  7916. Res_ThreeCode star_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(0, 3));
  7917. string starCity = "";
  7918. if (star_Three != null)
  7919. {
  7920. string str2 = "--";
  7921. string translateResult2 = transDic.Where(s => s.Key == star_Three.AirPort).FirstOrDefault().Value;
  7922. if (!string.IsNullOrEmpty(translateResult2))
  7923. {
  7924. str2 = translateResult2;
  7925. str2 = _airTicketResRep.Processing(str2);
  7926. }
  7927. starCity = str2;
  7928. }
  7929. Res_ThreeCode End_Three = _sqlSugar.Queryable<Res_ThreeCode>().First(a => a.Three == tempstr[3].Substring(3, 3));
  7930. string EndCity = "";
  7931. if (End_Three != null)
  7932. {
  7933. string str1 = "--";
  7934. string translateResult1 = transDic.Where(s => s.Key == End_Three.AirPort).FirstOrDefault().Value;
  7935. if (!string.IsNullOrEmpty(translateResult1))
  7936. {
  7937. str1 = translateResult1;
  7938. str1 = _airTicketResRep.Processing(str1);
  7939. }
  7940. EndCity = str1;
  7941. }
  7942. air.Destination = starCity + "/" + EndCity;
  7943. air.Flight = FlightsCode[i];
  7944. string str = "--";
  7945. string translateResult = transDic.Where(s => s.Key == item.CTypeName).FirstOrDefault().Value;
  7946. if (!string.IsNullOrEmpty(translateResult))
  7947. {
  7948. str = translateResult;
  7949. str = _airTicketResRep.Processing(str);
  7950. }
  7951. air.SeatingClass = str;
  7952. string dateTime = tempstr[2];
  7953. string DateTemp = dateTime.Substring(2, 5).ToUpper();
  7954. air.FlightDate = DateTemp;
  7955. air.DepartureTime = tempstr[5];
  7956. air.LandingTime = tempstr[6];
  7957. air.ValidityPeriod = DateTemp + "/" + DateTemp;
  7958. air.TicketStatus = "--";
  7959. air.Luggage = "--";
  7960. air.DepartureTerminal = "--";
  7961. air.LandingTerminal = "--";
  7962. airs.Add(air);
  7963. }
  7964. int row = 13;
  7965. for (int i = 0; i < airs.Count; i++)
  7966. {
  7967. if (airs.Count > 2)
  7968. {
  7969. for (int j = 0; j < airs.Count - 2; j++)
  7970. {
  7971. var CopyRow = table.Rows[12].Clone(true);
  7972. table.Rows.Add(CopyRow);
  7973. }
  7974. }
  7975. PropertyInfo[] properties = airs[i].GetType().GetProperties();
  7976. int index = 0;
  7977. foreach (PropertyInfo property in properties)
  7978. {
  7979. string value = property.GetValue(airs[i]).ToString();
  7980. Cell ishcel0 = table.Rows[row].Cells[index];
  7981. var p = new Paragraph(doc);
  7982. string s = value;
  7983. p.AppendChild(new Run(doc, s));
  7984. p.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
  7985. ishcel0.AppendChild(p);
  7986. ishcel0.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
  7987. //ishcel0.CellFormat.VerticalAlignment=
  7988. index++;
  7989. }
  7990. row++;
  7991. }
  7992. #endregion
  7993. var lastParagraph = new Paragraph(doc);
  7994. //第一个表格末尾加段落
  7995. table.ParentNode.InsertAfter(lastParagraph, table);
  7996. //复制第一个表格
  7997. Table cloneTable = (Table)table.Clone(true);
  7998. //在文档末尾段落后面加入复制的表格
  7999. table.ParentNode.InsertAfter(cloneTable, lastParagraph);
  8000. if (item != _AirTicketReservations[_AirTicketReservations.Count - 1])
  8001. {
  8002. int rownewsIndex = 13;
  8003. for (int i = 0; i < 2; i++)
  8004. {
  8005. var CopyRow = table.Rows[12].Clone(true);
  8006. table.Rows.RemoveAt(13);
  8007. table.Rows.Add(CopyRow);
  8008. rownewsIndex++;
  8009. }
  8010. }
  8011. else
  8012. {
  8013. table.Rows.RemoveAt(12);
  8014. }
  8015. cloneTable.Rows.RemoveAt(12);
  8016. }
  8017. if (_AirTicketReservations.Count != 0)
  8018. {
  8019. string[] FlightsCode = _AirTicketReservations[0].FlightsCode.Split('/');
  8020. if (FlightsCode.Length != 0)
  8021. {
  8022. Res_AirCompany _AirCompany = _sqlSugar.Queryable<Res_AirCompany>().First(a => a.ShortCode == FlightsCode[0].Substring(0, 2));
  8023. if (_AirCompany != null)
  8024. {
  8025. string str = "--";
  8026. string translateResult = transDic.Where(s => s.Key == _AirCompany.CnName).FirstOrDefault().Value;
  8027. if (!string.IsNullOrEmpty(translateResult))
  8028. {
  8029. str = translateResult;
  8030. str = _airTicketResRep.Processing(str);
  8031. }
  8032. table.Range.Bookmarks["AirlineCompany"].Text = str;
  8033. }
  8034. else
  8035. {
  8036. table.Range.Bookmarks["AirlineCompany"].Text = "--";
  8037. }
  8038. }
  8039. table.Range.Bookmarks["AirlineRecordCode"].Text = "--";
  8040. table.Range.Bookmarks["ReservationRecordCode"].Text = "--";
  8041. string[] nameArray = Regex.Split(_AirTicketReservations[0].ClientName, "\\d+\\.", RegexOptions.IgnoreCase);
  8042. nameArray = nameArray.Where(str => str != "" && str != " " && !string.IsNullOrEmpty(str)).ToArray();
  8043. string names = "";
  8044. foreach (string clientName in nameArray)
  8045. {
  8046. names += clientName + ",";
  8047. }
  8048. if (!string.IsNullOrWhiteSpace(names))
  8049. {
  8050. string str = "--";
  8051. string translateResult = transDic.Where(s => s.Key == names).FirstOrDefault().Value;
  8052. if (!string.IsNullOrEmpty(translateResult))
  8053. {
  8054. str = translateResult;
  8055. str = _airTicketResRep.Processing(str);
  8056. }
  8057. table.Range.Bookmarks["ClientName"].Text = str;
  8058. }
  8059. else
  8060. {
  8061. table.Range.Bookmarks["ClientName"].Text = "--";
  8062. }
  8063. table.Range.Bookmarks["TicketNumber"].Text = "--";
  8064. table.Range.Bookmarks["IdentificationCode"].Text = "--";
  8065. table.Range.Bookmarks["JointTicket"].Text = "--";
  8066. table.Range.Bookmarks["TimeIssue"].Text = "--";
  8067. table.Range.Bookmarks["DrawingAgent"].Text = "--";
  8068. table.Range.Bookmarks["NavigationCode"].Text = "--";
  8069. table.Range.Bookmarks["AgentsAddress"].Text = "--";
  8070. table.Range.Bookmarks["AgentPhone"].Text = "--";
  8071. table.Range.Bookmarks["AgentFacsimile"].Text = "--";
  8072. }
  8073. doc.MailMerge.Execute(new[] { "PageCount" }, new object[] { doc.PageCount });
  8074. //保存合并后的文档
  8075. string fileName = "AirItinerary/电子客票英文行程单_EN.docx";
  8076. string rst = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + fileName;
  8077. doc.Save(AppSettingsHelper.Get("WordBasePath") + fileName);
  8078. return Ok(JsonView(true, "成功!", rst));
  8079. }
  8080. }
  8081. }
  8082. catch (Exception ex)
  8083. {
  8084. return Ok(JsonView(StatusCodes.Status400BadRequest, "程序错误!", ""));
  8085. throw;
  8086. }
  8087. }
  8088. #endregion
  8089. #region 团组增减款项 --> 其他款项
  8090. /// <summary>
  8091. /// 团组增减款项下拉框绑定
  8092. /// </summary>
  8093. /// <param name="dto"></param>
  8094. /// <returns></returns>
  8095. [HttpPost]
  8096. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8097. public async Task<IActionResult> DecreasePaymentsSelect(DecreasePaymentsDto dto)
  8098. {
  8099. #region 参数验证
  8100. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  8101. if (dto.CTId < 1) return Ok(JsonView(false, "请传入有效的CTId参数!"));
  8102. #endregion
  8103. return Ok(await _decreasePaymentsRep.DecreasePaymentsSelect(dto));
  8104. }
  8105. /// <summary>
  8106. /// 根据团组Id查询团组增减款项
  8107. /// </summary>
  8108. /// <param name="dto"></param>
  8109. /// <returns></returns>
  8110. [HttpPost]
  8111. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8112. public async Task<IActionResult> DecreasePaymentsList(DecreasePaymentsListDto dto)
  8113. {
  8114. #region 参数验证
  8115. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  8116. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  8117. #endregion
  8118. return Ok(await _decreasePaymentsRep.DecreasePaymentsList(dto));
  8119. }
  8120. /// <summary>
  8121. /// 团组增减款项操作(Status:1.新增,2.修改)
  8122. /// </summary>
  8123. /// <param name="dto"></param>
  8124. /// <returns></returns>
  8125. [HttpPost]
  8126. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8127. public async Task<IActionResult> OpDecreasePayments(DecreasePaymentsOpDto dto)
  8128. {
  8129. JsonView groupData = await _decreasePaymentsRep.OpDecreasePayments(dto);
  8130. if (groupData.Code != 200)
  8131. {
  8132. return Ok(JsonView(false, groupData.Msg));
  8133. }
  8134. #region 应用推送
  8135. //int otherId = (int)groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  8136. //int ccpId = (int)groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  8137. //int sign = (int)groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  8138. int otherId = Convert.ToInt32(groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null) ?? 0);
  8139. int ccpId = Convert.ToInt32(groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null) ?? 0);
  8140. int sign = Convert.ToInt32(groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null) ?? 0);
  8141. bool recheck = Convert.ToBoolean(groupData.Data.GetType().GetProperty("recheck").GetValue(groupData.Data, null) ?? "True");
  8142. if (recheck)
  8143. {
  8144. //自动审核
  8145. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(3, dto.DiId, otherId);
  8146. }
  8147. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  8148. //2024-10-21 新增LZ UID
  8149. var userIds = new List<int>() { 21 };
  8150. string title = $"系统通知";
  8151. string content = "";
  8152. var diId = dto.DiId;
  8153. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  8154. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  8155. if (dto.Status == 1) content = $"[新增-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8156. else if (dto.Status == 2) content = $"[更新-其他款项({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8157. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  8158. //await APNsTools.iOS_PushNotifications1("051", $"其他款项费用审核", "", content);
  8159. #endregion
  8160. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8161. }
  8162. /// <summary>
  8163. /// 团组增减款项操作 删除
  8164. /// </summary>
  8165. /// <param name="dto"></param>
  8166. /// <returns></returns>
  8167. [HttpPost]
  8168. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8169. public async Task<IActionResult> DelDecreasePayments(DelBaseDto dto)
  8170. {
  8171. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  8172. if (dto.DeleteUserId < 1) return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  8173. var res = await _decreasePaymentsRep._Del(dto.Id, dto.DeleteUserId);
  8174. if (res.Code == 0) return Ok(JsonView(true, "删除成功!"));
  8175. return Ok(JsonView(false, res?.Msg ?? "删除失败!"));
  8176. }
  8177. /// <summary>
  8178. /// 根据团组增减款项Id查询
  8179. /// </summary>
  8180. /// <param name="dto"></param>
  8181. /// <returns></returns>
  8182. [HttpPost]
  8183. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8184. public async Task<IActionResult> QueryDecreasePaymentsById(DecreasePaymentsByIdDto dto)
  8185. {
  8186. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的数据Id!"));
  8187. return Ok(await _decreasePaymentsRep.QueryDecreasePaymentsById(dto));
  8188. }
  8189. /// <summary>
  8190. /// 查询供应商名称
  8191. /// </summary>
  8192. /// <param name="dto"></param>
  8193. /// <returns></returns>
  8194. [HttpPost]
  8195. public IActionResult QueryAssociateSupplier(AssociateSupplierDto dto)
  8196. {
  8197. var dbResult = _sqlSugar.Queryable<Grp_DecreasePayments>()
  8198. .Where(x => x.SupplierName.Contains(dto.param) && x.IsDel == 0).ToList()
  8199. ?? new List<Grp_DecreasePayments>();
  8200. dbResult = dbResult.Distinct(new
  8201. ProductComparer()).ToList();
  8202. var jw = JsonView(true, "success", dbResult.OrderByDescending(x => x.Id).Select(x => new
  8203. {
  8204. x.Id,
  8205. x.SupplierAddress,
  8206. x.SupplierArea,
  8207. x.SupplierContact,
  8208. x.SupplierContactNumber,
  8209. x.SupplierEmail,
  8210. x.SupplierName,
  8211. x.SupplierSocialAccount,
  8212. x.SupplierTypeId,
  8213. }).ToList());
  8214. return Ok(jw);
  8215. }
  8216. /// <summary>
  8217. /// 团组增减款项 OTA匹配
  8218. /// </summary>
  8219. /// <param name="file"></param>
  8220. /// <returns></returns>
  8221. [HttpPost]
  8222. public async Task<IActionResult> DecreasePaymentsOTAMate(IFormFile file)
  8223. {
  8224. if (file.Length < 1) return Ok(JsonView(false, "请上传文件!"));
  8225. string fileName = file.FileName;
  8226. if (!fileName.EndsWith(".xlsx") && !fileName.EndsWith(".xls"))
  8227. {
  8228. return Ok(JsonView(false, "请上传Excel文件!"));
  8229. }
  8230. //D:\FTP\File\OA2023\Office\GrpFile\团组增减款项相关文件\团组其他款项(OTA)
  8231. var path = @$"{AppSettingsHelper.Get("GrpFileBasePath")}团组增减款项相关文件/团组其他款项(OTA)";
  8232. if (!Directory.Exists(path))
  8233. {
  8234. Directory.CreateDirectory(path);
  8235. }
  8236. var filePath = @$"{path}/{fileName}";
  8237. //保存文件
  8238. using (FileStream fs = System.IO.File.Create(filePath))
  8239. {
  8240. file.CopyTo(fs);
  8241. fs.Flush();
  8242. }
  8243. if (!System.IO.File.Exists(filePath)) return Ok(JsonView(false, "文件不存在!"));
  8244. //读取ExcelFile
  8245. DataTable dt = ConvertExcelToDataTable(filePath);
  8246. if (dt == null) return Ok(JsonView(false, $"您上传的Excel工作表没有内容,请检查!!!"));
  8247. dt.TableName = "TB";
  8248. //修改table列名
  8249. dt.Columns[0].ColumnName = "OrderNo"; // 订单号
  8250. dt.Columns[1].ColumnName = "OTAOrderNo"; // OTA订单号
  8251. dt.Columns[2].ColumnName = "PackageName"; // 套餐名
  8252. dt.Columns[3].ColumnName = "IsPay"; // 是否支付
  8253. dt.Columns[4].ColumnName = "IsShipments"; // 是否发货
  8254. dt.Columns[5].ColumnName = "IsSendBack"; // 是否寄回
  8255. dt.Columns[6].ColumnName = "OpUser"; // 使用人信息
  8256. dt.Columns[7].ColumnName = "OrderTime"; // 下单时间
  8257. dt.Columns[8].ColumnName = "UseTime"; // 使用时间
  8258. dt.Columns[9].ColumnName = "Quantity"; // 台数
  8259. dt.Columns[10].ColumnName = "Days"; // 租赁天数
  8260. dt.Columns[11].ColumnName = "QuantityShipped";// 发货数量
  8261. dt.Columns[12].ColumnName = "TotalPrice"; // 总金额
  8262. dt.Columns[13].ColumnName = "GroupName"; // 团组名称
  8263. dt.Columns[14].ColumnName = "OATotalPrice"; // OA金额
  8264. var otaOrderNos = new List<string>();
  8265. foreach (DataRow item in dt.Rows)
  8266. {
  8267. otaOrderNos.Add(item["OTAOrderNo"].ToString());
  8268. }
  8269. var oaDatas = await _sqlSugar.Queryable<Grp_DecreasePayments>()
  8270. .LeftJoin<Grp_DelegationInfo>((dp, di) => dp.DiId == di.Id)
  8271. .Where((dp, di) => dp.IsDel == 0 && dp.PriceName.Contains("wifi") || otaOrderNos.Contains(dp.OTAOrderNo))
  8272. .Select((dp, di) => new
  8273. {
  8274. dp.PriceName,
  8275. dp.OTAOrderNo,
  8276. dp.FeeTotal,
  8277. di.TeamName,
  8278. })
  8279. .ToListAsync();
  8280. foreach (DataRow item in dt.Rows)
  8281. {
  8282. var otaOrderNo = item["OTAOrderNo"].ToString();
  8283. var oaData = oaDatas.Find(x => !string.IsNullOrEmpty(x.OTAOrderNo) && x.OTAOrderNo.Contains(otaOrderNo));
  8284. if (oaData == null) continue;
  8285. item["GroupName"] = oaData.TeamName;
  8286. item["OATotalPrice"] = oaData.FeeTotal.ToString("#0.00");
  8287. }
  8288. string fileName1 = $"OTA_WIFI费用{DateTime.Now:yyyyMMddHHmmss}.xls";
  8289. var pairs = new Dictionary<string, object>();
  8290. var datas = new List<DataTable>
  8291. {
  8292. dt
  8293. };
  8294. url = AsposeHelper.ExpertExcelToModel("WIFI费用清单-模板.xlsx", $"GrpFile/团组增减款项相关文件/团组其他款项(OTA)", fileName1, pairs, datas);
  8295. return Ok(JsonView(true, "操作成功", new { url }));
  8296. }
  8297. #region
  8298. private static DataTable ConvertExcelToDataTable(string excelFilePath)
  8299. {
  8300. // 创建Workbook对象
  8301. var workbook = new Workbook(excelFilePath);
  8302. // 获取第一个工作表
  8303. var worksheet = workbook.Worksheets[0];
  8304. // 将工作表转换为DataTable
  8305. DataTable dataTable = worksheet.Cells.ExportDataTable(1, 0, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1);
  8306. return dataTable;
  8307. }
  8308. #endregion
  8309. /// <summary>
  8310. /// 世运会数据
  8311. /// </summary>
  8312. /// <returns></returns>
  8313. [HttpGet]
  8314. public IActionResult WorldGamesData()
  8315. {
  8316. var setData = _sqlSugar.Queryable<Grp_GamesBudgetMaster>().Where(x => x.IsDel == 0).ToList();
  8317. var groupMenu = setData.GroupBy(x => x.T0);
  8318. var resultArr = new List<DecreasePaymentsWorldGamesDataView>();
  8319. foreach (var item in groupMenu)
  8320. {
  8321. resultArr.Add(new DecreasePaymentsWorldGamesDataView
  8322. {
  8323. Data = new SetDataView
  8324. {
  8325. Name = item.Key
  8326. },
  8327. Child = item.Select(x => x.CalculationContent).ToList() ?? new List<string>()
  8328. });
  8329. }
  8330. return Ok(JsonView(true, "success", resultArr));
  8331. }
  8332. #endregion
  8333. #region 文件上传、删除
  8334. /// <summary>
  8335. /// region 文件上传 可以带参数
  8336. /// </summary>
  8337. /// <param name="file"></param>
  8338. /// <returns></returns>
  8339. [HttpPost]
  8340. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8341. public async Task<IActionResult> UploadProject(IFormFile file)
  8342. {
  8343. //var TypeName = Request.Headers["TypeName"].ToString();
  8344. //if (file == null) return Ok(JsonView(false, "文件不存在!"));
  8345. //var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8346. ////文件名称
  8347. //string projectFileName = file.FileName;
  8348. ////上传的文件的路径
  8349. //string filePath = $"{fileDir}/{projectFileName}";
  8350. //if (TypeName == "A")//A代表团组增减款项
  8351. //{
  8352. // filePath = fileDir + $@"\团组增减款项相关文件";
  8353. // if (!Directory.Exists(filePath))
  8354. // {
  8355. // Directory.CreateDirectory(filePath);
  8356. // }
  8357. // //上传的文件的路径
  8358. // filePath += $@"\{projectFileName}";
  8359. //}
  8360. //else if (TypeName == "B")//B代表商邀相关文件
  8361. //{
  8362. // //上传的文件的路径
  8363. // filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8364. // if (!Directory.Exists(filePath))
  8365. // {
  8366. // Directory.CreateDirectory(filePath);
  8367. // }
  8368. // //上传的文件的路径
  8369. // filePath = $@"\{projectFileName}";
  8370. //}
  8371. //try
  8372. //{
  8373. // using (FileStream fs = System.IO.File.Create(filePath))
  8374. // {
  8375. // file.CopyTo(fs);
  8376. // fs.Flush();
  8377. // }
  8378. //}
  8379. //catch (Exception ex)
  8380. //{
  8381. // return Ok(JsonView(false, $"文件上传失败! Error:{ex.Message}"));
  8382. //}
  8383. //return Ok(JsonView(true, "上传成功!", projectFileName));
  8384. try
  8385. {
  8386. var TypeName = Request.Headers["TypeName"].ToString();
  8387. if (file != null)
  8388. {
  8389. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8390. //文件名称
  8391. string projectFileName = file.FileName;
  8392. //上传的文件的路径
  8393. string filePath = $"{fileDir}/{projectFileName}";
  8394. if (TypeName == "A")//A代表团组增减款项
  8395. {
  8396. if (!Directory.Exists(fileDir))
  8397. {
  8398. Directory.CreateDirectory(fileDir);
  8399. }
  8400. //上传的文件的路径
  8401. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  8402. }
  8403. else if (TypeName == "B")//B代表商邀相关文件
  8404. {
  8405. if (!Directory.Exists(fileDir))
  8406. {
  8407. Directory.CreateDirectory(fileDir);
  8408. }
  8409. //上传的文件的路径
  8410. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8411. }
  8412. using (FileStream fs = System.IO.File.Create(filePath))
  8413. {
  8414. file.CopyTo(fs);
  8415. fs.Flush();
  8416. }
  8417. return Ok(JsonView(true, "上传成功!", projectFileName));
  8418. }
  8419. else
  8420. {
  8421. return Ok(JsonView(false, "上传失败!"));
  8422. }
  8423. }
  8424. catch (Exception ex)
  8425. {
  8426. return Ok(JsonView(false, ex.Message));
  8427. }
  8428. }
  8429. /// <summary>
  8430. /// 删除指定文件
  8431. /// </summary>
  8432. /// <param name="dto"></param>
  8433. /// <returns></returns>
  8434. [HttpPost]
  8435. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8436. public async Task<IActionResult> DelFile(DelFileDto dto)
  8437. {
  8438. try
  8439. {
  8440. var TypeName = Request.Headers["TypeName"].ToString();
  8441. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  8442. string filePath = "";
  8443. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8444. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  8445. int id = 0;
  8446. if (TypeName == "A")
  8447. {
  8448. filePath = fileDir + "/团组增减款项相关文件/" + dto.fileName;
  8449. // 删除该文件
  8450. System.IO.File.Delete(filePath);
  8451. id = await _sqlSugar.Updateable<Grp_DecreasePayments>()
  8452. .Where(a => a.Id == dto.Id)
  8453. .SetColumns(a => new Grp_DecreasePayments { FilePath = "" })
  8454. .ExecuteCommandAsync();
  8455. }
  8456. else if (TypeName == "B")
  8457. {
  8458. filePath = fileDir + "/商邀相关文件/" + dto.fileName;
  8459. // 删除该文件
  8460. System.IO.File.Delete(filePath);
  8461. var info = await _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(x => x.Id == dto.Id && x.IsDel == 0).FirstAsync();
  8462. if (info != null)
  8463. {
  8464. string[] files = Array.Empty<string>();
  8465. if (!string.IsNullOrEmpty(info.Attachment))
  8466. {
  8467. try
  8468. {
  8469. files = JsonConvert.DeserializeObject<string[]>(info.Attachment);
  8470. }
  8471. catch (Exception)
  8472. {
  8473. files = new List<string>() { info.Attachment }.ToArray();
  8474. }
  8475. }
  8476. if (files.Length > 0)
  8477. {
  8478. var files1 = files.Where(x => !x.Equals(dto.fileName)).ToArray();
  8479. string filePath2 = string.Empty;
  8480. if (files1.Length > 0)
  8481. {
  8482. filePath2 = JsonConvert.SerializeObject(files1);
  8483. }
  8484. id = await _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  8485. .Where(a => a.Id == dto.Id)
  8486. .SetColumns(a => new Grp_InvitationOfficialActivities { Attachment = filePath2 })
  8487. .ExecuteCommandAsync();
  8488. }
  8489. }
  8490. }
  8491. if (id != 0)
  8492. {
  8493. return Ok(JsonView(true, "成功!"));
  8494. }
  8495. else
  8496. {
  8497. return Ok(JsonView(false, "失败!"));
  8498. }
  8499. }
  8500. catch (Exception ex)
  8501. {
  8502. return Ok(JsonView(false, "程序错误!"));
  8503. throw;
  8504. }
  8505. }
  8506. /// <summary>
  8507. /// 文件上传多个文件 可以带参数
  8508. /// </summary>
  8509. /// <param name="files"></param>
  8510. /// <returns></returns>
  8511. [HttpPost]
  8512. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8513. public async Task<IActionResult> UploadProjects(IFormFile[] files)
  8514. {
  8515. try
  8516. {
  8517. var TypeName = Request.Headers["TypeName"].ToString();
  8518. if (string.IsNullOrEmpty(TypeName)) return Ok(JsonView(false, "请选择选组对应模块!"));
  8519. if (files.Length < 1) return Ok(JsonView(false, "请选择文件!"));
  8520. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  8521. var filePahts = new List<string>();
  8522. foreach (var file in files)
  8523. {
  8524. //文件名称
  8525. string projectFileName = file.FileName;
  8526. //上传的文件的路径
  8527. string filePath = $"{fileDir}/{projectFileName}";
  8528. if (TypeName == "A")//A代表团组增减款项
  8529. {
  8530. if (!Directory.Exists(fileDir))
  8531. {
  8532. Directory.CreateDirectory(fileDir);
  8533. }
  8534. //上传的文件的路径
  8535. filePath = fileDir + $@"\团组增减款项相关文件\{projectFileName}";
  8536. }
  8537. else if (TypeName == "B")//B代表商邀相关文件
  8538. {
  8539. if (!Directory.Exists(fileDir))
  8540. {
  8541. Directory.CreateDirectory(fileDir);
  8542. }
  8543. //上传的文件的路径
  8544. filePath = fileDir + $@"\商邀相关文件\{projectFileName}";
  8545. }
  8546. using (FileStream fs = System.IO.File.Create(filePath))
  8547. {
  8548. file.CopyTo(fs);
  8549. fs.Flush();
  8550. }
  8551. filePahts.Add(projectFileName);
  8552. }
  8553. return Ok(JsonView(true, "上传成功!", filePahts));
  8554. }
  8555. catch (Exception ex)
  8556. {
  8557. return Ok(JsonView(false, ex.Message));
  8558. }
  8559. }
  8560. #endregion
  8561. #region 商邀费用录入
  8562. /// <summary>
  8563. /// 根据团组Id查询商邀费用列表
  8564. /// </summary>
  8565. /// <param name="dto"></param>
  8566. /// <returns></returns>
  8567. [HttpPost]
  8568. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8569. public async Task<IActionResult> InvitationOfficialActivitiesList(InvitationOfficialActivitiesListDto dto)
  8570. {
  8571. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesList(dto);
  8572. if (groupData.Code != 0)
  8573. {
  8574. return Ok(JsonView(false, groupData.Msg));
  8575. }
  8576. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8577. }
  8578. /// <summary>
  8579. /// 商邀费用列表
  8580. /// 下载文件
  8581. /// </summary>
  8582. /// <param name="id"></param>
  8583. /// <returns></returns>
  8584. [HttpGet("{id}")]
  8585. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8586. public async Task<IActionResult> InvitationOfficialActivitiesListDownFile(int id)
  8587. {
  8588. if (id < 1) return Ok(JsonView(false, "请传入有效的Id!"));
  8589. var info = await _InvitationOfficialActivitiesRep.Query(x => x.Id == id).FirstAsync();
  8590. if (info == null) return Ok(JsonView(false, "数据不存在!"));
  8591. if (string.IsNullOrEmpty(info.Attachment)) return Ok(JsonView(false, "文件不存在!"));
  8592. var filePaths = new List<string>();
  8593. var filePathBase = @$"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/";
  8594. try
  8595. {
  8596. filePaths = JsonConvert.DeserializeObject<List<string>>(info.Attachment);
  8597. }
  8598. catch (Exception ex)
  8599. {
  8600. filePaths.Add(info.Attachment);
  8601. }
  8602. if (filePaths != null && filePaths.Count < 1) return Ok(JsonView(false, "文件不存在!"));
  8603. for (int i = 0; i < filePaths.Count; i++)
  8604. {
  8605. filePaths[i] = $"{filePathBase}{filePaths[i]}";
  8606. }
  8607. var zipFilePathGuid = $"{Guid.NewGuid()}.zip";
  8608. var zipFilePath = $"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件/{zipFilePathGuid}";
  8609. using (var zipFileStream = new FileStream(zipFilePath, FileMode.Create))
  8610. {
  8611. using (var zipArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Create))
  8612. {
  8613. foreach (string filePath in filePaths)
  8614. {
  8615. if (System.IO.File.Exists(filePath))
  8616. {
  8617. // 获取文件名
  8618. string fileName = Path.GetFileName(filePath);
  8619. // 将文件添加到ZIP归档中
  8620. zipArchive.CreateEntryFromFile(filePath, fileName);
  8621. }
  8622. }
  8623. }
  8624. }
  8625. return Ok(JsonView(new { url = @$"{AppSettingsHelper.Get("OfficeBaseUrl")}{AppSettingsHelper.Get("GrpFileFtpPath")}/商邀相关文件/{zipFilePathGuid}" }));
  8626. }
  8627. /// <summary>
  8628. /// 商邀费用 Info Page 基础数据源
  8629. /// </summary>
  8630. /// <returns></returns>
  8631. [HttpPost]
  8632. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8633. public async Task<IActionResult> InvitationOfficialActivityInitBasicData()
  8634. {
  8635. try
  8636. {
  8637. Result groupData = await _InvitationOfficialActivitiesRep.InitBasicData();
  8638. if (groupData.Code != 0)
  8639. {
  8640. return Ok(JsonView(false, groupData.Msg));
  8641. }
  8642. return Ok(JsonView(true, "操作成功", groupData.Data));
  8643. }
  8644. catch (Exception ex)
  8645. {
  8646. return Ok(JsonView(false, ex.Message));
  8647. throw;
  8648. }
  8649. }
  8650. /// <summary>
  8651. /// 根据商邀费用ID查询C表和商邀费用数据
  8652. /// </summary>
  8653. /// <param name="dto"></param>
  8654. /// <returns></returns>
  8655. [HttpPost]
  8656. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8657. public async Task<IActionResult> InvitationOfficialActivitiesById(InvitationOfficialActivitiesByIdDto dto)
  8658. {
  8659. try
  8660. {
  8661. Result groupData = await _InvitationOfficialActivitiesRep.InvitationOfficialActivitiesById(dto);
  8662. if (groupData.Code != 0)
  8663. {
  8664. return Ok(JsonView(false, groupData.Msg));
  8665. }
  8666. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8667. }
  8668. catch (Exception ex)
  8669. {
  8670. return Ok(JsonView(false, ex.Message));
  8671. throw;
  8672. }
  8673. }
  8674. /// <summary>
  8675. /// 商邀费用录入操作(Status:1.新增,2.修改)
  8676. /// </summary>
  8677. /// <param name="dto"></param>
  8678. /// <returns></returns>
  8679. [HttpPost]
  8680. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8681. public async Task<IActionResult> OpInvitationOfficialActivities(OpInvitationOfficialActivitiesDto dto)
  8682. {
  8683. //验证
  8684. if (dto.Status == 2)
  8685. {
  8686. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  8687. if (!valid) return Ok(JsonView(false, msg));
  8688. }
  8689. Result groupData = await _InvitationOfficialActivitiesRep.OpInvitationOfficialActivities(dto, _setDataRep.PostCurrencyByDiid);
  8690. if (groupData.Code != 0)
  8691. {
  8692. return Ok(JsonView(false, groupData.Msg));
  8693. }
  8694. #region 应用推送
  8695. try
  8696. {
  8697. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  8698. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  8699. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  8700. //2024-10-21 新增LZ UID
  8701. var userIds = new List<int>() { 21 };
  8702. string title = $"系统通知";
  8703. string content = "";
  8704. var diId = dto.DiId;
  8705. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  8706. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  8707. if (dto.Status == 1) content = $"[新增-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8708. else if (dto.Status == 2) content = $"[更新-商邀费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  8709. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  8710. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "81" };
  8711. await APNsTools.iOS_PushNotifications1("051", $"商邀费用审核", "", content, true, "ExpenseAuditWebView", h5);
  8712. }
  8713. catch (Exception ex)
  8714. {
  8715. }
  8716. #endregion
  8717. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  8718. }
  8719. /// <summary>
  8720. /// 商邀删除
  8721. /// </summary>
  8722. /// <param name="dto"></param>
  8723. /// <returns></returns>
  8724. [HttpPost]
  8725. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  8726. public async Task<IActionResult> DelInvitationOfficialActivities(DelBaseDto dto)
  8727. {
  8728. try
  8729. {
  8730. //验证
  8731. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 81);
  8732. if (!valid) return Ok(JsonView(false, msg));
  8733. _sqlSugar.BeginTran();
  8734. var res1 = _sqlSugar.Updateable<Grp_InvitationOfficialActivities>()
  8735. .SetColumns(it => new Grp_InvitationOfficialActivities()
  8736. {
  8737. IsDel = 1,
  8738. DeleteUserId = dto.DeleteUserId,
  8739. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  8740. })
  8741. .Where(it => it.Id == dto.Id)
  8742. .ExecuteCommand();
  8743. if (res1 > 0)
  8744. {
  8745. int _diId = 0;
  8746. var _ioaInfo = _sqlSugar.Queryable<Grp_InvitationOfficialActivities>().Where(it => it.Id == dto.Id).First();
  8747. if (_ioaInfo != null)
  8748. {
  8749. _diId = _ioaInfo.DiId;
  8750. }
  8751. var res2 = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  8752. .SetColumns(a => new Grp_CreditCardPayment()
  8753. {
  8754. IsDel = 1,
  8755. DeleteUserId = dto.DeleteUserId,
  8756. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  8757. })
  8758. .Where(a => a.CId == dto.Id && a.DIId == _diId && a.CTable == 81)
  8759. .ExecuteCommand();
  8760. if (res2 > 0)
  8761. {
  8762. _sqlSugar.CommitTran();
  8763. return Ok(JsonView(true, "删除成功!"));
  8764. }
  8765. }
  8766. _sqlSugar.RollbackTran();
  8767. return Ok(JsonView(false, "删除失败"));
  8768. }
  8769. catch (Exception ex)
  8770. {
  8771. _sqlSugar.RollbackTran();
  8772. return Ok(JsonView(false, ex.Message));
  8773. }
  8774. }
  8775. #endregion
  8776. #region 票据上传
  8777. /// <summary>
  8778. /// 团组模块文件上传
  8779. /// </summary>
  8780. /// <param name="dto"></param>
  8781. /// <returns></returns>
  8782. [HttpPost]
  8783. public IActionResult CommonSaveFile([FromForm] CommonSaveFileDto dto)
  8784. {
  8785. var jw = JsonView(false);
  8786. long M = 1024 * 1024;
  8787. if (dto.Files == null || dto.Files.Count == 0)
  8788. {
  8789. jw.Msg = "无文件信息!";
  8790. return Ok(jw);
  8791. }
  8792. if (dto.Files.Sum(x => x.Length) > 20 * M)
  8793. {
  8794. jw.Msg = "文件大小超过20M!";
  8795. return Ok(jw);
  8796. }
  8797. //var nameSp = dto.File.FileName.Split(".");
  8798. //if (nameSp.Length < 2)
  8799. //{
  8800. // jw.Msg = "拓展名称有误!";
  8801. // return Ok(jw);
  8802. //}
  8803. //var existsName = new string[]{ "RAR", "ZIP", "ARJ","GZ","Z","7Z","TAR" };
  8804. //if (!existsName.Contains(nameSp[1].ToUpper()))
  8805. //{
  8806. // jw.Msg = $"请使用指定拓展名!({string.Join("-",existsName)})";
  8807. // return Ok(jw);
  8808. //}
  8809. var Ctable = _sqlSugar.Queryable<Sys_SetData>().First(x => x.STid == 16 && x.IsDel == 0 && x.Id == dto.Ctable);
  8810. if (Ctable == null)
  8811. {
  8812. jw.Msg = "Ctable指向有误!";
  8813. return Ok(jw);
  8814. }
  8815. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  8816. if (groupInfo == null)
  8817. {
  8818. jw.Msg = "团组信息不存在!";
  8819. return Ok(jw);
  8820. }
  8821. Ctable.Name = Regex.Replace(Ctable.Name, @"[^\w\.@-]", "",
  8822. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8823. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  8824. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8825. var path = "\\GroupModelFiles\\" + groupInfo.TeamName + "\\" + Ctable.Name;
  8826. var fileBase = AppSettingsHelper.Get("GrpFileBasePath") + path;
  8827. try
  8828. {
  8829. if (!Directory.Exists(fileBase))
  8830. {
  8831. Directory.CreateDirectory(fileBase);
  8832. }
  8833. var saveArr = new List<Grp_GroupModelFile>();
  8834. foreach (var fileStream in dto.Files)
  8835. {
  8836. var fileName = fileStream.FileName;
  8837. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
  8838. string extension = Path.GetExtension(fileName);
  8839. int counter = 0;
  8840. //文件重命名验证
  8841. string newFilePath;
  8842. string currFileName;
  8843. do
  8844. {
  8845. string newFileName;
  8846. if (counter == 0) newFileName = $"{fileNameWithoutExtension}{extension}";
  8847. else newFileName = $"{fileNameWithoutExtension} ({counter}){extension}";
  8848. currFileName = newFileName;
  8849. newFilePath = Path.Combine(fileBase, newFileName);
  8850. counter++;
  8851. } while (System.IO.File.Exists(newFilePath));
  8852. var saveFilePath = fileBase + "\\" + currFileName;
  8853. var file = new Grp_GroupModelFile()
  8854. {
  8855. Cid = dto.Cid,
  8856. CreateTime = DateTime.Now,
  8857. CreateUserId = dto.Userid,
  8858. Ctable = dto.Ctable,
  8859. Diid = dto.Diid,
  8860. IsDel = 0,
  8861. FilePath = saveFilePath,
  8862. FileName = currFileName
  8863. };
  8864. using (FileStream fs = System.IO.File.Create(saveFilePath))
  8865. {
  8866. fileStream.CopyTo(fs);
  8867. fs.Flush();
  8868. }
  8869. saveArr.Add(file);
  8870. }
  8871. var addResult = _sqlSugar.Insertable<Grp_GroupModelFile>(saveArr).ExecuteCommand();
  8872. //url = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("GrpFileFtpPath") + path + "\\" + dto.File.FileName
  8873. jw = JsonView(true, "保存成功!", new
  8874. {
  8875. count = addResult,
  8876. filesName = saveArr.Select(x => x.FileName)
  8877. });
  8878. }
  8879. catch (Exception ex)
  8880. {
  8881. jw = JsonView(false, $"保存失败! ({ex.Message}) ", new
  8882. {
  8883. count = 0,
  8884. filesName = Array.Empty<string>(),
  8885. });
  8886. }
  8887. return Ok(jw);
  8888. }
  8889. /// <summary>
  8890. /// 查询各模块已保存文件
  8891. /// </summary>
  8892. /// <param name="dto"></param>
  8893. /// <returns></returns>
  8894. [HttpPost]
  8895. public IActionResult QueryGroupModelFile(QueryGroupModelFileDto dto)
  8896. {
  8897. var expression = Expressionable.Create<Grp_GroupModelFile>()
  8898. .AndIF(dto.UserId != -1, x => x.CreateUserId == dto.UserId);
  8899. var visaIds = _sqlSugar.Queryable<Sys_Users>().Where(x => x.JobPostId == 26).Select(x => x.Id).ToList();
  8900. if (visaIds.Contains(dto.UserId) && dto.Ctable == 80)
  8901. {
  8902. expression = Expressionable.Create<Grp_GroupModelFile>()
  8903. .And(x => visaIds.Contains(x.CreateUserId));
  8904. }
  8905. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>()
  8906. .Where(x => x.IsDel == 0 && x.Cid == dto.Cid && x.Ctable == dto.Ctable && x.Diid == dto.Diid)
  8907. .Where(expression.ToExpression())
  8908. .ToList();
  8909. //.ToPageList(pagenumber, pageSize, ref totalCount, ref totalPage)
  8910. return Ok(JsonView(true, "success", dbQuery.Select(x => new
  8911. {
  8912. x.FileName,
  8913. x.Id,
  8914. Url = AppSettingsHelper.Get("GrpFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("GrpFileBasePath"), AppSettingsHelper.Get("GrpFileFtpPath")),
  8915. CreateTime = x.CreateTime.ToString("yyyy-MM-dd HH-mm"),
  8916. })));
  8917. }
  8918. /// <summary>
  8919. /// 下载该团组下的所有文件
  8920. /// </summary>
  8921. /// <param name="dto"></param>
  8922. /// <returns></returns>
  8923. [HttpPost]
  8924. public IActionResult ExportGroupZip(ExportGroupZipDto dto)
  8925. {
  8926. var jw = JsonView(false);
  8927. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  8928. if (groupInfo == null)
  8929. {
  8930. jw.Msg = "团组信息不存在!";
  8931. return Ok(jw);
  8932. }
  8933. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  8934. var isModule = Convert.ToBoolean(dto.isModule);
  8935. var Zips = new Dictionary<string, Stream>();
  8936. var io = new IOOperatorHelper();
  8937. if (isModule)
  8938. {
  8939. var moduleGroup = dbQuery.GroupBy(x => x.Ctable);
  8940. foreach (var moduleArr in moduleGroup)
  8941. {
  8942. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == moduleArr.Key && x.IsDel == 0);
  8943. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  8944. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8945. var chiZips = new Dictionary<string, Stream>();
  8946. foreach (var item in moduleArr)
  8947. {
  8948. if (System.IO.File.Exists(item.FilePath))
  8949. {
  8950. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  8951. {
  8952. byte[] bytes = new byte[fileStream.Length];
  8953. fileStream.Read(bytes, 0, bytes.Length);
  8954. fileStream.Close();
  8955. Stream stream = new MemoryStream(bytes);
  8956. chiZips.Add(item.FileName, stream);
  8957. }
  8958. }
  8959. }
  8960. if (chiZips.Count > 0)
  8961. {
  8962. var byts = io.ConvertZipStream(chiZips);
  8963. Stream stream = new MemoryStream(byts);
  8964. Zips.Add(key.Name + "_.zip", stream);
  8965. }
  8966. }
  8967. }
  8968. else
  8969. {
  8970. foreach (var item in dbQuery)
  8971. {
  8972. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  8973. {
  8974. byte[] bytes = new byte[fileStream.Length];
  8975. fileStream.Read(bytes, 0, bytes.Length);
  8976. fileStream.Close();
  8977. var stream = new MemoryStream(bytes);
  8978. while (Zips.ContainsKey(item.FileName))
  8979. {
  8980. item.FileName = new Random().Next(100) + "_" + item.FileName;
  8981. }
  8982. Zips.Add(item.FileName, stream);
  8983. }
  8984. }
  8985. }
  8986. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  8987. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  8988. if (Zips.Count > 0)
  8989. {
  8990. var byts = io.ConvertZipStream(Zips);
  8991. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  8992. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_.Zip");
  8993. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_.zip" });
  8994. }
  8995. else
  8996. {
  8997. jw.Msg = "暂无生成文件!";
  8998. }
  8999. return Ok(jw);
  9000. }
  9001. /// <summary>
  9002. /// 下载该团组下此模块的所有文件
  9003. /// </summary>
  9004. /// <param name="dto"></param>
  9005. /// <returns></returns>
  9006. [HttpPost]
  9007. public IActionResult ExportGroupByModule(ExportGroupByModuleDto dto)
  9008. {
  9009. var jw = JsonView(false);
  9010. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  9011. if (groupInfo == null)
  9012. {
  9013. jw.Msg = "团组信息不存在!";
  9014. return Ok(jw);
  9015. }
  9016. var dbQuery = _sqlSugar.Queryable<Grp_GroupModelFile>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid && x.Ctable == dto.Ctable).ToList();
  9017. var key = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.Ctable
  9018. && x.IsDel == 0);
  9019. if (key == null)
  9020. {
  9021. jw.Msg = "Ctable指向错误!";
  9022. return Ok(jw);
  9023. }
  9024. key.Name = Regex.Replace(key.Name, @"[^\w\.@-]", "",
  9025. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  9026. groupInfo.TeamName = Regex.Replace(groupInfo.TeamName, @"[^\w\.@-]", "",
  9027. RegexOptions.None, TimeSpan.FromSeconds(1.5));
  9028. var io = new IOOperatorHelper();
  9029. var Zips = new Dictionary<string, Stream>();
  9030. foreach (var item in dbQuery)
  9031. {
  9032. if (System.IO.File.Exists(item.FilePath))
  9033. {
  9034. using (var fileStream = new FileStream(item.FilePath, FileMode.Open, FileAccess.Read))
  9035. {
  9036. byte[] bytes = new byte[fileStream.Length];
  9037. fileStream.Read(bytes, 0, bytes.Length);
  9038. fileStream.Close();
  9039. var stream = new MemoryStream(bytes);
  9040. while (Zips.ContainsKey(item.FileName))
  9041. {
  9042. item.FileName = new Random().Next(100) + "_" + item.FileName;
  9043. }
  9044. Zips.Add(item.FileName, stream);
  9045. }
  9046. }
  9047. }
  9048. if (Zips.Count > 0)
  9049. {
  9050. var byts = io.ConvertZipStream(Zips);
  9051. var path = "\\GroupModelFiles\\" + groupInfo.TeamName;
  9052. io.ByteToFile(byts, AppSettingsHelper.Get("GrpFileBasePath") + $"{path}\\{groupInfo.TeamName}_{key.Name}_.Zip");
  9053. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("GrpFileBaseUrl") + $"{AppSettingsHelper.Get("GrpFileFtpPath")}{path}\\{groupInfo.TeamName}_{key.Name}_.Zip" });
  9054. }
  9055. else
  9056. {
  9057. jw.Msg = "暂无生成文件!";
  9058. }
  9059. return Ok(jw);
  9060. }
  9061. /// <summary>
  9062. /// 删除该团组下的指定文件
  9063. /// </summary>
  9064. /// <param name="dto"></param>
  9065. /// <returns></returns>
  9066. [HttpPost]
  9067. public IActionResult DeleteGroupFile(DeleteGroupFileDto dto)
  9068. {
  9069. var jw = JsonView(false);
  9070. var sing = _sqlSugar.Queryable<Grp_GroupModelFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  9071. if (sing == null)
  9072. {
  9073. jw.Msg = "暂无";
  9074. return Ok(jw);
  9075. }
  9076. if (System.IO.File.Exists(sing.FilePath))
  9077. {
  9078. try
  9079. {
  9080. System.IO.File.Delete(sing.FilePath);
  9081. }
  9082. catch (Exception ex)
  9083. {
  9084. jw.Msg = "删除失败!" + ex.Message;
  9085. return Ok(jw);
  9086. }
  9087. }
  9088. sing.IsDel = 1;
  9089. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9090. sing.DeleteUserId = dto.UserId;
  9091. _sqlSugar.Updateable<Grp_GroupModelFile>(sing).ExecuteCommand();
  9092. jw = JsonView(true, "删除成功!");
  9093. return Ok(jw);
  9094. }
  9095. #endregion
  9096. #region 共享文件上传
  9097. /// <summary>
  9098. /// 超支通知推送
  9099. /// </summary>
  9100. /// <param name="dto"></param>
  9101. /// <returns></returns>
  9102. [HttpPost]
  9103. public async Task<IActionResult> qyWeChatNotification(qyWeChatNotificationDto dto)
  9104. {
  9105. //81 邀请/公务活动
  9106. var syCTable = new List<int> { 81 };
  9107. //76 酒店预订
  9108. //79 车/导游地接
  9109. //85 机票预订
  9110. var gjCTable = new List<int> { 76, 79, 85 };
  9111. var jw = JsonView(false);
  9112. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.IsDel == 0 && x.Id == dto.Diid);
  9113. if (di == null)
  9114. {
  9115. jw.Msg = "团组信息不存在!";
  9116. return Ok(jw);
  9117. }
  9118. var user = _sqlSugar.Queryable<Sys_Users>().First(x => x.IsDel == 0 && x.Id == dto.UserId);
  9119. if (user == null)
  9120. {
  9121. jw.Msg = "用户信息不存在!";
  9122. return Ok(jw);
  9123. }
  9124. if (syCTable.Contains(dto.CTable))
  9125. {
  9126. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat02);
  9127. }
  9128. else if (gjCTable.Contains(dto.CTable))
  9129. {
  9130. await AppNoticeLibrary.SendChatMsg_ExpenseOverrunsChat(dto.Diid, dto.UserId, dto.CTable, QiyeWeChatEnum.ExpenseOverrunsChat01);
  9131. }
  9132. else
  9133. {
  9134. jw.Msg = "CTABLE类型有误!";
  9135. }
  9136. jw = JsonView(true, "推送成功!", "");
  9137. return Ok(jw);
  9138. }
  9139. /// <summary>
  9140. /// 共享文件数据初始化
  9141. /// </summary>
  9142. /// <returns></returns>
  9143. [HttpGet]
  9144. public async Task<IActionResult> SharedFileInit(int userid, int portType)
  9145. {
  9146. var marketingDepartmentIds = new List<int> { 6, 26, 27, 28 };
  9147. var isMarketingDepartment = _sqlSugar.Queryable<Sys_Users>()
  9148. .Where(x => x.IsDel == 0 && marketingDepartmentIds.Contains(x.DepId))
  9149. .Select(x => x.Id)
  9150. .ToList()
  9151. .Contains(userid);
  9152. var dropDownType = _sqlSugar.Queryable<Sys_SetData>()
  9153. .Where(x => x.STid == 111 && x.IsDel == 0)
  9154. .Select(x => new
  9155. {
  9156. x.Name,
  9157. x.Id,
  9158. }).ToList();
  9159. if (isMarketingDepartment)
  9160. {
  9161. dropDownType = dropDownType.Where(x => x.Id == 1412).ToList();
  9162. }
  9163. if (portType == 1)
  9164. {
  9165. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  9166. var dropDownGroupList = _sqlSugar.Queryable<Grp_DelegationInfo>()
  9167. .Where(x => x.IsDel == 0)
  9168. .OrderByDescending(x => x.VisitDate)
  9169. .Select(x => new
  9170. {
  9171. x.TeamName,
  9172. x.Id,
  9173. x.CityId,
  9174. })
  9175. .ToList()
  9176. .Select(x =>
  9177. {
  9178. var provinceId = x.CityId;
  9179. var isDefualtVal = true;
  9180. if (provinceId > 0)
  9181. {
  9182. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  9183. if (parentId != null)
  9184. {
  9185. isDefualtVal = false;
  9186. provinceId = (int)parentId;
  9187. }
  9188. }
  9189. if (isDefualtVal)
  9190. {
  9191. provinceId = 122; //默认四川
  9192. }
  9193. return new
  9194. {
  9195. x.TeamName,
  9196. x.Id,
  9197. provinceId,
  9198. };
  9199. })
  9200. .ToList();
  9201. return Ok(JsonView(true, "SUCCESS!", new
  9202. {
  9203. dropDownType,
  9204. dropDownGroupList,
  9205. isMarketingDepartment
  9206. }));
  9207. }
  9208. else if (portType == 2 || portType == 3)
  9209. {
  9210. return Ok(JsonView(true, "SUCCESS!", new
  9211. {
  9212. dropDownType,
  9213. isMarketingDepartment
  9214. }));
  9215. }
  9216. else
  9217. {
  9218. return Ok(JsonView(false, "portType有误!"));
  9219. }
  9220. }
  9221. /// <summary>
  9222. /// 共享文件上传
  9223. /// </summary>
  9224. /// <param name="dto"></param>
  9225. /// <returns></returns>
  9226. [HttpPost]
  9227. public IActionResult SharedFileUpload([FromForm] SharedFileUploadDto dto)
  9228. {
  9229. var isGroup = new List<int> { 1412 };
  9230. if (isGroup.Contains(dto.FileType) && dto.Diid < 1)
  9231. {
  9232. return Ok(JsonView(false, "该文件需要关联团组!"));
  9233. }
  9234. if (dto.Files == null || dto.Files.Count == 0)
  9235. {
  9236. return Ok(JsonView(false, "无文件信息!"));
  9237. }
  9238. if (dto.Files.Sum(x => x.Length) > 20 * 1024 * 1024)
  9239. {
  9240. return Ok(JsonView(false, "文件大小超过20M!"));
  9241. }
  9242. if (dto.Userid < 1)
  9243. {
  9244. return Ok(JsonView(false, "请传入有效的Userid!"));
  9245. }
  9246. var jobInfo = _sqlSugar.Queryable<Sys_Users, Sys_JobPost>((u, j) => u.JobPostId == j.Id && j.IsDel == 0)
  9247. .Where(u => u.IsDel == 0 && u.Id == dto.Userid)
  9248. .Select((u, j) => new
  9249. {
  9250. u.CnName,
  9251. UserId = u.Id,
  9252. j.JobName,
  9253. })
  9254. .First();
  9255. if (jobInfo == null)
  9256. {
  9257. return Ok(JsonView(false, "请传入有效的Userid!"));
  9258. }
  9259. var commonFileExtensions = new List<string>
  9260. {
  9261. // 文本文件
  9262. ".txt", ".doc", ".docx", ".odt", ".pdf", ".rtf", ".md", ".log",
  9263. // 图片文件
  9264. ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg",
  9265. // 视频文件
  9266. ".mp4", ".avi", ".mov", ".mkv", ".wmv", ".flv", ".mpg", ".mpeg",
  9267. // 音频文件
  9268. ".mp3", ".wav", ".ogg", ".aac", ".flac",
  9269. // 压缩文件
  9270. ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2",
  9271. // 数据文件
  9272. ".csv", ".xls", ".xlsx", ".json", ".xml", ".yaml", ".ini",
  9273. };
  9274. try
  9275. {
  9276. var setting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1416);
  9277. var settingExtend = JsonConvert.DeserializeObject<List<string>>(setting.Remark);
  9278. commonFileExtensions.AddRange(settingExtend);
  9279. }
  9280. catch (Exception)
  9281. { }
  9282. var setdata = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == dto.FileType);
  9283. if (setdata == null)
  9284. {
  9285. return Ok(JsonView(false, "请传入有效的FileType!"));
  9286. }
  9287. var insertList = new List<Grp_GroupShareFile>();
  9288. string winPath = AppSettingsHelper.Get("ShareFileBasePath") + $"{setdata.Name}/";
  9289. if (!Directory.Exists(winPath))
  9290. {
  9291. Directory.CreateDirectory(winPath);
  9292. }
  9293. foreach (var item in dto.Files)
  9294. {
  9295. var houzui = Path.GetExtension(item.FileName);
  9296. if (!commonFileExtensions.Contains(houzui))
  9297. {
  9298. return Ok(JsonView(false, "未知后缀名称!"));
  9299. }
  9300. var fileName = $"{jobInfo.JobName}-{jobInfo.CnName}-{item.FileName}";
  9301. var saveFilePath = winPath + fileName;
  9302. using (FileStream fs = System.IO.File.Create(saveFilePath))
  9303. {
  9304. item.CopyTo(fs);
  9305. fs.Flush();
  9306. }
  9307. var fileDetail = new Grp_GroupShareFile()
  9308. {
  9309. CreateUserId = dto.Userid,
  9310. CreateTime = DateTime.Now,
  9311. UploadJob = jobInfo.JobName,
  9312. FileName = fileName,
  9313. FileType = dto.FileType,
  9314. Diid = dto.Diid,
  9315. FilePath = winPath + fileName,
  9316. };
  9317. insertList.Add(fileDetail);
  9318. }
  9319. _sqlSugar.Insertable<Grp_GroupShareFile>(insertList).ExecuteCommand();
  9320. return Ok(JsonView(true, "保存成功!"));
  9321. }
  9322. /// <summary>
  9323. /// 查询共享文件列表
  9324. /// </summary>
  9325. /// <param name="dto"></param>
  9326. /// <returns></returns>
  9327. [HttpPost]
  9328. public IActionResult QuerySharedFile(QuerySharedFileDto dto)
  9329. {
  9330. var isGroup = new List<int> { 1412 };
  9331. if (!isGroup.Contains(dto.FileType)) dto.Diid = 0;
  9332. var queryExpression = Expressionable.Create<Grp_GroupShareFile>()
  9333. .And(x => x.Diid == dto.Diid)
  9334. .And(x => x.FileType == dto.FileType)
  9335. .And(x => x.IsDel == 0)
  9336. .AndIF(!dto.FileName.IsNullOrWhiteSpace(), x => x.FileName.Contains(dto.FileName))
  9337. .AndIF(DateTime.TryParse(dto.StartTime, out DateTime Start), x => x.CreateTime >= Start)
  9338. .AndIF(DateTime.TryParse(dto.EndTime, out DateTime End), x => x.CreateTime <= End);
  9339. int totalCount = 0;
  9340. var dbQuery = _sqlSugar.Queryable<Grp_GroupShareFile>()
  9341. .Where(queryExpression.ToExpression())
  9342. .OrderBy(x => x.UploadJob)
  9343. .Select(x => new
  9344. {
  9345. x.Id,
  9346. FilePath = AppSettingsHelper.Get("ShareFileBaseUrl") + x.FilePath.Replace(AppSettingsHelper.Get("ShareFileBasePath"), AppSettingsHelper.Get("ShareFileFtpPath")),
  9347. x.FileName,
  9348. x.FileType,
  9349. x.CreateTime,
  9350. })
  9351. .ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
  9352. return Ok(JsonView(true, "SUCCESS!", new
  9353. {
  9354. FileList = dbQuery,
  9355. dto.PageSize,
  9356. dto.PageIndex,
  9357. totalCount
  9358. }));
  9359. }
  9360. /// <summary>
  9361. /// 删除共享文件模块下的指定文件
  9362. /// </summary>
  9363. /// <param name="dto"></param>
  9364. /// <returns></returns>
  9365. [HttpPost]
  9366. public IActionResult DeleteSharedFile(DeleteGroupFileDto dto)
  9367. {
  9368. var jw = JsonView(false);
  9369. var sing = _sqlSugar.Queryable<Grp_GroupShareFile>().First(x => x.Id == dto.Id && x.IsDel == 0);
  9370. if (sing == null)
  9371. {
  9372. jw.Msg = "暂无文件信息!";
  9373. return Ok(jw);
  9374. }
  9375. if (sing.CreateUserId != dto.UserId)
  9376. {
  9377. jw.Msg = "只能删除自己上传的文件!";
  9378. return Ok(jw);
  9379. }
  9380. if (System.IO.File.Exists(sing.FilePath))
  9381. {
  9382. try
  9383. {
  9384. System.IO.File.Delete(sing.FilePath);
  9385. }
  9386. catch (Exception ex)
  9387. {
  9388. jw.Msg = "删除失败!" + ex.Message;
  9389. return Ok(jw);
  9390. }
  9391. }
  9392. sing.IsDel = 1;
  9393. sing.DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9394. sing.DeleteUserId = dto.UserId;
  9395. _sqlSugar.Updateable<Grp_GroupShareFile>(sing).ExecuteCommand();
  9396. jw = JsonView(true, "删除成功!");
  9397. return Ok(jw);
  9398. }
  9399. #endregion
  9400. #region 团组英文资料
  9401. /// <summary>
  9402. /// 查询团组英文所有资料
  9403. /// </summary>
  9404. /// <param name="dto"></param>
  9405. /// <returns></returns>
  9406. [HttpPost]
  9407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9408. public async Task<IActionResult> QueryDelegationEnData(QueryDelegationEnDataDto dto)
  9409. {
  9410. try
  9411. {
  9412. Result groupData = await _delegationEnDataRep.QueryDelegationEnData(dto);
  9413. if (groupData.Code != 0)
  9414. {
  9415. return Ok(JsonView(false, groupData.Msg));
  9416. }
  9417. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9418. }
  9419. catch (Exception ex)
  9420. {
  9421. return Ok(JsonView(false, ex.Message));
  9422. throw;
  9423. }
  9424. }
  9425. /// <summary>
  9426. /// 团组英文资料操作(Status:1.新增,2.修改)
  9427. /// </summary>
  9428. /// <param name="dto"></param>
  9429. /// <returns></returns>
  9430. [HttpPost]
  9431. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9432. public async Task<IActionResult> OpDelegationEnData(OpDelegationEnDataDto dto)
  9433. {
  9434. try
  9435. {
  9436. Result groupData = await _delegationEnDataRep.OpDelegationEnData(dto);
  9437. if (groupData.Code != 0)
  9438. {
  9439. return Ok(JsonView(false, groupData.Msg));
  9440. }
  9441. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  9442. }
  9443. catch (Exception ex)
  9444. {
  9445. return Ok(JsonView(false, ex.Message));
  9446. throw;
  9447. }
  9448. }
  9449. /// <summary>
  9450. /// 团组英文资料Id查询数据
  9451. /// </summary>
  9452. /// <param name="dto"></param>
  9453. /// <returns></returns>
  9454. [HttpPost]
  9455. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9456. public async Task<IActionResult> QueryDelegationEnDataById(QueryDelegationEnDataByIdDto dto)
  9457. {
  9458. try
  9459. {
  9460. Grp_DelegationEnData _DelegationEnData = await _sqlSugar.Queryable<Grp_DelegationEnData>().FirstAsync(it => it.Id == dto.Id && it.IsDel == 0);
  9461. if (_DelegationEnData != null)
  9462. {
  9463. return Ok(JsonView(true, "查询成功!", _DelegationEnData));
  9464. }
  9465. return Ok(JsonView(true, "暂无数据!", _DelegationEnData));
  9466. }
  9467. catch (Exception ex)
  9468. {
  9469. return Ok(JsonView(false, "程序错误!"));
  9470. throw;
  9471. }
  9472. }
  9473. /// <summary>
  9474. /// 团组英文资料删除
  9475. /// </summary>
  9476. /// <param name="dto"></param>
  9477. /// <returns></returns>
  9478. [HttpPost]
  9479. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9480. public async Task<IActionResult> DelDelegationEnData(DelBaseDto dto)
  9481. {
  9482. try
  9483. {
  9484. var res = await _delegationEnDataRep.SoftDeleteByIdAsync<Grp_DelegationEnData>(dto.Id.ToString(), dto.DeleteUserId);
  9485. if (!res)
  9486. {
  9487. return Ok(JsonView(false, "删除失败"));
  9488. }
  9489. return Ok(JsonView(true, "删除成功!"));
  9490. }
  9491. catch (Exception ex)
  9492. {
  9493. return Ok(JsonView(false, ex.Message));
  9494. throw;
  9495. }
  9496. }
  9497. #endregion
  9498. #region 导出邀请函
  9499. /// <summary>
  9500. /// 导出邀请函页面初始化
  9501. /// </summary>
  9502. /// <param name="dto"></param>
  9503. /// <returns></returns>
  9504. [HttpPost]
  9505. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9506. public async Task<IActionResult> QueryinvitationLetter(DecreasePaymentsListDto dto)
  9507. {
  9508. try
  9509. {
  9510. var grp_Delegations = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(a => a.IsDel == 0).OrderBy(a => a.VisitStartDate, OrderByType.Desc).ToList();
  9511. var crm_Deles = new List<Crm_DeleClient>();
  9512. if (dto.DiId == 0)
  9513. {
  9514. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == grp_Delegations[0].Id && a.IsDel == 0).ToListAsync();
  9515. }
  9516. else
  9517. {
  9518. crm_Deles = await _sqlSugar.Queryable<Crm_DeleClient>().Where(a => a.DiId == dto.DiId && a.IsDel == 0).ToListAsync();
  9519. }
  9520. return Ok(JsonView(true, "查询成功!", new
  9521. {
  9522. deleClient = crm_Deles,
  9523. delegations = grp_Delegations
  9524. }));
  9525. }
  9526. catch (Exception ex)
  9527. {
  9528. return Ok(JsonView(false, "程序错误!"));
  9529. throw;
  9530. }
  9531. }
  9532. /// <summary>
  9533. /// 导出邀请函
  9534. /// </summary>
  9535. /// <param name="dto"></param>
  9536. /// <returns></returns>
  9537. [HttpPost]
  9538. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9539. public async Task<IActionResult> invitationLetter(DecreasePaymentsListDto dto)
  9540. {
  9541. #region 参数验证
  9542. //if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  9543. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数!"));
  9544. #endregion
  9545. try
  9546. {
  9547. var transDic = new Dictionary<string, string>();
  9548. string sql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  9549. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  9550. From Grp_TourClientList tcl
  9551. Left Join
  9552. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  9553. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  9554. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  9555. From Crm_DeleClient dc
  9556. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  9557. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  9558. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  9559. Where dc.IsDel = 0) temp
  9560. On temp.DcId =tcl.ClientId
  9561. Where tcl.IsDel = 0 And tcl.DiId = {0}", dto.DiId);
  9562. var datas = _sqlSugar.SqlQueryable<TourClientListDetailsView>(sql).ToList();
  9563. var texts = new List<string>();
  9564. if (datas.Count != 0)
  9565. {
  9566. foreach (TourClientListDetailsView item in datas)
  9567. {
  9568. if (!string.IsNullOrWhiteSpace(item.Pinyin))
  9569. {
  9570. transDic.Add(item.LastName + item.FirstName, item.Pinyin);
  9571. }
  9572. else
  9573. {
  9574. string name = item.LastName + item.FirstName;
  9575. texts.Add(name);
  9576. }
  9577. if (!string.IsNullOrEmpty(item.Job) && !texts.Contains(item.Job))
  9578. {
  9579. if (!transDic.ContainsKey(item.Job))
  9580. {
  9581. texts.Add(item.Job);
  9582. }
  9583. }
  9584. if (!string.IsNullOrEmpty(item.CompanyFullName))
  9585. {
  9586. texts.Add(item.CompanyFullName);
  9587. }
  9588. }
  9589. var transData = await _airTicketResRep.ReTransBatch(texts, "en");
  9590. if (transData.Count > 0)
  9591. {
  9592. foreach (TranslateResult item in transData)
  9593. {
  9594. if (!transDic.ContainsKey(item.Query))
  9595. {
  9596. transDic.Add(item.Query, item.Translation);
  9597. }
  9598. }
  9599. }
  9600. var list = new List<GuestList>();
  9601. foreach (var dele in datas)
  9602. {
  9603. var guestList = new GuestList();
  9604. if (!string.IsNullOrWhiteSpace(dele.Pinyin))
  9605. {
  9606. guestList.Name = dele.Pinyin;
  9607. }
  9608. else
  9609. {
  9610. string Name = transDic.Where(s => s.Key == dele.LastName + dele.FirstName).FirstOrDefault().Value;
  9611. guestList.Name = Name;
  9612. }
  9613. if (dele.Sex == 0)
  9614. {
  9615. guestList.Sex = "Male";
  9616. }
  9617. else if (dele.Sex == 1)
  9618. {
  9619. guestList.Sex = "Female";
  9620. }
  9621. guestList.DOB = dele.BirthDay.Replace('-', '.');
  9622. if (!string.IsNullOrEmpty(dele.Job))
  9623. {
  9624. guestList.Job = dele.Job;
  9625. }
  9626. list.Add(guestList);
  9627. }
  9628. //载入模板
  9629. var doc = new Document(AppSettingsHelper.Get("WordBasePath") + "Template/邀请函模板0210.docx");
  9630. var builder = new DocumentBuilder(doc);
  9631. //获取word里所有表格
  9632. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  9633. //获取所填表格的序数
  9634. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  9635. var rowStart = tableOne.Rows[0]; //获取第1行
  9636. //循环赋值
  9637. for (int i = 0; i < list.Count; i++)
  9638. {
  9639. builder.MoveToCell(0, i + 1, 0, 0);
  9640. builder.Write(list[i].Name.ToString());
  9641. builder.MoveToCell(0, i + 1, 1, 0);
  9642. builder.Write(list[i].Sex.ToString());
  9643. builder.MoveToCell(0, i + 1, 2, 0);
  9644. builder.Write(list[i].DOB.ToString());
  9645. builder.MoveToCell(0, i + 1, 3, 0);
  9646. builder.Write(list[i].Job.ToString());
  9647. }
  9648. //删除多余行
  9649. while (tableOne.Rows.Count > list.Count + 1)
  9650. {
  9651. tableOne.Rows.RemoveAt(list.Count + 1);
  9652. }
  9653. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  9654. string fileName = "邀请函" + DateTime.Now.ToString("yyyy-MM-dd") + ".docx";
  9655. string filePath = fileDir + $@"商邀相关文件/{fileName}";
  9656. doc.Save(filePath);
  9657. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/GrpFile/商邀相关文件/" + fileName;
  9658. return Ok(JsonView(true, "操作成功!", Url));
  9659. }
  9660. else
  9661. {
  9662. return Ok(JsonView(false, "该团组客户名单暂未录入!"));
  9663. }
  9664. }
  9665. catch (Exception ex)
  9666. {
  9667. return Ok(JsonView(false, ex.Message));
  9668. throw;
  9669. }
  9670. }
  9671. #endregion
  9672. #region 团组经理模块 出入境费用
  9673. /// <summary>
  9674. /// 团组模块 - 出入境费用 - 省份基础数据源
  9675. /// </summary>
  9676. /// <returns></returns>
  9677. [HttpGet]
  9678. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9679. public async Task<IActionResult> GetEnterExitProvBelongCostDataSource()
  9680. {
  9681. return Ok(JsonView(await _groupRepository.ProvinceBasicSource()));
  9682. }
  9683. /// <summary>
  9684. /// 团组模块 - 出入境费用 - 基础数据源(团组名称/币种类型)
  9685. /// </summary>
  9686. /// <param name="dto"></param>
  9687. /// <returns></returns>
  9688. [HttpPost]
  9689. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9690. public async Task<IActionResult> GetEnterExitCostDataSource(EnterExitCostDataSourceDto dto)
  9691. {
  9692. var groupNameData = await _groupRepository.EnterExitCostGroupNameAsync();
  9693. var groupNamFirst = groupNameData.FirstOrDefault();
  9694. //SetDataInfoView
  9695. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  9696. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  9697. List<SetDataInfoView> _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  9698. //验证城市归属并给默认值
  9699. int provinceId = 122;
  9700. if (groupNamFirst != null) provinceId = groupNamFirst.ProvinceId;
  9701. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  9702. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  9703. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  9704. return Ok(JsonView(true, "查询成功!", new
  9705. {
  9706. GroupNameData = groupNameData,
  9707. CurrencyData = _CurrencyData,
  9708. WordTypeData = wordTypeData,
  9709. ExcelTypeData = excelTypeData,
  9710. CurrencyInit = _currencyInfos
  9711. }));
  9712. }
  9713. /// <summary>
  9714. /// 团组模块 - 出入境费用 - 文件类型list 跟据省份Id获取
  9715. /// </summary>
  9716. /// <returns></returns>
  9717. [HttpGet("{provinceId}")]
  9718. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9719. public async Task<IActionResult> EnterExitCostFileOwner([FromRoute] int provinceId = 122)
  9720. {
  9721. //验证城市归属并给默认值
  9722. if (provinceId < 1) provinceId = 122;
  9723. /*
  9724. * 122 四川
  9725. * 108 贵州
  9726. * 103 重庆
  9727. * 132 云南
  9728. */
  9729. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  9730. return Ok(JsonView(true, "查询成功!", new
  9731. {
  9732. WordTypeData = wordTypeData,
  9733. ExcelTypeData = excelTypeData,
  9734. }));
  9735. }
  9736. /// <summary>
  9737. /// 团组模块 - 出入境费用
  9738. /// 实时汇率 tips
  9739. /// 签证费用 tips
  9740. /// 机票费用 tips
  9741. /// </summary>
  9742. /// <returns></returns>
  9743. [HttpPost]
  9744. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9745. public async Task<IActionResult> GetEnterExitCostCorrelationTips(EnterExitCostInfobyDiIdDto dto)
  9746. {
  9747. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(it => it.Id == dto.DiId && it.IsDel == 0);
  9748. //默认币种显示
  9749. var reteInfos = await GeneralMethod.EnterExitCostLiveRate();
  9750. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.DiId);
  9751. var airData = await GeneralMethod.EntryAndExitTips(dto.DiId);
  9752. return Ok(JsonView(true, "查询成功!", new
  9753. {
  9754. //GroupNameData = groupNameData.Data,
  9755. visaData = visaData.Data,
  9756. airData,
  9757. reteInfos
  9758. }));
  9759. }
  9760. #region 城市区间交通费
  9761. /// <summary>
  9762. /// 团组模块 - 出入境费用 - 基础数据源(境外用车)
  9763. /// </summary>
  9764. /// <param name="groupId"></param>
  9765. /// <returns></returns>
  9766. [HttpGet("{groupId}")]
  9767. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9768. public async Task<IActionResult> GetEnterExitCostOVByGroupId(int groupId)
  9769. {
  9770. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  9771. if (groupInfo == null)
  9772. {
  9773. return Ok(JsonView(false, "团组信息为空"));
  9774. }
  9775. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  9776. if (countryies?.Any() != true)
  9777. {
  9778. return Ok(JsonView(false, "团组出访国家信息为空"));
  9779. }
  9780. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  9781. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  9782. .Where(x => x.IsDel == 0 && x.STid == 66)
  9783. .ToListAsync();
  9784. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  9785. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  9786. .ToListAsync();
  9787. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  9788. //只返回接送机的数据
  9789. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  9790. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  9791. .ToListAsync();
  9792. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  9793. var overseaVehicleCityDatas = new List<dynamic>() {
  9794. new
  9795. {
  9796. Id = 0,
  9797. area= "未选择",
  9798. CarTypeName = "",
  9799. serviceType = "",
  9800. Price = 0.00M,
  9801. guidePrice = 0.00M,
  9802. otherPrice = 0.00M,
  9803. currency = 0,
  9804. currencyName = "",
  9805. currRate = 1.0000M,
  9806. LastUpdateUserName = "",
  9807. LastUpdateTime = "",
  9808. Remark = ""
  9809. }};
  9810. foreach (var item in overseaVehicleTypes)
  9811. {
  9812. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  9813. string area = string.Empty,
  9814. serviceType = "未设置",
  9815. currencyName = string.Empty;
  9816. decimal otherPrice = 0.00M;
  9817. if (parentInfo != null)
  9818. {
  9819. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  9820. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  9821. serviceType = item.ServiceType.GetDescription();
  9822. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  9823. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  9824. }
  9825. //当前币种汇率值
  9826. var currRate = 1.0000M;
  9827. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  9828. if (currencyInfo != null) currRate = currencyInfo.Rate;
  9829. overseaVehicleCityDatas.add(new
  9830. {
  9831. item.Id,
  9832. area,
  9833. item.CarTypeName,
  9834. serviceType,
  9835. item.Price,
  9836. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  9837. otherPrice,
  9838. currency = parentInfo?.Currency ?? 0,
  9839. currencyName,
  9840. currRate,
  9841. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  9842. item.LastUpdateTime,
  9843. item.Remark
  9844. });
  9845. }
  9846. var total = overseaVehicleCityDatas.Count;
  9847. var view = new
  9848. {
  9849. visitCountries = string.Join("、", countryies),
  9850. groupSize = groupInfo.VisitPNumber, //出访人数
  9851. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  9852. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  9853. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  9854. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  9855. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  9856. Currencies = currencies,
  9857. data = overseaVehicleCityDatas
  9858. };
  9859. if (overseaVehicleCityDatas.Count == 0)
  9860. {
  9861. return Ok(JsonView(true, "暂无数据!", view));
  9862. }
  9863. return Ok(JsonView(true, "查询成功!", view, total));
  9864. }
  9865. /// <summary>
  9866. /// 团组模块 - 出入境费用 - 境外用车计算详细信息
  9867. /// </summary>
  9868. /// <param name="groupId"></param>
  9869. /// <param name="currUserId"></param>
  9870. /// <returns></returns>
  9871. [HttpGet("{groupId}")]
  9872. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9873. public async Task<IActionResult> GetEnterExitCostOVFeeDetails(int groupId, int currUserId)
  9874. {
  9875. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  9876. if (groupInfo == null)
  9877. {
  9878. return Ok(JsonView(false, "团组信息为空"));
  9879. }
  9880. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  9881. //CityIntervalInfo
  9882. var info = new CityIntervalInfo();
  9883. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  9884. {
  9885. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  9886. return Ok(JsonView(true, "查询成功!", info));
  9887. }
  9888. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  9889. var userName = userInfo?.CnName ?? "-";
  9890. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9891. //返回默认数据
  9892. info = new CityIntervalInfo()
  9893. {
  9894. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  9895. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  9896. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  9897. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  9898. LastUpdateUserName = userName,
  9899. LastUpdateTime = nowTime,
  9900. CreateUserName = userName,
  9901. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  9902. CreateTime = nowTime
  9903. };
  9904. return Ok(JsonView(true, "查询成功!", info));
  9905. }
  9906. /// <summary>
  9907. /// 团组模块 - 出入境费用 - 境外用车计算 保存
  9908. /// </summary>
  9909. /// <param name="dto"></param>
  9910. /// <returns></returns>
  9911. [HttpPost]
  9912. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  9913. public async Task<IActionResult> GetEnterExitCostOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  9914. {
  9915. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  9916. if (groupInfo == null)
  9917. {
  9918. return Ok(JsonView(false, "团组信息为空"));
  9919. }
  9920. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  9921. if (userInfo == null)
  9922. {
  9923. return Ok(JsonView(false, "员工信息为空"));
  9924. }
  9925. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  9926. if (eecInfo == null)
  9927. {
  9928. return Ok(JsonView(false, "出入境费用信息为空"));
  9929. }
  9930. var oldData = new CityIntervalInfo();
  9931. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  9932. {
  9933. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  9934. }
  9935. var userName = userInfo?.CnName ?? "-";
  9936. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  9937. var info = new CityIntervalInfo()
  9938. {
  9939. APTFeeTotal = dto.APTFeeTotal,
  9940. APTFeeDetails = dto.APTFeeDetails,
  9941. PullCartFeeTotal = dto.PullCartFeeTotal,
  9942. PullCartFeeDetails = dto.PullCartFeeDetails,
  9943. TrainFeeTotal = dto.TrainFeeTotal,
  9944. TrainFeeDetails = dto.TrainFeeDetails,
  9945. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  9946. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  9947. Currencies = dto.Currencies,
  9948. LastUpdateUserName = userName,
  9949. LastUpdateTime = nowTime,
  9950. CreateUserName = oldData?.CreateUserName ?? userName,
  9951. CreateTime = oldData?.CreateTime ?? nowTime
  9952. };
  9953. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  9954. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  9955. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  9956. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  9957. .SetColumns(it => it.LastUpdateTime == nowTime)
  9958. .Where(x => x.Id == eecInfo.Id)
  9959. .ExecuteCommandAsync();
  9960. if (upd < 1)
  9961. {
  9962. return Ok(JsonView(false));
  9963. }
  9964. //返回数据处理
  9965. var label = new StringBuilder();
  9966. //接送机
  9967. if (dto.APTFeeDetails?.Any() == true)
  9968. {
  9969. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  9970. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  9971. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  9972. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  9973. .Select((ovtp, ov) => new
  9974. {
  9975. ovtp.Id,
  9976. ov.CountryName,
  9977. ov.CityName
  9978. }).ToListAsync();
  9979. var items = dto.APTFeeDetails
  9980. .Select(item =>
  9981. {
  9982. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  9983. if (areaInfo == null) return null;
  9984. return areaInfo.CountryName == areaInfo.CityName
  9985. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  9986. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  9987. })
  9988. .Where(item => item != null)
  9989. .ToList();
  9990. label.AppendLine($"接送机({string.Join("、", items)});");
  9991. }
  9992. //拉车
  9993. if (dto.PullCartFeeDetails?.Any() == true)
  9994. {
  9995. var feeLabel = string.Join("、",
  9996. dto.PullCartFeeDetails.Select(x =>
  9997. $"{x.Quote:#0.00} CNY"
  9998. ));
  9999. label.AppendLine($"拉车({feeLabel});");
  10000. }
  10001. //火车
  10002. if (dto.TrainFeeDetails?.Any() == true)
  10003. {
  10004. var feeLabel = string.Join("、",
  10005. dto.TrainFeeDetails.Select(x =>
  10006. $"{x.Quote:#0.00} CNY"
  10007. ));
  10008. label.AppendLine($"火车票({feeLabel});");
  10009. }
  10010. //城市机票
  10011. if (dto.CityAirTicketFeeDetails?.Any() == true)
  10012. {
  10013. var feeLabel = string.Join("、",
  10014. dto.CityAirTicketFeeDetails.Select(x =>
  10015. $"{x.Quote:#0.00} CNY"
  10016. ));
  10017. label.AppendLine($"城市机票({feeLabel});");
  10018. }
  10019. //费用
  10020. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  10021. decimal jjcQuote = quote;
  10022. decimal gwcQuote = quote;
  10023. decimal tdcQuote = quote;
  10024. var view = new
  10025. {
  10026. label = label.ToString(),
  10027. jjcQuote,
  10028. gwcQuote,
  10029. tdcQuote
  10030. };
  10031. return Ok(JsonView(view));
  10032. }
  10033. #endregion
  10034. /// <summary>
  10035. /// 团组模块 - 出入境费用 - Info
  10036. /// </summary>
  10037. /// <param name="dto"></param>
  10038. /// <returns></returns>
  10039. [HttpPost]
  10040. //[ApiLog("Grp_EnterExitCost", OperationEnum.Details)]
  10041. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10042. public async Task<IActionResult> GetEnterExitCostInfobyDiId(EnterExitCostInfobyDiIdDto dto)
  10043. {
  10044. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  10045. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  10046. return Ok(await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto));
  10047. }
  10048. /// <summary>
  10049. /// 团组模块 - 出入境费用 - 设置view权限
  10050. /// </summary>
  10051. /// <returns></returns>
  10052. [HttpPost]
  10053. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10054. public async Task<IActionResult> EnterExitCostSetViewPermissiion(EnterExitCostSetViewPermissiionDto dto)
  10055. {
  10056. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  10057. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  10058. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  10059. var permissions = new List<Grp_EnterExitCostPermission>();
  10060. foreach (var userId in dto.UserIds)
  10061. {
  10062. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.GroupId, UserId = userId, CreateUserId = dto.CurrUserId });
  10063. }
  10064. if (permissions.Any())
  10065. {
  10066. _sqlSugar.BeginTran();
  10067. try
  10068. {
  10069. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.GroupId).ExecuteCommandAsync();
  10070. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  10071. if (result < 1)
  10072. {
  10073. _sqlSugar.RollbackTran();
  10074. return Ok(JsonView(false));
  10075. }
  10076. }
  10077. catch (Exception ex)
  10078. {
  10079. _sqlSugar.RollbackTran();
  10080. return Ok(JsonView(false, ex.Message));
  10081. }
  10082. _sqlSugar.CommitTran();
  10083. return Ok(JsonView(true));
  10084. }
  10085. return Ok(JsonView(false));
  10086. }
  10087. /// <summary>
  10088. /// 团组模块 - 出入境费用 - Add And Update
  10089. /// </summary>
  10090. /// <returns></returns>
  10091. [HttpPost]
  10092. [ApiLog("Grp_EnterExitCost", OperationEnum.Add)]
  10093. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10094. public async Task<IActionResult> PostEnterExitCostOperate(EnterExitCostOperateDto dto)
  10095. {
  10096. try
  10097. {
  10098. var rateRecords = new List<RateRecordInfo>();
  10099. #region 汇率保存前存储
  10100. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == dto.DiId);
  10101. if (info != null)
  10102. {
  10103. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  10104. if (cacheRateInfos != null && cacheRateInfos.Count > 0)
  10105. {
  10106. rateRecords = cacheRateInfos.Select(x => new RateRecordInfo()
  10107. {
  10108. CurrencyCode = x.CurrencyCode,
  10109. CurrencyName = x.CurrencyName,
  10110. UpdatePreRate = x.Rate,
  10111. UpdateBreRate = dto.Currencys.Where(x1 => x1.CurrencyName.Equals(x.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M
  10112. }).ToList();
  10113. }
  10114. else
  10115. {
  10116. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  10117. {
  10118. CurrencyCode = x.CurrencyCode,
  10119. CurrencyName = x.CurrencyName,
  10120. UpdatePreRate = 0.00M,
  10121. UpdateBreRate = x.Rate
  10122. }).ToList();
  10123. }
  10124. }
  10125. else
  10126. {
  10127. rateRecords = dto.Currencys.Select(x => new RateRecordInfo()
  10128. {
  10129. CurrencyCode = x.CurrencyCode,
  10130. CurrencyName = x.CurrencyName,
  10131. UpdatePreRate = 0.00M,
  10132. UpdateBreRate = x.Rate
  10133. }).ToList();
  10134. }
  10135. #endregion
  10136. var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  10137. if (dto.DayOtherPriceData.Any())
  10138. {
  10139. var inserList = dto.DayOtherPriceData
  10140. .Where(x => x.Id == 0)
  10141. .Select(x => new Grp_DayOtherPrice
  10142. {
  10143. Cost = x.Cost,
  10144. Id = x.Id,
  10145. CreateTime = DateTime.Now,
  10146. CreateUserId = dto.UserId,
  10147. Currency = x.Currency,
  10148. Diid = x.DiId,
  10149. Index = x.Index,
  10150. IsDel = 0,
  10151. SetDataId = x.SetDataId,
  10152. SubTotal = x.SubTotal,
  10153. Remark = x.Remark
  10154. })
  10155. .ToList();
  10156. var updateList = dto.DayOtherPriceData
  10157. .Where(x => x.Id != 0)
  10158. .Select(x => new Grp_DayOtherPrice
  10159. {
  10160. Cost = x.Cost,
  10161. Id = x.Id,
  10162. CreateTime = DateTime.Now,
  10163. CreateUserId = dto.UserId,
  10164. Currency = x.Currency,
  10165. Diid = x.DiId,
  10166. Index = x.Index,
  10167. IsDel = 0,
  10168. SetDataId = x.SetDataId,
  10169. SubTotal = x.SubTotal,
  10170. Remark = x.Remark
  10171. })
  10172. .ToList();
  10173. //添加
  10174. _sqlSugar.BeginTran();
  10175. if (inserList.Any())
  10176. {
  10177. var rowCount = _sqlSugar.Insertable<Grp_DayOtherPrice>(inserList).ExecuteCommand();
  10178. }
  10179. if (updateList.Any())
  10180. {
  10181. var rowCount = _sqlSugar.Updateable<Grp_DayOtherPrice>(updateList).ExecuteCommand();
  10182. }
  10183. _sqlSugar.CommitTran();
  10184. }
  10185. if (data.Code != 0)
  10186. {
  10187. return Ok(JsonView(false, data.Msg));
  10188. }
  10189. //生成默认文件pdf并且通知人员
  10190. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  10191. {
  10192. DiId = dto.DiId,
  10193. ExportType = 1,
  10194. SubTypeId = 1005
  10195. }, "pdf");
  10196. //发送通知
  10197. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  10198. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  10199. string md5Sign = GeneralMethod.Encrypt($"{sign}&fileName={fileUrl}");
  10200. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", sign, fileUrl);
  10201. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(dto.DiId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  10202. //汇率信息记录
  10203. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  10204. var checkCurrencys = await _enterExitCostRep.GetCheckCurrencies(dto.DiId);
  10205. //汇率验证、反推
  10206. (bool isSendMsg, string msgContent, List<CurrencyInfo> liveRates) = await GeneralMethod.EnterExitCostCheckRate(dto.DiId, checkCurrencys);
  10207. if (isSendMsg)
  10208. {
  10209. //消息推送
  10210. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFin(dto.DiId, dto.UserId, msgContent);
  10211. }
  10212. #region 日志汇率记录
  10213. //按照已使用币种记录
  10214. if (checkCurrencys != null && checkCurrencys.Count > 0)
  10215. {
  10216. rateRecords = rateRecords.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  10217. //汇率记录中加入实时汇率
  10218. if (liveRates != null && liveRates.Count > 0)
  10219. {
  10220. foreach (var item in rateRecords)
  10221. {
  10222. item.CurrLiveRate = liveRates.Where(x => x.CurrencyName.Equals(item.CurrencyName)).FirstOrDefault()?.Rate ?? 0.00M;
  10223. }
  10224. }
  10225. var teamName = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.DiId && x.IsDel == 0).Select(x => x.TeamName).FirstAsync();
  10226. var operationName = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.UserId && x.IsDel == 0).Select(x => x.CnName).FirstAsync();
  10227. var logContent = new StringBuilder();
  10228. foreach (var item in rateRecords)
  10229. {
  10230. var blRate = (item.CurrLiveRate * 1.0350M).TruncDecimals(4);
  10231. string msg = $">- {item.CurrencyName}汇率:(页面保存前){item.UpdatePreRate:#0.0000}/(页面保存){item.UpdateBreRate:#0.0000}/实时汇率(已上浮1.0350):{blRate:#0.0000}【注:原接口输出汇率为:{item.CurrLiveRate:#0.0000}】";
  10232. logContent.AppendLine(msg);
  10233. }
  10234. _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());
  10235. }
  10236. #endregion
  10237. return Ok(JsonView(true, data.Msg, data.Data));
  10238. }
  10239. catch (Exception ex)
  10240. {
  10241. return Ok(JsonView(false, ex.Message));
  10242. }
  10243. }
  10244. /// <summary>
  10245. /// 团组模块 - 出入境费用 - Confirm 费用
  10246. /// </summary>
  10247. /// <returns></returns>
  10248. [HttpPost]
  10249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10250. public async Task<IActionResult> PostEnterExitCostIsConfirm(ConfirmCostDto dto)
  10251. {
  10252. //TODO:测试完毕需把对应的用户ID更改
  10253. //1、数据表添加字段
  10254. //2、更改字段接口()
  10255. var _view = await _enterExitCostRep.ConfirmCost(dto);
  10256. //3、确认成功 给财务发送消息
  10257. if (_view.Code == 200)
  10258. {
  10259. if (dto.Type == 1)
  10260. {
  10261. int diId = _enterExitCostRep._sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.Id == dto.Id).First()?.DiId ?? 0;
  10262. await AppNoticeLibrary.SendUserMsg_GroupShare_ToFinance(diId);
  10263. }
  10264. }
  10265. return Ok(_view);
  10266. }
  10267. /// <summary>
  10268. /// 团组模块 - 出入境费用 - File download
  10269. /// </summary>
  10270. /// <param name="dto"></param>
  10271. /// <returns></returns>
  10272. [HttpPost]
  10273. //[ApiLog("Grp_EnterExitCost", OperationEnum.Download)]
  10274. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  10275. public async Task<IActionResult> PostEnterExitCostDownload(EnterExitCostDownloadDto dto)
  10276. {
  10277. try
  10278. {
  10279. if (dto.DiId < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  10280. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  10281. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  10282. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  10283. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  10284. 3 团组成员名单 1 团组成员名单", ""));
  10285. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).OrderByDescending(x => x.CreateTime).First();
  10286. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  10287. if (_EnterExitCosts == null) return Ok(JsonView(400, "该团组未填写出入境费用;", ""));
  10288. var currencyInit = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToList();
  10289. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  10290. //数据源
  10291. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  10292. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  10293. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  10294. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  10295. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  10296. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  10297. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  10298. .Where((x, a, b) => x.IsDel == 0 && x.Diid == dto.DiId)
  10299. .Select((x, a, b) => new
  10300. {
  10301. x.Index,
  10302. itemName = a.Name,
  10303. CurrencyStr = b.Name,
  10304. x.Cost,
  10305. x.SubTotal,
  10306. x.Remark
  10307. })
  10308. .OrderBy((x) => x.Index)
  10309. .ToList(); //其他款项费用
  10310. var peiceItemCurrencys = new List<string>();
  10311. if (_DayAndCosts.Any())
  10312. {
  10313. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  10314. if (currencyIds.Any()) peiceItemCurrencys.AddRange(currencyInit.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  10315. }
  10316. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  10317. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  10318. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  10319. {
  10320. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  10321. }
  10322. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  10323. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  10324. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  10325. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  10326. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  10327. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  10328. .Select((tcl, dc, cc) => new ClientInfo
  10329. {
  10330. LastName = dc.LastName,
  10331. FirstName = dc.FirstName,
  10332. Sex = dc.Sex,
  10333. Birthday = dc.BirthDay,
  10334. Company = cc.CompanyFullName,
  10335. Job = dc.Job
  10336. })
  10337. .ToList();
  10338. foreach (var item in DeleClientList)
  10339. {
  10340. EncryptionProcessor.DecryptProperties(item);
  10341. }
  10342. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  10343. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  10344. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  10345. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  10346. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  10347. if (dto.ExportType == 1) //明细表
  10348. {
  10349. if (dto.SubTypeId == 1005) //1005(默认明细表)
  10350. {
  10351. //获取模板
  10352. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  10353. //载入模板
  10354. var doc = new Document(tempPath);
  10355. var builder = new DocumentBuilder(doc);
  10356. var dic = new Dictionary<string, string>();
  10357. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  10358. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  10359. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  10360. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  10361. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  10362. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  10363. //境内费用(其他费用)
  10364. if (_EnterExitCosts.ChoiceOne == 1)
  10365. {
  10366. string row1 = "";
  10367. if (_EnterExitCosts.Visa > 0)
  10368. {
  10369. //insidePayTotal += _EnterExitCosts.Visa;
  10370. row1 = $"签证费:{_EnterExitCosts.Visa:#0.00} 元/人\r\n";
  10371. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  10372. //{
  10373. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  10374. //}
  10375. }
  10376. if (_EnterExitCosts.YiMiao > 0)
  10377. {
  10378. //insidePayTotal += _EnterExitCosts.YiMiao;
  10379. row1 += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00} 元/人\r\n";
  10380. }
  10381. if (_EnterExitCosts.HeSuan > 0)
  10382. {
  10383. //insidePayTotal += _EnterExitCosts.HeSuan;
  10384. row1 += $"核酸检测费:{_EnterExitCosts.HeSuan:#0.00} 元/人\r\n";
  10385. }
  10386. if (_EnterExitCosts.Service > 0)
  10387. {
  10388. //insidePayTotal += _EnterExitCosts.Service;
  10389. row1 += $"服务费:{_EnterExitCosts.Service:#0.00} 元/人\r\n";
  10390. }
  10391. if (_EnterExitCosts.Safe > 0)
  10392. {
  10393. //insidePayTotal += _EnterExitCosts.Safe;
  10394. row1 += $"保险费:{_EnterExitCosts.Safe:#0.00} 元/人\r\n";
  10395. }
  10396. if (_EnterExitCosts.Ticket > 0)
  10397. {
  10398. //insidePayTotal += _EnterExitCosts.Ticket;
  10399. row1 += $"参展门票:{_EnterExitCosts.Ticket:#0.00} 元/人\r\n";
  10400. }
  10401. row1 += $"备注:{_EnterExitCosts.FirstItemRemark}";
  10402. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  10403. dic.Add("Row1Str", row1);
  10404. }
  10405. var airTotalStr = new StringBuilder();
  10406. var airPriceStr = new StringBuilder();
  10407. var cityTrafficLabel = new StringBuilder();
  10408. //经济舱
  10409. if (_EnterExitCosts.SumJJC == 1)
  10410. {
  10411. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideJJPay:#0.00}元/人(经济舱)");
  10412. airPriceStr.AppendFormat($"{_EnterExitCosts.AirJJ:#0.00}元/人(经济舱)");
  10413. cityTrafficLabel.AppendFormat("经济舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic);
  10414. }
  10415. //公务舱
  10416. if (_EnterExitCosts.SumGWC == 1)
  10417. {
  10418. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideGWPay:#0.00} 元/人(公务舱)");
  10419. airPriceStr.AppendFormat($"{_EnterExitCosts.AirGW:#0.00} 元/人(公务舱)");
  10420. cityTrafficLabel.AppendFormat("公务舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic1);
  10421. }
  10422. //头等舱
  10423. if (_EnterExitCosts.SumTDC == 1)
  10424. {
  10425. airTotalStr.AppendFormat($"{_EnterExitCosts.OutsideTDPay:#0.00} 元/人(头等舱)");
  10426. airPriceStr.AppendFormat($"{_EnterExitCosts.AirTD:#0.00} 元/人(头等舱)");
  10427. cityTrafficLabel.AppendFormat("头等舱:{0:#0.00} 元/人 ", _EnterExitCosts.CityTranffic2);
  10428. }
  10429. //描述
  10430. var remarkLable = new StringBuilder();
  10431. //第二项描述
  10432. remarkLable.Append("备注:");
  10433. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) remarkLable.AppendFormat(_EnterExitCosts.TwoItemRemark);
  10434. //汇率描述
  10435. if (peiceItemCurrencyInfos.Any())
  10436. {
  10437. remarkLable.AppendLine();
  10438. remarkLable.AppendFormat("汇率描述:");
  10439. foreach (var item in peiceItemCurrencyInfos)
  10440. {
  10441. remarkLable.AppendFormat($"{item.CurrencyName}({item.CurrencyCode}):{item.Rate:#0.0000} ");
  10442. }
  10443. }
  10444. dic.Add("AirTotalStr", airTotalStr.ToString());
  10445. dic.Add("AirPriceStr", airPriceStr.ToString());
  10446. dic.Add("CityTranffic", cityTrafficLabel.ToString());
  10447. dic.Add("TwoItemRemark", remarkLable.ToString());
  10448. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  10449. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  10450. int table1Row = 0,
  10451. table2Row = 0,
  10452. table3Row = 0,
  10453. table4Row = 0,
  10454. table5Row = 0;
  10455. //住宿费
  10456. if (_EnterExitCosts.ChoiceThree == 1)
  10457. {
  10458. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  10459. table1Row = dac1.Count;
  10460. #region 填充word表格内容
  10461. for (int i = 0; i < dac1.Count; i++)
  10462. {
  10463. Grp_DayAndCost dac = dac1[i];
  10464. if (dac == null) continue;
  10465. builder.MoveToCell(0, i, 0, 0);
  10466. builder.Write("第" + dac.Days.ToString() + "晚:");
  10467. builder.MoveToCell(0, i, 1, 0);
  10468. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  10469. //builder.Write(dac.Place == null ? "" : dac.Place);
  10470. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10471. builder.MoveToCell(0, i, 2, 0);
  10472. builder.Write("费用标准:");
  10473. string curr = "";
  10474. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10475. if (currData != null)
  10476. {
  10477. curr = currData.Name;
  10478. }
  10479. builder.MoveToCell(0, i, 3, 0);
  10480. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10481. builder.MoveToCell(0, i, 4, 0);
  10482. builder.Write("费用小计:");
  10483. builder.MoveToCell(0, i, 5, 0);
  10484. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10485. }
  10486. #endregion
  10487. }
  10488. else dic.Add("SubZS", "0.00");
  10489. //删除多余行
  10490. while (table1 != null && table1.Rows.Count > table1Row)
  10491. {
  10492. table1.Rows.RemoveAt(table1Row);
  10493. }
  10494. //伙食费
  10495. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  10496. if (_EnterExitCosts.ChoiceFour == 1)
  10497. {
  10498. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  10499. table2Row = dac2.Count;
  10500. #region 填充word表格内容
  10501. for (int i = 0; i < dac2.Count; i++)
  10502. {
  10503. Grp_DayAndCost dac = dac2[i];
  10504. if (dac == null) continue;
  10505. builder.MoveToCell(1, i, 0, 0);
  10506. builder.Write("第" + dac.Days.ToString() + "天:");
  10507. builder.MoveToCell(1, i, 1, 0);
  10508. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10509. builder.MoveToCell(1, i, 2, 0);
  10510. builder.Write("费用标准:");
  10511. string curr = "";
  10512. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10513. if (currData != null)
  10514. {
  10515. curr = currData.Name;
  10516. }
  10517. builder.MoveToCell(1, i, 3, 0);
  10518. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10519. builder.MoveToCell(1, i, 4, 0);
  10520. builder.Write("费用小计:");
  10521. builder.MoveToCell(1, i, 5, 0);
  10522. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10523. }
  10524. #endregion
  10525. }
  10526. else dic.Add("SubHS", "0.00");
  10527. //删除多余行
  10528. while (table2 != null && table2.Rows.Count > table2Row)
  10529. {
  10530. table2.Rows.RemoveAt(table2Row);
  10531. }
  10532. //公杂费
  10533. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  10534. if (_EnterExitCosts.ChoiceFive == 1)
  10535. {
  10536. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  10537. table3Row = dac3.Count;
  10538. #region 填充word表格内容
  10539. for (int i = 0; i < dac3.Count; i++)
  10540. {
  10541. Grp_DayAndCost dac = dac3[i];
  10542. if (dac == null) continue;
  10543. builder.MoveToCell(2, i, 0, 0);
  10544. builder.Write("第" + dac.Days.ToString() + "天:");
  10545. builder.MoveToCell(2, i, 1, 0);
  10546. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10547. builder.MoveToCell(2, i, 2, 0);
  10548. builder.Write("费用标准:");
  10549. string curr = "";
  10550. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10551. if (currData != null)
  10552. {
  10553. curr = currData.Name;
  10554. }
  10555. builder.MoveToCell(2, i, 3, 0);
  10556. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10557. builder.MoveToCell(2, i, 4, 0);
  10558. builder.Write("费用小计:");
  10559. builder.MoveToCell(2, i, 5, 0);
  10560. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10561. }
  10562. //删除多余行
  10563. while (table3.Rows.Count > table3Row)
  10564. {
  10565. table3.Rows.RemoveAt(table3Row);
  10566. }
  10567. #endregion
  10568. }
  10569. else dic.Add("SubGZF", "0.00");
  10570. //删除多余行
  10571. while (table3 != null && table3.Rows.Count > table3Row)
  10572. {
  10573. table3.Rows.RemoveAt(table3Row);
  10574. }
  10575. //培训费
  10576. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  10577. if (_EnterExitCosts.ChoiceSix == 1)
  10578. {
  10579. string pxStr = $"六、培训费合计: {tainFeeTotal:#0.00} 元/人";
  10580. dic.Add("SubPX", pxStr);
  10581. table4Row = dac4.Count;
  10582. #region 填充word表格内容
  10583. for (int i = 0; i < dac4.Count; i++)
  10584. {
  10585. Grp_DayAndCost dac = dac4[i];
  10586. if (dac == null) continue;
  10587. builder.MoveToCell(3, i, 0, 0);
  10588. builder.Write("第" + dac.Days.ToString() + "天:");
  10589. builder.MoveToCell(3, i, 1, 0);
  10590. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10591. builder.MoveToCell(3, i, 2, 0);
  10592. builder.Write("费用标准:");
  10593. string curr = "";
  10594. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  10595. if (currData != null)
  10596. {
  10597. curr = currData.Name;
  10598. }
  10599. builder.MoveToCell(3, i, 3, 0);
  10600. builder.Write(dac.Cost.ToString("#0.00") + curr);
  10601. builder.MoveToCell(3, i, 4, 0);
  10602. builder.Write("费用小计:");
  10603. builder.MoveToCell(3, i, 5, 0);
  10604. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10605. }
  10606. #endregion
  10607. }
  10608. //else dic.Add("SubPX", $"六、培训费合计: 0.00 元/人");
  10609. //删除多余行
  10610. while (table4 != null && table4.Rows.Count > table4Row)
  10611. {
  10612. table4.Rows.RemoveAt(table4Row);
  10613. }
  10614. //其他费用
  10615. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  10616. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  10617. {
  10618. string qtStr = $"七、其他费用合计: {otherPriceTotal:#0.00} 元/人";
  10619. dic.Add("titleQi", qtStr);
  10620. table5Row = dac5.Count;
  10621. #region 填充word表格内容
  10622. for (int i = 0; i < dac5.Count; i++)
  10623. {
  10624. var dac = dac5[i];
  10625. if (dac == null) continue;
  10626. builder.MoveToCell(4, i, 0, 0);
  10627. builder.Write("第" + dac.Index.ToString() + "项:");
  10628. builder.MoveToCell(4, i, 1, 0);
  10629. builder.Write(dac.itemName);
  10630. builder.MoveToCell(4, i, 2, 0);
  10631. builder.Write("费用标准:");
  10632. builder.MoveToCell(4, i, 3, 0);
  10633. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  10634. builder.MoveToCell(4, i, 4, 0);
  10635. builder.Write("费用小计:");
  10636. builder.MoveToCell(4, i, 5, 0);
  10637. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  10638. builder.MoveToCell(4, i, 6, 0);
  10639. builder.Write("备注:");
  10640. builder.MoveToCell(4, i, 7, 0);
  10641. builder.Write(dac.Remark);
  10642. }
  10643. #endregion
  10644. }
  10645. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  10646. //删除多余行
  10647. while (table5 != null && table5.Rows.Count > table5Row)
  10648. {
  10649. table5.Rows.RemoveAt(table5Row);
  10650. }
  10651. //加上其他费用
  10652. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  10653. decimal subJJC = 0.00M,
  10654. subGWC = 0.00M,
  10655. subTDC = 0.00M;
  10656. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  10657. string totalLabel = string.Format("全部费用总计:");
  10658. //经济舱
  10659. if (_EnterExitCosts.SumJJC == 1)
  10660. {
  10661. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  10662. totalLabel += $"{subJJC:#0.00} 元/人(经济舱)";
  10663. }
  10664. //公务舱
  10665. if (_EnterExitCosts.SumGWC == 1)
  10666. {
  10667. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  10668. totalLabel += $"{subGWC:#0.00} 元/人(公务舱)";
  10669. }
  10670. //头等舱
  10671. if (_EnterExitCosts.SumTDC == 1)
  10672. {
  10673. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  10674. totalLabel += $"{subTDC:#0.00} 元/人(头等舱)";
  10675. }
  10676. //TotalLabel
  10677. dic.Add("TotalLabel", totalLabel);
  10678. //dic.Add("SubJJC", subJJC.ToString("#0.00"));
  10679. //dic.Add("SubGWC", subGWC.ToString("#0.00"));
  10680. //dic.Add("SubTDC", subTDC.ToString("#0.00"));
  10681. #region 填充word模板书签内容
  10682. foreach (var key in dic.Keys)
  10683. {
  10684. Bookmark bookmark = doc.Range.Bookmarks[key];
  10685. if (bookmark != null)
  10686. {
  10687. builder.MoveToBookmark(key);
  10688. builder.Write(dic[key]);
  10689. }
  10690. }
  10691. #endregion
  10692. #region 设置页眉
  10693. string userLabel = string.Empty;
  10694. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  10695. if (currUserInfo != null)
  10696. {
  10697. var userInfo = await _usersRep.GetUserBriefInfo(currUserInfo.UserId);
  10698. if (userInfo != null)
  10699. {
  10700. string ext = string.IsNullOrEmpty(userInfo.ExtensionNumber) ? "-" : userInfo.ExtensionNumber;
  10701. //userLabel = $"联系人:{userInfo.Name} 职位:{userInfo.Job}\r\n座机/分机号:{ext} 手机号:{userInfo.Tel} 公司邮箱:{userInfo.Email}";
  10702. userLabel = $"联系人:{userInfo.Name} 职 位:{userInfo.Job} 手机号:{userInfo.Tel}\r\n公司邮箱:{userInfo.Email}";
  10703. }
  10704. }
  10705. //设置页脚
  10706. //GeneralMethod.AsposeWordSetFooter(builder, userLabel, "华文仿宋", 10);
  10707. #endregion
  10708. var guid = CommonFun.GUID.Substring(0, 8);
  10709. //文件名
  10710. string strFileName = CommonFun.ValidFileName($"{_DelegationInfo.TeamName}出入境费用{guid}.docx");
  10711. AsposeHelper.removewatermark_v2180();
  10712. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  10713. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  10714. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  10715. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  10716. }
  10717. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  10718. {
  10719. //获取模板
  10720. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  10721. //载入模板
  10722. var doc = new Document(tempPath);
  10723. var builder = new DocumentBuilder(doc);
  10724. var dic = new Dictionary<string, string>();
  10725. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  10726. {
  10727. var list = new List<string>();
  10728. try
  10729. {
  10730. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  10731. foreach (var item in spilitArr)
  10732. {
  10733. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  10734. var depCode = spDotandEmpty[2].Substring(0, 3);
  10735. var arrCode = spDotandEmpty[2].Substring(3, 3);
  10736. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  10737. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  10738. list.Add(depName);
  10739. list.Add(arrName);
  10740. }
  10741. list = list.Distinct().ToList();
  10742. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  10743. }
  10744. catch (Exception)
  10745. {
  10746. dic.Add("ReturnCode", "行程录入不正确!");
  10747. }
  10748. }
  10749. else
  10750. {
  10751. dic.Add("ReturnCode", "未录入行程!");
  10752. }
  10753. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  10754. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  10755. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  10756. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  10757. {
  10758. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  10759. dic.Add("Day", sp.Days.ToString());
  10760. }
  10761. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  10762. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  10763. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  10764. //dic.Add("Names", Names);
  10765. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  10766. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  10767. decimal dac1totalPrice = 0.00M;
  10768. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  10769. foreach (var dac in dac1)
  10770. {
  10771. if (dac.SubTotal == 0.00M)
  10772. {
  10773. continue;
  10774. }
  10775. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  10776. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  10777. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  10778. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10779. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  10780. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  10781. builder.Write(currency);//币种
  10782. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  10783. builder.Write(dac.Cost.ToString("#0.00"));//标准
  10784. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  10785. builder.Write("");//人数
  10786. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  10787. builder.Write("");//天数
  10788. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  10789. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  10790. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  10791. decimal rate = 0.00M;
  10792. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  10793. builder.Write(rate.ToString("#0.0000"));//汇率
  10794. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  10795. decimal rbmPrice = dac.SubTotal;
  10796. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  10797. accommodationStartIndex++;
  10798. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  10799. }
  10800. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  10801. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  10802. {
  10803. table1.Rows.RemoveAt(i - 1);
  10804. foodandotherStartIndex--;
  10805. }
  10806. if (dac2.Count == dac3.Count)//国家 币种 金额
  10807. {
  10808. for (int i = 0; i < dac2.Count; i++)
  10809. {
  10810. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  10811. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  10812. }
  10813. }
  10814. decimal dac2totalPrice = 0.00M;
  10815. foreach (var dac in dac2)
  10816. {
  10817. if (dac.SubTotal == 0)
  10818. {
  10819. continue;
  10820. }
  10821. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  10822. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  10823. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  10824. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  10825. builder.Write(currency);//币种
  10826. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  10827. builder.Write(dac.Cost.ToString("#0.00"));//标准
  10828. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  10829. builder.Write("");//人数
  10830. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  10831. builder.Write("");//天数
  10832. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  10833. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  10834. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  10835. decimal rate = 0.00M;
  10836. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  10837. builder.Write(rate.ToString("#0.0000"));//汇率
  10838. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  10839. decimal rbmPrice = dac.SubTotal;
  10840. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  10841. foodandotherStartIndex++;
  10842. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  10843. }
  10844. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  10845. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  10846. {
  10847. table1.Rows.RemoveAt(i - 1);
  10848. }
  10849. var cityTrafficLabel = new StringBuilder()
  10850. .AppendFormat(" 经济舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic)
  10851. .AppendFormat(" 公务舱:{0:#0.00} 元", _EnterExitCosts.CityTranffic1)
  10852. .AppendFormat(" 头等舱:{0:#0.00} ", _EnterExitCosts.CityTranffic2)
  10853. .ToString();
  10854. dic.Add("CityTranffic", cityTrafficLabel);
  10855. string otherFeeStr = "";
  10856. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00} 元,";
  10857. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00} 元,";
  10858. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00} 元,";
  10859. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  10860. foreach (var otherInfo in dac5)
  10861. {
  10862. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  10863. }
  10864. #endregion
  10865. if (otherFeeStr.Length > 0)
  10866. {
  10867. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  10868. otherFeeStr = $"({otherFeeStr})";
  10869. dic.Add("OtherFeeStr", otherFeeStr);
  10870. }
  10871. //总计
  10872. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  10873. //国际旅费
  10874. string outsideAir = string.Empty;
  10875. string allPriceAir = string.Empty;
  10876. if (_EnterExitCosts.SumJJC == 1)
  10877. {
  10878. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  10879. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  10880. }
  10881. if (_EnterExitCosts.SumGWC == 1)
  10882. {
  10883. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  10884. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  10885. }
  10886. if (_EnterExitCosts.SumTDC == 1)
  10887. {
  10888. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  10889. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  10890. }
  10891. dic.Add("InTravelPrice", $"({outsideAir})");
  10892. dic.Add("FinalSumPrice", $"({allPriceAir})");
  10893. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  10894. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  10895. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  10896. foreach (var key in dic.Keys)
  10897. {
  10898. builder.MoveToBookmark(key);
  10899. builder.Write(dic[key]);
  10900. }
  10901. //模板文件名
  10902. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  10903. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  10904. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  10905. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  10906. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  10907. }
  10908. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  10909. {
  10910. //获取模板
  10911. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  10912. //载入模板
  10913. var designer = new WorkbookDesigner
  10914. {
  10915. Workbook = new Workbook(tempPath)
  10916. };
  10917. var dic = new Dictionary<string, string>();
  10918. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  10919. {
  10920. var list = new List<string>();
  10921. try
  10922. {
  10923. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  10924. foreach (var item in spilitArr)
  10925. {
  10926. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  10927. var depCode = spDotandEmpty[2].Substring(0, 3);
  10928. var arrCode = spDotandEmpty[2].Substring(3, 3);
  10929. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  10930. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  10931. list.Add(depName);
  10932. list.Add(arrName);
  10933. }
  10934. list = list.Distinct().ToList();
  10935. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  10936. }
  10937. catch (Exception)
  10938. {
  10939. dic.Add("ReturnCode", "行程录入不正确!");
  10940. }
  10941. }
  10942. else
  10943. {
  10944. dic.Add("ReturnCode", "未录入行程!");
  10945. }
  10946. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  10947. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  10948. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  10949. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  10950. {
  10951. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  10952. dic.Add("Day", sp.Days.ToString());
  10953. }
  10954. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  10955. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  10956. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  10957. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  10958. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  10959. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  10960. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  10961. designer.SetDataSource("Name", Names);
  10962. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  10963. designer.SetDataSource("Day", dic["Day"] + "天");
  10964. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  10965. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  10966. int startIndex = 10;
  10967. const int startIndexcopy = 10;
  10968. if (dac2.Count == dac3.Count)//国家 币种 金额
  10969. {
  10970. for (int i = 0; i < dac2.Count; i++)
  10971. {
  10972. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  10973. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  10974. }
  10975. }
  10976. var dtdac1 = new DataTable();
  10977. var place = new List<string>();
  10978. dtdac1.Columns.AddRange(new DataColumn[] {
  10979. new(){ ColumnName = "city"},
  10980. new(){ ColumnName = "curr"},
  10981. new(){ ColumnName = "criterion"},
  10982. new(){ ColumnName = "number",DataType = typeof(int)},
  10983. new(){ ColumnName = "day",DataType = typeof(int)},
  10984. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  10985. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  10986. new(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  10987. });
  10988. var dtdac2 = new DataTable();
  10989. dtdac2.Columns.AddRange(new DataColumn[] {
  10990. new(){ ColumnName = "city"},
  10991. new(){ ColumnName = "curr"},
  10992. new(){ ColumnName = "criterion"},
  10993. new(){ ColumnName = "number",DataType = typeof(int)},
  10994. new(){ ColumnName = "day",DataType = typeof(int)},
  10995. new(){ ColumnName = "cost", DataType = typeof(decimal)},
  10996. new(){ ColumnName = "rate", DataType = typeof(decimal) },
  10997. new(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  10998. });
  10999. dtdac1.TableName = "tb1";
  11000. dtdac2.TableName = "tb2";
  11001. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  11002. foreach (var item in dac1)
  11003. {
  11004. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  11005. if (place.Contains(item.Place))
  11006. {
  11007. continue;
  11008. }
  11009. DataRow row = dtdac1.NewRow();
  11010. row["city"] = item.Place;
  11011. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  11012. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11013. row["curr"] = currency;
  11014. row["rate"] = rate.ToString("#0.0000");
  11015. row["criterion"] = item.Cost.ToString("#0.00");
  11016. row["number"] = 1;
  11017. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  11018. //row["costRMB"] = rbmPrice;
  11019. dtdac1.Rows.Add(row);
  11020. place.Add(item.Place);
  11021. }
  11022. place = new List<string>();
  11023. foreach (var item in dac2)
  11024. {
  11025. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  11026. if (place.Contains(item.Place))
  11027. {
  11028. continue;
  11029. }
  11030. DataRow row = dtdac2.NewRow();
  11031. row["city"] = item.Place;
  11032. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  11033. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11034. row["curr"] = currency;
  11035. row["rate"] = rate.ToString("#0.0000");
  11036. row["criterion"] = item.Cost.ToString("#0.00");
  11037. row["number"] = 1;
  11038. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  11039. //row["cost"] = item.SubTotal;
  11040. //row["costRMB"] = rbmPrice;
  11041. dtdac2.Rows.Add(row);
  11042. place.Add(item.Place);
  11043. //dac2totalPrice += rbmPrice;
  11044. }
  11045. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  11046. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  11047. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  11048. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  11049. var cityTrafficLabel = new StringBuilder()
  11050. .AppendFormat(" 其中:国外城市间")
  11051. .AppendFormat(" 经济舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic)
  11052. .AppendFormat(" 公务舱费:{0:#0.00} 元、", _EnterExitCosts.CityTranffic1)
  11053. .AppendFormat(" 头等舱费:{0:#0.00} 元", _EnterExitCosts.CityTranffic2)
  11054. .ToString();
  11055. //decimal cityTraffic =_EnterExitCosts.CityTranffic + _EnterExitCosts.CityTranffic1 + _EnterExitCosts.CityTranffic2;
  11056. designer.SetDataSource("cityTranffic", cityTrafficLabel);
  11057. // designer.SetDataSource("sumCityTranffic", @$"{cityTraffic:#0.00} ");
  11058. string cell4Str1 = string.Empty;
  11059. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  11060. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  11061. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  11062. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  11063. string cellStr = $" 5.其他费用(";
  11064. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  11065. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  11066. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  11067. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  11068. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  11069. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  11070. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  11071. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  11072. foreach (var otherInfo in dac5)
  11073. {
  11074. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  11075. }
  11076. #endregion
  11077. if (cellStr.Length > 8)
  11078. {
  11079. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  11080. }
  11081. cellStr += ")";
  11082. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  11083. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  11084. decimal pxFee = dac4.Sum(it => it.Cost);
  11085. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  11086. string celllastStr1 = "";
  11087. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  11088. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  11089. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  11090. celllastStr1 += $",国际旅费 元";
  11091. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  11092. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  11093. designer.SetDataSource("cell4Str", cell4Str);
  11094. designer.SetDataSource("cellStr", cellStr);
  11095. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  11096. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  11097. designer.SetDataSource("celllastStr", celllastStr);
  11098. Workbook wb = designer.Workbook;
  11099. var sheet = wb.Worksheets[0];
  11100. //绑定datatable数据集
  11101. designer.SetDataSource(dtdac1);
  11102. designer.SetDataSource(dtdac2);
  11103. designer.Process();
  11104. var rowStart = dtdac1.Rows.Count;
  11105. while (rowStart > 0)
  11106. {
  11107. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  11108. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  11109. startIndex++;
  11110. rowStart--;
  11111. }
  11112. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  11113. startIndex += 1; //总计行
  11114. rowStart = dtdac2.Rows.Count;
  11115. while (rowStart > 0)
  11116. {
  11117. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  11118. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  11119. startIndex++;
  11120. rowStart--;
  11121. }
  11122. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  11123. wb.CalculateFormula(true);
  11124. //模板文件名
  11125. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  11126. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11127. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11128. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11129. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11130. }
  11131. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  11132. {
  11133. //获取模板
  11134. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  11135. //载入模板
  11136. var doc = new Document(tempPath);
  11137. var builder = new DocumentBuilder(doc);
  11138. var dic = new Dictionary<string, string>
  11139. {
  11140. { "GroupName", _DelegationInfo.TeamName },
  11141. { "ClientUnit", _DelegationInfo.ClientUnit }
  11142. };
  11143. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  11144. string missionLeaderJob = "";//负责人job
  11145. //int groupNumber = 0; //团人数
  11146. if (DeleClientList.Count > 0)
  11147. {
  11148. missionLeader = DeleClientList[0]?.Name ?? "";
  11149. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  11150. }
  11151. dic.Add("MissionLeader", missionLeader); //团负责人
  11152. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  11153. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  11154. #region MyRegion
  11155. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  11156. //{
  11157. // List<string> list = new List<string>();
  11158. // try
  11159. // {
  11160. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  11161. // foreach (var item in spilitArr)
  11162. // {
  11163. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  11164. // var depCode = spDotandEmpty[2].Substring(0, 3);
  11165. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  11166. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  11167. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  11168. // list.Add(depName);
  11169. // list.Add(arrName);
  11170. // }
  11171. // list = list.Distinct().ToList();
  11172. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  11173. // }
  11174. // catch (Exception)
  11175. // {
  11176. // dic.Add("ReturnCode", "行程录入不正确!");
  11177. // }
  11178. //}
  11179. //else
  11180. //{
  11181. // dic.Add("ReturnCode", "未录入行程!");
  11182. //}
  11183. List<string> countrys = _groupRepository.GroupSplitCountry(_DelegationInfo.VisitCountry);
  11184. dic.Add("ReturnCode", string.Join("、", countrys));
  11185. #endregion
  11186. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  11187. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  11188. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  11189. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  11190. //{
  11191. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  11192. // dic.Add("Day", sp.Days.ToString());
  11193. //}
  11194. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  11195. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  11196. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  11197. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11198. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11199. //培训人员名单
  11200. int cultivateRowIndex = 7;
  11201. foreach (var item in DeleClientList)
  11202. {
  11203. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  11204. builder.Write(item.Name);
  11205. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  11206. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  11207. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  11208. string birthDay = "";
  11209. if (item.Birthday != null)
  11210. {
  11211. DateTime dt = Convert.ToDateTime(item.Birthday);
  11212. birthDay = $"{dt.Year}.{dt.Month}";
  11213. }
  11214. builder.Write(birthDay);
  11215. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  11216. builder.Write(item.Company);
  11217. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  11218. builder.Write(item.Job);
  11219. cultivateRowIndex++;
  11220. }
  11221. //删除多余行
  11222. //cultivateRowIndex -= 2;
  11223. int delRows = 10 + 7 - cultivateRowIndex;
  11224. if (delRows > 0)
  11225. {
  11226. for (int i = 0; i < delRows; i++)
  11227. {
  11228. table1.Rows.RemoveAt(cultivateRowIndex);
  11229. //cultivateRowIndex++;
  11230. }
  11231. }
  11232. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  11233. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  11234. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  11235. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  11236. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  11237. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  11238. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  11239. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  11240. //decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  11241. decimal cityTranfficFeeToatal = 0.00M;
  11242. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));
  11243. //其他费用
  11244. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  11245. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  11246. //其他费用合计
  11247. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  11248. decimal _jjcFeeToatal = _EnterExitCosts.OutsideJJPay + _otherFeeTotal; //经济舱
  11249. decimal _gwcFeeToatal = _EnterExitCosts.OutsideGWPay + _otherFeeTotal; //公务舱
  11250. //公务舱合计
  11251. //国际旅费
  11252. //string outsideJJ = "";
  11253. //string allPriceJJ = "";
  11254. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  11255. {
  11256. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideJJPay.ToString("#0.00"));
  11257. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  11258. }
  11259. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  11260. {
  11261. dic.Add("AirFeeTotal", _EnterExitCosts.OutsideGWPay.ToString("#0.00"));
  11262. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  11263. }
  11264. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  11265. {
  11266. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.OutsideJJPay:#0.00} 公务舱:{_EnterExitCosts.OutsideGWPay:#0.00}");
  11267. dic.Add("AirFeeTotal", airFeeTotalStr);
  11268. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  11269. dic.Add("FeeTotal", feeTotalStr);
  11270. }
  11271. foreach (var key in dic.Keys)
  11272. {
  11273. builder.MoveToBookmark(key);
  11274. builder.Write(dic[key]);
  11275. }
  11276. //模板文件名
  11277. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  11278. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11279. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11280. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11281. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11282. }
  11283. }
  11284. else if (dto.ExportType == 2) //表格
  11285. {
  11286. //利用键值对存放数据
  11287. Dictionary<string, string> dic = new Dictionary<string, string>();
  11288. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  11289. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  11290. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  11291. dic.Add("Day", sp.Days.ToString());
  11292. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  11293. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  11294. {
  11295. //获取模板
  11296. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  11297. //载入模板
  11298. var doc = new Document(tempPath);
  11299. var builder = new DocumentBuilder(doc);
  11300. dic.Add("TeamName", _DelegationInfo.TeamName);
  11301. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  11302. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  11303. string missionLeaderName = "",
  11304. missionLeaderJob = "";
  11305. if (DeleClientList.Count > 0)
  11306. {
  11307. missionLeaderName = DeleClientList[0].Name;
  11308. missionLeaderJob = DeleClientList[0].Job;
  11309. }
  11310. dic.Add("MissionLeaderName", missionLeaderName);
  11311. dic.Add("MissionLeaderJob", missionLeaderJob);
  11312. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  11313. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  11314. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11315. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11316. int rowCount = 10;//总人数行
  11317. int startRowIndex = 7; //起始行
  11318. for (int i = 0; i < DeleClientList.Count; i++)
  11319. {
  11320. builder.MoveToCell(0, startRowIndex, 0, 0);
  11321. builder.Write(DeleClientList[i].Name); //出国人员姓名
  11322. builder.MoveToCell(0, startRowIndex, 1, 0);
  11323. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  11324. builder.Write(sex);//性别
  11325. builder.MoveToCell(0, startRowIndex, 2, 0);
  11326. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  11327. builder.MoveToCell(0, startRowIndex, 3, 0);
  11328. builder.Write(DeleClientList[i].Company);//工作单位
  11329. builder.MoveToCell(0, startRowIndex, 4, 0);
  11330. builder.Write(DeleClientList[i].Job);//职务及级别
  11331. builder.MoveToCell(0, startRowIndex, 5, 0);
  11332. builder.Write("");//人员属性
  11333. builder.MoveToCell(0, startRowIndex, 6, 0);
  11334. builder.Write("");//上次出国时间
  11335. startRowIndex++;
  11336. }
  11337. int nullRow = rowCount - DeleClientList.Count;//空行
  11338. for (int i = 0; i < nullRow; i++)
  11339. {
  11340. table1.Rows.Remove(table1.Rows[startRowIndex]);
  11341. }
  11342. foreach (var key in dic.Keys)
  11343. {
  11344. builder.MoveToBookmark(key);
  11345. builder.Write(dic[key]);
  11346. }
  11347. //模板文件名
  11348. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  11349. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11350. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11351. if (dto.PortType == 1) return Ok(JsonView(true, "成功", new { Url = url }));
  11352. else if (dto.PortType == 2 || dto.PortType == 3) return Ok(JsonView(true, "成功", url));
  11353. }
  11354. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  11355. {
  11356. //获取模板
  11357. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  11358. //载入模板
  11359. var doc = new Document(tempPath);
  11360. var builder = new DocumentBuilder(doc);
  11361. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  11362. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  11363. dic.Add("Names", Names);
  11364. int accommodationRows = 12;
  11365. //int foodandotherRows = 12;
  11366. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  11367. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  11368. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11369. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  11370. int accommodationStartIndex = 6;
  11371. decimal dac1totalPrice = 0.00M;
  11372. foreach (var dac in dac1)
  11373. {
  11374. if (dac.SubTotal == 0)
  11375. {
  11376. continue;
  11377. }
  11378. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  11379. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  11380. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  11381. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  11382. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  11383. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  11384. builder.Write(currency);//币种
  11385. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  11386. builder.Write(dac.Cost.ToString("#0.00"));//标准
  11387. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  11388. builder.Write("");//人数
  11389. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  11390. builder.Write("");//天数
  11391. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  11392. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  11393. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  11394. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11395. builder.Write(rate.ToString("#0.0000"));//汇率
  11396. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  11397. decimal rbmPrice = rate * dac.SubTotal;
  11398. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  11399. accommodationStartIndex++;
  11400. dac1totalPrice += rbmPrice;
  11401. }
  11402. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  11403. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  11404. builder.Write("小计");
  11405. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  11406. builder.Write(dac1totalPrice.ToString("#0.00"));
  11407. accommodationStartIndex++;
  11408. int nullRow = accommodationRows - dac1.Count;
  11409. //删除空行
  11410. //if (nullRow > 0)
  11411. //{
  11412. // int rowIndex = accommodationStartIndex;
  11413. // for (int i = 0; i < nullRow; i++)
  11414. // {
  11415. // Aspose.Words.Tables.Row row = table1.Rows[rowIndex];
  11416. // row.Remove();
  11417. // rowIndex++;
  11418. // }
  11419. //}
  11420. if (dac2.Count == dac3.Count)//国家 币种 金额
  11421. {
  11422. for (int i = 0; i < dac2.Count; i++)
  11423. {
  11424. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  11425. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  11426. }
  11427. }
  11428. int foodandotherStartIndex = 19;//
  11429. decimal dac2totalPrice = 0.00M;
  11430. foreach (var dac in dac2)
  11431. {
  11432. if (dac.SubTotal == 0)
  11433. {
  11434. continue;
  11435. }
  11436. //foodandotherStartIndex = 12;
  11437. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  11438. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  11439. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  11440. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  11441. builder.Write(currency);//币种
  11442. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  11443. builder.Write(dac.Cost.ToString("#0.00"));//标准
  11444. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  11445. builder.Write("");//人数
  11446. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  11447. builder.Write("");//天数
  11448. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  11449. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  11450. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  11451. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  11452. builder.Write(rate.ToString("#0.0000"));//汇率
  11453. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  11454. decimal rbmPrice = rate * dac.SubTotal;
  11455. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  11456. foodandotherStartIndex++;
  11457. dac2totalPrice += rbmPrice;
  11458. }
  11459. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  11460. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  11461. //删除空行
  11462. //if (dac2.Count < foodandotherRows)
  11463. //{
  11464. // while (table2.Rows.Count > dac2.Count)
  11465. // {
  11466. // table2.Rows.RemoveAt(dac2.Count);
  11467. // }
  11468. //}
  11469. var citytrafficLable = new StringBuilder()
  11470. .AppendFormat($"经济舱费用:{_EnterExitCosts.CityTranffic:#0.00} 元、")
  11471. .AppendFormat($"公务舱费用:{_EnterExitCosts.CityTranffic1:#0.00}元、")
  11472. .AppendFormat($"头等舱费用:{_EnterExitCosts.CityTranffic2:#0.00}")
  11473. .ToString();
  11474. dic.Add("CityTranffic", citytrafficLable);
  11475. string otherFeeStr = "";
  11476. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  11477. if (_EnterExitCosts.YiMiao > 0) otherFeeStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  11478. if (_EnterExitCosts.HeSuan > 0) otherFeeStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  11479. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  11480. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  11481. if (_EnterExitCosts.Service > 0) otherFeeStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  11482. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  11483. foreach (var otherInfo in dac5)
  11484. {
  11485. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  11486. }
  11487. #endregion
  11488. if (otherFeeStr.Length > 0)
  11489. {
  11490. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  11491. otherFeeStr = $"({otherFeeStr})";
  11492. dic.Add("OtherFeeStr", otherFeeStr);
  11493. }
  11494. foreach (var key in dic.Keys)
  11495. {
  11496. builder.MoveToBookmark(key);
  11497. builder.Write(dic[key]);
  11498. }
  11499. //模板文件名
  11500. string strFileName = $"省级单位出(境)经费报销单{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  11501. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11502. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11503. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11504. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11505. }
  11506. }
  11507. else if (dto.ExportType == 3)
  11508. {
  11509. if (dto.SubTypeId == 1) //团组成员名单
  11510. {
  11511. if (!DeleClientList.Any()) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成员暂未录入!!!", ""));
  11512. //获取模板
  11513. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  11514. //载入模板
  11515. var doc = new Document(tempPath);
  11516. var builder = new DocumentBuilder(doc);
  11517. //获取word里所有表格
  11518. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  11519. //获取所填表格的序数
  11520. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  11521. var rowStart = tableOne.Rows[0]; //获取第1行
  11522. //循环赋值
  11523. for (int i = 0; i < DeleClientList.Count; i++)
  11524. {
  11525. builder.MoveToCell(0, i + 1, 0, 0);
  11526. builder.Write(DeleClientList[i].Name);
  11527. builder.MoveToCell(0, i + 1, 1, 0);
  11528. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  11529. builder.Write(sex);
  11530. builder.MoveToCell(0, i + 1, 2, 0);
  11531. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  11532. builder.MoveToCell(0, i + 1, 3, 0);
  11533. builder.Write(DeleClientList[i].Company);
  11534. builder.MoveToCell(0, i + 1, 4, 0);
  11535. builder.Write(DeleClientList[i].Job);
  11536. }
  11537. //删除多余行
  11538. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  11539. {
  11540. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  11541. }
  11542. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  11543. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  11544. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  11545. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  11546. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  11547. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  11548. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  11549. }
  11550. }
  11551. return Ok(JsonView(400, "操作失败!", ""));
  11552. }
  11553. catch (Exception ex)
  11554. {
  11555. return Ok(JsonView(400, ex.Message, ""));
  11556. }
  11557. }
  11558. /// <summary>
  11559. /// 获取三公费用标准city
  11560. /// </summary>
  11561. /// <param name="placeData"></param>
  11562. /// <param name="nationalTravelFeeId"></param>
  11563. /// <returns></returns>
  11564. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  11565. {
  11566. string _city = string.Empty;
  11567. if (placeData.Count < 1) return _city;
  11568. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  11569. if (data == null) return _city;
  11570. string country = data.Country;
  11571. string city = data.City;
  11572. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  11573. else _city = city;
  11574. return _city;
  11575. }
  11576. ///// <summary>
  11577. ///// 团组模块 - 出入境费用 - 明细表导出
  11578. ///// </summary>
  11579. ///// <returns></returns>
  11580. //[HttpPost]
  11581. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11582. //public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
  11583. //{
  11584. // var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
  11585. // if (data.Code != 0)
  11586. // {
  11587. // return Ok(JsonView(false, data.Msg));
  11588. // }
  11589. // return Ok(JsonView(true, data.Msg, data.Data));
  11590. //}
  11591. /// <summary>
  11592. /// 团组模块 - 出入境费用 - 一键清空
  11593. /// </summary>
  11594. /// <returns></returns>
  11595. [HttpPost]
  11596. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11597. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11598. public async Task<IActionResult> PostEnterExitCostOneClickClear(EnterExitCostOneClickClearDto dto)
  11599. {
  11600. if (dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数;"));
  11601. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  11602. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  11603. var _view = await _enterExitCostRep.OneClickClear(dto.Id, dto.DiId, dto.UserId);
  11604. await _sqlSugar.Updateable<Grp_DayOtherPrice>()
  11605. .Where(x => x.Diid == dto.DiId && x.IsDel == 0)
  11606. .SetColumns(x => new Grp_DayOtherPrice
  11607. {
  11608. IsDel = 1,
  11609. DeleteUserId = dto.UserId,
  11610. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  11611. })
  11612. .ExecuteCommandAsync();
  11613. if (_view.Code == 0)
  11614. {
  11615. return Ok(JsonView(true, "操作成功"));
  11616. }
  11617. return Ok(JsonView(false, "操作失败"));
  11618. }
  11619. /// <summary>
  11620. /// 团组模块 - 出入境费用 - 子项删除
  11621. /// </summary>
  11622. /// <returns></returns>
  11623. [HttpPost]
  11624. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11625. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11626. public async Task<IActionResult> PostEnterExitCostSubItemDel(EnterExitCostSubItemDelDto dto)
  11627. {
  11628. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  11629. if (data.Code != 0)
  11630. {
  11631. return Ok(JsonView(false, data.Msg));
  11632. }
  11633. return Ok(JsonView(true, "操作成功!", data.Data));
  11634. }
  11635. /// <summary>
  11636. /// 删除三公其他费用
  11637. /// </summary>
  11638. /// <param name="dto"></param>
  11639. /// <returns></returns>
  11640. [HttpPost]
  11641. //[ApiLog("Grp_EnterExitCost", OperationEnum.Del)]
  11642. public IActionResult DeleteOtherExpenses(EnterExitCostSubItemDelDto dto)
  11643. {
  11644. var jw = JsonView(false, "删除失败!");
  11645. var data = new Grp_DayOtherPrice()
  11646. {
  11647. Id = dto.Id,
  11648. IsDel = 1,
  11649. DeleteUserId = dto.DeleteUserId,
  11650. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  11651. };
  11652. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  11653. if (del > 0)
  11654. {
  11655. jw.Code = 200;
  11656. jw.Msg = "删除成功!";
  11657. }
  11658. return Ok(jw);
  11659. }
  11660. /// <summary>
  11661. /// 团组模块 - 出入境国家费用标准 List
  11662. /// </summary>
  11663. /// <returns></returns>
  11664. [HttpPost]
  11665. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11666. public async Task<IActionResult> GetNationalTravelFeeData(NationalTravelFeeDataDto dto)
  11667. {
  11668. int provinceId = dto.ProvinceId;
  11669. if (provinceId < 1) provinceId = 122; //默认四川省数据
  11670. var nftData = await _sqlSugar
  11671. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, c) => new JoinQueryInfos(
  11672. JoinType.Left, ntf.Currency == sd1.Id,
  11673. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  11674. JoinType.Left, ntf.ProvinceId == c.Id
  11675. ))
  11676. .Where((ntf, sd1, u, c) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  11677. .Select((ntf, sd1, u, c) => new NationalTravelFeeInfoView
  11678. {
  11679. Id = ntf.Id,
  11680. ProvinceId = ntf.ProvinceId,
  11681. ProvinceName = c.Name_CN,
  11682. Continent = ntf.Continent,
  11683. Country = ntf.Country,
  11684. City = ntf.City,
  11685. Currency = ntf.Currency,
  11686. CurrencyCode = sd1.Name,
  11687. CurrencyName = sd1.Remark,
  11688. RoomCost = ntf.RoomCost,
  11689. FoodCost = ntf.FoodCost,
  11690. PublicCost = ntf.PublicCost,
  11691. LastUpdateUserId = ntf.LastUpdateUserId,
  11692. LastUpdateUserName = u.CnName,
  11693. LastUpdateTime = ntf.LastUpdateTime
  11694. })
  11695. .ToListAsync();
  11696. return Ok(JsonView(true, "查询成功!", nftData));
  11697. }
  11698. /// <summary>
  11699. /// 团组模块 - 出入境国家费用标准 Page List Data Source
  11700. /// </summary>
  11701. /// <returns></returns>
  11702. [HttpPost]
  11703. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11704. public async Task<IActionResult> GetNationalTravelFeePageDataSource()
  11705. {
  11706. string sql = string.Format(@"Select * From Grp_NationalTravelFee Where Isdel = 0 ");
  11707. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<Grp_NationalTravelFee>(sql).ToListAsync();
  11708. List<string> countryData = new List<string>();
  11709. countryData.AddRange(nationalTravelFeeData.Select(it => it.Country!).ToList());
  11710. countryData = countryData.Distinct().ToList();
  11711. List<dynamic> dataSource = new List<dynamic>();
  11712. foreach (var item in countryData)
  11713. {
  11714. var cityData1 = new List<string>();
  11715. cityData1 = nationalTravelFeeData.Where(it => it.Country == item).Select(it => it.City ?? "").ToList();
  11716. var countryData2 = new
  11717. {
  11718. CountryName = item,
  11719. CityData = cityData1
  11720. };
  11721. if (!dataSource.Contains(countryData2))
  11722. {
  11723. dataSource.Add(countryData2);
  11724. }
  11725. }
  11726. return Ok(JsonView(true, "查询成功!", dataSource));
  11727. }
  11728. /// <summary>
  11729. /// 团组模块 - 出入境国家费用标准 Page List
  11730. /// </summary>
  11731. /// <returns></returns>
  11732. [HttpPost]
  11733. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11734. public async Task<IActionResult> PostNationalTravelFeePage(NationalTravelFeePageDto dto)
  11735. {
  11736. int portId = dto.PortType,
  11737. pageIndex = dto.PageIndex,
  11738. pageSize = dto.PageSize;
  11739. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  11740. if (pageIndex == 0) pageIndex = 1;
  11741. if (pageSize == 0) pageSize = 10;
  11742. RefAsync<int> total = 0;
  11743. var nationalTravelFeeData = await _sqlSugar
  11744. .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, sd2) => new JoinQueryInfos(
  11745. JoinType.Left, ntf.Currency == sd1.Id,
  11746. JoinType.Left, ntf.LastUpdateUserId == u.Id,
  11747. JoinType.Left, ntf.ProvinceId == sd2.Id
  11748. ))
  11749. .Where((ntf, sd1, u, sd2) => ntf.IsDel == 0)
  11750. .WhereIF(dto.ProvinceId > 0, (ntf, sd1, u, sd2) => ntf.ProvinceId == dto.ProvinceId)
  11751. .WhereIF(!string.IsNullOrEmpty(dto.Country), (ntf, sd1, u, sd2) => ntf.Country.Contains(dto.Country))
  11752. .WhereIF(!string.IsNullOrEmpty(dto.City), (ntf, sd1, u, sd2) => ntf.City.Contains(dto.City))
  11753. .OrderByDescending((ntf, sd1, u, sd2) => ntf.LastUpdateTime)
  11754. .Select((ntf, sd1, u, sd2) => new NationalTravelFeePageInfoView
  11755. {
  11756. RowNumber = SqlFunc.RowNumber($"{ntf.LastUpdateTime} Desc"),
  11757. Id = ntf.Id,
  11758. ProvinceId = ntf.ProvinceId,
  11759. ProvinceName = sd2.Name_CN,
  11760. Continent = ntf.Continent,
  11761. Country = ntf.Country,
  11762. City = ntf.City,
  11763. Currency = ntf.Currency,
  11764. CurrencyCode = sd1.Name,
  11765. CurrencyName = sd1.Remark,
  11766. RoomCost = ntf.RoomCost,
  11767. FoodCost = ntf.FoodCost,
  11768. PublicCost = ntf.PublicCost,
  11769. LastUpdateUserId = ntf.LastUpdateUserId,
  11770. LastUpdateUserName = u.CnName,
  11771. LastUpdateTime = ntf.LastUpdateTime,
  11772. Remark = ntf.Remark
  11773. })
  11774. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  11775. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData, (int)total));
  11776. }
  11777. /// <summary>
  11778. /// 团组模块 - 出入境国家费用标准 根据城市查询
  11779. /// </summary>
  11780. /// <returns></returns>
  11781. [HttpPost]
  11782. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11783. public async Task<IActionResult> PostNationalTravelFeeInfoByCountryAndCity(NationalTravelFeeByCountryAndCityDto dto)
  11784. {
  11785. if (dto == null) return Ok(JsonView(false, "请传入参数!"));
  11786. int portId = dto.PortType;
  11787. if (portId != 1 && portId != 2 && portId != 3) return Ok(JsonView(false, "请输入正确的端口号!\r\n请求端口分类1 Web 2 Android 3 IOS"));
  11788. string whereSql = string.Empty;
  11789. if (!string.IsNullOrEmpty(dto.Country))
  11790. {
  11791. whereSql = string.Format(@"And Country = '{0}' ", dto.Country);
  11792. }
  11793. if (!string.IsNullOrEmpty(dto.City))
  11794. {
  11795. whereSql = string.Format(@"And City = '{0}' ", dto.City);
  11796. }
  11797. string sql = string.Format(@"Select gntf.Country,gntf.City,gntf.Currency,ssd.Name as CurrencyCode,
  11798. ssd.Remark as CurrencyName,gntf.RoomCost,gntf.FoodCost,gntf.PublicCost,gntf.TrainCost,
  11799. gntf.LastUpdateUserId,su.CnName as LastUpdateUserName,gntf.LastUpdateTime
  11800. From Grp_NationalTravelFee gntf
  11801. Left Join Sys_SetData ssd On ssd.STid = 66 And gntf.Currency = ssd.Id
  11802. Left Join Sys_Users su On gntf.LastUpdateUserId = su.Id
  11803. Where gntf.Isdel = 0 {0} ", whereSql);
  11804. var nationalTravelFeeData = await _groupRepository._sqlSugar.SqlQueryable<NationalTravelFeeInfoByCountryAndCityView>(sql).FirstAsync();
  11805. return Ok(JsonView(true, "查询成功!", nationalTravelFeeData));
  11806. }
  11807. /// <summary>
  11808. /// 团组模块 - 出入境国家费用标准 - Add Or Update
  11809. /// </summary>
  11810. /// <returns></returns>
  11811. [HttpPost]
  11812. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11813. public async Task<IActionResult> PostNationalTravelFeeOperate(NationalTravelFeeOperateDto dto)
  11814. {
  11815. return Ok(await _enterExitCostRep.PostNationalTravelFeeOperate(dto));
  11816. }
  11817. /// <summary>
  11818. /// 团组模块 - 出入境国家费用标准 - Del
  11819. /// </summary>
  11820. /// <returns></returns>
  11821. [HttpPost]
  11822. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11823. public async Task<IActionResult> PostNationalTravelFeeDel(NationalTravelFeeDelDto dto)
  11824. {
  11825. Grp_NationalTravelFee _nationalTravelFee = new Grp_NationalTravelFee()
  11826. {
  11827. Id = dto.Id,
  11828. DeleteUserId = dto.DeleteUserId,
  11829. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  11830. IsDel = 1
  11831. };
  11832. var delStatus = await _enterExitCostRep._sqlSugar.Updateable<Grp_NationalTravelFee>(_nationalTravelFee)
  11833. .UpdateColumns(it => new { it.DeleteTime, it.DeleteUserId, it.IsDel })
  11834. .WhereColumns(it => new { it.Id })
  11835. .ExecuteCommandAsync();
  11836. if (delStatus <= 0)
  11837. {
  11838. return Ok(JsonView(false, "删除失败!"));
  11839. }
  11840. return Ok(JsonView(true, "操作成功!"));
  11841. }
  11842. /// <summary>
  11843. /// 团组模块 - 出入境国家费用标准 - 费用导入收款账单
  11844. /// 注:Get 请求Headers 加 Token
  11845. /// </summary>
  11846. /// <param name="groupId"></param>
  11847. /// <returns></returns>
  11848. [HttpGet("{groupId}")]
  11849. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11850. public async Task<IActionResult> NationalTravelFeeImportReceivables(int groupId)
  11851. {
  11852. var _currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  11853. if (_currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  11854. var data = await GeneralMethod.ReceivablesImportFeeAsync(groupId);
  11855. data.ForEach(x =>
  11856. {
  11857. x.CreateUserId = _currUserInfo.UserId;
  11858. });
  11859. if (data.Any())
  11860. {
  11861. var add = await _sqlSugar.Insertable(data).ExecuteCommandAsync();
  11862. if (add > 0)
  11863. {
  11864. return Ok(JsonView(true, "操作成功!"));
  11865. }
  11866. }
  11867. return Ok(JsonView(false, "未操作!"));
  11868. }
  11869. #endregion
  11870. #region 团组经理模块 出入境费用-草稿
  11871. /// <summary>
  11872. /// 团组模块-出入境费用-草稿
  11873. /// 基础数据源-省份归属
  11874. /// </summary>
  11875. /// <returns></returns>
  11876. [HttpGet]
  11877. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11878. public async Task<IActionResult> EnterExitDraftProvBelongCostDataSource()
  11879. {
  11880. var provData = await _groupRepository.ProvinceBasicSource();
  11881. return Ok(JsonView(true, "查询成功!", provData));
  11882. }
  11883. /// <summary>
  11884. /// 团组模块-出入境费用-草稿
  11885. /// 文件类型list 根据省份Id获取
  11886. /// </summary>
  11887. /// <returns></returns>
  11888. [HttpGet("{provinceId}")]
  11889. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11890. public async Task<IActionResult> EnterExitCostDraftFileOwner([FromRoute] int provinceId = 122)
  11891. {
  11892. //验证城市归属并给默认值
  11893. if (provinceId < 1) provinceId = 122;
  11894. /*
  11895. * 122 四川
  11896. * 108 贵州
  11897. * 103 重庆
  11898. * 132 云南
  11899. */
  11900. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostDraftRep.FileOwner(provinceId);
  11901. return Ok(JsonView(true, "查询成功!", new
  11902. {
  11903. WordTypeData = wordTypeData,
  11904. ExcelTypeData = excelTypeData,
  11905. }));
  11906. }
  11907. /// <summary>
  11908. /// 团组模块 - 出入境费用-草稿
  11909. /// 基础数据源(团组名称/币种类型)
  11910. /// </summary>
  11911. /// <returns></returns>
  11912. [HttpPost]
  11913. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11914. public async Task<IActionResult> EnterExitCostDraftDataSource(EnterExitCostDraftDataSourceDto dto)
  11915. {
  11916. var draftNameDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  11917. .Where(x => x.IsDel == 0)
  11918. .OrderByDescending(x => x.CreateTime)
  11919. .Select(x => new { x.Id, x.DraftName })
  11920. .ToListAsync();
  11921. string sql = string.Format("Select * From Sys_SetData Where IsDel = 0");
  11922. //SetDataInfoView
  11923. var dataSource = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  11924. var currencyData = dataSource.Where(it => it.STid == 66).ToList(); //所有币种
  11925. var _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
  11926. int provinceId = dto.ProvinceId;
  11927. if (provinceId < 1) provinceId = 122;
  11928. /*
  11929. * 122 四川
  11930. * 108 贵州
  11931. * 103 重庆
  11932. * 132 云南
  11933. */
  11934. (SetDataInfoView[] wordTypeData, SetDataInfoView[] excelTypeData) = await _enterExitCostRep.FileOwner(provinceId);
  11935. //默认币种显示
  11936. var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
  11937. var viewPermissionData = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  11938. return Ok(JsonView(true, "查询成功!", new
  11939. {
  11940. DraftNameDatas = draftNameDatas,
  11941. CurrencyData = _CurrencyData,
  11942. WordTypeData = wordTypeData,
  11943. ExcelTypeData = excelTypeData,
  11944. CurrencyInit = _currencyInfos,
  11945. ViewPermissionData = viewPermissionData
  11946. }));
  11947. }
  11948. /// <summary>
  11949. /// 团组模块 - 出入境费用-草稿
  11950. /// 实时汇率 tips、机票费用 tips
  11951. /// </summary>
  11952. /// <returns></returns>
  11953. [HttpPost]
  11954. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11955. public async Task<IActionResult> EnterExitCostDraftCorrelationTips(EnterExitCostDraftCorrelationTipsDto dto)
  11956. {
  11957. //var airData = await _ticketBlackCodeRep.EntryAndExitTips(dto.DiId);
  11958. return Ok(JsonView(true, "查询成功!", new
  11959. {
  11960. //GroupNameData = groupNameData.Data,
  11961. //visaData = visaData.Data,
  11962. //airData = airData.Data,
  11963. reteInfos = await GeneralMethod.EnterExitCostLiveRate()
  11964. }));
  11965. }
  11966. /// <summary>
  11967. /// 团组模块 - 出入境费用-草稿
  11968. /// 签证费用 tips
  11969. /// </summary>
  11970. /// <returns></returns>
  11971. [HttpPost]
  11972. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  11973. public async Task<IActionResult> EnterExitCostDraftVisaTips(EnterExitCostDraftVisaTipsDto dto)
  11974. {
  11975. //if (dto.DraftId < 1) return Ok(JsonView(false,MsgTips.Id));
  11976. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  11977. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  11978. .Select(x => x.NationalTravelFeeId)
  11979. .Distinct()
  11980. .ToListAsync();
  11981. //if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  11982. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  11983. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  11984. .Select(x => x.Country)
  11985. .Distinct()
  11986. .ToArrayAsync();
  11987. //if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  11988. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  11989. return Ok(JsonView(true, "查询成功!", new
  11990. {
  11991. totalAmt,
  11992. remark
  11993. }));
  11994. }
  11995. #region 城市区间交通费
  11996. /// <summary>
  11997. /// 团组模块 - 出入境费用-草稿
  11998. /// 境外用车 基础数据源
  11999. /// </summary>
  12000. /// <param name="draftId">草稿Id</param>
  12001. /// <returns></returns>
  12002. [HttpGet("{draftId}")]
  12003. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12004. public async Task<IActionResult> EnterExitCostDraftOVByGroupId(int draftId)
  12005. {
  12006. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  12007. if (draftInfo == null)
  12008. {
  12009. return Ok(JsonView(false, "三公费用草稿信息为空"));
  12010. }
  12011. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  12012. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  12013. .Select(x => x.NationalTravelFeeId)
  12014. .Distinct()
  12015. .ToListAsync();
  12016. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  12017. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  12018. .Select(x => x.Country)
  12019. .Distinct()
  12020. .ToListAsync();
  12021. if (countries?.Any() != true)
  12022. {
  12023. return Ok(JsonView(false, "草稿选择城市信息为空"));
  12024. }
  12025. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  12026. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  12027. .Where(x => x.IsDel == 0 && x.STid == 66)
  12028. .ToListAsync();
  12029. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  12030. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  12031. .ToListAsync();
  12032. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  12033. //只返回接送机的数据
  12034. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  12035. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  12036. .ToListAsync();
  12037. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  12038. var overseaVehicleCityDatas = new List<dynamic>() {
  12039. new
  12040. {
  12041. Id = 0,
  12042. area= "未选择",
  12043. CarTypeName = "",
  12044. serviceType = "",
  12045. Price = 0.00M,
  12046. guidePrice = 0.00M,
  12047. otherPrice = 0.00M,
  12048. currency = 0,
  12049. currencyName = "",
  12050. currRate = 1.0000M,
  12051. LastUpdateUserName = "",
  12052. LastUpdateTime = "",
  12053. Remark = ""
  12054. }};
  12055. foreach (var item in overseaVehicleTypes)
  12056. {
  12057. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  12058. string area = string.Empty,
  12059. serviceType = "未设置",
  12060. currencyName = string.Empty;
  12061. decimal otherPrice = 0.00M;
  12062. if (parentInfo != null)
  12063. {
  12064. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  12065. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  12066. serviceType = item.ServiceType.GetDescription();
  12067. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  12068. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  12069. }
  12070. //当前币种汇率值
  12071. var currRate = 1.0000M;
  12072. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  12073. if (currencyInfo != null) currRate = currencyInfo.Rate;
  12074. overseaVehicleCityDatas.add(new
  12075. {
  12076. item.Id,
  12077. area,
  12078. item.CarTypeName,
  12079. serviceType,
  12080. item.Price,
  12081. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  12082. otherPrice,
  12083. currency = parentInfo?.Currency ?? 0,
  12084. currencyName,
  12085. currRate,
  12086. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  12087. item.LastUpdateTime,
  12088. item.Remark
  12089. });
  12090. }
  12091. var total = overseaVehicleCityDatas.Count;
  12092. var view = new
  12093. {
  12094. visitCountries = string.Join("、", countries),
  12095. groupSize = 0, //出访人数
  12096. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  12097. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  12098. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  12099. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  12100. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  12101. Currencies = currencies,
  12102. data = overseaVehicleCityDatas
  12103. };
  12104. if (overseaVehicleCityDatas.Count == 0)
  12105. {
  12106. return Ok(JsonView(true, "暂无数据!", view));
  12107. }
  12108. return Ok(JsonView(true, "查询成功!", view, total));
  12109. }
  12110. /// <summary>
  12111. /// 团组模块 - 出入境费用-草稿
  12112. /// 境外用车 计算详细信息
  12113. /// </summary>
  12114. /// <param name="draftId"></param>
  12115. /// <param name="currUserId"></param>
  12116. /// <returns></returns>
  12117. [HttpGet("{draftId}")]
  12118. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12119. public async Task<IActionResult> EnterExitCostDraftOVFeeDetails(int draftId, int currUserId)
  12120. {
  12121. // 1. 验证草稿是否存在
  12122. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  12123. .Where(x => x.Id == draftId && x.IsDel == 0)
  12124. .FirstAsync();
  12125. if (eecInfo == null)
  12126. {
  12127. return Ok(JsonView(false, "草稿信息为空"));
  12128. }
  12129. // 2. 获取用户信息
  12130. var userInfo = await _sqlSugar.Queryable<Sys_Users>()
  12131. .Where(x => x.IsDel == 0 && x.Id == currUserId)
  12132. .FirstAsync();
  12133. var userName = userInfo?.CnName ?? "-";
  12134. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12135. // 3. 处理草稿信息
  12136. CityIntervalDraftInfo info;
  12137. if (eecInfo.CityIntervalFeeDetails != null)
  12138. {
  12139. info = eecInfo.CityIntervalFeeDetails;
  12140. // 检查费用详情是否为空
  12141. bool isEmpty = !info.APTFeeDetails.Any() &&
  12142. !info.PullCartFeeDetails.Any() &&
  12143. !info.TrainFeeDetails.Any() &&
  12144. !info.CityAirTicketFeeDetails.Any();
  12145. if (isEmpty)
  12146. {
  12147. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  12148. }
  12149. else
  12150. {
  12151. // 更新时间和用户信息
  12152. info.LastUpdateUserName = userName;
  12153. info.LastUpdateTime = nowTime;
  12154. }
  12155. }
  12156. else
  12157. {
  12158. // 创建默认信息
  12159. info = await CreateDefaultCityIntervalDraftInfo(draftId, userName, nowTime);
  12160. }
  12161. return Ok(JsonView(true, "查询成功!", info));
  12162. }
  12163. /// <summary>
  12164. /// 创建默认的城市区间费用草稿信息
  12165. /// </summary>
  12166. private static async Task<CityIntervalDraftInfo> CreateDefaultCityIntervalDraftInfo(
  12167. int draftId,
  12168. string userName,
  12169. string nowTime)
  12170. {
  12171. return new CityIntervalDraftInfo()
  12172. {
  12173. APTFeeDetails = new List<RoundTripTransferInfo>()
  12174. {
  12175. new()
  12176. {
  12177. No = 1,
  12178. Coefficient = Def_AirportTransferCoeff,
  12179. ServiceCount = Def_ServiceCount
  12180. }
  12181. },
  12182. PullCartFeeDetails = new List<PullCartInfo>()
  12183. {
  12184. new()
  12185. {
  12186. No = 1,
  12187. Coefficient = Def_PullCartCoeff
  12188. }
  12189. },
  12190. TrainFeeDetails = new List<TrainInfo>()
  12191. {
  12192. new()
  12193. {
  12194. No = 1,
  12195. Coefficient = Def_TrainCoeff
  12196. }
  12197. },
  12198. CityAirTicketFeeDetails = new List<CityAirTicketInfo>()
  12199. {
  12200. new()
  12201. {
  12202. No = 1,
  12203. Coefficient = Def_CityFlightCoeff
  12204. }
  12205. },
  12206. LastUpdateUserName = userName,
  12207. LastUpdateTime = nowTime,
  12208. CreateUserName = userName,
  12209. CreateTime = nowTime,
  12210. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId)
  12211. };
  12212. }
  12213. /// <summary>
  12214. /// 团组模块 - 出入境费用-草稿
  12215. /// 境外用车 保存
  12216. /// </summary>
  12217. /// <param name="dto"></param>
  12218. /// <returns></returns>
  12219. [HttpPost]
  12220. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12221. public async Task<IActionResult> EnterExitCostDraftOVFeeSave(EnterExitCostDraftOVFeeSaveDto dto)
  12222. {
  12223. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  12224. if (draftInfo == null)
  12225. {
  12226. return Ok(JsonView(false, "草稿信息为空"));
  12227. }
  12228. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  12229. if (userInfo == null)
  12230. {
  12231. return Ok(JsonView(false, "员工信息为空"));
  12232. }
  12233. var userName = userInfo?.CnName ?? "-";
  12234. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  12235. var info = new CityIntervalDraftInfo()
  12236. {
  12237. GroupSize = dto.GroupSize,
  12238. APTFeeTotal = dto.APTFeeTotal,
  12239. APTFeeDetails = dto.APTFeeDetails,
  12240. PullCartFeeTotal = dto.PullCartFeeTotal,
  12241. PullCartFeeDetails = dto.PullCartFeeDetails,
  12242. TrainFeeTotal = dto.TrainFeeTotal,
  12243. TrainFeeDetails = dto.TrainFeeDetails,
  12244. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  12245. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  12246. Currencies = dto.Currencies,
  12247. LastUpdateUserName = userName,
  12248. LastUpdateTime = nowTime,
  12249. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  12250. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  12251. };
  12252. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  12253. .SetColumns(it => it.CityIntervalFeeDetails == info)
  12254. .Where(x => x.Id == draftInfo.Id)
  12255. .ExecuteCommandAsync();
  12256. if (upd < 1)
  12257. {
  12258. return Ok(JsonView(false));
  12259. }
  12260. //返回参数处理
  12261. var label = new StringBuilder();
  12262. if (dto.APTFeeDetails.Any())
  12263. {
  12264. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  12265. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  12266. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  12267. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  12268. .Select((ovtp, ov) => new
  12269. {
  12270. ovtp.Id,
  12271. ov.CountryName,
  12272. ov.CityName
  12273. })
  12274. .ToListAsync();
  12275. if (areas.Any())
  12276. {
  12277. var items = dto.APTFeeDetails
  12278. .Select(item =>
  12279. {
  12280. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  12281. if (areaInfo == null) return null;
  12282. return areaInfo.CountryName == areaInfo.CityName
  12283. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  12284. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  12285. })
  12286. .Where(item => item != null)
  12287. .ToList();
  12288. string areaLabel = $"接送机({string.Join("、", items)});";
  12289. label.AppendLine(areaLabel);
  12290. }
  12291. }
  12292. if (dto.PullCartFeeDetails.Any())
  12293. {
  12294. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12295. string subLabel = $"拉车({string.Join("、", amounts)});";
  12296. label.AppendLine(subLabel);
  12297. }
  12298. if (dto.TrainFeeDetails.Any())
  12299. {
  12300. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12301. string subLabel = $"火车票({string.Join("、", amounts)});";
  12302. label.AppendLine(subLabel);
  12303. }
  12304. if (dto.CityAirTicketFeeDetails.Any())
  12305. {
  12306. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  12307. string subLabel = $"城市机票({string.Join("、", amounts)});";
  12308. label.AppendLine(subLabel);
  12309. }
  12310. //费用
  12311. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  12312. decimal jjcQuote = quote;
  12313. decimal gwcQuote = quote;
  12314. decimal tdcQuote = quote;
  12315. var view = new
  12316. {
  12317. label = label.ToString(),
  12318. jjcQuote,
  12319. gwcQuote,
  12320. tdcQuote
  12321. };
  12322. return Ok(JsonView(view));
  12323. }
  12324. #endregion
  12325. /// <summary>
  12326. /// 团组模块 - 出入境费用-草稿
  12327. /// Info
  12328. /// </summary>
  12329. /// <returns></returns>
  12330. [HttpPost]
  12331. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Details)]
  12332. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12333. public async Task<IActionResult> EnterExitCostDraftInfoById(EnterExitCostDraftInfoByIdDto dto)
  12334. {
  12335. return Ok(await _enterExitCostDraftRep.EnterExitCostDraftInfoById(dto));
  12336. }
  12337. /// <summary>
  12338. /// 团组模块 - 出入境费用-草稿
  12339. /// 设置view权限
  12340. /// </summary>
  12341. /// <returns></returns>
  12342. [HttpPost]
  12343. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12344. public async Task<IActionResult> EnterExitCostDraftSetViewPermissiion(EnterExitCostDraftSetViewPermissiionDto dto)
  12345. {
  12346. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  12347. if (dto.DraftId < 1) return Ok(JsonView(false, "请传入有效的DraftId;"));
  12348. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  12349. var permissions = new List<Grp_EnterExitCostDraftPermission>();
  12350. foreach (var userId in dto.UserIds)
  12351. {
  12352. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  12353. }
  12354. if (permissions.Any())
  12355. {
  12356. _sqlSugar.BeginTran();
  12357. try
  12358. {
  12359. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  12360. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  12361. if (result < 1)
  12362. {
  12363. _sqlSugar.RollbackTran();
  12364. return Ok(JsonView(false));
  12365. }
  12366. }
  12367. catch (Exception ex)
  12368. {
  12369. _sqlSugar.RollbackTran();
  12370. return Ok(JsonView(false, ex.Message));
  12371. }
  12372. _sqlSugar.CommitTran();
  12373. return Ok(JsonView(true));
  12374. }
  12375. return Ok(JsonView(false));
  12376. }
  12377. /// <summary>
  12378. /// 团组模块 - 出入境费用-草稿
  12379. /// Add And Update
  12380. /// </summary>
  12381. /// <returns></returns>
  12382. [HttpPost]
  12383. [ApiLog("Grp_EnterExitCostDraft", OperationEnum.Add)]
  12384. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12385. public async Task<IActionResult> EnterExitCostDraftOp(EnterExitCostDraftOpDto dto)
  12386. {
  12387. var data = await _enterExitCostDraftRep.EnterExitCostDraftOp(dto);
  12388. if (data.Code != 0)
  12389. {
  12390. return Ok(JsonView(false, data.Msg));
  12391. }
  12392. int sign = (int)data.Data.GetType().GetProperty("sign").GetValue(data.Data, null);
  12393. //汇率信息记录
  12394. await GeneralMethod.RateRecordSave(dto.UserId, sign, "出入境费用");
  12395. return Ok(JsonView(true, data.Msg, data.Data));
  12396. }
  12397. /// <summary>
  12398. /// 团组模块 - 出入境费用-草稿
  12399. /// File downlaod
  12400. /// </summary>
  12401. /// <param name="dto"></param>
  12402. /// <returns></returns>
  12403. [HttpPost]
  12404. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Download)]
  12405. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  12406. public async Task<IActionResult> EnterExitCostDraftDownload(EnterExitCostDraftDownloadDto dto)
  12407. {
  12408. try
  12409. {
  12410. var id = dto.Id;
  12411. if (id < 1) return Ok(JsonView(400, "请传入有效的DiId参数;", ""));
  12412. if (dto.ExportType < 1) return Ok(JsonView(400, "请传入有效的ExportType参数; 1 明细表 2 表格", ""));
  12413. if (dto.SubTypeId < 1) return Ok(JsonView(400, @"请传入有效的SubTypeId参数;
  12414. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  12415. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  12416. 3 团组成员名单 1 团组成员名单", ""));
  12417. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(it => it.IsDel == 0 && it.Id == id).OrderByDescending(x => x.CreateTime).First();
  12418. if (_EnterExitCosts == null) return Ok(JsonView(400, "未填写出入境费用-草稿;", ""));
  12419. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(it => it.IsDel == 0 && it.ParentId == id).ToList();
  12420. var countryIds = _DayAndCosts.Select(x => x.NationalTravelFeeId).ToList();
  12421. var nationalTravelFeeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0 && countryIds.Contains(it.Id)).ToList();
  12422. var enterExitCostCurrencys = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(_EnterExitCosts.CurrencyRemark);
  12423. //数据源
  12424. var dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  12425. var dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  12426. var dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  12427. var dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  12428. var dac5 = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  12429. .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
  12430. .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
  12431. .Where((x, a, b) => x.IsDel == 0 && x.ParentId == id)
  12432. .Select((x, a, b) => new
  12433. {
  12434. x.Index,
  12435. itemName = a.Name,
  12436. CurrencyStr = b.Name,
  12437. x.Cost,
  12438. x.SubTotal,
  12439. x.Remark
  12440. })
  12441. .OrderBy((x) => x.Index)
  12442. .ToList(); //其他款项费用
  12443. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  12444. var peiceItemCurrencys = new List<string>();
  12445. if (_DayAndCosts.Any())
  12446. {
  12447. var currencyIds = _DayAndCosts.Select(x => x.Currency).Distinct().ToList();
  12448. if (currencyIds.Any()) peiceItemCurrencys.AddRange(_CurrDatas.Where(x => currencyIds.Contains(x.Id)).Select(x => x.Name).ToList());
  12449. }
  12450. if (dac5.Any()) peiceItemCurrencys.AddRange(dac5.Select(x => x.CurrencyStr).Distinct().ToList());
  12451. var peiceItemCurrencyInfos = new List<CurrencyInfo>();
  12452. if (enterExitCostCurrencys.Any() && peiceItemCurrencys.Any())
  12453. {
  12454. peiceItemCurrencyInfos = enterExitCostCurrencys.Where(x => peiceItemCurrencys.Contains(x.CurrencyCode)).ToList();
  12455. }
  12456. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  12457. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  12458. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  12459. if (dto.ExportType == 1) //明细表
  12460. {
  12461. if (dto.SubTypeId == 1005) //1005(默认明细表)
  12462. {
  12463. //获取模板
  12464. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  12465. //载入模板
  12466. Document doc = new Document(tempPath);
  12467. DocumentBuilder builder = new DocumentBuilder(doc);
  12468. //利用键值对存放数据
  12469. Dictionary<string, string> dic = new Dictionary<string, string>();
  12470. decimal stayFeeTotal = _EnterExitCosts.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M; // 住宿费
  12471. decimal mealsFeeTotal = _EnterExitCosts.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M; // 伙食费费
  12472. decimal miscellaneousFeeTotal = _EnterExitCosts.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
  12473. decimal tainFeeTotal = _EnterExitCosts.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M; // 培训费
  12474. decimal otherPriceTotal = _EnterExitCosts.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
  12475. decimal insidePayTotal = _EnterExitCosts.ChoiceOne == 1 ? _EnterExitCosts.InsidePay : 0.00M;
  12476. //境内费用(其他费用)
  12477. if (_EnterExitCosts.ChoiceOne == 1)
  12478. {
  12479. string row1_1 = "";
  12480. if (_EnterExitCosts.Visa > 0)
  12481. {
  12482. //insidePayTotal += _EnterExitCosts.Visa;
  12483. row1_1 = $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 人民币/人";
  12484. //if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  12485. //{
  12486. // row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark} 人民币/人";
  12487. //}
  12488. }
  12489. string row1_2 = "";
  12490. if (_EnterExitCosts.YiMiao > 0)
  12491. {
  12492. //insidePayTotal += _EnterExitCosts.YiMiao;
  12493. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")} 人民币/人";
  12494. }
  12495. if (_EnterExitCosts.HeSuan > 0)
  12496. {
  12497. //insidePayTotal += _EnterExitCosts.HeSuan;
  12498. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan.ToString("#0.00")} 人民币/人";
  12499. }
  12500. if (_EnterExitCosts.Service > 0)
  12501. {
  12502. //insidePayTotal += _EnterExitCosts.Service;
  12503. row1_2 += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")} 人民币/人";
  12504. }
  12505. string row1_3 = "";
  12506. if (_EnterExitCosts.Safe > 0)
  12507. {
  12508. //insidePayTotal += _EnterExitCosts.Safe;
  12509. row1_3 += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 人民币/人";
  12510. }
  12511. if (_EnterExitCosts.Ticket > 0)
  12512. {
  12513. //insidePayTotal += _EnterExitCosts.Ticket;
  12514. row1_3 += $"参展门票:{_EnterExitCosts.Ticket.ToString("#0.00")} 人民币/人";
  12515. }
  12516. string row1 = "";
  12517. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  12518. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  12519. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}\r\n";
  12520. row1 += $"备注:{_EnterExitCosts.Remark}";
  12521. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  12522. dic.Add("Row1Str", row1);
  12523. }
  12524. string airTotalStr = string.Empty,
  12525. airPriceStr = string.Empty;
  12526. //经济舱
  12527. if (_EnterExitCosts.SumJJC == 1)
  12528. {
  12529. airTotalStr += $"{_EnterExitCosts.OutsideJJPay.ToString("#0.00")}元/人(经济舱)";
  12530. airPriceStr += $"{_EnterExitCosts.AirJJ.ToString("#0.00")}元/人(经济舱)";
  12531. }
  12532. //公务舱
  12533. if (_EnterExitCosts.SumGWC == 1)
  12534. {
  12535. airTotalStr += $" {_EnterExitCosts.OutsideGWPay.ToString("#0.00")} 元/人(公务舱)";
  12536. airPriceStr += $" {_EnterExitCosts.AirGW.ToString("#0.00")} 元/人(公务舱)";
  12537. }
  12538. //头等舱
  12539. if (_EnterExitCosts.SumTDC == 1)
  12540. {
  12541. airTotalStr += $" {_EnterExitCosts.OutsideTDPay.ToString("#0.00")} 元/人(头等舱)";
  12542. airPriceStr += $" {_EnterExitCosts.AirTD.ToString("#0.00")} 元/人(头等舱)";
  12543. }
  12544. //汇率描述
  12545. string rateStr = "";
  12546. if (peiceItemCurrencyInfos.Any())
  12547. {
  12548. rateStr = "\r\n汇率描述:";
  12549. foreach (var item in peiceItemCurrencyInfos)
  12550. {
  12551. rateStr += $"{item.CurrencyName}({item.CurrencyCode}):{item.Rate.ToString("#0.0000")} ";
  12552. }
  12553. }
  12554. string twoItemRemark = "备注:";
  12555. if (!string.IsNullOrEmpty(_EnterExitCosts.TwoItemRemark)) twoItemRemark += _EnterExitCosts.TwoItemRemark;
  12556. if (!string.IsNullOrEmpty(rateStr)) twoItemRemark += rateStr;
  12557. dic.Add("AirTotalStr", airTotalStr);
  12558. dic.Add("AirPriceStr", airPriceStr);
  12559. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  12560. dic.Add("TwoItemRemark", twoItemRemark);
  12561. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12562. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  12563. int table1Row = 0,
  12564. table2Row = 0,
  12565. table3Row = 0,
  12566. table4Row = 0,
  12567. table5Row = 0;
  12568. //住宿费
  12569. if (_EnterExitCosts.ChoiceThree == 1)
  12570. {
  12571. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  12572. table1Row = dac1.Count;
  12573. #region 填充word表格内容
  12574. for (int i = 0; i < dac1.Count; i++)
  12575. {
  12576. var dac = dac1[i];
  12577. if (dac == null) continue;
  12578. builder.MoveToCell(0, i, 0, 0);
  12579. builder.Write("第" + dac.Days.ToString() + "晚:");
  12580. builder.MoveToCell(0, i, 1, 0);
  12581. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  12582. //builder.Write(dac.Place == null ? "" : dac.Place);
  12583. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12584. builder.MoveToCell(0, i, 2, 0);
  12585. builder.Write("费用标准:");
  12586. string curr = "";
  12587. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12588. if (currData != null)
  12589. {
  12590. curr = currData.Name;
  12591. }
  12592. builder.MoveToCell(0, i, 3, 0);
  12593. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12594. builder.MoveToCell(0, i, 4, 0);
  12595. builder.Write("费用小计:");
  12596. builder.MoveToCell(0, i, 5, 0);
  12597. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12598. }
  12599. #endregion
  12600. }
  12601. else dic.Add("SubZS", "0.00");
  12602. //删除多余行
  12603. while (table1.Rows.Count > table1Row)
  12604. {
  12605. table1.Rows.RemoveAt(table1Row);
  12606. }
  12607. //伙食费
  12608. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  12609. if (_EnterExitCosts.ChoiceFour == 1)
  12610. {
  12611. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  12612. table2Row = dac2.Count;
  12613. #region 填充word表格内容
  12614. for (int i = 0; i < dac2.Count; i++)
  12615. {
  12616. var dac = dac2[i];
  12617. if (dac == null) continue;
  12618. builder.MoveToCell(1, i, 0, 0);
  12619. builder.Write("第" + dac.Days.ToString() + "天:");
  12620. builder.MoveToCell(1, i, 1, 0);
  12621. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12622. builder.MoveToCell(1, i, 2, 0);
  12623. builder.Write("费用标准:");
  12624. string curr = "";
  12625. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12626. if (currData != null)
  12627. {
  12628. curr = currData.Name;
  12629. }
  12630. builder.MoveToCell(1, i, 3, 0);
  12631. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12632. builder.MoveToCell(1, i, 4, 0);
  12633. builder.Write("费用小计:");
  12634. builder.MoveToCell(1, i, 5, 0);
  12635. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12636. }
  12637. #endregion
  12638. }
  12639. else dic.Add("SubHS", "0.00");
  12640. //删除多余行
  12641. while (table2.Rows.Count > table2Row)
  12642. {
  12643. table2.Rows.RemoveAt(table2Row);
  12644. }
  12645. //公杂费
  12646. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  12647. if (_EnterExitCosts.ChoiceFive == 1)
  12648. {
  12649. dic.Add("SubGZF", miscellaneousFeeTotal.ToString("#0.00"));
  12650. table3Row = dac3.Count;
  12651. #region 填充word表格内容
  12652. for (int i = 0; i < dac3.Count; i++)
  12653. {
  12654. var dac = dac3[i];
  12655. if (dac == null) continue;
  12656. builder.MoveToCell(2, i, 0, 0);
  12657. builder.Write("第" + dac.Days.ToString() + "天:");
  12658. builder.MoveToCell(2, i, 1, 0);
  12659. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12660. builder.MoveToCell(2, i, 2, 0);
  12661. builder.Write("费用标准:");
  12662. string curr = "";
  12663. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12664. if (currData != null)
  12665. {
  12666. curr = currData.Name;
  12667. }
  12668. builder.MoveToCell(2, i, 3, 0);
  12669. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12670. builder.MoveToCell(2, i, 4, 0);
  12671. builder.Write("费用小计:");
  12672. builder.MoveToCell(2, i, 5, 0);
  12673. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12674. }
  12675. //删除多余行
  12676. while (table3.Rows.Count > table3Row)
  12677. {
  12678. table3.Rows.RemoveAt(table3Row);
  12679. }
  12680. #endregion
  12681. }
  12682. else dic.Add("SubGZF", "0.00");
  12683. //删除多余行
  12684. while (table3.Rows.Count > table3Row)
  12685. {
  12686. table3.Rows.RemoveAt(table3Row);
  12687. }
  12688. //培训费
  12689. Aspose.Words.Tables.Table table4 = allTables[3] as Aspose.Words.Tables.Table;
  12690. if (_EnterExitCosts.ChoiceSix == 1)
  12691. {
  12692. string pxStr = $"六、培训费合计: {tainFeeTotal.ToString("#0.00")} 元/人";
  12693. dic.Add("SubPX", pxStr);
  12694. table4Row = dac4.Count;
  12695. #region 填充word表格内容
  12696. for (int i = 0; i < dac4.Count; i++)
  12697. {
  12698. var dac = dac4[i];
  12699. if (dac == null) continue;
  12700. builder.MoveToCell(3, i, 0, 0);
  12701. builder.Write("第" + dac.Days.ToString() + "天:");
  12702. builder.MoveToCell(3, i, 1, 0);
  12703. builder.Write(GetEnterExitCostDraftExportCity(placeData, dac.NationalTravelFeeId));
  12704. builder.MoveToCell(3, i, 2, 0);
  12705. builder.Write("费用标准:");
  12706. string curr = "";
  12707. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  12708. if (currData != null)
  12709. {
  12710. curr = currData.Name;
  12711. }
  12712. builder.MoveToCell(3, i, 3, 0);
  12713. builder.Write(dac.Cost.ToString("#0.00") + curr);
  12714. builder.MoveToCell(3, i, 4, 0);
  12715. builder.Write("费用小计:");
  12716. builder.MoveToCell(3, i, 5, 0);
  12717. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12718. }
  12719. #endregion
  12720. }
  12721. //else dic.Add("SubPX", $"六、培训费合计: 0 元/人");
  12722. //删除多余行
  12723. while (table4.Rows.Count > table4Row)
  12724. {
  12725. table4.Rows.RemoveAt(table4Row);
  12726. }
  12727. //其他费用
  12728. Aspose.Words.Tables.Table table5 = allTables[4] as Aspose.Words.Tables.Table;
  12729. if (_EnterExitCosts.OtherExpenses_Checked == 1)
  12730. {
  12731. string qtStr = $"七、其他费用合计: {otherPriceTotal.ToString("#0.00")} 元/人";
  12732. dic.Add("titleQi", qtStr);
  12733. table5Row = dac5.Count;
  12734. #region 填充word表格内容
  12735. for (int i = 0; i < dac5.Count; i++)
  12736. {
  12737. var dac = dac5[i];
  12738. if (dac == null) continue;
  12739. builder.MoveToCell(4, i, 0, 0);
  12740. builder.Write("第" + dac.Index.ToString() + "项:");
  12741. builder.MoveToCell(4, i, 1, 0);
  12742. builder.Write(dac.itemName);
  12743. builder.MoveToCell(4, i, 2, 0);
  12744. builder.Write("费用标准:");
  12745. builder.MoveToCell(4, i, 3, 0);
  12746. builder.Write(dac.Cost.ToString("#0.00") + dac.CurrencyStr);
  12747. builder.MoveToCell(4, i, 4, 0);
  12748. builder.Write("费用小计:");
  12749. builder.MoveToCell(4, i, 5, 0);
  12750. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  12751. builder.MoveToCell(4, i, 6, 0);
  12752. builder.Write("备注:");
  12753. builder.MoveToCell(4, i, 7, 0);
  12754. builder.Write(dac.Remark);
  12755. }
  12756. #endregion
  12757. }
  12758. //else dic.Add("SubQT", "七、其他费用合计: 0 元/人");
  12759. //删除多余行
  12760. while (table5.Rows.Count > table5Row)
  12761. {
  12762. table5.Rows.RemoveAt(table5Row);
  12763. }
  12764. //加上其他费用
  12765. decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
  12766. decimal subJJC = 0.00M,
  12767. subGWC = 0.00M,
  12768. subTDC = 0.00M;
  12769. //全部费用总计: 元 / 人(经济舱) 元 / 人(公务舱) 元 / 人(头等舱)
  12770. string totalLabel = string.Format("全部费用总计:");
  12771. //经济舱
  12772. if (_EnterExitCosts.SumJJC == 1)
  12773. {
  12774. subJJC = otherFeeTotal + _EnterExitCosts.OutsideJJPay;
  12775. totalLabel += $"{subJJC.ToString("#0.00")} 元/人(经济舱)";
  12776. }
  12777. //公务舱
  12778. if (_EnterExitCosts.SumGWC == 1)
  12779. {
  12780. subGWC = otherFeeTotal + _EnterExitCosts.OutsideGWPay;
  12781. totalLabel += $"{subGWC.ToString("#0.00")} 元/人(公务舱)";
  12782. }
  12783. //头等舱
  12784. if (_EnterExitCosts.SumTDC == 1)
  12785. {
  12786. subTDC = otherFeeTotal + _EnterExitCosts.OutsideTDPay;
  12787. totalLabel += $"{subTDC.ToString("#0.00")} 元/人(头等舱)";
  12788. }
  12789. //TotalLabel
  12790. dic.Add("TotalLabel", totalLabel);
  12791. #region 填充word模板书签内容
  12792. foreach (var key in dic.Keys)
  12793. {
  12794. Bookmark bookmark = doc.Range.Bookmarks[key];
  12795. if (bookmark != null)
  12796. {
  12797. builder.MoveToBookmark(key);
  12798. builder.Write(dic[key]);
  12799. }
  12800. }
  12801. #endregion
  12802. //文件名
  12803. string strFileName = $"{_EnterExitCosts.DraftName}_出入境费用-草稿{Guid.NewGuid().ToString()}.docx";
  12804. strFileName = CommonFun.ValidFileName(strFileName);
  12805. AsposeHelper.removewatermark_v2180();
  12806. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  12807. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  12808. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  12809. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  12810. }
  12811. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  12812. {
  12813. //获取模板
  12814. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  12815. //载入模板
  12816. Document doc = new Document(tempPath);
  12817. DocumentBuilder builder = new DocumentBuilder(doc);
  12818. Dictionary<string, string> dic = new Dictionary<string, string>();
  12819. string returnCodeLabel = string.Empty;
  12820. if (nationalTravelFeeData.Any())
  12821. {
  12822. List<string> list = new List<string>();
  12823. foreach (var item in nationalTravelFeeData)
  12824. {
  12825. list.Add($"{item.Country}({item.City})");
  12826. }
  12827. list = list.Distinct().ToList();
  12828. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  12829. }
  12830. var countryLabel = string.Empty;
  12831. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  12832. if (countryData.Any())
  12833. {
  12834. countryLabel = string.Join("、", countryData);
  12835. }
  12836. dic.Add("ReturnCodeAir", returnCodeLabel);
  12837. dic.Add("VisitStartDate", "-");
  12838. dic.Add("VisitEndDate", "-");
  12839. dic.Add("Day", "-");
  12840. dic.Add("VisitCountry", countryLabel);
  12841. dic.Add("ClientUnit", "-");
  12842. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  12843. //dic.Add("Names", Names);
  12844. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  12845. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  12846. decimal dac1totalPrice = 0.00M;
  12847. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  12848. foreach (var dac in dac1)
  12849. {
  12850. if (dac.SubTotal == 0.00M)
  12851. {
  12852. continue;
  12853. }
  12854. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  12855. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  12856. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  12857. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  12858. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  12859. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  12860. builder.Write(currency);//币种
  12861. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  12862. builder.Write(dac.Cost.ToString("#0.00"));//标准
  12863. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  12864. builder.Write("");//人数
  12865. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  12866. builder.Write("");//天数
  12867. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  12868. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  12869. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  12870. decimal rate = 0.00M;
  12871. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  12872. builder.Write(rate.ToString("#0.0000"));//汇率
  12873. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  12874. decimal rbmPrice = dac.SubTotal;
  12875. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  12876. accommodationStartIndex++;
  12877. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  12878. }
  12879. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  12880. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  12881. {
  12882. table1.Rows.RemoveAt(i - 1);
  12883. foodandotherStartIndex--;
  12884. }
  12885. if (dac2.Count == dac3.Count)//国家 币种 金额
  12886. {
  12887. for (int i = 0; i < dac2.Count; i++)
  12888. {
  12889. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  12890. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  12891. }
  12892. }
  12893. decimal dac2totalPrice = 0.00M;
  12894. foreach (var dac in dac2)
  12895. {
  12896. if (dac.SubTotal == 0)
  12897. {
  12898. continue;
  12899. }
  12900. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  12901. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  12902. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  12903. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  12904. builder.Write(currency);//币种
  12905. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  12906. builder.Write(dac.Cost.ToString("#0.00"));//标准
  12907. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  12908. builder.Write("");//人数
  12909. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  12910. builder.Write("");//天数
  12911. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  12912. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  12913. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  12914. decimal rate = 0.00M;
  12915. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  12916. builder.Write(rate.ToString("#0.0000"));//汇率
  12917. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  12918. decimal rbmPrice = dac.SubTotal;
  12919. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  12920. foodandotherStartIndex++;
  12921. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  12922. }
  12923. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  12924. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  12925. {
  12926. table1.Rows.RemoveAt(i - 1);
  12927. }
  12928. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  12929. string otherFeeStr = "";
  12930. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  12931. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  12932. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费:{_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  12933. #region 其他款项费用 增加位置:模板第6项其他费用字符串追加
  12934. foreach (var otherInfo in dac5)
  12935. {
  12936. otherFeeStr += $"{otherInfo.itemName}:{otherInfo.SubTotal.ToString("#0.00")} 元,";
  12937. }
  12938. #endregion
  12939. if (otherFeeStr.Length > 0)
  12940. {
  12941. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  12942. otherFeeStr = $"({otherFeeStr})";
  12943. dic.Add("OtherFeeStr", otherFeeStr);
  12944. }
  12945. //总计
  12946. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  12947. //国际旅费
  12948. string outsideAir = string.Empty;
  12949. string allPriceAir = string.Empty;
  12950. if (_EnterExitCosts.SumJJC == 1)
  12951. {
  12952. outsideAir += string.Format(@"经济舱:{0} 元/人;", _EnterExitCosts.AirJJ.ToString("#0.00"));
  12953. allPriceAir += string.Format(@"经济舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  12954. }
  12955. if (_EnterExitCosts.SumGWC == 1)
  12956. {
  12957. outsideAir += string.Format(@"公务舱:{0} 元/人;", _EnterExitCosts.AirGW.ToString("#0.00"));
  12958. allPriceAir += string.Format(@"公务舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  12959. }
  12960. if (_EnterExitCosts.SumTDC == 1)
  12961. {
  12962. outsideAir += string.Format(@"头等舱:{0} 元/人;", _EnterExitCosts.AirTD.ToString("#0.00"));
  12963. allPriceAir += string.Format(@"头等舱:{0} 元/人;", (allPrice + _EnterExitCosts.OutsideTDPay).ToString("#0.00"));
  12964. }
  12965. dic.Add("InTravelPrice", $"({outsideAir})");
  12966. dic.Add("FinalSumPrice", $"({allPriceAir})");
  12967. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  12968. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  12969. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  12970. foreach (var key in dic.Keys)
  12971. {
  12972. builder.MoveToBookmark(key);
  12973. builder.Write(dic[key]);
  12974. }
  12975. //模板文件名
  12976. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_因公出国(境)经费测算明细表{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  12977. strFileName = CommonFun.ValidFileName(strFileName);
  12978. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  12979. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  12980. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  12981. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  12982. }
  12983. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  12984. {
  12985. //获取模板
  12986. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  12987. //载入模板
  12988. WorkbookDesigner designer = new WorkbookDesigner();
  12989. designer.Workbook = new Workbook(tempPath);
  12990. Dictionary<string, string> dic = new Dictionary<string, string>();
  12991. string returnCodeLabel = string.Empty;
  12992. if (nationalTravelFeeData.Any())
  12993. {
  12994. List<string> list = new List<string>();
  12995. foreach (var item in nationalTravelFeeData)
  12996. {
  12997. list.Add($"{item.Country}({item.City})");
  12998. }
  12999. list = list.Distinct().ToList();
  13000. returnCodeLabel = string.Join("-", list).TrimEnd('-');
  13001. }
  13002. var countryLabel = string.Empty;
  13003. var countryData = nationalTravelFeeData.Select(x => x.Country).Distinct().ToList();
  13004. if (countryData.Any())
  13005. {
  13006. countryLabel = string.Join("、", countryData);
  13007. }
  13008. dic.Add("ReturnCodeAir", returnCodeLabel);
  13009. dic.Add("VisitStartDate", "-");
  13010. dic.Add("VisitEndDate", "-");
  13011. dic.Add("Day", "0");
  13012. dic.Add("VisitCountry", countryLabel);
  13013. dic.Add("ClientUnit", "-");
  13014. designer.SetDataSource("ClientUnit", "-");
  13015. designer.SetDataSource("VisitCountry", countryLabel);
  13016. designer.SetDataSource("Group", "-");
  13017. designer.SetDataSource("ClientUnitTitle", "-");
  13018. designer.SetDataSource("Name", "-");
  13019. designer.SetDataSource("VisitStartDate", "-");
  13020. designer.SetDataSource("Day", "0");
  13021. designer.SetDataSource("ReturnCode", returnCodeLabel);
  13022. designer.SetDataSource("ReturnCodeAir", "-");
  13023. int startIndex = 10;
  13024. const int startIndexcopy = 10;
  13025. if (dac2.Count == dac3.Count)//国家 币种 金额
  13026. {
  13027. for (int i = 0; i < dac2.Count; i++)
  13028. {
  13029. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  13030. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  13031. }
  13032. }
  13033. DataTable dtdac1 = new DataTable();
  13034. List<string> place = new List<string>();
  13035. dtdac1.Columns.AddRange(new DataColumn[] {
  13036. new DataColumn(){ ColumnName = "city"},
  13037. new DataColumn(){ ColumnName = "curr"},
  13038. new DataColumn(){ ColumnName = "criterion"},
  13039. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  13040. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  13041. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  13042. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  13043. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  13044. });
  13045. DataTable dtdac2 = new DataTable();
  13046. dtdac2.Columns.AddRange(new DataColumn[] {
  13047. new DataColumn(){ ColumnName = "city"},
  13048. new DataColumn(){ ColumnName = "curr"},
  13049. new DataColumn(){ ColumnName = "criterion"},
  13050. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  13051. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  13052. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  13053. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  13054. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  13055. });
  13056. dtdac1.TableName = "tb1";
  13057. dtdac2.TableName = "tb2";
  13058. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  13059. foreach (var item in dac1)
  13060. {
  13061. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  13062. if (place.Contains(item.Place))
  13063. {
  13064. continue;
  13065. }
  13066. DataRow row = dtdac1.NewRow();
  13067. row["city"] = item.Place;
  13068. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  13069. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  13070. row["curr"] = currency;
  13071. row["rate"] = rate.ToString("#0.0000");
  13072. row["criterion"] = item.Cost.ToString("#0.00");
  13073. row["number"] = 1;
  13074. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  13075. //row["costRMB"] = rbmPrice;
  13076. dtdac1.Rows.Add(row);
  13077. place.Add(item.Place);
  13078. }
  13079. place = new List<string>();
  13080. foreach (var item in dac2)
  13081. {
  13082. item.Place = GetEnterExitCostDraftExportCity(placeData, item.NationalTravelFeeId);
  13083. if (place.Contains(item.Place))
  13084. {
  13085. continue;
  13086. }
  13087. DataRow row = dtdac2.NewRow();
  13088. row["city"] = item.Place;
  13089. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  13090. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  13091. row["curr"] = currency;
  13092. row["rate"] = rate.ToString("#0.0000");
  13093. row["criterion"] = item.Cost.ToString("#0.00");
  13094. row["number"] = 1;
  13095. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  13096. //row["cost"] = item.SubTotal;
  13097. //row["costRMB"] = rbmPrice;
  13098. dtdac2.Rows.Add(row);
  13099. place.Add(item.Place);
  13100. //dac2totalPrice += rbmPrice;
  13101. }
  13102. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  13103. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  13104. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  13105. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  13106. designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {_EnterExitCosts.CityTranffic:#0.00} 元");
  13107. designer.SetDataSource("sumCityTranffic", @$"{_EnterExitCosts.CityTranffic:#0.00} ");
  13108. string cell4Str1 = string.Empty;
  13109. if (_EnterExitCosts.SumJJC == 1) cell4Str1 += $"经济舱:{_EnterExitCosts.AirJJ:#0.00} 元/人;";
  13110. if (_EnterExitCosts.SumGWC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirGW:#0.00} 元/人;";
  13111. if (_EnterExitCosts.SumTDC == 1) cell4Str1 += $"公务舱:{_EnterExitCosts.AirTD:#0.00} 元/人;";
  13112. string cell4Str = $" 4.国际旅费:{cell4Str1}";
  13113. string cellStr = $" 5.其他费用(";
  13114. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa:#0.00}元,";
  13115. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao:#0.00}元,";
  13116. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan:#0.00}元,";
  13117. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe:#0.00}元,";
  13118. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket:#0.00}元,";
  13119. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service:#0.00}元,";
  13120. #region 其他款项费用 增加位置:模板第5项其他费用字符串追加
  13121. var otherPriceTotal = dac5.Sum(x => x.SubTotal);
  13122. foreach (var otherInfo in dac5)
  13123. {
  13124. cellStr += $"{otherInfo.itemName}:{otherInfo.SubTotal:#0.00} 元,";
  13125. }
  13126. #endregion
  13127. if (cellStr.Length > 8)
  13128. {
  13129. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  13130. }
  13131. cellStr += ")";
  13132. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service + otherPriceTotal;
  13133. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  13134. decimal pxFee = dac4.Sum(it => it.Cost);
  13135. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  13136. string celllastStr1 = "";
  13137. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice:#0.00} 元";
  13138. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice:#0.00} 元";
  13139. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee:#0.00} 元";
  13140. celllastStr1 += $",国际旅费 元";
  13141. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee:#0.00} 元";
  13142. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  13143. designer.SetDataSource("cell4Str", cell4Str);
  13144. designer.SetDataSource("cellStr", cellStr);
  13145. designer.SetDataSource("cellSum", otherFee.ToString("#0.00"));
  13146. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  13147. designer.SetDataSource("celllastStr", celllastStr);
  13148. Workbook wb = designer.Workbook;
  13149. var sheet = wb.Worksheets[0];
  13150. //绑定datatable数据集
  13151. designer.SetDataSource(dtdac1);
  13152. designer.SetDataSource(dtdac2);
  13153. designer.Process();
  13154. var rowStart = dtdac1.Rows.Count;
  13155. while (rowStart > 0)
  13156. {
  13157. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  13158. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  13159. startIndex++;
  13160. rowStart--;
  13161. }
  13162. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  13163. startIndex += 1; //总计行
  13164. rowStart = dtdac2.Rows.Count;
  13165. while (rowStart > 0)
  13166. {
  13167. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  13168. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  13169. startIndex++;
  13170. rowStart--;
  13171. }
  13172. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  13173. wb.CalculateFormula(true);
  13174. //模板文件名
  13175. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  13176. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  13177. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  13178. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  13179. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  13180. }
  13181. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  13182. {
  13183. //获取模板
  13184. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  13185. //载入模板
  13186. Document doc = new Document(tempPath);
  13187. DocumentBuilder builder = new DocumentBuilder(doc);
  13188. Dictionary<string, string> dic = new Dictionary<string, string>();
  13189. dic.Add("GroupName", "-");
  13190. dic.Add("ClientUnit", "-");
  13191. //string missionLeader = ""; //团负责人默认接团客户名单第一个人
  13192. //string missionLeaderJob = "";//负责人job
  13193. //int groupNumber = 0; //团人数
  13194. dic.Add("MissionLeader", "-"); //团负责人
  13195. dic.Add("MissionLeaderJob", "-"); //团负责人job
  13196. dic.Add("GroupNumber", "0"); //团人数
  13197. dic.Add("Day", "0");
  13198. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  13199. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  13200. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  13201. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  13202. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  13203. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  13204. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  13205. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  13206. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  13207. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  13208. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  13209. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  13210. decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  13211. dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  13212. //其他费用
  13213. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service + dac5.Sum(x => x.SubTotal);
  13214. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  13215. //其他费用合计
  13216. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  13217. decimal _jjcFeeToatal = _EnterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  13218. decimal _gwcFeeToatal = _EnterExitCosts.AirGW + _otherFeeTotal; //公务舱
  13219. //公务舱合计
  13220. //国际旅费
  13221. //string outsideJJ = "";
  13222. //string allPriceJJ = "";
  13223. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  13224. {
  13225. dic.Add("AirFeeTotal", _EnterExitCosts.AirJJ.ToString("#0.00"));
  13226. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  13227. }
  13228. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  13229. {
  13230. dic.Add("AirFeeTotal", _EnterExitCosts.AirGW.ToString("#0.00"));
  13231. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  13232. }
  13233. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  13234. {
  13235. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.AirJJ:#0.00} 公务舱:{_EnterExitCosts.AirGW:#0.00}");
  13236. dic.Add("AirFeeTotal", airFeeTotalStr);
  13237. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal:#0.00} 公务舱:{_gwcFeeToatal:#0.00}");
  13238. dic.Add("FeeTotal", feeTotalStr);
  13239. }
  13240. foreach (var key in dic.Keys)
  13241. {
  13242. builder.MoveToBookmark(key);
  13243. builder.Write(dic[key]);
  13244. }
  13245. //模板文件名
  13246. string strFileName = $"草稿_{_EnterExitCosts.DraftName}_成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  13247. strFileName = CommonFun.ValidFileName(strFileName);
  13248. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  13249. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  13250. if (dto.PortType == 1 || dto.PortType == 3) return Ok(JsonView(true, "成功", new { Url = url }));
  13251. else if (dto.PortType == 2) return Ok(JsonView(true, "成功", url));
  13252. }
  13253. }
  13254. else if (dto.ExportType == 2) //表格
  13255. {
  13256. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  13257. }
  13258. else if (dto.ExportType == 3)
  13259. {
  13260. return Ok(JsonView(400, "因需关联团组信息和客户信息,请在出入境费用明细里下载!", ""));
  13261. }
  13262. return Ok(JsonView(400, "只可导出明细表!", ""));
  13263. }
  13264. catch (Exception ex)
  13265. {
  13266. return Ok(JsonView(400, ex.Message, ""));
  13267. }
  13268. }
  13269. /// <summary>
  13270. /// 团组模块 - 出入境费用-草稿
  13271. /// 获取三公费用标准city
  13272. /// </summary>
  13273. /// <param name="placeData"></param>
  13274. /// <param name="nationalTravelFeeId"></param>
  13275. /// <returns></returns>
  13276. private string GetEnterExitCostDraftExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  13277. {
  13278. string _city = string.Empty;
  13279. if (!placeData.Any()) return _city;
  13280. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  13281. if (data == null) return _city;
  13282. string country = data.Country;
  13283. string city = data.City;
  13284. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  13285. else _city = city;
  13286. return _city;
  13287. }
  13288. /// <summary>
  13289. /// 团组模块 - 出入境费用-草稿
  13290. /// 一键清空
  13291. /// </summary>
  13292. /// <returns></returns>
  13293. [HttpPost]
  13294. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13295. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13296. public async Task<IActionResult> EnterExitCostDraftOneClickEmpty(EnterExitCostDraftOneClickEmptyDto dto)
  13297. {
  13298. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数;"));
  13299. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数;"));
  13300. var _view = await _enterExitCostDraftRep.OneClickEmpty(dto.Id, dto.UserId);
  13301. if (_view.Code == 0)
  13302. {
  13303. return Ok(JsonView(true, "操作成功"));
  13304. }
  13305. return Ok(JsonView(false, "操作失败"));
  13306. }
  13307. /// <summary>
  13308. /// 团组模块 - 出入境费用-草稿
  13309. /// 子项删除
  13310. /// </summary>
  13311. /// <returns></returns>
  13312. [HttpPost]
  13313. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13314. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13315. public async Task<IActionResult> EnterExitCostDraftSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  13316. {
  13317. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  13318. if (data.Code != 0)
  13319. {
  13320. return Ok(JsonView(false, data.Msg));
  13321. }
  13322. return Ok(JsonView(true, "操作成功!", data.Data));
  13323. }
  13324. /// <summary>
  13325. /// 团组模块 - 出入境费用-草稿
  13326. /// 删除
  13327. /// </summary>
  13328. /// <param name="dto"></param>
  13329. /// <returns></returns>
  13330. [HttpPost]
  13331. //[ApiLog("Grp_EnterExitCostDraft", OperationEnum.Del)]
  13332. public IActionResult EnterExitCostDraftOtherExpensesDel(EnterExitCostDraftOtherExpensesDelDto dto)
  13333. {
  13334. var jw = JsonView(false, "删除失败!");
  13335. var data = new Grp_DayOtherPriceDraft()
  13336. {
  13337. Id = dto.Id,
  13338. IsDel = 1,
  13339. DeleteUserId = dto.DeleteUserId,
  13340. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  13341. };
  13342. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  13343. if (del > 0)
  13344. {
  13345. jw.Code = 200;
  13346. jw.Msg = "删除成功!";
  13347. }
  13348. return Ok(jw);
  13349. }
  13350. /// <summary>
  13351. /// 团组模块 - 出入境费用-草稿
  13352. /// 导入正式出入境费用基础数据
  13353. /// </summary>
  13354. /// <returns></returns>
  13355. [HttpPost]
  13356. public async Task<IActionResult> EnterExitCostDraftImportDataInit()
  13357. {
  13358. var jw = JsonView(false);
  13359. var groupNameDatas = await _groupRepository.EnterExitCostGroupNameAsync();
  13360. var draftDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0).OrderByDescending(x => x.CreateTime).Select(x => new { x.Id, x.DraftName }).ToListAsync();
  13361. jw.Code = StatusCodes.Status200OK;
  13362. jw.Msg = "操作成功!";
  13363. jw.Data = new { groupNameDatas, draftNames = draftDatas };
  13364. return Ok(jw);
  13365. }
  13366. /// <summary>
  13367. /// 团组模块 - 出入境费用-草稿
  13368. /// 导入正式出入境费用
  13369. /// </summary>
  13370. /// <param name="dto"></param>
  13371. /// <returns></returns>
  13372. [HttpPost]
  13373. public async Task<IActionResult> EnterExitCostDraftImportData(EnterExitCostDraftImportDataDto dto)
  13374. {
  13375. int userId = dto.UserId,
  13376. portId = dto.PortType,
  13377. groupId = dto.GroupId,
  13378. draftId = dto.DraftId;
  13379. _portTypeData.Add(1);
  13380. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13381. if (!_portTypeData.Contains(portId)) return Ok(JsonView(false, MsgTips.Port));
  13382. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId!"));
  13383. if (draftId < 1) return Ok(JsonView(false, "请传入有效的DraftId!"));
  13384. _sqlSugar.BeginTran();
  13385. try
  13386. {
  13387. var draftDatas = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).First();
  13388. if (draftDatas == null)
  13389. {
  13390. _sqlSugar.RollbackTran();
  13391. return Ok(JsonView(false, "草稿数据为空,不可导入!"));
  13392. }
  13393. //验证可覆盖已有数据 两边创建人需为同一人;
  13394. int draftCreateUserId = draftDatas.CreateUserId,
  13395. formalCreateUserId = 0;
  13396. var formalData = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  13397. if (formalData != null)
  13398. {
  13399. formalCreateUserId = formalData.CreateUserId;
  13400. if (draftCreateUserId != formalCreateUserId)
  13401. {
  13402. _sqlSugar.RollbackTran();
  13403. return Ok(JsonView(false, "由草稿数据到入至正式数据,两边创建人为同一人才可导入正式版!"));
  13404. }
  13405. }
  13406. //默认添加查看、编辑权限(创建人、自己)
  13407. await _enterExitCostRep.InitPerm(dto.GroupId, dto.UserId);
  13408. var dayDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  13409. var otherDatas = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == draftId).ToList();
  13410. var newExterData = _mapper.Map<Grp_EnterExitCost>(draftDatas);
  13411. newExterData.DiId = groupId;
  13412. newExterData.CreateUserId = userId;
  13413. newExterData.Remark = $"由草稿数据导入;草稿数Id:{draftId}";
  13414. var newDayDatas = _mapper.Map<List<Grp_DayAndCost>>(dayDatas);
  13415. if (newDayDatas.Any()) newDayDatas.Select(x => { x.DiId = groupId; x.CreateUserId = userId; return x; }).ToList();
  13416. var newOtherDatas = _mapper.Map<List<Grp_DayOtherPrice>>(otherDatas);
  13417. if (newOtherDatas.Any()) newOtherDatas.Select(x => { x.Diid = groupId; x.CreateUserId = userId; return x; }).ToList();
  13418. var enterExitCostInfo = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).First();
  13419. //数据如果存在执行删除
  13420. if (enterExitCostInfo != null)
  13421. {
  13422. _sqlSugar.Updateable<Grp_EnterExitCost>()
  13423. .SetColumns(x => new Grp_EnterExitCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Remark = "由草稿数据导入前软删除数据!" })
  13424. .Where(x => x.Id == enterExitCostInfo.Id)
  13425. .ExecuteCommand();
  13426. _sqlSugar.Updateable<Grp_DayAndCost>()
  13427. .SetColumns(x => new Grp_DayAndCost() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13428. .Where(x => x.DiId == groupId)
  13429. .ExecuteCommand();
  13430. _sqlSugar.Updateable<Grp_DayOtherPrice>()
  13431. .SetColumns(x => new Grp_DayOtherPrice() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13432. .Where(x => x.Diid == groupId)
  13433. .ExecuteCommand();
  13434. _sqlSugar.Updateable<Grp_EnterExitCostPermission>()
  13435. .SetColumns(x => new Grp_EnterExitCostPermission() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  13436. .Where(x => x.GroupId == groupId)
  13437. .ExecuteCommand();
  13438. }
  13439. //执行insert
  13440. var insertId = _sqlSugar.Insertable(newExterData).ExecuteReturnIdentity();
  13441. if (insertId < 1)
  13442. {
  13443. _sqlSugar.RollbackTran();
  13444. return Ok(JsonView(false, "草稿数据导入失败!"));
  13445. }
  13446. if (newDayDatas.Any()) _sqlSugar.Insertable(newDayDatas).ExecuteCommand();
  13447. if (newOtherDatas.Any()) _sqlSugar.Insertable(newOtherDatas).ExecuteCommand();
  13448. #region 默认添加权限
  13449. #endregion
  13450. _sqlSugar.CommitTran();
  13451. //执行操作之后
  13452. //生成默认文件pdf并且通知人员
  13453. var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  13454. {
  13455. DiId = groupId,
  13456. ExportType = 1,
  13457. SubTypeId = 1005
  13458. }, "pdf");
  13459. //发送通知
  13460. string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  13461. string md5Sign = GeneralMethod.Encrypt($"{insertId}&fileName={fileUrl}");
  13462. string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", insertId, fileUrl);
  13463. await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(groupId, new List<string>() { "208", "233", "21" }, dto.UserId, url);
  13464. //汇率信息记录
  13465. await GeneralMethod.RateRecordSave(userId, insertId, "出入境费用-草稿导入");
  13466. return Ok(JsonView(true));
  13467. }
  13468. catch (Exception ex)
  13469. {
  13470. _sqlSugar.RollbackTran();
  13471. return Ok(JsonView(false, ex.Message));
  13472. }
  13473. }
  13474. #endregion
  13475. #region 团组经理模块 出入境费用 移动端(Android/IOS)
  13476. #region 城市区间交通费
  13477. /// <summary>
  13478. /// 团组模块 - 出入境费用 - 移动端 - 基础数据源(境外用车)
  13479. /// </summary>
  13480. /// <param name="groupId"></param>
  13481. /// <returns></returns>
  13482. [HttpGet("{groupId}")]
  13483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13484. public async Task<IActionResult> EnterExitCostMobileOVByGroupId(int groupId)
  13485. {
  13486. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13487. if (groupInfo == null)
  13488. {
  13489. return Ok(JsonView(false, "团组信息为空"));
  13490. }
  13491. var countryies = _groupRepository.GroupSplitCountry(groupInfo.VisitCountry);
  13492. if (countryies?.Any() != true)
  13493. {
  13494. return Ok(JsonView(false, "团组出访国家信息为空"));
  13495. }
  13496. var currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId);
  13497. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  13498. .Where(x => x.IsDel == 0 && x.STid == 66)
  13499. .ToListAsync();
  13500. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  13501. .Where(x => x.IsDel == 0 && countryies.Contains(x.CountryName))
  13502. .ToListAsync();
  13503. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  13504. //只返回接送机的数据
  13505. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13506. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  13507. .ToListAsync();
  13508. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  13509. var overseaVehicleCityDatas = new List<dynamic>() {
  13510. new
  13511. {
  13512. Id = 0,
  13513. area= "未选择",
  13514. CarTypeName = "",
  13515. serviceType = "",
  13516. Price = 0.00M,
  13517. guidePrice = 0.00M,
  13518. otherPrice = 0.00M,
  13519. currency = 0,
  13520. currencyName = "",
  13521. currRate = 1.0000M,
  13522. LastUpdateUserName = "",
  13523. LastUpdateTime = "",
  13524. Remark = ""
  13525. }};
  13526. foreach (var item in overseaVehicleTypes)
  13527. {
  13528. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  13529. string area = string.Empty,
  13530. serviceType = "未设置",
  13531. currencyName = string.Empty;
  13532. decimal otherPrice = 0.00M;
  13533. if (parentInfo != null)
  13534. {
  13535. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  13536. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  13537. serviceType = item.ServiceType.GetDescription();
  13538. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  13539. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  13540. }
  13541. //当前币种汇率值
  13542. var currRate = 1.0000M;
  13543. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  13544. if (currencyInfo != null) currRate = currencyInfo.Rate;
  13545. overseaVehicleCityDatas.add(new
  13546. {
  13547. item.Id,
  13548. area,
  13549. item.CarTypeName,
  13550. serviceType,
  13551. item.Price,
  13552. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  13553. otherPrice,
  13554. currency = parentInfo?.Currency ?? 0,
  13555. currencyName,
  13556. currRate,
  13557. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  13558. item.LastUpdateTime,
  13559. item.Remark
  13560. });
  13561. }
  13562. var total = overseaVehicleCityDatas.Count;
  13563. var view = new
  13564. {
  13565. visitCountries = string.Join("、", countryies),
  13566. groupSize = groupInfo.VisitPNumber, //出访人数
  13567. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  13568. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  13569. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  13570. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  13571. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  13572. Currencies = currencies,
  13573. data = overseaVehicleCityDatas
  13574. };
  13575. if (overseaVehicleCityDatas.Count == 0)
  13576. {
  13577. return Ok(JsonView(true, "暂无数据!", view));
  13578. }
  13579. return Ok(JsonView(true, "查询成功!", view, total));
  13580. }
  13581. /// <summary>
  13582. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算详细信息
  13583. /// </summary>
  13584. /// <param name="groupId"></param>
  13585. /// <param name="currUserId"></param>
  13586. /// <returns></returns>
  13587. [HttpGet("{groupId}")]
  13588. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13589. public async Task<IActionResult> EnterExitCostMobileOVFeeDetails(int groupId, int currUserId)
  13590. {
  13591. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  13592. if (groupInfo == null)
  13593. {
  13594. return Ok(JsonView(false, "团组信息为空"));
  13595. }
  13596. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  13597. //CityIntervalInfo
  13598. var info = new CityIntervalInfo();
  13599. if (eecInfo != null && !string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13600. {
  13601. info = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13602. return Ok(JsonView(true, "查询成功!", info));
  13603. }
  13604. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  13605. var userName = userInfo?.CnName ?? "-";
  13606. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13607. //返回默认数据
  13608. info = new CityIntervalInfo()
  13609. {
  13610. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  13611. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  13612. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  13613. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  13614. LastUpdateUserName = userName,
  13615. LastUpdateTime = nowTime,
  13616. CreateUserName = userName,
  13617. Currencies = await GeneralMethod.EnterExitCostOVFeeUsedCurrencyAsync(groupId),
  13618. CreateTime = nowTime
  13619. };
  13620. return Ok(JsonView(true, "查询成功!", info));
  13621. }
  13622. /// <summary>
  13623. /// 团组模块 - 出入境费用 - 移动端 - 境外用车计算 保存
  13624. /// </summary>
  13625. /// <param name="dto"></param>
  13626. /// <returns></returns>
  13627. [HttpPost]
  13628. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13629. public async Task<IActionResult> EnterExitCostMobileOVFeeSave(GetEnterExitCostOVFeeSaveDto dto)
  13630. {
  13631. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == dto.GroupId).FirstAsync();
  13632. if (groupInfo == null)
  13633. {
  13634. return Ok(JsonView(false, "团组信息为空"));
  13635. }
  13636. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  13637. if (userInfo == null)
  13638. {
  13639. return Ok(JsonView(false, "员工信息为空"));
  13640. }
  13641. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).FirstAsync();
  13642. if (eecInfo == null)
  13643. {
  13644. return Ok(JsonView(false, "出入境费用信息为空"));
  13645. }
  13646. var oldData = new CityIntervalInfo();
  13647. if (!string.IsNullOrEmpty(eecInfo.CityIntervalFeeDetails))
  13648. {
  13649. oldData = JsonConvert.DeserializeObject<CityIntervalInfo>(eecInfo.CityIntervalFeeDetails);
  13650. }
  13651. var userName = userInfo?.CnName ?? "-";
  13652. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  13653. var info = new CityIntervalInfo()
  13654. {
  13655. APTFeeTotal = dto.APTFeeTotal,
  13656. APTFeeDetails = dto.APTFeeDetails,
  13657. PullCartFeeTotal = dto.PullCartFeeTotal,
  13658. PullCartFeeDetails = dto.PullCartFeeDetails,
  13659. TrainFeeTotal = dto.TrainFeeTotal,
  13660. TrainFeeDetails = dto.TrainFeeDetails,
  13661. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  13662. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  13663. Currencies = dto.Currencies,
  13664. LastUpdateUserName = userName,
  13665. LastUpdateTime = nowTime,
  13666. CreateUserName = oldData?.CreateUserName ?? userName,
  13667. CreateTime = oldData?.CreateTime ?? nowTime
  13668. };
  13669. eecInfo.CityIntervalFeeDetails = JsonConvert.SerializeObject(info);
  13670. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  13671. .SetColumns(it => it.CityIntervalFeeDetails == eecInfo.CityIntervalFeeDetails)
  13672. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  13673. .SetColumns(it => it.LastUpdateTime == nowTime)
  13674. .Where(x => x.Id == eecInfo.Id)
  13675. .ExecuteCommandAsync();
  13676. if (upd < 1)
  13677. {
  13678. return Ok(JsonView(false));
  13679. }
  13680. //返回数据处理
  13681. var label = new StringBuilder();
  13682. //接送机
  13683. if (dto.APTFeeDetails?.Any() == true)
  13684. {
  13685. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  13686. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  13687. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  13688. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  13689. .Select((ovtp, ov) => new
  13690. {
  13691. ovtp.Id,
  13692. ov.CountryName,
  13693. ov.CityName
  13694. }).ToListAsync();
  13695. var items = dto.APTFeeDetails
  13696. .Select(item =>
  13697. {
  13698. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  13699. if (areaInfo == null) return null;
  13700. return areaInfo.CountryName == areaInfo.CityName
  13701. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  13702. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  13703. })
  13704. .Where(item => item != null)
  13705. .ToList();
  13706. label.AppendLine($"接送机({string.Join("、", items)});");
  13707. }
  13708. //拉车
  13709. if (dto.PullCartFeeDetails?.Any() == true)
  13710. {
  13711. var feeLabel = string.Join("、",
  13712. dto.PullCartFeeDetails.Select(x =>
  13713. $"{x.Quote:#0.00} CNY"
  13714. ));
  13715. label.AppendLine($"拉车({feeLabel});");
  13716. }
  13717. //火车
  13718. if (dto.TrainFeeDetails?.Any() == true)
  13719. {
  13720. var feeLabel = string.Join("、",
  13721. dto.TrainFeeDetails.Select(x =>
  13722. $"{x.Quote:#0.00} CNY"
  13723. ));
  13724. label.AppendLine($"火车票({feeLabel});");
  13725. }
  13726. //城市机票
  13727. if (dto.CityAirTicketFeeDetails?.Any() == true)
  13728. {
  13729. var feeLabel = string.Join("、",
  13730. dto.CityAirTicketFeeDetails.Select(x =>
  13731. $"{x.Quote:#0.00} CNY"
  13732. ));
  13733. label.AppendLine($"城市机票({feeLabel});");
  13734. }
  13735. //费用
  13736. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  13737. decimal jjcQuote = quote;
  13738. decimal gwcQuote = quote;
  13739. decimal tdcQuote = quote;
  13740. var view = new
  13741. {
  13742. label = label.ToString(),
  13743. jjcQuote,
  13744. gwcQuote,
  13745. tdcQuote
  13746. };
  13747. return Ok(JsonView(view));
  13748. }
  13749. #endregion
  13750. /// <summary>
  13751. /// 获取币种基础数据(含逻辑处理)
  13752. /// </summary>
  13753. /// <returns></returns>
  13754. private async Task<List<CurrencyInfo>> EnterExitCostMobileGetCurrencyInit()
  13755. {
  13756. return await GeneralMethod.EnterExitCostInitRate();
  13757. }
  13758. /// <summary>
  13759. /// 团组模块 - 出入境费用-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  13760. /// </summary>
  13761. /// <returns></returns>
  13762. [HttpPost]
  13763. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13764. public async Task<IActionResult> EnterExitCostMobileDataSource(EnterExitCostMobileDataSourceDto dto)
  13765. {
  13766. //验证城市归属并给默认值
  13767. int provinceId = dto.ProvinceId;
  13768. if (provinceId < 1) provinceId = 122;
  13769. var dataSource = await _sqlSugar
  13770. .Queryable<Sys_SetData>()
  13771. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  13772. .ToListAsync();
  13773. var fileTypes = new List<EecSetDataInfoView>();
  13774. //三公费用-Word明细类型
  13775. var wordTypeData = dataSource
  13776. .Where(it => it.STid == 72)
  13777. .Select(x => new EecSetDataInfoView
  13778. {
  13779. ParentId = 1,
  13780. Id = x.Id,
  13781. Name = x.Name
  13782. })
  13783. .ToArray();
  13784. if (wordTypeData.Any()) fileTypes.AddRange(wordTypeData);
  13785. var excelTypeData = dataSource
  13786. .Where(it => it.STid == 73)
  13787. .Select(x => new EecSetDataInfoView
  13788. {
  13789. ParentId = 2,
  13790. Id = x.Id,
  13791. Name = x.Name
  13792. })
  13793. .ToArray();
  13794. if (excelTypeData.Any()) fileTypes.AddRange(excelTypeData);
  13795. var groupNameList = new EecSetDataInfoView() { ParentId = 3, Id = 1, Name = "团组成员名单" };
  13796. fileTypes.Add(groupNameList);
  13797. fileTypes = fileTypes.OrderBy(x => x.ParentId).ThenBy(x => x.Id).ToList();
  13798. //默认币种显示
  13799. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  13800. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  13801. return Ok(JsonView(true, "查询成功!", new
  13802. {
  13803. FileTypeData = fileTypes,
  13804. CurrencyInit = _currencyInfos,
  13805. viewPermissionData = viewPermissionData
  13806. }));
  13807. }
  13808. /// <summary>
  13809. /// 团组模块 - 出入境费用-移动端 - 团组基础数据Data
  13810. /// </summary>
  13811. /// <returns></returns>
  13812. [HttpPost]
  13813. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13814. public async Task<IActionResult> EnterExitCostMobileGroupData(PostEnterExitCostMobileGroupDataDto dto)
  13815. {
  13816. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13817. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  13818. RefAsync<int> total = 0;
  13819. int diId = 0;
  13820. var status = int.TryParse(dto.GroupName, out diId);
  13821. var basicUserId = await _enterExitCostRep.PermissionViewUsersAsync();
  13822. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  13823. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  13824. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  13825. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  13826. .OrderByDescending(x => x.VisitStartDate)
  13827. .Select(x => new EnterExitCostMobileGroupView()
  13828. {
  13829. Id = x.Id,
  13830. GroupName = x.TeamName,
  13831. IsNull = SqlFunc.Subqueryable<Grp_EnterExitCost>().Where(x1 => x1.DiId == x.Id && x1.IsDel == 0).Any() ? false : true,
  13832. IsView = SqlFunc.Subqueryable<Grp_EnterExitCostPermission>().Where(x1 => x1.GroupId == x.Id && x1.UserId == dto.CurrUserId).Any(),
  13833. ProvinceId = x.CityId
  13834. })
  13835. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13836. //处理省份Id
  13837. if (data.Any())
  13838. {
  13839. var provCityDatas = await _groupRepository.ProvinceCityBasicSource();
  13840. if (provCityDatas.Any())
  13841. {
  13842. foreach (var item in data)
  13843. {
  13844. var provinceId = item.ProvinceId;
  13845. var isDefualtVal = true;
  13846. if (provinceId > 0)
  13847. {
  13848. var parentId = _groupRepository.FindParentIdByChildId(provCityDatas, provinceId);
  13849. if (parentId != null)
  13850. {
  13851. isDefualtVal = false;
  13852. item.ProvinceId = (int)parentId;
  13853. }
  13854. }
  13855. if (isDefualtVal)
  13856. {
  13857. item.ProvinceId = 122; //默认四川
  13858. }
  13859. }
  13860. }
  13861. }
  13862. //处理是否显示
  13863. if (basicUserId.Any(x => x.Id == dto.CurrUserId))
  13864. {
  13865. foreach (var item in data)
  13866. {
  13867. item.IsView = true;
  13868. }
  13869. }
  13870. return Ok(JsonView(true, "查询成功!", data, total));
  13871. }
  13872. /// <summary>
  13873. /// 团组模块 - 出入境费用-移动端 - 币种基础数据Data
  13874. /// </summary>
  13875. /// <returns></returns>
  13876. [HttpPost]
  13877. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13878. public async Task<IActionResult> EnterExitCostMobileCurrencyData(PostEnterExitCostMobileCurrencyDataDto dto)
  13879. {
  13880. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13881. RefAsync<int> total = 0;
  13882. var data = await _sqlSugar.Queryable<Sys_SetData>()
  13883. .Where(x => x.IsDel == 0 && x.STid == 66)
  13884. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  13885. .Select(x => new
  13886. {
  13887. id = x.Id,
  13888. name = x.Name,
  13889. remark = x.Remark,
  13890. })
  13891. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13892. return Ok(JsonView(true, "查询成功!", data, total));
  13893. }
  13894. /// <summary>
  13895. /// 团组模块 - 出入境费用-移动端 - 其他款项 - 币种、费用类型基础数据Data
  13896. /// </summary>
  13897. /// <returns></returns>
  13898. [HttpPost]
  13899. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13900. public async Task<IActionResult> EnterExitCostMobileOtherItemCurrencyData(PostEnterExitCostMobileOtherItemCurrencyDataDto dto)
  13901. {
  13902. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13903. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13904. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(dto.PortType, dto.DiId, 98);
  13905. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  13906. var groupOtherRateData = groupRateData.TeamRates;
  13907. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  13908. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  13909. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  13910. groupOtherRateData = groupOtherRateData
  13911. .Select(x => new TeamRateDescAddCurrencyIdView
  13912. {
  13913. CurrencyId = x.CurrencyId,
  13914. CurrencyName = x.CurrencyName,
  13915. CurrencyCode = x.CurrencyCode,
  13916. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  13917. }).ToList();
  13918. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  13919. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  13920. }
  13921. /// <summary>
  13922. /// 团组模块 - 出入境费用-移动端 - 实时汇率、签证费用、机票费用 Tips
  13923. /// </summary>
  13924. /// <returns></returns>
  13925. [HttpPost]
  13926. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13927. public async Task<IActionResult> EnterExitCostMobileFeeTips(GetEnterExitCostMobileFeeTipsDto dto)
  13928. {
  13929. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13930. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13931. var tipsData = new List<int>() { 1, 2, 3 };
  13932. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  13933. if (dto.TipsType == 1)
  13934. {
  13935. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  13936. }
  13937. else if (dto.TipsType == 2)
  13938. {
  13939. var visaData = await _visaFeeInfoRep.EnterExitCostVisaTips(dto.GroupId);
  13940. return Ok(JsonView(true, "查询成功!", visaData.Data));
  13941. }
  13942. else if (dto.TipsType == 3)
  13943. {
  13944. var airData = await GeneralMethod.EntryAndExitTips(dto.GroupId);
  13945. return Ok(JsonView(true, "查询成功!", airData));
  13946. }
  13947. return Ok(JsonView(false));
  13948. }
  13949. /// <summary>
  13950. /// 团组模块 - 出入境国家费用标准-移动端 List
  13951. /// </summary>
  13952. /// <returns></returns>
  13953. [HttpPost]
  13954. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13955. public async Task<IActionResult> NationalTravelFeeMobileData(PostNationalTravelFeeMobileDataDto dto)
  13956. {
  13957. Stopwatch sw = new Stopwatch();
  13958. sw.Start();
  13959. int provinceId = dto.ProvinceId;
  13960. if (provinceId < 1) provinceId = 122; // 默认四川
  13961. RefAsync<int> total = 0;
  13962. var data = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  13963. .LeftJoin<Sys_SetData>((ntf, sd) => ntf.Currency == sd.Id)
  13964. .LeftJoin<Sys_Users>((ntf, sd, u) => ntf.CreateUserId == u.Id)
  13965. .LeftJoin<Sys_Cities>((ntf, sd, u, sd1) => ntf.ProvinceId == sd1.Id)
  13966. .Where((ntf, sd, u, sd1) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
  13967. .WhereIF(!string.IsNullOrEmpty(dto.Search), (ntf, sd, u, sd1) => dto.Search.Contains(ntf.Country) || dto.Search.Contains(ntf.City))
  13968. .Select((ntf, sd, u, sd1) => new
  13969. {
  13970. Id = ntf.Id,
  13971. Area = $"{ntf.Country}-{ntf.City}",
  13972. Currency = ntf.Currency,
  13973. CurrencyCode = sd.Name,
  13974. CurrencyName = sd.Remark,
  13975. RoomCost = ntf.RoomCost,
  13976. FoodCost = ntf.FoodCost,
  13977. PublicCost = ntf.PublicCost,
  13978. TrainCost = ntf.TrainCost,
  13979. LastUpdateUserId = ntf.LastUpdateUserId,
  13980. LastUpdateUserName = u.CnName,
  13981. LastUpdateTime = ntf.LastUpdateTime
  13982. })
  13983. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  13984. sw.Stop();
  13985. return Ok(JsonView(true, "查询成功!耗时:" + sw.ElapsedMilliseconds + "ms", data, total));
  13986. }
  13987. /// <summary>
  13988. /// 团组模块 - 出入境费用-移动端 - Info
  13989. /// </summary>
  13990. /// <returns></returns>
  13991. [HttpPost]
  13992. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  13993. public async Task<IActionResult> EnterExitCostMobileInfo(EnterExitCostInfobyDiIdDto dto)
  13994. {
  13995. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  13996. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  13997. var data = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  13998. return Ok(data);
  13999. }
  14000. /// <summary>
  14001. /// 团组模块 - 出入境费用-移动端 - ParentInfo
  14002. /// </summary>
  14003. /// <returns></returns>
  14004. [HttpPost]
  14005. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14006. public async Task<IActionResult> EnterExitCostMobileParentInfo(EnterExitCostInfobyDiIdDto dto)
  14007. {
  14008. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14009. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14010. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14011. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  14012. var mobileInfo = new EnterExitCostMobileParentInfoView();
  14013. mobileInfo.DiId = dto.DiId;
  14014. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  14015. if (eecInfo == null) return Ok(mobileInfo);
  14016. //验证查看权限
  14017. (bool isView, bool isSet) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);
  14018. if (!isView) return Ok(JsonView(false, "没有查看权限!"));
  14019. mobileInfo = _mapper.Map<EnterExitCostMobileParentInfoView>(eecInfo);
  14020. mobileInfo.IsAssignPerm = isSet;
  14021. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCost>()
  14022. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14023. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14024. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  14025. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14026. {
  14027. SubId = dac.Id,
  14028. DiId = dac.DiId,
  14029. Type = dac.Type,
  14030. Days = dac.Days,
  14031. NationalTravelFeeId = dac.NationalTravelFeeId,
  14032. Arae = $"{ntf.Country}-{ntf.City}",
  14033. Cost = dac.Cost,
  14034. Currency = dac.Currency,
  14035. CurrencyName = sd.Name,
  14036. SubTotal = dac.SubTotal,
  14037. })
  14038. .ToList();
  14039. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  14040. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  14041. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  14042. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  14043. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  14044. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  14045. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  14046. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  14047. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  14048. //其他款项
  14049. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14050. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  14051. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  14052. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  14053. .OrderBy((dop, sd1, sd2) => dop.Index)
  14054. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  14055. {
  14056. SubId = dop.Id,
  14057. DiId = dop.Diid,
  14058. Index = dop.Index,
  14059. SetDataId = dop.SetDataId,
  14060. SetDataName = sd1.Name,
  14061. Cost = dop.Cost,
  14062. Currency = dop.Currency,
  14063. CurrencyName = sd2.Remark,
  14064. SubTotal = dop.SubTotal,
  14065. Remark = dop.Remark,
  14066. })
  14067. .ToArray();
  14068. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  14069. return Ok(mobileInfo);
  14070. }
  14071. /// <summary>
  14072. /// 团组模块 - 出入境费用-移动端 - 查看权限用户
  14073. /// </summary>
  14074. /// <returns></returns>
  14075. [HttpPost]
  14076. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14077. public async Task<IActionResult> EnterExitCostMobileViewPermissionUsers(EnterExitCostMobileViewPermissionUsersDto dto)
  14078. {
  14079. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14080. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14081. //验证查看权限
  14082. (bool viewPerm, bool assignPerm) = await _enterExitCostRep.PermissionValidationAsync(dto.DiId, dto.CurrUserId);//分配权限
  14083. if (!viewPerm) return Ok(JsonView(false, "未分配查看权限,如要查看,请联系市场部或国交部负责人!"));
  14084. var userIds = await _sqlSugar
  14085. .Queryable<Grp_EnterExitCostPermission>()
  14086. .Where(x => x.IsDel == 0 && x.GroupId == dto.DiId)
  14087. .Select(x => x.UserId)
  14088. .ToArrayAsync();
  14089. var perUsers = await _enterExitCostRep.PermissionViewUsersAsync();
  14090. var perUsersView = new List<dynamic>();
  14091. foreach (var item in perUsers)
  14092. {
  14093. bool isView1 = false;
  14094. if (userIds.Any(x => x == item.Id)) isView1 = true;
  14095. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  14096. }
  14097. return Ok(JsonView(perUsersView));
  14098. }
  14099. /// <summary>
  14100. /// 团组模块 - 出入境费用-移动端 - SubInfo
  14101. /// </summary>
  14102. /// <returns></returns>
  14103. [HttpPost]
  14104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14105. public async Task<IActionResult> EnterExitCostMobileSubInfo(PostEnterExitCostMobileSubInfoDto dto)
  14106. {
  14107. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14108. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14109. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14110. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  14111. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  14112. //验证查看权限
  14113. //(bool isView, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId);
  14114. //if (!isView) return Ok(JsonView(false, msg));
  14115. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DiId == dto.DiId && it.IsDel == 0);
  14116. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  14117. var subType = dto.SubType;
  14118. if (subType == 1) //1:境内费用
  14119. {
  14120. var oneData = new ChoiceOneMobileSubInfoView()
  14121. {
  14122. Id = eecInfo.Id,
  14123. ChoiceOne = eecInfo.ChoiceOne,
  14124. ChoiceOneTotalCost = eecInfo.InsidePay,
  14125. Visa = eecInfo.Visa,
  14126. VisaRemark = eecInfo.VisaRemark,
  14127. YiMiao = eecInfo.YiMiao,
  14128. HeSuan = eecInfo.HeSuan,
  14129. Service = eecInfo.Service,
  14130. Ticket = eecInfo.Ticket,
  14131. Safe = eecInfo.Safe,
  14132. FirstItemRemark = eecInfo.FirstItemRemark
  14133. };
  14134. return Ok(JsonView(oneData));
  14135. }
  14136. else if (subType == 2) //2:国际旅费
  14137. {
  14138. var twoData = new ChoiceTwoMobileSubInfoView()
  14139. {
  14140. Id = eecInfo.Id,
  14141. ChoiceTwoJJ = eecInfo.SumJJC,
  14142. OutsideJJPay = eecInfo.OutsideJJPay,
  14143. ChoiceTwoGW = eecInfo.SumGWC,
  14144. OutsideGWPay = eecInfo.OutsideGWPay,
  14145. ChoiceTwoTD = eecInfo.SumTDC,
  14146. OutsideTDPay = eecInfo.OutsideTDPay,
  14147. AirJJ = eecInfo.AirJJ,
  14148. AirGW = eecInfo.AirGW,
  14149. AirTD = eecInfo.AirTD,
  14150. CityTranffic = eecInfo.CityTranffic,
  14151. CityTranffic1 = eecInfo.CityTranffic1,
  14152. CityTranffic2 = eecInfo.CityTranffic2,
  14153. TwoItemRemark = eecInfo.TwoItemRemark
  14154. };
  14155. return Ok(JsonView(twoData));
  14156. }
  14157. else if (subType == 3) //3:住宿费
  14158. {
  14159. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14160. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14161. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14162. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 1)
  14163. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14164. {
  14165. SubId = dac.Id,
  14166. DiId = dac.DiId,
  14167. Type = dac.Type,
  14168. Days = dac.Days,
  14169. NationalTravelFeeId = dac.NationalTravelFeeId,
  14170. Arae = $"{ntf.Country}-{ntf.City}",
  14171. Cost = dac.Cost,
  14172. Currency = dac.Currency,
  14173. CurrencyName = sd.Name,
  14174. SubTotal = dac.SubTotal,
  14175. })
  14176. .ToArray();
  14177. var data = new ChoiceMobileSubInfo3To6View()
  14178. {
  14179. ParentId = eecInfo.Id,
  14180. Choice = eecInfo.ChoiceThree,
  14181. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14182. Details = dayAndCostDatas
  14183. };
  14184. return Ok(JsonView(data));
  14185. }
  14186. else if (subType == 4) //4:伙食费
  14187. {
  14188. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14189. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14190. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14191. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 2)
  14192. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14193. {
  14194. SubId = dac.Id,
  14195. DiId = dac.DiId,
  14196. Type = dac.Type,
  14197. Days = dac.Days,
  14198. NationalTravelFeeId = dac.NationalTravelFeeId,
  14199. Arae = $"{ntf.Country}-{ntf.City}",
  14200. Cost = dac.Cost,
  14201. Currency = dac.Currency,
  14202. CurrencyName = sd.Name,
  14203. SubTotal = dac.SubTotal,
  14204. })
  14205. .ToArray();
  14206. var data = new ChoiceMobileSubInfo3To6View()
  14207. {
  14208. ParentId = eecInfo.Id,
  14209. Choice = eecInfo.ChoiceFour,
  14210. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14211. Details = dayAndCostDatas
  14212. };
  14213. return Ok(JsonView(data));
  14214. }
  14215. else if (subType == 5) //5:公杂费
  14216. {
  14217. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14218. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14219. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14220. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 3)
  14221. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14222. {
  14223. SubId = dac.Id,
  14224. DiId = dac.DiId,
  14225. Type = dac.Type,
  14226. Days = dac.Days,
  14227. NationalTravelFeeId = dac.NationalTravelFeeId,
  14228. Arae = $"{ntf.Country}-{ntf.City}",
  14229. Cost = dac.Cost,
  14230. Currency = dac.Currency,
  14231. CurrencyName = sd.Name,
  14232. SubTotal = dac.SubTotal,
  14233. })
  14234. .ToArray();
  14235. var data = new ChoiceMobileSubInfo3To6View()
  14236. {
  14237. ParentId = eecInfo.Id,
  14238. Choice = eecInfo.ChoiceFive,
  14239. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14240. Details = dayAndCostDatas
  14241. };
  14242. return Ok(JsonView(data));
  14243. }
  14244. else if (subType == 6) //6:培训费
  14245. {
  14246. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCost>()
  14247. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  14248. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  14249. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId && dac.Type == 4)
  14250. .Select((dac, ntf, sd) => new DayAndCostMobileInfoView
  14251. {
  14252. SubId = dac.Id,
  14253. DiId = dac.DiId,
  14254. Type = dac.Type,
  14255. Days = dac.Days,
  14256. NationalTravelFeeId = dac.NationalTravelFeeId,
  14257. Arae = $"{ntf.Country}-{ntf.City}",
  14258. Cost = dac.Cost,
  14259. Currency = dac.Currency,
  14260. CurrencyName = sd.Name,
  14261. SubTotal = dac.SubTotal,
  14262. })
  14263. .ToArray();
  14264. var data = new ChoiceMobileSubInfo3To6View()
  14265. {
  14266. ParentId = eecInfo.Id,
  14267. Choice = eecInfo.ChoiceSix,
  14268. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  14269. Details = dayAndCostDatas
  14270. };
  14271. return Ok(JsonView(data));
  14272. }
  14273. else if (subType == 7) //7:其他
  14274. {
  14275. //其他款项
  14276. var otherData = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14277. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  14278. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  14279. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  14280. .OrderBy((dop, sd1, sd2) => dop.Index)
  14281. .Select((dop, sd1, sd2) => new DayOtherPriceMobileInfoView
  14282. {
  14283. SubId = dop.Id,
  14284. DiId = dop.Diid,
  14285. Index = dop.Index,
  14286. SetDataId = dop.SetDataId,
  14287. SetDataName = sd1.Name,
  14288. Cost = dop.Cost,
  14289. Currency = dop.Currency,
  14290. CurrencyName = sd2.Name,
  14291. SubTotal = dop.SubTotal,
  14292. Remark = dop.Remark,
  14293. })
  14294. .ToArray();
  14295. var data = new ChoiceSevenMobileSubInfoView()
  14296. {
  14297. ParentId = eecInfo.Id,
  14298. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  14299. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  14300. Details = otherData
  14301. };
  14302. return Ok(JsonView(data));
  14303. }
  14304. return Ok(JsonView(false));
  14305. }
  14306. #region op
  14307. ///// <summary>
  14308. ///// 移动端更新费用消息通知
  14309. ///// </summary>
  14310. ///// <param name="diid"></param>
  14311. ///// <param name="id"></param>
  14312. ///// <param name="currUserId"></param>
  14313. //private async Task EnterExitCostMobileOpNotice(int diid, int id, int currUserId)
  14314. //{
  14315. // try
  14316. // {
  14317. // ////生成默认文件pdf并且通知人员
  14318. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  14319. // //{
  14320. // // DiId = diid,
  14321. // // ExportType = 1,
  14322. // // SubTypeId = 1005
  14323. // //}, "pdf");
  14324. // ////发送通知
  14325. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  14326. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  14327. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  14328. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(diid, new List<string>() { "208", "233", "21" }, currUserId, url);
  14329. // ////汇率信息记录
  14330. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  14331. // }
  14332. // catch (Exception ex)
  14333. // {
  14334. // //记录日志
  14335. // throw;
  14336. // }
  14337. //}
  14338. /// <summary>
  14339. /// 验证出入境费用数据是否存在
  14340. /// 不存在添加
  14341. /// </summary>
  14342. /// <param name="diId"></param>
  14343. /// <param name="currUserId"></param>
  14344. /// <returns></returns>
  14345. private async Task<int> EnterExitCostVerifyIsNull(int diId, int currUserId)
  14346. {
  14347. var parentId = 0;
  14348. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == diId).OrderByDescending(x => x.CreateTime).FirstAsync();
  14349. if (info != null)
  14350. {
  14351. parentId = info.Id;
  14352. }
  14353. else
  14354. {
  14355. var currencys = await EnterExitCostMobileGetCurrencyInit();
  14356. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCost() { DiId = diId, CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  14357. parentId = addId;
  14358. }
  14359. return parentId;
  14360. }
  14361. /// <summary>
  14362. /// 团组模块 - 出入境费用-移动端 - 设置view权限
  14363. /// </summary>
  14364. /// <returns></returns>
  14365. [HttpPost]
  14366. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14367. public async Task<IActionResult> EnterExitCostMobileSetViewPermissiion(EnterExitCostMobileSetViewPermissiionDto dto)
  14368. {
  14369. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14370. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14371. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  14372. //验证编辑权限
  14373. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14374. //if (!isEdit) return Ok(JsonView(false, msg));
  14375. var permissions = new List<Grp_EnterExitCostPermission>();
  14376. foreach (var userId in dto.UserIds)
  14377. {
  14378. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = userId, CreateUserId = dto.CurrUserId });
  14379. }
  14380. if (permissions.Any())
  14381. {
  14382. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  14383. {
  14384. permissions.Add(new Grp_EnterExitCostPermission { Permission = 1, GroupId = dto.DiId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  14385. }
  14386. _sqlSugar.BeginTran();
  14387. await _sqlSugar.Deleteable<Grp_EnterExitCostPermission>().Where(it => it.GroupId == dto.DiId).ExecuteCommandAsync();
  14388. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  14389. if (result < 1)
  14390. {
  14391. _sqlSugar.RollbackTran();
  14392. return Ok(JsonView(false));
  14393. }
  14394. _sqlSugar.CommitTran();
  14395. return Ok(JsonView(true));
  14396. }
  14397. return Ok(JsonView(false));
  14398. }
  14399. /// <summary>
  14400. /// 团组模块 - 出入境费用-移动端 - OP --> 汇率
  14401. /// </summary>
  14402. /// <returns></returns>
  14403. [HttpPost]
  14404. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14405. public async Task<IActionResult> EnterExitCostMobileOpRate(PostEnterExitCostMobileFeeRateOpDto dto)
  14406. {
  14407. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14408. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14409. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14410. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  14411. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  14412. int id = dto.Id;
  14413. if (id <= 0) //add
  14414. {
  14415. //int provinceId = dto.ProvinceId;
  14416. int groupId = dto.DiId;
  14417. //if (provinceId < 1) provinceId = 122;
  14418. var info = new Grp_EnterExitCost() { DiId = groupId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId };
  14419. info.LastUpdateUserId = dto.CurrUserId;
  14420. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14421. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  14422. if (add < 1) return Ok(JsonView(false));
  14423. id = add;
  14424. }
  14425. else //update
  14426. {
  14427. ////验证编辑权限
  14428. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14429. //if (!isEdit) return Ok(JsonView(false, msg));
  14430. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>().SetColumns(x => new Grp_EnterExitCost()
  14431. {
  14432. CurrencyRemark = currencyStr,
  14433. LastUpdateUserId = dto.CurrUserId,
  14434. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  14435. }).Where(x => x.Id == dto.Id).ExecuteCommandAsync();
  14436. if (upd < 1) return Ok(JsonView(false));
  14437. }
  14438. #region 汇率变更时更改币种相关费用
  14439. var opDayCosts = new List<Grp_DayAndCost>();
  14440. var opDayOtherCosts = new List<Grp_DayOtherPrice>();
  14441. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  14442. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCost>()
  14443. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  14444. .Where((dac, sd) => dac.IsDel == 0 && dac.DiId == dto.DiId)
  14445. .Select((dac, sd) => new
  14446. {
  14447. dac.Id,
  14448. dac.DiId,
  14449. CurrencyCode = sd.Name,
  14450. dac.Cost
  14451. })
  14452. .ToList();
  14453. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPrice>()
  14454. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  14455. .Where((dop, sd) => dop.IsDel == 0 && dop.Diid == dto.DiId)
  14456. .Select((dop, sd) => new
  14457. {
  14458. dop.Id,
  14459. dop.Diid,
  14460. CurrencyCode = sd.Name,
  14461. dop.Cost
  14462. })
  14463. .ToList();
  14464. if (dayCosts.Count > 0)
  14465. {
  14466. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  14467. foreach (var dc in new_dayCosts)
  14468. {
  14469. var thisCurrency = dc.Key.ToUpper();
  14470. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  14471. if (thisRate == 0.00M) continue;
  14472. foreach (var dcSub in dc)
  14473. {
  14474. opDayCosts.Add(new Grp_DayAndCost()
  14475. {
  14476. Id = dcSub.Id,
  14477. DiId = dcSub.DiId,
  14478. Cost = dcSub.Cost,
  14479. SubTotal = dcSub.Cost * thisRate,
  14480. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  14481. });
  14482. }
  14483. }
  14484. if (opDayCosts.Count > 0)
  14485. {
  14486. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  14487. }
  14488. }
  14489. if (dayOtherCosts.Count > 0)
  14490. {
  14491. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  14492. foreach (var dc in new_dayOtherCosts)
  14493. {
  14494. var thisCurrency = dc.Key.ToUpper();
  14495. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  14496. if (thisRate == 0.00M) continue;
  14497. foreach (var dcSub in dc)
  14498. {
  14499. opDayOtherCosts.Add(new Grp_DayOtherPrice()
  14500. {
  14501. Id = dcSub.Id,
  14502. Diid = dcSub.Diid,
  14503. Cost = dcSub.Cost,
  14504. SubTotal = dcSub.Cost * thisRate,
  14505. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  14506. });
  14507. }
  14508. }
  14509. if (opDayOtherCosts.Count > 0)
  14510. {
  14511. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  14512. }
  14513. }
  14514. #endregion
  14515. //消息通知
  14516. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14517. //汇率信息记录
  14518. await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  14519. return Ok(JsonView(new { parentId = id }));
  14520. }
  14521. /// <summary>
  14522. /// 团组模块 - 出入境费用-移动端 - OP --> 复选框
  14523. /// </summary>
  14524. /// <returns></returns>
  14525. [HttpPost]
  14526. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14527. public async Task<IActionResult> EnterExitCostMobileOpCheckbox(PostEnterExitCostMobileFeeOpCheckboxDto dto)
  14528. {
  14529. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14530. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14531. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14532. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14533. var checkboxInfo = _mapper.Map<Grp_EnterExitCost>(dto);
  14534. checkboxInfo.LastUpdateUserId = dto.CurrUserId;
  14535. checkboxInfo.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14536. int id = dto.Id;
  14537. if (id <= 0) //add
  14538. {
  14539. checkboxInfo.CreateUserId = dto.CurrUserId;
  14540. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14541. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  14542. if (add < 1) return Ok(JsonView(false));
  14543. }
  14544. else //update
  14545. {
  14546. ////验证编辑权限
  14547. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14548. //if (!isEdit) return Ok(JsonView(false, msg));
  14549. var upd = await _sqlSugar.Updateable(checkboxInfo)
  14550. .UpdateColumns(x => new
  14551. {
  14552. x.ChoiceOne,
  14553. x.ChoiceTwo,
  14554. x.SumJJC,
  14555. x.SumGWC,
  14556. x.SumTDC,
  14557. x.ChoiceThree,
  14558. x.ChoiceFour,
  14559. x.ChoiceFive,
  14560. x.ChoiceSix,
  14561. x.OtherExpenses_Checked
  14562. })
  14563. .Where(x => x.Id == id)
  14564. .ExecuteCommandAsync();
  14565. if (upd < 1) return Ok(JsonView(false));
  14566. }
  14567. return Ok(JsonView(new { parentId = id }));
  14568. }
  14569. /// <summary>
  14570. /// 团组模块 - 出入境费用-移动端 - OP --> 3-7项复选框单个复选框更改
  14571. /// </summary>
  14572. /// <returns></returns>
  14573. [HttpPost]
  14574. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14575. public async Task<IActionResult> EnterExitCostMobileOpSingleCheckbox(EnterExitCostMobileOpSingleCheckboxDto dto)
  14576. {
  14577. int itemTypeId = dto.ItemType, id = dto.Id, currUserId = dto.CurrUserId, diId = dto.DiId, isSelected = dto.IsSelected;
  14578. // if (provinceId < 1) provinceId = 122;
  14579. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  14580. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14581. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14582. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14583. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  14584. var checkboxInfo = new Grp_EnterExitCost()
  14585. {
  14586. Id = id,
  14587. //ProvinceId = provinceId,
  14588. DiId = diId,
  14589. CreateUserId = currUserId,
  14590. LastUpdateUserId = dto.CurrUserId,
  14591. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  14592. };
  14593. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  14594. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  14595. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  14596. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  14597. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  14598. if (id <= 0) //add
  14599. {
  14600. checkboxInfo.CreateUserId = dto.CurrUserId;
  14601. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14602. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  14603. if (add < 1) return Ok(JsonView(false));
  14604. }
  14605. else //update
  14606. {
  14607. ////验证编辑权限
  14608. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14609. //if (!isEdit) return Ok(JsonView(false, msg));
  14610. var upd = await _sqlSugar.Updateable<Grp_EnterExitCost>()
  14611. .SetColumns(it => it.LastUpdateUserId == dto.CurrUserId)
  14612. .SetColumns(it => it.LastUpdateTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  14613. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  14614. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  14615. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  14616. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  14617. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  14618. .Where(x => x.Id == id)
  14619. .ExecuteCommandAsync();
  14620. if (upd < 1) return Ok(JsonView(false));
  14621. }
  14622. return Ok(JsonView(new { parentId = id }));
  14623. }
  14624. /// <summary>
  14625. /// 团组模块 - 出入境费用-移动端 - OP --> 境内费用 Step1
  14626. /// </summary>
  14627. /// <returns></returns>
  14628. [HttpPost]
  14629. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14630. public async Task<IActionResult> EnterExitCostMobileOpStep1(PostEnterExitCostMobileOpStep1Dto dto)
  14631. {
  14632. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14633. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14634. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14635. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14636. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  14637. info.FirstItemRemark = dto.FirstItemRemark;
  14638. info.LastUpdateUserId = dto.CurrUserId;
  14639. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14640. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  14641. int id = dto.Id;
  14642. if (id <= 0) //add
  14643. {
  14644. info.CreateUserId = dto.CurrUserId;
  14645. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14646. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  14647. if (add < 1) return Ok(JsonView(false));
  14648. id = add;
  14649. }
  14650. else //update
  14651. {
  14652. ////验证编辑权限
  14653. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14654. //if (!isEdit) return Ok(JsonView(false, msg));
  14655. var upd = await _sqlSugar.Updateable(info)
  14656. .UpdateColumns(x => new
  14657. {
  14658. x.ChoiceOne,
  14659. x.InsidePay,
  14660. x.VisaRemark,
  14661. x.Visa,
  14662. x.Service,
  14663. x.Safe,
  14664. x.Ticket,
  14665. x.HeSuan,
  14666. x.YiMiao,
  14667. x.FirstItemRemark,
  14668. x.LastUpdateUserId,
  14669. x.LastUpdateTime
  14670. })
  14671. .Where(x => x.Id == id)
  14672. .ExecuteCommandAsync();
  14673. if (upd < 1) return Ok(JsonView(false));
  14674. }
  14675. //消息通知
  14676. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14677. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  14678. }
  14679. /// <summary>
  14680. /// 团组模块 - 出入境费用-移动端 - OP --> 国际旅费 Step2
  14681. /// </summary>
  14682. /// <returns></returns>
  14683. [HttpPost]
  14684. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14685. public async Task<IActionResult> EnterExitCostMobileOpStep2(PostEnterExitCostMobileOpStep2Dto dto)
  14686. {
  14687. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14688. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14689. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14690. //if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  14691. var info = _mapper.Map<Grp_EnterExitCost>(dto);
  14692. info.DiId = dto.DiId;
  14693. //info.ProvinceId = dto.ProvinceId;
  14694. info.OutsideJJPay = dto.OutsideJJPay;
  14695. info.OutsideGWPay = dto.OutsideGWPay;
  14696. info.OutsideTDPay = dto.OutsideTDPay;
  14697. info.AirJJ = dto.AirJJ;
  14698. info.AirGW = dto.AirGW;
  14699. info.AirTD = dto.AirTD;
  14700. info.CityTranffic = dto.CityTranffic;
  14701. info.CityTranffic1 = dto.CityTranffic1;
  14702. info.CityTranffic2 = dto.CityTranffic2;
  14703. info.TwoItemRemark = dto.TwoItemRemark;
  14704. info.SumJJC = dto.ChoiceTwoJJ;
  14705. info.SumGWC = dto.ChoiceTwoGW;
  14706. info.SumTDC = dto.ChoiceTwoTD;
  14707. info.LastUpdateUserId = dto.CurrUserId;
  14708. info.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  14709. int id = dto.Id;
  14710. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  14711. if (id <= 0) //add i
  14712. {
  14713. info.CreateUserId = dto.CurrUserId;
  14714. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  14715. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  14716. if (addId <= 0) return Ok(JsonView(false));
  14717. id = addId;
  14718. }
  14719. else //update
  14720. {
  14721. ////验证编辑权限
  14722. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14723. //if (!isEdit) return Ok(JsonView(false, msg));
  14724. var upd = await _sqlSugar.Updateable(info)
  14725. .UpdateColumns(x => new
  14726. {
  14727. x.SumJJC,
  14728. x.OutsideJJPay,
  14729. x.SumGWC,
  14730. x.OutsideGWPay,
  14731. x.SumTDC,
  14732. x.OutsideTDPay,
  14733. x.AirJJ,
  14734. x.AirGW,
  14735. x.AirTD,
  14736. x.CityTranffic,
  14737. x.CityTranffic1,
  14738. x.CityTranffic2,
  14739. x.TwoItemRemark,
  14740. x.LastUpdateTime,
  14741. x.LastUpdateUserId
  14742. })
  14743. .Where(x => x.Id == id)
  14744. .ExecuteCommandAsync();
  14745. if (upd < 1) return Ok(JsonView(false));
  14746. }
  14747. jjcItemTotal = info.AirJJ + info.CityTranffic;
  14748. gwcItemTotal = info.AirGW + info.CityTranffic1;
  14749. tdcItemTotal = info.AirTD + info.CityTranffic2;
  14750. //消息通知
  14751. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14752. return Ok(JsonView(new
  14753. {
  14754. parentId = id,
  14755. choiceTwoJJ = dto.ChoiceTwoJJ,
  14756. jjcItemTotal = jjcItemTotal,
  14757. choiceTwoGW = dto.ChoiceTwoGW,
  14758. gwcItemTotal = gwcItemTotal,
  14759. choiceTwoTD = dto.ChoiceTwoTD,
  14760. tdcItemTotal = tdcItemTotal
  14761. }));
  14762. }
  14763. /// <summary>
  14764. /// 团组模块 - 出入境费用-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  14765. /// </summary>
  14766. /// <returns></returns>
  14767. [HttpPost]
  14768. [ApiExplorerSettings(IgnoreApi = true)]
  14769. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14770. public async Task<IActionResult> EnterExitCostMobileOpBatchStep3To6(PostEnterExitCostMobileOpStep3To6Dto dto)
  14771. {
  14772. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14773. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14774. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14775. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  14776. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  14777. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  14778. var infos1 = _mapper.Map<List<Grp_DayAndCost>>(dto.Infos);
  14779. var infos = infos1.Select(x => new Grp_DayAndCost
  14780. {
  14781. Id = x.Id,
  14782. DiId = dto.DiId,
  14783. Type = dto.FeeType,
  14784. Days = x.Days,
  14785. NationalTravelFeeId = x.NationalTravelFeeId,
  14786. Cost = x.Cost,
  14787. Currency = x.Currency,
  14788. SubTotal = x.SubTotal,
  14789. CreateUserId = dto.CurrUserId
  14790. })
  14791. .ToList();
  14792. var adds = infos.Where(x => x.Id <= 0).ToList();
  14793. var upds = infos.Where(x => x.Id > 0).ToList();
  14794. if (adds.Count > 0)
  14795. {
  14796. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  14797. if (add < 1) return Ok(JsonView(false));
  14798. }
  14799. if (upds.Count > 0)
  14800. {
  14801. var upd = await _sqlSugar.Updateable(adds)
  14802. .UpdateColumns(x => new
  14803. {
  14804. x.Days,
  14805. x.NationalTravelFeeId,
  14806. x.Cost,
  14807. x.Currency,
  14808. x.SubTotal
  14809. })
  14810. .WhereColumns(x => new { x.Id })
  14811. .ExecuteCommandAsync();
  14812. if (upd < 1) return Ok(JsonView(false));
  14813. }
  14814. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  14815. //消息通知
  14816. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  14817. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14818. return Ok(JsonView(new { itemTotal = itemTotal }));
  14819. }
  14820. /// <summary>
  14821. /// 团组模块 - 出入境费用-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  14822. /// </summary>
  14823. /// <returns></returns>
  14824. [HttpPost]
  14825. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14826. public async Task<IActionResult> EnterExitCostMobileOpSingleStep3To6(PostEnterExitCostMobileOpSingleStep3To6Dto dto)
  14827. {
  14828. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  14829. int subId = dto.SubId, feeType = dto.FeeType;
  14830. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14831. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14832. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14833. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  14834. var subInfo = _mapper.Map<Grp_DayAndCost>(dto);
  14835. subInfo.Id = subId;
  14836. subInfo.DiId = dto.DiId;
  14837. if (feeType == 3) subInfo.Type = 1;
  14838. else if (feeType == 4) subInfo.Type = 2;
  14839. else if (feeType == 5) subInfo.Type = 3;
  14840. else if (feeType == 6) subInfo.Type = 4;
  14841. subInfo.CreateUserId = dto.CurrUserId;
  14842. int parentId = await EnterExitCostVerifyIsNull(dto.DiId, dto.CurrUserId); //主表验证
  14843. if (parentId < 1) return Ok(JsonView(false));
  14844. //子表op
  14845. if (subId < 1)
  14846. {
  14847. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  14848. if (subAdd < 1) return Ok(JsonView(false));
  14849. }
  14850. else
  14851. {
  14852. ////验证编辑权限
  14853. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.DiId, dto.CurrUserId, 2);
  14854. //if (!isEdit) return Ok(JsonView(false, msg));
  14855. var subUpd = await _sqlSugar.Updateable(subInfo)
  14856. .UpdateColumns(x => new
  14857. {
  14858. x.Days,
  14859. x.NationalTravelFeeId,
  14860. x.Cost,
  14861. x.Currency,
  14862. x.SubTotal
  14863. })
  14864. .WhereColumns(x => new { x.Id })
  14865. .ExecuteCommandAsync();
  14866. if (subUpd < 1) return Ok(JsonView(false));
  14867. }
  14868. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Type == feeType).Sum(x => x.SubTotal);
  14869. //await EnterExitCostMobileOpNotice(dto.DiId, parentId, dto.CurrUserId);
  14870. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  14871. }
  14872. /// <summary>
  14873. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-批量 Step7
  14874. /// </summary>
  14875. /// <returns></returns>
  14876. [HttpPost]
  14877. [ApiExplorerSettings(IgnoreApi = true)]
  14878. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14879. public async Task<IActionResult> EnterExitCostMobileOpBatchStep7(PostEnterExitCostMobileOpStep7Dto dto)
  14880. {
  14881. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14882. if (dto.DiId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14883. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14884. var infos1 = _mapper.Map<List<Grp_DayOtherPrice>>(dto.Infos);
  14885. var infos = infos1.Select(x => new Grp_DayOtherPrice()
  14886. {
  14887. Id = x.Id,
  14888. Diid = dto.DiId,
  14889. SetDataId = x.SetDataId,
  14890. Index = x.Index,
  14891. Cost = x.Cost,
  14892. Currency = x.Currency,
  14893. SubTotal = x.SubTotal,
  14894. CreateUserId = dto.CurrUserId,
  14895. Remark = x.Remark
  14896. }).ToList();
  14897. var adds = infos.Where(x => x.Id <= 0).ToList();
  14898. var upds = infos.Where(x => x.Id > 0).ToList();
  14899. if (adds.Count > 0)
  14900. {
  14901. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  14902. if (add < 1) return Ok(JsonView(false));
  14903. }
  14904. if (upds.Count > 0)
  14905. {
  14906. var upd = await _sqlSugar.Updateable(adds)
  14907. .UpdateColumns(x => new
  14908. {
  14909. x.Index,
  14910. x.SetDataId,
  14911. x.Cost,
  14912. x.Currency,
  14913. x.SubTotal,
  14914. x.Remark
  14915. })
  14916. .WhereColumns(x => new { x.Id })
  14917. .ExecuteCommandAsync();
  14918. if (upd < 1) return Ok(JsonView(false));
  14919. }
  14920. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == dto.DiId).Sum(x => x.SubTotal);
  14921. //消息通知
  14922. var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == dto.DiId).First()?.Id ?? 0;
  14923. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  14924. return Ok(JsonView(new { itemTotal = itemTotal }));
  14925. }
  14926. /// <summary>
  14927. /// 团组模块 - 出入境费用-移动端 - OP --> 其他费用-单条 Step7
  14928. /// </summary>
  14929. /// <returns></returns>
  14930. [HttpPost]
  14931. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14932. public async Task<IActionResult> EnterExitCostMobileOpSingleStep7(PostEnterExitCostMobileOpSingleStep7Dto dto)
  14933. {
  14934. int subId = dto.SubId;
  14935. int diId = dto.Diid;
  14936. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  14937. if (diId < 1) return Ok(JsonView(false, MsgTips.DiId));
  14938. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  14939. var subInfo = _mapper.Map<Grp_DayOtherPrice>(dto);
  14940. subInfo.Id = subId;
  14941. subInfo.Diid = dto.Diid;
  14942. subInfo.CreateUserId = dto.CurrUserId;
  14943. int parentId = await EnterExitCostVerifyIsNull(diId, dto.CurrUserId); //主表验证
  14944. if (parentId < 1) return Ok(JsonView(false));
  14945. #region 子表op
  14946. if (subId < 1)//add
  14947. {
  14948. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  14949. if (subAdd < 1) return Ok(JsonView(false));
  14950. }
  14951. else //upd
  14952. {
  14953. ////验证编辑权限
  14954. //(bool isEdit, string msg) = await _enterExitCostRep.MobilePermissionsValidationAsync(dto.Diid, dto.CurrUserId, 2);
  14955. //if (!isEdit) return Ok(JsonView(false, msg));
  14956. var subUpd = await _sqlSugar.Updateable(subInfo)
  14957. .UpdateColumns(x => new
  14958. {
  14959. x.Index,
  14960. x.SetDataId,
  14961. x.Cost,
  14962. x.Currency,
  14963. x.SubTotal,
  14964. x.Remark
  14965. })
  14966. .WhereColumns(x => new { x.Id })
  14967. .ExecuteCommandAsync();
  14968. if (subUpd < 1) return Ok(JsonView(false));
  14969. }
  14970. #endregion
  14971. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPrice>().Where(x => x.IsDel == 0 && x.Diid == diId).Sum(x => x.SubTotal);
  14972. //消息通知
  14973. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  14974. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  14975. }
  14976. /// <summary>
  14977. /// 团组模块 - 出入境费用-移动端 - 3-6子项删除
  14978. /// </summary>
  14979. /// <returns></returns>
  14980. [HttpPost]
  14981. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  14982. public async Task<IActionResult> EnterExitCostMobileSubItemDel(EnterExitCostSubItemDelDto dto)
  14983. {
  14984. var data = await _enterExitCostRep.PostEnterExitCostSubItemDel(dto);
  14985. if (data.Code != 0)
  14986. {
  14987. return Ok(JsonView(false, data.Msg));
  14988. }
  14989. return Ok(JsonView(true, "操作成功!", data.Data));
  14990. }
  14991. /// <summary>
  14992. /// 团组模块 - 出入境费用-移动端 - 其他费用删除
  14993. /// </summary>
  14994. /// <param name="dto"></param>
  14995. /// <returns></returns>
  14996. [HttpPost]
  14997. public IActionResult EnterExitCostMobileOtherFeeDel(EnterExitCostSubItemDelDto dto)
  14998. {
  14999. var data = new Grp_DayOtherPrice()
  15000. {
  15001. Id = dto.Id,
  15002. IsDel = 1,
  15003. DeleteUserId = dto.DeleteUserId,
  15004. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  15005. };
  15006. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  15007. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  15008. return Ok(JsonView(false, "删除失败!"));
  15009. }
  15010. #endregion
  15011. #endregion
  15012. #region 团组经理模块 出入境费用-草稿 移动端(Android/IOS)
  15013. /// <summary>
  15014. /// 团组模块 - 出入境费用-草稿 - 基础数据源 - 省份归属
  15015. /// </summary>
  15016. /// <returns></returns>
  15017. [HttpGet]
  15018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15019. public async Task<IActionResult> EnterExitDraftMobileProvBelongCostDataSource()
  15020. {
  15021. var provData = await _groupRepository.ProvinceBasicSource();
  15022. return Ok(JsonView(true, "查询成功!", provData));
  15023. }
  15024. /// <summary>
  15025. /// 团组模块 - 出入境费用-草稿-移动端 - 草稿名称数据Data
  15026. /// </summary>
  15027. /// <returns></returns>
  15028. [HttpPost]
  15029. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15030. public async Task<IActionResult> EnterExitCostDraftMobileNameData(EnterExitCostDraftMobileNameDataDto dto)
  15031. {
  15032. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15033. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15034. RefAsync<int> total = 0;
  15035. var data = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>()
  15036. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.DraftName))
  15037. .WhereIF(!string.IsNullOrEmpty(dto.DraftName), x => x.DraftName.Contains(dto.DraftName))
  15038. .Select(x => new
  15039. {
  15040. Id = x.Id,
  15041. DraftName = x.DraftName,
  15042. IsViewOrEdit = SqlFunc.Subqueryable<Grp_EnterExitCostDraftPermission>()
  15043. .Where(x1 => x1.IsDel == 0 && x1.Permission == 1 && x1.DraftId == x.Id && x1.UserId == dto.CurrUserId)
  15044. .Any()
  15045. })
  15046. .OrderByDescending(x => x.Id)
  15047. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15048. return Ok(JsonView(true, "查询成功!", data, total));
  15049. }
  15050. /// <summary>
  15051. /// 出入境费用-草稿 移动端
  15052. /// 获取币种基础数据(含逻辑处理)
  15053. /// </summary>
  15054. /// <returns></returns>
  15055. private async Task<List<CurrencyInfo>> EnterExitCostDraftMobileGetCurrencyInit()
  15056. {
  15057. return await GeneralMethod.EnterExitCostInitRate();
  15058. }
  15059. /// <summary>
  15060. /// 团组模块 - 出入境费用-草稿-移动端 - 基础数据源(Word明细类型、Excel明细类型、默认币种显示)
  15061. /// </summary>
  15062. /// <returns></returns>
  15063. [HttpPost]
  15064. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15065. public async Task<IActionResult> EnterExitCostDraftMobileDataSource(EnterExitCostDraftMobileDataSourceDto dto)
  15066. {
  15067. //验证城市归属并给默认值
  15068. int provinceId = dto.ProvinceId;
  15069. if (provinceId < 1) provinceId = 122;
  15070. var dataSource = await _sqlSugar
  15071. .Queryable<Sys_SetData>()
  15072. .Where(x => x.IsDel == 0 && (x.STid == 72 || x.STid == 73) && x.Remark.Contains(provinceId.ToString()))
  15073. .ToListAsync();
  15074. //三公费用-Word明细类型
  15075. var wordTypeData = dataSource.Where(it => it.STid == 72)
  15076. .Select(x => new SetDataInfoView
  15077. {
  15078. Id = x.Id,
  15079. Name = x.Name,
  15080. Remark = x.Remark
  15081. })
  15082. .ToList();
  15083. //三公费用-Excel明细类型
  15084. var excelTypeData = dataSource.Where(it => it.STid == 73)
  15085. .Select(x => new SetDataInfoView
  15086. {
  15087. Id = x.Id,
  15088. Name = x.Name,
  15089. Remark = x.Remark
  15090. })
  15091. .ToList();
  15092. //默认币种显示
  15093. var _currencyInfos = await EnterExitCostMobileGetCurrencyInit();
  15094. var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
  15095. return Ok(JsonView(true, "查询成功!", new
  15096. {
  15097. WordTypeData = wordTypeData,
  15098. ExcelTypeData = excelTypeData,
  15099. CurrencyInit = _currencyInfos,
  15100. viewPermissionData = viewPermissionData
  15101. }));
  15102. }
  15103. /// <summary>
  15104. /// 团组模块 - 出入境费用-草稿-移动端 - 团组基础数据Data
  15105. /// </summary>
  15106. /// <returns></returns>
  15107. [HttpPost]
  15108. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15109. public async Task<IActionResult> EnterExitCostDraftMobileGroupData(PostEnterExitCostDraftMobileGroupDataDto dto)
  15110. {
  15111. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15112. RefAsync<int> total = 0;
  15113. int diId = 0;
  15114. var status = int.TryParse(dto.GroupName, out diId);
  15115. var data = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  15116. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  15117. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && diId > 0, x => x.Id == diId)
  15118. .WhereIF(!string.IsNullOrEmpty(dto.GroupName) && !status, x => x.TeamName.Contains(dto.GroupName))
  15119. .OrderByDescending(x => x.VisitStartDate)
  15120. .Select(x => new
  15121. {
  15122. Id = x.Id,
  15123. GroupName = x.TeamName
  15124. })
  15125. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15126. return Ok(JsonView(true, "查询成功!", data, total));
  15127. }
  15128. /// <summary>
  15129. /// 团组模块 - 出入境费用-草稿-移动端 - 币种基础数据Data
  15130. /// </summary>
  15131. /// <returns></returns>
  15132. [HttpPost]
  15133. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15134. public async Task<IActionResult> EnterExitCostDraftMobileCurrencyData(PostEnterExitCostDraftMobileCurrencyDataDto dto)
  15135. {
  15136. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15137. RefAsync<int> total = 0;
  15138. var data = await _sqlSugar.Queryable<Sys_SetData>()
  15139. .Where(x => x.IsDel == 0 && x.STid == 66)
  15140. .WhereIF(!string.IsNullOrEmpty(dto.CurrencyName), x => x.Name.ToLower().Contains(dto.CurrencyName) || x.Remark.Contains(dto.CurrencyName))
  15141. .Select(x => new
  15142. {
  15143. id = x.Id,
  15144. name = x.Name,
  15145. remark = x.Remark,
  15146. })
  15147. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  15148. return Ok(JsonView(true, "查询成功!", data, total));
  15149. }
  15150. /// <summary>
  15151. /// 团组模块 - 出入境费用-草稿-移动端 - 其他款项 - 币种、费用类型基础数据Data
  15152. /// </summary>
  15153. /// <returns></returns>
  15154. [HttpPost]
  15155. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15156. public async Task<IActionResult> EnterExitCostDraftMobileOtherItemCurrencyData(PostEnterExitCostDraftMobileOtherItemCurrencyDataDto dto)
  15157. {
  15158. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15159. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15160. var groupRateData = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, 2477, 98);
  15161. if (groupRateData == null) return Ok(JsonView(false, "请填写“团组汇率-->其他款项”汇率!"));
  15162. var groupOtherRateData = groupRateData.TeamRates;
  15163. var enterExitCostInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15164. if (enterExitCostInfo == null) return Ok(JsonView(groupOtherRateData));
  15165. var eecRateData = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(enterExitCostInfo.CurrencyRemark);
  15166. groupOtherRateData = groupOtherRateData
  15167. .Select(x => new TeamRateDescAddCurrencyIdView
  15168. {
  15169. CurrencyId = x.CurrencyId,
  15170. CurrencyName = x.CurrencyName,
  15171. CurrencyCode = x.CurrencyCode,
  15172. Rate = eecRateData.Find(it => it.CurrencyCode.ToUpper().Equals(x.CurrencyCode.ToUpper()))?.Rate ?? x.Rate
  15173. }).ToList();
  15174. var otherFeeTypeData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 92).Select(x => new { x.Id, x.Name }).ToListAsync();
  15175. return Ok(JsonView(true, "查询成功!", new { groupOtherRateData = groupOtherRateData, otherFeeTypeData = otherFeeTypeData }));
  15176. }
  15177. /// <summary>
  15178. /// 团组模块 - 出入境费用-草稿-移动端 - 实时汇率、签证费用、机票费用 Tips
  15179. /// </summary>
  15180. /// <returns></returns>
  15181. [HttpPost]
  15182. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15183. public async Task<IActionResult> EnterExitCostDraftMobileFeeTips(EnterExitCostDraftMobileFeeTipsDto dto)
  15184. {
  15185. int portType = dto.PortType;
  15186. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15187. var tipsData = new List<int>() { 1, 2, 3 };
  15188. if (!tipsData.Contains(dto.TipsType)) return Ok(JsonView(false, $"请传入有效的TipsType参数;1 实时汇率;2 签证费用;3 机票费用;"));
  15189. if (dto.TipsType == 1)
  15190. {
  15191. return Ok(JsonView(true, "查询成功!", await GeneralMethod.EnterExitCostLiveRate()));
  15192. }
  15193. else if (dto.TipsType == 2)
  15194. {
  15195. if (portType == 2)
  15196. {
  15197. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15198. }
  15199. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15200. .Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId)
  15201. .Select(x => x.NationalTravelFeeId)
  15202. .Distinct()
  15203. .ToListAsync();
  15204. if (portType == 2)
  15205. {
  15206. if (!cityIds.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15207. }
  15208. var countrys = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15209. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15210. .Select(x => x.Country)
  15211. .Distinct()
  15212. .ToArrayAsync();
  15213. if (portType == 2)
  15214. {
  15215. if (!countrys.Any()) return Ok(JsonView(false, "请先录入出入境费用明细!"));
  15216. }
  15217. (decimal totalAmt, string remark) = await _visaFeeInfoRep.EnterExitCostDraftVisaTips(countrys);
  15218. return Ok(JsonView(true, "查询成功!", new
  15219. {
  15220. totalAmt = totalAmt,
  15221. remark = remark
  15222. }));
  15223. }
  15224. else if (dto.TipsType == 3)
  15225. {
  15226. return Ok(JsonView(false, "暂无机票费用提示信息!"));
  15227. }
  15228. return Ok(JsonView(false));
  15229. }
  15230. #region 城市区间交通费
  15231. /// <summary>
  15232. /// 团组模块 - 出入境费用 - 草稿 - 移动端 - 基础数据源(境外用车)
  15233. /// </summary>
  15234. /// <param name="draftId">草稿Id</param>
  15235. /// <returns></returns>
  15236. [HttpGet("{darfId}")]
  15237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15238. public async Task<IActionResult> EnterExitCostDraftOVMobileByGroupId(int draftId)
  15239. {
  15240. var groupInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  15241. if (groupInfo == null)
  15242. {
  15243. return Ok(JsonView(false, "三公费用草稿信息为空"));
  15244. }
  15245. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15246. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  15247. .Select(x => x.NationalTravelFeeId)
  15248. .Distinct()
  15249. .ToListAsync();
  15250. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  15251. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  15252. .Select(x => x.Country)
  15253. .Distinct()
  15254. .ToListAsync();
  15255. if (countries?.Any() != true)
  15256. {
  15257. return Ok(JsonView(false, "草稿选择城市信息为空"));
  15258. }
  15259. var currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId);
  15260. var currencyData = await _sqlSugar.Queryable<Sys_SetData>()
  15261. .Where(x => x.IsDel == 0 && x.STid == 66)
  15262. .ToListAsync();
  15263. var overseaVehicles = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  15264. .Where(x => x.IsDel == 0 && countries.Contains(x.CountryName))
  15265. .ToListAsync();
  15266. var overseaVehicleIds = overseaVehicles.Select(x => x.Id).ToList();
  15267. //只返回接送机的数据
  15268. var overseaVehicleTypes = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15269. .Where(x => x.IsDel == 0 && x.ServiceType == VehicleServiceTypeEnum.TransferService && overseaVehicleIds.Contains(x.OvId))
  15270. .ToListAsync();
  15271. var sysUers = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToListAsync();
  15272. var overseaVehicleCityDatas = new List<dynamic>() {
  15273. new
  15274. {
  15275. Id = 0,
  15276. area= "未选择",
  15277. CarTypeName = "",
  15278. serviceType = "",
  15279. Price = 0.00M,
  15280. guidePrice = 0.00M,
  15281. otherPrice = 0.00M,
  15282. currency = 0,
  15283. currencyName = "",
  15284. currRate = 1.0000M,
  15285. LastUpdateUserName = "",
  15286. LastUpdateTime = "",
  15287. Remark = ""
  15288. }};
  15289. foreach (var item in overseaVehicleTypes)
  15290. {
  15291. var parentInfo = overseaVehicles.FirstOrDefault(x => x.Id == item.OvId);
  15292. string area = string.Empty,
  15293. serviceType = "未设置",
  15294. currencyName = string.Empty;
  15295. decimal otherPrice = 0.00M;
  15296. if (parentInfo != null)
  15297. {
  15298. if (parentInfo.CountryName == parentInfo.CityName) area = parentInfo.CountryName;
  15299. else area = $"{parentInfo.CountryName}-{parentInfo.CityName}";
  15300. serviceType = item.ServiceType.GetDescription();
  15301. currencyName = currencyData.FirstOrDefault(x => x.Id == parentInfo.Currency)?.Name ?? "-";
  15302. otherPrice = parentInfo.OtherPrice1 + parentInfo.OtherPrice2;
  15303. }
  15304. //当前币种汇率值
  15305. var currRate = 1.0000M;
  15306. var currencyInfo = currencies.FirstOrDefault(x => x.CurrencyCode == currencyName);
  15307. if (currencyInfo != null) currRate = currencyInfo.Rate;
  15308. overseaVehicleCityDatas.add(new
  15309. {
  15310. item.Id,
  15311. area,
  15312. item.CarTypeName,
  15313. serviceType,
  15314. item.Price,
  15315. guidePrice = parentInfo?.GuidePrice ?? 0.00M,
  15316. otherPrice,
  15317. currency = parentInfo?.Currency ?? 0,
  15318. currencyName,
  15319. currRate,
  15320. LastUpdateUserName = sysUers.FirstOrDefault(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-",
  15321. item.LastUpdateTime,
  15322. item.Remark
  15323. });
  15324. }
  15325. var total = overseaVehicleCityDatas.Count;
  15326. var view = new
  15327. {
  15328. visitCountries = string.Join("、", countries),
  15329. //groupSize = 0, //出访人数
  15330. defAirportTransferCoeff = Def_AirportTransferCoeff, //接送机默认报价系数
  15331. defServiceCount = Def_ServiceCount, //接送机默认服务次数
  15332. defTrainCoeff = Def_TrainCoeff, //火车默认报价系数
  15333. defPullCartCoeff = Def_PullCartCoeff, //拉车默认报价系数
  15334. defCityFlightCoeff = Def_CityFlightCoeff, //城市机票默认报价系数
  15335. Currencies = currencies,
  15336. data = overseaVehicleCityDatas
  15337. };
  15338. if (overseaVehicleCityDatas.Count == 0)
  15339. {
  15340. return Ok(JsonView(true, "暂无数据!", view));
  15341. }
  15342. return Ok(JsonView(true, "查询成功!", view, total));
  15343. }
  15344. /// <summary>
  15345. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算详细信息
  15346. /// </summary>
  15347. /// <param name="draftId"></param>
  15348. /// <param name="currUserId"></param>
  15349. /// <returns></returns>
  15350. [HttpGet("{groupId}")]
  15351. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15352. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileDetails(int draftId, int currUserId)
  15353. {
  15354. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId && x.IsDel == 0).FirstAsync();
  15355. if (eecInfo == null)
  15356. {
  15357. return Ok(JsonView(false, "草稿信息为空"));
  15358. }
  15359. var info = new CityIntervalDraftInfo();
  15360. if (eecInfo != null)
  15361. {
  15362. info = eecInfo.CityIntervalFeeDetails;
  15363. return Ok(JsonView(true, "查询成功!", info));
  15364. }
  15365. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == currUserId).FirstAsync();
  15366. var userName = userInfo?.CnName ?? "-";
  15367. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15368. //返回默认数据
  15369. info = new CityIntervalDraftInfo()
  15370. {
  15371. APTFeeDetails = new List<RoundTripTransferInfo>() { new() { No = 1, Coefficient = Def_AirportTransferCoeff, ServiceCount = Def_ServiceCount } },
  15372. PullCartFeeDetails = new List<PullCartInfo>() { new() { No = 1, Coefficient = Def_PullCartCoeff } },
  15373. TrainFeeDetails = new List<TrainInfo>() { new() { No = 1, Coefficient = Def_TrainCoeff } },
  15374. CityAirTicketFeeDetails = new List<CityAirTicketInfo>() { new() { No = 1, Coefficient = Def_CityFlightCoeff } },
  15375. LastUpdateUserName = userName,
  15376. LastUpdateTime = nowTime,
  15377. CreateUserName = userName,
  15378. Currencies = await GeneralMethod.EnterExitCostDrafOVFeeUsedCurrencyAsync(draftId),
  15379. CreateTime = nowTime
  15380. };
  15381. return Ok(JsonView(true, "查询成功!", info));
  15382. }
  15383. /// <summary>
  15384. /// 团组模块 - 出入境费用 - 草稿 - 境外用车计算 保存
  15385. /// </summary>
  15386. /// <param name="dto"></param>
  15387. /// <returns></returns>
  15388. [HttpPost]
  15389. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15390. public async Task<IActionResult> EnterExitCostDraftOVFeeMobileSave(EnterExitCostDraftOVFeeSaveDto dto)
  15391. {
  15392. var draftInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == dto.DraftId).FirstAsync();
  15393. if (draftInfo == null)
  15394. {
  15395. return Ok(JsonView(false, "草稿信息为空"));
  15396. }
  15397. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.Id == dto.CurrUserId).FirstAsync();
  15398. if (userInfo == null)
  15399. {
  15400. return Ok(JsonView(false, "员工信息为空"));
  15401. }
  15402. var userName = userInfo?.CnName ?? "-";
  15403. var nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  15404. var info = new CityIntervalDraftInfo()
  15405. {
  15406. GroupSize = dto.GroupSize,
  15407. APTFeeTotal = dto.APTFeeTotal,
  15408. APTFeeDetails = dto.APTFeeDetails,
  15409. PullCartFeeTotal = dto.PullCartFeeTotal,
  15410. PullCartFeeDetails = dto.PullCartFeeDetails,
  15411. TrainFeeTotal = dto.TrainFeeTotal,
  15412. TrainFeeDetails = dto.TrainFeeDetails,
  15413. CityAirTicketFeeTotal = dto.CityAirTicketFeeTotal,
  15414. CityAirTicketFeeDetails = dto.CityAirTicketFeeDetails,
  15415. Currencies = dto.Currencies,
  15416. LastUpdateUserName = userName,
  15417. LastUpdateTime = nowTime,
  15418. CreateUserName = draftInfo.CityIntervalFeeDetails?.CreateUserName ?? userName,
  15419. CreateTime = draftInfo.CityIntervalFeeDetails?.CreateTime ?? nowTime
  15420. };
  15421. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  15422. .SetColumns(it => it.CityIntervalFeeDetails == info)
  15423. .Where(x => x.Id == draftInfo.Id)
  15424. .ExecuteCommandAsync();
  15425. if (upd < 1)
  15426. {
  15427. return Ok(JsonView(false));
  15428. }
  15429. //返回参数处理
  15430. var label = new StringBuilder();
  15431. if (dto.APTFeeDetails.Any())
  15432. {
  15433. var ovIds = dto.APTFeeDetails.Select(x => x.OvId).ToList();
  15434. var areas = await _sqlSugar.Queryable<Res_OverseaVehicleTypePrice>()
  15435. .LeftJoin<Res_OverseaVehicle>((ovtp, ov) => ovtp.OvId == ov.Id)
  15436. .Where((ovtp, ov) => ovtp.IsDel == 0 && ovIds.Contains(ovtp.Id))
  15437. .Select((ovtp, ov) => new
  15438. {
  15439. ovtp.Id,
  15440. ov.CountryName,
  15441. ov.CityName
  15442. })
  15443. .ToListAsync();
  15444. if (areas.Any())
  15445. {
  15446. var items = dto.APTFeeDetails
  15447. .Select(item =>
  15448. {
  15449. var areaInfo = areas.FirstOrDefault(x => x.Id == item.OvId);
  15450. if (areaInfo == null) return null;
  15451. return areaInfo.CountryName == areaInfo.CityName
  15452. ? $"{areaInfo.CountryName}({item.Quote:#0.00} CNY)"
  15453. : $"{areaInfo.CountryName}-{areaInfo.CityName}({item.Quote:#0.00} CNY)";
  15454. })
  15455. .Where(item => item != null)
  15456. .ToList();
  15457. string areaLabel = $"接送机({string.Join("、", items)});";
  15458. label.AppendLine(areaLabel);
  15459. }
  15460. }
  15461. if (dto.PullCartFeeDetails.Any())
  15462. {
  15463. var amounts = dto.PullCartFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15464. string subLabel = $"拉车({string.Join("、", amounts)});";
  15465. label.AppendLine(subLabel);
  15466. }
  15467. if (dto.TrainFeeDetails.Any())
  15468. {
  15469. var amounts = dto.TrainFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15470. string subLabel = $"火车票({string.Join("、", amounts)});";
  15471. label.AppendLine(subLabel);
  15472. }
  15473. if (dto.CityAirTicketFeeDetails.Any())
  15474. {
  15475. var amounts = dto.CityAirTicketFeeDetails.Select(item => $"{item.Quote:#0.00}");
  15476. string subLabel = $"城市机票({string.Join("、", amounts)});";
  15477. label.AppendLine(subLabel);
  15478. }
  15479. //费用
  15480. decimal quote = (dto.APTFeeTotal + dto.PullCartFeeTotal + dto.TrainFeeTotal + dto.CityAirTicketFeeTotal).ConvertToDecimal1();
  15481. decimal jjcQuote = quote;
  15482. decimal gwcQuote = quote;
  15483. decimal tdcQuote = quote;
  15484. var view = new
  15485. {
  15486. label = label.ToString(),
  15487. jjcQuote,
  15488. gwcQuote,
  15489. tdcQuote
  15490. };
  15491. return Ok(JsonView(view));
  15492. }
  15493. #endregion
  15494. /// <summary>
  15495. /// 团组模块 - 出入境费用-草稿-移动端 - 创建
  15496. /// </summary>
  15497. /// <returns></returns>
  15498. [HttpPost]
  15499. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15500. public async Task<IActionResult> EnterExitCostDraftMobileCreate(EnterExitCostDraftMobileCreateDto dto)
  15501. {
  15502. if (string.IsNullOrEmpty(dto.DraftName)) return Ok(JsonView(false, "草稿名称为空!"));
  15503. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15504. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15505. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.DraftName.Equals(dto.DraftName) && it.IsDel == 0);
  15506. if (eecInfo != null) return Ok(JsonView(false, "草稿名称重复!"));
  15507. var rateInfos = await EnterExitCostMobileGetCurrencyInit();
  15508. var info = new Grp_EnterExitCostDraft()
  15509. {
  15510. ProvinceId = dto.ProvinceId,
  15511. DraftName = dto.DraftName,
  15512. CurrencyRemark = CommonFun.GetCurrencyChinaToString(rateInfos),
  15513. CreateUserId = dto.CurrUserId
  15514. };
  15515. _sqlSugar.BeginTran();
  15516. var draftId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  15517. if (draftId < 1)
  15518. {
  15519. _sqlSugar.RollbackTran();
  15520. return Ok(JsonView(false, "草稿创建失败!"));
  15521. }
  15522. //添加默认权限
  15523. await _enterExitCostDraftRep.InitPerm(draftId, dto.CurrUserId);
  15524. _sqlSugar.CommitTran();
  15525. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(draftId, dto.CurrUserId);
  15526. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  15527. mobileInfo.Id = draftId;
  15528. mobileInfo.DraftName = dto.DraftName;
  15529. mobileInfo.Currencys = rateInfos;
  15530. mobileInfo.IsAssignPerm = assignPerm;
  15531. return Ok(JsonView(mobileInfo));
  15532. }
  15533. /// <summary>
  15534. /// 出入境费用-草稿-移动端 查看编辑提示消息
  15535. /// </summary>
  15536. private static string _viewPermStr = $"未分配查看权限,如要查看,请联系市场部或国交部负责人!";
  15537. /// <summary>
  15538. /// 团组模块 - 出入境费用-草稿-移动端 - ParentInfo
  15539. /// </summary>
  15540. /// <returns></returns>
  15541. [HttpPost]
  15542. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15543. public async Task<IActionResult> EnterExitCostDraftMobileParentInfo(EnterExitCostDraftMobileParentInfoDto dto)
  15544. {
  15545. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  15546. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15547. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15548. var mobileInfo = new EnterExitCostDraftMobileParentInfoView();
  15549. mobileInfo.Currencys = await EnterExitCostMobileGetCurrencyInit();
  15550. if (eecInfo == null) return Ok(JsonView(mobileInfo));
  15551. //验证查看编辑权限
  15552. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15553. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15554. mobileInfo = _mapper.Map<EnterExitCostDraftMobileParentInfoView>(eecInfo);
  15555. mobileInfo.ProvinceId = eecInfo.ProvinceId;
  15556. mobileInfo.IsAssignPerm = assignPerm;
  15557. var dayAndCostData = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15558. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15559. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15560. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  15561. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15562. {
  15563. ParentId = dac.ParentId,
  15564. SubId = dac.Id,
  15565. Type = dac.Type,
  15566. Days = dac.Days,
  15567. NationalTravelFeeId = dac.NationalTravelFeeId,
  15568. Arae = $"{ntf.Country}-{ntf.City}",
  15569. Cost = dac.Cost,
  15570. Currency = dac.Currency,
  15571. CurrencyName = sd.Name,
  15572. SubTotal = dac.SubTotal,
  15573. })
  15574. .ToList();
  15575. mobileInfo.ChoiceOneTotalCost = eecInfo.InsidePay;
  15576. mobileInfo.ChoiceTwoJJ = eecInfo.SumJJC;
  15577. mobileInfo.ChoiceTwoGW = eecInfo.SumGWC;
  15578. mobileInfo.ChoiceTwoTD = eecInfo.SumTDC;
  15579. mobileInfo.Currencys = !string.IsNullOrEmpty(eecInfo.CurrencyRemark) ? CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark) : mobileInfo.Currencys;
  15580. mobileInfo.ChoiceThreeTotalCost = dayAndCostData.Where(it => it.Type == 1).Sum(x => x.SubTotal); //住宿费 1
  15581. mobileInfo.ChoiceFourTotalCost = dayAndCostData.Where(it => it.Type == 2).Sum(x => x.SubTotal); //伙食费 2
  15582. mobileInfo.ChoiceFiveTotalCost = dayAndCostData.Where(it => it.Type == 3).Sum(x => x.SubTotal); //公杂费 3
  15583. mobileInfo.ChoiceSixTotalCost = dayAndCostData.Where(it => it.Type == 4).Sum(x => x.SubTotal); //培训费 4
  15584. //其他款项
  15585. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  15586. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  15587. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  15588. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  15589. .OrderBy((dop, sd1, sd2) => dop.Index)
  15590. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  15591. {
  15592. ParentId = dop.ParentId,
  15593. SubId = dop.Id,
  15594. Index = dop.Index,
  15595. SetDataId = dop.SetDataId,
  15596. SetDataName = sd1.Name,
  15597. Cost = dop.Cost,
  15598. Currency = dop.Currency,
  15599. CurrencyName = sd2.Remark,
  15600. SubTotal = dop.SubTotal,
  15601. Remark = dop.Remark,
  15602. })
  15603. .ToArray();
  15604. mobileInfo.OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal);
  15605. return Ok(mobileInfo);
  15606. }
  15607. /// <summary>
  15608. /// 团组模块 - 出入境费用-草稿-移动端 - SubInfo
  15609. /// </summary>
  15610. /// <returns></returns>
  15611. [HttpPost]
  15612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15613. public async Task<IActionResult> EnterExitCostDraftMobileSubInfo(PostEnterExitCostDraftMobileSubInfoDto dto)
  15614. {
  15615. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15616. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15617. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15618. var subTypes = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
  15619. if (!subTypes.Contains(dto.SubType)) return Ok(JsonView(false, $"请传入有效的subTypeId!"));
  15620. //验证查看编辑权限
  15621. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15622. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15623. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().OrderByDescending(x => x.CreateTime).FirstAsync(it => it.Id == dto.DraftId && it.IsDel == 0);
  15624. if (eecInfo == null) return Ok(JsonView(false, $"出入境费用明细未录入!"));
  15625. var subType = dto.SubType;
  15626. if (subType == 1) //1:境内费用
  15627. {
  15628. var oneData = new ChoiceOneMobileSubInfoView()
  15629. {
  15630. Id = eecInfo.Id,
  15631. ChoiceOne = eecInfo.ChoiceOne,
  15632. ChoiceOneTotalCost = eecInfo.InsidePay,
  15633. Visa = eecInfo.Visa,
  15634. VisaRemark = eecInfo.VisaRemark,
  15635. YiMiao = eecInfo.YiMiao,
  15636. HeSuan = eecInfo.HeSuan,
  15637. Service = eecInfo.Service,
  15638. Ticket = eecInfo.Ticket,
  15639. Safe = eecInfo.Safe,
  15640. FirstItemRemark = eecInfo.FirstItemRemark
  15641. };
  15642. return Ok(JsonView(oneData));
  15643. }
  15644. else if (subType == 2) //2:国际旅费
  15645. {
  15646. var twoData = new ChoiceTwoMobileSubInfoView()
  15647. {
  15648. Id = eecInfo.Id,
  15649. ChoiceTwoJJ = eecInfo.SumJJC,
  15650. OutsideJJPay = eecInfo.OutsideJJPay,
  15651. ChoiceTwoGW = eecInfo.SumGWC,
  15652. OutsideGWPay = eecInfo.OutsideGWPay,
  15653. ChoiceTwoTD = eecInfo.SumTDC,
  15654. OutsideTDPay = eecInfo.OutsideTDPay,
  15655. AirJJ = eecInfo.AirJJ,
  15656. AirGW = eecInfo.AirGW,
  15657. AirTD = eecInfo.AirTD,
  15658. CityTranffic = eecInfo.CityTranffic,
  15659. CityTranffic1 = eecInfo.CityTranffic1,
  15660. CityTranffic2 = eecInfo.CityTranffic2,
  15661. TwoItemRemark = eecInfo.TwoItemRemark
  15662. };
  15663. return Ok(JsonView(twoData));
  15664. }
  15665. else if (subType == 3) //3:住宿费
  15666. {
  15667. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15668. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15669. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15670. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 1)
  15671. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15672. {
  15673. ParentId = dac.ParentId,
  15674. SubId = dac.Id,
  15675. Type = dac.Type,
  15676. Days = dac.Days,
  15677. NationalTravelFeeId = dac.NationalTravelFeeId,
  15678. Arae = $"{ntf.Country}-{ntf.City}",
  15679. Cost = dac.Cost,
  15680. Currency = dac.Currency,
  15681. CurrencyName = sd.Name,
  15682. SubTotal = dac.SubTotal,
  15683. })
  15684. .ToArray();
  15685. var data = new ChoiceDraftMobileSubInfo3To6View()
  15686. {
  15687. ParentId = eecInfo.Id,
  15688. Choice = eecInfo.ChoiceThree,
  15689. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15690. Details = dayAndCostDatas
  15691. };
  15692. return Ok(JsonView(data));
  15693. }
  15694. else if (subType == 4) //4:伙食费
  15695. {
  15696. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15697. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15698. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15699. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 2)
  15700. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15701. {
  15702. ParentId = dac.ParentId,
  15703. SubId = dac.Id,
  15704. Type = dac.Type,
  15705. Days = dac.Days,
  15706. NationalTravelFeeId = dac.NationalTravelFeeId,
  15707. Arae = $"{ntf.Country}-{ntf.City}",
  15708. Cost = dac.Cost,
  15709. Currency = dac.Currency,
  15710. CurrencyName = sd.Name,
  15711. SubTotal = dac.SubTotal,
  15712. })
  15713. .ToArray();
  15714. var data = new ChoiceDraftMobileSubInfo3To6View()
  15715. {
  15716. ParentId = eecInfo.Id,
  15717. Choice = eecInfo.ChoiceFour,
  15718. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15719. Details = dayAndCostDatas
  15720. };
  15721. return Ok(JsonView(data));
  15722. }
  15723. else if (subType == 5) //5:公杂费
  15724. {
  15725. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15726. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15727. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15728. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 3)
  15729. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15730. {
  15731. ParentId = dac.ParentId,
  15732. SubId = dac.Id,
  15733. Type = dac.Type,
  15734. Days = dac.Days,
  15735. NationalTravelFeeId = dac.NationalTravelFeeId,
  15736. Arae = $"{ntf.Country}-{ntf.City}",
  15737. Cost = dac.Cost,
  15738. Currency = dac.Currency,
  15739. CurrencyName = sd.Name,
  15740. SubTotal = dac.SubTotal,
  15741. })
  15742. .ToArray();
  15743. var data = new ChoiceDraftMobileSubInfo3To6View()
  15744. {
  15745. ParentId = eecInfo.Id,
  15746. Choice = eecInfo.ChoiceFive,
  15747. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15748. Details = dayAndCostDatas
  15749. };
  15750. return Ok(JsonView(data));
  15751. }
  15752. else if (subType == 6) //6:培训费
  15753. {
  15754. var dayAndCostDatas = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  15755. .LeftJoin<Grp_NationalTravelFee>((dac, ntf) => dac.NationalTravelFeeId == ntf.Id)
  15756. .LeftJoin<Sys_SetData>((dac, ntf, sd) => dac.Currency == sd.Id)
  15757. .Where((dac, ntf, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId && dac.Type == 4)
  15758. .Select((dac, ntf, sd) => new DayAndCostDraftMobileInfoView
  15759. {
  15760. ParentId = dac.ParentId,
  15761. SubId = dac.Id,
  15762. Type = dac.Type,
  15763. Days = dac.Days,
  15764. NationalTravelFeeId = dac.NationalTravelFeeId,
  15765. Arae = $"{ntf.Country}-{ntf.City}",
  15766. Cost = dac.Cost,
  15767. Currency = dac.Currency,
  15768. CurrencyName = sd.Name,
  15769. SubTotal = dac.SubTotal,
  15770. })
  15771. .ToArray();
  15772. var data = new ChoiceDraftMobileSubInfo3To6View()
  15773. {
  15774. ParentId = eecInfo.Id,
  15775. Choice = eecInfo.ChoiceSix,
  15776. TotalCost = dayAndCostDatas.Sum(x => x.SubTotal),
  15777. Details = dayAndCostDatas
  15778. };
  15779. return Ok(JsonView(data));
  15780. }
  15781. else if (subType == 7) //7:其他
  15782. {
  15783. //其他款项
  15784. var otherData = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  15785. .LeftJoin<Sys_SetData>((dop, sd1) => dop.SetDataId == sd1.Id)
  15786. .LeftJoin<Sys_SetData>((dop, sd1, sd2) => dop.Currency == sd2.Id)
  15787. .Where((dop, sd1, sd2) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  15788. .OrderBy((dop, sd1, sd2) => dop.Index)
  15789. .Select((dop, sd1, sd2) => new DayOtherPriceDraftMobileInfoView
  15790. {
  15791. ParentId = dop.ParentId,
  15792. SubId = dop.Id,
  15793. Index = dop.Index,
  15794. SetDataId = dop.SetDataId,
  15795. SetDataName = sd1.Name,
  15796. Cost = dop.Cost,
  15797. Currency = dop.Currency,
  15798. CurrencyName = sd2.Name,
  15799. SubTotal = dop.SubTotal,
  15800. Remark = dop.Remark,
  15801. })
  15802. .ToArray();
  15803. var data = new ChoiceSevenDraftMobileSubInfoView()
  15804. {
  15805. ParentId = eecInfo.Id,
  15806. OtherExpenses_Checked = eecInfo.OtherExpenses_Checked,
  15807. OtherExpensesTotalCost = otherData.Sum(x => x.SubTotal),
  15808. Details = otherData
  15809. };
  15810. return Ok(JsonView(data));
  15811. }
  15812. return Ok(JsonView(false));
  15813. }
  15814. #region op
  15815. ///// <summary>
  15816. ///// 移动端更新费用消息通知
  15817. ///// </summary>
  15818. ///// <param name="draftId"></param>
  15819. ///// <param name="id"></param>
  15820. ///// <param name="currUserId"></param>
  15821. //private async Task EnterExitCostDraftMobileOpNotice(int draftId, int id, int currUserId)
  15822. //{
  15823. // try
  15824. // {
  15825. // ////生成默认文件pdf并且通知人员
  15826. // //var fileView = await GeneralMethod.EnterExitCostDownload(new EnterExitCostDownloadDto()
  15827. // //{
  15828. // // DiId = draftId,
  15829. // // ExportType = 1,
  15830. // // SubTypeId = 1005
  15831. // //}, "pdf");
  15832. // ////发送通知
  15833. // //string fileUrl = (string)fileView.Data.GetType().GetProperty("Url").GetValue(fileView.Data, null);
  15834. // //string md5Sign = GeneralMethod.Encrypt($"{id}&fileName={fileUrl}");
  15835. // //string url = string.Format("http://oa.pan-american-intl.com:4399/#/Sankunginfo?sign={0}&fileName={1}", id, fileUrl);
  15836. // //await AppNoticeLibrary.SendUserMsg_GroupShare_ToGM(draftId, new List<string>() { "208", "233", "21" }, currUserId, url);
  15837. // ////汇率信息记录
  15838. // //await GeneralMethod.RateRecordSave(currUserId, id, "出入境费用");
  15839. // }
  15840. // catch (Exception ex)
  15841. // {
  15842. // //记录日志
  15843. // throw;
  15844. // }
  15845. //}
  15846. /// <summary>
  15847. /// 验证出入境费用数据是否存在
  15848. /// 不存在添加
  15849. /// </summary>
  15850. /// <param name="draftId"></param>
  15851. /// <param name="currUserId"></param>
  15852. /// <returns></returns>
  15853. private async Task<int> EnterExitCostDraftVerifyIsNull(int draftId, int currUserId)
  15854. {
  15855. var parentId = 0;
  15856. var info = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == draftId).OrderByDescending(x => x.CreateTime).FirstAsync();
  15857. if (info != null) parentId = info.Id;
  15858. else
  15859. {
  15860. var currencys = await EnterExitCostDraftMobileGetCurrencyInit();
  15861. int addId = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { CreateUserId = currUserId, CurrencyRemark = JsonConvert.SerializeObject(currencys) }).ExecuteReturnIdentityAsync();
  15862. parentId = addId;
  15863. }
  15864. return parentId;
  15865. }
  15866. /// <summary>
  15867. /// 团组模块 - 出入境费用-草稿-移动端 - 查看权限用户
  15868. /// </summary>
  15869. /// <returns></returns>
  15870. [HttpPost]
  15871. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15872. public async Task<IActionResult> EnterExitCostDraftMobileViewPermissionUsers(EnterExitCostDraftMobileViewPermissionUsersDto dto)
  15873. {
  15874. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15875. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15876. //验证查看权限
  15877. (bool isView, bool isSet) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15878. if (!isView) return Ok(JsonView(false, _viewPermStr));
  15879. var userIds = await _sqlSugar
  15880. .Queryable<Grp_EnterExitCostDraftPermission>()
  15881. .Where(x => x.IsDel == 0 && x.DraftId == dto.DraftId)
  15882. .Select(x => x.UserId)
  15883. .ToArrayAsync();
  15884. var perUsers = await _enterExitCostDraftRep.PermissionViewUsersAsync();
  15885. var perUsersView = new List<dynamic>();
  15886. var feeBasePerm = AppSettingsHelper.Get<FeeBasePermView>("FeeBasePerm");
  15887. var viewPermissionData = new List<PermissionViewUserview>();
  15888. if (feeBasePerm.Any())
  15889. {
  15890. foreach (var item in feeBasePerm)
  15891. {
  15892. if (item.Users.Any())
  15893. {
  15894. viewPermissionData.AddRange(item.Users);
  15895. }
  15896. }
  15897. }
  15898. foreach (var item in perUsers)
  15899. {
  15900. bool isView1 = false;
  15901. if (userIds.Any(x => x == item.Id)) isView1 = true;
  15902. else if (viewPermissionData.Any(x => x.Id == dto.CurrUserId) && item.Id == dto.CurrUserId) isView1 = true;
  15903. perUsersView.Add(new { Id = item.Id, Name = item.Name, IsView = isView1 });
  15904. }
  15905. return Ok(JsonView(perUsersView));
  15906. }
  15907. /// <summary>
  15908. /// 团组模块 - 出入境费用-草稿-移动端 - 设置view权限
  15909. /// </summary>
  15910. /// <returns></returns>
  15911. [HttpPost]
  15912. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15913. public async Task<IActionResult> EnterExitCostDraftMobileSetViewPermissiion(EnterExitCostDraftMobileSetViewPermissiionDto dto)
  15914. {
  15915. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15916. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  15917. if (dto.UserIds.Length < 1) return Ok(JsonView(false, "请传入有效的userId;"));
  15918. //验证查看编辑权限
  15919. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15920. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15921. var permissions = new List<Grp_EnterExitCostDraftPermission>() { };
  15922. foreach (var userId in dto.UserIds)
  15923. {
  15924. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = userId, CreateUserId = dto.CurrUserId });
  15925. }
  15926. if (permissions.Any())
  15927. {
  15928. if (!permissions.Any(x => x.UserId == dto.CurrUserId))
  15929. {
  15930. permissions.Add(new Grp_EnterExitCostDraftPermission { Permission = 1, DraftId = dto.DraftId, UserId = dto.CurrUserId, CreateUserId = dto.CurrUserId });
  15931. }
  15932. _sqlSugar.BeginTran();
  15933. await _sqlSugar.Deleteable<Grp_EnterExitCostDraftPermission>().Where(it => it.DraftId == dto.DraftId).ExecuteCommandAsync();
  15934. var result = await _sqlSugar.Insertable(permissions).ExecuteCommandAsync();
  15935. if (result < 1)
  15936. {
  15937. _sqlSugar.RollbackTran();
  15938. return Ok(JsonView(false));
  15939. }
  15940. _sqlSugar.CommitTran();
  15941. return Ok(JsonView(true));
  15942. }
  15943. return Ok(JsonView(false));
  15944. }
  15945. /// <summary>
  15946. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 省份
  15947. /// </summary>
  15948. /// <returns></returns>
  15949. [HttpPost]
  15950. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15951. public async Task<IActionResult> EnterExitCostDraftMobileOpProv(EnterExitCostDraftMobileOpProvDto dto)
  15952. {
  15953. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15954. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15955. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15956. if (dto.ProvinceId < 1) return Ok(JsonView(false, "请传入有效的省份Id!"));
  15957. int id = dto.DraftId;
  15958. if (id <= 0) //add
  15959. {
  15960. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15961. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  15962. if (add < 1) return Ok(JsonView(false));
  15963. id = add;
  15964. }
  15965. else //update
  15966. {
  15967. //验证查看编辑权限
  15968. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  15969. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  15970. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  15971. if (upd < 1) return Ok(JsonView(false));
  15972. }
  15973. return Ok(JsonView(new { parentId = id }));
  15974. }
  15975. /// <summary>
  15976. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 汇率
  15977. /// </summary>
  15978. /// <returns></returns>
  15979. [HttpPost]
  15980. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  15981. public async Task<IActionResult> EnterExitCostDraftMobileOpRate(PostEnterExitCostDraftMobileFeeRateOpDto dto)
  15982. {
  15983. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  15984. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15985. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  15986. if (dto.Currencys.Length < 1) return Ok(JsonView(false, "请传入有效的汇率信息!"));
  15987. var currencyStr = CommonFun.GetCurrencyChinaToString(dto.Currencys.ToList());
  15988. int id = dto.DraftId;
  15989. if (id <= 0) //add
  15990. {
  15991. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  15992. var add = await _sqlSugar.Insertable(new Grp_EnterExitCostDraft() { ProvinceId = dto.ProvinceId, CurrencyRemark = currencyStr, CreateUserId = dto.CurrUserId }).ExecuteCommandAsync();
  15993. if (add < 1) return Ok(JsonView(false));
  15994. id = add;
  15995. }
  15996. else //update
  15997. {
  15998. //验证查看编辑权限
  15999. (bool viewPerm, bool assignPerm) = await _enterExitCostDraftRep.PermissionValidationAsync(dto.DraftId, dto.CurrUserId);
  16000. if (!viewPerm) return Ok(JsonView(false, _viewPermStr));
  16001. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>().SetColumns(x => new Grp_EnterExitCostDraft() { CurrencyRemark = currencyStr }).Where(x => x.Id == dto.DraftId).ExecuteCommandAsync();
  16002. if (upd < 1) return Ok(JsonView(false));
  16003. }
  16004. #region 汇率变更时更改币种相关费用
  16005. var opDayCosts = new List<Grp_DayAndCostDraft>();
  16006. var opDayOtherCosts = new List<Grp_DayOtherPriceDraft>();
  16007. var eecCurrencys = dto.Currencys.Select(x => x.CurrencyCode.ToUpper()).ToList();
  16008. var dayCosts = _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  16009. .LeftJoin<Sys_SetData>((dac, sd) => dac.Currency == sd.Id)
  16010. .Where((dac, sd) => dac.IsDel == 0 && dac.ParentId == dto.DraftId)
  16011. .Select((dac, sd) => new
  16012. {
  16013. dac.Id,
  16014. dac.ParentId,
  16015. CurrencyCode = sd.Name,
  16016. dac.Cost
  16017. })
  16018. .ToList();
  16019. var dayOtherCosts = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>()
  16020. .LeftJoin<Sys_SetData>((dop, sd) => dop.Currency == sd.Id)
  16021. .Where((dop, sd) => dop.IsDel == 0 && dop.ParentId == dto.DraftId)
  16022. .Select((dop, sd) => new
  16023. {
  16024. dop.Id,
  16025. dop.ParentId,
  16026. CurrencyCode = sd.Name,
  16027. dop.Cost
  16028. })
  16029. .ToList();
  16030. if (dayCosts.Count > 0)
  16031. {
  16032. var new_dayCosts = dayCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  16033. foreach (var dc in new_dayCosts)
  16034. {
  16035. var thisCurrency = dc.Key.ToUpper();
  16036. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  16037. if (thisRate == 0.00M) continue;
  16038. foreach (var dcSub in dc)
  16039. {
  16040. opDayCosts.Add(new Grp_DayAndCostDraft()
  16041. {
  16042. Id = dcSub.Id,
  16043. ParentId = dcSub.ParentId,
  16044. Cost = dcSub.Cost,
  16045. SubTotal = dcSub.Cost * thisRate,
  16046. Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now:yyyy-MM-dd HH:mm:ss}、opUserId:{dto.CurrUserId}]"
  16047. });
  16048. }
  16049. }
  16050. if (opDayCosts.Count > 0)
  16051. {
  16052. await _sqlSugar.Updateable(opDayCosts).UpdateColumns(x => new { x.SubTotal, x.Remark }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  16053. }
  16054. }
  16055. if (dayOtherCosts.Count > 0)
  16056. {
  16057. var new_dayOtherCosts = dayOtherCosts.Where(x => eecCurrencys.Contains(x.CurrencyCode.ToUpper())).GroupBy(x => x.CurrencyCode);
  16058. foreach (var dc in new_dayOtherCosts)
  16059. {
  16060. var thisCurrency = dc.Key.ToUpper();
  16061. var thisRate = dto.Currencys.Where(x => x.CurrencyCode.ToUpper().Equals(thisCurrency)).First()?.Rate ?? 0.00M;
  16062. if (thisRate == 0.00M) continue;
  16063. foreach (var dcSub in dc)
  16064. {
  16065. opDayOtherCosts.Add(new Grp_DayOtherPriceDraft()
  16066. {
  16067. Id = dcSub.Id,
  16068. ParentId = dcSub.ParentId,
  16069. Cost = dcSub.Cost,
  16070. SubTotal = dcSub.Cost * thisRate,
  16071. // Remark = $"[移动端->汇率变更时费用变更][变更信息:currency:{thisCurrency}、opDatetime:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}、opUserId:{dto.CurrUserId}]"
  16072. });
  16073. }
  16074. }
  16075. if (opDayOtherCosts.Count > 0)
  16076. {
  16077. await _sqlSugar.Updateable(opDayOtherCosts).UpdateColumns(x => new { x.SubTotal }).WhereColumns(x => new { x.Id }).ExecuteCommandAsync();
  16078. }
  16079. }
  16080. #endregion
  16081. ////消息通知
  16082. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16083. ////汇率信息记录
  16084. //await GeneralMethod.RateRecordSave(dto.CurrUserId, id, "出入境费用");
  16085. return Ok(JsonView(new { parentId = id }));
  16086. }
  16087. /// <summary>
  16088. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 复选框
  16089. /// </summary>
  16090. /// <returns></returns>
  16091. [HttpPost]
  16092. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16093. public async Task<IActionResult> EnterExitCostDraftMobileOpCheckbox(PostEnterExitCostDraftMobileFeeOpCheckboxDto dto)
  16094. {
  16095. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16096. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.Id));
  16097. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16098. var checkboxInfo = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  16099. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16100. int id = dto.DraftId;
  16101. if (id <= 0) //add
  16102. {
  16103. checkboxInfo.ProvinceId = dto.ProvinceId;
  16104. checkboxInfo.CreateUserId = dto.CurrUserId;
  16105. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostDraftMobileGetCurrencyInit());
  16106. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  16107. if (add < 1) return Ok(JsonView(false));
  16108. }
  16109. else //update
  16110. {
  16111. var upd = await _sqlSugar.Updateable(checkboxInfo)
  16112. .UpdateColumns(x => new
  16113. {
  16114. x.ChoiceOne,
  16115. x.ChoiceTwo,
  16116. x.SumJJC,
  16117. x.SumGWC,
  16118. x.SumTDC,
  16119. x.ChoiceThree,
  16120. x.ChoiceFour,
  16121. x.ChoiceFive,
  16122. x.ChoiceSix,
  16123. x.OtherExpenses_Checked
  16124. })
  16125. .Where(x => x.Id == id)
  16126. .ExecuteCommandAsync();
  16127. if (upd < 1) return Ok(JsonView(false));
  16128. }
  16129. return Ok(JsonView(new { parentId = id }));
  16130. }
  16131. /// <summary>
  16132. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 3-7项复选框单个复选框
  16133. /// </summary>
  16134. /// <returns></returns>
  16135. [HttpPost]
  16136. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16137. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleCheckbox(EnterExitCostDarftMobileOpSingleCheckboxDto dto)
  16138. {
  16139. int itemTypeId = dto.ItemType, currUserId = dto.CurrUserId, draftId = dto.DraftId, isSelected = dto.IsSelected;
  16140. var itemTypes = new List<int>() { 3, 4, 5, 6, 7 };
  16141. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16142. if (draftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16143. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16144. if (!itemTypes.Contains(itemTypeId)) return Ok(JsonView(false, $"请传入要修改的项类型;3:住宿费; 4:伙食费; 5:公杂费; 6:培训费;7:其他;"));
  16145. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16146. var checkboxInfo = new Grp_EnterExitCostDraft()
  16147. {
  16148. Id = draftId,
  16149. ProvinceId = dto.ProvinceId,
  16150. CreateUserId = currUserId
  16151. };
  16152. if (itemTypeId == 3) checkboxInfo.ChoiceThree = isSelected;
  16153. else if (itemTypeId == 4) checkboxInfo.ChoiceFour = isSelected;
  16154. else if (itemTypeId == 5) checkboxInfo.ChoiceFive = isSelected;
  16155. else if (itemTypeId == 6) checkboxInfo.ChoiceSix = isSelected;
  16156. else if (itemTypeId == 7) checkboxInfo.OtherExpenses_Checked = isSelected;
  16157. if (draftId <= 0) //add
  16158. {
  16159. checkboxInfo.CreateUserId = dto.CurrUserId;
  16160. checkboxInfo.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16161. var add = await _sqlSugar.Insertable(checkboxInfo).ExecuteCommandAsync();
  16162. if (add < 1) return Ok(JsonView(false));
  16163. }
  16164. else //update
  16165. {
  16166. var upd = await _sqlSugar.Updateable<Grp_EnterExitCostDraft>()
  16167. .SetColumnsIF(itemTypeId == 3, it => it.ChoiceThree == isSelected)
  16168. .SetColumnsIF(itemTypeId == 4, it => it.ChoiceFour == isSelected)
  16169. .SetColumnsIF(itemTypeId == 5, it => it.ChoiceFive == isSelected)
  16170. .SetColumnsIF(itemTypeId == 6, it => it.ChoiceSix == isSelected)
  16171. .SetColumnsIF(itemTypeId == 7, it => it.OtherExpenses_Checked == isSelected)
  16172. .Where(x => x.Id == draftId)
  16173. .ExecuteCommandAsync();
  16174. if (upd < 1) return Ok(JsonView(false));
  16175. }
  16176. return Ok(JsonView(new { parentId = draftId }));
  16177. }
  16178. /// <summary>
  16179. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 境内费用 Step1
  16180. /// </summary>
  16181. /// <returns></returns>
  16182. [HttpPost]
  16183. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16184. public async Task<IActionResult> EnterExitCostDraftMobileOpStep1(PostEnterExitCostDraftMobileOpStep1Dto dto)
  16185. {
  16186. int id = dto.DraftId, currUserId = dto.CurrUserId;
  16187. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16188. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  16189. if (currUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16190. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16191. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  16192. info.ProvinceId = dto.ProvinceId;
  16193. info.FirstItemRemark = dto.FirstItemRemark;
  16194. info.InsidePay = dto.Visa + dto.Service + dto.Safe + dto.Ticket + dto.HeSuan + dto.YiMiao;
  16195. if (id <= 0) //add
  16196. {
  16197. info.CreateUserId = dto.CurrUserId;
  16198. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16199. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  16200. if (add < 1) return Ok(JsonView(false));
  16201. id = add;
  16202. }
  16203. else //update
  16204. {
  16205. var upd = await _sqlSugar.Updateable(info)
  16206. .UpdateColumns(x => new
  16207. {
  16208. x.ChoiceOne,
  16209. x.InsidePay,
  16210. x.VisaRemark,
  16211. x.Visa,
  16212. x.Service,
  16213. x.Safe,
  16214. x.Ticket,
  16215. x.HeSuan,
  16216. x.YiMiao,
  16217. x.FirstItemRemark
  16218. })
  16219. .Where(x => x.Id == id)
  16220. .ExecuteCommandAsync();
  16221. if (upd < 1) return Ok(JsonView(false));
  16222. }
  16223. ////消息通知
  16224. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16225. return Ok(JsonView(new { parentId = id, itemTotal = info.InsidePay }));
  16226. }
  16227. /// <summary>
  16228. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 国际旅费 Step2
  16229. /// </summary>
  16230. /// <returns></returns>
  16231. [HttpPost]
  16232. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16233. public async Task<IActionResult> EnterExitCostDraftMobileOpStep2(PostEnterExitCostDraftMobileOpStep2Dto dto)
  16234. {
  16235. int id = dto.DraftId;
  16236. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16237. if (id < 1) return Ok(JsonView(false, MsgTips.DiId));
  16238. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16239. if (dto.ProvinceId < 1) dto.ProvinceId = 122;
  16240. var info = _mapper.Map<Grp_EnterExitCostDraft>(dto);
  16241. info.ProvinceId = dto.ProvinceId;
  16242. info.OutsideJJPay = dto.OutsideJJPay;
  16243. info.OutsideGWPay = dto.OutsideGWPay;
  16244. info.OutsideTDPay = dto.OutsideTDPay;
  16245. info.AirJJ = dto.AirJJ;
  16246. info.AirGW = dto.AirGW;
  16247. info.AirTD = dto.AirTD;
  16248. info.CityTranffic = dto.CityTranffic;
  16249. info.CityTranffic1 = dto.CityTranffic1;
  16250. info.CityTranffic2 = dto.CityTranffic2;
  16251. info.TwoItemRemark = dto.TwoItemRemark;
  16252. info.SumJJC = dto.ChoiceTwoJJ;
  16253. info.SumGWC = dto.ChoiceTwoGW;
  16254. info.SumTDC = dto.ChoiceTwoTD;
  16255. decimal jjcItemTotal = 0.00M, gwcItemTotal = 0.00M, tdcItemTotal = 0.00M;
  16256. if (id <= 0) //add
  16257. {
  16258. info.CreateUserId = dto.CurrUserId;
  16259. info.CurrencyRemark = JsonConvert.SerializeObject(await EnterExitCostMobileGetCurrencyInit());
  16260. var addId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  16261. if (addId <= 0) return Ok(JsonView(false));
  16262. id = addId;
  16263. }
  16264. else //update
  16265. {
  16266. var upd = await _sqlSugar.Updateable(info)
  16267. .UpdateColumns(x => new
  16268. {
  16269. x.SumJJC,
  16270. x.OutsideJJPay,
  16271. x.SumGWC,
  16272. x.OutsideGWPay,
  16273. x.SumTDC,
  16274. x.OutsideTDPay,
  16275. x.AirJJ,
  16276. x.AirGW,
  16277. x.AirTD,
  16278. x.CityTranffic,
  16279. x.CityTranffic1,
  16280. x.CityTranffic2,
  16281. x.TwoItemRemark
  16282. })
  16283. .Where(x => x.Id == id)
  16284. .ExecuteCommandAsync();
  16285. if (upd < 1) return Ok(JsonView(false));
  16286. }
  16287. jjcItemTotal = info.AirJJ + info.CityTranffic;
  16288. gwcItemTotal = info.AirGW + info.CityTranffic;
  16289. tdcItemTotal = info.AirTD + info.CityTranffic;
  16290. ////消息通知
  16291. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16292. return Ok(JsonView(new
  16293. {
  16294. parentId = id,
  16295. choiceTwoJJ = dto.ChoiceTwoJJ,
  16296. jjcItemTotal = jjcItemTotal,
  16297. choiceTwoGW = dto.ChoiceTwoGW,
  16298. gwcItemTotal = gwcItemTotal,
  16299. choiceTwoTD = dto.ChoiceTwoTD,
  16300. tdcItemTotal = tdcItemTotal
  16301. }));
  16302. }
  16303. /// <summary>
  16304. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 批量(住宿、伙食、公杂、培训) Step3-Step6
  16305. /// </summary>
  16306. /// <returns></returns>
  16307. [HttpPost]
  16308. [ApiExplorerSettings(IgnoreApi = true)]
  16309. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16310. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep3To6(PostEnterExitCostDraftMobileOpStep3To6Dto dto)
  16311. {
  16312. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16313. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16314. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16315. if (dto.Infos.Length < 1) return Ok(JsonView(false, "请传入有效的费用信息!"));
  16316. var feeTypeIds = new List<int>() { 1, 2, 3, 4, };
  16317. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  16318. var infos1 = _mapper.Map<List<Grp_DayAndCostDraft>>(dto.Infos);
  16319. var infos = infos1.Select(x => new Grp_DayAndCostDraft
  16320. {
  16321. Id = x.Id,
  16322. ParentId = dto.DraftId,
  16323. Type = dto.FeeType,
  16324. Days = x.Days,
  16325. NationalTravelFeeId = x.NationalTravelFeeId,
  16326. Cost = x.Cost,
  16327. Currency = x.Currency,
  16328. SubTotal = x.SubTotal,
  16329. CreateUserId = dto.CurrUserId
  16330. })
  16331. .ToList();
  16332. var adds = infos.Where(x => x.Id <= 0).ToList();
  16333. var upds = infos.Where(x => x.Id > 0).ToList();
  16334. if (adds.Count > 0)
  16335. {
  16336. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  16337. if (add < 1) return Ok(JsonView(false));
  16338. }
  16339. if (upds.Count > 0)
  16340. {
  16341. var upd = await _sqlSugar.Updateable(adds)
  16342. .UpdateColumns(x => new
  16343. {
  16344. x.Days,
  16345. x.NationalTravelFeeId,
  16346. x.Cost,
  16347. x.Currency,
  16348. x.SubTotal
  16349. })
  16350. .WhereColumns(x => new { x.Id })
  16351. .ExecuteCommandAsync();
  16352. if (upd < 1) return Ok(JsonView(false));
  16353. }
  16354. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == dto.FeeType).Sum(x => x.SubTotal);
  16355. ////消息通知
  16356. //var id = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).First()?.Id ?? 0;
  16357. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16358. return Ok(JsonView(new { itemTotal = itemTotal }));
  16359. }
  16360. /// <summary>
  16361. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 单条(住宿、伙食、公杂、培训) Step3-Step6
  16362. /// </summary>
  16363. /// <returns></returns>
  16364. [HttpPost]
  16365. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16366. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep3To6(PostEnterExitCostDraftMobileOpSingleStep3To6Dto dto)
  16367. {
  16368. var feeTypeIds = new List<int>() { 3, 4, 5, 6 };
  16369. int subId = dto.SubId, feeType = dto.FeeType;
  16370. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16371. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16372. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16373. if (!feeTypeIds.Contains(dto.FeeType)) return Ok(JsonView(false, "请传入有效的费用类型!"));
  16374. var subInfo = _mapper.Map<Grp_DayAndCostDraft>(dto);
  16375. subInfo.Id = subId;
  16376. subInfo.ParentId = dto.DraftId;
  16377. if (feeType == 3) subInfo.Type = 1;
  16378. else if (feeType == 4) subInfo.Type = 2;
  16379. else if (feeType == 5) subInfo.Type = 3;
  16380. else if (feeType == 6) subInfo.Type = 4;
  16381. subInfo.CreateUserId = dto.CurrUserId;
  16382. int parentId = await EnterExitCostDraftVerifyIsNull(dto.DraftId, dto.CurrUserId); //主表验证
  16383. if (parentId < 1) return Ok(JsonView(false));
  16384. //子表op
  16385. if (subId < 1)
  16386. {
  16387. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  16388. if (subAdd < 1) return Ok(JsonView(false));
  16389. }
  16390. else
  16391. {
  16392. var subUpd = await _sqlSugar.Updateable(subInfo)
  16393. .UpdateColumns(x => new
  16394. {
  16395. x.Days,
  16396. x.NationalTravelFeeId,
  16397. x.Cost,
  16398. x.Currency,
  16399. x.SubTotal
  16400. })
  16401. .WhereColumns(x => new { x.Id })
  16402. .ExecuteCommandAsync();
  16403. if (subUpd < 1) return Ok(JsonView(false));
  16404. }
  16405. var itemTotal = _sqlSugar.Queryable<Grp_DayAndCostDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId && x.Type == feeType).Sum(x => x.SubTotal);
  16406. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  16407. }
  16408. /// <summary>
  16409. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-批量 Step7
  16410. /// </summary>
  16411. /// <returns></returns>
  16412. [HttpPost]
  16413. [ApiExplorerSettings(IgnoreApi = true)]
  16414. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16415. public async Task<IActionResult> EnterExitCostDraftMobileOpBatchStep7(PostEnterExitCostDraftMobileOpStep7Dto dto)
  16416. {
  16417. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16418. if (dto.DraftId < 1) return Ok(JsonView(false, MsgTips.DiId));
  16419. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16420. var infos1 = _mapper.Map<List<Grp_DayOtherPriceDraft>>(dto.Infos);
  16421. var infos = infos1.Select(x => new Grp_DayOtherPriceDraft()
  16422. {
  16423. Id = x.Id,
  16424. ParentId = dto.DraftId,
  16425. SetDataId = x.SetDataId,
  16426. Index = x.Index,
  16427. Cost = x.Cost,
  16428. Currency = x.Currency,
  16429. SubTotal = x.SubTotal,
  16430. CreateUserId = dto.CurrUserId,
  16431. Remark = x.Remark
  16432. }).ToList();
  16433. var adds = infos.Where(x => x.Id <= 0).ToList();
  16434. var upds = infos.Where(x => x.Id > 0).ToList();
  16435. if (adds.Count > 0)
  16436. {
  16437. var add = await _sqlSugar.Insertable(adds).ExecuteCommandAsync();
  16438. if (add < 1) return Ok(JsonView(false));
  16439. }
  16440. if (upds.Count > 0)
  16441. {
  16442. var upd = await _sqlSugar.Updateable(adds)
  16443. .UpdateColumns(x => new
  16444. {
  16445. x.Index,
  16446. x.SetDataId,
  16447. x.Cost,
  16448. x.Currency,
  16449. x.SubTotal,
  16450. x.Remark
  16451. })
  16452. .WhereColumns(x => new { x.Id })
  16453. .ExecuteCommandAsync();
  16454. if (upd < 1) return Ok(JsonView(false));
  16455. }
  16456. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == dto.DraftId).Sum(x => x.SubTotal);
  16457. //消息通知
  16458. //var id = _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0 && x.Id == dto.DraftId).First()?.Id ?? 0;
  16459. //await EnterExitCostMobileOpNotice(dto.DiId, id, dto.CurrUserId);
  16460. return Ok(JsonView(new { itemTotal = itemTotal }));
  16461. }
  16462. /// <summary>
  16463. /// 团组模块 - 出入境费用-草稿-移动端 - OP --> 其他费用-单条 Step7
  16464. /// </summary>
  16465. /// <returns></returns>
  16466. [HttpPost]
  16467. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16468. public async Task<IActionResult> EnterExitCostDraftMobileOpSingleStep7(PostEnterExitCostDraftMobileOpSingleStep7Dto dto)
  16469. {
  16470. int subId = dto.SubId, id = dto.DraftId;
  16471. if (!_portTypeData.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
  16472. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  16473. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16474. var subInfo = _mapper.Map<Grp_DayOtherPriceDraft>(dto);
  16475. subInfo.Id = subId;
  16476. subInfo.ParentId = id;
  16477. subInfo.CreateUserId = dto.CurrUserId;
  16478. int parentId = await EnterExitCostDraftVerifyIsNull(id, dto.CurrUserId); //主表验证
  16479. if (parentId < 1) return Ok(JsonView(false));
  16480. #region 子表op
  16481. if (subId < 1)//add
  16482. {
  16483. var subAdd = await _sqlSugar.Insertable(subInfo).ExecuteCommandAsync();
  16484. if (subAdd < 1) return Ok(JsonView(false));
  16485. }
  16486. else //upd
  16487. {
  16488. var subUpd = await _sqlSugar.Updateable(subInfo)
  16489. .UpdateColumns(x => new
  16490. {
  16491. x.Index,
  16492. x.SetDataId,
  16493. x.Cost,
  16494. x.Currency,
  16495. x.SubTotal,
  16496. x.Remark
  16497. })
  16498. .WhereColumns(x => new { x.Id })
  16499. .ExecuteCommandAsync();
  16500. if (subUpd < 1) return Ok(JsonView(false));
  16501. }
  16502. #endregion
  16503. var itemTotal = _sqlSugar.Queryable<Grp_DayOtherPriceDraft>().Where(x => x.IsDel == 0 && x.ParentId == id).Sum(x => x.SubTotal);
  16504. ////消息通知
  16505. //await EnterExitCostMobileOpNotice(dto.Diid, parentId, dto.CurrUserId);
  16506. return Ok(JsonView(new { parentId = parentId, itemTotal = itemTotal }));
  16507. }
  16508. /// <summary>
  16509. /// 团组模块 - 出入境费用-草稿-移动端 - 3-6子项删除
  16510. /// </summary>
  16511. /// <returns></returns>
  16512. [HttpPost]
  16513. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16514. public async Task<IActionResult> EnterExitCostDraftMobileSubItemDel(EnterExitCostDraftSubItemDelDto dto)
  16515. {
  16516. var data = await _enterExitCostDraftRep.EnterExitCostDraftSubItemDel(dto);
  16517. if (data.Code != 0)
  16518. {
  16519. return Ok(JsonView(false, data.Msg));
  16520. }
  16521. return Ok(JsonView(true, "操作成功!", data.Data));
  16522. }
  16523. /// <summary>
  16524. /// 团组模块 - 出入境费用-草稿-移动端 - 其他费用删除
  16525. /// </summary>
  16526. /// <param name="dto"></param>
  16527. /// <returns></returns>
  16528. [HttpPost]
  16529. public IActionResult EnterExitCostDraftMobileOtherFeeDel(EnterExitCostDraftSubItemDelDto dto)
  16530. {
  16531. var data = new Grp_DayOtherPriceDraft()
  16532. {
  16533. Id = dto.Id,
  16534. IsDel = 1,
  16535. DeleteUserId = dto.DeleteUserId,
  16536. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
  16537. };
  16538. var del = _sqlSugar.Updateable(data).UpdateColumns(it => new { it.IsDel, it.DeleteUserId, it.DeleteTime }).ExecuteCommand();
  16539. if (del > 0) return Ok(JsonView(true, "删除成功!"));
  16540. return Ok(JsonView(false, "删除失败!"));
  16541. }
  16542. #endregion
  16543. #endregion
  16544. #region 团组经理模块 出入境费用报价表
  16545. /// <summary>
  16546. /// 团组模块 - 出入境费用报价表 - 初始化数据源(币种类型)
  16547. /// </summary>
  16548. /// <returns></returns>
  16549. [HttpPost]
  16550. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16551. public async Task<IActionResult> EnterExitCostQuoteInitData(PortDtoBase dto)
  16552. {
  16553. var initRates = await GeneralMethod.EnterExitCostInitRate();
  16554. var liveRates = await GeneralMethod.EnterExitCostLiveRate();
  16555. var cnyInfo = new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.0000M };
  16556. initRates.Insert(0, cnyInfo);
  16557. liveRates.Insert(0, cnyInfo);
  16558. return Ok(JsonView(true, "查询成功!", new
  16559. {
  16560. InitRates = initRates,
  16561. LiveRates = liveRates
  16562. }));
  16563. }
  16564. /// <summary>
  16565. /// 团组模块 - 出入境费用报价表 - 报价表名称列表
  16566. /// </summary>
  16567. /// <returns></returns>
  16568. [HttpPost]
  16569. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16570. public async Task<IActionResult> EnterExitCostQuoteNameList(EnterExitCostQuoteNameListDto dto)
  16571. {
  16572. return Ok(await _enterExitCostQuoteRep.QuoteNameListAsync(dto));
  16573. }
  16574. /// <summary>
  16575. /// 团组模块 - 出入境费用报价表 - 团组名称列表
  16576. /// </summary>
  16577. /// <returns></returns>
  16578. [HttpPost]
  16579. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16580. public async Task<IActionResult> EnterExitCostQuoteGroupNameList(EnterExitCostQuoteGroupNameListDto dto)
  16581. {
  16582. return Ok(await _enterExitCostQuoteRep.GroupNameListAsync(dto));
  16583. }
  16584. /// <summary>
  16585. /// 团组模块 - 出入境费用报价表 - 根据团组Id获出入境费用相关信息
  16586. /// </summary>
  16587. /// <returns></returns>
  16588. [HttpPost]
  16589. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16590. public async Task<IActionResult> EnterExitCostQuoteEntryExitCosts(EnterExitCostInfobyDiIdDto dto)
  16591. {
  16592. int groupId = dto.DiId,
  16593. currUserId = dto.CurrUserId;
  16594. if (groupId < 1) return Ok(JsonView(false, "请传入有效的GroupId;"));
  16595. if (currUserId < 1) return Ok(JsonView(false, "请传入有效的CurrUserId;"));
  16596. //验证报价数据是否存在
  16597. var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.GroupId == dto.DiId);
  16598. if (isNull != null)
  16599. {
  16600. var info1 = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = isNull.Id });
  16601. if (!info1.Rates.Any())
  16602. {
  16603. var rates = await GeneralMethod.EnterExitCostInitRate();
  16604. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16605. info1.Rates = rates.ToArray();
  16606. }
  16607. return Ok(JsonView(info1));
  16608. }
  16609. var result = await _enterExitCostQuoteRep.InfoByGroupIdAsync(dto.DiId);
  16610. result.GroupId = groupId;
  16611. //处理报价名称
  16612. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.DiId && x.IsDel == 0);
  16613. if (groupInfo != null)
  16614. {
  16615. var visitCountry = groupInfo.VisitCountry;
  16616. if (!string.IsNullOrEmpty(visitCountry))
  16617. {
  16618. string quoteName = string.Empty;
  16619. if (visitCountry.Contains("|"))
  16620. {
  16621. var countrys = visitCountry.Split("|");
  16622. quoteName = string.Join("、", countrys);
  16623. }
  16624. else quoteName = visitCountry;
  16625. quoteName += $"团组报价表";
  16626. result.Name = quoteName;
  16627. }
  16628. }
  16629. var info = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
  16630. if (info.Code != StatusCodes.Status200OK)
  16631. {
  16632. if (!result.Rates.Any())
  16633. {
  16634. var rates = await GeneralMethod.EnterExitCostInitRate();
  16635. result.Rates = rates.ToArray();
  16636. }
  16637. return Ok(JsonView(true, $"出入境费用明细未填写!", result));
  16638. }
  16639. var infoView = info.Data as EnterExitCostInfoView;
  16640. if (infoView == null) return Ok(JsonView(false, "数据类型转换失败!;"));
  16641. var countryFees = await _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).ToListAsync();
  16642. var cityFilter = new List<string>() { "全部城市", "其他城市" };
  16643. var currencys = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
  16644. var eecRates = infoView.Currencys;
  16645. //默认添加人名币
  16646. if (!eecRates.Any(x => x.CurrencyCode.Equals("CNY")))
  16647. {
  16648. eecRates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16649. }
  16650. //处理团组人数
  16651. int pplNum = 1;
  16652. if (groupInfo != null) pplNum = groupInfo.VisitPNumber;
  16653. var views = new List<QuoteSubItemInfo>();
  16654. #region 数据填充
  16655. var intTravelCosts = new List<QuoteSubItemInfo>();
  16656. #region 机票费用 1354
  16657. int intTravelIndex = 1;
  16658. if (infoView.SumJJC == 1)
  16659. {
  16660. intTravelCosts.Add(new QuoteSubItemInfo
  16661. {
  16662. ItemId = 1354,
  16663. Index = intTravelIndex,
  16664. FeeName = "经济舱",
  16665. UnitPrice = infoView.AirJJ,
  16666. Currency = "CNY",
  16667. Quantity = 1,
  16668. PplNum = 1,
  16669. TotalAmt = infoView.AirJJ,
  16670. Remark = "",
  16671. });
  16672. intTravelIndex++;
  16673. }
  16674. if (infoView.SumGWC == 1)
  16675. {
  16676. intTravelCosts.Add(new QuoteSubItemInfo
  16677. {
  16678. ItemId = 1354,
  16679. Index = intTravelIndex,
  16680. FeeName = "公务舱",
  16681. UnitPrice = infoView.AirGW,
  16682. Currency = "CNY",
  16683. Quantity = 1,
  16684. PplNum = 1,
  16685. TotalAmt = infoView.AirGW,
  16686. Remark = "",
  16687. });
  16688. intTravelIndex++;
  16689. }
  16690. if (infoView.SumTDC == 1)
  16691. {
  16692. intTravelCosts.Add(new QuoteSubItemInfo
  16693. {
  16694. ItemId = 1354,
  16695. Index = intTravelIndex,
  16696. FeeName = "头等舱",
  16697. UnitPrice = infoView.AirTD,
  16698. Currency = "CNY",
  16699. Quantity = 1,
  16700. PplNum = 1,
  16701. TotalAmt = infoView.AirTD,
  16702. Remark = "",
  16703. });
  16704. intTravelIndex++;
  16705. }
  16706. intTravelCosts.Add(new QuoteSubItemInfo
  16707. {
  16708. ItemId = 1354,
  16709. Index = intTravelIndex,
  16710. FeeName = "城市间交通费用(经济舱)",
  16711. UnitPrice = infoView.CityTranffic,
  16712. Currency = "CNY",
  16713. Quantity = 1,
  16714. PplNum = pplNum,
  16715. TotalAmt = infoView.CityTranffic * pplNum,
  16716. Remark = "",
  16717. });
  16718. intTravelCosts.Add(new QuoteSubItemInfo
  16719. {
  16720. ItemId = 1354,
  16721. Index = intTravelIndex,
  16722. FeeName = "城市间交通费用(公务舱)",
  16723. UnitPrice = infoView.CityTranffic1,
  16724. Currency = "CNY",
  16725. Quantity = 1,
  16726. PplNum = pplNum,
  16727. TotalAmt = infoView.CityTranffic1 * pplNum,
  16728. Remark = "",
  16729. });
  16730. intTravelCosts.Add(new QuoteSubItemInfo
  16731. {
  16732. ItemId = 1354,
  16733. Index = intTravelIndex,
  16734. FeeName = "城市间交通费用(头等舱)",
  16735. UnitPrice = infoView.CityTranffic2,
  16736. Currency = "CNY",
  16737. Quantity = 1,
  16738. PplNum = pplNum,
  16739. TotalAmt = infoView.CityTranffic2 * pplNum,
  16740. Remark = "",
  16741. });
  16742. views.AddRange(intTravelCosts);
  16743. #endregion
  16744. var accomCosts = new List<QuoteSubItemInfo>();
  16745. #region 住宿费 1355
  16746. if (infoView.QuarterageData.Any())
  16747. {
  16748. int accomIndex = 1;
  16749. int accomItemTypeId = 1355;
  16750. var groupData = infoView.QuarterageData.GroupBy(x => x.NationalTravelFeeId);
  16751. foreach (var item in groupData)
  16752. {
  16753. string feeName = string.Empty;
  16754. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16755. if (countryInfo != null)
  16756. {
  16757. feeName = countryInfo.Country;
  16758. var city = countryInfo.City;
  16759. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16760. {
  16761. feeName += $"-{city}";
  16762. }
  16763. }
  16764. var hotelInfo = item.FirstOrDefault();
  16765. if (hotelInfo == null) continue;
  16766. var thisCurrency = currencys.FirstOrDefault(x => x.Id == hotelInfo.Currency)?.Name ?? "nuknow";
  16767. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16768. int quantity = item.ToList().Count;
  16769. accomCosts.Add(new QuoteSubItemInfo
  16770. {
  16771. ItemId = accomItemTypeId,
  16772. Index = accomIndex,
  16773. FeeName = feeName,
  16774. UnitPrice = hotelInfo.Cost,
  16775. Currency = thisCurrency,
  16776. Quantity = quantity,
  16777. PplNum = pplNum,
  16778. TotalAmt = hotelInfo.Cost * thisRate * quantity * pplNum,
  16779. Remark = "",
  16780. });
  16781. accomIndex++;
  16782. }
  16783. views.AddRange(accomCosts);
  16784. }
  16785. #endregion
  16786. var mealCosts = new List<QuoteSubItemInfo>();
  16787. #region 餐饮费 1356
  16788. if (infoView.BoardWagesData.Any())
  16789. {
  16790. var mealIndex = 1;
  16791. int mealItemTypeId = 1356;
  16792. var groupData = infoView.BoardWagesData.GroupBy(x => x.NationalTravelFeeId);
  16793. foreach (var item in groupData)
  16794. {
  16795. string feeName = string.Empty;
  16796. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16797. if (countryInfo != null)
  16798. {
  16799. feeName = countryInfo.Country;
  16800. var city = countryInfo.City;
  16801. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16802. {
  16803. feeName += $"-{city}";
  16804. }
  16805. }
  16806. var mealInfo = item.FirstOrDefault();
  16807. if (mealInfo == null) continue;
  16808. var thisCurrency = currencys.FirstOrDefault(x => x.Id == mealInfo.Currency)?.Name ?? "nuknow";
  16809. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16810. int quantity = item.ToList().Count;
  16811. mealCosts.Add(new QuoteSubItemInfo
  16812. {
  16813. ItemId = mealItemTypeId,
  16814. Index = mealIndex,
  16815. FeeName = feeName,
  16816. UnitPrice = mealInfo.Cost,
  16817. Currency = thisCurrency,
  16818. Quantity = quantity,
  16819. PplNum = pplNum,
  16820. TotalAmt = mealInfo.Cost * thisRate * quantity * pplNum,
  16821. Remark = "",
  16822. });
  16823. mealIndex++;
  16824. }
  16825. views.AddRange(mealCosts);
  16826. }
  16827. #endregion
  16828. var miscCosts = new List<QuoteSubItemInfo>();
  16829. #region 公杂费 1364
  16830. if (infoView.MiscellaneousFeeData.Any())
  16831. {
  16832. var miscIndex = 1;
  16833. int miscItemTypeId = 1364;
  16834. var groupData = infoView.MiscellaneousFeeData.GroupBy(x => x.NationalTravelFeeId);
  16835. foreach (var item in groupData)
  16836. {
  16837. string feeName = string.Empty;
  16838. var countryInfo = countryFees.FirstOrDefault(x => x.Id == item.Key);
  16839. if (countryInfo != null)
  16840. {
  16841. feeName = countryInfo.Country;
  16842. var city = countryInfo.City;
  16843. if (!string.IsNullOrEmpty(city) && cityFilter.Any(x => !x.Contains(city)))
  16844. {
  16845. feeName += $"-{city}";
  16846. }
  16847. }
  16848. var miscInfo = item.FirstOrDefault();
  16849. if (miscInfo == null) continue;
  16850. var thisCurrency = currencys.FirstOrDefault(x => x.Id == miscInfo.Currency)?.Name ?? "nuknow";
  16851. var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
  16852. int quantity = item.ToList().Count;
  16853. miscCosts.Add(new QuoteSubItemInfo
  16854. {
  16855. ItemId = miscItemTypeId,
  16856. Index = miscIndex,
  16857. FeeName = feeName,
  16858. UnitPrice = miscInfo.Cost,
  16859. Currency = thisCurrency,
  16860. Quantity = quantity,
  16861. PplNum = pplNum,
  16862. TotalAmt = miscInfo.Cost * thisRate * quantity * pplNum,
  16863. Remark = "",
  16864. });
  16865. miscIndex++;
  16866. }
  16867. views.AddRange(miscCosts);
  16868. }
  16869. #endregion
  16870. #region 签证+保险 1362
  16871. int visaInsIndex = 1;
  16872. int visaInsItemTypeId = 1362;
  16873. if (infoView.Visa > 0)
  16874. {
  16875. views.Add(new QuoteSubItemInfo()
  16876. {
  16877. ItemId = visaInsItemTypeId,
  16878. Index = visaInsIndex,
  16879. FeeName = $"签证",
  16880. UnitPrice = infoView.Visa,
  16881. Currency = $"CNY",
  16882. Quantity = 1,
  16883. PplNum = pplNum,
  16884. TotalAmt = infoView.Visa * pplNum,
  16885. Remark = "",
  16886. });
  16887. visaInsIndex++;
  16888. }
  16889. if (infoView.Safe > 0)
  16890. {
  16891. views.Add(new QuoteSubItemInfo()
  16892. {
  16893. ItemId = visaInsItemTypeId,
  16894. Index = visaInsIndex,
  16895. FeeName = $"保险",
  16896. UnitPrice = infoView.Safe,
  16897. Currency = $"CNY",
  16898. Quantity = 1,
  16899. PplNum = pplNum,
  16900. TotalAmt = infoView.Safe * pplNum,
  16901. Remark = "",
  16902. });
  16903. }
  16904. #endregion
  16905. #region 服务费 1363
  16906. int serviceFeeIndex = 1;
  16907. int serviceFeeItemTypeId = 1363;
  16908. if (infoView.Service > 0)
  16909. {
  16910. views.Add(new QuoteSubItemInfo()
  16911. {
  16912. ItemId = serviceFeeItemTypeId,
  16913. Index = serviceFeeIndex,
  16914. FeeName = $"服务费",
  16915. UnitPrice = infoView.Service,
  16916. Currency = $"CNY",
  16917. Quantity = 1,
  16918. PplNum = pplNum,
  16919. TotalAmt = infoView.Service * pplNum,
  16920. Remark = "",
  16921. });
  16922. }
  16923. #endregion
  16924. #endregion
  16925. if (result.FeeItems.Any())
  16926. {
  16927. result.FeeItems.Select(x =>
  16928. {
  16929. var feeInfos = views.Where(y => y.ItemId == x.ItemId).OrderBy(y => y.Index).ToArray();
  16930. if (feeInfos.Any()) x.Infos = feeInfos;
  16931. return x;
  16932. }
  16933. ).OrderBy(x => x.Index)
  16934. .ToList();
  16935. if (!result.Rates.Any())
  16936. {
  16937. if (eecRates.Any()) result.Rates = eecRates?.ToArray() ?? Array.Empty<CurrencyInfo>();
  16938. else
  16939. {
  16940. var rates = await GeneralMethod.EnterExitCostInitRate();
  16941. rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16942. result.Rates = rates.ToArray();
  16943. }
  16944. }
  16945. }
  16946. return Ok(JsonView(result));
  16947. }
  16948. /// <summary>
  16949. /// 团组模块 - 出入境费用报价表 - Info
  16950. /// </summary>
  16951. /// <returns></returns>
  16952. [HttpPost]
  16953. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16954. public async Task<IActionResult> EnterExitCostQuoteInfo(EnterExitCostQuoteInfoDto dto)
  16955. {
  16956. var info = await _enterExitCostQuoteRep.InfoAsync(dto);
  16957. if (!info.Rates.Any())
  16958. {
  16959. var rates = await GeneralMethod.EnterExitCostInitRate();
  16960. rates.Add(new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
  16961. info.Rates = rates.ToArray();
  16962. }
  16963. return Ok(JsonView(info));
  16964. }
  16965. /// <summary>
  16966. /// 团组模块 - 出入境费用报价表 - OP
  16967. /// </summary>
  16968. /// <returns></returns>
  16969. [HttpPost]
  16970. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16971. public async Task<IActionResult> EnterExitCostQuoteOp(EnterExitCostQuoteOpDto dto)
  16972. {
  16973. return Ok(await _enterExitCostQuoteRep.OpAsync(dto));
  16974. }
  16975. /// <summary>
  16976. /// 团组模块 - 出入境费用报价表 - 删除 项
  16977. /// </summary>
  16978. /// <returns></returns>
  16979. [HttpPost]
  16980. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16981. public async Task<IActionResult> EnterExitCostQuoteItemDel(EnterExitCostQuoteItemDelDto dto)
  16982. {
  16983. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  16984. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16985. return Ok(await _enterExitCostQuoteRep.ItemDelAsync(dto));
  16986. }
  16987. /// <summary>
  16988. /// 团组模块 - 出入境费用报价表 - 导出
  16989. /// </summary>
  16990. /// <returns></returns>
  16991. [HttpPost]
  16992. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  16993. public async Task<IActionResult> EnterExitCostQuoteExcelExport(EnterExitCostQuoteExcelExportDto dto)
  16994. {
  16995. if (dto.Id < 1) return Ok(JsonView(false, MsgTips.Id));
  16996. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  16997. var info = await _enterExitCostQuoteRep.InfoAsync(new EnterExitCostQuoteInfoDto() { Id = dto.Id });
  16998. if (info == null) return Ok(JsonView(false, "报价信息未填写!"));
  16999. var rates = info.Rates;
  17000. var intTravelCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1354);//国际旅费
  17001. var accomCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1355); //住宿费
  17002. var mealCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1356); //餐饮费
  17003. var vehArranges = info.FeeItems.FirstOrDefault(x => x.ItemId == 1357); //车辆安排
  17004. var inviteTo = info.FeeItems.FirstOrDefault(x => x.ItemId == 1358); //邀请函发放对象
  17005. var inviteCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1359); //邀请函费用
  17006. var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1360); //邀请函发放时间
  17007. var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1361); //公务活动
  17008. var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1362); //签证+保险
  17009. var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1363); //服务费
  17010. var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1364); //公杂费
  17011. var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1365); //税费
  17012. //获取模板
  17013. string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/出入境费用明细报价表模板.xlsx";
  17014. var designer = new WorkbookDesigner();
  17015. designer.Workbook = new Workbook(tempPath);
  17016. designer.SetDataSource("QuoteName", info.Name);
  17017. designer.SetDataSource("CompanyTitle", "公司名称");
  17018. designer.SetDataSource("CompanyLabel", "");
  17019. #region 国际旅费
  17020. designer.SetDataSource("IntTravelTitle", intTravelCosts?.ItemWrapName ?? "国际旅费\r\n(公务舱和经济舱分别罗列)");
  17021. if (intTravelCosts != null && intTravelCosts.Infos.Any())
  17022. {
  17023. var cabClassFilter = new string[] { "经济舱", "公务舱", "头等舱" };
  17024. var label = new StringBuilder();
  17025. var infos = intTravelCosts.Infos.Where(x => cabClassFilter.Contains(x.FeeName)).ToArray();
  17026. if (infos.Any())
  17027. {
  17028. label.Append(infos.Sum(x => x.PplNum));
  17029. label.Append("人全程机票:");
  17030. label.Append(infos.Sum(x => x.TotalAmt).TruncDecimals(2));
  17031. label.AppendLine("元");
  17032. }
  17033. foreach (var item in intTravelCosts.Infos)
  17034. {
  17035. label.Append(item.FeeName);
  17036. label.Append(":");
  17037. label.Append(item.UnitPrice.TruncDecimals(2));
  17038. label.Append("元/人*");
  17039. label.Append(item.PplNum);
  17040. label.AppendLine("人");
  17041. }
  17042. if (label.HasValue())
  17043. {
  17044. label.Append("\r\n以上小计:");
  17045. label.Append(intTravelCosts.TotalAmt.TruncDecimals(2));
  17046. label.Append("元");
  17047. }
  17048. designer.SetDataSource("IntTravelLabel", label.ToString());
  17049. }
  17050. #endregion
  17051. #region 住宿费
  17052. designer.SetDataSource("AccomTitle", accomCosts?.ItemWrapName ?? "住宿费\r\n(请备注明酒店星级)");
  17053. if (accomCosts != null && accomCosts.Infos.Any())
  17054. {
  17055. string currencyName = string.Empty,
  17056. countryName = string.Empty;
  17057. decimal rate = 1.0000M;
  17058. var label = new StringBuilder();
  17059. label.AppendLine("全程五星酒店,每人1间房");
  17060. foreach (var item in accomCosts.Infos)
  17061. {
  17062. //乌兹别克斯坦: 塔什干:120美金/间/晚*2*6人
  17063. string name = string.Empty, thisCountryName = string.Empty;
  17064. if (item.FeeName.Contains('-'))
  17065. {
  17066. var feeName = item.FeeName.Split('-');
  17067. thisCountryName = feeName[0];
  17068. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  17069. name = feeName[1];
  17070. }
  17071. else name = item.FeeName;
  17072. string thisFeeName = string.Empty;
  17073. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  17074. else thisFeeName = $"\r\n{name}:";
  17075. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  17076. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  17077. rate = rateInfo?.Rate ?? 1.0000M;
  17078. string subLabel = string.Format("{0}{1}{2}/间/晚*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity.ToString("#0"), item.PplNum.ToString("#0"));
  17079. label.AppendLine(subLabel);
  17080. }
  17081. if (label.HasValue())
  17082. {
  17083. //以上小计:52440元(美金汇率:7.5 )
  17084. string subLabel = string.Format("\r\n以上小计:{0}元({1}汇率:{2})", accomCosts.TotalAmt.TruncDecimals(2), currencyName, rate.TruncDecimals(4));
  17085. label.AppendLine(subLabel);
  17086. }
  17087. designer.SetDataSource("AccomLabel", label.ToString());
  17088. }
  17089. #endregion
  17090. #region 餐饮费
  17091. designer.SetDataSource("MealTitle", mealCosts?.ItemWrapName ?? "餐饮费");
  17092. if (mealCosts != null && mealCosts.Infos.Any())
  17093. {
  17094. string currencyName = string.Empty;
  17095. decimal rate = 1.0000M;
  17096. var label = new StringBuilder();
  17097. label.Append("全程酒店含早,\r\n若因航班过早,\r\n酒店准备路早。\r\n\r\n");
  17098. foreach (var item in mealCosts.Infos)
  17099. {
  17100. string name = string.Empty;
  17101. if (item.FeeName.Contains('-'))
  17102. {
  17103. var feeName = item.FeeName.Split('-');
  17104. name = $"\r\n{feeName[0]}:\r\n{feeName[1]}:";
  17105. }
  17106. else name = $"\r\n{item.FeeName}:";
  17107. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  17108. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  17109. rate = rateInfo?.Rate ?? 1.0000M;
  17110. label.Append(name);
  17111. label.Append(item.UnitPrice.TruncDecimals(2));
  17112. label.Append(currencyName);
  17113. label.Append("/天*");
  17114. label.Append(item.Quantity.ToString("#0"));
  17115. label.Append('*');
  17116. label.Append(item.PplNum);
  17117. label.Append("人\r\n");
  17118. }
  17119. if (label.HasValue())
  17120. {
  17121. label.Append("\r\n以上小计:");
  17122. label.Append(accomCosts.TotalAmt.TruncDecimals(2));
  17123. label.Append("元\r\n(");
  17124. label.Append("汇率:");
  17125. label.Append(rate.TruncDecimals(4));
  17126. label.Append(')');
  17127. }
  17128. designer.SetDataSource("MealLabel", label.ToString());
  17129. }
  17130. #endregion
  17131. #region 车辆安排
  17132. designer.SetDataSource("VehArrangeTitle", vehArranges?.ItemWrapName ?? "车辆安排\r\n(司兼导分开的情况下,车辆品牌、座位及费用)");
  17133. if (vehArranges != null && vehArranges.Infos.Any())
  17134. {
  17135. string currencyName = string.Empty;
  17136. //decimal rate = 1.0000M;
  17137. var label = new StringBuilder();
  17138. foreach (var item in vehArranges.Infos)
  17139. {
  17140. label.AppendLine();
  17141. label.AppendLine();
  17142. label.Append(item.FeeName);
  17143. label.Append($"\r\n\r\n费用:{item.TotalAmt.TruncDecimals(2)}元");
  17144. }
  17145. designer.SetDataSource("VehArrangeLabel", label.ToString());
  17146. }
  17147. #endregion
  17148. #region 邀请函发放对象
  17149. designer.SetDataSource("InviteToTitle", inviteTo?.ItemWrapName ?? "邀请函发放对象");
  17150. designer.SetDataSource("InviteToContent", "");
  17151. #endregion
  17152. #region 邀请函费
  17153. designer.SetDataSource("InviteCostTitle", inviteCosts?.ItemWrapName ?? "邀请函费用");
  17154. var is_label = new StringBuilder();
  17155. if (inviteCosts != null && inviteCosts.Infos.Any())
  17156. {
  17157. string currencyName = string.Empty;
  17158. decimal rate = 1.0000M;
  17159. foreach (var item in inviteCosts.Infos)
  17160. {
  17161. //乌兹别克斯坦:2000美金
  17162. currencyName = item.Currency;
  17163. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  17164. string label = string.Format("{0}:{1}{2}", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName);
  17165. is_label.AppendLine(label);
  17166. }
  17167. if (is_label.HasValue())
  17168. {
  17169. //以上小计:28500元(美金汇率:7.5)
  17170. string label = string.Format("以上小计:{0}{1}({2}汇率:{3})", inviteCosts.TotalAmt.TruncDecimals(2), "元", currencyName, rate.TruncDecimals(4));
  17171. is_label.AppendLine(label);
  17172. }
  17173. }
  17174. designer.SetDataSource("InviteCostContent", is_label.ToString());
  17175. #endregion
  17176. #region 邀请函发放时间
  17177. designer.SetDataSource("InviteToTimeTitle", inviteTime?.ItemWrapName ?? "邀请函发放时间");
  17178. designer.SetDataSource("InviteToTimeContent", "拿到团员名单10-15工作日");
  17179. #endregion
  17180. #region 公务活动(含翻译)
  17181. designer.SetDataSource("OfficialActsTitle", officialActs?.ItemWrapName ?? "公务活动(含翻译)");
  17182. var oa_label = new StringBuilder();
  17183. if (officialActs != null && officialActs.Infos.Any())
  17184. {
  17185. string currencyName = string.Empty;
  17186. decimal rate = 1.0000M;
  17187. string label_title = string.Empty, label_content = "超出报价部分需额付费:\r\n";
  17188. foreach (var item in officialActs.Infos)
  17189. {
  17190. //乌兹别克斯坦:1000美金/场
  17191. currencyName = item.Currency;
  17192. rate = rates.FirstOrDefault(x => currencyName.Equals(x.CurrencyCode))?.Rate ?? 1.0000M;
  17193. string label_remark = string.Empty;
  17194. if (!string.IsNullOrEmpty(item.Remark)) label_remark = $"({item.Remark})";
  17195. label_content += string.Format("{0}:{1}{2}/场{3}\r\n", item.FeeName, item.UnitPrice.TruncDecimals(2), currencyName, label_remark);
  17196. }
  17197. label_content += "*总费用中未含超出公务活动价格";
  17198. //8场公务活动(以上小计:60000元)
  17199. var quantity = officialActs.Infos.Sum(x => x.Quantity);
  17200. label_title = string.Format("{0}场公务活动(以上小计:{1}元)", quantity, officialActs.TotalAmt.TruncDecimals(2));
  17201. oa_label.AppendLine(label_title);
  17202. oa_label.AppendLine(label_content);
  17203. }
  17204. designer.SetDataSource("OfficialActsContent", oa_label.ToString());
  17205. #endregion
  17206. #region 签证+保险
  17207. designer.SetDataSource("VisaInsTitle", visaIns?.ItemWrapName ?? "签证+保险\r\n(单位:元)");
  17208. var vi_label = new StringBuilder();
  17209. if (visaIns != null && visaIns.Infos.Any())
  17210. {
  17211. foreach (var item in visaIns.Infos)
  17212. {
  17213. //签证:500元/人
  17214. string label = string.Format("{0}:{1}元/人*{2}人", item.FeeName, item.UnitPrice.TruncDecimals(2), item.PplNum);
  17215. vi_label.AppendLine(label);
  17216. }
  17217. if (vi_label.HasValue())
  17218. {
  17219. //以上小计:6000元
  17220. string label = string.Format("以上小计:{0}元", visaIns.TotalAmt.TruncDecimals(2));
  17221. vi_label.AppendLine(label);
  17222. }
  17223. }
  17224. designer.SetDataSource("VisaInsContent", vi_label.ToString());
  17225. #endregion
  17226. #region 服务费
  17227. designer.SetDataSource("ServiceCostTitle", serviceCosts?.ItemWrapName ?? "服务费");
  17228. designer.SetDataSource("ServiceCostContent", serviceCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  17229. #endregion
  17230. #region 公杂费
  17231. designer.SetDataSource("PubMiscsTitle", pubMiscs?.ItemWrapName ?? "公杂费\r\n(发给团组成员)");
  17232. var pm_label = new StringBuilder();
  17233. if (pubMiscs != null && pubMiscs.Infos.Any())
  17234. {
  17235. string currencyName = string.Empty,
  17236. countryName = string.Empty;
  17237. decimal rate = 1.0000M;
  17238. foreach (var item in pubMiscs.Infos)
  17239. {
  17240. //乌兹别克斯坦:塔什干:32美金 / 天 * 3 * 6人
  17241. string name = string.Empty, thisCountryName = string.Empty;
  17242. if (item.FeeName.Contains('-'))
  17243. {
  17244. var feeName = item.FeeName.Split('-');
  17245. thisCountryName = feeName[0];
  17246. if (!thisCountryName.Equals(countryName)) countryName = feeName[0];
  17247. name = feeName[1];
  17248. }
  17249. else name = item.FeeName;
  17250. string thisFeeName = string.Empty;
  17251. if (!thisCountryName.Equals(countryName)) thisFeeName = $"{countryName}:\r\n{name}:";
  17252. else thisFeeName = $"\r\n{name}:";
  17253. var rateInfo = rates.FirstOrDefault(x => item.Currency.Equals(x.CurrencyCode));
  17254. currencyName = rateInfo?.CurrencyName ?? "UnKnow";
  17255. rate = rateInfo?.Rate ?? 1.0000M;
  17256. string label = string.Format("{0}:{1}{2}/天*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity, item.PplNum);
  17257. pm_label.AppendLine(label);
  17258. }
  17259. if (pm_label.HasValue())
  17260. {
  17261. //以上小计:13497.6元\r\n(美金汇率:7.5 )\r\n部分发放成员
  17262. pm_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
  17263. pm_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
  17264. pm_label.AppendLine(string.Format("部分发放成员"));
  17265. }
  17266. }
  17267. designer.SetDataSource("PubMiscsContent", pm_label.ToString());
  17268. #endregion
  17269. #region 税费
  17270. designer.SetDataSource("TaxCostTitle", taxCosts?.ItemWrapName ?? "税费");
  17271. designer.SetDataSource("TaxCostContent", taxCosts?.TotalAmt.TruncDecimals(2) ?? 0.00M);
  17272. #endregion
  17273. #region 合计(单位:元)
  17274. designer.SetDataSource("CostTotalTitle", "合计\r\n(单位:元)");
  17275. designer.SetDataSource("CostTotalContent", info.FeeItems.Sum(x => x.TotalAmt).TruncDecimals(2));
  17276. #endregion
  17277. #region 汇率 Remark
  17278. var rate_label = new StringBuilder();
  17279. var rateGroups = rates.GroupBy(x => x.CurrencyName);
  17280. foreach (var item in rateGroups)
  17281. {
  17282. //美元汇率按\r\n1:7.5
  17283. string label = string.Format("{0}汇率按\r\n1:{1}", item.Key, item.FirstOrDefault()?.Rate.TruncDecimals(4) ?? 0.0000M);
  17284. rate_label.AppendLine(label);
  17285. }
  17286. designer.SetDataSource("RateLabel", rate_label.ToString());
  17287. #endregion
  17288. designer.Process();
  17289. //文件名
  17290. string fileName = $"{info.Name}{DateTime.Now:yyyyMMddHHmmss}.xls";
  17291. designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "EnterExitCostQuote/" + fileName);
  17292. string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/EnterExitCostQuote/" + fileName;
  17293. return Ok(JsonView(true, "成功", url));
  17294. }
  17295. #endregion
  17296. #region 签证费用录入
  17297. /// <summary>
  17298. /// 根据diid查询签证费用列表
  17299. /// </summary>
  17300. /// <param name="dto"></param>
  17301. /// <returns></returns>
  17302. [HttpPost]
  17303. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17304. public async Task<IActionResult> QueryVisaByDiId(VisaPriceDto dto)
  17305. {
  17306. Result groupData = await _visaPriceRep.PostVisaByDiId(dto);
  17307. if (groupData.Code != 0)
  17308. {
  17309. return Ok(JsonView(false, groupData.Msg));
  17310. }
  17311. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17312. }
  17313. /// <summary>
  17314. /// 根据签证费用Id查询单条数据及c表数据
  17315. /// </summary>
  17316. /// <param name="dto"></param>
  17317. /// <returns></returns>
  17318. [HttpPost]
  17319. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17320. public async Task<IActionResult> QueryVisaById(PostVisaByIdDto dto)
  17321. {
  17322. Result groupData = await _visaPriceRep.PostVisaById(dto);
  17323. if (groupData.Code != 0)
  17324. {
  17325. return Ok(JsonView(false, groupData.Msg));
  17326. }
  17327. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17328. }
  17329. /// <summary>
  17330. /// 签证费用删除
  17331. /// </summary>
  17332. /// <param name="dto"></param>
  17333. /// <returns></returns>
  17334. [HttpPost]
  17335. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17336. public async Task<IActionResult> DelVisaPrice(DelBaseDto dto)
  17337. {
  17338. _sqlSugar.BeginTran();
  17339. //验证
  17340. (bool vaild, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  17341. if (!vaild)
  17342. {
  17343. _sqlSugar.RollbackTran();
  17344. return Ok(JsonView(false, msg));
  17345. }
  17346. var res = await _visaPriceRep.SoftDeleteByIdAsync<Grp_VisaInfo>(dto.Id.ToString(), dto.DeleteUserId);
  17347. if (!res)
  17348. {
  17349. _sqlSugar.RollbackTran();
  17350. return Ok(JsonView(false, "删除失败"));
  17351. }
  17352. var resSub = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  17353. .Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 80)
  17354. .SetColumns(a => new Grp_CreditCardPayment()
  17355. {
  17356. IsDel = 1,
  17357. DeleteUserId = dto.DeleteUserId,
  17358. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17359. })
  17360. .ExecuteCommand();
  17361. if (resSub < 1)
  17362. {
  17363. _sqlSugar.RollbackTran();
  17364. return Ok(JsonView(false, "删除失败"));
  17365. }
  17366. _sqlSugar.CommitTran();
  17367. return Ok(JsonView(true, "删除成功!"));
  17368. }
  17369. /// <summary>
  17370. /// 签证费用录入下拉框初始化
  17371. /// </summary>
  17372. /// <returns></returns>
  17373. [HttpPost]
  17374. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17375. public async Task<IActionResult> VisaPriceAddSelect()
  17376. {
  17377. //支付方式
  17378. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  17379. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  17380. //币种
  17381. List<Sys_SetData> CurrencyList = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 66 && a.IsDel == 0).ToList();
  17382. List<SetDataInfoView> _CurrencyList = _mapper.Map<List<SetDataInfoView>>(CurrencyList);
  17383. //乘客类型
  17384. List<Sys_SetData> PassengerType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 69 && a.IsDel == 0).ToList();
  17385. List<SetDataInfoView> _PassengerType = _mapper.Map<List<SetDataInfoView>>(PassengerType);
  17386. //卡类型
  17387. List<Sys_SetData> BankCard = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  17388. List<SetDataInfoView> _BankCard = _mapper.Map<List<SetDataInfoView>>(BankCard);
  17389. //代办费类型
  17390. var agencyFeeTypeData = new List<dynamic>() {
  17391. new { id = 0 , Text = "未选择" },
  17392. new { id = 1 , Text = "小公务" },
  17393. new { id = 2 , Text = "大公务" },
  17394. };
  17395. //签证费用标准国家Data
  17396. var visaSql = string.Format(@"select
  17397. id,
  17398. case
  17399. when FeeType = 0 then Country+'(因公)'
  17400. when FeeType = 1 then Country+'(因私)'
  17401. else Country+'(未设置)'
  17402. end as 'country'
  17403. from Res_VisaFeeStandard where isdel = 0");
  17404. var visaCountryFeeData = _sqlSugar.SqlQueryable<dynamic>(visaSql).ToList();
  17405. var data = new
  17406. {
  17407. Payment = _Payment,
  17408. CurrencyList = _CurrencyList,
  17409. PassengerType = _PassengerType,
  17410. BankCard = _BankCard,
  17411. AgencyFeeType = agencyFeeTypeData,
  17412. CountryFeeData = visaCountryFeeData
  17413. };
  17414. return Ok(JsonView(true, "查询成功!", data));
  17415. }
  17416. /// <summary>
  17417. /// 签证费用录入操作(Status:1.新增,2.修改)
  17418. /// </summary>
  17419. /// <param name="dto"></param>
  17420. /// <returns></returns>
  17421. [HttpPost]
  17422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17423. public async Task<IActionResult> OpVisaPrice(OpVisaPriceDto dto)
  17424. {
  17425. //修改验证
  17426. if (dto.Status == 2)
  17427. {
  17428. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 80);
  17429. if (!valid) return Ok(JsonView(false, msg));
  17430. }
  17431. Result groupData = await _visaPriceRep.OpVisaPrice(dto);
  17432. if (groupData.Code != 0)
  17433. {
  17434. return Ok(JsonView(false, groupData.Msg));
  17435. }
  17436. #region 应用推送
  17437. try
  17438. {
  17439. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  17440. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  17441. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  17442. //2024-10-21 新增LZ UID
  17443. var userIds = new List<int>() { 21 };
  17444. string title = $"系统通知";
  17445. string content = "";
  17446. var diId = dto.DiId;
  17447. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  17448. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  17449. if (dto.Status == 1) content = $"[新增-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  17450. else if (dto.Status == 2) content = $"[更新-签证费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate):#0.00} CNY;";
  17451. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  17452. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "80" };
  17453. await APNsTools.iOS_PushNotifications1("051", $"签证费用审核", "", content, true, "ExpenseAuditWebView", h5);
  17454. }
  17455. catch (Exception ex)
  17456. {
  17457. }
  17458. #endregion
  17459. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17460. }
  17461. #endregion
  17462. #region 签证提成录入
  17463. /// <summary>
  17464. /// 签证提成录入
  17465. /// 基础数据
  17466. /// </summary>
  17467. /// <returns></returns>
  17468. [HttpGet]
  17469. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17470. public async Task<IActionResult> VisaCommissionInit()
  17471. {
  17472. return Ok(await _visaCommissionRep.Init());
  17473. }
  17474. /// <summary>
  17475. /// 签证提成录入
  17476. /// Item
  17477. /// </summary>
  17478. /// <param name="_dto"></param>
  17479. /// <returns></returns>
  17480. [HttpPost]
  17481. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17482. public async Task<IActionResult> VisaCommissionItem(VisaCommissionItemDto _dto)
  17483. {
  17484. var validator = new VisaCommissionItemDtoValidator();
  17485. var validatorRes = await validator.ValidateAsync(_dto);
  17486. if (!validatorRes.IsValid)
  17487. {
  17488. var sb = new StringBuilder();
  17489. foreach (var item in validatorRes.Errors)
  17490. {
  17491. sb.AppendLine(item.ErrorMessage);
  17492. }
  17493. return Ok(JsonView(false, sb.ToString()));
  17494. }
  17495. return Ok(await _visaCommissionRep.Item(_dto));
  17496. }
  17497. /// <summary>
  17498. /// 签证提成录入
  17499. /// Save
  17500. /// </summary>
  17501. /// <param name="_dto"></param>
  17502. /// <returns></returns>
  17503. [HttpPost]
  17504. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17505. public async Task<IActionResult> VisaCommissionSave(VisaCommissionSaveDto _dto)
  17506. {
  17507. //参数验证
  17508. if (_dto.Items.Length < 1) return Ok(JsonView(false, "请输入有效的请求!"));
  17509. foreach (var item in _dto.Items)
  17510. {
  17511. if (item.CurrUserId < 1) return Ok(JsonView(false, "请输入有效的CurrUserId!"));
  17512. if (item.DiId < 1) return Ok(JsonView(false, "请输入有效的DiId!"));
  17513. if (string.IsNullOrEmpty(item.Country)) return Ok(JsonView(false, "国家为空!"));
  17514. //if (item.Quantity < 1) return Ok(JsonView(false, "请输入有效的Qauntity!"));
  17515. }
  17516. return Ok(await _visaCommissionRep.Save(_dto));
  17517. }
  17518. /// <summary>
  17519. /// 签证提成录入
  17520. /// Create
  17521. /// </summary>
  17522. /// <param name="_dto"></param>
  17523. /// <returns></returns>
  17524. [HttpPost]
  17525. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17526. public async Task<IActionResult> VisaCommissionCreate(VisaCommissionCreateDto _dto)
  17527. {
  17528. var validator = new VisaCommissionCreateDtoValidator();
  17529. var validatorRes = await validator.ValidateAsync(_dto);
  17530. if (!validatorRes.IsValid)
  17531. {
  17532. var sb = new StringBuilder();
  17533. foreach (var item in validatorRes.Errors)
  17534. {
  17535. sb.AppendLine(item.ErrorMessage);
  17536. }
  17537. return Ok(JsonView(false, sb.ToString()));
  17538. }
  17539. return Ok(await _visaCommissionRep.Create(_dto));
  17540. }
  17541. /// <summary>
  17542. /// 签证提成录入
  17543. /// Put(编辑)
  17544. /// </summary>
  17545. /// <param name="id"></param>
  17546. /// <param name="_dto"></param>
  17547. /// <returns></returns>
  17548. [HttpPut]
  17549. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17550. public async Task<IActionResult> VisaCommissionEdit(int id, VisaCommissionCreateDto _dto)
  17551. {
  17552. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  17553. var validator = new VisaCommissionCreateDtoValidator();
  17554. var validatorRes = await validator.ValidateAsync(_dto);
  17555. if (!validatorRes.IsValid)
  17556. {
  17557. var sb = new StringBuilder();
  17558. foreach (var item in validatorRes.Errors)
  17559. {
  17560. sb.AppendLine(item.ErrorMessage);
  17561. }
  17562. return Ok(JsonView(false, sb.ToString()));
  17563. }
  17564. return Ok(await _visaCommissionRep.Edit(id, _dto));
  17565. }
  17566. /// <summary>
  17567. /// 签证提成录入
  17568. /// Del
  17569. /// </summary>
  17570. /// <param name="id"></param>
  17571. /// <param name="currUserId"></param>
  17572. /// <returns></returns>
  17573. [HttpPost]
  17574. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17575. public async Task<IActionResult> VisaCommissionDel(int id, int currUserId)
  17576. {
  17577. if (id < 1) return Ok(JsonView(false, "请输入正确的id参数!"));
  17578. if (currUserId < 1) return Ok(JsonView(false, "请输入正确的currUserId参数!"));
  17579. return Ok(await _visaCommissionRep.Del(id, currUserId));
  17580. }
  17581. #endregion
  17582. #region op费用录入
  17583. /// <summary>
  17584. /// 根据diid查询op费用列表
  17585. /// </summary>
  17586. /// <param name="dto"></param>
  17587. /// <returns></returns>
  17588. [HttpPost]
  17589. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17590. public async Task<IActionResult> QueryCarTouristGuideGroundByDiId(CarTouristGuideGroundDto dto)
  17591. {
  17592. Result groupData = await _carTouristGuideGroundRep.QueryCarTouristGuideGroundByDiId(dto);
  17593. if (groupData.Code != 0)
  17594. {
  17595. return Ok(JsonView(false, groupData.Msg));
  17596. }
  17597. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17598. }
  17599. /// <summary>
  17600. /// 根据op费用Id查询单条数据及c表数据
  17601. /// </summary>
  17602. /// <param name="dto"></param>
  17603. /// <returns></returns>
  17604. [HttpPost]
  17605. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17606. public async Task<IActionResult> QueryCarTouristGuideGroundById(CarTouristGuideGroundIdDto dto)
  17607. {
  17608. try
  17609. {
  17610. Grp_CarTouristGuideGroundReservations _groupData = await _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().FirstAsync(a => a.Id == dto.Id && a.IsDel == 0);
  17611. Grp_CreditCardPayment _creditCardPayment = await _sqlSugar.Queryable<Grp_CreditCardPayment>().FirstAsync(a => a.CId == dto.Id && a.CTable == 79 && a.IsDel == 0);
  17612. var data = new
  17613. {
  17614. CarTouristGuideGround = _groupData,
  17615. CreditCardPayment = _creditCardPayment
  17616. };
  17617. return Ok(JsonView(true, "查询成功!", data));
  17618. }
  17619. catch (Exception ex)
  17620. {
  17621. return Ok(JsonView(false, "程序错误!"));
  17622. }
  17623. }
  17624. /// <summary>
  17625. /// op费用删除
  17626. /// </summary>
  17627. /// <param name="dto"></param>
  17628. /// <returns></returns>
  17629. [HttpPost]
  17630. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17631. public async Task<IActionResult> DelCarTouristGuideGround(DelBaseDto dto)
  17632. {
  17633. try
  17634. {
  17635. _sqlSugar.BeginTran();
  17636. //验证
  17637. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 79);
  17638. if (!valid)
  17639. {
  17640. _sqlSugar.RollbackTran();
  17641. return Ok(JsonView(false, msg));
  17642. }
  17643. var res = await _carTouristGuideGroundRep.SoftDeleteByIdAsync<Grp_CarTouristGuideGroundReservations>(dto.Id.ToString(), dto.DeleteUserId);
  17644. if (!res)
  17645. {
  17646. _sqlSugar.RollbackTran();
  17647. return Ok(JsonView(false, "删除失败"));
  17648. }
  17649. var result = await _sqlSugar.Updateable<Grp_CarTouristGuideGroundReservationsContent>().Where(a => a.CTGGRId == dto.Id && a.IsDel == 0).SetColumns(a => new Grp_CarTouristGuideGroundReservationsContent()
  17650. {
  17651. IsDel = 1,
  17652. DeleteUserId = dto.DeleteUserId,
  17653. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17654. }).ExecuteCommandAsync();
  17655. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 79).SetColumns(a => new Grp_CreditCardPayment()
  17656. {
  17657. IsDel = 1,
  17658. DeleteUserId = dto.DeleteUserId,
  17659. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17660. }).ExecuteCommandAsync();
  17661. #region 删除超支相关数据
  17662. //删除导入的超支数据
  17663. var ids = _sqlSugar.Queryable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.LocalGuideId == dto.Id && x.IsDel == 0).Select(x => x.OverspendId).ToList();
  17664. var count = _sqlSugar.Updateable<Fin_GroupExtraCost>().Where(x => ids.Contains(x.Id) && x.IsDel == 0).SetColumns(x => new Fin_GroupExtraCost
  17665. {
  17666. IsDel = 1,
  17667. DeleteUserId = dto.DeleteUserId,
  17668. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17669. }).ExecuteCommand();
  17670. count = _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(x => x.CTable == 1015 && x.IsDel == 0 && ids.Contains(x.CId)).SetColumns(x => new Grp_CreditCardPayment
  17671. {
  17672. IsDel = 1,
  17673. DeleteUserId = dto.DeleteUserId,
  17674. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17675. }).ExecuteCommand();
  17676. count = _sqlSugar.Updateable<Fin_LocalGuideRelevancyOverspend>().Where(x => x.IsDel == 0 && x.LocalGuideId == dto.Id).SetColumns(x => new Fin_LocalGuideRelevancyOverspend
  17677. {
  17678. IsDel = 1,
  17679. DeleteUserId = dto.DeleteUserId,
  17680. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17681. }).ExecuteCommand();
  17682. #endregion
  17683. _sqlSugar.CommitTran();
  17684. return Ok(JsonView(true, "删除成功!"));
  17685. }
  17686. catch (Exception ex)
  17687. {
  17688. _sqlSugar.RollbackTran();
  17689. return Ok(JsonView(false, "程序错误!" + ex.Message));
  17690. }
  17691. }
  17692. /// <summary>
  17693. /// op费用录入操作(Status:1.新增,2.修改)
  17694. /// </summary>
  17695. /// <param name="dto"></param>
  17696. /// <returns></returns>
  17697. [HttpPost]
  17698. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17699. public async Task<IActionResult> OpCarTouristGuideGround(OpCarTouristGuideGroundDto dto)
  17700. {
  17701. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGround(dto);
  17702. if (groupData.Code != 0)
  17703. {
  17704. return Ok(JsonView(false, groupData.Msg));
  17705. }
  17706. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17707. }
  17708. /// <summary>
  17709. /// 填写费用详细页面初始化绑定
  17710. /// </summary>
  17711. /// <param name="dto"></param>
  17712. /// <returns></returns>
  17713. [HttpPost]
  17714. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17715. public IActionResult CarTouristGuideGroundContentInitialize(CarTouristGuideGroundContentDto dto)
  17716. {
  17717. try
  17718. {
  17719. Result groupData = _carTouristGuideGroundRep.CarTouristGuideGroundContent(dto);
  17720. if (groupData.Code != 0)
  17721. {
  17722. return Ok(JsonView(false, groupData.Msg));
  17723. }
  17724. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17725. }
  17726. catch (Exception ex)
  17727. {
  17728. return Ok(JsonView(false, ex.Message));
  17729. }
  17730. }
  17731. /// <summary>
  17732. /// 根据op费用Id查询详细数据
  17733. /// </summary>
  17734. /// <param name="dto"></param>
  17735. /// <returns></returns>
  17736. [HttpPost]
  17737. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17738. public IActionResult OpCarTouristGuideGroundContentById(CarTouristGuideGroundIdDto dto)
  17739. {
  17740. try
  17741. {
  17742. Result groupData = _carTouristGuideGroundRep.OpCarTouristGuideGroundContentById(dto);
  17743. if (groupData.Code != 0)
  17744. {
  17745. return Ok(JsonView(false, groupData.Msg));
  17746. }
  17747. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17748. }
  17749. catch (Exception ex)
  17750. {
  17751. return Ok(JsonView(false, ex.Message));
  17752. }
  17753. }
  17754. /// <summary>
  17755. /// OP费用录入填写详情
  17756. /// </summary>
  17757. /// <param name="dto"></param>
  17758. /// <returns></returns>
  17759. [HttpPost]
  17760. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  17761. public async Task<IActionResult> OpCarTouristGuideGroundContent(OpCarTouristGuideGroundContentDto dto)
  17762. {
  17763. try
  17764. {
  17765. #region 参数校验
  17766. if (dto.Currency <= 0) return Ok(JsonView(false, "币种错误!"));
  17767. var di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.DiId && x.IsDel == 0);
  17768. if (di == null) return Ok(JsonView(false, "团组错误!"));
  17769. #endregion
  17770. //验证
  17771. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.CTGGRId, 79);
  17772. if (!valid)
  17773. {
  17774. _sqlSugar.RollbackTran();
  17775. return Ok(JsonView(false, msg));
  17776. }
  17777. Result groupData = await _carTouristGuideGroundRep.OpCarTouristGuideGroundContent(dto);
  17778. if (groupData.Code != 0)
  17779. {
  17780. return Ok(JsonView(false, groupData.Msg));
  17781. }
  17782. //自动审核
  17783. await _feeAuditRep.FeeAutomaticAudit(2, dto.DiId, dto.CTGGRId);
  17784. #region 尾款自动审核
  17785. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  17786. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.Id == dto.CTGGRId);
  17787. if (opinfos.PriceType == 1062)
  17788. {
  17789. var isAuto = false;
  17790. //找对应的首付款
  17791. var firstPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  17792. .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))
  17793. .First(x => x.IsDel == 0 && x.DiId == dto.DiId && x.PriceName == opinfos.PriceName &&
  17794. x.ServiceStartTime == opinfos.ServiceStartTime && x.ServiceEndTime == opinfos.ServiceEndTime && x.Area == opinfos.Area &&
  17795. x.PriceType == 1061 && x.DiId == dto.DiId);
  17796. if (firstPrice != null && !(opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支")) && firstPrice.CId == opinfos.CId)
  17797. {
  17798. var cprice = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(x => x.IsDel == 0 && x.CId == firstPrice.Id && x.CTable == 79);
  17799. var balance = firstPrice.ServiceQuotedPrice * (100 - cprice.PayPercentage) / 100;
  17800. //合计中排除城市税
  17801. var cityPrice = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  17802. .Where(x => x.SId == 1452 && x.IsDel == 0 && x.DiId == dto.DiId && x.CTGGRId == dto.CTGGRId)
  17803. .Sum(x => x.Price * x.Count);
  17804. opinfos.ServiceQuotedPrice = opinfos.ServiceQuotedPrice - cityPrice;
  17805. if (balance >= opinfos.ServiceQuotedPrice)
  17806. {
  17807. isAuto = true;
  17808. }
  17809. }
  17810. if (isAuto)
  17811. {
  17812. var execCount = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  17813. .SetColumns(a => new Grp_CreditCardPayment
  17814. {
  17815. IsAuditGM = 3, //自动审核通过
  17816. AuditGMOperate = 4,
  17817. AuditGMDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  17818. })
  17819. .Where(a => a.CId == dto.CTGGRId && a.CTable == 79 && a.DIId == dto.DiId)
  17820. .ExecuteCommand();
  17821. }
  17822. }
  17823. #endregion
  17824. #region 应用推送
  17825. try
  17826. {
  17827. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  17828. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  17829. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  17830. //2024-10-21 新增LZ UID
  17831. var userIds = new List<int>() { 21 };
  17832. string title = $"系统通知";
  17833. var diId = dto.DiId;
  17834. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  17835. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  17836. string content = $"[更新-OP费用录入填写详情({groupInfo?.TeamName ?? "-"})]一项费用:{(((ccpInfo.PayMoney * ccpInfo.DayRate) / 100) * ccpInfo.PayPercentage):#0.00} CNY;";
  17837. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  17838. var h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "79" };
  17839. await APNsTools.iOS_PushNotifications1("051", $"OP费用审核", "", content, true, "ExpenseAuditWebView", h5);
  17840. }
  17841. catch (Exception ex)
  17842. {
  17843. }
  17844. #endregion
  17845. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  17846. }
  17847. catch (Exception ex)
  17848. {
  17849. return Ok(JsonView(false, ex.Message));
  17850. }
  17851. }
  17852. /// <summary>
  17853. /// 获取三公详细所有城市
  17854. /// </summary>
  17855. /// <returns></returns>
  17856. [HttpGet]
  17857. public IActionResult OpCarCityResult()
  17858. {
  17859. var jw = JsonView(false);
  17860. var data = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(x => x.IsDel == 0).Select(x => new
  17861. {
  17862. x.Id,
  17863. x.Country,
  17864. x.City,
  17865. }).ToList();
  17866. if (data.Count > 0)
  17867. {
  17868. jw = JsonView(true, "获取成功!", data);
  17869. }
  17870. else
  17871. {
  17872. jw.Msg = "城市数据为空!";
  17873. jw.Data = Array.Empty<string>();
  17874. }
  17875. return Ok(jw);
  17876. }
  17877. /// <summary>
  17878. /// 导出地接费用明细
  17879. /// </summary>
  17880. /// <param name="dto"></param>
  17881. /// <returns></returns>
  17882. [HttpPost]
  17883. public IActionResult ExportLocalGuidePriceDetail(ExportLocalGuidePriceDetailDto dto)
  17884. {
  17885. var jw = JsonView(false);
  17886. if (dto.Diid < 1)
  17887. {
  17888. jw.Msg = "请输入正确的diid!";
  17889. return Ok(jw);
  17890. }
  17891. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  17892. if (group == null)
  17893. {
  17894. jw.Msg = "未找到团组信息!";
  17895. return Ok(jw);
  17896. }
  17897. var localGuideArr = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  17898. if (localGuideArr.Count == 0)
  17899. {
  17900. jw.Msg = "该团组暂无地接信息!";
  17901. return Ok(jw);
  17902. }
  17903. var localGroup = localGuideArr.GroupBy(x => x.Area).ToList();
  17904. var overspendSoure = new Dictionary<int, int>
  17905. {
  17906. { 91, 982 }, //车
  17907. { 92 , 1059} ,//导游
  17908. { 994 , 1073}, //翻译
  17909. { 988 , 1074 }, //早餐
  17910. { 93 , 1075 }, //午餐
  17911. { 989 , 1076 }, //晚餐
  17912. };
  17913. var Zips = new Dictionary<string, Stream>();
  17914. foreach (var groupArr in localGroup)
  17915. {
  17916. var keyValue = groupArr.Key;
  17917. if (int.TryParse(keyValue, out int cityid))
  17918. {
  17919. var city = _sqlSugar.Queryable<Grp_NationalTravelFee>().First(x => x.Id == cityid && x.IsDel == 0);
  17920. keyValue = city == null ? keyValue : city.Country + "-" + city.City;
  17921. }
  17922. var contentArr = new List<List<Grp_CarTouristGuideGroundReservationsContentExtend>>();
  17923. foreach (var item in groupArr)
  17924. {
  17925. var content = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent, Sys_SetData>((a, b) => a.SId == b.Id
  17926. ).Where((a, b) => a.CTGGRId == item.Id && a.Price != 0M && a.IsDel == 0 && b.IsDel == 0).Select((a, b) =>
  17927. new Grp_CarTouristGuideGroundReservationsContentExtend
  17928. {
  17929. Count = a.Count,
  17930. CreateTime = a.CreateTime,
  17931. CreateUserId = a.CreateUserId,
  17932. CTGGRId = a.CTGGRId,
  17933. Currency = a.Currency,
  17934. DatePrice = a.DatePrice,
  17935. DeleteTime = a.DeleteTime,
  17936. DeleteUserId = a.DeleteUserId,
  17937. DiId = a.DiId,
  17938. Id = a.Id,
  17939. IsDel = a.IsDel,
  17940. Price = a.Price,
  17941. PriceContent = a.PriceContent,
  17942. Remark = a.Remark,
  17943. SId = a.SId,
  17944. SidName = b.Name,
  17945. Units = a.Units,
  17946. }
  17947. ).ToList();
  17948. if (content.Count > 0)
  17949. {
  17950. contentArr.Add(content);
  17951. }
  17952. }
  17953. //open excel
  17954. //set excel
  17955. //save excel
  17956. try
  17957. {
  17958. string filePath = AppSettingsHelper.Get("ExcelBasePath") + "\\Template\\地接费用明细.xlsx";
  17959. IWorkbook workbook;
  17960. if (Path.GetExtension(filePath).ToLower() == ".xls")
  17961. {
  17962. workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  17963. }
  17964. else
  17965. {
  17966. workbook = new XSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
  17967. }
  17968. ISheet sheet = workbook.GetSheetAt(0);
  17969. var rowStartIndex = 2;
  17970. var clounmCount = 10;
  17971. var initStyleRow = sheet.GetRow(2);
  17972. var arr = contentArr.SelectMany(x => x).OrderBy(x => x.SId).ToList();
  17973. //var overspendArrDetail =
  17974. var existsId = new List<CarCompare>();
  17975. var lastElem = arr.Last();
  17976. var thisSid = -1;
  17977. var curr = arr.Count > 0 ? arr[0].Currency : -1;
  17978. var currObj = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == curr && x.IsDel == 0) ?? new Sys_SetData
  17979. {
  17980. Name = "未知币种!",
  17981. Remark = "未知币种!",
  17982. };
  17983. sheet.GetRow(0).GetCell(1).SetCellValue($"{keyValue}费用明细(货币:{currObj.Remark})");
  17984. Action cloneRowFn = () =>
  17985. {
  17986. rowStartIndex++;
  17987. var cloneRow = sheet.CreateRow(rowStartIndex);
  17988. // 复制样式
  17989. for (int i = initStyleRow.FirstCellNum; i < initStyleRow.LastCellNum; i++)
  17990. {
  17991. ICell sourceCell = initStyleRow.GetCell(i);
  17992. ICell targetCell = cloneRow.GetCell(i) ?? cloneRow.CreateCell(i);
  17993. // 确保单元格存在样式
  17994. if (sourceCell.CellStyle != null)
  17995. {
  17996. targetCell.CellStyle = sourceCell.CellStyle;
  17997. }
  17998. }
  17999. };
  18000. var mergeRow = () =>
  18001. {
  18002. for (int i = 2; i < sheet.LastRowNum; i++)
  18003. {
  18004. var row = sheet.GetRow(i);
  18005. var cellFirst = row.GetCell(0);
  18006. var thisIndex = i + 1;
  18007. while (thisIndex < sheet.LastRowNum)
  18008. {
  18009. var nextRow = sheet.GetRow(thisIndex);
  18010. var nextCellFirst = nextRow.GetCell(0);
  18011. if (cellFirst != null && nextCellFirst != null && cellFirst.ToString().Trim() == nextCellFirst.ToString().Trim())
  18012. {
  18013. thisIndex++;
  18014. }
  18015. else
  18016. {
  18017. break;
  18018. }
  18019. }
  18020. thisIndex--;
  18021. if (thisIndex != i)
  18022. {
  18023. //合并row
  18024. var cellRangeAddress = new CellRangeAddress(
  18025. i, // 起始行索引(0-based)
  18026. thisIndex, // 结束行索引(0-based)
  18027. 0, // 起始列索引(0-based)
  18028. 0 // 结束列索引(0-based)
  18029. );
  18030. sheet.AddMergedRegion(cellRangeAddress);
  18031. i = thisIndex;
  18032. }
  18033. }
  18034. };
  18035. var chaoshiNumber = 0;
  18036. var totalNumber = 0.00M;
  18037. string lastStr = "";
  18038. var queryCarArrByCityAndDiid = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations, Grp_CreditCardPayment>((x, b) => x.Id == b.CId && b.IsDel == 0 && b.CTable == 79)
  18039. .Where(x => x.DiId == dto.Diid && x.Area == groupArr.Key).Select((x, b) => new
  18040. {
  18041. b.IsAuditGM,
  18042. x.Id,
  18043. x.Area,
  18044. b.PayPercentage,
  18045. b.PayMoney,
  18046. }).ToList();
  18047. string yesPayment = "", noPayment = "";
  18048. foreach (var item in queryCarArrByCityAndDiid)
  18049. {
  18050. if (item.IsAuditGM == 1)
  18051. {
  18052. yesPayment += $"已支付团款({(int)item.PayPercentage}%):{item.PayMoney} {currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  18053. }
  18054. else
  18055. {
  18056. noPayment += $"剩余团款:{item.PayMoney}{currObj.Remark}(如有需要,请在此处填写明细)\r\n";
  18057. }
  18058. }
  18059. lastStr = yesPayment + noPayment;
  18060. foreach (var item in arr)
  18061. {
  18062. if (existsId.FirstOrDefault(x => x.Sid == item.SId && DateTime.Compare(x.DataPrice, item.DatePrice.ObjToDate()) == 0) == null && !overspendSoure.ContainsValue(item.SId))
  18063. {
  18064. if (thisSid != item.SId)
  18065. {
  18066. if (thisSid == -1)
  18067. {
  18068. thisSid = item.SId;
  18069. }
  18070. else
  18071. {
  18072. //合并小计行
  18073. //创建合并区域的实例
  18074. var cellRangeAddress = new CellRangeAddress(
  18075. rowStartIndex, // 起始行索引(0-based)
  18076. rowStartIndex, // 结束行索引(0-based)
  18077. 0, // 起始列索引(0-based)
  18078. 3 // 结束列索引(0-based)
  18079. );
  18080. sheet.AddMergedRegion(cellRangeAddress);
  18081. var CellStyle = workbook.CreateCellStyle();
  18082. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18083. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  18084. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  18085. for (int i = 0; i <= clounmCount; i++)
  18086. {
  18087. if (i > 6)
  18088. {
  18089. var CellStyle1 = workbook.CreateCellStyle();
  18090. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18091. IFont Font = workbook.CreateFont(); // 创建字体
  18092. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  18093. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  18094. CellStyle1.SetFont(Font);
  18095. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  18096. }
  18097. else
  18098. {
  18099. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  18100. }
  18101. }
  18102. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  18103. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  18104. //超时合计
  18105. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  18106. //超时数
  18107. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  18108. //超时合计费用
  18109. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  18110. thisSid = item.SId;
  18111. cloneRowFn();
  18112. chaoshiNumber = 0;
  18113. totalNumber = 0;
  18114. }
  18115. }
  18116. IRow row = sheet.GetRow(rowStartIndex);
  18117. var whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  18118. var isOpenOverspendSoure = overspendSoure.ContainsKey(item.SId);
  18119. List<Grp_CarTouristGuideGroundReservationsContentExtend> overspendWhereForResult = null;
  18120. if (isOpenOverspendSoure)
  18121. {
  18122. overspendWhereForResult = arr.Where(x => x.SId == overspendSoure[item.SId] && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  18123. chaoshiNumber += overspendWhereForResult.Sum(x => x.Count);
  18124. totalNumber += overspendWhereForResult.Sum(x => x.Count * x.Price);
  18125. }
  18126. for (int i = 0; i <= clounmCount; i++)
  18127. {
  18128. var cell = row.GetCell(i);
  18129. var setCellValue = InIndexOutFunction(i, whereForResult, overspendWhereForResult);
  18130. if (cell == null)
  18131. {
  18132. cell = row.CreateCell(i);
  18133. }
  18134. var fontRed = workbook.CreateCellStyle(); // 创建单元格样式
  18135. fontRed.CloneStyleFrom(cell.CellStyle);
  18136. IFont Font = workbook.CreateFont(); // 创建字体
  18137. Font.CloneStyleFrom(cell.CellStyle.GetFont(workbook));
  18138. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  18139. fontRed.SetFont(Font);
  18140. byte[] rgb = new byte[3] { 255, 242, 204 };
  18141. var BackgroundColor255_242_204 = workbook.CreateCellStyle();
  18142. BackgroundColor255_242_204.CloneStyleFrom(cell.CellStyle);
  18143. byte[] rgb1 = new byte[3] { 189, 215, 238 };
  18144. if (workbook is XSSFWorkbook)
  18145. {
  18146. BackgroundColor255_242_204.FillForegroundColor = 0;
  18147. ((XSSFColor)BackgroundColor255_242_204.FillForegroundColorColor).SetRgb(rgb);
  18148. BackgroundColor255_242_204.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  18149. }
  18150. else
  18151. {
  18152. BackgroundColor255_242_204.FillForegroundColor = (((NPOI.HSSF.UserModel.HSSFWorkbook)workbook).GetCustomPalette().FindSimilarColor(rgb[0], rgb[1], rgb[2])).Indexed;
  18153. }
  18154. if (i == 1 || i > 6)
  18155. {
  18156. if (i > 6)
  18157. {
  18158. fontRed.FillForegroundColor = 0;
  18159. ((XSSFColor)fontRed.FillForegroundColorColor).SetRgb(rgb1);
  18160. fontRed.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
  18161. }
  18162. cell.CellStyle = fontRed;
  18163. }
  18164. if (i > 2 && i < 7)
  18165. {
  18166. cell.CellStyle = BackgroundColor255_242_204;
  18167. }
  18168. cell.SetCellValue(setCellValue); //写入单元格
  18169. }
  18170. if (overspendSoure.ContainsKey(thisSid))
  18171. {
  18172. var overspendId = overspendSoure[thisSid];
  18173. whereForResult = arr.Where(x => x.SId == item.SId && DateTime.Compare(x.DatePrice.ObjToDate(), item.DatePrice.ObjToDate()) == 0).ToList();
  18174. }
  18175. cloneRowFn();
  18176. existsId.Add(new CarCompare
  18177. {
  18178. DataPrice = item.DatePrice.ObjToDate(),
  18179. Sid = item.SId
  18180. });
  18181. }
  18182. if (item.Equals(lastElem))
  18183. {
  18184. //合并小计行
  18185. //创建合并区域的实例
  18186. var cellRangeAddress = new CellRangeAddress(
  18187. rowStartIndex, // 起始行索引(0-based)
  18188. rowStartIndex, // 结束行索引(0-based)
  18189. 0, // 起始列索引(0-based)
  18190. 3 // 结束列索引(0-based)
  18191. );
  18192. sheet.AddMergedRegion(cellRangeAddress);
  18193. var CellStyle = workbook.CreateCellStyle();
  18194. CellStyle.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18195. CellStyle.FillForegroundColor = IndexedColors.Yellow.Index; // 选择填充颜色
  18196. CellStyle.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground; // 填充方式
  18197. for (int i = 0; i <= clounmCount; i++)
  18198. {
  18199. if (i > 6)
  18200. {
  18201. var CellStyle1 = workbook.CreateCellStyle();
  18202. CellStyle1.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(0).CellStyle);
  18203. IFont Font = workbook.CreateFont(); // 创建字体
  18204. Font.CloneStyleFrom(sheet.GetRow(rowStartIndex).GetCell(i).CellStyle.GetFont(workbook));
  18205. Font.Color = IndexedColors.Red.Index; // 选择字体颜色
  18206. CellStyle1.SetFont(Font);
  18207. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle1;
  18208. }
  18209. else
  18210. {
  18211. sheet.GetRow(rowStartIndex).GetCell(i).CellStyle = CellStyle;
  18212. }
  18213. }
  18214. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue("合计:");
  18215. sheet.GetRow(rowStartIndex).GetCell(4).SetCellValue(arr.Where(x => x.SId == thisSid).Sum(x => x.Count * x.Price).ToString("F2"));
  18216. //超时合计
  18217. sheet.GetRow(rowStartIndex).GetCell(7).SetCellValue("超时合计:");
  18218. //超时数
  18219. sheet.GetRow(rowStartIndex).GetCell(8).SetCellValue(chaoshiNumber == 0 ? "" : chaoshiNumber.ToString());
  18220. //超时合计费用
  18221. sheet.GetRow(rowStartIndex).GetCell(9).SetCellValue(totalNumber == 0 ? "" : totalNumber.ToString());
  18222. cloneRowFn();
  18223. // 创建合并区域的实例
  18224. cellRangeAddress = new CellRangeAddress(
  18225. rowStartIndex, // 起始行索引(0-based)
  18226. rowStartIndex, // 结束行索引(0-based)
  18227. 0, // 起始列索引(0-based)
  18228. initStyleRow.LastCellNum - 1 // 结束列索引(0-based)
  18229. );
  18230. // 添加合并区域
  18231. sheet.AddMergedRegion(cellRangeAddress);
  18232. sheet.GetRow(rowStartIndex).Height = 30 * 30;
  18233. sheet.GetRow(rowStartIndex).GetCell(0).SetCellValue(lastStr);
  18234. }
  18235. }
  18236. mergeRow();
  18237. // 保存修改后的Excel文件到新文件
  18238. //string newFilePath = Path.Combine(Path.GetDirectoryName(filePath), keyValue +"_" + Path.GetFileName(filePath));
  18239. // new FileStream(newFilePath, FileMode.CreateNew)
  18240. using (var stream = new MemoryStream())
  18241. {
  18242. workbook.Write(stream, true);
  18243. stream.Flush();
  18244. stream.Seek(0, SeekOrigin.Begin);
  18245. var memoryStream = new MemoryStream();
  18246. stream.CopyTo(memoryStream);
  18247. memoryStream.Seek(0, SeekOrigin.Begin);
  18248. Zips.Add(keyValue + "_" + "费用明细表.xlsx", memoryStream);
  18249. }
  18250. workbook.Close();
  18251. workbook.Dispose();
  18252. }
  18253. catch (Exception ex)
  18254. {
  18255. jw.Msg = "出现异常!" + ex.Message;
  18256. return Ok(jw);
  18257. }
  18258. }
  18259. if (Zips.Count > 0)
  18260. {
  18261. var io = new IOOperatorHelper();
  18262. var byts = io.ConvertZipStream(Zips);
  18263. io.ByteToFile(byts, AppSettingsHelper.Get("ExcelBasePath") + $"\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip");
  18264. //http://132.232.92.186:24/Office/Word/EnterExitCost/File/
  18265. jw = JsonView(true, "success", new { url = AppSettingsHelper.Get("OfficeBaseUrl") + $"\\Office\\Excel\\ExportLocalGuidePriceDetail\\{group.TeamName}_地接费用明细.zip" });
  18266. }
  18267. else
  18268. {
  18269. jw.Msg = "暂无生成文件!";
  18270. }
  18271. return Ok(jw);
  18272. }
  18273. private string InIndexOutFunction(int i, List<Grp_CarTouristGuideGroundReservationsContentExtend> arr, List<Grp_CarTouristGuideGroundReservationsContentExtend> arrOverspendSoure)
  18274. {
  18275. string outStr = string.Empty;
  18276. switch (i)
  18277. {
  18278. case 0:
  18279. outStr = arr[0].SidName;
  18280. break;
  18281. case 1:
  18282. outStr = arr[0].DataPriceStr;
  18283. break;
  18284. case 2:
  18285. outStr = string.Join("-", arr.Select(x => x.PriceContent));
  18286. break;
  18287. case 4:
  18288. outStr = arr.Sum(x => x.Subtotal).ToString("F2");
  18289. break;
  18290. case 7:
  18291. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18292. {
  18293. var curr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Currency && x.IsDel == 0);
  18294. var unit = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == arrOverspendSoure[0].Units && x.IsDel == 0);
  18295. outStr = arrOverspendSoure.Sum(x => x.Price).ToString("F2") + curr?.Remark + "/" + unit?.Name;
  18296. }
  18297. break;
  18298. case 8:
  18299. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18300. {
  18301. outStr = arrOverspendSoure.Sum(x => x.Count).ToString();
  18302. }
  18303. break;
  18304. case 9:
  18305. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18306. {
  18307. outStr = arrOverspendSoure.Sum(x => x.Count * x.Price).ToString();
  18308. }
  18309. break;
  18310. case 10:
  18311. if (arrOverspendSoure != null && arrOverspendSoure.Count > 0)
  18312. {
  18313. outStr = string.Join("-", arrOverspendSoure.Select(x => x.PriceContent));
  18314. }
  18315. break;
  18316. }
  18317. return outStr;
  18318. }
  18319. #region OP行程单
  18320. /// <summary>
  18321. /// OP行程单初始化
  18322. /// </summary>
  18323. /// <param name="dto"></param>
  18324. /// <returns></returns>
  18325. [HttpPost]
  18326. public IActionResult InitOpTravel(InitOpTravelDto dto)
  18327. {
  18328. var jw = JsonView(false);
  18329. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  18330. var group = groupList.First();
  18331. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  18332. if (group == null)
  18333. {
  18334. jw.Msg = "暂无团组!";
  18335. return Ok(jw);
  18336. }
  18337. group = groupList.Find(x => x.Id == diid);
  18338. if (group == null)
  18339. {
  18340. jw.Msg = "请输入正确的团组ID!";
  18341. return Ok(jw);
  18342. }
  18343. string city = string.Empty;
  18344. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  18345. if (blackCode.Count > 0)
  18346. {
  18347. var black = blackCode.First();
  18348. black.BlackCode = black.BlackCode ?? "";
  18349. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  18350. if (blackSp.Length > 0)
  18351. {
  18352. try
  18353. {
  18354. var cityArrCode = new List<string>(20);
  18355. foreach (var item in blackSp)
  18356. {
  18357. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  18358. var IndexSelect = itemSp[2];
  18359. var cityArrCodeLength = cityArrCode.Count - 1;
  18360. var startCity = IndexSelect.Substring(0, 3);
  18361. if (cityArrCodeLength > 0)
  18362. {
  18363. var arrEndCity = cityArrCode[cityArrCodeLength];
  18364. if (arrEndCity != startCity)
  18365. {
  18366. cityArrCode.Add(startCity.ToUpper());
  18367. }
  18368. }
  18369. else
  18370. {
  18371. cityArrCode.Add(startCity.ToUpper());
  18372. }
  18373. var endCity = IndexSelect.Substring(3, 3);
  18374. cityArrCode.Add(endCity.ToUpper());
  18375. }
  18376. var cityThree = string.Empty;
  18377. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  18378. cityThree = cityThree.TrimEnd(',');
  18379. if (string.IsNullOrWhiteSpace(cityThree))
  18380. {
  18381. throw new
  18382. Exception("error");
  18383. }
  18384. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  18385. var cityArr = _sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  18386. foreach (var item in cityArrCode)
  18387. {
  18388. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  18389. if (find != null)
  18390. {
  18391. city += find.City + "/";
  18392. }
  18393. else
  18394. {
  18395. city += item + "三字码未收入/";
  18396. }
  18397. }
  18398. city = city.TrimEnd('/');
  18399. }
  18400. catch (Exception e)
  18401. {
  18402. city = "黑屏代码格式不正确!";
  18403. }
  18404. }
  18405. }
  18406. else
  18407. {
  18408. city = "未录入黑屏代码";
  18409. }
  18410. var OpTravelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0).OrderBy(x => x.Days).Select(x => new TravelArrView
  18411. {
  18412. Date = x.Date,
  18413. Days = x.Days,
  18414. Diffgroup = x.Diffgroup,
  18415. Diid = x.Diid,
  18416. Traffic_First = x.Traffic_First,
  18417. Traffic_Second = x.Traffic_Second,
  18418. Trip = x.Trip,
  18419. WeekDay = x.WeekDay,
  18420. Id = x.Id
  18421. }).ToList();
  18422. jw.Data = new
  18423. {
  18424. groupList = groupList.Select(x => new
  18425. {
  18426. x.Id,
  18427. x.TeamName,
  18428. x.TourCode
  18429. }).ToList(),
  18430. groupInfo = new
  18431. {
  18432. group.VisitDays,
  18433. group.TourCode,
  18434. group.VisitPNumber,
  18435. group.TeamName,
  18436. city
  18437. },
  18438. OpTravelList
  18439. };
  18440. jw.Code = 200;
  18441. jw.Msg = "操作成功!";
  18442. return Ok(jw);
  18443. }
  18444. /// <summary>
  18445. /// 删除团组行程单
  18446. /// </summary>
  18447. /// <returns></returns>
  18448. [HttpPost]
  18449. public IActionResult DelTravel(DelOpTravelDto dto)
  18450. {
  18451. var jw = JsonView(false);
  18452. if (dto.UserId <= 0 || dto.Diid <= 0)
  18453. {
  18454. jw.Msg = "请输入正确的参数!";
  18455. return Ok(jw);
  18456. }
  18457. var isTrue = _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Diid == dto.Diid && x.IsDel == 0)
  18458. .SetColumns(x => new Grp_TravelList
  18459. {
  18460. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  18461. DeleteUserId = dto.UserId,
  18462. IsDel = 1,
  18463. }).ExecuteCommand();
  18464. jw = JsonView(true);
  18465. return Ok(jw);
  18466. }
  18467. /// <summary>
  18468. /// 行程单保存
  18469. /// </summary>
  18470. /// <returns></returns>
  18471. [HttpPost]
  18472. public IActionResult TravelSave(TravelSaveDto dto)
  18473. {
  18474. var jw = JsonView(false);
  18475. if (dto.Arr.Count > 0)
  18476. {
  18477. try
  18478. {
  18479. var travelList_DB = _sqlSugar.Queryable<Grp_TravelList>()
  18480. .Where(x => dto.Arr.Select(x => x.Id).Contains(x.Id))
  18481. .ToList();
  18482. _sqlSugar.BeginTran();
  18483. foreach (var item in dto.Arr)
  18484. {
  18485. if (item.Id == 0)
  18486. {
  18487. throw new Exception("请传入正确的Id");
  18488. }
  18489. //比较上一次的差异
  18490. var findTravel = travelList_DB.Find(x => x.Id == item.Id);
  18491. if (findTravel != null)
  18492. {
  18493. item.Trip = item.Trip.Replace("[++]", string.Empty);
  18494. findTravel.Trip = findTravel.Trip.Replace("[++]", string.Empty);
  18495. item.Trip = CheckStr(findTravel.Trip, item.Trip);
  18496. }
  18497. _sqlSugar.Updateable<Grp_TravelList>().Where(x => x.Id == item.Id)
  18498. .SetColumns(x => new Grp_TravelList
  18499. {
  18500. Trip = item.Trip
  18501. }).ExecuteCommand();
  18502. }
  18503. _sqlSugar.CommitTran();
  18504. jw = JsonView(true);
  18505. }
  18506. catch (Exception ex)
  18507. {
  18508. _sqlSugar.RollbackTran();
  18509. jw.Msg = "程序异常!" + ex.Message;
  18510. }
  18511. }
  18512. else
  18513. {
  18514. jw.Msg = "请传入正确的参数!";
  18515. }
  18516. return Ok(jw);
  18517. }
  18518. private static string CheckStr(string original, string changed)
  18519. {
  18520. // 创建diff_match_patch对象
  18521. var dmp = new diff_match_patch();
  18522. // 计算差异
  18523. List<Diff> diffs = dmp.diff_main(original, changed);
  18524. // 清理和合并差异
  18525. dmp.diff_cleanupSemantic(diffs);
  18526. // 使用StringBuilder构建最终的字符串
  18527. var finalString = new StringBuilder();
  18528. // 输出差异结果,并构建变动后的字符串
  18529. foreach (Diff diff in diffs)
  18530. {
  18531. switch (diff.operation)
  18532. {
  18533. case Operation.EQUAL:
  18534. // 相等的部分,直接添加到最终字符串
  18535. finalString.Append(diff.text);
  18536. break;
  18537. case Operation.INSERT:
  18538. // 插入的部分,添加标记并添加到最终字符串
  18539. finalString.Append("[++]" + diff.text + "[++]");
  18540. break;
  18541. case Operation.DELETE:
  18542. // 删除的部分,不添加到最终字符串
  18543. //finalString.Append("[++]" + diff.text + "[++]");
  18544. break;
  18545. }
  18546. }
  18547. // 输出变动后的字符串
  18548. return finalString.ToString();
  18549. }
  18550. private class tagContent
  18551. {
  18552. public DateTime Date { get; set; }
  18553. public string StartTag { get; set; }
  18554. public string EndTag { get; set; }
  18555. public string Content { get; set; }
  18556. public static int tagLength { get { return 3; } }
  18557. public static Tuple<string, string> TagFormat { get { return new Tuple<string, string>("【#", "#】"); } }
  18558. public string QueryTag { get { return this.StartTag + this.EndTag; } }
  18559. public bool IsFinally { get; set; }
  18560. }
  18561. private static List<string> ExtractContentBetweenTags(string input, string tag)
  18562. {
  18563. var results = new List<string>();
  18564. // 构造正则表达式,匹配形如 [++]内容[++] 的部分
  18565. string pattern = $@"{Regex.Escape(tag)}(.*?){Regex.Escape(tag)}";
  18566. // 添加 RegexOptions.Singleline 选项使 . 匹配包括换行符在内的所有字符
  18567. MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Singleline);
  18568. string[] strValueArr = new string[1];
  18569. foreach (System.Text.RegularExpressions.Match match in matches)
  18570. {
  18571. var strValue = match.Groups[1].Value;
  18572. strValueArr = Regex.Split(strValue, @"\r\n|\n");
  18573. }
  18574. results.AddRange(strValueArr.Where(x => !string.IsNullOrWhiteSpace(x)));
  18575. return results;
  18576. }
  18577. /// <summary>
  18578. /// 导出行程单
  18579. /// </summary>
  18580. /// <param name="dto"></param>
  18581. /// <returns></returns>
  18582. [HttpPost]
  18583. public IActionResult ExportTravel(ExportTravelDto dto)
  18584. {
  18585. var jw = JsonView(false);
  18586. jw.Data = "";
  18587. int diid = 0;
  18588. var Find = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid);
  18589. if (Find == null)
  18590. {
  18591. jw.Msg = "请选择正确的团组!";
  18592. return Ok(jw);
  18593. }
  18594. else
  18595. {
  18596. diid = Find.Id;
  18597. }
  18598. //数据源
  18599. var _travelList = new List<Grp_TravelList>();
  18600. DataTable dtBlack = null;
  18601. try
  18602. {
  18603. dtBlack = GeneralMethod.GetTableByBlackCode(diid);
  18604. }
  18605. catch (Exception)
  18606. {
  18607. jw.Msg = "机票黑屏代码有误!";
  18608. return Ok(jw);
  18609. }
  18610. string CityStr = string.Empty;
  18611. if (dtBlack.Rows.Count == 0)
  18612. {
  18613. jw.Msg = "机票黑屏代码有误!";
  18614. return Ok(jw);
  18615. }
  18616. else
  18617. {
  18618. foreach (DataRow row in dtBlack.Rows)
  18619. {
  18620. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  18621. {
  18622. jw.Msg = "机票黑屏代码有误!" + row["Error"].ToString();
  18623. return Ok(jw);
  18624. }
  18625. }
  18626. CityStr = GeneralMethod.GetGroupCityLine(diid, "/");
  18627. _travelList = _sqlSugar.Queryable<Grp_TravelList>().Where(x => x.Diid == diid && x.IsDel == 0 && x.Issel == 1).ToList();
  18628. }
  18629. // 指定的文字
  18630. var targetTextDic = new Dictionary<string, List<string>>();
  18631. //创建数据源Table
  18632. var dtSource = new DataTable();
  18633. dtSource.Columns.Add("Days", typeof(string));
  18634. dtSource.Columns.Add("Date", typeof(string));
  18635. dtSource.Columns.Add("Week", typeof(string));
  18636. dtSource.Columns.Add("Traffic", typeof(string));
  18637. dtSource.Columns.Add("Trip", typeof(string));
  18638. //获取数据,放到datatable
  18639. foreach (var item in _travelList)
  18640. {
  18641. targetTextDic.Add(item.Date, ExtractContentBetweenTags(item.Trip, "[++]"));
  18642. item.Trip = item.Trip.Replace(tagContent.TagFormat.Item1, string.Empty)
  18643. .Replace(tagContent.TagFormat.Item2, string.Empty)
  18644. .Replace("[++]", string.Empty);
  18645. DataRow dr = dtSource.NewRow();
  18646. dr["Days"] = item.Days;
  18647. dr["Date"] = item.Date;
  18648. dr["Week"] = item.WeekDay;
  18649. dr["Traffic"] = item.Traffic_First
  18650. + "\r\n"
  18651. + item.Traffic_Second;
  18652. dr["Trip"] = item.Trip;
  18653. dtSource.Rows.Add(dr);
  18654. }
  18655. var dic = new Dictionary<string, string>
  18656. {
  18657. { "Dele", Find.TeamName.ToString() + GetNum(Find.VisitDays.ToString()) },
  18658. { "City", CityStr },
  18659. { "Days", Find.VisitDays.ToString() },
  18660. { "DeleCode", Find.TourCode },
  18661. { "Pnum", Find.VisitPNumber.ToString() }
  18662. };
  18663. //模板路径
  18664. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Travel/日行程3.docx";
  18665. //载入模板
  18666. Document doc = null;
  18667. DocumentBuilder builder = null;
  18668. try
  18669. {
  18670. //载入模板
  18671. doc = new Document(tempPath);
  18672. builder = new DocumentBuilder(doc);
  18673. }
  18674. catch (Exception)
  18675. {
  18676. jw.Msg = "模板位置不存在!";
  18677. return Ok(jw);
  18678. }
  18679. foreach (var key in dic.Keys)
  18680. {
  18681. Bookmark bookmark = doc.Range.Bookmarks[key];
  18682. if (bookmark != null)
  18683. {
  18684. builder.MoveToBookmark(key);
  18685. builder.Write(dic[key]);
  18686. }
  18687. }
  18688. //获取word里所有表格
  18689. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  18690. //获取所填表格的序数
  18691. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  18692. try
  18693. {
  18694. //循环赋值
  18695. for (int i = 0; i < dtSource.Rows.Count; i++)
  18696. {
  18697. builder.MoveToCell(0, i + 1, 0, 0);
  18698. builder.Write(dtSource.Rows[i]["Days"].ToString());
  18699. builder.MoveToCell(0, i + 1, 1, 0);
  18700. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  18701. builder.MoveToCell(0, i + 1, 2, 0);
  18702. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  18703. var trip = dtSource.Rows[i]["Trip"].ToString();
  18704. builder.MoveToCell(0, i + 1, 3, 0);
  18705. builder.Write(trip);
  18706. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  18707. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  18708. // 获取特定索引的段落
  18709. Paragraph paragraph = (Paragraph)paragraphs[0];
  18710. Run run = paragraph.Runs[0];
  18711. Aspose.Words.Font font = run.Font;
  18712. font.Name = "黑体";
  18713. //设置双休红色
  18714. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  18715. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  18716. paragraph = (Paragraph)paragraphs[1];
  18717. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  18718. {
  18719. run = paragraph.Runs[0];
  18720. font = run.Font;
  18721. font.Color = Color.Red;
  18722. }
  18723. }
  18724. }
  18725. catch (Exception ex)
  18726. {
  18727. }
  18728. //删除多余行
  18729. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  18730. {
  18731. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  18732. }
  18733. var targetTextList = new List<string>();
  18734. // 遍历文档中的表格
  18735. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  18736. {
  18737. foreach (Aspose.Words.Tables.Row row in table.Rows)
  18738. {
  18739. var cellIndex = 0;
  18740. foreach (Cell cell in row.Cells)
  18741. {
  18742. if (cellIndex == 1 && row.Cells.Count == 4)
  18743. {
  18744. foreach (var target in targetTextDic.Keys)
  18745. {
  18746. if (cell.GetText().Contains(target))
  18747. {
  18748. targetTextList = targetTextDic[target];
  18749. break;
  18750. }
  18751. }
  18752. }
  18753. // 遍历单元格中的所有段落
  18754. foreach (Paragraph paragraph in cell.Paragraphs)
  18755. {
  18756. // 使用临时列表存储原始 Runs,避免修改时影响遍历
  18757. var runs = new List<Run>();
  18758. foreach (Run run in paragraph.Runs)
  18759. {
  18760. runs.Add(run);
  18761. }
  18762. foreach (Run run in runs)
  18763. {
  18764. foreach (var targetText in targetTextList)
  18765. {
  18766. // 检查文字是否包含指定文字
  18767. if (run.Text.Contains(targetText))
  18768. {
  18769. // 将包含的部分设置为红色
  18770. HighlightText(run, targetText, Color.Red);
  18771. }
  18772. }
  18773. }
  18774. }
  18775. cellIndex++;
  18776. }
  18777. }
  18778. }
  18779. string savePath = AppSettingsHelper.Get("WordBasePath") + "Travel/export/";
  18780. if (!Directory.Exists(savePath))
  18781. {
  18782. try
  18783. {
  18784. Directory.CreateDirectory(savePath);
  18785. }
  18786. catch
  18787. {
  18788. }
  18789. }
  18790. string path = savePath + Find.TeamName + "出访日程";
  18791. string ftpPath = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + "Travel/export/" + Find.TeamName + "出访日程";
  18792. try
  18793. {
  18794. Aspose.Words.SaveFormat saveFormat = Aspose.Words.SaveFormat.Doc;
  18795. string postfix = ".docx";
  18796. if (dto.IsPDF == 1)
  18797. {
  18798. saveFormat = Aspose.Words.SaveFormat.Pdf;
  18799. postfix = ".pdf";
  18800. }
  18801. doc.Save(path + postfix, saveFormat);
  18802. jw = JsonView(true, "导出成功", ftpPath + postfix);
  18803. }
  18804. catch (Exception)
  18805. {
  18806. jw = JsonView(false);
  18807. }
  18808. return Ok(jw);
  18809. }
  18810. /// <summary>
  18811. /// 根据大写数字返回小写数字或根据小写数字返回大写数字
  18812. /// </summary>
  18813. /// <param name="num"></param>
  18814. /// <returns></returns>
  18815. static string GetNum(string num)
  18816. {
  18817. string str = "";
  18818. switch (num)
  18819. {
  18820. case "1":
  18821. str = "一";
  18822. break;
  18823. case "2":
  18824. str = "二";
  18825. break;
  18826. case "3":
  18827. str = "三";
  18828. break;
  18829. case "4":
  18830. str = "四";
  18831. break;
  18832. case "5":
  18833. str = "五";
  18834. break;
  18835. case "6":
  18836. str = "六";
  18837. break;
  18838. case "7":
  18839. str = "七";
  18840. break;
  18841. case "8":
  18842. str = "八";
  18843. break;
  18844. case "9":
  18845. str = "九";
  18846. break;
  18847. case "10":
  18848. str = "十";
  18849. break;
  18850. case "11":
  18851. str = "十一";
  18852. break;
  18853. case "12":
  18854. str = "十二";
  18855. break;
  18856. case "一":
  18857. str = "1";
  18858. break;
  18859. case "二":
  18860. str = "2";
  18861. break;
  18862. case "三":
  18863. str = "3";
  18864. break;
  18865. case "四":
  18866. str = "4";
  18867. break;
  18868. case "五":
  18869. str = "5";
  18870. break;
  18871. case "六":
  18872. str = "6";
  18873. break;
  18874. case "七":
  18875. str = "7";
  18876. break;
  18877. case "八":
  18878. str = "8";
  18879. break;
  18880. case "九":
  18881. str = "9";
  18882. break;
  18883. case "十":
  18884. str = "10";
  18885. break;
  18886. case "十一":
  18887. str = "11";
  18888. break;
  18889. case "十二":
  18890. str = "12";
  18891. break;
  18892. }
  18893. return str;
  18894. }
  18895. /// <summary>
  18896. /// 高亮包含指定文字的部分
  18897. /// </summary>
  18898. /// <param name="run"></param>
  18899. /// <param name="targetText"></param>
  18900. /// <param name="color"></param>
  18901. static void HighlightText(Run run, string targetText, Color color)
  18902. {
  18903. string text = run.Text;
  18904. int startIndex = text.IndexOf(targetText, StringComparison.Ordinal);
  18905. if (startIndex >= 0)
  18906. {
  18907. Paragraph parentParagraph = (Paragraph)run.ParentNode;
  18908. // 前部分
  18909. if (startIndex > 0)
  18910. {
  18911. Run beforeRun = (Run)run.Clone(true);
  18912. beforeRun.Text = text.Substring(0, startIndex);
  18913. parentParagraph.InsertBefore(beforeRun, run);
  18914. }
  18915. // 匹配部分
  18916. Run matchRun = (Run)run.Clone(true);
  18917. matchRun.Text = text.Substring(startIndex, targetText.Length);
  18918. matchRun.Font.Color = color;
  18919. parentParagraph.InsertBefore(matchRun, run);
  18920. // 后部分
  18921. if (startIndex + targetText.Length < text.Length)
  18922. {
  18923. Run afterRun = (Run)run.Clone(true);
  18924. afterRun.Text = text.Substring(startIndex + targetText.Length);
  18925. parentParagraph.InsertBefore(afterRun, run);
  18926. }
  18927. // 删除原始Run
  18928. run.Remove();
  18929. }
  18930. }
  18931. #endregion
  18932. #endregion
  18933. #region 团组成本
  18934. /// <summary>
  18935. /// 团组成本数据初始化
  18936. /// </summary>
  18937. /// <param name="dto"></param>
  18938. /// <returns></returns>
  18939. [HttpPost]
  18940. public async Task<IActionResult> GroupCostInit(GroupCostInItDto dto)
  18941. {
  18942. var groupList = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  18943. Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  18944. WHEN COUNT(*) >= 0 THEN 'True'
  18945. ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  18946. Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  18947. ").ToList(); //团组列表
  18948. int diid = dto.Diid == -1 ? groupList.First().Id : dto.Diid;
  18949. var groupInfo = await _groupRepository.PostShareGroupInfo(new ShareGroupInfoDto { PortType = 1, Id = diid }); //团组信息
  18950. var visaCountryInfoArr = new ArrayList();
  18951. var groupinfoValue = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == diid && x.IsDel == 0);
  18952. if (groupinfoValue != null)
  18953. {
  18954. var countryArr = groupinfoValue.VisitCountry ??= string.Empty;
  18955. var dicity = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == groupinfoValue.CityId);
  18956. dicity ??= new Sys_Cities()
  18957. {
  18958. ParentId = 122
  18959. };
  18960. var diparent = _sqlSugar.Queryable<Sys_Cities>().First(x => x.IsDel == 0 && x.Id == dicity.ParentId);
  18961. var spArr = new string[1] { countryArr };
  18962. if (countryArr.Contains("|"))
  18963. {
  18964. spArr = countryArr.Split("|");
  18965. }
  18966. else if (countryArr.Contains("、"))
  18967. {
  18968. spArr = countryArr.Split("、");
  18969. }
  18970. foreach (var item in spArr.Where(x => !string.IsNullOrWhiteSpace(x)).ToList())
  18971. {
  18972. try
  18973. {
  18974. var visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  18975. .Where(x => x.IsDel == 0 && x.Country == item)
  18976. .ToList();
  18977. if (!visa.Any())
  18978. {
  18979. visa = _sqlSugar.Queryable<Res_VisaFeeStandard>()
  18980. .Where(x => x.IsDel == 0 && x.Country.Contains(item))
  18981. .ToList();
  18982. }
  18983. if (visa.Any())
  18984. {
  18985. var visainfo = _sqlSugar.Queryable<Res_VisaFeeStandardDetails>()
  18986. .Where(x => x.IsDel == 0 && visa.Select(x => x.Id).Contains(x.ParentId))
  18987. .ToList();
  18988. var visaMain = visainfo.FirstOrDefault(x => x.ProvinceId == diparent.Id);
  18989. var visayinsiValue = visainfo.FirstOrDefault(x => x.ParentId == visa.FirstOrDefault(x => x.FeeType == 1)?.Id);
  18990. visaCountryInfoArr.Add(new
  18991. {
  18992. country = item,
  18993. yinsi = new
  18994. {
  18995. Id = visayinsiValue.Id,
  18996. value = visayinsiValue.SmallVisaPrice
  18997. },
  18998. visaMain = new
  18999. {
  19000. Id = visaMain.Id,
  19001. IsVisaOnArrival = visaMain.IsVisaOnArrival ? "是" : "否",
  19002. IsElectronicSign = visaMain.IsElectronicSign ? "是" : "否",
  19003. VisaTime = visaMain.VisaTime,
  19004. IsVisaExemptionLarge = visaMain.IsVisaExemptionLarge ? "是" : "否",
  19005. LargeVisaPrice = visaMain.LargeVisaPrice,
  19006. LargeAgencyFee = visaMain.LargeAgencyFee,
  19007. IsVisaExemptionSmall = visaMain.IsVisaExemptionSmall ? "是" : "否",
  19008. SmallVisaPrice = visaMain.SmallVisaPrice,
  19009. SmallAgencyFee = visaMain.SmallAgencyFee,
  19010. NormExtFee = visaMain.NormExtFee,
  19011. UrgExtFee = visaMain.UrgExtFee,
  19012. IsUrgent = visaMain.IsUrgent ? "是" : "否",
  19013. UrgentTime = visaMain.UrgentTime,
  19014. UrgentPrice = visaMain.UrgentPrice,
  19015. UrgentPriceDesc = visaMain.UrgentPriceDesc,
  19016. Remark = visaMain.Remark,
  19017. }
  19018. });
  19019. }
  19020. }
  19021. catch (Exception ex)
  19022. {
  19023. //写入日志
  19024. _logger.LogError(ex, "团组成本解析签证异常!");
  19025. }
  19026. }
  19027. }
  19028. var groupChecks = _checkBoxs.GetCheckBoxsByDiid(diid); //团组选中信息 可枚举
  19029. var groupCost = _GroupCostRepository.GetAllByDiid(diid); //团组列表信息
  19030. #region 屏蔽黑屏代码生成
  19031. //var create = _GroupCostRepository.
  19032. // CreateGroupCostByBlackCode(dto.Diid);
  19033. //if (groupCost.Count == 0 && create.Code == 0)
  19034. //{
  19035. // groupCost = (create.Data as List<Grp_GroupCost>) ?? new List<Grp_GroupCost>();
  19036. //}
  19037. #endregion
  19038. var groupCostMap = _mapper.Map<List<Grp_GroupCostDto>>(groupCost);
  19039. var hotelNumber = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(diid); //酒店数量 可枚举
  19040. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(diid); //成本系数 可枚举
  19041. groupCostMap = groupCostMap.Select(x =>
  19042. {
  19043. if (DateTime.TryParse(x.Date, out DateTime dataForamt))
  19044. {
  19045. x.Date = dataForamt.ToString("yyyy-MM-dd");
  19046. }
  19047. return x;
  19048. }).ToList();
  19049. //GroupCostParameter.Add(new
  19050. // Grp_GroupCostParameter());
  19051. var GroupCostParameterMap = _mapper.Map<List<Grp_GroupCostParameterDto>>(GroupCostParameter);
  19052. bool hotelIsTrue = _sqlSugar.Queryable<Grp_HotelInquiry>().Where(x => x.DiId == diid && x.IsDel == 0).Count() > 0;
  19053. var groupModuleOperators = GeneralMethod.GetGroupModuleOperators(diid);
  19054. return Ok(JsonView(new
  19055. {
  19056. groupList,
  19057. groupInfo,
  19058. groupChecks,
  19059. groupCost = groupCostMap,
  19060. hotelNumber,
  19061. GroupCostParameter = GroupCostParameterMap,
  19062. visaCountryInfoArr = visaCountryInfoArr,
  19063. baoPi = _GroupCostParameterRepository.GetBaoPi(diid),
  19064. blackCodeIsTrue = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).Any(), //create.Code == 0 ? true : false,
  19065. hotelIsTrue,
  19066. groupModuleOperators
  19067. }));
  19068. }
  19069. /// <summary>
  19070. /// 团组成本信息保存
  19071. /// </summary>
  19072. /// <param name="dto"></param>
  19073. /// <returns></returns>
  19074. [HttpPost]
  19075. public async Task<IActionResult> SaveGroupCost(GroupCostSavaDto dto)
  19076. {
  19077. if (dto.Diid <= 0 || dto.Userid <= 0)
  19078. {
  19079. return Ok(JsonView(false));
  19080. }
  19081. JsonView jw = null;
  19082. bool isTrue = false;
  19083. #region 复制团组成本
  19084. //if (dto.Diid == 2581)
  19085. //{
  19086. // dto.Diid = 2599;
  19087. // dto.CheckBoxs.ForEach(x =>
  19088. // {
  19089. // x.Diid = 2599;
  19090. // });
  19091. // dto.GroupCosts.ForEach(x =>
  19092. // {
  19093. // x.Diid = 2599;
  19094. // });
  19095. // dto.CostTypeHotelNumbers.ForEach(x =>
  19096. // {
  19097. // x.Diid = 2599;
  19098. // });
  19099. // dto.GroupCostParameters.ForEach(x =>
  19100. // {
  19101. // x.DiId = 2599;
  19102. // });
  19103. //}
  19104. #endregion
  19105. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  19106. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  19107. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  19108. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  19109. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  19110. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  19111. try
  19112. {
  19113. _sqlSugar.BeginTran();
  19114. isTrue = await _GroupCostRepository.
  19115. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  19116. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  19117. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  19118. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  19119. _sqlSugar.CommitTran();
  19120. jw = JsonView(true, "保存成功!", isTrue);
  19121. }
  19122. catch (Exception)
  19123. {
  19124. _sqlSugar.RollbackTran();
  19125. jw = JsonView(false);
  19126. }
  19127. return Ok(jw);
  19128. }
  19129. /// <summary>
  19130. /// 复制团组成本信息
  19131. /// </summary>
  19132. /// <param name="dto"></param>
  19133. /// <returns></returns>
  19134. [HttpPost]
  19135. public async Task<IActionResult> CopyGroupCost(CopyGroupCostDto dto)
  19136. {
  19137. if (dto.Diid <= 0 || dto.Userid <= 0 || dto.ToGroupId <= 0)
  19138. {
  19139. return Ok(JsonView(false, "参数有误!"));
  19140. }
  19141. #region 复制团组成本
  19142. dto.Diid = dto.ToGroupId;
  19143. dto.CheckBoxs.ForEach(x =>
  19144. {
  19145. x.Diid = dto.ToGroupId;
  19146. });
  19147. dto.GroupCosts.ForEach(x =>
  19148. {
  19149. x.Diid = dto.ToGroupId;
  19150. });
  19151. dto.CostTypeHotelNumbers.ForEach(x =>
  19152. {
  19153. x.Diid = dto.ToGroupId;
  19154. });
  19155. dto.GroupCostParameters.ForEach(x =>
  19156. {
  19157. x.DiId = dto.ToGroupId;
  19158. });
  19159. #endregion
  19160. JsonView jw = null;
  19161. bool isTrue = false;
  19162. var Grp_groups = _mapper.Map<List<Grp_GroupCost>>(dto.GroupCosts);
  19163. Grp_groups.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; }); //.ToString("yyyy-MM-dd HH:mm:ss")
  19164. var Grp_CheckBoxs = _mapper.Map<List<Grp_CheckBoxs>>(dto.CheckBoxs);
  19165. Grp_CheckBoxs.ForEach(x => { x.CreateUserId = dto.Userid; x.CreateTime = DateTime.Now; });
  19166. var Grp_HotelNumber = _mapper.Map<List<Grp_CostTypeHotelNumber>>(dto.CostTypeHotelNumbers);
  19167. var Grp_CostParameters = _mapper.Map<List<Grp_GroupCostParameter>>(dto.GroupCostParameters);
  19168. try
  19169. {
  19170. _sqlSugar.BeginTran();
  19171. isTrue = await _GroupCostRepository.
  19172. SaveGroupCostList(Grp_groups, dto.Diid, dto.Userid); //列表
  19173. isTrue = await _checkBoxs.SaveCheckBoxs(Grp_CheckBoxs, dto.Diid); //选中项
  19174. isTrue = await _CostTypeHotelNumberRepository.SaveHotelNumber(Grp_HotelNumber, dto.Userid, dto.Diid); //酒店房间数量
  19175. isTrue = await _GroupCostParameterRepository.SaveAsync(Grp_CostParameters, dto.Userid, dto.Diid); //系数
  19176. _sqlSugar.CommitTran();
  19177. jw = JsonView(true, "保存成功!", isTrue);
  19178. }
  19179. catch (Exception)
  19180. {
  19181. _sqlSugar.RollbackTran();
  19182. jw = JsonView(false);
  19183. }
  19184. return Ok(jw);
  19185. }
  19186. /// <summary>
  19187. /// 司兼导数据
  19188. /// </summary>
  19189. /// <param name="dto"></param>
  19190. /// <returns></returns>
  19191. [HttpPost]
  19192. public IActionResult GetCarGuides(CarGuidesDto dto)
  19193. {
  19194. var Data = _sqlSugar.SqlQueryable<Grp_CarGuides>($@" select * from Grp_CarGuides where isdel = 0 ").ToList();
  19195. return Ok(JsonView(true, "获取成功!", Data));
  19196. }
  19197. /// <summary>
  19198. /// 导游数据
  19199. /// </summary>
  19200. /// <param name="dto"></param>
  19201. /// <returns></returns>
  19202. [HttpPost]
  19203. public IActionResult GetGuidesInfo(CarGuidesDto dto)
  19204. {
  19205. //var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" SELECT* FROM (
  19206. // 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
  19207. // where RowNumber BETWEEN {(dto.Page - 1) * dto.Size + 1} and {(dto.Page) * dto.Size}").ToList();
  19208. var Data = _sqlSugar.SqlQueryable<Grp_GuidesInfo>($@" select * from Grp_GuidesInfo where isdel = 0 ").ToList();
  19209. return Ok(JsonView(true, "获取成功!", Data));
  19210. }
  19211. /// <summary>
  19212. /// 成本车数据
  19213. /// </summary>
  19214. /// <param name="dto"></param>
  19215. /// <returns></returns>
  19216. [HttpPost]
  19217. public IActionResult GetCarInfo(CarGuidesDto dto)
  19218. {
  19219. var Data = _sqlSugar.SqlQueryable<Grp_CarInfo>($@" select * from Grp_CarInfo where isdel = 0 ").ToList();
  19220. return Ok(JsonView(true, "获取成功!", Data));
  19221. }
  19222. /// <summary>
  19223. /// 景点数据
  19224. /// </summary>
  19225. /// <param name="dto"></param>
  19226. /// <returns></returns>
  19227. [HttpPost]
  19228. public IActionResult GetScenicSpotInfo(CarGuidesDto dto)
  19229. {
  19230. var Data = _sqlSugar.SqlQueryable<Grp_ScenicSpotInfo>($@" select * from Grp_ScenicSpotInfo where isdel = 0 ").ToList();
  19231. return Ok(JsonView(true, "获取成功!", Data));
  19232. }
  19233. /// <summary>
  19234. /// 成本通知
  19235. /// </summary>
  19236. /// <param name="dto"></param>
  19237. /// <returns></returns>
  19238. [HttpPost]
  19239. public async Task<IActionResult> GroupIsShare(GroupIsShareDto dto)
  19240. {
  19241. if (dto.Diid < 0)
  19242. {
  19243. return Ok(JsonView(false));
  19244. }
  19245. JsonView jw;
  19246. var GroupCostParameter = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  19247. if (GroupCostParameter != null)
  19248. {
  19249. int IsShare = 0;
  19250. if (GroupCostParameter.IsShare == 0) IsShare = 1;
  19251. else if (GroupCostParameter.IsShare == 1) IsShare = 0;
  19252. bool isTrue = await _GroupCostParameterRepository.UpdateIsShareById(GroupCostParameter.Id, IsShare);
  19253. string msg = string.Empty;
  19254. if (isTrue)
  19255. {
  19256. if (IsShare == 0)
  19257. {
  19258. msg = "禁止通知,其他模块操作人员不可见此成本信息!";
  19259. }
  19260. else
  19261. {
  19262. #region 企微通知对应岗位用户
  19263. try
  19264. {
  19265. await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.Diid);
  19266. //机票预算群通知
  19267. await AppNoticeLibrary.SendChatMsg_AirCostChat(dto.Diid, QiyeWeChatEnum.AirCostChat01);
  19268. }
  19269. catch (Exception)
  19270. {
  19271. }
  19272. #endregion
  19273. msg = "通知成功,其他模块操作人员可见此成本信息!";
  19274. }
  19275. jw = JsonView(isTrue, msg, new { IsShare });
  19276. }
  19277. else
  19278. {
  19279. msg = "修改失败!";
  19280. jw = JsonView(isTrue, msg);
  19281. }
  19282. }
  19283. else
  19284. {
  19285. jw = JsonView(false, "该团没有数据,请添加数据,保存后再操作!");
  19286. }
  19287. return Ok(jw);
  19288. }
  19289. /// <summary>
  19290. /// 导出报价单
  19291. /// </summary>
  19292. /// <param name="dto"></param>
  19293. /// <returns></returns>
  19294. [HttpPost]
  19295. public async Task<IActionResult> ExportPriceCheckWordFile(GroupCostExportWordFile dto)
  19296. {
  19297. if (dto.Diid == 0)
  19298. {
  19299. return Ok(JsonView(false, "请传递团组id"));
  19300. }
  19301. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  19302. if (deleInfo.Code != 0)
  19303. {
  19304. return Ok(JsonView(false, "团组信息查询失败!"));
  19305. }
  19306. var di = deleInfo.Data as DelegationInfoWebView;
  19307. if (di != null)
  19308. {
  19309. di.TeamName = di.TeamName.Replace("|", "、");
  19310. di.VisitCountry = di.VisitCountry.Replace("|", "、");
  19311. //文件名
  19312. string strFileName = di.TeamName + "-收款账单.doc";
  19313. //获取模板
  19314. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  19315. //载入模板
  19316. Document doc = new Document(tmppath);
  19317. decimal TotalPrice = 0.00M;
  19318. string itemStr = string.Empty;
  19319. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  19320. //airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  19321. airSouer.Add("JJCTBR", "经济舱及酒店双人间");
  19322. airSouer.Add("JJCSGR", "经济舱及酒店单人间");
  19323. airSouer.Add("GWCSGR", "公务舱及酒店单人间");
  19324. airSouer.Add("GWCJSES", "公务舱及酒店小套房");
  19325. airSouer.Add("GWCSUITE", "公务舱及酒店套房");
  19326. airSouer.Add("JJCSUITE", "经济舱及酒店套房");
  19327. var groupCostType = dto.airs.GroupBy(x => x.costType).OrderBy(x => x.Key);
  19328. foreach (var cost in groupCostType)
  19329. {
  19330. var List = cost.ToList();
  19331. if (cost.Key == "A")
  19332. {
  19333. foreach (var ListItem in List)
  19334. {
  19335. if (ListItem.number > 0)
  19336. {
  19337. if (ListItem.code.Contains("TBR"))
  19338. {
  19339. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19340. }
  19341. else
  19342. {
  19343. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19344. }
  19345. TotalPrice += (ListItem.number * ListItem.price);
  19346. }
  19347. }
  19348. }
  19349. else
  19350. {
  19351. itemStr = itemStr.Insert(0, "A段\r\n");
  19352. itemStr += "B段\r\n";
  19353. foreach (var ListItem in List)
  19354. {
  19355. if (ListItem.number > 0)
  19356. {
  19357. if (ListItem.code.Contains("TBR"))
  19358. {
  19359. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + (ListItem.number / 2) + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19360. }
  19361. else
  19362. {
  19363. itemStr += "团费(" + airSouer[ListItem.code] + ") RMB " + ListItem.price.ToString("F2") + "/人*" + ListItem.number + "(" + ListItem.number + "间) ............合计 RMB " + (ListItem.number * ListItem.price).ToString("#0.00") + "\n";
  19364. }
  19365. TotalPrice += (ListItem.number * ListItem.price);
  19366. }
  19367. }
  19368. }
  19369. }
  19370. #region 替换Word模板书签内容
  19371. Dictionary<string, string> marks = new Dictionary<string, string>();
  19372. marks.Add("To", di.ClientUnit);//付款方
  19373. marks.Add("ToTel", di.TellPhone);//付款方电话
  19374. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  19375. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  19376. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  19377. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  19378. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  19379. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  19380. marks.Add("PayItemContent", itemStr);//详细信息
  19381. marks.Add("Total", TotalPrice.ToString("F2"));//合计
  19382. #endregion
  19383. ////注
  19384. //if (doc.Range.Bookmarks["Attention"] != null)
  19385. //{
  19386. // Bookmark mark = doc.Range.Bookmarks["Attention"];
  19387. // mark.Text = frList[0].Attention;
  19388. //}
  19389. foreach (var item in marks.Keys)
  19390. {
  19391. if (doc.Range.Bookmarks[item] != null)
  19392. {
  19393. Bookmark mark = doc.Range.Bookmarks[item];
  19394. mark.Text = marks[item];
  19395. }
  19396. }
  19397. byte[] bytes = null;
  19398. using (MemoryStream stream = new MemoryStream())
  19399. {
  19400. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  19401. bytes = stream.ToArray();
  19402. }
  19403. //doc.Save((AppSettingsHelper.Get("WordBasePath") + "Template/") + strFileName);
  19404. return Ok(JsonView(true, "", new
  19405. {
  19406. Data = bytes,
  19407. strFileName,
  19408. }));
  19409. }
  19410. else
  19411. {
  19412. return Ok(JsonView(false, "团组信息不存在!"));
  19413. }
  19414. }
  19415. /// <summary>
  19416. /// 导出团组成本
  19417. /// </summary>
  19418. /// <param name="dto"></param>
  19419. /// <returns></returns>
  19420. [HttpPost]
  19421. public async Task<IActionResult> ExportGroupCostExcelFile(GroupCostExportExcelFile dto)
  19422. {
  19423. var jw = JsonView(false);
  19424. if (dto.Diid == 0)
  19425. {
  19426. return Ok(JsonView(false, "请传递团组id"));
  19427. }
  19428. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  19429. if (deleInfo.Code != 0)
  19430. {
  19431. return Ok(JsonView(false, "团组信息查询失败!"));
  19432. }
  19433. var di = deleInfo.Data as DelegationInfoWebView;
  19434. if (di == null)
  19435. {
  19436. return Ok(JsonView(false, "团组信息查询失败!"));
  19437. }
  19438. List<GroupCost_Excel> List_GC1 = new List<GroupCost_Excel>();
  19439. WorkbookDesigner designer = new WorkbookDesigner();
  19440. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/团组-成本.xls"));
  19441. var List_GC = _GroupCostRepository.GetAllByDiid(dto.Diid);
  19442. List<int> hideColumnList = new List<int>();
  19443. var ColumnSetting = new[]
  19444. {
  19445. new { tag = "VF", Index = 4, P = "CarCost" },
  19446. new { tag = "VN", Index = 5, P = "CarNumber" },
  19447. new { tag = "VRD", Index = 6, P = "CarTiming" },
  19448. new { tag = "T/G S", Index = 7, P = "TGS" },
  19449. new { tag = "TGWH", Index = 8, P = "TGWH" },
  19450. new { tag = "T/G OF", Index = 9, P = "TGOF" },
  19451. new { tag = "T/G M", Index = 10, P = "TGM" },
  19452. new { tag = "T/G A", Index = 11, P = "TGA" },
  19453. new { tag = "T/G TF", Index = 12, P = "TGTF" },
  19454. new { tag = "T/G EF", Index = 13, P = "TGEF" },
  19455. new { tag = "C/F S", Index = 14, P = "CFS" },
  19456. new { tag = "C/F M", Index = 15, P = "CFM" },
  19457. new { tag = "C/F OF", Index = 16, P = "CFOF" },
  19458. new { tag = "B", Index = 17, P = "B" },
  19459. new { tag = "L", Index = 18, P = "L" },
  19460. new { tag = "D", Index = 19, P = "D" },
  19461. new { tag = "TBR", Index = 20, P = "TBR" },
  19462. new { tag = "SGR", Index = 21, P = "SGR" },
  19463. new { tag = "JS/ES", Index = 22, P = "JS_ES" },
  19464. new { tag = "Suite", Index = 23, P = "Suite" },
  19465. new { tag = "ACCO N", Index = 24, P = "ACCON" },
  19466. new { tag = "T/V", Index = 25, P = "TV" },
  19467. new { tag = "1/L", Index = 26, P = "iL" },
  19468. new { tag = "I/F", Index = 27, P = "IF" },
  19469. new { tag = "EF", Index = 28, P = "EF" },
  19470. new { tag = "B/R/F", Index = 29, P = "B_R_F" },
  19471. new { tag = "TE", Index = 30, P = "TE" },
  19472. new { tag = "T/G T", Index = 31, P = "TGTips" },
  19473. new { tag = "DRV T", Index = 32, P = "DRVTips" },
  19474. new { tag = "P/C", Index = 33, P = "PC" },
  19475. new { tag = "T/L F", Index = 34, P = "TLF" },
  19476. new { tag = "E/C T", Index = 35, P = "ECT" }
  19477. };
  19478. Func<string, bool> isEmpty = (str) =>
  19479. {
  19480. if (decimal.TryParse(str, out decimal str_De) && str_De == 0)
  19481. {
  19482. return true;
  19483. }
  19484. if (string.IsNullOrWhiteSpace(str))
  19485. {
  19486. return true;
  19487. }
  19488. return false;
  19489. };
  19490. for (int i = 0; i < List_GC.Count; i++)
  19491. {
  19492. GroupCost_Excel gc = new GroupCost_Excel();
  19493. gc.Id = List_GC[i].Id;
  19494. gc.Diid = List_GC[i].Diid.ToString();
  19495. gc.DAY = List_GC[i].DAY;
  19496. string week = "";
  19497. if (!string.IsNullOrEmpty(List_GC[i].Date.Trim()))
  19498. week = CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(List_GC[i].Date).DayOfWeek);
  19499. gc.Date = (List_GC[i].Date + "\n" + week).ToString();
  19500. gc.ITIN = List_GC[i].ITIN;
  19501. gc.CarType = List_GC[i].CarType;
  19502. gc.CarTiming = isEmpty(List_GC[i].CarTiming.ToString()) ? "" : List_GC[i].CarTiming.ToString();
  19503. gc.CarCost = isEmpty(List_GC[i].CarCost.ToString()) ? "" : List_GC[i].CarCost.ToString();
  19504. gc.CarNumber = isEmpty(List_GC[i].CarNumber.ToString()) ? "" : List_GC[i].CarNumber.ToString();
  19505. gc.TGS = isEmpty(List_GC[i].TGS.ToString()) ? "" : List_GC[i].TGS.ToString();
  19506. gc.TGWH = isEmpty(List_GC[i].TGWH.ToString()) ? "" : List_GC[i].TGWH.ToString();
  19507. gc.TGN = isEmpty(List_GC[i].TGN.ToString()) ? "" : List_GC[i].TGN.ToString();
  19508. gc.TGOF = isEmpty(List_GC[i].TGOF.ToString()) ? "" : List_GC[i].TGOF.ToString();
  19509. gc.TGM = isEmpty(List_GC[i].TGM.ToString()) ? "" : List_GC[i].TGM.ToString();
  19510. gc.TGA = isEmpty(List_GC[i].TGA.ToString()) ? "" : List_GC[i].TGA.ToString();
  19511. gc.TGTF = isEmpty(List_GC[i].TGTF.ToString()) ? "" : List_GC[i].TGTF.ToString();
  19512. gc.TGEF = isEmpty(List_GC[i].TGEF.ToString()) ? "" : List_GC[i].TGEF.ToString();
  19513. gc.CFS = isEmpty(List_GC[i].CFS.ToString()) ? "" : List_GC[i].CFS.ToString();
  19514. gc.CFM = isEmpty(List_GC[i].CFM.ToString()) ? "" : List_GC[i].CFM.ToString();
  19515. gc.CFOF = isEmpty(List_GC[i].CFOF.ToString()) ? "" : List_GC[i].CFOF.ToString();
  19516. gc.B = isEmpty(List_GC[i].B.ToString()) ? "" : List_GC[i].B.ToString();
  19517. gc.L = isEmpty(List_GC[i].L.ToString()) ? "" : List_GC[i].L.ToString();
  19518. gc.D = isEmpty(List_GC[i].D.ToString()) ? "" : List_GC[i].D.ToString();
  19519. gc.TBR = isEmpty(List_GC[i].TBR.ToString()) ? "" : List_GC[i].TBR.ToString();
  19520. gc.SGR = isEmpty(List_GC[i].SGR.ToString()) ? "" : List_GC[i].SGR.ToString();
  19521. gc.JS_ES = isEmpty(List_GC[i].JS_ES.ToString()) ? "" : List_GC[i].JS_ES.ToString();
  19522. gc.Suite = isEmpty(List_GC[i].Suite.ToString()) ? "" : List_GC[i].Suite.ToString();
  19523. gc.ACCON = isEmpty(List_GC[i].ACCON.ToString()) ? "" : List_GC[i].ACCON.ToString();
  19524. gc.TV = isEmpty(List_GC[i].TV.ToString()) ? "" : List_GC[i].TV.ToString();
  19525. gc.iL = isEmpty(List_GC[i].iL.ToString()) ? "" : List_GC[i].iL.ToString();
  19526. gc.IF = isEmpty(List_GC[i].IF.ToString()) ? "" : List_GC[i].IF.ToString();
  19527. gc.EF = isEmpty(List_GC[i].EF.ToString()) ? "" : List_GC[i].EF.ToString();
  19528. gc.B_R_F = isEmpty(List_GC[i].B_R_F.ToString()) ? "" : List_GC[i].B_R_F.ToString();
  19529. gc.TE = isEmpty(List_GC[i].TE.ToString()) ? "" : List_GC[i].TE.ToString();
  19530. gc.TGTips = isEmpty(List_GC[i].TGTips.ToString()) ? "" : List_GC[i].TGTips.ToString();
  19531. gc.DRVTips = isEmpty(List_GC[i].DRVTips.ToString()) ? "" : List_GC[i].DRVTips.ToString();
  19532. gc.PC = isEmpty(List_GC[i].PC.ToString()) ? "" : List_GC[i].PC.ToString();
  19533. gc.TLF = isEmpty(List_GC[i].TLF.ToString()) ? "" : List_GC[i].TLF.ToString();
  19534. gc.ECT = isEmpty(List_GC[i].ECT.ToString()) ? "" : List_GC[i].ECT.ToString();
  19535. gc.EFR = List_GC[i].EFR;
  19536. List_GC1.Add(gc);
  19537. }
  19538. if (List_GC1.Count > 0)
  19539. {
  19540. var p = List_GC1[0];
  19541. var prs = p.GetType().GetProperties();
  19542. foreach (var item in prs)
  19543. {
  19544. var tp = item.PropertyType;
  19545. if (tp == typeof(int))
  19546. {
  19547. var val = List_GC1.Sum(x =>
  19548. {
  19549. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  19550. return raw == null ? 0 : (int)raw;
  19551. });
  19552. if (val == 0)
  19553. {
  19554. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19555. if (columnSetting != null)
  19556. {
  19557. hideColumnList.Add(columnSetting.Index);
  19558. }
  19559. }
  19560. }
  19561. if (tp == typeof(decimal))
  19562. {
  19563. var val = List_GC1.Sum(x =>
  19564. {
  19565. var raw = x.GetType().GetProperty(item.Name).GetValue(x);
  19566. return raw == null ? 0m : (decimal)raw;
  19567. });
  19568. if (val == 0)
  19569. {
  19570. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19571. if (columnSetting != null)
  19572. {
  19573. hideColumnList.Add(columnSetting.Index);
  19574. }
  19575. }
  19576. }
  19577. if (tp == typeof(string))
  19578. {
  19579. var val = List_GC1.Sum(x =>
  19580. {
  19581. var str = (string)x.GetType().GetProperty(item.Name).GetValue(x);
  19582. if (decimal.TryParse(str, out decimal str_De))
  19583. {
  19584. return str_De;
  19585. }
  19586. else
  19587. {
  19588. return string.IsNullOrEmpty((string)x.GetType().GetProperty(item.Name).GetValue(x)) ? 0 : 1;
  19589. }
  19590. });
  19591. if (val == 0)
  19592. {
  19593. var columnSetting = ColumnSetting.FirstOrDefault(x => x.P == item.Name);
  19594. if (columnSetting != null)
  19595. {
  19596. hideColumnList.Add(columnSetting.Index);
  19597. }
  19598. }
  19599. }
  19600. }
  19601. }
  19602. var dt = CommonFun.GetDataTableFromIList(List_GC1);
  19603. dt.TableName = "TB";
  19604. //报表标题等不用dt的值
  19605. designer.SetDataSource("TeamName", dto.title.TeamName);
  19606. designer.SetDataSource("Pnumber", dto.title.GroupNumber);
  19607. designer.SetDataSource("Tax", dto.title.Tax);
  19608. //designer.SetDataSource("FFYS", lblHotelCB.Text);
  19609. designer.SetDataSource("Currency", dto.title.Currency);
  19610. //designer.SetDataSource("HotelXS", txtHotelXS.Text);
  19611. designer.SetDataSource("Rate", dto.title.Rate);
  19612. var hotels = _CostTypeHotelNumberRepository.GetCostTypeHotelNumberByDiid(dto.Diid);
  19613. var Aparams = hotels.Find(x => x.Type == "Default");
  19614. if (Aparams == null)
  19615. {
  19616. return Ok(jw);
  19617. }
  19618. //酒店数量
  19619. var txtSGRNumber = Aparams.SGR.ToString();
  19620. var txtTBRNumber = Aparams.TBR.ToString();
  19621. var txtJSESNumber = Aparams.JSES.ToString();
  19622. var txtSUITENumbe = Aparams.SUITE.ToString();
  19623. if (dto.costType == "B")
  19624. {
  19625. Aparams = hotels.Find(x => x.Type == "A");
  19626. var Bparams = hotels.Find(x => x.Type == "B");
  19627. if (Aparams == null || Bparams == null)
  19628. {
  19629. return Ok(jw);
  19630. }
  19631. txtSGRNumber = "A段人数:" + Aparams.SGR.ToString() + " B段人数:" + Bparams.SGR.ToString();
  19632. txtTBRNumber = "A段人数:" + Aparams.TBR.ToString() + " B段人数:" + Bparams.TBR.ToString();
  19633. txtJSESNumber = "A段人数:" + Aparams.JSES.ToString() + " B段人数:" + Bparams.JSES.ToString();
  19634. txtSUITENumbe = "A段人数:" + Aparams.SUITE.ToString() + " B段人数:" + Bparams.SUITE.ToString();
  19635. }
  19636. designer.SetDataSource("SGRNumber", txtSGRNumber);
  19637. designer.SetDataSource("TBRNumber", txtTBRNumber);
  19638. designer.SetDataSource("JSESNumber", txtJSESNumber);
  19639. designer.SetDataSource("SUITENumber", txtSUITENumbe);
  19640. var ws = designer.Workbook.Worksheets[1];
  19641. int Row = List_GC.Count;
  19642. int startIndex = 0;
  19643. int HideRows = 0;
  19644. Row = 0;
  19645. List<int> hideRowsList = new List<int>();
  19646. decimal TzZCB2 = 0.00M, TzZLR2 = 0.00M, TzZBJ2 = 0.00M;
  19647. #region A段left数据
  19648. var left = dto.leftInfo.Find(x => x.Type == "A");
  19649. if (left == null)
  19650. {
  19651. return Ok(jw);
  19652. }
  19653. var leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("签证"));
  19654. if (leftBindData != null)
  19655. {
  19656. designer.SetDataSource("VisaDRCB", leftBindData.cb);
  19657. designer.SetDataSource("VisaRS", leftBindData.rs);
  19658. designer.SetDataSource("VisaXS", leftBindData.xs);
  19659. designer.SetDataSource("VisaZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19660. designer.SetDataSource("VisaDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19661. designer.SetDataSource("VisaZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19662. designer.SetDataSource("VisaDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19663. designer.SetDataSource("VisaZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19664. }
  19665. else
  19666. {
  19667. hideRowsList.Add(Row + startIndex + HideRows);
  19668. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19669. }
  19670. HideRows += 2;
  19671. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("保险"));
  19672. if (leftBindData != null)
  19673. {
  19674. designer.SetDataSource("BXDRCB", leftBindData.cb);
  19675. designer.SetDataSource("BXRS", leftBindData.rs);
  19676. designer.SetDataSource("BXXS", leftBindData.xs);
  19677. designer.SetDataSource("BXZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19678. designer.SetDataSource("BXDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19679. designer.SetDataSource("BXZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19680. designer.SetDataSource("BXDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19681. designer.SetDataSource("BXZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19682. }
  19683. else
  19684. {
  19685. hideRowsList.Add(Row + startIndex + HideRows);
  19686. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19687. }
  19688. HideRows += 2;
  19689. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  19690. if (leftBindData != null)
  19691. {
  19692. designer.SetDataSource("HSDRCB", leftBindData.cb);
  19693. designer.SetDataSource("HSRS", leftBindData.rs);
  19694. designer.SetDataSource("HSXS", leftBindData.xs);
  19695. designer.SetDataSource("HSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19696. designer.SetDataSource("HSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19697. designer.SetDataSource("HSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19698. designer.SetDataSource("HSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19699. designer.SetDataSource("HSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19700. }
  19701. else
  19702. {
  19703. hideRowsList.Add(Row + startIndex + HideRows);
  19704. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19705. }
  19706. HideRows += 2;
  19707. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  19708. if (leftBindData != null)
  19709. {
  19710. designer.SetDataSource("JPJJCCB", leftBindData.cb);
  19711. designer.SetDataSource("JPJJCPnum", leftBindData.rs);
  19712. designer.SetDataSource("JPJJCXS", leftBindData.xs);
  19713. designer.SetDataSource("JPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19714. designer.SetDataSource("JPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19715. designer.SetDataSource("JPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19716. designer.SetDataSource("JPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19717. designer.SetDataSource("JPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19718. }
  19719. else
  19720. {
  19721. hideRowsList.Add(Row + startIndex + HideRows);
  19722. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19723. }
  19724. HideRows += 2;
  19725. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  19726. if (leftBindData != null)
  19727. {
  19728. designer.SetDataSource("JPGWCCB", leftBindData.cb);
  19729. designer.SetDataSource("JPGWCPNum", leftBindData.rs);
  19730. designer.SetDataSource("JPGWCXS", leftBindData.xs);
  19731. designer.SetDataSource("JPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19732. designer.SetDataSource("JPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19733. designer.SetDataSource("JPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19734. designer.SetDataSource("JPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19735. designer.SetDataSource("JPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19736. }
  19737. else
  19738. {
  19739. hideRowsList.Add(Row + startIndex + HideRows);
  19740. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19741. }
  19742. HideRows += 2;
  19743. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  19744. if (leftBindData != null)
  19745. {
  19746. designer.SetDataSource("JPTDCCB", leftBindData.cb);
  19747. designer.SetDataSource("JPTDCPNum", leftBindData.rs);
  19748. designer.SetDataSource("JPTDCXS", leftBindData.xs);
  19749. designer.SetDataSource("JPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19750. designer.SetDataSource("JPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19751. designer.SetDataSource("JPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19752. designer.SetDataSource("JPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19753. designer.SetDataSource("JPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19754. }
  19755. else
  19756. {
  19757. hideRowsList.Add(Row + startIndex + HideRows);
  19758. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19759. }
  19760. HideRows += 2;
  19761. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  19762. if (leftBindData != null)
  19763. {
  19764. ////TBR
  19765. designer.SetDataSource("HotelTBRDRCB", leftBindData.cb);
  19766. designer.SetDataSource("HotelTBRRS", leftBindData.rs);
  19767. designer.SetDataSource("HotelTBRXS", leftBindData.xs);
  19768. designer.SetDataSource("HotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19769. designer.SetDataSource("HotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19770. designer.SetDataSource("HotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19771. designer.SetDataSource("HotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19772. designer.SetDataSource("HotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19773. }
  19774. else
  19775. {
  19776. hideRowsList.Add(Row + startIndex + HideRows);
  19777. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19778. }
  19779. HideRows += 2;
  19780. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  19781. if (leftBindData != null)
  19782. {
  19783. ////SGR
  19784. designer.SetDataSource("HotelSGRDRCB", leftBindData.cb);
  19785. designer.SetDataSource("HotelSGRRS", leftBindData.rs);
  19786. designer.SetDataSource("HotelSGRXS", leftBindData.xs);
  19787. designer.SetDataSource("HotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19788. designer.SetDataSource("HotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19789. designer.SetDataSource("HotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19790. designer.SetDataSource("HotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19791. designer.SetDataSource("HotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19792. }
  19793. else
  19794. {
  19795. hideRowsList.Add(Row + startIndex + HideRows);
  19796. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19797. }
  19798. HideRows += 2;
  19799. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  19800. if (leftBindData != null)
  19801. {
  19802. ////JS/ES
  19803. designer.SetDataSource("HotelJSESDRCB", leftBindData.cb);
  19804. designer.SetDataSource("HotelJSESRS", leftBindData.rs);
  19805. designer.SetDataSource("HotelJSESXS", leftBindData.xs);
  19806. designer.SetDataSource("HotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19807. designer.SetDataSource("HotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19808. designer.SetDataSource("HotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19809. designer.SetDataSource("HotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19810. designer.SetDataSource("HotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19811. }
  19812. else
  19813. {
  19814. hideRowsList.Add(Row + startIndex + HideRows);
  19815. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19816. }
  19817. HideRows += 2;
  19818. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  19819. if (leftBindData != null)
  19820. {
  19821. ////SUITE
  19822. designer.SetDataSource("HotelSUITEDRCB", leftBindData.cb);
  19823. designer.SetDataSource("HotelSUITERS", leftBindData.rs);
  19824. designer.SetDataSource("HotelSUITEXS", leftBindData.xs);
  19825. designer.SetDataSource("HotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19826. designer.SetDataSource("HotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19827. designer.SetDataSource("HotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19828. designer.SetDataSource("HotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19829. designer.SetDataSource("HotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19830. }
  19831. else
  19832. {
  19833. hideRowsList.Add(Row + startIndex + HideRows);
  19834. // ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19835. }
  19836. HideRows += 2;
  19837. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  19838. if (leftBindData != null)
  19839. {
  19840. designer.SetDataSource("DJDRCB", leftBindData.cb);
  19841. designer.SetDataSource("DJRS", leftBindData.rs);
  19842. designer.SetDataSource("DJXS", leftBindData.xs);
  19843. designer.SetDataSource("DJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19844. designer.SetDataSource("DJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19845. designer.SetDataSource("DJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19846. designer.SetDataSource("DJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19847. designer.SetDataSource("DJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19848. }
  19849. else
  19850. {
  19851. hideRowsList.Add(Row + startIndex + HideRows);
  19852. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19853. }
  19854. HideRows += 2;
  19855. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  19856. if (leftBindData != null)
  19857. {
  19858. designer.SetDataSource("HCPCB", leftBindData.cb);
  19859. designer.SetDataSource("HCPRS", leftBindData.rs);
  19860. designer.SetDataSource("HCPXS", leftBindData.xs);
  19861. designer.SetDataSource("HCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19862. designer.SetDataSource("HCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19863. designer.SetDataSource("HCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19864. designer.SetDataSource("HCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19865. designer.SetDataSource("HCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19866. }
  19867. else
  19868. {
  19869. hideRowsList.Add(Row + startIndex + HideRows);
  19870. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19871. }
  19872. HideRows += 2;
  19873. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  19874. if (leftBindData != null)
  19875. {
  19876. designer.SetDataSource("CPCB", leftBindData.cb);
  19877. designer.SetDataSource("CPRS", leftBindData.rs);
  19878. designer.SetDataSource("CPXS", leftBindData.xs);
  19879. designer.SetDataSource("CPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19880. designer.SetDataSource("CPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19881. designer.SetDataSource("CPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19882. designer.SetDataSource("CPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19883. designer.SetDataSource("CPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19884. }
  19885. else
  19886. {
  19887. hideRowsList.Add(Row + startIndex + HideRows);
  19888. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19889. }
  19890. HideRows += 2;
  19891. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  19892. if (leftBindData != null)
  19893. {
  19894. designer.SetDataSource("GWDRCD", leftBindData.cb);
  19895. designer.SetDataSource("GWRS", leftBindData.rs);
  19896. designer.SetDataSource("GWXS", leftBindData.xs);
  19897. designer.SetDataSource("GWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19898. designer.SetDataSource("GWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19899. designer.SetDataSource("GWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19900. designer.SetDataSource("GWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19901. designer.SetDataSource("GWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19902. }
  19903. else
  19904. {
  19905. hideRowsList.Add(Row + startIndex + HideRows);
  19906. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19907. }
  19908. HideRows += 2;
  19909. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  19910. if (leftBindData != null)
  19911. {
  19912. designer.SetDataSource("LYJDRCB", leftBindData.cb);
  19913. designer.SetDataSource("LYJRS", leftBindData.rs);
  19914. designer.SetDataSource("LYJXS", leftBindData.xs);
  19915. designer.SetDataSource("LYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  19916. designer.SetDataSource("LYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  19917. designer.SetDataSource("LYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  19918. designer.SetDataSource("LYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  19919. designer.SetDataSource("LYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  19920. }
  19921. else
  19922. {
  19923. hideRowsList.Add(Row + startIndex + HideRows);
  19924. //ws.Cells.HideRows((Row + startIndex + HideRows), 2);
  19925. }
  19926. #endregion
  19927. #region A段Right信息
  19928. var right = dto.rightInfo.Find(x => x.Type == "A");
  19929. if (right == null)
  19930. {
  19931. return Ok(jw);
  19932. }
  19933. HideRows += 4;
  19934. var rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  19935. if (rightBindData != null)
  19936. {
  19937. //经济舱 + 双人间 TBR
  19938. designer.SetDataSource("lblJJCTBRDRCB", rightBindData.cb);
  19939. designer.SetDataSource("txtJJCTBRRS", rightBindData.rs);
  19940. designer.SetDataSource("lblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19941. designer.SetDataSource("lblJJCTBRDRBJ", rightBindData.bj);
  19942. designer.SetDataSource("lblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19943. designer.SetDataSource("lblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19944. designer.SetDataSource("lblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19945. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19946. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19947. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19948. }
  19949. else
  19950. {
  19951. hideRowsList.Add(Row + startIndex + HideRows);
  19952. }
  19953. HideRows += 2;
  19954. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  19955. if (rightBindData != null)
  19956. {
  19957. //经济舱 + 单人间 SGR
  19958. designer.SetDataSource("lblJJCSGRDRCB", rightBindData.cb);
  19959. designer.SetDataSource("txtJJCSGRRS", rightBindData.rs);
  19960. designer.SetDataSource("lblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19961. designer.SetDataSource("lblJJCSGRDRBJ", rightBindData.bj);
  19962. designer.SetDataSource("lblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19963. designer.SetDataSource("lblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19964. designer.SetDataSource("lblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19965. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19966. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19967. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19968. }
  19969. else
  19970. {
  19971. hideRowsList.Add(Row + startIndex + HideRows);
  19972. }
  19973. HideRows += 2;
  19974. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  19975. if (rightBindData != null)
  19976. {
  19977. //公务舱 + 单人间 SGR
  19978. designer.SetDataSource("lblGWCSGRCB", rightBindData.cb);
  19979. designer.SetDataSource("lblGWCSGRRS", rightBindData.rs);
  19980. designer.SetDataSource("lblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  19981. designer.SetDataSource("lblGWCSGRDRBJ", rightBindData.bj);
  19982. designer.SetDataSource("lblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  19983. designer.SetDataSource("lblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  19984. designer.SetDataSource("lblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  19985. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  19986. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  19987. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  19988. }
  19989. else
  19990. {
  19991. hideRowsList.Add(Row + startIndex + HideRows);
  19992. }
  19993. HideRows += 2;
  19994. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  19995. if (rightBindData != null)
  19996. {
  19997. //公务舱 + 小套房 JSES
  19998. designer.SetDataSource("lblGWCJSESDRCB", rightBindData.cb);
  19999. designer.SetDataSource("txtGWCJSESRS", rightBindData.rs);
  20000. designer.SetDataSource("lblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20001. designer.SetDataSource("lblGWCJSESDRBJ", rightBindData.bj);
  20002. designer.SetDataSource("lblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20003. designer.SetDataSource("lblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20004. designer.SetDataSource("lblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20005. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20006. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20007. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20008. }
  20009. else
  20010. {
  20011. hideRowsList.Add(Row + startIndex + HideRows);
  20012. }
  20013. HideRows += 2;
  20014. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  20015. if (rightBindData != null)
  20016. {
  20017. //公务舱 + 小套房 JSES
  20018. designer.SetDataSource("lblGWCSUITEDRCB", rightBindData.cb);
  20019. designer.SetDataSource("txtGWCSUITERS", rightBindData.rs);
  20020. designer.SetDataSource("lblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20021. designer.SetDataSource("lblGWCSUITEDRBJ", rightBindData.bj);
  20022. designer.SetDataSource("lblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20023. designer.SetDataSource("lblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20024. designer.SetDataSource("lblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20025. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20026. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20027. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20028. }
  20029. else
  20030. {
  20031. hideRowsList.Add(Row + startIndex + HideRows);
  20032. }
  20033. HideRows += 2;
  20034. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  20035. if (rightBindData != null)
  20036. {
  20037. //经济舱 + 大套房
  20038. designer.SetDataSource("lblJJCSUITEDRCB", rightBindData.cb);
  20039. designer.SetDataSource("txtJJCSUITERS", rightBindData.rs);
  20040. designer.SetDataSource("lblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20041. designer.SetDataSource("lblJJCSUITEDRBJ", rightBindData.bj);
  20042. designer.SetDataSource("lblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20043. designer.SetDataSource("lblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20044. designer.SetDataSource("lblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20045. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20046. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20047. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20048. }
  20049. else
  20050. {
  20051. hideRowsList.Add(Row + startIndex + HideRows);
  20052. }
  20053. HideRows += 2;
  20054. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  20055. if (rightBindData != null)
  20056. {
  20057. //头等舱 + 小套房 JSES
  20058. designer.SetDataSource("lblTDCJSESDRCB", rightBindData.cb);
  20059. designer.SetDataSource("txtTDCJSESRS", rightBindData.rs);
  20060. designer.SetDataSource("lblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20061. designer.SetDataSource("lblTDCJSESDRBJ", rightBindData.bj);
  20062. designer.SetDataSource("lblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20063. designer.SetDataSource("lblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20064. designer.SetDataSource("lblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20065. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20066. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20067. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20068. }
  20069. else
  20070. {
  20071. hideRowsList.Add(Row + startIndex + HideRows);
  20072. }
  20073. HideRows += 2;
  20074. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  20075. if (rightBindData != null)
  20076. {
  20077. //头等舱 + 大套房
  20078. designer.SetDataSource("lblTDCSUITEDRCB", rightBindData.cb);
  20079. designer.SetDataSource("txtTDCSUITERS", rightBindData.rs);
  20080. designer.SetDataSource("lblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20081. designer.SetDataSource("lblTDCSUITEDRBJ", rightBindData.bj);
  20082. designer.SetDataSource("lblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20083. designer.SetDataSource("lblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20084. designer.SetDataSource("lblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20085. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20086. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20087. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20088. }
  20089. else
  20090. {
  20091. hideRowsList.Add(Row + startIndex + HideRows);
  20092. }
  20093. #endregion
  20094. #region B段标题清空
  20095. designer.SetDataSource("CostBDRCB", "");
  20096. designer.SetDataSource("CostBRS", "");
  20097. designer.SetDataSource("CostBXS", "");
  20098. designer.SetDataSource("CostBZCB", "");
  20099. designer.SetDataSource("CostBDRBJ", "");
  20100. designer.SetDataSource("CostBZBJ", "");
  20101. designer.SetDataSource("CostBDRLR", "");
  20102. designer.SetDataSource("CostBZLR", "");
  20103. designer.SetDataSource("CostBDRCBOM", "");
  20104. designer.SetDataSource("CostBRSOM", "");
  20105. designer.SetDataSource("CostBZCBOM", "");
  20106. designer.SetDataSource("CostBDRBJOM", "");
  20107. designer.SetDataSource("CostBZBJOM", "");
  20108. designer.SetDataSource("CostBDRLROM", "");
  20109. designer.SetDataSource("CostBZLROM", "");
  20110. #endregion
  20111. designer.SetDataSource("HotelTBRName", "酒店TBR单间成本(CNY)");
  20112. designer.SetDataSource("HotelSGRName", "酒店SGR单间成本(CNY)");
  20113. designer.SetDataSource("HotelJSESName", "酒店JSES单间成本(CNY)");
  20114. designer.SetDataSource("HotelSUITEName", "酒店SUITE单间成本(CNY)");
  20115. designer.SetDataSource("DJName", "地接(CNY)");
  20116. designer.SetDataSource("HCPName", "地接-火车票(CNY)");
  20117. designer.SetDataSource("CPName", "地接-船票(CNY)");
  20118. designer.SetDataSource("GWName", "公务(CNY)");
  20119. designer.SetDataSource("YQHName", "邀请函(CNY)");
  20120. designer.SetDataSource("LYJName", "零用金(CNY)");
  20121. designer.SetDataSource("HSName", "核酸检测(CNY)");
  20122. designer.SetDataSource("AirGWCName", "机票-公务舱(CNY)");
  20123. designer.SetDataSource("AirJJCName", "机票-经济舱(CNY)");
  20124. designer.SetDataSource("AirTDCName", "机票-头等舱(CNY)");
  20125. designer.SetDataSource("BXName", "保险(CNY)");
  20126. designer.SetDataSource("VisaName", "签证(CNY)");
  20127. #region B段基本数据
  20128. if (dto.costType == "B")
  20129. {
  20130. left = dto.leftInfo.Find(x => x.Type == "B");
  20131. if (left == null)
  20132. {
  20133. return Ok(jw);
  20134. }
  20135. #region B段left数据
  20136. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("核酸"));
  20137. if (leftBindData != null)
  20138. {
  20139. designer.SetDataSource("BHSDRCB", leftBindData.cb);
  20140. designer.SetDataSource("BHSRS", leftBindData.rs);
  20141. designer.SetDataSource("BHSXS", leftBindData.xs);
  20142. designer.SetDataSource("BHSZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20143. designer.SetDataSource("BHSDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20144. designer.SetDataSource("BHSZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20145. designer.SetDataSource("BHSDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20146. designer.SetDataSource("BHSZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20147. }
  20148. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("经济舱"));
  20149. if (leftBindData != null)
  20150. {
  20151. designer.SetDataSource("BJPJJCCB", leftBindData.cb);
  20152. designer.SetDataSource("BJPJJCPnum", leftBindData.rs);
  20153. designer.SetDataSource("BJPJJCXS", leftBindData.xs);
  20154. designer.SetDataSource("BJPJJCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20155. designer.SetDataSource("BJPJJCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20156. designer.SetDataSource("BJPJJCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20157. designer.SetDataSource("BJPJJCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20158. designer.SetDataSource("BJPJJCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20159. }
  20160. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务舱"));
  20161. if (leftBindData != null)
  20162. {
  20163. designer.SetDataSource("BJPGWCCB", leftBindData.cb);
  20164. designer.SetDataSource("BJPGWCPNum", leftBindData.rs);
  20165. designer.SetDataSource("BJPGWCXS", leftBindData.xs);
  20166. designer.SetDataSource("BJPGWCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20167. designer.SetDataSource("BJPGWCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20168. designer.SetDataSource("BJPGWCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20169. designer.SetDataSource("BJPGWCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20170. designer.SetDataSource("BJPGWCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20171. }
  20172. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("头等舱"));
  20173. if (leftBindData != null)
  20174. {
  20175. designer.SetDataSource("BJPTDCCB", leftBindData.cb);
  20176. designer.SetDataSource("BJPTDCPNum", leftBindData.rs);
  20177. designer.SetDataSource("BJPTDCXS", leftBindData.xs);
  20178. designer.SetDataSource("BJPTDCZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20179. designer.SetDataSource("BJPTDCDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20180. designer.SetDataSource("BJPTDCZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20181. designer.SetDataSource("BJPTDCDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20182. designer.SetDataSource("BJPTDCZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20183. }
  20184. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("火车票"));
  20185. if (leftBindData != null)
  20186. {
  20187. designer.SetDataSource("BHCPCB", leftBindData.cb);
  20188. designer.SetDataSource("BHCPRS", leftBindData.rs);
  20189. designer.SetDataSource("BHCPXS", leftBindData.xs);
  20190. designer.SetDataSource("BHCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20191. designer.SetDataSource("BHCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20192. designer.SetDataSource("BHCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20193. designer.SetDataSource("BHCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20194. designer.SetDataSource("BHCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20195. }
  20196. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("船票"));
  20197. if (leftBindData != null)
  20198. {
  20199. designer.SetDataSource("BCPCB", leftBindData.cb);
  20200. designer.SetDataSource("BCPRS", leftBindData.rs);
  20201. designer.SetDataSource("BCPXS", leftBindData.xs);
  20202. designer.SetDataSource("BCPZCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20203. designer.SetDataSource("BCPDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20204. designer.SetDataSource("BCPZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20205. designer.SetDataSource("BCPDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20206. designer.SetDataSource("BCPZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20207. }
  20208. //TBR
  20209. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("TBR"));
  20210. if (leftBindData != null)
  20211. {
  20212. designer.SetDataSource("BHotelTBRDRCB", leftBindData.cb);
  20213. designer.SetDataSource("BHotelTBRRS", leftBindData.rs);
  20214. designer.SetDataSource("BHotelTBRXS", leftBindData.xs);
  20215. designer.SetDataSource("BHotelTBRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20216. designer.SetDataSource("BHotelTBRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20217. designer.SetDataSource("BHotelTBRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20218. designer.SetDataSource("BHotelTBRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20219. designer.SetDataSource("BHotelTBRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20220. }
  20221. //SGR
  20222. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SGR"));
  20223. if (leftBindData != null)
  20224. {
  20225. designer.SetDataSource("BHotelSGRDRCB", leftBindData.cb);
  20226. designer.SetDataSource("BHotelSGRRS", leftBindData.rs);
  20227. designer.SetDataSource("BHotelSGRXS", leftBindData.xs);
  20228. designer.SetDataSource("BHotelSGRCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20229. designer.SetDataSource("BHotelSGRDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20230. designer.SetDataSource("BHotelSGRZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20231. designer.SetDataSource("BHotelSGRDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20232. designer.SetDataSource("BHotelSGRZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20233. }
  20234. //JS/ES
  20235. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("JSES"));
  20236. if (leftBindData != null)
  20237. {
  20238. designer.SetDataSource("BHotelJSESDRCB", leftBindData.cb);
  20239. designer.SetDataSource("BHotelJSESRS", leftBindData.rs);
  20240. designer.SetDataSource("BHotelJSESXS", leftBindData.xs);
  20241. designer.SetDataSource("BHotelJSESCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20242. designer.SetDataSource("BHotelJSESDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20243. designer.SetDataSource("BHotelJSESZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20244. designer.SetDataSource("BHotelJSESDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20245. designer.SetDataSource("BHotelJSESZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20246. }
  20247. //SUITE
  20248. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("SUITE"));
  20249. if (leftBindData != null)
  20250. {
  20251. designer.SetDataSource("BHotelSUITEDRCB", leftBindData.cb);
  20252. designer.SetDataSource("BHotelSUITERS", leftBindData.rs);
  20253. designer.SetDataSource("BHotelSUITEXS", leftBindData.xs);
  20254. designer.SetDataSource("BHotelSUITECB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20255. designer.SetDataSource("BHotelSUITEDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20256. designer.SetDataSource("BHotelSUITEZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20257. designer.SetDataSource("BHotelSUITEDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20258. designer.SetDataSource("BHotelSUITEZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20259. }
  20260. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("地接"));
  20261. if (leftBindData != null)
  20262. {
  20263. designer.SetDataSource("BDJDRCB", leftBindData.cb);
  20264. designer.SetDataSource("BDJRS", leftBindData.rs);
  20265. designer.SetDataSource("BDJXS", leftBindData.xs);
  20266. designer.SetDataSource("BDJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20267. designer.SetDataSource("BDJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20268. designer.SetDataSource("BDJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20269. designer.SetDataSource("BDJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20270. designer.SetDataSource("BDJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20271. }
  20272. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("公务单人"));
  20273. if (leftBindData != null)
  20274. {
  20275. designer.SetDataSource("BGWDRCD", leftBindData.cb);
  20276. designer.SetDataSource("BGWRS", leftBindData.rs);
  20277. designer.SetDataSource("BGWXS", leftBindData.xs);
  20278. designer.SetDataSource("BGWCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20279. designer.SetDataSource("BGWDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20280. designer.SetDataSource("BGWZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20281. designer.SetDataSource("BGWDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20282. designer.SetDataSource("BGWZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20283. }
  20284. #region 优化方案
  20285. //Dictionary<string, object> excelBind = new Dictionary<string, object>();
  20286. //excelBind.Add("零用金", new {
  20287. //cb="",
  20288. //rs="",
  20289. //xs ="",
  20290. //zcb = "",
  20291. //});
  20292. #endregion
  20293. leftBindData = left.leftinfoNumber.Find(x => x.title.Contains("零用金"));
  20294. if (leftBindData != null)
  20295. {
  20296. designer.SetDataSource("BLYJDRCB", leftBindData.cb);
  20297. designer.SetDataSource("BLYJRS", leftBindData.rs);
  20298. designer.SetDataSource("BLYJXS", leftBindData.xs);
  20299. designer.SetDataSource("BLYJCB", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.rs));
  20300. designer.SetDataSource("BLYJDRBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs));
  20301. designer.SetDataSource("BLYJZBJ", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) * decimal.Parse(leftBindData.rs));
  20302. designer.SetDataSource("BLYJDRLR", decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs) - decimal.Parse(leftBindData.cb));
  20303. designer.SetDataSource("BLYJZLR", ((decimal.Parse(leftBindData.cb) * decimal.Parse(leftBindData.xs)) - decimal.Parse(leftBindData.cb)) * decimal.Parse(leftBindData.rs));
  20304. }
  20305. #endregion
  20306. #region B段Right信息
  20307. right = dto.rightInfo.Find(x => x.Type == "B");
  20308. if (right == null)
  20309. {
  20310. return Ok(jw);
  20311. }
  20312. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 TBR"));
  20313. if (rightBindData != null)
  20314. {
  20315. //经济舱 + 双人间 TBR
  20316. designer.SetDataSource("BlblJJCTBRDRCB", rightBindData.cb);
  20317. designer.SetDataSource("BtxtJJCTBRRS", rightBindData.rs);
  20318. designer.SetDataSource("BlblJJCTBRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20319. designer.SetDataSource("BlblJJCTBRDRBJ", rightBindData.bj);
  20320. designer.SetDataSource("BlblJJCTBRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20321. designer.SetDataSource("BlblJJCTBRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20322. designer.SetDataSource("BlblJJCTBRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20323. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20324. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20325. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20326. }
  20327. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SGR"));
  20328. if (rightBindData != null)
  20329. {
  20330. //经济舱 + 单人间 SGR
  20331. designer.SetDataSource("BlblJJCSGRDRCB", rightBindData.cb);
  20332. designer.SetDataSource("BtxtJJCSGRRS", rightBindData.rs);
  20333. designer.SetDataSource("BlblJJCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20334. designer.SetDataSource("BlblJJCSGRDRBJ", rightBindData.bj);
  20335. designer.SetDataSource("BlblJJCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20336. designer.SetDataSource("BlblJJCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20337. designer.SetDataSource("BlblJJCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20338. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20339. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20340. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20341. }
  20342. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SGR"));
  20343. if (rightBindData != null)
  20344. {
  20345. //公务舱 + 单人间 SGR
  20346. designer.SetDataSource("BlblGWCSGRCB", rightBindData.cb);
  20347. designer.SetDataSource("BlblGWCSGRRS", rightBindData.rs);
  20348. designer.SetDataSource("BlblGWCSGRZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20349. designer.SetDataSource("BlblGWCSGRDRBJ", rightBindData.bj);
  20350. designer.SetDataSource("BlblGWCSGRZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20351. designer.SetDataSource("BlblGWCSGRDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20352. designer.SetDataSource("BlblGWCSGRZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20353. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20354. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20355. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20356. }
  20357. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 JS/ES"));
  20358. if (rightBindData != null)
  20359. {
  20360. //公务舱 + 小套房 JSES
  20361. designer.SetDataSource("BlblGWCJSESDRCB", rightBindData.cb);
  20362. designer.SetDataSource("BtxtGWCJSESRS", rightBindData.rs);
  20363. designer.SetDataSource("BlblGWCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20364. designer.SetDataSource("BlblGWCJSESDRBJ", rightBindData.bj);
  20365. designer.SetDataSource("BlblGWCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20366. designer.SetDataSource("BlblGWCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20367. designer.SetDataSource("BlblGWCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20368. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20369. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20370. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20371. }
  20372. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("公务舱 SUITE"));
  20373. if (rightBindData != null)
  20374. {
  20375. //公务舱 + 小套房 JSES
  20376. designer.SetDataSource("BlblGWCSUITEDRCB", rightBindData.cb);
  20377. designer.SetDataSource("BtxtGWCSUITERS", rightBindData.rs);
  20378. designer.SetDataSource("BlblGWCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20379. designer.SetDataSource("BlblGWCSUITEDRBJ", rightBindData.bj);
  20380. designer.SetDataSource("BlblGWCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20381. designer.SetDataSource("BlblGWCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20382. designer.SetDataSource("BlblGWCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20383. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20384. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20385. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20386. }
  20387. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("经济舱 SUITE"));
  20388. if (rightBindData != null)
  20389. {
  20390. //经济舱 + 大套房
  20391. designer.SetDataSource("BlblJJCSUITEDRCB", rightBindData.cb);
  20392. designer.SetDataSource("BtxtJJCSUITERS", rightBindData.rs);
  20393. designer.SetDataSource("BlblJJCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20394. designer.SetDataSource("BlblJJCSUITEDRBJ", rightBindData.bj);
  20395. designer.SetDataSource("BlblJJCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20396. designer.SetDataSource("BlblJJCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20397. designer.SetDataSource("BlblJJCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20398. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20399. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20400. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20401. }
  20402. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 JS/ES"));
  20403. if (rightBindData != null)
  20404. {
  20405. //头等舱 + 小套房 JSES
  20406. designer.SetDataSource("BlblTDCJSESDRCB", rightBindData.cb);
  20407. designer.SetDataSource("BtxtTDCJSESRS", rightBindData.rs);
  20408. designer.SetDataSource("BlblTDCJSESZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20409. designer.SetDataSource("BlblTDCJSESDRBJ", rightBindData.bj);
  20410. designer.SetDataSource("BlblTDCJSESZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20411. designer.SetDataSource("BlblTDCJSESDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20412. designer.SetDataSource("BlblTDCJSESZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20413. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20414. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20415. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20416. }
  20417. rightBindData = right.rightInfoNumber.Find(x => x.title.Contains("头等舱 SUITE"));
  20418. if (rightBindData != null)
  20419. {
  20420. //头等舱 + 大套房
  20421. designer.SetDataSource("BlblTDCSUITEDRCB", rightBindData.cb);
  20422. designer.SetDataSource("BtxtTDCSUITERS", rightBindData.rs);
  20423. designer.SetDataSource("BlblTDCSUITEZCB", decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs));
  20424. designer.SetDataSource("BlblTDCSUITEDRBJ", rightBindData.bj);
  20425. designer.SetDataSource("BlblTDCSUITEZBJ", decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs));
  20426. designer.SetDataSource("BlblTDCSUITEDRLR", decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb));
  20427. designer.SetDataSource("BlblTDCSUITEZLR", (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs));
  20428. TzZCB2 += decimal.Parse(rightBindData.cb) * decimal.Parse(rightBindData.rs);
  20429. TzZLR2 += (decimal.Parse(rightBindData.bj) - decimal.Parse(rightBindData.cb)) * decimal.Parse(rightBindData.rs);
  20430. TzZBJ2 += decimal.Parse(rightBindData.bj) * decimal.Parse(rightBindData.rs);
  20431. }
  20432. #endregion
  20433. #region 标题
  20434. designer.SetDataSource("CostBDRCB", "单人成本");
  20435. designer.SetDataSource("CostBRS", "人数");
  20436. designer.SetDataSource("CostBXS", "系数");
  20437. designer.SetDataSource("CostBZCB", "总成本");
  20438. designer.SetDataSource("CostBDRBJ", "单人报价");
  20439. designer.SetDataSource("CostBZBJ", "总报价");
  20440. designer.SetDataSource("CostBDRLR", "单人利润");
  20441. designer.SetDataSource("CostBZLR", "总利润");
  20442. designer.SetDataSource("CostBDRCBOM", "单人成本");
  20443. designer.SetDataSource("CostBRSOM", "人数");
  20444. designer.SetDataSource("CostBZCBOM", "总成本");
  20445. designer.SetDataSource("CostBDRBJOM", "单人报价");
  20446. designer.SetDataSource("CostBZBJOM", "总报价");
  20447. designer.SetDataSource("CostBDRLROM", "单人利润");
  20448. designer.SetDataSource("CostBZLROM", "总利润");
  20449. #endregion
  20450. }
  20451. #endregion
  20452. designer.SetDataSource("TzZCB2", TzZCB2);
  20453. designer.SetDataSource("TzZBJ2", TzZBJ2);
  20454. designer.SetDataSource("TzZLR2", TzZLR2);
  20455. string[] dataSourceKeys = new string[]
  20456. {
  20457. "VF",
  20458. "TGS",
  20459. "TGOF",
  20460. "TGM",
  20461. "TGA",
  20462. "TGTF",
  20463. "TGEF",
  20464. "CFM",
  20465. "CFOF",
  20466. "B",
  20467. "L",
  20468. "D",
  20469. "TBR",
  20470. "SGR",
  20471. "JSES",
  20472. "Suite",
  20473. "TV",
  20474. "1L",
  20475. "IF",
  20476. "EF",
  20477. "BRF",
  20478. "TE",
  20479. "TGT",
  20480. "DRVT",
  20481. "PC",
  20482. "TLF",
  20483. "ECT"
  20484. };
  20485. foreach (var item in dataSourceKeys)
  20486. {
  20487. Func<TitleModel, bool> expr = x => x.label.Replace(" ", "").Replace("/", "") == item
  20488. || x.label.Replace(" ", "").Replace("/", "").ToUpper() == item.ToUpper();
  20489. var find = dto.titleModel.FirstOrDefault(expr);
  20490. if (find != null)
  20491. {
  20492. designer.SetDataSource(item, find.text);
  20493. }
  20494. else
  20495. {
  20496. designer.SetDataSource(item, 0);
  20497. }
  20498. }
  20499. designer.SetDataSource(dt);
  20500. //根据数据源处理生成报表内容
  20501. designer.Process();
  20502. designer.Workbook.Worksheets[0].Name = "费用明细";
  20503. designer.Workbook.Worksheets[1].Name = "费用总核算";
  20504. Worksheet sheet = designer.Workbook.Worksheets[0];
  20505. #region 隐藏舱位
  20506. var settingAir = new[]
  20507. {
  20508. new { key = "经济舱", index = 7 },
  20509. new { key = "公务舱", index = 19 },
  20510. new { key = "头等舱", index = 11 }
  20511. };
  20512. var airType = _sqlSugar.Queryable<Grp_TourClientList>()
  20513. .LeftJoin<Sys_SetData>((c, s) => s.IsDel == 0 && c.ShippingSpaceTypeId == s.Id)
  20514. .Where((c, s) => c.IsDel == 0 && c.DiId == di.Id)
  20515. .Select((c, s) => s.Name)
  20516. .ToList()
  20517. .GroupBy(x => x)
  20518. .Select(x => x.Key);
  20519. foreach (var item in settingAir)
  20520. {
  20521. if (!airType.Contains(item.key))
  20522. {
  20523. hideRowsList.Add(item.index);
  20524. }
  20525. }
  20526. #endregion
  20527. foreach (var Rowindex in hideRowsList)
  20528. {
  20529. ws.Cells.HideRows(Rowindex, 2);
  20530. }
  20531. ws = designer.Workbook.Worksheets[0];
  20532. foreach (var Column in hideColumnList)
  20533. {
  20534. ws.Cells.HideColumns(Column, 1);
  20535. }
  20536. byte[] bytes = null;
  20537. string strFileName = di.TeamName + "-团组-成本.xls";
  20538. using (MemoryStream stream = new MemoryStream())
  20539. {
  20540. designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  20541. bytes = stream.ToArray();
  20542. }
  20543. return Ok(JsonView(true, "", new
  20544. {
  20545. Data = bytes,
  20546. strFileName,
  20547. }));
  20548. }
  20549. /// <summary>
  20550. /// 导出客户报表
  20551. /// </summary>
  20552. /// <returns></returns>
  20553. [HttpPost]
  20554. public async Task<IActionResult> ExportClientWordFile(ExportClientWordFileDto dto)
  20555. {
  20556. var jw = JsonView(false);
  20557. if (dto.Diid == 0)
  20558. {
  20559. return Ok(JsonView(false, "请传递团组id"));
  20560. }
  20561. var deleInfo = await _groupRepository.PostGroupInfo(new GroupInfoDto { Id = dto.Diid, PortType = 1 });
  20562. if (deleInfo.Code != 0)
  20563. {
  20564. return Ok(JsonView(false, "团组信息查询失败!"));
  20565. }
  20566. var di = deleInfo.Data as DelegationInfoWebView;
  20567. if (di == null)
  20568. {
  20569. return Ok(JsonView(false, "团组信息查询失败!"));
  20570. }
  20571. //文件名
  20572. //string strFileName = di.TeamName + "-团组-客户报价.doc";
  20573. //获取模板
  20574. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/团组-客户报价.doc");
  20575. //载入模板
  20576. Document doc = new Document(tmppath);
  20577. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
  20578. Dictionary<string, string> DickeyValue = new Dictionary<string, string>();
  20579. DickeyValue.Add("DickeyValue", di.TeamName); //团组名
  20580. var ParameterList = _GroupCostParameterRepository.GetGroupCostParameterListByDiid(dto.Diid);
  20581. var AParameter = ParameterList.Find(x => x.CostType == "A");
  20582. var BParameter = ParameterList.Find(x => x.CostType == "B");
  20583. if (AParameter == null)
  20584. {
  20585. return Ok(JsonView(false, "系数不存在!"));
  20586. }
  20587. string CarGuides, TzNumber, CarGuides1, Meal, SubsidizedMeals, NightRepair, AttractionsTickets, MiscellaneousFees, ATip, TzHotelDesc, Offcial, PettyCash, Visa, TrainTicket, TicketPrice
  20588. , TzAirDesc, TzZCost;
  20589. CarGuides = TzNumber = CarGuides1 = Meal = SubsidizedMeals = NightRepair = AttractionsTickets = MiscellaneousFees = ATip = TzHotelDesc = Offcial = PettyCash = Visa = TrainTicket = TicketPrice
  20590. = TzAirDesc = TzZCost = string.Empty;
  20591. TzNumber = AParameter.CostTypenumber.ToString();
  20592. CarGuides = "RMB " + (AParameter.DJCB * AParameter.DJXS).ToString("#0.00");
  20593. CarGuides1 = dto.CarGuides1;
  20594. Meal = dto.Meal;
  20595. SubsidizedMeals = dto.SubsidizedMeals;
  20596. NightRepair = dto.NightRepair;
  20597. AttractionsTickets = dto.AttractionsTickets;
  20598. MiscellaneousFees = dto.MiscellaneousFees;
  20599. ATip = dto.ATip;
  20600. TzHotelDesc = "";
  20601. Offcial = "RMB " + (AParameter.GWCB * AParameter.GWXS).ToString("#0.00");
  20602. PettyCash = "RMB " + (AParameter.LYJCB * AParameter.LYJXS).ToString("#0.00");
  20603. Visa = "RMB " + (AParameter.VisaCB * AParameter.VisaXS + AParameter.HSCB * AParameter.HSXS + AParameter.BXCB * AParameter.BXXS).ToString("#0.00");
  20604. TrainTicket = "RMB " + (AParameter.HCPCB * AParameter.HCPXS).ToString("#0.00");
  20605. TicketPrice = "RMB " + (AParameter.CPCB * AParameter.CPXS).ToString("#0.00");
  20606. TzAirDesc = "";
  20607. TzZCost = dto.TzZCost;
  20608. var TzHotelDescArr = new string[] { "SGR", "JSES", "SUITE", "TBR" };
  20609. var TzAirDescArr = new string[] { "经济舱", "公务舱" };
  20610. var index = 1;
  20611. var AinfoArr = dto.leftInfo.Find(x => x.Type == "A");
  20612. foreach (var item in TzHotelDescArr)
  20613. {
  20614. if (AinfoArr != null)
  20615. {
  20616. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20617. if (Ainfo != null)
  20618. {
  20619. if (int.Parse(Ainfo.rs) <= 0)
  20620. {
  20621. continue;
  20622. }
  20623. var hotelText = string.Empty;
  20624. switch (item)
  20625. {
  20626. case "SGR":
  20627. hotelText = "单人间";
  20628. break;
  20629. case "JSES":
  20630. hotelText = "小套房";
  20631. break;
  20632. case "SUITE":
  20633. hotelText = "套房";
  20634. break;
  20635. case "TBR":
  20636. hotelText = "双人间";
  20637. break;
  20638. }
  20639. if (item != "TBR")
  20640. {
  20641. 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";
  20642. }
  20643. else
  20644. {
  20645. 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";
  20646. }
  20647. index++;
  20648. }
  20649. }
  20650. }
  20651. index = 1;
  20652. foreach (var item in TzAirDescArr)
  20653. {
  20654. if (AinfoArr != null)
  20655. {
  20656. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20657. if (Ainfo != null)
  20658. {
  20659. if (int.Parse(Ainfo.rs) <= 0)
  20660. {
  20661. continue;
  20662. }
  20663. 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";
  20664. index++;
  20665. }
  20666. }
  20667. }
  20668. if (dto.costType == "B")
  20669. {
  20670. if (BParameter == null)
  20671. {
  20672. return Ok(JsonView(false, "B段系数不存在!"));
  20673. }
  20674. CarGuides = CarGuides.Insert(0, "A段 ") + " B段 RMB" + (BParameter.DJCB * BParameter.DJXS).ToString("#0.00");
  20675. Offcial = Offcial.Insert(0, "A段 ") + " B段 RMB " + (BParameter.GWCB * BParameter.GWXS).ToString("#0.00");
  20676. PettyCash = PettyCash.Insert(0, "A段 ") + " B段 RMB " + (BParameter.LYJCB * BParameter.LYJXS).ToString("#0.00");
  20677. Visa = Visa.Insert(0, "A段 ") + " B段 RMB " + (BParameter.VisaCB * BParameter.VisaXS + BParameter.HSCB * BParameter.HSXS + BParameter.BXCB * BParameter.BXXS).ToString("#0.00");
  20678. TrainTicket = TrainTicket.Insert(0, "A段 ") + " B段 RMB " + (BParameter.HCPCB * BParameter.HCPXS).ToString("#0.00");
  20679. TicketPrice = TicketPrice.Insert(0, "A段 ") + " B段 RMB " + (BParameter.CPCB * BParameter.CPXS).ToString("#0.00");
  20680. AinfoArr = dto.leftInfo.Find(x => x.Type == "B");
  20681. foreach (var item in TzHotelDescArr)
  20682. {
  20683. if (AinfoArr != null)
  20684. {
  20685. TzHotelDesc += "B段信息 \r\n";
  20686. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20687. if (Ainfo != null)
  20688. {
  20689. if (int.Parse(Ainfo.rs) <= 0)
  20690. {
  20691. continue;
  20692. }
  20693. var hotelText = string.Empty;
  20694. switch (item)
  20695. {
  20696. case "SGR":
  20697. hotelText = "单人间";
  20698. break;
  20699. case "JSES":
  20700. hotelText = "小套房";
  20701. break;
  20702. case "SUITE":
  20703. hotelText = "套房";
  20704. break;
  20705. case "TBR":
  20706. hotelText = "双人间";
  20707. break;
  20708. }
  20709. if (item != "TBR")
  20710. {
  20711. 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";
  20712. }
  20713. else
  20714. {
  20715. 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";
  20716. }
  20717. index++;
  20718. }
  20719. TzHotelDesc = TzHotelDesc.Insert(0, "A段信息 \r\n");
  20720. }
  20721. }
  20722. index = 1;
  20723. foreach (var item in TzAirDescArr)
  20724. {
  20725. if (AinfoArr != null)
  20726. {
  20727. var Ainfo = AinfoArr.leftinfoNumber.Find(x => x.title.Contains(item));
  20728. if (Ainfo != null)
  20729. {
  20730. if (int.Parse(Ainfo.rs) <= 0)
  20731. {
  20732. continue;
  20733. }
  20734. 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";
  20735. index++;
  20736. }
  20737. }
  20738. }
  20739. }
  20740. Visa = Visa.Insert(0, "签证及保险(含核酸检测): ");
  20741. DickeyValue.Add("TzNumber", TzNumber); //团组人数
  20742. DickeyValue.Add("CarGuides", CarGuides); //地接单人报价
  20743. DickeyValue.Add("CarGuides1", CarGuides1); // 地接 - 车导费
  20744. DickeyValue.Add("Meal", Meal); // 地接 - 餐费
  20745. DickeyValue.Add("SubsidizedMeals", SubsidizedMeals);// 地接 - 餐补
  20746. DickeyValue.Add("NightRepair", NightRepair); // 地接 - 宿补
  20747. DickeyValue.Add("AttractionsTickets", AttractionsTickets); // 地接 - 景点
  20748. DickeyValue.Add("MiscellaneousFees", MiscellaneousFees); // 地接 - 杂费
  20749. DickeyValue.Add("ATip", ATip); // 地接 - 小费
  20750. DickeyValue.Add("TzHotelDesc", TzHotelDesc); //酒店
  20751. DickeyValue.Add("Offcial", Offcial); // 公务单人报价
  20752. DickeyValue.Add("PettyCash", PettyCash); // 零用金单人报价
  20753. DickeyValue.Add("Visa", Visa); // 签证单人报价
  20754. DickeyValue.Add("TrainTicket", TrainTicket); //火车票
  20755. DickeyValue.Add("TicketPrice", TicketPrice); //船票
  20756. DickeyValue.Add("TzAirDesc", TzAirDesc); //机票
  20757. DickeyValue.Add("TzZCost", TzZCost);
  20758. foreach (var key in DickeyValue.Keys)
  20759. {
  20760. if (doc.Range.Bookmarks[key] != null)
  20761. {
  20762. Bookmark mark = doc.Range.Bookmarks[key];
  20763. mark.Text = DickeyValue[key];
  20764. }
  20765. }
  20766. byte[] bytes = null;
  20767. string strFileName = di.TeamName + "-客户报价.doc";
  20768. using (MemoryStream stream = new MemoryStream())
  20769. {
  20770. doc.Save(stream, Aspose.Words.SaveFormat.Doc);
  20771. bytes = stream.ToArray();
  20772. }
  20773. return Ok(JsonView(true, "", new
  20774. {
  20775. Data = bytes,
  20776. strFileName,
  20777. }));
  20778. }
  20779. /// <summary>
  20780. /// 团组成本 各模块(酒店,地接,机票)成本提示
  20781. /// </summary>
  20782. /// <param name="dto"></param>
  20783. /// <returns></returns>
  20784. [HttpPost]
  20785. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  20786. public async Task<IActionResult> PostGroupCostModulePrompt(GroupCostModulePromptDto dto)
  20787. {
  20788. try
  20789. {
  20790. #region 参数验证
  20791. if (dto.DiId < 0)
  20792. {
  20793. return Ok(JsonView(false, "请传入有效的DiId参数!"));
  20794. }
  20795. List<int> cTableIds = new List<int>() {
  20796. 76 ,//酒店预订
  20797. 77 ,//行程
  20798. 79 ,//车/导游地接
  20799. 80 ,//签证
  20800. 81 ,//邀请/公务活
  20801. 82 ,//团组客户保险
  20802. 85 ,//机票预订
  20803. 98 ,//其他款项
  20804. 285 ,//收款退还
  20805. 751 ,//酒店早餐
  20806. 1015 // 超支费用
  20807. };
  20808. if (dto.CTable < 0 && !cTableIds.Contains(dto.CTable))
  20809. {
  20810. return Ok(JsonView(false, "请传入有效的CTable参数!"));
  20811. }
  20812. #endregion
  20813. //Grp_GroupCostParameter 预算表 Grp_GroupCost 详细费用列表
  20814. var _GroupCostParameters = _usersRep._sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  20815. if (_GroupCostParameters.Count <= 0)
  20816. {
  20817. return Ok(JsonView(false, "暂无该团组成本信息!", new List<dynamic>()));
  20818. }
  20819. if (_GroupCostParameters[0].IsShare == 0)
  20820. {
  20821. return Ok(JsonView(false, "该团组成本未完成!", new List<dynamic>()));
  20822. }
  20823. var _GroupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  20824. //处理date为空问题
  20825. if (_GroupCosts.Count > 0)
  20826. {
  20827. for (int i = 0; i < _GroupCosts.Count; i++)
  20828. {
  20829. if (string.IsNullOrEmpty(_GroupCosts[i].Date))
  20830. {
  20831. if (i > 0)
  20832. {
  20833. _GroupCosts[i].Date = _GroupCosts[i - 1].Date;
  20834. }
  20835. }
  20836. }
  20837. }
  20838. GroupCostModulePromptView _view = new GroupCostModulePromptView();
  20839. List<GroupCostModulePromptInfo> _ModulePromptInfos = new List<GroupCostModulePromptInfo>(); //机票存储多段
  20840. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  20841. string currCode = "";
  20842. #region currCode 验证
  20843. bool isInt = int.TryParse(_GroupCostParameters[0].Currency, out int intCurrency);
  20844. if (isInt)
  20845. {
  20846. var currData = currDatas.Find(it => it.Id == intCurrency);
  20847. if (currData != null)
  20848. {
  20849. currCode = currData.Name;
  20850. }
  20851. }
  20852. else
  20853. {
  20854. currCode = _GroupCostParameters[0].Currency.Trim();
  20855. }
  20856. #endregion
  20857. //op,酒店单段模式存储
  20858. GroupCostModulePromptInfo _ModulePromptInfo = new GroupCostModulePromptInfo()
  20859. {
  20860. CurrencyCode = currCode,
  20861. Rate = _GroupCostParameters[0].Rate,
  20862. CostType = _GroupCostParameters[0].CostType,
  20863. CostTypeStartTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeStartTime).ToString("yyyy-MM-dd"),
  20864. CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[0].CostTypeendTime).ToString("yyyy-MM-dd"),
  20865. CostTypeNumber = _GroupCostParameters[0].CostTypenumber
  20866. };
  20867. List<dynamic> _ModuleSubPromptInfo = new List<dynamic>(); // 存储CTbale != 85 的动态数据
  20868. if (_GroupCostParameters.Count == 2)
  20869. {
  20870. _ModulePromptInfo.CostTypeEndTime = Convert.ToDateTime(_GroupCostParameters[1].CostTypeendTime).ToString("yyyy-MM-dd");
  20871. }
  20872. foreach (var item in _GroupCostParameters)
  20873. {
  20874. decimal _rate = 1;
  20875. decimal _rate1 = item.Rate;
  20876. decimal _scale = 1;
  20877. //decimal _scale = 0.95M; 雷怡 2024-06-11 10:06:08 屏蔽
  20878. #region 处理地接价格比例 总经理 国交部经理 主管 不下调 其他人 下调 5%
  20879. //var userInfo = _usersRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.IsDel == 0 && it.Id == dto.UserId).First();
  20880. //if (userInfo != null)
  20881. //{
  20882. // if (userInfo.DepId == 1 || userInfo.DepId == 7)
  20883. // {
  20884. // if (userInfo.JobPostId == 1 || userInfo.JobPostId == 22 || userInfo.JobPostId == 32)
  20885. // {
  20886. // _scale = 1.00M;
  20887. // }
  20888. // }
  20889. //}
  20890. #endregion
  20891. GroupCostModulePromptInfo modulePromptInfo = new GroupCostModulePromptInfo()
  20892. {
  20893. CurrencyCode = currCode,
  20894. Rate = _rate1,
  20895. CostType = item.CostType,
  20896. CostTypeStartTime = Convert.ToDateTime(item.CostTypeStartTime).ToString("yyyy-MM-dd"),
  20897. CostTypeEndTime = Convert.ToDateTime(item.CostTypeendTime).ToString("yyyy-MM-dd"),
  20898. CostTypeNumber = item.CostTypenumber
  20899. };
  20900. if (_GroupCostParameters.Count > 1)
  20901. {
  20902. modulePromptInfo.CostTypeNumber = item.CostTypenumber;
  20903. }
  20904. else
  20905. {
  20906. modulePromptInfo.CostTypeNumber = item.LYJRS;
  20907. }
  20908. if (dto.CTable == 79)//
  20909. {
  20910. modulePromptInfo.IndividualCost = item.DJCB / modulePromptInfo.CostTypeNumber;
  20911. modulePromptInfo.TotalCost = item.DJCB;
  20912. }
  20913. List<string> costTypes = new List<string>() { "A", "B" };
  20914. List<Grp_GroupCost> _GroupCostsTypeData = new List<Grp_GroupCost>();
  20915. var _GroupCostsDuplicates = _GroupCostParameters.GroupBy(x => x.CostType).Select(y => y.FirstOrDefault());
  20916. if (_GroupCostsDuplicates.Count() == 1)
  20917. {
  20918. _GroupCostsTypeData = _GroupCosts;
  20919. }
  20920. else
  20921. {
  20922. _GroupCostsTypeData = _GroupCosts.Where(it => Convert.ToDateTime(it.Date) >= Convert.ToDateTime(item.CostTypeStartTime) &&
  20923. Convert.ToDateTime(it.Date) <= Convert.ToDateTime(item.CostTypeendTime)).ToList();
  20924. }
  20925. /*
  20926. * 76 酒店预订
  20927. * 77 行程
  20928. * 79 车/导游地接
  20929. * 80 签证
  20930. * 81 邀请/公务活动
  20931. * 82 团组客户保险
  20932. * 85 机票预订
  20933. * 98 其他款项
  20934. * 285 收款退还
  20935. * 751 酒店早餐
  20936. * 1015 超支费用
  20937. */
  20938. switch (dto.CTable)
  20939. {
  20940. case 76: // 酒店预订
  20941. _ModuleSubPromptInfo.AddRange(
  20942. _GroupCostsTypeData.Select(it => new
  20943. {
  20944. it.DAY,
  20945. it.Date,
  20946. it.ACCON,
  20947. it.ITIN,
  20948. it.SGR,
  20949. it.TBR,
  20950. it.JS_ES,
  20951. it.Suite
  20952. })
  20953. );
  20954. break;
  20955. case 79: // 车/导游地接
  20956. _ModuleSubPromptInfo.AddRange(
  20957. _GroupCostsTypeData.Select(it => new
  20958. {
  20959. Date = it.Date, //日期
  20960. CarFee = it.CarCost * _rate * _scale, //车费用
  20961. CarType = it.CarType, //车型
  20962. DriverFee = it.CFS * _rate * _scale, //司机工资
  20963. DriverTipsFee = it.DRVTips * _rate * _scale, //司机小费
  20964. DriverMealSubsidy = it.CFM * _rate * _scale, //司机餐补
  20965. DriverOvertimeFee = it.CFOF * _rate * _scale, //司机超时费用
  20966. GuideFee = it.TGS * _rate * _scale, //导游费用
  20967. GuideOvertimeFee = it.TGOF * _rate * _scale, //导游超时费用
  20968. GuideMealSubsidy = it.TGM * _rate * _scale, //导游餐补
  20969. GuideRoomSubsidy = it.TGA * _rate * _scale, //导游房补
  20970. GuideCarFare = it.TGTF * _rate * _scale, //导游交通费
  20971. GuideSpotFee = it.TGEF * _rate * _scale, //导游景点费
  20972. GuideTipsFee = it.TGTips * _rate * _scale, //导游小费
  20973. Breakfast = it.B * _rate * _scale, //早餐费
  20974. Lunch = it.L * _rate * _scale, //午餐费
  20975. Dinner = it.D * _rate * _scale, //晚餐费
  20976. OfficialActivitiesFee = it.TV * _rate * _scale,//会务活动费 --新加
  20977. OfficialTransFee = it.IF * _rate * _scale, //公务翻译费 --新加
  20978. InvitationFee = it.iL * _rate * _scale, //邀请函费用 --新加
  20979. TicketFee = it.EF * _rate * _scale, //门票费
  20980. TicketRemark = it.EFR, //门票费描述
  20981. DrinksSnacksFruitFee = it.B_R_F * _rate * _scale, //饮料零食水果
  20982. TravelSupplies = it.TE * _rate * _scale, //出行物资
  20983. SpentCash = it.PC * _rate * _scale, //零用金
  20984. LeadersFee = it.TLF * _rate * _scale, //领队费
  20985. ActivitiesFee = it.ECT * _rate * _scale, //会务费 --新加
  20986. })
  20987. );
  20988. break;
  20989. case 85: // 机票
  20990. List<dynamic> datas = new List<dynamic>();
  20991. datas.Add(
  20992. new
  20993. {
  20994. AirType = "经济舱",
  20995. AirNum = item.JJCRS,
  20996. AirDRCB = item.JJCCB,
  20997. AirZCB = (item.JJCRS * item.JJCCB)
  20998. }
  20999. );
  21000. datas.Add(
  21001. new
  21002. {
  21003. AirType = "公务舱",
  21004. AirNum = item.GWCRS,
  21005. AirDRCB = item.GWCCB,
  21006. AirZCB = (item.GWCRS * item.GWCCB)
  21007. }
  21008. );
  21009. var groupCosts = _usersRep._sqlSugar.Queryable<Grp_GroupCost>().Where(it => it.IsDel == 0 && it.Diid == dto.DiId).ToList();
  21010. var initDatas = groupCosts.Select(it => new { date = it.Date, week = it.Date.GetWeek() == "" ? "-" : it.Date.GetWeek(), itinerary = it.ITIN }).ToList();
  21011. modulePromptInfo.Data = new
  21012. {
  21013. airFeeData = datas,
  21014. airInitData = initDatas
  21015. };
  21016. _ModulePromptInfos.Add(modulePromptInfo);
  21017. break;
  21018. default:
  21019. break;
  21020. }
  21021. }
  21022. if (dto.CTable != 85)
  21023. {
  21024. _ModulePromptInfo.Data = _ModuleSubPromptInfo;
  21025. _ModulePromptInfos.Add(_ModulePromptInfo);
  21026. }
  21027. _view.ModulePromptInfos = _ModulePromptInfos;
  21028. return Ok(JsonView(true, "操作成功!", _view));
  21029. }
  21030. catch (Exception ex)
  21031. {
  21032. return Ok(JsonView(false, ex.Message));
  21033. }
  21034. }
  21035. /// <summary>
  21036. /// 根据黑屏代码重新生成行程
  21037. /// </summary>
  21038. /// <param name="dto"></param>
  21039. /// <returns></returns>
  21040. [HttpPost]
  21041. public IActionResult CraeteGroupCostTravel(GroupCostInItDto dto)
  21042. {
  21043. var jw = JsonView(false, "Error");
  21044. var Create = _sqlSugar.Queryable<Air_TicketBlackCode>()
  21045. .Where(x => x.IsDel == 0 && x.DiId == dto.Diid)
  21046. .Select(x => new
  21047. {
  21048. x.Id,
  21049. x.Title
  21050. })
  21051. .ToList();
  21052. if (Create.Any())
  21053. {
  21054. jw.Msg = "获取成功!";
  21055. jw.Code = 200;
  21056. jw.Data = new
  21057. {
  21058. BlackCodeListSelect = Create,
  21059. blackCodeIsTrue = true
  21060. };
  21061. }
  21062. else
  21063. {
  21064. jw.Code = 400;
  21065. jw.Data = new
  21066. {
  21067. BlackCodeListSelect = Create,
  21068. blackCodeIsTrue = false,
  21069. };
  21070. }
  21071. return Ok(jw);
  21072. }
  21073. /// <summary>
  21074. /// 根据黑屏代码Id重新生成行程
  21075. /// </summary>
  21076. /// <param name="dto"></param>
  21077. /// <returns></returns>
  21078. [HttpPost]
  21079. public IActionResult CraeteGroupCostTravelById(CraeteGroupCostTravelByIdDto dto)
  21080. {
  21081. var jw = JsonView(false, "Error");
  21082. var result = _GroupCostRepository.CreateGroupCostByBlackCode(dto.DiId, dto.BlackCodeId);
  21083. if (result.Code == 0)
  21084. {
  21085. jw.Msg = "获取成功!";
  21086. jw.Code = 200;
  21087. jw.Data = new
  21088. {
  21089. groupCost = result.Data,
  21090. blackCodeIsTrue = true
  21091. };
  21092. }
  21093. else
  21094. {
  21095. jw.Code = 400;
  21096. jw.Data = new
  21097. {
  21098. groupCost = result.Data,
  21099. blackCodeIsTrue = false,
  21100. };
  21101. }
  21102. return Ok(jw);
  21103. }
  21104. /// <summary>
  21105. /// 成本获取OP历史车费用
  21106. /// </summary>
  21107. /// <param name="dto"></param>
  21108. /// <returns></returns>
  21109. [HttpPost]
  21110. public async Task<IActionResult> GetHistoryCarData(HistoryCarDataDto dto)
  21111. {
  21112. var jw = JsonView(false);
  21113. try
  21114. {
  21115. List<HistoryCarDataView> dbResult = new List<HistoryCarDataView>();
  21116. //获取现有所有车的数据
  21117. if (!dto.Param.IsNullOrWhiteSpace())
  21118. {
  21119. string sql = $@"
  21120. SELECT gdi.TeamName , gctggr.Area, gctggr.PriceName , gctggrc.Id ,gctggrc.Price , gctggrc.DatePrice , gctggrc.PriceContent , gctggrc.Currency , gctggr.ServiceStartTime , gctggr.ServiceEndTime
  21121. FROM Grp_CarTouristGuideGroundReservationsContent gctggrc inner join Grp_CarTouristGuideGroundReservations gctggr on
  21122. gctggrc.CTGGRId = gctggr.Id inner JOIN Grp_DelegationInfo gdi on gctggr.DiId = gdi.Id LEFT JOIN Sys_SetData ssd on ssd.Id = gctggr.PriceType
  21123. 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
  21124. AND gctggr.ServiceEndTime is not NULL
  21125. ORDER by gctggrc.id DESC
  21126. ";
  21127. dbResult = await _sqlSugar.SqlQueryable<HistoryCarDataView>(sql).ToListAsync();
  21128. var numeberResult = await Task.Run(() =>
  21129. {
  21130. var numberArr = dbResult.Where(x => int.TryParse(x.Area, out int number)).ToList();
  21131. _ = dbResult.RemoveAll(x => int.TryParse(x.Area, out int number));
  21132. return numberArr;
  21133. });
  21134. var cityArr = await _sqlSugar.Queryable<Grp_NationalTravelFee>().ToListAsync();
  21135. foreach (var item in numeberResult)
  21136. {
  21137. var find = cityArr.Find(x => x.Id == int.Parse(item.Area)) ?? new Grp_NationalTravelFee
  21138. {
  21139. Country = "数据异常!",
  21140. City = string.Empty,
  21141. };
  21142. item.Area = find.Country + " " + find.City;
  21143. }
  21144. dbResult.AddRange(numeberResult);
  21145. if (dto.Param.Contains("、"))
  21146. {
  21147. var sp = dto.Param.Split("、");
  21148. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  21149. .Where(x =>
  21150. {
  21151. return System.Array.Exists(sp, e =>
  21152. {
  21153. bool where = false;
  21154. if (x.Area != null)
  21155. {
  21156. where = x.Area.Contains(e);
  21157. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  21158. {
  21159. return false;
  21160. }
  21161. }
  21162. if (x.PriceName != null && !where)
  21163. {
  21164. where = x.PriceName.Contains(e);
  21165. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  21166. {
  21167. return false;
  21168. }
  21169. }
  21170. return where;
  21171. });
  21172. }).ToList();
  21173. }
  21174. else
  21175. {
  21176. dbResult = dbResult.AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount)
  21177. .Where(x =>
  21178. {
  21179. bool where = false;
  21180. if (x.Area != null)
  21181. {
  21182. where = x.Area.Contains(dto.Param);
  21183. if (x.Area.Contains("尾款") || x.PriceName.Contains("尾款"))
  21184. {
  21185. return false;
  21186. }
  21187. }
  21188. if (x.PriceName != null && !where)
  21189. {
  21190. where = x.PriceName.Contains(dto.Param);
  21191. if (x.PriceName.Contains("尾款") || x.PriceName.Contains("尾款"))
  21192. {
  21193. return false;
  21194. }
  21195. }
  21196. return where;
  21197. }
  21198. )
  21199. .ToList();
  21200. }
  21201. }
  21202. var view = dbResult.Select(x =>
  21203. {
  21204. decimal dp = 0.00M;
  21205. var startB = DateTime.TryParse(x.Start.ToString(), out DateTime startD);
  21206. var endB = DateTime.TryParse(x.End.ToString(), out DateTime endD);
  21207. if (string.IsNullOrWhiteSpace(x.DatePrice))
  21208. {
  21209. if (startB && endB)
  21210. {
  21211. var timesp = endD.Subtract(startD);
  21212. if ((timesp.Days + 1) != 0)
  21213. {
  21214. dp = x.Price / (timesp.Days + 1);
  21215. }
  21216. }
  21217. }
  21218. else
  21219. {
  21220. dp = x.Price;
  21221. }
  21222. return new
  21223. {
  21224. start = startB ? startD.ToString("yyyy-MM-dd") : "",
  21225. end = endB ? endD.ToString("yyyy-MM-dd") : "",
  21226. x.Area,
  21227. x.id,
  21228. price = x.Price.ToString("F2"),
  21229. x.PriceName,
  21230. x.PriceContent,
  21231. x.TeamName,
  21232. x.DatePrice,
  21233. dayPrice = dp.ToString("F2"),
  21234. };
  21235. }).OrderByDescending(x => x.id).ToList();
  21236. jw = JsonView(true, "获取成功!", view);
  21237. }
  21238. catch (Exception e)
  21239. {
  21240. jw = JsonView(false, e.Message);
  21241. }
  21242. return Ok(jw);
  21243. }
  21244. [HttpPost]
  21245. public async Task<IActionResult> SearchGroupByKeyword(SearchGroupByKeywordDto dto)
  21246. {
  21247. var jw = JsonView(true);
  21248. List<DelegationInfoAndIsTrueView> matches = new List<DelegationInfoAndIsTrueView>();
  21249. #region SQL语句
  21250. //if (string.IsNullOrWhiteSpace(dto.Keyword))
  21251. //{
  21252. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  21253. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  21254. // WHEN COUNT(*) >= 0 THEN 'True'
  21255. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  21256. // Where TeamName != '' And IsDel = 0 Order By a.VisitStartDate Desc
  21257. // ")
  21258. // .ToList();
  21259. //}
  21260. //else
  21261. //{
  21262. // string likeKey = string.Empty;
  21263. // foreach (var item in dto.Keyword)
  21264. // {
  21265. // likeKey += "%" + item;
  21266. // }
  21267. // likeKey += "%";
  21268. // matches = _sqlSugar.SqlQueryable<DelegationInfoAndIsTrueView>($@"
  21269. // Select a.Id,TeamName GroupName,b.isTrue From Grp_DelegationInfo a left join (select top 100 percent Diid, CASE
  21270. // WHEN COUNT(*) >= 0 THEN 'True'
  21271. // ELSE 'False' END as isTrue from Grp_GroupCost where Isdel = 0 and date != '' group by Diid) b on a.Id = b.Diid
  21272. // Where TeamName != '' And IsDel = 0 And TeamName LIKE '{likeKey}' Order By a.VisitStartDate Desc
  21273. // ")
  21274. // .ToList();
  21275. //}
  21276. #endregion
  21277. var table = _sqlSugar.Ado.UseStoredProcedure().GetDataTable("SearchGroupByKeyword", new
  21278. {
  21279. @KeyWord = dto.Keyword
  21280. });
  21281. if (table != null && table.Rows.Count > 0)
  21282. {
  21283. foreach (DataRow row in table.Rows)
  21284. {
  21285. matches.Add(new DelegationInfoAndIsTrueView
  21286. {
  21287. Id = row.Field<int>("Id"),
  21288. GroupName = row.Field<string>("GroupName"),
  21289. isTrue = row.Field<string>("isTrue")
  21290. });
  21291. }
  21292. }
  21293. if (matches.Any())
  21294. {
  21295. jw.Data = matches;
  21296. }
  21297. else
  21298. {
  21299. jw.Code = 201;
  21300. jw.Msg = "empty list";
  21301. jw.Data = new List<string>(1);
  21302. }
  21303. return Ok(jw);
  21304. }
  21305. /// <summary>
  21306. /// 报价Word下载
  21307. /// </summary>
  21308. /// <param name="dto"></param>
  21309. /// <returns></returns>
  21310. [HttpPost]
  21311. public async Task<IActionResult> GroupQuotationsFileDown(GroupQuotationsFileDownDto dto)
  21312. {
  21313. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21314. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21315. if (di == null)
  21316. {
  21317. return Ok(JsonView(false, "团组不存在!"));
  21318. }
  21319. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  21320. if (mainPrice == null || mainPrice.IsShare == 0)
  21321. {
  21322. return Ok(JsonView(false, "团组成本不存在!"));
  21323. }
  21324. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  21325. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  21326. if (costTypeHotelNumbers == null)
  21327. {
  21328. return Ok(JsonView(false, "团组成本不存在!"));
  21329. }
  21330. //文件名
  21331. string strFileName = di.TeamName + "-收款账单.doc";
  21332. //获取模板
  21333. string tmppath = (AppSettingsHelper.Get("WordBasePath") + "Template/收款账单(四川)模板.doc");
  21334. //载入模板
  21335. Document doc = new Document(tmppath);
  21336. decimal allPrice = 0.00M;
  21337. string itemStr = string.Empty;
  21338. Dictionary<string, string> airSouer = new Dictionary<string, string>();
  21339. airSouer.Add("经济舱TBR", "经济舱及酒店双人间");
  21340. airSouer.Add("经济舱SGR", "经济舱及酒店单人间");
  21341. airSouer.Add("公务舱SGR", "公务舱及酒店单人间");
  21342. airSouer.Add("公务舱JSES", "公务舱及酒店小套房");
  21343. airSouer.Add("公务舱SUITE", "公务舱及酒店套房");
  21344. airSouer.Add("经济舱SUITE", "经济舱及酒店套房");
  21345. airSouer.Add("头等舱JSES", "头等舱及酒店小套房");
  21346. airSouer.Add("头等舱SUITE", "头等舱及酒店套房");
  21347. airSouer.Add("经济舱JSES", "经济舱及酒店小套房");
  21348. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  21349. {
  21350. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  21351. ("BXRS", "BXCB", "BXXS", "bx"),
  21352. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  21353. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  21354. ("GWCRS", "GWCCB", "GWCXS", "gwc"),
  21355. ("TDCRS", "TDCCB", "TDCXS", "tdc"),
  21356. ("CPRS", "CPCB", "CPXS", "cp"),
  21357. ("HSRS", "HSCB", "HSXS", "hsjc"),
  21358. ("TBRNumber", "TBRCB", "TBRXS", "tbr"),
  21359. ("SGRNumber", "SGRCB", "SGRXS", "sgr"),
  21360. ("JSESNumber", "JSESCB", "JSESXS", "jses"),
  21361. ("SUITENumber", "SUITECB", "SUITEXS", "suite"),
  21362. ("DJRS", "DJCB", "DJXS", "dj"),
  21363. ("GWRS", "GWCB", "GWXS", "gw"),
  21364. ("LYJRS", "LYJCB", "LYJXS", "lyj"),
  21365. };
  21366. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  21367. var rightSum = 0.00M;
  21368. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  21369. {
  21370. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  21371. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  21372. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  21373. if (prefix == "tbr")
  21374. {
  21375. rsValue *= 2;
  21376. cbValue /= 2;
  21377. }
  21378. if (OtherCostPropertyBJ.Contains(prefix))
  21379. {
  21380. rightSum += cbValue * xsValue;
  21381. }
  21382. }
  21383. var hotelRooms = new Dictionary<string, int>
  21384. {
  21385. { "SGR", costTypeHotelNumbers.SGR },
  21386. { "TBR", costTypeHotelNumbers.TBR },
  21387. { "JSES", costTypeHotelNumbers.JSES },
  21388. { "SUITE", costTypeHotelNumbers.SUITE }
  21389. };
  21390. var flights = new Dictionary<string, int>
  21391. {
  21392. { "经济舱", mainPrice.JJCRS },
  21393. { "公务舱", mainPrice.GWCRS },
  21394. { "头等舱", mainPrice.TDCRS }
  21395. };
  21396. var flightRoomMatchingRules = new Dictionary<string, string[]>
  21397. {
  21398. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  21399. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  21400. { "头等舱", new[] { "SUITE", "JSES" } }
  21401. };
  21402. var result = new Dictionary<string, int>();
  21403. List<AirHotelPrice> airHotelPriceList = new List<AirHotelPrice>();
  21404. foreach (var flight in flights.Keys)
  21405. {
  21406. // 获取当前舱位的匹配规则
  21407. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  21408. {
  21409. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  21410. }
  21411. }
  21412. #region right计算
  21413. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  21414. {
  21415. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21416. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  21417. airHotelPriceList.Add(new
  21418. AirHotelPrice
  21419. {
  21420. Name = "经济舱TBR",
  21421. Price = rightSum + air + hotel,
  21422. Count = result["经济舱TBR"] * 2
  21423. });
  21424. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  21425. }
  21426. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  21427. {
  21428. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21429. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21430. airHotelPriceList.Add(new
  21431. AirHotelPrice
  21432. {
  21433. Name = "经济舱SGR",
  21434. Price = rightSum + air + hotel,
  21435. Count = result["经济舱SGR"]
  21436. });
  21437. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  21438. }
  21439. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  21440. {
  21441. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21442. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21443. airHotelPriceList.Add(new
  21444. AirHotelPrice
  21445. {
  21446. Name = "公务舱SGR",
  21447. Price = rightSum + air + hotel,
  21448. Count = result["公务舱SGR"]
  21449. });
  21450. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  21451. }
  21452. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  21453. {
  21454. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21455. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21456. airHotelPriceList.Add(new
  21457. AirHotelPrice
  21458. {
  21459. Name = "公务舱JSES",
  21460. Price = rightSum + air + hotel,
  21461. Count = result["公务舱JSES"]
  21462. });
  21463. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  21464. }
  21465. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  21466. {
  21467. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21468. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21469. airHotelPriceList.Add(new
  21470. AirHotelPrice
  21471. {
  21472. Name = "公务舱SUITE",
  21473. Price = rightSum + air + hotel,
  21474. Count = result["公务舱SUITE"]
  21475. });
  21476. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  21477. }
  21478. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  21479. {
  21480. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21481. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21482. airHotelPriceList.Add(new
  21483. AirHotelPrice
  21484. {
  21485. Name = "经济舱SUITE",
  21486. Price = rightSum + air + hotel,
  21487. Count = result["经济舱SUITE"]
  21488. });
  21489. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  21490. }
  21491. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  21492. {
  21493. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21494. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21495. airHotelPriceList.Add(new
  21496. AirHotelPrice
  21497. {
  21498. Name = "头等舱JSES",
  21499. Price = rightSum + air + hotel,
  21500. Count = result["头等舱JSES"]
  21501. });
  21502. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  21503. }
  21504. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  21505. {
  21506. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21507. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21508. airHotelPriceList.Add(new
  21509. AirHotelPrice
  21510. {
  21511. Name = "头等舱SUITE",
  21512. Price = rightSum + air + hotel,
  21513. Count = result["头等舱SUITE"]
  21514. });
  21515. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  21516. }
  21517. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  21518. {
  21519. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21520. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21521. airHotelPriceList.Add(new
  21522. AirHotelPrice
  21523. {
  21524. Name = "经济舱JSES",
  21525. Price = rightSum + air + hotel,
  21526. Count = result["经济舱JSES"]
  21527. });
  21528. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  21529. }
  21530. #endregion
  21531. foreach (var item in airSouer.Keys)
  21532. {
  21533. var find = airHotelPriceList.FirstOrDefault(x => x.Name == item);
  21534. if (find != null && find.Count > 0)
  21535. {
  21536. if (item.Contains("TBR"))
  21537. {
  21538. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + (find.Count / 2) + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  21539. }
  21540. else
  21541. {
  21542. itemStr += "团费(" + airSouer[item] + ") RMB " + find.Price.ToString("F2") + "/人*" + find.Count + "(" + find.Count + "间) ............合计 RMB " + (find.Count * find.Price).ToString("#0.00") + "\n";
  21543. }
  21544. }
  21545. }
  21546. #region 替换Word模板书签内容
  21547. Dictionary<string, string> marks = new Dictionary<string, string>();
  21548. marks.Add("To", di.ClientUnit);//付款方
  21549. marks.Add("ToTel", di.TellPhone);//付款方电话
  21550. marks.Add("Date", DateTime.Now.ToString("yyyy-MM-dd"));//导出时间
  21551. marks.Add("Team", di.VisitCountry.Replace(" ", "、"));//团队名称
  21552. marks.Add("TontractTime", (di.VisitDate).ToString("yyyy年MM月dd日"));//付款日期
  21553. marks.Add("PayDay", (di.PayDay).ToString());//付款预期
  21554. marks.Add("PaymentMoney", (di.PaymentMoney).ToString("#0.00"));//付款金额
  21555. marks.Add("WeChat", di.WeChatNo ?? "");//微信号
  21556. marks.Add("PayItemContent", itemStr);//详细信息
  21557. marks.Add("Total", allPrice.ToString("F2"));//合计
  21558. #endregion
  21559. foreach (var item in marks.Keys)
  21560. {
  21561. if (doc.Range.Bookmarks[item] != null)
  21562. {
  21563. Bookmark mark = doc.Range.Bookmarks[item];
  21564. mark.Text = marks[item];
  21565. }
  21566. }
  21567. string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupCostQuotations/{di.TeamName}_报批费用.doc";
  21568. doc.Save(savePaht);
  21569. var jw = new JsonView();
  21570. jw.Msg = "生成成功!";
  21571. jw.Code = 200;
  21572. jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath")) };
  21573. return Ok(jw);
  21574. }
  21575. /// <summary>
  21576. /// 详细报价费用Excel下载
  21577. /// </summary>
  21578. /// <param name="dto"></param>
  21579. /// <returns></returns>
  21580. [HttpPost]
  21581. public async Task<IActionResult> GroupQuotationsDetailFileDown(GroupQuotationsFileDownDto dto)
  21582. {
  21583. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21584. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21585. if (di == null)
  21586. {
  21587. return Ok(JsonView(false, "团组不存在!"));
  21588. }
  21589. var mainPrice = _GroupCostParameterRepository.GetGroupCostParameterMainByDiid(dto.Diid);
  21590. if (mainPrice == null || mainPrice.IsShare == 0)
  21591. {
  21592. return Ok(JsonView(false, "团组成本不存在!"));
  21593. }
  21594. var costTypeHotelNumbers = await _sqlSugar.Queryable<Grp_CostTypeHotelNumber>()
  21595. .FirstAsync(x => x.Type == "Default" && x.Diid == dto.Diid && x.IsDel == 0);
  21596. if (costTypeHotelNumbers == null)
  21597. {
  21598. return Ok(JsonView(false, "团组成本不存在!"));
  21599. }
  21600. WorkbookDesigner designer = new WorkbookDesigner();
  21601. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + ("Template/报价详细表.xls"));
  21602. List<int> hideRowsList = new List<int>();
  21603. int conterStartIndex = 3;
  21604. int rowIndex = conterStartIndex;
  21605. designer.SetDataSource("GroupName", di.TeamName);
  21606. var priceDataList = new List<(string rsName, string cbName, string xsName, string prefix)>
  21607. {
  21608. ("VisaRS", "VisaCB", "VisaXS", "qz"),
  21609. ("BXRS", "BXCB", "BXXS", "bx"),
  21610. ("HCPRS", "HCPCB", "HCPXS", "hcp"),
  21611. ("JJCRS", "JJCCB", "JJCXS", "jjc"),
  21612. ("GWCRS", "GWCCB", "GWCXS", "gwc") ,
  21613. ("TDCRS", "TDCCB", "TDCXS", "tdc") ,
  21614. ("CPRS", "CPCB", "CPXS", "cp") ,
  21615. ("HSRS", "HSCB", "HSXS", "hsjc") ,
  21616. ("TBRNumber", "TBRCB", "TBRXS", "tbr") ,
  21617. ("SGRNumber", "SGRCB", "SGRXS", "sgr") ,
  21618. ("JSESNumber", "JSESCB", "JSESXS", "jses") ,
  21619. ("SUITENumber", "SUITECB", "SUITEXS", "suite") ,
  21620. ("DJRS", "DJCB", "DJXS", "dj") ,
  21621. ("GWRS", "GWCB", "GWXS", "gw") ,
  21622. ("LYJRS", "LYJCB", "LYJXS", "lyj") ,
  21623. };
  21624. var OtherCostPropertyBJ = new string[] { "qz", "hcp", "cp", "bx", "hsjc", "dj", "gw", "lyj" };
  21625. var rightSum = 0.00M;
  21626. foreach (var (rsName, cbName, xsName, prefix) in priceDataList)
  21627. {
  21628. var rsValue = (int)mainPrice.GetType().GetProperty(rsName).GetValue(mainPrice);
  21629. var cbValue = (decimal)mainPrice.GetType().GetProperty(cbName).GetValue(mainPrice);
  21630. var xsValue = (decimal)mainPrice.GetType().GetProperty(xsName).GetValue(mainPrice);
  21631. if (prefix == "tbr")
  21632. {
  21633. rsValue *= 2;
  21634. cbValue /= 2;
  21635. }
  21636. if (OtherCostPropertyBJ.Contains(prefix))
  21637. {
  21638. rightSum += cbValue * xsValue;
  21639. }
  21640. if (rsValue == 0)
  21641. {
  21642. hideRowsList.Add(rowIndex);
  21643. }
  21644. else
  21645. {
  21646. designer.SetDataSource($"{prefix}rs", rsValue);
  21647. designer.SetDataSource($"{prefix}bj", cbValue * xsValue);
  21648. designer.SetDataSource($"{prefix}zbj", cbValue * xsValue * rsValue);
  21649. }
  21650. rowIndex += 2;
  21651. }
  21652. var hotelRooms = new Dictionary<string, int>
  21653. {
  21654. { "SGR", costTypeHotelNumbers.SGR },
  21655. { "TBR", costTypeHotelNumbers.TBR },
  21656. { "JSES", costTypeHotelNumbers.JSES },
  21657. { "SUITE", costTypeHotelNumbers.SUITE }
  21658. };
  21659. var flights = new Dictionary<string, int>
  21660. {
  21661. { "经济舱", mainPrice.JJCRS },
  21662. { "公务舱", mainPrice.GWCRS },
  21663. { "头等舱", mainPrice.TDCRS }
  21664. };
  21665. var flightRoomMatchingRules = new Dictionary<string, string[]>
  21666. {
  21667. { "经济舱", new[] { "TBR", "SGR", "JSES", "SUITE" } },
  21668. { "公务舱", new[] { "SUITE", "JSES", "SGR" } },
  21669. { "头等舱", new[] { "SUITE", "JSES" } }
  21670. };
  21671. var result = new Dictionary<string, int>();
  21672. foreach (var flight in flights.Keys)
  21673. {
  21674. // 获取当前舱位的匹配规则
  21675. if (flightRoomMatchingRules.TryGetValue(flight, out string[] roomTypes))
  21676. {
  21677. MatchRooms(ref hotelRooms, ref flights, roomTypes, flight, ref result);
  21678. }
  21679. }
  21680. var allPrice = 0.00M;
  21681. #region right计算
  21682. int airRowIndex = 35;
  21683. if (result.Keys.Contains("经济舱TBR") && result["经济舱TBR"] > 0)
  21684. {
  21685. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21686. var hotel = (mainPrice.TBRCB * mainPrice.TBRXS) / 2;
  21687. designer.SetDataSource("jjctbrrs", result["经济舱TBR"] * 2);
  21688. designer.SetDataSource("jjctbrbj", rightSum + air + hotel);
  21689. designer.SetDataSource("jjctbrzbj", (rightSum + air + hotel) * result["经济舱TBR"] * 2);
  21690. allPrice += (rightSum + air + hotel) * result["经济舱TBR"] * 2;
  21691. }
  21692. else
  21693. {
  21694. hideRowsList.Add(airRowIndex);
  21695. }
  21696. airRowIndex += 2;
  21697. if (result.Keys.Contains("经济舱SGR") && result["经济舱SGR"] > 0)
  21698. {
  21699. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21700. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21701. designer.SetDataSource("jjcsgrrs", result["经济舱SGR"]);
  21702. designer.SetDataSource("jjcsgrbj", rightSum + air + hotel);
  21703. designer.SetDataSource("jjcsgrzbj", (rightSum + air + hotel) * result["经济舱SGR"]);
  21704. allPrice += (rightSum + air + hotel) * result["经济舱SGR"];
  21705. }
  21706. else
  21707. {
  21708. hideRowsList.Add(airRowIndex);
  21709. }
  21710. airRowIndex += 2;
  21711. if (result.Keys.Contains("公务舱SGR") && result["公务舱SGR"] > 0)
  21712. {
  21713. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21714. var hotel = mainPrice.SGRCB * mainPrice.SGRXS;
  21715. designer.SetDataSource("gwcsgrrs", result["公务舱SGR"]);
  21716. designer.SetDataSource("gwcsgrbj", rightSum + air + hotel);
  21717. designer.SetDataSource("gwcsgrzbj", (rightSum + air + hotel) * result["公务舱SGR"]);
  21718. allPrice += (rightSum + air + hotel) * result["公务舱SGR"];
  21719. }
  21720. else
  21721. {
  21722. hideRowsList.Add(airRowIndex);
  21723. }
  21724. airRowIndex += 2;
  21725. if (result.Keys.Contains("公务舱JSES") && result["公务舱JSES"] > 0)
  21726. {
  21727. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21728. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21729. designer.SetDataSource("gwcjsesrs", result["公务舱JSES"]);
  21730. designer.SetDataSource("gwcjsesbj", rightSum + air + hotel);
  21731. designer.SetDataSource("gwcjseszbj", (rightSum + air + hotel) * result["公务舱JSES"]);
  21732. allPrice += (rightSum + air + hotel) * result["公务舱JSES"];
  21733. }
  21734. else
  21735. {
  21736. hideRowsList.Add(airRowIndex);
  21737. }
  21738. airRowIndex += 2;
  21739. if (result.Keys.Contains("公务舱SUITE") && result["公务舱SUITE"] > 0)
  21740. {
  21741. var air = mainPrice.GWCCB * mainPrice.GWCXS;
  21742. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21743. designer.SetDataSource("gwcsuiters", result["公务舱SUITE"]);
  21744. designer.SetDataSource("gwcsuitebj", rightSum + air + hotel);
  21745. designer.SetDataSource("gwcsuitezbj", (rightSum + air + hotel) * result["公务舱SUITE"]);
  21746. allPrice += (rightSum + air + hotel) * result["公务舱SUITE"];
  21747. }
  21748. else
  21749. {
  21750. hideRowsList.Add(airRowIndex);
  21751. }
  21752. airRowIndex += 2;
  21753. if (result.Keys.Contains("经济舱SUITE") && result["经济舱SUITE"] > 0)
  21754. {
  21755. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21756. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21757. designer.SetDataSource("jjcsuiters", result["经济舱SUITE"]);
  21758. designer.SetDataSource("jjcsuitebj", rightSum + air + hotel);
  21759. designer.SetDataSource("jjcsuitezbj", (rightSum + air + hotel) * result["经济舱SUITE"]);
  21760. allPrice += (rightSum + air + hotel) * result["经济舱SUITE"];
  21761. }
  21762. else
  21763. {
  21764. hideRowsList.Add(airRowIndex);
  21765. }
  21766. airRowIndex += 2;
  21767. if (result.Keys.Contains("头等舱JSES") && result["头等舱JSES"] > 0)
  21768. {
  21769. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21770. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21771. designer.SetDataSource("tdcjsesrs", result["头等舱JSES"]);
  21772. designer.SetDataSource("tdcjsesbj", rightSum + air + hotel);
  21773. designer.SetDataSource("tdcjseszbj", (rightSum + air + hotel) * result["头等舱JSES"]);
  21774. allPrice += (rightSum + air + hotel) * result["头等舱JSES"];
  21775. }
  21776. else
  21777. {
  21778. hideRowsList.Add(airRowIndex);
  21779. }
  21780. airRowIndex += 2;
  21781. if (result.Keys.Contains("头等舱SUITE") && result["头等舱SUITE"] > 0)
  21782. {
  21783. var air = mainPrice.TDCCB * mainPrice.TDCXS;
  21784. var hotel = mainPrice.SUITECB * mainPrice.SUITEXS;
  21785. designer.SetDataSource("tdcsuiters", result["头等舱SUITE"]);
  21786. designer.SetDataSource("tdcsuitebj", rightSum + air + hotel);
  21787. designer.SetDataSource("tdcsuitezbj", (rightSum + air + hotel) * result["头等舱SUITE"]);
  21788. allPrice += (rightSum + air + hotel) * result["头等舱SUITE"];
  21789. }
  21790. else
  21791. {
  21792. hideRowsList.Add(airRowIndex);
  21793. }
  21794. airRowIndex += 2;
  21795. if (result.Keys.Contains("经济舱JSES") && result["经济舱JSES"] > 0)
  21796. {
  21797. var air = mainPrice.JJCCB * mainPrice.JJCXS;
  21798. var hotel = mainPrice.JSESCB * mainPrice.JSESXS;
  21799. designer.SetDataSource("jjcjsesrs", result["经济舱JSES"]);
  21800. designer.SetDataSource("jjcjsesbj", rightSum + air + hotel);
  21801. designer.SetDataSource("jjcjseszbj", (rightSum + air + hotel) * result["经济舱JSES"]);
  21802. allPrice += (rightSum + air + hotel) * result["经济舱JSES"];
  21803. }
  21804. else
  21805. {
  21806. hideRowsList.Add(airRowIndex);
  21807. }
  21808. #endregion
  21809. designer.SetDataSource("AllPrice", "总金额:" + allPrice.ToString("#0.00"));
  21810. string savePaht = AppSettingsHelper.Get("ExcelBasePath") + "GroupCostQuotations/" + di.TeamName + "_详细报批费用.xls";
  21811. var ws = designer.Workbook.Worksheets[0];
  21812. foreach (var Rowindex in hideRowsList)
  21813. {
  21814. ws.Cells.HideRows(Rowindex, 2);
  21815. }
  21816. designer.Process();
  21817. designer.Workbook.Save(savePaht);
  21818. return Ok(JsonView(true, "生成成功!", new
  21819. {
  21820. Url = AppSettingsHelper.Get("ExcelBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelFtpPath"))
  21821. }));
  21822. }
  21823. private void MatchRooms(ref Dictionary<string, int> hotelRooms, ref Dictionary<string, int> flights, string[] roomTypes, string flightType, ref Dictionary<string, int> result)
  21824. {
  21825. foreach (var roomType in roomTypes)
  21826. {
  21827. while (hotelRooms[roomType] > 0 && flights[flightType] > 0)
  21828. {
  21829. hotelRooms[roomType]--;
  21830. flights[flightType]--;
  21831. if (roomType == "TBR")
  21832. {
  21833. flights[flightType]--; // 双人间在减少1
  21834. }
  21835. string key = flightType + roomType;
  21836. if (result.Keys.Contains(key))
  21837. {
  21838. result[key]++;
  21839. }
  21840. else
  21841. {
  21842. result.Add(key, 1);
  21843. }
  21844. }
  21845. }
  21846. }
  21847. private class AirHotelPrice
  21848. {
  21849. public string Name { get; set; }
  21850. public decimal Price { get; set; }
  21851. public int Count { get; set; }
  21852. }
  21853. /// <summary>
  21854. /// 团组系数设置
  21855. /// </summary>
  21856. /// <param name="dto"></param>
  21857. /// <returns></returns>
  21858. [HttpPost]
  21859. public async Task<IActionResult> QueryGroupCostCoefficient(QueryGroupCostCoefficientDto dto)
  21860. {
  21861. var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  21862. .FirstAsync(x => x.Id == dto.Diid && x.IsDel == 0);
  21863. if (di == null)
  21864. {
  21865. return Ok(JsonView(false, "团组不存在!"));
  21866. }
  21867. //var firstExpression = Expressionable.Create<Grp_GroupCostParameter>()
  21868. // .And(x => x.CostType == "A" && x.DiId == di.Id && x.IsDel == 0);
  21869. //var groupCostMainPrice = await _sqlSugar.Queryable<Grp_GroupCostParameter>().
  21870. // FirstAsync(firstExpression.ToExpression());
  21871. #region JSON
  21872. string hcpJson = @"
  21873. [
  21874. {
  21875. ""min"": 1,
  21876. ""max"": 500,
  21877. ""value"": 1.50
  21878. },
  21879. {
  21880. ""min"": 501,
  21881. ""max"": 1000,
  21882. ""value"": 1.40
  21883. },
  21884. {
  21885. ""min"": 1001,
  21886. ""max"": 2000,
  21887. ""value"": 1.35
  21888. }
  21889. ]";
  21890. #endregion
  21891. var hcpPriceRange = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PriceRange>>(hcpJson);
  21892. List<(Predicate<decimal>, decimal)> hcpSwitchDictionary = hcpPriceRange
  21893. .Select(pr => (new Predicate<decimal>(x => x >= pr.Min && x <= pr.Max), pr.Value))
  21894. .ToList();
  21895. List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)> jjcSwitchDictionary =
  21896. new List<(Predicate<decimal>, List<(Predicate<decimal>, decimal)>)>();
  21897. //jjcSwitchDictionary.Add((new Predicate<decimal>(x => x >= 1 && x <= 3),
  21898. // new List<(Predicate<decimal>, decimal)>()
  21899. // {
  21900. // (new Predicate<decimal>(y => y >= 1000 && y <= 3000), 2.6M),
  21901. // (new Predicate<decimal>(y => y > 3000), 2.5M)
  21902. // }
  21903. // ));
  21904. #region 签证系数
  21905. var visaXS = 0.00M;
  21906. switch (dto.VisaCB)
  21907. {
  21908. case decimal n when (n > 1 && n < 500):
  21909. switch (dto.VisaRS)
  21910. {
  21911. case 2 or 3:
  21912. visaXS = 1.35M;
  21913. break;
  21914. case 4 or 5:
  21915. visaXS = 1.30M;
  21916. break;
  21917. case 6 or 7:
  21918. visaXS = 1.25M;
  21919. break;
  21920. case 8 or 9 or 10:
  21921. visaXS = 1.20M;
  21922. break;
  21923. case > 10:
  21924. visaXS = 1.15M;
  21925. break;
  21926. default:
  21927. visaXS = 0.00M;
  21928. break;
  21929. }
  21930. break;
  21931. case decimal n when (n >= 500 && n < 1000):
  21932. switch (dto.VisaRS)
  21933. {
  21934. case 2 or 3 or 4:
  21935. visaXS = 1.30M;
  21936. break;
  21937. case 5 or 6 or 7 or 8:
  21938. visaXS = 1.25M;
  21939. break;
  21940. case 9 or 10:
  21941. visaXS = 1.20M;
  21942. break;
  21943. case > 10:
  21944. visaXS = 1.15M;
  21945. break;
  21946. default:
  21947. visaXS = 0.00M;
  21948. break;
  21949. }
  21950. break;
  21951. default:
  21952. switch (dto.VisaRS)
  21953. {
  21954. case 2 or 3 or 4:
  21955. visaXS = 1.30M;
  21956. break;
  21957. case 5 or 6 or 7 or 8:
  21958. visaXS = 1.25M;
  21959. break;
  21960. case 9 or 10:
  21961. visaXS = 1.20M;
  21962. break;
  21963. case > 10:
  21964. visaXS = 1.15M;
  21965. break;
  21966. default:
  21967. visaXS = 0.00M;
  21968. break;
  21969. }
  21970. break;
  21971. }
  21972. #endregion
  21973. #region 火车系数
  21974. var hcpXS = 0.00M;
  21975. foreach (var (condition, result) in hcpSwitchDictionary)
  21976. {
  21977. if (condition(dto.HCPCB))
  21978. {
  21979. hcpXS = result;
  21980. break;
  21981. }
  21982. }
  21983. #endregion
  21984. #region 机票系数
  21985. #region 经济舱系数
  21986. var jjcXS = 0.00M;
  21987. switch (dto.JJCCB)
  21988. {
  21989. case decimal x when (x >= 1000 && x <= 3000):
  21990. jjcXS = 2.6M;
  21991. break;
  21992. case decimal x when (x >= 3001 && x <= 8000):
  21993. jjcXS = 2.3M;
  21994. break;
  21995. case decimal x when (x >= 8001 && x <= 15000):
  21996. jjcXS = 2.1M;
  21997. break;
  21998. case decimal x when (x >= 15001 && x <= 30000):
  21999. jjcXS = 1.95M;
  22000. break;
  22001. case > 30000:
  22002. jjcXS = 1.8M;
  22003. break;
  22004. default:
  22005. break;
  22006. }
  22007. #endregion
  22008. #region 公务舱系数
  22009. var gwcXS = 0.00M;
  22010. switch (dto.GWCCB)
  22011. {
  22012. case decimal x when (x >= 1000 && x <= 3000):
  22013. gwcXS = 2.5M;
  22014. break;
  22015. case decimal x when (x >= 3001 && x <= 8000):
  22016. gwcXS = 2.2M;
  22017. break;
  22018. case decimal x when (x >= 8001 && x <= 15000):
  22019. gwcXS = 2.0M;
  22020. break;
  22021. case decimal x when (x >= 15001 && x <= 30000):
  22022. gwcXS = 1.85M;
  22023. break;
  22024. case > 30000:
  22025. gwcXS = 1.7M;
  22026. break;
  22027. default:
  22028. break;
  22029. }
  22030. #endregion
  22031. #region 头等舱系数
  22032. var tdcXS = 0.00M;
  22033. switch (dto.TDCCB)
  22034. {
  22035. case > 70000:
  22036. tdcXS = 1.5M;
  22037. break;
  22038. default:
  22039. tdcXS = 1.9M;
  22040. break;
  22041. }
  22042. #endregion
  22043. #endregion
  22044. #region 酒店系数
  22045. Dictionary<decimal, List<string>> dic = new Dictionary<decimal, List<string>>()
  22046. {
  22047. {1.6M, new List<string>(){"新西兰","澳大利亚" }},
  22048. {1.5M, new List<string>(){"越南社会主义共和国",
  22049. "老挝",
  22050. "柬埔寨",
  22051. "泰国",
  22052. "缅甸",
  22053. "马来西亚",
  22054. //"新加坡",
  22055. "文莱达鲁萨兰",
  22056. "印度尼西亚",
  22057. "东帝汶"}},
  22058. {1.2M, new List<string>(){ "日本","新加坡","法国","意大利","荷兰"}},
  22059. };
  22060. #region SGR
  22061. var sgrXS = 1.25M;
  22062. #endregion
  22063. #region TBR
  22064. var tbrXS = 1.25M;
  22065. #endregion
  22066. #region JSES
  22067. var jsesXS = 1.25M;
  22068. #endregion
  22069. #region SUITE
  22070. var suiteXS = 1.25M;
  22071. #endregion
  22072. var countryArr = di.VisitCountry.Split("|");
  22073. foreach (var item in dic)
  22074. {
  22075. var extsisCount = item.Value.Where(x => countryArr.Contains(x))
  22076. .Count();
  22077. if (extsisCount > 0)
  22078. {
  22079. jsesXS = item.Key;
  22080. sgrXS = item.Key;
  22081. tbrXS = item.Key;
  22082. suiteXS = item.Key;
  22083. }
  22084. }
  22085. #endregion
  22086. #region 地接系数
  22087. var djXS = 0.00M;
  22088. switch (dto.DJRS)
  22089. {
  22090. case 2 or 3:
  22091. djXS = 2.65M;
  22092. break;
  22093. case 4:
  22094. djXS = 2.6M;
  22095. break;
  22096. case 5 or 6:
  22097. djXS = 2.5M;
  22098. break;
  22099. case 7 or 8:
  22100. djXS = 2.4M;
  22101. break;
  22102. case 9 or 10:
  22103. djXS = 2.3M;
  22104. break;
  22105. case 11:
  22106. djXS = 2.2M;
  22107. break;
  22108. case 12:
  22109. djXS = 2.1M;
  22110. break;
  22111. case 13 or 14:
  22112. djXS = 2M;
  22113. break;
  22114. case 15:
  22115. djXS = 1.9M;
  22116. break;
  22117. case 16 or 17 or 18:
  22118. djXS = 1.8M;
  22119. break;
  22120. case 19 or 20:
  22121. djXS = 1.7M;
  22122. break;
  22123. }
  22124. #endregion
  22125. #region 零用金系数
  22126. var lyjXS = 0.00M;
  22127. switch (dto.LYJRS)
  22128. {
  22129. case 2:
  22130. lyjXS = 1.25M;
  22131. break;
  22132. case 3 or 4 or 5:
  22133. lyjXS = 1.2M;
  22134. break;
  22135. case int number when (number > 5 && number < 10):
  22136. lyjXS = 1.15M;
  22137. break;
  22138. case > 10:
  22139. lyjXS = 1.1M;
  22140. break;
  22141. default:
  22142. break;
  22143. }
  22144. #endregion
  22145. return Ok(JsonView(true, "查询成功", new ArrayList()
  22146. {
  22147. new { label = "火车票系数", value = hcpXS, key = "hcpXS" },
  22148. new { label = "经济舱系数", value = jjcXS, key = "jjcXS" },
  22149. new { label = "公务舱系数", value = gwcXS, key = "gwcXS" },
  22150. new { label = "头等舱系数", value = tdcXS, key = "tdcXS" },
  22151. new { label = "SGR系数", value = sgrXS, key = "sgrXS" },
  22152. new { label = "TBR系数", value = tbrXS, key = "tbrXS" },
  22153. new { label = "JSES系数", value = jsesXS, key = "jsesXS" },
  22154. new { label = "SUITE系数", value = suiteXS, key = "suiteXS" },
  22155. new { label = "地接系数", value = djXS, key = "djXS" },
  22156. new { label = "零用金系数", value = lyjXS, key = "lyjXS" },
  22157. new { label = "公务系数", value = 2M, key = "gwXS" }
  22158. }));
  22159. }
  22160. #endregion
  22161. #region 酒店预订 New 2023-12-28 17:45
  22162. /// <summary>
  22163. /// 酒店预订
  22164. /// 酒店费用列表 根据团组Id查询
  22165. /// </summary>
  22166. /// <param name="_dto"></param>
  22167. /// <returns></returns>
  22168. [HttpPost]
  22169. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22170. public async Task<IActionResult> PostHotelReservationsItemsByDiId(HotelReservationItemDto _dto)
  22171. {
  22172. #region 参数验证
  22173. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22174. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22175. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22176. #region 团组操作权限验证 76 酒店预定模块
  22177. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22178. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22179. #endregion
  22180. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22181. #region 页面操作权限验证
  22182. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22183. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22184. #endregion
  22185. #endregion
  22186. return Ok(await _hotelPriceRep.ItemsByDiId(_dto.PortType, _dto.DiId));
  22187. }
  22188. /// <summary>
  22189. /// 酒店预订
  22190. /// 基础数据
  22191. /// </summary>
  22192. /// <param name="_dto"></param>
  22193. /// <returns></returns>
  22194. [HttpPost]
  22195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22196. public async Task<IActionResult> PostHotelReservationsBasicsDataInit(HotelReservationBasicsDataInitDto _dto)
  22197. {
  22198. #region 参数验证
  22199. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22200. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22201. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22202. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22203. #region 页面操作权限验证
  22204. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22205. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22206. #endregion
  22207. #region 团组操作权限验证 76 酒店预定模块
  22208. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22209. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22210. #endregion
  22211. #endregion
  22212. return Ok(await _hotelPriceRep.BasicsDataInit(_dto.PortType, _dto.DiId));
  22213. }
  22214. /// <summary>
  22215. /// 酒店预订
  22216. /// 创建 入住卷号码
  22217. /// </summary>
  22218. /// <param name="_dto"></param>
  22219. /// <returns></returns>
  22220. [HttpPost]
  22221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22222. public async Task<IActionResult> PostHotelReservationsCreateCheckVolumeNo(HotelReservationBasicsDataInitDto _dto)
  22223. {
  22224. #region 参数验证
  22225. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22226. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22227. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22228. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22229. #region 页面操作权限验证
  22230. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22231. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22232. #endregion
  22233. #region 团组操作权限验证 76 酒店预定模块
  22234. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22235. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22236. #endregion
  22237. #endregion
  22238. Result data = await _hotelPriceRep.CreateCheckVolumeNo(_dto.DiId);
  22239. if (data.Code != 0)
  22240. {
  22241. return Ok(JsonView(false, data.Msg));
  22242. }
  22243. return Ok(JsonView(true, data.Msg, data.Data));
  22244. }
  22245. /// <summary>
  22246. /// 酒店预订
  22247. /// 详情
  22248. /// </summary>
  22249. /// <param name="_dto"></param>
  22250. /// <returns></returns>
  22251. [HttpPost]
  22252. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22253. public async Task<IActionResult> PostHotelReservationsDetails(HotelReservationsDetailsDto _dto)
  22254. {
  22255. #region 参数验证
  22256. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入正确的UserId参数"));
  22257. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22258. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入正确的DiId参数"));
  22259. #region 团组操作权限验证 76 酒店预定模块
  22260. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22261. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22262. #endregion
  22263. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22264. #region 页面操作权限验证
  22265. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22266. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  22267. #endregion
  22268. #endregion
  22269. return Ok(await _hotelPriceRep.Details(_dto.PortType, _dto.Id));
  22270. }
  22271. /// <summary>
  22272. /// 酒店预订
  22273. /// Add Or Edit
  22274. /// </summary>
  22275. /// <param name="_dto"></param>
  22276. /// <returns></returns>
  22277. [HttpPost]
  22278. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22279. public async Task<IActionResult> PostHotelReservationsAddOrEdit(HotelReservationsAddOrEditDto _dto)
  22280. {
  22281. #region 参数验证
  22282. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22283. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22284. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22285. #region 团组操作权限验证 76 酒店预定模块
  22286. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22287. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22288. #endregion
  22289. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22290. #region 页面操作权限验证
  22291. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22292. if (_dto.Id == 0) // Add
  22293. {
  22294. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  22295. }
  22296. else if (_dto.Id > 1) // Edit
  22297. {
  22298. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  22299. }
  22300. else return Ok(JsonView(false, "请输入正确的数据Id!"));
  22301. #endregion
  22302. #endregion
  22303. //验证
  22304. if (_dto.Id > 0)
  22305. {
  22306. (bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  22307. if (!valid) return Ok(JsonView(false, msg));
  22308. }
  22309. JsonView _view = await _hotelPriceRep.AddOrEdit(_dto);
  22310. if (_view.Code != 200)
  22311. {
  22312. return Ok(_view);
  22313. }
  22314. #region 成本无酒店价格数据进入超支
  22315. _sqlSugar.BeginTran();
  22316. var start_Bool = DateTime.TryParse(_dto.CheckInDate, out DateTime start_Time);
  22317. var end_Bool = DateTime.TryParse(_dto.CheckOutDate, out DateTime end_Time);
  22318. var groupCost = _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.Diid == _dto.DiId && x.IsDel == 0).ToList();
  22319. for (int i = 0; i < groupCost.Count; i++)
  22320. {
  22321. if (groupCost[i].Date.IsNullOrWhiteSpace() && i != 0)
  22322. {
  22323. groupCost[i].Date = groupCost[i - 1].Date;
  22324. }
  22325. }
  22326. var groupCost_Grp = groupCost.GroupBy(x => x.Date).ToList();
  22327. List<Fin_GroupExtraCostDto_OP> extraCostList = new
  22328. List<Fin_GroupExtraCostDto_OP>();
  22329. if (start_Bool && end_Bool)
  22330. {
  22331. while (start_Time < end_Time)
  22332. {
  22333. foreach (var item in groupCost_Grp)
  22334. {
  22335. if (DateTime.TryParse(item.Key, out DateTime cost_Time))
  22336. {
  22337. if (DateTime.Compare(start_Time, cost_Time) == 0 && item.Sum(x => x.SGR + x.Suite + x.TBR + x.JS_ES) == 0)
  22338. {
  22339. extraCostList.Add(new
  22340. Fin_GroupExtraCostDto_OP
  22341. {
  22342. Area = _dto.AreaId,
  22343. coefficient = 1.5M,
  22344. createUser = _dto.UserId,
  22345. currency = _dto.CardPriceCurrency,
  22346. diId = _dto.DiId,
  22347. ManagerConfirm = 0,
  22348. SupervisorConfirm = 0,
  22349. SYsupervisorConfirm = 0,
  22350. editType = 1,
  22351. PortType = 1,
  22352. price = _dto.CardPrice,
  22353. PriceCount = 1,
  22354. priceType = 1027,
  22355. priceDetailType = 1044,
  22356. PriceDt = start_Time.ToString("yyyy-MM-dd"),
  22357. priceName = $"酒店超支费用-酒店导入-({start_Time.ToString("yyyy/MM/dd")})",
  22358. });
  22359. }
  22360. }
  22361. }
  22362. start_Time = start_Time.AddDays(1);
  22363. }
  22364. }
  22365. if (extraCostList.Any())
  22366. {
  22367. await _carTouristGuideGroundRep.GroupExtraCost_OperatorList(extraCostList);
  22368. }
  22369. _sqlSugar.CommitTran();
  22370. #endregion
  22371. #region 应用推送
  22372. try
  22373. {
  22374. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  22375. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  22376. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  22377. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  22378. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  22379. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  22380. var diId = _dto.DiId;
  22381. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  22382. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  22383. #region 操作记录
  22384. var opInfo = new Crm_TableOperationRecord()
  22385. {
  22386. TableName = "Grp_HotelReservations",
  22387. PortType = _dto.PortType,
  22388. DataId = hotelId,
  22389. CreateUserId = _dto.UserId
  22390. };
  22391. //var opStatus = OperationEnum.NoOperation;
  22392. if (_dto.Id < 1) //添加操作
  22393. {
  22394. opInfo.OperationItem = OperationEnum.Add;
  22395. }
  22396. else if (_dto.Id > 0)
  22397. {
  22398. opInfo.OperationItem = OperationEnum.Edit;
  22399. }
  22400. string opRemark = string.Empty;
  22401. if (ccpInfo != null)
  22402. {
  22403. // USD 1211.86、 CNY 8761.75、汇率:7.2300
  22404. var currency = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.Id == ccpInfo.PaymentCurrency).First()?.Name;
  22405. var cnyPrice = ccpInfo.PayMoney * ccpInfo.DayRate;
  22406. opRemark = $"{currency} {ccpInfo.PayMoney.ToString("#0.00")}、CNY {cnyPrice.ToString("#0.00")}、汇率:{ccpInfo.DayRate.ToString("#0.0000")}";
  22407. }
  22408. opInfo.Remark = opRemark;
  22409. await _tableorRep.AddAsync(opInfo);
  22410. #endregion
  22411. _logger.LogInformation($"【iOS推送通知Exception】Begin");
  22412. //2024-10-21 新增LZ UID
  22413. var userIds = new List<int>() { 21 };
  22414. string title = $"费用审核";
  22415. string content = "";
  22416. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22417. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22418. try
  22419. {
  22420. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "76" };
  22421. await APNsTools.iOS_PushNotifications1("051", title, "", content, true, "ExpenseAuditWebView", h5);
  22422. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】Start");
  22423. //var iosRes = await APNsTools.iOS_PushNotifications("051", title, "", content);
  22424. //Logs($"【iOS推送通知PostHotelReservationsAddOrEdit】End Response:[{JsonConvert.SerializeObject(iosRes)}]");
  22425. }
  22426. catch (Exception ex)
  22427. {
  22428. Logs($"【iOS推送通知-PostHotelReservationsAddOrEdit-Exception】[{ex.Message}]");
  22429. }
  22430. }
  22431. catch (Exception ex)
  22432. {
  22433. Logs($"【iOS推送通知Exception】【{ex.Message}】");
  22434. }
  22435. try
  22436. {
  22437. //int ccpId = (int)_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null);
  22438. //int sign = (int)_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null);
  22439. //int hotelId = (int)_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null);
  22440. int ccpId = Convert.ToInt32(_view.Data.GetType().GetProperty("ccpId").GetValue(_view.Data, null) ?? 0);
  22441. int sign = Convert.ToInt32(_view.Data.GetType().GetProperty("sign").GetValue(_view.Data, null) ?? 0);
  22442. int hotelId = Convert.ToInt32(_view.Data.GetType().GetProperty("hotelId").GetValue(_view.Data, null) ?? 0);
  22443. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  22444. //自动审核
  22445. var autoAdit = await _feeAuditRep.FeeAutomaticAudit(1, _dto.DiId, hotelId);
  22446. //if (autoAdit.Code != 200) _view.Msg += $"\r\n{autoAdit.Msg}";
  22447. _logger.LogInformation($"【酒店自动审核】【{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}】执行调用 调用结果:{JsonConvert.SerializeObject(autoAdit)}");
  22448. //2024-10-21 新增LZ UID
  22449. var userIds = new List<int>() { 21 };
  22450. string title = $"系统通知";
  22451. var diId = _dto.DiId;
  22452. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  22453. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  22454. string content = "";
  22455. if (_dto.Id == 0) content = $"[新增-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22456. else if (_dto.Id > 0) content = $"[更新-酒店费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  22457. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  22458. }
  22459. catch (Exception ex)
  22460. {
  22461. }
  22462. #endregion
  22463. return Ok(_view);
  22464. }
  22465. /// <summary>
  22466. /// 酒店自动审核测试
  22467. /// Add Or Edit
  22468. /// </summary>
  22469. /// <param name="diid"></param>
  22470. /// <param name="dataId"></param>
  22471. /// <returns></returns>
  22472. [HttpPost]
  22473. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22474. public async Task<IActionResult> PostHotelAutoAuditTest(int diid, int dataId)
  22475. {
  22476. #region 应用推送
  22477. try
  22478. {
  22479. //自动审核
  22480. await _feeAuditRep.FeeAutomaticAudit(1, diid, dataId);
  22481. }
  22482. catch (Exception ex)
  22483. {
  22484. return Ok(JsonView(false, ex.Message));
  22485. }
  22486. #endregion
  22487. return Ok(JsonView(false, "操作成功"));
  22488. }
  22489. /// <summary>
  22490. /// 酒店预订
  22491. /// Del
  22492. /// </summary>
  22493. /// <param name="_dto"></param>
  22494. /// <returns></returns>
  22495. [HttpPost]
  22496. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22497. public async Task<IActionResult> PostHotelReservationsDel(HotelReservationsDelDto _dto)
  22498. {
  22499. #region 参数验证
  22500. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22501. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22502. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22503. #region 团组操作权限验证 76 酒店预定模块
  22504. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22505. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22506. #endregion
  22507. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22508. #region 页面操作权限验证
  22509. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22510. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  22511. #endregion
  22512. #endregion
  22513. //验证
  22514. (bool valid, string msg) = await GeneralMethod.FeeOpValid(_dto.Id, 76);
  22515. if (!valid) return Ok(JsonView(false, msg));
  22516. var data = await _hotelPriceRep.Del(_dto.Id, _dto.UserId);
  22517. #region 操作记录
  22518. await _tableorRep.AddAsync(new Crm_TableOperationRecord()
  22519. {
  22520. TableName = "Grp_HotelReservations",
  22521. PortType = _dto.PortType,
  22522. OperationItem = OperationEnum.Del,
  22523. DataId = _dto.Id,
  22524. CreateUserId = _dto.UserId
  22525. });
  22526. #endregion
  22527. return Ok(data);
  22528. }
  22529. /// <summary>
  22530. /// 酒店预订
  22531. /// 生成VOUCHER
  22532. /// 2024.05.06 之前版本
  22533. /// </summary>
  22534. /// <param name="_dto"></param>
  22535. /// <returns></returns>
  22536. [HttpPost]
  22537. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22538. public async Task<IActionResult> PostHotelReservationsCreateVoucherOld(HotelReservationsCreateVoucherDto _dto)
  22539. {
  22540. try
  22541. {
  22542. #region 参数验证
  22543. if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  22544. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22545. if (_dto.DiId < 1) return Ok(JsonView(false, "团组Id为空"));
  22546. if (_dto.Id < 1) return Ok(JsonView(false, "Id为空"));
  22547. #region 团组操作权限验证 76 酒店预定模块
  22548. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22549. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  22550. #endregion
  22551. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22552. #region 页面操作权限验证
  22553. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22554. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22555. #endregion
  22556. #endregion
  22557. Grp_HotelReservations hr = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.Id == _dto.Id).FirstAsync();
  22558. //判断数据是否完整
  22559. if (hr != null)
  22560. {
  22561. if (!string.IsNullOrEmpty(hr.DetermineNo))
  22562. {
  22563. string strFileName = "HotelStatement/";
  22564. Grp_DelegationInfo dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  22565. if (dele != null)
  22566. strFileName += dele.TourCode;
  22567. //载入模板
  22568. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/酒店预订模板.doc";
  22569. Document doc = new Document(sss);
  22570. DocumentBuilder builder = new DocumentBuilder(doc);
  22571. #region 替换Word模板书签内容
  22572. //这里可以创建个DataTable循环添加书签的值,这里提示一下就不多做修改了
  22573. //入住卷预定号码
  22574. if (doc.Range.Bookmarks["VNO"] != null)
  22575. {
  22576. Bookmark mark = doc.Range.Bookmarks["VNO"];
  22577. mark.Text = hr.CheckNumber;
  22578. }
  22579. //酒店时间
  22580. if (doc.Range.Bookmarks["Date"] != null)
  22581. {
  22582. Bookmark mark = doc.Range.Bookmarks["Date"];
  22583. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  22584. }
  22585. //团号
  22586. if (doc.Range.Bookmarks["TNo"] != null)
  22587. {
  22588. Bookmark mark = doc.Range.Bookmarks["TNo"];
  22589. mark.Text = dele.TourCode;
  22590. }
  22591. //预定号码
  22592. if (doc.Range.Bookmarks["BookingId"] != null)
  22593. {
  22594. Bookmark mark = doc.Range.Bookmarks["BookingId"];
  22595. mark.Text = hr.ReservationsNo;
  22596. }
  22597. if (doc.Range.Bookmarks["HotelConfirmNo"] != null)
  22598. {
  22599. Bookmark mark = doc.Range.Bookmarks["HotelConfirmNo"];
  22600. mark.Text = hr.DetermineNo;
  22601. }
  22602. //酒店城市
  22603. if (doc.Range.Bookmarks["City"] != null)
  22604. {
  22605. Bookmark mark = doc.Range.Bookmarks["City"];
  22606. mark.Text = hr.City;
  22607. }
  22608. //酒店名称
  22609. if (doc.Range.Bookmarks["HName"] != null)
  22610. {
  22611. Bookmark mark = doc.Range.Bookmarks["HName"];
  22612. mark.Text = hr.HotelName;
  22613. }
  22614. //酒店地址
  22615. if (doc.Range.Bookmarks["Address"] != null)
  22616. {
  22617. Bookmark mark = doc.Range.Bookmarks["Address"];
  22618. mark.Text = hr.HotelAddress;
  22619. }
  22620. //酒店电话
  22621. if (doc.Range.Bookmarks["Tel"] != null)
  22622. {
  22623. Bookmark mark = doc.Range.Bookmarks["Tel"];
  22624. mark.Text = hr.HotelTel;
  22625. }
  22626. //酒店传真
  22627. if (doc.Range.Bookmarks["Fax"] != null)
  22628. {
  22629. Bookmark mark = doc.Range.Bookmarks["Fax"];
  22630. if (!string.IsNullOrWhiteSpace(hr.HotelFax))
  22631. {
  22632. mark.Text = hr.HotelFax;
  22633. }
  22634. }
  22635. //入住时间
  22636. if (doc.Range.Bookmarks["CIn"] != null)
  22637. {
  22638. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  22639. Bookmark mark = doc.Range.Bookmarks["CIn"];
  22640. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year;
  22641. }
  22642. //退房时间
  22643. if (doc.Range.Bookmarks["COut"] != null)
  22644. {
  22645. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  22646. Bookmark mark = doc.Range.Bookmarks["COut"];
  22647. mark.Text = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  22648. }
  22649. //客户名称
  22650. if (doc.Range.Bookmarks["GName"] != null)
  22651. {
  22652. string guestName = "";
  22653. string[] clients = Array.Empty<string>();
  22654. if (hr.GuestName.Contains(","))
  22655. {
  22656. clients = hr.GuestName.Split(",");
  22657. }
  22658. else
  22659. {
  22660. clients = new string[] { hr.GuestName };
  22661. }
  22662. List<int> clientIds_int = new List<int>();
  22663. if (clients.Length > 0)
  22664. {
  22665. foreach (var item in clients)
  22666. {
  22667. if (item.IsNumeric())
  22668. {
  22669. clientIds_int.Add(int.Parse(item));
  22670. }
  22671. }
  22672. }
  22673. if (clientIds_int.Count > 0)
  22674. {
  22675. var _clientDatas = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && clientIds_int.Contains(it.Id)).ToList();
  22676. foreach (var client in _clientDatas)
  22677. {
  22678. //男
  22679. if (client.Sex == 0) guestName += $"Mr.";
  22680. //女
  22681. else if (client.Sex == 1) guestName += $"Ms.";
  22682. if (!String.IsNullOrEmpty(client.FirstName + client.LastName))
  22683. {
  22684. guestName += $"{string.Join("", client.FirstName.GetTotalPingYin()).ToUpper()} {string.Join("", client.LastName.GetTotalPingYin()).ToUpper()},";
  22685. }
  22686. //guestName += $"{client.Pinyin},";
  22687. }
  22688. if (guestName.Length > 0)
  22689. {
  22690. guestName = guestName.Substring(0, guestName.Length - 1);
  22691. }
  22692. }
  22693. else
  22694. {
  22695. guestName = hr.GuestName;
  22696. }
  22697. Bookmark mark = doc.Range.Bookmarks["GName"];
  22698. mark.Text = guestName;
  22699. }
  22700. //房间介绍
  22701. if (doc.Range.Bookmarks["ROOM"] != null)
  22702. {
  22703. Bookmark mark = doc.Range.Bookmarks["ROOM"];
  22704. mark.Text = hr.RoomExplanation;
  22705. }
  22706. //报价描述
  22707. if (doc.Range.Bookmarks["NOTE"] != null)
  22708. {
  22709. Bookmark mark = doc.Range.Bookmarks["NOTE"];
  22710. Sys_SetData ss = _sqlSugar.Queryable<Sys_SetData>().First(a => a.Id == hr.ReservationsWebsite);
  22711. if (ss != null)
  22712. mark.Text = ss.Name;
  22713. }
  22714. //入住时间
  22715. if (doc.Range.Bookmarks["CheckIn"] != null)
  22716. {
  22717. DateTime dtCheckIn = Convert.ToDateTime(hr.CheckInDate);
  22718. Bookmark mark = doc.Range.Bookmarks["CheckIn"];
  22719. mark.Text = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  22720. }
  22721. //退房时间
  22722. if (doc.Range.Bookmarks["CheckOut"] != null)
  22723. {
  22724. DateTime dtCheckOut = Convert.ToDateTime(hr.CheckOutDate);
  22725. Bookmark mark = doc.Range.Bookmarks["CheckOut"];
  22726. mark.Text = " " + dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year;
  22727. }
  22728. //日期
  22729. if (doc.Range.Bookmarks["DT"] != null)
  22730. {
  22731. Bookmark mark = doc.Range.Bookmarks["DT"];
  22732. mark.Text = Convert.ToDateTime(hr.CreateTime).ToString("yyyy-MM-dd");
  22733. }
  22734. //名称
  22735. if (doc.Range.Bookmarks["VName"] != null)
  22736. {
  22737. Bookmark mark = doc.Range.Bookmarks["VName"];
  22738. mark.Text = hr.HotelName;
  22739. }
  22740. //号码
  22741. if (doc.Range.Bookmarks["VOUCHERNO"] != null)
  22742. {
  22743. Bookmark mark = doc.Range.Bookmarks["VOUCHERNO"];
  22744. mark.Text = hr.CheckNumber;
  22745. }
  22746. #endregion
  22747. strFileName += "VOUCHER.doc";
  22748. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  22749. doc.Save(fileDir);
  22750. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  22751. return Ok(JsonView(true, "操作成功!", Url));
  22752. }
  22753. else
  22754. {
  22755. return Ok(JsonView(false, "酒店确定号码未填写,无法生成Voucher!"));
  22756. }
  22757. }
  22758. else
  22759. {
  22760. return Ok(JsonView(false, "该条数据已删除或不存在!"));
  22761. }
  22762. }
  22763. catch (Exception ex)
  22764. {
  22765. return Ok(JsonView(false, ex.Message));
  22766. }
  22767. }
  22768. /// <summary>
  22769. /// 酒店预订
  22770. /// 生成VOUCHER
  22771. /// 2024.05.06 之后版本
  22772. /// </summary>
  22773. /// <param name="_dto"></param>
  22774. /// <returns></returns>
  22775. [HttpPost]
  22776. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22777. public async Task<IActionResult> PostHotelReservationsCreateVoucher(HotelReservationsCreateVoucherDto _dto)
  22778. {
  22779. #region 参数验证
  22780. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  22781. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  22782. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  22783. #region 团组操作权限验证 76 酒店预定模块
  22784. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22785. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  22786. #endregion
  22787. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22788. #region 页面操作权限验证
  22789. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22790. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22791. #endregion
  22792. #endregion
  22793. List<Grp_HotelReservations> hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToListAsync();
  22794. //判断数据是否完整
  22795. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  22796. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  22797. string strFileName = "HotelStatement/";
  22798. string guestNames = ""; //格式Mr.xxx Ms.xxx
  22799. List<HotelVoucherInfoView> vouchers = new List<HotelVoucherInfoView>();
  22800. #region 数据处理
  22801. List<int> guestIds = new List<int>();
  22802. //int index = 0;
  22803. foreach (var item in hrDtas)
  22804. {
  22805. if (item.GuestName.Contains(","))
  22806. {
  22807. string[] guestIdArr = item.GuestName.Split(',');
  22808. foreach (var guestIdStr in guestIdArr)
  22809. {
  22810. bool guestBool = int.TryParse(guestIdStr, out int guestId);
  22811. if (guestBool)
  22812. {
  22813. guestIds.Add(guestId);
  22814. }
  22815. }
  22816. }
  22817. else guestNames += item.GuestName;
  22818. var voucherInfo = new HotelVoucherInfoView()
  22819. {
  22820. HotelName = item.HotelName,
  22821. CheckInDate = item.CheckInDate,
  22822. CheckOutDate = item.CheckOutDate,
  22823. ConfirmationNumber = item.DetermineNo.Trim(),
  22824. RoomType = item.RoomExplanation
  22825. };
  22826. vouchers.Add(voucherInfo);
  22827. }
  22828. if (guestIds.Count > 0)
  22829. {
  22830. guestIds = guestIds.Distinct().ToList();
  22831. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 && guestIds.Contains(it.Id)).ToListAsync();
  22832. if (guestDatas.Count > 0)
  22833. {
  22834. guestNames = "";
  22835. foreach (var guest in guestDatas)
  22836. {
  22837. string guestName = "";
  22838. if (guest.Sex == 0) guestName += @"MR.";
  22839. else if (guest.Sex == 1) guestName += @"MS.";
  22840. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  22841. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  22842. guestNames += @$"{guestName.Trim()}、";
  22843. }
  22844. if (guestNames.Length > 0)
  22845. {
  22846. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  22847. }
  22848. }
  22849. }
  22850. #endregion
  22851. //载入模板
  22852. string sss = AppSettingsHelper.Get("WordBasePath") + "Template/Voucher-2024Versions.docx";
  22853. Document doc = new Document(sss);
  22854. DocumentBuilder builder = new DocumentBuilder(doc);
  22855. if (doc.Range.Bookmarks["GuestName"] != null)
  22856. {
  22857. Bookmark mark = doc.Range.Bookmarks["GuestName"];
  22858. mark.Text = guestNames;
  22859. }
  22860. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  22861. Aspose.Words.Tables.Table table = allTables[0] as Aspose.Words.Tables.Table;
  22862. vouchers = vouchers.OrderBy(it => it.CheckInDate).ToList();
  22863. for (int i = 1; i <= vouchers.Count; i++)
  22864. {
  22865. HotelVoucherInfoView hviv = vouchers[i - 1];
  22866. builder.MoveToCell(0, i, 0, 0);
  22867. builder.Write(hviv.HotelName);
  22868. builder.MoveToCell(0, i, 1, 0);
  22869. builder.Write(hviv.CheckInDate);
  22870. builder.MoveToCell(0, i, 2, 0);
  22871. builder.Write(hviv.CheckOutDate);
  22872. builder.MoveToCell(0, i, 3, 0);
  22873. builder.Write(hviv.RoomType);
  22874. builder.MoveToCell(0, i, 4, 0);
  22875. builder.Write(hviv.ConfirmationNumber);
  22876. }
  22877. //删除多余行
  22878. int currRowIndex = vouchers.Count + 1;
  22879. int delRows = 21 - currRowIndex;
  22880. if (delRows > 0)
  22881. {
  22882. for (int i = 0; i < delRows; i++)
  22883. {
  22884. table.Rows.RemoveAt(currRowIndex);
  22885. //cultivateRowIndex++;
  22886. }
  22887. }
  22888. strFileName += "VOUCHER.docx";
  22889. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  22890. doc.Save(fileDir);
  22891. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  22892. return Ok(JsonView(true, "操作成功!", Url));
  22893. }
  22894. /// <summary>
  22895. /// 酒店预订
  22896. /// 生成VOUCHER 批量生成
  22897. /// New
  22898. /// </summary>
  22899. /// <param name="_dto"></param>
  22900. /// <returns></returns>
  22901. [HttpPost]
  22902. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  22903. public async Task<IActionResult> PostHotelReservationsCreateVoucherBatchNew(HotelReservationsCreateVoucherDto _dto)
  22904. {
  22905. #region 参数验证
  22906. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  22907. if (_dto.PageId < 1) _dto.PageId = 28;
  22908. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  22909. #region 团组操作权限验证 76 酒店预定模块
  22910. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  22911. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  22912. #endregion
  22913. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  22914. #region 页面操作权限验证
  22915. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  22916. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  22917. #endregion
  22918. #endregion
  22919. var hrDtas = await _sqlSugar.Queryable<Grp_HotelReservations>()
  22920. .Where(it => it.IsDel == 0 && it.DiId == _dto.DiId)
  22921. .OrderBy(x => x.CheckInDate)
  22922. .ToListAsync();
  22923. //判断数据是否完整
  22924. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "请先录入酒店预订信息!", ""));
  22925. string strFileName = "HotelStatement/";
  22926. var dele = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == _dto.DiId).FirstAsync();
  22927. if (dele != null)
  22928. strFileName += $"{dele?.TeamName ?? ""}_{dele.TourCode}_";
  22929. var guestDatas = await _sqlSugar.Queryable<Crm_DeleClient>()
  22930. .Select(x => new Crm_DeleClient { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Pinyin = x.Pinyin })
  22931. .Where(it => it.IsDel == 0)
  22932. .ToListAsync();
  22933. foreach (var item in guestDatas) EncryptionProcessor.DecryptProperties(item);
  22934. for (int i = 0; i < hrDtas.Count; i++)
  22935. {
  22936. string guestNames = string.Empty;
  22937. List<int> guestIds = new List<int>();
  22938. var item = hrDtas[i];
  22939. //处理客户姓名
  22940. if (item.GuestName.Contains(","))
  22941. {
  22942. string[] guestIdArr = item.GuestName.Split(',');
  22943. foreach (var guestIdStr in guestIdArr)
  22944. if (int.TryParse(guestIdStr, out int guestId))
  22945. guestIds.Add(guestId);
  22946. }
  22947. else
  22948. {
  22949. bool guestIdBool = int.TryParse(item.GuestName, out int guestId);
  22950. if (guestIdBool)
  22951. {
  22952. guestIds.Add(guestId);
  22953. }
  22954. //NaN
  22955. if (item.GuestName.Contains("NaN"))
  22956. {
  22957. guestNames += item.GuestName.Replace("NaN", "").Replace(",", "");
  22958. }
  22959. }
  22960. if (guestIds.Count > 0)
  22961. {
  22962. guestIds = guestIds.Distinct().ToList();
  22963. var guestDatas1 = guestDatas.Where(it => guestIds.Contains(it.Id)).ToList();
  22964. if (guestDatas1.Count > 0)
  22965. {
  22966. guestNames = "";
  22967. foreach (var guest in guestDatas1)
  22968. {
  22969. string guestName = "";
  22970. if (guest.Sex == 0) guestName += @"MR.";
  22971. else if (guest.Sex == 1) guestName += @"MS.";
  22972. if (guest.Pinyin == null) guestName += $"{string.Join("", guest.LastName.GetTotalPingYin()).ToUpper()}/{string.Join("", guest.FirstName.GetTotalPingYin()).ToUpper()}";
  22973. else guestName += @$"{guest.Pinyin.Replace(" ", "")}";
  22974. guestNames += @$"{guestName.Trim()}、";
  22975. }
  22976. if (guestNames.Length > 0)
  22977. {
  22978. guestNames = guestNames.Substring(0, guestNames.Length - 1);
  22979. }
  22980. }
  22981. }
  22982. //if (!string.IsNullOrEmpty(guestNames))
  22983. //{
  22984. hrDtas[i].GuestName = guestNames;
  22985. //}
  22986. }
  22987. strFileName += $"VOUCHER_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.docx";
  22988. Document doc = new Document();
  22989. DocumentBuilder builder = new DocumentBuilder(doc);
  22990. try
  22991. {
  22992. builder.MoveToDocumentStart();
  22993. foreach (var item in hrDtas)
  22994. {
  22995. //标题
  22996. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  22997. builder.ParagraphFormat.LineSpacing = 1;
  22998. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  22999. builder.ParagraphFormat.Style.Font.Size = 9;
  23000. builder.ParagraphFormat.Style.Font.Bold = true;
  23001. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  23002. builder.Writeln(@$"ACCOMMODATION VOUCHER");
  23003. builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
  23004. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  23005. builder.ParagraphFormat.LineSpacing = 1;
  23006. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23007. builder.ParagraphFormat.Style.Font.Size = 9;
  23008. builder.ParagraphFormat.Style.Font.Bold = true;
  23009. builder.Writeln(@$"VOUCHER No:{item.CheckNumber} DATE: {item.CreateTime.ToString("yyyy-MM-dd")}");
  23010. builder.StartTable();
  23011. // 设置边框颜色
  23012. builder.CellFormat.Borders.Top.Color = System.Drawing.Color.Black;
  23013. //设置边框样式
  23014. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Dot;
  23015. //表格
  23016. #region 第一行
  23017. builder.InsertCell();
  23018. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23019. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23020. //builder.CellFormat.AllowAutoFit = false;
  23021. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23022. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23023. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23024. builder.CellFormat.WrapText = true; //自动换行
  23025. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23026. builder.RowFormat.AllowBreakAcrossPages = false; //文字自适应大小
  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("TOUR NO:");
  23032. builder.InsertCell();
  23033. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23034. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23035. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23036. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23037. builder.ParagraphFormat.Style.Font.Bold = false;
  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($"{dele?.TourCode ?? "-"}");
  23045. builder.InsertCell();
  23046. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23047. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23048. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23049. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23050. builder.ParagraphFormat.Style.Font.Bold = false;
  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($"CITY:");
  23058. builder.InsertCell();
  23059. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23060. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23061. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23062. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23063. builder.ParagraphFormat.Style.Font.Bold = false;
  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.City}");
  23071. builder.EndRow();
  23072. #endregion
  23073. #region 第二行
  23074. builder.InsertCell();
  23075. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23076. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23077. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23078. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23079. builder.ParagraphFormat.Style.Font.Bold = false;
  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("CONFIRMATION NO:");
  23087. builder.InsertCell();
  23088. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23089. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23090. builder.ParagraphFormat.Style.Font.Size = 8;
  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. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23100. builder.Write($"{item.DetermineNo}");
  23101. builder.InsertCell();
  23102. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23103. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23104. builder.InsertCell();
  23105. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23106. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23107. builder.EndRow();
  23108. #endregion
  23109. #region 第三行
  23110. builder.InsertCell();
  23111. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23112. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23113. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23114. builder.ParagraphFormat.Style.Font.Bold = false;
  23115. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23116. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23117. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23118. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23119. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23120. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23121. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23122. builder.Write($"HOTEL NAME:");
  23123. builder.InsertCell();
  23124. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23125. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23126. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23127. builder.ParagraphFormat.Style.Font.Bold = false;
  23128. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23129. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23130. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23131. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23132. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23133. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23134. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23135. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23136. builder.Write($"{item.HotelName}");
  23137. builder.InsertCell();
  23138. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23139. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23140. builder.InsertCell();
  23141. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23142. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23143. builder.EndRow();
  23144. #endregion
  23145. #region 第四行
  23146. builder.InsertCell();
  23147. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23148. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23149. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23150. builder.ParagraphFormat.Style.Font.Bold = false;
  23151. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23152. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23153. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  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.Write($"HOTEL ADDRESS:");
  23159. builder.InsertCell();
  23160. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23161. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23162. builder.ParagraphFormat.Style.Font.Size = 8;
  23163. builder.ParagraphFormat.Style.Font.Bold = false;
  23164. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23165. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23166. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23167. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23168. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23169. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23170. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23171. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23172. builder.Write($"{item.HotelAddress}");
  23173. builder.InsertCell();
  23174. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23175. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23176. builder.InsertCell();
  23177. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23178. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23179. builder.EndRow();
  23180. #endregion
  23181. #region 第五行
  23182. builder.InsertCell();
  23183. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  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.Right;//对齐
  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.Write("TEL:");
  23195. builder.InsertCell();
  23196. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23197. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23198. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23199. builder.ParagraphFormat.Style.Font.Bold = false;
  23200. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23201. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23202. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23203. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23204. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23205. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23206. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23207. builder.Write($"{item.HotelTel}");
  23208. builder.InsertCell();
  23209. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23210. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23211. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23212. builder.ParagraphFormat.Style.Font.Bold = false;
  23213. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23214. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23215. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23216. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23217. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23218. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23219. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23220. builder.Write($"FAX:");
  23221. builder.InsertCell();
  23222. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23223. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23224. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23225. builder.ParagraphFormat.Style.Font.Bold = false;
  23226. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23227. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23228. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23229. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23230. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23231. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23232. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23233. builder.Write($"{item.HotelFax}");
  23234. builder.EndRow();
  23235. #endregion
  23236. #region 第六行
  23237. builder.InsertCell();
  23238. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23239. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23240. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23241. builder.ParagraphFormat.Style.Font.Bold = false;
  23242. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23243. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23244. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23245. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23246. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23247. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23248. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23249. builder.Write("CHECK IN:");
  23250. builder.InsertCell();
  23251. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23252. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23253. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23254. builder.ParagraphFormat.Style.Font.Bold = false;
  23255. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23256. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23257. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23258. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23259. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23260. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23261. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23262. DateTime dtCheckIn = Convert.ToDateTime(item.CheckInDate);
  23263. string checkInStr = dtCheckIn.Day + " " + dtCheckIn.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckIn.Year + " ";
  23264. builder.Write($"{checkInStr}");
  23265. builder.InsertCell();
  23266. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23267. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23268. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23269. builder.ParagraphFormat.Style.Font.Bold = false;
  23270. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23271. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23272. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23273. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23274. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23275. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23276. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23277. builder.Write($"CHECK OUT:");
  23278. builder.InsertCell();
  23279. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23280. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23281. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23282. builder.ParagraphFormat.Style.Font.Bold = false;
  23283. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23284. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23285. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23286. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23287. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23288. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23289. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23290. DateTime dtCheckOut = Convert.ToDateTime(item.CheckOutDate);
  23291. string checkOutStr = dtCheckOut.Day + " " + dtCheckOut.ToString("MMMM", CultureInfo.GetCultureInfo("en-US")) + " " + dtCheckOut.Year + " ";
  23292. builder.Write($"{checkOutStr}");
  23293. builder.EndRow();
  23294. #endregion
  23295. #region 第七行
  23296. builder.InsertCell();
  23297. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23298. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23299. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23300. builder.ParagraphFormat.Style.Font.Bold = false;
  23301. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23302. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23303. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23304. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23305. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23306. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23307. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23308. builder.Write($"GUEST NAME:");
  23309. builder.InsertCell();
  23310. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23311. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23312. builder.ParagraphFormat.Style.Font.Size = 8;
  23313. builder.ParagraphFormat.Style.Font.Bold = false;
  23314. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23315. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23316. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23317. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23318. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23319. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23320. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23321. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23322. builder.Write($"{item.GuestName.Trim()}");
  23323. builder.InsertCell();
  23324. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23325. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23326. builder.InsertCell();
  23327. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23328. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23329. builder.EndRow();
  23330. #endregion
  23331. #region 第八行
  23332. builder.InsertCell();
  23333. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23334. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23335. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23336. builder.ParagraphFormat.Style.Font.Bold = false;
  23337. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23338. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23339. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23340. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23341. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23342. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23343. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23344. builder.Write($"ROOM TYPE:");
  23345. builder.InsertCell();
  23346. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23347. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23348. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23349. builder.ParagraphFormat.Style.Font.Bold = false;
  23350. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23351. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23352. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23353. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23354. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23355. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23356. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23357. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23358. builder.Write($"{item.RoomExplanation}");
  23359. builder.InsertCell();
  23360. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23361. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23362. builder.InsertCell();
  23363. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23364. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23365. builder.EndRow();
  23366. #endregion
  23367. #region 第九行
  23368. builder.InsertCell();
  23369. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23370. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23371. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23372. builder.ParagraphFormat.Style.Font.Bold = false;
  23373. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23374. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23375. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;//对齐
  23376. builder.ParagraphFormat.SpaceBefore = 0; //设置段前间距 0
  23377. builder.ParagraphFormat.SpaceAfter = 0; //设置段后间距 0
  23378. builder.ParagraphFormat.LineSpacingRule = LineSpacingRule.Exactly; //设置行距 固定值
  23379. builder.ParagraphFormat.LineSpacing = 11; //设置固定的行距为11磅
  23380. builder.Write($"NOTE:");
  23381. builder.InsertCell();
  23382. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23383. builder.ParagraphFormat.Style.Font.Name = "微软雅黑";
  23384. builder.ParagraphFormat.Style.Font.Size = 7.5;
  23385. builder.ParagraphFormat.Style.Font.Bold = false;
  23386. builder.CellFormat.HorizontalMerge = CellMerge.None;
  23387. builder.CellFormat.FitText = true;//单元格内文字设为多行(默认为单行,会影响单元格宽)
  23388. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//对齐
  23389. builder.CellFormat.HorizontalMerge = CellMerge.First;
  23390. 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.");
  23391. builder.InsertCell();
  23392. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);//列宽 - 百分比
  23393. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23394. builder.InsertCell();
  23395. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);//列宽 - 百分比
  23396. builder.CellFormat.HorizontalMerge = CellMerge.Previous;
  23397. builder.EndRow();
  23398. #endregion
  23399. builder.EndTable();
  23400. //换行
  23401. builder.Writeln("");
  23402. builder.Writeln("");
  23403. }
  23404. #region 获取文档中的所有表格 设置文字自适应
  23405. // 获取文档中的所有表格。
  23406. foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
  23407. {
  23408. // 遍历表格中的所有行。
  23409. foreach (Aspose.Words.Tables.Row row in table.Rows)
  23410. {
  23411. foreach (Cell cell in row.Cells)
  23412. {
  23413. Aspose.Words.Tables.CellFormat cellFormat = cell.CellFormat;
  23414. cellFormat.Width = 0;
  23415. }
  23416. }
  23417. }
  23418. #endregion
  23419. #region 设置页眉
  23420. builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
  23421. string voucherHeaderPath = $"./Images/VoucherHeader.png";
  23422. if (System.IO.File.Exists(voucherHeaderPath))
  23423. {
  23424. byte[] imageBytes = System.IO.File.ReadAllBytes(voucherHeaderPath);
  23425. //Image image = Image.FromStream(imageBytes, ImageType.Png);
  23426. //builder.InsertImage(imageBytes, RelativeHorizontalPosition.Margin, 0, RelativeVerticalPosition.Margin, 0, 81, 36, WrapType.None);
  23427. Aspose.Words.Drawing.Shape shape = builder.InsertImage(imageBytes);
  23428. // 调整图片位置
  23429. shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page; // 将图片的水平位置设置为页面
  23430. shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin; // 将图片的垂直位置设置为页眉上边距
  23431. shape.Top = 50; // 将图片距离页眉上边缘的距离
  23432. shape.Left = 0; // 将图片距离页面左边缘的距离
  23433. shape.Width = 81; // 设置图片宽度
  23434. shape.Height = 36; // 设置图片高度
  23435. }
  23436. //靠右
  23437. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  23438. //// 设置页脚上下边距
  23439. //builder.PageSetup.HeaderDistance = 42;
  23440. // 添加页眉线
  23441. Aspose.Words.Border borderHeader = null;
  23442. try
  23443. {
  23444. borderHeader = builder.ParagraphFormat.Borders.Bottom;
  23445. }
  23446. catch (Exception e)
  23447. {
  23448. // TODO Auto-generated catch block
  23449. //e.printStackTrace();
  23450. }
  23451. borderHeader.Shadow = true;
  23452. borderHeader.DistanceFromText = 2;
  23453. borderHeader.LineStyle = Aspose.Words.LineStyle.Single;
  23454. #endregion
  23455. }
  23456. catch (Exception ex)
  23457. {
  23458. }
  23459. var fileDir = AppSettingsHelper.Get("WordBasePath") + strFileName;
  23460. doc.Save(fileDir);
  23461. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/" + strFileName;
  23462. return Ok(JsonView(true, "操作成功!", Url));
  23463. }
  23464. /// <summary>
  23465. /// 酒店预订
  23466. /// 生成 预定成本 Excel
  23467. /// </summary>
  23468. /// <param name="_dto"></param>
  23469. /// <returns></returns>
  23470. [HttpPost]
  23471. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23472. public async Task<IActionResult> PostHotelReservationsPredictedCostFileDownload(HotelReservations_PCFD_DTO _dto)
  23473. {
  23474. #region 参数验证
  23475. var vadalitor = new HotelReservations_PCFD_DTOFoalidator();
  23476. var vadalitorRes = await vadalitor.ValidateAsync(_dto);
  23477. if (!vadalitorRes.IsValid)
  23478. {
  23479. var errors = new StringBuilder();
  23480. foreach (var valid in vadalitorRes.Errors) errors.AppendLine(valid.ErrorMessage);
  23481. return Ok(JsonView(StatusCodes.Status400BadRequest, errors.ToString(), ""));
  23482. }
  23483. #region 团组操作权限验证 76 酒店预定模块
  23484. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  23485. if (groupAuthView.Code != 0) return Ok(JsonView(false, groupAuthView.Msg));
  23486. #endregion
  23487. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  23488. #region 页面操作权限验证
  23489. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  23490. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  23491. #endregion
  23492. #endregion
  23493. decimal _rate = 1.00M;
  23494. string _currency = string.Empty;
  23495. var currDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 66).ToList();
  23496. var hrDtas = _sqlSugar.Queryable<Grp_HotelReservations>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  23497. if (hrDtas.Count < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "酒店预订费用未录入,不支持预定成本Excel导出", ""));
  23498. var hotelSubData = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).ToList();
  23499. var ccpData = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(it => it.IsDel == 0 && it.DIId == _dto.DiId && it.CTable == 76).ToList();
  23500. var _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(it => it.IsDel == 0 && it.DiId == _dto.DiId).First();
  23501. //if (_GroupCostParameter == null) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用未录入,不支持预定成本Excel导出", ""));
  23502. if (_GroupCostParameter == null)
  23503. {
  23504. //return Ok(JsonView(StatusCodes.Status400BadRequest, "团组成本费用“币种为录入”未录入,不支持预定成本Excel导出", ""));
  23505. bool isIntType = int.TryParse(_currency, out int currId);
  23506. if (isIntType)
  23507. {
  23508. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  23509. }
  23510. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  23511. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  23512. if (currInfo == null)
  23513. {
  23514. //return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  23515. }
  23516. else _rate = currInfo.Rate;
  23517. if (!string.IsNullOrEmpty(_currency) && !_currency.ToUpper().Equals("CNY"))
  23518. {
  23519. _rate = _GroupCostParameter.Rate;
  23520. }
  23521. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  23522. //string strFileName = "HotelStatement/";
  23523. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  23524. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  23525. var rateDatas = new List<dynamic>();
  23526. #region 数据处理
  23527. foreach (var item in hrDtas)
  23528. {
  23529. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  23530. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  23531. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  23532. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  23533. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  23534. if (ccpInfo == null || roomInfo == null || breakfastInfo == null || governmentRentInfo == null || cityTaxInfo == null)
  23535. {
  23536. continue;
  23537. }
  23538. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  23539. if (string.IsNullOrEmpty(_currency)) _currency = $"CNY";
  23540. string singleRoomFeeStr = string.Empty,
  23541. doubleRoomFeeStr = string.Empty,
  23542. suiteRoomFeeStr = string.Empty,
  23543. otherRoomFeeStr = string.Empty,
  23544. payMoneyStr = string.Empty,
  23545. cardPriceStr = string.Empty;
  23546. if (roomCurr.Equals("CNY"))
  23547. {
  23548. rateDatas.Add(new { code = "CNY", rate = 1.0000 });
  23549. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23550. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23551. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23552. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23553. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? ""}";
  23554. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {currDatas.Find(it => it.Id == item.CardPriceCurrency)?.Name ?? ""}";
  23555. }
  23556. else
  23557. {
  23558. //singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23559. //doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23560. //suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23561. //otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23562. //payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  23563. //cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  23564. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23565. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23566. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23567. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}\r\n{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}";
  23568. rateDatas.Add(new { code = roomCurr, rate = roomInfo.Rate });
  23569. var ccpPaymentCurrency = currDatas.Find(it => it.Id == ccpInfo?.PaymentCurrency)?.Name ?? "";
  23570. if (ccpPaymentCurrency.Equals("CNY"))
  23571. {
  23572. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} CNY";
  23573. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  23574. }
  23575. else
  23576. {
  23577. rateDatas.Add(new { code = ccpPaymentCurrency, rate = ccpInfo.DayRate });
  23578. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {ccpPaymentCurrency}\r\n{((ccpInfo.PayMoney * ccpInfo.DayRate) / _rate).ToString("#0.00")} CNY";
  23579. }
  23580. var hotelcardPriceCurrency = currDatas.Find(it => it.Id == item?.CardPriceCurrency)?.Name ?? "";
  23581. if (hotelcardPriceCurrency.Equals("CNY"))
  23582. {
  23583. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} CNY";
  23584. }
  23585. else
  23586. {
  23587. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {hotelcardPriceCurrency}\r\n{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} CNY";
  23588. }
  23589. }
  23590. string breakfastPriceStr = string.Empty,
  23591. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  23592. governmentRentStr = string.Empty,
  23593. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  23594. cityTaxStr = string.Empty,
  23595. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  23596. var breakfastCurrency1 = currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name;
  23597. if (!string.IsNullOrEmpty(breakfastCurrency1))
  23598. {
  23599. if (breakfastCurrency1.Equals("CNY"))
  23600. {
  23601. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  23602. }
  23603. else
  23604. {
  23605. rateDatas.Add(new { code = breakfastCurrency1, rate = breakfastInfo.Rate });
  23606. var breakfastPriceCny = breakfastInfo.Price * breakfastInfo.Rate;
  23607. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}\r\n{breakfastPriceCny.ToString("#0.00")} CNY";
  23608. }
  23609. }
  23610. else breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {breakfastCurrency1}";
  23611. var governmentRentCurrency1 = currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name;
  23612. if (!string.IsNullOrEmpty(governmentRentCurrency1))
  23613. {
  23614. if (governmentRentCurrency.Equals("CNY"))
  23615. {
  23616. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  23617. }
  23618. else
  23619. {
  23620. rateDatas.Add(new { code = governmentRentCurrency1, rate = governmentRentInfo.Rate });
  23621. var governmentRentCny = governmentRentInfo.Price * governmentRentInfo.Rate;
  23622. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}\r\n{governmentRentCny.ToString("#0.00")} CNY";
  23623. }
  23624. }
  23625. else governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {governmentRentCurrency1}";
  23626. var cityTaxStrCurrency1 = currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name;
  23627. if (!string.IsNullOrEmpty(cityTaxStrCurrency1))
  23628. {
  23629. if (cityTaxStrCurrency1.Equals("CNY"))
  23630. {
  23631. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  23632. }
  23633. else
  23634. {
  23635. rateDatas.Add(new { code = cityTaxStrCurrency1, rate = cityTaxInfo.Rate });
  23636. var cityTaxCny = cityTaxInfo.Price * cityTaxInfo.Rate;
  23637. cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}\r\n{cityTaxCny.ToString("#0.00")} CNY";
  23638. }
  23639. }
  23640. else cityTaxStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {cityTaxStrCurrency1}";
  23641. int payDId = roomInfo?.PayDId ?? 0;
  23642. pcfds.Add(new HotelReservations_PCFD_View()
  23643. {
  23644. City = item.City,
  23645. HotelName = item.HotelName,
  23646. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  23647. // SingleRoomCount = item.SingleRoomCount,
  23648. SingleRoomPrice = singleRoomFeeStr,
  23649. // DoubleRoomCount = item.DoubleRoomCount,
  23650. DoubleRoomPrice = doubleRoomFeeStr,
  23651. //SuiteRoomCount = item.SuiteRoomCount,
  23652. SuiteRoomPrice = suiteRoomFeeStr,
  23653. OtherRoomPrice = otherRoomFeeStr,
  23654. //OtherRoomCount = item.OtherRoomCount,
  23655. BreakfastPrice = breakfastPriceStr,
  23656. GovernmentRent = governmentRentStr,
  23657. CityTax = cityTaxStr,
  23658. RoomExplanation = item.RoomExplanation,
  23659. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  23660. PayTime = roomInfo?.ConsumptionDate,
  23661. BankNo = roomInfo?.BankNo,
  23662. PayMoney = payMoneyStr,
  23663. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  23664. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  23665. CardPrice = cardPriceStr,
  23666. Remark = ccpInfo.Remark
  23667. });
  23668. }
  23669. #endregion
  23670. //载入模板
  23671. WorkbookDesigner designer = new WorkbookDesigner();
  23672. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  23673. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  23674. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  23675. designer.SetDataSource("TourNo", groupInfo.TourCode);
  23676. var rateDatas1 = rateDatas.Distinct();
  23677. var rateStr = string.Empty;
  23678. foreach (var item in rateDatas1)
  23679. {
  23680. rateStr += $"{item.code} {item.rate.ToString("#0.0000")} \t\t";
  23681. }
  23682. designer.SetDataSource("TeamName", $"酒店模块汇率:{rateStr}");
  23683. designer.SetDataSource("Opertor", userInfo.CnName);
  23684. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  23685. dt.TableName = "ViewMyHotelReservations";
  23686. designer.SetDataSource(dt);
  23687. designer.Process();
  23688. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  23689. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  23690. designer.Workbook.Save(serverPath);
  23691. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  23692. #region 删除指定行
  23693. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  23694. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  23695. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  23696. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  23697. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  23698. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  23699. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  23700. cssIndex = dt.Columns["CityTax"].Ordinal,
  23701. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  23702. remarkIndex = dt.Columns["Remark"].Ordinal;
  23703. //删除指定列
  23704. foreach (DataRow item in dt.Rows)
  23705. {
  23706. string singleStr = item["SingleRoomPrice"].ToString();
  23707. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  23708. if (containsDigitButNotZero1) singleDel = false;
  23709. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  23710. string doubleStr = item["DoubleRoomPrice"].ToString();
  23711. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23712. if (containsDigitButNotZero2) doubleDel = false;
  23713. string suiteStr = item["SuiteRoomPrice"].ToString();
  23714. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23715. if (containsDigitButNotZero3) suiteDel = false;
  23716. string otherStr = item["OtherRoomPrice"].ToString();
  23717. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  23718. if (containsDigitButNotZero4) otherDel = false;
  23719. string zcStr = item["BreakfastPrice"].ToString();
  23720. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  23721. if (containsDigitButNotZero5) zcDel = false;
  23722. string dsStr = item["GovernmentRent"].ToString();
  23723. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  23724. if (containsDigitButNotZero6) dsDel = false;
  23725. string cssStr = item["CityTax"].ToString();
  23726. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  23727. if (containsDigitButNotZero7) cssDel = false;
  23728. string cpStr = item["ConsumptionPatterns"].ToString();
  23729. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  23730. string remarkStr = item["Remark"].ToString();
  23731. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  23732. }
  23733. DeleteColumn(serverPath, remarkIndex, remarkDel);
  23734. DeleteColumn(serverPath, cpIndex, cpDel);
  23735. DeleteColumn(serverPath, dsIndex, dsDel);
  23736. DeleteColumn(serverPath, cssIndex, cssDel);
  23737. DeleteColumn(serverPath, zcIndex, zcDel);
  23738. DeleteColumn(serverPath, otherIndex, otherDel);
  23739. DeleteColumn(serverPath, suiteIndex, suiteDel);
  23740. DeleteColumn(serverPath, doubleIndex, doubleDel);
  23741. DeleteColumn(serverPath, singleIndex, singleDel);
  23742. #endregion
  23743. //只保留第一个表格
  23744. DeleteSheet(serverPath);
  23745. return Ok(JsonView(true, "操作成功", url = rst));
  23746. }
  23747. else
  23748. {
  23749. _currency = _GroupCostParameter.Currency;
  23750. bool isIntType = int.TryParse(_currency, out int currId);
  23751. if (isIntType)
  23752. {
  23753. _currency = currDatas.Find(it => it.Id == currId)?.Name ?? "";
  23754. }
  23755. var teamRate = await _teamRateRep.PostGroupTeamRateItemByDiIdAndCTableId(1, _dto.DiId, 76);
  23756. var currInfo = teamRate.Find(it => it.CurrencyCode.Equals(_currency));
  23757. if (currInfo == null)
  23758. {
  23759. return Ok(JsonView(StatusCodes.Status400BadRequest, $"团组汇率-->酒店模块 {_currency} 币种未设置汇率,不支持预定成本Excel导出", ""));
  23760. }
  23761. if (!_currency.ToUpper().Equals("CNY"))
  23762. {
  23763. _rate = _GroupCostParameter.Rate;
  23764. }
  23765. _rate = currInfo.Rate;
  23766. hrDtas = hrDtas.OrderBy(it => it.CheckInDate).ToList();
  23767. //string strFileName = "HotelStatement/";
  23768. //string guestNames = ""; //格式Mr.xxx Ms.xxx
  23769. List<HotelReservations_PCFD_View> pcfds = new List<HotelReservations_PCFD_View>();
  23770. #region 数据处理
  23771. foreach (var item in hrDtas)
  23772. {
  23773. var ccpInfo = ccpData.Where(it => it.DIId == _dto.DiId && it.CId == item.Id).First();
  23774. var roomInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 1).FirstOrDefault(); //房费
  23775. var breakfastInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 2).FirstOrDefault(); //早餐
  23776. var governmentRentInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 3).FirstOrDefault(); //地税
  23777. var cityTaxInfo = hotelSubData.Where(it => it.HrId == item.Id && it.PriceType == 4).FirstOrDefault(); //城市税
  23778. string roomCurr = currDatas.Find(it => it.Id == roomInfo?.Currency)?.Name ?? "";
  23779. string singleRoomFeeStr = string.Empty,
  23780. doubleRoomFeeStr = string.Empty,
  23781. suiteRoomFeeStr = string.Empty,
  23782. otherRoomFeeStr = string.Empty,
  23783. payMoneyStr = string.Empty,
  23784. cardPriceStr = string.Empty;
  23785. if (roomCurr.Equals(_currency))
  23786. {
  23787. singleRoomFeeStr = $"{item.SingleRoomPrice.ToString("#0.00")} {_currency}";
  23788. doubleRoomFeeStr = $"{item.DoubleRoomPrice.ToString("#0.00")} {_currency}";
  23789. suiteRoomFeeStr = $"{item.SuiteRoomPrice.ToString("#0.00")} {_currency}";
  23790. otherRoomFeeStr = $"{item.OtherRoomPrice.ToString("#0.00")} {_currency}";
  23791. payMoneyStr = $"{ccpInfo.PayMoney.ToString("#0.00")} {_currency}";
  23792. cardPriceStr = $"{item.CardPrice.ToString("#0.00")} {_currency}";
  23793. }
  23794. else
  23795. {
  23796. singleRoomFeeStr = $"{((item.SingleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SingleRoomPrice.ToString("#0.00")} {roomCurr}";
  23797. doubleRoomFeeStr = $"{((item.DoubleRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.DoubleRoomPrice.ToString("#0.00")} {roomCurr}";
  23798. suiteRoomFeeStr = $"{((item.SuiteRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.SuiteRoomPrice.ToString("#0.00")} {roomCurr}";
  23799. otherRoomFeeStr = $"{((item.OtherRoomPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.OtherRoomPrice.ToString("#0.00")} {roomCurr}";
  23800. payMoneyStr = $"{((ccpInfo.PayMoney * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{ccpInfo.PayMoney.ToString("#0.00")} {roomCurr}";
  23801. cardPriceStr = $"{((item.CardPrice * roomInfo.Rate) / _rate).ToString("#0.00")} {_currency}\r\n{item.CardPrice.ToString("#0.00")} {roomCurr}";
  23802. }
  23803. string breakfastPriceStr = string.Empty,
  23804. breakfastCurrency = currDatas.Find(it => it.Id == item.BreakfastCurrency)?.Name ?? "",
  23805. governmentRentStr = string.Empty,
  23806. governmentRentCurrency = currDatas.Find(it => it.Id == item.GovernmentRentCurrency)?.Name ?? "",
  23807. cityTaxStrStr = string.Empty,
  23808. cityTaxStrCurrency = currDatas.Find(it => it.Id == item.CityTaxCurrency)?.Name ?? "";
  23809. breakfastPriceStr = $"{breakfastInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == breakfastInfo?.Currency)?.Name}";
  23810. governmentRentStr = $"{governmentRentInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == governmentRentInfo?.Currency)?.Name}";
  23811. cityTaxStrStr = $"{cityTaxInfo?.Price.ToString("#0.00")} {currDatas.Find(it => it.Id == cityTaxInfo?.Currency)?.Name}";
  23812. int payDId = roomInfo?.PayDId ?? 0;
  23813. pcfds.Add(new HotelReservations_PCFD_View()
  23814. {
  23815. City = item.City,
  23816. HotelName = item.HotelName,
  23817. Date = $"{item.CheckInDate} - {item.CheckOutDate}",
  23818. // SingleRoomCount = item.SingleRoomCount,
  23819. SingleRoomPrice = singleRoomFeeStr,
  23820. // DoubleRoomCount = item.DoubleRoomCount,
  23821. DoubleRoomPrice = doubleRoomFeeStr,
  23822. //SuiteRoomCount = item.SuiteRoomCount,
  23823. SuiteRoomPrice = suiteRoomFeeStr,
  23824. OtherRoomPrice = otherRoomFeeStr,
  23825. //OtherRoomCount = item.OtherRoomCount,
  23826. BreakfastPrice = breakfastPriceStr,
  23827. GovernmentRent = governmentRentStr,
  23828. CityTax = cityTaxStrStr,
  23829. RoomExplanation = item.RoomExplanation,
  23830. PayTypeName = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.Id == payDId).First()?.Name ?? "",
  23831. PayTime = roomInfo?.ConsumptionDate,
  23832. BankNo = roomInfo?.BankNo,
  23833. PayMoney = payMoneyStr,
  23834. //PayMoneys = ccpInfo.PayMoney.ToString("#0.00"),
  23835. ConsumptionPatterns = roomInfo?.ConsumptionPatterns,
  23836. CardPrice = cardPriceStr,
  23837. Remark = ccpInfo.Remark
  23838. });
  23839. }
  23840. #endregion
  23841. //载入模板
  23842. WorkbookDesigner designer = new WorkbookDesigner();
  23843. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/酒店预订成本.xls");
  23844. var groupInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == _dto.DiId).First();
  23845. var userInfo = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == hrDtas[0].CreateUserId).First();
  23846. designer.SetDataSource("TourNo", groupInfo.TourCode);
  23847. designer.SetDataSource("TeamName", $"{groupInfo.TeamName} 团组成本币种:{_currency} 团组汇率-->酒店模块汇率:{_rate.ToString("#0.0000")}");
  23848. designer.SetDataSource("Opertor", userInfo.CnName);
  23849. DataTable dt = CommonFun.GetDataTableFromIList<HotelReservations_PCFD_View>(pcfds);
  23850. dt.TableName = "ViewMyHotelReservations";
  23851. designer.SetDataSource(dt);
  23852. designer.Process();
  23853. string fileName = $"HotelReservation/{groupInfo.TeamName.Replace("/", "").Replace(@"\", "").Trim()}_酒店预订成本_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
  23854. string serverPath = AppSettingsHelper.Get("ExcelBasePath") + fileName;
  23855. designer.Workbook.Save(serverPath);
  23856. string rst = AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  23857. #region 删除指定行
  23858. bool singleDel = true, doubleDel = true, suiteDel = true, otherDel = true, zcDel = true, dsDel = true, cssDel = true, cpDel = true, remarkDel = true;
  23859. int singleIndex = dt.Columns["SingleRoomPrice"].Ordinal,
  23860. doubleIndex = dt.Columns["DoubleRoomPrice"].Ordinal,
  23861. suiteIndex = dt.Columns["SuiteRoomPrice"].Ordinal,
  23862. otherIndex = dt.Columns["OtherRoomPrice"].Ordinal,
  23863. zcIndex = dt.Columns["BreakfastPrice"].Ordinal,
  23864. dsIndex = dt.Columns["GovernmentRent"].Ordinal,
  23865. cssIndex = dt.Columns["CityTax"].Ordinal,
  23866. cpIndex = dt.Columns["ConsumptionPatterns"].Ordinal,
  23867. remarkIndex = dt.Columns["Remark"].Ordinal;
  23868. //删除指定列
  23869. foreach (DataRow item in dt.Rows)
  23870. {
  23871. string singleStr = item["SingleRoomPrice"].ToString();
  23872. bool containsDigitButNotZero1 = !singleStr.StartsWith("0") && Regex.IsMatch(singleStr, @"[1-9]");
  23873. if (containsDigitButNotZero1) singleDel = false;
  23874. singleIndex = dt.Columns["SingleRoomPrice"].Ordinal;
  23875. string doubleStr = item["DoubleRoomPrice"].ToString();
  23876. bool containsDigitButNotZero2 = !doubleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23877. if (containsDigitButNotZero2) doubleDel = false;
  23878. string suiteStr = item["SuiteRoomPrice"].ToString();
  23879. bool containsDigitButNotZero3 = !singleStr.StartsWith("0") && Regex.IsMatch(doubleStr, @"[1-9]");
  23880. if (containsDigitButNotZero3) suiteDel = false;
  23881. string otherStr = item["OtherRoomPrice"].ToString();
  23882. bool containsDigitButNotZero4 = !otherStr.StartsWith("0") && Regex.IsMatch(otherStr, @"[1-9]");
  23883. if (containsDigitButNotZero4) otherDel = false;
  23884. string zcStr = item["BreakfastPrice"].ToString();
  23885. bool containsDigitButNotZero5 = !zcStr.StartsWith("0") && Regex.IsMatch(zcStr, @"[1-9]");
  23886. if (containsDigitButNotZero5) zcDel = false;
  23887. string dsStr = item["GovernmentRent"].ToString();
  23888. bool containsDigitButNotZero6 = !dsStr.StartsWith("0") && Regex.IsMatch(dsStr, @"[1-9]");
  23889. if (containsDigitButNotZero6) dsDel = false;
  23890. string cssStr = item["CityTax"].ToString();
  23891. bool containsDigitButNotZero7 = !cssStr.StartsWith("0") && Regex.IsMatch(cssStr, @"[1-9]");
  23892. if (containsDigitButNotZero7) cssDel = false;
  23893. string cpStr = item["ConsumptionPatterns"].ToString();
  23894. if (!string.IsNullOrEmpty(cpStr)) cpDel = false;
  23895. string remarkStr = item["Remark"].ToString();
  23896. if (!string.IsNullOrEmpty(remarkStr)) remarkDel = false;
  23897. }
  23898. DeleteColumn(serverPath, remarkIndex, remarkDel);
  23899. DeleteColumn(serverPath, cpIndex, cpDel);
  23900. DeleteColumn(serverPath, dsIndex, dsDel);
  23901. DeleteColumn(serverPath, cssIndex, cssDel);
  23902. DeleteColumn(serverPath, zcIndex, zcDel);
  23903. DeleteColumn(serverPath, otherIndex, otherDel);
  23904. DeleteColumn(serverPath, suiteIndex, suiteDel);
  23905. DeleteColumn(serverPath, doubleIndex, doubleDel);
  23906. DeleteColumn(serverPath, singleIndex, singleDel);
  23907. #endregion
  23908. //只保留第一个表格
  23909. DeleteSheet(serverPath);
  23910. return Ok(JsonView(true, "操作成功", url = rst));
  23911. }
  23912. //return Ok(JsonView(false));
  23913. }
  23914. /// <summary>
  23915. /// 删除指定列
  23916. /// </summary>
  23917. /// <param name="file"></param>
  23918. /// <param name="columnIndex"></param>
  23919. /// <param name="isDel"></param>
  23920. private void DeleteColumn(string file, int columnIndex, bool isDel)
  23921. {
  23922. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  23923. //wb.Save(file);
  23924. Aspose.Cells.Worksheet sheet1 = wb.Worksheets[0];
  23925. if (sheet1 != null)
  23926. {
  23927. if (isDel)
  23928. {
  23929. Cells cells = sheet1.Cells;
  23930. cells.DeleteColumn(columnIndex);
  23931. }
  23932. }
  23933. wb.Save(file);
  23934. }
  23935. /// <summary>
  23936. /// 删除sheet
  23937. /// </summary>
  23938. /// <param name="file"></param>
  23939. private void DeleteSheet(string file)
  23940. {
  23941. Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(file);
  23942. //wb.Save(file);
  23943. List<string> sheets = new List<string>();
  23944. foreach (var item in wb.Worksheets)
  23945. {
  23946. sheets.Add(item.Name);
  23947. }
  23948. if (sheets.Count > 0)
  23949. {
  23950. sheets.RemoveAt(0);//不删除第一个sheet
  23951. foreach (var item in sheets)
  23952. {
  23953. wb.Worksheets.RemoveAt(item);
  23954. }
  23955. }
  23956. wb.Save(file);
  23957. }
  23958. /// <summary>
  23959. /// 酒店预订
  23960. /// 确认单
  23961. /// </summary>
  23962. /// <param name="_dto"></param>
  23963. /// <returns></returns>
  23964. [HttpPost]
  23965. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  23966. public async Task<IActionResult> PostHotelReservationsConfirmationSlip(HotelReservationsConfirmationSlipDto _dto)
  23967. {
  23968. try
  23969. {
  23970. #region 参数验证
  23971. if (_dto.UserId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "员工Id为空", ""));
  23972. if (_dto.PageId < 1) _dto.PageId = 28; //酒店预定Id
  23973. if (_dto.DiId < 1) return Ok(JsonView(StatusCodes.Status400BadRequest, "团组Id为空", ""));
  23974. #region 团组操作权限验证 76 酒店预定模块
  23975. var groupAuthView = await GeneralMethod.PostGroupOperationAuth(_dto.DiId, _dto.UserId, 76);
  23976. if (groupAuthView.Code != 0) return Ok(JsonView(StatusCodes.Status400BadRequest, groupAuthView.Msg, ""));
  23977. #endregion
  23978. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  23979. #region 页面操作权限验证
  23980. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  23981. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  23982. #endregion
  23983. #endregion
  23984. //团组信息
  23985. Grp_DelegationInfo di = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == _dto.DiId);
  23986. //酒店数据
  23987. List<Grp_HotelReservations> listhoteldata = await _sqlSugar.Queryable<Grp_HotelReservations>().Where(a => a.DiId == _dto.DiId && a.IsDel == 0).ToListAsync();
  23988. if (listhoteldata.Count < 0)
  23989. {
  23990. return Ok(JsonView(StatusCodes.Status400BadRequest, "当前团组暂无酒店预订信息!", ""));
  23991. }
  23992. //利datatable存储
  23993. DataTable dt = new DataTable();
  23994. dt.Columns.Add("CheckInDate", typeof(string));
  23995. dt.Columns.Add("City", typeof(string));
  23996. dt.Columns.Add("Hotel", typeof(string));
  23997. dt.Columns.Add("Room", typeof(string));
  23998. for (int i = 0; i < listhoteldata.Count; i++)
  23999. {
  24000. DateTime dayStart = Convert.ToDateTime(listhoteldata[i].CheckInDate);
  24001. DateTime dayEnd = Convert.ToDateTime(listhoteldata[i].CheckOutDate);
  24002. while (dayStart < dayEnd)
  24003. {
  24004. string temp = "";
  24005. DataRow row = dt.NewRow();
  24006. row["CheckInDate"] = dayStart.ToString("yyyy-MM-dd");
  24007. row["City"] = listhoteldata[i].City;
  24008. row["Hotel"] = listhoteldata[i].HotelName;
  24009. if (listhoteldata[i].SingleRoomCount > 0)
  24010. {
  24011. temp = listhoteldata[i].SingleRoomCount + "个单间" + "\r\n";
  24012. }
  24013. if (listhoteldata[i].DoubleRoomCount > 0)
  24014. {
  24015. temp = temp + listhoteldata[i].DoubleRoomCount + "个标间" + "\r\n";
  24016. }
  24017. if (listhoteldata[i].SuiteRoomCount > 0)
  24018. {
  24019. temp = temp + listhoteldata[i].SuiteRoomCount + "个套房" + "\r\n";
  24020. }
  24021. if (listhoteldata[i].OtherRoomCount > 0)
  24022. {
  24023. temp = temp + listhoteldata[i].OtherRoomCount + "个其他房型" + "\r\n";
  24024. }
  24025. row["Room"] = temp;
  24026. dt.Rows.Add(row);
  24027. dayStart = dayStart.AddDays(1);
  24028. }
  24029. }
  24030. Dictionary<string, string> dic = new Dictionary<string, string>();
  24031. dic.Add("Dele", di.TeamName);
  24032. dic.Add("City", di.VisitCountry);
  24033. //模板路径
  24034. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/酒店用房确认单-模板.doc";
  24035. //载入模板
  24036. Aspose.Words.Document doc = new Aspose.Words.Document(tempPath);
  24037. DocumentBuilder builder = new DocumentBuilder(doc);
  24038. foreach (var key in dic.Keys)
  24039. {
  24040. builder.MoveToBookmark(key);
  24041. builder.Write(dic[key]);
  24042. }
  24043. //获取word里所有表格
  24044. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  24045. //获取所填表格的序数
  24046. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  24047. var rowStart = tableOne.Rows[0]; //获取第1行
  24048. //循环赋值
  24049. for (int i = 0; i < dt.Rows.Count; i++)
  24050. {
  24051. builder.MoveToCell(0, i + 1, 0, 0);
  24052. builder.Write(dt.Rows[i]["CheckInDate"].ToString());
  24053. builder.MoveToCell(0, i + 1, 1, 0);
  24054. builder.Write(dt.Rows[i]["City"].ToString());
  24055. builder.MoveToCell(0, i + 1, 2, 0);
  24056. builder.Write(dt.Rows[i]["Hotel"].ToString());
  24057. builder.MoveToCell(0, i + 1, 3, 0);
  24058. builder.Write(dt.Rows[i]["Room"].ToString());
  24059. }
  24060. //删除多余行
  24061. while (tableOne.Rows.Count > dt.Rows.Count + 1)
  24062. {
  24063. tableOne.Rows.RemoveAt(dt.Rows.Count + 1);
  24064. }
  24065. string strFileName = di.TeamName + "酒店确认单.doc";
  24066. doc.Save(AppSettingsHelper.Get("WordBasePath") + "HotelStatement/" + strFileName);
  24067. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/HotelStatement/" + strFileName;
  24068. return Ok(JsonView(true, "成功", url));
  24069. }
  24070. catch (Exception ex)
  24071. {
  24072. return Ok(JsonView(StatusCodes.Status400BadRequest, ex.Message, ""));
  24073. }
  24074. }
  24075. #endregion
  24076. #region 团组状态
  24077. /// <summary>
  24078. /// 团组状态列表 Page
  24079. /// </summary>
  24080. /// <param name="dto">团组列表请求dto</param>
  24081. /// <returns></returns>
  24082. [HttpPost]
  24083. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24084. public async Task<IActionResult> PostGroupStatusPageList(GroupStatusListDto dto)
  24085. {
  24086. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  24087. if (dto.PortType == 1 || dto.PortType == 2) // web/Android
  24088. {
  24089. string sqlWhere = string.Empty;
  24090. if (dto.IsSure == 0) //未完成
  24091. {
  24092. sqlWhere += string.Format(@" And IsSure = 0");
  24093. }
  24094. else if (dto.IsSure == 1) //已完成
  24095. {
  24096. sqlWhere += string.Format(@" And IsSure = 1");
  24097. }
  24098. if (!string.IsNullOrEmpty(dto.SearchCriteria))
  24099. {
  24100. string tj = dto.SearchCriteria;
  24101. 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}%')",
  24102. tj, tj, tj, tj, tj);
  24103. }
  24104. string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  24105. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  24106. VisitDate,VisitDays,VisitPNumber,JietuanOperator,IsSure,CreateTime
  24107. From (
  24108. Select row_number() over(order by gdi.VisitStartDate Desc) as Row_Number,
  24109. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  24110. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  24111. VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime
  24112. From Grp_DelegationInfo gdi
  24113. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  24114. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  24115. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  24116. Where gdi.IsDel = 0 {0}
  24117. ) temp ", sqlWhere);
  24118. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  24119. var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatusView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  24120. return Ok(JsonView(true, "查询成功!", _DelegationList, total));
  24121. }
  24122. else
  24123. {
  24124. return Ok(JsonView(false, "查询失败"));
  24125. }
  24126. }
  24127. /// <summary>
  24128. /// 团组状态
  24129. /// 设置操作完成
  24130. /// </summary>
  24131. /// <param name="dto">团组列表请求dto</param>
  24132. /// <returns></returns>
  24133. [HttpPost]
  24134. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24135. public async Task<IActionResult> PostGroupStatusSetOperationComplete(GroupStatusSetOperationCompleteDto dto)
  24136. {
  24137. if (dto == null) return Ok(JsonView(false, "请输入搜索条件!"));
  24138. Grp_DelegationInfo _DelegationInfo = new Grp_DelegationInfo()
  24139. {
  24140. Id = dto.Id,
  24141. IsSure = 1
  24142. };
  24143. var result = await _sqlSugar.Updateable(_DelegationInfo)
  24144. .UpdateColumns(it => new { it.IsSure })
  24145. .WhereColumns(it => new { it.Id })
  24146. .ExecuteCommandAsync();
  24147. if (result > 0)
  24148. {
  24149. return Ok(JsonView(true, "操作完成!"));
  24150. }
  24151. return Ok(JsonView(false, "操作失败!"));
  24152. }
  24153. #endregion
  24154. #region 保险费用录入
  24155. /// <summary>
  24156. /// 根据团组Id查询保险费用列表
  24157. /// </summary>
  24158. /// <param name="dto"></param>
  24159. /// <returns></returns>
  24160. [HttpPost]
  24161. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24162. public async Task<IActionResult> CustomersByDiId(CustomersByDiIdDto dto)
  24163. {
  24164. Result groupData = await _customersRep.CustomersByDiId(dto);
  24165. if (groupData.Code != 0)
  24166. {
  24167. return Ok(JsonView(false, groupData.Msg));
  24168. }
  24169. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24170. }
  24171. /// <summary>
  24172. /// 根据保险费用Id查询保险费用详细
  24173. /// </summary>
  24174. /// <param name="dto"></param>
  24175. /// <returns></returns>
  24176. [HttpPost]
  24177. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24178. public async Task<IActionResult> CustomersById(CustomersByIdDto dto)
  24179. {
  24180. try
  24181. {
  24182. Result groupData = await _customersRep.CustomersById(dto);
  24183. if (groupData.Code != 0)
  24184. {
  24185. return Ok(JsonView(false, groupData.Msg));
  24186. }
  24187. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24188. }
  24189. catch (Exception ex)
  24190. {
  24191. return Ok(JsonView(false, ex.Message));
  24192. }
  24193. }
  24194. /// <summary>
  24195. /// 保险费用录入页面初始化绑定
  24196. /// </summary>
  24197. /// <param name="dto"></param>
  24198. /// <returns></returns>
  24199. [HttpPost]
  24200. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24201. public async Task<IActionResult> CustomersInitialize(CustomersInitializeDto dto)
  24202. {
  24203. try
  24204. {
  24205. Result groupData = await _customersRep.CustomersInitialize(dto);
  24206. if (groupData.Code != 0)
  24207. {
  24208. return Ok(JsonView(false, groupData.Msg));
  24209. }
  24210. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24211. }
  24212. catch (Exception ex)
  24213. {
  24214. return Ok(JsonView(false, ex.Message));
  24215. }
  24216. }
  24217. /// <summary>
  24218. /// 保险费用操作(Status:1.新增,2.修改)
  24219. /// </summary>
  24220. /// <param name="dto"></param>
  24221. /// <returns></returns>
  24222. [HttpPost]
  24223. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24224. public async Task<IActionResult> OpCustomers(OpCustomersDto dto)
  24225. {
  24226. //验证
  24227. if (dto.Status == 2)
  24228. {
  24229. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  24230. if (!valid) return Ok(JsonView(false, msg));
  24231. }
  24232. Result groupData = await _customersRep.OpCustomers(dto);
  24233. if (groupData.Code != 0)
  24234. {
  24235. return Ok(JsonView(false, groupData.Msg));
  24236. }
  24237. #region 应用推送
  24238. try
  24239. {
  24240. int ccpId = groupData.Data.GetType().GetProperty("ccpId").GetValue(groupData.Data, null);
  24241. int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
  24242. int dataId = groupData.Data.GetType().GetProperty("dataId").GetValue(groupData.Data, null);
  24243. await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
  24244. //自动审核
  24245. await _feeAuditRep.FeeAutomaticAudit(4, dto.DiId, dataId);
  24246. //2024-10-21 新增LZ UID
  24247. var userIds = new List<int>() { 21 };
  24248. string title = $"系统通知";
  24249. var diId = dto.DiId;
  24250. var groupInfo = await _groupRepository.Query(x => x.Id == diId).FirstAsync();
  24251. var ccpInfo = await _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.Id == ccpId).FirstAsync();
  24252. string content = "";
  24253. if (dto.Status == 1) content = $"[新增-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  24254. else if (dto.Status == 2) content = $"[更新-保险费用录入({groupInfo?.TeamName ?? "-"})]一项费用:{(ccpInfo.PayMoney * ccpInfo.DayRate).ToString("#0.00")} CNY;";
  24255. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.GroupBusinessOperations, title, content, userIds, diId);
  24256. PageParam_PriceAuditH5 h5 = new PageParam_PriceAuditH5() { diid = diId.ToString(), uid = "21", itemId = "82" };
  24257. await APNsTools.iOS_PushNotifications1("051", "保险费用审核", "", content, true, "ExpenseAuditWebView", h5);
  24258. }
  24259. catch (Exception ex)
  24260. {
  24261. }
  24262. #endregion
  24263. return Ok(JsonView(true, groupData.Msg, groupData.Data));
  24264. }
  24265. /// <summary>
  24266. /// 保险文件上传
  24267. /// </summary>
  24268. /// <param name="file"></param>
  24269. /// <returns></returns>
  24270. [HttpPost]
  24271. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24272. public async Task<IActionResult> UploadCus(IFormFile file)
  24273. {
  24274. try
  24275. {
  24276. if (file != null)
  24277. {
  24278. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  24279. //文件名称
  24280. string projectFileName = file.FileName;
  24281. //上传的文件的路径
  24282. string filePath = "";
  24283. if (!Directory.Exists(fileDir))
  24284. {
  24285. Directory.CreateDirectory(fileDir);
  24286. }
  24287. //上传的文件的路径
  24288. filePath = fileDir + $@"\保险费用文件上传\{projectFileName}";
  24289. using (FileStream fs = System.IO.File.Create(filePath))
  24290. {
  24291. file.CopyTo(fs);
  24292. fs.Flush();
  24293. }
  24294. return Ok(JsonView(true, "上传成功!", projectFileName));
  24295. }
  24296. else
  24297. {
  24298. return Ok(JsonView(false, "上传失败!"));
  24299. }
  24300. }
  24301. catch (Exception ex)
  24302. {
  24303. return Ok(JsonView(false, ex.Message));
  24304. }
  24305. }
  24306. /// <summary>
  24307. /// 保险删除指定文件
  24308. /// </summary>
  24309. /// <param name="dto"></param>
  24310. /// <returns></returns>
  24311. [HttpPost]
  24312. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24313. public async Task<IActionResult> DelFileCus(DelFileDto dto)
  24314. {
  24315. try
  24316. {
  24317. string filePath = "";
  24318. var fileDir = AppSettingsHelper.Get("GrpFileBasePath");
  24319. // 返回与指定虚拟路径相对应的物理路径即绝对路径
  24320. //int id = 0;
  24321. filePath = fileDir + "/保险费用文件上传/" + dto.fileName;
  24322. // 删除该文件
  24323. try
  24324. {
  24325. System.IO.File.Delete(filePath);
  24326. 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()
  24327. {
  24328. Attachment = "",
  24329. }).ExecuteCommandAsync();
  24330. if (result != 0)
  24331. {
  24332. return Ok(JsonView(true, "成功!"));
  24333. }
  24334. else
  24335. {
  24336. return Ok(JsonView(false, "失败!"));
  24337. }
  24338. }
  24339. catch (Exception)
  24340. {
  24341. 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()
  24342. {
  24343. Attachment = "",
  24344. }).ExecuteCommandAsync();
  24345. if (result != 0)
  24346. {
  24347. return Ok(JsonView(true, "成功!"));
  24348. }
  24349. else
  24350. {
  24351. return Ok(JsonView(false, "失败!"));
  24352. }
  24353. }
  24354. }
  24355. catch (Exception ex)
  24356. {
  24357. return Ok(JsonView(false, "程序错误!"));
  24358. throw;
  24359. }
  24360. }
  24361. /// <summary>
  24362. /// 保险费用操作(删除)
  24363. /// </summary>
  24364. /// <param name="dto"></param>
  24365. /// <returns></returns>
  24366. [HttpPost]
  24367. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24368. public async Task<IActionResult> DelCustomers(DelBaseDto dto)
  24369. {
  24370. try
  24371. {
  24372. //验证
  24373. (bool valid, string msg) = await GeneralMethod.FeeOpValid(dto.Id, 82);
  24374. if (!valid) return Ok(JsonView(false, msg));
  24375. var res = await _customersRep.SoftDeleteByIdAsync<Grp_Customers>(dto.Id.ToString(), dto.DeleteUserId);
  24376. if (!res)
  24377. {
  24378. return Ok(JsonView(false, "删除失败"));
  24379. }
  24380. var resultC = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.CId == dto.Id && a.IsDel == 0 && a.CTable == 82).SetColumns(a => new Grp_CreditCardPayment()
  24381. {
  24382. IsDel = 1,
  24383. DeleteUserId = dto.DeleteUserId,
  24384. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  24385. }).ExecuteCommandAsync();
  24386. return Ok(JsonView(true, "删除成功!"));
  24387. }
  24388. catch (Exception ex)
  24389. {
  24390. return Ok(JsonView(false, "程序错误!"));
  24391. }
  24392. }
  24393. #endregion
  24394. #region 接团客户名单 PageId 104
  24395. /// <summary>
  24396. /// 接团客户名单
  24397. /// 迁移数据(慎用!)
  24398. /// </summary>
  24399. /// <returns></returns>
  24400. [HttpPost]
  24401. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24402. public async Task<IActionResult> PostTourClientListChange()
  24403. {
  24404. try
  24405. {
  24406. _sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  24407. //var groupClinetData1
  24408. string sql = string.Format($"Select * From DeleClient Where Isdel = 0");
  24409. var oldOAClientList = await _sqlSugar.SqlQueryable<OA2021_DeleClient>(sql).Where(it => it.Isdel == 0).ToListAsync();
  24410. int updateCount = 0;
  24411. if (oldOAClientList.Count > 0)
  24412. {
  24413. _sqlSugar.ChangeDatabase(DBEnum.OA2023DB);
  24414. _sqlSugar.BeginTran();
  24415. var clientComInfos = _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToList();
  24416. var clientInfos = _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToList();
  24417. foreach (var item in oldOAClientList)
  24418. {
  24419. int comId = 0;
  24420. string format = "yyyy-MM-dd HH:mm:ss";
  24421. string data11 = "1990-01-01 00:00";
  24422. var data1 = IsValidDate(item.OPdate, format);
  24423. if (data1) data11 = item.OPdate;
  24424. //客户公司验证
  24425. if (!string.IsNullOrEmpty(item.Company))
  24426. {
  24427. var clientComInfo = clientComInfos.Where(it => it.CompanyFullName.Equals(item.Company)).FirstOrDefault();
  24428. if (clientComInfo == null) // add
  24429. {
  24430. var addInfo = new Crm_CustomerCompany()
  24431. {
  24432. CompanyAbbreviation = "",
  24433. CompanyFullName = item.Company,
  24434. Address = "",
  24435. PostCodes = "",
  24436. LastedOpUserId = item.OPer,
  24437. LastedOpDt = Convert.ToDateTime(data11),
  24438. CreateUserId = item.OPer,
  24439. CreateTime = Convert.ToDateTime(data11),
  24440. IsDel = 0
  24441. };
  24442. var comId1 = _sqlSugar.Insertable<Crm_CustomerCompany>(addInfo).ExecuteReturnIdentity();
  24443. if (comId1 > 0) comId = comId1;
  24444. }
  24445. else comId = clientComInfo.Id;
  24446. }
  24447. //客户人员验证
  24448. int clientId = 0;
  24449. string name = item.LastName + item.Name;
  24450. if (!string.IsNullOrEmpty(name))
  24451. {
  24452. var clientInfo = clientInfos.Where(it => (it.LastName + it.FirstName).Equals(name)).FirstOrDefault();
  24453. if (clientInfo == null)
  24454. {
  24455. DateTime? dateTime = null;
  24456. var isDt = DateTime.TryParse(item.Birthday, out DateTime birthDayDt);
  24457. if (isDt) dateTime = birthDayDt;
  24458. var addInfo1 = new Crm_DeleClient()
  24459. {
  24460. CrmCompanyId = comId,
  24461. DiId = -1,
  24462. LastName = item.LastName,
  24463. FirstName = item.Name,
  24464. OldName = "",
  24465. Pinyin = item.Pinyin,
  24466. Sex = item.Sex == "男" ? 0 : item.Sex == "女" ? 1 : -1,
  24467. Marriage = 0,
  24468. Phone = item.Phone,
  24469. Job = item.Job,
  24470. BirthDay = dateTime
  24471. };
  24472. var clientId1 = _sqlSugar.Insertable<Crm_DeleClient>(addInfo1).ExecuteReturnIdentity();
  24473. if (clientId1 > 0) clientId = clientId1;
  24474. }
  24475. else clientId = clientInfo.Id;
  24476. }
  24477. if (clientId < 1)
  24478. {
  24479. continue;
  24480. }
  24481. int airType = 0;
  24482. if (item.AirType == "超经舱") airType = 459;
  24483. else if (item.AirType == "公务舱") airType = 458;
  24484. else if (item.AirType == "经济舱") airType = 460;
  24485. else if (item.AirType == "其他") airType = 565;
  24486. else if (item.AirType == "头等舱") airType = 457;
  24487. var _TourClientListEntity = new Grp_TourClientList()
  24488. {
  24489. DiId = item.Diid,
  24490. ClientId = clientId,
  24491. CreateUserId = item.OPer,
  24492. CreateTime = Convert.ToDateTime(data11),
  24493. Remark = item.Remark,
  24494. IsDel = item.Isdel,
  24495. ShippingSpaceTypeId = airType,
  24496. ShippingSpaceSpecialNeeds = item.AirRemark,
  24497. HotelSpecialNeeds = item.RoomType
  24498. };
  24499. var _TourClientList = _sqlSugar.Insertable<Grp_TourClientList>(_TourClientListEntity).ExecuteCommand();
  24500. if (_TourClientList > 0)
  24501. {
  24502. updateCount++;
  24503. }
  24504. }
  24505. _sqlSugar.CommitTran();
  24506. }
  24507. return Ok(JsonView(true, $"更新条数:{updateCount}条"));
  24508. }
  24509. catch (Exception ex)
  24510. {
  24511. _sqlSugar.RollbackTran();
  24512. return Ok(JsonView(false, ex.Message));
  24513. }
  24514. //return Ok(JsonView(true));
  24515. }
  24516. private bool IsValidDate(string dateString, string format)
  24517. {
  24518. return DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dateValue);
  24519. }
  24520. /// <summary>
  24521. /// 接团客户名单
  24522. /// 根据团组Id查询List
  24523. /// </summary>
  24524. /// <param name="_dto"></param>
  24525. /// <returns></returns>
  24526. [HttpPost]
  24527. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24528. public async Task<IActionResult> PostTourClientListByDiId(TourClientListByDiIdDto _dto)
  24529. {
  24530. #region 参数验证
  24531. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId"));
  24532. if (_dto.PageId != 104) _dto.PageId = 104; //接团客户名单PageId
  24533. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId!"));
  24534. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24535. #region 页面操作权限验证
  24536. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24537. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24538. #endregion
  24539. #endregion
  24540. var viewData = await _tourClientListRep._ItemByDiId(_dto.PortType, _dto.DiId);
  24541. if (viewData.Code != 0)
  24542. {
  24543. return Ok(JsonView(false, viewData.Msg));
  24544. }
  24545. return Ok(JsonView(viewData.Data));
  24546. }
  24547. /// <summary>
  24548. /// 接团客户名单
  24549. /// 基础数据 Init
  24550. /// </summary>
  24551. /// <param name="_dto"></param>
  24552. /// <returns></returns>
  24553. [HttpPost]
  24554. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24555. public async Task<IActionResult> PostTourClientListBasicDataInit(TourClientListBasicDataInitDto _dto)
  24556. {
  24557. #region 参数验证
  24558. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24559. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24560. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24561. #region 页面操作权限验证
  24562. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24563. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24564. #endregion
  24565. #endregion
  24566. return Ok(await _tourClientListRep._BasicDataInit(_dto.PortType));
  24567. }
  24568. /// <summary>
  24569. /// 接团客户名单
  24570. /// 根据 Id查询 Details
  24571. /// </summary>
  24572. /// <param name="_dto"></param>
  24573. /// <returns></returns>
  24574. [HttpPost]
  24575. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24576. public async Task<IActionResult> PostTourClientListDetails(TourClientListDetailsDto _dto)
  24577. {
  24578. #region 参数验证
  24579. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24580. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24581. if (_dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  24582. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24583. #region 页面操作权限验证
  24584. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24585. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  24586. #endregion
  24587. #endregion
  24588. var viewData = await _tourClientListRep._Details(_dto.PortType, _dto.Id);
  24589. if (viewData.Code != 0)
  24590. {
  24591. return Ok(JsonView(false, viewData.Msg));
  24592. }
  24593. return Ok(JsonView(viewData.Data));
  24594. }
  24595. /// <summary>
  24596. /// 接团客户名单
  24597. /// Add Or Edit
  24598. /// </summary>
  24599. /// <param name="_dto"></param>
  24600. /// <returns></returns>
  24601. [HttpPost]
  24602. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24603. public async Task<IActionResult> PostTourClientListAddOrEdit(TourClientListAddOrEditDto _dto)
  24604. {
  24605. #region 参数验证
  24606. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24607. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24608. if (_dto.Id < 0) return Ok(JsonView(false, "请传入有效的Id参数!"));
  24609. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24610. #region 页面操作权限验证
  24611. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24612. if (_dto.Id == 0) //添加
  24613. {
  24614. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24615. }
  24616. else if (_dto.Id >= 0) //修改
  24617. {
  24618. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  24619. }
  24620. #endregion
  24621. #endregion
  24622. var viewData = await _tourClientListRep._AddOrEdit(_dto);
  24623. if (viewData.Code != 0)
  24624. {
  24625. return Ok(JsonView(false, viewData.Msg));
  24626. }
  24627. return Ok(JsonView(true));
  24628. }
  24629. /// <summary>
  24630. /// 接团客户名单
  24631. /// json字符串 AddMultiple(添加多个)
  24632. /// </summary>
  24633. /// <param name="_dto"></param>
  24634. /// <returns></returns>
  24635. [HttpPost]
  24636. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24637. public async Task<IActionResult> PostTourClientListJsonFormatAddMultiple(PostTourClientListJsonFormatAddMultipleDto _dto)
  24638. {
  24639. #region 参数验证
  24640. string jsonLabel = _dto.JsonLabel;
  24641. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24642. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24643. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24644. #region 页面操作权限验证
  24645. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24646. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24647. #endregion
  24648. #endregion
  24649. var request = new TourClientListAddMultipleDto();
  24650. request.DiId = _dto.DiId;
  24651. request.UserId = _dto.UserId;
  24652. if (!CommonFun.IsValidJson(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数不是合法的json格式!"));
  24653. if (string.IsNullOrEmpty(jsonLabel)) return Ok(JsonView(false, "JsonLabel参数值不能为空"));
  24654. List<TourClientListInfoCN> datas = JsonConvert.DeserializeObject<List<TourClientListInfoCN>>(jsonLabel);
  24655. if (!datas.Any()) return Ok(JsonView(false, "JsonLabel参数值不能为空!"));
  24656. var infos = new List<TourClientListInfo>();
  24657. foreach (var data in datas)
  24658. {
  24659. (string lastName, string firstName) = CommonFun.GetLastNameAndFirstName(data.Name);
  24660. string lastNameEn = CommonFun.ConvertToPinyin(lastName),
  24661. firstNameEn = CommonFun.ConvertToPinyin(lastName);
  24662. if (string.IsNullOrEmpty(lastNameEn) || string.IsNullOrEmpty(firstNameEn))
  24663. {
  24664. continue;
  24665. }
  24666. infos.Add(new TourClientListInfo()
  24667. {
  24668. IsAccompany = 1,
  24669. LastName = lastName,
  24670. FirstName = firstName,
  24671. Pinyin = lastNameEn + @"/" + firstNameEn,
  24672. Sex = data.Sex.Equals("男") ? 0 : data.Sex.Equals("女") ? 1 : 2,
  24673. CompanyFullName = data.CompanyFullName,
  24674. Job = data.Job
  24675. });
  24676. }
  24677. if (infos.Any())
  24678. {
  24679. var viewData = await _tourClientListRep._AddMultiple(request);
  24680. if (viewData.Code != 0)
  24681. {
  24682. return Ok(JsonView(false, viewData.Msg));
  24683. }
  24684. return Ok(JsonView(true));
  24685. }
  24686. return Ok(JsonView(false));
  24687. }
  24688. /// <summary>
  24689. /// 接团客户名单
  24690. /// AddMultiple(添加多个)
  24691. /// </summary>
  24692. /// <param name="_dto"></param>
  24693. /// <returns></returns>
  24694. [HttpPost]
  24695. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24696. public async Task<IActionResult> PostTourClientListAddMultiple(TourClientListAddMultipleDto _dto)
  24697. {
  24698. #region 参数验证
  24699. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24700. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24701. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24702. #region 页面操作权限验证
  24703. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24704. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  24705. #endregion
  24706. #endregion
  24707. var viewData = await _tourClientListRep._AddMultiple(_dto);
  24708. if (viewData.Code != 0)
  24709. {
  24710. return Ok(JsonView(false, viewData.Msg));
  24711. }
  24712. return Ok(JsonView(true));
  24713. }
  24714. /// <summary>
  24715. /// 接团客户名单
  24716. /// Del
  24717. /// </summary>
  24718. /// <param name="_dto"></param>
  24719. /// <returns></returns>
  24720. [HttpPost]
  24721. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24722. public async Task<IActionResult> PostTourClientListDel(TourClientListDelDto _dto)
  24723. {
  24724. #region 参数验证
  24725. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24726. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24727. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24728. #region 页面操作权限验证
  24729. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24730. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  24731. #endregion
  24732. #endregion
  24733. var viewData = await _tourClientListRep._Del(_dto.Id, _dto.UserId);
  24734. if (viewData.Code != 0)
  24735. {
  24736. return Ok(JsonView(false, viewData.Msg));
  24737. }
  24738. return Ok(JsonView(true));
  24739. }
  24740. /// <summary>
  24741. /// 接团客户名单
  24742. /// 文件下载 客户名单
  24743. /// </summary>
  24744. /// <param name="_dto"></param>
  24745. /// <returns></returns>
  24746. [HttpPost]
  24747. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  24748. public async Task<IActionResult> PostTourClientListDownloadFile(PostTourClientListDownloadFile _dto)
  24749. {
  24750. #region 参数验证
  24751. if (_dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数"));
  24752. if (_dto.PageId < 1) _dto.PageId = 104; //接团客户名单PageId
  24753. if (_dto.DiId < 1) return Ok(JsonView(false, "请传入有效的DiId参数"));
  24754. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  24755. #region 页面操作权限验证
  24756. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
  24757. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
  24758. #endregion
  24759. #endregion
  24760. string clientSql = string.Format(@"Select tcl.Id,tcl.DiId,temp.*,tcl.ShippingSpaceTypeId,tcl.ShippingSpaceSpecialNeeds,
  24761. tcl.HotelSpecialNeeds,tcl.MealSpecialNeeds,tcl.Remark
  24762. From Grp_TourClientList tcl
  24763. Left Join
  24764. (Select dc.Id As DcId,dc.LastName,dc.FirstName,dc.Pinyin,dc.Sex,ccom.CompanyFullName,dc.Job,
  24765. cc1.CertNo As IDCardNo,dc.Phone,dc.BirthDay,cc2.PassportType,cc2.CertNo As PassportNo,cc2.Country,
  24766. cc2.Area,cc2.IssueDt,cc2.ExpiryDt
  24767. From Crm_DeleClient dc
  24768. Left Join Crm_CustomerCompany ccom On dc.CrmCompanyId = ccom.Id And ccom.IsDel = 0
  24769. Left Join Crm_CustomerCert cc1 On dc.Id = cc1.DcId And cc1.SdId = 773 And cc1.IsDel = 0
  24770. Left Join Crm_CustomerCert cc2 On dc.Id = cc2.DcId And cc2.SdId = 774 And cc2.IsDel = 0
  24771. Where dc.IsDel = 0) temp
  24772. On temp.DcId =tcl.ClientId
  24773. Where tcl.IsDel = 0 And tcl.DiId = {0}", _dto.DiId);
  24774. List<TourClientListDetailsView> DcList = await _sqlSugar.SqlQueryable<TourClientListDetailsView>(clientSql).ToListAsync();
  24775. if (DcList.Count < 0) return Ok(JsonView(false, "该团未录入客户名单!"));
  24776. //载入模板
  24777. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/dwon_团组人员列表模板.doc";
  24778. if (_dto.Language == 1)
  24779. {
  24780. tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/EN_Down_团组人员列表模板.doc";
  24781. }
  24782. //载入模板
  24783. var doc = new Document(tempPath);
  24784. DocumentBuilder builder = new DocumentBuilder(doc);
  24785. //获取word里所有表格
  24786. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  24787. //获取所填表格的序数
  24788. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  24789. var rowStart = tableOne.Rows[0]; //获取第1行
  24790. if (_dto.Language == 0)
  24791. {
  24792. //循环赋值
  24793. for (int i = 0; i < DcList.Count; i++)
  24794. {
  24795. EncryptionProcessor.DecryptProperties(DcList[i]);
  24796. builder.MoveToCell(0, i + 1, 0, 0);
  24797. builder.Write(DcList[i].LastName + DcList[i].FirstName);
  24798. builder.MoveToCell(0, i + 1, 1, 0);
  24799. int sex = DcList[i].Sex;
  24800. string sexStr = string.Empty;
  24801. if (sex == 0) sexStr = "男";
  24802. else if (sex == 1) sexStr = "女";
  24803. else sexStr = "未设置";
  24804. builder.Write(sexStr);
  24805. builder.MoveToCell(0, i + 1, 2, 0);
  24806. string birthDay = DcList[i].BirthDay;
  24807. string birthDayStr = string.Empty;
  24808. if (!string.IsNullOrEmpty(birthDay))
  24809. {
  24810. birthDayStr = Convert.ToDateTime(birthDay).ToString("yyyy-MM-dd");
  24811. }
  24812. builder.Write(birthDayStr);
  24813. builder.MoveToCell(0, i + 1, 3, 0);
  24814. string company = "";
  24815. if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  24816. {
  24817. company = DcList[i].CompanyFullName.ToString();
  24818. }
  24819. builder.Write(company);
  24820. builder.MoveToCell(0, i + 1, 4, 0);
  24821. builder.Write(DcList[i].Job);
  24822. }
  24823. }
  24824. else if (_dto.Language == 1)
  24825. {
  24826. List<Res_PositionEnglishComparison> listPEC = _setDataRep.Query<Res_PositionEnglishComparison>(s => s.IsDel == 0).ToList();
  24827. List<Res_CompanyEnglishComparison> listCEC = _setDataRep.Query<Res_CompanyEnglishComparison>(s => s.IsDel == 0).ToList();
  24828. List<string> transArrayStr = new List<string>();
  24829. string transStrRes1 = "";
  24830. var clientEnglishs = new List<ClientEnglishView>();
  24831. for (int i = 0; i < DcList.Count; i++)
  24832. {
  24833. var dc = DcList[i];
  24834. EncryptionProcessor.DecryptProperties(dc);
  24835. if (dc.CompanyFullName.Equals("暂无")) dc.CompanyFullName = "-";
  24836. if (dc.Job.Equals("暂无")) dc.Job = "-";
  24837. string str1 = $"{i}&{dc.CompanyFullName}&{dc.Job}";
  24838. if (DcList.Count - 1 == i) transStrRes1 += str1;
  24839. else transStrRes1 += $"{str1}|";
  24840. clientEnglishs.Add(new()
  24841. {
  24842. Id = dc.Id,
  24843. LastName = dc.LastName,
  24844. FirstName = dc.FirstName,
  24845. Pinyin = dc.Pinyin,
  24846. Sex = dc.Sex,
  24847. CompanyFullName = dc.CompanyFullName,
  24848. Job = dc.Job,
  24849. IDCardNo = dc.IDCardNo,
  24850. BirthDay = dc.BirthDay,
  24851. });
  24852. }
  24853. #region AI转英文
  24854. string jsonValue = JsonConvert.SerializeObject(clientEnglishs);
  24855. string text = @"将此JSON的中文部分全部翻译为英文,然后只给出修改后的JSON数据,不要其他任何文字";
  24856. List<SeedMessages> messages = new List<SeedMessages>()
  24857. {
  24858. new SeedMessages
  24859. {
  24860. Role = KimiRole.user,
  24861. Content = jsonValue + text
  24862. }
  24863. };
  24864. KiMiApiClient client = new KiMiApiClient();
  24865. var kimiApiResult = await client.SeedMessage(messages);
  24866. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  24867. string clients = kimiApiResult_JObject["content"].ToString();
  24868. string startStr = "```json", endStr = "```";
  24869. // 判断并清除开头部分
  24870. if (clients.StartsWith(startStr))
  24871. {
  24872. clients = clients.Remove(0, startStr.Length);
  24873. }
  24874. // 判断并清除结尾部分
  24875. if (clients.EndsWith(endStr))
  24876. {
  24877. clients = clients.Remove(clients.Length - endStr.Length);
  24878. }
  24879. var en_Json = JsonConvert.DeserializeObject<List<ClientEnglishView>>(clients);
  24880. //循环赋值
  24881. for (int i = 0; i < en_Json.Count; i++)
  24882. {
  24883. var dc = en_Json[i];
  24884. var dc1 = DcList.Find(x => x.Id == dc.Id);
  24885. string PYName = dc.FirstName + " " + dc.LastName;
  24886. builder.MoveToCell(0, i + 1, 0, 0);
  24887. builder.Write(PYName);
  24888. string sex = dc.Sex == 0 ? "Male" : dc.Sex == 1 ? "Female" : "";
  24889. builder.MoveToCell(0, i + 1, 1, 0);
  24890. builder.Write(sex);
  24891. DateTime birthDt;
  24892. bool b_birth = DateTime.TryParse(dc.BirthDay, out birthDt);
  24893. string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  24894. builder.MoveToCell(0, i + 1, 2, 0);
  24895. builder.Write(birthday);
  24896. string company = string.Empty, job = string.Empty;
  24897. company = dc.CompanyFullName;
  24898. job = dc.Job;
  24899. if (dc1 != null && !string.IsNullOrEmpty(dc1.CompanyFullName))
  24900. {
  24901. //查询对照表
  24902. Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(dc1.CompanyFullName.ToString().Trim()));
  24903. if (tempCec != null)
  24904. {
  24905. company = tempCec.enName;
  24906. }
  24907. }
  24908. builder.MoveToCell(0, i + 1, 3, 0);
  24909. builder.Write(company);
  24910. if (dc1 != null && !string.IsNullOrEmpty(dc1.Job))
  24911. {
  24912. //查询对照表
  24913. Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == dc1.Job.ToString().Trim());
  24914. if (tempPec != null)
  24915. {
  24916. job = tempPec.enName;
  24917. }
  24918. }
  24919. builder.MoveToCell(0, i + 1, 4, 0);
  24920. builder.Write(job);
  24921. }
  24922. #endregion
  24923. #region 旧翻译英文处理
  24924. ////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";
  24925. //string transStrRes = "";
  24926. //if (transStrRes1.Length > 0)
  24927. //{
  24928. // transStrRes = await _juHeApi.GetTextTranslateAsync(transStrRes1);
  24929. //}
  24930. ////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
  24931. ////await _juHeApi.GetTextTranslateAsync(DcList[i].CompanyFullName.ToString().Trim()) ?? "";
  24932. ////List<string> transArray = new List<string> { };
  24933. //List<TranslateInfo> transArray = new List<TranslateInfo>();
  24934. //if (transStrRes.Contains("|"))
  24935. //{
  24936. // string[] transArray1 = transStrRes.Split('|');
  24937. // if (transArray1.Length > 0)
  24938. // {
  24939. // foreach (var item in transArray1)
  24940. // {
  24941. // if (item.Contains("&"))
  24942. // {
  24943. // string[] transArray2 = item.Split('&');
  24944. // int index = 0;
  24945. // string companyName = "", job = "";
  24946. // if (transArray2.Length > 0)
  24947. // {
  24948. // bool success = int.TryParse(transArray2[0].Trim(), out index);
  24949. // if (1 < transArray2.Length) companyName = transArray2[1];
  24950. // if (2 < transArray2.Length) job = transArray2[2];
  24951. // }
  24952. // transArray.Add(new TranslateInfo { Index = index, CompanyName = companyName, Job = job });
  24953. // }
  24954. // }
  24955. // }
  24956. //}
  24957. ////循环赋值
  24958. //for (int i = 0; i < DcList.Count; i++)
  24959. //{
  24960. // string PYName = "";
  24961. // if (DcList[i].Pinyin.Length > 0 && DcList[i].Pinyin.IndexOf('/') > -1)
  24962. // {
  24963. // string PY_Last = DcList[i].Pinyin.Split('/')[0];
  24964. // string PY_First = DcList[i].Pinyin.Split('/')[1];
  24965. // PYName = PY_First + " " + PY_Last;
  24966. // }
  24967. // else
  24968. // {
  24969. // string PY_Last = DcList[i].LastName.GetTotalPingYin().Count > 0 ? DcList[i].LastName.GetTotalPingYin()[0].ToUpper() : "";
  24970. // string PY_First = DcList[i].FirstName.GetTotalPingYin().Count > 0 ? DcList[i].FirstName.GetTotalPingYin()[0].ToUpper() : "";
  24971. // PYName = PY_First + " " + PY_Last;
  24972. // }
  24973. // builder.MoveToCell(0, i + 1, 0, 0);
  24974. // builder.Write(PYName);
  24975. // string sex = DcList[i].Sex == 0 ? "Male" : DcList[i].Sex == 1 ? "Female" : "";
  24976. // builder.MoveToCell(0, i + 1, 1, 0);
  24977. // builder.Write(sex);
  24978. // DateTime birthDt;
  24979. // bool b_birth = DateTime.TryParse(DcList[i].BirthDay, out birthDt);
  24980. // string birthday = b_birth ? birthDt.ToString("yyyy-MM-dd") : " ";
  24981. // builder.MoveToCell(0, i + 1, 2, 0);
  24982. // builder.Write(birthday);
  24983. // string company = string.Empty, job = string.Empty;
  24984. // var dcTransInfo = transArray.FirstOrDefault(s => s.Index == i);
  24985. // if (dcTransInfo != null)
  24986. // {
  24987. // company = dcTransInfo.CompanyName;
  24988. // job = dcTransInfo.Job;
  24989. // }
  24990. // if (!string.IsNullOrEmpty(DcList[i].CompanyFullName))
  24991. // {
  24992. // //查询对照表
  24993. // Res_CompanyEnglishComparison tempCec = listCEC.FirstOrDefault(s => s.zhName.Contains(DcList[i].CompanyFullName.ToString().Trim()));
  24994. // if (tempCec != null)
  24995. // {
  24996. // company = tempCec.enName;
  24997. // }
  24998. // //翻译
  24999. // else
  25000. // {
  25001. // }
  25002. // }
  25003. // builder.MoveToCell(0, i + 1, 3, 0);
  25004. // builder.Write(company);
  25005. // if (!string.IsNullOrEmpty(DcList[i].Job.ToString()))
  25006. // {
  25007. // //查询对照表
  25008. // Res_PositionEnglishComparison tempPec = listPEC.FirstOrDefault(s => s.zhName == DcList[i].Job.ToString().Trim());
  25009. // if (tempPec != null)
  25010. // {
  25011. // job = tempPec.enName;
  25012. // }
  25013. // //翻译
  25014. // else
  25015. // {
  25016. // }
  25017. // }
  25018. // builder.MoveToCell(0, i + 1, 4, 0);
  25019. // builder.Write(job);
  25020. //}
  25021. #endregion
  25022. }
  25023. //删除多余行
  25024. while (tableOne.Rows.Count > DcList.Count + 1)
  25025. {
  25026. tableOne.Rows.RemoveAt(DcList.Count + 1);
  25027. }
  25028. string fileName = "组团人员名单(" + DateTime.Now.ToString("yyyyhhddHHmmss") + ").doc";
  25029. var fileDir = AppSettingsHelper.Get("WordBasePath") + "TourClientList/" + fileName;
  25030. doc.Save(fileDir);
  25031. string Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/TourClientList/" + fileName;
  25032. return Ok(JsonView(true, "操作成功!", Url));
  25033. }
  25034. private class TranslateInfo
  25035. {
  25036. public int Index { get; set; }
  25037. public string CompanyName { get; set; }
  25038. public string Job { get; set; }
  25039. }
  25040. [HttpPost]
  25041. public async Task<IActionResult> FileReadClient(List<IFormFile> files)
  25042. {
  25043. if (files.Count == 0)
  25044. {
  25045. return Ok(JsonView(false, "文件为空"));
  25046. }
  25047. KiMiApiClient KiMiApi = new KiMiApiClient();
  25048. var seedConter = await KiMiApi.UploadFilesAsync(files);
  25049. if (seedConter.Count == 0)
  25050. {
  25051. return Ok(JsonView(false, "上传结果为空!"));
  25052. }
  25053. var messages = new List<SeedMessages>
  25054. {
  25055. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  25056. new SeedMessages { Role = KimiRole.user, Content = "根据文件内容 ,按照“姓、名、姓名拼音、性别、单位、职务、出生日期”的json格式来排列整理(性别和出生日期通过身份证来识别 , 当识别到性别为男时值给0女给1 未识别到性别的情况下值给-1,出生日期按照yyyy-MM-dd来整理(若出生日期没有值则为‘-’),文件存在拼音的情况读取对应的拼音不存在则设置拼音为中文名字全拼),只输出JSON数组数据 从'['开始 到']'结尾 ,不要除JSON数据外的任何文字以及符号" }
  25057. };
  25058. messages.InsertRange(1, seedConter);
  25059. var kimiApiResult = await KiMiApi.SeedMessage(messages);
  25060. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  25061. string clients = kimiApiResult_JObject["content"].ToString();
  25062. string startStr = "```json", endStr = "```";
  25063. // 判断并清除开头部分
  25064. if (clients.StartsWith(startStr))
  25065. {
  25066. clients = clients.Remove(0, startStr.Length);
  25067. }
  25068. // 判断并清除结尾部分
  25069. if (clients.EndsWith(endStr))
  25070. {
  25071. clients = clients.Remove(clients.Length - endStr.Length);
  25072. }
  25073. var clients_JObject = JsonConvert.DeserializeObject<List<JObject>>(clients);
  25074. Dictionary<string, string> clientFieldMap = new Dictionary<string, string>()
  25075. {
  25076. {"姓", "LastName" },
  25077. {"名", "FirstName" },
  25078. {"姓名拼音", "Pinyin" },
  25079. {"性别", "Sex" },
  25080. {"单位", "CompanyFullName" },
  25081. {"职务", "Job" },
  25082. {"出生日期", "Birthday" },
  25083. };
  25084. List<BaiduClientOCRView> crmClients = new List<BaiduClientOCRView>();
  25085. foreach (var item in clients_JObject)
  25086. {
  25087. BaiduClientOCRView cdc = new BaiduClientOCRView();
  25088. foreach (var field in clientFieldMap.Keys)
  25089. {
  25090. if (item.TryGetValue(field, out JToken value))
  25091. {
  25092. var getValue = value.ToString();
  25093. System.Type type = cdc.GetType();
  25094. PropertyInfo propertyInfo = type.GetProperty(clientFieldMap[field]);
  25095. var propertyValue = Convert.ChangeType(getValue, propertyInfo.PropertyType);
  25096. propertyInfo.SetValue(cdc, propertyValue);
  25097. }
  25098. }
  25099. crmClients.Add(cdc);
  25100. }
  25101. return Ok(JsonView(new
  25102. {
  25103. fileCount = files.Count,
  25104. UploadCount = seedConter.Count,
  25105. ApiResult = clients,
  25106. CrmClients = crmClients
  25107. }));
  25108. }
  25109. #endregion
  25110. #region 团组倒推表
  25111. /// <summary>
  25112. /// 倒推表基础数据
  25113. /// Init
  25114. /// </summary>
  25115. /// <returns></returns>
  25116. [HttpPost]
  25117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25118. public async Task<IActionResult> PostInvertedListInit()
  25119. {
  25120. var viewData = await _invertedListRep.Init();
  25121. if (viewData.Code != 0)
  25122. {
  25123. return Ok(JsonView(false, viewData.Msg));
  25124. }
  25125. return Ok(JsonView(viewData.Data));
  25126. }
  25127. /// <summary>
  25128. /// 倒推表
  25129. /// Info
  25130. /// </summary>
  25131. /// <param name="dto"></param>
  25132. /// <returns></returns>
  25133. [HttpPost]
  25134. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25135. public async Task<IActionResult> PostInvertedListInfo(InvertedListCreateDto dto)
  25136. {
  25137. var viewData = await _invertedListRep.Info(dto.PortType, dto.DiId);
  25138. if (viewData.Code != 0)
  25139. {
  25140. return Ok(JsonView(false, viewData.Msg));
  25141. }
  25142. return Ok(JsonView(viewData.Data));
  25143. }
  25144. /// <summary>
  25145. /// 倒推表
  25146. /// Create
  25147. /// </summary>
  25148. /// <param name="dto"></param>
  25149. /// <returns></returns>
  25150. [HttpPost]
  25151. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25152. public async Task<IActionResult> PostInvertedListCreate(InvertedListCreateDto dto)
  25153. {
  25154. var viewData = await _invertedListRep.Create(dto.PortType, dto.DiId);
  25155. if (viewData.Code != 0)
  25156. {
  25157. return Ok(JsonView(false, viewData.Msg));
  25158. }
  25159. return Ok(JsonView(viewData.Data));
  25160. }
  25161. /// <summary>
  25162. /// 倒推表
  25163. /// Update
  25164. /// </summary>
  25165. /// <param name="dto"></param>
  25166. /// <returns></returns>
  25167. [HttpPost]
  25168. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25169. public async Task<IActionResult> PostInvertedListUpdate(InvertedListUpdateDto dto)
  25170. {
  25171. var viewData = await _invertedListRep.Update(dto);
  25172. if (viewData.Code != 0)
  25173. {
  25174. return Ok(JsonView(false, viewData.Msg));
  25175. }
  25176. return Ok(JsonView(viewData.Data));
  25177. }
  25178. /// <summary>
  25179. /// 倒推表
  25180. /// File Download
  25181. /// </summary>
  25182. /// <param name="dto"></param>
  25183. /// <returns></returns>
  25184. [HttpPost]
  25185. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25186. public async Task<IActionResult> PostInvertedListFileDownload(InvertedListFileDownloadDto dto)
  25187. {
  25188. var info2 = await _invertedListRep.Info(1, dto.DiId);
  25189. if (info2.Code != 0)
  25190. {
  25191. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  25192. }
  25193. var info1 = info2.Data as InvertedListInfoView;
  25194. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  25195. string teamName = "";
  25196. if (info != null) teamName = info.TeamName;
  25197. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  25198. var doc = new Document();
  25199. var builder = new DocumentBuilder(doc);
  25200. #region old insert
  25201. ////载入模板
  25202. //var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20200617.doc";
  25203. //Document doc = new Document(tempPath);
  25204. //DocumentBuilder builder = new DocumentBuilder(doc);
  25205. //利用键值对存放数据
  25206. //Dictionary<string, string> dic = new Dictionary<string, string>();
  25207. //dic.Add("TeamName", teamName);
  25208. //dic.Add("StartTime", info1.AirportdDropOffDt.ConvertToDatetime()); //开始时间
  25209. //dic.Add("BPtime", info1.ApprovalDataDt.ConvertToDatetime());
  25210. //dic.Add("BPRemark", info1.ApprovalDataRemark);
  25211. //dic.Add("SQtime", info1.ApprovalDt.ConvertToDatetime());
  25212. //dic.Add("SQRemark", info1.ApprovalRemark);
  25213. //dic.Add("CPJtime", info1.IssueApprovalDt.ConvertToDatetime());
  25214. //dic.Add("CPJRemark", info1.IssueApprovalRemark);
  25215. ////dic.Add("HZtime", info1.ApplyPassportDt.ConvertToDatetime());
  25216. ////dic.Add("HZRemark", info1.ApplyPassportRemark);
  25217. //dic.Add("QZtime", info1.VisaInformationDt.ConvertToDatetime());
  25218. //dic.Add("QZRemark", info1.VisaInformationRemark);
  25219. //dic.Add("SQQZtime", info1.SendVisaDt.ConvertToDatetime());
  25220. //dic.Add("SQQZRemark", info1.SendVisaRemark);
  25221. //dic.Add("CQtime", info1.IssueVisaDt.ConvertToDatetime());
  25222. //dic.Add("CQRemark", info1.IssueVisaRemark);
  25223. //dic.Add("XQHtime", info1.PreTripMeetingDt.ConvertToDatetime());
  25224. //dic.Add("XQHRemark", info1.PreTripMeetingRemark);
  25225. //dic.Add("SJtime", info1.AirportdDropOffDt.ConvertToDatetime());
  25226. //dic.Add("SJRemark", info1.AirportdDropOffRemark);
  25227. //#region 填充word模板书签内容
  25228. //foreach (var key in dic.Keys)
  25229. //{
  25230. // builder.MoveToBookmark(key);
  25231. // builder.Write(dic[key]);
  25232. //}
  25233. //#endregion
  25234. #endregion
  25235. #region New Insert
  25236. string titleFont = $"仿宋",
  25237. contentFont = $"仿宋";
  25238. var fontColor = Color.FromArgb(64, 64, 64);
  25239. //设置标题 团组名称
  25240. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25241. builder.Font.Name = titleFont;
  25242. builder.Font.Color = fontColor;
  25243. builder.Font.Size = 12;
  25244. builder.Font.Bold = true;
  25245. builder.Writeln(teamName);
  25246. //设置副标题 团组出访时间
  25247. builder.Font.Size = 12;
  25248. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  25249. builder.Writeln();
  25250. var backgroundColor = Color.FromArgb(199, 199, 199);
  25251. var table = builder.StartTable();
  25252. builder.InsertCell();
  25253. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  25254. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  25255. builder.CellFormat.Borders.LineWidth = 1;
  25256. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  25257. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  25258. builder.RowFormat.Height = 40;
  25259. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25260. builder.Font.Name = contentFont;
  25261. builder.Font.Size = 12;
  25262. builder.Font.Bold = true;
  25263. builder.Font.Color = fontColor;
  25264. builder.Write("时间");
  25265. builder.InsertCell();
  25266. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  25267. builder.Write("流程");
  25268. builder.InsertCell();
  25269. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  25270. builder.Write("说明");
  25271. builder.EndRow();
  25272. //报批资料准备
  25273. if (info1.IsSelectedAirportd)
  25274. {
  25275. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  25276. }
  25277. //报批/提供送签资料
  25278. if (info1.IsSelectedApprovalData)
  25279. {
  25280. InvertedListFileDownloadSetRow(builder, contentFont, info1.ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  25281. }
  25282. //出批件护照办理
  25283. if (info1.IsSelectedIssueApproval)
  25284. {
  25285. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  25286. }
  25287. //签证资料准备
  25288. if (info1.IsSelectedVisaInfo)
  25289. {
  25290. InvertedListFileDownloadSetRow(builder, contentFont, info1.VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  25291. }
  25292. //送签
  25293. if (info1.IsSelectedSendVisa)
  25294. {
  25295. InvertedListFileDownloadSetRow(builder, contentFont, info1.SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  25296. }
  25297. //出签
  25298. if (info1.IsSelectedIssueVisa)
  25299. {
  25300. InvertedListFileDownloadSetRow(builder, contentFont, info1.IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  25301. }
  25302. //机票
  25303. if (info1.IsSelectedAirTicket)
  25304. {
  25305. if (string.IsNullOrEmpty(info1.AirTicketDt)) info1.AirTicketDt = info1.IssueVisaDt;
  25306. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  25307. }
  25308. //酒店
  25309. if (info1.IsSelectedHotel)
  25310. {
  25311. if (string.IsNullOrEmpty(info1.HotelDt)) info1.HotelDt = info1.IssueVisaDt;
  25312. InvertedListFileDownloadSetRow(builder, contentFont, info1.HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  25313. }
  25314. //开行前会
  25315. if (info1.IsSelectedPreTripMeeting)
  25316. {
  25317. InvertedListFileDownloadSetRow(builder, contentFont, info1.PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  25318. }
  25319. //送机
  25320. if (info1.IsSelectedAirportdDropOff)
  25321. {
  25322. InvertedListFileDownloadSetRow(builder, contentFont, info1.AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  25323. }
  25324. builder.EndTable();
  25325. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  25326. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  25327. for (int i = 0; i < table.Rows.Count; i++)
  25328. {
  25329. var row = table.Rows[i];
  25330. //设置宽度
  25331. row.Cells[0].CellFormat.Width = 20.00;
  25332. row.Cells[1].CellFormat.Width = 30.00;
  25333. row.Cells[2].CellFormat.Width = 50.00;
  25334. if (i != 0)
  25335. {
  25336. //边框设置
  25337. InvertedListFileDownloadSetBorders(row.Cells, 0);
  25338. InvertedListFileDownloadSetBorders(row.Cells, 1);
  25339. InvertedListFileDownloadSetBorders(row.Cells, 2);
  25340. }
  25341. }
  25342. #region 页脚插入图片
  25343. // 创建页脚
  25344. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  25345. doc.FirstSection.HeadersFooters.Add(footer);
  25346. Paragraph para = new Paragraph(doc);
  25347. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  25348. footer.AppendChild(para);
  25349. builder.MoveTo(para);
  25350. string imagePath = "./Images/FMGJ_Log.png";
  25351. builder.InsertImage(imagePath);
  25352. #endregion
  25353. #endregion
  25354. var fileDir = AppSettingsHelper.Get("WordBasePath");
  25355. string fileName = $"{teamName}团出行准备流程表{CommonFun.GUID}.doc";
  25356. string filePath = fileDir + $@"InvertedList/{fileName}";
  25357. doc.Save(filePath);
  25358. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  25359. return Ok(JsonView(true, "操作成功!", Url));
  25360. }
  25361. /// <summary>
  25362. /// 倒推表
  25363. /// File Download
  25364. /// 客户版
  25365. /// </summary>
  25366. /// <param name="dto"></param>
  25367. /// <returns></returns>
  25368. [HttpPost]
  25369. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25370. public async Task<IActionResult> PostInvertedListClientFileDownload(InvertedListFileDownloadDto dto)
  25371. {
  25372. var info2 = await _invertedListRep.Info(1, dto.DiId);
  25373. if (info2.Code != 0)
  25374. {
  25375. return Ok(JsonView(false, "倒推表数据未生成,请先生成倒退表数据!"));
  25376. }
  25377. var info1 = info2.Data as InvertedListInfoView;
  25378. var info = await _invertedListRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).FirstAsync();
  25379. string teamName = "";
  25380. if (info != null) teamName = info.TeamName;
  25381. var tempPath = $"{AppSettingsHelper.Get("WordBasePath")}Template/倒退表模板20250121.doc";
  25382. var doc = new Document();
  25383. var builder = new DocumentBuilder(doc);
  25384. #region New Insert
  25385. string titleFont = $"仿宋",
  25386. contentFont = $"仿宋";
  25387. var fontColor = Color.FromArgb(64, 64, 64);
  25388. //设置标题 团组名称
  25389. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25390. builder.Font.Name = titleFont;
  25391. builder.Font.Color = fontColor;
  25392. builder.Font.Size = 12;
  25393. builder.Font.Bold = true;
  25394. builder.Writeln(teamName);
  25395. //设置副标题 团组出访时间
  25396. builder.Font.Size = 12;
  25397. builder.Writeln("出发时间:" + info1.AirportdDropOffDt.ConvertToDatetime());
  25398. builder.Writeln();
  25399. var backgroundColor = Color.FromArgb(199, 199, 199);
  25400. var table = builder.StartTable();
  25401. builder.InsertCell();
  25402. builder.CellFormat.Shading.BackgroundPatternColor = backgroundColor;
  25403. builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
  25404. builder.CellFormat.Borders.LineWidth = 1;
  25405. builder.CellFormat.Borders.Color = Color.FromArgb(183, 183, 183);
  25406. table.FirstRow.FirstCell.CellFormat.Width = 20; // 单位为百分比
  25407. builder.RowFormat.Height = 40;
  25408. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25409. builder.Font.Name = contentFont;
  25410. builder.Font.Size = 12;
  25411. builder.Font.Bold = true;
  25412. builder.Font.Color = fontColor;
  25413. builder.Write("时间");
  25414. builder.InsertCell();
  25415. table.FirstRow.FirstCell.CellFormat.Width = 30; // 单位为百分比
  25416. builder.Write("流程");
  25417. builder.InsertCell();
  25418. table.FirstRow.FirstCell.CellFormat.Width = 50; // 单位为百分比
  25419. builder.Write("说明");
  25420. builder.EndRow();
  25421. //报批资料准备
  25422. if (info1.IsSelectedAirportd)
  25423. {
  25424. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDataDt.ConvertToDatetime(), "报批资料准备", info1.ApprovalDataRemark);
  25425. }
  25426. //报批/提供送签资料
  25427. if (info1.IsSelectedApprovalData)
  25428. {
  25429. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_ApprovalDt.ConvertToDatetime(), "报批/提供送签资料", info1.ApprovalRemark);
  25430. }
  25431. //出批件护照办理
  25432. if (info1.IsSelectedIssueApproval)
  25433. {
  25434. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueApprovalDt.ConvertToDatetime(), "出批件\r\n护照办理", info1.IssueApprovalRemark);
  25435. }
  25436. //签证资料准备
  25437. if (info1.IsSelectedVisaInfo)
  25438. {
  25439. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_VisaInformationDt.ConvertToDatetime(), "签证资料准备", info1.VisaInformationRemark);
  25440. }
  25441. //送签
  25442. if (info1.IsSelectedSendVisa)
  25443. {
  25444. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_SendVisaDt.ConvertToDatetime(), "送签", info1.SendVisaRemark);
  25445. }
  25446. //出签
  25447. if (info1.IsSelectedIssueVisa)
  25448. {
  25449. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_IssueVisaDt.ConvertToDatetime(), "出签", info1.IssueVisaRemark);
  25450. }
  25451. //机票
  25452. if (info1.IsSelectedAirTicket)
  25453. {
  25454. if (string.IsNullOrEmpty(info1.Client_AirTicketDt)) info1.Client_AirTicketDt = info1.Client_IssueVisaDt;
  25455. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirTicketDt.ConvertToDatetime(), "机票", info1.AirTicketRemark);
  25456. }
  25457. //酒店
  25458. if (info1.IsSelectedHotel)
  25459. {
  25460. if (string.IsNullOrEmpty(info1.Client_HotelDt)) info1.Client_HotelDt = info1.Client_IssueVisaDt;
  25461. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_HotelDt.ConvertToDatetime(), "酒店", info1.HotelRemark);
  25462. }
  25463. //开行前会
  25464. if (info1.IsSelectedPreTripMeeting)
  25465. {
  25466. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_PreTripMeetingDt.ConvertToDatetime(), "开行前会", info1.PreTripMeetingRemark);
  25467. }
  25468. //送机
  25469. if (info1.IsSelectedAirportdDropOff)
  25470. {
  25471. InvertedListFileDownloadSetRow(builder, contentFont, info1.Client_AirportdDropOffDt.ConvertToDatetime(), "送机", info1.AirportdDropOffRemark);
  25472. }
  25473. builder.EndTable();
  25474. //table.PreferredWidth = PreferredWidth.FromPercent(100.00);
  25475. //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
  25476. for (int i = 0; i < table.Rows.Count; i++)
  25477. {
  25478. var row = table.Rows[i];
  25479. //设置宽度
  25480. row.Cells[0].CellFormat.Width = 20.00;
  25481. row.Cells[1].CellFormat.Width = 30.00;
  25482. row.Cells[2].CellFormat.Width = 50.00;
  25483. if (i != 0)
  25484. {
  25485. //边框设置
  25486. InvertedListFileDownloadSetBorders(row.Cells, 0);
  25487. InvertedListFileDownloadSetBorders(row.Cells, 1);
  25488. InvertedListFileDownloadSetBorders(row.Cells, 2);
  25489. }
  25490. }
  25491. #region 页脚插入图片
  25492. // 创建页脚
  25493. Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, HeaderFooterType.FooterPrimary);
  25494. doc.FirstSection.HeadersFooters.Add(footer);
  25495. Paragraph para = new Paragraph(doc);
  25496. para.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  25497. footer.AppendChild(para);
  25498. builder.MoveTo(para);
  25499. string imagePath = "./Images/FMGJ_Log.png";
  25500. builder.InsertImage(imagePath);
  25501. #endregion
  25502. #endregion
  25503. var fileDir = AppSettingsHelper.Get("WordBasePath");
  25504. string fileName = $"{teamName}团出行准备流程表(客户版){CommonFun.GUID}.doc";
  25505. string filePath = fileDir + $@"InvertedList/{fileName}";
  25506. doc.Save(filePath);
  25507. string Url = $@"{AppSettingsHelper.Get("WordBaseUrl")}Office/Word/InvertedList/{fileName}";
  25508. return Ok(JsonView(true, "操作成功!", Url));
  25509. }
  25510. private void InvertedListFileDownloadSetRow(DocumentBuilder builder, string fontName, string dateTime, string content, string reamrk)
  25511. {
  25512. var fontColor = Color.FromArgb(64, 64, 64);
  25513. builder.InsertCell();
  25514. builder.CellFormat.Shading.BackgroundPatternColor = Color.Empty;
  25515. builder.RowFormat.Height = 40;
  25516. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25517. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  25518. builder.Font.Name = fontName;
  25519. builder.Font.Size = 8;
  25520. builder.Font.Bold = true;
  25521. builder.Font.Color = fontColor;
  25522. builder.Write(dateTime);
  25523. builder.InsertCell();
  25524. builder.Font.Size = 9;
  25525. builder.Font.Bold = true;
  25526. builder.Font.Color = fontColor;
  25527. builder.Write(content);
  25528. builder.InsertCell();
  25529. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  25530. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  25531. builder.Font.Size = 9;
  25532. builder.Font.Bold = false;
  25533. builder.Font.Color = fontColor;
  25534. builder.Write(reamrk);
  25535. builder.EndRow();
  25536. }
  25537. private void InvertedListFileDownloadSetBorders(CellCollection cell, int index)
  25538. {
  25539. cell[index].CellFormat.Borders.Top.LineStyle = Aspose.Words.LineStyle.None;
  25540. cell[index].CellFormat.Borders.Bottom.LineStyle = Aspose.Words.LineStyle.None;
  25541. cell[index].CellFormat.Borders.Left.LineStyle = Aspose.Words.LineStyle.None;
  25542. cell[index].CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.None;
  25543. //cell[index].CellFormat.Borders.Horizontal.LineStyle = Aspose.Words.LineStyle.None;
  25544. //cell[index].CellFormat.Borders.Vertical.LineStyle = Aspose.Words.LineStyle.None;
  25545. }
  25546. #endregion
  25547. #region 会务倒推表
  25548. /// <summary>
  25549. /// 会务倒推表
  25550. /// Init
  25551. /// </summary>
  25552. /// <returns></returns>
  25553. [HttpPost]
  25554. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25555. public async Task<IActionResult> InforRetrogressTableInit()
  25556. {
  25557. var groupData = await _groupRepository.PostShareGroupInfos(1);
  25558. if (groupData.Code == 0) return Ok(JsonView(groupData.Data));
  25559. return Ok(JsonView(false, groupData.Msg));
  25560. }
  25561. /// <summary>
  25562. /// 会务倒推表
  25563. /// ExcelDownload
  25564. /// </summary>
  25565. /// <param name="dto"></param>
  25566. /// <returns></returns>
  25567. [HttpPost]
  25568. [ApiLog("InforRetrogressTable", OperationEnum.Download)]
  25569. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25570. public async Task<IActionResult> InforRetrogressTableFileDownload(InforRetrogressTableFileDownloadDto dto)
  25571. {
  25572. var validator = new InforRetrogressTableFileDownloadDtoValidator();
  25573. var validatorRes = await validator.ValidateAsync(dto);
  25574. if (!validatorRes.IsValid)
  25575. {
  25576. StringBuilder sb = new StringBuilder();
  25577. foreach (var item in validatorRes.Errors)
  25578. {
  25579. sb.AppendLine(item.ErrorMessage);
  25580. }
  25581. return Ok(JsonView(false, sb.ToString()));
  25582. }
  25583. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.GroupId);
  25584. if (groupInfo == null) return Ok(JsonView(false, $"该团组信息未填写!"));
  25585. //时间根据团组出访日期-接团录入日期的天数来判断用哪个模板
  25586. var days = groupInfo.VisitDate.Subtract(groupInfo.CreateTime).Days;
  25587. #region Excel
  25588. var tempPath = AppSettingsHelper.Get("ExcelTempPath");
  25589. var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
  25590. var savePath = AppSettingsHelper.Get("ExcelBasePath") + "InforRetrogressTable/";
  25591. var ftpPath = AppSettingsHelper.Get("ExcelFtpPath") + "InforRetrogressTable/";
  25592. var fileNamePrefix = string.Empty;
  25593. if (days >= 30)
  25594. {
  25595. tempPath += $"会务工作倒推进度表(30天).xlsx";
  25596. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(30天)";
  25597. }
  25598. else if (days < 30 && days > 7)
  25599. {
  25600. tempPath += $"会务工作倒推进度表(15天).xlsx";
  25601. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(15天)";
  25602. }
  25603. else if (days <= 7)
  25604. {
  25605. tempPath += $"会务工作倒推进度表(7天).xlsx";
  25606. fileNamePrefix = $"{groupInfo.TeamName}_会务工作倒推进度表(7天)";
  25607. }
  25608. var fileName = $"{fileNamePrefix}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
  25609. fileName = CommonFun.ValidFileName(fileName);
  25610. //载入模板
  25611. WorkbookDesigner designer = new WorkbookDesigner();
  25612. designer.Workbook = new Workbook(tempPath);
  25613. designer.Process();
  25614. if (!Directory.Exists(savePath))
  25615. {
  25616. Directory.CreateDirectory(savePath);
  25617. }
  25618. string serverPath = $"{savePath}{fileName}";
  25619. designer.Workbook.Save(serverPath);
  25620. string rst = $"{servicePath}{ftpPath}{fileName}";
  25621. #endregion
  25622. return Ok(JsonView(new { url = rst }));
  25623. }
  25624. #endregion
  25625. #region 三公签证费用(签证费、代办费)
  25626. /// <summary>
  25627. /// 三公签证费用(签证费、代办费)
  25628. /// List
  25629. /// </summary>
  25630. /// <returns></returns>
  25631. [HttpPost]
  25632. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25633. public async Task<IActionResult> PostVisaFeeList(VisaFeeListDto _dto)
  25634. {
  25635. return Ok(await _visaFeeInfoRep.List(_dto.PortType, _dto.DiId));
  25636. }
  25637. /// <summary>
  25638. /// 三公签证费用(签证费、代办费)
  25639. /// Add Or Update
  25640. /// </summary>
  25641. /// <returns></returns>
  25642. [HttpPost]
  25643. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25644. public async Task<IActionResult> PostVisaFeeAddAndUpdate(VisaFeeAddAndUpdateDto _dto)
  25645. {
  25646. var _view = await _visaFeeInfoRep.Update(_dto);
  25647. if (_view.Code != 0)
  25648. {
  25649. return Ok(JsonView(false, _view.Msg));
  25650. }
  25651. return Ok(JsonView(true, _view.Msg));
  25652. }
  25653. #endregion
  25654. #region 酒店询价
  25655. /// <summary>
  25656. /// 酒店询价
  25657. /// Init
  25658. /// </summary>
  25659. /// <returns></returns>
  25660. [HttpPost]
  25661. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25662. public async Task<IActionResult> PostHotelInquiryInit()
  25663. {
  25664. var res = await _hotelInquiryRep._Init();
  25665. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25666. return Ok(JsonView(true, res.Msg, res.Data));
  25667. }
  25668. /// <summary>
  25669. /// 酒店询价
  25670. /// page Item
  25671. /// </summary>
  25672. /// <param name="_dto"></param>
  25673. /// <returns></returns>
  25674. [HttpPost]
  25675. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25676. public async Task<IActionResult> PostHotelInquiryPageItem(HotelInquiryPageItemDto _dto)
  25677. {
  25678. var res = await _hotelInquiryRep._PageItem(_dto.PageIndex, _dto.PageSize, _dto.PortType, _dto.DiId);
  25679. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25680. var view = res.Data as PageDataViewBase;
  25681. return Ok(JsonView(true, res.Msg, view.Data, view.Total));
  25682. }
  25683. /// <summary>
  25684. /// 酒店询价
  25685. /// info
  25686. /// </summary>
  25687. /// <param name="_dto"></param>
  25688. /// <returns></returns>
  25689. [HttpPost]
  25690. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25691. public async Task<IActionResult> PostHotelInquiryInfo(HotelInquiryInfoDto _dto)
  25692. {
  25693. var res = await _hotelInquiryRep._Info(_dto.PortType, _dto.Id);
  25694. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25695. return Ok(JsonView(true, res.Msg, res.Data));
  25696. }
  25697. /// <summary>
  25698. /// 酒店询价
  25699. /// Add Or Edit
  25700. /// </summary>
  25701. /// <param name="_dto"></param>
  25702. /// <returns></returns>
  25703. [HttpPost]
  25704. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25705. public async Task<IActionResult> PostHotelInquiryAddOrEdit(HotelInquiryAddOrEditDto _dto)
  25706. {
  25707. var res = await _hotelInquiryRep._AddOrEdit(_dto);
  25708. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25709. return Ok(JsonView(true, res.Msg, res.Data));
  25710. }
  25711. /// <summary>
  25712. /// 酒店询价
  25713. /// Del
  25714. /// </summary>
  25715. /// <param name="_dto"></param>
  25716. /// <returns></returns>
  25717. [HttpPost]
  25718. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25719. public async Task<IActionResult> PostHotelInquiryDel(HotelInquiryDelDto _dto)
  25720. {
  25721. var res = await _hotelInquiryRep._Del(_dto.Id, _dto.DeleteUserId);
  25722. if (res.Code != 0) return Ok(JsonView(false, res.Msg));
  25723. return Ok(JsonView(true, res.Msg, res.Data));
  25724. }
  25725. #endregion
  25726. #region 下载匹配op行程单
  25727. /// <summary>
  25728. /// 匹配op行程单
  25729. /// Init
  25730. /// </summary>
  25731. /// <param name="dto">团组列表请求dto</param>
  25732. /// <returns></returns>
  25733. [HttpPost]
  25734. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25735. public async Task<IActionResult> PostMateOpGroupInit(MateOpGroupInitDto dto)
  25736. {
  25737. Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  25738. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  25739. bool isDepStatus = await GeneralMethod.IsMarketingStaff(dto.CurrUserId);
  25740. List<Grp_DelegationInfo> groupInfos = new List<Grp_DelegationInfo>();
  25741. groupInfos = _sqlSugar.Queryable<Grp_DelegationInfo>()
  25742. .Where(it => it.IsDel == 0)
  25743. .WhereIF(isDepStatus, it => it.JietuanOperator == dto.CurrUserId)
  25744. .OrderByDescending(it => it.VisitStartDate)
  25745. .ToList();
  25746. if (groupInfos.Count < 1) return Ok(JsonView(false, "暂无和你相关的团组信息!"));
  25747. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  25748. var diids = groupInfos.Select(it => it.Id).ToList();
  25749. List<string> countrys = new List<string>();
  25750. foreach (var item in country)
  25751. {
  25752. var data = _groupRepository.FormartTeamName(item);
  25753. var dataArray = _groupRepository.GroupSplitCountry(data);
  25754. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  25755. }
  25756. countrys = countrys.Where(it => !string.IsNullOrEmpty(it)).Distinct().ToList();
  25757. List<string> areaArray = new List<string>(); //GetGroupCityLine
  25758. var areaItem = GeneralMethod.GetGroupCityLineItem(diids, "-");
  25759. foreach (var item in areaItem)
  25760. {
  25761. string areaStr = item.Value;
  25762. if (!string.IsNullOrEmpty(areaStr))
  25763. {
  25764. string[] str1 = areaStr.Split("-");
  25765. if (str1.Length > 0)
  25766. {
  25767. areaArray.AddRange(str1);
  25768. }
  25769. }
  25770. }
  25771. if (areaArray.Count > 0) areaArray = areaArray.Distinct().ToList();
  25772. var cityDatas = _sqlSugar.Queryable<Sys_Cities>()
  25773. .Where(it => it.IsDel == 0 && areaArray.Contains(it.Name_CN))
  25774. .Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN })
  25775. .ToList();
  25776. List<int> countriesIds = cityDatas.Select(it => it.parentId).ToList();
  25777. var countriesDatas = _sqlSugar.Queryable<Sys_Countries>()
  25778. .Where(it => countriesIds.Contains(it.Id))
  25779. .Select(it => new { it.Id, Name = it.Name_CN })
  25780. .ToList();
  25781. var teamNames = groupInfos.Where(it => !string.IsNullOrEmpty(it.TeamName))
  25782. .Select(it => it.TeamName).ToList();
  25783. stopwatch.Stop();
  25784. return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames, countriesDatas, citiesDatas = cityDatas }));
  25785. }
  25786. ///// <summary>
  25787. ///// 匹配op行程单
  25788. ///// Init 查询区域数据
  25789. ///// </summary>
  25790. ///// <param name="dto">团组列表请求dto</param>
  25791. ///// <returns></returns>
  25792. //[HttpPost]
  25793. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25794. //public async Task<IActionResult> PostMateOpGroupCountryChangeData(MateOpGroupCountryChangeDataDto dto)
  25795. //{
  25796. // Stopwatch stopwatch = Stopwatch.StartNew(); // 创建并启动Stopwatch
  25797. // List<Sys_Cities> cityDatas = new List<Sys_Cities>();
  25798. // string countriesDataStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("CityDatas");//string 取
  25799. // if (string.IsNullOrEmpty(countriesDataStr))
  25800. // {
  25801. // cityDatas = await _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0).ToListAsync();
  25802. // TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay; //设置redis 过期时间 2
  25803. // await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("CountriesDatas", JsonConvert.SerializeObject(cityDatas), ts);//string 存
  25804. // }
  25805. // else
  25806. // {
  25807. // cityDatas = JsonConvert.DeserializeObject<List<Sys_Cities>>(countriesDataStr);
  25808. // }
  25809. // var provinceData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 1).ToList();
  25810. // var citiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 2).ToList();
  25811. // var countiesData = cityDatas.Where(it => it.CountriesId == dto.CountriesId && it.Level == 3).ToList();
  25812. // List<dynamic> childList = new List<dynamic>();
  25813. // int parentId = dto.CountriesId;
  25814. // if (provinceData.Count > 1)
  25815. // {
  25816. // foreach (var item1 in provinceData)
  25817. // {
  25818. // List<dynamic> childList1 = new List<dynamic>();
  25819. // var citiesData1 = citiesData.Where(it => it.ParentId == item1.Id).ToList();
  25820. // foreach (var item2 in citiesData1)
  25821. // {
  25822. // List<dynamic> childList2 = new List<dynamic>();
  25823. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25824. // foreach (var item3 in countiesData1)
  25825. // {
  25826. // childList2.Add(new
  25827. // {
  25828. // id = item3.Id,
  25829. // parentId = item2.Id,
  25830. // level = "district",
  25831. // name = item3.Name_CN,
  25832. // });
  25833. // }
  25834. // childList1.Add(new
  25835. // {
  25836. // id = item2.Id,
  25837. // parentId = item1.Id,
  25838. // level = "city",
  25839. // name = item2.Name_CN,
  25840. // childList = childList2
  25841. // });
  25842. // }
  25843. // childList.Add(new
  25844. // {
  25845. // id = item1.Id,
  25846. // parentId = parentId,
  25847. // level = "province",
  25848. // name = item1.Name_CN,
  25849. // childList = childList1
  25850. // });
  25851. // }
  25852. // //城市
  25853. // var citiesData2 = citiesData.Where(it => it.ParentId == 0).ToList();
  25854. // foreach (var item2 in citiesData2)
  25855. // {
  25856. // List<dynamic> childList22 = new List<dynamic>();
  25857. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25858. // foreach (var item3 in countiesData1)
  25859. // {
  25860. // childList22.Add(new
  25861. // {
  25862. // id = item3.Id,
  25863. // parentId = item2.Id,
  25864. // level = "district",
  25865. // name = item3.Name_CN,
  25866. // });
  25867. // }
  25868. // childList.Add(new
  25869. // {
  25870. // id = item2.Id,
  25871. // parentId = parentId,
  25872. // level = "city",
  25873. // name = item2.Name_CN,
  25874. // childList = childList22
  25875. // });
  25876. // }
  25877. // }
  25878. // else
  25879. // {
  25880. // foreach (var item2 in citiesData)
  25881. // {
  25882. // string cname = item2.Name_CN;
  25883. // List<dynamic> childList1 = new List<dynamic>();
  25884. // var countiesData1 = countiesData.Where(it => it.ParentId == item2.Id).ToList();
  25885. // foreach (var item3 in countiesData1)
  25886. // {
  25887. // childList1.Add(new
  25888. // {
  25889. // Id = item3.Id,
  25890. // parentId = item2.Id,
  25891. // level = "district",
  25892. // name = item3.Name_CN
  25893. // });
  25894. // }
  25895. // childList.Add(new
  25896. // {
  25897. // id = item2.Id,
  25898. // parentId = parentId,
  25899. // level = "city",
  25900. // name = item2.Name_CN,
  25901. // childList = childList1
  25902. // });
  25903. // }
  25904. // }
  25905. // stopwatch.Stop();
  25906. // return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", childList));
  25907. //}
  25908. /// <summary>
  25909. /// 匹配op行程单
  25910. /// 接团信息列表 Page
  25911. /// </summary>
  25912. /// <param name="dto">团组列表请求dto</param>
  25913. /// <returns></returns>
  25914. [HttpPost]
  25915. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25916. public async Task<IActionResult> PostMateOpGroupPageList(MateOpGroupPageListDto dto)
  25917. {
  25918. var swatch = new Stopwatch();
  25919. swatch.Start();
  25920. #region 参数验证
  25921. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25922. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  25923. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25924. #region 页面操作权限验证
  25925. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  25926. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限"));
  25927. #endregion
  25928. #endregion
  25929. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  25930. {
  25931. var _view = await GeneralMethod.MateOpGroupPageListRedis();
  25932. //string sqlWhere = "";
  25933. if (!string.IsNullOrEmpty(dto.Country))
  25934. {
  25935. _view = _view.Where(x => !string.IsNullOrEmpty(x.VisitCountry) && x.VisitCountry.Contains(dto.Country)).ToList();
  25936. }
  25937. if (!string.IsNullOrEmpty(dto.Area))
  25938. {
  25939. _view = _view.Where(x => !string.IsNullOrEmpty(x.RouteCity) && x.RouteCity.Contains(dto.Area)).ToList();
  25940. }
  25941. if (!string.IsNullOrEmpty(dto.TeamName))
  25942. {
  25943. _view = _view.Where(x => !string.IsNullOrEmpty(x.TeamName) && x.TeamName.Contains(dto.TeamName)).ToList();
  25944. }
  25945. int startIndex = (dto.PageIndex - 1) * dto.PageSize; // 计算开始的索引
  25946. int endIndex = startIndex + dto.PageSize - 1; // 计算结束的索引
  25947. var _view1 = _view.Skip(startIndex).Take(endIndex).ToList();
  25948. swatch.Stop();
  25949. return Ok(JsonView(true, $"查询成功!耗时 {swatch.ElapsedMilliseconds} ms", _view1, _view.Count));
  25950. }
  25951. else
  25952. {
  25953. return Ok(JsonView(false, "查询失败"));
  25954. }
  25955. }
  25956. /// <summary>
  25957. /// 匹配op行程单
  25958. /// 行程单下载
  25959. /// </summary>
  25960. /// <param name="dto">团组列表请求dto</param>
  25961. /// <returns></returns>
  25962. [HttpPost]
  25963. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  25964. public async Task<IActionResult> PostMateOpGroupDownload(MateOpGroupDownloadDto dto)
  25965. {
  25966. #region 参数验证
  25967. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  25968. if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
  25969. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  25970. #region 页面操作权限验证
  25971. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  25972. if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限"));
  25973. #endregion
  25974. #endregion
  25975. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android
  25976. {
  25977. var res = ExportTravel(new ExportTravelDto() { Diid = dto.diId });
  25978. return Ok(res.GetType().GetProperty("Value").GetValue(res, null));
  25979. }
  25980. else
  25981. {
  25982. return Ok(JsonView(false, "下载失败!"));
  25983. }
  25984. }
  25985. #endregion
  25986. #region 国家信息 数据 注释
  25987. //[HttpPost]
  25988. //public async Task<IActionResult> LoadCitiesInitData(List<int> dto)
  25989. //{
  25990. // List<Grp_GroupsTaskAssignment> infos = new List<Grp_GroupsTaskAssignment>();
  25991. // foreach (var item in dto)
  25992. // {
  25993. // infos.Add(new Grp_GroupsTaskAssignment()
  25994. // {
  25995. // DIId = item,
  25996. // CTId = 82,
  25997. // UId = 248,
  25998. // IsEnable = 1,
  25999. // CreateUserId = 233,
  26000. // CreateTime = DateTime.Now,
  26001. // IsDel = 0
  26002. // });
  26003. // infos.Add(new Grp_GroupsTaskAssignment()
  26004. // {
  26005. // DIId = item,
  26006. // CTId = 82,
  26007. // UId = 286,
  26008. // IsEnable = 1,
  26009. // CreateUserId = 233,
  26010. // CreateTime = DateTime.Now,
  26011. // IsDel = 0
  26012. // });
  26013. // }
  26014. // int add = _sqlSugar.Insertable<Grp_GroupsTaskAssignment>(infos).ExecuteCommand();
  26015. // return Ok("操作成功");
  26016. //}
  26017. //public class paramJsonDto
  26018. //{
  26019. // public List<CountriesInfo> str { get; set; }
  26020. //}
  26021. //[HttpPost]
  26022. //public async Task<IActionResult> LoadCitiesInitData(paramJsonDto dto)
  26023. //{
  26024. // //List<CountriesInfo> infos = new List<CountriesInfo>();
  26025. // //infos = JsonConvert.DeserializeObject<List<CountriesInfo>>(dto.str);
  26026. // List<Sys_Cities> cities = new List<Sys_Cities>();
  26027. // List<Sys_Cities> districts = new List<Sys_Cities>();
  26028. // var counties = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  26029. // _sqlSugar.BeginTran();
  26030. // int countitiesIndex = 0;
  26031. // foreach (var item in dto.str)
  26032. // {
  26033. // dynamic data = item.c;
  26034. // int countriesId = counties.Find(it => it.Name_CN.Equals(item.cn))?.Id ?? 0;
  26035. // if (data != null)
  26036. // {
  26037. // countitiesIndex++;
  26038. // foreach (var item1 in data)
  26039. // {
  26040. // string cnname = item1.cn;
  26041. // string enname = item1.en;
  26042. // Sys_Cities provinceInfo = new Sys_Cities()
  26043. // {
  26044. // CountriesId = countriesId,
  26045. // Name_CN = cnname,
  26046. // Name_EN = enname,
  26047. // ParentId = 0,
  26048. // IsCapital = 1,
  26049. // CreateUserId = 208,
  26050. // CreateTime = DateTime.Now,
  26051. // IsDel = 0
  26052. // };
  26053. // if (item1.lv == "province") //省份
  26054. // {
  26055. // provinceInfo.Level = 1;
  26056. // int provinceId = 0;
  26057. // var provinceInfo1 = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(cnname)).First();
  26058. // if (provinceInfo1 != null) provinceId = provinceInfo1.Id;
  26059. // else provinceId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  26060. // var data1 = item1.c;
  26061. // foreach (var item2 in data1)
  26062. // {
  26063. // if (item2.lv == "city")
  26064. // {
  26065. // string citycnname = item2.cn;
  26066. // string cityenname = item2.en;
  26067. // Sys_Cities cityInfo = new Sys_Cities()
  26068. // {
  26069. // CountriesId = countriesId,
  26070. // ParentId = provinceId,
  26071. // Level = 2,
  26072. // Name_CN = citycnname,
  26073. // Name_EN = cityenname,
  26074. // IsCapital = 1,
  26075. // CreateUserId = 208,
  26076. // CreateTime = DateTime.Now,
  26077. // IsDel = 0
  26078. // };
  26079. // if (item2.c != null)
  26080. // {
  26081. // int cityId = 0;
  26082. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 2 && it.Name_CN.Equals(citycnname)).First();
  26083. // if (citiesInfo != null) cityId = citiesInfo.Id;
  26084. // else cityId = _sqlSugar.Insertable<Sys_Cities>(cityInfo).ExecuteReturnIdentity();
  26085. // foreach (var item3 in item2.c)
  26086. // {
  26087. // if (item3.lv == "district")
  26088. // {
  26089. // var districtInfo = new Sys_Cities()
  26090. // {
  26091. // CountriesId = countriesId,
  26092. // Name_CN = item3.cn,
  26093. // Name_EN = item3.en,
  26094. // Level = 3,
  26095. // ParentId = cityId,
  26096. // IsCapital = 1,
  26097. // CreateUserId = 208,
  26098. // CreateTime = DateTime.Now,
  26099. // IsDel = 0
  26100. // };
  26101. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  26102. // //{
  26103. // districts.Add(districtInfo);
  26104. // //}
  26105. // }
  26106. // }
  26107. // }
  26108. // else
  26109. // {
  26110. // //if (cities.Find(it => it.CountriesId == countriesId && it.ParentId == provinceId && it.Name_CN.Equals(citycnname)) == null)
  26111. // //{
  26112. // cities.Add(cityInfo);
  26113. // //}
  26114. // }
  26115. // }
  26116. // }
  26117. // }
  26118. // else if (item1.lv == "city")//城市
  26119. // {
  26120. // provinceInfo.Level = 2;
  26121. // if (item1.c != null)
  26122. // {
  26123. // int cityId = 0;
  26124. // var citiesInfo = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.CountriesId == countriesId && it.Level == 1 && it.Name_CN.Equals(provinceInfo.Name_CN)).First();
  26125. // if (citiesInfo != null) cityId = citiesInfo.Id;
  26126. // else cityId = _sqlSugar.Insertable<Sys_Cities>(provinceInfo).ExecuteReturnIdentity();
  26127. // foreach (var item3 in item1.c)
  26128. // {
  26129. // if (item3.lv == "district")
  26130. // {
  26131. // var districtInfo = new Sys_Cities()
  26132. // {
  26133. // CountriesId = countriesId,
  26134. // Name_CN = item3.cn,
  26135. // Name_EN = item3.en,
  26136. // Level = 3,
  26137. // ParentId = cityId,
  26138. // IsCapital = 1,
  26139. // CreateUserId = 208,
  26140. // CreateTime = DateTime.Now,
  26141. // IsDel = 0
  26142. // };
  26143. // //if (districts.Find(it => it.CountriesId == countriesId && it.ParentId == cityId && it.Name_CN.Equals(districtInfo.Name_CN)) == null)
  26144. // //{
  26145. // districts.Add(districtInfo);
  26146. // //}
  26147. // }
  26148. // }
  26149. // }
  26150. // else
  26151. // {
  26152. // //if (cities.Find(it => it.CountriesId == countriesId && it.Name_CN.Equals(provinceInfo.Name_CN)) == null)
  26153. // //{
  26154. // cities.Add(provinceInfo);
  26155. // //}
  26156. // }
  26157. // }
  26158. // }
  26159. // }
  26160. // }
  26161. // var procinceDatas = _sqlSugar.Queryable<Sys_Cities>().ToList();
  26162. // cities = cities.Distinct().ToList();
  26163. // districts = districts.Distinct().ToList();
  26164. // var citiesDatas = cities.Where(it => it.Level == 2).ToList();
  26165. // //var districtDatas = cities.Where(it => it.Level == 3).ToList();
  26166. // cities.AddRange(districts);
  26167. // var citiesAdd = _sqlSugar.Insertable<Sys_Cities>(cities).ExecuteReturnIdentity();
  26168. // //_sqlSugar.RollbackTran();
  26169. // _sqlSugar.CommitTran();
  26170. // return Ok(JsonView(false, "操作成功!"));
  26171. //}
  26172. //[HttpPost]
  26173. //public async Task<IActionResult> LoadCitiesInitInfo(CounrtiesDto dto)
  26174. //{
  26175. // List<CountitiesInfo> infos = dto.MyProperty;
  26176. // List<Sys_Cities> cityInfos = new List<Sys_Cities>();
  26177. // _sqlSugar.BeginTran();
  26178. // var countities = _sqlSugar.Queryable<Sys_Countries>().Where(it => it.IsDel == 0).ToList();
  26179. // var citities = _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0 && it.Level == 2).ToList();
  26180. // foreach (var item in infos)
  26181. // {
  26182. // var countryInfo = countities.Where(it => it.ThreeCode.Equals(item.country_code3)).FirstOrDefault();
  26183. // if (countryInfo != null)
  26184. // {
  26185. // var cityInfo = citities.Where(it => it.CountriesId == countryInfo.Id).ToList();
  26186. // var cityInfo1 = cityInfo.Where(it => item.capital_name_chinese.Contains(it.Name_CN)).FirstOrDefault();
  26187. // if (cityInfo1 != null)
  26188. // {
  26189. // cityInfo1.IsCapital = 0;
  26190. // cityInfos.Add(cityInfo1);
  26191. // }
  26192. // }
  26193. // }
  26194. // var update = _sqlSugar.Updateable<Sys_Cities>(cityInfos)
  26195. // .UpdateColumns(it => it.IsCapital)
  26196. // .WhereColumns(it => it.Id)
  26197. // .ExecuteCommand();
  26198. // //_sqlSugar.RollbackTran();
  26199. // _sqlSugar.CommitTran();
  26200. // return Ok(JsonView(false, "操作成功!"));
  26201. //}
  26202. //public class CounrtiesDto
  26203. //{
  26204. // public List<CountitiesInfo> MyProperty { get; set; }
  26205. //}
  26206. //public class CountitiesInfo
  26207. //{
  26208. // /// <summary>
  26209. // /// 圣约翰
  26210. // /// </summary>
  26211. // public string capital_name_chinese { get; set; }
  26212. // /// <summary>
  26213. // ///
  26214. // /// </summary>
  26215. // public string capital_name { get; set; }
  26216. // /// <summary>
  26217. // ///
  26218. // /// </summary>
  26219. // public string country_type { get; set; }
  26220. // /// <summary>
  26221. // /// 安提瓜和巴布达
  26222. // /// </summary>
  26223. // public string country_name_chinese { get; set; }
  26224. // /// <summary>
  26225. // /// 安提瓜和巴布达
  26226. // /// </summary>
  26227. // public string country_name_chinese_short { get; set; }
  26228. // /// <summary>
  26229. // /// 安提瓜和巴布达
  26230. // /// </summary>
  26231. // public string country_name_chinese_UN { get; set; }
  26232. // /// <summary>
  26233. // ///
  26234. // /// </summary>
  26235. // public string country_name_english_abbreviation { get; set; }
  26236. // /// <summary>
  26237. // ///
  26238. // /// </summary>
  26239. // public string country_name_english_formal { get; set; }
  26240. // /// <summary>
  26241. // ///
  26242. // /// </summary>
  26243. // public string country_name_english_UN { get; set; }
  26244. // /// <summary>
  26245. // ///
  26246. // /// </summary>
  26247. // public string continent_name { get; set; }
  26248. // /// <summary>
  26249. // ///
  26250. // /// </summary>
  26251. // public string subregion_name { get; set; }
  26252. // /// <summary>
  26253. // ///
  26254. // /// </summary>
  26255. // public string country_code2 { get; set; }
  26256. // /// <summary>
  26257. // ///
  26258. // /// </summary>
  26259. // public string country_code3 { get; set; }
  26260. // /// <summary>
  26261. // ///
  26262. // /// </summary>
  26263. // public string phone_code { get; set; }
  26264. //}
  26265. //public class CountriesInfo : BasicInfo
  26266. //{
  26267. // public List<CitiesInfo> c { get; set; }
  26268. //}
  26269. //public class CitiesInfo : BasicInfo
  26270. //{
  26271. // public List<AreaInfo> c { get; set; }
  26272. //}
  26273. //public class AreaInfo : BasicInfo
  26274. //{
  26275. // public List<AreaInfo> c { get; set; }
  26276. //}
  26277. //public class BasicInfo
  26278. //{
  26279. // public string code { get; set; }
  26280. // public string cn { get; set; }
  26281. // public string lv { get; set; }
  26282. // public string en { get; set; }
  26283. //}
  26284. #endregion
  26285. #region 查看邀请方
  26286. /// <summary>
  26287. /// 查看邀请方
  26288. /// 邀请方信息 Init
  26289. /// </summary>
  26290. /// <param name="dto"></param>
  26291. /// <returns></returns>
  26292. [HttpPost]
  26293. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26294. public async Task<IActionResult> PostGroupLinkInvitingUnitNameInit(GroupLinkInvitingUnitNameInitDto dto)
  26295. {
  26296. string sqlWhere = string.Empty;
  26297. if (!string.IsNullOrEmpty(dto.Search))
  26298. {
  26299. sqlWhere = string.Format($@" And UnitName Like '%{dto.Search}%'");
  26300. }
  26301. string sql = string.Format($@"Select
  26302. ROW_NUMBER() Over(Order By Id desc) As Row_Number,
  26303. Id,
  26304. UnitName
  26305. From Res_InvitationOfficialActivityData
  26306. Where IsDel = 0
  26307. And (UnitName != '' Or UnitName != null) {sqlWhere}");
  26308. RefAsync<int> total = 0;
  26309. var _views = await _sqlSugar.SqlQueryable<GroupLinkInvitingUnitNameInitView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26310. return Ok(JsonView(true, MsgTips.Succeed, _views, total));
  26311. }
  26312. /// <summary>
  26313. /// 查看邀请方
  26314. /// 国家信息 Init
  26315. /// </summary>
  26316. /// <param name="dto"></param>
  26317. /// <returns></returns>
  26318. [HttpPost]
  26319. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26320. public async Task<IActionResult> PostGroupLinkInvitingCountryInit(GroupLinkInvitingUnitNameInitDto dto)
  26321. {
  26322. var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
  26323. var country = groupInfos.Select(it => it.VisitCountry).ToList();
  26324. var diids = groupInfos.Select(it => it.Id).ToList();
  26325. List<string> countrys = new List<string>();
  26326. foreach (var item in country)
  26327. {
  26328. var data = _groupRepository.FormartTeamName(item);
  26329. var dataArray = _groupRepository.GroupSplitCountry(data);
  26330. if (dataArray.Count > 0) countrys.AddRange(dataArray);
  26331. }
  26332. countrys = countrys.Distinct().ToList();
  26333. for (int i = 0; i < countrys.Count; i++)
  26334. {
  26335. string item = countrys[i];
  26336. if (string.IsNullOrEmpty(item) || item.Contains("-"))
  26337. {
  26338. countrys.Remove(item);
  26339. i--;
  26340. }
  26341. }
  26342. RefAsync<int> total = 0;
  26343. var countyDatas = await _sqlSugar.Queryable<Sys_Countries>()
  26344. .Where(it => countrys.Contains(it.Name_CN))
  26345. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  26346. .Select(it => new { id = it.Id, name = it.Name_CN })
  26347. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26348. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  26349. }
  26350. /// <summary>
  26351. /// 查看邀请方
  26352. /// 城市信息 Init
  26353. /// </summary>
  26354. /// <param name="dto"></param>
  26355. /// <returns></returns>
  26356. [HttpPost]
  26357. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26358. public async Task<IActionResult> PostGroupLinkInvitingCityInit(GroupLinkInvitingCityInitDto dto)
  26359. {
  26360. if (dto.CountiesId < 1) return Ok(JsonView(false, "请传入有效的国家Id"));
  26361. RefAsync<int> total = 0;
  26362. var countyDatas = await _sqlSugar.Queryable<Sys_Cities>()
  26363. .Where(it => it.CountriesId == dto.CountiesId)
  26364. .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
  26365. .OrderBy(it => new { IsCapital = SqlFunc.Asc(it.IsCapital), Id = SqlFunc.Asc(it.Id) })
  26366. .Select(it => new { id = it.Id, name = it.Name_CN })
  26367. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26368. return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
  26369. }
  26370. /// <summary>
  26371. /// 查看邀请方
  26372. /// 团组名称 Init
  26373. /// </summary>
  26374. /// <param name="dto"></param>
  26375. /// <returns></returns>
  26376. [HttpPost]
  26377. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26378. public async Task<IActionResult> PostGroupLinkInvitingGroupInit(GroupLinkInvitingDto dto)
  26379. {
  26380. var watch = new Stopwatch();
  26381. watch.Start();
  26382. RefAsync<int> total = 0;
  26383. var countyDatas = await _sqlSugar.Queryable<Res_OfficialActivities>()
  26384. .InnerJoin<Grp_DelegationInfo>((oa, di) => oa.DiId == di.Id)
  26385. .Where((oa, di) => oa.IsDel == 0)
  26386. .WhereIF(!string.IsNullOrEmpty(dto.Search), (oa, di) => di.TeamName.Contains(dto.Search))
  26387. .OrderBy((oa, di) => new { id = SqlFunc.Desc(di.Id) })
  26388. .Select((oa, di) => new { id = di.Id, name = di.TeamName })
  26389. .Distinct()
  26390. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26391. watch.Stop();
  26392. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
  26393. }
  26394. /// <summary>
  26395. /// 查看邀请方
  26396. /// 团组 & 邀请方信息
  26397. /// </summary>
  26398. /// <param name="dto"></param>
  26399. /// <returns></returns>
  26400. [HttpPost]
  26401. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  26402. public async Task<IActionResult> PostGroupLinkInvitingPageList(GroupLinkInvitingPageListDto dto)
  26403. {
  26404. var watch = new Stopwatch();
  26405. watch.Start();
  26406. RefAsync<int> total = 0;
  26407. var infos = await _sqlSugar.Queryable<GroupLinkInvitingPageListView>()
  26408. .AS("Grp_DelegationInfo")
  26409. .Includes(x => x.InvitingInfos)
  26410. .Where(x => x.IsDel == 0 && x.InvitingInfos.Any(z => z.IsDel == 0))
  26411. .WhereIF(!string.IsNullOrEmpty(dto.Counrty), x => x.VisitCountry.Contains(dto.Counrty))
  26412. .WhereIF(!string.IsNullOrEmpty(dto.Area), x => x.InvitingInfos.Any(z => z.Area.Contains(dto.Area))) //
  26413. .WhereIF(!string.IsNullOrEmpty(dto.TeamName), x => x.TeamName.Contains(dto.TeamName)) //
  26414. .WhereIF(!string.IsNullOrEmpty(dto.UnitName), x => x.InvitingInfos.Any(z => z.Client.Contains(dto.UnitName)))
  26415. .OrderBy(x => new { JietuanTime = SqlFunc.Desc(x.VisitStartDate) })
  26416. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  26417. var userDatas = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToList();
  26418. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
  26419. infos.ForEach(x =>
  26420. {
  26421. x.TeamDid = setDatas.Find(y => int.Parse(x.TeamDid) == y.Id)?.Name ?? "-";
  26422. x.JietuanOperator = userDatas.Find(y => int.Parse(x.JietuanOperator) == y.Id)?.CnName ?? "-";
  26423. x.TeamLevSId = setDatas.Find(y => int.Parse(x.TeamLevSId) == y.Id)?.Name ?? "-";
  26424. x.InvitingInfos = x.InvitingInfos.Where(it => it.IsDel == 0).ToList();
  26425. });
  26426. watch.Stop();
  26427. return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", infos, total));
  26428. }
  26429. #endregion
  26430. #region 报批行程
  26431. /// <summary>
  26432. /// 报批行程初始化
  26433. /// </summary>
  26434. /// <param name="dto"></param>
  26435. /// <returns></returns>
  26436. [HttpPost]
  26437. public IActionResult ApprovalJourneyInit(ApprovalJourneyDto dto)
  26438. {
  26439. const int chiNumber = 5;
  26440. var jw = JsonView(false);
  26441. var groupList = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).OrderByDescending(x => x.VisitStartDate).ToList();
  26442. var group = groupList.First();
  26443. var diid = dto.Diid == -1 ? group?.Id : dto.Diid;
  26444. group = groupList.First(x => x.Id == diid);
  26445. var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  26446. .Where(x => x.DiId == diid && x.IsDel == 0)
  26447. .ToArray();
  26448. var count = 1;
  26449. foreach (var item in blackCodeList)
  26450. {
  26451. if (string.IsNullOrWhiteSpace(item.Title))
  26452. {
  26453. item.Title = "未设置名称数据" + count;
  26454. }
  26455. count++;
  26456. }
  26457. ;
  26458. if (group == null)
  26459. {
  26460. jw.Msg = "暂无团组!";
  26461. return Ok(jw);
  26462. }
  26463. var data = new
  26464. {
  26465. groupList = groupList.Select(x => new
  26466. {
  26467. x.TeamName,
  26468. x.Id
  26469. }),
  26470. content = new ArrayList(),
  26471. groupInfo = new
  26472. {
  26473. group.VisitDays,
  26474. group.TourCode,
  26475. group.VisitPNumber,
  26476. group.TeamName,
  26477. group.Id,
  26478. visitStartDate = group.VisitStartDate.ToString("yyyy-MM-dd"),
  26479. visitEndDate = group.VisitEndDate.ToString("yyyy-MM-dd"),
  26480. group.ClientUnit
  26481. },
  26482. blackCodeList = blackCodeList.Select(x => new
  26483. {
  26484. x.Title,
  26485. x.Id
  26486. }),
  26487. FileTempList = new ArrayList()
  26488. {
  26489. new { Index = 1,FileName = "旧模板" },
  26490. new { Index = 2,FileName = "省外办" },
  26491. new { Index = 3,FileName = "市外办" },
  26492. }
  26493. };
  26494. var resultArr = new ArrayList();
  26495. var content = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == diid && x.IsDel == 0).ToList();
  26496. #region 默认不生成行程
  26497. //if (content.Count == 0)
  26498. //{
  26499. // var stay = "-";
  26500. // var cityPath = "-";
  26501. // var blackCodeList = _sqlSugar.Queryable<Air_TicketBlackCode>()
  26502. // .Where(x => x.DiId == diid && x.IsDel == 0)
  26503. // .ToList();
  26504. // //添加城市路径以及住宿地
  26505. // //黑屏代码数据
  26506. // DataTable dtBlack = GeneralMethod.GetTableByBlackCodeById(blackCodeList.FirstOrDefault());
  26507. // if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  26508. // {
  26509. // jw = JsonView(true, "黑屏代码有误!", data);
  26510. // return Ok(jw);
  26511. // }
  26512. // data = data with
  26513. // {
  26514. // blackCodeList = new ArrayList(blackCodeList.Select(x => new
  26515. // {
  26516. // x.Title,
  26517. // x.Id,
  26518. // }).ToArray())
  26519. // };
  26520. // foreach (DataRow row in dtBlack.Rows)
  26521. // {
  26522. // if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  26523. // {
  26524. // jw = JsonView(true, "黑屏代码有误!" + row["Error"].ToString(), data);
  26525. // return Ok(jw);
  26526. // }
  26527. // }
  26528. // //黑屏代码获取时间区间
  26529. // var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  26530. // string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  26531. // _sqlSugar.BeginTran();
  26532. // for (int i = 0; i < timeArr.Count; i++)
  26533. // {
  26534. // stay = "-";
  26535. // cityPath = "-";
  26536. // DateTime NewData = DateTime.Parse(timeArr[i]);
  26537. // string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  26538. // Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  26539. // var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  26540. // if (tbSelect.Length > 0)
  26541. // {
  26542. // List<string> threeCodeStr = new List<string>();
  26543. // foreach (var item in tbSelect)
  26544. // {
  26545. // var threeCode = item["Three"].ToString() ?? "";
  26546. // if (threeCode.Length == 6)
  26547. // {
  26548. // var start = threeCode.Substring(0, 3);
  26549. // var end = threeCode.Substring(3, 3);
  26550. // if (threeCodeStr.Count == 0)
  26551. // {
  26552. // threeCodeStr.Add(start);
  26553. // threeCodeStr.Add(end);
  26554. // }
  26555. // else
  26556. // {
  26557. // if (threeCodeStr[threeCodeStr.Count - 1] == start)
  26558. // {
  26559. // threeCodeStr.Add(end);
  26560. // }
  26561. // else
  26562. // {
  26563. // threeCodeStr.Add(start);
  26564. // threeCodeStr.Add(end);
  26565. // }
  26566. // }
  26567. // }
  26568. // }
  26569. // var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  26570. // var last = threeCodeStr.Last();
  26571. // foreach (var item in threeCodeStr)
  26572. // {
  26573. // cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  26574. // if (item.Equals(last))
  26575. // {
  26576. // stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  26577. // }
  26578. // }
  26579. // cityPath = cityPath.Trim('-');
  26580. // }
  26581. // appro.Date = "第" + intToString(i + 1) + "天 " + NewData.Month + "月" + NewData.Day + "日(" + week + ") " + cityPath + " 宿:" + stay;
  26582. // appro.Diid = diid ?? -1;
  26583. // var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  26584. // appro.Id = thisId;
  26585. // appro.CreateUserId = dto.UserId;
  26586. // appro.CreateTime = DateTime.Now;
  26587. // content.Add(appro);
  26588. // }
  26589. // _sqlSugar.CommitTran();
  26590. //}
  26591. #endregion
  26592. foreach (var x in content)
  26593. {
  26594. var chiList = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x1 => x1.ParentId == x.Id && x1.IsDel == 0).ToList();
  26595. if (chiList.Count < chiNumber)
  26596. {
  26597. for (int i = chiList.Count; i < chiNumber; i++)
  26598. {
  26599. chiList.Add(new Grp_ApprovalTravelDetails());
  26600. }
  26601. }
  26602. resultArr.Add(new
  26603. {
  26604. x.Id,
  26605. x.Date,
  26606. x.Diid,
  26607. chiList = chiList.Select(x1 => new
  26608. {
  26609. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  26610. x1.Details,
  26611. x1.ParentId,
  26612. x1.Id
  26613. })
  26614. });
  26615. }
  26616. data = data with
  26617. {
  26618. content = resultArr,
  26619. };
  26620. jw = JsonView(true, "获取成功!", data);
  26621. return Ok(jw);
  26622. }
  26623. /// <summary>
  26624. /// 报批行程删除
  26625. /// </summary>
  26626. /// <param name="dto"></param>
  26627. /// <returns></returns>
  26628. [HttpPost]
  26629. public IActionResult DeleteApprovalJourney(DeleteApprovalJourney dto)
  26630. {
  26631. var jw = JsonView(false);
  26632. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  26633. if (group == null)
  26634. {
  26635. jw.Msg = "团组参数有误!";
  26636. return Ok(jw);
  26637. }
  26638. try
  26639. {
  26640. _sqlSugar.BeginTran();
  26641. var arr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.Diid == dto.Diid && x.IsDel == 0).Select(x => x.Id).ToList();
  26642. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().SetColumns(x => new Grp_ApprovalTravelDetails
  26643. {
  26644. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26645. DeleteUserId = dto.uesrId,
  26646. IsDel = 1
  26647. }).Where(x => arr.Contains(x.ParentId) && x.IsDel == 0).ExecuteCommand();
  26648. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>().SetColumns(x => new Grp_ApprovalTravel
  26649. {
  26650. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26651. DeleteUserId = dto.uesrId,
  26652. IsDel = 1
  26653. }).Where(x => arr.Contains(x.Id)).ExecuteCommand();
  26654. _sqlSugar.CommitTran();
  26655. jw = JsonView(true, "删除成功");
  26656. }
  26657. catch (Exception ex)
  26658. {
  26659. jw = JsonView(false, ex.Message);
  26660. }
  26661. return Ok(jw);
  26662. }
  26663. /// <summary>
  26664. /// 报批行程保存
  26665. /// </summary>
  26666. /// <param name="dto"></param>
  26667. /// <returns></returns>
  26668. [HttpPost]
  26669. public IActionResult SaveApprovalJourney(SaveApprovalJourney dto)
  26670. {
  26671. var jw = JsonView(false);
  26672. var Find = dto.Arr.Find(x => x.id == 0);
  26673. if (Find != null)
  26674. {
  26675. jw.Msg = "生成的ID为0!";
  26676. return Ok(jw);
  26677. }
  26678. foreach (var item in dto.Arr)
  26679. {
  26680. foreach (var chi in item.chiList)
  26681. {
  26682. if (chi.parentId == 0)
  26683. {
  26684. chi.parentId = item.id;
  26685. }
  26686. }
  26687. }
  26688. var chiArr = dto.Arr.SelectMany(x => x.chiList).ToList();
  26689. _sqlSugar.BeginTran();
  26690. if (chiArr.Where(x => x.id == 0).Count() == chiArr.Count)
  26691. {
  26692. var parentIds = dto.Arr.Select(x => x.id).ToList();
  26693. _sqlSugar.Updateable<Grp_ApprovalTravelDetails>().Where(x => parentIds.Contains(x.ParentId) && x.IsDel == 0).SetColumns(x => new Grp_ApprovalTravelDetails
  26694. {
  26695. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  26696. DeleteUserId = dto.UserId,
  26697. IsDel = 1
  26698. }).ExecuteCommand();
  26699. }
  26700. try
  26701. {
  26702. _ = _sqlSugar.Insertable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id == 0).Select(x => new Grp_ApprovalTravelDetails
  26703. {
  26704. CreateTime = DateTime.Now,
  26705. CreateUserId = dto.UserId,
  26706. Details = x.details,
  26707. ParentId = x.parentId,
  26708. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  26709. Remark = "",
  26710. IsDel = 0
  26711. }).ToList()).ExecuteCommand();
  26712. _ = _sqlSugar.Updateable<Grp_ApprovalTravelDetails>(chiArr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravelDetails
  26713. {
  26714. Id = x.id,
  26715. Details = x.details,
  26716. ParentId = x.parentId,
  26717. Time = x.timeInterval.Where(x => !string.IsNullOrWhiteSpace(x)).Count() > 1 ? x.timeInterval[0] + "-" + x.timeInterval[1] : "",
  26718. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravelDetails
  26719. {
  26720. Details = x.Details,
  26721. ParentId = x.ParentId,
  26722. Time = x.Time
  26723. }).ExecuteCommand();
  26724. _ = _sqlSugar.Updateable<Grp_ApprovalTravel>(dto.Arr.Where(x => x.id != 0).Select(x => new Grp_ApprovalTravel
  26725. {
  26726. Id = x.id,
  26727. Date = x.date,
  26728. }).ToList()).UpdateColumns(x => new Grp_ApprovalTravel
  26729. {
  26730. Date = x.Date
  26731. }).ExecuteCommand();
  26732. _sqlSugar.CommitTran();
  26733. jw = JsonView(true, "保存成功!");
  26734. }
  26735. catch (Exception ex)
  26736. {
  26737. _sqlSugar.RollbackTran();
  26738. jw = JsonView(false, "保存失败!" + ex.Message);
  26739. }
  26740. return Ok(jw);
  26741. }
  26742. /// <summary>
  26743. /// 报批行程生成
  26744. /// </summary>
  26745. /// <param name="dto"></param>
  26746. /// <returns></returns>
  26747. [HttpPost]
  26748. public IActionResult CreateApprovalJourney(CreateApprovalJourneyDto dto)
  26749. {
  26750. var jw = JsonView(false);
  26751. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  26752. if (group == null)
  26753. {
  26754. jw.Msg = "暂无该团组!";
  26755. return Ok(jw);
  26756. }
  26757. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().First(x => x.Id == dto.BlackCodeId && x.IsDel == 0);
  26758. //黑屏代码数据
  26759. DataTable dtBlack = GeneralMethod.GetTableByBlackCodeBySingle(blackCode);
  26760. if (dtBlack.Rows.Count == 0 || string.IsNullOrWhiteSpace(dtBlack.Rows[0][1].ToString()))
  26761. {
  26762. jw.Msg = "黑屏代码有误!";
  26763. return Ok(jw);
  26764. }
  26765. foreach (DataRow row in dtBlack.Rows)
  26766. {
  26767. if (!string.IsNullOrWhiteSpace(row["Error"].ToString()))
  26768. {
  26769. jw.Msg = "黑屏代码有误!" + row["Error"].ToString();
  26770. return Ok(jw);
  26771. }
  26772. }
  26773. //var officialActivitiesArr = _sqlSugar.Queryable<Res_OfficialActivities>().Where(x => x.DiId == dto.Diid && x.IsDel == 0).ToList();
  26774. var resultArr = new ArrayList();
  26775. //if (officialActivitiesArr.Count == 0)
  26776. //{
  26777. // jw.Msg = "暂无公务出访信息!";
  26778. // return Ok(jw);
  26779. //}
  26780. try
  26781. {
  26782. _sqlSugar.BeginTran();
  26783. DeleteApprovalJourney(new
  26784. Domain.Dtos.Groups.DeleteApprovalJourney
  26785. {
  26786. Diid = dto.Diid,
  26787. uesrId = dto.Userid
  26788. });
  26789. var stay = "-";
  26790. var cityPath = "-";
  26791. var arriveCountry = string.Empty;
  26792. //添加城市路径以及住宿地
  26793. //黑屏代码获取时间区间
  26794. var timeArr = GeneralMethod.GetTimeListByDataTable(dtBlack);
  26795. var empty = "【未收入该三字码!请机票同事录入】";
  26796. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  26797. #region 配置公务活动时间
  26798. List<Tuple<int, string, string>> Times = new List<Tuple<int, string, string>>();
  26799. Times.Add(new Tuple<int, string, string>(9, "9:00", "10:30"));
  26800. Times.Add(new Tuple<int, string, string>(11, "11:00", "12:00"));
  26801. Times.Add(new Tuple<int, string, string>(14, "14:00", "15:30"));
  26802. Times.Add(new Tuple<int, string, string>(16, "16:00", "17:00"));
  26803. List<Tuple<DateTime, List<string>>> fallTimesCheckCountry = new List<Tuple<DateTime, List<string>>>()
  26804. {
  26805. 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" }),
  26806. 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"}),
  26807. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  26808. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,13,30,0), new List<string>{"16:30-17:30"}),
  26809. };
  26810. List<Tuple<DateTime, List<string>>> fallTimesNotCheckCountry = new List<Tuple<DateTime, List<string>>>()
  26811. {
  26812. 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" }),
  26813. 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"}),
  26814. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,11,30,0), new List<string>{"14:00-15:30","16:00-17:00"}),
  26815. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,30,0), new List<string>{"16:30-17:30"}),
  26816. };
  26817. List<Tuple<DateTime, List<string>>> takeoffTimes = new List<Tuple<DateTime, List<string>>>()
  26818. {
  26819. 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" }),
  26820. 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"}),
  26821. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,14,00,0), new List<string>{"9:00-10:30", "11:00-12:00",}),
  26822. new Tuple<DateTime, List<string>>(new DateTime(1900,1,1,12,00,0), new List<string>{"09:00-10:00"}),
  26823. };
  26824. #endregion
  26825. var nextDayNum = 0;
  26826. for (int i = 0; i < timeArr.Count; i++)
  26827. {
  26828. stay = "-";
  26829. cityPath = "-";
  26830. var chiarr = new List<Grp_ApprovalTravelDetails>();
  26831. DateTime NewData = DateTime.Parse(timeArr[i]);
  26832. //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();
  26833. var tbSelect = dtBlack.Select(string.Format("Day = '{0}'", NewData.ToString("yyyy-MM-dd")));
  26834. if (nextDayNum > 0)
  26835. {
  26836. nextDayNum--;
  26837. }
  26838. if (tbSelect.Length > 0)
  26839. {
  26840. List<string> threeCodeStr = new List<string>();
  26841. bool isTrade = false;
  26842. string trip = string.Empty;
  26843. foreach (var item in tbSelect)
  26844. {
  26845. if (nextDayNum == 0)
  26846. {
  26847. nextDayNum = Convert.ToInt32(item["Sign"]);
  26848. }
  26849. var airStartTime = item["StartTime"].ToString() ?? "0000";
  26850. var airEndTime = item["EndTime"].ToString() ?? "0000";
  26851. var takeOffTime = DateTime.Parse(timeArr[i]);
  26852. var fallToTime = DateTime.Parse(timeArr[i]);
  26853. takeOffTime = takeOffTime.AddHours(int.Parse(airStartTime.Substring(0, 2)));
  26854. takeOffTime = takeOffTime.AddMinutes(int.Parse(airStartTime.Substring(2, 2)));
  26855. fallToTime = fallToTime.AddHours(int.Parse(airEndTime.Substring(0, 2)));
  26856. fallToTime = fallToTime.AddMinutes(int.Parse(airEndTime.Substring(2, 2)));
  26857. if (nextDayNum > 0)
  26858. {
  26859. fallToTime = fallToTime.AddDays(nextDayNum);
  26860. }
  26861. trip = string.Empty;
  26862. var start = string.Empty;
  26863. var end = string.Empty;
  26864. var threeCode = item["Three"].ToString() ?? "";
  26865. if (threeCode.Length == 6)
  26866. {
  26867. start = threeCode.Substring(0, 3);
  26868. end = threeCode.Substring(3, 3);
  26869. if (threeCodeStr.Count == 0)
  26870. {
  26871. threeCodeStr.Add(start);
  26872. threeCodeStr.Add(end);
  26873. }
  26874. else
  26875. {
  26876. if (threeCodeStr[threeCodeStr.Count - 1] == start)
  26877. {
  26878. threeCodeStr.Add(end);
  26879. }
  26880. else
  26881. {
  26882. threeCodeStr.Add(start);
  26883. threeCodeStr.Add(end);
  26884. }
  26885. }
  26886. }
  26887. //处理机票信息
  26888. var start_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == start.ToUpper());
  26889. var end_Object = _sqlSugar.Queryable<Res_ThreeCode>().First(x => x.Three.ToUpper() == end.ToUpper());
  26890. if (start_Object == null)
  26891. {
  26892. start_Object = new Res_ThreeCode()
  26893. {
  26894. AirPort = empty,
  26895. AirPort_En = empty,
  26896. City = empty,
  26897. Country = empty,
  26898. Four = empty,
  26899. Three = empty,
  26900. };
  26901. }
  26902. if (end_Object == null)
  26903. {
  26904. end_Object = new Res_ThreeCode()
  26905. {
  26906. AirPort = empty,
  26907. AirPort_En = empty,
  26908. City = empty,
  26909. Country = empty,
  26910. Four = empty,
  26911. Three = empty,
  26912. };
  26913. }
  26914. //机型判断
  26915. string airModel = item["AirModel"].ToString();
  26916. airModel = GeneralMethod.GetLonger(airModel!.Substring(0, 1)) + airModel;
  26917. string flightTime = item["FlightTime"].ToString();
  26918. flightTime = ParseBlackTime(flightTime);
  26919. //航班号
  26920. string flightcode = item["Fliagtcode"].ToString();
  26921. var aircompany = _sqlSugar.Queryable<Res_AirCompany>().First(x => x.ShortCode.ToUpper() == flightcode!.Substring(0, 2).ToUpper() && x.IsDel == 0);
  26922. var hsEmpty = "【此航司" + flightcode!.Substring(0, 2).ToUpper() + "未收录,请机票同事录入】";
  26923. if (aircompany == null)
  26924. {
  26925. aircompany = new Res_AirCompany
  26926. {
  26927. CnName = hsEmpty,
  26928. EnName = hsEmpty,
  26929. ShortCode = hsEmpty,
  26930. };
  26931. }
  26932. //航班前公务安排
  26933. if (tbSelect.First().Equals(item) && i != 0)
  26934. {
  26935. foreach (var takeoff in takeoffTimes)
  26936. {
  26937. var takeoffItem1 = NewData.AddHours(takeoff.Item1.Hour).AddMinutes(takeoff.Item1.Minute);
  26938. if (DateTime.Compare(takeOffTime, takeoffItem1) > 0)
  26939. {
  26940. foreach (var addTime in takeoff.Item2)
  26941. {
  26942. chiarr.Add(new Grp_ApprovalTravelDetails
  26943. {
  26944. Time = addTime,
  26945. CreateTime = DateTime.Now,
  26946. CreateUserId = dto.Userid,
  26947. ParentId = 0,
  26948. Details = "公务活动"
  26949. });
  26950. }
  26951. break;
  26952. }
  26953. }
  26954. }
  26955. //从成都天府国际机场搭乘四川航空公司3U3961飞往东京
  26956. //trip += $"从{start_Object.AirPort}搭乘{aircompany.CnName}{flightcode}飞往{end_Object.City}。\r\n({start_Object.AirPort}/{end_Object.AirPort} 机型:{airModel} 飞行时间{flightTime});\r\n";
  26957. //乘坐四川航空3U3901次航班由成都飞往加德满都,3小时25分钟
  26958. trip += $"乘坐{aircompany.CnName}{flightcode}次航班由{start_Object.City}飞往{end_Object.City},{flightTime}";
  26959. isTrade = Convert.ToBoolean(item["isTransitShipment"]);
  26960. if (isTrade)
  26961. {
  26962. //trip += $"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼(中转 行李直达)\r\n";
  26963. trip += "(转机不出机场)。";
  26964. }
  26965. //else
  26966. //{
  26967. // trip += "\r\n"; //$"抵达{end_Object.AirPort}{item["EndBuilding"].ToString().Trim()}航站楼,办理入境手续,之后前往提取行李\r\n";
  26968. //}
  26969. chiarr.Add(new Grp_ApprovalTravelDetails
  26970. {
  26971. Time = takeOffTime.ToString("HH:mm") + "-" + fallToTime.ToString("HH:mm"),
  26972. CreateTime = DateTime.Now,
  26973. CreateUserId = dto.Userid,
  26974. ParentId = 0,
  26975. Details = trip
  26976. });
  26977. //最后一条到达的时间安排公务
  26978. if (tbSelect.Last().Equals(item) && i != timeArr.Count - 1)
  26979. {
  26980. bool isCheckCountry = false;
  26981. if (end_Object.Country != arriveCountry)
  26982. {
  26983. arriveCountry = end_Object.Country;
  26984. isCheckCountry = true;
  26985. }
  26986. if (nextDayNum == 0)
  26987. {
  26988. //需要入境的情况
  26989. if (isCheckCountry)
  26990. {
  26991. foreach (var fallTime in fallTimesCheckCountry)
  26992. {
  26993. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  26994. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  26995. {
  26996. foreach (var addTime in fallTime.Item2)
  26997. {
  26998. chiarr.Add(new Grp_ApprovalTravelDetails
  26999. {
  27000. Time = addTime,
  27001. CreateTime = DateTime.Now,
  27002. CreateUserId = dto.Userid,
  27003. ParentId = 0,
  27004. Details = "公务活动"
  27005. });
  27006. }
  27007. break;
  27008. }
  27009. }
  27010. }
  27011. else
  27012. {
  27013. foreach (var fallTime in fallTimesNotCheckCountry)
  27014. {
  27015. var fallTimeItem1 = NewData.AddHours(fallTime.Item1.Hour).AddMinutes(fallTime.Item1.Minute);
  27016. if (DateTime.Compare(fallToTime, fallTimeItem1) < 0)
  27017. {
  27018. foreach (var addTime in fallTime.Item2)
  27019. {
  27020. chiarr.Add(new Grp_ApprovalTravelDetails
  27021. {
  27022. Time = addTime,
  27023. CreateTime = DateTime.Now,
  27024. CreateUserId = dto.Userid,
  27025. ParentId = 0,
  27026. Details = "公务活动"
  27027. });
  27028. }
  27029. break;
  27030. }
  27031. }
  27032. }
  27033. }
  27034. }
  27035. }
  27036. //添加乘车语句
  27037. //chiarr.Add(new Grp_ApprovalTravelDetails
  27038. //{
  27039. // Time = (fallToTime.AddHours(2.5).ToString("HH:mm") + "-" + fallToTime.AddHours(3).ToString("HH:mm")),
  27040. // CreateTime = DateTime.Now,
  27041. // CreateUserId = dto.Userid,
  27042. // ParentId = 0,
  27043. // Details = "乘车前往市区(约xx公里,大约需要xx分钟)"
  27044. //});
  27045. //if (i != timeArr.Count - 1)
  27046. //{
  27047. // fallToTime = fallToTime.AddHours(2.5);
  27048. // foreach (var item in Times)
  27049. // {
  27050. // //排列公务时间
  27051. // if (fallToTime.Hour < item.Item1)
  27052. // {
  27053. // chiarr.Add(new Grp_ApprovalTravelDetails
  27054. // {
  27055. // Time = $"{item.Item2} - {item.Item3}",
  27056. // CreateTime = DateTime.Now,
  27057. // CreateUserId = dto.Userid,
  27058. // ParentId = 0,
  27059. // Details = "公务活动"
  27060. // });
  27061. // }
  27062. // }
  27063. //}
  27064. var threeCodeList = _threeCodeRepository.QueryThreeCodeArray(threeCodeStr);
  27065. var last = threeCodeStr.Last();
  27066. foreach (var item in threeCodeStr)
  27067. {
  27068. cityPath += (threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】") + "-";
  27069. if (item.Equals(last))
  27070. {
  27071. stay = threeCodeList.Keys.Contains(item) ? threeCodeList[item].City : "【未知三字码】";
  27072. }
  27073. }
  27074. cityPath = cityPath.Trim('-');
  27075. }
  27076. else
  27077. {
  27078. foreach (var item in Times)
  27079. {
  27080. chiarr.Add(new Grp_ApprovalTravelDetails
  27081. {
  27082. Time = $"{item.Item2} - {item.Item3}",
  27083. CreateTime = DateTime.Now,
  27084. CreateUserId = dto.Userid,
  27085. ParentId = 0,
  27086. Details = "公务活动"
  27087. });
  27088. }
  27089. }
  27090. string week = Day[Convert.ToInt32(NewData.DayOfWeek.ToString("d"))].ToString();
  27091. Grp_ApprovalTravel appro = new Grp_ApprovalTravel();
  27092. appro.Date = NewData.Month + "月" + NewData.Day + "日(" + week + ")" + "第" + intToString(i + 1) + "天 ";
  27093. appro.Diid = dto.Diid;
  27094. appro.CreateUserId = dto.Userid;
  27095. appro.CreateTime = DateTime.Now;
  27096. var thisId = _sqlSugar.Insertable<Grp_ApprovalTravel>(appro).ExecuteReturnIdentity();
  27097. appro.Id = thisId;
  27098. //foreach (var item in gwinfo)
  27099. //{
  27100. // Grp_ApprovalTravelDetails chi = new Grp_ApprovalTravelDetails();
  27101. // chi.Details = "拜访" + item.Client;
  27102. // if (!string.IsNullOrWhiteSpace(item.ReqSample))
  27103. // {
  27104. // chi.Details += "," + item.ReqSample;
  27105. // }
  27106. // chi.ParentId = thisId;
  27107. // chi.Time = item.Time;
  27108. // chiarr.Add(chi);
  27109. //}
  27110. if (chiarr.Count < 6)
  27111. {
  27112. for (int j = chiarr.Count; j < 6; j++)
  27113. {
  27114. chiarr.Add(new
  27115. Grp_ApprovalTravelDetails());
  27116. }
  27117. }
  27118. resultArr.Add(new
  27119. {
  27120. appro.Id,
  27121. appro.Date,
  27122. appro.Diid,
  27123. chiList = chiarr.Select(x1 => new
  27124. {
  27125. timeInterval = string.IsNullOrWhiteSpace(x1.Time) ? new string[1] : x1.Time.Split('-'),
  27126. x1.Details,
  27127. x1.ParentId,
  27128. x1.Id
  27129. })
  27130. });
  27131. }
  27132. _sqlSugar.CommitTran();
  27133. jw = JsonView(true, "生成成功!", resultArr);
  27134. }
  27135. catch (Exception ex)
  27136. {
  27137. jw.Code = 400;
  27138. jw.Msg = "生成失败!" + ex.Message;
  27139. }
  27140. return Ok(jw);
  27141. }
  27142. /// <summary>
  27143. /// 报批行程word导出
  27144. /// </summary>
  27145. /// <param name="dto"></param>
  27146. /// <returns></returns>
  27147. [HttpPost]
  27148. public IActionResult ExportApprovalJourneyWord(ExportApprovalJourneyWord dto)
  27149. {
  27150. var jw = JsonView(false);
  27151. var group = _sqlSugar.Queryable<Grp_DelegationInfo>().First(x => x.Id == dto.Diid && x.IsDel == 0);
  27152. if (group == null)
  27153. {
  27154. jw.Msg = "暂无该团组!";
  27155. return Ok(jw);
  27156. }
  27157. //模板路径
  27158. string tempPath = AppSettingsHelper.Get("WordBasePath") + "Template/";
  27159. var fileName = string.Empty;
  27160. string titleFont = string.Empty, timeFont = string.Empty, contentFont = string.Empty;
  27161. bool bold = false;
  27162. if (dto.FileIndex == 1)
  27163. {
  27164. fileName = "公务行程导出模板.docx"; //"C:\\Server\\File\\OA2023\\Office\\Word\\Template/公务行程导出模板.docx"
  27165. }
  27166. else if (dto.FileIndex == 2)
  27167. {
  27168. fileName = "省外办-报批.docx";
  27169. bold = false;
  27170. titleFont = "方正黑体简体";
  27171. timeFont = "Times New Roman";
  27172. contentFont = "方正仿宋_GBK";
  27173. }
  27174. else if (dto.FileIndex == 3)
  27175. {
  27176. fileName = "市外办-报批.docx";
  27177. titleFont = "方正黑体简体";
  27178. timeFont = "Times New Roman";
  27179. contentFont = "方正仿宋简体";
  27180. }
  27181. tempPath = tempPath + fileName;
  27182. //载入模板
  27183. Document doc = new Document(tempPath);
  27184. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  27185. //获取所填表格的序数
  27186. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  27187. Aspose.Words.Tables.Row titleRowClone = null;
  27188. Aspose.Words.Tables.Row CenterRowClone = null;
  27189. int index = 0;
  27190. int indexChi = 0;
  27191. int SetIndex = 0;
  27192. var ApprovalTravelArr = _sqlSugar.Queryable<Grp_ApprovalTravel>().Where(x => x.IsDel == 0 && x.Diid == dto.Diid).ToList();
  27193. //获取数据,放到datatable
  27194. foreach (var item in ApprovalTravelArr)
  27195. {
  27196. if (index > 0)
  27197. {
  27198. titleRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[0].Clone(true);
  27199. tableOne.AppendChild(titleRowClone);
  27200. }
  27201. var textTime = item.Date;
  27202. var ChiRep = _sqlSugar.Queryable<Grp_ApprovalTravelDetails>().Where(x => x.IsDel == 0 && x.ParentId == item.Id).ToList();
  27203. SetCells(tableOne, doc, SetIndex, 0, textTime, titleFont, bold);
  27204. SetIndex++;
  27205. if (ChiRep.Count > 0)
  27206. {
  27207. foreach (var itemChi in ChiRep)
  27208. {
  27209. var txtTime = itemChi.Time;
  27210. var txtDetail = itemChi.Details;
  27211. if (string.IsNullOrEmpty(txtTime) && string.IsNullOrEmpty(txtDetail))
  27212. {
  27213. //SetCells(tableOne, doc, SetIndex, 0, "", timeFont, bold);
  27214. //SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  27215. //indexChi++;
  27216. //SetIndex++;
  27217. break;
  27218. }
  27219. if (indexChi > 0)
  27220. {
  27221. CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  27222. tableOne.AppendChild(CenterRowClone);
  27223. }
  27224. SetCells(tableOne, doc, SetIndex, 0, txtTime, timeFont, bold);
  27225. SetCells(tableOne, doc, SetIndex, 1, txtDetail, contentFont, bold);
  27226. indexChi++;
  27227. SetIndex++;
  27228. }
  27229. }
  27230. //else
  27231. //{
  27232. // if (indexChi > 0)
  27233. // {
  27234. // CenterRowClone = (Aspose.Words.Tables.Row)tableOne.Rows[1].Clone(true);
  27235. // tableOne.AppendChild(CenterRowClone);
  27236. // }
  27237. // SetCells(tableOne, doc, SetIndex, 0, "",timeFont, bold);
  27238. // SetCells(tableOne, doc, SetIndex, 1, "", contentFont, bold);
  27239. // indexChi++;
  27240. // SetIndex++;
  27241. //}
  27242. index++;
  27243. }
  27244. string strFileName = "/Travel/ExportApprovalJourneyWord/" + group.TeamName + fileName;
  27245. doc.Save(AppSettingsHelper.Get("WordBasePath") + strFileName, Aspose.Words.SaveFormat.Docx); //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  27246. jw.Data = AppSettingsHelper.Get("WordBaseUrl") + AppSettingsHelper.Get("WordFtpPath") + strFileName; //"C:\\Server\\File\\OA2023\\Office\\Word" + strFileName
  27247. jw.Code = 200;
  27248. jw.Msg = "";
  27249. return Ok(jw);
  27250. }
  27251. private string ParseBlackTime(string time)
  27252. {
  27253. // 匹配可能只有分钟的情况
  27254. string pattern = @"(?:(\d+)H)?(?:(\d+)M)?";
  27255. System.Text.RegularExpressions.Match match = Regex.Match(time, pattern);
  27256. if (match.Success)
  27257. {
  27258. string hours = match.Groups[1].Value;
  27259. string minutes = match.Groups[2].Value;
  27260. // 如果小时部分为空,则只显示分钟
  27261. if (string.IsNullOrEmpty(hours))
  27262. {
  27263. return $"{minutes}分钟";
  27264. }
  27265. // 如果分钟部分为空,则只显示小时
  27266. else if (string.IsNullOrEmpty(minutes))
  27267. {
  27268. return $"{hours}小时";
  27269. }
  27270. // 否则显示完整格式
  27271. else
  27272. {
  27273. return $"{hours}小时{minutes}分钟";
  27274. }
  27275. }
  27276. else
  27277. {
  27278. return "未知时长";
  27279. }
  27280. }
  27281. private string intToString(int numberVal)
  27282. {
  27283. string numberval = numberVal.ToString();
  27284. Dictionary<char, string> Number = new Dictionary<char, string>();
  27285. Number.Add('1', "一");
  27286. Number.Add('2', "二");
  27287. Number.Add('3', "三");
  27288. Number.Add('4', "四");
  27289. Number.Add('5', "五");
  27290. Number.Add('6', "六");
  27291. Number.Add('7', "七");
  27292. Number.Add('8', "八");
  27293. Number.Add('9', "九");
  27294. string stringNumberVal = string.Empty;
  27295. for (int i = 0; i < numberval.Length; i++)
  27296. {
  27297. if (i == 0)
  27298. {
  27299. stringNumberVal += Number[numberval[i]];
  27300. }
  27301. else if (i >= 1)
  27302. {
  27303. if (numberval[i] == '0')
  27304. {
  27305. stringNumberVal = "十";
  27306. }
  27307. else
  27308. {
  27309. stringNumberVal += "十" + Number[numberval[i]];
  27310. }
  27311. }
  27312. }
  27313. return stringNumberVal;
  27314. }
  27315. private void SetCells(Aspose.Words.Tables.Table table, Document doc, int rows, int cells, string val, string font, bool bold)
  27316. {
  27317. //获取table中的某个单元格,从0开始
  27318. Cell lshCell = table.Rows[rows].Cells[cells];
  27319. //将单元格中段落移除
  27320. foreach (Paragraph item in lshCell.Paragraphs)
  27321. {
  27322. lshCell.Paragraphs.Remove(item);
  27323. }
  27324. if (val.Contains("\r\n"))
  27325. {
  27326. var spArr = val.Split("\r\n").Where(x => !string.IsNullOrWhiteSpace(x));
  27327. foreach (var item in spArr)
  27328. {
  27329. //新建一个段落
  27330. Paragraph p = new Paragraph(doc);
  27331. var r = new Run(doc, item);
  27332. //设置字体
  27333. if (!string.IsNullOrEmpty(font))
  27334. {
  27335. r.Font.Name = font;
  27336. }
  27337. r.Font.Bold = bold;
  27338. //把设置的值赋给之前新建的段落
  27339. p.AppendChild(r);
  27340. //将此段落加到单元格内
  27341. lshCell.AppendChild(p);
  27342. }
  27343. }
  27344. else
  27345. {
  27346. //新建一个段落
  27347. Paragraph p = new Paragraph(doc);
  27348. var r = new Run(doc, val);
  27349. //设置字体
  27350. if (!string.IsNullOrEmpty(font))
  27351. {
  27352. r.Font.Name = font;
  27353. }
  27354. r.Font.Bold = bold;
  27355. //把设置的值赋给之前新建的段落
  27356. p.AppendChild(r);
  27357. //将此段落加到单元格内
  27358. lshCell.AppendChild(p);
  27359. }
  27360. }
  27361. /// <summary>
  27362. /// 报批行程AI续写
  27363. /// </summary>
  27364. /// <returns></returns>
  27365. [HttpPost]
  27366. public async Task<IActionResult> ApprovalJourneyAiWrite(ApprovalJourneyAiWriteDto dto)
  27367. {
  27368. var jw = JsonView(false);
  27369. if (dto.ClientPurpose.IsNullOrWhiteSpace() || dto.ClientName.IsNullOrWhiteSpace())
  27370. {
  27371. jw.Msg = "参数有误!";
  27372. return Ok(jw);
  27373. }
  27374. KiMiApiClient kiMi = new KiMiApiClient();
  27375. List<SeedMessages> messages = new List<SeedMessages>() {
  27376. new SeedMessages
  27377. {
  27378. Role = KimiRole.system,
  27379. Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。"
  27380. },
  27381. new SeedMessages
  27382. {
  27383. Role = KimiRole.user,
  27384. Content = $@"参考这个模板格式来编写一份{dto.ClientName}拜访{dto.ClientPurpose},结合{dto.ClientName}的业务,描述拜访目的,字数在200字内(直接给出拜访目的,不输出其他内容)"
  27385. }
  27386. };
  27387. var kimi_result = await kiMi.SeedMessageByFullConterObject(messages);
  27388. string data = kimi_result.Choices[0]?.Message.Content;
  27389. if (string.IsNullOrWhiteSpace(data))
  27390. {
  27391. jw.Data = "Ai续写失败!";
  27392. }
  27393. else
  27394. {
  27395. jw = JsonView(true, "success!", data);
  27396. }
  27397. return Ok(jw);
  27398. }
  27399. #endregion
  27400. #region 团组接待意见调查
  27401. /// <summary>
  27402. /// 团组接待意见调查 - 信息管理
  27403. /// 基础数据(团组)
  27404. /// </summary>
  27405. /// <returns></returns>
  27406. [HttpGet]
  27407. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27408. public async Task<IActionResult> OpinionaireInit()
  27409. {
  27410. var groupData = await _groupRepository.Query(x => x.IsDel == 0)
  27411. .Select(x => new
  27412. {
  27413. x.Id,
  27414. GroupName = $"[{x.VisitDate.ToString("yyyy-MM-dd")}]{x.TeamName}"
  27415. })
  27416. .OrderByDescending(x => x.Id)
  27417. .ToListAsync();
  27418. return Ok(JsonView(groupData, groupData.Count));
  27419. }
  27420. /// <summary>
  27421. /// 团组接待意见调查 - 信息管理
  27422. /// 列表
  27423. /// </summary>
  27424. /// <param name="groupId"></param>
  27425. /// <returns></returns>
  27426. [HttpGet("{groupId}")]
  27427. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27428. public async Task<IActionResult> OpinionaireManageList(int groupId)
  27429. {
  27430. if (groupId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27431. var data = await _opinionaireRep.Query(x => x.DiId == groupId)
  27432. .Select(x => new
  27433. {
  27434. x.Id,
  27435. x.TourGuideName,
  27436. x.CityName,
  27437. CreateUserName = SqlFunc.Subqueryable<Sys_Users>().Where(x1 => x.CreateUserId == x1.Id).Select(x1 => x1.CnName),
  27438. x.CreateTime
  27439. })
  27440. .OrderBy(x => x.Id)
  27441. .ToListAsync();
  27442. return Ok(JsonView(data));
  27443. }
  27444. /// <summary>
  27445. /// 团组接待意见调查 - 信息管理
  27446. /// 保存
  27447. /// </summary>
  27448. /// <param name="dto"></param>
  27449. /// <returns></returns>
  27450. [HttpPost]
  27451. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27452. public async Task<IActionResult> OpinionaireManageSave(OpinionaireManageSaveDto dto)
  27453. {
  27454. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  27455. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  27456. if (dto.DiId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27457. if (dto.Items.Length < 1) Ok(JsonView(false, "请传入需要保存的信息"));
  27458. var addData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id == 0).ToList());
  27459. var updData = _mapper.Map<List<Grp_Opinionaire>>(dto.Items.Where(x => x.Id > 0).ToList());
  27460. _opinionaireRep.BeginTran();
  27461. if (addData != null && addData.Count > 0)
  27462. {
  27463. foreach (var item in addData)
  27464. {
  27465. item.CreateUserId = currUserInfo.UserId;
  27466. item.DiId = dto.DiId;
  27467. }
  27468. var add = await _opinionaireRep._sqlSugar.Insertable(addData).ExecuteCommandAsync();
  27469. }
  27470. if (updData != null && updData.Count > 0)
  27471. {
  27472. var upd = await _opinionaireRep._sqlSugar
  27473. .Updateable(updData)
  27474. .UpdateColumns(x => new { x.CityName, x.TourGuideName })
  27475. .WhereColumns(x => new { x.Id })
  27476. .ExecuteCommandAsync();
  27477. }
  27478. _opinionaireRep.CommitTran();
  27479. return Ok(JsonView("操作成功!"));
  27480. }
  27481. /// <summary>
  27482. /// 团组接待意见调查 - 信息管理
  27483. /// 删除
  27484. /// </summary>
  27485. /// <param name="id"></param>
  27486. /// <returns></returns>
  27487. [HttpDelete("{id}")]
  27488. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27489. public async Task<IActionResult> OpinionaireManageDel(int id)
  27490. {
  27491. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  27492. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  27493. if (id < 1) Ok(JsonView(false, "请传入有效的id"));
  27494. var del = await _opinionaireRep.SoftDeleteAsync(x => x.Id == id, currUserInfo.UserId);
  27495. if (!del) return Ok(JsonView("操作失败!"));
  27496. return Ok(JsonView("操作成功!"));
  27497. }
  27498. /// <summary>
  27499. /// 团组接待意见调查 - 用户
  27500. /// 列表
  27501. /// </summary>
  27502. /// <param name="diId"></param>
  27503. /// <returns></returns>
  27504. [HttpGet("{diId}")]
  27505. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27506. public async Task<IActionResult> OpinionaireUserList(int diId)
  27507. {
  27508. if (diId < 1) Ok(JsonView(false, "请传入有效的diId"));
  27509. var sql = string.Format(@"
  27510. SELECT
  27511. o.Id,
  27512. o.DiId,
  27513. di.TeamName AS 'GroupName',
  27514. di.VisitPNumber AS 'PeopleNumber',
  27515. di.ClientName AS 'LeadGroup',
  27516. di.VisitCountry AS 'Travel',
  27517. di.VisitDays AS 'Days',
  27518. o.CityName,
  27519. o.TourGuideName,
  27520. o.Catering,
  27521. o.CateringReason,
  27522. o.Stay,
  27523. o.StayReason,
  27524. o.[Route],
  27525. o.RouteReason,
  27526. o.OfficialActivity,
  27527. o.OfficialActivityReason,
  27528. o.TourGuide,
  27529. o.TourGuideReason,
  27530. o.[Translate],
  27531. o.TranslateReason,
  27532. o.Trip,
  27533. o.TripReason,
  27534. o.ESFileName,
  27535. o.SignatureDate,
  27536. o.Remark
  27537. FROM
  27538. Grp_Opinionaire o
  27539. LEFT JOIN Grp_DelegationInfo di ON o.DiId = di.Id
  27540. WHERE
  27541. o.IsDel = 0
  27542. AND o.DiId = {0}
  27543. ORDER BY
  27544. o.Id ASC", diId);
  27545. var data = await _sqlSugar.SqlQueryable<OpinionaireUserListView>(sql).ToListAsync();
  27546. if (data.Count < 1) return Ok(JsonView(false, "暂无数据"));
  27547. return Ok(JsonView(data));
  27548. }
  27549. /// <summary>
  27550. /// 团组接待意见调查 - 用户
  27551. /// 保存
  27552. /// </summary>
  27553. /// <param name="dto"></param>
  27554. /// <returns></returns>
  27555. [HttpPost]
  27556. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27557. public async Task<IActionResult> OpinionaireUserSave([FromForm] OpinionaireUserSaveInfo[] dto)
  27558. {
  27559. if (dto.Length < 1) Ok(JsonView(false, "请传入有效的参数"));
  27560. foreach (var item in dto)
  27561. {
  27562. if (string.IsNullOrEmpty(item.Catering)) Ok(JsonView(false, "请选择餐饮评分!"));
  27563. if (string.IsNullOrEmpty(item.Stay)) Ok(JsonView(false, "请选择住宿评分!"));
  27564. if (string.IsNullOrEmpty(item.Route)) Ok(JsonView(false, "请选择行程评分!"));
  27565. if (string.IsNullOrEmpty(item.OfficialActivity)) Ok(JsonView(false, "请选择公务活动评分!"));
  27566. if (string.IsNullOrEmpty(item.Translate)) Ok(JsonView(false, "请选择翻译评分!"));
  27567. if (string.IsNullOrEmpty(item.Trip)) Ok(JsonView(false, "请选择行程评分!"));
  27568. if (string.IsNullOrEmpty(item.SignatureDate)) Ok(JsonView(false, "请填写签名日期!"));
  27569. if (item.File.Length < 1) Ok(JsonView(false, "请上传签名图片!"));
  27570. }
  27571. var filePathBase = $"{AppSettingsHelper.Get("GrpFileBasePath")}OpinionaireElectronicSignature";
  27572. if (!Directory.Exists(filePathBase))
  27573. {
  27574. Directory.CreateDirectory(filePathBase);
  27575. }
  27576. #region 上传文件
  27577. var filePaths = new List<string>();
  27578. foreach (var item in dto)
  27579. {
  27580. var file = item.File;
  27581. // 将文件保存到指定位置
  27582. var filePath = Path.Combine(filePathBase, file.FileName);
  27583. using (var stream = new FileStream(filePath, FileMode.Create))
  27584. {
  27585. await file.CopyToAsync(stream);
  27586. }
  27587. //验证文件是否上传成功
  27588. if (!System.IO.File.Exists(filePath))
  27589. {
  27590. foreach (var filePathStr in filePaths)
  27591. {
  27592. System.IO.File.Delete(filePathStr);
  27593. }
  27594. return Ok(JsonView(false, "文件上传失败!"));
  27595. }
  27596. item.ESFileName = file.FileName;
  27597. }
  27598. #endregion
  27599. var infos = _mapper.Map<List<Grp_Opinionaire>>(dto);
  27600. var upd = await _sqlSugar.Updateable<Grp_Opinionaire>(infos)
  27601. .UpdateColumns(x => new
  27602. {
  27603. x.Catering,
  27604. x.CateringReason,
  27605. x.Stay,
  27606. x.StayReason,
  27607. x.Route,
  27608. x.RouteReason,
  27609. x.OfficialActivity,
  27610. x.OfficialActivityReason,
  27611. x.TourGuide,
  27612. x.TourGuideReason,
  27613. x.Translate,
  27614. x.TranslateReason,
  27615. x.Trip,
  27616. x.TripReason,
  27617. x.ESFileName,
  27618. x.SignatureDate,
  27619. x.Remark
  27620. })
  27621. .WhereColumns(x => new { x.Id })
  27622. .ExecuteCommandAsync();
  27623. if (upd < 1)
  27624. {
  27625. foreach (var filePathStr in filePaths)
  27626. {
  27627. System.IO.File.Delete(filePathStr);
  27628. }
  27629. return Ok(JsonView(false));
  27630. }
  27631. return Ok(JsonView(true));
  27632. }
  27633. #endregion
  27634. #region 团组餐厅相关信息
  27635. /// <summary>
  27636. /// 团组相关餐厅信息
  27637. /// 基础数据(团组)
  27638. /// </summary>
  27639. /// <returns></returns>
  27640. [HttpGet]
  27641. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27642. public async Task<IActionResult> RestaurantInit()
  27643. {
  27644. return Ok(await _restaurantRep.InitAsync());
  27645. }
  27646. /// <summary>
  27647. /// 团组相关餐厅信息
  27648. /// Item
  27649. /// </summary>
  27650. /// <param name="dto"></param>
  27651. /// <returns></returns>
  27652. [HttpPost]
  27653. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27654. public async Task<IActionResult> RestaurantItem(RestaurantItemDto dto)
  27655. {
  27656. int portType = dto.PortType,
  27657. groupId = dto.GroupId;
  27658. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27659. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27660. return Ok(await _restaurantRep.ItemAsync(portType, groupId));
  27661. }
  27662. /// <summary>
  27663. /// 团组相关餐厅信息
  27664. /// List
  27665. /// </summary>
  27666. /// <param name="dto"></param>
  27667. /// <returns></returns>
  27668. [HttpPost]
  27669. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27670. public async Task<IActionResult> RestaurantList(RestaurantItemDto dto)
  27671. {
  27672. int portType = dto.PortType,
  27673. groupId = dto.GroupId;
  27674. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27675. if (groupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27676. var sql = string.Format(@" SELECT
  27677. ri.Id,
  27678. ri.GroupId,
  27679. ri.Date,
  27680. ri.StartTime,
  27681. ri.EndTime,
  27682. CASE WHEN ri.Type = 1 THEN '早餐'
  27683. WHEN ri.Type = 2 THEN '午餐'
  27684. WHEN ri.Type = 3 THEN '晚餐'
  27685. ELSE '其他'
  27686. END AS 'Type',
  27687. ri.Name,
  27688. ri.Address,
  27689. ri.Tel,
  27690. ri.Remark,
  27691. ri.CreateTime,
  27692. u.CnName AS CreateUserName
  27693. FROM
  27694. Grp_RestaurantInfo ri
  27695. LEFT JOIN Sys_Users u ON ri.CreateUserId = u.Id
  27696. WHERE
  27697. ri.IsDel = 0
  27698. AND ri.GroupId = {0}
  27699. ORDER BY
  27700. ri.Date ASC
  27701. ", groupId);
  27702. var infos = await _sqlSugar.SqlQueryable<RestaurantItemView>(sql).ToListAsync();
  27703. if (!infos.Any()) Ok(JsonView(false, "数据未填写!"));
  27704. return Ok(JsonView(infos));
  27705. }
  27706. /// <summary>
  27707. /// 团组相关餐厅信息
  27708. /// Info
  27709. /// </summary>
  27710. /// <param name="dto"></param>
  27711. /// <returns></returns>
  27712. [HttpPost]
  27713. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27714. public async Task<IActionResult> RestaurantInfo(RestaurantInfoDto dto)
  27715. {
  27716. int portType = dto.PortType,
  27717. id = dto.Id;
  27718. if (!SharingStaticData.PortTypes.Contains(portType)) return Ok(JsonView(false, MsgTips.Port));
  27719. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  27720. return Ok(await _restaurantRep.InfoAsync(portType, id));
  27721. }
  27722. /// <summary>
  27723. /// 团组相关餐厅信息
  27724. /// Op
  27725. /// </summary>
  27726. /// <param name="dto"></param>
  27727. /// <returns></returns>
  27728. [HttpPost]
  27729. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27730. public async Task<IActionResult> RestaurantOp(RestaurantOpDto dto)
  27731. {
  27732. if (dto.CurrUserId < 1) return Ok(JsonView(false, MsgTips.UserId));
  27733. if (dto.GroupId < 1) return Ok(JsonView(false, MsgTips.DiId));
  27734. if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "餐厅名称为空!"));
  27735. return Ok(await _restaurantRep.OpAsync(dto));
  27736. }
  27737. /// <summary>
  27738. /// 团组相关餐厅信息
  27739. /// Del
  27740. /// </summary>
  27741. /// <param name="dto"></param>
  27742. /// <returns></returns>
  27743. [HttpPost]
  27744. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  27745. public async Task<IActionResult> RestaurantDel(RestaurantDelDto dto)
  27746. {
  27747. int userId = dto.DeleteUserId;
  27748. var id = dto.Id;
  27749. if (userId < 1) return Ok(JsonView(false, MsgTips.UserId));
  27750. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  27751. return Ok(await _restaurantRep.DelAsync(dto));
  27752. }
  27753. #endregion
  27754. #region 团组会务成本
  27755. /// <summary>
  27756. /// 团组会务成本数据初始化
  27757. /// </summary>
  27758. /// <returns></returns>
  27759. [HttpPost]
  27760. public async Task<IActionResult> ConferenceAffairsInIt(ConferenceAffairsInItDto Dto)
  27761. {
  27762. var hwids = _sqlSugar.Queryable<Sys_SetData>()
  27763. .Where(x => x.IsDel == 0 && x.STid == 10 && x.Name.Contains("会务活动"))
  27764. .Select(x => x.Id)
  27765. .ToList();
  27766. var expr = _sqlSugar.Queryable<Grp_DelegationInfo>()
  27767. .OrderByDescending(x => x.CreateTime)
  27768. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  27769. .Select<DelegationEasyView>();
  27770. DelegationEasyView di = Dto.GroupId == 0 ?
  27771. expr.First() :
  27772. expr.First(x => x.Id == Dto.GroupId);
  27773. if (di == null)
  27774. {
  27775. return Ok(JsonView(false, "团组信息不存在!"));
  27776. }
  27777. var typeData = await _sqlSugar.Queryable<Sys_SetData>()
  27778. .Where(x => x.IsDel == 0 && x.STid == 21)
  27779. .Select(x => new { x.Id, Text = x.Name })
  27780. .ToListAsync();
  27781. //仅检索会务团组
  27782. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  27783. .Where(x => x.IsDel == 0 && hwids.Contains(x.TeamDid))
  27784. .OrderByDescending(x => x.VisitDate)
  27785. .Select(x => new { x.Id, x.TeamName })
  27786. .ToListAsync();
  27787. var currenyList = await GeneralMethod.PostGroupTeamRateByDiIdAndCTableId(1, di.Id, 98);
  27788. var userList = await _sqlSugar.Queryable<Sys_Users>()
  27789. .Where(x => x.IsDel == 0)
  27790. .Select(x => new { x.Id, x.CnName })
  27791. .ToListAsync();
  27792. var units = await _sqlSugar.Queryable<Sys_SetData>()
  27793. .Where(x => x.IsDel == 0 && x.STid == 119)
  27794. .Select(x => new { x.Id, Text = x.Name })
  27795. .ToListAsync();
  27796. var FileType = new[]
  27797. {
  27798. new { Id = 0 , Name = "成本下载" },
  27799. new { Id = 1 , Name = "报价下载" },
  27800. new { Id = 2 , Name = "总表下载" },
  27801. };
  27802. var GM = new List<int>();
  27803. var permissionControlDB = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1448)?.Remark;
  27804. try
  27805. {
  27806. GM = JsonConvert.DeserializeObject<List<int>>(permissionControlDB);
  27807. }
  27808. catch (Exception ex)
  27809. {
  27810. GM = new List<int>() { 21 };
  27811. }
  27812. var isReview = Dto.UserId == 21;
  27813. var isGM = GM.Contains(Dto.UserId);
  27814. var ConferenceAffairsCost = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  27815. .Where(x => x.IsDel == 0)
  27816. .First(x => x.Diid == di.Id);
  27817. if (ConferenceAffairsCost == null)
  27818. {
  27819. //插入主表数据
  27820. ConferenceAffairsCost = new Grp_ConferenceAffairsCost()
  27821. {
  27822. Diid = di.Id,
  27823. CreateTime = DateTime.Now,
  27824. CreateUserId = Dto.UserId,
  27825. IsDel = 0,
  27826. AllocationAmount = 0,
  27827. AllocationCurrency = 836,
  27828. AllocationRate = 0,
  27829. AllocationGroupId = di.Id,
  27830. CostAll = 0,
  27831. BaoJiaAll = 0,
  27832. MostCurr = 836,
  27833. Remark = "",
  27834. City = "",
  27835. };
  27836. ConferenceAffairsCost.Id = _sqlSugar.Insertable(ConferenceAffairsCost).ExecuteReturnIdentity();
  27837. }
  27838. #region 权限校验
  27839. var ids = _sqlSugar.Queryable<Grp_ConferenceAffairsCostControl>()
  27840. .Where(x => x.Diid == di.Id && x.IsDel == 0)
  27841. .Select(x => x.UserId)
  27842. .Distinct()
  27843. .ToList();
  27844. if (!ids.Contains(Dto.UserId) && !isGM)
  27845. {
  27846. return Ok(JsonView(201, "暂无权限!", new
  27847. {
  27848. typeData,
  27849. groupList,
  27850. currenyList,
  27851. isGM,
  27852. userList,
  27853. units,
  27854. isReview,
  27855. operatorUser = ids,
  27856. di,
  27857. FileType
  27858. }));
  27859. }
  27860. #endregion
  27861. var ConferenceAffairsCostChi = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  27862. .Where(x => x.IsDel == 0 && x.Diid == di.Id)
  27863. .Select<ConferenceAffairsCostChildView>()
  27864. .OrderBy(x => x.Index)
  27865. .ToList();
  27866. for (int i = 1; i <= ConferenceAffairsCostChi.Count; i++)
  27867. {
  27868. ConferenceAffairsCostChi[i - 1].Index = i;
  27869. }
  27870. var ConferenceAffairsCostMap = _mapper.Map<ConferenceAffairsCostView>(ConferenceAffairsCost);
  27871. var backData = new
  27872. {
  27873. ConferenceAffairsCost = ConferenceAffairsCostMap,
  27874. ConferenceAffairsCostChi,
  27875. typeData,
  27876. groupList,
  27877. currenyList,
  27878. isGM,
  27879. userList,
  27880. units,
  27881. isReview,
  27882. operatorUser = ids,
  27883. di,
  27884. FileType
  27885. };
  27886. return Ok(JsonView(true, "SUCCESS", backData));
  27887. }
  27888. [HttpPost]
  27889. public async Task<IActionResult> ConferenceAffairsChildAddRowReturnId(ConferenceAffairsChildAddRowReturnIdDto dto)
  27890. {
  27891. var data = _mapper.Map<Grp_ConferenceAffairsCostChild>(dto.data);
  27892. var id = await _sqlSugar.Insertable(data).ExecuteReturnIdentityAsync();
  27893. return Ok(JsonView(true, "SUCCESS", new { id }));
  27894. }
  27895. /// <summary>
  27896. /// 会务成本从表新增行
  27897. /// </summary>
  27898. /// <param name="Dto"></param>
  27899. /// <returns></returns>
  27900. [HttpPost]
  27901. public async Task<IActionResult> ConferenceAffairsChildAddRow(ConferenceAffairsChildAddRowDto Dto)
  27902. {
  27903. if (Dto.diid < 1) return Ok(JsonView(false, "团组id有误!"));
  27904. if (Dto.userId < 1) return Ok(JsonView(false, "用户id有误!"));
  27905. var queryList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  27906. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  27907. .OrderByDescending(x => x.Index)
  27908. .ToList();
  27909. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  27910. .Where(x => x.IsDel == 0 && x.Diid == Dto.diid)
  27911. .First();
  27912. if (queryData == null)
  27913. {
  27914. return Ok(JsonView(false, "会务成本主表不存在!"));
  27915. }
  27916. var child = new Grp_ConferenceAffairsCostChild();
  27917. child.Diid = Dto.diid;
  27918. child.CreateTime = DateTime.Now;
  27919. child.CreateUserId = Dto.userId;
  27920. child.IsDel = 0;
  27921. child.Index = queryList.Count + 1;
  27922. child.ConferenceAffairsCostId = queryData.Id;
  27923. child.PriceType = 0;
  27924. child.PriceName = "";
  27925. child.CostPrice = 0;
  27926. child.Currency = 836;
  27927. child.Rate = 0;
  27928. child.Count = 0;
  27929. child.Unit = 0;
  27930. child.Coefficient = 0;
  27931. child.BaoJiaPrice = 0;
  27932. child.AddedValue = 0;
  27933. child.Details = "";
  27934. child.ReviewStatus = 0;
  27935. child.Imgs = "";
  27936. child.Id = _sqlSugar.Insertable(child).ExecuteReturnIdentity();
  27937. var result = new
  27938. {
  27939. index = queryList.Count + 1,
  27940. priceType = "",
  27941. priceName = "",
  27942. costPrice = 0m,
  27943. currency = 836,
  27944. rate = 1m,
  27945. count = 0,
  27946. unit = "",
  27947. coefficient = 0m,
  27948. baoJiaPrice = 0m,
  27949. addedValue = 0m,
  27950. details = "",
  27951. reviewStatus = 0,
  27952. diid = Dto.diid,
  27953. imgs = "",
  27954. imgsList = new List<string>(),
  27955. id = child.Id,
  27956. remark = ""
  27957. };
  27958. return Ok(JsonView(true, "新增成功!", result));
  27959. }
  27960. /// <summary>
  27961. /// 会务成本从表图片文件上传
  27962. /// </summary>
  27963. /// <param name="Dto"></param>
  27964. /// <returns></returns>
  27965. [HttpPost]
  27966. public async Task<IActionResult> ConferenceAffairsChildImageUpload([FromForm] ConferenceAffairsChildImageUploadDto Dto)
  27967. {
  27968. try
  27969. {
  27970. if (Dto == null || Dto.Files == null || Dto.Files.Count == 0)
  27971. {
  27972. return Ok(JsonView(false, "请选择要上传的图片文件!"));
  27973. }
  27974. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  27975. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  27976. .First();
  27977. if (child == null)
  27978. {
  27979. return Ok(JsonView(false, "会务成本从表不存在!"));
  27980. }
  27981. // 允许的图片类型
  27982. var allowedImageTypes = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp" };
  27983. var allowedContentTypes = new[] { "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp" };
  27984. // 获取配置路径
  27985. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  27986. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  27987. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  27988. // 确保路径以/结尾
  27989. if (!baseUrl.EndsWith("/"))
  27990. {
  27991. baseUrl = baseUrl.TrimEnd('/') + "/";
  27992. }
  27993. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  27994. {
  27995. basePath = basePath.TrimEnd('\\', '/') + "\\";
  27996. }
  27997. // 创建保存目录(按childId分目录)
  27998. string saveDir = Path.Combine(basePath, "child", child.Id.ToString());
  27999. if (!Directory.Exists(saveDir))
  28000. {
  28001. Directory.CreateDirectory(saveDir);
  28002. }
  28003. var uploadedImageUrls = new List<string>();
  28004. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  28005. ? new List<string>()
  28006. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  28007. foreach (var file in Dto.Files)
  28008. {
  28009. if (file == null || file.Length == 0)
  28010. {
  28011. continue;
  28012. }
  28013. // 验证文件扩展名
  28014. var fileExtension = Path.GetExtension(file.FileName).ToLowerInvariant();
  28015. if (string.IsNullOrEmpty(fileExtension) || !allowedImageTypes.Contains(fileExtension))
  28016. {
  28017. return Ok(JsonView(false, $"文件 {file.FileName} 不是支持的图片格式,仅支持:{string.Join("、", allowedImageTypes)}"));
  28018. }
  28019. // 验证ContentType
  28020. if (!string.IsNullOrEmpty(file.ContentType) && !allowedContentTypes.Contains(file.ContentType.ToLowerInvariant()))
  28021. {
  28022. return Ok(JsonView(false, $"文件 {file.FileName} 的ContentType不正确,不是图片类型"));
  28023. }
  28024. // 获取原始文件名(不含扩展名)和扩展名
  28025. string originalFileName = Path.GetFileNameWithoutExtension(file.FileName);
  28026. string fileName = file.FileName;
  28027. string filePath = Path.Combine(saveDir, fileName);
  28028. // 如果文件已存在,添加计数后缀
  28029. int count = 0;
  28030. while (System.IO.File.Exists(filePath))
  28031. {
  28032. count++;
  28033. fileName = $"{originalFileName}({count}){fileExtension}";
  28034. filePath = Path.Combine(saveDir, fileName);
  28035. }
  28036. // 保存文件
  28037. using (var stream = new FileStream(filePath, FileMode.Create))
  28038. {
  28039. await file.CopyToAsync(stream);
  28040. }
  28041. // 生成完整URL路径
  28042. string imageUrl = $"{baseUrl}{ftpPath}child/{child.Id}/{fileName}";
  28043. uploadedImageUrls.Add(imageUrl);
  28044. }
  28045. if (uploadedImageUrls.Count == 0)
  28046. {
  28047. return Ok(JsonView(false, "没有成功上传任何图片!"));
  28048. }
  28049. // 合并现有图片路径和新上传的图片路径
  28050. existingImgs.AddRange(uploadedImageUrls);
  28051. string updatedImgs = string.Join(",", existingImgs);
  28052. // 更新数据库
  28053. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  28054. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  28055. .Where(x => x.Id == child.Id)
  28056. .ExecuteCommand();
  28057. return Ok(JsonView(true, $"成功上传 {uploadedImageUrls.Count} 张图片", uploadedImageUrls));
  28058. }
  28059. catch (Exception ex)
  28060. {
  28061. return Ok(JsonView(false, $"上传失败:{ex.Message}"));
  28062. }
  28063. }
  28064. /// <summary>
  28065. /// 根据文件名和从表id删除对应的图片
  28066. /// </summary>
  28067. /// <param name="Dto"></param>
  28068. /// <returns></returns>
  28069. [HttpPost]
  28070. public async Task<IActionResult> ConferenceAffairsChildImageDelete(ConferenceAffairsChildImageDeleteDto Dto)
  28071. {
  28072. if (Dto == null || Dto.fileNames == null || Dto.fileNames.Count == 0)
  28073. {
  28074. return Ok(JsonView(false, "请提供要删除的文件名列表!"));
  28075. }
  28076. var child = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  28077. .Where(x => x.IsDel == 0 && x.Id == Dto.childId)
  28078. .First();
  28079. if (child == null)
  28080. {
  28081. return Ok(JsonView(false, "会务成本id有误!"));
  28082. }
  28083. var existingImgs = string.IsNullOrWhiteSpace(child.Imgs)
  28084. ? new List<string>()
  28085. : child.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  28086. // 获取配置路径
  28087. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  28088. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  28089. string ftpPath = AppSettingsHelper.Get("ConferenceCostImageFtpPath");
  28090. // 确保路径格式正确
  28091. if (!baseUrl.EndsWith("/"))
  28092. {
  28093. baseUrl = baseUrl.TrimEnd('/') + "/";
  28094. }
  28095. if (!basePath.EndsWith("\\") && !basePath.EndsWith("/"))
  28096. {
  28097. basePath = basePath.TrimEnd('\\', '/') + "\\";
  28098. }
  28099. if (!ftpPath.EndsWith("/"))
  28100. {
  28101. ftpPath = ftpPath.TrimEnd('/') + "/";
  28102. }
  28103. int deletedCount = 0;
  28104. var expectedUrlPrefix = $"{baseUrl}{ftpPath}child/{child.Id}/";
  28105. var fileDir = Path.Combine(basePath, "child", child.Id.ToString());
  28106. // 遍历要删除的文件名列表
  28107. foreach (var fileNameOrUrl in Dto.fileNames)
  28108. {
  28109. if (string.IsNullOrWhiteSpace(fileNameOrUrl))
  28110. {
  28111. continue;
  28112. }
  28113. string fileName = fileNameOrUrl;
  28114. string fullUrl = fileNameOrUrl;
  28115. // 判断是完整URL还是文件名
  28116. if (fileNameOrUrl.StartsWith("http://") || fileNameOrUrl.StartsWith("https://"))
  28117. {
  28118. // 是完整URL,提取文件名
  28119. try
  28120. {
  28121. var uri = new Uri(fileNameOrUrl);
  28122. fileName = Path.GetFileName(uri.AbsolutePath);
  28123. // 如果URL包含child/{childId}/路径,使用完整URL匹配
  28124. if (fileNameOrUrl.Contains($"/child/{child.Id}/"))
  28125. {
  28126. fullUrl = fileNameOrUrl;
  28127. }
  28128. else
  28129. {
  28130. // URL格式不匹配,尝试构造完整URL
  28131. fullUrl = $"{expectedUrlPrefix}{fileName}";
  28132. }
  28133. }
  28134. catch
  28135. {
  28136. // URL解析失败,当作文件名处理
  28137. fileName = Path.GetFileName(fileNameOrUrl);
  28138. fullUrl = $"{expectedUrlPrefix}{fileName}";
  28139. }
  28140. }
  28141. else
  28142. {
  28143. // 是文件名,构造完整URL用于匹配
  28144. fullUrl = $"{expectedUrlPrefix}{fileName}";
  28145. }
  28146. // 从现有图片列表中移除(支持完整URL匹配或文件名匹配)
  28147. var removed = existingImgs.RemoveAll(img =>
  28148. img.Equals(fullUrl, StringComparison.OrdinalIgnoreCase) ||
  28149. img.Equals(fileNameOrUrl, StringComparison.OrdinalIgnoreCase) ||
  28150. img.EndsWith($"/{fileName}", StringComparison.OrdinalIgnoreCase));
  28151. if (removed > 0)
  28152. {
  28153. deletedCount++;
  28154. }
  28155. // 删除磁盘上的文件
  28156. var filePath = Path.Combine(fileDir, fileName);
  28157. if (System.IO.File.Exists(filePath))
  28158. {
  28159. try
  28160. {
  28161. System.IO.File.Delete(filePath);
  28162. }
  28163. catch (Exception ex)
  28164. {
  28165. _logger.LogError(ex, "删除图片失败:{fileName}", fileName);
  28166. }
  28167. }
  28168. }
  28169. if (deletedCount == 0)
  28170. {
  28171. return Ok(JsonView(false, "没有找到要删除的图片!"));
  28172. }
  28173. // 更新数据库
  28174. var updatedImgs = string.Join(",", existingImgs);
  28175. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  28176. .SetColumns(x => new Grp_ConferenceAffairsCostChild { Imgs = updatedImgs })
  28177. .Where(x => x.Id == child.Id)
  28178. .ExecuteCommand();
  28179. return Ok(JsonView(true, $"成功删除 {deletedCount} 张图片", updatedImgs));
  28180. }
  28181. /// <summary>
  28182. /// 会务流程word下载
  28183. /// </summary>
  28184. /// <param name="Dto"></param>
  28185. /// <returns></returns>
  28186. [HttpPost]
  28187. public async Task<IActionResult> InspectionReportFileDown(InspectionReportFileDownDto Dto)
  28188. {
  28189. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  28190. .Where(x => x.IsDel == 0 && x.Id == Dto.Diid)
  28191. .First();
  28192. if (di == null)
  28193. {
  28194. return Ok(JsonView(false, "团组信息不存在!"));
  28195. }
  28196. //书签dic
  28197. var bookmarks = new Dictionary<string, string>();
  28198. bookmarks.Add("TeamName", di.TeamName);
  28199. bookmarks.Add("TeamName1", di.TeamName);
  28200. bookmarks.Add("ClientUnit", di.ClientUnit);
  28201. bookmarks.Add("ClientUnit1", di.ClientUnit);
  28202. bookmarks.Add("thisTime", DateTime.Now.ToString("yyyy年MM月dd日"));
  28203. //读取word模板
  28204. var templatePath = $"{AppSettingsHelper.Get("WordBasePath")}/template/活动验收报告.docx";
  28205. var doc = new Document(templatePath);
  28206. var chiList = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  28207. .Where(x => x.IsDel == 0 && x.Diid == Dto.Diid && x.PriceType > 0 && x.Unit > 0)
  28208. .Select(x => new
  28209. {
  28210. x.Index,
  28211. x.PriceName,
  28212. PriceType = SqlFunc.Subqueryable<Sys_SetData>().Where(y => y.IsDel == 0 && y.Id == x.PriceType).Select(y => y.Name),
  28213. x.Count,
  28214. x.Remark,
  28215. x.Imgs
  28216. })
  28217. .OrderBy(x => x.Index)
  28218. .ToList();
  28219. //获取word所有表格
  28220. var allTables = doc.GetChildNodes(NodeType.Table, true);
  28221. //获取word第一个表格
  28222. var table = allTables[0] as Aspose.Words.Tables.Table;
  28223. //内容行索引
  28224. var startIndex = 2;
  28225. var copyRow = table.Rows[startIndex].Clone(true);
  28226. for (int i = 0; i < chiList.Count; i++)
  28227. {
  28228. var chi = chiList[i];
  28229. //插入复制的行(从第2次开始插入新行,第1次使用模板行)
  28230. if (i > 0)
  28231. {
  28232. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  28233. table.Rows.Insert(startIndex, newRow);
  28234. }
  28235. //word 表格 赋值
  28236. var row = table.Rows[startIndex];
  28237. row.Cells[0].FirstParagraph.Runs.Clear();
  28238. row.Cells[0].FirstParagraph.AppendChild(new Run(doc, (i + 1).ToString()));
  28239. row.Cells[1].FirstParagraph.Runs.Clear();
  28240. row.Cells[1].FirstParagraph.AppendChild(new Run(doc, chi.PriceName));
  28241. row.Cells[2].FirstParagraph.Runs.Clear();
  28242. row.Cells[2].FirstParagraph.AppendChild(new Run(doc, chi.PriceType));
  28243. row.Cells[3].FirstParagraph.Runs.Clear();
  28244. row.Cells[3].FirstParagraph.AppendChild(new Run(doc, chi.Count.ToString()));
  28245. row.Cells[4].FirstParagraph.Runs.Clear();
  28246. row.Cells[4].FirstParagraph.AppendChild(new Run(doc, chi.Remark));
  28247. if (!string.IsNullOrWhiteSpace(chi.Imgs))
  28248. {
  28249. var imgs = chi.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  28250. if (imgs.Length > 0)
  28251. {
  28252. // 获取图片基础路径配置
  28253. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  28254. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  28255. // 按图片方向分类,同时缓存图片字节数据
  28256. var imageInfos = new List<(string url, bool isWide, int width, int height, byte[] imageData)>();
  28257. _logger.LogInformation($"开始处理图片,配置 - BaseUrl: {baseUrl}, BasePath: {basePath}, 索引: {chi.Index}");
  28258. using (var httpClient = new HttpClient())
  28259. {
  28260. httpClient.Timeout = TimeSpan.FromSeconds(30);
  28261. foreach (var imgUrl in imgs)
  28262. {
  28263. try
  28264. {
  28265. string fullUrl = imgUrl;
  28266. string localPath = "";
  28267. // 判断是否为完整URL
  28268. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  28269. {
  28270. fullUrl = imgUrl;
  28271. // 尝试从URL转换为本地路径
  28272. if (imgUrl.Contains("/child/"))
  28273. {
  28274. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  28275. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  28276. }
  28277. }
  28278. else
  28279. {
  28280. // 文件名,构造本地路径和完整URL
  28281. localPath = Path.Combine(basePath, "child", chi.Index.ToString(), imgUrl);
  28282. fullUrl = $"{baseUrl.TrimEnd('/')}/child/{chi.Index}/{imgUrl}";
  28283. }
  28284. _logger.LogInformation($"处理图片 [{imgUrl}] - 本地路径: {localPath}, URL: {fullUrl}");
  28285. // 优先使用本地文件,如果不存在则尝试下载
  28286. byte[] imageBytes = null;
  28287. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  28288. {
  28289. imageBytes = System.IO.File.ReadAllBytes(localPath);
  28290. _logger.LogInformation($"从本地加载成功,大小: {imageBytes.Length} 字节");
  28291. }
  28292. else
  28293. {
  28294. // 从URL下载图片
  28295. try
  28296. {
  28297. _logger.LogInformation($"本地文件不存在,尝试从URL下载: {fullUrl}");
  28298. imageBytes = await httpClient.GetByteArrayAsync(fullUrl);
  28299. _logger.LogInformation($"从URL下载成功,大小: {imageBytes.Length} 字节");
  28300. }
  28301. catch (Exception ex)
  28302. {
  28303. _logger.LogWarning($"下载图片失败: {fullUrl}, 错误: {ex.Message}");
  28304. continue;
  28305. }
  28306. }
  28307. if (imageBytes != null && imageBytes.Length > 0)
  28308. {
  28309. // 获取图片尺寸
  28310. using (var ms = new MemoryStream(imageBytes))
  28311. {
  28312. using (var image = System.Drawing.Image.FromStream(ms))
  28313. {
  28314. bool isWide = image.Width >= image.Height;
  28315. // 缓存图片数据,避免后续重复加载
  28316. imageInfos.Add((imgUrl, isWide, image.Width, image.Height, imageBytes));
  28317. _logger.LogInformation($"图片分析完成 - 宽度: {image.Width}px, 高度: {image.Height}px, 类型: {(isWide ? "横图" : "竖图")}");
  28318. }
  28319. }
  28320. }
  28321. }
  28322. catch (Exception ex)
  28323. {
  28324. _logger.LogError(ex, $"处理图片失败: {imgUrl}");
  28325. continue;
  28326. }
  28327. }
  28328. }
  28329. _logger.LogInformation($"图片处理完成,成功加载 {imageInfos.Count} 张图片");
  28330. // 插入图片行
  28331. if (imageInfos.Count > 0)
  28332. {
  28333. var builder = new DocumentBuilder(doc);
  28334. // 从数据模板行获取正确的列数,而不是标题行(标题行可能是合并单元格)
  28335. int totalColumns = table.Rows[startIndex].Cells.Count;
  28336. _logger.LogInformation($"表格总列数: {totalColumns}(从第{startIndex}行获取)");
  28337. for (int imgIndex = 0; imgIndex < imageInfos.Count;)
  28338. {
  28339. var currentImg = imageInfos[imgIndex];
  28340. // 在当前行后插入新行(使用复制的模板行)
  28341. var newRow = copyRow.Clone(true) as Aspose.Words.Tables.Row;
  28342. table.Rows.Insert(startIndex + 1, newRow);
  28343. startIndex++; // 更新startIndex,因为插入了新行
  28344. // 重置所有单元格的合并状态(关键:清除克隆行的原有格式)
  28345. for (int col = 0; col < totalColumns; col++)
  28346. {
  28347. if (col < newRow.Cells.Count)
  28348. {
  28349. newRow.Cells[col].CellFormat.HorizontalMerge = CellMerge.None;
  28350. newRow.Cells[col].CellFormat.VerticalMerge = CellMerge.None;
  28351. }
  28352. }
  28353. if (currentImg.isWide)
  28354. {
  28355. _logger.LogInformation($"开始插入宽图 [{currentImg.url}],宽度: {currentImg.width}px");
  28356. // 宽图:先设置所有单元格的合并状态
  28357. for (int col = 0; col < totalColumns; col++)
  28358. {
  28359. if (col < newRow.Cells.Count)
  28360. {
  28361. var cell = newRow.Cells[col];
  28362. cell.RemoveAllChildren();
  28363. if (col == 0)
  28364. {
  28365. cell.CellFormat.HorizontalMerge = CellMerge.First;
  28366. }
  28367. else
  28368. {
  28369. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  28370. }
  28371. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  28372. }
  28373. }
  28374. // 然后在第一个单元格插入图片
  28375. var firstCell = newRow.Cells[0];
  28376. var para = new Paragraph(doc);
  28377. para.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  28378. firstCell.AppendChild(para);
  28379. builder.MoveTo(para);
  28380. try
  28381. {
  28382. // 使用缓存的图片数据
  28383. byte[] imageBytes = currentImg.imageData;
  28384. if (imageBytes != null && imageBytes.Length > 0)
  28385. {
  28386. using (var imgStream = new MemoryStream(imageBytes))
  28387. {
  28388. // 插入图片,设置合理的宽度和最大高度
  28389. var shape = builder.InsertImage(imgStream);
  28390. // 使用预先获取的原始尺寸
  28391. double originalWidth = currentImg.width;
  28392. double originalHeight = currentImg.height;
  28393. // 设置最大宽度(约表格宽度的85%,避免超出)
  28394. double maxWidth = 380;
  28395. double maxHeight = 300; // 限制最大高度,避免图片过高
  28396. // 计算缩放比例
  28397. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  28398. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  28399. double scale = Math.Min(widthScale, heightScale);
  28400. shape.Width = originalWidth * scale;
  28401. shape.Height = originalHeight * scale;
  28402. _logger.LogInformation($"宽图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并 {totalColumns} 个单元格");
  28403. }
  28404. }
  28405. else
  28406. {
  28407. _logger.LogWarning($"图片数据为空");
  28408. para.AppendChild(new Run(doc, "[图片数据为空]"));
  28409. }
  28410. }
  28411. catch (Exception ex)
  28412. {
  28413. _logger.LogError(ex, $"插入宽图失败: {currentImg.url}");
  28414. para.AppendChild(new Run(doc, "[图片加载失败]"));
  28415. }
  28416. imgIndex++; // 处理下一张图片
  28417. }
  28418. else
  28419. {
  28420. _logger.LogInformation($"开始插入高图 [{currentImg.url}],高度: {currentImg.height}px");
  28421. // 高图:合并一半单元格
  28422. int halfColumns = totalColumns / 2;
  28423. _logger.LogInformation($"高图模式 - 前半部分列数: {halfColumns}, 后半部分列数: {totalColumns - halfColumns}");
  28424. // 先设置前一半单元格的合并状态
  28425. for (int col = 0; col < halfColumns; col++)
  28426. {
  28427. if (col < newRow.Cells.Count)
  28428. {
  28429. var cell = newRow.Cells[col];
  28430. cell.RemoveAllChildren();
  28431. if (col == 0)
  28432. {
  28433. cell.CellFormat.HorizontalMerge = CellMerge.First;
  28434. }
  28435. else
  28436. {
  28437. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  28438. }
  28439. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  28440. }
  28441. }
  28442. // 设置后一半单元格的合并状态
  28443. for (int col = halfColumns; col < totalColumns; col++)
  28444. {
  28445. if (col < newRow.Cells.Count)
  28446. {
  28447. var cell = newRow.Cells[col];
  28448. cell.RemoveAllChildren();
  28449. if (col == halfColumns)
  28450. {
  28451. cell.CellFormat.HorizontalMerge = CellMerge.First;
  28452. }
  28453. else
  28454. {
  28455. cell.CellFormat.HorizontalMerge = CellMerge.Previous;
  28456. }
  28457. cell.CellFormat.PreferredWidth = PreferredWidth.Auto;
  28458. }
  28459. }
  28460. // 在第一个单元格插入第一张高图
  28461. var firstCell = newRow.Cells[0];
  28462. var para1 = new Paragraph(doc);
  28463. para1.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  28464. firstCell.AppendChild(para1);
  28465. builder.MoveTo(para1);
  28466. try
  28467. {
  28468. // 使用缓存的图片数据
  28469. byte[] imageBytes = currentImg.imageData;
  28470. if (imageBytes != null && imageBytes.Length > 0)
  28471. {
  28472. using (var imgStream = new MemoryStream(imageBytes))
  28473. {
  28474. var shape = builder.InsertImage(imgStream);
  28475. // 使用预先获取的原始尺寸
  28476. double originalWidth = currentImg.width;
  28477. double originalHeight = currentImg.height;
  28478. // 设置最大宽度和高度(约表格一半宽度)
  28479. double maxWidth = 180;
  28480. double maxHeight = 300; // 限制最大高度
  28481. // 计算缩放比例
  28482. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  28483. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  28484. double scale = Math.Min(widthScale, heightScale);
  28485. shape.Width = originalWidth * scale;
  28486. shape.Height = originalHeight * scale;
  28487. _logger.LogInformation($"第一张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并前 {halfColumns} 个单元格");
  28488. }
  28489. }
  28490. else
  28491. {
  28492. _logger.LogWarning($"图片数据为空");
  28493. para1.AppendChild(new Run(doc, "[图片数据为空]"));
  28494. }
  28495. }
  28496. catch (Exception ex)
  28497. {
  28498. _logger.LogError(ex, $"插入高图失败: {currentImg.url}");
  28499. para1.AppendChild(new Run(doc, "[图片加载失败]"));
  28500. }
  28501. imgIndex++; // 第一张高图已处理
  28502. // 检查是否还有下一张高图,如果有则插入到后一半单元格
  28503. if (imgIndex < imageInfos.Count && !imageInfos[imgIndex].isWide)
  28504. {
  28505. var secondCell = newRow.Cells[halfColumns];
  28506. var para2 = new Paragraph(doc);
  28507. para2.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  28508. secondCell.AppendChild(para2);
  28509. builder.MoveTo(para2);
  28510. try
  28511. {
  28512. var nextImg = imageInfos[imgIndex];
  28513. _logger.LogInformation($"开始插入第二张高图 [{nextImg.url}]");
  28514. // 使用缓存的图片数据
  28515. byte[] imageBytes = nextImg.imageData;
  28516. if (imageBytes != null && imageBytes.Length > 0)
  28517. {
  28518. using (var imgStream = new MemoryStream(imageBytes))
  28519. {
  28520. var shape = builder.InsertImage(imgStream);
  28521. // 使用预先获取的原始尺寸
  28522. double originalWidth = nextImg.width;
  28523. double originalHeight = nextImg.height;
  28524. // 设置最大宽度和高度
  28525. double maxWidth = 180;
  28526. double maxHeight = 300;
  28527. // 计算缩放比例
  28528. double widthScale = originalWidth > maxWidth ? maxWidth / originalWidth : 1;
  28529. double heightScale = originalHeight > maxHeight ? maxHeight / originalHeight : 1;
  28530. double scale = Math.Min(widthScale, heightScale);
  28531. shape.Width = originalWidth * scale;
  28532. shape.Height = originalHeight * scale;
  28533. _logger.LogInformation($"第二张高图插入成功,原始尺寸: {originalWidth}x{originalHeight}, 缩放后: {shape.Width:F0}x{shape.Height:F0},已合并后 {totalColumns - halfColumns} 个单元格");
  28534. }
  28535. }
  28536. else
  28537. {
  28538. _logger.LogWarning($"第二张高图数据为空");
  28539. para2.AppendChild(new Run(doc, "[图片数据为空]"));
  28540. }
  28541. imgIndex++; // 第二张高图已处理
  28542. }
  28543. catch (Exception ex)
  28544. {
  28545. _logger.LogError(ex, $"插入第二张高图失败");
  28546. para2.AppendChild(new Run(doc, "[图片加载失败]"));
  28547. }
  28548. }
  28549. }
  28550. }
  28551. }
  28552. }
  28553. }
  28554. startIndex++;
  28555. }
  28556. //替换书签
  28557. foreach (var key in bookmarks.Keys)
  28558. {
  28559. if (doc.Range.Bookmarks[key] != null)
  28560. {
  28561. Bookmark mark = doc.Range.Bookmarks[key];
  28562. mark.Text = bookmarks[key];
  28563. }
  28564. }
  28565. //去水印
  28566. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String(AsposeHelper.asposeKey)));
  28567. //保存word
  28568. string fileName = $"活动验收报告_{di.TeamName}_{DateTime.Now:yyyyMMddHHmmss}.docx";
  28569. string filePath = $"InspectionReport/{fileName}";
  28570. string fullPath = AppSettingsHelper.Get("WordBasePath") + filePath;
  28571. //确保目录存在
  28572. string directory = Path.GetDirectoryName(fullPath);
  28573. if (!Directory.Exists(directory))
  28574. {
  28575. Directory.CreateDirectory(directory);
  28576. }
  28577. //保存文档
  28578. doc.Save(fullPath, Aspose.Words.SaveFormat.Docx);
  28579. //返回文件路径http
  28580. string url = AppSettingsHelper.Get("WordBaseUrl") + $"Office/Word/{filePath}";
  28581. return Ok(JsonView(true, "SUCCESS!", new { Url = url, FileName = fileName }));
  28582. }
  28583. /// <summary>
  28584. /// 会务成本保存
  28585. /// </summary>
  28586. /// <returns></returns>
  28587. [HttpPost]
  28588. public async Task<IActionResult> ConferenceAffairsSave(ConferenceAffairsSaveDto Dto)
  28589. {
  28590. _sqlSugar.BeginTran();
  28591. var data = _mapper.Map<Grp_ConferenceAffairsCost>(Dto.ConferenceAffairsCost);
  28592. var childResult = new
  28593. {
  28594. success = 0,
  28595. error = 0
  28596. };
  28597. try
  28598. {
  28599. if (data.Id == 0)
  28600. {
  28601. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  28602. .Where(x => x.Diid == Dto.GroupId)
  28603. .SetColumns(x => new Grp_ConferenceAffairsCost
  28604. {
  28605. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28606. DeleteUserId = Dto.UserId
  28607. })
  28608. .ExecuteCommand();
  28609. data.Diid = Dto.GroupId;
  28610. data.CreateTime = DateTime.Now;
  28611. data.CreateUserId = Dto.UserId;
  28612. data.Id = _sqlSugar.Insertable<Grp_ConferenceAffairsCost>(data)
  28613. .ExecuteReturnIdentity();
  28614. }
  28615. else
  28616. {
  28617. _sqlSugar.Updateable<Grp_ConferenceAffairsCost>(data)
  28618. .ExecuteCommand();
  28619. data.Id = data.Id;
  28620. }
  28621. if (Dto.ConferenceAffairsCostChild.Any())
  28622. {
  28623. var datas = _mapper.Map<List<Grp_ConferenceAffairsCostChild>>(Dto.ConferenceAffairsCostChild);
  28624. var insertArr = datas.Where(x => x.Id == 0).ToList();
  28625. var updateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus != 1).ToList();
  28626. var notUpdateArr = datas.Where(x => x.Id != 0 && x.ReviewStatus == 1).ToList();
  28627. insertArr.ForEach(x => { x.Diid = Dto.GroupId; x.ConferenceAffairsCostId = data.Id; });
  28628. var inrsetCount = insertArr.Any() ? _sqlSugar.Insertable<Grp_ConferenceAffairsCostChild>(insertArr).ExecuteCommand() : 0;
  28629. var updateCount = updateArr.Any() ? _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>(updateArr)
  28630. .IgnoreColumns(x => new { x.ConferenceAffairsCostId })
  28631. .ExecuteCommand() : 0;
  28632. childResult = childResult with
  28633. {
  28634. error = notUpdateArr.Count(),
  28635. success = inrsetCount + updateCount
  28636. };
  28637. }
  28638. _sqlSugar.CommitTran();
  28639. }
  28640. catch (Exception ex)
  28641. {
  28642. _sqlSugar.RollbackTran();
  28643. return Ok(JsonView(false, "失败!" + ex.Message));
  28644. }
  28645. return Ok(JsonView(true, "操作成功!", childResult));
  28646. }
  28647. [HttpPost]
  28648. public async Task<IActionResult> ConferenceAffairsAudit(ConferenceAffairsAuditDto Dto)
  28649. {
  28650. var count = 0;
  28651. if (Dto.ConferenceAffairsCostChildids.Any())
  28652. {
  28653. count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>().
  28654. Where(x => Dto.ConferenceAffairsCostChildids.Contains(x.Id)).
  28655. SetColumns(x => new Grp_ConferenceAffairsCostChild
  28656. {
  28657. ReviewStatus = Dto.ReviewStatus
  28658. }).
  28659. ExecuteCommand();
  28660. }
  28661. return Ok(JsonView(true, "操作成功!", count));
  28662. }
  28663. /// <summary>
  28664. /// 会务成本所有数据清除
  28665. /// </summary>
  28666. /// <param name="Dto"></param>
  28667. /// <returns></returns>
  28668. [HttpPost]
  28669. public async Task<IActionResult> ConferenceAffairsDelete(ConferenceAffairsDeleteDto Dto)
  28670. {
  28671. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  28672. if (Dto.UserId < 1) return Ok(JsonView(false, "请传入有效的用户Id"));
  28673. _sqlSugar.BeginTran();
  28674. try
  28675. {
  28676. var delCount = _sqlSugar.Updateable<Grp_ConferenceAffairsCost>()
  28677. .Where(x => x.Diid == Dto.GroupId)
  28678. .SetColumns(x => new Grp_ConferenceAffairsCost
  28679. {
  28680. IsDel = 1,
  28681. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28682. DeleteUserId = Dto.UserId
  28683. })
  28684. .ExecuteCommand();
  28685. if (delCount > 0)
  28686. {
  28687. _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  28688. .Where(x => x.Diid == Dto.GroupId)
  28689. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  28690. {
  28691. IsDel = 1,
  28692. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28693. DeleteUserId = Dto.UserId
  28694. })
  28695. .ExecuteCommand();
  28696. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  28697. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  28698. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  28699. {
  28700. IsDel = 1,
  28701. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28702. DeleteUserId = Dto.UserId
  28703. })
  28704. .ExecuteCommand();
  28705. }
  28706. _sqlSugar.CommitTran();
  28707. }
  28708. catch (Exception ex)
  28709. {
  28710. _sqlSugar.RollbackTran();
  28711. return Ok(JsonView(false, "操作失败!" + ex.Message));
  28712. }
  28713. return Ok(JsonView(true, "操作成功!"));
  28714. }
  28715. /// <summary>
  28716. /// 子项数据删除
  28717. /// </summary>
  28718. /// <param name="Dto"></param>
  28719. /// <returns></returns>
  28720. [HttpPost]
  28721. public async Task<IActionResult> ConferenceAffairSinglesDelete(ConferenceAffairsDeleteSingleDto Dto)
  28722. {
  28723. var isAudit = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  28724. .Any(x => x.ReviewStatus == 1);
  28725. if (isAudit) return Ok(JsonView(false, "包含已审核数据无法删除!"));
  28726. var queryData = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
  28727. .Where(x => x.IsDel == 0 && Dto.ids.Contains(x.Id))
  28728. .ToList();
  28729. //删除图片
  28730. foreach (var item in queryData)
  28731. {
  28732. if (!string.IsNullOrEmpty(item.Imgs))
  28733. {
  28734. var imgList = item.Imgs.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  28735. string baseUrl = AppSettingsHelper.Get("ConferenceCostImageBaseUrl");
  28736. string basePath = AppSettingsHelper.Get("ConferenceCostImageBasePath");
  28737. foreach (var imgUrl in imgList)
  28738. {
  28739. try
  28740. {
  28741. string localPath = "";
  28742. // 判断是否为完整URL
  28743. if (imgUrl.StartsWith("http://") || imgUrl.StartsWith("https://"))
  28744. {
  28745. // 尝试从URL转换为本地路径
  28746. if (imgUrl.Contains("/child/"))
  28747. {
  28748. var pathPart = imgUrl.Substring(imgUrl.IndexOf("/child/"));
  28749. localPath = Path.Combine(basePath, pathPart.TrimStart('/').Replace("/", "\\"));
  28750. }
  28751. }
  28752. else
  28753. {
  28754. // 文件名,构造本地路径
  28755. localPath = Path.Combine(basePath, "child", item.Index.ToString(), imgUrl);
  28756. }
  28757. if (!string.IsNullOrEmpty(localPath) && System.IO.File.Exists(localPath))
  28758. {
  28759. _logger.LogInformation($"-----------------------");
  28760. _logger.LogInformation($"删除图片: {localPath}");
  28761. System.IO.File.Delete(localPath);
  28762. _logger.LogInformation($"删除成功");
  28763. _logger.LogInformation($"-----------------------");
  28764. }
  28765. else
  28766. {
  28767. _logger.LogWarning($"图片文件不存在或路径为空: {imgUrl} -> {localPath}");
  28768. }
  28769. }
  28770. catch (Exception ex)
  28771. {
  28772. _logger.LogError(ex, $"删除图片失败: {imgUrl}");
  28773. }
  28774. }
  28775. }
  28776. }
  28777. var count = _sqlSugar.Updateable<Grp_ConferenceAffairsCostChild>()
  28778. .Where(x => Dto.ids.Contains(x.Id) && x.IsDel == 0)
  28779. .SetColumns(x => new Grp_ConferenceAffairsCostChild
  28780. {
  28781. IsDel = 1,
  28782. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28783. DeleteUserId = Dto.UserId
  28784. })
  28785. .ExecuteCommand();
  28786. return Ok(JsonView(true, "SUCCESS!", count));
  28787. }
  28788. /// <summary>
  28789. /// 会务成本权限分配
  28790. /// </summary>
  28791. /// <param name="Dto"></param>
  28792. /// <returns></returns>
  28793. [HttpPost]
  28794. public async Task<IActionResult> PermissionSetting(PermissionSettingDto Dto)
  28795. {
  28796. _sqlSugar.BeginTran();
  28797. var count = 0;
  28798. try
  28799. {
  28800. _sqlSugar.Updateable<Grp_ConferenceAffairsCostControl>()
  28801. .Where(x => x.Diid == Dto.GroupId && x.IsDel == 0)
  28802. .SetColumns(x => new Grp_ConferenceAffairsCostControl
  28803. {
  28804. IsDel = 1,
  28805. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  28806. DeleteUserId = Dto.CreateUserId
  28807. })
  28808. .ExecuteCommand();
  28809. count = _sqlSugar.Insertable<Grp_ConferenceAffairsCostControl>(Dto.UserIds.Select(x => new Grp_ConferenceAffairsCostControl
  28810. {
  28811. CreateTime = DateTime.Now,
  28812. CreateUserId = Dto.CreateUserId,
  28813. UserId = x,
  28814. Diid = Dto.GroupId,
  28815. }).ToList()).ExecuteCommand();
  28816. _sqlSugar.CommitTran();
  28817. }
  28818. catch (Exception ex)
  28819. {
  28820. _sqlSugar.RollbackTran();
  28821. return Ok(JsonView(false, "操作失败!" + ex.Message));
  28822. }
  28823. return Ok(JsonView(true, "操作成功!", count));
  28824. }
  28825. /// <summary>
  28826. /// 团组会务成本文件下载
  28827. /// </summary>
  28828. /// <returns></returns>
  28829. [HttpPost]
  28830. public async Task<IActionResult> ConferenceAffairsFileDown(ConferenceAffairsFileDownDto Dto)
  28831. {
  28832. var FileType = new[]
  28833. {
  28834. new { Id = 0 , Name = "成本下载" },
  28835. new { Id = 1 , Name = "报价下载" },
  28836. new { Id = 2 , Name = "总表下载" },
  28837. };
  28838. if (Dto.GroupId < 1) return Ok(JsonView(false, "请传入有效的Id"));
  28839. if (Dto.FileTypeId < 0 || Dto.FileTypeId > 2) return Ok(JsonView(false, "请传入有效的文件类型"));
  28840. var di = _sqlSugar.Queryable<Grp_DelegationInfo>()
  28841. .Where(x => x.IsDel == 0 && x.Id == Dto.GroupId)
  28842. .Select<DelegationEasyView>()
  28843. .First();
  28844. var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
  28845. .First(x => x.Diid == Dto.GroupId && x.IsDel == 0);
  28846. if (main == null)
  28847. {
  28848. return Ok(JsonView(false, "团组会务成本信息不存在!"));
  28849. }
  28850. JsonView jw = JsonView(false);
  28851. //总表下载
  28852. var loadPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/template/";
  28853. var outputPath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceAffairs/output/total/";
  28854. var networkPath = outputPath.Replace(AppSettingsHelper.Get("ExcelBasePath"), AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  28855. var field = string.Empty;
  28856. var fileTypeName = string.Empty;
  28857. field = @$"
  28858. a.[Index],a.PriceName,a.CostPrice,a.Count,a.Coefficient,a.BaoJiaPrice,a.AddedValue,a.Details,a.Remark,a.Rate,
  28859. b.Name as PriceTypeStr ,
  28860. c.Name as CurrencyStr ,
  28861. d.Name as UnitStr ,
  28862. case a.ReviewStatus
  28863. WHEN 1 THEN '已通过'
  28864. WHEN 0 THEN '未审核'
  28865. WHEN -1 THEN '未通过'
  28866. ELSE '未审核'
  28867. END AS ReviewStatusStr
  28868. ";
  28869. if (Dto.FileTypeId == 0)
  28870. {
  28871. fileTypeName = "会务成本成本表";
  28872. loadPath += $"{fileTypeName}.xlsx";
  28873. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28874. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28875. }
  28876. else if (Dto.FileTypeId == 1)
  28877. {
  28878. fileTypeName = "会务成本报价表";
  28879. loadPath += $"{fileTypeName}.xlsx";
  28880. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28881. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28882. }
  28883. else if (Dto.FileTypeId == 2)
  28884. {
  28885. fileTypeName = "会务成本总表";
  28886. loadPath += $"{fileTypeName}.xlsx";
  28887. outputPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28888. networkPath += $"{di.TeamName}_{fileTypeName}.xlsx";
  28889. }
  28890. var chiExcelContent = _sqlSugar.SqlQueryable<ConferenceAffairsExcelContent>(@$"
  28891. SELECT
  28892. {field}
  28893. FROM Grp_ConferenceAffairsCostChild a
  28894. LEFT JOIN Sys_SetData b on b.IsDel = 0 AND b.Id = a.PriceType
  28895. LEFT JOIN Sys_SetData c on c.IsDel = 0 AND c.Id = a.Currency
  28896. LEFT JOIN Sys_SetData d on d.IsDel = 0 AND d.Id = a.Unit
  28897. WHERE a.isdel = 0
  28898. AND a.Diid = {main.Diid}
  28899. AND a.ConferenceAffairsCostId = {main.Id}
  28900. ").ToList();
  28901. var currLists = chiExcelContent.Select(x => new CurrList
  28902. {
  28903. CurrName = x.CurrencyStr,
  28904. CurrRate = x.Rate
  28905. })
  28906. .Distinct()
  28907. .ToList();
  28908. var designer = new WorkbookDesigner
  28909. {
  28910. Workbook = new Workbook(loadPath)
  28911. };
  28912. var MostCurr = _sqlSugar.Queryable<Sys_SetData>().First(x => x.IsDel == 0 && x.Id == main.MostCurr);
  28913. MostCurr ??= new Sys_SetData { Name = "暂无!" };
  28914. designer.SetDataSource("TeamName", di.TeamName);
  28915. designer.SetDataSource("City", main.City);
  28916. designer.SetDataSource("AllCost", main.CostAll);
  28917. designer.SetDataSource("AllBaoJia", main.BaoJiaAll);
  28918. designer.SetDataSource("Curr", MostCurr.Name);
  28919. designer.SetDataSource("Curr1", MostCurr.Name);
  28920. DataTable dt = CommonFun.GetDataTableFromIList<ConferenceAffairsExcelContent>(chiExcelContent);
  28921. dt.TableName = "TB";
  28922. designer.SetDataSource(dt);
  28923. DataTable dt1 = CommonFun.GetDataTableFromIList<CurrList>(currLists);
  28924. dt1.TableName = "currTb";
  28925. designer.SetDataSource(dt1);
  28926. designer.Process();
  28927. designer.Workbook.Save(outputPath);
  28928. jw = JsonView(true, "操作成功!", new
  28929. {
  28930. FileName = $"{di.TeamName}_{fileTypeName}.xlsx",
  28931. FilePath = networkPath
  28932. });
  28933. return Ok(jw);
  28934. }
  28935. [HttpPost]
  28936. public async Task<IActionResult> QueryConferenceAffairsChild(QueryConferenceAffairsChildDto Dto)
  28937. {
  28938. return Ok(JsonView(true, "SUCCESS", _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>().Where(x => x.IsDel == 0 && x.Diid == Dto.GroupId)
  28939. .Select(x => x.PriceName).ToList()));
  28940. }
  28941. #endregion
  28942. #region 会务流程
  28943. /// <summary>
  28944. /// 会务流程 - 团组列表
  28945. /// </summary>
  28946. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  28947. [HttpGet]
  28948. public async Task<IActionResult> ConferenceProceduresGroupNames()
  28949. {
  28950. var conferenceTypeIds = new List<int>() {
  28951. 302, // 成都-会务活动
  28952. 691 // 四川-会务活动
  28953. };
  28954. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28955. .Where(x => x.IsDel == 0)
  28956. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  28957. .OrderByDescending(x => x.VisitDate)
  28958. .Select(x => new
  28959. {
  28960. x.Id,
  28961. x.TeamName,
  28962. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  28963. .Where(child => child.DiId == x.Id) // 替换关联条件
  28964. .Any() // 判断子表是否存在数据
  28965. })
  28966. .ToListAsync();
  28967. return Ok(JsonView(true, "SUCCESS", groupList));
  28968. }
  28969. /// <summary>
  28970. /// 会务流程 - 数据初始化
  28971. /// </summary>
  28972. /// <param name="dto"></param>
  28973. /// <returns>团组基本信息、团组列表和会务基本信息列表</returns>
  28974. [HttpPost]
  28975. public async Task<IActionResult> ConferenceProceduresInit(ConferenceProceduresInitDto dto)
  28976. {
  28977. try
  28978. {
  28979. var conferenceTypeIds = new List<int>() {
  28980. 302, // 成都-会务活动
  28981. 691 // 四川-会务活动
  28982. };
  28983. Grp_DelegationInfo targetGroup = null;
  28984. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28985. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  28986. .FirstAsync();
  28987. if (targetGroup == null)
  28988. {
  28989. targetGroup = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  28990. .Where(x => x.IsDel == 0)
  28991. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  28992. .OrderByDescending(x => x.VisitDate)
  28993. .FirstAsync();
  28994. }
  28995. if (targetGroup == null)
  28996. {
  28997. return Ok(JsonView(false, "未找到任何团组信息"));
  28998. }
  28999. var groupList = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29000. .Where(x => x.IsDel == 0)
  29001. .Where(x => conferenceTypeIds.Contains(x.TeamDid))
  29002. .OrderByDescending(x => x.VisitDate)
  29003. .Select(x => new
  29004. {
  29005. x.Id,
  29006. x.TeamName,
  29007. HasChildData = SqlFunc.Subqueryable<Grp_ConferenceProcedures>()
  29008. .Where(child => child.DiId == x.Id)
  29009. .Any() // 判断子表是否存在数据
  29010. })
  29011. .ToListAsync();
  29012. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  29013. .Where(x => x.DiId == targetGroup.Id && x.IsDel == 0)
  29014. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  29015. .ToListAsync();
  29016. if (!conferenceProceduresList.Any())
  29017. {
  29018. conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  29019. .Where(x => x.DiId == -1 && x.IsDel == 0)
  29020. .Select(x => new { x.Id, x.Title, x.DataDetails, x.Details, x.Remark })
  29021. .ToListAsync();
  29022. }
  29023. var conferenceProceduresGroupByTitle = conferenceProceduresList
  29024. .GroupBy(x => x.Title)
  29025. .Select(x => new
  29026. {
  29027. title = x.Key,
  29028. itmes = x.Select(y => new
  29029. {
  29030. y.Id,
  29031. y.DataDetails,
  29032. y.Details,
  29033. y.Remark
  29034. }).ToList()
  29035. })
  29036. .ToList();
  29037. var response = new
  29038. {
  29039. GroupInfo = new
  29040. {
  29041. targetGroup.Id,
  29042. targetGroup.TeamName,
  29043. targetGroup.VisitDate,
  29044. targetGroup.VisitDays,
  29045. targetGroup.VisitPNumber,
  29046. targetGroup.VisitCountry,
  29047. targetGroup.VisitStartDate,
  29048. targetGroup.VisitEndDate,
  29049. targetGroup.ClientName,
  29050. targetGroup.ClientUnit
  29051. },
  29052. GroupList = groupList,
  29053. ConferenceProceduresList = conferenceProceduresList,
  29054. conferenceProceduresGroupByTitle = conferenceProceduresGroupByTitle
  29055. };
  29056. return Ok(JsonView(true, "SUCCESS", response));
  29057. }
  29058. catch (Exception ex)
  29059. {
  29060. _logger.LogError(ex, "数据初始化失败");
  29061. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  29062. }
  29063. }
  29064. /// <summary>
  29065. /// 会务流程 - 保存
  29066. /// </summary>
  29067. /// <param name="dto"></param>
  29068. /// <returns></returns>
  29069. [HttpPost]
  29070. public async Task<IActionResult> ConferenceProceduresSave(ConferenceProceduresSaveDto dto)
  29071. {
  29072. _sqlSugar.BeginTran();
  29073. try
  29074. {
  29075. //删除旧数据
  29076. _sqlSugar.Updateable<Grp_ConferenceProcedures>()
  29077. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  29078. .SetColumns(x => new Grp_ConferenceProcedures
  29079. {
  29080. IsDel = 1,
  29081. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd"),
  29082. DeleteUserId = dto.UserId
  29083. })
  29084. .ExecuteCommand();
  29085. //添加新数据
  29086. var newData = new List<Grp_ConferenceProcedures>();
  29087. foreach (var item in dto.ConferenceProceduresSaveItem)
  29088. {
  29089. foreach (var item2 in item.itmes)
  29090. {
  29091. newData.Add(new Grp_ConferenceProcedures
  29092. {
  29093. DiId = dto.GroupId,
  29094. Title = item.title,
  29095. DataDetails = item2.DataDetails,
  29096. Details = item2.details,
  29097. Remark = item2.Remark,
  29098. CreateTime = DateTime.Now,
  29099. CreateUserId = dto.UserId
  29100. });
  29101. }
  29102. }
  29103. _sqlSugar.Insertable(newData).ExecuteCommand();
  29104. _sqlSugar.CommitTran();
  29105. }
  29106. catch (Exception ex)
  29107. {
  29108. _sqlSugar.RollbackTran();
  29109. return Ok(JsonView(false, $"ERROR:{ex.Message}"));
  29110. }
  29111. return Ok(JsonView(true, "SUCCESS"));
  29112. }
  29113. [HttpPost]
  29114. public async Task<IActionResult> ConferenceProceduresFileDown(ConferenceProceduresFileDownDto dto)
  29115. {
  29116. var jw = JsonView(false, "团组信息不存在");
  29117. jw.Data = string.Empty;
  29118. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29119. .Where(x => x.Id == dto.GroupId && x.IsDel == 0)
  29120. .FirstAsync();
  29121. if (groupInfo == null)
  29122. {
  29123. return Ok(jw);
  29124. }
  29125. var conferenceProceduresList = await _sqlSugar.Queryable<Grp_ConferenceProcedures>()
  29126. .Where(x => x.DiId == dto.GroupId && x.IsDel == 0)
  29127. .ToListAsync();
  29128. if (!conferenceProceduresList.Any())
  29129. {
  29130. jw.Msg = "会务流程信息不存在";
  29131. return Ok(jw);
  29132. }
  29133. var filePath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/会务流程.xlsx";
  29134. if (!System.IO.File.Exists(filePath))
  29135. {
  29136. jw.Msg = "模板文件不存在";
  29137. return Ok(jw);
  29138. }
  29139. var designer = new WorkbookDesigner();
  29140. designer.Workbook = new Workbook(filePath);
  29141. designer.SetDataSource("TB", conferenceProceduresList);
  29142. designer.Process();
  29143. var sheet = designer.Workbook.Worksheets[0];
  29144. var cells = sheet.Cells;
  29145. int col = 0; // 第一列
  29146. int startRow = 2; // 若第0行为表头,则从第1行开始;无表头请改为0
  29147. int endRow = cells.MaxDataRow;
  29148. if (endRow >= startRow)
  29149. {
  29150. int mergeStart = startRow;
  29151. string prev = cells[mergeStart, col].StringValue?.Trim() ?? string.Empty;
  29152. for (int r = startRow + 1; r <= endRow; r++)
  29153. {
  29154. string cur = cells[r, col].StringValue?.Trim() ?? string.Empty;
  29155. if (!string.Equals(cur, prev, StringComparison.Ordinal))
  29156. {
  29157. int count = r - mergeStart;
  29158. if (count > 1)
  29159. cells.Merge(mergeStart, col, count, 1);
  29160. mergeStart = r;
  29161. prev = cur;
  29162. }
  29163. }
  29164. int tailCount = endRow - mergeStart + 1;
  29165. if (tailCount > 1)
  29166. cells.Merge(mergeStart, col, tailCount, 1);
  29167. }
  29168. // byte[] bytes = null;
  29169. // using (MemoryStream stream = new MemoryStream())
  29170. // {
  29171. // designer.Workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  29172. // bytes = stream.ToArray();
  29173. // }
  29174. // return File(bytes, "application/excel", $"{groupInfo.TeamName}_会务流程.xlsx");
  29175. string savePath = $"{AppSettingsHelper.Get("ExcelBasePath")}ConferenceProcedures";
  29176. if (!System.IO.Directory.Exists(savePath))
  29177. {
  29178. System.IO.Directory.CreateDirectory(savePath);
  29179. }
  29180. designer.Workbook.Save($"{savePath}/{groupInfo.TeamName}_会务流程.xlsx");
  29181. string rst = savePath.replace(AppSettingsHelper.Get("ExcelBasePath"),
  29182. AppSettingsHelper.Get("ExcelBaseUrl") + AppSettingsHelper.Get("ExcelFtpPath"));
  29183. return Ok(JsonView(true, "SUCCESS", $"{rst}/{groupInfo.TeamName}_会务流程.xlsx"));
  29184. }
  29185. #endregion
  29186. #region 团组签证流程
  29187. /// <summary>
  29188. /// 团组签证流程 - 团组列表(分页)
  29189. /// </summary>
  29190. /// <returns></returns>
  29191. [HttpPost]
  29192. public async Task<IActionResult> VisaProcessGroupNames(VisaProcessGroupNamesDto dto)
  29193. {
  29194. int currUserId = dto.CurrUserId <= 0 ? 1 : dto.CurrUserId;
  29195. string groupName = dto.GroupName.Trim();
  29196. int pageIndex = dto.PageIndex <= 0 ? 1 : dto.PageIndex;
  29197. int pageSize = dto.PageSize <= 0 ? 10 : dto.PageSize;
  29198. int portType = dto.PortType;
  29199. RefAsync<int> total = 0;
  29200. var query = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
  29201. .InnerJoin<Grp_DelegationInfo>((x, y) => x.DIId == y.Id)
  29202. .InnerJoin<Grp_VisaProcessSteps>((x, y, z) => x.DIId == z.GroupId)
  29203. .Where((x, y, z) => x.IsDel == 0 && x.CTId == 80 && x.UId == currUserId && z.IsDel == 0);
  29204. //构建单字模糊查询
  29205. if (!string.IsNullOrEmpty(groupName))
  29206. {
  29207. var characters = groupName.ToCharArray();
  29208. foreach (var character in characters)
  29209. {
  29210. var charString = character.ToString();
  29211. query = query.Where((x, y) =>
  29212. SqlFunc.Contains(y.TeamName, charString));
  29213. }
  29214. }
  29215. var groups = await query
  29216. .OrderByDescending((x, y) => y.VisitDate)
  29217. .Select((x, y) => new
  29218. {
  29219. y.Id,
  29220. GroupName = y.TeamName,
  29221. y.VisitDate,
  29222. // 加入子查询统计子表条数
  29223. CompletedCount = SqlFunc.Subqueryable<Grp_VisaProcessSteps>()
  29224. .Where(sub => sub.GroupId == y.Id && sub.IsCompleted && sub.IsDel == 0)
  29225. .Count()
  29226. })
  29227. .Distinct()
  29228. .ToPageListAsync(pageIndex, pageSize, total);
  29229. var msg = "SUCCESS";
  29230. if (total <= 0) msg = "暂无可操作的团组,请联系经理分配团组!";
  29231. var groups1 = groups.Select(x => new
  29232. {
  29233. x.Id,
  29234. x.GroupName,
  29235. x.CompletedCount
  29236. }).ToList();
  29237. return Ok(JsonView(true, msg, groups1, total));
  29238. }
  29239. /// <summary>
  29240. /// 团组签证流程 - 详情
  29241. /// </summary>
  29242. /// <returns></returns>
  29243. [HttpPost]
  29244. public async Task<IActionResult> VisaProcessInfoByGroupId(VisaProcessInfoByGroupIdDto dto)
  29245. {
  29246. var res = await _visaProcessRep.Info(dto);
  29247. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  29248. return Ok(JsonView(true, res.Msg, res.Data));
  29249. }
  29250. /// <summary>
  29251. /// 团组签证流程 - 流程创建测试
  29252. /// </summary>
  29253. /// <returns></returns>
  29254. [HttpPost]
  29255. public async Task<IActionResult> VisaProcessAdd(int groupId, int currUserId)
  29256. {
  29257. return Ok(await _visaProcessRep.Create(currUserId, groupId));
  29258. }
  29259. /// <summary>
  29260. /// 团组签证流程 - 流程Top4Init 测试
  29261. /// </summary>
  29262. /// <returns></returns>
  29263. [HttpPost]
  29264. public async Task<IActionResult> VisaProcessTop4StepInit(int groupId, int currUserId)
  29265. {
  29266. return Ok(await _visaProcessRep.UpdateBatchTop4Step(groupId, currUserId));
  29267. }
  29268. /// <summary>
  29269. /// 团组签证流程 - 设置状态 完成/未完成
  29270. /// </summary>
  29271. /// <returns></returns>
  29272. [HttpPost]
  29273. public async Task<IActionResult> VisaProcessSetCompleted(VisaProcessSetCompletedDto dto)
  29274. {
  29275. //参数验证
  29276. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).AnyAsync();
  29277. if (!stepValid) return Ok(JsonView(false, "签证流程ID无效。"));
  29278. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  29279. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  29280. var res = await _visaProcessRep.SetCompleted(dto.StepId, dto.CurrUserId, dto.IsCompleted);
  29281. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  29282. return Ok(JsonView(true, res.Msg));
  29283. }
  29284. /// <summary>
  29285. /// 团组签证流程 - 修改各步骤内容
  29286. /// </summary>
  29287. /// <returns></returns>
  29288. [HttpPost]
  29289. public async Task<IActionResult> VisaProcessSetContent(VisaProcessSetContent dto)
  29290. {
  29291. //参数验证
  29292. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  29293. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  29294. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  29295. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  29296. if (dto.StepContents == null && dto.StepContents.Count < 1)
  29297. {
  29298. return Ok(JsonView(false, "步骤内容无效。"));
  29299. }
  29300. //各步骤值处理
  29301. object stepVal;
  29302. if (stepValid.Step == 7) stepVal = dto.StepContents;
  29303. else stepVal = dto.StepContents[0].ToString();
  29304. var stepInfo = new Grp_VisaProcessSteps
  29305. {
  29306. Id = dto.StepId,
  29307. DataType = stepValid.DataType,
  29308. TypedValue = stepVal,
  29309. LastUpdateUserId = dto.CurrUserId
  29310. };
  29311. var res = await _visaProcessRep.Update(stepInfo);
  29312. if (res.Code != 200) return Ok(JsonView(false, res.Msg));
  29313. return Ok(JsonView(true, res.Msg));
  29314. }
  29315. /// <summary>
  29316. /// 团组签证流程 - 上传文件
  29317. /// </summary>
  29318. /// <returns></returns>
  29319. [HttpPost]
  29320. public async Task<IActionResult> VisaProcessUploadFiles([FromForm] VisaProcessUploadFilesDto dto)
  29321. {
  29322. //参数验证
  29323. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == dto.StepId && x.IsDel == 0).FirstAsync();
  29324. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  29325. var before = stepValid;
  29326. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == dto.CurrUserId && x.IsDel == 0).AnyAsync();
  29327. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  29328. //验证文件是否存在
  29329. if (dto.Files == null || dto.Files.Count < 1) return Ok(JsonView(false, "请选择文件。"));
  29330. //验证该步骤是否可以上传文件
  29331. var uploadSteps = new List<int>() {
  29332. 5, //实际出签时间
  29333. 6, //是否需要开出境证明
  29334. 7, //是否需要办理电子入境卡手续
  29335. };
  29336. if (!uploadSteps.Contains(stepValid.Step))
  29337. {
  29338. return Ok(JsonView(false, $"该步骤不可上传附件。可上传附件步骤({string.Join("、", uploadSteps)})"));
  29339. }
  29340. //验证根目录
  29341. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  29342. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  29343. if (!System.IO.Directory.Exists(rootPath))
  29344. {
  29345. System.IO.Directory.CreateDirectory(rootPath);
  29346. }
  29347. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  29348. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29349. .Where(x => x.IsDel == 0 && x.Id == stepValid.GroupId)
  29350. .Select(x => $"{x.TeamName}({x.Id})")
  29351. .FirstAsync();
  29352. //创建团组文件夹
  29353. var groupPath = rootPath + "GrpFile/VisaProcessFiles/" + groupName;
  29354. if (!System.IO.Directory.Exists(groupPath))
  29355. {
  29356. System.IO.Directory.CreateDirectory(groupPath);
  29357. }
  29358. List<string> filePaths = new List<string>();
  29359. //保存文件
  29360. foreach (var file in dto.Files)
  29361. {
  29362. // 生成存储文件名
  29363. var fileName = CommonFun.GenerateStoredFileName($"Step{stepValid.Step}.{file.FileName.Split(".")[1]}");
  29364. var filePath = Path.Combine(groupPath, fileName);
  29365. // 保存文件到磁盘
  29366. using (var stream = new FileStream(filePath, FileMode.Create))
  29367. {
  29368. await file.CopyToAsync(stream);
  29369. }
  29370. filePaths.Add($"GrpFile/VisaProcessFiles/{groupName}/{fileName}");
  29371. }
  29372. //数据库存储
  29373. stepValid.TypedFileNameValue = filePaths;
  29374. stepValid.LastUpdateUserId = dto.CurrUserId;
  29375. stepValid.LastUpdateTime = DateTime.Now;
  29376. var res = await _sqlSugar.Updateable(stepValid)
  29377. .UpdateColumns(it => new { it.TypedFileNameValue, it.LastUpdateUserId, it.LastUpdateTime })
  29378. .Where(s => s.Id == dto.StepId && s.IsDel == 0)
  29379. .ExecuteCommandAsync();
  29380. if (res < 1) Ok(JsonView(false, "文件上传失败。"));
  29381. //记录上传文件
  29382. await _visaProcessRep.LogOperationAsync(before, stepValid, "Upload", dto.CurrUserId);
  29383. return Ok(JsonView(true));
  29384. }
  29385. /// <summary>
  29386. /// 团组签证流程 - step 7 资料下载
  29387. /// </summary>
  29388. /// <returns></returns>
  29389. [HttpGet]
  29390. public async Task<IActionResult> VisaProcessDownload(int groupId, int currUserId)
  29391. {
  29392. var userValid = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.Id == currUserId && x.IsDel == 0).AnyAsync();
  29393. if (!userValid) return Ok(JsonView(false, "用户ID无效。"));
  29394. //验证根目录
  29395. string rootRrl = AppSettingsHelper.Get("OfficeBaseUrl");
  29396. string rootPath = AppSettingsHelper.Get("OfficeTempBasePath");
  29397. if (!System.IO.Directory.Exists(rootPath))
  29398. {
  29399. System.IO.Directory.CreateDirectory(rootPath);
  29400. }
  29401. //验证签证流程上传文件夹 //按照团组名称存储文件夹 GrpFile/VisaProcessFiles/
  29402. var groupName = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29403. .Where(x => x.IsDel == 0 && x.Id == groupId)
  29404. .Select(x => $"{x.TeamName}({x.Id})")
  29405. .FirstAsync();
  29406. //创建团组文件夹
  29407. var timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");
  29408. var randomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  29409. var dirName = $"{groupName}_相关资料_{timestamp}";
  29410. var sourceDirectoryPath = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}";
  29411. var path = $"{rootPath}/GrpFile/VisaProcessFiles/{groupName}/{dirName}";
  29412. if (!System.IO.Directory.Exists(path))
  29413. {
  29414. System.IO.Directory.CreateDirectory(path);
  29415. }
  29416. //验证接团客户名单
  29417. string sql = string.Format(@"
  29418. SELECT
  29419. tcl.Id,
  29420. tcl.DiId,
  29421. tcl.IsAccompany,
  29422. temp.*,
  29423. u.CnName AS Operator,
  29424. tcl.CreateTime AS OperatingTime,
  29425. ssd.name AS ShippingSpaceType
  29426. FROM
  29427. Grp_TourClientList tcl
  29428. LEFT JOIN (
  29429. SELECT
  29430. dc.Id AS DcId,
  29431. dc.LastName,
  29432. dc.FirstName,
  29433. ccom.CompanyFullName,
  29434. dc.Job,
  29435. cc.CertNo AS IDCardNo,
  29436. dc.Sex,
  29437. dc.BirthDay
  29438. FROM
  29439. Crm_DeleClient dc
  29440. LEFT JOIN Crm_CustomerCompany ccom ON dc.CrmCompanyId = ccom.Id
  29441. AND ccom.IsDel = 0
  29442. LEFT JOIN Crm_CustomerCert cc ON dc.Id = cc.DcId
  29443. AND cc.SdId = 773
  29444. AND cc.IsDel = 0
  29445. WHERE
  29446. dc.IsDel = 0
  29447. ) temp ON temp.DcId = tcl.ClientId
  29448. LEFT JOIN Sys_Users u ON tcl.CreateUserId = u.Id
  29449. LEFT JOIN sys_setdata ssd ON ssd.isdel = 0 AND ssd.id = tcl.ShippingSpaceTypeid
  29450. WHERE
  29451. tcl.IsDel = 0
  29452. AND tcl.DiId = {0}", groupId);
  29453. var groupClientList = await _sqlSugar.SqlQueryable<TourClientInfosView>(sql).ToListAsync();
  29454. //解密
  29455. foreach (var item in groupClientList)
  29456. {
  29457. EncryptionProcessor.DecryptProperties(item);
  29458. }
  29459. if (groupClientList == null || groupClientList.Count < 1)
  29460. {
  29461. return Ok(JsonView(false, $"团组客户名单未录入客户信息,不可生成相关资料。"));
  29462. }
  29463. #region 生成文件
  29464. //酒店信息
  29465. var hotelInfos = await _sqlSugar.Queryable<Grp_HotelReservations>()
  29466. .Where(x => x.IsDel == 0 && x.DiId == groupId)
  29467. .OrderBy(x => x.CheckInDate)
  29468. .ToListAsync();
  29469. //航班信息
  29470. var airInfos = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  29471. .Where(x => x.IsDel == 0 && x.DIId == groupId)
  29472. .OrderBy(x => x.FlightsDate)
  29473. .ToListAsync();
  29474. foreach (var clientInfo in groupClientList)
  29475. {
  29476. var clientId = clientInfo.DcId;
  29477. var guestName = $"{clientInfo.LastName}{clientInfo.FirstName}";
  29478. #region 个人信息资料
  29479. #endregion
  29480. #region 机票航班信息
  29481. var clientAirInfos = airInfos.Where(x => x.ClientName.Contains(clientId.ToString())).ToList();
  29482. if (clientAirInfos != null && clientAirInfos.Count > 0)
  29483. {
  29484. //创建表格
  29485. Document airDoc = new Document();
  29486. DocumentBuilder airBuilder = new DocumentBuilder(airDoc);
  29487. GeneralMethod.SetupDocumentStyles(airBuilder);
  29488. GeneralMethod.AddTitle(airBuilder, $"{guestName} - 机票信息");
  29489. GeneralMethod.AddAirInfoSections(airBuilder, clientAirInfos, "机票航班信息");
  29490. var airRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  29491. var airFileName = $"{guestName}_机票信息_{airRandomStr}.docx";
  29492. airDoc.Save($"{path}/{airFileName}");
  29493. }
  29494. #endregion
  29495. #region 酒店信息
  29496. var clientHotelInfos = hotelInfos.Where(x => x.GuestName.Contains(clientId.ToString())).ToList();
  29497. if (clientHotelInfos != null && clientHotelInfos.Count > 0)
  29498. {
  29499. //创建表格
  29500. Document hotelDoc = new Document();
  29501. DocumentBuilder HotelBuilder = new DocumentBuilder(hotelDoc);
  29502. GeneralMethod.SetupDocumentStyles(HotelBuilder);
  29503. GeneralMethod.AddTitle(HotelBuilder, $"{guestName} - 酒店信息");
  29504. GeneralMethod.AddHotelInfoSections(HotelBuilder, clientHotelInfos, "酒店信息");
  29505. var hotelRandomStr = Guid.NewGuid().ToString("N").Substring(0, 8);
  29506. var hotelFileName = $"{guestName}_酒店信息_{hotelRandomStr}.docx";
  29507. hotelDoc.Save($"{path}/{hotelFileName}");
  29508. }
  29509. #endregion
  29510. }
  29511. #endregion
  29512. //打包文件夹
  29513. var sourceDirectory = $"{sourceDirectoryPath}/{dirName}";
  29514. var zipFilePath = $"{sourceDirectoryPath}/{dirName}.zip";
  29515. if (System.IO.File.Exists(zipFilePath))
  29516. {
  29517. System.IO.File.Delete(zipFilePath);
  29518. }
  29519. ZipFile.CreateFromDirectory(sourceDirectory, zipFilePath, CompressionLevel.Fastest, false);
  29520. // 等待并验证
  29521. await Task.Delay(100); // 给系统时间完成文件操作
  29522. if (System.IO.File.Exists(zipFilePath))
  29523. {
  29524. var fileInfo = new FileInfo(zipFilePath);
  29525. var url = $"{rootRrl}Office/GrpFile/VisaProcessFiles/{groupName}/{dirName}.zip";
  29526. //记录下载日志
  29527. await _visaProcessRep.LogOperationAsync(null, null, "Download", currUserId);
  29528. return Ok(JsonView(StatusCodes.Status200OK, "操作成功!", url));
  29529. }
  29530. return Ok(JsonView(false));
  29531. }
  29532. /// <summary>
  29533. /// 团组签证流程 - 根据步骤记录ID获取该步骤的所有操作日志
  29534. /// </summary>
  29535. /// <returns></returns>
  29536. [HttpGet]
  29537. public async Task<IActionResult> VisaProcessLogByStepId(int stepId)
  29538. {
  29539. //参数验证
  29540. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.Id == stepId && x.IsDel == 0).FirstAsync();
  29541. if (stepValid == null) return Ok(JsonView(false, "签证流程ID无效。"));
  29542. var logs = await _visaProcessRep.GetStepLogsAsync(stepId);
  29543. return Ok(JsonView(logs));
  29544. }
  29545. /// <summary>
  29546. /// 团组签证流程 - 根据团组ID获取该团组下所有步骤的操作日志
  29547. /// </summary>
  29548. /// <returns></returns>
  29549. [HttpGet]
  29550. public async Task<IActionResult> VisaProcessLogByGroupId(int groupId)
  29551. {
  29552. //参数验证
  29553. var stepValid = await _sqlSugar.Queryable<Grp_VisaProcessSteps>().Where(x => x.GroupId == groupId && x.IsDel == 0).FirstAsync();
  29554. if (stepValid == null) return Ok(JsonView(false, "团组ID无效。"));
  29555. var logs = await _visaProcessRep.GetGroupStepLogsAsync(groupId);
  29556. return Ok(JsonView(logs));
  29557. }
  29558. #endregion
  29559. #region 团组总览进程
  29560. /// <summary>
  29561. /// 团组总览进程 - 流程创建测试
  29562. /// </summary>
  29563. /// <returns></returns>
  29564. [HttpGet]
  29565. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29566. public async Task<IActionResult> GroupProcessInitTest(int groupId, int currUserId)
  29567. {
  29568. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  29569. }
  29570. /// <summary>
  29571. /// 团组总览进程 - 团组名称集合
  29572. /// </summary>
  29573. /// <returns></returns>
  29574. [HttpGet()]
  29575. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29576. public async Task<IActionResult> GroupProcessGroupNames()
  29577. {
  29578. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29579. .Where(x => x.IsDel == 0)
  29580. .OrderByDescending(x => x.VisitDate)
  29581. .Select(x => new
  29582. {
  29583. x.Id,
  29584. GroupName = x.TeamName,
  29585. HasProcess = SqlFunc.Subqueryable<Grp_ProcessOverview>()
  29586. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  29587. .Any()
  29588. })
  29589. .ToListAsync();
  29590. return Ok(JsonView(groupNames));
  29591. }
  29592. /// <summary>
  29593. /// 团组总览进程 - 流程详情
  29594. /// </summary>
  29595. /// <returns></returns>
  29596. [HttpGet]
  29597. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29598. public async Task<IActionResult> GroupProcessDetails(int groupId)
  29599. {
  29600. var res = await _processOverviewRep.ProcessesDetailsAsync(groupId);
  29601. if (res.Code == StatusCodes.Status200OK)
  29602. {
  29603. return Ok(JsonView(res.Data));
  29604. }
  29605. return Ok(JsonView(false, res.Msg));
  29606. }
  29607. /// <summary>
  29608. /// 团组总览进程 - 更新节点状态
  29609. /// </summary>
  29610. /// <returns></returns>
  29611. [HttpPost]
  29612. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29613. public async Task<IActionResult> GroupProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  29614. {
  29615. var res = await _processOverviewRep.UpdateNodeStatusSimpleAsync(dto.NodeId, dto.CurrUserId);
  29616. if (res.Code == StatusCodes.Status200OK)
  29617. {
  29618. return Ok(JsonView(res.Data));
  29619. }
  29620. return Ok(JsonView(false, res.Msg));
  29621. }
  29622. /// <summary>
  29623. /// 团组总览进程 - 更新签证节点信息
  29624. /// </summary>
  29625. /// <returns></returns>
  29626. [HttpPost]
  29627. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29628. public async Task<IActionResult> GroupProcessUpdateVisaNodeDetails(GroupProcessUpdateVisaNodeDetailsDto dto)
  29629. {
  29630. //验证签证信息
  29631. if (dto.VisaSubNodes.Count < 1) return Ok(JsonView(false, "请传入有效的签证节点信息。"));
  29632. var res = await _processOverviewRep.UpdateVisaNodeDetailsAsync(dto);
  29633. if (res.Code == StatusCodes.Status200OK)
  29634. {
  29635. return Ok(JsonView(res.Data));
  29636. }
  29637. return Ok(JsonView(false, res.Msg));
  29638. }
  29639. /// <summary>
  29640. /// 团组总览进程 - 设置实际完成时间
  29641. /// </summary>
  29642. /// <returns></returns>
  29643. [HttpPost]
  29644. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29645. public async Task<IActionResult> GroupProcessSetActualDone(GroupProcessSetActualDoneDto dto)
  29646. {
  29647. //验证签证信息
  29648. var res = await _processOverviewRep.SetActualDoneAsync(dto);
  29649. if (res.Code == StatusCodes.Status200OK)
  29650. {
  29651. return Ok(JsonView(res.Data));
  29652. }
  29653. return Ok(JsonView(false, res.Msg));
  29654. }
  29655. #endregion
  29656. #region 团组会务总览进程
  29657. /// <summary>
  29658. /// 团组会务总览进程 - 流程创建测试
  29659. /// </summary>
  29660. /// <returns></returns>
  29661. [HttpGet]
  29662. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29663. public async Task<IActionResult> ConfProcessInitTest(int groupId, int currUserId)
  29664. {
  29665. return Ok(await _processOverviewRep.ProcessInitAsync(groupId, currUserId));
  29666. }
  29667. /// <summary>
  29668. /// 团组会务总览进程 - 基础信息集合(团组名称、参与人信息)
  29669. /// </summary>
  29670. /// <returns></returns>
  29671. [HttpGet]
  29672. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29673. public async Task<IActionResult> ConfProcessGroupNames()
  29674. {
  29675. var groupTypes = new List<int>() {
  29676. 302, // 成都-会务活动
  29677. 691, // 四川-会务活动
  29678. 762, // 四川-赛事项目收入
  29679. 1047 // 成都-赛事项目收入
  29680. };
  29681. var groupNames = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  29682. .Where(x => x.IsDel == 0 && groupTypes.Contains(x.TeamDid))
  29683. .OrderByDescending(x => x.VisitDate)
  29684. .Select(x => new
  29685. {
  29686. x.Id,
  29687. GroupName = x.TeamName,
  29688. HasProcess = SqlFunc.Subqueryable<Grp_ConfProcessOverview>()
  29689. .Where(po => po.GroupId == x.Id && po.IsDel == 0)
  29690. .Any()
  29691. })
  29692. .ToListAsync();
  29693. var participators = await _sqlSugar.Queryable<Sys_Users>()
  29694. .Where(x => x.IsDel == 0 && x.DepId == 5)
  29695. .Select(x => new ParticipatorInfo()
  29696. {
  29697. UserId = x.Id,
  29698. UserName = x.CnName
  29699. })
  29700. .ToListAsync();
  29701. var view = new { groupNames, participators };
  29702. return Ok(JsonView(view));
  29703. }
  29704. /// <summary>
  29705. /// 团组会务总览进程 - 获取节点模板信息
  29706. /// </summary>
  29707. /// <returns></returns>
  29708. [HttpGet]
  29709. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29710. public async Task<IActionResult> ConfProcessNodeTempInfos(int groupId, int currUserId)
  29711. {
  29712. var nodeTemps1 = await _processOverviewRep.DefaultConfProcessTemps(groupId, currUserId);
  29713. var nodeTemps = nodeTemps1.Select(x => new
  29714. {
  29715. TempId = x.ProcessOrder,
  29716. TempName = $"情况{x.ProcessOrder}",
  29717. //TempNodes = x.Nodes
  29718. }).ToList();
  29719. return Ok(JsonView(nodeTemps));
  29720. }
  29721. /// <summary>
  29722. /// 团组会务总览进程 - 更新节点模板
  29723. /// </summary>
  29724. /// <param name="groupId">团组Id</param>
  29725. /// <param name="nodeTempId">节点模板Id</param>
  29726. /// <param name="currUserId">当前用户Id</param>
  29727. /// <returns></returns>
  29728. [HttpGet]
  29729. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29730. public async Task<IActionResult> ConfProcessChangeNodeTempSave(int groupId, int nodeTempId, int currUserId)
  29731. {
  29732. var res = await _processOverviewRep.ConfProcessChangeNodeTempSaveAsync(groupId, nodeTempId, currUserId);
  29733. if (res.Code == StatusCodes.Status200OK)
  29734. {
  29735. return Ok(JsonView(res.Data));
  29736. }
  29737. return Ok(JsonView(false, res.Msg));
  29738. }
  29739. /// <summary>
  29740. /// 团组会务总览进程 - 流程详情
  29741. /// </summary>
  29742. /// <param name="groupId">团组Id</param>
  29743. /// <param name="currUserId">当前userId</param>
  29744. /// <returns></returns>
  29745. [HttpGet]
  29746. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29747. public async Task<IActionResult> ConfProcessDetails(int groupId, int currUserId)
  29748. {
  29749. var res = await _processOverviewRep.ConfProcessesDetailsAsync(groupId, currUserId);
  29750. if (res.Code == StatusCodes.Status200OK)
  29751. {
  29752. return Ok(JsonView(res.Data));
  29753. }
  29754. return Ok(JsonView(false, res.Msg));
  29755. }
  29756. /// <summary>
  29757. /// 团组会务总览进程 - 更新节点状态
  29758. /// </summary>
  29759. /// <returns></returns>
  29760. [HttpPost]
  29761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29762. public async Task<IActionResult> ConfProcessUpdateNodeStatus(GroupProcessUpdateNodeStatusDto dto)
  29763. {
  29764. var res = await _processOverviewRep.UpdateConfNodeStatusAsync(dto.NodeId, dto.CurrUserId);
  29765. if (res.Code == StatusCodes.Status200OK)
  29766. {
  29767. return Ok(JsonView(res.Data));
  29768. }
  29769. return Ok(JsonView(false, res.Msg));
  29770. }
  29771. /// <summary>
  29772. /// 团组会务总览进程 - 设置实际完成时间及其他信息
  29773. /// </summary>
  29774. /// <returns></returns>
  29775. [HttpPost]
  29776. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  29777. public async Task<IActionResult> ConfProcessSetActualDone(ConfProcessSetActualDoneDto dto)
  29778. {
  29779. var res = await _processOverviewRep.SetNodeInfoAsync(dto);
  29780. if (res.Code == StatusCodes.Status200OK)
  29781. {
  29782. return Ok(JsonView(res.Data));
  29783. }
  29784. return Ok(JsonView(false, res.Msg));
  29785. }
  29786. #endregion
  29787. }
  29788. }