GeneralMethod.cs 196 KB

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