GeneralMethod.cs 194 KB

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