GeneralMethod.cs 351 KB

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