GeneralMethod.cs 188 KB

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