GeneralMethod.cs 196 KB

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