GeneralMethod.cs 188 KB

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