GeneralMethod.cs 317 KB

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