GeneralMethod.cs 197 KB

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