GeneralMethod.cs 318 KB

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