GeneralMethod.cs 196 KB

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