GeneralMethod.cs 187 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249
  1. 
  2. using Aspose.Cells;
  3. using Aspose.Words;
  4. using Aspose.Words.Layout;
  5. using Aspose.Words.Saving;
  6. using Microsoft.AspNetCore.SignalR;
  7. using Microsoft.International.Converters.PinYinConverter;
  8. using Microsoft.VisualBasic;
  9. using NPOI.HSSF.Util;
  10. using OASystem.API.OAMethodLib.File;
  11. using OASystem.API.OAMethodLib.Hub.HubClients;
  12. using OASystem.API.OAMethodLib.Hub.Hubs;
  13. using OASystem.API.OAMethodLib.JuHeAPI;
  14. using OASystem.API.OAMethodLib.SignalR.Hubs;
  15. using OASystem.Domain.Dtos.Groups;
  16. using OASystem.Domain.Entities.Customer;
  17. using OASystem.Domain.Entities.District;
  18. using OASystem.Domain.Entities.Financial;
  19. using OASystem.Domain.Entities.Groups;
  20. using OASystem.Domain.ViewModels.Financial;
  21. using OASystem.Domain.ViewModels.Groups;
  22. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  23. using OASystem.Infrastructure.Repositories.CRM;
  24. using OASystem.Infrastructure.Repositories.Groups;
  25. using System.Data;
  26. using System.IdentityModel.Tokens.Jwt;
  27. using System.IO.Compression;
  28. using System.Security.Claims;
  29. using System.Web;
  30. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  31. namespace OASystem.API.OAMethodLib
  32. {
  33. public static class GeneralMethod
  34. {
  35. //团组信息
  36. private readonly static SqlSugarClient _sqlSugar = AutofacIocManager.Instance.GetService<SqlSugarClient>();
  37. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  38. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  39. private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  40. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  41. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  42. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  43. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  44. private readonly static string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  45. #region 员工注册默认添加基础页面
  46. /// <summary>
  47. /// 默认职位权限
  48. /// </summary>
  49. public static bool DefaultPostAuth(int depId, int postId, int userId, int createUserId)
  50. {
  51. if (depId < 1) return false;
  52. if (postId < 1) return false;
  53. if (userId < 1) return false;
  54. if (userId < 1) return false;
  55. List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
  56. if (_defaultData.Count < 1) return false;
  57. var postJobDatas = _dirRep._sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0).ToList();
  58. List<int> pageData = new List<int>();
  59. //添加公司公共页面
  60. pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
  61. //添加部门页面
  62. var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
  63. var jobPublicPageData = postJobDatas.Find(it => it.DepId == depId && it.Id == postId);
  64. if (depPublicPageData != null) //特殊部门
  65. {
  66. //公共页面
  67. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
  68. if (depId == 7) //国交部特殊处理
  69. {
  70. List<string> postNames = new List<string>() { "主管", "经理" };
  71. //岗位页面
  72. if (jobPublicPageData != null)
  73. {
  74. if (postNames.Contains(jobPublicPageData.JobName))
  75. {
  76. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == 0)?.PageIds ?? new List<int>());
  77. }
  78. else
  79. {
  80. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
  81. }
  82. }
  83. }
  84. }
  85. else //通用部门
  86. {
  87. pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
  88. }
  89. if (pageData.Count > 0)
  90. {
  91. //页面操作权限数据(添加修改等...)
  92. var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0).ToList();
  93. var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority() {
  94. UId = userId,
  95. SmId = it.SmId,
  96. FId = it.FId,
  97. CreateUserId = createUserId, //管理员
  98. CreateTime = DateTime.Now,
  99. IsDel = 0,
  100. IsTemp = 1
  101. }).ToList();
  102. if (defaultPageData.Count > 0)
  103. {
  104. //移除每个页面的审核权限,审核权限需要单独开启
  105. defaultPageData = defaultPageData.Where(it => it.FId != 12).ToList();
  106. //添加页面操作权限
  107. var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
  108. if (s > 0)
  109. {
  110. return true;
  111. }
  112. }
  113. }
  114. return false;
  115. }
  116. #endregion
  117. #region 消息
  118. /// <summary>
  119. /// 消息 发布And 通知
  120. /// </summary>
  121. /// <param name="msgTypeEnum">
  122. /// 消息类型
  123. /// 1 公告通知
  124. /// 2 团组流程管控通知
  125. /// 3 团组业务操作通知
  126. /// 4 团组费用审核消息
  127. /// 5 团组签证进度通知
  128. /// 6 团组任务进度通知
  129. /// </param>
  130. /// <param name="title">消息标题</param>
  131. /// <param name="content">消息内容</param>
  132. /// <param name="userIds"></param>
  133. /// <param name="diId">团组id</param>
  134. /// <param name="param">团组id</param>
  135. /// <returns></returns>
  136. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  137. {
  138. MessageDto messageDto = new()
  139. {
  140. Type = msgTypeEnum,
  141. IssuerId = 4,//管理员
  142. DiId = diId,
  143. Title = title,
  144. Content = content,
  145. ReleaseTime = DateTime.Now,
  146. UIdList = userIds,
  147. Param = param
  148. };
  149. var status = await _messageRep.AddMsg(messageDto);//添加消息
  150. if (status)
  151. {
  152. //给在线在用户发送消息
  153. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  154. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  155. string notificationTypeStr = JsonConvert.SerializeObject(
  156. new
  157. {
  158. UserIds = userIds,
  159. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  160. }
  161. );
  162. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  163. return true;
  164. }
  165. return false;
  166. }
  167. /// <summary>
  168. /// 根据消息类型 获取 消息通知类型
  169. /// </summary>
  170. /// <returns></returns>
  171. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  172. {
  173. int notificationType = 0;
  174. string notificationStr = "";
  175. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  176. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  177. if (notificationType == 1021) notificationStr = "操作";
  178. else if (notificationType == 1020) notificationStr = "任务";
  179. return notificationStr;
  180. }
  181. #endregion
  182. #region md5 加密
  183. /// <summary>
  184. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  185. /// 使用的UTF8编码
  186. /// </summary>
  187. /// <param name="source">待加密字串</param>
  188. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  189. /// <returns>加密后的字串</returns>
  190. public static string Encrypt(string source, int length = 32)
  191. {
  192. if (string.IsNullOrWhiteSpace(source))
  193. return string.Empty;
  194. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  195. byte[] bytes = Encoding.UTF8.GetBytes(source);
  196. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  197. StringBuilder sb = new StringBuilder();
  198. switch (length)
  199. {
  200. case 16://16位密文是32位密文的9到24位字符
  201. for (int i = 4; i < 12; i++)
  202. {
  203. sb.Append(hashValue[i].ToString("x2"));
  204. }
  205. break;
  206. case 32:
  207. for (int i = 0; i < 16; i++)
  208. {
  209. sb.Append(hashValue[i].ToString("x2"));
  210. }
  211. break;
  212. default:
  213. for (int i = 0; i < hashValue.Length; i++)
  214. {
  215. sb.Append(hashValue[i].ToString("x2"));
  216. }
  217. break;
  218. }
  219. return sb.ToString();
  220. }
  221. #endregion
  222. #region jwt
  223. /// <summary>
  224. /// 获取token
  225. /// </summary>
  226. /// <param name="_config"></param>
  227. /// <param name="Number"></param>
  228. /// <param name="exp"></param>
  229. /// <returns></returns>
  230. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  231. {
  232. string userId = Guid.NewGuid().ToString().Replace("-", "");
  233. var claims = new[] {
  234. new Claim(ClaimTypes.NameIdentifier, uName),
  235. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  236. new Claim(ClaimTypes.NameIdentifier, userId),
  237. new Claim("Number",Number)
  238. };
  239. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  240. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  241. var token = new JwtSecurityToken(
  242. issuer: "OASystem.com",
  243. audience: "OASystem.com",
  244. claims: claims,
  245. expires: exp,
  246. signingCredentials: creds);
  247. var indentity = new ClaimsIdentity(claims, "formlogin");
  248. var principal = new ClaimsPrincipal(indentity);
  249. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  250. return new JwtSecurityTokenHandler().WriteToken(token);
  251. }
  252. #endregion
  253. #region 数据类型转换
  254. /// <summary>
  255. /// object 转 Int
  256. /// </summary>
  257. /// <param name="obj"></param>
  258. /// <returns></returns>
  259. public static int GetInt(this object obj)
  260. {
  261. if (obj == null)
  262. return 0;
  263. int _number = 0;
  264. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  265. return _number;
  266. }
  267. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  268. private static long longTime = 621355968000000000;
  269. private static int samllTime = 10000000;
  270. /// <summary>
  271. /// 时间戳 转 datetime
  272. /// </summary>
  273. /// <param name="timeStamp"></param>
  274. /// <returns></returns>
  275. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  276. {
  277. if (timeStamp == null) return dateStart;
  278. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  279. return dateTime;
  280. }
  281. #endregion
  282. #region 用户页面操作功能 权限
  283. /// <summary>
  284. /// 用户页面操作功能(可使用)
  285. /// </summary>
  286. /// <param name="userId">用户Id</param>
  287. /// <param name="PageId">页面Id</param>
  288. /// <returns></returns>
  289. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  290. {
  291. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  292. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  293. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  294. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  295. From Sys_UserAuthority ua
  296. Left Join Sys_Users u On ua.UId = u.Id
  297. Left Join (
  298. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  299. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  300. From Sys_SystemMenuAndFunction smaf
  301. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  302. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  303. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  304. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  305. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  306. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  307. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  308. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  309. if (userPageFuncDatas.Count <= 0)
  310. {
  311. return pageFunAuth;
  312. }
  313. UserPageFuncView userPageFunc = new UserPageFuncView();
  314. //查询 1
  315. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  316. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  317. //删除 2
  318. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  319. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  320. //编辑 3
  321. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  322. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  323. //下载 4
  324. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  325. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  326. //上传 5
  327. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  328. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  329. //添加 11
  330. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  331. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  332. //审核 12
  333. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  334. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  335. return pageFunAuth;
  336. }
  337. #endregion
  338. #region 业务模块 团组权限
  339. /// <summary>
  340. /// 业务模块 团组操作权限
  341. /// 验证 并返回可操作的团
  342. /// </summary>
  343. /// <param name="diId">团组Id</param>
  344. /// <param name="userId">用户Id</param>
  345. /// <param name="CTable">业务模块Id</param>
  346. /// <returns></returns>
  347. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  348. {
  349. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  350. if (CTable < 1)
  351. {
  352. _result.Msg = "请填写正确的用户Id!";
  353. return _result;
  354. }
  355. var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
  356. if (data == null)
  357. {
  358. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  359. }
  360. else
  361. {
  362. _result.Code = 0;
  363. }
  364. return _result;
  365. }
  366. /// <summary>
  367. /// 业务模块 团组操作权限
  368. /// 返回可操作的团
  369. /// </summary>
  370. /// <param name="diId">团组Id</param>
  371. /// <param name="userId">用户Id</param>
  372. /// <param name="CTable">业务模块Id</param>
  373. /// <returns></returns>
  374. public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
  375. {
  376. List<Web_ShareGroupInfoView> _ShareGroupInfoViews = new List<Web_ShareGroupInfoView>();
  377. var taskDatas = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
  378. if (taskDatas.Count < 1) return _ShareGroupInfoViews;
  379. string diIds = string.Join(",", taskDatas.Select(it => it.DIId).ToList());
  380. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  381. From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
  382. _ShareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  383. return _ShareGroupInfoViews;
  384. }
  385. #endregion
  386. #region 团组相关
  387. #region 建团按国家默认添加汇率 / 默认权限分配
  388. /// <summary>
  389. /// 团组汇率
  390. /// 建团时 添加基础汇率 CNY
  391. /// 按国家 添加 默认币种
  392. /// </summary>
  393. /// <param name="userId"></param>
  394. /// <param name="diId"></param>
  395. /// <returns></returns>
  396. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  397. {
  398. Result result = new() { Code = -2 };
  399. if (userId < 1)
  400. {
  401. result.Msg = string.Format(@"请传入正确的userId");
  402. return result;
  403. }
  404. if (diId < 1)
  405. {
  406. result.Msg = string.Format(@"请传入正确的DiId");
  407. return result;
  408. }
  409. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  410. string rateInit = string.Format(@"人民币(CNY):1.0000");
  411. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  412. //if (gropInfo == null)
  413. //{
  414. // result.Msg = $@"未查询到团组信息!";
  415. // return result;
  416. //}
  417. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  418. if (juheRateData.Error_code != 0)
  419. {
  420. result.Msg = juheRateData.Reason;
  421. return result;
  422. }
  423. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  424. if (exchangeRateModels.Count <= 0)
  425. {
  426. result.Msg = $@"未查询到聚合接口汇率信息!";
  427. return result;
  428. }
  429. if (exchangeRateModels.Count > 0)
  430. {
  431. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  432. for (int i = 0; i < exchangeRateModels.Count; i++)
  433. {
  434. string currencyName = exchangeRateModels[i].Name;
  435. string code = "";
  436. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  437. if (currencyData != null)
  438. {
  439. code = currencyData.Name;
  440. decimal currRate = 0.00M;
  441. string MSellPri = exchangeRateModels[i].MSellPri;
  442. if (!string.IsNullOrEmpty(MSellPri))
  443. {
  444. currRate = Convert.ToDecimal(MSellPri) / 100M;
  445. }
  446. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  447. }
  448. }
  449. }
  450. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  451. if (cTableIds.Count < 1)
  452. {
  453. result.Msg = $@"未查询到操作模块信息!";
  454. return result;
  455. }
  456. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  457. foreach (var item in cTableIds)
  458. {
  459. grp_TeamRates.Add(
  460. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  461. );
  462. }
  463. if (grp_TeamRates.Count > 0)
  464. {
  465. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  466. if (addId < 1)
  467. {
  468. result.Msg = string.Format(@"添加失败!");
  469. return result;
  470. }
  471. }
  472. result.Code = 0;
  473. result.Msg = string.Format(@"操作成功!");
  474. return result;
  475. }
  476. /// <summary>
  477. /// 团组任务分配
  478. /// 建团时 默认按照岗位分配权限
  479. /// </summary>
  480. /// <param name="userId"></param>
  481. /// <param name="diId"></param>
  482. /// <param name="companyId"></param>
  483. /// <returns></returns>
  484. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  485. {
  486. Result result = new() { Code = -2 };
  487. if (userId < 0)
  488. {
  489. result.Msg = string.Format(@"请传入正确的userId");
  490. return result;
  491. }
  492. if (companyId < 0)
  493. {
  494. result.Msg = string.Format(@"请传入正确的companyId");
  495. return result;
  496. }
  497. if (diId < 0)
  498. {
  499. result.Msg = string.Format(@"请传入正确的DiId");
  500. return result;
  501. }
  502. var userDatas = await _teamRateRep._sqlSugar
  503. .Queryable<Sys_Users>()
  504. .LeftJoin<Sys_Department>((su, sd) => su.DepId == sd.Id && sd.IsDel == 0)
  505. .LeftJoin<Sys_JobPost>((su, sd, sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  506. .Where(su => su.IsDel == 0)
  507. .Select((su, sd, sjp) => new {
  508. su.DepId,
  509. sd.DepName,
  510. su.JobPostId,
  511. sjp.JobName,
  512. su.Id,
  513. su.CnName
  514. })
  515. .ToListAsync();
  516. /*
  517. * 76 酒店预订 --> 国交部门 酒店 岗位
  518. * 77 行程 --> 国交部门 经理,主管 岗位
  519. * 79 车/导游地接 --> 国交部门 OP 岗位
  520. * 80 签证 --> 国交部门 签证 岗位
  521. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  522. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  523. * 85 机票预订 --> 国交部门 机票 岗位
  524. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  525. * 1015 超支费用,69 收款退还 --> 财务部门(ALL)岗位
  526. * 1015 超支费用 --> 国交部(ALL)岗位
  527. */
  528. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  529. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  530. _GroupsTaskAssignments.AddRange(
  531. userDatas
  532. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  533. .Select(it => new Grp_GroupsTaskAssignment()
  534. {
  535. DIId = diId,
  536. CTId = 76,
  537. UId = it.Id,
  538. CreateUserId = userId
  539. }).ToList()
  540. );
  541. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  542. _GroupsTaskAssignments.AddRange(
  543. userDatas
  544. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  545. .Select(it => new Grp_GroupsTaskAssignment()
  546. {
  547. DIId = diId,
  548. CTId = 77,
  549. UId = it.Id,
  550. CreateUserId = userId
  551. }).ToList()
  552. );
  553. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  554. _GroupsTaskAssignments.AddRange(
  555. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  556. .Select(it => new Grp_GroupsTaskAssignment()
  557. {
  558. DIId = diId,
  559. CTId = 79,
  560. UId = it.Id,
  561. CreateUserId = userId
  562. }).ToList()
  563. );
  564. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  565. _GroupsTaskAssignments.AddRange(
  566. userDatas
  567. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  568. .Select(it => new Grp_GroupsTaskAssignment()
  569. {
  570. DIId = diId,
  571. CTId = 81,
  572. UId = it.Id,
  573. CreateUserId = userId
  574. }).ToList()
  575. );
  576. //80 签证 --> 国交部门(7) 签证(26) 岗位
  577. _GroupsTaskAssignments.AddRange(
  578. userDatas
  579. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  580. .Select(it => new Grp_GroupsTaskAssignment()
  581. {
  582. DIId = diId,
  583. CTId = 80,
  584. UId = it.Id,
  585. CreateUserId = userId
  586. }).ToList()
  587. );
  588. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  589. //2024-06-25 默认将保险权限分配给签证岗。 签证(26) 岗位
  590. List<int> insurancePositions = new List<int>() { 32, 22, 26 };
  591. _GroupsTaskAssignments.AddRange(
  592. userDatas
  593. .Where(it => it.DepId == 7 && insurancePositions.Contains(it.JobPostId))
  594. .Select(it => new Grp_GroupsTaskAssignment()
  595. {
  596. DIId = diId,
  597. CTId = 82,
  598. UId = it.Id,
  599. CreateUserId = userId
  600. }).ToList()
  601. );
  602. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  603. _GroupsTaskAssignments.AddRange(
  604. userDatas
  605. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  606. .Select(it => new Grp_GroupsTaskAssignment()
  607. {
  608. DIId = diId,
  609. CTId = 85,
  610. UId = it.Id,
  611. CreateUserId = userId
  612. }).ToList()
  613. );
  614. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  615. List<int> depIds = new List<int>() { 7, 3, 5 };
  616. List<int> jobIds = new List<int>() { 1, 74 };
  617. _GroupsTaskAssignments.AddRange(
  618. userDatas
  619. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  620. .Select(it => new Grp_GroupsTaskAssignment()
  621. {
  622. DIId = diId,
  623. CTId = 98,
  624. UId = it.Id,
  625. CreateUserId = userId
  626. }).ToList()
  627. );
  628. //1015 超支费用,285 收款退还 --> 财务部门(ALL)岗位
  629. _GroupsTaskAssignments.AddRange(
  630. userDatas
  631. .Where(it => it.DepId == 3)
  632. .Select(it => new Grp_GroupsTaskAssignment()
  633. {
  634. DIId = diId,
  635. CTId = 1015,
  636. UId = it.Id,
  637. CreateUserId = userId
  638. }).ToList()
  639. );
  640. _GroupsTaskAssignments.AddRange(
  641. userDatas
  642. .Where(it => it.DepId == 3)
  643. .Select(it => new Grp_GroupsTaskAssignment()
  644. {
  645. DIId = diId,
  646. CTId = 285,
  647. UId = it.Id,
  648. CreateUserId = userId
  649. }).ToList()
  650. );
  651. //1015 超支费用 --> 国交部(ALL)岗位
  652. _GroupsTaskAssignments.AddRange(
  653. userDatas
  654. .Where(it => it.DepId == 7)
  655. .Select(it => new Grp_GroupsTaskAssignment()
  656. {
  657. DIId = diId,
  658. CTId = 1015,
  659. UId = it.Id,
  660. CreateUserId = userId
  661. }).ToList()
  662. );
  663. if (_GroupsTaskAssignments.Count > 0)
  664. {
  665. var addId = _teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  666. }
  667. result.Code = 0;
  668. result.Msg = string.Format(@"操作成功!");
  669. return result;
  670. }
  671. #endregion
  672. #region 员工是否是市场部人员
  673. /// <summary>
  674. /// 验证市场部客户人员
  675. /// </summary>
  676. /// <param name="userId"></param>
  677. /// <returns></returns>
  678. public static async Task<bool> IsMarketingStaff(int userId)
  679. {
  680. var userInfos = await _dirRep._sqlSugar
  681. .Queryable<Sys_Users>()
  682. .InnerJoin<Sys_Department>((u,d) => u.DepId == d.Id)
  683. .Where((u,d) => u.IsDel == 0 && u.Id == userId && d.DepName.Contains("市场部"))
  684. .ToListAsync();
  685. if (userInfos.Count > 0) return true;
  686. return false;
  687. }
  688. #endregion
  689. #endregion
  690. #region 团组汇率
  691. /// <summary>
  692. /// 团组汇率
  693. /// 获取板块 币种 及 汇率
  694. /// 76 酒店预订 77 行程 79 车/导游地接
  695. /// 80 签证 82 团组客户保险 85 机票预订
  696. /// 98 其他款项 285 收款退还
  697. /// </summary>
  698. /// <param name="teamRateModels"></param>
  699. /// <param name="cTable"></param>
  700. /// <param name="currencyCode"></param>
  701. /// <returns>
  702. /// string
  703. /// eg: CNY 1.0000
  704. /// </returns>
  705. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  706. {
  707. string str = "";
  708. List<string> currencyRates = new List<string>();
  709. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  710. if (hotelRateData != null)
  711. {
  712. var hotelRates = hotelRateData.TeamRates;
  713. foreach (var item in currencyCodes)
  714. {
  715. if (!string.IsNullOrEmpty(item))
  716. {
  717. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  718. if (hotelRateInfo != null)
  719. {
  720. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  721. currencyRates.Add(str1);
  722. }
  723. }
  724. }
  725. if (currencyRates != null || currencyRates.Count > 0)
  726. {
  727. currencyRates = currencyRates.Distinct().ToList();
  728. foreach (var item in currencyRates)
  729. {
  730. str += item;
  731. }
  732. }
  733. }
  734. return str;
  735. }
  736. /// <summary>
  737. /// 团组汇率 币种 Item (来源:团组汇率)
  738. /// 根据 团组Id And 业务类型(CTable)Id
  739. /// api处理CTable = 285,默认返回CNY
  740. /// </summary>
  741. /// <param name="portType"></param>
  742. /// <param name="diId"></param>
  743. /// <param name="cTable"></param>
  744. /// <returns></returns>
  745. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  746. {
  747. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  748. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  749. return _view;
  750. }
  751. /// <summary>
  752. /// 汇率备注拆分
  753. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  754. /// </summary>
  755. /// <param name="rateRemark"></param>
  756. /// <returns></returns>
  757. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  758. {
  759. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  760. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  761. #region 获取所有币种
  762. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  763. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  764. if (DBdata == null || DBdata.Count == 0)
  765. {
  766. return _view;
  767. }
  768. currencyDatas = DBdata.Select(x => new SetDataInfoView
  769. {
  770. Name = x.Name,
  771. Id = x.Id,
  772. Remark = x.Remark,
  773. }).ToList();
  774. #endregion
  775. #region 拆分remark里的汇率
  776. if (string.IsNullOrEmpty(rateRemark))
  777. {
  778. return _view;
  779. }
  780. if (rateRemark.Contains("|"))
  781. {
  782. string[] currencyArr = rateRemark.Split("|");
  783. foreach (string currency in currencyArr)
  784. {
  785. string[] currency1 = currency.Split(":");
  786. string[] currency2 = currency1[0].Split("(");
  787. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  788. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  789. {
  790. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  791. CurrencyCode = currencyCode,
  792. CurrencyName = currency2[0],
  793. Rate = decimal.Parse(currency1[1]),
  794. };
  795. _view.Add(rateDescView);
  796. }
  797. }
  798. else
  799. {
  800. try
  801. {
  802. string[] currency1 = rateRemark.Split(":");
  803. string[] currency2 = currency1[0].Split("(");
  804. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  805. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  806. {
  807. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  808. CurrencyCode = currencyCode,
  809. CurrencyName = currency2[0],
  810. Rate = decimal.Parse(currency1[1]),
  811. };
  812. _view.Add(rateDescView);
  813. }
  814. catch (Exception)
  815. {
  816. return _view;
  817. }
  818. }
  819. #endregion
  820. return _view;
  821. }
  822. #endregion
  823. #region 汉字转换拼音
  824. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  825. {
  826. var chs = text.ToCharArray();
  827. //记录每个汉字的全拼
  828. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  829. for (int i = 0; i < chs.Length; i++)
  830. {
  831. var pinyinList = new List<string>();
  832. //是否是有效的汉字
  833. if (ChineseChar.IsValidChar(chs[i]))
  834. {
  835. ChineseChar cc = new ChineseChar(chs[i]);
  836. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  837. }
  838. else
  839. {
  840. pinyinList.Add(chs[i].ToString());
  841. }
  842. //去除声调,转小写
  843. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  844. //去重
  845. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  846. if (pinyinList.Any())
  847. {
  848. totalPingYinList[i] = pinyinList;
  849. }
  850. }
  851. return totalPingYinList;
  852. }
  853. /// <summary>
  854. /// 获取汉语拼音全拼
  855. /// </summary>
  856. /// <param name="text">The string.</param>
  857. /// <returns></returns>
  858. public static List<string> GetTotalPingYin(this string text)
  859. {
  860. var result = new List<string>();
  861. foreach (var pys in GetTotalPingYinDictionary(text))
  862. {
  863. var items = pys.Value;
  864. if (result.Count <= 0)
  865. {
  866. result = items;
  867. }
  868. else
  869. {
  870. //全拼循环匹配
  871. var newTotalPingYinList = new List<string>();
  872. foreach (var totalPingYin in result)
  873. {
  874. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  875. }
  876. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  877. result = newTotalPingYinList;
  878. }
  879. }
  880. return result;
  881. }
  882. /// <summary>
  883. /// 获取中文第一个拼音
  884. /// </summary>
  885. /// <param name="text"></param>
  886. /// <param name="isUp"></param>
  887. /// <returns></returns>
  888. public static string GetTotalPingYinFirst(this string text , bool isUp = true)
  889. {
  890. var returnstr = string.Empty;
  891. var enResult = text.GetTotalPingYin();
  892. if(enResult.Count == 0)
  893. {
  894. returnstr = text;
  895. }
  896. else if (isUp)
  897. {
  898. returnstr = enResult[0].ToUpper();
  899. }
  900. else
  901. {
  902. returnstr = enResult[0].ToLower();
  903. }
  904. return returnstr;
  905. }
  906. /// <summary>
  907. /// 获取汉语拼音首字母
  908. /// </summary>
  909. /// <param name="text"></param>
  910. /// <returns></returns>
  911. public static List<string> GetFirstPingYin(this string text)
  912. {
  913. var result = new List<string>();
  914. foreach (var pys in GetTotalPingYinDictionary(text))
  915. {
  916. var items = pys.Value;
  917. if (result.Count <= 0)
  918. {
  919. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  920. }
  921. else
  922. {
  923. //首字母循环匹配
  924. var newFirstPingYinList = new List<string>();
  925. foreach (var firstPingYin in result)
  926. {
  927. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  928. }
  929. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  930. result = newFirstPingYinList;
  931. }
  932. }
  933. return result;
  934. }
  935. #endregion
  936. #region 新客户资料表 操作记录
  937. /// <summary>
  938. /// 新客户资料表
  939. /// 操作记录添加
  940. /// </summary>
  941. /// <param name="portType"></param>
  942. /// <param name="operationEnum"></param>
  943. /// <param name="userId"></param>
  944. /// <param name="dataId"></param>
  945. /// <param name="remark"></param>
  946. /// <returns></returns>
  947. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  948. {
  949. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  950. {
  951. TableName = "Crm_NewClientData",
  952. PortType = portType,
  953. OperationItem = operationEnum,
  954. DataId = dataId,
  955. CreateUserId = userId,
  956. CreateTime = DateTime.Now,
  957. Remark = remark
  958. };
  959. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  960. if (add) return false;
  961. return false;
  962. }
  963. #endregion
  964. #region 金额转大写
  965. /// <summary>
  966. /// 金额转换为大写数字
  967. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  968. /// <para>2、小数点后最多支持两位</para>
  969. /// </summary>
  970. /// <param name="num">数值</param>
  971. /// <returns></returns>
  972. public static string ConvertCNYUpper(this decimal num)
  973. {
  974. if (num == 0)
  975. {
  976. return "零元";
  977. }
  978. // 解决327000000转换后缺少单位万的问题
  979. return ConvertToChinese(num);
  980. }
  981. #region 实例
  982. /// <summary>
  983. /// 要转换的数字
  984. /// </summary>
  985. private static decimal j;
  986. /// <summary>
  987. ///
  988. /// </summary>
  989. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  990. /// <summary>
  991. /// 判断输入的数字是否大于double类型
  992. /// </summary>
  993. private static bool IsNumber
  994. {
  995. get
  996. {
  997. if (j > decimal.MaxValue || j <= 0)
  998. return false;
  999. else
  1000. return true;
  1001. }
  1002. }
  1003. /// <summary>
  1004. /// 数字转换成大写汉字主函数
  1005. /// </summary>
  1006. /// <returns>返回转换后的大写汉字</returns>
  1007. public static string ConvertToChinese(decimal m)
  1008. {
  1009. j = m;
  1010. string bb = "";
  1011. if (IsNumber)
  1012. {
  1013. string str = j.ToString();
  1014. string[] Num = str.Split('.');
  1015. if (Num.Length == 1)
  1016. {
  1017. bb = NumberString(Num[0]) + "元整";
  1018. bb = bb.Replace("零零", "零");
  1019. }
  1020. else
  1021. {
  1022. bb = NumberString(Num[0]) + "元";
  1023. bb += FloatString(Num[1]);
  1024. bb = bb.Replace("零零", "零");
  1025. }
  1026. }
  1027. else
  1028. {
  1029. throw new FormatException("你输入的数字格式不正确或不是数字!");
  1030. }
  1031. return bb;
  1032. }
  1033. /// <summary>
  1034. /// 小数位转换只支持两位的小数
  1035. /// </summary>
  1036. /// <param name="Num">转换的小数</param>
  1037. /// <returns>小数转换成汉字</returns>
  1038. private static string FloatString(string Num)
  1039. {
  1040. string cc = "";
  1041. if (Num.Length > 2)
  1042. {
  1043. throw new FormatException("小数位数过多.");
  1044. }
  1045. else
  1046. {
  1047. string bb = ConvertString(Num);
  1048. int len = bb.IndexOf("零");
  1049. if (len != 0)
  1050. {
  1051. bb = bb.Replace("零", "");
  1052. if (bb.Length == 1)
  1053. {
  1054. cc = bb.Substring(0, 1) + "角";
  1055. }
  1056. else
  1057. {
  1058. cc = bb.Substring(0, 1) + "角";
  1059. cc += bb.Substring(1, 1) + "分";
  1060. }
  1061. }
  1062. else
  1063. cc = bb + "分";
  1064. }
  1065. return cc;
  1066. }
  1067. /// <summary>
  1068. /// 判断数字位数以进行拆分转换
  1069. /// </summary>
  1070. /// <param name="Num">要进行拆分的数字</param>
  1071. /// <returns>转换成的汉字</returns>
  1072. private static string NumberString(string Num)
  1073. {
  1074. string bb = "";
  1075. if (Num.Length <= 4)
  1076. {
  1077. bb = Convert4(Num);
  1078. }
  1079. else if (Num.Length > 4 && Num.Length <= 8)
  1080. {
  1081. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  1082. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1083. }
  1084. else if (Num.Length > 8 && Num.Length <= 12)
  1085. {
  1086. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  1087. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  1088. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  1089. bb += "零";
  1090. else
  1091. bb += "";
  1092. else
  1093. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  1094. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1095. }
  1096. else
  1097. {
  1098. throw new Exception("整数部分最多支持12位");
  1099. }
  1100. return bb;
  1101. }
  1102. /// <summary>
  1103. /// 四位数字的转换
  1104. /// </summary>
  1105. /// <param name="Num">准备转换的四位数字</param>
  1106. /// <returns>转换以后的汉字</returns>
  1107. private static string Convert4(string Num)
  1108. {
  1109. string bb = "";
  1110. if (Num.Length == 1)
  1111. {
  1112. bb = ConvertString(Num);
  1113. }
  1114. else if (Num.Length == 2)
  1115. {
  1116. bb = ConvertString(Num);
  1117. bb = Convert2(bb);
  1118. }
  1119. else if (Num.Length == 3)
  1120. {
  1121. bb = ConvertString(Num);
  1122. bb = Convert3(bb);
  1123. }
  1124. else
  1125. {
  1126. bb = ConvertString(Num);
  1127. string cc = "";
  1128. string len = bb.Substring(0, 4);
  1129. if (len != "零零零零")
  1130. {
  1131. len = bb.Substring(0, 3);
  1132. if (len != "零零零")
  1133. {
  1134. bb = bb.Replace("零零零", "");
  1135. if (bb.Length == 1)
  1136. {
  1137. bb = bb.Substring(0, 1) + "仟";
  1138. }
  1139. else
  1140. {
  1141. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  1142. cc = bb.Substring(0, 1) + "仟";
  1143. else
  1144. cc = bb.Substring(0, 1);
  1145. bb = cc + Convert3(bb.Substring(1, 3));
  1146. }
  1147. }
  1148. else
  1149. {
  1150. bb = bb.Replace("零零零", "零");
  1151. }
  1152. }
  1153. else
  1154. {
  1155. bb = bb.Replace("零零零零", "");
  1156. }
  1157. }
  1158. return bb;
  1159. }
  1160. /// <summary>
  1161. /// 将数字转换成汉字
  1162. /// </summary>
  1163. /// <param name="Num">需要转换的数字</param>
  1164. /// <returns>转换后的汉字</returns>
  1165. private static string ConvertString(string Num)
  1166. {
  1167. string bb = "";
  1168. for (int i = 0; i < Num.Length; i++)
  1169. {
  1170. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1171. }
  1172. return bb;
  1173. }
  1174. /// <summary>
  1175. /// 两位数字的转换
  1176. /// </summary>
  1177. /// <param name="Num">两位数字</param>
  1178. /// <returns>转换后的汉字</returns>
  1179. private static string Convert2(string Num)
  1180. {
  1181. string bb = ""; string cc = "";
  1182. string len = Num.Substring(0, 1);
  1183. if (len != "零")
  1184. {
  1185. bb = Num.Replace("零", "");
  1186. if (bb.Length == 1)
  1187. {
  1188. cc = bb.Substring(0, 1) + "拾";
  1189. }
  1190. else
  1191. {
  1192. cc = bb.Substring(0, 1) + "拾";
  1193. cc += bb.Substring(1, 1);
  1194. }
  1195. }
  1196. else
  1197. cc = Num;
  1198. return cc;
  1199. }
  1200. /// <summary>
  1201. /// 三位数字的转换
  1202. /// </summary>
  1203. /// <param name="Num">三位数字</param>
  1204. /// <returns>转换后的汉字</returns>
  1205. private static string Convert3(string Num)
  1206. {
  1207. string bb = ""; string cc = "";
  1208. string len = Num.Substring(0, 2);
  1209. if (len != "零零")
  1210. {
  1211. bb = Num.Replace("零零", "");
  1212. if (bb.Length == 1)
  1213. {
  1214. bb = bb.Substring(0, 1) + "佰";
  1215. }
  1216. else
  1217. {
  1218. if (bb.Substring(0, 1) != "零")
  1219. cc = bb.Substring(0, 1) + "佰";
  1220. else
  1221. cc = bb.Substring(0, 1);
  1222. bb = cc + Convert2(bb.Substring(1, 2));
  1223. }
  1224. }
  1225. else
  1226. {
  1227. bb = Num.Replace("零零", "零");
  1228. }
  1229. return bb;
  1230. }
  1231. #endregion
  1232. #endregion
  1233. #region 数字验证
  1234. /// <summary>
  1235. /// 验证数字字符串
  1236. /// </summary>
  1237. /// <param name="num"></param>
  1238. /// <returns></returns>
  1239. public static bool IsNumeric(this string numStr)
  1240. {
  1241. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  1242. if (isNumeric)
  1243. {
  1244. return true;
  1245. }
  1246. return false;
  1247. }
  1248. #endregion
  1249. #region 日期 格式转换
  1250. /// <summary>
  1251. /// 验证数字字符串
  1252. /// </summary>
  1253. /// <param name="str"></param>
  1254. /// <returns></returns>
  1255. public static string ConvertToDatetime(this string str)
  1256. {
  1257. if (!string.IsNullOrEmpty(str))
  1258. {
  1259. DateTime currentDate = Convert.ToDateTime(str);
  1260. return $"{currentDate.Year}年{currentDate.Month}月{currentDate.Day}日";
  1261. }
  1262. return "";
  1263. }
  1264. #endregion
  1265. #region 月份/季度
  1266. /// <summary>
  1267. /// 获取月份对应的起始天数
  1268. /// </summary>
  1269. /// <param name="year"></param>
  1270. /// <returns></returns>
  1271. public static List<MonthInfo> GetMonthInfos(int year)
  1272. {
  1273. List<MonthInfo> months = new List<MonthInfo>();
  1274. if (year > 1)
  1275. {
  1276. for (int i = 1; i < 13; i++)
  1277. {
  1278. months.Add(new MonthInfo()
  1279. {
  1280. Month = i,
  1281. Days = new DaysInfo() { BeginDays = 1, EndDays = DateTime.DaysInMonth(year, i) }
  1282. });
  1283. }
  1284. }
  1285. return months;
  1286. }
  1287. /// <summary>
  1288. /// 获取季度对应的起始天数
  1289. /// </summary>
  1290. /// <param name="year"></param>
  1291. /// <returns></returns>
  1292. public static List<MonthInfo> GetQuarter(int year)
  1293. {
  1294. List<MonthInfo> months = new List<MonthInfo>();
  1295. months.Add(new MonthInfo() { Month = 1, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //1.1 - 3.31
  1296. months.Add(new MonthInfo() { Month = 2, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //4.1 - 6.30
  1297. months.Add(new MonthInfo() { Month = 3, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //7.1 - 9.31
  1298. months.Add(new MonthInfo() { Month = 4, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //10.1 - 12.31
  1299. return months;
  1300. }
  1301. public class MonthInfo
  1302. {
  1303. public int Month { get; set; }
  1304. public DaysInfo Days { get; set; }
  1305. }
  1306. public class DaysInfo
  1307. {
  1308. public int BeginDays { get; set; }
  1309. public int EndDays { get; set; }
  1310. }
  1311. #endregion
  1312. #region op行程单,黑屏幕代码
  1313. public static string GetCountryStandingTime(int diId)
  1314. {
  1315. DataTable datas = GetTableByBlackCode(diId);
  1316. string countryStr = "[黑屏代码未录入].";
  1317. if (datas.Rows.Count > 0)
  1318. {
  1319. var airDatas = from row in datas.AsEnumerable()
  1320. select new
  1321. {
  1322. Three = row.Field<string>("Three"),
  1323. Day = row.Field<string>("Day"),
  1324. ArrivedDate = row.Field<string>("ArrivedDate"),
  1325. };
  1326. //三字码信息
  1327. List<Res_ThreeCode> listcode = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToList();
  1328. //string countryStr = "";
  1329. int index = 0;
  1330. List<string> cityCodes = new List<string>();
  1331. //去掉开始和结束城市
  1332. foreach (var row in airDatas)
  1333. {
  1334. if (!string.IsNullOrEmpty(row.Three))
  1335. {
  1336. if (index == 0) cityCodes.Add(row.Three.Substring(3, 3)); //到达国家
  1337. else if (airDatas.Count() - 1 == index) cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1338. else cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1339. }
  1340. index++;
  1341. }
  1342. cityCodes = cityCodes.Distinct().ToList();
  1343. if (cityCodes.Count > 0) countryStr = "";
  1344. foreach (var item in cityCodes)
  1345. {
  1346. var airData = airDatas.Where(it => it.Three.Contains(item)).ToList();
  1347. string country = listcode.Find(it => it.Three.Equals(item))?.Country ?? "Unknown";
  1348. if (country.Equals("中国"))
  1349. {
  1350. country = listcode.Find(it => it.Three.Equals(item))?.City ?? "Unknown";
  1351. }
  1352. int days = 0;
  1353. if (airData.Count == 2)
  1354. {
  1355. DateTime arr_dt = Convert.ToDateTime(airData[0].ArrivedDate); //抵达时间
  1356. DateTime dep_dt = Convert.ToDateTime(airData[1].Day); //离开时间
  1357. days = (dep_dt - arr_dt).Days;
  1358. //countryStr += $@"{country}停留{days}日、";
  1359. countryStr += $@"{country}停留 日、";
  1360. }
  1361. }
  1362. if (countryStr.Length > 0) countryStr = countryStr.Substring(0, countryStr.Length - 1);
  1363. }
  1364. return countryStr;
  1365. }
  1366. /// <summary>
  1367. ///根据机票黑屏代码整理DataTable
  1368. /// </summary>
  1369. /// <param name="diid"></param>
  1370. /// <returns></returns>
  1371. public static DataTable GetTableByBlackCode1(int diid)
  1372. {
  1373. //黑屏代码信息
  1374. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  1375. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  1376. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  1377. DataTable dt = new DataTable();
  1378. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1379. dt.Columns.Add("Date", typeof(string));//起飞日期
  1380. dt.Columns.Add("Three", typeof(string));//三字码
  1381. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1382. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1383. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1384. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1385. dt.Columns.Add("AirModel", typeof(string)); //机型
  1386. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1387. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1388. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1389. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1390. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1391. //判断是否录入黑屏代码
  1392. if (listcode.Count() == 0 || listcode == null)
  1393. {
  1394. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null);
  1395. }
  1396. else
  1397. {
  1398. //读取单段黑屏代码
  1399. for (int i = 0; i < listcode.Count; i++)
  1400. {
  1401. //去除序号
  1402. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  1403. //去除多余空格,方法一Linq扩展方法
  1404. CodeList = CodeList.Where(str => str != "").ToArray();
  1405. CodeList = CodeList.Where(str => str != " ").ToArray();
  1406. //年
  1407. int year = Convert.ToInt32(DateTime.Now.Year.ToString());
  1408. //读取单条黑屏代码
  1409. for (int j = 0; j < CodeList.Count(); j++)
  1410. {
  1411. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  1412. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  1413. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1414. //string[] Info = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1415. // .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1416. //去除多余空格
  1417. Info = Info.Where(str => str != "").ToArray();
  1418. Info = Info.Where(str => str != " ").ToArray();
  1419. //判断黑屏代码是否正确拆分; 理应拆成9段
  1420. if (Info.Count() < 9)
  1421. {
  1422. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null);
  1423. }
  1424. else
  1425. {
  1426. try
  1427. {
  1428. //月
  1429. int month = Convert.ToInt32(GetLonger(Info[1].Substring(4, 3)));
  1430. //日
  1431. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  1432. #region 逐一比较月份,判断是否翻年;逐一比较三字码顶真,判断是否跑错机场
  1433. if (j > 0)
  1434. {
  1435. string[] Temp = CodeList[j - 1].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1436. .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1437. Temp = Temp.Where(str => str != "").ToArray();
  1438. Temp = Temp.Where(str => str != " ").ToArray();
  1439. int monthTemp = Convert.ToInt32(GetLonger(Temp[1].Substring(4, 3)));
  1440. // 如果相邻月份之差小于0,则证明次一条年份需+1
  1441. if (month - monthTemp < 0)
  1442. {
  1443. year = year + 1;
  1444. }
  1445. //如果相邻代码三字码不顶真,提醒
  1446. string FootThree = Temp[2].Substring(3, 3);
  1447. string HeadThree = Info[2].Substring(0, 3);
  1448. if (FootThree != HeadThree)
  1449. {
  1450. //DelegationInfoService s = new DelegationInfoService();
  1451. //UsersService us = new UsersService();
  1452. //GroupsTaskAssignmentService gts = new GroupsTaskAssignmentService();
  1453. //77 行程
  1454. List<Grp_GroupsTaskAssignment> list2 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 77 && x.DIId == diid && x.IsDel == 0).ToList();
  1455. foreach (var temp in list2)
  1456. {
  1457. //if (temp.UId != 21)
  1458. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1459. // "黑屏代码提醒",
  1460. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1461. }
  1462. //85 机票预订
  1463. List<Grp_GroupsTaskAssignment> list6 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 85 && x.DIId == diid && x.IsDel == 0).ToList();
  1464. foreach (var temp in list6)
  1465. {
  1466. //if (temp.UId != 21)
  1467. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1468. // "黑屏代码提醒",
  1469. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1470. }
  1471. }
  1472. }
  1473. #endregion
  1474. #region 判断到达日期是否需要加1
  1475. if (Info[4].Contains("+"))
  1476. {
  1477. //日期+1
  1478. day = day + 1;
  1479. //判断是否进入下一月
  1480. if (day > Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year)))
  1481. {
  1482. day = day - Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year));
  1483. month = month + 1;
  1484. //判断是否进入下一年
  1485. if (month > 12)
  1486. {
  1487. month = month - 12;
  1488. year = year + 1;
  1489. }
  1490. }
  1491. //月份整理格式
  1492. string monthTemp = month.ToString();
  1493. if (month < 10)
  1494. {
  1495. monthTemp = "0" + monthTemp;
  1496. }
  1497. //日期整理格式
  1498. string daytemp = day.ToString();
  1499. if (day < 10)
  1500. {
  1501. daytemp = "0" + daytemp;
  1502. }
  1503. string temp = Info[4].Split('+')[0];
  1504. //添加起飞数据
  1505. dt.Rows.Add(Info[0],
  1506. Info[1],
  1507. Info[2],
  1508. Info[3],
  1509. temp,
  1510. Info[5],
  1511. Info[6],
  1512. Info[7],
  1513. Info[8],
  1514. year + "-" + GetLonger(Info[1].Substring(4, 3)) + "-" + Info[1].Substring(2, 2),
  1515. year + "-" + monthTemp + "-" + daytemp,
  1516. "",
  1517. "0");
  1518. //加1天,添加到达数据
  1519. dt.Rows.Add(Info[0],
  1520. Info[1].Replace(Info[1].Substring(2, 2), daytemp),
  1521. Info[2],
  1522. Info[3],
  1523. temp,
  1524. Info[5],
  1525. Info[6],
  1526. Info[7],
  1527. Info[8],
  1528. year + "-" + monthTemp + "-" + daytemp,
  1529. year + "-" + monthTemp + "-" + daytemp,
  1530. "",
  1531. "1");
  1532. }
  1533. else
  1534. {
  1535. //月份整理格式
  1536. string monthTemp = month.ToString();
  1537. if (month < 10)
  1538. {
  1539. monthTemp = "0" + monthTemp;
  1540. }
  1541. //日期整理格式
  1542. string daytemp = day.ToString();
  1543. if (day < 10)
  1544. {
  1545. daytemp = "0" + daytemp;
  1546. }
  1547. dt.Rows.Add(Info[0],
  1548. Info[1],
  1549. Info[2],
  1550. Info[3],
  1551. Info[4],
  1552. Info[5],
  1553. Info[6],
  1554. Info[7],
  1555. Info[8],
  1556. year + "-" + monthTemp + "-" + daytemp,
  1557. year + "-" + monthTemp + "-" + daytemp,
  1558. "",
  1559. "0");
  1560. }
  1561. #endregion
  1562. }
  1563. catch (Exception ex)
  1564. {
  1565. string exstr = ex.Message.ToString();
  1566. }
  1567. }
  1568. }
  1569. //排序
  1570. dt.DefaultView.Sort = "Day asc";
  1571. dt = dt.DefaultView.ToTable();
  1572. }
  1573. }
  1574. return dt;
  1575. }
  1576. private readonly static string[] excludeArr = new string[] { "[中转]", "[转机]" };
  1577. /// <summary>
  1578. ///根据机票黑屏代码整理DataTable
  1579. /// </summary>
  1580. /// <param name="diid"></param>
  1581. /// <returns></returns>
  1582. public static DataTable GetTableByBlackCode(int diid)
  1583. {
  1584. //黑屏代码信息
  1585. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  1586. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  1587. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  1588. DataTable dt = new DataTable();
  1589. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1590. dt.Columns.Add("Date", typeof(string));//起飞日期
  1591. dt.Columns.Add("Three", typeof(string));//三字码
  1592. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1593. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1594. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1595. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1596. dt.Columns.Add("AirModel", typeof(string)); //机型
  1597. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1598. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1599. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1600. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1601. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1602. //添加转机标识
  1603. dt.Columns.Add("isTransitShipment", typeof(bool));
  1604. //判断是否录入黑屏代码
  1605. if (listcode.Count() == 0 || listcode == null)
  1606. {
  1607. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false);
  1608. }
  1609. else
  1610. {
  1611. //读取单段黑屏代码
  1612. for (int i = 0; i < listcode.Count; i++)
  1613. {
  1614. //去除序号
  1615. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  1616. //去除多余空格,方法一Linq扩展方法
  1617. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  1618. //读取单条黑屏代码
  1619. for (int j = 0; j < CodeList.Count(); j++)
  1620. {
  1621. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  1622. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  1623. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1624. //去除多余空格
  1625. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  1626. //判断黑屏代码是否正确拆分; 理应拆成9段
  1627. if (Info.TakeWhile((x) =>
  1628. {
  1629. return !excludeArr.Contains(x);
  1630. }).Count() != 9)
  1631. {
  1632. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false);
  1633. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  1634. return dt;
  1635. }
  1636. else
  1637. {
  1638. try
  1639. {
  1640. var monthEn = Info[1].Substring(4, 3);
  1641. //月
  1642. int month = Convert.ToInt32(GetLonger(monthEn));
  1643. //日
  1644. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  1645. var time = new DateTime(DateTime.Now.Year, month, day); //
  1646. var isExist = Info.Contains("[中转]");
  1647. //dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1648. //dt.Columns.Add("Date", typeof(string));//起飞日期
  1649. //dt.Columns.Add("Three", typeof(string));//三字码
  1650. //dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1651. //dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1652. //dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1653. //dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1654. //dt.Columns.Add("AirModel", typeof(string)); //机型
  1655. //dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1656. //dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1657. //dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1658. //dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1659. //dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1660. dt.Rows.Add(Info[0],
  1661. Info[1],
  1662. Info[2],
  1663. Info[3],
  1664. Info[4],
  1665. Info[5],
  1666. Info[6],
  1667. Info[7],
  1668. Info[8],
  1669. time.ToString("yyyy-MM-dd"),
  1670. time.ToString("yyyy-MM-dd"),
  1671. "",
  1672. "0",
  1673. isExist
  1674. );
  1675. }
  1676. catch (Exception ex)
  1677. {
  1678. string exstr = ex.Message.ToString();
  1679. }
  1680. }
  1681. }
  1682. //排序
  1683. dt.DefaultView.Sort = "Day asc";
  1684. dt = dt.DefaultView.ToTable();
  1685. }
  1686. }
  1687. return dt;
  1688. }
  1689. /// <summary>
  1690. /// 根据星期,月份的缩写,转换成数字或者全称
  1691. /// 根据币种中文名称返回币种代码
  1692. /// 根据数字返回机型型号【2、3开头的就是空客,比如空客320,7开头的就是波音,比如波音777】
  1693. /// 20210903贾文滔
  1694. /// </summary>
  1695. /// <param name="startDate"></param>
  1696. /// <param name="endDate"></param>
  1697. /// <returns></returns>
  1698. public static string GetLonger(string temp)
  1699. {
  1700. string str = "";
  1701. switch (temp.ToUpper())
  1702. {
  1703. case "美元":
  1704. str = "USD";
  1705. break;
  1706. case "日元":
  1707. str = "JPY";
  1708. break;
  1709. case "英镑":
  1710. str = "GBP";
  1711. break;
  1712. case "欧元":
  1713. str = "EUR";
  1714. break;
  1715. case "港币":
  1716. str = "HKD";
  1717. break;
  1718. case "MO":
  1719. str = "星期一";
  1720. break;
  1721. case "TU":
  1722. str = "星期二";
  1723. break;
  1724. case "WE":
  1725. str = "星期三";
  1726. break;
  1727. case "TH":
  1728. str = "星期四";
  1729. break;
  1730. case "FR":
  1731. str = "星期五";
  1732. break;
  1733. case "SA":
  1734. str = "星期六";
  1735. break;
  1736. case "SU":
  1737. str = "星期天";
  1738. break;
  1739. case "JAN":
  1740. str = "01";
  1741. break;
  1742. case "FEB":
  1743. str = "02";
  1744. break;
  1745. case "MAR":
  1746. str = "03";
  1747. break;
  1748. case "APR":
  1749. str = "04";
  1750. break;
  1751. case "MAY":
  1752. str = "05";
  1753. break;
  1754. case "JUN":
  1755. str = "06";
  1756. break;
  1757. case "JUL":
  1758. str = "07";
  1759. break;
  1760. case "AUG":
  1761. str = "08";
  1762. break;
  1763. case "SEP":
  1764. str = "09";
  1765. break;
  1766. case "OCT":
  1767. str = "10";
  1768. break;
  1769. case "NOV":
  1770. str = "11";
  1771. break;
  1772. case "DEC":
  1773. str = "12";
  1774. break;
  1775. case "MONDAY":
  1776. str = "星期一";
  1777. break;
  1778. case "TUESDAY":
  1779. str = "星期二";
  1780. break;
  1781. case "WEDNESDAY":
  1782. str = "星期三";
  1783. break;
  1784. case "THURSDAY":
  1785. str = "星期四";
  1786. break;
  1787. case "FRIDAY":
  1788. str = "星期五";
  1789. break;
  1790. case "SATURDAY":
  1791. str = "星期六";
  1792. break;
  1793. case "SUNDAY":
  1794. str = "星期日";
  1795. break;
  1796. case "01":
  1797. str = "JAN";
  1798. break;
  1799. case "02":
  1800. str = "FEB";
  1801. break;
  1802. case "03":
  1803. str = "MAR";
  1804. break;
  1805. case "04":
  1806. str = "APR";
  1807. break;
  1808. case "05":
  1809. str = "MAY";
  1810. break;
  1811. case "06":
  1812. str = "JUN";
  1813. break;
  1814. case "07":
  1815. str = "JUL";
  1816. break;
  1817. case "08":
  1818. str = "AUG";
  1819. break;
  1820. case "09":
  1821. str = "SEP";
  1822. break;
  1823. case "10":
  1824. str = "OCT";
  1825. break;
  1826. case "11":
  1827. str = "NOV";
  1828. break;
  1829. case "12":
  1830. str = "DEC";
  1831. break;
  1832. case "2":
  1833. str = "空客A";
  1834. break;
  1835. case "3":
  1836. str = "空客A";
  1837. break;
  1838. case "7":
  1839. str = "波音";
  1840. break;
  1841. }
  1842. return str;
  1843. }
  1844. /// <summary>
  1845. /// 根据月份返回天数
  1846. /// </summary>
  1847. /// <param name="temp"></param>
  1848. /// <returns></returns>
  1849. public static string GetDaysByMonth(string Month, int year)
  1850. {
  1851. string str = "";
  1852. //判断是否是闰年
  1853. if (DateTime.IsLeapYear(year) == false)
  1854. {
  1855. switch (Month.ToUpper())
  1856. {
  1857. case "JAN":
  1858. str = "31";
  1859. break;
  1860. case "FEB":
  1861. str = "28";
  1862. break;
  1863. case "MAR":
  1864. str = "31";
  1865. break;
  1866. case "APR":
  1867. str = "30";
  1868. break;
  1869. case "MAY":
  1870. str = "31";
  1871. break;
  1872. case "JUN":
  1873. str = "30";
  1874. break;
  1875. case "JUL":
  1876. str = "31";
  1877. break;
  1878. case "AUG":
  1879. str = "31";
  1880. break;
  1881. case "SEP":
  1882. str = "30";
  1883. break;
  1884. case "OCT":
  1885. str = "31";
  1886. break;
  1887. case "NOV":
  1888. str = "30";
  1889. break;
  1890. case "DEC":
  1891. str = "31";
  1892. break;
  1893. case "01":
  1894. str = "31";
  1895. break;
  1896. case "02":
  1897. str = "28";
  1898. break;
  1899. case "03":
  1900. str = "31";
  1901. break;
  1902. case "04":
  1903. str = "30";
  1904. break;
  1905. case "05":
  1906. str = "31";
  1907. break;
  1908. case "06":
  1909. str = "30";
  1910. break;
  1911. case "07":
  1912. str = "31";
  1913. break;
  1914. case "08":
  1915. str = "31";
  1916. break;
  1917. case "09":
  1918. str = "30";
  1919. break;
  1920. case "10":
  1921. str = "31";
  1922. break;
  1923. case "11":
  1924. str = "30";
  1925. break;
  1926. case "12":
  1927. str = "31";
  1928. break;
  1929. }
  1930. }
  1931. else
  1932. {
  1933. switch (Month.ToUpper())
  1934. {
  1935. case "JAN":
  1936. str = "31";
  1937. break;
  1938. case "FEB":
  1939. str = "29";
  1940. break;
  1941. case "MAR":
  1942. str = "31";
  1943. break;
  1944. case "APR":
  1945. str = "30";
  1946. break;
  1947. case "MAY":
  1948. str = "31";
  1949. break;
  1950. case "JUN":
  1951. str = "30";
  1952. break;
  1953. case "JUL":
  1954. str = "31";
  1955. break;
  1956. case "AUG":
  1957. str = "31";
  1958. break;
  1959. case "SEP":
  1960. str = "30";
  1961. break;
  1962. case "OCT":
  1963. str = "31";
  1964. break;
  1965. case "NOV":
  1966. str = "30";
  1967. break;
  1968. case "DEC":
  1969. str = "31";
  1970. break;
  1971. case "01":
  1972. str = "31";
  1973. break;
  1974. case "02":
  1975. str = "29";
  1976. break;
  1977. case "03":
  1978. str = "31";
  1979. break;
  1980. case "04":
  1981. str = "30";
  1982. break;
  1983. case "05":
  1984. str = "31";
  1985. break;
  1986. case "06":
  1987. str = "30";
  1988. break;
  1989. case "07":
  1990. str = "31";
  1991. break;
  1992. case "08":
  1993. str = "31";
  1994. break;
  1995. case "09":
  1996. str = "30";
  1997. break;
  1998. case "10":
  1999. str = "31";
  2000. break;
  2001. case "11":
  2002. str = "30";
  2003. break;
  2004. case "12":
  2005. str = "31";
  2006. break;
  2007. }
  2008. }
  2009. return str;
  2010. }
  2011. /// <summary>
  2012. /// op行程单 团组 城市路径
  2013. /// </summary>
  2014. /// <param name="diid">团组Id</param>
  2015. /// <param name="separator">分隔符</param>
  2016. /// <returns></returns>
  2017. public static string GetGroupCityLine(int diid, string separator)
  2018. {
  2019. string city = string.Empty;
  2020. var blackCode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  2021. if (blackCode.Count > 0)
  2022. {
  2023. var black = blackCode.First();
  2024. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  2025. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  2026. if (blackSp.Length > 0)
  2027. {
  2028. try
  2029. {
  2030. var cityArrCode = new List<string>(20);
  2031. foreach (var item in blackSp)
  2032. {
  2033. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  2034. var IndexSelect = itemSp[2];
  2035. var cityArrCodeLength = cityArrCode.Count - 1;
  2036. var startCity = IndexSelect.Substring(0, 3);
  2037. if (cityArrCodeLength > 0)
  2038. {
  2039. var arrEndCity = cityArrCode[cityArrCodeLength];
  2040. if (arrEndCity != startCity)
  2041. {
  2042. cityArrCode.Add(startCity.ToUpper());
  2043. }
  2044. }
  2045. else
  2046. {
  2047. cityArrCode.Add(startCity.ToUpper());
  2048. }
  2049. var endCity = IndexSelect.Substring(3, 3);
  2050. cityArrCode.Add(endCity.ToUpper());
  2051. }
  2052. var cityThree = string.Empty;
  2053. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  2054. cityThree = cityThree.TrimEnd(',');
  2055. if (string.IsNullOrWhiteSpace(cityThree))
  2056. {
  2057. throw new Exception("error");
  2058. }
  2059. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  2060. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  2061. foreach (var item in cityArrCode)
  2062. {
  2063. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  2064. if (find != null)
  2065. {
  2066. city += find.City + separator;
  2067. }
  2068. else
  2069. {
  2070. city += item + "[三字码未收录]" + separator;
  2071. }
  2072. }
  2073. city = city.TrimEnd(char.Parse(separator));
  2074. }
  2075. catch (Exception e)
  2076. {
  2077. city = "[黑屏代码格式不正确!]";
  2078. }
  2079. }
  2080. }
  2081. else city = "[未录入黑屏代码]";
  2082. return city;
  2083. }
  2084. /// <summary>
  2085. /// op行程单 团组 城市路径
  2086. /// </summary>
  2087. /// <param name="diid">团组Id</param>
  2088. /// <param name="separator">分隔符</param>
  2089. /// <returns></returns>
  2090. public static Dictionary<int,string> GetGroupCityLineItem(List<int> diids, string separator)
  2091. {
  2092. Dictionary<int, string> dicCitys = new Dictionary<int, string>();
  2093. var cityCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  2094. var blackCodes = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && diids.Contains(x.DiId)).ToList();
  2095. foreach (var diid in diids)
  2096. {
  2097. string city = string.Empty;
  2098. var blackCode = blackCodes.Where(it => it.DiId == diid).ToList();
  2099. if (blackCode.Count > 0)
  2100. {
  2101. var black = blackCode.First();
  2102. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  2103. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  2104. if (blackSp.Length > 0)
  2105. {
  2106. try
  2107. {
  2108. var cityArrCode = new List<string>(20);
  2109. foreach (var item in blackSp)
  2110. {
  2111. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  2112. var IndexSelect = itemSp[2];
  2113. var cityArrCodeLength = cityArrCode.Count - 1;
  2114. var startCity = IndexSelect.Substring(0, 3);
  2115. if (cityArrCodeLength > 0)
  2116. {
  2117. var arrEndCity = cityArrCode[cityArrCodeLength];
  2118. if (arrEndCity != startCity)
  2119. {
  2120. cityArrCode.Add(startCity.ToUpper());
  2121. }
  2122. }
  2123. else
  2124. {
  2125. cityArrCode.Add(startCity.ToUpper());
  2126. }
  2127. var endCity = IndexSelect.Substring(3, 3);
  2128. cityArrCode.Add(endCity.ToUpper());
  2129. }
  2130. var cityThree = string.Empty;
  2131. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  2132. cityThree = cityThree.TrimEnd(',');
  2133. if (string.IsNullOrWhiteSpace(cityThree))
  2134. {
  2135. throw new Exception("error");
  2136. }
  2137. var cityArr = cityCodes.Where(it => cityThree.Contains(it.Three.ToUpper())).ToList();
  2138. foreach (var item in cityArrCode)
  2139. {
  2140. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  2141. if (find != null)
  2142. {
  2143. city += find.City + separator;
  2144. }
  2145. else
  2146. {
  2147. city += item + "[三字码未收录]" + separator;
  2148. }
  2149. }
  2150. city = city.TrimEnd(char.Parse(separator));
  2151. }
  2152. catch (Exception e)
  2153. {
  2154. city = "[黑屏代码格式不正确!]";
  2155. }
  2156. }
  2157. }
  2158. else city = "[未录入黑屏代码]";
  2159. dicCitys.Add(diid,city);
  2160. }
  2161. return dicCitys;
  2162. }
  2163. /// <summary>
  2164. /// op行程单相关团组信息 含途径城市
  2165. /// </summary>
  2166. /// <returns></returns>
  2167. public static async Task< List<MateOpGroupPageListView>> MateOpGroupPageListRedis()
  2168. {
  2169. List<MateOpGroupPageListView> _views = new List<MateOpGroupPageListView>();
  2170. string viewStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("MateOpGroupPageList");//string 取
  2171. if (!string.IsNullOrEmpty(viewStr))
  2172. {
  2173. _views = JsonConvert.DeserializeObject<List<MateOpGroupPageListView>>(viewStr);
  2174. }
  2175. else
  2176. {
  2177. string sql = string.Format($@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  2178. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  2179. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  2180. JietuanOperator,IsSure,CreateTime,VisitCountry
  2181. From (
  2182. Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
  2183. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  2184. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  2185. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  2186. su.CnName JietuanOperator,IsSure,gdi.CreateTime,gdi.VisitCountry
  2187. From Grp_DelegationInfo gdi
  2188. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  2189. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  2190. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  2191. Where gdi.IsDel = 0
  2192. ) temp");
  2193. _views = _dirRep._sqlSugar.SqlQueryable<MateOpGroupPageListView>(sql).ToList();
  2194. #region 处理所属部门
  2195. /*
  2196. * 1.sq 和 gyy 等显示 市场部
  2197. * 2.王鸽和主管及张总还有管理员号统一国交部
  2198. * 2-1. 4 管理员 ,21 张海麟
  2199. */
  2200. List<int> userIds = _views.Select(it => it.JietuanOperatorId).ToList();
  2201. List<int> userIds1 = new List<int>() { 4, 21 };
  2202. var UserDepDatas = _dirRep._sqlSugar.Queryable<Sys_Users>()
  2203. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2204. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2205. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2206. .ToList();
  2207. #endregion
  2208. _views.ForEach(it => {
  2209. it.RouteCity = GetGroupCityLine(it.Id, @"/");
  2210. it.Department = UserDepDatas.Find(it1 => it.JietuanOperatorId == it1.UserId)?.DepName ?? "Unknown";
  2211. });
  2212. TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay;
  2213. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("MateOpGroupPageList", JsonConvert.SerializeObject(_views), ts);//string 存
  2214. }
  2215. return _views;
  2216. }
  2217. /// <summary>
  2218. /// 获取黑屏代码日期列表
  2219. /// </summary>
  2220. /// <param name="dt"></param>
  2221. /// <returns></returns>
  2222. public static List<string> GetTimeListByDataTable(DataTable dt)
  2223. {
  2224. DateTime datestart = Convert.ToDateTime(dt.Rows[0]["Day"].ToString());
  2225. DateTime dateend = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["ArrivedDate"].ToString());
  2226. List<string> timeList = new List<string>();
  2227. while (datestart <= dateend)
  2228. {
  2229. timeList.Add(datestart.ToString("yyyy-MM-dd"));
  2230. datestart = datestart.AddDays(1);
  2231. }
  2232. return timeList;
  2233. }
  2234. const decimal conversion = 1.61M;
  2235. /// <summary>
  2236. /// 简要行程
  2237. /// </summary>
  2238. /// <param name="diid"></param>
  2239. /// <returns></returns>
  2240. public static Result GetBriefStroke (int diid)
  2241. {
  2242. DataTable resultTable = GetTableByBlackCode(diid);
  2243. if (resultTable == null)
  2244. {
  2245. return new Result { Code = -1, Msg = "黑屏代码有误或黑屏代码未录入" };
  2246. }
  2247. if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
  2248. {
  2249. string msg = string.Empty;
  2250. if (resultTable.Rows.Count > 0)
  2251. {
  2252. msg = resultTable.Rows[0]["Error"].ToString();
  2253. }
  2254. return new Result { Code = -1, Msg = $"黑屏代码有误;{msg}" };
  2255. }
  2256. var timeArr = GetTimeListByDataTable(resultTable);
  2257. var threeCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList(); //三字码
  2258. var airCompanys = _dirRep._sqlSugar.Queryable<Res_AirCompany>().Where(it => it.IsDel == 0).ToList(); //航司公司
  2259. var obDatas = _dirRep._sqlSugar.Queryable<Res_OfficialActivities>().Where(it => it.IsDel == 0 && it.DiId == diid).ToList(); //公务信息
  2260. var NewListTravel = new List<Grp_TravelList>();
  2261. var index = 0;
  2262. var stopCity = string.Empty;
  2263. foreach (var item in timeArr)
  2264. {
  2265. string trip = string.Empty;
  2266. string weekDay = string.Empty;
  2267. DateTime time = DateTime.Now;
  2268. if (DateTime.TryParse(item, out time))
  2269. {
  2270. weekDay = weekdays[(int)time.DayOfWeek];
  2271. }
  2272. else
  2273. {
  2274. weekDay = "日期格式不正确!";
  2275. }
  2276. var empty = "【未收入该三字码!请机票同事录入】";
  2277. var tabSelect = resultTable.Select(string.Format("Day = '{0}'", item));
  2278. var isMoreTraffic = false;
  2279. if (tabSelect.Length > 0)
  2280. {
  2281. isMoreTraffic = true;
  2282. var takeOffTime = DateTime.Parse(item);
  2283. var fallToTime = DateTime.Parse(item);
  2284. Res_ThreeCode start_Object = null;
  2285. Res_ThreeCode end_Object = null;
  2286. bool isTrade = false;
  2287. //air 处理
  2288. foreach (var tabRow in tabSelect)
  2289. {
  2290. takeOffTime = DateTime.Parse(item);
  2291. fallToTime = DateTime.Parse(item);
  2292. var takeOff = tabRow["StartTime"].ToString();
  2293. var fallTo = tabRow["EndTime"].ToString();
  2294. takeOffTime = takeOffTime.AddHours(int.Parse(takeOff.Substring(0, 2)));
  2295. takeOffTime = takeOffTime.AddMinutes(int.Parse(takeOff.Substring(2, 2)));
  2296. fallToTime = fallToTime.AddHours(int.Parse(fallTo.Substring(0, 2)));
  2297. fallToTime = fallToTime.AddMinutes(int.Parse(fallTo.Substring(2, 2)));
  2298. var threeCode = tabRow["Three"].ToString();
  2299. var start = threeCode.Substring(0, 3);
  2300. var end = threeCode.Substring(3, 3);
  2301. stopCity = end;
  2302. start_Object = threeCodes.Find(x => x.Three.ToUpper() == start.ToUpper());
  2303. end_Object = threeCodes.Find(x => x.Three.ToUpper() == end.ToUpper());
  2304. if (start_Object == null)
  2305. {
  2306. start_Object = new Res_ThreeCode()
  2307. {
  2308. AirPort = empty,
  2309. AirPort_En = empty,
  2310. City = empty,
  2311. Country = empty,
  2312. Four = empty,
  2313. Three = empty,
  2314. };
  2315. }
  2316. if (end_Object == null)
  2317. {
  2318. end_Object = new Res_ThreeCode()
  2319. {
  2320. AirPort = empty,
  2321. AirPort_En = empty,
  2322. City = empty,
  2323. Country = empty,
  2324. Four = empty,
  2325. Three = empty,
  2326. };
  2327. }
  2328. //航班号
  2329. string flightcode = tabRow["Fliagtcode"].ToString();
  2330. trip += $"{takeOffTime.ToString("HH:mm")}—{fallToTime.ToString("HH:mm")} {start_Object.City}—{end_Object.City} 航班号:{flightcode}\r\n";
  2331. }
  2332. //var airArrive = fallToTime; //航班落地时间
  2333. time = fallToTime.AddHours(1.5); //出机场一个半小时
  2334. string Time = string.Empty;
  2335. string Distance = string.Empty;
  2336. int GetGoogleResult = 0;
  2337. int GetDistResult = 0;
  2338. JObject Result = null;
  2339. try
  2340. {
  2341. Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace(" ", "").Trim();
  2342. Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString().Replace(" ", "").Trim();
  2343. if (Time.Contains("hours"))
  2344. {
  2345. Time = Time.Replace("hours", "小时");
  2346. }
  2347. if (Time.Contains("hour"))
  2348. {
  2349. Time = Time.Replace("hour", "小时");
  2350. }
  2351. Time = Time.Replace("mins", "分钟");
  2352. if (Distance.Contains("mi"))
  2353. {
  2354. var distSp = Regex.Split(Distance, "mi");
  2355. if (distSp.Length > 0)
  2356. {
  2357. Distance = (decimal.Parse(distSp[0]) * conversion).ToString("#0.00") + " 公里";
  2358. }
  2359. }
  2360. if (Distance.Contains("km"))
  2361. {
  2362. Distance = Distance.Replace("km", "公里");
  2363. }
  2364. if (Time.Contains("小时"))
  2365. {
  2366. var xs = Regex.Split(Time, "小时");
  2367. var xsValue = int.Parse(xs[0]);
  2368. var fz = Regex.Split(xs[1], "分钟");
  2369. var fzValue = int.Parse(fz[0]);
  2370. GetGoogleResult = xsValue * 60;
  2371. GetGoogleResult += fzValue;
  2372. }
  2373. else if (Time.Contains("分钟"))
  2374. {
  2375. GetGoogleResult = int.Parse(Regex.Split(Time, "分钟")[0]);
  2376. }
  2377. if (Distance.Contains("公里"))
  2378. {
  2379. GetDistResult = (int)decimal.Parse(Regex.Split(Distance, "公里")[0]);
  2380. }
  2381. if (GetGoogleResult > 0 && GetGoogleResult % 5 != 0)
  2382. {
  2383. while (GetGoogleResult % 5 != 0)
  2384. {
  2385. GetGoogleResult++;
  2386. }
  2387. }
  2388. if (GetDistResult % 5 != 0 && GetDistResult > 0)
  2389. {
  2390. while (GetDistResult % 5 != 0)
  2391. {
  2392. GetDistResult++;
  2393. }
  2394. }
  2395. int H = (GetGoogleResult / 60);
  2396. int m = (GetGoogleResult % 60);
  2397. string TimeStr = string.Empty;
  2398. if (H != 0)
  2399. {
  2400. if (H < 10)
  2401. {
  2402. TimeStr += "0" + H + "小时";
  2403. }
  2404. else
  2405. {
  2406. TimeStr += H + "小时";
  2407. }
  2408. }
  2409. if (m < 10)
  2410. {
  2411. TimeStr += "0" + m + "分钟";
  2412. }
  2413. else
  2414. {
  2415. TimeStr += m + "分钟";
  2416. }
  2417. Time = TimeStr;
  2418. Distance = GetDistResult.ToString() + "公里";
  2419. }
  2420. catch (Exception ex)
  2421. {
  2422. Time = "未知!";
  2423. Distance = "未知!";
  2424. }
  2425. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区 路程{Distance},耗时{Time})";
  2426. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区)";
  2427. time = time.AddMinutes(GetGoogleResult); //到达市区时间
  2428. string tripDate = Convert.ToDateTime(item).ToString("M月d日");
  2429. if (index == timeArr.Count - 1)
  2430. {
  2431. NewListTravel.Add(new Grp_TravelList
  2432. {
  2433. CreateTime = DateTime.Now,
  2434. CreateUserId = 0,
  2435. Diid = diid,
  2436. Date = tripDate,
  2437. Trip = trip,
  2438. WeekDay = weekDay,
  2439. Days = index + 1,
  2440. Traffic_First = "飞机",
  2441. Traffic_Second = "汽车",
  2442. Diffgroup = 1,
  2443. Issel = 1,
  2444. IsDel = 0,
  2445. });
  2446. continue;
  2447. }
  2448. if (time.Day != fallToTime.Day) //超出一天
  2449. {
  2450. NewListTravel.Add(new Grp_TravelList
  2451. {
  2452. CreateTime = DateTime.Now,
  2453. CreateUserId = 0,
  2454. Diid = diid,
  2455. Date = tripDate,
  2456. Trip = trip,
  2457. WeekDay = weekDay,
  2458. Days = index + 1,
  2459. Traffic_First = "飞机",
  2460. Traffic_Second = "汽车",
  2461. Diffgroup = 1,
  2462. Issel = 1,
  2463. IsDel = 0,
  2464. });
  2465. continue;
  2466. }
  2467. var obInfo = obDatas.Find(it => Convert.ToDateTime(it.Date).ToString("M月d日").Equals(tripDate));
  2468. string obtime = "";
  2469. string obcontent = "";
  2470. if (obInfo != null)
  2471. {
  2472. obtime = obInfo.Time;
  2473. obcontent = $"拜访{obInfo.Client ?? "公务出访单位未录入"}{obInfo.Job ?? "公务出访联系人职务未录入"}{obInfo.Contact ?? "公务出访联系人职务未录入"}";
  2474. }
  2475. bool obTime_bool = DateTime.TryParse(obtime, out DateTime obTimeDt);
  2476. if (time.Hour < 9) // && (airArrive < new DateTime(airArrive.Year,airArrive.Month,airArrive.Day,6, 30, 0))
  2477. {
  2478. if (obTime_bool)
  2479. {
  2480. if (obTimeDt.Hour < 9)
  2481. {
  2482. trip += $"{obTimeDt.ToString("HH:mm")}—10:30 {obcontent};\r\n";
  2483. }
  2484. }
  2485. else
  2486. {
  2487. trip += "09:00—10:30 公务活动;\r\n";
  2488. }
  2489. }
  2490. else if (time.Hour < 10)
  2491. {
  2492. if (obTime_bool)
  2493. {
  2494. if (obTimeDt.Hour < 10)
  2495. {
  2496. trip += $"{obTimeDt.ToString("HH:mm")}—12:00 {obcontent};\r\n";
  2497. }
  2498. }
  2499. else
  2500. {
  2501. trip += "10:30—12:00 公务活动;\r\n";
  2502. }
  2503. }
  2504. if (time.Hour < 13)
  2505. {
  2506. //trip += $"\r\n{time.ToString("HH:mm")} 午餐于当地餐厅;";
  2507. }
  2508. if (time < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  2509. {
  2510. if (obTime_bool)
  2511. {
  2512. if (obTimeDt < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  2513. {
  2514. trip += $"{obTimeDt.ToString("HH:mm")}—16:00 {obcontent};\r\n";
  2515. }
  2516. }
  2517. else
  2518. {
  2519. trip += "14:00—16:00 公务活动;\r\n";
  2520. }
  2521. }
  2522. else if (time.Hour < 16)
  2523. {
  2524. if (obTime_bool)
  2525. {
  2526. if (obTimeDt.Hour < 16)
  2527. {
  2528. trip += $"{obTimeDt.ToString("HH:mm")}—17:30 {obcontent};\r\n";
  2529. }
  2530. }
  2531. else
  2532. {
  2533. trip += "16:00—17:30 公务活动;\r\n";
  2534. }
  2535. }
  2536. //if (time.Hour < 18)
  2537. //{
  2538. // trip += $"\r\n18:00 晚餐于当地餐厅;";
  2539. //}
  2540. //time = time.AddHours(1);
  2541. //trip += $"\r\n{time.ToString("HH:mm")} 搭乘专车前往酒店,抵达后办理入住;";
  2542. }
  2543. else
  2544. {
  2545. var end_Object = threeCodes.Find(x => x.Three.ToUpper() == stopCity.ToUpper());
  2546. if (end_Object == null)
  2547. {
  2548. end_Object = new Res_ThreeCode()
  2549. {
  2550. AirPort = empty,
  2551. AirPort_En = empty,
  2552. City = empty,
  2553. Country = empty,
  2554. Four = empty,
  2555. Three = empty,
  2556. };
  2557. }
  2558. //trip += $"{end_Object.City}\r\n";
  2559. // trip += @"08:00 早餐于酒店;
  2560. //09:00—10:30 公务活动;
  2561. //12:00 午餐于当地餐厅;
  2562. //14:00—16:00 公务活动;
  2563. //18:00 晚餐于当地餐厅;
  2564. //19:00 入住酒店休息;";
  2565. trip += "09:00—10:30 公务活动;\r\n14:00—16:00 公务活动;\r\n";
  2566. }
  2567. string[] traffic = new string[] { "飞机", "汽车" };
  2568. if (!isMoreTraffic)
  2569. {
  2570. traffic = new string[] { "汽车", "" };
  2571. }
  2572. NewListTravel.Add(new Grp_TravelList
  2573. {
  2574. CreateTime = DateTime.Now,
  2575. CreateUserId = 0,
  2576. Diid = diid,
  2577. Date = Convert.ToDateTime(item).ToString("M月d日"),
  2578. Trip = trip,
  2579. WeekDay = weekDay,
  2580. Days = index + 1,
  2581. Traffic_First = traffic[0],
  2582. Traffic_Second = traffic[1],
  2583. Diffgroup = 1,
  2584. Issel = 1,
  2585. IsDel = 0,
  2586. });
  2587. index++;
  2588. }
  2589. return new Result() { Code = 0, Msg = "获取成功!", Data = NewListTravel };
  2590. }
  2591. /// <summary>
  2592. /// 根据日期获取星期
  2593. /// </summary>
  2594. /// <param name="dt"></param>
  2595. /// <returns></returns>
  2596. public static string GetWeek(this string dtStr)
  2597. {
  2598. string week = "";
  2599. bool isDt = DateTime.TryParse(dtStr,out DateTime dt);
  2600. if (isDt)
  2601. {
  2602. week = weekdays[(int)dt.DayOfWeek];
  2603. }
  2604. return week;
  2605. }
  2606. #endregion
  2607. #region 三公费用明细 文件下载
  2608. /// <summary>
  2609. /// 获取三公费用标准city
  2610. /// </summary>
  2611. /// <param name="placeData"></param>
  2612. /// <param name="nationalTravelFeeId"></param>
  2613. /// <returns></returns>
  2614. private static string GetEnterExitCostExportCity(List<Grp_NationalTravelFee> placeData, int nationalTravelFeeId)
  2615. {
  2616. string _city = string.Empty;
  2617. if (placeData.Count < 1) return _city;
  2618. var data = placeData.Find(it => it.Id == nationalTravelFeeId);
  2619. if (data == null) return _city;
  2620. string country = data.Country;
  2621. string city = data.City;
  2622. if (city.Contains("其他城市") || city.Contains("所有城市")) _city = $"{country}-{city}";
  2623. else _city = city;
  2624. return _city;
  2625. }
  2626. /// <summary>
  2627. /// 三公费用明细 文件下载
  2628. /// </summary>
  2629. /// <param name="diId"></param>
  2630. /// <param name="userId"></param>
  2631. /// <param name="CTable"></param>
  2632. /// <returns></returns>
  2633. public static async Task<JsonView> EnterExitCostDownload(EnterExitCostDownloadDto dto,string fileFormat = "pdf")
  2634. {
  2635. var _view = new JsonView() { Code = StatusCodes.Status204NoContent };
  2636. if (dto.DiId < 1)
  2637. {
  2638. _view.Msg = "请传入有效的DiId参数;";
  2639. return _view;
  2640. }
  2641. if (dto.ExportType < 1)
  2642. {
  2643. _view.Msg = MsgTips.Port;
  2644. return _view;
  2645. }
  2646. if (dto.SubTypeId < 1)
  2647. {
  2648. _view.Msg = @"请传入有效的SubTypeId参数;
  2649. 1 明细表 --> 1005(默认明细表) 1006(因公出国(境)经费测算明细表) 1007(四川省商务厅出国经费财政先行审核表)
  2650. 2 表格 --> 1008(派员单位出(境)任务和预算审批意见表) 1009(省级单位出(境)经费报销单)
  2651. 3 团组成员名单 1 团组成员名单";
  2652. return _view;
  2653. }
  2654. try
  2655. {
  2656. var _EnterExitCosts = _sqlSugar.Queryable<Grp_EnterExitCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  2657. var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).ToList();
  2658. if (_EnterExitCosts == null)
  2659. {
  2660. _view.Msg = @"该团组未填写出入境费用;";
  2661. return _view;
  2662. }
  2663. //数据源
  2664. List<Grp_DayAndCost> dac1 = _DayAndCosts.Where(it => it.Type == 1).ToList(); //住宿费
  2665. List<Grp_DayAndCost> dac2 = _DayAndCosts.Where(it => it.Type == 2).ToList(); //伙食费
  2666. List<Grp_DayAndCost> dac3 = _DayAndCosts.Where(it => it.Type == 3).ToList(); //公杂费
  2667. List<Grp_DayAndCost> dac4 = _DayAndCosts.Where(it => it.Type == 4).ToList(); //培训费
  2668. var _CurrDatas = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  2669. var _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == dto.DiId).First();
  2670. var DeleClientList = _sqlSugar.Queryable<Grp_TourClientList>()
  2671. .LeftJoin<Crm_DeleClient>((tcl, dc) => tcl.ClientId == dc.Id && dc.IsDel == 0)
  2672. .LeftJoin<Crm_CustomerCompany>((tcl, dc, cc) => dc.CrmCompanyId == cc.Id && dc.IsDel == 0)
  2673. .Where((tcl, dc, cc) => tcl.IsDel == 0 && tcl.DiId == dto.DiId)
  2674. .Select((tcl, dc, cc) => new
  2675. {
  2676. Name = dc.LastName + dc.FirstName,
  2677. Sex = dc.Sex,
  2678. Birthday = dc.BirthDay,
  2679. Company = cc.CompanyFullName,
  2680. Job = dc.Job
  2681. })
  2682. .ToList();
  2683. var blackCode = _sqlSugar.Queryable<Air_TicketBlackCode>().Where(it => it.IsDel == 0 && it.DiId == dto.DiId).First();
  2684. var threeCodes = _sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  2685. var placeData = _sqlSugar.Queryable<Grp_NationalTravelFee>().Where(it => it.IsDel == 0).ToList();
  2686. var rateDatas = await _EnterExitCosts.CurrencyRemark.SplitExchangeRate();
  2687. _DelegationInfo.VisitCountry = _DelegationInfo.VisitCountry.Replace("|", "、");
  2688. if (dto.ExportType == 1) //明细表
  2689. {
  2690. if (dto.SubTypeId == 1005) //1005(默认明细表)
  2691. {
  2692. if (!fileFormat.Equals("pdf")) fileFormat = "docx";
  2693. //获取模板
  2694. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/出入境费用表模板.docx");
  2695. //载入模板
  2696. Document doc = new Document(tempPath);
  2697. DocumentBuilder builder = new DocumentBuilder(doc);
  2698. //利用键值对存放数据
  2699. Dictionary<string, string> dic = new Dictionary<string, string>();
  2700. decimal stayFeeTotal = _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal); // 住宿费
  2701. decimal mealsFeeTotal = _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal); // 伙食费费
  2702. decimal miscellaneousFeeTotal = _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal); // 公杂费
  2703. decimal tainFeeTotal = _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal); // 培训费
  2704. decimal insidePayTotal = _EnterExitCosts.InsidePay;
  2705. string row1_1 = "";
  2706. if (_EnterExitCosts.Visa > 0)
  2707. {
  2708. //insidePayTotal += _EnterExitCosts.Visa;
  2709. row1_1 = $"签证费: {_EnterExitCosts.Visa.ToString("#0.00")} 人民币/人";
  2710. if (!string.IsNullOrEmpty(_EnterExitCosts.VisaRemark))
  2711. {
  2712. row1_1 += $"\t签证费用描述: {_EnterExitCosts.VisaRemark}";
  2713. }
  2714. }
  2715. string row1_2 = "";
  2716. if (_EnterExitCosts.YiMiao > 0)
  2717. {
  2718. //insidePayTotal += _EnterExitCosts.YiMiao;
  2719. row1_2 += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")} 人民币/人";
  2720. }
  2721. if (_EnterExitCosts.HeSuan > 0)
  2722. {
  2723. //insidePayTotal += _EnterExitCosts.HeSuan;
  2724. row1_2 += $"核酸检测费:{_EnterExitCosts.HeSuan.ToString("#0.00")} 人民币/人";
  2725. }
  2726. if (_EnterExitCosts.Service > 0)
  2727. {
  2728. //insidePayTotal += _EnterExitCosts.Service;
  2729. row1_2 += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")} 人民币/人";
  2730. }
  2731. string row1_3 = "";
  2732. if (_EnterExitCosts.Safe > 0)
  2733. {
  2734. //insidePayTotal += _EnterExitCosts.Safe;
  2735. row1_3 += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")} 人民币/人";
  2736. }
  2737. if (_EnterExitCosts.Ticket > 0)
  2738. {
  2739. //insidePayTotal += _EnterExitCosts.Ticket;
  2740. row1_3 += $"参展门票:{_EnterExitCosts.Ticket.ToString("#0.00")} 人民币/人";
  2741. }
  2742. string row1 = "";
  2743. if (!string.IsNullOrEmpty(row1_1)) row1 += $"{row1_1}\r\n";
  2744. if (!string.IsNullOrEmpty(row1_2)) row1 += $"{row1_2}\r\n";
  2745. if (!string.IsNullOrEmpty(row1_3)) row1 += $"{row1_3}";
  2746. dic.Add("InsidePay", insidePayTotal.ToString("#0.00"));
  2747. dic.Add("Row1Str", row1);
  2748. dic.Add("OutsideJJ", _EnterExitCosts.OutsideJJPay.ToString("#0.00"));
  2749. dic.Add("OutsaideGW", _EnterExitCosts.OutsideGWPay.ToString("#0.00"));
  2750. dic.Add("AirJJ", _EnterExitCosts.AirJJ.ToString("#0.00"));
  2751. dic.Add("AirGW", _EnterExitCosts.AirGW.ToString("#0.00"));
  2752. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  2753. dic.Add("SubZS", stayFeeTotal.ToString("#0.00"));
  2754. dic.Add("SubHS", mealsFeeTotal.ToString("#0.00"));
  2755. string miscellaneousFeeTotalStr = miscellaneousFeeTotal.ToString("#0.00");
  2756. dic.Add("SubGZF", miscellaneousFeeTotalStr);
  2757. //dic.Add("SubPX", tainFeeTotal.ToString("#0.00"));
  2758. decimal subJJC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + _EnterExitCosts.OutsideJJPay;
  2759. decimal subGWC = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + _EnterExitCosts.OutsideGWPay;
  2760. dic.Add("SubJJC", subJJC.ToString("#0.00"));
  2761. dic.Add("SubGWC", subGWC.ToString("#0.00"));
  2762. #region 填充word模板书签内容
  2763. foreach (var key in dic.Keys)
  2764. {
  2765. builder.MoveToBookmark(key);
  2766. builder.Write(dic[key]);
  2767. }
  2768. #endregion
  2769. #region 填充word表格内容
  2770. ////获读取指定表格方法二
  2771. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  2772. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  2773. for (int i = 0; i < dac1.Count; i++)
  2774. {
  2775. Grp_DayAndCost dac = dac1[i];
  2776. if (dac == null) continue;
  2777. builder.MoveToCell(0, i, 0, 0);
  2778. builder.Write("第" + dac.Days.ToString() + "晚:");
  2779. builder.MoveToCell(0, i, 1, 0);
  2780. //builder.Write(placeData.Find(it => it.Id == dac.NationalTravelFeeId)?.Country ?? "Unknown");
  2781. //builder.Write(dac.Place == null ? "" : dac.Place);
  2782. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  2783. builder.MoveToCell(0, i, 2, 0);
  2784. builder.Write("费用标准:");
  2785. string curr = "";
  2786. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  2787. if (currData != null)
  2788. {
  2789. curr = currData.Name;
  2790. }
  2791. builder.MoveToCell(0, i, 3, 0);
  2792. builder.Write(dac.Cost.ToString("#0.00") + curr);
  2793. builder.MoveToCell(0, i, 4, 0);
  2794. builder.Write("费用小计:");
  2795. builder.MoveToCell(0, i, 5, 0);
  2796. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  2797. }
  2798. //删除多余行
  2799. while (table1.Rows.Count > dac1.Count)
  2800. {
  2801. table1.Rows.RemoveAt(dac1.Count);
  2802. }
  2803. Aspose.Words.Tables.Table table2 = allTables[1] as Aspose.Words.Tables.Table;
  2804. for (int i = 0; i < dac2.Count; i++)
  2805. {
  2806. Grp_DayAndCost dac = dac2[i];
  2807. if (dac == null) continue;
  2808. builder.MoveToCell(1, i, 0, 0);
  2809. builder.Write("第" + dac.Days.ToString() + "天:");
  2810. builder.MoveToCell(1, i, 1, 0);
  2811. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  2812. builder.MoveToCell(1, i, 2, 0);
  2813. builder.Write("费用标准:");
  2814. string curr = "";
  2815. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  2816. if (currData != null)
  2817. {
  2818. curr = currData.Name;
  2819. }
  2820. builder.MoveToCell(1, i, 3, 0);
  2821. builder.Write(dac.Cost.ToString("#0.00") + curr);
  2822. builder.MoveToCell(1, i, 4, 0);
  2823. builder.Write("费用小计:");
  2824. builder.MoveToCell(1, i, 5, 0);
  2825. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  2826. }
  2827. //删除多余行
  2828. while (table2.Rows.Count > dac2.Count)
  2829. {
  2830. table2.Rows.RemoveAt(dac2.Count);
  2831. }
  2832. Aspose.Words.Tables.Table table3 = allTables[2] as Aspose.Words.Tables.Table;
  2833. for (int i = 0; i < dac3.Count; i++)
  2834. {
  2835. Grp_DayAndCost dac = dac3[i];
  2836. if (dac == null) continue;
  2837. builder.MoveToCell(2, i, 0, 0);
  2838. builder.Write("第" + dac.Days.ToString() + "天:");
  2839. builder.MoveToCell(2, i, 1, 0);
  2840. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  2841. builder.MoveToCell(2, i, 2, 0);
  2842. builder.Write("费用标准:");
  2843. string curr = "";
  2844. var currData = _CurrDatas.Where(it => it.Id == dac.Currency).FirstOrDefault();
  2845. if (currData != null)
  2846. {
  2847. curr = currData.Name;
  2848. }
  2849. builder.MoveToCell(2, i, 3, 0);
  2850. builder.Write(dac.Cost.ToString("#0.00") + curr);
  2851. builder.MoveToCell(2, i, 4, 0);
  2852. builder.Write("费用小计:");
  2853. builder.MoveToCell(2, i, 5, 0);
  2854. builder.Write(dac.SubTotal.ToString("#0.00") + "CNY");
  2855. }
  2856. //删除多余行
  2857. while (table3.Rows.Count > dac3.Count)
  2858. {
  2859. table3.Rows.RemoveAt(dac3.Count);
  2860. }
  2861. #endregion
  2862. //文件名
  2863. //string strFileName = $"{_DelegationInfo.TeamName}出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  2864. //string strFileName = $"{_DelegationInfo.TeamName}-出入境费用{Guid.NewGuid().ToString()}.{fileFormat}";
  2865. string strFileName = $"{_DelegationInfo.TeamName}{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.{fileFormat}";
  2866. AsposeHelper.removewatermark_v2180();
  2867. //doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  2868. var saveFormat = Aspose.Words.SaveFormat.Docx;
  2869. if (fileFormat.Equals("pdf")) {
  2870. //doc.LayoutOptions.IsShowComments = false;
  2871. doc.LayoutOptions.IsShowHiddenText = false;
  2872. doc.LayoutOptions.IsShowParagraphMarks = false;
  2873. doc.LayoutOptions.RevisionOptions.DeletedTextEffect = RevisionTextEffect.None;
  2874. doc.AcceptAllRevisions();
  2875. Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions();
  2876. options.Compliance = PdfCompliance.PdfA1a;
  2877. options.CreateNoteHyperlinks = true;
  2878. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, options);
  2879. //_view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  2880. _view.Data = new { Url = strFileName };
  2881. _view.Msg = "成功";
  2882. return _view;
  2883. }
  2884. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName, saveFormat);
  2885. _view.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName };
  2886. _view.Msg = "成功";
  2887. return _view;
  2888. }
  2889. else if (dto.SubTypeId == 1006)//1006(因公出国(境)经费测算明细表)
  2890. {
  2891. //获取模板
  2892. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/因公出国(境)经费测算明细表.docx");
  2893. //载入模板
  2894. Document doc = new Document(tempPath);
  2895. DocumentBuilder builder = new DocumentBuilder(doc);
  2896. Dictionary<string, string> dic = new Dictionary<string, string>();
  2897. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  2898. {
  2899. List<string> list = new List<string>();
  2900. try
  2901. {
  2902. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  2903. foreach (var item in spilitArr)
  2904. {
  2905. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  2906. var depCode = spDotandEmpty[2].Substring(0, 3);
  2907. var arrCode = spDotandEmpty[2].Substring(3, 3);
  2908. string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  2909. arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  2910. list.Add(depName);
  2911. list.Add(arrName);
  2912. }
  2913. list = list.Distinct().ToList();
  2914. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  2915. }
  2916. catch (Exception)
  2917. {
  2918. dic.Add("ReturnCode", "行程录入不正确!");
  2919. }
  2920. }
  2921. else
  2922. {
  2923. dic.Add("ReturnCode", "未录入行程!");
  2924. }
  2925. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  2926. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  2927. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  2928. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  2929. {
  2930. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  2931. dic.Add("Day", sp.Days.ToString());
  2932. }
  2933. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  2934. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  2935. //var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  2936. //dic.Add("Names", Names);
  2937. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  2938. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  2939. decimal dac1totalPrice = 0.00M;
  2940. int accommodationStartIndex = 6, foodandotherStartIndex = 22;
  2941. foreach (var dac in dac1)
  2942. {
  2943. if (dac.SubTotal == 0.00M)
  2944. {
  2945. continue;
  2946. }
  2947. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  2948. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  2949. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  2950. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  2951. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  2952. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  2953. builder.Write(currency);//币种
  2954. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  2955. builder.Write(dac.Cost.ToString("#0.00"));//标准
  2956. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  2957. builder.Write("");//人数
  2958. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  2959. builder.Write("");//天数
  2960. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  2961. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  2962. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  2963. decimal rate = 0.00M;
  2964. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  2965. builder.Write(rate.ToString("#0.0000"));//汇率
  2966. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  2967. decimal rbmPrice = dac.SubTotal;
  2968. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  2969. accommodationStartIndex++;
  2970. dac1totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  2971. }
  2972. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  2973. for (int i = 21; i > (dac1.Count == 0 ? 1 : dac1.Count) + 6; i--)
  2974. {
  2975. table1.Rows.RemoveAt(i - 1);
  2976. foodandotherStartIndex--;
  2977. }
  2978. if (dac2.Count == dac3.Count)//国家 币种 金额
  2979. {
  2980. for (int i = 0; i < dac2.Count; i++)
  2981. {
  2982. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  2983. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  2984. }
  2985. }
  2986. decimal dac2totalPrice = 0.00M;
  2987. foreach (var dac in dac2)
  2988. {
  2989. if (dac.SubTotal == 0)
  2990. {
  2991. continue;
  2992. }
  2993. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  2994. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));
  2995. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  2996. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknown";
  2997. builder.Write(currency);//币种
  2998. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  2999. builder.Write(dac.Cost.ToString("#0.00"));//标准
  3000. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  3001. builder.Write("");//人数
  3002. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  3003. builder.Write("");//天数
  3004. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  3005. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  3006. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  3007. decimal rate = 0.00M;
  3008. rate = rateDatas.Find(it => it.CurrencyName.Equals(currency))?.Rate ?? 0.00M;
  3009. builder.Write(rate.ToString("#0.0000"));//汇率
  3010. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  3011. decimal rbmPrice = dac.SubTotal;
  3012. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  3013. foodandotherStartIndex++;
  3014. dac2totalPrice += Convert.ToDecimal(rbmPrice.ToString("#0.00"));
  3015. }
  3016. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  3017. for (int i = foodandotherStartIndex + (15 - dac2.Count); i > (dac2.Count == 0 ? 1 : 0) + foodandotherStartIndex; i--)
  3018. {
  3019. table1.Rows.RemoveAt(i - 1);
  3020. }
  3021. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  3022. string otherFeeStr = "";
  3023. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费: {_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  3024. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费: {_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  3025. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  3026. if (otherFeeStr.Length > 0)
  3027. {
  3028. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  3029. otherFeeStr = $"({otherFeeStr})";
  3030. dic.Add("OtherFeeStr", otherFeeStr);
  3031. }
  3032. //总计
  3033. decimal allPrice = dac1totalPrice + dac2totalPrice + _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket;
  3034. //国际旅费
  3035. string outsideJJ = "";
  3036. string allPriceJJ = "";
  3037. if (_EnterExitCosts.SumJJC == 1)
  3038. {
  3039. outsideJJ = string.Format(@"经济舱:{0} 元/人", _EnterExitCosts.AirJJ.ToString("#0.00"));
  3040. allPriceJJ = string.Format(@"经济舱:{0} 元/人", (allPrice + _EnterExitCosts.OutsideJJPay).ToString("#0.00"));
  3041. }
  3042. string outsideGW = "";
  3043. string allPriceGW = "";
  3044. if (_EnterExitCosts.SumGWC == 1)
  3045. {
  3046. outsideGW = string.Format(@"公务舱:{0} 元/人", _EnterExitCosts.AirGW.ToString("#0.00"));
  3047. allPriceGW = string.Format(@"公务舱:{0} 元/人", (allPrice + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  3048. }
  3049. if (_EnterExitCosts.SumJJC == 1 || _EnterExitCosts.SumGWC == 1)
  3050. {
  3051. string InTravelPriceStr = string.Format(@" ({0} {1})", outsideJJ, outsideGW);
  3052. dic.Add("InTravelPrice", InTravelPriceStr);
  3053. string FinalSumPriceStr = string.Format(@" ({0} {1})", allPriceJJ, allPriceGW);
  3054. dic.Add("FinalSumPrice", FinalSumPriceStr);
  3055. }
  3056. //dic.Add("VisaPay", _EnterExitCosts.Visa.ToString("#0.00"));
  3057. //dic.Add("SafePay", _EnterExitCosts.Safe.ToString("#0.00"));
  3058. //dic.Add("YiMiao", _EnterExitCosts.YiMiao.ToString("#0.00"));
  3059. foreach (var key in dic.Keys)
  3060. {
  3061. builder.MoveToBookmark(key);
  3062. builder.Write(dic[key]);
  3063. }
  3064. //模板文件名
  3065. string strFileName = $"{_DelegationInfo.TeamName}因公出国(境)经费测算明细表.docx";
  3066. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3067. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3068. _view.Data = new { Url = url };
  3069. _view.Msg = "成功";
  3070. return _view;
  3071. }
  3072. else if (dto.SubTypeId == 1007) //1007(四川省商务厅出国经费财政先行审核表)
  3073. {
  3074. //获取模板
  3075. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/四川省商务厅出国经费财政先行审核表.xls");
  3076. //载入模板
  3077. WorkbookDesigner designer = new WorkbookDesigner();
  3078. designer.Workbook = new Workbook(tempPath);
  3079. Dictionary<string, string> dic = new Dictionary<string, string>();
  3080. if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  3081. {
  3082. List<string> list = new List<string>();
  3083. try
  3084. {
  3085. var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  3086. foreach (var item in spilitArr)
  3087. {
  3088. var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  3089. var depCode = spDotandEmpty[2].Substring(0, 3);
  3090. var arrCode = spDotandEmpty[2].Substring(3, 3);
  3091. string depName = threeCodes.Find(it => it.Three.Equals(depCode))?.City ?? "Unknwon",
  3092. arrName = threeCodes.Find(it => it.Three.Equals(arrCode))?.City ?? "Unknown";
  3093. list.Add(depName);
  3094. list.Add(arrName);
  3095. }
  3096. list = list.Distinct().ToList();
  3097. dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  3098. }
  3099. catch (Exception)
  3100. {
  3101. dic.Add("ReturnCode", "行程录入不正确!");
  3102. }
  3103. }
  3104. else
  3105. {
  3106. dic.Add("ReturnCode", "未录入行程!");
  3107. }
  3108. dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  3109. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  3110. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  3111. if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  3112. {
  3113. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  3114. dic.Add("Day", sp.Days.ToString());
  3115. }
  3116. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  3117. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  3118. var Names = string.Join("、", DeleClientList.Select(it => it.Name).ToList()).TrimEnd('、');
  3119. designer.SetDataSource("ClientUnit", _DelegationInfo.ClientUnit);
  3120. designer.SetDataSource("VisitCountry", _DelegationInfo.VisitCountry);
  3121. designer.SetDataSource("Group", _DelegationInfo.TeamName);
  3122. designer.SetDataSource("ClientUnitTitle", _DelegationInfo.TeamName);
  3123. designer.SetDataSource("Name", Names);
  3124. designer.SetDataSource("VisitStartDate", dic["VisitStartDate"] + "-" + dic["VisitEndDate"]);
  3125. designer.SetDataSource("Day", dic["Day"] + "天");
  3126. designer.SetDataSource("ReturnCode", dic["ReturnCode"]);
  3127. designer.SetDataSource("ReturnCodeAir", dic["ReturnCodeAir"]);
  3128. int startIndex = 10;
  3129. const int startIndexcopy = 10;
  3130. if (dac2.Count == dac3.Count)//国家 币种 金额
  3131. {
  3132. for (int i = 0; i < dac2.Count; i++)
  3133. {
  3134. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  3135. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  3136. }
  3137. }
  3138. DataTable dtdac1 = new DataTable();
  3139. List<string> place = new List<string>();
  3140. dtdac1.Columns.AddRange(new DataColumn[] {
  3141. new DataColumn(){ ColumnName = "city"},
  3142. new DataColumn(){ ColumnName = "curr"},
  3143. new DataColumn(){ ColumnName = "criterion"},
  3144. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  3145. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  3146. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  3147. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  3148. new DataColumn(){ ColumnName = "costRMB", DataType = typeof(decimal) },
  3149. });
  3150. DataTable dtdac2 = new DataTable();
  3151. dtdac2.Columns.AddRange(new DataColumn[] {
  3152. new DataColumn(){ ColumnName = "city"},
  3153. new DataColumn(){ ColumnName = "curr"},
  3154. new DataColumn(){ ColumnName = "criterion"},
  3155. new DataColumn(){ ColumnName = "number",DataType = typeof(int)},
  3156. new DataColumn(){ ColumnName = "day",DataType = typeof(int)},
  3157. new DataColumn(){ ColumnName = "cost", DataType = typeof(decimal)},
  3158. new DataColumn(){ ColumnName = "rate", DataType = typeof(decimal) },
  3159. new DataColumn(){ ColumnName = "costRMB",DataType = typeof(decimal)},
  3160. });
  3161. dtdac1.TableName = "tb1";
  3162. dtdac2.TableName = "tb2";
  3163. decimal dac1totalPrice = 0.00M, dac2totalPrice = 0.00M;
  3164. foreach (var item in dac1)
  3165. {
  3166. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  3167. if (place.Contains(item.Place))
  3168. {
  3169. continue;
  3170. }
  3171. DataRow row = dtdac1.NewRow();
  3172. row["city"] = item.Place;
  3173. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  3174. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  3175. row["curr"] = currency;
  3176. row["rate"] = rate.ToString("#0.0000");
  3177. row["criterion"] = item.Cost.ToString("#0.00");
  3178. row["number"] = 1;
  3179. row["day"] = dac1.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  3180. //row["costRMB"] = rbmPrice;
  3181. dtdac1.Rows.Add(row);
  3182. place.Add(item.Place);
  3183. }
  3184. place = new List<string>();
  3185. foreach (var item in dac2)
  3186. {
  3187. item.Place = GetEnterExitCostExportCity(placeData, item.NationalTravelFeeId);
  3188. if (place.Contains(item.Place))
  3189. {
  3190. continue;
  3191. }
  3192. DataRow row = dtdac2.NewRow();
  3193. row["city"] = item.Place;
  3194. string currency = _CurrDatas.Find(it => it.Id == item.Currency)?.Remark ?? "Unknwon";
  3195. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  3196. row["curr"] = currency;
  3197. row["rate"] = rate.ToString("#0.0000");
  3198. row["criterion"] = item.Cost.ToString("#0.00");
  3199. row["number"] = 1;
  3200. row["day"] = dac2.FindAll(x => x.NationalTravelFeeId == item.NationalTravelFeeId).Count;
  3201. //row["cost"] = item.SubTotal;
  3202. //row["costRMB"] = rbmPrice;
  3203. dtdac2.Rows.Add(row);
  3204. place.Add(item.Place);
  3205. //dac2totalPrice += rbmPrice;
  3206. }
  3207. dac1totalPrice = dac1.Sum(it => it.SubTotal);
  3208. dac2totalPrice = dac2.Sum(it => it.SubTotal);
  3209. designer.SetDataSource("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  3210. designer.SetDataSource("dac2totalPrice", dac2totalPrice);
  3211. designer.SetDataSource("cityTranffic", @$"其中:国外城市间机票费: {_EnterExitCosts.CityTranffic.ToString("#0.00")} 元");
  3212. designer.SetDataSource("sumCityTranffic", @$"{_EnterExitCosts.CityTranffic.ToString("#0.00")} ");
  3213. string cell4Str = $" 4.国际旅费:经济舱:{_EnterExitCosts.AirJJ.ToString("#0.00")} 元/人,公务舱:{_EnterExitCosts.AirGW.ToString("#0.00")} 元/人";
  3214. string cellStr = $" 5.其他费用(";
  3215. if (_EnterExitCosts.Visa > 0) cellStr += $"签证费:{_EnterExitCosts.Visa.ToString("#0.00")}元,";
  3216. if (_EnterExitCosts.YiMiao > 0) cellStr += $"疫苗费:{_EnterExitCosts.YiMiao.ToString("#0.00")}元,";
  3217. if (_EnterExitCosts.HeSuan > 0) cellStr += $"核酸费:{_EnterExitCosts.HeSuan.ToString("#0.00")}元,";
  3218. if (_EnterExitCosts.Safe > 0) cellStr += $"保险费:{_EnterExitCosts.Safe.ToString("#0.00")}元,";
  3219. if (_EnterExitCosts.Ticket > 0) cellStr += $"参展门票费:{_EnterExitCosts.Ticket.ToString("#0.00")}元,";
  3220. if (_EnterExitCosts.Service > 0) cellStr += $"服务费:{_EnterExitCosts.Service.ToString("#0.00")}元,";
  3221. if (cellStr.Length > 8)
  3222. {
  3223. cellStr = cellStr.Substring(0, cellStr.Length - 1);
  3224. }
  3225. cellStr += ")";
  3226. decimal otherFee = _EnterExitCosts.Visa + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.Service;
  3227. decimal s = dac1totalPrice + dac2totalPrice + _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay + otherFee;
  3228. decimal pxFee = dac4.Sum(it => it.Cost);
  3229. decimal glvFee = _EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay;
  3230. string celllastStr1 = "";
  3231. if (dac1totalPrice > 0) celllastStr1 += $"住宿费 {dac1totalPrice.ToString("#0.00")} 元";
  3232. if (dac2totalPrice > 0) celllastStr1 += $",伙食费和公杂费 {dac2totalPrice.ToString("#0.00")} 元";
  3233. if (pxFee > 0) celllastStr1 += $",培训费 {pxFee.ToString("#0.00")} 元";
  3234. celllastStr1 += $",国际旅费 元";
  3235. if (otherFee > 0) celllastStr1 += $",其他费用 {otherFee.ToString("#0.00")} 元";
  3236. string celllastStr = $" 经审核,{celllastStr1},本次出国经费预算合计为 元。其中:市本级安排 。";
  3237. designer.SetDataSource("cell4Str", cell4Str);
  3238. designer.SetDataSource("cellStr", cellStr);
  3239. designer.SetDataSource("cellSum", (_EnterExitCosts.Visa + _EnterExitCosts.Safe).ToString("#0.00"));
  3240. designer.SetDataSource("cellSum4", (_EnterExitCosts.OutsideJJPay + _EnterExitCosts.OutsideGWPay).ToString("#0.00"));
  3241. designer.SetDataSource("celllastStr", celllastStr);
  3242. Workbook wb = designer.Workbook;
  3243. var sheet = wb.Worksheets[0];
  3244. //绑定datatable数据集
  3245. designer.SetDataSource(dtdac1);
  3246. designer.SetDataSource(dtdac2);
  3247. designer.Process();
  3248. var rowStart = dtdac1.Rows.Count;
  3249. while (rowStart > 0)
  3250. {
  3251. sheet.Cells[startIndex, 8].Formula = $"=G{startIndex + 1} * H{startIndex + 1}";
  3252. sheet.Cells[startIndex, 6].Formula = $"=E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  3253. startIndex++;
  3254. rowStart--;
  3255. }
  3256. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + 1}: I{startIndex})";
  3257. startIndex += 1; //总计行
  3258. rowStart = dtdac2.Rows.Count;
  3259. while (rowStart > 0)
  3260. {
  3261. sheet.Cells[startIndex, 8].Formula = $"= G{startIndex + 1} * H{startIndex + 1}";
  3262. sheet.Cells[startIndex, 6].Formula = $"= E{startIndex + 1} * F{startIndex + 1} * D{startIndex + 1}";
  3263. startIndex++;
  3264. rowStart--;
  3265. }
  3266. sheet.Cells[startIndex, 8].Formula = $"=SUM(I{startIndexcopy + dtdac1.Rows.Count + 2}: I{startIndex})";
  3267. wb.CalculateFormula(true);
  3268. //模板文件名
  3269. string strFileName = $"{_DelegationInfo.TeamName}-四川省商务厅出国经费财政先行审核表{DateTime.Now.ToString("yyyyMMddHHmmss")}.xls"; ;//$".xls";
  3270. designer.Workbook.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3271. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3272. _view.Data = new { Url = url };
  3273. _view.Msg = "成功";
  3274. return _view;
  3275. }
  3276. else if (dto.SubTypeId == 1066) //成都市因公临时出国任务和预算审批意见表(外专培训团专用)
  3277. {
  3278. //获取模板
  3279. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/成都市因公临时出国任务和预算审批意见表.docx");
  3280. //载入模板
  3281. Document doc = new Document(tempPath);
  3282. DocumentBuilder builder = new DocumentBuilder(doc);
  3283. Dictionary<string, string> dic = new Dictionary<string, string>();
  3284. dic.Add("GroupName", _DelegationInfo.TeamName);
  3285. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  3286. string missionLeader = ""; //团负责人默认接团客户名单第一个人
  3287. string missionLeaderJob = "";//负责人job
  3288. int groupNumber = 0; //团人数
  3289. if (DeleClientList.Count > 0)
  3290. {
  3291. missionLeader = DeleClientList[0]?.Name ?? "";
  3292. missionLeaderJob = DeleClientList[0]?.Job ?? "";
  3293. }
  3294. dic.Add("MissionLeader", missionLeader); //团负责人
  3295. dic.Add("MissionLeaderJob", missionLeaderJob); //团负责人job
  3296. dic.Add("GroupNumber", _DelegationInfo.VisitPNumber.ToString()); //团人数
  3297. #region MyRegion
  3298. //if (blackCode != null && !string.IsNullOrWhiteSpace(blackCode.BlackCode))
  3299. //{
  3300. // List<string> list = new List<string>();
  3301. // try
  3302. // {
  3303. // var spilitArr = Regex.Split(blackCode.BlackCode, "\r\n");
  3304. // foreach (var item in spilitArr)
  3305. // {
  3306. // var spDotandEmpty = item.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  3307. // var depCode = spDotandEmpty[2].Substring(0, 3);
  3308. // var arrCode = spDotandEmpty[2].Substring(3, 3);
  3309. // string depName = threeCodes.Find(it => it.Three.Equals(depCode)).City,
  3310. // arrName = threeCodes.Find(it => it.Three.Equals(arrCode)).City;
  3311. // list.Add(depName);
  3312. // list.Add(arrName);
  3313. // }
  3314. // list = list.Distinct().ToList();
  3315. // dic.Add("ReturnCode", string.Join("-", list).TrimEnd('-'));
  3316. // }
  3317. // catch (Exception)
  3318. // {
  3319. // dic.Add("ReturnCode", "行程录入不正确!");
  3320. // }
  3321. //}
  3322. //else
  3323. //{
  3324. // dic.Add("ReturnCode", "未录入行程!");
  3325. //}
  3326. List<string> countrys = _dirRep.GroupSplitCountry(_DelegationInfo.VisitCountry);
  3327. dic.Add("ReturnCode", string.Join("、", countrys));
  3328. #endregion
  3329. //dic.Add("ReturnCodeAir", dic["ReturnCode"]);
  3330. //dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  3331. //dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  3332. //if (dic.ContainsKey("VisitStartDate") && dic.ContainsKey("VisitEndDate"))
  3333. //{
  3334. // TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  3335. // dic.Add("Day", sp.Days.ToString());
  3336. //}
  3337. dic.Add("Day", _DelegationInfo.VisitDays.ToString());
  3338. dic.Add("CultivateDay", dac4.Count.ToString()); //培训天数
  3339. // dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  3340. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  3341. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  3342. //培训人员名单
  3343. int cultivateRowIndex = 7;
  3344. foreach (var item in DeleClientList)
  3345. {
  3346. builder.MoveToCell(0, cultivateRowIndex, 0, 0);
  3347. builder.Write(item.Name);
  3348. builder.MoveToCell(0, cultivateRowIndex, 1, 0);
  3349. builder.Write(item.Sex == 0 ? "男" : item.Sex == 1 ? "女" : "");
  3350. builder.MoveToCell(0, cultivateRowIndex, 2, 0);
  3351. string birthDay = "";
  3352. if (item.Birthday != null)
  3353. {
  3354. DateTime dt = Convert.ToDateTime(item.Birthday);
  3355. birthDay = $"{dt.Year}.{dt.Month}";
  3356. }
  3357. builder.Write(birthDay);
  3358. builder.MoveToCell(0, cultivateRowIndex, 3, 0);
  3359. builder.Write(item.Company);
  3360. builder.MoveToCell(0, cultivateRowIndex, 4, 0);
  3361. builder.Write(item.Job);
  3362. cultivateRowIndex++;
  3363. }
  3364. //删除多余行
  3365. //cultivateRowIndex -= 2;
  3366. int delRows = 10 + 7 - cultivateRowIndex;
  3367. if (delRows > 0)
  3368. {
  3369. for (int i = 0; i < delRows; i++)
  3370. {
  3371. table1.Rows.RemoveAt(cultivateRowIndex);
  3372. //cultivateRowIndex++;
  3373. }
  3374. }
  3375. decimal hotelFeeTotal = dac1.Sum(it => it.SubTotal);//住宿费
  3376. dic.Add("HotelFeeTotal", hotelFeeTotal.ToString("#0.00"));
  3377. decimal mealsFeeTotal = dac2.Sum(it => it.SubTotal);//伙食费
  3378. dic.Add("MealsFeeTotal", mealsFeeTotal.ToString("#0.00"));
  3379. decimal miscellaneousFeeTotal = dac3.Sum(it => it.SubTotal);//公杂费
  3380. dic.Add("MiscellaneousFeeTotal", miscellaneousFeeTotal.ToString("#0.00"));
  3381. decimal trainingFeeTotal = dac4.Sum(it => it.SubTotal);//培训费
  3382. dic.Add("TrainingFeeTotal", trainingFeeTotal.ToString("#0.00"));
  3383. decimal cityTranfficFeeToatal = _EnterExitCosts.CityTranffic; //城市区间交通费
  3384. dic.Add("CityTranfficFeeToatal", cityTranfficFeeToatal.ToString("#0.00"));//
  3385. //其他费用
  3386. decimal otherFeeTotal = _EnterExitCosts.Visa + _EnterExitCosts.Safe + _EnterExitCosts.Ticket + _EnterExitCosts.YiMiao + _EnterExitCosts.HeSuan + _EnterExitCosts.Service;
  3387. dic.Add("OtherFeeTotal", otherFeeTotal.ToString("#0.00"));
  3388. //其他费用合计
  3389. decimal _otherFeeTotal = hotelFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + trainingFeeTotal + cityTranfficFeeToatal + otherFeeTotal;
  3390. decimal _jjcFeeToatal = _EnterExitCosts.AirJJ + _otherFeeTotal; //经济舱
  3391. decimal _gwcFeeToatal = _EnterExitCosts.AirGW + _otherFeeTotal; //公务舱
  3392. //公务舱合计
  3393. //国际旅费
  3394. string outsideJJ = "";
  3395. string allPriceJJ = "";
  3396. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 0)
  3397. {
  3398. dic.Add("AirFeeTotal", _EnterExitCosts.AirJJ.ToString("#0.00"));
  3399. dic.Add("FeeTotal", _jjcFeeToatal.ToString("#0.00"));
  3400. }
  3401. if (_EnterExitCosts.SumGWC == 1 && _EnterExitCosts.SumJJC == 0)
  3402. {
  3403. dic.Add("AirFeeTotal", _EnterExitCosts.AirGW.ToString("#0.00"));
  3404. dic.Add("FeeTotal", _gwcFeeToatal.ToString("#0.00"));
  3405. }
  3406. if (_EnterExitCosts.SumJJC == 1 && _EnterExitCosts.SumGWC == 1)
  3407. {
  3408. string airFeeTotalStr = string.Format(@$"经济舱:{_EnterExitCosts.AirJJ.ToString("#0.00")} 公务舱:{_EnterExitCosts.AirGW.ToString("#0.00")}");
  3409. dic.Add("AirFeeTotal", airFeeTotalStr);
  3410. string feeTotalStr = string.Format(@$"经济舱:{_jjcFeeToatal.ToString("#0.00")} 公务舱:{_gwcFeeToatal.ToString("#0.00")}");
  3411. dic.Add("FeeTotal", feeTotalStr);
  3412. }
  3413. foreach (var key in dic.Keys)
  3414. {
  3415. builder.MoveToBookmark(key);
  3416. builder.Write(dic[key]);
  3417. }
  3418. //模板文件名
  3419. string strFileName = $"{_DelegationInfo.TeamName}-成都市因公临时出国任务和预算审批意见表(外专培训团专用).docx";
  3420. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3421. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3422. _view.Data = new { Url = url };
  3423. _view.Msg = "成功";
  3424. return _view;
  3425. }
  3426. }
  3427. else if (dto.ExportType == 2) //表格
  3428. {
  3429. //利用键值对存放数据
  3430. Dictionary<string, string> dic = new Dictionary<string, string>();
  3431. dic.Add("VisitStartDate", _DelegationInfo.VisitStartDate.ToString("yyyy年MM月dd日"));
  3432. dic.Add("VisitEndDate", _DelegationInfo.VisitEndDate.ToString("yyyy年MM月dd日"));
  3433. TimeSpan sp = _DelegationInfo.VisitEndDate.Subtract(_DelegationInfo.VisitStartDate);
  3434. dic.Add("Day", sp.Days.ToString());
  3435. dic.Add("VisitCountry", _DelegationInfo.VisitCountry);
  3436. if (dto.SubTypeId == 1008) //1008(派员单位出(境)任务和预算审批意见表)
  3437. {
  3438. //获取模板
  3439. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/派员单位出(境)任务和预算审批意见表.docx");
  3440. //载入模板
  3441. Document doc = new Document(tempPath);
  3442. DocumentBuilder builder = new DocumentBuilder(doc);
  3443. dic.Add("TeamName", _DelegationInfo.TeamName);
  3444. dic.Add("ClientUnit", _DelegationInfo.ClientUnit);
  3445. //dic.Add("TellPhone", _DelegationInfo.TellPhone);
  3446. string missionLeaderName = "",
  3447. missionLeaderJob = "";
  3448. if (DeleClientList.Count > 0)
  3449. {
  3450. missionLeaderName = DeleClientList[0].Name;
  3451. missionLeaderJob = DeleClientList[0].Job;
  3452. }
  3453. dic.Add("MissionLeaderName", missionLeaderName);
  3454. dic.Add("MissionLeaderJob", missionLeaderJob);
  3455. dic.Add("VisitPNumber", _DelegationInfo.VisitPNumber.ToString());
  3456. dic.Add("VisitPurpose", _DelegationInfo.VisitPurpose);
  3457. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  3458. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  3459. int rowCount = 10;//总人数行
  3460. int startRowIndex = 7; //起始行
  3461. for (int i = 0; i < DeleClientList.Count; i++)
  3462. {
  3463. builder.MoveToCell(0, startRowIndex, 0, 0);
  3464. builder.Write(DeleClientList[i].Name); //出国人员姓名
  3465. builder.MoveToCell(0, startRowIndex, 1, 0);
  3466. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  3467. builder.Write(sex);//性别
  3468. builder.MoveToCell(0, startRowIndex, 2, 0);
  3469. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));//出生年月
  3470. builder.MoveToCell(0, startRowIndex, 3, 0);
  3471. builder.Write(DeleClientList[i].Company);//工作单位
  3472. builder.MoveToCell(0, startRowIndex, 4, 0);
  3473. builder.Write(DeleClientList[i].Job);//职务及级别
  3474. builder.MoveToCell(0, startRowIndex, 5, 0);
  3475. builder.Write("");//人员属性
  3476. builder.MoveToCell(0, startRowIndex, 6, 0);
  3477. builder.Write("");//上次出国时间
  3478. startRowIndex++;
  3479. }
  3480. int nullRow = rowCount - DeleClientList.Count;//空行
  3481. for (int i = 0; i < nullRow; i++)
  3482. {
  3483. table1.Rows.Remove(table1.Rows[startRowIndex]);
  3484. }
  3485. foreach (var key in dic.Keys)
  3486. {
  3487. builder.MoveToBookmark(key);
  3488. builder.Write(dic[key]);
  3489. }
  3490. //模板文件名
  3491. string strFileName = $"派员单位出(境)任务和预算审批意见表.docx";
  3492. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3493. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3494. _view.Data = new { Url = url };
  3495. _view.Msg = "成功";
  3496. return _view;
  3497. }
  3498. else if (dto.SubTypeId == 1009)//1009(省级单位出(境)经费报销单)
  3499. {
  3500. //获取模板
  3501. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/省级单位出(境)经费报销单.docx");
  3502. //载入模板
  3503. Document doc = new Document(tempPath);
  3504. DocumentBuilder builder = new DocumentBuilder(doc);
  3505. dic.Add("GroupClient", _DelegationInfo.ClientUnit);
  3506. var Names = string.Join("、", DeleClientList.Select(x => x.Name)).TrimEnd('、');
  3507. dic.Add("Names", Names);
  3508. int accommodationRows = 12, foodandotherRows = 12;
  3509. var Dac1currCn = dac1.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  3510. var Dac2currCn = dac2.GroupBy(x => x.Currency).Select(x => x.Key).ToList();
  3511. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  3512. Aspose.Words.Tables.Table table1 = allTables[0] as Aspose.Words.Tables.Table;
  3513. int accommodationStartIndex = 6;
  3514. decimal dac1totalPrice = 0.00M;
  3515. foreach (var dac in dac1)
  3516. {
  3517. if (dac.SubTotal == 0)
  3518. {
  3519. continue;
  3520. }
  3521. //builder.MoveToCell(0, accommodationStartIndex, 0, 0);
  3522. //builder.Write(DeleClientList[i].LastName + DeleClientList[i].Name);
  3523. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  3524. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  3525. builder.MoveToCell(0, accommodationStartIndex, 2, 0);
  3526. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  3527. builder.Write(currency);//币种
  3528. builder.MoveToCell(0, accommodationStartIndex, 3, 0);
  3529. builder.Write(dac.Cost.ToString("#0.00"));//标准
  3530. builder.MoveToCell(0, accommodationStartIndex, 4, 0);
  3531. builder.Write("");//人数
  3532. builder.MoveToCell(0, accommodationStartIndex, 5, 0);
  3533. builder.Write("");//天数
  3534. builder.MoveToCell(0, accommodationStartIndex, 6, 0);
  3535. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  3536. builder.MoveToCell(0, accommodationStartIndex, 7, 0);
  3537. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  3538. builder.Write(rate.ToString("#0.0000"));//汇率
  3539. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  3540. decimal rbmPrice = rate * dac.SubTotal;
  3541. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  3542. accommodationStartIndex++;
  3543. dac1totalPrice += rbmPrice;
  3544. }
  3545. dic.Add("dac1totalPrice", dac1totalPrice.ToString("#0.00"));
  3546. builder.MoveToCell(0, accommodationStartIndex, 1, 0);
  3547. builder.Write("小计");
  3548. builder.MoveToCell(0, accommodationStartIndex, 8, 0);
  3549. builder.Write(dac1totalPrice.ToString("#0.00"));
  3550. accommodationStartIndex++;
  3551. int nullRow = accommodationRows - dac1.Count;
  3552. //删除空行
  3553. //if (nullRow > 0)
  3554. //{
  3555. // int rowIndex = accommodationStartIndex;
  3556. // for (int i = 0; i < nullRow; i++)
  3557. // {
  3558. // Row row = table1.Rows[rowIndex];
  3559. // row.Remove();
  3560. // rowIndex++;
  3561. // }
  3562. //}
  3563. if (dac2.Count == dac3.Count)//国家 币种 金额
  3564. {
  3565. for (int i = 0; i < dac2.Count; i++)
  3566. {
  3567. dac2[i].SubTotal = dac2[i].SubTotal + dac3[i].SubTotal; //小计
  3568. dac2[i].Cost = dac3[i].Cost + dac2[i].Cost; //标准
  3569. }
  3570. }
  3571. int foodandotherStartIndex = 19;//
  3572. decimal dac2totalPrice = 0.00M;
  3573. foreach (var dac in dac2)
  3574. {
  3575. if (dac.SubTotal == 0)
  3576. {
  3577. continue;
  3578. }
  3579. //foodandotherStartIndex = 12;
  3580. builder.MoveToCell(0, foodandotherStartIndex, 1, 0);
  3581. builder.Write(GetEnterExitCostExportCity(placeData, dac.NationalTravelFeeId));//城市
  3582. builder.MoveToCell(0, foodandotherStartIndex, 2, 0);
  3583. string currency = _CurrDatas.Find(it => it.Id == dac.Currency)?.Remark ?? "Unknwon";
  3584. builder.Write(currency);//币种
  3585. builder.MoveToCell(0, foodandotherStartIndex, 3, 0);
  3586. builder.Write(dac.Cost.ToString("#0.00"));//标准
  3587. builder.MoveToCell(0, foodandotherStartIndex, 4, 0);
  3588. builder.Write("");//人数
  3589. builder.MoveToCell(0, foodandotherStartIndex, 5, 0);
  3590. builder.Write("");//天数
  3591. builder.MoveToCell(0, foodandotherStartIndex, 6, 0);
  3592. builder.Write(dac.SubTotal.ToString("#0.00"));//小计
  3593. builder.MoveToCell(0, foodandotherStartIndex, 7, 0);
  3594. decimal rate = rateDatas.Find(it => it.CurrencyName == currency)?.Rate ?? 0.00M;
  3595. builder.Write(rate.ToString("#0.0000"));//汇率
  3596. builder.MoveToCell(0, foodandotherStartIndex, 8, 0);
  3597. decimal rbmPrice = rate * dac.SubTotal;
  3598. builder.Write(rbmPrice.ToString("#0.00"));//折合人民币
  3599. foodandotherStartIndex++;
  3600. dac2totalPrice += rbmPrice;
  3601. }
  3602. dic.Add("dac2totalPrice", dac2totalPrice.ToString("#0.00"));
  3603. //删除空行
  3604. if (dac2.Count < foodandotherRows)
  3605. {
  3606. //int nullRow = accommodationRows - dac2.Count;
  3607. //while (table2.Rows.Count > dac2.Count)
  3608. //{
  3609. // table2.Rows.RemoveAt(dac2.Count);
  3610. //}
  3611. }
  3612. dic.Add("CityTranffic", _EnterExitCosts.CityTranffic.ToString("#0.00"));
  3613. string otherFeeStr = "";
  3614. if (_EnterExitCosts.Visa > 0) otherFeeStr += $"签证费: {_EnterExitCosts.Visa.ToString("#0.00")} 元,";
  3615. if (_EnterExitCosts.Safe > 0) otherFeeStr += $"保险费: {_EnterExitCosts.Safe.ToString("#0.00")} 元,";
  3616. if (_EnterExitCosts.Ticket > 0) otherFeeStr += $"参展门票费: {_EnterExitCosts.Ticket.ToString("#0.00")} 元,";
  3617. if (otherFeeStr.Length > 0)
  3618. {
  3619. otherFeeStr = otherFeeStr.Substring(0, otherFeeStr.Length - 1);
  3620. otherFeeStr = $"({otherFeeStr})";
  3621. dic.Add("OtherFeeStr", otherFeeStr);
  3622. }
  3623. foreach (var key in dic.Keys)
  3624. {
  3625. builder.MoveToBookmark(key);
  3626. builder.Write(dic[key]);
  3627. }
  3628. //模板文件名
  3629. string strFileName = $"省级单位出(境)经费报销单.docx";
  3630. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3631. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3632. _view.Data = new { Url = url };
  3633. _view.Msg = "成功";
  3634. return _view;
  3635. }
  3636. }
  3637. else if (dto.ExportType == 3)
  3638. {
  3639. if (dto.SubTypeId == 1) //团组成员名单
  3640. {
  3641. if (DeleClientList.Count < 1)
  3642. {
  3643. _view.Msg = "团组成员暂未录入!!!";
  3644. return _view;
  3645. }
  3646. //获取模板
  3647. string tempPath = (AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/Temp/dwon_团组人员列表模板.doc");
  3648. //载入模板
  3649. Document doc = new Document(tempPath);
  3650. DocumentBuilder builder = new DocumentBuilder(doc);
  3651. //获取word里所有表格
  3652. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  3653. //获取所填表格的序数
  3654. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  3655. var rowStart = tableOne.Rows[0]; //获取第1行
  3656. //循环赋值
  3657. for (int i = 0; i < DeleClientList.Count; i++)
  3658. {
  3659. builder.MoveToCell(0, i + 1, 0, 0);
  3660. builder.Write(DeleClientList[i].Name);
  3661. builder.MoveToCell(0, i + 1, 1, 0);
  3662. string sex = DeleClientList[i].Sex == 0 ? "男" : DeleClientList[i].Sex == 1 ? "女" : "";
  3663. builder.Write(sex);
  3664. builder.MoveToCell(0, i + 1, 2, 0);
  3665. builder.Write(Convert.ToDateTime(DeleClientList[i].Birthday).ToString("yyyy年MM月dd日"));
  3666. builder.MoveToCell(0, i + 1, 3, 0);
  3667. builder.Write(DeleClientList[i].Company);
  3668. builder.MoveToCell(0, i + 1, 4, 0);
  3669. builder.Write(DeleClientList[i].Job);
  3670. }
  3671. //删除多余行
  3672. while (tableOne.Rows.Count > DeleClientList.Count + 1)
  3673. {
  3674. tableOne.Rows.RemoveAt(DeleClientList.Count + 1);
  3675. }
  3676. string strFileName = $"{_DelegationInfo.TeamName}组团人员名单({DateTime.Now.ToString("yyyyMMddHHmmss")}).doc";
  3677. //C:/Server/File/OA2023/Office/Word/EnterExitCost/File/
  3678. //C:\Server\File\OA2023\Office\Word\EnterExitCost\File\
  3679. doc.Save(AppSettingsHelper.Get("WordBasePath") + "EnterExitCost/File/" + strFileName);
  3680. string url = AppSettingsHelper.Get("WordBaseUrl") + "Office/Word/EnterExitCost/File/" + strFileName;
  3681. _view.Data = new { Url = url };
  3682. _view.Msg = "成功";
  3683. return _view;
  3684. }
  3685. }
  3686. }
  3687. catch (Exception ex)
  3688. {
  3689. _view.Code = StatusCodes.Status500InternalServerError;
  3690. _view.Msg = ex.Message;
  3691. return _view;
  3692. }
  3693. return _view;
  3694. }
  3695. #endregion
  3696. }
  3697. }