GeneralMethod.cs 352 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817
  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. /// 混元提示词构建(高度定制化,适配商邀资料场景)
  1476. /// </summary>
  1477. /// <param name="tasks">包含国家及 Count 数量的任务列表</param>
  1478. /// <param name="countryTasks"></param>
  1479. /// <param name="entryInfo">包含规则基础信息</param>
  1480. /// <returns>最终构建的 System Prompt 字符串</returns>
  1481. public static string BuildHunyuanPrompt(List<CountryAIPormptInfo> tasks, List<AITaskItem> countryTasks, EntryInfo entryInfo)
  1482. {
  1483. // 行业信息,用于提示词硬约束
  1484. string industryEnum = string.Join("、", IndustryTree.Build().Select(x => x.NameCn).ToList());
  1485. var businessConstraints = new StringBuilder();
  1486. if (entryInfo.Industries.Any()) businessConstraints.AppendLine($" - 行业信息: {string.Join("、", entryInfo.Industries)}");
  1487. if (entryInfo.ScaleTypes.Any()) businessConstraints.AppendLine($" - 单位规模: {string.Join("、", entryInfo.ScaleTypes)}");
  1488. if (entryInfo.IsBackground) businessConstraints.AppendLine($" - 单位是否包含华人背景: 是");
  1489. if (!string.IsNullOrEmpty(entryInfo.OrgLevel) && !entryInfo.OrgLevel.Equals("全部")) businessConstraints.AppendLine($" - 公司层级: {entryInfo.OrgLevel}");
  1490. if (!string.IsNullOrEmpty(entryInfo.OtherConstraints)) businessConstraints.AppendLine($" - 其他规则: {entryInfo.OtherConstraints}");
  1491. if (businessConstraints == null || businessConstraints.Length == 0) businessConstraints.AppendLine("无");
  1492. return $@"
  1493. # [SYSTEM_ROLE]
  1494. 顶级商务咨询顾问。精通全球实时经贸情报。输出 JSON 必须 100% 兼容强类型反序列化。遵循:无存证不输出、官网优先、AB管道证伪、零虚构熔断。
  1495. # [CONTEXT]
  1496. CurrentDate: {DateTime.Now:yyyy-MM-dd}
  1497. OriginUnit: {entryInfo.OriginUnit}
  1498. BusinessConstraints: {businessConstraints}
  1499. CountryTasks: {JsonConvert.SerializeObject(countryTasks)}
  1500. Tasks: {JsonConvert.SerializeObject(tasks)}
  1501. # [REALITY_CHECK_RULES]
  1502. ## 1. 企业存在性三位一体核验(多源公证)
  1503. 必须同时满足,且每项至少通过 **两种独立、可公证的来源** 交叉验证:
  1504. - 官网可访问且业务匹配(来源:企业官网 + 工商/协会/权威媒体)
  1505. - 管道A:目标国工商/证券/经商处备案(来源:政府公示 + 权威平台)
  1506. - 管道B:LinkedIn(官方认证页)/Bloomberg/Crunchbase 近3年动态(来源:平台 + 媒体)
  1507. → 任一核心字段无法通过多源公证 → 整条作废
  1508. ### 可接受的公证件来源(任选 ≥ 2):
  1509. - 政府/监管:工商注册、证券交易所、驻华经商处
  1510. - 国际平台:LinkedIn(认证页)、Bloomberg、Crunchbase
  1511. - 行业协会/展会:国际农业展、种业协会名录
  1512. - 主流媒体:Reuters、Bloomberg、当地财经媒体
  1513. - 企业披露:官网 About / Contact / Imprint
  1514. ### 不可作为公证来源:
  1515. - Wikipedia、论坛、博客、聚合导航站、模型推断
  1516. ## 2. 实时可达性检测
  1517. SiteUrl / PostUrl 必须通过:
  1518. - DNS 成功
  1519. - HTTP 200,响应 < 5s
  1520. - HTML ≥ 500 字符
  1521. - 不含:404/not found/page not found/under maintenance/coming soon/site is temporarily down
  1522. → SiteUrl 不通过 → SiteUrl 返回 """"
  1523. → PostUrl 不通过 → PostUrl 返回 []
  1524. ## 3. 软 404 熔断
  1525. URL 含以下关键词 → 死链:
  1526. 404 Not Found, Page Not Found, Oops, Seite nicht gefunden, foundpage, 链接不存在
  1527. → SiteUrl 命中 → SiteUrl 返回 """"
  1528. → PostUrl 命中 → PostUrl 返回 []
  1529. ## 4. 属地物理地址强校验
  1530. - 地址必须在 CountryTasks 指定国家
  1531. - 与官网 Contact/Imprint/About Us 完全一致
  1532. - Google Maps / OpenStreetMap 可验证真实建筑
  1533. - 非虚拟办公室 / P.O. Box / 商业中心
  1534. → 不通过 → 整条作废
  1535. ## 5. 英文命名清洗
  1536. NameEn 严禁包含:
  1537. LTD, LLC, JSC, AO, TOO, IP, PLC, INC, CORP, GMBH, AG, BV, NV 等
  1538. → 仅保留核心品牌名,与官网首页 Title 一致
  1539. → 清洗后为空或通用词 → 整条作废
  1540. ## 6. 链接健康评分 ≥ 90
  1541. DNS(20)+HTTP200(30)+HTML≥500(20)+无软死链(20)+归属企业一致(10)
  1542. → <90 → 对应 URL 直接丢弃
  1543. ## 7. 官网地址刚性约束(Zero-Guess Rule)
  1544. - SiteUrl 必须是企业在互联网上真实存在、可直接访问的官网地址;
  1545. - AI 严禁对网址进行任何形式的拼接、补全、改写或推断;
  1546. - 仅允许原样返回企业在官网、工商备案或 AB 管道中公开披露的地址;
  1547. - 严禁添加国别编码、语言路径、查询参数、目录层级或任何模型生成的路径片段;
  1548. - 若模型无法确认某个网址的真实存在性,则该字段必须返回空字符串。
  1549. ## 8. 零容忍熔断
  1550. 触发任一即终止条目:
  1551. - 官网不可达
  1552. - 地址无法地图验证
  1553. - 企业无法三位一体证伪
  1554. - 任何字段推测性补全
  1555. → 严禁为填满配额降低标准
  1556. ## 9. 时效约束
  1557. • 所有数据必须是 {DateTime.Now.Year} 当天检测结果
  1558. • 禁止缓存 / 历史快照 / 旧索引
  1559. # [BUSINESS_CONSTRAINTS]
  1560. - 零虚构:禁止编造企业/人名/链接/动态
  1561. - Industry 严格锁定
  1562. - Scale 严格匹配
  1563. - NameEn 执行命名清洗
  1564. # [QUOTA]
  1565. - 有效条目不足允许 < 配额
  1566. - 禁止凑数,禁止降级标准
  1567. # [EXECUTION_PIPELINE]
  1568. 严格顺序执行,禁止跳步、禁止提前生成企业名称或 JSON:
  1569. 1. 解析 CountryTasks + BusinessConstraints
  1570. 2. 检索候选企业(仅目标国)
  1571. 3. 多源公证核验(官网 + 管道A + 管道B + 交叉验证)
  1572. - 企业名称、官网、地址、联系方式必须通过 ≥2 个独立来源验证
  1573. 4. 官网实时可达性检测(DNS/HTTP/HTML)
  1574. 5. 软 404 与链接健康评分 ≥ 90
  1575. 6. 属地物理地址强校验(地图实体验证)
  1576. 7. 英文命名清洗
  1577. 8. 提取字段(官网优先,AB 管道补位)
  1578. - SiteUrl 必须原样取自企业公开信息,禁止任何形式的拼接、改写或补全;
  1579. - 拿不准就留空,严禁生成“看起来合理”的地址。
  1580. 9. 最终零容忍熔断检查
  1581. 10. 输出纯净 JSON 或失败审计
  1582. # [FAILURE_AUDIT_HOOK]
  1583. 若最终输出为空数组 [],必须改用以下格式输出(仅字符串,不含 JSON):
  1584. AuditReason::StepX::{{失败原因}}
  1585. 示例:
  1586. AuditReason::Step3::多源公证失败,企业名称仅出现在单一来源
  1587. AuditReason::Step3::多源公证失败,官网地址无法通过工商与平台交叉验证
  1588. AuditReason::Step4::官网不可达,DNS解析失败
  1589. AuditReason::Step7::官网地址为模型拼接,已熔断
  1590. # [OUTPUT_SCHEMA]
  1591. PascalCase,禁止新增字段:
  1592. [
  1593. {{{{
  1594. ""Region"":""string"",
  1595. ""Industry"":""string"",
  1596. ""Scale"":""string"",
  1597. ""NameCn"":""string"",
  1598. ""NameEn"":""string"",
  1599. ""Address"":""string"",
  1600. ""Scope"":""string"",
  1601. ""Contact"":""string"",
  1602. ""Phone"":""string"",
  1603. ""Email"":""string"",
  1604. ""SiteUrl"":""string"",
  1605. ""PostUrl"":[{{{{""Date"":""yyyy-MM-dd"",""Description"":""string"",""Url"":""string""}}}}],
  1606. ""RecLevel"":""Core|Backup"",
  1607. ""IntgAdvice"":""string""
  1608. }}}}
  1609. ]
  1610. # [OUTPUT_RULES]
  1611. • 非空结果:仅输出 JSON
  1612. • 空结果:仅输出 AuditReason 字符串
  1613. • 不输出 Markdown / 解释 / 思考过程
  1614. • JSON 首字符 [,末字符 ]
  1615. • 空结果输出 []
  1616. # [EXECUTE]
  1617. 立即执行:以 {DateTime.Now.Year} 为锚点,严格按 EXECUTION_PIPELINE 执行,任何步骤失败即终止并输出 AuditReason。
  1618. ";
  1619. }
  1620. /// <summary>
  1621. /// 失败审计结构
  1622. /// </summary>
  1623. /// <param name="IsSuccess"></param>
  1624. /// <param name="Data"></param>
  1625. /// <param name="AuditStep"></param>
  1626. /// <param name="AuditReason"></param>
  1627. public record HunyuanAuditResult<T>(
  1628. bool IsSuccess,
  1629. List<T>? Data,
  1630. string? AuditStep,
  1631. string? AuditReason
  1632. );
  1633. /// <summary>
  1634. /// 失败审计解析器
  1635. /// </summary>
  1636. /// <param name="raw"></param>
  1637. /// <returns></returns>
  1638. public static HunyuanAuditResult<T> ParseHunyuanResult<T>(string raw)
  1639. {
  1640. if (string.IsNullOrWhiteSpace(raw))
  1641. return new(false, null, "Unknown", "AI 返回空内容");
  1642. // 失败审计(Prompt 约定)
  1643. if (raw.TrimStart().StartsWith("AuditReason::"))
  1644. {
  1645. var parts = raw.Split("::", 3, StringSplitOptions.RemoveEmptyEntries);
  1646. return new(
  1647. false,
  1648. null,
  1649. parts.ElementAtOrDefault(1) ?? "Unknown",
  1650. parts.ElementAtOrDefault(2) ?? "未说明原因"
  1651. );
  1652. }
  1653. try
  1654. {
  1655. var data = JsonConvert.DeserializeObject<List<T>>(raw);
  1656. return new(true, data, null, null);
  1657. }
  1658. catch
  1659. {
  1660. return new(false, null, "Parse", "JSON 解析失败,原始内容非预期格式");
  1661. }
  1662. }
  1663. /// <summary>
  1664. /// 步骤错误提示
  1665. /// </summary>
  1666. /// <param name="step"></param>
  1667. /// <returns></returns>
  1668. public static string GetFrontendAuditTitle(string step) => step switch
  1669. {
  1670. "Step3" => "未找到符合条件的境外单位备案信息",
  1671. "Step4" => "境外单位官网暂不可访问",
  1672. "Step6" => "境外单位办公地址无法核验",
  1673. "Step10" => "本次未检索到符合条件的境外单位",
  1674. "Parse" => "AI 返回数据格式异常",
  1675. _ => "境外单位检索未完成"
  1676. };
  1677. /// <summary>
  1678. /// 审计失败原因
  1679. /// </summary>
  1680. /// <param name="reason"></param>
  1681. /// <returns></returns>
  1682. public static string GetFrontendAuditReason(string reason) => reason switch
  1683. {
  1684. "三位一体核验失败,无工商备案" => "未在目标国官方系统中查到注册信息",
  1685. "官网不可达,DNS解析失败" => "官网暂时无法访问",
  1686. "地址无法在Google Maps验证为真实建筑" => "办公地址无法确认实际存在",
  1687. _ => reason
  1688. };
  1689. #endregion
  1690. #region 基础数据 整合
  1691. /// <summary>
  1692. /// 商邀AI invName 整合
  1693. /// </summary>
  1694. /// <returns></returns>
  1695. public static async Task<List<InvitationAIInvNameView>> InvitationAIInvName()
  1696. {
  1697. // 预定义 UnionAll 查询
  1698. var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
  1699. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  1700. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
  1701. var query2 = _sqlSugar.Queryable<Res_InvitationAI>()
  1702. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
  1703. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime });
  1704. var unionQuery = _sqlSugar.UnionAll(query1, query2);
  1705. // 先进行去重逻辑处理
  1706. var distinctQuery = _sqlSugar.Queryable(unionQuery)
  1707. .PartitionBy(it => it.Name)
  1708. .OrderByDescending(it => it.SortTime)
  1709. .Select(it => it);
  1710. // 将去重后的结果包装,再进行全局
  1711. return await _sqlSugar.Queryable(distinctQuery)
  1712. .OrderByDescending(it => it.Source)
  1713. .OrderByDescending(it => it.SortTime)
  1714. .ToListAsync();
  1715. }
  1716. /// <summary>
  1717. /// 商邀AI-无团组 invName 整合
  1718. /// </summary>
  1719. /// <returns></returns>
  1720. public static async Task<List<InvitationAIInvNameView>> InvitationAI_NoGroupInvName()
  1721. {
  1722. return await _sqlSugar.Queryable<Res_InvitationAI_NoGroup>()
  1723. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.InvName))
  1724. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.InvName, Source = 2, SortTime = x.CreateTime })
  1725. .OrderByDescending(it => it.Source)
  1726. .OrderByDescending(it => it.SortTime)
  1727. .ToListAsync();
  1728. }
  1729. /// <summary>
  1730. /// 商邀AI ClientName 处理
  1731. /// </summary>
  1732. /// <returns></returns>
  1733. public static async Task<List<string>> InvitationAIClientName()
  1734. {
  1735. var rawEncryptedDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1736. .Where(x => x.IsDel == 0 && x.Client != null)
  1737. .Select(x => x.Client)
  1738. .ToListAsync();
  1739. // 解密 -> 去空格 -> 排除横杠 -> 去重
  1740. var unitNames = rawEncryptedDatas
  1741. .Select(encryptedItem =>
  1742. {
  1743. try
  1744. {
  1745. return AesEncryptionHelper.Decrypt(encryptedItem);
  1746. }
  1747. catch
  1748. {
  1749. return null; // 异常解密处理
  1750. }
  1751. })
  1752. .Where(decrypted => !string.IsNullOrWhiteSpace(decrypted)) // 排除空或纯空格
  1753. .Select(decrypted => decrypted.Replace(" ", "")) // 去除所有内部空格
  1754. .Where(cleaned => !cleaned.Contains("-")) // 此时过滤解密后的 "-" 才有效
  1755. .Distinct() // 最终去重
  1756. .ToList();
  1757. return unitNames;
  1758. }
  1759. /// <summary>
  1760. /// 商邀AI CountryName 处理
  1761. /// </summary>
  1762. /// <returns></returns>
  1763. public static async Task<List<string>> InvitationAICountryName()
  1764. {
  1765. var counties = await _sqlSugar.Queryable<Sys_Countries>()
  1766. .Where(x => x.IsDel == 0)
  1767. .Select(x => x.Name_CN)
  1768. .Distinct()
  1769. .ToListAsync();
  1770. // 处理特殊城市 如 香港、澳门 等,统一为国家级别
  1771. var targetCities = new List<string> { "澳门", "香港" };
  1772. var cities = await _sqlSugar.Queryable<Sys_Cities>()
  1773. .LeftJoin<Sys_Countries>((city, country) => city.CountriesId == country.Id)
  1774. .Where(city => city.IsDel == 0 && targetCities.Contains(city.Name_CN))
  1775. .Select((city, country) => country.Name_CN + "(" + city.Name_CN + ")")
  1776. .ToListAsync();
  1777. // 合并
  1778. var result = counties.Union(cities).ToList();
  1779. // 自定义排序:中国相关优先,其他按拼音排序
  1780. var customOrder = result.OrderBy(x => !x.Contains("中国")) // 包含"中国"的排前面
  1781. .ThenBy(x => x) // 再按字母排序
  1782. .ToList();
  1783. return customOrder;
  1784. }
  1785. #endregion
  1786. #endregion
  1787. #region op地接资料 AI
  1788. #region 提示词构建
  1789. /// <summary>
  1790. /// 混元提示词构建(国外地接公司 · AI 自动采集专用 · 完整最终版)
  1791. /// </summary>
  1792. /// <param name="tasks">国家 & 数量配额</param>
  1793. /// <param name="entryInfo">业务约束</param>
  1794. /// <returns>System Prompt</returns>
  1795. public static string OpLocalBuildHunyuanPrompt(
  1796. List<CountryAIPormptInfo> tasks,
  1797. EntryInfo entryInfo)
  1798. {
  1799. #region 1. 业务约束拼接
  1800. var businessConstraints = new StringBuilder();
  1801. if (entryInfo.ScaleTypes?.Any() == true)
  1802. businessConstraints.AppendLine($" - 单位规模: {string.Join("、", entryInfo.ScaleTypes)}");
  1803. if (entryInfo.IsBackground)
  1804. businessConstraints.AppendLine(" - 是否包含华人背景: 是");
  1805. if (!string.IsNullOrEmpty(entryInfo.OrgLevel) && entryInfo.OrgLevel != "全部")
  1806. businessConstraints.AppendLine($" - 公司层级: {entryInfo.OrgLevel}");
  1807. if (!string.IsNullOrEmpty(entryInfo.OtherConstraints))
  1808. businessConstraints.AppendLine($" - 其他规则: {entryInfo.OtherConstraints}");
  1809. if (businessConstraints.Length == 0)
  1810. businessConstraints.AppendLine("无");
  1811. #endregion
  1812. #region 2. Prompt 主体
  1813. return $@"
  1814. # [SYSTEM_ROLE]
  1815. 你是全球旅游与地接行业的【顶级情报采集系统】。
  1816. 你具备 .NET 6 强类型架构思维,输出 JSON 必须 100% 可直接反序列化。
  1817. 你信奉唯一铁律:**无官网不收录、无许可不采信、无存证不输出**。
  1818. # [CONTEXT_ANALYSIS]
  1819. • 基准时间: {DateTime.Now:yyyy-MM-dd}
  1820. • 业务约束:
  1821. {businessConstraints}
  1822. # [COUNTRY_QUOTA_MATRIX - 动态国家配额]
  1823. 以下为国家及其对应的**最大获取数量**(严格锁定):
  1824. {string.Join("\n", tasks.Select(t => $"- {t.Country}: {t.Count} 家"))}
  1825. 🚨 配额规则:
  1826. - 每个国家 **不得超过** 指定数量
  1827. - 若无法满足数量要求,**允许少于配额**
  1828. - 严禁跨国家凑数
  1829. - 严禁编造企业填补空缺
  1830. # [COUNTRY_SCOPE_LOCK - 国家白名单]
  1831. 允许采集的国家列表(严格锁定):
  1832. {string.Join("、", tasks.Select(t => t.Country))}
  1833. 🚨 最高禁令:
  1834. - 严禁采集上述国家以外的任何地接公司
  1835. - 严禁通过翻译、联想、扩展国家名称
  1836. # [CORE_COLLECTION_RULES - 自动采集五锁机制]
  1837. ## 🔒 锁 1:企业存在性(Anti-Hallucination)
  1838. - 严禁编造、推测或拼接地接公司名称
  1839. - 必须同时满足:
  1840. 1. 官网可访问(SiteUrl)
  1841. 2. 当地旅游许可可查证
  1842. 3. Google Maps 存在实体办公地址
  1843. ## 🔒 锁 2:官网真实性(Soft-404 熔断)
  1844. - 若 SiteUrl 命中以下特征 → 整条作废:
  1845. - 404 / Not Found / Oops
  1846. - Seite nicht gefunden
  1847. - foundpage / 链接不存在
  1848. ## 🔒 锁 3:属地物理地址(GEO_LOCK)
  1849. - 禁止虚拟办公室 / 信箱 / 注册代理地址
  1850. - 地址必须:
  1851. - 位于指定国家境内
  1852. - 与官网 Contact / Imprint 页面一致
  1853. - Google Maps / Apple Maps 可精确定位
  1854. - 输出格式:街道 + 城市 + 州/省 + 邮编 + 国家
  1855. ## 🔒 锁 4:车队与资源真实性(FLEET_REALITY_LOCK)
  1856. - 必须同时包含:
  1857. - 数量(如:15辆)
  1858. - 品牌 + 车型(如:奔驰商务)
  1859. - 座位数(如:7座)
  1860. - 推荐格式:
  1861. > 15辆奔驰商务(7座)
  1862. - 模糊描述 → FleetInfo 返回空
  1863. ## 🔒 锁 5:Email 校验与复制规则(VALIDATE_THEN_COPY)
  1864. ### ✅ 校验流程
  1865. AI 必须按顺序执行:
  1866. 1. 格式合法(xxx@domain.com)
  1867. 2. 域名可解析
  1868. 3. MX 记录存在(逻辑判断)
  1869. 4. 邮箱域名 ≈ 官网域名(关键)
  1870. ### ✅ 复制规则
  1871. - **仅当 1+2+3+4 全部通过**
  1872. → 才写入 `Email`
  1873. - 否则:
  1874. - `Email` 返回空
  1875. - 原始邮箱写入 `EmailInfo.Address`
  1876. ### 🚨 严禁
  1877. - 将未通过校验的邮箱写入 Email
  1878. - 为了“有数据”强行复制
  1879. # [OUTPUT_SCHEMA - STRICT]
  1880. 属性命名 PascalCase,禁止新增字段:
  1881. [
  1882. {{
  1883. ""Region"": ""string"",
  1884. ""Industry"": ""旅游与地接"",
  1885. ""Scale"": ""string"",
  1886. ""NameCn"": ""string"",
  1887. ""NameEn"": ""string"",
  1888. ""Address"": ""string"",
  1889. ""Scope"": ""string"",
  1890. ""Contact"": ""string"",
  1891. ""Phone"": ""string"",
  1892. ""Email"": ""string"",
  1893. ""SiteUrl"": ""string"",
  1894. ""PostUrl"": [
  1895. {{ ""Date"": ""yyyy-MM-dd"", ""Description"": ""string"", ""Url"": ""string"" }}
  1896. ],
  1897. ""RecLevel"": ""Core|Backup"",
  1898. ""IntgAdvice"": ""string"",
  1899. ""RiskNote"": ""string"",
  1900. ""License"": {{
  1901. ""LicenseNo"": ""string"",
  1902. ""LocalLicense"": ""string"",
  1903. ""DotNumber"": ""string"",
  1904. ""AssociationMember"": ""string"",
  1905. ""LiabilityInsurance"": ""string""
  1906. }},
  1907. ""Resource"": {{
  1908. ""BusinessScope"": ""string"",
  1909. ""FleetInfo"": ""string"",
  1910. ""GuideInfo"": ""string"",
  1911. ""DirectContract"": ""string"",
  1912. ""IsDirectSupplier"": true
  1913. }}
  1914. }}
  1915. ]
  1916. # [OUTPUT_GUARDRAILS]
  1917. - 仅输出 JSON
  1918. - 不输出 Markdown
  1919. - 不输出解释、不输出思考过程
  1920. - 首字符 `[`,末字符 `]`
  1921. - 无结果时输出 `[]`
  1922. # [EXECUTE_NOW]
  1923. 以 {DateTime.Now:yyyy-MM-dd} 为时间锚点,
  1924. 仅在以下国家范围内执行全自动采集:
  1925. {string.Join("、", tasks.Select(t => t.Country))}
  1926. 并严格遵守各国配额限制,
  1927. 执行五锁机制,输出纯净 JSON。
  1928. ";
  1929. #endregion
  1930. }
  1931. public class AICreateEmailTask
  1932. {
  1933. public string Country { get; set; }
  1934. public string City { get; set; }
  1935. public int PersonCount { get; set; }
  1936. public string DateRange { get; set; }
  1937. public List<LocalAgencyInfo> Agencies { get; set; }
  1938. public EntryInfo EntryInfo { get; set; }
  1939. }
  1940. /// <summary>
  1941. /// 混元提示词构建(多公司 / 多国家 / 多城市)
  1942. /// </summary>
  1943. public static string BuildBatchCreateEmailPrompt(
  1944. AICreateEmailTask task)
  1945. {
  1946. var agenciesJson = JsonConvert.SerializeObject(
  1947. task.Agencies.Select(a => new
  1948. {
  1949. a.NameCn,
  1950. a.NameEn,
  1951. a.Region,
  1952. //a.City,
  1953. a.Contact,
  1954. a.Email,
  1955. a.SiteUrl,
  1956. a.Scope,
  1957. a.Resource?.FleetInfo
  1958. }));
  1959. return $@"
  1960. # [SYSTEM_ROLE]
  1961. 你是国际地接与商务考察的【用车与报价专家】。
  1962. 你具备 .NET 强类型架构思维,输出 JSON 必须 100% 可直接反序列化。
  1963. # [CONTEXT]
  1964. • 当前时间: {DateTime.Now:yyyy-MM-dd}
  1965. • 发起单位: {task.EntryInfo.OriginUnit}
  1966. • 出访人数: {task.PersonCount}
  1967. • 出访日期: {task.DateRange}
  1968. # [TASK]
  1969. 请针对以下每家地接公司,分别生成一封**首次报价请求邮件**:
  1970. {agenciesJson}
  1971. # [RULES - 每家公司独立处理]
  1972. 1. 每家公司:
  1973. - 国家 = Company.Region
  1974. - 城市 = Company.City
  1975. - 车型必须基于 Company.FleetInfo
  1976. 2. 禁止编造车型
  1977. 3. 若 FleetInfo 无法匹配人数:
  1978. - 请在邮件中说明
  1979. - 请对方推荐替代方案
  1980. 4. 邮件语言:
  1981. - 默认:英文
  1982. - Region = 日本 → 追加日文
  1983. - Region = 韩国 → 追加韩文
  1984. # [OUTPUT_SCHEMA - STRICT]
  1985. 请返回 JSON 数组,每项对应一家公司:
  1986. [
  1987. {{
  1988. ""Guid"": """",
  1989. ""NameCn"": ""string"",
  1990. ""Scope"": ""string"",
  1991. ""Subject"": ""string"",
  1992. ""Content"": ""string(纯文本,\n 表示换行)""
  1993. }}
  1994. ]
  1995. # [OUTPUT_GUARDRAILS]
  1996. - 仅输出 JSON
  1997. - 不输出 Markdown
  1998. - 不输出解释
  1999. - 首字符 [,末字符 ]
  2000. # [EXECUTE_NOW]
  2001. 基于上述公司列表,
  2002. 为每家公司生成一封高回复率的首次报价请求邮件,
  2003. 并以 AICreateEmailInfo 格式返回纯净 JSON。
  2004. ";
  2005. }
  2006. #endregion
  2007. #region 基础数据
  2008. /// <summary>
  2009. /// op地接资料AI 团组名称整理
  2010. /// </summary>
  2011. /// <returns></returns>
  2012. public static async Task<List<InvitationAIInvNameView>> OpLocalServiceAINames()
  2013. {
  2014. // 预定义 UnionAll 查询
  2015. var query1 = _sqlSugar.Queryable<Grp_DelegationInfo>()
  2016. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.TeamName))
  2017. .Select(x => new InvitationAIInvNameView { Id = x.Id, Name = x.TeamName, Source = 1, SortTime = x.VisitDate });
  2018. var unionQuery = _sqlSugar.UnionAll(query1);
  2019. // 先进行去重逻辑处理
  2020. var distinctQuery = _sqlSugar.Queryable(unionQuery)
  2021. .PartitionBy(it => it.Name)
  2022. .OrderByDescending(it => it.SortTime)
  2023. .Select(it => it);
  2024. // 将去重后的结果包装,再进行全局
  2025. return await _sqlSugar.Queryable(distinctQuery)
  2026. .OrderByDescending(it => it.Source)
  2027. .OrderByDescending(it => it.SortTime)
  2028. .ToListAsync();
  2029. }
  2030. #endregion
  2031. #endregion
  2032. #endregion
  2033. #region 团组汇率
  2034. /// <summary>
  2035. /// 团组汇率
  2036. /// 获取板块 币种 及 汇率
  2037. /// 76 酒店预订 77 行程 79 车/导游地接
  2038. /// 80 签证 82 团组客户保险 85 机票预订
  2039. /// 98 其他款项 285 收款退还
  2040. /// </summary>
  2041. /// <param name="teamRateModels"></param>
  2042. /// <param name="cTable"></param>
  2043. /// <param name="currencyCodes"></param>
  2044. /// <returns>
  2045. /// string
  2046. /// eg: CNY 1.0000
  2047. /// </returns>
  2048. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  2049. {
  2050. string str = "";
  2051. List<string> currencyRates = new List<string>();
  2052. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  2053. if (hotelRateData != null)
  2054. {
  2055. var hotelRates = hotelRateData.TeamRates;
  2056. foreach (var item in currencyCodes)
  2057. {
  2058. if (!string.IsNullOrEmpty(item))
  2059. {
  2060. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  2061. if (hotelRateInfo != null)
  2062. {
  2063. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  2064. currencyRates.Add(str1);
  2065. }
  2066. }
  2067. }
  2068. if (currencyRates != null || currencyRates.Count > 0)
  2069. {
  2070. currencyRates = currencyRates.Distinct().ToList();
  2071. foreach (var item in currencyRates)
  2072. {
  2073. str += item;
  2074. }
  2075. }
  2076. }
  2077. return str;
  2078. }
  2079. /// <summary>
  2080. /// 团组汇率 币种 Item (来源:团组汇率)
  2081. /// 根据 团组Id And 业务类型(CTable)Id
  2082. /// api处理CTable = 285,默认返回CNY
  2083. /// </summary>
  2084. /// <param name="portType"></param>
  2085. /// <param name="diId"></param>
  2086. /// <param name="cTable"></param>
  2087. /// <returns></returns>
  2088. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  2089. {
  2090. return await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  2091. }
  2092. /// <summary>
  2093. /// 汇率备注拆分
  2094. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  2095. /// </summary>
  2096. /// <param name="rateRemark"></param>
  2097. /// <returns></returns>
  2098. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  2099. {
  2100. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  2101. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  2102. #region 获取所有币种
  2103. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  2104. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  2105. if (DBdata == null || DBdata.Count == 0)
  2106. {
  2107. return _view;
  2108. }
  2109. currencyDatas = DBdata.Select(x => new SetDataInfoView
  2110. {
  2111. Name = x.Name,
  2112. Id = x.Id,
  2113. Remark = x.Remark,
  2114. }).ToList();
  2115. #endregion
  2116. #region 拆分remark里的汇率
  2117. if (string.IsNullOrEmpty(rateRemark))
  2118. {
  2119. return _view;
  2120. }
  2121. if (rateRemark.Contains("|"))
  2122. {
  2123. string[] currencyArr = rateRemark.Split("|");
  2124. foreach (string currency in currencyArr)
  2125. {
  2126. string[] currency1 = currency.Split(":");
  2127. string[] currency2 = currency1[0].Split("(");
  2128. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  2129. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  2130. {
  2131. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  2132. CurrencyCode = currencyCode,
  2133. CurrencyName = currency2[0],
  2134. Rate = decimal.Parse(currency1[1]),
  2135. };
  2136. _view.Add(rateDescView);
  2137. }
  2138. }
  2139. else
  2140. {
  2141. try
  2142. {
  2143. string[] currency1 = rateRemark.Split(":");
  2144. string[] currency2 = currency1[0].Split("(");
  2145. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  2146. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  2147. {
  2148. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  2149. CurrencyCode = currencyCode,
  2150. CurrencyName = currency2[0],
  2151. Rate = decimal.Parse(currency1[1]),
  2152. };
  2153. _view.Add(rateDescView);
  2154. }
  2155. catch (Exception)
  2156. {
  2157. return _view;
  2158. }
  2159. }
  2160. #endregion
  2161. return _view;
  2162. }
  2163. #endregion
  2164. #region 汉字转换拼音
  2165. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  2166. {
  2167. var chs = text.ToCharArray();
  2168. //记录每个汉字的全拼
  2169. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  2170. for (int i = 0; i < chs.Length; i++)
  2171. {
  2172. var pinyinList = new List<string>();
  2173. //是否是有效的汉字
  2174. if (ChineseChar.IsValidChar(chs[i]))
  2175. {
  2176. ChineseChar cc = new ChineseChar(chs[i]);
  2177. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  2178. }
  2179. else
  2180. {
  2181. pinyinList.Add(chs[i].ToString());
  2182. }
  2183. //去除声调,转小写
  2184. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  2185. //去重
  2186. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  2187. if (pinyinList.Any())
  2188. {
  2189. totalPingYinList[i] = pinyinList;
  2190. }
  2191. }
  2192. return totalPingYinList;
  2193. }
  2194. /// <summary>
  2195. /// 获取汉语拼音全拼
  2196. /// </summary>
  2197. /// <param name="text">The string.</param>
  2198. /// <returns></returns>
  2199. public static List<string> GetTotalPingYin(this string text)
  2200. {
  2201. var result = new List<string>();
  2202. foreach (var pys in GetTotalPingYinDictionary(text))
  2203. {
  2204. var items = pys.Value;
  2205. if (result.Count <= 0)
  2206. {
  2207. result = items;
  2208. }
  2209. else
  2210. {
  2211. //全拼循环匹配
  2212. var newTotalPingYinList = new List<string>();
  2213. foreach (var totalPingYin in result)
  2214. {
  2215. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  2216. }
  2217. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  2218. result = newTotalPingYinList;
  2219. }
  2220. }
  2221. return result;
  2222. }
  2223. /// <summary>
  2224. /// 获取中文第一个拼音
  2225. /// </summary>
  2226. /// <param name="text"></param>
  2227. /// <param name="isUp"></param>
  2228. /// <returns></returns>
  2229. public static string GetTotalPingYinFirst(this string text, bool isUp = true)
  2230. {
  2231. var returnstr = string.Empty;
  2232. var enResult = text.GetTotalPingYin();
  2233. if (enResult.Count == 0)
  2234. {
  2235. returnstr = text;
  2236. }
  2237. else if (isUp)
  2238. {
  2239. returnstr = enResult[0].ToUpper();
  2240. }
  2241. else
  2242. {
  2243. returnstr = enResult[0].ToLower();
  2244. }
  2245. return returnstr;
  2246. }
  2247. /// <summary>
  2248. /// 获取汉语拼音首字母
  2249. /// </summary>
  2250. /// <param name="text"></param>
  2251. /// <returns></returns>
  2252. public static List<string> GetFirstPingYin(this string text)
  2253. {
  2254. var result = new List<string>();
  2255. foreach (var pys in GetTotalPingYinDictionary(text))
  2256. {
  2257. var items = pys.Value;
  2258. if (result.Count <= 0)
  2259. {
  2260. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  2261. }
  2262. else
  2263. {
  2264. //首字母循环匹配
  2265. var newFirstPingYinList = new List<string>();
  2266. foreach (var firstPingYin in result)
  2267. {
  2268. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  2269. }
  2270. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  2271. result = newFirstPingYinList;
  2272. }
  2273. }
  2274. return result;
  2275. }
  2276. #endregion
  2277. #region 新客户资料表 操作记录
  2278. /// <summary>
  2279. /// 新客户资料表
  2280. /// 操作记录添加
  2281. /// </summary>
  2282. /// <param name="portType"></param>
  2283. /// <param name="operationEnum"></param>
  2284. /// <param name="userId"></param>
  2285. /// <param name="dataId"></param>
  2286. /// <param name="remark"></param>
  2287. /// <returns></returns>
  2288. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  2289. {
  2290. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  2291. {
  2292. TableName = "Crm_NewClientData",
  2293. PortType = portType,
  2294. OperationItem = operationEnum,
  2295. DataId = dataId,
  2296. CreateUserId = userId,
  2297. CreateTime = DateTime.Now,
  2298. Remark = remark
  2299. };
  2300. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  2301. if (add) return false;
  2302. return false;
  2303. }
  2304. #endregion
  2305. #region 金额转大写
  2306. /// <summary>
  2307. /// 金额转换为大写数字
  2308. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  2309. /// <para>2、小数点后最多支持两位</para>
  2310. /// </summary>
  2311. /// <param name="num">数值</param>
  2312. /// <returns></returns>
  2313. public static string ConvertCNYUpper(this decimal num)
  2314. {
  2315. if (num == 0)
  2316. {
  2317. return "零元";
  2318. }
  2319. // 解决327000000转换后缺少单位万的问题
  2320. return ConvertToChinese(num);
  2321. }
  2322. #region 实例
  2323. /// <summary>
  2324. /// 要转换的数字
  2325. /// </summary>
  2326. private static decimal j;
  2327. /// <summary>
  2328. ///
  2329. /// </summary>
  2330. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  2331. /// <summary>
  2332. /// 判断输入的数字是否大于double类型
  2333. /// </summary>
  2334. private static bool IsNumber
  2335. {
  2336. get
  2337. {
  2338. if (j > decimal.MaxValue || j <= 0)
  2339. return false;
  2340. else
  2341. return true;
  2342. }
  2343. }
  2344. /// <summary>
  2345. /// 数字转换成大写汉字主函数
  2346. /// </summary>
  2347. /// <returns>返回转换后的大写汉字</returns>
  2348. public static string ConvertToChinese(decimal m)
  2349. {
  2350. j = m;
  2351. string bb = "";
  2352. if (IsNumber)
  2353. {
  2354. string str = j.ToString();
  2355. string[] Num = str.Split('.');
  2356. if (Num.Length == 1)
  2357. {
  2358. bb = NumberString(Num[0]) + "元整";
  2359. bb = bb.Replace("零零", "零");
  2360. }
  2361. else
  2362. {
  2363. bb = NumberString(Num[0]) + "元";
  2364. bb += FloatString(Num[1]);
  2365. bb = bb.Replace("零零", "零");
  2366. }
  2367. }
  2368. else
  2369. {
  2370. throw new FormatException("你输入的数字格式不正确或不是数字!");
  2371. }
  2372. return bb;
  2373. }
  2374. /// <summary>
  2375. /// 小数位转换只支持两位的小数
  2376. /// </summary>
  2377. /// <param name="Num">转换的小数</param>
  2378. /// <returns>小数转换成汉字</returns>
  2379. private static string FloatString(string Num)
  2380. {
  2381. string cc = "";
  2382. if (Num.Length > 2)
  2383. {
  2384. throw new FormatException("小数位数过多.");
  2385. }
  2386. else
  2387. {
  2388. string bb = ConvertString(Num);
  2389. int len = bb.IndexOf("零");
  2390. if (len != 0)
  2391. {
  2392. bb = bb.Replace("零", "");
  2393. if (bb.Length == 1)
  2394. {
  2395. cc = bb.Substring(0, 1) + "角";
  2396. }
  2397. else
  2398. {
  2399. cc = bb.Substring(0, 1) + "角";
  2400. cc += bb.Substring(1, 1) + "分";
  2401. }
  2402. }
  2403. else
  2404. cc = bb + "分";
  2405. }
  2406. return cc;
  2407. }
  2408. /// <summary>
  2409. /// 判断数字位数以进行拆分转换
  2410. /// </summary>
  2411. /// <param name="Num">要进行拆分的数字</param>
  2412. /// <returns>转换成的汉字</returns>
  2413. private static string NumberString(string Num)
  2414. {
  2415. string bb = "";
  2416. if (Num.Length <= 4)
  2417. {
  2418. bb = Convert4(Num);
  2419. }
  2420. else if (Num.Length > 4 && Num.Length <= 8)
  2421. {
  2422. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  2423. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  2424. }
  2425. else if (Num.Length > 8 && Num.Length <= 12)
  2426. {
  2427. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  2428. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  2429. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  2430. bb += "零";
  2431. else
  2432. bb += "";
  2433. else
  2434. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  2435. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  2436. }
  2437. else
  2438. {
  2439. throw new Exception("整数部分最多支持12位");
  2440. }
  2441. return bb;
  2442. }
  2443. /// <summary>
  2444. /// 四位数字的转换
  2445. /// </summary>
  2446. /// <param name="Num">准备转换的四位数字</param>
  2447. /// <returns>转换以后的汉字</returns>
  2448. private static string Convert4(string Num)
  2449. {
  2450. string bb = "";
  2451. if (Num.Length == 1)
  2452. {
  2453. bb = ConvertString(Num);
  2454. }
  2455. else if (Num.Length == 2)
  2456. {
  2457. bb = ConvertString(Num);
  2458. bb = Convert2(bb);
  2459. }
  2460. else if (Num.Length == 3)
  2461. {
  2462. bb = ConvertString(Num);
  2463. bb = Convert3(bb);
  2464. }
  2465. else
  2466. {
  2467. bb = ConvertString(Num);
  2468. string cc = "";
  2469. string len = bb.Substring(0, 4);
  2470. if (len != "零零零零")
  2471. {
  2472. len = bb.Substring(0, 3);
  2473. if (len != "零零零")
  2474. {
  2475. bb = bb.Replace("零零零", "");
  2476. if (bb.Length == 1)
  2477. {
  2478. bb = bb.Substring(0, 1) + "仟";
  2479. }
  2480. else
  2481. {
  2482. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  2483. cc = bb.Substring(0, 1) + "仟";
  2484. else
  2485. cc = bb.Substring(0, 1);
  2486. bb = cc + Convert3(bb.Substring(1, 3));
  2487. }
  2488. }
  2489. else
  2490. {
  2491. bb = bb.Replace("零零零", "零");
  2492. }
  2493. }
  2494. else
  2495. {
  2496. bb = bb.Replace("零零零零", "");
  2497. }
  2498. }
  2499. return bb;
  2500. }
  2501. /// <summary>
  2502. /// 将数字转换成汉字
  2503. /// </summary>
  2504. /// <param name="Num">需要转换的数字</param>
  2505. /// <returns>转换后的汉字</returns>
  2506. private static string ConvertString(string Num)
  2507. {
  2508. string bb = "";
  2509. for (int i = 0; i < Num.Length; i++)
  2510. {
  2511. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  2512. }
  2513. return bb;
  2514. }
  2515. /// <summary>
  2516. /// 两位数字的转换
  2517. /// </summary>
  2518. /// <param name="Num">两位数字</param>
  2519. /// <returns>转换后的汉字</returns>
  2520. private static string Convert2(string Num)
  2521. {
  2522. string bb = ""; string cc = "";
  2523. string len = Num.Substring(0, 1);
  2524. if (len != "零")
  2525. {
  2526. bb = Num.Replace("零", "");
  2527. if (bb.Length == 1)
  2528. {
  2529. cc = bb.Substring(0, 1) + "拾";
  2530. }
  2531. else
  2532. {
  2533. cc = bb.Substring(0, 1) + "拾";
  2534. cc += bb.Substring(1, 1);
  2535. }
  2536. }
  2537. else
  2538. cc = Num;
  2539. return cc;
  2540. }
  2541. /// <summary>
  2542. /// 三位数字的转换
  2543. /// </summary>
  2544. /// <param name="Num">三位数字</param>
  2545. /// <returns>转换后的汉字</returns>
  2546. private static string Convert3(string Num)
  2547. {
  2548. string bb = ""; string cc = "";
  2549. string len = Num.Substring(0, 2);
  2550. if (len != "零零")
  2551. {
  2552. bb = Num.Replace("零零", "");
  2553. if (bb.Length == 1)
  2554. {
  2555. bb = bb.Substring(0, 1) + "佰";
  2556. }
  2557. else
  2558. {
  2559. if (bb.Substring(0, 1) != "零")
  2560. cc = bb.Substring(0, 1) + "佰";
  2561. else
  2562. cc = bb.Substring(0, 1);
  2563. bb = cc + Convert2(bb.Substring(1, 2));
  2564. }
  2565. }
  2566. else
  2567. {
  2568. bb = Num.Replace("零零", "零");
  2569. }
  2570. return bb;
  2571. }
  2572. #endregion
  2573. #endregion
  2574. #region 数字验证
  2575. /// <summary>
  2576. /// 验证数字字符串
  2577. /// </summary>
  2578. /// <param name="numStr"></param>
  2579. /// <returns></returns>
  2580. public static bool IsNumeric(this string numStr)
  2581. {
  2582. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  2583. if (isNumeric)
  2584. {
  2585. return true;
  2586. }
  2587. return false;
  2588. }
  2589. #endregion
  2590. #region 日期 格式转换
  2591. /// <summary>
  2592. /// 验证日期字符串
  2593. /// </summary>
  2594. /// <param name="str"></param>
  2595. /// <returns></returns>
  2596. public static string ConvertToDatetime(this string str)
  2597. {
  2598. if (!string.IsNullOrEmpty(str))
  2599. {
  2600. DateTime currentDate = Convert.ToDateTime(str);
  2601. return $"{currentDate.Year}年{currentDate.Month}月{currentDate.Day}日";
  2602. }
  2603. return "";
  2604. }
  2605. #endregion
  2606. #region 月份/季度
  2607. /// <summary>
  2608. /// 获取月份对应的起始天数
  2609. /// </summary>
  2610. /// <param name="year"></param>
  2611. /// <returns></returns>
  2612. public static List<MonthInfo> GetMonthInfos(int year)
  2613. {
  2614. List<MonthInfo> months = new List<MonthInfo>();
  2615. if (year > 1)
  2616. {
  2617. for (int i = 1; i < 13; i++)
  2618. {
  2619. months.Add(new MonthInfo()
  2620. {
  2621. Month = i,
  2622. Days = new DaysInfo() { BeginDays = 1, EndDays = DateTime.DaysInMonth(year, i) }
  2623. });
  2624. }
  2625. }
  2626. return months;
  2627. }
  2628. /// <summary>
  2629. /// 获取季度对应的起始天数
  2630. /// </summary>
  2631. /// <param name="year"></param>
  2632. /// <returns></returns>
  2633. public static List<MonthInfo> GetQuarter(int year)
  2634. {
  2635. List<MonthInfo> months = new List<MonthInfo>();
  2636. months.Add(new MonthInfo() { Month = 1, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //1.1 - 3.31
  2637. months.Add(new MonthInfo() { Month = 2, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //4.1 - 6.30
  2638. months.Add(new MonthInfo() { Month = 3, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //7.1 - 9.31
  2639. months.Add(new MonthInfo() { Month = 4, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //10.1 - 12.31
  2640. return months;
  2641. }
  2642. public class MonthInfo
  2643. {
  2644. public int Month { get; set; }
  2645. public DaysInfo Days { get; set; }
  2646. }
  2647. public class DaysInfo
  2648. {
  2649. public int BeginDays { get; set; }
  2650. public int EndDays { get; set; }
  2651. }
  2652. #endregion
  2653. #region op行程单,黑屏幕代码
  2654. public static string GetCountryStandingTime(int diId)
  2655. {
  2656. DataTable datas = GetTableByBlackCode(diId);
  2657. string countryStr = "[黑屏代码未录入].";
  2658. if (datas.Rows.Count > 0)
  2659. {
  2660. var airDatas = from row in datas.AsEnumerable()
  2661. select new
  2662. {
  2663. Three = row.Field<string>("Three"),
  2664. Day = row.Field<string>("Day"),
  2665. ArrivedDate = row.Field<string>("ArrivedDate"),
  2666. };
  2667. //三字码信息
  2668. List<Res_ThreeCode> listcode = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToList();
  2669. //string countryStr = "";
  2670. int index = 0;
  2671. List<string> cityCodes = new List<string>();
  2672. //去掉开始和结束城市
  2673. foreach (var row in airDatas)
  2674. {
  2675. if (!string.IsNullOrEmpty(row.Three))
  2676. {
  2677. if (index == 0) cityCodes.Add(row.Three.Substring(3, 3)); //到达国家
  2678. else if (airDatas.Count() - 1 == index) cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  2679. else cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  2680. }
  2681. index++;
  2682. }
  2683. cityCodes = cityCodes.Distinct().ToList();
  2684. if (cityCodes.Count > 0) countryStr = "";
  2685. foreach (var item in cityCodes)
  2686. {
  2687. var airData = airDatas.Where(it => it.Three.Contains(item)).ToList();
  2688. string country = listcode.Find(it => it.Three.Equals(item))?.Country ?? "Unknown";
  2689. if (country.Equals("中国"))
  2690. {
  2691. country = listcode.Find(it => it.Three.Equals(item))?.City ?? "Unknown";
  2692. }
  2693. //int days = 0;
  2694. if (airData.Count == 2)
  2695. {
  2696. DateTime arr_dt = Convert.ToDateTime(airData[0].ArrivedDate); //抵达时间
  2697. DateTime dep_dt = Convert.ToDateTime(airData[1].Day); //离开时间
  2698. //days = (dep_dt - arr_dt).Days;
  2699. //countryStr += $@"{country}停留{days}日、";
  2700. countryStr += $@"{country}停留 日、";
  2701. }
  2702. }
  2703. if (countryStr.Length > 0) countryStr = countryStr.Substring(0, countryStr.Length - 1);
  2704. }
  2705. return countryStr;
  2706. }
  2707. /// <summary>
  2708. ///根据机票黑屏代码整理DataTable
  2709. /// </summary>
  2710. /// <param name="diid"></param>
  2711. /// <returns></returns>
  2712. public static DataTable GetTableByBlackCode1(int diid)
  2713. {
  2714. //黑屏代码信息
  2715. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  2716. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  2717. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  2718. DataTable dt = new DataTable();
  2719. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2720. dt.Columns.Add("Date", typeof(string));//起飞日期
  2721. dt.Columns.Add("Three", typeof(string));//三字码
  2722. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2723. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2724. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2725. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2726. dt.Columns.Add("AirModel", typeof(string)); //机型
  2727. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2728. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2729. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2730. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2731. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2732. //判断是否录入黑屏代码
  2733. if (listcode.Count == 0 || listcode == null)
  2734. {
  2735. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null);
  2736. }
  2737. else
  2738. {
  2739. //读取单段黑屏代码
  2740. for (int i = 0; i < listcode.Count; i++)
  2741. {
  2742. //去除序号
  2743. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  2744. //去除多余空格,方法一Linq扩展方法
  2745. CodeList = CodeList.Where(str => str != "").ToArray();
  2746. CodeList = CodeList.Where(str => str != " ").ToArray();
  2747. //年
  2748. int year = Convert.ToInt32(DateTime.Now.Year.ToString());
  2749. //读取单条黑屏代码
  2750. for (int j = 0; j < CodeList.Length; j++)
  2751. {
  2752. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  2753. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  2754. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2755. //string[] Info = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  2756. // .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2757. //去除多余空格
  2758. Info = Info.Where(str => str != "").ToArray();
  2759. Info = Info.Where(str => str != " ").ToArray();
  2760. //判断黑屏代码是否正确拆分; 理应拆成9段
  2761. if (Info.Length < 9)
  2762. {
  2763. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null);
  2764. }
  2765. else
  2766. {
  2767. try
  2768. {
  2769. //月
  2770. int month = Convert.ToInt32(GetLonger(Info[1].Substring(4, 3)));
  2771. //日
  2772. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  2773. #region 逐一比较月份,判断是否翻年;逐一比较三字码顶真,判断是否跑错机场
  2774. if (j > 0)
  2775. {
  2776. string[] Temp = CodeList[j - 1].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  2777. .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2778. Temp = Temp.Where(str => str != "").ToArray();
  2779. Temp = Temp.Where(str => str != " ").ToArray();
  2780. int monthTemp = Convert.ToInt32(GetLonger(Temp[1].Substring(4, 3)));
  2781. // 如果相邻月份之差小于0,则证明次一条年份需+1
  2782. if (month - monthTemp < 0)
  2783. {
  2784. year = year + 1;
  2785. }
  2786. //如果相邻代码三字码不顶真,提醒
  2787. string FootThree = Temp[2].Substring(3, 3);
  2788. string HeadThree = Info[2].Substring(0, 3);
  2789. if (FootThree != HeadThree)
  2790. {
  2791. //DelegationInfoService s = new DelegationInfoService();
  2792. //UsersService us = new UsersService();
  2793. //GroupsTaskAssignmentService gts = new GroupsTaskAssignmentService();
  2794. //77 行程
  2795. List<Grp_GroupsTaskAssignment> list2 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 77 && x.DIId == diid && x.IsDel == 0).ToList();
  2796. foreach (var temp in list2)
  2797. {
  2798. //if (temp.UId != 21)
  2799. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  2800. // "黑屏代码提醒",
  2801. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  2802. }
  2803. //85 机票预订
  2804. List<Grp_GroupsTaskAssignment> list6 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 85 && x.DIId == diid && x.IsDel == 0).ToList();
  2805. foreach (var temp in list6)
  2806. {
  2807. //if (temp.UId != 21)
  2808. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  2809. // "黑屏代码提醒",
  2810. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  2811. }
  2812. }
  2813. }
  2814. #endregion
  2815. #region 判断到达日期是否需要加1
  2816. if (Info[4].Contains("+"))
  2817. {
  2818. //日期+1
  2819. day = day + 1;
  2820. //判断是否进入下一月
  2821. if (day > Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year)))
  2822. {
  2823. day = day - Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year));
  2824. month = month + 1;
  2825. //判断是否进入下一年
  2826. if (month > 12)
  2827. {
  2828. month = month - 12;
  2829. year = year + 1;
  2830. }
  2831. }
  2832. //月份整理格式
  2833. string monthTemp = month.ToString();
  2834. if (month < 10)
  2835. {
  2836. monthTemp = "0" + monthTemp;
  2837. }
  2838. //日期整理格式
  2839. string daytemp = day.ToString();
  2840. if (day < 10)
  2841. {
  2842. daytemp = "0" + daytemp;
  2843. }
  2844. string temp = Info[4].Split('+')[0];
  2845. //添加起飞数据
  2846. dt.Rows.Add(Info[0],
  2847. Info[1],
  2848. Info[2],
  2849. Info[3],
  2850. temp,
  2851. Info[5],
  2852. Info[6],
  2853. Info[7],
  2854. Info[8],
  2855. year + "-" + GetLonger(Info[1].Substring(4, 3)) + "-" + Info[1].Substring(2, 2),
  2856. year + "-" + monthTemp + "-" + daytemp,
  2857. "",
  2858. "0");
  2859. //加1天,添加到达数据
  2860. dt.Rows.Add(Info[0],
  2861. Info[1].Replace(Info[1].Substring(2, 2), daytemp),
  2862. Info[2],
  2863. Info[3],
  2864. temp,
  2865. Info[5],
  2866. Info[6],
  2867. Info[7],
  2868. Info[8],
  2869. year + "-" + monthTemp + "-" + daytemp,
  2870. year + "-" + monthTemp + "-" + daytemp,
  2871. "",
  2872. "1");
  2873. }
  2874. else
  2875. {
  2876. //月份整理格式
  2877. string monthTemp = month.ToString();
  2878. if (month < 10)
  2879. {
  2880. monthTemp = "0" + monthTemp;
  2881. }
  2882. //日期整理格式
  2883. string daytemp = day.ToString();
  2884. if (day < 10)
  2885. {
  2886. daytemp = "0" + daytemp;
  2887. }
  2888. dt.Rows.Add(Info[0],
  2889. Info[1],
  2890. Info[2],
  2891. Info[3],
  2892. Info[4],
  2893. Info[5],
  2894. Info[6],
  2895. Info[7],
  2896. Info[8],
  2897. year + "-" + monthTemp + "-" + daytemp,
  2898. year + "-" + monthTemp + "-" + daytemp,
  2899. "",
  2900. "0");
  2901. }
  2902. #endregion
  2903. }
  2904. catch (Exception ex)
  2905. {
  2906. string exstr = ex.Message.ToString();
  2907. }
  2908. }
  2909. }
  2910. //排序
  2911. dt.DefaultView.Sort = "Day asc";
  2912. dt = dt.DefaultView.ToTable();
  2913. }
  2914. }
  2915. return dt;
  2916. }
  2917. private readonly static string[] excludeArr = new string[] { "[中转]", "[转机]", "[国内]" };
  2918. /// <summary>
  2919. ///根据机票黑屏代码整理DataTable
  2920. /// </summary>
  2921. /// <param name="diid"></param>
  2922. /// <returns></returns>
  2923. public static DataTable GetTableByBlackCode(int diid)
  2924. {
  2925. //黑屏代码信息
  2926. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  2927. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  2928. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  2929. DataTable dt = new DataTable();
  2930. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2931. dt.Columns.Add("Date", typeof(string));//起飞日期
  2932. dt.Columns.Add("Three", typeof(string));//三字码
  2933. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2934. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2935. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2936. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2937. dt.Columns.Add("AirModel", typeof(string)); //机型
  2938. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2939. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2940. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2941. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  2942. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2943. //添加转机标识
  2944. dt.Columns.Add("isTransitShipment", typeof(bool));
  2945. //判断是否录入黑屏代码
  2946. if (listcode.Count == 0 || listcode == null)
  2947. {
  2948. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false);
  2949. }
  2950. else
  2951. {
  2952. //读取单段黑屏代码
  2953. for (int i = 0; i < listcode.Count; i++)
  2954. {
  2955. //去除序号
  2956. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  2957. //去除多余空格,方法一Linq扩展方法
  2958. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2959. //读取单条黑屏代码
  2960. for (int j = 0; j < CodeList.Length; j++)
  2961. {
  2962. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  2963. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  2964. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  2965. //去除多余空格
  2966. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  2967. //判断黑屏代码是否正确拆分; 理应拆成9段
  2968. if (Info.TakeWhile((x) =>
  2969. {
  2970. return !excludeArr.Contains(x);
  2971. }).Count() != 9)
  2972. {
  2973. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false);
  2974. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  2975. return dt;
  2976. }
  2977. else
  2978. {
  2979. try
  2980. {
  2981. var monthEn = Info[1].Substring(4, 3);
  2982. //月
  2983. int month = Convert.ToInt32(GetLonger(monthEn));
  2984. //日
  2985. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  2986. var time = new DateTime(DateTime.Now.Year, month, day); //
  2987. var isExist = Info.Contains("[中转]");
  2988. //dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  2989. //dt.Columns.Add("Date", typeof(string));//起飞日期
  2990. //dt.Columns.Add("Three", typeof(string));//三字码
  2991. //dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  2992. //dt.Columns.Add("EndTime", typeof(string));//到达时刻
  2993. //dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  2994. //dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  2995. //dt.Columns.Add("AirModel", typeof(string)); //机型
  2996. //dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  2997. //dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  2998. //dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  2999. //dt.Columns.Add("Error", typeof(string));//整理的到达日期
  3000. //dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  3001. dt.Rows.Add(Info[0],
  3002. Info[1],
  3003. Info[2],
  3004. Info[3],
  3005. Info[4],
  3006. Info[5],
  3007. Info[6],
  3008. Info[7],
  3009. Info[8],
  3010. time.ToString("yyyy-MM-dd"),
  3011. time.ToString("yyyy-MM-dd"),
  3012. "",
  3013. "0",
  3014. isExist
  3015. );
  3016. }
  3017. catch (Exception ex)
  3018. {
  3019. string exstr = ex.Message.ToString();
  3020. }
  3021. }
  3022. }
  3023. //排序
  3024. dt.DefaultView.Sort = "Day asc";
  3025. dt = dt.DefaultView.ToTable();
  3026. }
  3027. }
  3028. return dt;
  3029. }
  3030. /// <summary>
  3031. ///根据黑屏代码整理DataTable
  3032. /// </summary>
  3033. /// <param name="blackCode"></param>
  3034. /// <returns></returns>
  3035. public static DataTable GetTableByBlackCodeBySingle(Air_TicketBlackCode blackCode)
  3036. {
  3037. DataTable dt = new DataTable();
  3038. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  3039. dt.Columns.Add("Date", typeof(string));//起飞日期
  3040. dt.Columns.Add("Three", typeof(string));//三字码
  3041. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  3042. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  3043. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  3044. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  3045. dt.Columns.Add("AirModel", typeof(string)); //机型
  3046. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  3047. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  3048. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  3049. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  3050. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  3051. //添加转机标识
  3052. dt.Columns.Add("isTransitShipment", typeof(bool));
  3053. //添加国内段标识
  3054. dt.Columns.Add("isDomesticSection", typeof(bool));
  3055. //判断是否录入黑屏代码
  3056. if (blackCode == null)
  3057. {
  3058. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false, false);
  3059. }
  3060. else
  3061. {
  3062. var listcode = new List<Air_TicketBlackCode> { blackCode };
  3063. //读取单段黑屏代码
  3064. for (int i = 0; i < listcode.Count; i++)
  3065. {
  3066. //去除序号
  3067. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  3068. //去除多余空格,方法一Linq扩展方法
  3069. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  3070. //读取单条黑屏代码
  3071. for (int j = 0; j < CodeList.Length; j++)
  3072. {
  3073. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  3074. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  3075. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  3076. //去除多余空格
  3077. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  3078. //判断黑屏代码是否正确拆分; 理应拆成9段
  3079. if (Info.TakeWhile((x) =>
  3080. {
  3081. return !excludeArr.Contains(x);
  3082. }).Count() != 9)
  3083. {
  3084. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false, false);
  3085. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  3086. return dt;
  3087. }
  3088. else
  3089. {
  3090. try
  3091. {
  3092. var monthEn = Info[1].Substring(4, 3);
  3093. //月
  3094. int month = Convert.ToInt32(GetLonger(monthEn));
  3095. //日
  3096. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  3097. var time = new DateTime(DateTime.Now.Year, month, day); //
  3098. var isExist = Info.Contains("[中转]");
  3099. if (!isExist)
  3100. {
  3101. isExist = Info.Contains("[转机]");
  3102. }
  3103. var isDomesticSection = Info.Contains("[国内]");
  3104. if (isDomesticSection)
  3105. {
  3106. continue;
  3107. }
  3108. dt.Rows.Add(Info[0],
  3109. Info[1],
  3110. Info[2],
  3111. Info[3],
  3112. Info[4],
  3113. Info[5],
  3114. Info[6],
  3115. Info[7],
  3116. Info[8],
  3117. time.ToString("yyyy-MM-dd"),
  3118. time.ToString("yyyy-MM-dd"),
  3119. "",
  3120. ExtractNumberAfterPlus(Info[4]),
  3121. isExist,
  3122. isDomesticSection
  3123. );
  3124. }
  3125. catch (Exception ex)
  3126. {
  3127. string exstr = ex.Message.ToString();
  3128. }
  3129. }
  3130. }
  3131. //排序
  3132. dt.DefaultView.Sort = "Day asc";
  3133. dt = dt.DefaultView.ToTable();
  3134. }
  3135. }
  3136. return dt;
  3137. }
  3138. private static int ExtractNumberAfterPlus(string input)
  3139. {
  3140. int value = 0;
  3141. if (string.IsNullOrEmpty(input))
  3142. {
  3143. return value;
  3144. }
  3145. string pattern = @"\+\d+"; // 匹配“+”及其后的数字
  3146. System.Text.RegularExpressions.Match match = Regex.Match(input, pattern);
  3147. if (match.Success)
  3148. {
  3149. int.TryParse(match.Value.Substring(1), out value); // 去掉“+”符号,只保留数字部分
  3150. }
  3151. return value;
  3152. }
  3153. /// <summary>
  3154. /// 根据星期,月份的缩写,转换成数字或者全称
  3155. /// 根据币种中文名称返回币种代码
  3156. /// 根据数字返回机型型号【2、3开头的就是空客,比如空客320,7开头的就是波音,比如波音777】
  3157. /// 20210903贾文滔
  3158. /// </summary>
  3159. /// <param name="temp"></param>
  3160. /// <returns></returns>
  3161. public static string GetLonger(string temp)
  3162. {
  3163. string str = "";
  3164. switch (temp.ToUpper())
  3165. {
  3166. case "美元":
  3167. str = "USD";
  3168. break;
  3169. case "日元":
  3170. str = "JPY";
  3171. break;
  3172. case "英镑":
  3173. str = "GBP";
  3174. break;
  3175. case "欧元":
  3176. str = "EUR";
  3177. break;
  3178. case "港币":
  3179. str = "HKD";
  3180. break;
  3181. case "MO":
  3182. str = "星期一";
  3183. break;
  3184. case "TU":
  3185. str = "星期二";
  3186. break;
  3187. case "WE":
  3188. str = "星期三";
  3189. break;
  3190. case "TH":
  3191. str = "星期四";
  3192. break;
  3193. case "FR":
  3194. str = "星期五";
  3195. break;
  3196. case "SA":
  3197. str = "星期六";
  3198. break;
  3199. case "SU":
  3200. str = "星期天";
  3201. break;
  3202. case "JAN":
  3203. str = "01";
  3204. break;
  3205. case "FEB":
  3206. str = "02";
  3207. break;
  3208. case "MAR":
  3209. str = "03";
  3210. break;
  3211. case "APR":
  3212. str = "04";
  3213. break;
  3214. case "MAY":
  3215. str = "05";
  3216. break;
  3217. case "JUN":
  3218. str = "06";
  3219. break;
  3220. case "JUL":
  3221. str = "07";
  3222. break;
  3223. case "AUG":
  3224. str = "08";
  3225. break;
  3226. case "SEP":
  3227. str = "09";
  3228. break;
  3229. case "OCT":
  3230. str = "10";
  3231. break;
  3232. case "NOV":
  3233. str = "11";
  3234. break;
  3235. case "DEC":
  3236. str = "12";
  3237. break;
  3238. case "MONDAY":
  3239. str = "星期一";
  3240. break;
  3241. case "TUESDAY":
  3242. str = "星期二";
  3243. break;
  3244. case "WEDNESDAY":
  3245. str = "星期三";
  3246. break;
  3247. case "THURSDAY":
  3248. str = "星期四";
  3249. break;
  3250. case "FRIDAY":
  3251. str = "星期五";
  3252. break;
  3253. case "SATURDAY":
  3254. str = "星期六";
  3255. break;
  3256. case "SUNDAY":
  3257. str = "星期日";
  3258. break;
  3259. case "01":
  3260. str = "JAN";
  3261. break;
  3262. case "02":
  3263. str = "FEB";
  3264. break;
  3265. case "03":
  3266. str = "MAR";
  3267. break;
  3268. case "04":
  3269. str = "APR";
  3270. break;
  3271. case "05":
  3272. str = "MAY";
  3273. break;
  3274. case "06":
  3275. str = "JUN";
  3276. break;
  3277. case "07":
  3278. str = "JUL";
  3279. break;
  3280. case "08":
  3281. str = "AUG";
  3282. break;
  3283. case "09":
  3284. str = "SEP";
  3285. break;
  3286. case "10":
  3287. str = "OCT";
  3288. break;
  3289. case "11":
  3290. str = "NOV";
  3291. break;
  3292. case "12":
  3293. str = "DEC";
  3294. break;
  3295. case "2":
  3296. str = "空客A";
  3297. break;
  3298. case "3":
  3299. str = "空客A";
  3300. break;
  3301. case "7":
  3302. str = "波音";
  3303. break;
  3304. }
  3305. return str;
  3306. }
  3307. /// <summary>
  3308. /// 根据月份返回天数
  3309. /// </summary>
  3310. /// <param name="Month"></param>
  3311. /// <param name="year"></param>
  3312. /// <returns></returns>
  3313. public static string GetDaysByMonth(string Month, int year)
  3314. {
  3315. string str = "";
  3316. //判断是否是闰年
  3317. if (DateTime.IsLeapYear(year) == false)
  3318. {
  3319. switch (Month.ToUpper())
  3320. {
  3321. case "JAN":
  3322. str = "31";
  3323. break;
  3324. case "FEB":
  3325. str = "28";
  3326. break;
  3327. case "MAR":
  3328. str = "31";
  3329. break;
  3330. case "APR":
  3331. str = "30";
  3332. break;
  3333. case "MAY":
  3334. str = "31";
  3335. break;
  3336. case "JUN":
  3337. str = "30";
  3338. break;
  3339. case "JUL":
  3340. str = "31";
  3341. break;
  3342. case "AUG":
  3343. str = "31";
  3344. break;
  3345. case "SEP":
  3346. str = "30";
  3347. break;
  3348. case "OCT":
  3349. str = "31";
  3350. break;
  3351. case "NOV":
  3352. str = "30";
  3353. break;
  3354. case "DEC":
  3355. str = "31";
  3356. break;
  3357. case "01":
  3358. str = "31";
  3359. break;
  3360. case "02":
  3361. str = "28";
  3362. break;
  3363. case "03":
  3364. str = "31";
  3365. break;
  3366. case "04":
  3367. str = "30";
  3368. break;
  3369. case "05":
  3370. str = "31";
  3371. break;
  3372. case "06":
  3373. str = "30";
  3374. break;
  3375. case "07":
  3376. str = "31";
  3377. break;
  3378. case "08":
  3379. str = "31";
  3380. break;
  3381. case "09":
  3382. str = "30";
  3383. break;
  3384. case "10":
  3385. str = "31";
  3386. break;
  3387. case "11":
  3388. str = "30";
  3389. break;
  3390. case "12":
  3391. str = "31";
  3392. break;
  3393. }
  3394. }
  3395. else
  3396. {
  3397. switch (Month.ToUpper())
  3398. {
  3399. case "JAN":
  3400. str = "31";
  3401. break;
  3402. case "FEB":
  3403. str = "29";
  3404. break;
  3405. case "MAR":
  3406. str = "31";
  3407. break;
  3408. case "APR":
  3409. str = "30";
  3410. break;
  3411. case "MAY":
  3412. str = "31";
  3413. break;
  3414. case "JUN":
  3415. str = "30";
  3416. break;
  3417. case "JUL":
  3418. str = "31";
  3419. break;
  3420. case "AUG":
  3421. str = "31";
  3422. break;
  3423. case "SEP":
  3424. str = "30";
  3425. break;
  3426. case "OCT":
  3427. str = "31";
  3428. break;
  3429. case "NOV":
  3430. str = "30";
  3431. break;
  3432. case "DEC":
  3433. str = "31";
  3434. break;
  3435. case "01":
  3436. str = "31";
  3437. break;
  3438. case "02":
  3439. str = "29";
  3440. break;
  3441. case "03":
  3442. str = "31";
  3443. break;
  3444. case "04":
  3445. str = "30";
  3446. break;
  3447. case "05":
  3448. str = "31";
  3449. break;
  3450. case "06":
  3451. str = "30";
  3452. break;
  3453. case "07":
  3454. str = "31";
  3455. break;
  3456. case "08":
  3457. str = "31";
  3458. break;
  3459. case "09":
  3460. str = "30";
  3461. break;
  3462. case "10":
  3463. str = "31";
  3464. break;
  3465. case "11":
  3466. str = "30";
  3467. break;
  3468. case "12":
  3469. str = "31";
  3470. break;
  3471. }
  3472. }
  3473. return str;
  3474. }
  3475. /// <summary>
  3476. /// op行程单 团组 城市路径
  3477. /// </summary>
  3478. /// <param name="diid">团组Id</param>
  3479. /// <param name="separator">分隔符</param>
  3480. /// <returns></returns>
  3481. public static string GetGroupCityLine(int diid, string separator)
  3482. {
  3483. string city = string.Empty;
  3484. var blackCode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  3485. if (blackCode.Count > 0)
  3486. {
  3487. var black = blackCode.First();
  3488. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3489. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3490. if (blackSp.Length > 0)
  3491. {
  3492. try
  3493. {
  3494. var cityArrCode = new List<string>(20);
  3495. foreach (var item in blackSp)
  3496. {
  3497. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3498. var IndexSelect = itemSp[2];
  3499. var cityArrCodeLength = cityArrCode.Count - 1;
  3500. var startCity = IndexSelect.Substring(0, 3);
  3501. if (cityArrCodeLength > 0)
  3502. {
  3503. var arrEndCity = cityArrCode[cityArrCodeLength];
  3504. if (arrEndCity != startCity)
  3505. {
  3506. cityArrCode.Add(startCity.ToUpper());
  3507. }
  3508. }
  3509. else
  3510. {
  3511. cityArrCode.Add(startCity.ToUpper());
  3512. }
  3513. var endCity = IndexSelect.Substring(3, 3);
  3514. cityArrCode.Add(endCity.ToUpper());
  3515. }
  3516. var cityThree = string.Empty;
  3517. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3518. cityThree = cityThree.TrimEnd(',');
  3519. if (string.IsNullOrWhiteSpace(cityThree))
  3520. {
  3521. throw new Exception("error");
  3522. }
  3523. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  3524. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  3525. foreach (var item in cityArrCode)
  3526. {
  3527. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3528. if (find != null)
  3529. {
  3530. city += find.City + separator;
  3531. }
  3532. else
  3533. {
  3534. city += item + "[三字码未收录]" + separator;
  3535. }
  3536. }
  3537. city = city.TrimEnd(char.Parse(separator));
  3538. }
  3539. catch (Exception e)
  3540. {
  3541. city = "[黑屏代码格式不正确!]";
  3542. }
  3543. }
  3544. }
  3545. else city = "[未录入黑屏代码]";
  3546. return city;
  3547. }
  3548. /// <summary>
  3549. /// op行程单 团组 城市路径
  3550. /// </summary>
  3551. /// <param name="black">黑屏代码实例</param>
  3552. /// <param name="separator">分隔符</param>
  3553. /// <returns></returns>
  3554. public static string GetGroupCityLine(Air_TicketBlackCode black, string separator)
  3555. {
  3556. string city = string.Empty;
  3557. if (black != null)
  3558. {
  3559. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3560. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3561. if (blackSp.Length > 0)
  3562. {
  3563. try
  3564. {
  3565. var cityArrCode = new List<string>(20);
  3566. foreach (var item in blackSp)
  3567. {
  3568. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3569. var IndexSelect = itemSp[2];
  3570. var cityArrCodeLength = cityArrCode.Count - 1;
  3571. var startCity = IndexSelect.Substring(0, 3);
  3572. if (cityArrCodeLength > 0)
  3573. {
  3574. var arrEndCity = cityArrCode[cityArrCodeLength];
  3575. if (arrEndCity != startCity)
  3576. {
  3577. cityArrCode.Add(startCity.ToUpper());
  3578. }
  3579. }
  3580. else
  3581. {
  3582. cityArrCode.Add(startCity.ToUpper());
  3583. }
  3584. var endCity = IndexSelect.Substring(3, 3);
  3585. cityArrCode.Add(endCity.ToUpper());
  3586. }
  3587. var cityThree = string.Empty;
  3588. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3589. cityThree = cityThree.TrimEnd(',');
  3590. if (string.IsNullOrWhiteSpace(cityThree))
  3591. {
  3592. throw new Exception("error");
  3593. }
  3594. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  3595. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  3596. foreach (var item in cityArrCode)
  3597. {
  3598. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3599. if (find != null)
  3600. {
  3601. city += find.City + separator;
  3602. }
  3603. else
  3604. {
  3605. city += item + "[三字码未收录]" + separator;
  3606. }
  3607. }
  3608. city = city.TrimEnd(char.Parse(separator));
  3609. }
  3610. catch (Exception e)
  3611. {
  3612. city = "[黑屏代码格式不正确!]";
  3613. }
  3614. }
  3615. }
  3616. else city = "[黑屏代码有误!]";
  3617. return city;
  3618. }
  3619. /// <summary>
  3620. /// op行程单 团组 城市路径
  3621. /// </summary>
  3622. /// <param name="diids">团组Id</param>
  3623. /// <param name="separator">分隔符</param>
  3624. /// <returns></returns>
  3625. public static Dictionary<int, string> GetGroupCityLineItem(List<int> diids, string separator)
  3626. {
  3627. Dictionary<int, string> dicCitys = new Dictionary<int, string>();
  3628. var cityCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  3629. var blackCodes = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && diids.Contains(x.DiId)).ToList();
  3630. foreach (var diid in diids)
  3631. {
  3632. string city = string.Empty;
  3633. var blackCode = blackCodes.Where(it => it.DiId == diid).ToList();
  3634. if (blackCode.Count > 0)
  3635. {
  3636. var black = blackCode.First();
  3637. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  3638. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  3639. if (blackSp.Length > 0)
  3640. {
  3641. try
  3642. {
  3643. var cityArrCode = new List<string>(20);
  3644. foreach (var item in blackSp)
  3645. {
  3646. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  3647. var IndexSelect = itemSp[2];
  3648. var cityArrCodeLength = cityArrCode.Count - 1;
  3649. var startCity = IndexSelect.Substring(0, 3);
  3650. if (cityArrCodeLength > 0)
  3651. {
  3652. var arrEndCity = cityArrCode[cityArrCodeLength];
  3653. if (arrEndCity != startCity)
  3654. {
  3655. cityArrCode.Add(startCity.ToUpper());
  3656. }
  3657. }
  3658. else
  3659. {
  3660. cityArrCode.Add(startCity.ToUpper());
  3661. }
  3662. var endCity = IndexSelect.Substring(3, 3);
  3663. cityArrCode.Add(endCity.ToUpper());
  3664. }
  3665. var cityThree = string.Empty;
  3666. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  3667. cityThree = cityThree.TrimEnd(',');
  3668. if (string.IsNullOrWhiteSpace(cityThree))
  3669. {
  3670. throw new Exception("error");
  3671. }
  3672. var cityArr = cityCodes.Where(it => cityThree.Contains(it.Three.ToUpper())).ToList();
  3673. foreach (var item in cityArrCode)
  3674. {
  3675. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  3676. if (find != null)
  3677. {
  3678. city += find.City + separator;
  3679. }
  3680. else
  3681. {
  3682. city += item + "[三字码未收录]" + separator;
  3683. }
  3684. }
  3685. city = city.TrimEnd(char.Parse(separator));
  3686. }
  3687. catch (Exception e)
  3688. {
  3689. city = "[黑屏代码格式不正确!]";
  3690. }
  3691. }
  3692. }
  3693. else city = "[未录入黑屏代码]";
  3694. dicCitys.Add(diid, city);
  3695. }
  3696. return dicCitys;
  3697. }
  3698. /// <summary>
  3699. /// op行程单相关团组信息 含途径城市
  3700. /// </summary>
  3701. /// <returns></returns>
  3702. public static async Task<List<MateOpGroupPageListView>> MateOpGroupPageListRedis()
  3703. {
  3704. List<MateOpGroupPageListView> _views = new List<MateOpGroupPageListView>();
  3705. string viewStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("MateOpGroupPageList");//string 取
  3706. if (!string.IsNullOrEmpty(viewStr))
  3707. {
  3708. _views = JsonConvert.DeserializeObject<List<MateOpGroupPageListView>>(viewStr);
  3709. }
  3710. else
  3711. {
  3712. string sql = string.Format($@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  3713. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  3714. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  3715. JietuanOperator,IsSure,CreateTime,VisitCountry
  3716. From (
  3717. Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
  3718. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  3719. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  3720. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  3721. su.CnName JietuanOperator,IsSure,gdi.CreateTime,gdi.VisitCountry
  3722. From Grp_DelegationInfo gdi
  3723. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  3724. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  3725. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  3726. Where gdi.IsDel = 0
  3727. ) temp");
  3728. _views = _dirRep._sqlSugar.SqlQueryable<MateOpGroupPageListView>(sql).ToList();
  3729. #region 处理所属部门
  3730. /*
  3731. * 1.sq 和 gyy 等显示 市场部
  3732. * 2.王鸽和主管及张总还有管理员号统一国交部
  3733. * 2-1. 4 管理员 ,21 张海麟
  3734. */
  3735. List<int> userIds = _views.Select(it => it.JietuanOperatorId).ToList();
  3736. List<int> userIds1 = new List<int>() { 4, 21 };
  3737. var UserDepDatas = _dirRep._sqlSugar.Queryable<Sys_Users>()
  3738. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  3739. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  3740. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  3741. .ToList();
  3742. #endregion
  3743. _views.ForEach(it =>
  3744. {
  3745. it.RouteCity = GetGroupCityLine(it.Id, @"/");
  3746. it.Department = UserDepDatas.Find(it1 => it.JietuanOperatorId == it1.UserId)?.DepName ?? "Unknown";
  3747. });
  3748. TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay;
  3749. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("MateOpGroupPageList", JsonConvert.SerializeObject(_views), ts);//string 存
  3750. }
  3751. return _views;
  3752. }
  3753. /// <summary>
  3754. /// 获取黑屏代码日期列表
  3755. /// </summary>
  3756. /// <param name="dt"></param>
  3757. /// <returns></returns>
  3758. public static List<string> GetTimeListByDataTable(DataTable dt)
  3759. {
  3760. DateTime datestart = Convert.ToDateTime(dt.Rows[0]["Day"].ToString());
  3761. DateTime dateend = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["ArrivedDate"].ToString());
  3762. List<string> timeList = new List<string>();
  3763. while (datestart <= dateend)
  3764. {
  3765. timeList.Add(datestart.ToString("yyyy-MM-dd"));
  3766. datestart = datestart.AddDays(1);
  3767. }
  3768. return timeList;
  3769. }
  3770. const decimal conversion = 1.61M;
  3771. /// <summary>
  3772. /// 简要行程
  3773. /// </summary>
  3774. /// <param name="diid"></param>
  3775. /// <returns></returns>
  3776. public static Result GetBriefStroke(int diid)
  3777. {
  3778. DataTable resultTable = GetTableByBlackCode(diid);
  3779. if (resultTable == null)
  3780. {
  3781. return new Result { Code = -1, Msg = "黑屏代码有误或黑屏代码未录入" };
  3782. }
  3783. if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
  3784. {
  3785. string msg = string.Empty;
  3786. if (resultTable.Rows.Count > 0)
  3787. {
  3788. msg = resultTable.Rows[0]["Error"].ToString();
  3789. }
  3790. return new Result { Code = -1, Msg = $"黑屏代码有误;{msg}" };
  3791. }
  3792. var timeArr = GetTimeListByDataTable(resultTable);
  3793. var threeCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList(); //三字码
  3794. var airCompanys = _dirRep._sqlSugar.Queryable<Res_AirCompany>().Where(it => it.IsDel == 0).ToList(); //航司公司
  3795. var obDatas = _dirRep._sqlSugar.Queryable<Res_OfficialActivities>().Where(it => it.IsDel == 0 && it.DiId == diid).ToList(); //公务信息
  3796. var NewListTravel = new List<Grp_TravelList>();
  3797. var index = 0;
  3798. var stopCity = string.Empty;
  3799. foreach (var item in timeArr)
  3800. {
  3801. string trip = string.Empty;
  3802. string weekDay = string.Empty;
  3803. DateTime time = DateTime.Now;
  3804. if (DateTime.TryParse(item, out time))
  3805. {
  3806. weekDay = weekdays[(int)time.DayOfWeek];
  3807. }
  3808. else
  3809. {
  3810. weekDay = "日期格式不正确!";
  3811. }
  3812. var empty = "【未收入该三字码!请机票同事录入】";
  3813. var tabSelect = resultTable.Select(string.Format("Day = '{0}'", item));
  3814. var isMoreTraffic = false;
  3815. if (tabSelect.Length > 0)
  3816. {
  3817. isMoreTraffic = true;
  3818. var takeOffTime = DateTime.Parse(item);
  3819. var fallToTime = DateTime.Parse(item);
  3820. Res_ThreeCode start_Object = null;
  3821. Res_ThreeCode end_Object = null;
  3822. //bool isTrade = false;
  3823. //air 处理
  3824. foreach (var tabRow in tabSelect)
  3825. {
  3826. takeOffTime = DateTime.Parse(item);
  3827. fallToTime = DateTime.Parse(item);
  3828. var takeOff = tabRow["StartTime"].ToString();
  3829. var fallTo = tabRow["EndTime"].ToString();
  3830. takeOffTime = takeOffTime.AddHours(int.Parse(takeOff.Substring(0, 2)));
  3831. takeOffTime = takeOffTime.AddMinutes(int.Parse(takeOff.Substring(2, 2)));
  3832. fallToTime = fallToTime.AddHours(int.Parse(fallTo.Substring(0, 2)));
  3833. fallToTime = fallToTime.AddMinutes(int.Parse(fallTo.Substring(2, 2)));
  3834. var threeCode = tabRow["Three"].ToString();
  3835. var start = threeCode.Substring(0, 3);
  3836. var end = threeCode.Substring(3, 3);
  3837. stopCity = end;
  3838. start_Object = threeCodes.Find(x => x.Three.ToUpper() == start.ToUpper());
  3839. end_Object = threeCodes.Find(x => x.Three.ToUpper() == end.ToUpper());
  3840. if (start_Object == null)
  3841. {
  3842. start_Object = new Res_ThreeCode()
  3843. {
  3844. AirPort = empty,
  3845. AirPort_En = empty,
  3846. City = empty,
  3847. Country = empty,
  3848. Four = empty,
  3849. Three = empty,
  3850. };
  3851. }
  3852. if (end_Object == null)
  3853. {
  3854. end_Object = new Res_ThreeCode()
  3855. {
  3856. AirPort = empty,
  3857. AirPort_En = empty,
  3858. City = empty,
  3859. Country = empty,
  3860. Four = empty,
  3861. Three = empty,
  3862. };
  3863. }
  3864. //航班号
  3865. string flightcode = tabRow["Fliagtcode"].ToString();
  3866. trip += $"{takeOffTime.ToString("HH:mm")}—{fallToTime.ToString("HH:mm")} {start_Object.City}—{end_Object.City} 航班号:{flightcode}\r\n";
  3867. }
  3868. //var airArrive = fallToTime; //航班落地时间
  3869. time = fallToTime.AddHours(1.5); //出机场一个半小时
  3870. string Time = string.Empty;
  3871. string Distance = string.Empty;
  3872. int GetGoogleResult = 0;
  3873. int GetDistResult = 0;
  3874. JObject Result = null;
  3875. try
  3876. {
  3877. Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace(" ", "").Trim();
  3878. Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString().Replace(" ", "").Trim();
  3879. if (Time.Contains("hours"))
  3880. {
  3881. Time = Time.Replace("hours", "小时");
  3882. }
  3883. if (Time.Contains("hour"))
  3884. {
  3885. Time = Time.Replace("hour", "小时");
  3886. }
  3887. Time = Time.Replace("mins", "分钟");
  3888. if (Distance.Contains("mi"))
  3889. {
  3890. var distSp = Regex.Split(Distance, "mi");
  3891. if (distSp.Length > 0)
  3892. {
  3893. Distance = (decimal.Parse(distSp[0]) * conversion).ToString("#0.00") + " 公里";
  3894. }
  3895. }
  3896. if (Distance.Contains("km"))
  3897. {
  3898. Distance = Distance.Replace("km", "公里");
  3899. }
  3900. if (Time.Contains("小时"))
  3901. {
  3902. var xs = Regex.Split(Time, "小时");
  3903. var xsValue = int.Parse(xs[0]);
  3904. var fz = Regex.Split(xs[1], "分钟");
  3905. var fzValue = int.Parse(fz[0]);
  3906. GetGoogleResult = xsValue * 60;
  3907. GetGoogleResult += fzValue;
  3908. }
  3909. else if (Time.Contains("分钟"))
  3910. {
  3911. GetGoogleResult = int.Parse(Regex.Split(Time, "分钟")[0]);
  3912. }
  3913. if (Distance.Contains("公里"))
  3914. {
  3915. GetDistResult = (int)decimal.Parse(Regex.Split(Distance, "公里")[0]);
  3916. }
  3917. if (GetGoogleResult > 0 && GetGoogleResult % 5 != 0)
  3918. {
  3919. while (GetGoogleResult % 5 != 0)
  3920. {
  3921. GetGoogleResult++;
  3922. }
  3923. }
  3924. if (GetDistResult % 5 != 0 && GetDistResult > 0)
  3925. {
  3926. while (GetDistResult % 5 != 0)
  3927. {
  3928. GetDistResult++;
  3929. }
  3930. }
  3931. int H = (GetGoogleResult / 60);
  3932. int m = (GetGoogleResult % 60);
  3933. string TimeStr = string.Empty;
  3934. if (H != 0)
  3935. {
  3936. if (H < 10)
  3937. {
  3938. TimeStr += "0" + H + "小时";
  3939. }
  3940. else
  3941. {
  3942. TimeStr += H + "小时";
  3943. }
  3944. }
  3945. if (m < 10)
  3946. {
  3947. TimeStr += "0" + m + "分钟";
  3948. }
  3949. else
  3950. {
  3951. TimeStr += m + "分钟";
  3952. }
  3953. Time = TimeStr;
  3954. Distance = GetDistResult.ToString() + "公里";
  3955. }
  3956. catch (Exception ex)
  3957. {
  3958. Time = "未知!";
  3959. Distance = "未知!";
  3960. }
  3961. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区 路程{Distance},耗时{Time})";
  3962. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区)";
  3963. time = time.AddMinutes(GetGoogleResult); //到达市区时间
  3964. string tripDate = Convert.ToDateTime(item).ToString("M月d日");
  3965. if (index == timeArr.Count - 1)
  3966. {
  3967. NewListTravel.Add(new Grp_TravelList
  3968. {
  3969. CreateTime = DateTime.Now,
  3970. CreateUserId = 0,
  3971. Diid = diid,
  3972. Date = tripDate,
  3973. Trip = trip,
  3974. WeekDay = weekDay,
  3975. Days = index + 1,
  3976. Traffic_First = "飞机",
  3977. Traffic_Second = "汽车",
  3978. Diffgroup = 1,
  3979. Issel = 1,
  3980. IsDel = 0,
  3981. });
  3982. continue;
  3983. }
  3984. if (time.Day != fallToTime.Day) //超出一天
  3985. {
  3986. NewListTravel.Add(new Grp_TravelList
  3987. {
  3988. CreateTime = DateTime.Now,
  3989. CreateUserId = 0,
  3990. Diid = diid,
  3991. Date = tripDate,
  3992. Trip = trip,
  3993. WeekDay = weekDay,
  3994. Days = index + 1,
  3995. Traffic_First = "飞机",
  3996. Traffic_Second = "汽车",
  3997. Diffgroup = 1,
  3998. Issel = 1,
  3999. IsDel = 0,
  4000. });
  4001. continue;
  4002. }
  4003. var obInfo = obDatas.Find(it => Convert.ToDateTime(it.Date).ToString("M月d日").Equals(tripDate));
  4004. string obtime = "";
  4005. string obcontent = "";
  4006. if (obInfo != null)
  4007. {
  4008. obtime = obInfo.Time;
  4009. obcontent = $"拜访{obInfo.Client ?? "公务出访单位未录入"}{obInfo.Job ?? "公务出访联系人职务未录入"}{obInfo.Contact ?? "公务出访联系人职务未录入"}";
  4010. }
  4011. bool obTime_bool = DateTime.TryParse(obtime, out DateTime obTimeDt);
  4012. if (time.Hour < 9) // && (airArrive < new DateTime(airArrive.Year,airArrive.Month,airArrive.Day,6, 30, 0))
  4013. {
  4014. if (obTime_bool)
  4015. {
  4016. if (obTimeDt.Hour < 9)
  4017. {
  4018. trip += $"{obTimeDt.ToString("HH:mm")}—10:30 {obcontent};\r\n";
  4019. }
  4020. }
  4021. else
  4022. {
  4023. trip += "09:00—10:30 公务活动;\r\n";
  4024. }
  4025. }
  4026. else if (time.Hour < 10)
  4027. {
  4028. if (obTime_bool)
  4029. {
  4030. if (obTimeDt.Hour < 10)
  4031. {
  4032. trip += $"{obTimeDt.ToString("HH:mm")}—12:00 {obcontent};\r\n";
  4033. }
  4034. }
  4035. else
  4036. {
  4037. trip += "10:30—12:00 公务活动;\r\n";
  4038. }
  4039. }
  4040. if (time.Hour < 13)
  4041. {
  4042. //trip += $"\r\n{time.ToString("HH:mm")} 午餐于当地餐厅;";
  4043. }
  4044. if (time < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  4045. {
  4046. if (obTime_bool)
  4047. {
  4048. if (obTimeDt < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  4049. {
  4050. trip += $"{obTimeDt.ToString("HH:mm")}—16:00 {obcontent};\r\n";
  4051. }
  4052. }
  4053. else
  4054. {
  4055. trip += "14:00—16:00 公务活动;\r\n";
  4056. }
  4057. }
  4058. else if (time.Hour < 16)
  4059. {
  4060. if (obTime_bool)
  4061. {
  4062. if (obTimeDt.Hour < 16)
  4063. {
  4064. trip += $"{obTimeDt.ToString("HH:mm")}—17:30 {obcontent};\r\n";
  4065. }
  4066. }
  4067. else
  4068. {
  4069. trip += "16:00—17:30 公务活动;\r\n";
  4070. }
  4071. }
  4072. //if (time.Hour < 18)
  4073. //{
  4074. // trip += $"\r\n18:00 晚餐于当地餐厅;";
  4075. //}
  4076. //time = time.AddHours(1);
  4077. //trip += $"\r\n{time.ToString("HH:mm")} 搭乘专车前往酒店,抵达后办理入住;";
  4078. }
  4079. else
  4080. {
  4081. var end_Object = threeCodes.Find(x => x.Three.ToUpper() == stopCity.ToUpper());
  4082. if (end_Object == null)
  4083. {
  4084. end_Object = new Res_ThreeCode()
  4085. {
  4086. AirPort = empty,
  4087. AirPort_En = empty,
  4088. City = empty,
  4089. Country = empty,
  4090. Four = empty,
  4091. Three = empty,
  4092. };
  4093. }
  4094. //trip += $"{end_Object.City}\r\n";
  4095. // trip += @"08:00 早餐于酒店;
  4096. //09:00—10:30 公务活动;
  4097. //12:00 午餐于当地餐厅;
  4098. //14:00—16:00 公务活动;
  4099. //18:00 晚餐于当地餐厅;
  4100. //19:00 入住酒店休息;";
  4101. trip += "09:00—10:30 公务活动;\r\n14:00—16:00 公务活动;\r\n";
  4102. }
  4103. string[] traffic = new string[] { "飞机", "汽车" };
  4104. if (!isMoreTraffic)
  4105. {
  4106. traffic = new string[] { "汽车", "" };
  4107. }
  4108. NewListTravel.Add(new Grp_TravelList
  4109. {
  4110. CreateTime = DateTime.Now,
  4111. CreateUserId = 0,
  4112. Diid = diid,
  4113. Date = Convert.ToDateTime(item).ToString("M月d日"),
  4114. Trip = trip,
  4115. WeekDay = weekDay,
  4116. Days = index + 1,
  4117. Traffic_First = traffic[0],
  4118. Traffic_Second = traffic[1],
  4119. Diffgroup = 1,
  4120. Issel = 1,
  4121. IsDel = 0,
  4122. });
  4123. index++;
  4124. }
  4125. return new Result() { Code = 0, Msg = "获取成功!", Data = NewListTravel };
  4126. }
  4127. /// <summary>
  4128. /// 根据日期获取星期
  4129. /// </summary>
  4130. /// <param name="dtStr"></param>
  4131. /// <returns></returns>
  4132. public static string GetWeek(this string dtStr)
  4133. {
  4134. string week = "";
  4135. bool isDt = DateTime.TryParse(dtStr, out DateTime dt);
  4136. if (isDt)
  4137. {
  4138. week = weekdays[(int)dt.DayOfWeek];
  4139. }
  4140. return week;
  4141. }
  4142. #endregion
  4143. #region 计算国家城市当时时间
  4144. /// <summary>
  4145. /// 中文城市名称映射
  4146. /// </summary>
  4147. private static readonly Dictionary<string, string> _timeZoneCityMappings = new Dictionary<string, string>
  4148. {
  4149. {"Africa/Abidjan","非洲/阿比让"} ,
  4150. {"Africa/Accra","非洲/阿克拉"} ,
  4151. {"Africa/Addis_Ababa","非洲/亚的斯亚贝巴"} ,
  4152. {"Africa/Algiers","非洲/阿尔及尔"} ,
  4153. {"Africa/Asmara","非洲/阿斯马拉"} ,
  4154. {"Africa/Asmera","非洲/阿斯梅拉"} ,
  4155. {"Africa/Bamako","非洲/巴马科"} ,
  4156. {"Africa/Bangui","非洲/班吉"} ,
  4157. {"Africa/Banjul","非洲/班珠尔"} ,
  4158. {"Africa/Bissau","非洲/比绍"} ,
  4159. {"Africa/Blantyre","非洲/布兰太尔"} ,
  4160. {"Africa/Brazzaville","非洲/布拉柴维尔"} ,
  4161. {"Africa/Bujumbura","非洲/布琼布拉"} ,
  4162. {"Africa/Cairo","非洲/开罗"} ,
  4163. {"Africa/Casablanca","非洲/卡萨布兰卡"} ,
  4164. {"Africa/Ceuta","非洲/休达"} ,
  4165. {"Africa/Conakry","非洲/科纳克里"} ,
  4166. {"Africa/Dakar","非洲/达喀尔"} ,
  4167. {"Africa/Dar_es_Salaam","非洲/达累斯萨拉姆"} ,
  4168. {"Africa/Djibouti","非洲/吉布提"} ,
  4169. {"Africa/Douala","非洲/杜阿拉"} ,
  4170. {"Africa/El_Aaiun","非洲/阿尤恩"} ,
  4171. {"Africa/Freetown","非洲/弗里敦"} ,
  4172. {"Africa/Gaborone","非洲/哈博罗内"} ,
  4173. {"Africa/Harare","非洲/哈拉雷"} ,
  4174. {"Africa/Johannesburg","非洲/约翰内斯堡"} ,
  4175. {"Africa/Juba","非洲/朱巴"} ,
  4176. {"Africa/Kampala","非洲/坎帕拉"} ,
  4177. {"Africa/Khartoum","非洲/喀土穆"} ,
  4178. {"Africa/Kigali","非洲/基加利"} ,
  4179. {"Africa/Kinshasa","非洲/金沙萨"} ,
  4180. {"Africa/Lagos","非洲/拉各斯"} ,
  4181. {"Africa/Libreville","非洲/利伯维尔"} ,
  4182. {"Africa/Lome","非洲/洛美"} ,
  4183. {"Africa/Luanda","非洲/罗安达"} ,
  4184. {"Africa/Lubumbashi","非洲/卢本巴希"} ,
  4185. {"Africa/Lusaka","非洲/卢萨卡"} ,
  4186. {"Africa/Malabo","非洲/马拉博"} ,
  4187. {"Africa/Maputo","非洲/马普托"} ,
  4188. {"Africa/Maseru","非洲/马塞卢"} ,
  4189. {"Africa/Mbabane","非洲/姆巴巴内"} ,
  4190. {"Africa/Mogadishu","非洲/摩加迪沙"} ,
  4191. {"Africa/Monrovia","非洲/蒙罗维亚"} ,
  4192. {"Africa/Nairobi","非洲/内罗毕"} ,
  4193. {"Africa/Ndjamena","非洲/恩贾梅纳"} ,
  4194. {"Africa/Niamey","非洲/尼亚美"} ,
  4195. {"Africa/Nouakchott","非洲/努瓦克肖特"} ,
  4196. {"Africa/Ouagadougou","非洲/瓦加杜古"} ,
  4197. {"Africa/Porto-Novo","非洲/波多诺伏"} ,
  4198. {"Africa/Sao_Tome","非洲/圣多美"} ,
  4199. {"Africa/Timbuktu","非洲/廷巴克图"} ,
  4200. {"Africa/Tripoli","非洲/的黎波里"} ,
  4201. {"Africa/Tunis","非洲/突尼斯"} ,
  4202. {"Africa/Windhoek","非洲/温得和克"} ,
  4203. {"America/Adak","美洲/埃达克"} ,
  4204. {"America/Anchorage","美洲/安克雷奇"} ,
  4205. {"America/Anguilla","美洲/安圭拉"} ,
  4206. {"America/Antigua","美洲/安提瓜岛"} ,
  4207. {"America/Araguaina","美洲/阿拉瓜纳"} ,
  4208. {"America/Argentina/Buenos_Aires","美洲/阿根廷/布宜诺斯艾利斯"} ,
  4209. {"America/Argentina/Catamarca","美洲/阿根廷/卡塔马卡"} ,
  4210. {"America/Argentina/ComodRivadavia","美洲/阿根廷/科莫德里瓦达维亚"} ,
  4211. {"America/Argentina/Cordoba","美洲/阿根廷/科尔多瓦"} ,
  4212. {"America/Argentina/Jujuy","美洲/阿根廷/胡胡伊省"} ,
  4213. {"America/Argentina/La_Rioja","美洲/阿根廷/拉里奥哈"} ,
  4214. {"America/Argentina/Mendoza","美洲/阿根廷/门多萨"} ,
  4215. {"America/Argentina/Rio_Gallegos","美洲/阿根廷/里奥加耶戈斯"} ,
  4216. {"America/Argentina/Salta","美洲/阿根廷/萨尔塔"} ,
  4217. {"America/Argentina/San_Juan","美洲/阿根廷/San_Juan"} ,
  4218. {"America/Argentina/San_Luis","美洲/阿根廷/圣路易斯"} ,
  4219. {"America/Argentina/Tucuman","美洲/阿根廷/图库曼"} ,
  4220. {"America/Argentina/Ushuaia","美洲/阿根廷/乌斯怀亚"} ,
  4221. {"America/Aruba","美洲/阿鲁巴岛"} ,
  4222. {"America/Asuncion","美洲/亚松森"} ,
  4223. {"America/Atikokan","美洲/阿蒂科坎"} ,
  4224. {"America/Atka","美洲/阿特卡"} ,
  4225. {"America/Bahia","美洲/巴伊亚"} ,
  4226. {"America/Bahia_Banderas","美洲/巴伊亚_班德拉斯"} ,
  4227. {"America/Barbados","美洲/巴巴多斯"} ,
  4228. {"America/Belem","美洲/贝伦"} ,
  4229. {"America/Belize","美洲/伯利兹"} ,
  4230. {"America/Blanc-Sablon","America/Blanc-Sablon"} ,
  4231. {"America/Boa_Vista","美洲/博阿维斯塔"} ,
  4232. {"America/Bogota","美洲/波哥大"} ,
  4233. {"America/Boise","美洲/博伊西"} ,
  4234. {"America/Buenos_Aires","美洲/布宜诺斯艾利斯"} ,
  4235. {"America/Cambridge_Bay","美洲/剑桥湾"} ,
  4236. {"America/Campo_Grande","美洲/大坎普"} ,
  4237. {"America/Cancun","美洲/坎昆"} ,
  4238. {"America/Caracas","美洲/加拉加斯"} ,
  4239. {"America/Catamarca","美洲/卡塔马卡"} ,
  4240. {"America/Cayenne","美洲/卡宴"} ,
  4241. {"America/Cayman","美洲/开曼"} ,
  4242. {"America/Chicago","美洲/芝加哥"} ,
  4243. {"America/Chihuahua","美洲/奇瓦瓦州"} ,
  4244. {"America/Ciudad_Juarez","美洲/华雷斯城"} ,
  4245. {"America/Coral_Harbour","美洲/珊瑚港"} ,
  4246. {"America/Cordoba","美洲/科尔多瓦"} ,
  4247. {"America/Costa_Rica","美洲/哥斯达黎加"} ,
  4248. {"America/Creston","美洲/克雷斯顿"} ,
  4249. {"America/Cuiaba","美洲/库艾巴"} ,
  4250. {"America/Curacao","美洲/库拉索岛"} ,
  4251. {"America/Danmarkshavn","美洲/丹麦港"} ,
  4252. {"America/Dawson","美洲/道森"} ,
  4253. {"America/Dawson_Creek","美洲/道森克里克"} ,
  4254. {"America/Denver","美洲/丹佛"} ,
  4255. {"America/Detroit","美洲/底特律"} ,
  4256. {"America/Dominica","美洲/多米尼克"} ,
  4257. {"America/Edmonton","美洲/埃德蒙顿"} ,
  4258. {"America/Eirunepe","美洲/埃鲁内佩"} ,
  4259. {"America/El_Salvador","美洲/萨尔瓦多"} ,
  4260. {"America/Ensenada","美洲/恩塞纳达"} ,
  4261. {"America/Fort_Nelson","美洲/纳尔逊堡"} ,
  4262. {"America/Fort_Wayne","美洲/韦恩堡"} ,
  4263. {"America/Fortaleza","美洲/福塔莱萨"} ,
  4264. {"America/Glace_Bay","America/Glace_Bay"} ,
  4265. {"America/Godthab","美洲/戈德哈布"} ,
  4266. {"America/Goose_Bay","America/Goose_Bay"} ,
  4267. {"America/Grand_Turk","美洲/大特克岛"} ,
  4268. {"America/Grenada","美洲/格林纳达"} ,
  4269. {"America/Guadeloupe","美洲/瓜德罗普岛"} ,
  4270. {"America/Guatemala","美洲/危地马拉"} ,
  4271. {"America/Guayaquil","美洲/瓜亚基尔"} ,
  4272. {"America/Guyana","美洲/圭亚那"} ,
  4273. {"America/Halifax","美洲/哈利法克斯"} ,
  4274. {"America/Havana","美洲/哈瓦那"} ,
  4275. {"America/Hermosillo","美洲/埃莫西约"} ,
  4276. {"America/Indiana/Indianapolis","美洲/印第安纳州/印第安纳波利斯"} ,
  4277. {"America/Indiana/Knox","美洲/印第安纳州/诺克斯"} ,
  4278. {"America/Indiana/Marengo","美洲/印第安纳州/马伦戈"} ,
  4279. {"America/Indiana/Petersburg","美洲/印第安纳州/彼得斯堡"} ,
  4280. {"America/Indiana/Tell_City","美洲/印第安纳州/Tell_City"} ,
  4281. {"America/Indiana/Vevay","美洲/印第安纳州/沃韦"} ,
  4282. {"America/Indiana/Vincennes","美洲/印第安纳州/文森斯"} ,
  4283. {"America/Indiana/Winamac","美洲/印第安纳州/威纳马克"} ,
  4284. {"America/Indianapolis","美洲/印第安纳波利斯"} ,
  4285. {"America/Inuvik","美洲/伊努维克人"} ,
  4286. {"America/Iqaluit","美洲/伊魁特"} ,
  4287. {"America/Jamaica","美洲/牙买加"} ,
  4288. {"America/Jujuy","美洲/胡胡伊省"} ,
  4289. {"America/Juneau","美洲/朱诺"} ,
  4290. {"America/Kentucky/Louisville","美洲/肯塔基州/路易斯维尔"} ,
  4291. {"America/Kentucky/Monticello","美洲/肯塔基州/蒙蒂塞洛"} ,
  4292. {"America/Knox_IN","美洲/Knox_IN"} ,
  4293. {"America/Kralendijk","美洲/克拉伦代克"} ,
  4294. {"America/La_Paz","美洲/拉巴斯"} ,
  4295. {"America/Lima","美洲/利马"} ,
  4296. {"America/Los_Angeles","美洲/洛杉矶"} ,
  4297. {"America/Louisville","美洲/路易斯维尔"} ,
  4298. {"America/Lower_Princes","美洲/下王子郡"} ,
  4299. {"America/Maceio","美洲/马塞约"} ,
  4300. {"America/Managua","美洲/马那瓜"} ,
  4301. {"America/Manaus","美洲/马瑙斯"} ,
  4302. {"America/Marigot","美洲/马里戈特"} ,
  4303. {"America/Martinique","美洲/马提尼克岛"} ,
  4304. {"America/Matamoros","美洲/马塔莫罗斯"} ,
  4305. {"America/Mazatlan","美洲/马萨特兰"} ,
  4306. {"America/Mendoza","美洲/门多萨"} ,
  4307. {"America/Menominee","美国/梅诺米尼"} ,
  4308. {"America/Merida","美洲/梅里达"} ,
  4309. {"America/Metlakatla","美洲/梅特拉卡特拉"} ,
  4310. {"America/Mexico_City","美洲/墨西哥_城市"} ,
  4311. {"America/Miquelon","美洲/密克隆群岛"} ,
  4312. {"America/Moncton","美洲/蒙克顿"} ,
  4313. {"America/Monterrey","美洲/蒙特雷"} ,
  4314. {"America/Montevideo","美洲/蒙得维的亚"} ,
  4315. {"America/Montreal","美洲/蒙特利尔"} ,
  4316. {"America/Montserrat","美洲/蒙特塞拉特"} ,
  4317. {"America/Nassau","美洲/拿骚"} ,
  4318. {"America/New_York","美洲/纽约"} ,
  4319. {"America/Nipigon","美洲/尼皮贡"} ,
  4320. {"America/Nome","美国/名称"} ,
  4321. {"America/Noronha","美国/某地"} ,
  4322. {"America/North_Dakota/Beulah","美洲/北达科他州/比尤拉"} ,
  4323. {"America/North_Dakota/Center","美洲/北达科他州/中部"} ,
  4324. {"America/North_Dakota/New_Salem","美洲/北达科他州/新塞勒姆"} ,
  4325. {"America/Nuuk","美洲/努克"} ,
  4326. {"America/Ojinaga","美洲/奥吉纳加"} ,
  4327. {"America/Panama","美洲/巴拿马"} ,
  4328. {"America/Pangnirtung","美洲/庞纳通"} ,
  4329. {"America/Paramaribo","美洲/帕拉马里博"} ,
  4330. {"America/Phoenix","美洲/菲尼克斯"} ,
  4331. {"America/Port-au-Prince","美洲/太子港"} ,
  4332. {"America/Port_of_Spain","美洲/西班牙港"} ,
  4333. {"America/Porto_Acre","美洲/阿卡港"} ,
  4334. {"America/Porto_Velho","美洲/旧波尔图"} ,
  4335. {"America/Puerto_Rico","美洲/波多黎各"} ,
  4336. {"America/Punta_Arenas","美洲/蓬塔阿雷纳斯"} ,
  4337. {"America/Rainy_River","美洲/雷尼河"} ,
  4338. {"America/Rankin_Inlet","兰金因莱特"} ,
  4339. {"America/Recife","美洲/累西腓"} ,
  4340. {"America/Regina","美洲/里贾纳"} ,
  4341. {"America/Resolute","美国/坚决"} ,
  4342. {"America/Rio_Branco","美洲/里奥布兰科"} ,
  4343. {"America/Rosario","美洲/罗萨里奥"} ,
  4344. {"America/Santa_Isabel","美洲/圣伊莎贝尔"} ,
  4345. {"America/Santarem","美洲/圣塔伦"} ,
  4346. {"America/Santiago","美洲/圣地亚哥"} ,
  4347. {"America/Santo_Domingo","美洲/圣多明各"} ,
  4348. {"America/Sao_Paulo","美洲/圣保罗"} ,
  4349. {"America/Scoresbysund","美洲/斯科斯比松"} ,
  4350. {"America/Shiprock","美洲/希普洛克"} ,
  4351. {"America/Sitka","美洲/锡特卡"} ,
  4352. {"America/St_Barthelemy","美洲/圣巴泰勒米"} ,
  4353. {"America/St_Johns","美洲/圣约翰斯"} ,
  4354. {"America/St_Kitts","美洲/圣基茨"} ,
  4355. {"America/St_Lucia","美洲/圣卢西亚"} ,
  4356. {"America/St_Thomas","美洲/圣托马斯"} ,
  4357. {"America/St_Vincent","美洲/圣文森特"} ,
  4358. {"America/Swift_Current","America/Swift_Current"} ,
  4359. {"America/Tegucigalpa","美洲/特古西加尔巴"} ,
  4360. {"America/Thule","美洲/图勒"} ,
  4361. {"America/Thunder_Bay","美洲/雷湾"} ,
  4362. {"America/Tijuana","美洲/蒂华纳"} ,
  4363. {"America/Toronto","美洲/多伦多"} ,
  4364. {"America/Tortola","美洲/托尔托拉岛"} ,
  4365. {"America/Vancouver","美洲/温哥华"} ,
  4366. {"America/Virgin","美国/维珍"} ,
  4367. {"America/Whitehorse","美洲/怀特霍斯"} ,
  4368. {"America/Winnipeg","美洲/温尼伯"} ,
  4369. {"America/Yakutat","美洲/雅库塔特"} ,
  4370. {"America/Yellowknife","美洲/黄刀镇"} ,
  4371. {"Antarctica/Casey","南极洲/凯西"} ,
  4372. {"Antarctica/Davis","南极洲/戴维斯"} ,
  4373. {"Antarctica/DumontDUrville","南极洲/杜蒙杜维尔"} ,
  4374. {"Antarctica/Macquarie","南极洲/麦格理"} ,
  4375. {"Antarctica/Mawson","南极洲/莫森"} ,
  4376. {"Antarctica/McMurdo","南极洲/麦克默多"} ,
  4377. {"Antarctica/Palmer","南极洲/帕尔默"} ,
  4378. {"Antarctica/Rothera","南极洲/罗塞拉岛"} ,
  4379. {"Antarctica/South_Pole","南极洲/南极点"} ,
  4380. {"Antarctica/Syowa","南极洲/昭和"} ,
  4381. {"Antarctica/Troll","南极洲/巨魔"} ,
  4382. {"Antarctica/Vostok","南极洲/东方"} ,
  4383. {"Arctic/Longyearbyen","北极/朗伊尔城"} ,
  4384. {"Asia/Aden","亚洲/亚丁"} ,
  4385. {"Asia/Almaty","亚洲/阿拉木图"} ,
  4386. {"Asia/Amman","亚洲/安曼"} ,
  4387. {"Asia/Anadyr","亚洲/阿纳德尔"} ,
  4388. {"Asia/Aqtau","亚洲/阿克套"} ,
  4389. {"Asia/Aqtobe","亚洲/阿克托比"} ,
  4390. {"Asia/Ashgabat","亚洲/阿什哈巴德"} ,
  4391. {"Asia/Ashkhabad","亚洲/阿什哈巴德"} ,
  4392. {"Asia/Atyrau","亚洲/阿特劳"} ,
  4393. {"Asia/Baghdad","亚洲/巴格达"} ,
  4394. {"Asia/Bahrain","亚洲/巴林"} ,
  4395. {"Asia/Baku","亚洲/巴库"} ,
  4396. {"Asia/Bangkok","亚洲/曼谷"} ,
  4397. {"Asia/Barnaul","亚洲/巴尔瑙尔"} ,
  4398. {"Asia/Beirut","亚洲/贝鲁特"} ,
  4399. {"Asia/Bishkek","亚洲/比什凯克"} ,
  4400. {"Asia/Brunei","亚洲/文莱"} ,
  4401. {"Asia/Calcutta","亚洲/加尔各答"} ,
  4402. {"Asia/Chita","亚洲/赤塔"} ,
  4403. {"Asia/Choibalsan","亚洲/乔巴山"} ,
  4404. {"Asia/Chongqing","亚洲/重庆"} ,
  4405. {"Asia/Chungking","亚洲/重庆"} ,
  4406. {"Asia/Colombo","亚洲/科伦坡"} ,
  4407. {"Asia/Dacca","亚洲/达卡"} ,
  4408. {"Asia/Damascus","亚洲/大马士革"} ,
  4409. {"Asia/Dhaka","亚洲/达卡"} ,
  4410. {"Asia/Dili","亚洲/帝力"} ,
  4411. {"Asia/Dubai","亚洲/迪拜"} ,
  4412. {"Asia/Dushanbe","亚洲/杜尚别"} ,
  4413. {"Asia/Famagusta","亚洲/法马古斯塔"} ,
  4414. {"Asia/Gaza","亚洲/加沙"} ,
  4415. {"Asia/Harbin","亚洲/哈尔滨"} ,
  4416. {"Asia/Hebron","亚洲/希伯伦"} ,
  4417. {"Asia/Ho_Chi_Minh","亚洲/胡志明市"} ,
  4418. {"Asia/Hong_Kong","亚洲/香港"} ,
  4419. {"Asia/Hovd","亚洲/霍布德"} ,
  4420. {"Asia/Irkutsk","亚洲/伊尔库茨克"} ,
  4421. {"Asia/Istanbul","亚洲/伊斯坦布尔"} ,
  4422. {"Asia/Jakarta","亚洲/雅加达"} ,
  4423. {"Asia/Jayapura","亚洲/查亚普拉"} ,
  4424. {"Asia/Jerusalem","亚洲/耶路撒冷"} ,
  4425. {"Asia/Kabul","亚洲/喀布尔"} ,
  4426. {"Asia/Kamchatka","亚洲/堪察加半岛"} ,
  4427. {"Asia/Karachi","亚洲/卡拉奇"} ,
  4428. {"Asia/Kashgar","亚洲/喀什"} ,
  4429. {"Asia/Kathmandu","亚洲/加德满都"} ,
  4430. {"Asia/Katmandu","亚洲/加德满都"} ,
  4431. {"Asia/Khandyga","亚洲/坎迪加"} ,
  4432. {"Asia/Kolkata","亚洲/加尔各答"} ,
  4433. {"Asia/Krasnoyarsk","亚洲/克拉斯诺亚尔斯克"} ,
  4434. {"Asia/Kuala_Lumpur","亚洲/吉隆坡_吉隆坡"} ,
  4435. {"Asia/Kuching","亚洲/古晋"} ,
  4436. {"Asia/Kuwait","亚洲/科威特"} ,
  4437. {"Asia/Macao","亚洲/澳门"} ,
  4438. {"Asia/Macau","亚洲/澳门"} ,
  4439. {"Asia/Magadan","亚洲/马加丹"} ,
  4440. {"Asia/Makassar","亚洲/望加锡"} ,
  4441. {"Asia/Manila","亚洲/马尼拉"} ,
  4442. {"Asia/Muscat","亚洲/马斯喀特"} ,
  4443. {"Asia/Nicosia","亚洲/尼科西亚"} ,
  4444. {"Asia/Novokuznetsk","亚洲/新库兹涅茨克"} ,
  4445. {"Asia/Novosibirsk","亚洲/新西伯利亚"} ,
  4446. {"Asia/Omsk","亚洲/鄂木斯克"} ,
  4447. {"Asia/Oral","亚洲/口头"} ,
  4448. {"Asia/Phnom_Penh","亚洲/金边"} ,
  4449. {"Asia/Pontianak","亚洲/笨珍"} ,
  4450. {"Asia/Pyongyang","亚洲/平壤"} ,
  4451. {"Asia/Qatar","亚洲/卡塔尔"} ,
  4452. {"Asia/Qostanay","亚洲/库斯塔奈"} ,
  4453. {"Asia/Qyzylorda","亚洲/克孜勒奥尔达"} ,
  4454. {"Asia/Rangoon","亚洲/仰光"} ,
  4455. {"Asia/Riyadh","亚洲/利雅得"} ,
  4456. {"Asia/Saigon","亚洲/西贡"} ,
  4457. {"Asia/Sakhalin","亚洲/萨哈林岛"} ,
  4458. {"Asia/Samarkand","亚洲/撒马尔罕"} ,
  4459. {"Asia/Seoul","亚洲/首尔"} ,
  4460. {"Asia/Shanghai","亚洲/上海"} ,
  4461. {"Asia/Singapore","亚洲/新加坡"} ,
  4462. {"Asia/Srednekolymsk","亚洲/中科雷姆斯克"} ,
  4463. {"Asia/Taipei","亚洲/台北"} ,
  4464. {"Asia/Tashkent","亚洲/塔什干"} ,
  4465. {"Asia/Tbilisi","亚洲/第比利斯"} ,
  4466. {"Asia/Tehran","亚洲/德黑兰"} ,
  4467. {"Asia/Tel_Aviv","亚洲/特拉维夫"} ,
  4468. {"Asia/Thimbu","亚洲/廷布"} ,
  4469. {"Asia/Thimphu","亚洲/廷布"} ,
  4470. {"Asia/Tokyo","亚洲/东京"} ,
  4471. {"Asia/Tomsk","亚洲/托木斯克"} ,
  4472. {"Asia/Ujung_Pandang","亚洲/乌戎_潘当"} ,
  4473. {"Asia/Ulaanbaatar","亚洲/乌兰巴托"} ,
  4474. {"Asia/Ulan_Bator","亚洲/乌兰巴托"} ,
  4475. {"Asia/Urumqi","亚洲/乌鲁木齐"} ,
  4476. {"Asia/Ust-Nera","亚洲/乌斯季-内拉"} ,
  4477. {"Asia/Vientiane","亚洲/万象"} ,
  4478. {"Asia/Vladivostok","亚洲/符拉迪沃斯托克"} ,
  4479. {"Asia/Yakutsk","亚洲/雅库茨克"} ,
  4480. {"Asia/Yangon","亚洲/仰光"} ,
  4481. {"Asia/Yekaterinburg","亚洲/叶卡捷琳堡"} ,
  4482. {"Asia/Yerevan","亚洲/埃里温"} ,
  4483. {"Atlantic/Azores","大西洋/亚速尔群岛"} ,
  4484. {"Atlantic/Bermuda","大西洋/百慕大"} ,
  4485. {"Atlantic/Canary","大西洋/加那利"} ,
  4486. {"Atlantic/Cape_Verde","大西洋/佛得角"} ,
  4487. {"Atlantic/Faeroe","大西洋/法罗"} ,
  4488. {"Atlantic/Faroe","大西洋/法罗"} ,
  4489. {"Atlantic/Jan_Mayen","大西洋/扬马延"} ,
  4490. {"Atlantic/Madeira","大西洋/马德拉"} ,
  4491. {"Atlantic/Reykjavik","大西洋/雷克雅未克"} ,
  4492. {"Atlantic/South_Georgia","大西洋/南乔治亚州"} ,
  4493. {"Atlantic/St_Helena","大西洋/圣赫勒拿岛"} ,
  4494. {"Atlantic/Stanley","大西洋/斯坦利"} ,
  4495. {"Australia/ACT","澳大利亚/澳大利亚首都地区"} ,
  4496. {"Australia/Adelaide","澳大利亚/阿德莱德"} ,
  4497. {"Australia/Brisbane","澳大利亚/布里斯班"} ,
  4498. {"Australia/Broken_Hill","澳大利亚/布罗肯希尔"} ,
  4499. {"Australia/Canberra","澳大利亚/堪培拉"} ,
  4500. {"Australia/Currie","澳大利亚/柯里"} ,
  4501. {"Australia/Darwin","澳大利亚/达尔文"} ,
  4502. {"Australia/Eucla","澳大利亚/尤克拉拉"} ,
  4503. {"Australia/Hobart","澳大利亚/霍巴特"} ,
  4504. {"Australia/LHI","澳大利亚/LHI"} ,
  4505. {"Australia/Lindeman","澳大利亚/林德曼"} ,
  4506. {"Australia/Lord_Howe","澳大利亚/豪勋爵"} ,
  4507. {"Australia/Melbourne","澳大利亚/墨尔本"} ,
  4508. {"Australia/NSW","澳大利亚/新南威尔士州"} ,
  4509. {"Australia/North","澳大利亚/北部"} ,
  4510. {"Australia/Perth","澳大利亚/珀斯"} ,
  4511. {"Australia/Queensland","澳大利亚/昆士兰"} ,
  4512. {"Australia/South","澳大利亚/南部"} ,
  4513. {"Australia/Sydney","澳大利亚/悉尼"} ,
  4514. {"Australia/Tasmania","澳大利亚/塔斯马尼亚"} ,
  4515. {"Australia/Victoria","澳大利亚/维多利亚"} ,
  4516. {"Australia/West","澳大利亚/西部"} ,
  4517. {"Australia/Yancowinna","澳大利亚/扬科温纳"} ,
  4518. {"Brazil/Acre","巴西/阿卡"} ,
  4519. {"Brazil/DeNoronha","巴西/迪诺罗尼亚群岛"} ,
  4520. {"Brazil/East","巴西/东部"} ,
  4521. {"Brazil/West","巴西/西部"} ,
  4522. {"CET","CET"} ,
  4523. {"CST6CDT","CST6CDT"} ,
  4524. {"Canada/Atlantic","加拿大/大西洋"} ,
  4525. {"Canada/Central","加拿大/中部"} ,
  4526. {"Canada/Eastern","加拿大/东部"} ,
  4527. {"Canada/Mountain","加拿大/山区"} ,
  4528. {"Canada/Newfoundland","加拿大/纽芬兰"} ,
  4529. {"Canada/Pacific","加拿大/太平洋地区"} ,
  4530. {"Canada/Saskatchewan","加拿大/萨斯喀彻温省"} ,
  4531. {"Canada/Yukon","加拿大/育空地区"} ,
  4532. {"Chile/Continental","智利/大陆航空"} ,
  4533. {"Chile/EasterIsland","智利/复活节岛"} ,
  4534. {"Cuba","古巴"} ,
  4535. {"EET","欧洲东部时间"} ,
  4536. {"EST","东部时间"} ,
  4537. {"EST5EDT","EST5EDT"} ,
  4538. {"Egypt","埃及"} ,
  4539. {"Eire","爱尔兰"} ,
  4540. {"Etc/GMT","Etc/GMT"} ,
  4541. {"Etc/GMT+0","Etc/GMT+0"} ,
  4542. {"Etc/GMT+1","Etc/GMT+1"} ,
  4543. {"Etc/GMT+10","Etc/GMT+10"} ,
  4544. {"Etc/GMT+11","Etc/GMT+11"} ,
  4545. {"Etc/GMT+12","Etc/GMT+12"} ,
  4546. {"Etc/GMT+2","Etc/GMT+2"} ,
  4547. {"Etc/GMT+3","Etc/GMT+3"} ,
  4548. {"Etc/GMT+4","Etc/GMT+4"} ,
  4549. {"Etc/GMT+5","Etc/GMT+5"} ,
  4550. {"Etc/GMT+6","Etc/GMT+6"} ,
  4551. {"Etc/GMT+7","Etc/GMT+7"} ,
  4552. {"Etc/GMT+8","Etc/GMT+8"} ,
  4553. {"Etc/GMT+9","Etc/GMT+9"} ,
  4554. {"Etc/GMT-0","Etc/GMT-0"} ,
  4555. {"Etc/GMT-1","Etc/GMT-1"} ,
  4556. {"Etc/GMT-10","Etc/GMT-10"} ,
  4557. {"Etc/GMT-11","Etc/GMT-11"} ,
  4558. {"Etc/GMT-12","Etc/GMT-12"} ,
  4559. {"Etc/GMT-13","Etc/GMT-13"} ,
  4560. {"Etc/GMT-14","Etc/GMT-14"} ,
  4561. {"Etc/GMT-2","Etc/GMT-2"} ,
  4562. {"Etc/GMT-3","Etc/GMT-3"} ,
  4563. {"Etc/GMT-4","Etc/GMT-4"} ,
  4564. {"Etc/GMT-5","Etc/GMT-5"} ,
  4565. {"Etc/GMT-6","Etc/GMT-6"} ,
  4566. {"Etc/GMT-7","Etc/GMT-7"} ,
  4567. {"Etc/GMT-8","Etc/GMT-8"} ,
  4568. {"Etc/GMT-9","Etc/GMT-9"} ,
  4569. {"Etc/GMT0","Etc/GMT0"} ,
  4570. {"Etc/Greenwich","Etc/格林威治"} ,
  4571. {"Etc/UCT","Etc/UCT"} ,
  4572. {"Etc/UTC","Etc/UTC"} ,
  4573. {"Etc/Universal","Etc/通用"} ,
  4574. {"Etc/Zulu","Etc/祖鲁语"} ,
  4575. {"Europe/Amsterdam","欧洲/阿姆斯特丹"} ,
  4576. {"Europe/Andorra","欧洲/安道尔"} ,
  4577. {"Europe/Astrakhan","欧洲/阿斯特拉罕"} ,
  4578. {"Europe/Athens","欧洲/雅典"} ,
  4579. {"Europe/Belfast","欧洲/贝尔法斯特"} ,
  4580. {"Europe/Belgrade","欧洲/贝尔格莱德"} ,
  4581. {"Europe/Berlin","欧洲/柏林"} ,
  4582. {"Europe/Bratislava","欧洲/布拉迪斯拉发"} ,
  4583. {"Europe/Brussels","欧洲/布鲁塞尔"} ,
  4584. {"Europe/Bucharest","欧洲/布加勒斯特"} ,
  4585. {"Europe/Budapest","欧洲/布达佩斯"} ,
  4586. {"Europe/Busingen","欧洲/布辛根"} ,
  4587. {"Europe/Chisinau","欧洲/基希讷乌"} ,
  4588. {"Europe/Copenhagen","欧洲/哥本哈根"} ,
  4589. {"Europe/Dublin","欧洲/都柏林"} ,
  4590. {"Europe/Gibraltar","欧洲/直布罗陀"} ,
  4591. {"Europe/Guernsey","欧洲/根西岛"} ,
  4592. {"Europe/Helsinki","欧洲/赫尔辛基"} ,
  4593. {"Europe/Isle_of_Man","欧洲/马恩岛"} ,
  4594. {"Europe/Istanbul","欧洲/伊斯坦布尔"} ,
  4595. {"Europe/Jersey","欧洲/泽西岛"} ,
  4596. {"Europe/Kaliningrad","欧洲/加里宁格勒"} ,
  4597. {"Europe/Kiev","欧洲/基辅"} ,
  4598. {"Europe/Kirov","欧洲/基洛夫"} ,
  4599. {"Europe/Kyiv","欧洲/基辅"} ,
  4600. {"Europe/Lisbon","欧洲/里斯本"} ,
  4601. {"Europe/Ljubljana","欧洲/卢布尔雅那"} ,
  4602. {"Europe/London","欧洲/伦敦"} ,
  4603. {"Europe/Luxembourg","欧洲/卢森堡"} ,
  4604. {"Europe/Madrid","欧洲/马德里"} ,
  4605. {"Europe/Malta","欧洲/马耳他"} ,
  4606. {"Europe/Mariehamn","欧洲/玛丽港"} ,
  4607. {"Europe/Minsk","欧洲/明斯克"} ,
  4608. {"Europe/Monaco","欧洲/摩纳哥"} ,
  4609. {"Europe/Moscow","欧洲/莫斯科"} ,
  4610. {"Europe/Nicosia","欧洲/尼科西亚"} ,
  4611. {"Europe/Oslo","欧洲/奥斯陆"} ,
  4612. {"Europe/Paris","欧洲/巴黎"} ,
  4613. {"Europe/Podgorica","欧洲/波德戈里察"} ,
  4614. {"Europe/Prague","欧洲/布拉格"} ,
  4615. {"Europe/Riga","欧洲/里加"} ,
  4616. {"Europe/Rome","欧洲/罗马"} ,
  4617. {"Europe/Samara","欧洲/萨马拉"} ,
  4618. {"Europe/San_Marino","欧洲/圣马力诺"} ,
  4619. {"Europe/Sarajevo","欧洲/萨拉热窝"} ,
  4620. {"Europe/Saratov","欧洲/萨拉托夫"} ,
  4621. {"Europe/Simferopol","欧洲/辛菲罗波尔"} ,
  4622. {"Europe/Skopje","欧洲/斯科普里"} ,
  4623. {"Europe/Sofia","欧洲/索非亚"} ,
  4624. {"Europe/Stockholm","欧洲/斯德哥尔摩"} ,
  4625. {"Europe/Tallinn","欧洲/塔林"} ,
  4626. {"Europe/Tirane","欧洲/地拉那"} ,
  4627. {"Europe/Tiraspol","欧洲/蒂拉斯波尔"} ,
  4628. {"Europe/Ulyanovsk","欧洲/乌里扬诺夫斯克"} ,
  4629. {"Europe/Uzhgorod","欧洲/乌日哥罗德"} ,
  4630. {"Europe/Vaduz","欧洲/瓦杜兹"} ,
  4631. {"Europe/Vatican","欧洲/梵蒂冈"} ,
  4632. {"Europe/Vienna","欧洲/维也纳"} ,
  4633. {"Europe/Vilnius","欧洲/维尔纽斯"} ,
  4634. {"Europe/Volgograd","欧洲/伏尔加格勒"} ,
  4635. {"Europe/Warsaw","欧洲/华沙"} ,
  4636. {"Europe/Zagreb","欧洲/萨格勒布"} ,
  4637. {"Europe/Zaporozhye","欧洲/扎波罗热"} ,
  4638. {"Europe/Zurich","欧洲/苏黎世"} ,
  4639. {"GB","国标"} ,
  4640. {"GB-Eire","英国-爱尔兰"} ,
  4641. {"GMT","格林威治标准时间"} ,
  4642. {"GMT+0","格林威治标准时间+0"} ,
  4643. {"GMT-0","GMT-0"} ,
  4644. {"GMT0","格林威治标准时间0"} ,
  4645. {"Greenwich","格林威治"} ,
  4646. {"HST","高温试验"} ,
  4647. {"Hongkong","香港"} ,
  4648. {"Iceland","冰岛"} ,
  4649. {"Indian/Antananarivo","印度/塔那那利佛"} ,
  4650. {"Indian/Chagos","印第安人/查戈斯人"} ,
  4651. {"Indian/Christmas","印度/圣诞节"} ,
  4652. {"Indian/Cocos","印度/科科斯"} ,
  4653. {"Indian/Comoro","印度/科摩罗"} ,
  4654. {"Indian/Kerguelen","印度/凯尔盖朗"} ,
  4655. {"Indian/Mahe","印度/马埃岛"} ,
  4656. {"Indian/Maldives","印度/马尔代夫"} ,
  4657. {"Indian/Mauritius","印度/毛里求斯"} ,
  4658. {"Indian/Mayotte","印度/马约特岛"} ,
  4659. {"Indian/Reunion","印度/留尼汪岛"} ,
  4660. {"Iran","伊朗"} ,
  4661. {"Israel","以色列"} ,
  4662. {"Jamaica","牙买加"} ,
  4663. {"Japan","日本"} ,
  4664. {"Kwajalein","夸贾林环礁"} ,
  4665. {"Libya","利比亚"} ,
  4666. {"MET","梅特"} ,
  4667. {"MST","MST"} ,
  4668. {"MST7MDT","MST7MDT"} ,
  4669. {"Mexico/BajaNorte","墨西哥/北下巴"} ,
  4670. {"Mexico/BajaSur","墨西哥/巴哈苏尔"} ,
  4671. {"Mexico/General","墨西哥/一般"} ,
  4672. {"NZ","新西兰"} ,
  4673. {"NZ-CHAT","新西兰聊天室"} ,
  4674. {"Navajo","纳瓦霍语"} ,
  4675. {"PRC","中国"} ,
  4676. {"PST8PDT","PST8PDT"} ,
  4677. {"Pacific/Apia","太平洋/阿皮亚"} ,
  4678. {"Pacific/Auckland","太平洋/奥克兰"} ,
  4679. {"Pacific/Bougainville","太平洋/布干维尔岛"} ,
  4680. {"Pacific/Chatham","太平洋/查塔姆"} ,
  4681. {"Pacific/Chuuk","太平洋/楚克"} ,
  4682. {"Pacific/Easter","太平洋/复活节"} ,
  4683. {"Pacific/Efate","太平洋/埃法特"} ,
  4684. {"Pacific/Enderbury","太平洋/恩德伯里"} ,
  4685. {"Pacific/Fakaofo","太平洋/法考福"} ,
  4686. {"Pacific/Fiji","太平洋/斐济"} ,
  4687. {"Pacific/Funafuti","太平洋/富纳富提"} ,
  4688. {"Pacific/Galapagos","太平洋/加拉帕戈斯群岛"} ,
  4689. {"Pacific/Gambier","太平洋/甘比尔"} ,
  4690. {"Pacific/Guadalcanal","太平洋/瓜达尔卡纳尔岛"} ,
  4691. {"Pacific/Guam","太平洋/关岛"} ,
  4692. {"Pacific/Honolulu","太平洋/檀香山"} ,
  4693. {"Pacific/Johnston","太平洋/约翰斯顿"} ,
  4694. {"Pacific/Kanton","太平洋/关东"} ,
  4695. {"Pacific/Kiritimati","太平洋/基里蒂马蒂"} ,
  4696. {"Pacific/Kosrae","太平洋/科斯雷"} ,
  4697. {"Pacific/Kwajalein","太平洋/夸贾林环礁"} ,
  4698. {"Pacific/Majuro","太平洋/马朱罗"} ,
  4699. {"Pacific/Marquesas","太平洋/马克萨斯"} ,
  4700. {"Pacific/Midway","太平洋/中途岛"} ,
  4701. {"Pacific/Nauru","太平洋/瑙鲁"} ,
  4702. {"Pacific/Niue","太平洋/纽埃"} ,
  4703. {"Pacific/Norfolk","太平洋/诺福克"} ,
  4704. {"Pacific/Noumea","太平洋/努美阿"} ,
  4705. {"Pacific/Pago_Pago","太平洋/帕果"} ,
  4706. {"Pacific/Palau","太平洋/帕劳"} ,
  4707. {"Pacific/Pitcairn","太平洋/皮特凯恩"} ,
  4708. {"Pacific/Pohnpei","太平洋/波纳佩"} ,
  4709. {"Pacific/Ponape","太平洋/波纳佩"} ,
  4710. {"Pacific/Port_Moresby","太平洋/莫尔兹比港"} ,
  4711. {"Pacific/Rarotonga","太平洋/拉罗汤加"} ,
  4712. {"Pacific/Saipan","太平洋/塞班岛"} ,
  4713. {"Pacific/Samoa","太平洋/萨摩亚"} ,
  4714. {"Pacific/Tahiti","太平洋/大溪地"} ,
  4715. {"Pacific/Tarawa","太平洋/塔拉瓦"} ,
  4716. {"Pacific/Tongatapu","太平洋/汤加塔布岛"} ,
  4717. {"Pacific/Truk","太平洋/特鲁克"} ,
  4718. {"Pacific/Wake","太平洋/威克"} ,
  4719. {"Pacific/Wallis","太平洋/沃利斯"} ,
  4720. {"Pacific/Yap","太平洋/雅浦岛"} ,
  4721. {"Poland","波兰"} ,
  4722. {"Portugal","葡萄牙"} ,
  4723. {"ROC","ROC"} ,
  4724. {"ROK","韩国"} ,
  4725. {"Singapore","新加坡"} ,
  4726. {"Turkey","Turkey"} ,
  4727. {"UCT","世界标准时间"} ,
  4728. {"US/Alaska","美国/阿拉斯加"} ,
  4729. {"US/Aleutian","美国/阿留申群岛"} ,
  4730. {"US/Arizona","美国/亚利桑那州"} ,
  4731. {"US/Central","美国/中部"} ,
  4732. {"US/East-Indiana","美国/东印第安纳州"} ,
  4733. {"US/Eastern","美国/东部"} ,
  4734. {"US/Hawaii","美国/夏威夷"} ,
  4735. {"US/Indiana-Starke","美国/印第安纳州斯塔克"} ,
  4736. {"US/Michigan","美国/密歇根州"} ,
  4737. {"US/Mountain","美国/山地"} ,
  4738. {"US/Pacific","美国/太平洋地区"} ,
  4739. {"US/Samoa","美国/萨摩亚"} ,
  4740. {"UTC","世界标准时间"} ,
  4741. {"Universal","Universal"} ,
  4742. {"W-SU","W-SU"} ,
  4743. {"WET","WET"} ,
  4744. {"Zulu","Zulu"}
  4745. };
  4746. /// <summary>
  4747. /// 获取国家或城市当地时间
  4748. /// </summary>
  4749. /// <param name="country"></param>
  4750. /// <param name="city"></param>
  4751. /// <returns></returns>
  4752. public static DateTime? GetCountryOrCityCurrentDateTime(string country, string city)
  4753. {
  4754. DateTime? currDt = null;
  4755. var currTimezones = _timeZoneCityMappings.Where(x => x.Value.Contains(city)).ToList();
  4756. if (!currTimezones.Any())
  4757. {
  4758. currTimezones = _timeZoneCityMappings.Where(x => x.Value.Contains(country)).ToList();
  4759. }
  4760. ;
  4761. string timeZoneId = string.Empty;
  4762. if (currTimezones.Count > 1)
  4763. {
  4764. currTimezones = currTimezones.Where(x => x.Value.Contains(country)).ToList();
  4765. timeZoneId = currTimezones.FirstOrDefault().Key ?? string.Empty;
  4766. }
  4767. else timeZoneId = currTimezones.FirstOrDefault().Key ?? string.Empty;
  4768. if (string.IsNullOrEmpty(timeZoneId)) return currDt;
  4769. // Step 1: 获取当前 UTC 时间
  4770. Instant now = SystemClock.Instance.GetCurrentInstant();
  4771. // Step 2: 加载目标时区(以 "Asia/Shanghai" 为例)
  4772. var timeZone = DateTimeZoneProviders.Tzdb[timeZoneId];
  4773. if (timeZone == null) return currDt;
  4774. // Step 3: 将 UTC 时间转换为目标时区的本地时间
  4775. currDt = now.InZone(timeZone).ToDateTimeUnspecified();
  4776. return currDt;
  4777. }
  4778. #endregion
  4779. #region aspose
  4780. /// <summary>
  4781. /// aspose word 设置页脚
  4782. /// </summary>
  4783. /// <param name="builder"></param>
  4784. /// <param name="footerLabel">页脚内容</param>
  4785. /// <param name="font">字体名称</param>
  4786. /// <param name="fontSize"><字体大小/param>
  4787. public static void AsposeWordSetFooter(DocumentBuilder builder, string footerLabel, string font, int fontSize)
  4788. {
  4789. Aspose.Words.Section currentSection = builder.CurrentSection;
  4790. var pageSetup = currentSection.PageSetup;
  4791. pageSetup.DifferentFirstPageHeaderFooter = true;
  4792. //第一页页脚
  4793. builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
  4794. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  4795. builder.Font.Name = font;
  4796. builder.Font.Bold = true;
  4797. builder.Font.Size = fontSize;
  4798. builder.Write(footerLabel);
  4799. //非第一页页脚
  4800. builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
  4801. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  4802. builder.Font.Name = font;
  4803. builder.Font.Bold = true;
  4804. builder.Font.Size = fontSize;
  4805. builder.Write(footerLabel);
  4806. }
  4807. #endregion
  4808. #region 出入境费用
  4809. #region 汇率
  4810. /// <summary>
  4811. /// 三公费用实时汇率调差
  4812. /// </summary>
  4813. private readonly static decimal _xchgRateAdj = 0.00M;
  4814. /// <summary>
  4815. /// 三公费用实时汇率上浮比例
  4816. /// </summary>
  4817. private readonly static decimal _fxRateRise = 1.0350M;
  4818. #region 城市区间费用详情
  4819. /// <summary>
  4820. /// 城市区间费用详情 使用的币种及汇率
  4821. /// </summary>
  4822. /// <param name="groupId"></param>
  4823. /// <returns></returns>
  4824. public static async Task<List<CurrencyInfo>> EnterExitCostOVFeeUsedCurrencyAsync(int groupId = 0)
  4825. {
  4826. var infos = new List<CurrencyInfo>();
  4827. bool isUsedGroup = false;
  4828. var countryies = new List<string>();
  4829. var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.Id == groupId).FirstAsync();
  4830. if (groupInfo != null)
  4831. {
  4832. countryies = _dirRep.GroupSplitCountry(groupInfo.VisitCountry);
  4833. if (countryies.Any())
  4834. {
  4835. isUsedGroup = true;
  4836. }
  4837. }
  4838. infos = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  4839. .LeftJoin<Sys_SetData>((ov, sd) => ov.Currency == sd.Id)
  4840. .Where((ov, sd) => ov.IsDel == 0)
  4841. .WhereIF(isUsedGroup, (ov, sd) => countryies.Contains(ov.CountryName))
  4842. .Select((ov, sd) => new CurrencyInfo()
  4843. {
  4844. CurrencyCode = sd.Name.ToUpper(),
  4845. CurrencyName = sd.Remark
  4846. })
  4847. .Distinct()
  4848. .ToListAsync();
  4849. //出入境费用存储的币种及汇率
  4850. var eexCurrencyInfos = new List<CurrencyInfo>();
  4851. if (infos.Any())
  4852. {
  4853. var eecInfo = await _sqlSugar.Queryable<Grp_EnterExitCost>().Where(x => x.IsDel == 0 && x.DiId == groupId).FirstAsync();
  4854. if (eecInfo != null)
  4855. {
  4856. eexCurrencyInfos = CommonFun.GetCurrencyChinaToList(eecInfo.CurrencyRemark);
  4857. }
  4858. }
  4859. //合并已使用币种及汇率
  4860. infos.ForEach(x =>
  4861. {
  4862. x.Rate = x.Rate == 0.00M ? 1.0000M : x.Rate;
  4863. var eexCurrencyInfo = eexCurrencyInfos.Where(y => y.CurrencyCode == x.CurrencyCode).FirstOrDefault();
  4864. if (eexCurrencyInfo != null)
  4865. {
  4866. x.Rate = eexCurrencyInfo.Rate;
  4867. }
  4868. });
  4869. //未存储费用集合
  4870. var unSaveCurrInfos = infos.Where(x => !eexCurrencyInfos.Any(y => y.CurrencyCode == x.CurrencyCode)).ToList();
  4871. if (unSaveCurrInfos.Any())
  4872. {
  4873. var currencyRate = await _juHeApi.PostItemRateAsync(unSaveCurrInfos.Select(it => it.CurrencyCode!).ToArray());
  4874. if (currencyRate.Count > 0)
  4875. {
  4876. foreach (var item in infos)
  4877. {
  4878. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4879. if (rateInfo != null)
  4880. {
  4881. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4882. rate1 *= _fxRateRise;
  4883. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4884. }
  4885. }
  4886. }
  4887. }
  4888. return infos;
  4889. }
  4890. /// <summary>
  4891. /// 城市区间-草稿费用详情 使用的币种及汇率
  4892. /// </summary>
  4893. /// <param name="draftId"></param>
  4894. /// <returns></returns>
  4895. public static async Task<List<CurrencyInfo>> EnterExitCostDrafOVFeeUsedCurrencyAsync(int draftId = 0)
  4896. {
  4897. var infos = new List<CurrencyInfo>();
  4898. bool isUsedDraft = false;
  4899. var countryies = new List<string>();
  4900. var drafInfo = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.Id == draftId).FirstAsync();
  4901. if (drafInfo != null)
  4902. {
  4903. var cityIds = await _sqlSugar.Queryable<Grp_DayAndCostDraft>()
  4904. .Where(x => x.IsDel == 0 && x.ParentId == draftId)
  4905. .Select(x => x.NationalTravelFeeId)
  4906. .Distinct()
  4907. .ToListAsync();
  4908. var countries = await _sqlSugar.Queryable<Grp_NationalTravelFee>()
  4909. .Where(x => x.IsDel == 0 && cityIds.Contains(x.Id))
  4910. .Select(x => x.Country)
  4911. .Distinct()
  4912. .ToListAsync();
  4913. if (countryies.Any())
  4914. {
  4915. isUsedDraft = true;
  4916. }
  4917. }
  4918. infos = await _sqlSugar.Queryable<Res_OverseaVehicle>()
  4919. .LeftJoin<Sys_SetData>((ov, sd) => ov.Currency == sd.Id)
  4920. .Where((ov, sd) => ov.IsDel == 0)
  4921. .WhereIF(isUsedDraft, (ov, sd) => countryies.Contains(ov.CountryName))
  4922. .Select((ov, sd) => new CurrencyInfo()
  4923. {
  4924. CurrencyCode = sd.Name.ToUpper(),
  4925. CurrencyName = sd.Remark
  4926. })
  4927. .Distinct()
  4928. .ToListAsync();
  4929. //出入境费用存储的币种及汇率
  4930. var eexCurrencyInfos = new List<CurrencyInfo>();
  4931. if (infos.Any())
  4932. {
  4933. if (drafInfo != null)
  4934. {
  4935. eexCurrencyInfos = CommonFun.GetCurrencyChinaToList(drafInfo.CurrencyRemark);
  4936. }
  4937. }
  4938. //合并已使用币种及汇率
  4939. infos.ForEach(x =>
  4940. {
  4941. if (x.CurrencyCode.Equals("CNY")) x.Rate = 1.0000M;
  4942. var eexCurrencyInfo = eexCurrencyInfos.Where(y => y.CurrencyCode == x.CurrencyCode).FirstOrDefault();
  4943. if (eexCurrencyInfo != null)
  4944. {
  4945. x.Rate = eexCurrencyInfo.Rate;
  4946. }
  4947. });
  4948. //未存储费用集合
  4949. var unSaveCurrInfos = infos.Where(x => !eexCurrencyInfos.Any(y => y.CurrencyCode == x.CurrencyCode)).ToList();
  4950. if (unSaveCurrInfos.Any())
  4951. {
  4952. var currencyRate = await _juHeApi.PostItemRateAsync(unSaveCurrInfos.Select(it => it.CurrencyCode!).ToArray());
  4953. if (currencyRate.Count > 0)
  4954. {
  4955. foreach (var item in infos)
  4956. {
  4957. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4958. if (rateInfo != null)
  4959. {
  4960. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4961. rate1 *= _fxRateRise;
  4962. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4963. }
  4964. }
  4965. }
  4966. }
  4967. return infos;
  4968. }
  4969. #endregion
  4970. /// <summary>
  4971. /// 出入境费用 初始化汇率
  4972. /// </summary>
  4973. /// <returns></returns>
  4974. public static async Task<List<CurrencyInfo>> EnterExitCostInitRate()
  4975. {
  4976. //默认币种显示
  4977. var currencyInfos = new List<CurrencyInfo>()
  4978. {
  4979. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  4980. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  4981. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  4982. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  4983. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M },
  4984. };
  4985. var currencyRate = await _juHeApi.PostItemRateAsync(currencyInfos.Select(it => it.CurrencyCode!).ToArray());
  4986. if (currencyRate.Count > 0)
  4987. {
  4988. foreach (var item in currencyInfos)
  4989. {
  4990. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  4991. if (rateInfo != null)
  4992. {
  4993. decimal rate1 = Convert.ToDecimal(rateInfo.FSellPri) / 100.00M;
  4994. rate1 *= _fxRateRise;
  4995. item.Rate = rate1.TruncDecimals(4) + _xchgRateAdj;
  4996. }
  4997. }
  4998. }
  4999. return currencyInfos;
  5000. }
  5001. /// <summary>
  5002. /// 出入境费用 实时汇率
  5003. /// </summary>
  5004. /// <returns></returns>
  5005. public static async Task<List<dynamic>> EnterExitCostLiveRate()
  5006. {
  5007. List<dynamic> reteInfos = new List<dynamic>();
  5008. //默认币种显示
  5009. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>()
  5010. {
  5011. new(){ CurrencyCode="USD",CurrencyName = "美元",Rate = 7.5000M },
  5012. new(){ CurrencyCode="EUR",CurrencyName = "欧元",Rate = 8.0000M },
  5013. new(){ CurrencyCode="GBP",CurrencyName = "英镑",Rate = 9.5000M },
  5014. new(){ CurrencyCode="JPY",CurrencyName = "日元",Rate = 0.0500M },
  5015. new(){ CurrencyCode="HKD",CurrencyName = "港币",Rate = 0.9500M }
  5016. };
  5017. var currencyRate = await _juHeApi.PostItemRateAsync(currencyInfos.Select(it => it.CurrencyCode!).ToArray());
  5018. if (currencyRate.Count > 0)
  5019. {
  5020. foreach (var item in currencyInfos)
  5021. {
  5022. var rateInfo = currencyRate.Where(it => it.Name.Equals(item.CurrencyName)).FirstOrDefault();
  5023. if (rateInfo != null)
  5024. {
  5025. item.Rate = Convert.ToDecimal((Convert.ToDecimal(rateInfo.FSellPri == null ? 0.00M : rateInfo.FSellPri) / 100.00M).ToString("#0.0000"));
  5026. decimal rate1 = item.Rate * _fxRateRise + _xchgRateAdj;
  5027. reteInfos.Add(new
  5028. {
  5029. currCode = item.CurrencyCode,
  5030. currName = item.CurrencyName,
  5031. rate = rate1.TruncDecimals(4),
  5032. lastUpdateDt = rateInfo.Date + " " + rateInfo.Time
  5033. });
  5034. }
  5035. }
  5036. }
  5037. return reteInfos;
  5038. }
  5039. /// <summary>
  5040. /// 出入境费用 汇率验证
  5041. /// </summary>
  5042. /// <param name="groupId"></param>
  5043. /// <param name="checkCurrencys">已使用币种</param>
  5044. /// <returns></returns>
  5045. public static async Task<(bool, string, List<CurrencyInfo>)> EnterExitCostCheckRate(int groupId, List<CurrencyInfo> checkCurrencys)
  5046. {
  5047. if (checkCurrencys == null || checkCurrencys.Count < 1) return (false, string.Empty, new List<CurrencyInfo>());
  5048. var info = await _sqlSugar.Queryable<Grp_EnterExitCost>().FirstAsync(x => x.IsDel == 0 && x.DiId == groupId);
  5049. if (info == null) return (false, string.Empty, new List<CurrencyInfo>());
  5050. List<CurrencyInfo> liveRates;
  5051. var cacheRateInfo = await _sqlSugar.Queryable<Sys_ExchangeRateRecord>()
  5052. .OrderByDescending(x => x.CreateTime)
  5053. .FirstAsync(x => x.IsDel == 0 && x.DiId == info.Id);
  5054. if (cacheRateInfo == null)
  5055. {
  5056. var _currencyRate = await _juHeApi.PostItemRateAsync(Array.Empty<string>());
  5057. if (_currencyRate.Count < 1) return (false, "获取汇率失败,请稍后再试!", new List<CurrencyInfo>());
  5058. liveRates = _currencyRate.Select(it => new CurrencyInfo
  5059. {
  5060. CurrencyCode = it.Name,
  5061. CurrencyName = it.Name,
  5062. Rate = Convert.ToDecimal((Convert.ToDecimal(it.FSellPri == null ? 0.00M : it.FSellPri) / 100.00M).ToString("#0.0000"))
  5063. }).ToList();
  5064. }
  5065. else
  5066. {
  5067. liveRates = CommonFun.GetCurrencyChinaToList(cacheRateInfo.RateInfo);
  5068. foreach (var x in liveRates)
  5069. x.Rate = (x.Rate / 100.00M).TruncDecimals(4);
  5070. }
  5071. var cacheRateInfos = CommonFun.GetCurrencyChinaToList(info.CurrencyRemark);
  5072. var isSendMsg = true;
  5073. var msgContent = new StringBuilder();
  5074. //去掉费用未使用得币种
  5075. if (checkCurrencys != null && checkCurrencys.Count > 0)
  5076. {
  5077. cacheRateInfos = cacheRateInfos.Where(x => checkCurrencys.Select(x1 => x1.CurrencyName).ToList().Contains(x.CurrencyName)).ToList();
  5078. }
  5079. if (cacheRateInfos.Any())
  5080. {
  5081. decimal rowthRate = _fxRateRise;
  5082. foreach (var cacheRate in cacheRateInfos)
  5083. {
  5084. var liveRate = liveRates.Find(x => x.CurrencyName.Equals(cacheRate.CurrencyName));
  5085. if (liveRate == null) continue;
  5086. var currRate = (rowthRate * liveRate.Rate).TruncDecimals(4) + _xchgRateAdj;
  5087. //if (cacheRate.Rate != currRate)
  5088. //{
  5089. // isSendMsg = true;
  5090. //>团组归属:<font color='info'>{groupName}</font>
  5091. msgContent.AppendLine($">- {cacheRate.CurrencyName}汇率(页面保存):{cacheRate.Rate:#0.0000} / 实时汇率(接口保存,已上浮1.0350):{currRate:#0.0000}【原接口输出汇率为:{liveRate.Rate:#0.0000}】");
  5092. //}
  5093. }
  5094. return (isSendMsg, msgContent.ToString(), liveRates);
  5095. }
  5096. return (false, string.Empty, new List<CurrencyInfo>());
  5097. }
  5098. #endregion
  5099. #region 三公费用明细 文件下载
  5100. /// <summary>
  5101. /// 获取三公费用标准city
  5102. /// </summary>
  5103. /// <param name="placeData"></param>
  5104. /// <param name="nationalTravelFeeId"></param>
  5105. /// <returns></returns>
  5106. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  5107. {
  5108. string _city = string.Empty;
  5109. if (placeData.Count < 1) return _city;
  5110. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  5111. if (data == null) return _city;
  5112. string country = data.Country;
  5113. string city = data.City;
  5114. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  5115. else _city = city;
  5116. return _city;
  5117. }
  5118. /// <summary>
  5119. /// 三公费用明细 文件下载
  5120. /// </summary>
  5121. /// <param name="dto"></param>
  5122. /// <param name="fileFormat"></param>
  5123. /// <returns></returns>
  5124. public static async Task<JsonView> EnterExitCostDownload(EnterExitCostDownloadDto dto, string fileFormat = "pdf")
  5125. {
  5126. var _view = new JsonView() { Code = StatusCodes.Status204NoContent };
  5127. if (dto.DiId < 1)
  5128. {
  5129. _view.Msg = "请传入有效的DiId参数;";
  5130. return _view;
  5131. }
  5132. if (dto.ExportType < 1)
  5133. {
  5134. _view.Msg = MsgTips.Port;
  5135. return _view;
  5136. }
  5137. if (dto.SubTypeId < 1)
  5138. {
  5139. _view.Msg = @"请传入有效的SubTypeId参数;
  5140. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  5141. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  5142. 3 团组成员名单 1 团组成员名单";
  5143. return _view;
  5144. }
  5145. try
  5146. {
  5147. var enterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  5148. var dayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  5149. if (enterExitCosts == null)
  5150. {
  5151. _view.Msg = @"该团组未填写出入境费用;";
  5152. return _view;
  5153. }
  5154. //数据源
  5155. List<Grp_DayAndCost> dac1 = dayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  5156. List<Grp_DayAndCost> dac2 = dayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  5157. List<Grp_DayAndCost> dac3 = dayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  5158. List<Grp_DayAndCost> dac4 = dayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  5159. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  5160. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.Id == dto.DiId).First();
  5161. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  5162. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  5163. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  5164. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  5165. .Select((tcl, dc, cc) => new
  5166. {
  5167. Name = dc.LastName + dc.FirstName,
  5168. Sex = dc.Sex,
  5169. Birthday = dc.BirthDay,
  5170. Company = cc.CompanyFullName,
  5171. Job = dc.Job
  5172. })
  5173. .ToList();
  5174. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  5175. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  5176. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  5177. var rateDatas = await enterExitCosts.CurrencyRemark.SplitExchangeRate();
  5178. _DelegationInfo.VisitCountry = _DelegationInfo?.VisitCountry?.Replace("|", "、") ?? "";
  5179. if (dto.ExportType == 1) //明细表
  5180. {
  5181. if (dto.SubTypeId == 1005) //1005(默认明细表)
  5182. {
  5183. if (!fileFormat.Equals("pdf")) fileFormat = "docx";
  5184. //获取模板
  5185. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  5186. //载入模板
  5187. Document doc = new Document(tempPath);
  5188. DocumentBuilder builder = new DocumentBuilder(doc);
  5189. //利用键值对存放数据
  5190. Dictionary<string, string> dic = new Dictionary<string, string>();
  5191. decimal stayFeeTotal = dayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal); // 住宿费
  5192. decimal mealsFeeTotal = dayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal); // 伙食费费
  5193. decimal miscellaneousFeeTotal = dayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal); // 公杂费
  5194. decimal tainFeeTotal = dayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal); // 培训费
  5195. decimal insidePayTotal = enterExitCosts.InsidePay;
  5196. string row1_1 = "";
  5197. if (enterExitCosts.Visa > 0)
  5198. {
  5199. //insidePayTotal += enterExitCosts.Visa;
  5200. row1_1 = $"签证费: {enterExitCosts.Visa:#0.00} 人民币/人";
  5201. //if (!string.IsNullOrEmpty(enterExitCosts.VisaRemark))
  5202. //{
  5203. // row1_1 += $"\t签证费用描述: {enterExitCosts.VisaRemark}";
  5204. //}
  5205. }
  5206. string row1_2 = "";
  5207. if (enterExitCosts.YiMiao > 0)
  5208. {
  5209. //insidePayTotal += enterExitCosts.YiMiao;
  5210. row1_2 += $"疫苗费:{enterExitCosts.YiMiao:#0.00} 人民币/人";
  5211. }
  5212. if (enterExitCosts.HeSuan > 0)
  5213. {
  5214. //insidePayTotal += enterExitCosts.HeSuan;
  5215. row1_2 += $"核酸检测费:{enterExitCosts.HeSuan:#0.00} 人民币/人";
  5216. }
  5217. if (enterExitCosts.Service > 0)
  5218. {
  5219. //insidePayTotal += enterExitCosts.Service;
  5220. row1_2 += $"服务费:{enterExitCosts.Service:#0.00} 人民币/人";
  5221. }
  5222. string row1_3 = "";
  5223. if (enterExitCosts.Safe > 0)
  5224. {
  5225. //insidePayTotal += enterExitCosts.Safe;
  5226. row1_3 += $"保险费:{enterExitCosts.Safe:#0.00} 人民币/人";
  5227. }
  5228. if (enterExitCosts.Ticket > 0)
  5229. {
  5230. //insidePayTotal += enterExitCosts.Ticket;
  5231. row1_3 += $"参展门票:{enterExitCosts.Ticket:#0.00} 人民币/人";
  5232. }
  5233. string row1 = "";
  5234. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  5235. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  5236. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}";
  5237. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  5238. dic.Add("Row1Str", row1);
  5239. dic.Add("OutsideJJ", enterExitCosts.OutsideJJPay.ToString("#0.00"));
  5240. dic.Add("OutsaideGW", enterExitCosts.OutsideGWPay.ToString("#0.00"));
  5241. dic.Add("AirJJ", enterExitCosts.AirJJ.ToString("#0.00"));
  5242. dic.Add("AirGW", enterExitCosts.AirGW.ToString("#0.00"));
  5243. var cityTrafficLable = new StringBuilder()
  5244. .AppendFormat($"经济舱费用:{enterExitCosts.CityTranffic:#0.00} 元/人、")
  5245. .AppendFormat($"公务舱费用:{enterExitCosts.CityTranffic1:#0.00} 元/人、")
  5246. .AppendFormat($"头等舱费用:{enterExitCosts.CityTranffic2:#0.00}")
  5247. .ToString();
  5248. dic.Add("CityTranffic", cityTrafficLable);
  5249. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  5250. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  5251. string miscellaneousFeeTotalStr = miscellaneousFeeTotal.ToString("#0.00");
  5252. dic.Add("SubGZF", miscellaneousFeeTotalStr);
  5253. //dic.Add("SubPX", tainFeeTotal.ToString("#0.00"));
  5254. decimal subJJC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + enterExitCosts.OutsideJJPay;
  5255. decimal subGWC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + enterExitCosts.OutsideGWPay;
  5256. dic.Add("SubJJC", subJJC.ToString("#0.00"));
  5257. dic.Add("SubGWC", subGWC.ToString("#0.00"));
  5258. #region 填充word模板书签内容
  5259. foreach (var key in dic.Keys)
  5260. {
  5261. builder.MoveToBookmark(key);
  5262. builder.Write(dic[key]);
  5263. }
  5264. #endregion
  5265. #region 填充word表格内容
  5266. ////获读取指定表格方法二
  5267. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5268. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5269. for (int i = 0; i < dac1.Count; i++)
  5270. {
  5271. Grp_DayAndCost dac = dac1[i];
  5272. if (dac == null) continue;
  5273. builder.MoveToCell(0, i, 0, 0);
  5274. builder.Write("第" + dac.Days.ToString() + "晚:");
  5275. builder.MoveToCell(0, i, 1, 0);
  5276. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  5277. //builder.Write(dac.Place == null ? "" : dac.Place);
  5278. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5279. builder.MoveToCell(0, i, 2, 0);
  5280. builder.Write("费用标准:");
  5281. string curr = "";
  5282. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5283. if (currData != null)
  5284. {
  5285. curr = currData.Name;
  5286. }
  5287. builder.MoveToCell(0, i, 3, 0);
  5288. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5289. builder.MoveToCell(0, i, 4, 0);
  5290. builder.Write("费用小计:");
  5291. builder.MoveToCell(0, i, 5, 0);
  5292. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5293. }
  5294. //删除多余行
  5295. while (table1.Rows.Count > dac1.Count)
  5296. {
  5297. table1.Rows.RemoveAt(dac1.Count);
  5298. }
  5299. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  5300. for (int i = 0; i < dac2.Count; i++)
  5301. {
  5302. Grp_DayAndCost dac = dac2[i];
  5303. if (dac == null) continue;
  5304. builder.MoveToCell(1, i, 0, 0);
  5305. builder.Write("第" + dac.Days.ToString() + "天:");
  5306. builder.MoveToCell(1, i, 1, 0);
  5307. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5308. builder.MoveToCell(1, i, 2, 0);
  5309. builder.Write("费用标准:");
  5310. string curr = "";
  5311. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5312. if (currData != null)
  5313. {
  5314. curr = currData.Name;
  5315. }
  5316. builder.MoveToCell(1, i, 3, 0);
  5317. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5318. builder.MoveToCell(1, i, 4, 0);
  5319. builder.Write("费用小计:");
  5320. builder.MoveToCell(1, i, 5, 0);
  5321. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5322. }
  5323. //删除多余行
  5324. while (table2.Rows.Count > dac2.Count)
  5325. {
  5326. table2.Rows.RemoveAt(dac2.Count);
  5327. }
  5328. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  5329. for (int i = 0; i < dac3.Count; i++)
  5330. {
  5331. Grp_DayAndCost dac = dac3[i];
  5332. if (dac == null) continue;
  5333. builder.MoveToCell(2, i, 0, 0);
  5334. builder.Write("第" + dac.Days.ToString() + "天:");
  5335. builder.MoveToCell(2, i, 1, 0);
  5336. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5337. builder.MoveToCell(2, i, 2, 0);
  5338. builder.Write("费用标准:");
  5339. string curr = "";
  5340. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  5341. if (currData != null)
  5342. {
  5343. curr = currData.Name;
  5344. }
  5345. builder.MoveToCell(2, i, 3, 0);
  5346. builder.Write(dac.Cost.ToString("#0.00") + curr);
  5347. builder.MoveToCell(2, i, 4, 0);
  5348. builder.Write("费用小计:");
  5349. builder.MoveToCell(2, i, 5, 0);
  5350. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  5351. }
  5352. //删除多余行
  5353. while (table3.Rows.Count > dac3.Count)
  5354. {
  5355. table3.Rows.RemoveAt(dac3.Count);
  5356. }
  5357. #endregion
  5358. //文件名
  5359. //string strFileName = $"{_DelegationInfo.TeamName}出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  5360. //string strFileName = $"{_DelegationInfo.TeamName}-出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  5361. string strFileName = $"{_DelegationInfo.TeamName}{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.{fileFormat}";
  5362. AsposeHelper.removewatermark_v2180();
  5363. //doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5364. var saveFormat = Aspose.Words.SaveFormat.Docx;
  5365. if (fileFormat.Equals("pdf"))
  5366. {
  5367. //doc.LayoutOptions.IsShowComments = false;
  5368. doc.LayoutOptions.IsShowHiddenText = false;
  5369. doc.LayoutOptions.IsShowParagraphMarks = false;
  5370. doc.LayoutOptions.RevisionOptions.DeletedTextEffect = RevisionTextEffect.None;
  5371. doc.AcceptAllRevisions();
  5372. Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
  5373. options.Compliance = PdfCompliance.PdfA1a;
  5374. options.CreateNoteHyperlinks = true;
  5375. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, options);
  5376. //_view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  5377. _view.Data = new { Url = strFileName };
  5378. _view.Msg = "成功";
  5379. return _view;
  5380. }
  5381. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, saveFormat);
  5382. _view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  5383. _view.Msg = "成功";
  5384. return _view;
  5385. }
  5386. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  5387. {
  5388. //获取模板
  5389. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  5390. //载入模板
  5391. Document doc = new Document(tempPath);
  5392. DocumentBuilder builder = new DocumentBuilder(doc);
  5393. Dictionary<string, string> dic = new Dictionary<string, string>();
  5394. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5395. {
  5396. List<string> list = new List<string>();
  5397. try
  5398. {
  5399. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5400. foreach (var item in spilitArr)
  5401. {
  5402. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5403. var depCode = spDotandEmpty[2].Substring(0, 3);
  5404. var arrCode = spDotandEmpty[2].Substring(3, 3);
  5405. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  5406. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  5407. list.Add(depName);
  5408. list.Add(arrName);
  5409. }
  5410. list = list.Distinct().ToList();
  5411. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5412. }
  5413. catch (Exception)
  5414. {
  5415. dic.Add("ReturnCode", "行程录入不正确!");
  5416. }
  5417. }
  5418. else
  5419. {
  5420. dic.Add("ReturnCode", "未录入行程!");
  5421. }
  5422. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5423. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5424. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5425. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5426. {
  5427. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5428. dic.Add("Day", sp.Days.ToString());
  5429. }
  5430. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5431. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5432. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  5433. //dic.Add("Names", Names);
  5434. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5435. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5436. decimal dac1totalPrice = 0.00M;
  5437. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  5438. foreach (var dac in dac1)
  5439. {
  5440. if (dac.SubTotal == 0.00M)
  5441. {
  5442. continue;
  5443. }
  5444. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  5445. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  5446. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  5447. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5448. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  5449. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  5450. builder.Write(currency);//币种
  5451. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  5452. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5453. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  5454. builder.Write("");//人数
  5455. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  5456. builder.Write("");//天数
  5457. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  5458. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5459. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  5460. decimal rate = 0.00M;
  5461. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  5462. builder.Write(rate.ToString("#0.0000"));//汇率
  5463. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  5464. decimal rbmPrice = dac.SubTotal;
  5465. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5466. accommodationStartIndex++;
  5467. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  5468. }
  5469. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  5470. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  5471. {
  5472. table1.Rows.RemoveAt(i - 1);
  5473. foodandotherStartIndex--;
  5474. }
  5475. if (dac2.Count == dac3.Count)//国家 币种 金额
  5476. {
  5477. for (int i = 0; i < dac2.Count; i++)
  5478. {
  5479. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  5480. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  5481. }
  5482. }
  5483. decimal dac2totalPrice = 0.00M;
  5484. foreach (var dac in dac2)
  5485. {
  5486. if (dac.SubTotal == 0)
  5487. {
  5488. continue;
  5489. }
  5490. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  5491. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  5492. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  5493. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  5494. builder.Write(currency);//币种
  5495. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  5496. builder.Write(dac.Cost.ToString("#0.00"));//标准
  5497. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  5498. builder.Write("");//人数
  5499. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  5500. builder.Write("");//天数
  5501. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  5502. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  5503. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  5504. decimal rate = 0.00M;
  5505. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  5506. builder.Write(rate.ToString("#0.0000"));//汇率
  5507. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  5508. decimal rbmPrice = dac.SubTotal;
  5509. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  5510. foodandotherStartIndex++;
  5511. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  5512. }
  5513. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  5514. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  5515. {
  5516. table1.Rows.RemoveAt(i - 1);
  5517. }
  5518. //dic.Add("CityTranffic", enterExitCosts.CityTranffic.ToString("#0.00"));
  5519. string otherFeeStr = "";
  5520. if (enterExitCosts.Visa > 0) otherFeeStr += $"签证费: {enterExitCosts.Visa.ToString("#0.00")} 元,";
  5521. if (enterExitCosts.Safe > 0) otherFeeStr += $"保险费: {enterExitCosts.Safe.ToString("#0.00")} 元,";
  5522. if (enterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {enterExitCosts.Ticket.ToString("#0.00")} 元,";
  5523. if (otherFeeStr.Length > 0)
  5524. {
  5525. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  5526. otherFeeStr = $"({otherFeeStr})";
  5527. dic.Add("OtherFeeStr", otherFeeStr);
  5528. }
  5529. //总计
  5530. decimal allPrice = dac1totalPrice + dac2totalPrice + enterExitCosts.Visa + enterExitCosts.Safe + enterExitCosts.Ticket;
  5531. //国际旅费
  5532. string outsideJJ = "";
  5533. string allPriceJJ = "";
  5534. if (enterExitCosts.SumJJC == 1)
  5535. {
  5536. outsideJJ = string.Format(@"经济舱:{0} 元/人", enterExitCosts.AirJJ.ToString("#0.00"));
  5537. allPriceJJ = string.Format(@"经济舱:{0} 元/人", (allPrice + enterExitCosts.OutsideJJPay).ToString("#0.00"));
  5538. }
  5539. string outsideGW = "";
  5540. string allPriceGW = "";
  5541. if (enterExitCosts.SumGWC == 1)
  5542. {
  5543. outsideGW = string.Format(@"公务舱:{0} 元/人", enterExitCosts.AirGW.ToString("#0.00"));
  5544. allPriceGW = string.Format(@"公务舱:{0} 元/人", (allPrice + enterExitCosts.OutsideGWPay).ToString("#0.00"));
  5545. }
  5546. if (enterExitCosts.SumJJC == 1 || enterExitCosts.SumGWC == 1)
  5547. {
  5548. string InTravelPriceStr = string.Format(@" ({0} {1})", outsideJJ, outsideGW);
  5549. dic.Add("InTravelPrice", InTravelPriceStr);
  5550. string FinalSumPriceStr = string.Format(@" ({0} {1})", allPriceJJ, allPriceGW);
  5551. dic.Add("FinalSumPrice", FinalSumPriceStr);
  5552. }
  5553. //dic.Add("VisaPay", enterExitCosts.Visa.ToString("#0.00"));
  5554. //dic.Add("SafePay", enterExitCosts.Safe.ToString("#0.00"));
  5555. //dic.Add("YiMiao", enterExitCosts.YiMiao.ToString("#0.00"));
  5556. foreach (var key in dic.Keys)
  5557. {
  5558. builder.MoveToBookmark(key);
  5559. builder.Write(dic[key]);
  5560. }
  5561. //模板文件名
  5562. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表.docx";
  5563. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5564. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5565. _view.Data = new { Url = url };
  5566. _view.Msg = "成功";
  5567. return _view;
  5568. }
  5569. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  5570. {
  5571. //获取模板
  5572. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  5573. //载入模板
  5574. WorkbookDesigner designer = new WorkbookDesigner();
  5575. designer.Workbook = new Aspose.Cells.Workbook(tempPath);
  5576. Dictionary<string, string> dic = new Dictionary<string, string>();
  5577. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5578. {
  5579. List<string> list = new List<string>();
  5580. try
  5581. {
  5582. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5583. foreach (var item in spilitArr)
  5584. {
  5585. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5586. var depCode = spDotandEmpty[2].Substring(0, 3);
  5587. var arrCode = spDotandEmpty[2].Substring(3, 3);
  5588. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  5589. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  5590. list.Add(depName);
  5591. list.Add(arrName);
  5592. }
  5593. list = list.Distinct().ToList();
  5594. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5595. }
  5596. catch (Exception)
  5597. {
  5598. dic.Add("ReturnCode", "行程录入不正确!");
  5599. }
  5600. }
  5601. else
  5602. {
  5603. dic.Add("ReturnCode", "未录入行程!");
  5604. }
  5605. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5606. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5607. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5608. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5609. {
  5610. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5611. dic.Add("Day", sp.Days.ToString());
  5612. }
  5613. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5614. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5615. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  5616. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  5617. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  5618. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  5619. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  5620. designer.SetDataSource("Name", Names);
  5621. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  5622. designer.SetDataSource("Day", dic["Day"] + "天");
  5623. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  5624. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  5625. int startIndex = 10;
  5626. const int startIndexcopy = 10;
  5627. if (dac2.Count == dac3.Count)//国家 币种 金额
  5628. {
  5629. for (int i = 0; i < dac2.Count; i++)
  5630. {
  5631. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  5632. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  5633. }
  5634. }
  5635. DataTable dtdac1 = new DataTable();
  5636. List<string> place = new List<string>();
  5637. dtdac1.Columns.AddRange(new DataColumn[] {
  5638. new DataColumn(){ ColumnName = "city"},
  5639. new DataColumn(){ ColumnName = "curr"},
  5640. new DataColumn(){ ColumnName = "criterion"},
  5641. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  5642. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  5643. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  5644. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  5645. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  5646. });
  5647. DataTable dtdac2 = new DataTable();
  5648. dtdac2.Columns.AddRange(new DataColumn[] {
  5649. new DataColumn(){ ColumnName = "city"},
  5650. new DataColumn(){ ColumnName = "curr"},
  5651. new DataColumn(){ ColumnName = "criterion"},
  5652. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  5653. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  5654. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  5655. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  5656. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  5657. });
  5658. dtdac1.TableName = "tb1";
  5659. dtdac2.TableName = "tb2";
  5660. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  5661. foreach (var item in dac1)
  5662. {
  5663. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  5664. if (place.Contains(item.Place))
  5665. {
  5666. continue;
  5667. }
  5668. DataRow row = dtdac1.NewRow();
  5669. row["city"] = item.Place;
  5670. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  5671. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5672. row["curr"] = currency;
  5673. row["rate"] = rate.ToString("#0.0000");
  5674. row["criterion"] = item.Cost.ToString("#0.00");
  5675. row["number"] = 1;
  5676. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  5677. //row["costRMB"] = rbmPrice;
  5678. dtdac1.Rows.Add(row);
  5679. place.Add(item.Place);
  5680. }
  5681. place = new List<string>();
  5682. foreach (var item in dac2)
  5683. {
  5684. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  5685. if (place.Contains(item.Place))
  5686. {
  5687. continue;
  5688. }
  5689. DataRow row = dtdac2.NewRow();
  5690. row["city"] = item.Place;
  5691. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  5692. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  5693. row["curr"] = currency;
  5694. row["rate"] = rate.ToString("#0.0000");
  5695. row["criterion"] = item.Cost.ToString("#0.00");
  5696. row["number"] = 1;
  5697. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  5698. //row["cost"] = item.SubTotal;
  5699. //row["costRMB"] = rbmPrice;
  5700. dtdac2.Rows.Add(row);
  5701. place.Add(item.Place);
  5702. //dac2totalPrice += rbmPrice;
  5703. }
  5704. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  5705. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  5706. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  5707. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  5708. //designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {enterExitCosts.CityTranffic.ToString("#0.00")} 元");
  5709. //designer.SetDataSource("sumCityTranffic", @$"{enterExitCosts.CityTranffic.ToString("#0.00")} ");
  5710. string cell4Str = $" 4.国际旅费:经济舱:{enterExitCosts.AirJJ.ToString("#0.00")} 元/人,公务舱:{enterExitCosts.AirGW.ToString("#0.00")} 元/人";
  5711. string cellStr = $" 5.其他费用(";
  5712. if (enterExitCosts.Visa > 0) cellStr += $"签证费:{enterExitCosts.Visa.ToString("#0.00")}元,";
  5713. if (enterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{enterExitCosts.YiMiao.ToString("#0.00")}元,";
  5714. if (enterExitCosts.HeSuan > 0) cellStr += $"核酸费:{enterExitCosts.HeSuan.ToString("#0.00")}元,";
  5715. if (enterExitCosts.Safe > 0) cellStr += $"保险费:{enterExitCosts.Safe.ToString("#0.00")}元,";
  5716. if (enterExitCosts.Ticket > 0) cellStr += $"参展门票费:{enterExitCosts.Ticket.ToString("#0.00")}元,";
  5717. if (enterExitCosts.Service > 0) cellStr += $"服务费:{enterExitCosts.Service.ToString("#0.00")}元,";
  5718. if (cellStr.Length > 8)
  5719. {
  5720. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  5721. }
  5722. cellStr += ")";
  5723. decimal otherFee = enterExitCosts.Visa + enterExitCosts.YiMiao + enterExitCosts.HeSuan + enterExitCosts.Safe + enterExitCosts.Ticket + enterExitCosts.Service;
  5724. decimal s = dac1totalPrice + dac2totalPrice + enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay + otherFee;
  5725. decimal pxFee = dac4.Sum(it => it.Cost);
  5726. decimal glvFee = enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay;
  5727. string celllastStr1 = "";
  5728. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice.ToString("#0.00")} 元";
  5729. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice.ToString("#0.00")} 元";
  5730. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee.ToString("#0.00")} 元";
  5731. celllastStr1 += $",国际旅费 元";
  5732. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee.ToString("#0.00")} 元";
  5733. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  5734. designer.SetDataSource("cell4Str", cell4Str);
  5735. designer.SetDataSource("cellStr", cellStr);
  5736. designer.SetDataSource("cellSum", (enterExitCosts.Visa + enterExitCosts.Safe).ToString("#0.00"));
  5737. designer.SetDataSource("cellSum4", (enterExitCosts.OutsideJJPay + enterExitCosts.OutsideGWPay).ToString("#0.00"));
  5738. designer.SetDataSource("celllastStr", celllastStr);
  5739. Aspose.Cells.Workbook wb = designer.Workbook;
  5740. var sheet = wb.Worksheets[0];
  5741. //绑定datatable数据集
  5742. designer.SetDataSource(dtdac1);
  5743. designer.SetDataSource(dtdac2);
  5744. designer.Process();
  5745. var rowStart = dtdac1.Rows.Count;
  5746. while (rowStart > 0)
  5747. {
  5748. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  5749. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  5750. startIndex++;
  5751. rowStart--;
  5752. }
  5753. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  5754. startIndex += 1; //总计行
  5755. rowStart = dtdac2.Rows.Count;
  5756. while (rowStart > 0)
  5757. {
  5758. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  5759. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  5760. startIndex++;
  5761. rowStart--;
  5762. }
  5763. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  5764. wb.CalculateFormula(true);
  5765. //模板文件名
  5766. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls"; ;//$".xls";
  5767. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5768. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5769. _view.Data = new { Url = url };
  5770. _view.Msg = "成功";
  5771. return _view;
  5772. }
  5773. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  5774. {
  5775. //获取模板
  5776. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  5777. //载入模板
  5778. Document doc = new Document(tempPath);
  5779. DocumentBuilder builder = new DocumentBuilder(doc);
  5780. Dictionary<string, string> dic = new Dictionary<string, string>();
  5781. dic.Add("GroupName", _DelegationInfo.TeamName);
  5782. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5783. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  5784. string missionLeaderJob = "";//负责人job
  5785. //int groupNumber = 0; //团人数
  5786. if (DeleClientList.Count > 0)
  5787. {
  5788. missionLeader = DeleClientList[0]?.Name ?? "";
  5789. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  5790. }
  5791. dic.Add("MissionLeader", missionLeader); //团负责人
  5792. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  5793. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  5794. #region MyRegion
  5795. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  5796. //{
  5797. // List<string> list = new List<string>();
  5798. // try
  5799. // {
  5800. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  5801. // foreach (var item in spilitArr)
  5802. // {
  5803. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  5804. // var depCode = spDotandEmpty[2].Substring(0, 3);
  5805. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  5806. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  5807. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  5808. // list.Add(depName);
  5809. // list.Add(arrName);
  5810. // }
  5811. // list = list.Distinct().ToList();
  5812. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  5813. // }
  5814. // catch (Exception)
  5815. // {
  5816. // dic.Add("ReturnCode", "行程录入不正确!");
  5817. // }
  5818. //}
  5819. //else
  5820. //{
  5821. // dic.Add("ReturnCode", "未录入行程!");
  5822. //}
  5823. List<string> countrys = _dirRep.GroupSplitCountry(_DelegationInfo.VisitCountry);
  5824. dic.Add("ReturnCode", string.Join("、", countrys));
  5825. #endregion
  5826. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  5827. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5828. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5829. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  5830. //{
  5831. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5832. // dic.Add("Day", sp.Days.ToString());
  5833. //}
  5834. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  5835. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  5836. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5837. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5838. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5839. //培训人员名单
  5840. int cultivateRowIndex = 7;
  5841. foreach (var item in DeleClientList)
  5842. {
  5843. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  5844. builder.Write(item.Name);
  5845. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  5846. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  5847. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  5848. string birthDay = "";
  5849. if (item.Birthday != null)
  5850. {
  5851. DateTime dt = Convert.ToDateTime(item.Birthday);
  5852. birthDay = $"{dt.Year}.{dt.Month}";
  5853. }
  5854. builder.Write(birthDay);
  5855. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  5856. builder.Write(item.Company);
  5857. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  5858. builder.Write(item.Job);
  5859. cultivateRowIndex++;
  5860. }
  5861. //删除多余行
  5862. //cultivateRowIndex -= 2;
  5863. int delRows = 10 + 7 - cultivateRowIndex;
  5864. if (delRows > 0)
  5865. {
  5866. for (int i = 0; i < delRows; i++)
  5867. {
  5868. table1.Rows.RemoveAt(cultivateRowIndex);
  5869. //cultivateRowIndex++;
  5870. }
  5871. }
  5872. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  5873. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  5874. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  5875. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  5876. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  5877. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  5878. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  5879. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  5880. decimal cityTranfficFeeToatal = 0.00M;
  5881. //decimal cityTranfficFeeToatal = enterExitCosts.CityTranffic; //城市区间交通费
  5882. //dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  5883. //其他费用
  5884. decimal otherFeeTotal = enterExitCosts.Visa + enterExitCosts.Safe + enterExitCosts.Ticket + enterExitCosts.YiMiao + enterExitCosts.HeSuan + enterExitCosts.Service;
  5885. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  5886. //其他费用合计
  5887. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  5888. decimal _jjcFeeToatal = enterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  5889. decimal _gwcFeeToatal = enterExitCosts.AirGW + _otherFeeTotal; //公务舱
  5890. //公务舱合计
  5891. //国际旅费
  5892. //string outsideJJ = "";
  5893. //string allPriceJJ = "";
  5894. if (enterExitCosts.SumJJC == 1 && enterExitCosts.SumGWC == 0)
  5895. {
  5896. dic.Add("AirFeeTotal", enterExitCosts.AirJJ.ToString("#0.00"));
  5897. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  5898. }
  5899. if (enterExitCosts.SumGWC == 1 && enterExitCosts.SumJJC == 0)
  5900. {
  5901. dic.Add("AirFeeTotal", enterExitCosts.AirGW.ToString("#0.00"));
  5902. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  5903. }
  5904. if (enterExitCosts.SumJJC == 1 && enterExitCosts.SumGWC == 1)
  5905. {
  5906. string airFeeTotalStr = string.Format(@$"经济舱:{enterExitCosts.AirJJ.ToString("#0.00")} 公务舱:{enterExitCosts.AirGW.ToString("#0.00")}");
  5907. dic.Add("AirFeeTotal", airFeeTotalStr);
  5908. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal.ToString("#0.00")} 公务舱:{_gwcFeeToatal.ToString("#0.00")}");
  5909. dic.Add("FeeTotal", feeTotalStr);
  5910. }
  5911. foreach (var key in dic.Keys)
  5912. {
  5913. builder.MoveToBookmark(key);
  5914. builder.Write(dic[key]);
  5915. }
  5916. //模板文件名
  5917. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  5918. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5919. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5920. _view.Data = new { Url = url };
  5921. _view.Msg = "成功";
  5922. return _view;
  5923. }
  5924. }
  5925. else if (dto.ExportType == 2) //表格
  5926. {
  5927. //利用键值对存放数据
  5928. Dictionary<string, string> dic = new Dictionary<string, string>();
  5929. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  5930. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  5931. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  5932. dic.Add("Day", sp.Days.ToString());
  5933. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  5934. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  5935. {
  5936. //获取模板
  5937. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  5938. //载入模板
  5939. Document doc = new Document(tempPath);
  5940. DocumentBuilder builder = new DocumentBuilder(doc);
  5941. dic.Add("TeamName", _DelegationInfo.TeamName);
  5942. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  5943. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  5944. string missionLeaderName = "",
  5945. missionLeaderJob = "";
  5946. if (DeleClientList.Count > 0)
  5947. {
  5948. missionLeaderName = DeleClientList[0].Name;
  5949. missionLeaderJob = DeleClientList[0].Job;
  5950. }
  5951. dic.Add("MissionLeaderName", missionLeaderName);
  5952. dic.Add("MissionLeaderJob", missionLeaderJob);
  5953. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  5954. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  5955. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  5956. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  5957. int rowCount = 10;//总人数行
  5958. int startRowIndex = 7; //起始行
  5959. for (int i = 0; i < DeleClientList.Count; i++)
  5960. {
  5961. builder.MoveToCell(0, startRowIndex, 0, 0);
  5962. builder.Write(DeleClientList[i].Name); //出国人员姓名
  5963. builder.MoveToCell(0, startRowIndex, 1, 0);
  5964. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  5965. builder.Write(sex);//性别
  5966. builder.MoveToCell(0, startRowIndex, 2, 0);
  5967. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  5968. builder.MoveToCell(0, startRowIndex, 3, 0);
  5969. builder.Write(DeleClientList[i].Company);//工作单位
  5970. builder.MoveToCell(0, startRowIndex, 4, 0);
  5971. builder.Write(DeleClientList[i].Job);//职务及级别
  5972. builder.MoveToCell(0, startRowIndex, 5, 0);
  5973. builder.Write("");//人员属性
  5974. builder.MoveToCell(0, startRowIndex, 6, 0);
  5975. builder.Write("");//上次出国时间
  5976. startRowIndex++;
  5977. }
  5978. int nullRow = rowCount - DeleClientList.Count;//空行
  5979. for (int i = 0; i < nullRow; i++)
  5980. {
  5981. table1.Rows.Remove(table1.Rows[startRowIndex]);
  5982. }
  5983. foreach (var key in dic.Keys)
  5984. {
  5985. builder.MoveToBookmark(key);
  5986. builder.Write(dic[key]);
  5987. }
  5988. //模板文件名
  5989. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  5990. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  5991. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  5992. _view.Data = new { Url = url };
  5993. _view.Msg = "成功";
  5994. return _view;
  5995. }
  5996. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  5997. {
  5998. //获取模板
  5999. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  6000. //载入模板
  6001. Document doc = new Document(tempPath);
  6002. DocumentBuilder builder = new DocumentBuilder(doc);
  6003. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  6004. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  6005. dic.Add("Names", Names);
  6006. int accommodationRows = 12, foodandotherRows = 12;
  6007. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  6008. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  6009. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  6010. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  6011. int accommodationStartIndex = 6;
  6012. decimal dac1totalPrice = 0.00M;
  6013. foreach (var dac in dac1)
  6014. {
  6015. if (dac.SubTotal == 0)
  6016. {
  6017. continue;
  6018. }
  6019. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  6020. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  6021. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  6022. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  6023. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  6024. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  6025. builder.Write(currency);//币种
  6026. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  6027. builder.Write(dac.Cost.ToString("#0.00"));//标准
  6028. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  6029. builder.Write("");//人数
  6030. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  6031. builder.Write("");//天数
  6032. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  6033. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  6034. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  6035. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  6036. builder.Write(rate.ToString("#0.0000"));//汇率
  6037. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  6038. decimal rbmPrice = rate * dac.SubTotal;
  6039. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  6040. accommodationStartIndex++;
  6041. dac1totalPrice += rbmPrice;
  6042. }
  6043. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  6044. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  6045. builder.Write("小计");
  6046. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  6047. builder.Write(dac1totalPrice.ToString("#0.00"));
  6048. accommodationStartIndex++;
  6049. int nullRow = accommodationRows - dac1.Count;
  6050. //删除空行
  6051. //if (nullRow > 0)
  6052. //{
  6053. // int rowIndex = accommodationStartIndex;
  6054. // for (int i = 0; i < nullRow; i++)
  6055. // {
  6056. // Row row = table1.Rows[rowIndex];
  6057. // row.Remove();
  6058. // rowIndex++;
  6059. // }
  6060. //}
  6061. if (dac2.Count == dac3.Count)//国家 币种 金额
  6062. {
  6063. for (int i = 0; i < dac2.Count; i++)
  6064. {
  6065. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  6066. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  6067. }
  6068. }
  6069. int foodandotherStartIndex = 19;//
  6070. decimal dac2totalPrice = 0.00M;
  6071. foreach (var dac in dac2)
  6072. {
  6073. if (dac.SubTotal == 0)
  6074. {
  6075. continue;
  6076. }
  6077. //foodandotherStartIndex = 12;
  6078. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  6079. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  6080. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  6081. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  6082. builder.Write(currency);//币种
  6083. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  6084. builder.Write(dac.Cost.ToString("#0.00"));//标准
  6085. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  6086. builder.Write("");//人数
  6087. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  6088. builder.Write("");//天数
  6089. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  6090. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  6091. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  6092. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  6093. builder.Write(rate.ToString("#0.0000"));//汇率
  6094. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  6095. decimal rbmPrice = rate * dac.SubTotal;
  6096. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  6097. foodandotherStartIndex++;
  6098. dac2totalPrice += rbmPrice;
  6099. }
  6100. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  6101. //删除空行
  6102. if (dac2.Count < foodandotherRows)
  6103. {
  6104. //int nullRow = accommodationRows - dac2.Count;
  6105. //while (table2.Rows.Count > dac2.Count)
  6106. //{
  6107. // table2.Rows.RemoveAt(dac2.Count);
  6108. //}
  6109. }
  6110. //dic.Add("CityTranffic", enterExitCosts.CityTranffic.ToString("#0.00"));
  6111. string otherFeeStr = "";
  6112. if (enterExitCosts.Visa > 0) otherFeeStr += $"签证费: {enterExitCosts.Visa.ToString("#0.00")} 元,";
  6113. if (enterExitCosts.Safe > 0) otherFeeStr += $"保险费: {enterExitCosts.Safe.ToString("#0.00")} 元,";
  6114. if (enterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {enterExitCosts.Ticket.ToString("#0.00")} 元,";
  6115. if (otherFeeStr.Length > 0)
  6116. {
  6117. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  6118. otherFeeStr = $"({otherFeeStr})";
  6119. dic.Add("OtherFeeStr", otherFeeStr);
  6120. }
  6121. foreach (var key in dic.Keys)
  6122. {
  6123. builder.MoveToBookmark(key);
  6124. builder.Write(dic[key]);
  6125. }
  6126. //模板文件名
  6127. string strFileName = $"省级单位出(境)经费报销单.docx";
  6128. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  6129. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  6130. _view.Data = new { Url = url };
  6131. _view.Msg = "成功";
  6132. return _view;
  6133. }
  6134. }
  6135. else if (dto.ExportType == 3)
  6136. {
  6137. if (dto.SubTypeId == 1) //团组成员名单
  6138. {
  6139. if (DeleClientList.Count < 1)
  6140. {
  6141. _view.Msg = "团组成员暂未录入!!!";
  6142. return _view;
  6143. }
  6144. //获取模板
  6145. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  6146. //载入模板
  6147. Document doc = new Document(tempPath);
  6148. DocumentBuilder builder = new DocumentBuilder(doc);
  6149. //获取word里所有表格
  6150. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  6151. //获取所填表格的序数
  6152. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  6153. var rowStart = tableOne.Rows[0]; //获取第1行
  6154. //循环赋值
  6155. for (int i = 0; i < DeleClientList.Count; i++)
  6156. {
  6157. builder.MoveToCell(0, i + 1, 0, 0);
  6158. builder.Write(DeleClientList[i].Name);
  6159. builder.MoveToCell(0, i + 1, 1, 0);
  6160. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  6161. builder.Write(sex);
  6162. builder.MoveToCell(0, i + 1, 2, 0);
  6163. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  6164. builder.MoveToCell(0, i + 1, 3, 0);
  6165. builder.Write(DeleClientList[i].Company);
  6166. builder.MoveToCell(0, i + 1, 4, 0);
  6167. builder.Write(DeleClientList[i].Job);
  6168. }
  6169. //删除多余行
  6170. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  6171. {
  6172. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  6173. }
  6174. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  6175. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  6176. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  6177. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  6178. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  6179. _view.Data = new { Url = url };
  6180. _view.Msg = "成功";
  6181. return _view;
  6182. }
  6183. }
  6184. }
  6185. catch (Exception ex)
  6186. {
  6187. _view.Code = StatusCodes.Status500InternalServerError;
  6188. _view.Msg = ex.Message;
  6189. return _view;
  6190. }
  6191. return _view;
  6192. }
  6193. #endregion
  6194. #region 机票费用提示
  6195. /// <summary>
  6196. /// 三公机票费用提示
  6197. /// </summary>
  6198. /// <param name="diId"></param>
  6199. /// <returns></returns>
  6200. public static async Task<EntryAndExitTipsView[]> EntryAndExitTips(int diId)
  6201. {
  6202. if (diId < 1) return Array.Empty<EntryAndExitTipsView>();
  6203. var airFees = await _sqlSugar.Queryable<Air_TicketBlackCode>().Where(a => a.IsDel == 0 && a.DiId == diId).ToListAsync();
  6204. if (airFees.Any())
  6205. {
  6206. var result = new List<EntryAndExitTipsView>();
  6207. foreach (var x in airFees)
  6208. {
  6209. string tripDesc = "";
  6210. if (!string.IsNullOrEmpty(x.BlackCode))
  6211. {
  6212. var redisKeyName = string.Format("AirTripDesc_{0}_{1}", x.DiId, x.Id);
  6213. tripDesc = await KIMIAirTripCodeRec(redisKeyName, x.BlackCode);
  6214. }
  6215. result.Add(new EntryAndExitTipsView
  6216. {
  6217. jjcCurrentRate = x.ECPrice,
  6218. gwcCurrentRate = x.BCPrice,
  6219. tdcCurrentRate = x.FCPrice,
  6220. remark = $"经济舱全价:{x.ECPrice.ToString("#0.00")} 元/人 公务舱全价:{x.BCPrice.ToString("#0.00")} 元/人 头等舱全价:{x.FCPrice.ToString("#0.00")} 元/人",
  6221. TripDesc = tripDesc
  6222. });
  6223. }
  6224. return result.OrderByDescending(x => x.jjcCurrentRate + x.gwcCurrentRate + x.tdcCurrentRate).ToArray();
  6225. }
  6226. return Array.Empty<EntryAndExitTipsView>();
  6227. }
  6228. /// <summary>
  6229. /// 机票行程代码识别
  6230. /// </summary>
  6231. /// <param name="redisKeyName">redis缓存名称(名称定义格式:AirTripDesc_Diid_Id)</param>
  6232. /// <param name="msg"></param>
  6233. /// <returns></returns>
  6234. public static async Task<string> KIMIAirTripCodeRec(string redisKeyName, string msg)
  6235. {
  6236. string result = string.Empty;
  6237. if (!string.IsNullOrEmpty(redisKeyName))
  6238. {
  6239. result = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(redisKeyName);//string 取
  6240. if (!string.IsNullOrEmpty(result)) return result;
  6241. }
  6242. if (string.IsNullOrEmpty(msg)) return result;
  6243. KiMiApiClient KiMiApi = new KiMiApiClient();
  6244. var kimiMsgs = new List<SeedMessages>() {
  6245. new SeedMessages { Role = KimiRole.system, Content = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。" },
  6246. new SeedMessages { Role = KimiRole.user, Content = "请将提供的三字码行程信息翻译成中文,每条信息独立一行,并在次日到达的时间后加上“+1”以表示次日。日期(星期)格式请按照“04月14日(星期一)”标注。航站楼信息请按照“T1”、“T2”、“ ”等格式标注。只输出正文数据,不要除正文数据外的任何文字以及符号。格式示例如下:\r\n1. CA445 05月17日(星期六) 成都天府 T1 - 米兰马尔彭萨 T1 01:50 06:55" },
  6247. new SeedMessages { Role = KimiRole.user, Content = msg }
  6248. };
  6249. var kimiApiResult = await KiMiApi.SeedMessage(kimiMsgs);
  6250. var kimiApiResult_JObject = JObject.Parse(kimiApiResult);
  6251. result = kimiApiResult_JObject["content"].ToString();
  6252. if (!string.IsNullOrEmpty(result))
  6253. {
  6254. TimeSpan expiry = TimeSpan.FromMinutes(5); // 5分钟
  6255. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(redisKeyName, result, expiry);//string 存
  6256. }
  6257. return result;
  6258. }
  6259. #endregion
  6260. #endregion
  6261. #region Excel导出服务
  6262. #region 类
  6263. public class FileExportSettings
  6264. {
  6265. public string ExportBasePath { get; set; } = "wwwroot/exports";
  6266. public string DownloadBaseUrl { get; set; } = "/exports";
  6267. public int RetentionDays { get; set; } = 7;
  6268. public int MaxFileSizeMB { get; set; } = 50;
  6269. public string ExcelTemplatesPath { get; set; } = "Templates/Excel";
  6270. }
  6271. public class ExportResult
  6272. {
  6273. public bool Success { get; set; }
  6274. public string FilePath { get; set; }
  6275. public string DownloadUrl { get; set; }
  6276. public string FileName { get; set; }
  6277. public long FileSize { get; set; }
  6278. public string MimeType { get; set; } = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  6279. public string ErrorMessage { get; set; }
  6280. public DateTime GeneratedAt { get; set; } = DateTime.Now;
  6281. }
  6282. public class ExportRequest
  6283. {
  6284. public IEnumerable<object> Data { get; set; }
  6285. public string FileName { get; set; }
  6286. public string SheetName { get; set; } = "Sheet1";
  6287. public string TemplateType { get; set; } = "default";
  6288. public Dictionary<string, string> CustomHeaders { get; set; }
  6289. }
  6290. public class ExportResponse
  6291. {
  6292. public string FilePath { get; set; }
  6293. public string DownloadUrl { get; set; }
  6294. public string FileName { get; set; }
  6295. public long FileSize { get; set; }
  6296. public DateTime GeneratedAt { get; set; }
  6297. public string Message { get; set; }
  6298. }
  6299. #endregion
  6300. public static async Task<ExportResult> ExportToExcel<T>(IEnumerable<T> data, string fileName, string sheetName = "Sheet1", string templateType = "default")
  6301. {
  6302. try
  6303. {
  6304. byte[] excelBytes = templateType.ToLower() switch
  6305. {
  6306. "styled" => GenerateStyledExcel(data, sheetName),
  6307. "with_formulas" => GenerateExcelWithFormulas(data, sheetName),
  6308. //"with_charts" => GenerateExcelWithCharts(data, sheetName),
  6309. _ => GenerateDefaultExcel(data, sheetName)
  6310. };
  6311. var filePath = await SaveFileAsync(excelBytes, fileName, "excel");
  6312. var downloadUrl = $"wwwroot/exports/{filePath}";
  6313. return new ExportResult
  6314. {
  6315. Success = true,
  6316. FilePath = filePath,
  6317. DownloadUrl = downloadUrl,
  6318. FileName = Path.GetFileName(filePath),
  6319. FileSize = excelBytes.Length,
  6320. MimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
  6321. };
  6322. }
  6323. catch (Exception ex)
  6324. {
  6325. return new ExportResult
  6326. {
  6327. Success = false,
  6328. ErrorMessage = ex.Message
  6329. };
  6330. }
  6331. }
  6332. private static byte[] GenerateDefaultExcel<T>(IEnumerable<T> data, string sheetName)
  6333. {
  6334. using var workbook = new Aspose.Cells.Workbook();
  6335. var worksheet = workbook.Worksheets[0];
  6336. worksheet.Name = sheetName;
  6337. if (data != null && data.Any())
  6338. {
  6339. FillWorksheetWithData(worksheet, data, 0);
  6340. worksheet.AutoFitColumns();
  6341. }
  6342. return SaveWorkbookToBytes(workbook);
  6343. }
  6344. private static byte[] GenerateStyledExcel<T>(IEnumerable<T> data, string sheetName)
  6345. {
  6346. using var workbook = new Aspose.Cells.Workbook();
  6347. var worksheet = workbook.Worksheets[0];
  6348. worksheet.Name = sheetName;
  6349. if (data != null && data.Any())
  6350. {
  6351. FillWorksheetWithData(worksheet, data, 0);
  6352. // 设置样式
  6353. var headerStyle = workbook.CreateStyle();
  6354. headerStyle.Pattern = BackgroundType.Solid;
  6355. headerStyle.ForegroundColor = System.Drawing.Color.LightGray;
  6356. headerStyle.Font.IsBold = true;
  6357. headerStyle.HorizontalAlignment = TextAlignmentType.Center;
  6358. var properties = typeof(T).GetProperties();
  6359. Aspose.Cells.Range headerRange = worksheet.Cells.CreateRange(0, 0, 1, properties.Length);
  6360. headerRange.ApplyStyle(headerStyle, new StyleFlag { All = true });
  6361. worksheet.AutoFitColumns();
  6362. }
  6363. return SaveWorkbookToBytes(workbook);
  6364. }
  6365. private static byte[] GenerateExcelWithFormulas<T>(IEnumerable<T> data, string sheetName)
  6366. {
  6367. using var workbook = new Aspose.Cells.Workbook();
  6368. var worksheet = workbook.Worksheets[0];
  6369. worksheet.Name = sheetName;
  6370. if (data != null && data.Any())
  6371. {
  6372. FillWorksheetWithData(worksheet, data, 0);
  6373. // 添加公式(例如:求和公式)
  6374. var properties = typeof(T).GetProperties();
  6375. int lastRow = data.Count() + 1;
  6376. for (int i = 0; i < properties.Length; i++)
  6377. {
  6378. if (IsNumericType(properties[i].PropertyType))
  6379. {
  6380. worksheet.Cells[lastRow, i].Formula = $"=SUM({worksheet.Cells[1, i].Name}:{worksheet.Cells[lastRow - 1, i].Name})";
  6381. }
  6382. }
  6383. worksheet.AutoFitColumns();
  6384. }
  6385. return SaveWorkbookToBytes(workbook);
  6386. }
  6387. private static void FillWorksheetWithData<T>(Worksheet worksheet, IEnumerable<T> data, int startRow)
  6388. {
  6389. var properties = typeof(T).GetProperties();
  6390. // 设置表头
  6391. for (int i = 0; i < properties.Length; i++)
  6392. {
  6393. worksheet.Cells[startRow, i].PutValue(properties[i].Name);
  6394. }
  6395. // 填充数据
  6396. int rowIndex = startRow + 1;
  6397. foreach (var item in data)
  6398. {
  6399. for (int colIndex = 0; colIndex < properties.Length; colIndex++)
  6400. {
  6401. var value = properties[colIndex].GetValue(item);
  6402. worksheet.Cells[rowIndex, colIndex].PutValue(value);
  6403. }
  6404. rowIndex++;
  6405. }
  6406. }
  6407. private static int FindDataStartRow(Worksheet worksheet)
  6408. {
  6409. // 在实际项目中,可以根据模板中的特定标记来定位数据起始行
  6410. // 例如查找 "{{DATA_START}}" 这样的标记
  6411. for (int row = 0; row < 50; row++)
  6412. {
  6413. for (int col = 0; col < 10; col++)
  6414. {
  6415. var value = worksheet.Cells[row, col].StringValue;
  6416. if (value == "{{DATA_START}}")
  6417. {
  6418. worksheet.Cells[row, col].PutValue(""); // 清空标记
  6419. return row + 1;
  6420. }
  6421. }
  6422. }
  6423. return 1; // 默认从第2行开始
  6424. }
  6425. private static byte[] SaveWorkbookToBytes(Aspose.Cells.Workbook workbook)
  6426. {
  6427. using var stream = new MemoryStream();
  6428. workbook.Save(stream, Aspose.Cells.SaveFormat.Xlsx);
  6429. return stream.ToArray();
  6430. }
  6431. private static bool IsNumericType(Type type)
  6432. {
  6433. return Type.GetTypeCode(type) switch
  6434. {
  6435. TypeCode.Byte or TypeCode.SByte or TypeCode.UInt16 or TypeCode.UInt32 or
  6436. TypeCode.UInt64 or TypeCode.Int16 or TypeCode.Int32 or TypeCode.Int64 or
  6437. TypeCode.Decimal or TypeCode.Double or TypeCode.Single => true,
  6438. _ => false
  6439. };
  6440. }
  6441. public static async Task<string> SaveFileAsync(byte[] fileData, string fileName, string subFolder = "")
  6442. {
  6443. try
  6444. {
  6445. var basePath = "wwwroot/exports/exports";
  6446. var folderPath = Path.Combine(basePath, subFolder);
  6447. Directory.CreateDirectory(folderPath);
  6448. var uniqueFileName = $"{Path.GetFileNameWithoutExtension(fileName)}_{Guid.NewGuid():N}{Path.GetExtension(fileName)}.xlsx";
  6449. var filePath = Path.Combine(folderPath, uniqueFileName);
  6450. await System.IO.File.WriteAllBytesAsync(filePath, fileData);
  6451. var relativePath = Path.Combine(basePath, subFolder, uniqueFileName).Replace("\\", "/");
  6452. return relativePath;
  6453. }
  6454. catch (Exception ex)
  6455. {
  6456. throw;
  6457. }
  6458. }
  6459. #endregion
  6460. #region 动态构架word表格
  6461. /// <summary>
  6462. /// 设置表格样式
  6463. /// </summary>
  6464. /// <param name="builder"></param>
  6465. public static void SetupDocumentStyles(DocumentBuilder builder)
  6466. {
  6467. builder.Font.Name = "微软雅黑";
  6468. builder.Font.Size = 10;
  6469. builder.ParagraphFormat.SpaceAfter = 0;
  6470. }
  6471. /// <summary>
  6472. /// 添加标题
  6473. /// </summary>
  6474. /// <param name="builder"></param>
  6475. /// <param name="title"></param>
  6476. public static void AddTitle(DocumentBuilder builder, string title)
  6477. {
  6478. // 主标题
  6479. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6480. builder.Font.Size = 16;
  6481. builder.Font.Bold = true;
  6482. builder.Font.Color = System.Drawing.Color.DarkBlue;
  6483. builder.Writeln(title);
  6484. // 空行
  6485. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6486. builder.Font.Size = 10;
  6487. builder.Font.Bold = false;
  6488. builder.Font.Color = System.Drawing.Color.Black;
  6489. builder.Writeln();
  6490. }
  6491. /// <summary>
  6492. /// 生成酒机票表格信息
  6493. /// </summary>
  6494. /// <param name="builder"></param>
  6495. /// <param name="airInfos"></param>
  6496. /// <param name="footerText"></param>
  6497. public static void AddAirInfoSections(DocumentBuilder builder, List<Grp_AirTicketReservations> airInfos, string? footerText)
  6498. {
  6499. if (airInfos == null || !airInfos.Any())
  6500. {
  6501. builder.Writeln("暂无机票航班信息。");
  6502. return;
  6503. }
  6504. int airCount = 0;
  6505. const int maxAirPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
  6506. for (int i = 0; i < airInfos.Count; i++)
  6507. {
  6508. var info = airInfos[i];
  6509. // 检查是否需要分页
  6510. if (airCount > 0 && airCount > maxAirPerPage)
  6511. {
  6512. builder.InsertBreak(BreakType.PageBreak);
  6513. airCount = 0;
  6514. }
  6515. airCount++;
  6516. // 为每个酒店创建详细信息表格
  6517. CreateAirDetailTable(builder, info);
  6518. // 酒店之间添加间距,但不是最后一个
  6519. if (i < airInfos.Count() - 1)
  6520. {
  6521. AddSpacingBetweenHotels(builder);
  6522. }
  6523. // 检查是否达到每页最大酒店数量
  6524. if (airCount >= maxAirPerPage && (i < airInfos.Count - 1 || i < airInfos.Count() - 1))
  6525. {
  6526. builder.InsertBreak(BreakType.PageBreak);
  6527. airCount = 0;
  6528. }
  6529. }
  6530. if (!string.IsNullOrEmpty(footerText))
  6531. {
  6532. AddFooter(builder, footerText);
  6533. }
  6534. }
  6535. /// <summary>
  6536. /// 生成酒店表格信息
  6537. /// </summary>
  6538. /// <param name="builder"></param>
  6539. /// <param name="hotelInfos"></param>
  6540. /// <param name="footerText"></param>
  6541. public static void AddHotelInfoSections(DocumentBuilder builder, List<Grp_HotelReservations> hotelInfos, string? footerText)
  6542. {
  6543. if (hotelInfos == null || !hotelInfos.Any())
  6544. {
  6545. builder.Writeln("暂无酒店信息");
  6546. return;
  6547. }
  6548. int hotelCount = 0;
  6549. const int maxHotelsPerPage = 3; // 每页最多显示3个酒店,确保有足够空间
  6550. for (int i = 0; i < hotelInfos.Count; i++)
  6551. {
  6552. var info = hotelInfos[i];
  6553. // 检查是否需要分页
  6554. if (hotelCount > 0 && hotelCount > maxHotelsPerPage)
  6555. {
  6556. builder.InsertBreak(BreakType.PageBreak);
  6557. hotelCount = 0;
  6558. }
  6559. hotelCount++;
  6560. AddCityHeader(builder, info.City);
  6561. // 为每个酒店创建详细信息表格
  6562. CreateHotelDetailTable(builder, info);
  6563. // 酒店之间添加间距,但不是最后一个
  6564. if (i < hotelInfos.Count() - 1)
  6565. {
  6566. AddSpacingBetweenHotels(builder);
  6567. }
  6568. // 检查是否达到每页最大酒店数量
  6569. if (hotelCount >= maxHotelsPerPage && (i < hotelInfos.Count - 1 || i < hotelInfos.Count() - 1))
  6570. {
  6571. builder.InsertBreak(BreakType.PageBreak);
  6572. hotelCount = 0;
  6573. }
  6574. }
  6575. if (!string.IsNullOrEmpty(footerText))
  6576. {
  6577. AddFooter(builder, footerText);
  6578. }
  6579. }
  6580. private static void AddSpacingBetweenHotels(DocumentBuilder builder)
  6581. {
  6582. builder.Writeln();
  6583. builder.InsertBreak(BreakType.LineBreak);
  6584. }
  6585. private static void AddCityHeader(DocumentBuilder builder, string cityName)
  6586. {
  6587. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6588. builder.Font.Size = 14;
  6589. builder.Font.Bold = true;
  6590. builder.Font.Color = System.Drawing.Color.DarkGreen;
  6591. builder.Writeln($"城市:{cityName}");
  6592. builder.Font.Size = 10;
  6593. builder.Font.Bold = false;
  6594. builder.Font.Color = System.Drawing.Color.Black;
  6595. }
  6596. private static void CreateHotelDetailTable(DocumentBuilder builder, Grp_HotelReservations hotel)
  6597. {
  6598. // 设置表格不允许跨页断行,确保整个表格在一页上
  6599. Table table = builder.StartTable();
  6600. //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
  6601. // 设置表格样式
  6602. ApplyTableStyle(table);
  6603. // 添加酒店基本信息行
  6604. AddTableRow(builder, "酒店名称", hotel.HotelName ?? "-", true);
  6605. AddTableRow(builder, "联系电话", hotel.HotelTel ?? "-");
  6606. AddTableRow(builder, "酒店地址", hotel.HotelAddress ?? "-");
  6607. AddTableRow(builder, "确认号码", hotel.DetermineNo ?? "-");
  6608. AddTableRow(builder, "入住日期", hotel.CheckInDate);
  6609. AddTableRow(builder, "离店日期", hotel.CheckOutDate);
  6610. AddTableRow(builder, "房间信息", hotel.RoomExplanation ?? "-");
  6611. builder.EndTable();
  6612. }
  6613. private static void CreateAirDetailTable(DocumentBuilder builder, Grp_AirTicketReservations air)
  6614. {
  6615. // 设置表格不允许跨页断行,确保整个表格在一页上
  6616. Table table = builder.StartTable();
  6617. //table.AllowBreakAcrossPages = false; // 关键设置:不允许表格跨页
  6618. // 设置表格样式
  6619. ApplyTableStyle(table);
  6620. // 添加酒店基本信息行
  6621. AddTableRow(builder, "城市(A-B)", air.FlightsCity ?? "-", true);
  6622. AddTableRow(builder, "航班日期", air.FlightsDate + " " + air.FlightsTime ?? "-");
  6623. AddTableRow(builder, "机票票号", air.TicketNumber ?? "-");
  6624. AddTableRow(builder, "航班简述", air.FlightsCode ?? "-");
  6625. AddTableRow(builder, "航班描述", air.FlightsDescription);
  6626. builder.EndTable();
  6627. }
  6628. private static void AddTableRow(DocumentBuilder builder, string title, string value, bool isHeaderRow = false)
  6629. {
  6630. // 左边单元格 - 标题
  6631. builder.InsertCell();
  6632. //builder.CellFormat.BackColor = isHeaderRow ? System.Drawing.Color.LightBlue : System.Drawing.Color.LightGray;
  6633. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  6634. builder.CellFormat.Width = 60;
  6635. builder.Font.Bold = true;
  6636. builder.Font.Size = isHeaderRow ? 12 : 10;
  6637. builder.Font.Color = isHeaderRow ? System.Drawing.Color.DarkBlue : System.Drawing.Color.Black;
  6638. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6639. builder.Write(title);
  6640. // 右边单元格 - 值
  6641. builder.InsertCell();
  6642. //builder.CellFormat.BackColor = System.Drawing.Color.White;
  6643. builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
  6644. builder.CellFormat.Width = 200;
  6645. builder.Font.Bold = isHeaderRow;
  6646. builder.Font.Size = isHeaderRow ? 12 : 10;
  6647. builder.Font.Color = System.Drawing.Color.Black;
  6648. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6649. builder.Write(value);
  6650. builder.EndRow();
  6651. // 重置单元格格式(除了宽度)
  6652. //builder.CellFormat.BackColor = System.Drawing.Color.White;
  6653. builder.Font.Bold = false;
  6654. builder.Font.Size = 10;
  6655. builder.Font.Color = System.Drawing.Color.Black;
  6656. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6657. }
  6658. private static void ApplyTableStyle(Table table)
  6659. {
  6660. try
  6661. {
  6662. // 设置表格边框
  6663. table.SetBorders(LineStyle.Single, 1.0, System.Drawing.Color.Gray);
  6664. // 设置表格属性
  6665. table.LeftPadding = 5;
  6666. table.RightPadding = 5;
  6667. table.TopPadding = 3;
  6668. table.BottomPadding = 3;
  6669. table.Alignment = TableAlignment.Left;
  6670. table.AllowAutoFit = false;
  6671. //table.AllowBreakAcrossPages = true;
  6672. // 设置表格宽度
  6673. table.PreferredWidth = PreferredWidth.FromPoints(400);
  6674. // 设置列宽
  6675. if (table.FirstRow != null && table.FirstRow.Cells.Count == 2)
  6676. {
  6677. table.FirstRow.Cells[0].CellFormat.PreferredWidth = PreferredWidth.FromPercent(20);
  6678. table.FirstRow.Cells[1].CellFormat.PreferredWidth = PreferredWidth.FromPercent(80);
  6679. }
  6680. }
  6681. catch (Exception ex)
  6682. {
  6683. //_logger.LogWarning(ex, "设置表格样式时发生错误");
  6684. }
  6685. }
  6686. private static void AddFooter(DocumentBuilder builder, string footerText)
  6687. {
  6688. builder.InsertBreak(BreakType.ParagraphBreak);
  6689. builder.Writeln();
  6690. builder.Writeln();
  6691. // 添加分隔线
  6692. builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
  6693. builder.Font.Size = 8;
  6694. builder.Font.Color = System.Drawing.Color.LightGray;
  6695. //builder.Writeln("────────────────────────────────────");
  6696. builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
  6697. builder.Font.Size = 9;
  6698. builder.Font.Italic = true;
  6699. builder.Font.Color = System.Drawing.Color.Gray;
  6700. builder.Writeln(footerText);
  6701. builder.Writeln($"文档生成时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}");
  6702. builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;
  6703. builder.Font.Size = 10;
  6704. builder.Font.Italic = false;
  6705. builder.Font.Color = System.Drawing.Color.Black;
  6706. }
  6707. #endregion
  6708. #region 动态参数字符串格式化
  6709. /// <summary>
  6710. /// 动态参数字符串格式化
  6711. /// </summary>
  6712. /// <param name="dto">字符串格式化参数DTO</param>
  6713. /// <returns>格式化结果View</returns>
  6714. public static Task<StringFormatView> StringFormatAsync(StringFormatDto dto)
  6715. {
  6716. // 参数验证
  6717. if (string.IsNullOrWhiteSpace(dto?.FormatTemplate))
  6718. {
  6719. return Task.FromResult(new StringFormatView
  6720. {
  6721. Success = false,
  6722. Message = "格式化模板不能为空!"
  6723. });
  6724. }
  6725. if (dto.Parameters == null)
  6726. {
  6727. dto.Parameters = new List<string>();
  6728. }
  6729. try
  6730. {
  6731. // 计算需要的占位符数量
  6732. var placeholderCount = CountPlaceholders(dto.FormatTemplate);
  6733. // 验证参数数量是否匹配
  6734. if (dto.Parameters.Count != placeholderCount)
  6735. {
  6736. return Task.FromResult(new StringFormatView
  6737. {
  6738. Success = false,
  6739. Message = $"参数数量不匹配!模板需要 {placeholderCount} 个参数,但提供了 {dto.Parameters.Count} 个参数。"
  6740. });
  6741. }
  6742. var parameters = dto.Parameters.Cast<object>().ToArray();
  6743. // 格式化字符串
  6744. string formattedResult = string.Format(dto.FormatTemplate, parameters);
  6745. var result = new StringFormatView
  6746. {
  6747. Success = true,
  6748. Message = "操作成功!",
  6749. OriginalTemplate = dto.FormatTemplate,
  6750. FormattedResult = formattedResult,
  6751. Parameters = dto.Parameters,
  6752. ParameterCount = dto.Parameters.Count
  6753. };
  6754. return Task.FromResult(result);
  6755. }
  6756. catch (FormatException ex)
  6757. {
  6758. return Task.FromResult(new StringFormatView
  6759. {
  6760. Success = false,
  6761. Message = $"格式化错误:{ex.Message}"
  6762. });
  6763. }
  6764. catch (Exception ex)
  6765. {
  6766. return Task.FromResult(new StringFormatView
  6767. {
  6768. Success = false,
  6769. Message = $"处理失败:{ex.Message}"
  6770. });
  6771. }
  6772. }
  6773. /// <summary>
  6774. /// 计算模板字符串中的占位符数量
  6775. /// </summary>
  6776. private static int CountPlaceholders(string template)
  6777. {
  6778. if (string.IsNullOrWhiteSpace(template))
  6779. return 0;
  6780. int maxIndex = -1;
  6781. int index = 0;
  6782. while (index < template.Length)
  6783. {
  6784. if (template[index] == '{')
  6785. {
  6786. int endIndex = template.IndexOf('}', index);
  6787. if (endIndex > index)
  6788. {
  6789. string placeholder = template.Substring(index + 1, endIndex - index - 1);
  6790. if (int.TryParse(placeholder, out int placeholderIndex))
  6791. {
  6792. maxIndex = Math.Max(maxIndex, placeholderIndex);
  6793. }
  6794. index = endIndex + 1;
  6795. }
  6796. else
  6797. {
  6798. index++;
  6799. }
  6800. }
  6801. else
  6802. {
  6803. index++;
  6804. }
  6805. }
  6806. return maxIndex + 1; // 返回最大索引+1(因为索引从0开始)
  6807. }
  6808. #endregion
  6809. /// <summary>
  6810. /// AI对话结果中提取JSON
  6811. /// </summary>
  6812. /// <param name="input"></param>
  6813. /// <returns></returns>
  6814. public static string ExtractJson(string input)
  6815. {
  6816. // 1) 优先匹配 Markdown 代码块: ```json ... ``` 或 ``` ... ```
  6817. var m = Regex.Match(
  6818. input,
  6819. @"```(?:json)?\s*([\s\S]*?)\s*```",
  6820. RegexOptions.IgnoreCase);
  6821. if (m.Success)
  6822. return m.Groups[1].Value.Trim();
  6823. // 2) 兜底:从文本中截取第一个 JSON 数组/对象
  6824. int arrStart = input.IndexOf('[');
  6825. int arrEnd = input.LastIndexOf(']');
  6826. if (arrStart >= 0 && arrEnd > arrStart)
  6827. return input.Substring(arrStart, arrEnd - arrStart + 1).Trim();
  6828. int objStart = input.IndexOf('{');
  6829. int objEnd = input.LastIndexOf('}');
  6830. if (objStart >= 0 && objEnd > objStart)
  6831. return input.Substring(objStart, objEnd - objStart + 1).Trim();
  6832. // 3) 实在提取不到,按原文返回,让反序列化抛错
  6833. return input.Trim();
  6834. }
  6835. }
  6836. }