GeneralMethod.cs 339 KB

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