GeneralMethod.cs 115 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887
  1. 
  2. using Microsoft.AspNetCore.SignalR;
  3. using Microsoft.International.Converters.PinYinConverter;
  4. using Microsoft.VisualBasic;
  5. using NPOI.HSSF.Util;
  6. using OASystem.API.OAMethodLib.Hub.HubClients;
  7. using OASystem.API.OAMethodLib.Hub.Hubs;
  8. using OASystem.API.OAMethodLib.JuHeAPI;
  9. using OASystem.API.OAMethodLib.SignalR.Hubs;
  10. using OASystem.Domain.Entities.Customer;
  11. using OASystem.Domain.Entities.District;
  12. using OASystem.Domain.Entities.Financial;
  13. using OASystem.Domain.Entities.Groups;
  14. using OASystem.Domain.ViewModels.Financial;
  15. using OASystem.Domain.ViewModels.Groups;
  16. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  17. using OASystem.Infrastructure.Repositories.CRM;
  18. using OASystem.Infrastructure.Repositories.Groups;
  19. using System.Data;
  20. using System.IdentityModel.Tokens.Jwt;
  21. using System.IO.Compression;
  22. using System.Security.Claims;
  23. using System.Web;
  24. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  25. namespace OASystem.API.OAMethodLib
  26. {
  27. public static class GeneralMethod
  28. {
  29. //团组信息
  30. private readonly static DelegationInfoRepository _dirRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  31. private readonly static TeamRateRepository _teamRateRep = AutofacIocManager.Instance.GetService<TeamRateRepository>();
  32. private readonly static IJuHeApiService _juHeApi = AutofacIocManager.Instance.GetService<IJuHeApiService>();
  33. private readonly static SetDataRepository _setDataRep = AutofacIocManager.Instance.GetService<SetDataRepository>();
  34. private readonly static TableOperationRecordRepository _tableOperationRecordRep = AutofacIocManager.Instance.GetService<TableOperationRecordRepository>();
  35. private readonly static MessageRepository _messageRep = AutofacIocManager.Instance.GetService<MessageRepository>();
  36. private readonly static IHubContext<ChatHub, IChatClient> _hubContext = AutofacIocManager.Instance.GetService<IHubContext<ChatHub, IChatClient>>();
  37. private readonly static string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  38. #region 员工注册默认添加基础页面
  39. /// <summary>
  40. /// 默认职位权限
  41. /// </summary>
  42. public static bool DefaultPostAuth(int depId, int postId, int userId, int createUserId)
  43. {
  44. if (depId < 1) return false;
  45. if (postId < 1) return false;
  46. if (userId < 1) return false;
  47. if (userId < 1) return false;
  48. List<DefaultPostPageAuthView> _defaultData = AppSettingsHelper.Get<DefaultPostPageAuthView>("DefaultPostPageData");
  49. if (_defaultData.Count < 1) return false;
  50. var postJobDatas = _dirRep._sqlSugar.Queryable<Sys_JobPost>().Where(it => it.IsDel == 0).ToList();
  51. List<int> pageData = new List<int>();
  52. //添加公司公共页面
  53. pageData.AddRange(_defaultData.Find(it => it.DepId == -1)?.PostPageAuths[0].PageIds ?? new List<int>());
  54. //添加部门页面
  55. var depPublicPageData = _defaultData.Find(it => it.DepId == depId);
  56. var jobPublicPageData = postJobDatas.Find(it => it.DepId == depId && it.Id == postId);
  57. if (depPublicPageData != null) //特殊部门
  58. {
  59. //公共页面
  60. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == -1)?.PageIds ?? new List<int>());
  61. if (depId == 7) //国交部特殊处理
  62. {
  63. List<string> postNames = new List<string>() { "主管", "经理" };
  64. //岗位页面
  65. if (jobPublicPageData != null)
  66. {
  67. if (postNames.Contains(jobPublicPageData.JobName))
  68. {
  69. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == 0)?.PageIds ?? new List<int>());
  70. }
  71. else
  72. {
  73. pageData.AddRange(depPublicPageData.PostPageAuths.Find(it => it.PostId == postId)?.PageIds ?? new List<int>());
  74. }
  75. }
  76. }
  77. }
  78. else //通用部门
  79. {
  80. pageData.AddRange(_defaultData.Find(it => it.DepId == 0)?.PostPageAuths[0].PageIds ?? new List<int>());
  81. }
  82. if (pageData.Count > 0)
  83. {
  84. //页面操作权限数据(添加修改等...)
  85. var pageFunctionData = _dirRep._sqlSugar.Queryable<Sys_SystemMenuAndFunction>().Where(it => pageData.Contains(it.SmId) && it.IsDel == 0).ToList();
  86. var defaultPageData = pageFunctionData.Select(it => new Sys_UserAuthority() {
  87. UId = userId,
  88. SmId = it.SmId,
  89. FId = it.FId,
  90. CreateUserId = createUserId, //管理员
  91. CreateTime = DateTime.Now,
  92. IsDel = 0,
  93. IsTemp = 1
  94. }).ToList();
  95. if (defaultPageData.Count > 0)
  96. {
  97. //移除每个页面的审核权限,审核权限需要单独开启
  98. defaultPageData = defaultPageData.Where(it => it.FId != 12).ToList();
  99. //添加页面操作权限
  100. var s = _dirRep._sqlSugar.Fastest<Sys_UserAuthority>().PageSize(100000).BulkCopy(defaultPageData);
  101. if (s > 0)
  102. {
  103. return true;
  104. }
  105. }
  106. }
  107. return false;
  108. }
  109. #endregion
  110. #region 消息
  111. /// <summary>
  112. /// 消息 发布And 通知
  113. /// </summary>
  114. /// <param name="msgTypeEnum">
  115. /// 消息类型
  116. /// 1 公告通知
  117. /// 2 团组流程管控通知
  118. /// 3 团组业务操作通知
  119. /// 4 团组费用审核消息
  120. /// 5 团组签证进度通知
  121. /// 6 团组任务进度通知
  122. /// </param>
  123. /// <param name="title">消息标题</param>
  124. /// <param name="content">消息内容</param>
  125. /// <param name="userIds"></param>
  126. /// <param name="diId">团组id</param>
  127. /// <param name="param">团组id</param>
  128. /// <returns></returns>
  129. public static async Task<bool> MessageIssueAndNotification(MessageTypeEnum msgTypeEnum, string title, string content, List<int> userIds, int diId = 0, string param = "")
  130. {
  131. MessageDto messageDto = new()
  132. {
  133. Type = msgTypeEnum,
  134. IssuerId = 4,//管理员
  135. DiId = diId,
  136. Title = title,
  137. Content = content,
  138. ReleaseTime = DateTime.Now,
  139. UIdList = userIds,
  140. Param = param
  141. };
  142. var status = await _messageRep.AddMsg(messageDto);//添加消息
  143. if (status)
  144. {
  145. //给在线在用户发送消息
  146. List<string> connIds = UserStore.OnlineUser.Where(it => userIds.Contains(it.UserId)).Select(it => it.ConnectionId).ToList();
  147. string notificationTypeStr1 = GetMsgNotificationType(msgTypeEnum);
  148. string notificationTypeStr = JsonConvert.SerializeObject(
  149. new
  150. {
  151. UserIds = userIds,
  152. Msg = $"您有一条{notificationTypeStr1}相关的消息!"
  153. }
  154. );
  155. await _hubContext.Clients.Clients(connIds).ReceiveMessage($"您有一条{notificationTypeStr1}相关的消息!");
  156. return true;
  157. }
  158. return false;
  159. }
  160. /// <summary>
  161. /// 根据消息类型 获取 消息通知类型
  162. /// </summary>
  163. /// <returns></returns>
  164. public static string GetMsgNotificationType(MessageTypeEnum msgTypeEnum)
  165. {
  166. int notificationType = 0;
  167. string notificationStr = "";
  168. List<NotificationTypeView> notificationTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  169. notificationType = notificationTypeViews.Where(it => it.MsgTypeIds.Contains((int)msgTypeEnum)).Select(it => it.TypeId).FirstOrDefault();
  170. if (notificationType == 1021) notificationStr = "操作";
  171. else if (notificationType == 1020) notificationStr = "任务";
  172. return notificationStr;
  173. }
  174. #endregion
  175. #region md5 加密
  176. /// <summary>
  177. /// MD5加密,和动网上的16/32位MD5加密结果相同,
  178. /// 使用的UTF8编码
  179. /// </summary>
  180. /// <param name="source">待加密字串</param>
  181. /// <param name="length">16或32值之一,其它则采用.net默认MD5加密算法</param>
  182. /// <returns>加密后的字串</returns>
  183. public static string Encrypt(string source, int length = 32)
  184. {
  185. if (string.IsNullOrWhiteSpace(source))
  186. return string.Empty;
  187. HashAlgorithm hashAlgorithm = CryptoConfig.CreateFromName("MD5") as HashAlgorithm;
  188. byte[] bytes = Encoding.UTF8.GetBytes(source);
  189. byte[] hashValue = hashAlgorithm.ComputeHash(bytes);
  190. StringBuilder sb = new StringBuilder();
  191. switch (length)
  192. {
  193. case 16://16位密文是32位密文的9到24位字符
  194. for (int i = 4; i < 12; i++)
  195. {
  196. sb.Append(hashValue[i].ToString("x2"));
  197. }
  198. break;
  199. case 32:
  200. for (int i = 0; i < 16; i++)
  201. {
  202. sb.Append(hashValue[i].ToString("x2"));
  203. }
  204. break;
  205. default:
  206. for (int i = 0; i < hashValue.Length; i++)
  207. {
  208. sb.Append(hashValue[i].ToString("x2"));
  209. }
  210. break;
  211. }
  212. return sb.ToString();
  213. }
  214. #endregion
  215. #region jwt
  216. /// <summary>
  217. /// 获取token
  218. /// </summary>
  219. /// <param name="_config"></param>
  220. /// <param name="Number"></param>
  221. /// <param name="exp"></param>
  222. /// <returns></returns>
  223. public static async Task<string> GetToken(IConfiguration _config, string Number, int uId, string uName, DateTime exp)
  224. {
  225. string userId = Guid.NewGuid().ToString().Replace("-", "");
  226. var claims = new[] {
  227. new Claim(ClaimTypes.NameIdentifier, uName),
  228. new Claim(ClaimTypes.NameIdentifier, uId.ToString()),
  229. new Claim(ClaimTypes.NameIdentifier, userId),
  230. new Claim("Number",Number)
  231. };
  232. var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["JwtSecurityKey"]));
  233. var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
  234. var token = new JwtSecurityToken(
  235. issuer: "OASystem.com",
  236. audience: "OASystem.com",
  237. claims: claims,
  238. expires: exp,
  239. signingCredentials: creds);
  240. var indentity = new ClaimsIdentity(claims, "formlogin");
  241. var principal = new ClaimsPrincipal(indentity);
  242. // await _httpContext.SignInAsync (CookieAuthenticationDefaults.AuthenticationScheme, principal);
  243. return new JwtSecurityTokenHandler().WriteToken(token);
  244. }
  245. #endregion
  246. #region 数据类型转换
  247. /// <summary>
  248. /// object 转 Int
  249. /// </summary>
  250. /// <param name="obj"></param>
  251. /// <returns></returns>
  252. public static int GetInt(this object obj)
  253. {
  254. if (obj == null)
  255. return 0;
  256. int _number = 0;
  257. bool reslut = Int32.TryParse(obj.ToString(), out _number);
  258. return _number;
  259. }
  260. private static DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
  261. private static long longTime = 621355968000000000;
  262. private static int samllTime = 10000000;
  263. /// <summary>
  264. /// 时间戳 转 datetime
  265. /// </summary>
  266. /// <param name="timeStamp"></param>
  267. /// <returns></returns>
  268. public static DateTime GetTimeSpmpToDate(this object timeStamp)
  269. {
  270. if (timeStamp == null) return dateStart;
  271. DateTime dateTime = new DateTime(longTime + Convert.ToInt64(timeStamp) * samllTime, DateTimeKind.Utc).ToLocalTime();
  272. return dateTime;
  273. }
  274. #endregion
  275. #region 用户页面操作功能 权限
  276. /// <summary>
  277. /// 用户页面操作功能(可使用)
  278. /// </summary>
  279. /// <param name="userId">用户Id</param>
  280. /// <param name="PageId">页面Id</param>
  281. /// <returns></returns>
  282. public static async Task<PageFunAuthViewBase> PostUserPageFuncDatas(int userId, int PageId)
  283. {
  284. PageFunAuthViewBase pageFunAuth = new PageFunAuthViewBase();
  285. List<UserPageFuncView> userPageFuncDatas = new List<UserPageFuncView>();
  286. string sql = string.Format(@"Select ua.UId As UserId, u.CnName As UserName, pa.ModuleId,pa.ModuleName,pa.PageId,pa.PageName,pa.PageIsEnable,
  287. pa.PagePhoneIsEnable,pa.FuncId,pa.FuncName,pa.FuncIsEnable
  288. From Sys_UserAuthority ua
  289. Left Join Sys_Users u On ua.UId = u.Id
  290. Left Join (
  291. Select sd.Id As ModuleId,sd.Name As ModuleName, smp.Id As PageId,smp.Name As PageName,smp.IsEnable As PageIsEnable,
  292. smp.phoneIsEnable As PagePhoneIsEnable,pfp.Id As FuncId,pfp.FunctionName As FuncName,pfp.IsEnable As FuncIsEnable
  293. From Sys_SystemMenuAndFunction smaf
  294. Left Join Sys_SystemMenuPermission smp On smaf.SmId = smp.Id
  295. Left Join Sys_SetData sd On sd.STid = 5 And smp.Mid = sd.Id
  296. Left Join Sys_PageFunctionPermission pfp On smaf.FId = pfp.Id
  297. Where smaf.IsDel = 0 And smp.IsDel = 0 And pfp.IsDel = 0 And sd.IsDel = 0 And smp.IsEnable = 1
  298. ) As pa On ua.SmId = pa.PageId And ua.FId = pa.FuncId
  299. Where ua.IsDel = 0 And ua.UId = {0} And pa.PageId = {1}
  300. Order By ModuleId,PageId,FuncId Asc", userId, PageId);
  301. userPageFuncDatas = await _dirRep._sqlSugar.SqlQueryable<UserPageFuncView>(sql).ToListAsync();
  302. if (userPageFuncDatas.Count <= 0)
  303. {
  304. return pageFunAuth;
  305. }
  306. UserPageFuncView userPageFunc = new UserPageFuncView();
  307. //查询 1
  308. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 1).FirstOrDefault();
  309. if (userPageFunc != null) pageFunAuth.CheckAuth = 1;
  310. //删除 2
  311. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 2).FirstOrDefault();
  312. if (userPageFunc != null) pageFunAuth.DeleteAuth = 1;
  313. //编辑 3
  314. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 3).FirstOrDefault();
  315. if (userPageFunc != null) pageFunAuth.EditAuth = 1;
  316. //下载 4
  317. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 4).FirstOrDefault();
  318. if (userPageFunc != null) pageFunAuth.FilesDownloadAuth = 1;
  319. //上传 5
  320. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 5).FirstOrDefault();
  321. if (userPageFunc != null) pageFunAuth.FilesUploadAuth = 1;
  322. //添加 11
  323. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 11).FirstOrDefault();
  324. if (userPageFunc != null) pageFunAuth.AddAuth = 1;
  325. //审核 12
  326. userPageFunc = userPageFuncDatas.Where(it => it.FuncId == 12).FirstOrDefault();
  327. if (userPageFunc != null) pageFunAuth.AuditAuth = 1;
  328. return pageFunAuth;
  329. }
  330. #endregion
  331. #region 业务模块 团组权限
  332. /// <summary>
  333. /// 业务模块 团组操作权限
  334. /// 验证 并返回可操作的团
  335. /// </summary>
  336. /// <param name="diId">团组Id</param>
  337. /// <param name="userId">用户Id</param>
  338. /// <param name="CTable">业务模块Id</param>
  339. /// <returns></returns>
  340. public static async Task<Result> PostGroupOperationAuth(int diId, int userId, int CTable)
  341. {
  342. Result _result = new Result { Code = -1, Msg = "No Operation Authorty!" };
  343. if (CTable < 1)
  344. {
  345. _result.Msg = "请填写正确的用户Id!";
  346. return _result;
  347. }
  348. var data = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.DIId == diId && it.UId == userId && it.CTId == CTable && it.IsDel == 0).First();
  349. if (data == null)
  350. {
  351. _result.Msg = "你没有本团下的该业务模块操作,请联系主管分配操作权限!";
  352. }
  353. else
  354. {
  355. _result.Code = 0;
  356. }
  357. return _result;
  358. }
  359. /// <summary>
  360. /// 业务模块 团组操作权限
  361. /// 返回可操作的团
  362. /// </summary>
  363. /// <param name="diId">团组Id</param>
  364. /// <param name="userId">用户Id</param>
  365. /// <param name="CTable">业务模块Id</param>
  366. /// <returns></returns>
  367. public static async Task<List<Web_ShareGroupInfoView>> PostOperationAuthReturnGroupInfosAsync(int userId, int CTable)
  368. {
  369. List<Web_ShareGroupInfoView> _ShareGroupInfoViews = new List<Web_ShareGroupInfoView>();
  370. var taskDatas = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(it => it.UId == userId && it.CTId == CTable && it.IsDel == 0).ToList();
  371. if (taskDatas.Count < 1) return _ShareGroupInfoViews;
  372. string diIds = string.Join(",", taskDatas.Select(it => it.DIId).ToList());
  373. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  374. From Grp_DelegationInfo Where Id In({0}) And IsDel = 0 Order By Id Desc", diIds);
  375. _ShareGroupInfoViews = await _dirRep._sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  376. return _ShareGroupInfoViews;
  377. }
  378. #endregion
  379. #region 团组相关
  380. #region 建团按国家默认添加汇率 / 默认权限分配
  381. /// <summary>
  382. /// 团组汇率
  383. /// 建团时 添加基础汇率 CNY
  384. /// 按国家 添加 默认币种
  385. /// </summary>
  386. /// <param name="userId"></param>
  387. /// <param name="diId"></param>
  388. /// <returns></returns>
  389. public static async Task<Result> PostGroupRateAddInit(int userId, int diId)
  390. {
  391. Result result = new() { Code = -2 };
  392. if (userId < 1)
  393. {
  394. result.Msg = string.Format(@"请传入正确的userId");
  395. return result;
  396. }
  397. if (diId < 1)
  398. {
  399. result.Msg = string.Format(@"请传入正确的DiId");
  400. return result;
  401. }
  402. //美元(USD):1.0000|欧元(EUR):1.0000|墨西哥比索(MXN):1.0000
  403. string rateInit = string.Format(@"人民币(CNY):1.0000");
  404. //var gropInfo = _dirRep._sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.Id == diId).First();
  405. //if (gropInfo == null)
  406. //{
  407. // result.Msg = $@"未查询到团组信息!";
  408. // return result;
  409. //}
  410. var juheRateData = await _juHeApi.GetExchangeRateAsync();
  411. if (juheRateData.Error_code != 0)
  412. {
  413. result.Msg = juheRateData.Reason;
  414. return result;
  415. }
  416. List<ExchangeRateModel> exchangeRateModels = (List<ExchangeRateModel>)juheRateData.Result;
  417. if (exchangeRateModels.Count <= 0)
  418. {
  419. result.Msg = $@"未查询到聚合接口汇率信息!";
  420. return result;
  421. }
  422. if (exchangeRateModels.Count > 0)
  423. {
  424. var codes = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 66).ToList();
  425. for (int i = 0; i < exchangeRateModels.Count; i++)
  426. {
  427. string currencyName = exchangeRateModels[i].Name;
  428. string code = "";
  429. var currencyData = codes.Where(it => it.Remark == currencyName).FirstOrDefault();
  430. if (currencyData != null)
  431. {
  432. code = currencyData.Name;
  433. decimal currRate = 0.00M;
  434. string MSellPri = exchangeRateModels[i].MSellPri;
  435. if (!string.IsNullOrEmpty(MSellPri))
  436. {
  437. currRate = Convert.ToDecimal(MSellPri) / 100M;
  438. }
  439. rateInit += $@"|{currencyName}({code}):{currRate.ToString("#0.0000")}";
  440. }
  441. }
  442. }
  443. var cTableIds = _dirRep._sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0 && it.STid == 16).ToList();
  444. if (cTableIds.Count < 1)
  445. {
  446. result.Msg = $@"未查询到操作模块信息!";
  447. return result;
  448. }
  449. List<Grp_TeamRate> grp_TeamRates = new List<Grp_TeamRate>();
  450. foreach (var item in cTableIds)
  451. {
  452. grp_TeamRates.Add(
  453. new Grp_TeamRate() { DiId = diId, CTable = item.Id, Remark = rateInit, CreateUserId = userId }
  454. );
  455. }
  456. if (grp_TeamRates.Count > 0)
  457. {
  458. var addId = _teamRateRep._sqlSugar.Insertable(grp_TeamRates).ExecuteCommand();
  459. if (addId < 1)
  460. {
  461. result.Msg = string.Format(@"添加失败!");
  462. return result;
  463. }
  464. }
  465. result.Code = 0;
  466. result.Msg = string.Format(@"操作成功!");
  467. return result;
  468. }
  469. /// <summary>
  470. /// 团组任务分配
  471. /// 建团时 默认按照岗位分配权限
  472. /// </summary>
  473. /// <param name="userId"></param>
  474. /// <param name="diId"></param>
  475. /// <param name="companyId"></param>
  476. /// <returns></returns>
  477. public static async Task<Result> PostGroupAuthAddInit(int userId, int diId, int companyId = 2)
  478. {
  479. Result result = new() { Code = -2 };
  480. if (userId < 0)
  481. {
  482. result.Msg = string.Format(@"请传入正确的userId");
  483. return result;
  484. }
  485. if (companyId < 0)
  486. {
  487. result.Msg = string.Format(@"请传入正确的companyId");
  488. return result;
  489. }
  490. if (diId < 0)
  491. {
  492. result.Msg = string.Format(@"请传入正确的DiId");
  493. return result;
  494. }
  495. var userDatas = await _teamRateRep._sqlSugar
  496. .Queryable<Sys_Users>()
  497. .LeftJoin<Sys_Department>((su, sd) => su.DepId == sd.Id && sd.IsDel == 0)
  498. .LeftJoin<Sys_JobPost>((su, sd, sjp) => su.JobPostId == sjp.Id && sjp.IsDel == 0)
  499. .Where(su => su.IsDel == 0)
  500. .Select((su, sd, sjp) => new {
  501. su.DepId,
  502. sd.DepName,
  503. su.JobPostId,
  504. sjp.JobName,
  505. su.Id,
  506. su.CnName
  507. })
  508. .ToListAsync();
  509. /*
  510. * 76 酒店预订 --> 国交部门 酒店 岗位
  511. * 77 行程 --> 国交部门 经理,主管 岗位
  512. * 79 车/导游地接 --> 国交部门 OP 岗位
  513. * 80 签证 --> 国交部门 签证 岗位
  514. * 81 邀请/公务活动 --> 国交部门 商邀 岗位
  515. * 82 团组客户保险 --> 国交部 经理,主管 岗位
  516. * 85 机票预订 --> 国交部门 机票 岗位
  517. * 98 其他款项 --> 总经办部门 总经理 岗位/国交部门(ALL) 岗位/财务部门(ALL) 岗位/策划部门(ALL) 岗位/人事部门 采购 岗位
  518. * 1015 超支费用,69 收款退还 --> 财务部门(ALL)岗位
  519. * 1015 超支费用 --> 国交部(ALL)岗位
  520. */
  521. List<Grp_GroupsTaskAssignment> _GroupsTaskAssignments = new List<Grp_GroupsTaskAssignment>();
  522. // 76 酒店预订 --> 国交部门(7) 酒店(25) 岗位
  523. _GroupsTaskAssignments.AddRange(
  524. userDatas
  525. .Where(it => it.DepId == 7 && it.JobPostId == 25)
  526. .Select(it => new Grp_GroupsTaskAssignment()
  527. {
  528. DIId = diId,
  529. CTId = 76,
  530. UId = it.Id,
  531. CreateUserId = userId
  532. }).ToList()
  533. );
  534. // 77 行程 --> 国交部门(7) 经理(32),主管(22) 岗位
  535. _GroupsTaskAssignments.AddRange(
  536. userDatas
  537. .Where(it => it.DepId == 7 && (it.JobPostId == 22 || it.JobPostId == 32))
  538. .Select(it => new Grp_GroupsTaskAssignment()
  539. {
  540. DIId = diId,
  541. CTId = 77,
  542. UId = it.Id,
  543. CreateUserId = userId
  544. }).ToList()
  545. );
  546. //79 车/导游地接 --> 国交部门(7) OP(28) 岗位
  547. _GroupsTaskAssignments.AddRange(
  548. userDatas.Where(it => it.DepId == 7 && it.JobPostId == 28)
  549. .Select(it => new Grp_GroupsTaskAssignment()
  550. {
  551. DIId = diId,
  552. CTId = 79,
  553. UId = it.Id,
  554. CreateUserId = userId
  555. }).ToList()
  556. );
  557. //81 邀请/公务活动 --> 国交部门(7) 商邀(27) 岗位
  558. _GroupsTaskAssignments.AddRange(
  559. userDatas
  560. .Where(it => it.DepId == 7 && it.JobPostId == 27)
  561. .Select(it => new Grp_GroupsTaskAssignment()
  562. {
  563. DIId = diId,
  564. CTId = 81,
  565. UId = it.Id,
  566. CreateUserId = userId
  567. }).ToList()
  568. );
  569. //80 签证 --> 国交部门(7) 签证(26) 岗位
  570. _GroupsTaskAssignments.AddRange(
  571. userDatas
  572. .Where(it => it.DepId == 7 && it.JobPostId == 26)
  573. .Select(it => new Grp_GroupsTaskAssignment()
  574. {
  575. DIId = diId,
  576. CTId = 80,
  577. UId = it.Id,
  578. CreateUserId = userId
  579. }).ToList()
  580. );
  581. //82 团组客户保险 --> 国交部(7) 经理(32),主管(22) 岗位
  582. //2024-06-25 默认将保险权限分配给签证岗。 签证(26) 岗位
  583. List<int> insurancePositions = new List<int>() { 32, 22, 26 };
  584. _GroupsTaskAssignments.AddRange(
  585. userDatas
  586. .Where(it => it.DepId == 7 && insurancePositions.Contains(it.JobPostId))
  587. .Select(it => new Grp_GroupsTaskAssignment()
  588. {
  589. DIId = diId,
  590. CTId = 82,
  591. UId = it.Id,
  592. CreateUserId = userId
  593. }).ToList()
  594. );
  595. //85 机票预订 --> 国交部门(7) 机票(24) 岗位
  596. _GroupsTaskAssignments.AddRange(
  597. userDatas
  598. .Where(it => it.DepId == 7 && it.JobPostId == 24)
  599. .Select(it => new Grp_GroupsTaskAssignment()
  600. {
  601. DIId = diId,
  602. CTId = 85,
  603. UId = it.Id,
  604. CreateUserId = userId
  605. }).ToList()
  606. );
  607. //98 其他款项 --> 总经办部门(1) 总经理(1) 岗位/国交部门(7)(ALL) 岗位/财务部门(3)(ALL) 岗位/策划部门(5)(ALL) 岗位/人事部门(4) 采购(74) 岗位
  608. List<int> depIds = new List<int>() { 7, 3, 5 };
  609. List<int> jobIds = new List<int>() { 1, 74 };
  610. _GroupsTaskAssignments.AddRange(
  611. userDatas
  612. .Where(it => depIds.Contains(it.DepId) || jobIds.Contains(it.JobPostId))
  613. .Select(it => new Grp_GroupsTaskAssignment()
  614. {
  615. DIId = diId,
  616. CTId = 98,
  617. UId = it.Id,
  618. CreateUserId = userId
  619. }).ToList()
  620. );
  621. //1015 超支费用,285 收款退还 --> 财务部门(ALL)岗位
  622. _GroupsTaskAssignments.AddRange(
  623. userDatas
  624. .Where(it => it.DepId == 3)
  625. .Select(it => new Grp_GroupsTaskAssignment()
  626. {
  627. DIId = diId,
  628. CTId = 1015,
  629. UId = it.Id,
  630. CreateUserId = userId
  631. }).ToList()
  632. );
  633. _GroupsTaskAssignments.AddRange(
  634. userDatas
  635. .Where(it => it.DepId == 3)
  636. .Select(it => new Grp_GroupsTaskAssignment()
  637. {
  638. DIId = diId,
  639. CTId = 285,
  640. UId = it.Id,
  641. CreateUserId = userId
  642. }).ToList()
  643. );
  644. //1015 超支费用 --> 国交部(ALL)岗位
  645. _GroupsTaskAssignments.AddRange(
  646. userDatas
  647. .Where(it => it.DepId == 7)
  648. .Select(it => new Grp_GroupsTaskAssignment()
  649. {
  650. DIId = diId,
  651. CTId = 1015,
  652. UId = it.Id,
  653. CreateUserId = userId
  654. }).ToList()
  655. );
  656. if (_GroupsTaskAssignments.Count > 0)
  657. {
  658. var addId = _teamRateRep._sqlSugar.Insertable(_GroupsTaskAssignments).ExecuteCommand();
  659. }
  660. result.Code = 0;
  661. result.Msg = string.Format(@"操作成功!");
  662. return result;
  663. }
  664. #endregion
  665. #region 员工是否是市场部人员
  666. /// <summary>
  667. /// 验证市场部客户人员
  668. /// </summary>
  669. /// <param name="userId"></param>
  670. /// <returns></returns>
  671. public static async Task<bool> IsMarketingStaff(int userId)
  672. {
  673. var userInfos = await _dirRep._sqlSugar
  674. .Queryable<Sys_Users>()
  675. .InnerJoin<Sys_Department>((u,d) => u.DepId == d.Id)
  676. .Where((u,d) => u.IsDel == 0 && u.Id == userId && d.DepName.Contains("市场部"))
  677. .ToListAsync();
  678. if (userInfos.Count > 0) return true;
  679. return false;
  680. }
  681. #endregion
  682. #endregion
  683. #region 团组汇率
  684. /// <summary>
  685. /// 团组汇率
  686. /// 获取板块 币种 及 汇率
  687. /// 76 酒店预订 77 行程 79 车/导游地接
  688. /// 80 签证 82 团组客户保险 85 机票预订
  689. /// 98 其他款项 285 收款退还
  690. /// </summary>
  691. /// <param name="teamRateModels"></param>
  692. /// <param name="cTable"></param>
  693. /// <param name="currencyCode"></param>
  694. /// <returns>
  695. /// string
  696. /// eg: CNY 1.0000
  697. /// </returns>
  698. public static async Task<string> PostGroupRateByCTableAndCurrency(List<TeamRateModelView> teamRateModels, int cTable, List<string> currencyCodes)
  699. {
  700. string str = "";
  701. List<string> currencyRates = new List<string>();
  702. TeamRateModelView hotelRateData = teamRateModels.Where(it => it.CTableId == cTable).FirstOrDefault();
  703. if (hotelRateData != null)
  704. {
  705. var hotelRates = hotelRateData.TeamRates;
  706. foreach (var item in currencyCodes)
  707. {
  708. if (!string.IsNullOrEmpty(item))
  709. {
  710. var hotelRateInfo = hotelRates.Where(it => it.CurrencyCode.Equals(item)).FirstOrDefault();
  711. if (hotelRateInfo != null)
  712. {
  713. string str1 = string.Format("{0} {1}\r\n", hotelRateInfo.CurrencyCode, hotelRateInfo.Rate.ToString("#0.0000"));
  714. currencyRates.Add(str1);
  715. }
  716. }
  717. }
  718. if (currencyRates != null || currencyRates.Count > 0)
  719. {
  720. currencyRates = currencyRates.Distinct().ToList();
  721. foreach (var item in currencyRates)
  722. {
  723. str += item;
  724. }
  725. }
  726. }
  727. return str;
  728. }
  729. /// <summary>
  730. /// 团组汇率 币种 Item (来源:团组汇率)
  731. /// 根据 团组Id And 业务类型(CTable)Id
  732. /// api处理CTable = 285,默认返回CNY
  733. /// </summary>
  734. /// <param name="portType"></param>
  735. /// <param name="diId"></param>
  736. /// <param name="cTable"></param>
  737. /// <returns></returns>
  738. public static async Task<TeamRateModelGeneralView> PostGroupTeamRateByDiIdAndCTableId(int portType, int diId, int cTable)
  739. {
  740. TeamRateModelGeneralView _view = new TeamRateModelGeneralView();
  741. _view = await _teamRateRep.PostGroupTeamRateByDiIdAndCTableId(portType, diId, cTable);
  742. return _view;
  743. }
  744. /// <summary>
  745. /// 汇率备注拆分
  746. /// (美元(USD):7.2370|日元(JPY):0.0499|欧元(EUR):8.3000|英镑(GBP):9.1996|港币(HKD):0.9291)
  747. /// </summary>
  748. /// <param name="rateRemark"></param>
  749. /// <returns></returns>
  750. public static async Task<List<TeamRateDescAddCurrencyIdView>> SplitExchangeRate(this string rateRemark)
  751. {
  752. List<TeamRateDescAddCurrencyIdView> _view = new List<TeamRateDescAddCurrencyIdView>();
  753. List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
  754. #region 获取所有币种
  755. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
  756. var DBdata = _setDataRep.GetListBySqlWithNolock(sql);
  757. if (DBdata == null || DBdata.Count == 0)
  758. {
  759. return _view;
  760. }
  761. currencyDatas = DBdata.Select(x => new SetDataInfoView
  762. {
  763. Name = x.Name,
  764. Id = x.Id,
  765. Remark = x.Remark,
  766. }).ToList();
  767. #endregion
  768. #region 拆分remark里的汇率
  769. if (string.IsNullOrEmpty(rateRemark))
  770. {
  771. return _view;
  772. }
  773. if (rateRemark.Contains("|"))
  774. {
  775. string[] currencyArr = rateRemark.Split("|");
  776. foreach (string currency in currencyArr)
  777. {
  778. string[] currency1 = currency.Split(":");
  779. string[] currency2 = currency1[0].Split("(");
  780. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  781. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  782. {
  783. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  784. CurrencyCode = currencyCode,
  785. CurrencyName = currency2[0],
  786. Rate = decimal.Parse(currency1[1]),
  787. };
  788. _view.Add(rateDescView);
  789. }
  790. }
  791. else
  792. {
  793. try
  794. {
  795. string[] currency1 = rateRemark.Split(":");
  796. string[] currency2 = currency1[0].Split("(");
  797. string currencyCode = currency2[1].Replace(")", "").TrimEnd();
  798. TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
  799. {
  800. CurrencyId = currencyDatas.Find(it => it.Name == currencyCode).Id,
  801. CurrencyCode = currencyCode,
  802. CurrencyName = currency2[0],
  803. Rate = decimal.Parse(currency1[1]),
  804. };
  805. _view.Add(rateDescView);
  806. }
  807. catch (Exception)
  808. {
  809. return _view;
  810. }
  811. }
  812. #endregion
  813. return _view;
  814. }
  815. #endregion
  816. #region 汉字转换拼音
  817. private static Dictionary<int, List<string>> GetTotalPingYinDictionary(string text)
  818. {
  819. var chs = text.ToCharArray();
  820. //记录每个汉字的全拼
  821. Dictionary<int, List<string>> totalPingYinList = new Dictionary<int, List<string>>();
  822. for (int i = 0; i < chs.Length; i++)
  823. {
  824. var pinyinList = new List<string>();
  825. //是否是有效的汉字
  826. if (ChineseChar.IsValidChar(chs[i]))
  827. {
  828. ChineseChar cc = new ChineseChar(chs[i]);
  829. pinyinList = cc.Pinyins.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
  830. }
  831. else
  832. {
  833. pinyinList.Add(chs[i].ToString());
  834. }
  835. //去除声调,转小写
  836. pinyinList = pinyinList.ConvertAll(p => Regex.Replace(p, @"\d", "").ToLower());
  837. //去重
  838. pinyinList = pinyinList.Where(p => !string.IsNullOrWhiteSpace(p)).Distinct().ToList();
  839. if (pinyinList.Any())
  840. {
  841. totalPingYinList[i] = pinyinList;
  842. }
  843. }
  844. return totalPingYinList;
  845. }
  846. /// <summary>
  847. /// 获取汉语拼音全拼
  848. /// </summary>
  849. /// <param name="text">The string.</param>
  850. /// <returns></returns>
  851. public static List<string> GetTotalPingYin(this string text)
  852. {
  853. var result = new List<string>();
  854. foreach (var pys in GetTotalPingYinDictionary(text))
  855. {
  856. var items = pys.Value;
  857. if (result.Count <= 0)
  858. {
  859. result = items;
  860. }
  861. else
  862. {
  863. //全拼循环匹配
  864. var newTotalPingYinList = new List<string>();
  865. foreach (var totalPingYin in result)
  866. {
  867. newTotalPingYinList.AddRange(items.Select(item => totalPingYin + item));
  868. }
  869. newTotalPingYinList = newTotalPingYinList.Distinct().ToList();
  870. result = newTotalPingYinList;
  871. }
  872. }
  873. return result;
  874. }
  875. /// <summary>
  876. /// 获取汉语拼音首字母
  877. /// </summary>
  878. /// <param name="text"></param>
  879. /// <returns></returns>
  880. public static List<string> GetFirstPingYin(this string text)
  881. {
  882. var result = new List<string>();
  883. foreach (var pys in GetTotalPingYinDictionary(text))
  884. {
  885. var items = pys.Value;
  886. if (result.Count <= 0)
  887. {
  888. result = items.ConvertAll(p => p.Substring(0, 1)).Distinct().ToList();
  889. }
  890. else
  891. {
  892. //首字母循环匹配
  893. var newFirstPingYinList = new List<string>();
  894. foreach (var firstPingYin in result)
  895. {
  896. newFirstPingYinList.AddRange(items.Select(item => firstPingYin + item.Substring(0, 1)));
  897. }
  898. newFirstPingYinList = newFirstPingYinList.Distinct().ToList();
  899. result = newFirstPingYinList;
  900. }
  901. }
  902. return result;
  903. }
  904. #endregion
  905. #region 新客户资料表 操作记录
  906. /// <summary>
  907. /// 新客户资料表
  908. /// 操作记录添加
  909. /// </summary>
  910. /// <param name="portType"></param>
  911. /// <param name="operationEnum"></param>
  912. /// <param name="userId"></param>
  913. /// <param name="dataId"></param>
  914. /// <param name="remark"></param>
  915. /// <returns></returns>
  916. public static async Task<bool> NewClientOperationRecord(int portType, OperationEnum operationEnum, int userId, int dataId, string remark)
  917. {
  918. Crm_TableOperationRecord _TableOperationRecord = new Crm_TableOperationRecord()
  919. {
  920. TableName = "Crm_NewClientData",
  921. PortType = portType,
  922. OperationItem = operationEnum,
  923. DataId = dataId,
  924. CreateUserId = userId,
  925. CreateTime = DateTime.Now,
  926. Remark = remark
  927. };
  928. bool add = await _tableOperationRecordRep._Add(_TableOperationRecord);
  929. if (add) return false;
  930. return false;
  931. }
  932. #endregion
  933. #region 金额转大写
  934. /// <summary>
  935. /// 金额转换为大写数字
  936. /// <para>1、支持的最大数字:999999999999.99(玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖元玖角玖分)</para>
  937. /// <para>2、小数点后最多支持两位</para>
  938. /// </summary>
  939. /// <param name="num">数值</param>
  940. /// <returns></returns>
  941. public static string ConvertCNYUpper(this decimal num)
  942. {
  943. if (num == 0)
  944. {
  945. return "零元";
  946. }
  947. // 解决327000000转换后缺少单位万的问题
  948. return ConvertToChinese(num);
  949. }
  950. #region 实例
  951. /// <summary>
  952. /// 要转换的数字
  953. /// </summary>
  954. private static decimal j;
  955. /// <summary>
  956. ///
  957. /// </summary>
  958. private static string[] NumChineseCharacter = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  959. /// <summary>
  960. /// 判断输入的数字是否大于double类型
  961. /// </summary>
  962. private static bool IsNumber
  963. {
  964. get
  965. {
  966. if (j > decimal.MaxValue || j <= 0)
  967. return false;
  968. else
  969. return true;
  970. }
  971. }
  972. /// <summary>
  973. /// 数字转换成大写汉字主函数
  974. /// </summary>
  975. /// <returns>返回转换后的大写汉字</returns>
  976. public static string ConvertToChinese(decimal m)
  977. {
  978. j = m;
  979. string bb = "";
  980. if (IsNumber)
  981. {
  982. string str = j.ToString();
  983. string[] Num = str.Split('.');
  984. if (Num.Length == 1)
  985. {
  986. bb = NumberString(Num[0]) + "元整";
  987. bb = bb.Replace("零零", "零");
  988. }
  989. else
  990. {
  991. bb = NumberString(Num[0]) + "元";
  992. bb += FloatString(Num[1]);
  993. bb = bb.Replace("零零", "零");
  994. }
  995. }
  996. else
  997. {
  998. throw new FormatException("你输入的数字格式不正确或不是数字!");
  999. }
  1000. return bb;
  1001. }
  1002. /// <summary>
  1003. /// 小数位转换只支持两位的小数
  1004. /// </summary>
  1005. /// <param name="Num">转换的小数</param>
  1006. /// <returns>小数转换成汉字</returns>
  1007. private static string FloatString(string Num)
  1008. {
  1009. string cc = "";
  1010. if (Num.Length > 2)
  1011. {
  1012. throw new FormatException("小数位数过多.");
  1013. }
  1014. else
  1015. {
  1016. string bb = ConvertString(Num);
  1017. int len = bb.IndexOf("零");
  1018. if (len != 0)
  1019. {
  1020. bb = bb.Replace("零", "");
  1021. if (bb.Length == 1)
  1022. {
  1023. cc = bb.Substring(0, 1) + "角";
  1024. }
  1025. else
  1026. {
  1027. cc = bb.Substring(0, 1) + "角";
  1028. cc += bb.Substring(1, 1) + "分";
  1029. }
  1030. }
  1031. else
  1032. cc = bb + "分";
  1033. }
  1034. return cc;
  1035. }
  1036. /// <summary>
  1037. /// 判断数字位数以进行拆分转换
  1038. /// </summary>
  1039. /// <param name="Num">要进行拆分的数字</param>
  1040. /// <returns>转换成的汉字</returns>
  1041. private static string NumberString(string Num)
  1042. {
  1043. string bb = "";
  1044. if (Num.Length <= 4)
  1045. {
  1046. bb = Convert4(Num);
  1047. }
  1048. else if (Num.Length > 4 && Num.Length <= 8)
  1049. {
  1050. bb = Convert4(Num.Substring(0, Num.Length - 4)) + "万";
  1051. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1052. }
  1053. else if (Num.Length > 8 && Num.Length <= 12)
  1054. {
  1055. bb = Convert4(Num.Substring(0, Num.Length - 8)) + "亿";
  1056. if (Convert4(Num.Substring(Num.Length - 8, 4)) == "")
  1057. if (Convert4(Num.Substring(Num.Length - 4, 4)) != "")
  1058. bb += "零";
  1059. else
  1060. bb += "";
  1061. else
  1062. bb += Convert4(Num.Substring(Num.Length - 8, 4)) + "万";
  1063. bb += Convert4(Num.Substring(Num.Length - 4, 4));
  1064. }
  1065. else
  1066. {
  1067. throw new Exception("整数部分最多支持12位");
  1068. }
  1069. return bb;
  1070. }
  1071. /// <summary>
  1072. /// 四位数字的转换
  1073. /// </summary>
  1074. /// <param name="Num">准备转换的四位数字</param>
  1075. /// <returns>转换以后的汉字</returns>
  1076. private static string Convert4(string Num)
  1077. {
  1078. string bb = "";
  1079. if (Num.Length == 1)
  1080. {
  1081. bb = ConvertString(Num);
  1082. }
  1083. else if (Num.Length == 2)
  1084. {
  1085. bb = ConvertString(Num);
  1086. bb = Convert2(bb);
  1087. }
  1088. else if (Num.Length == 3)
  1089. {
  1090. bb = ConvertString(Num);
  1091. bb = Convert3(bb);
  1092. }
  1093. else
  1094. {
  1095. bb = ConvertString(Num);
  1096. string cc = "";
  1097. string len = bb.Substring(0, 4);
  1098. if (len != "零零零零")
  1099. {
  1100. len = bb.Substring(0, 3);
  1101. if (len != "零零零")
  1102. {
  1103. bb = bb.Replace("零零零", "");
  1104. if (bb.Length == 1)
  1105. {
  1106. bb = bb.Substring(0, 1) + "仟";
  1107. }
  1108. else
  1109. {
  1110. if (bb.Substring(0, 1) != "零" && bb.Substring(0, 2) != "零")
  1111. cc = bb.Substring(0, 1) + "仟";
  1112. else
  1113. cc = bb.Substring(0, 1);
  1114. bb = cc + Convert3(bb.Substring(1, 3));
  1115. }
  1116. }
  1117. else
  1118. {
  1119. bb = bb.Replace("零零零", "零");
  1120. }
  1121. }
  1122. else
  1123. {
  1124. bb = bb.Replace("零零零零", "");
  1125. }
  1126. }
  1127. return bb;
  1128. }
  1129. /// <summary>
  1130. /// 将数字转换成汉字
  1131. /// </summary>
  1132. /// <param name="Num">需要转换的数字</param>
  1133. /// <returns>转换后的汉字</returns>
  1134. private static string ConvertString(string Num)
  1135. {
  1136. string bb = "";
  1137. for (int i = 0; i < Num.Length; i++)
  1138. {
  1139. bb += NumChineseCharacter[int.Parse(Num.Substring(i, 1))];
  1140. }
  1141. return bb;
  1142. }
  1143. /// <summary>
  1144. /// 两位数字的转换
  1145. /// </summary>
  1146. /// <param name="Num">两位数字</param>
  1147. /// <returns>转换后的汉字</returns>
  1148. private static string Convert2(string Num)
  1149. {
  1150. string bb = ""; string cc = "";
  1151. string len = Num.Substring(0, 1);
  1152. if (len != "零")
  1153. {
  1154. bb = Num.Replace("零", "");
  1155. if (bb.Length == 1)
  1156. {
  1157. cc = bb.Substring(0, 1) + "拾";
  1158. }
  1159. else
  1160. {
  1161. cc = bb.Substring(0, 1) + "拾";
  1162. cc += bb.Substring(1, 1);
  1163. }
  1164. }
  1165. else
  1166. cc = Num;
  1167. return cc;
  1168. }
  1169. /// <summary>
  1170. /// 三位数字的转换
  1171. /// </summary>
  1172. /// <param name="Num">三位数字</param>
  1173. /// <returns>转换后的汉字</returns>
  1174. private static string Convert3(string Num)
  1175. {
  1176. string bb = ""; string cc = "";
  1177. string len = Num.Substring(0, 2);
  1178. if (len != "零零")
  1179. {
  1180. bb = Num.Replace("零零", "");
  1181. if (bb.Length == 1)
  1182. {
  1183. bb = bb.Substring(0, 1) + "佰";
  1184. }
  1185. else
  1186. {
  1187. if (bb.Substring(0, 1) != "零")
  1188. cc = bb.Substring(0, 1) + "佰";
  1189. else
  1190. cc = bb.Substring(0, 1);
  1191. bb = cc + Convert2(bb.Substring(1, 2));
  1192. }
  1193. }
  1194. else
  1195. {
  1196. bb = Num.Replace("零零", "零");
  1197. }
  1198. return bb;
  1199. }
  1200. #endregion
  1201. #endregion
  1202. #region 数字验证
  1203. /// <summary>
  1204. /// 验证数字字符串
  1205. /// </summary>
  1206. /// <param name="num"></param>
  1207. /// <returns></returns>
  1208. public static bool IsNumeric(this string numStr)
  1209. {
  1210. bool isNumeric = Regex.IsMatch(numStr, @"^\d+$");
  1211. if (isNumeric)
  1212. {
  1213. return true;
  1214. }
  1215. return false;
  1216. }
  1217. #endregion
  1218. #region 日期 格式转换
  1219. /// <summary>
  1220. /// 验证数字字符串
  1221. /// </summary>
  1222. /// <param name="str"></param>
  1223. /// <returns></returns>
  1224. public static string ConvertToDatetime(this string str)
  1225. {
  1226. if (!string.IsNullOrEmpty(str))
  1227. {
  1228. DateTime currentDate = Convert.ToDateTime(str);
  1229. return $"{currentDate.Year}年{currentDate.Month}月{currentDate.Day}日";
  1230. }
  1231. return "";
  1232. }
  1233. #endregion
  1234. #region 月份/季度
  1235. /// <summary>
  1236. /// 获取月份对应的起始天数
  1237. /// </summary>
  1238. /// <param name="year"></param>
  1239. /// <returns></returns>
  1240. public static List<MonthInfo> GetMonthInfos(int year)
  1241. {
  1242. List<MonthInfo> months = new List<MonthInfo>();
  1243. if (year > 1)
  1244. {
  1245. for (int i = 1; i < 13; i++)
  1246. {
  1247. months.Add(new MonthInfo()
  1248. {
  1249. Month = i,
  1250. Days = new DaysInfo() { BeginDays = 1, EndDays = DateTime.DaysInMonth(year, i) }
  1251. });
  1252. }
  1253. }
  1254. return months;
  1255. }
  1256. /// <summary>
  1257. /// 获取季度对应的起始天数
  1258. /// </summary>
  1259. /// <param name="year"></param>
  1260. /// <returns></returns>
  1261. public static List<MonthInfo> GetQuarter(int year)
  1262. {
  1263. List<MonthInfo> months = new List<MonthInfo>();
  1264. months.Add(new MonthInfo() { Month = 1, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //1.1 - 3.31
  1265. months.Add(new MonthInfo() { Month = 2, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //4.1 - 6.30
  1266. months.Add(new MonthInfo() { Month = 3, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //7.1 - 9.31
  1267. months.Add(new MonthInfo() { Month = 4, Days = new DaysInfo() { BeginDays = 1, EndDays = 31 } }); //10.1 - 12.31
  1268. return months;
  1269. }
  1270. public class MonthInfo
  1271. {
  1272. public int Month { get; set; }
  1273. public DaysInfo Days { get; set; }
  1274. }
  1275. public class DaysInfo
  1276. {
  1277. public int BeginDays { get; set; }
  1278. public int EndDays { get; set; }
  1279. }
  1280. #endregion
  1281. #region op行程单,黑屏幕代码
  1282. public static string GetCountryStandingTime(int diId)
  1283. {
  1284. DataTable datas = GetTableByBlackCode(diId);
  1285. string countryStr = "[黑屏代码未录入].";
  1286. if (datas.Rows.Count > 0)
  1287. {
  1288. var airDatas = from row in datas.AsEnumerable()
  1289. select new
  1290. {
  1291. Three = row.Field<string>("Three"),
  1292. Day = row.Field<string>("Day"),
  1293. ArrivedDate = row.Field<string>("ArrivedDate"),
  1294. };
  1295. //三字码信息
  1296. List<Res_ThreeCode> listcode = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(x => x.IsDel == 0).ToList();
  1297. //string countryStr = "";
  1298. int index = 0;
  1299. List<string> cityCodes = new List<string>();
  1300. //去掉开始和结束城市
  1301. foreach (var row in airDatas)
  1302. {
  1303. if (!string.IsNullOrEmpty(row.Three))
  1304. {
  1305. if (index == 0) cityCodes.Add(row.Three.Substring(3, 3)); //到达国家
  1306. else if (airDatas.Count() - 1 == index) cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1307. else cityCodes.Add(row.Three.Substring(0, 3)); //到达国家
  1308. }
  1309. index++;
  1310. }
  1311. cityCodes = cityCodes.Distinct().ToList();
  1312. if (cityCodes.Count > 0) countryStr = "";
  1313. foreach (var item in cityCodes)
  1314. {
  1315. var airData = airDatas.Where(it => it.Three.Contains(item)).ToList();
  1316. string country = listcode.Find(it => it.Three.Equals(item))?.Country ?? "Unknown";
  1317. if (country.Equals("中国"))
  1318. {
  1319. country = listcode.Find(it => it.Three.Equals(item))?.City ?? "Unknown";
  1320. }
  1321. int days = 0;
  1322. if (airData.Count == 2)
  1323. {
  1324. DateTime arr_dt = Convert.ToDateTime(airData[0].ArrivedDate); //抵达时间
  1325. DateTime dep_dt = Convert.ToDateTime(airData[1].Day); //离开时间
  1326. days = (dep_dt - arr_dt).Days;
  1327. //countryStr += $@"{country}停留{days}日、";
  1328. countryStr += $@"{country}停留 日、";
  1329. }
  1330. }
  1331. if (countryStr.Length > 0) countryStr = countryStr.Substring(0, countryStr.Length - 1);
  1332. }
  1333. return countryStr;
  1334. }
  1335. /// <summary>
  1336. ///根据机票黑屏代码整理DataTable
  1337. /// </summary>
  1338. /// <param name="diid"></param>
  1339. /// <returns></returns>
  1340. public static DataTable GetTableByBlackCode1(int diid)
  1341. {
  1342. //黑屏代码信息
  1343. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  1344. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  1345. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  1346. DataTable dt = new DataTable();
  1347. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1348. dt.Columns.Add("Date", typeof(string));//起飞日期
  1349. dt.Columns.Add("Three", typeof(string));//三字码
  1350. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1351. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1352. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1353. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1354. dt.Columns.Add("AirModel", typeof(string)); //机型
  1355. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1356. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1357. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1358. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1359. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1360. //判断是否录入黑屏代码
  1361. if (listcode.Count() == 0 || listcode == null)
  1362. {
  1363. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null);
  1364. }
  1365. else
  1366. {
  1367. //读取单段黑屏代码
  1368. for (int i = 0; i < listcode.Count; i++)
  1369. {
  1370. //去除序号
  1371. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  1372. //去除多余空格,方法一Linq扩展方法
  1373. CodeList = CodeList.Where(str => str != "").ToArray();
  1374. CodeList = CodeList.Where(str => str != " ").ToArray();
  1375. //年
  1376. int year = Convert.ToInt32(DateTime.Now.Year.ToString());
  1377. //读取单条黑屏代码
  1378. for (int j = 0; j < CodeList.Count(); j++)
  1379. {
  1380. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  1381. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  1382. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1383. //string[] Info = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1384. // .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1385. //去除多余空格
  1386. Info = Info.Where(str => str != "").ToArray();
  1387. Info = Info.Where(str => str != " ").ToArray();
  1388. //判断黑屏代码是否正确拆分; 理应拆成9段
  1389. if (Info.Count() < 9)
  1390. {
  1391. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null);
  1392. }
  1393. else
  1394. {
  1395. try
  1396. {
  1397. //月
  1398. int month = Convert.ToInt32(GetLonger(Info[1].Substring(4, 3)));
  1399. //日
  1400. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  1401. #region 逐一比较月份,判断是否翻年;逐一比较三字码顶真,判断是否跑错机场
  1402. if (j > 0)
  1403. {
  1404. string[] Temp = CodeList[j - 1].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty)
  1405. .TrimStart().TrimEnd().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1406. Temp = Temp.Where(str => str != "").ToArray();
  1407. Temp = Temp.Where(str => str != " ").ToArray();
  1408. int monthTemp = Convert.ToInt32(GetLonger(Temp[1].Substring(4, 3)));
  1409. // 如果相邻月份之差小于0,则证明次一条年份需+1
  1410. if (month - monthTemp < 0)
  1411. {
  1412. year = year + 1;
  1413. }
  1414. //如果相邻代码三字码不顶真,提醒
  1415. string FootThree = Temp[2].Substring(3, 3);
  1416. string HeadThree = Info[2].Substring(0, 3);
  1417. if (FootThree != HeadThree)
  1418. {
  1419. //DelegationInfoService s = new DelegationInfoService();
  1420. //UsersService us = new UsersService();
  1421. //GroupsTaskAssignmentService gts = new GroupsTaskAssignmentService();
  1422. //77 行程
  1423. List<Grp_GroupsTaskAssignment> list2 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 77 && x.DIId == diid && x.IsDel == 0).ToList();
  1424. foreach (var temp in list2)
  1425. {
  1426. //if (temp.UId != 21)
  1427. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1428. // "黑屏代码提醒",
  1429. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1430. }
  1431. //85 机票预订
  1432. List<Grp_GroupsTaskAssignment> list6 = _dirRep._sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(x => x.CTId == 85 && x.DIId == diid && x.IsDel == 0).ToList();
  1433. foreach (var temp in list6)
  1434. {
  1435. //if (temp.UId != 21)
  1436. //SendAndReturn(us.GetUsersByID(temp.UId).Email,
  1437. // "黑屏代码提醒",
  1438. // s.GetDelegationInfoByID(diid).TeamName + "的机票黑屏代码中,相邻航段的三字码不连续,请查看!");
  1439. }
  1440. }
  1441. }
  1442. #endregion
  1443. #region 判断到达日期是否需要加1
  1444. if (Info[4].Contains("+"))
  1445. {
  1446. //日期+1
  1447. day = day + 1;
  1448. //判断是否进入下一月
  1449. if (day > Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year)))
  1450. {
  1451. day = day - Convert.ToInt32(GetDaysByMonth(Info[1].Substring(4, 3), year));
  1452. month = month + 1;
  1453. //判断是否进入下一年
  1454. if (month > 12)
  1455. {
  1456. month = month - 12;
  1457. year = year + 1;
  1458. }
  1459. }
  1460. //月份整理格式
  1461. string monthTemp = month.ToString();
  1462. if (month < 10)
  1463. {
  1464. monthTemp = "0" + monthTemp;
  1465. }
  1466. //日期整理格式
  1467. string daytemp = day.ToString();
  1468. if (day < 10)
  1469. {
  1470. daytemp = "0" + daytemp;
  1471. }
  1472. string temp = Info[4].Split('+')[0];
  1473. //添加起飞数据
  1474. dt.Rows.Add(Info[0],
  1475. Info[1],
  1476. Info[2],
  1477. Info[3],
  1478. temp,
  1479. Info[5],
  1480. Info[6],
  1481. Info[7],
  1482. Info[8],
  1483. year + "-" + GetLonger(Info[1].Substring(4, 3)) + "-" + Info[1].Substring(2, 2),
  1484. year + "-" + monthTemp + "-" + daytemp,
  1485. "",
  1486. "0");
  1487. //加1天,添加到达数据
  1488. dt.Rows.Add(Info[0],
  1489. Info[1].Replace(Info[1].Substring(2, 2), daytemp),
  1490. Info[2],
  1491. Info[3],
  1492. temp,
  1493. Info[5],
  1494. Info[6],
  1495. Info[7],
  1496. Info[8],
  1497. year + "-" + monthTemp + "-" + daytemp,
  1498. year + "-" + monthTemp + "-" + daytemp,
  1499. "",
  1500. "1");
  1501. }
  1502. else
  1503. {
  1504. //月份整理格式
  1505. string monthTemp = month.ToString();
  1506. if (month < 10)
  1507. {
  1508. monthTemp = "0" + monthTemp;
  1509. }
  1510. //日期整理格式
  1511. string daytemp = day.ToString();
  1512. if (day < 10)
  1513. {
  1514. daytemp = "0" + daytemp;
  1515. }
  1516. dt.Rows.Add(Info[0],
  1517. Info[1],
  1518. Info[2],
  1519. Info[3],
  1520. Info[4],
  1521. Info[5],
  1522. Info[6],
  1523. Info[7],
  1524. Info[8],
  1525. year + "-" + monthTemp + "-" + daytemp,
  1526. year + "-" + monthTemp + "-" + daytemp,
  1527. "",
  1528. "0");
  1529. }
  1530. #endregion
  1531. }
  1532. catch (Exception ex)
  1533. {
  1534. string exstr = ex.Message.ToString();
  1535. }
  1536. }
  1537. }
  1538. //排序
  1539. dt.DefaultView.Sort = "Day asc";
  1540. dt = dt.DefaultView.ToTable();
  1541. }
  1542. }
  1543. return dt;
  1544. }
  1545. private readonly static string[] excludeArr = new string[] { "[中转]", };
  1546. /// <summary>
  1547. ///根据机票黑屏代码整理DataTable
  1548. /// </summary>
  1549. /// <param name="diid"></param>
  1550. /// <returns></returns>
  1551. public static DataTable GetTableByBlackCode(int diid)
  1552. {
  1553. //黑屏代码信息
  1554. List<Air_TicketBlackCode> listcode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.DiId == diid && x.IsDel == 0).ToList();
  1555. //测试数据为序号,航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间
  1556. //1.3U8391 TU17NOV CTUCAI 0220 0715 T1 T2 330 10H55M
  1557. DataTable dt = new DataTable();
  1558. dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1559. dt.Columns.Add("Date", typeof(string));//起飞日期
  1560. dt.Columns.Add("Three", typeof(string));//三字码
  1561. dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1562. dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1563. dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1564. dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1565. dt.Columns.Add("AirModel", typeof(string)); //机型
  1566. dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1567. dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1568. dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1569. dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1570. dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1571. //添加转机标识
  1572. dt.Columns.Add("isTransitShipment", typeof(bool));
  1573. //判断是否录入黑屏代码
  1574. if (listcode.Count() == 0 || listcode == null)
  1575. {
  1576. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "黑屏代码未录入!", null, false);
  1577. }
  1578. else
  1579. {
  1580. //读取单段黑屏代码
  1581. for (int i = 0; i < listcode.Count; i++)
  1582. {
  1583. //去除序号
  1584. string[] CodeList = Regex.Split(listcode[i].BlackCode, "\\d+\\.", RegexOptions.IgnoreCase);
  1585. //去除多余空格,方法一Linq扩展方法
  1586. CodeList = CodeList.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  1587. //读取单条黑屏代码
  1588. for (int j = 0; j < CodeList.Count(); j++)
  1589. {
  1590. //去除多余空格,方法二使用Split()方法进行分割,分割有一个选项是RemoveEmptyEntries
  1591. CodeList[j] = CodeList[j].Replace("\r\n", string.Empty).Replace("\\r\\n", string.Empty).TrimStart().TrimEnd();
  1592. string[] Info = CodeList[j].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1593. //去除多余空格
  1594. Info = Info.Where(str => !string.IsNullOrWhiteSpace(str)).ToArray();
  1595. //判断黑屏代码是否正确拆分; 理应拆成9段
  1596. if (Info.TakeWhile((x) =>
  1597. {
  1598. return !excludeArr.Contains(x);
  1599. }).Count() != 9)
  1600. {
  1601. dt.Rows.Add(null, null, null, null, null, null, null, null, null, null, null, "本团组第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误,请联系机票同事核对", null, false);
  1602. //MessageBoxEx.Show("第" + (i + 1) + "段黑屏代码中第" + (j + 1) + " 条有误, 请联系机票同事核对");
  1603. return dt;
  1604. }
  1605. else
  1606. {
  1607. try
  1608. {
  1609. var monthEn = Info[1].Substring(4, 3);
  1610. //月
  1611. int month = Convert.ToInt32(GetLonger(monthEn));
  1612. //日
  1613. int day = Convert.ToInt32(Info[1].Substring(2, 2));
  1614. var time = new DateTime(2023, month, day); //
  1615. var isExist = Info.Contains("[中转]");
  1616. //dt.Columns.Add("Fliagtcode", typeof(string)); //航班号
  1617. //dt.Columns.Add("Date", typeof(string));//起飞日期
  1618. //dt.Columns.Add("Three", typeof(string));//三字码
  1619. //dt.Columns.Add("StartTime", typeof(string));//起飞时刻
  1620. //dt.Columns.Add("EndTime", typeof(string));//到达时刻
  1621. //dt.Columns.Add("StartBuilding", typeof(string));//出发航站楼
  1622. //dt.Columns.Add("EndBuilding", typeof(string));//到达航站楼
  1623. //dt.Columns.Add("AirModel", typeof(string)); //机型
  1624. //dt.Columns.Add("FlightTime", typeof(string));//飞行时间
  1625. //dt.Columns.Add("Day", typeof(string));//整理的起飞日期;作为排序依据
  1626. //dt.Columns.Add("ArrivedDate", typeof(string));//整理的到达日期
  1627. //dt.Columns.Add("Error", typeof(string));//整理的到达日期
  1628. //dt.Columns.Add("Sign", typeof(string));//标识:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1629. dt.Rows.Add(Info[0],
  1630. Info[1],
  1631. Info[2],
  1632. Info[3],
  1633. Info[4],
  1634. Info[5],
  1635. Info[6],
  1636. Info[7],
  1637. Info[8],
  1638. time.ToString("yyyy-MM-dd"),
  1639. time.ToString("yyyy-MM-dd"),
  1640. "",
  1641. "0",
  1642. isExist
  1643. );
  1644. }
  1645. catch (Exception ex)
  1646. {
  1647. string exstr = ex.Message.ToString();
  1648. }
  1649. }
  1650. }
  1651. //排序
  1652. dt.DefaultView.Sort = "Day asc";
  1653. dt = dt.DefaultView.ToTable();
  1654. }
  1655. }
  1656. return dt;
  1657. }
  1658. /// <summary>
  1659. /// 根据星期,月份的缩写,转换成数字或者全称
  1660. /// 根据币种中文名称返回币种代码
  1661. /// 根据数字返回机型型号【2、3开头的就是空客,比如空客320,7开头的就是波音,比如波音777】
  1662. /// 20210903贾文滔
  1663. /// </summary>
  1664. /// <param name="startDate"></param>
  1665. /// <param name="endDate"></param>
  1666. /// <returns></returns>
  1667. public static string GetLonger(string temp)
  1668. {
  1669. string str = "";
  1670. switch (temp.ToUpper())
  1671. {
  1672. case "美元":
  1673. str = "USD";
  1674. break;
  1675. case "日元":
  1676. str = "JPY";
  1677. break;
  1678. case "英镑":
  1679. str = "GBP";
  1680. break;
  1681. case "欧元":
  1682. str = "EUR";
  1683. break;
  1684. case "港币":
  1685. str = "HKD";
  1686. break;
  1687. case "MO":
  1688. str = "星期一";
  1689. break;
  1690. case "TU":
  1691. str = "星期二";
  1692. break;
  1693. case "WE":
  1694. str = "星期三";
  1695. break;
  1696. case "TH":
  1697. str = "星期四";
  1698. break;
  1699. case "FR":
  1700. str = "星期五";
  1701. break;
  1702. case "SA":
  1703. str = "星期六";
  1704. break;
  1705. case "SU":
  1706. str = "星期天";
  1707. break;
  1708. case "JAN":
  1709. str = "01";
  1710. break;
  1711. case "FEB":
  1712. str = "02";
  1713. break;
  1714. case "MAR":
  1715. str = "03";
  1716. break;
  1717. case "APR":
  1718. str = "04";
  1719. break;
  1720. case "MAY":
  1721. str = "05";
  1722. break;
  1723. case "JUN":
  1724. str = "06";
  1725. break;
  1726. case "JUL":
  1727. str = "07";
  1728. break;
  1729. case "AUG":
  1730. str = "08";
  1731. break;
  1732. case "SEP":
  1733. str = "09";
  1734. break;
  1735. case "OCT":
  1736. str = "10";
  1737. break;
  1738. case "NOV":
  1739. str = "11";
  1740. break;
  1741. case "DEC":
  1742. str = "12";
  1743. break;
  1744. case "MONDAY":
  1745. str = "星期一";
  1746. break;
  1747. case "TUESDAY":
  1748. str = "星期二";
  1749. break;
  1750. case "WEDNESDAY":
  1751. str = "星期三";
  1752. break;
  1753. case "THURSDAY":
  1754. str = "星期四";
  1755. break;
  1756. case "FRIDAY":
  1757. str = "星期五";
  1758. break;
  1759. case "SATURDAY":
  1760. str = "星期六";
  1761. break;
  1762. case "SUNDAY":
  1763. str = "星期日";
  1764. break;
  1765. case "01":
  1766. str = "JAN";
  1767. break;
  1768. case "02":
  1769. str = "FEB";
  1770. break;
  1771. case "03":
  1772. str = "MAR";
  1773. break;
  1774. case "04":
  1775. str = "APR";
  1776. break;
  1777. case "05":
  1778. str = "MAY";
  1779. break;
  1780. case "06":
  1781. str = "JUN";
  1782. break;
  1783. case "07":
  1784. str = "JUL";
  1785. break;
  1786. case "08":
  1787. str = "AUG";
  1788. break;
  1789. case "09":
  1790. str = "SEP";
  1791. break;
  1792. case "10":
  1793. str = "OCT";
  1794. break;
  1795. case "11":
  1796. str = "NOV";
  1797. break;
  1798. case "12":
  1799. str = "DEC";
  1800. break;
  1801. case "2":
  1802. str = "空客A";
  1803. break;
  1804. case "3":
  1805. str = "空客A";
  1806. break;
  1807. case "7":
  1808. str = "波音";
  1809. break;
  1810. }
  1811. return str;
  1812. }
  1813. /// <summary>
  1814. /// 根据月份返回天数
  1815. /// </summary>
  1816. /// <param name="temp"></param>
  1817. /// <returns></returns>
  1818. public static string GetDaysByMonth(string Month, int year)
  1819. {
  1820. string str = "";
  1821. //判断是否是闰年
  1822. if (DateTime.IsLeapYear(year) == false)
  1823. {
  1824. switch (Month.ToUpper())
  1825. {
  1826. case "JAN":
  1827. str = "31";
  1828. break;
  1829. case "FEB":
  1830. str = "28";
  1831. break;
  1832. case "MAR":
  1833. str = "31";
  1834. break;
  1835. case "APR":
  1836. str = "30";
  1837. break;
  1838. case "MAY":
  1839. str = "31";
  1840. break;
  1841. case "JUN":
  1842. str = "30";
  1843. break;
  1844. case "JUL":
  1845. str = "31";
  1846. break;
  1847. case "AUG":
  1848. str = "31";
  1849. break;
  1850. case "SEP":
  1851. str = "30";
  1852. break;
  1853. case "OCT":
  1854. str = "31";
  1855. break;
  1856. case "NOV":
  1857. str = "30";
  1858. break;
  1859. case "DEC":
  1860. str = "31";
  1861. break;
  1862. case "01":
  1863. str = "31";
  1864. break;
  1865. case "02":
  1866. str = "28";
  1867. break;
  1868. case "03":
  1869. str = "31";
  1870. break;
  1871. case "04":
  1872. str = "30";
  1873. break;
  1874. case "05":
  1875. str = "31";
  1876. break;
  1877. case "06":
  1878. str = "30";
  1879. break;
  1880. case "07":
  1881. str = "31";
  1882. break;
  1883. case "08":
  1884. str = "31";
  1885. break;
  1886. case "09":
  1887. str = "30";
  1888. break;
  1889. case "10":
  1890. str = "31";
  1891. break;
  1892. case "11":
  1893. str = "30";
  1894. break;
  1895. case "12":
  1896. str = "31";
  1897. break;
  1898. }
  1899. }
  1900. else
  1901. {
  1902. switch (Month.ToUpper())
  1903. {
  1904. case "JAN":
  1905. str = "31";
  1906. break;
  1907. case "FEB":
  1908. str = "29";
  1909. break;
  1910. case "MAR":
  1911. str = "31";
  1912. break;
  1913. case "APR":
  1914. str = "30";
  1915. break;
  1916. case "MAY":
  1917. str = "31";
  1918. break;
  1919. case "JUN":
  1920. str = "30";
  1921. break;
  1922. case "JUL":
  1923. str = "31";
  1924. break;
  1925. case "AUG":
  1926. str = "31";
  1927. break;
  1928. case "SEP":
  1929. str = "30";
  1930. break;
  1931. case "OCT":
  1932. str = "31";
  1933. break;
  1934. case "NOV":
  1935. str = "30";
  1936. break;
  1937. case "DEC":
  1938. str = "31";
  1939. break;
  1940. case "01":
  1941. str = "31";
  1942. break;
  1943. case "02":
  1944. str = "29";
  1945. break;
  1946. case "03":
  1947. str = "31";
  1948. break;
  1949. case "04":
  1950. str = "30";
  1951. break;
  1952. case "05":
  1953. str = "31";
  1954. break;
  1955. case "06":
  1956. str = "30";
  1957. break;
  1958. case "07":
  1959. str = "31";
  1960. break;
  1961. case "08":
  1962. str = "31";
  1963. break;
  1964. case "09":
  1965. str = "30";
  1966. break;
  1967. case "10":
  1968. str = "31";
  1969. break;
  1970. case "11":
  1971. str = "30";
  1972. break;
  1973. case "12":
  1974. str = "31";
  1975. break;
  1976. }
  1977. }
  1978. return str;
  1979. }
  1980. /// <summary>
  1981. /// op行程单 团组 城市路径
  1982. /// </summary>
  1983. /// <param name="diid">团组Id</param>
  1984. /// <param name="separator">分隔符</param>
  1985. /// <returns></returns>
  1986. public static string GetGroupCityLine(int diid, string separator)
  1987. {
  1988. string city = string.Empty;
  1989. var blackCode = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && x.DiId == diid).ToList();
  1990. if (blackCode.Count > 0)
  1991. {
  1992. var black = blackCode.First();
  1993. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  1994. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  1995. if (blackSp.Length > 0)
  1996. {
  1997. try
  1998. {
  1999. var cityArrCode = new List<string>(20);
  2000. foreach (var item in blackSp)
  2001. {
  2002. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  2003. var IndexSelect = itemSp[2];
  2004. var cityArrCodeLength = cityArrCode.Count - 1;
  2005. var startCity = IndexSelect.Substring(0, 3);
  2006. if (cityArrCodeLength > 0)
  2007. {
  2008. var arrEndCity = cityArrCode[cityArrCodeLength];
  2009. if (arrEndCity != startCity)
  2010. {
  2011. cityArrCode.Add(startCity.ToUpper());
  2012. }
  2013. }
  2014. else
  2015. {
  2016. cityArrCode.Add(startCity.ToUpper());
  2017. }
  2018. var endCity = IndexSelect.Substring(3, 3);
  2019. cityArrCode.Add(endCity.ToUpper());
  2020. }
  2021. var cityThree = string.Empty;
  2022. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  2023. cityThree = cityThree.TrimEnd(',');
  2024. if (string.IsNullOrWhiteSpace(cityThree))
  2025. {
  2026. throw new Exception("error");
  2027. }
  2028. string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
  2029. var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
  2030. foreach (var item in cityArrCode)
  2031. {
  2032. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  2033. if (find != null)
  2034. {
  2035. city += find.City + separator;
  2036. }
  2037. else
  2038. {
  2039. city += item + "[三字码未收录]" + separator;
  2040. }
  2041. }
  2042. city = city.TrimEnd(char.Parse(separator));
  2043. }
  2044. catch (Exception e)
  2045. {
  2046. city = "[黑屏代码格式不正确!]";
  2047. }
  2048. }
  2049. }
  2050. else city = "[未录入黑屏代码]";
  2051. return city;
  2052. }
  2053. /// <summary>
  2054. /// op行程单 团组 城市路径
  2055. /// </summary>
  2056. /// <param name="diid">团组Id</param>
  2057. /// <param name="separator">分隔符</param>
  2058. /// <returns></returns>
  2059. public static Dictionary<int,string> GetGroupCityLineItem(List<int> diids, string separator)
  2060. {
  2061. Dictionary<int, string> dicCitys = new Dictionary<int, string>();
  2062. var cityCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
  2063. var blackCodes = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && diids.Contains(x.DiId)).ToList();
  2064. foreach (var diid in diids)
  2065. {
  2066. string city = string.Empty;
  2067. var blackCode = blackCodes.Where(it => it.DiId == diid).ToList();
  2068. if (blackCode.Count > 0)
  2069. {
  2070. var black = blackCode.First();
  2071. black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
  2072. var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
  2073. if (blackSp.Length > 0)
  2074. {
  2075. try
  2076. {
  2077. var cityArrCode = new List<string>(20);
  2078. foreach (var item in blackSp)
  2079. {
  2080. var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
  2081. var IndexSelect = itemSp[2];
  2082. var cityArrCodeLength = cityArrCode.Count - 1;
  2083. var startCity = IndexSelect.Substring(0, 3);
  2084. if (cityArrCodeLength > 0)
  2085. {
  2086. var arrEndCity = cityArrCode[cityArrCodeLength];
  2087. if (arrEndCity != startCity)
  2088. {
  2089. cityArrCode.Add(startCity.ToUpper());
  2090. }
  2091. }
  2092. else
  2093. {
  2094. cityArrCode.Add(startCity.ToUpper());
  2095. }
  2096. var endCity = IndexSelect.Substring(3, 3);
  2097. cityArrCode.Add(endCity.ToUpper());
  2098. }
  2099. var cityThree = string.Empty;
  2100. cityArrCode.ForEach(x => cityThree += "'" + x + "',");
  2101. cityThree = cityThree.TrimEnd(',');
  2102. if (string.IsNullOrWhiteSpace(cityThree))
  2103. {
  2104. throw new Exception("error");
  2105. }
  2106. var cityArr = cityCodes.Where(it => cityThree.Contains(it.Three.ToUpper())).ToList();
  2107. foreach (var item in cityArrCode)
  2108. {
  2109. var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
  2110. if (find != null)
  2111. {
  2112. city += find.City + separator;
  2113. }
  2114. else
  2115. {
  2116. city += item + "[三字码未收录]" + separator;
  2117. }
  2118. }
  2119. city = city.TrimEnd(char.Parse(separator));
  2120. }
  2121. catch (Exception e)
  2122. {
  2123. city = "[黑屏代码格式不正确!]";
  2124. }
  2125. }
  2126. }
  2127. else city = "[未录入黑屏代码]";
  2128. dicCitys.Add(diid,city);
  2129. }
  2130. return dicCitys;
  2131. }
  2132. /// <summary>
  2133. /// op行程单相关团组信息 含途径城市
  2134. /// </summary>
  2135. /// <returns></returns>
  2136. public static async Task< List<MateOpGroupPageListView>> MateOpGroupPageListRedis()
  2137. {
  2138. List<MateOpGroupPageListView> _views = new List<MateOpGroupPageListView>();
  2139. string viewStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("MateOpGroupPageList");//string 取
  2140. if (!string.IsNullOrEmpty(viewStr))
  2141. {
  2142. _views = JsonConvert.DeserializeObject<List<MateOpGroupPageListView>>(viewStr);
  2143. }
  2144. else
  2145. {
  2146. string sql = string.Format($@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
  2147. TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
  2148. VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
  2149. JietuanOperator,IsSure,CreateTime,VisitCountry
  2150. From (
  2151. Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
  2152. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
  2153. ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
  2154. VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
  2155. su.CnName JietuanOperator,IsSure,gdi.CreateTime,gdi.VisitCountry
  2156. From Grp_DelegationInfo gdi
  2157. Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  2158. Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  2159. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  2160. Where gdi.IsDel = 0
  2161. ) temp");
  2162. _views = _dirRep._sqlSugar.SqlQueryable<MateOpGroupPageListView>(sql).ToList();
  2163. #region 处理所属部门
  2164. /*
  2165. * 1.sq 和 gyy 等显示 市场部
  2166. * 2.王鸽和主管及张总还有管理员号统一国交部
  2167. * 2-1. 4 管理员 ,21 张海麟
  2168. */
  2169. List<int> userIds = _views.Select(it => it.JietuanOperatorId).ToList();
  2170. List<int> userIds1 = new List<int>() { 4, 21 };
  2171. var UserDepDatas = _dirRep._sqlSugar.Queryable<Sys_Users>()
  2172. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2173. .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
  2174. .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
  2175. .ToList();
  2176. #endregion
  2177. _views.ForEach(it => {
  2178. it.RouteCity = GetGroupCityLine(it.Id, @"/");
  2179. it.Department = UserDepDatas.Find(it1 => it.JietuanOperatorId == it1.UserId)?.DepName ?? "Unknown";
  2180. });
  2181. TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay;
  2182. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("MateOpGroupPageList", JsonConvert.SerializeObject(_views), ts);//string 存
  2183. }
  2184. return _views;
  2185. }
  2186. /// <summary>
  2187. /// 获取黑屏代码日期列表
  2188. /// </summary>
  2189. /// <param name="dt"></param>
  2190. /// <returns></returns>
  2191. public static List<string> GetTimeListByDataTable(DataTable dt)
  2192. {
  2193. DateTime datestart = Convert.ToDateTime(dt.Rows[0]["Day"].ToString());
  2194. DateTime dateend = Convert.ToDateTime(dt.Rows[dt.Rows.Count - 1]["ArrivedDate"].ToString());
  2195. List<string> timeList = new List<string>();
  2196. while (datestart <= dateend)
  2197. {
  2198. timeList.Add(datestart.ToString("yyyy-MM-dd"));
  2199. datestart = datestart.AddDays(1);
  2200. }
  2201. return timeList;
  2202. }
  2203. const decimal conversion = 1.61M;
  2204. /// <summary>
  2205. /// 简要行程
  2206. /// </summary>
  2207. /// <param name="diid"></param>
  2208. /// <returns></returns>
  2209. public static Result GetBriefStroke (int diid)
  2210. {
  2211. DataTable resultTable = GetTableByBlackCode(diid);
  2212. if (resultTable == null)
  2213. {
  2214. return new Result { Code = -1, Msg = "黑屏代码有误或黑屏代码未录入" };
  2215. }
  2216. if (resultTable.Rows.Count == 0 || string.IsNullOrWhiteSpace(resultTable.Rows[0][1].ToString()))
  2217. {
  2218. string msg = string.Empty;
  2219. if (resultTable.Rows.Count > 0)
  2220. {
  2221. msg = resultTable.Rows[0]["Error"].ToString();
  2222. }
  2223. return new Result { Code = -1, Msg = $"黑屏代码有误;{msg}" };
  2224. }
  2225. var timeArr = GetTimeListByDataTable(resultTable);
  2226. var threeCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList(); //三字码
  2227. var airCompanys = _dirRep._sqlSugar.Queryable<Res_AirCompany>().Where(it => it.IsDel == 0).ToList(); //航司公司
  2228. var obDatas = _dirRep._sqlSugar.Queryable<Res_OfficialActivities>().Where(it => it.IsDel == 0 && it.DiId == diid).ToList(); //公务信息
  2229. var NewListTravel = new List<Grp_TravelList>();
  2230. var index = 0;
  2231. var stopCity = string.Empty;
  2232. foreach (var item in timeArr)
  2233. {
  2234. string trip = string.Empty;
  2235. string weekDay = string.Empty;
  2236. DateTime time = DateTime.Now;
  2237. if (DateTime.TryParse(item, out time))
  2238. {
  2239. weekDay = weekdays[(int)time.DayOfWeek];
  2240. }
  2241. else
  2242. {
  2243. weekDay = "日期格式不正确!";
  2244. }
  2245. var empty = "【未收入该三字码!请机票同事录入】";
  2246. var tabSelect = resultTable.Select(string.Format("Day = '{0}'", item));
  2247. var isMoreTraffic = false;
  2248. if (tabSelect.Length > 0)
  2249. {
  2250. isMoreTraffic = true;
  2251. var takeOffTime = DateTime.Parse(item);
  2252. var fallToTime = DateTime.Parse(item);
  2253. Res_ThreeCode start_Object = null;
  2254. Res_ThreeCode end_Object = null;
  2255. bool isTrade = false;
  2256. //air 处理
  2257. foreach (var tabRow in tabSelect)
  2258. {
  2259. takeOffTime = DateTime.Parse(item);
  2260. fallToTime = DateTime.Parse(item);
  2261. var takeOff = tabRow["StartTime"].ToString();
  2262. var fallTo = tabRow["EndTime"].ToString();
  2263. takeOffTime = takeOffTime.AddHours(int.Parse(takeOff.Substring(0, 2)));
  2264. takeOffTime = takeOffTime.AddMinutes(int.Parse(takeOff.Substring(2, 2)));
  2265. fallToTime = fallToTime.AddHours(int.Parse(fallTo.Substring(0, 2)));
  2266. fallToTime = fallToTime.AddMinutes(int.Parse(fallTo.Substring(2, 2)));
  2267. var threeCode = tabRow["Three"].ToString();
  2268. var start = threeCode.Substring(0, 3);
  2269. var end = threeCode.Substring(3, 3);
  2270. stopCity = end;
  2271. start_Object = threeCodes.Find(x => x.Three.ToUpper() == start.ToUpper());
  2272. end_Object = threeCodes.Find(x => x.Three.ToUpper() == end.ToUpper());
  2273. if (start_Object == null)
  2274. {
  2275. start_Object = new Res_ThreeCode()
  2276. {
  2277. AirPort = empty,
  2278. AirPort_En = empty,
  2279. City = empty,
  2280. Country = empty,
  2281. Four = empty,
  2282. Three = empty,
  2283. };
  2284. }
  2285. if (end_Object == null)
  2286. {
  2287. end_Object = new Res_ThreeCode()
  2288. {
  2289. AirPort = empty,
  2290. AirPort_En = empty,
  2291. City = empty,
  2292. Country = empty,
  2293. Four = empty,
  2294. Three = empty,
  2295. };
  2296. }
  2297. //航班号
  2298. string flightcode = tabRow["Fliagtcode"].ToString();
  2299. trip += $"{takeOffTime.ToString("HH:mm")}—{fallToTime.ToString("HH:mm")} {start_Object.City}—{end_Object.City} 航班号:{flightcode}\r\n";
  2300. }
  2301. //var airArrive = fallToTime; //航班落地时间
  2302. time = fallToTime.AddHours(1.5); //出机场一个半小时
  2303. string Time = string.Empty;
  2304. string Distance = string.Empty;
  2305. int GetGoogleResult = 0;
  2306. int GetDistResult = 0;
  2307. JObject Result = null;
  2308. try
  2309. {
  2310. Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace(" ", "").Trim();
  2311. Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString().Replace(" ", "").Trim();
  2312. if (Time.Contains("hours"))
  2313. {
  2314. Time = Time.Replace("hours", "小时");
  2315. }
  2316. if (Time.Contains("hour"))
  2317. {
  2318. Time = Time.Replace("hour", "小时");
  2319. }
  2320. Time = Time.Replace("mins", "分钟");
  2321. if (Distance.Contains("mi"))
  2322. {
  2323. var distSp = Regex.Split(Distance, "mi");
  2324. if (distSp.Length > 0)
  2325. {
  2326. Distance = (decimal.Parse(distSp[0]) * conversion).ToString("#0.00") + " 公里";
  2327. }
  2328. }
  2329. if (Distance.Contains("km"))
  2330. {
  2331. Distance = Distance.Replace("km", "公里");
  2332. }
  2333. if (Time.Contains("小时"))
  2334. {
  2335. var xs = Regex.Split(Time, "小时");
  2336. var xsValue = int.Parse(xs[0]);
  2337. var fz = Regex.Split(xs[1], "分钟");
  2338. var fzValue = int.Parse(fz[0]);
  2339. GetGoogleResult = xsValue * 60;
  2340. GetGoogleResult += fzValue;
  2341. }
  2342. else if (Time.Contains("分钟"))
  2343. {
  2344. GetGoogleResult = int.Parse(Regex.Split(Time, "分钟")[0]);
  2345. }
  2346. if (Distance.Contains("公里"))
  2347. {
  2348. GetDistResult = (int)decimal.Parse(Regex.Split(Distance, "公里")[0]);
  2349. }
  2350. if (GetGoogleResult > 0 && GetGoogleResult % 5 != 0)
  2351. {
  2352. while (GetGoogleResult % 5 != 0)
  2353. {
  2354. GetGoogleResult++;
  2355. }
  2356. }
  2357. if (GetDistResult % 5 != 0 && GetDistResult > 0)
  2358. {
  2359. while (GetDistResult % 5 != 0)
  2360. {
  2361. GetDistResult++;
  2362. }
  2363. }
  2364. int H = (GetGoogleResult / 60);
  2365. int m = (GetGoogleResult % 60);
  2366. string TimeStr = string.Empty;
  2367. if (H != 0)
  2368. {
  2369. if (H < 10)
  2370. {
  2371. TimeStr += "0" + H + "小时";
  2372. }
  2373. else
  2374. {
  2375. TimeStr += H + "小时";
  2376. }
  2377. }
  2378. if (m < 10)
  2379. {
  2380. TimeStr += "0" + m + "分钟";
  2381. }
  2382. else
  2383. {
  2384. TimeStr += m + "分钟";
  2385. }
  2386. Time = TimeStr;
  2387. Distance = GetDistResult.ToString() + "公里";
  2388. }
  2389. catch (Exception ex)
  2390. {
  2391. Time = "未知!";
  2392. Distance = "未知!";
  2393. }
  2394. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区 路程{Distance},耗时{Time})";
  2395. //trip += $"{time.ToString("HH:mm")} 搭乘专车前往市区({end_Object.AirPort} - {end_Object.City}市区)";
  2396. time = time.AddMinutes(GetGoogleResult); //到达市区时间
  2397. string tripDate = Convert.ToDateTime(item).ToString("M月d日");
  2398. if (index == timeArr.Count - 1)
  2399. {
  2400. NewListTravel.Add(new Grp_TravelList
  2401. {
  2402. CreateTime = DateTime.Now,
  2403. CreateUserId = 0,
  2404. Diid = diid,
  2405. Date = tripDate,
  2406. Trip = trip,
  2407. WeekDay = weekDay,
  2408. Days = index + 1,
  2409. Traffic_First = "飞机",
  2410. Traffic_Second = "汽车",
  2411. Diffgroup = 1,
  2412. Issel = 1,
  2413. IsDel = 0,
  2414. });
  2415. continue;
  2416. }
  2417. if (time.Day != fallToTime.Day) //超出一天
  2418. {
  2419. NewListTravel.Add(new Grp_TravelList
  2420. {
  2421. CreateTime = DateTime.Now,
  2422. CreateUserId = 0,
  2423. Diid = diid,
  2424. Date = tripDate,
  2425. Trip = trip,
  2426. WeekDay = weekDay,
  2427. Days = index + 1,
  2428. Traffic_First = "飞机",
  2429. Traffic_Second = "汽车",
  2430. Diffgroup = 1,
  2431. Issel = 1,
  2432. IsDel = 0,
  2433. });
  2434. continue;
  2435. }
  2436. var obInfo = obDatas.Find(it => Convert.ToDateTime(it.Date).ToString("M月d日").Equals(tripDate));
  2437. string obtime = "";
  2438. string obcontent = "";
  2439. if (obInfo != null)
  2440. {
  2441. obtime = obInfo.Time;
  2442. obcontent = $"拜访{obInfo.Client ?? "公务出访单位未录入"}{obInfo.Job ?? "公务出访联系人职务未录入"}{obInfo.Contact ?? "公务出访联系人职务未录入"}";
  2443. }
  2444. bool obTime_bool = DateTime.TryParse(obtime, out DateTime obTimeDt);
  2445. if (time.Hour < 9) // && (airArrive < new DateTime(airArrive.Year,airArrive.Month,airArrive.Day,6, 30, 0))
  2446. {
  2447. if (obTime_bool)
  2448. {
  2449. if (obTimeDt.Hour < 9)
  2450. {
  2451. trip += $"{obTimeDt.ToString("HH:mm")}—10:30 {obcontent};\r\n";
  2452. }
  2453. }
  2454. else
  2455. {
  2456. trip += "09:00—10:30 公务活动;\r\n";
  2457. }
  2458. }
  2459. else if (time.Hour < 10)
  2460. {
  2461. if (obTime_bool)
  2462. {
  2463. if (obTimeDt.Hour < 10)
  2464. {
  2465. trip += $"{obTimeDt.ToString("HH:mm")}—12:00 {obcontent};\r\n";
  2466. }
  2467. }
  2468. else
  2469. {
  2470. trip += "10:30—12:00 公务活动;\r\n";
  2471. }
  2472. }
  2473. if (time.Hour < 13)
  2474. {
  2475. //trip += $"\r\n{time.ToString("HH:mm")} 午餐于当地餐厅;";
  2476. }
  2477. if (time < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  2478. {
  2479. if (obTime_bool)
  2480. {
  2481. if (obTimeDt < new DateTime(time.Year, time.Month, time.Day, 14, 30, 0))
  2482. {
  2483. trip += $"{obTimeDt.ToString("HH:mm")}—16:00 {obcontent};\r\n";
  2484. }
  2485. }
  2486. else
  2487. {
  2488. trip += "14:00—16:00 公务活动;\r\n";
  2489. }
  2490. }
  2491. else if (time.Hour < 16)
  2492. {
  2493. if (obTime_bool)
  2494. {
  2495. if (obTimeDt.Hour < 16)
  2496. {
  2497. trip += $"{obTimeDt.ToString("HH:mm")}—17:30 {obcontent};\r\n";
  2498. }
  2499. }
  2500. else
  2501. {
  2502. trip += "16:00—17:30 公务活动;\r\n";
  2503. }
  2504. }
  2505. //if (time.Hour < 18)
  2506. //{
  2507. // trip += $"\r\n18:00 晚餐于当地餐厅;";
  2508. //}
  2509. //time = time.AddHours(1);
  2510. //trip += $"\r\n{time.ToString("HH:mm")} 搭乘专车前往酒店,抵达后办理入住;";
  2511. }
  2512. else
  2513. {
  2514. var end_Object = threeCodes.Find(x => x.Three.ToUpper() == stopCity.ToUpper());
  2515. if (end_Object == null)
  2516. {
  2517. end_Object = new Res_ThreeCode()
  2518. {
  2519. AirPort = empty,
  2520. AirPort_En = empty,
  2521. City = empty,
  2522. Country = empty,
  2523. Four = empty,
  2524. Three = empty,
  2525. };
  2526. }
  2527. //trip += $"{end_Object.City}\r\n";
  2528. // trip += @"08:00 早餐于酒店;
  2529. //09:00—10:30 公务活动;
  2530. //12:00 午餐于当地餐厅;
  2531. //14:00—16:00 公务活动;
  2532. //18:00 晚餐于当地餐厅;
  2533. //19:00 入住酒店休息;";
  2534. trip += "09:00—10:30 公务活动;\r\n14:00—16:00 公务活动;\r\n";
  2535. }
  2536. string[] traffic = new string[] { "飞机", "汽车" };
  2537. if (!isMoreTraffic)
  2538. {
  2539. traffic = new string[] { "汽车", "" };
  2540. }
  2541. NewListTravel.Add(new Grp_TravelList
  2542. {
  2543. CreateTime = DateTime.Now,
  2544. CreateUserId = 0,
  2545. Diid = diid,
  2546. Date = Convert.ToDateTime(item).ToString("M月d日"),
  2547. Trip = trip,
  2548. WeekDay = weekDay,
  2549. Days = index + 1,
  2550. Traffic_First = traffic[0],
  2551. Traffic_Second = traffic[1],
  2552. Diffgroup = 1,
  2553. Issel = 1,
  2554. IsDel = 0,
  2555. });
  2556. index++;
  2557. }
  2558. return new Result() { Code = 0, Msg = "获取成功!", Data = NewListTravel };
  2559. }
  2560. /// <summary>
  2561. /// 根据日期获取星期
  2562. /// </summary>
  2563. /// <param name="dt"></param>
  2564. /// <returns></returns>
  2565. public static string GetWeek(this string dtStr)
  2566. {
  2567. string week = "";
  2568. bool isDt = DateTime.TryParse(dtStr,out DateTime dt);
  2569. if (isDt)
  2570. {
  2571. week = weekdays[(int)dt.DayOfWeek];
  2572. }
  2573. return week;
  2574. }
  2575. #endregion
  2576. }
  2577. }