GeneralMethod.cs 345 KB

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