GeneralMethod.cs 197 KB

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