GeneralMethod.cs 348 KB

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