GeneralMethod.cs 309 KB

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