GeneralMethod.cs 321 KB

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