GeneralMethod.cs 351 KB

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