GeneralMethod.cs 196 KB

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