GeneralMethod.cs 351 KB

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