DelegationInfoRepository.cs 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.AesEncryption;
  4. using OASystem.Domain.Dtos.Financial;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.ViewModels.Groups;
  9. using OASystem.Infrastructure.Repositories.System;
  10. using OASystem.Infrastructure.Tools;
  11. using System.Diagnostics;
  12. namespace OASystem.Infrastructure.Repositories.Groups
  13. {
  14. /// <summary>
  15. /// 接团信息
  16. /// </summary>
  17. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  18. {
  19. private readonly SetDataRepository _setDataRepository;
  20. private readonly UsersRepository _usersRepository;
  21. private readonly TaskAssignmentRepository _taskAssignmentRep;
  22. private readonly IMapper _mapper;
  23. //private readonly TeamRateRepository _teamRateRep;
  24. //public readonly Logs _logs;
  25. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository,
  26. TaskAssignmentRepository taskAssignmentRep, IMapper mapper)
  27. : base(sqlSugar)
  28. {
  29. _setDataRepository = setDataRepository;
  30. _usersRepository = usersRepository;
  31. _taskAssignmentRep = taskAssignmentRep;
  32. _mapper = mapper;
  33. //_teamRateRep = teamRateRep;
  34. }
  35. #region 团组信息 团组详情共享Api
  36. /// <summary>
  37. /// 查询团组简略详情列表
  38. /// Page 根据Ctable And User 返回可操作的团
  39. /// </summary>
  40. /// <param name="dto"></param>
  41. /// <returns></returns>
  42. public async Task<JsonView> ListByCTableAndUserId(GroupListByCTableAndUserIdDto dto)
  43. {
  44. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  45. if (dto.CTable < 1)
  46. {
  47. view.Msg = MsgTips.UserId;
  48. return view;
  49. }
  50. if (dto.CTable < 1)
  51. {
  52. view.Msg = "请输入正确的CTable Id !76 酒店预订<br/>77 行程<br/>79 车/导游地接<br/>80 签证<br/>81 邀请/公务活动<br/>82 团组客户保险<br/>85 机票预订<br/>98 其他款项<br/>751 酒店早餐";
  53. return view;
  54. }
  55. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  56. {
  57. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  58. string sql = string.Format(@"Select row_number() over(order by di.VisitStartDate Desc) as Row_Number,
  59. di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,
  60. di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime
  61. From Grp_GroupsTaskAssignment gta
  62. Inner Join Grp_DelegationInfo di On gta.DIId = di.Id
  63. Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
  64. And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
  65. if (!string.IsNullOrEmpty(dto.TeamName))
  66. {
  67. sql = string.Format($"{sql} And di.TeamName Like '%{dto.TeamName}%'");
  68. }
  69. //去重
  70. sql = $"{sql} GROUP BY di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,di.VisitEndDate,di.VisitDays,di.VisitPNumber,di.CreateTime";
  71. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  72. var data = await _sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
  73. foreach (var item in data)
  74. {
  75. item.VisitStartDate = item.VisitStartDate == "" ? "" : Convert.ToDateTime(item.VisitStartDate).ToString("yyyy-MM-dd");
  76. item.VisitEndDate = item.VisitEndDate == "" ? "" : Convert.ToDateTime(item.VisitEndDate).ToString("yyyy-MM-dd");
  77. item.VisitCountry = !string.IsNullOrEmpty(item.VisitCountry) && item.VisitCountry.Contains("|") ? item.VisitCountry.Replace("|", "、") : item.VisitCountry;
  78. }
  79. view.Code = StatusCodes.Status200OK;
  80. view.Msg = "操作成功!";
  81. view.Data = data;
  82. view.Count = total;
  83. return view;
  84. }
  85. else
  86. {
  87. view.Msg = "请输入正确的PortType 1 Web 2 Android 3 IOS ";
  88. return view;
  89. }
  90. }
  91. /// <summary>
  92. /// 团组信息 团组预览详情共享Api
  93. /// </summary>
  94. /// <param name="dto"></param>
  95. /// <returns></returns>
  96. public async Task<JsonView> PostShareGroupInfo(ShareGroupInfoDto dto)
  97. {
  98. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  99. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  100. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  101. if (dto.PortType == 1) //Web
  102. {
  103. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).FirstAsync();
  104. if (_DelegationInfo != null)
  105. {
  106. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  107. }
  108. else
  109. {
  110. view.Msg = "暂无该团组信息";
  111. return view;
  112. }
  113. view.Data = _DelegationInfo;
  114. }
  115. else if (dto.PortType == 2 || dto.PortType == 3) //IOS Or Android
  116. {
  117. var _DelegationInfo = await _sqlSugar.SqlQueryable<IOSOrAndroid_ShareGroupInfoView>(sql).FirstAsync();
  118. if (_DelegationInfo != null)
  119. {
  120. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  121. view.Data = _DelegationInfo;
  122. }
  123. else
  124. {
  125. view.Msg = "暂无该团组信息";
  126. return view;
  127. }
  128. view.Data = _DelegationInfo;
  129. }
  130. else
  131. {
  132. view.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS";
  133. return view;
  134. }
  135. view.Code = StatusCodes.Status200OK;
  136. view.Msg = "成功!";
  137. return view;
  138. }
  139. /// <summary>
  140. /// 团组信息List 团组预览详情共享Api
  141. /// </summary>
  142. /// <param name="dto"></param>
  143. /// <returns></returns>
  144. public async Task<Result> PostShareGroupInfos(int portType)
  145. {
  146. var result = new Result() { Code = -2, Msg = "未知错误", Data = new List<object>() { } };
  147. string sql = string.Format(@"Select Id,TeamName,TourCode,ClientName,VisitCountry,VisitStartDate,VisitEndDate,VisitDays,VisitPNumber
  148. From Grp_DelegationInfo With(NoLock) Where IsDel = 0 Order By VisitStartDate Desc");
  149. var _DelegationInfo = await _sqlSugar.SqlQueryable<Web_ShareGroupInfoView>(sql).ToListAsync();
  150. if (_DelegationInfo.Count > 0)
  151. {
  152. foreach (var item in _DelegationInfo)
  153. {
  154. item.VisitCountry = FormartTeamName(item.VisitCountry);
  155. }
  156. }
  157. else { result.Msg = "暂无该团组信息"; return result; }
  158. if (portType == 1) //Web
  159. {
  160. result.Data = _DelegationInfo;
  161. }
  162. else if (portType == 2 || portType == 3) //IOS Or Android
  163. {
  164. result.Data = _DelegationInfo;
  165. }
  166. else { result.Msg = "请输入正确的端口号。1 Web 2 Android 3 IOS"; return result; }
  167. result.Code = 0;
  168. result.Msg = "成功!";
  169. return result;
  170. }
  171. #endregion
  172. /// <summary>
  173. /// 获取接团信息Info
  174. /// </summary>
  175. /// <param name="dto"></param>
  176. /// <returns></returns>
  177. public async Task<Result> PostGroupInfo(GroupInfoDto dto)
  178. {
  179. var result = new Result() { Code = -2, Msg = "未知错误" };
  180. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  181. {
  182. string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  183. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  184. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  185. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,Officialneeds
  186. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  187. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  188. if (_DelegationInfo != null)
  189. {
  190. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  191. result.Code = 0;
  192. result.Msg = "成功!";
  193. result.Data = _DelegationInfo;
  194. }
  195. else result.Msg = "暂无该团组信息";
  196. }
  197. return result;
  198. }
  199. #region 团组
  200. /// <summary>
  201. /// 统一团组国家分割字符
  202. /// </summary>
  203. /// <param name="teamName"></param>
  204. /// <returns></returns>
  205. public string FormartTeamName(string? teamName)
  206. {
  207. string str = "";
  208. if (!string.IsNullOrEmpty(teamName))
  209. {
  210. str = teamName;
  211. var searchreplaces = new List<string>() { "|", " ", "/", ",", "," };
  212. foreach (var item in searchreplaces)
  213. {
  214. if (str.Contains(item))
  215. {
  216. str = str.Replace(item, "、");
  217. break;
  218. }
  219. }
  220. }
  221. return str.Trim();
  222. }
  223. /// <summary>
  224. /// 团组国家分割字符
  225. /// 返回 国家数组
  226. /// </summary>
  227. /// <param name="countryString"></param>
  228. /// <returns></returns>
  229. public List<string> GroupSplitCountry(string countryString)
  230. {
  231. if (string.IsNullOrWhiteSpace(countryString))
  232. return new List<string>();
  233. // 预先定义分隔符
  234. var separators = new[]
  235. {
  236. ' ', '\t', '\n', '\r', // 空白字符
  237. '、', '|', ',', ',', ';', ';', '/', '\\', // 分隔符
  238. '(', ')', '[', ']', '{', '}', '<', '>', // 括号
  239. '【', '】', '(', ')', '《', '》', // 中文括号
  240. '\'', '"', '`', // 引号
  241. '-', '_', '+', '=', '~', '!', '@', '#', '$', '%', '^', '&', '*',
  242. '·', '。', '?', '!', ':', ';', ',', '、', '~', '—', // 中文标点
  243. '€', '£', '¥', '¢' // 货币符号
  244. };
  245. return countryString.Trim()
  246. .Split(separators, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
  247. .Distinct() // 去重
  248. .ToList();
  249. }
  250. /// <summary>
  251. /// 获取接团信息 Page List
  252. /// </summary>
  253. /// <param name="dto"></param>
  254. /// <returns></returns>
  255. public async Task<Result> GetGroupPageList(GroupCommissionDto dto)
  256. {
  257. var result = new Result() { Code = -2, Msg = "未知错误" };
  258. var groupsInfoPageList = new ListViewBase<DelegationPageListView>()
  259. {
  260. ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  261. };
  262. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  263. {
  264. int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;
  265. int endIndex = startIndex + dto.PageSize - 1;
  266. //int taskUserId = -1;
  267. string taskGroupIds = string.Empty;
  268. #region 处理用户团组操作权限
  269. if (dto.UserId != -1)
  270. {
  271. }
  272. #endregion
  273. string sql = string.Format(@"Select * From(Select row_number() over (order by gdi.Id Desc) as RowNumber,
  274. gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,
  275. ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,
  276. su.CnName JietuanOperator,IsSure
  277. From Grp_DelegationInfo gdi
  278. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  279. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  280. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  281. Where gdi.IsDel = 0
  282. )temp Where RowNumber Between {0} and {1}", startIndex, endIndex);
  283. string sqlCount = string.Format(@"Select Count(1) as Count From Grp_DelegationInfo gdi
  284. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  285. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  286. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  287. Where gdi.IsDel = 0 ");
  288. List<DelegationPageListView> _DeleInfoList = await _sqlSugar.SqlQueryable<DelegationPageListView>(sql).ToListAsync();
  289. DelegationPageCountView _DeleCount = await _sqlSugar.SqlQueryable<DelegationPageCountView>(sqlCount).FirstAsync();
  290. int count = _DeleCount.Count;
  291. groupsInfoPageList = new ListViewBase<DelegationPageListView>
  292. {
  293. CurrPageIndex = dto.PageIndex,
  294. CurrPageSize = dto.PageSize,
  295. DataCount = count,
  296. DataList = _DeleInfoList
  297. };
  298. result.Code = 0;
  299. result.Msg = "成功!";
  300. result.Data = groupsInfoPageList;
  301. }
  302. return result;
  303. }
  304. /// <summary>
  305. /// 获取接团信息List
  306. /// </summary>
  307. /// <param name="dto"></param>
  308. /// <returns></returns>
  309. public async Task<Result> GetGroupList(GroupListDto dto)
  310. {
  311. var result = new Result() { Code = -2, Msg = "未知错误" };
  312. if (dto.PortType == 1)
  313. {
  314. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  315. ,gs.Id as GrpScheduleId
  316. From Grp_DelegationInfo gdi
  317. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  318. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  319. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  320. left Join Grp_Schedule gs On gdi.Id = gs.DiId
  321. Where gdi.IsDel = 0
  322. Order By gdi.CreateTime Desc");
  323. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  324. if (_DelegationList.Count > 0)
  325. {
  326. result.Code = 0;
  327. result.Msg = "成功!";
  328. result.Data = _DelegationList;
  329. }
  330. else
  331. {
  332. result.Msg = "暂无该团组信息";
  333. }
  334. }
  335. else if (dto.PortType == 2 || dto.PortType == 3) //web
  336. {
  337. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  338. From Grp_DelegationInfo gdi
  339. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  340. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  341. Left Join Sys_Users su On gdi.CreateUserId = su.Id
  342. Where gdi.IsDel = 0
  343. Order By gdi.CreateTime Desc");
  344. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  345. if (_DelegationList.Count > 0)
  346. {
  347. result.Code = 0;
  348. result.Msg = "成功!";
  349. result.Data = _DelegationList;
  350. }
  351. else
  352. {
  353. result.Msg = "暂无该团组信息";
  354. }
  355. }
  356. return result;
  357. }
  358. /// <summary>
  359. /// 获取接团信息Info
  360. /// </summary>
  361. /// <param name="dto"></param>
  362. /// <returns></returns>
  363. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  364. {
  365. var result = new Result() { Code = -2, Msg = "未知错误" };
  366. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
  367. {
  368. string sql = string.Format(@"Select Id,CityId,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  369. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,IsBid,
  370. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  371. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,WeChatNo,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds
  372. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  373. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  374. if (_DelegationInfo != null)
  375. {
  376. _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
  377. _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
  378. //验证城市值 不存在则设置默认值
  379. var cityInfo = await CityInfoById(_DelegationInfo.CityId);
  380. if (cityInfo != null)
  381. {
  382. _DelegationInfo.CityName = cityInfo.Name;
  383. }
  384. else
  385. {
  386. _DelegationInfo.CityId = 3505;
  387. _DelegationInfo.CityName = "四川-成都";
  388. }
  389. //if (_DelegationInfo.TontractTime)
  390. //{
  391. //}
  392. result.Code = 0;
  393. result.Msg = "成功!";
  394. result.Data = _DelegationInfo;
  395. if (dto.PortType == 2)
  396. {
  397. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  398. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  399. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  400. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  401. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  402. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  403. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  404. var timeParam = new DateTime();
  405. foreach (var item in _DeleClients)
  406. {
  407. var param = new TourClientListProcessInfo();
  408. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  409. clientInfo ??= new Crm_DeleClient();
  410. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  411. clientIDInfo ??= new Crm_CustomerCert();
  412. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  413. Company ??= new Crm_CustomerCompany();
  414. param.IDCardNo = clientIDInfo.CertNo;
  415. param.Remark = item.Remark;
  416. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  417. param.FirstName = clientInfo.FirstName;
  418. param.LastName = clientInfo.LastName;
  419. param.CompanyFullName = Company.CompanyFullName;
  420. param.Job = clientInfo.Job;
  421. param.Sex = clientInfo.Sex;
  422. param.Phone = clientInfo.Phone;
  423. param.Pinyin = clientInfo.Pinyin;
  424. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  425. param.MealSpecialNeeds = item.MealSpecialNeeds;
  426. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  427. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  428. param.Id = clientInfo.Id;
  429. EncryptionProcessor.DecryptProperties(param);
  430. TourClientListInfoArr.Add(param);
  431. }
  432. GroupProcessOperationDtoParam.PortType = dto.PortType;
  433. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  434. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  435. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  436. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  437. result.Data = GroupProcessOperationDtoParam;
  438. }
  439. else if (dto.PortType == 3)
  440. {
  441. var GroupProcessOperationDtoParam = new GroupProcessOperationDto();
  442. GroupProcessOperationDtoParam = _mapper.Map<DelegationInfoWebView, GroupProcessOperationDto>(_DelegationInfo);
  443. List<Crm_DeleClient> DeleClientArr = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0).ToListAsync(); //客户信息
  444. List<Grp_TourClientList> _DeleClients = await _sqlSugar.Queryable<Grp_TourClientList>().Where(it => it.IsDel == 0 && it.DiId == dto.Id).ToListAsync(); // 接团客户名单
  445. List<Crm_CustomerCert> _CustomerCerts = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 && it.SdId == 773).ToListAsync(); // 身份证类型证件信息
  446. List<Crm_CustomerCompany> CompanyArr = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0).ToListAsync();
  447. var TourClientListInfoArr = new List<TourClientListProcessInfo>();
  448. var timeParam = new DateTime();
  449. foreach (var item in _DeleClients)
  450. {
  451. var param = new TourClientListProcessInfo();
  452. var clientInfo = DeleClientArr.FirstOrDefault(x => x.Id == item.ClientId);
  453. clientInfo ??= new Crm_DeleClient();
  454. var clientIDInfo = _CustomerCerts.FirstOrDefault(x => x.DcId == item.ClientId); //身份证信息
  455. clientIDInfo ??= new Crm_CustomerCert();
  456. var Company = CompanyArr.FirstOrDefault(x => x.Id == clientInfo.CrmCompanyId);
  457. Company ??= new Crm_CustomerCompany();
  458. param.IDCardNo = clientIDInfo.CertNo;
  459. param.Remark = item.Remark;
  460. param.BirthDay = clientInfo.BirthDay == null ? "" : DateTime.TryParse(Convert.ToDateTime(clientInfo.BirthDay).ToString("yyyy-MM-dd"), out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  461. param.FirstName = clientInfo.FirstName;
  462. param.LastName = clientInfo.LastName;
  463. param.CompanyFullName = Company.CompanyFullName;
  464. param.Job = clientInfo.Job;
  465. param.Sex = clientInfo.Sex;
  466. param.Phone = clientInfo.Phone;
  467. param.Pinyin = clientInfo.Pinyin;
  468. param.HotelSpecialNeeds = item.HotelSpecialNeeds;
  469. param.MealSpecialNeeds = item.MealSpecialNeeds;
  470. param.ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds;
  471. param.ShippingSpaceTypeId = item.ShippingSpaceTypeId;
  472. param.Id = item.Id;
  473. EncryptionProcessor.DecryptProperties(param);
  474. TourClientListInfoArr.Add(param);
  475. }
  476. GroupProcessOperationDtoParam.PortType = dto.PortType;
  477. GroupProcessOperationDtoParam.TourClientListInfos = TourClientListInfoArr;
  478. GroupProcessOperationDtoParam.VisitDate = DateTime.TryParse(GroupProcessOperationDtoParam.VisitDate, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  479. GroupProcessOperationDtoParam.TontractTime = DateTime.TryParse(GroupProcessOperationDtoParam.TontractTime, out timeParam) ? timeParam.ToString("yyyy-MM-dd") : "";
  480. result.Data = GroupProcessOperationDtoParam;
  481. }
  482. }
  483. else result.Msg = "暂无该团组信息";
  484. }
  485. return result;
  486. }
  487. /// <summary>
  488. /// 获取接团信息 编辑
  489. /// 城市基础 数据源
  490. /// </summary>
  491. /// <param name="dto"></param>
  492. /// <returns></returns>
  493. public async Task<List<CityTree>> ProvinceCityBasicSource()
  494. {
  495. var data = await _sqlSugar.Queryable<CityTree>().AS("Sys_Cities")
  496. .Where(x => x.IsDel == 0 && x.CountriesId == 44)
  497. .ToTreeAsync(it => it.Child, it => it.ParentId, 0);
  498. if (data.Any())
  499. {
  500. //移动指定数据在最前面
  501. data = MoveElementToFront(data, "云南");
  502. data = MoveElementToFront(data, "贵州");
  503. data = MoveElementToFront(data, "重庆");
  504. data = MoveElementToFront(data, "四川");
  505. }
  506. return data;
  507. }
  508. /// <summary>
  509. /// 获取接团信息 编辑
  510. /// 省份基础 数据源
  511. /// </summary>
  512. /// <param name="dto"></param>
  513. /// <returns></returns>
  514. public async Task<GroupCityBasicSourceView[]> ProvinceBasicSource()
  515. {
  516. var list = Array.Empty<GroupCityBasicSourceView>();
  517. var data = await ProvinceCityBasicSource();
  518. if (data.Any())
  519. {
  520. //移动指定数据在最前面
  521. data = MoveElementToFront(data, "北京");
  522. data = MoveElementToFront(data, "云南");
  523. data = MoveElementToFront(data, "贵州");
  524. data = MoveElementToFront(data, "重庆");
  525. data = MoveElementToFront(data, "四川");
  526. list = data.Select(x => new GroupCityBasicSourceView() { Id = x.Id, Name = x.Name_CN }).ToArray();
  527. }
  528. return list;
  529. }
  530. /// <summary>
  531. /// 获取接团信息 编辑
  532. /// 城市基础 数据源
  533. /// </summary>
  534. /// <param name="dto"></param>
  535. /// <returns></returns>
  536. public async Task<GroupCityBasicSourceView[]> CityBasicSource()
  537. {
  538. var list = new List<GroupCityBasicSourceView>();
  539. var data = await ProvinceCityBasicSource();
  540. if (data.Any())
  541. {
  542. //移动指定数据在最前面
  543. data = MoveElementToFront(data, "云南");
  544. data = MoveElementToFront(data, "贵州");
  545. data = MoveElementToFront(data, "重庆");
  546. data = MoveElementToFront(data, "四川");
  547. foreach (var province in data)
  548. {
  549. foreach (var city in province.Child)
  550. {
  551. list.Add(new GroupCityBasicSourceView()
  552. {
  553. Id = city.Id,
  554. Name = $"{province.Name_CN}-{city.Name_CN}"
  555. });
  556. }
  557. }
  558. //四川成都放在最前面
  559. var cdInfo = list.FirstOrDefault(x => x.Name.Equals("四川-成都"));
  560. if (cdInfo != null)
  561. {
  562. list.Remove(cdInfo);
  563. list.Insert(0, cdInfo);
  564. }
  565. }
  566. return list.ToArray();
  567. }
  568. /// <summary>
  569. /// 获取接团信息 编辑
  570. /// 基础 数据源
  571. /// </summary>
  572. /// <param name="dto"></param>
  573. /// <returns></returns>
  574. public async Task<GroupCityBasicSourceView> CityInfoById(int id)
  575. {
  576. var list = await CityBasicSource();
  577. var info = list.FirstOrDefault(x => x.Id == id);
  578. return info;
  579. }
  580. private static List<CityTree> MoveElementToFront(List<CityTree> list, string elementName)
  581. {
  582. var element = list.FirstOrDefault(x => x.Name_CN == elementName);
  583. if (element != null)
  584. {
  585. list.Remove(element);
  586. list.Insert(0, element);
  587. }
  588. return list;
  589. }
  590. /// <summary>
  591. /// 获取接团信息 编辑
  592. /// 基础 数据源
  593. /// </summary>
  594. /// <param name="dto"></param>
  595. /// <returns></returns>
  596. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  597. {
  598. var result = new Result() { Code = -2, Msg = "未知错误" };
  599. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  600. {
  601. dynamic? teamTypeData1 = null;
  602. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  603. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  604. if (teamTypeData.Any())
  605. {
  606. teamTypeData1 = teamTypeData;
  607. if (teamTypeData.Any(x => x.Name.Equals("前期沟通")))
  608. {
  609. var info = teamTypeData.Find(x => x.Name.Equals("前期沟通"));
  610. if (info != null)
  611. {
  612. teamTypeData.Remove(info);
  613. teamTypeData.Insert(2, info);
  614. }
  615. }
  616. }
  617. dynamic? teamLevData1 = null;
  618. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  619. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  620. if (teamLevData.Any())
  621. {
  622. teamLevData1 = teamLevData;
  623. }
  624. dynamic? userData1 = null;
  625. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  626. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync();
  627. if (userData.Any())
  628. {
  629. userData1 = userData;
  630. }
  631. //客户单位数据源 来源市场客户资料
  632. dynamic? clientData1 = null;
  633. string clientSql = $@"Select Client,Contact,Telephone,WeChat From Crm_NewClientData Where IsDel = 0";
  634. var clientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(clientSql).ToListAsync();
  635. if (clientData.Any())
  636. {
  637. clientData1 = clientData.Select(it => new
  638. {
  639. Client = AesEncryptionHelper.Decrypt(it.Client),
  640. Contact = AesEncryptionHelper.Decrypt(it.Contact),
  641. Telephone = AesEncryptionHelper.Decrypt(it.Telephone),
  642. Wechat = AesEncryptionHelper.Decrypt(it.Wechat)
  643. }).ToList();
  644. }
  645. var userDepDatas = new List<TextView>();
  646. userDepDatas.Insert(0, new TextView() { Text = "全部", Value = "全部" });
  647. userDepDatas.Insert(1, new TextView() { Text = "国交部", Value = "国交部" });
  648. userDepDatas.Insert(2, new TextView() { Text = "市场部", Value = "市场部" });
  649. userDepDatas.Insert(3, new TextView() { Text = "策划部", Value = "策划部" });
  650. var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new TextView { Value = x.Id.ToString(), Text = x.Name }).ToListAsync();
  651. rankDatas.Insert(0, new TextView { Value = "0", Text = "全部" });
  652. result.Code = 0;
  653. result.Msg = "成功!";
  654. result.Data = new
  655. {
  656. teamTypeData = teamTypeData1,
  657. teamLevData = teamLevData1,
  658. userData = userData1,
  659. clientData = clientData1,
  660. depData = userDepDatas,
  661. rankData = rankDatas,
  662. cityData = await CityBasicSource()
  663. };
  664. }
  665. return result;
  666. }
  667. /// <summary>
  668. /// 团组信息操作
  669. /// </summary>
  670. /// <param name="dto"></param>
  671. /// <returns></returns>
  672. public async Task<Result> GroupOperation(GroupOperationDto dto)
  673. {
  674. var result = new Result() { Code = -2, Msg = "未知错误" };
  675. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  676. {
  677. #region 添加出访起止时间
  678. var startTime = new DateTime();
  679. var endTime = new DateTime();
  680. if (DateTime.TryParse(dto.VisitDate, out startTime))
  681. {
  682. endTime = startTime.AddDays(dto.VisitDays - 1);//含当天
  683. }
  684. #endregion
  685. if (dto.Status == 1) //添加
  686. {
  687. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  688. Where IsDel = 0
  689. And TeamName = '{0}'
  690. And ClientName = '{1}'
  691. And ClientUnit ='{2}'
  692. And VisitDate ='{3}'", dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  693. var selectGroupInfo = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).First();
  694. if (selectGroupInfo != null)
  695. {
  696. result.Msg = "数据已存在,请勿重复添加!";
  697. return result;
  698. }
  699. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  700. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  701. //string SalesQuoteNo = "";
  702. //while (true)
  703. //{
  704. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  705. // if (!teamCodeItem.Equals(SalesQuoteNo))
  706. // {
  707. // break;
  708. // }
  709. //}
  710. string countrys = string.Empty;
  711. string countryReq = dto.VisitCountry;
  712. if (!string.IsNullOrEmpty(countryReq))
  713. {
  714. if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  715. else if (countryReq.Contains(",")) countrys = countryReq.Replace(',', '|');
  716. else if (countryReq.Contains(" ")) countrys = countryReq.Replace(' ', '|');
  717. else if (countryReq.Contains("、")) countrys = countryReq.Replace('、', '|');
  718. else if (countryReq.Contains(".")) countrys = countryReq.Replace('.', '|');
  719. else countrys = countryReq;
  720. }
  721. //建团时 默认出团 设置 团组code
  722. string teamCode = "";
  723. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  724. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  725. while (true)
  726. {
  727. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  728. if (!teamCodeItem.Equals(teamCode))
  729. {
  730. break;
  731. }
  732. }
  733. var delegationInfo = new Grp_DelegationInfo()
  734. {
  735. CityId = dto.CityId,
  736. SalesQuoteNo = dto.SalesQuoteNo,
  737. TeamLevSId = dto.TeamLevSId,
  738. ClientName = dto.ClientName,
  739. ClientUnit = dto.ClientUnit,
  740. TeamName = dto.TeamName,
  741. TeamDid = dto.TeamDid,
  742. VisitDate = Convert.ToDateTime(dto.VisitDate),
  743. VisitCountry = countrys,
  744. VisitPurpose = dto.VisitPurpose,
  745. VisitDays = dto.VisitDays,
  746. VisitPNumber = dto.VisitPNumber,
  747. SpecialNeeds = dto.SpecialNeeds,
  748. OtherNeeds = dto.OtherNeeds,
  749. Remark = dto.Remark,
  750. JietuanOperator = dto.JietuanOperator,
  751. TellPhone = dto.TellPhone,
  752. WeChatNo = dto.WeChatNo,
  753. CGRWSPBMMC = dto.CGRWSPBMMC,
  754. CGRWSPWH = dto.CGRWSPWH,
  755. ZZSCBMMC = dto.ZZSCBMMC,
  756. ZZSCSPWH = dto.ZZSCSPWH,
  757. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  758. IsBid = dto.IsBid,
  759. PaymentMoney = dto.PaymentMoney,
  760. PayDay = dto.PayDay,
  761. TourCode = teamCode,
  762. GroupsOperator = dto.UserId,
  763. GroupsTime = DateTime.Now,
  764. SalesDate = DateTime.Now,
  765. IsState = 0, //默认团组未完成 0
  766. JietuanTime = DateTime.Now,
  767. IsDel = 0,
  768. BudgetCost = 0.00M,
  769. HotelComplain = 0,
  770. OPComplain = 0,
  771. OAComplain = 0,
  772. AirComplain = 0,
  773. VisaComplain = 0,
  774. CreateUserId = dto.UserId,
  775. CreateTime = DateTime.Now,
  776. DeleteUserId = null,
  777. DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss"),
  778. OpRoyaltyLv = dto.OpRoyaltyLv,
  779. OpRoyaltyRemark = dto.opRoyaltyRemark,
  780. Officialneeds = dto.Officialneeds,
  781. VisitStartDate = startTime,
  782. VisitEndDate = endTime,
  783. };
  784. var addId = _sqlSugar.Insertable(delegationInfo).ExecuteReturnIdentity();
  785. if (addId > 0)
  786. {
  787. result.Code = 0;
  788. result.Msg = "添加成功!";
  789. result.Data = addId;
  790. }
  791. else
  792. {
  793. result.Msg = "添加失败!";
  794. }
  795. }
  796. else if (dto.Status == 2) //修改
  797. {
  798. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  799. {
  800. CityId = dto.CityId,
  801. SalesQuoteNo = dto.SalesQuoteNo,
  802. TeamLevSId = dto.TeamLevSId,
  803. ClientName = dto.ClientName,
  804. ClientUnit = dto.ClientUnit,
  805. TeamName = dto.TeamName,
  806. TeamDid = dto.TeamDid,
  807. VisitDate = Convert.ToDateTime(dto.VisitDate),
  808. VisitCountry = dto.VisitCountry,
  809. VisitPurpose = dto.VisitPurpose,
  810. VisitDays = dto.VisitDays,
  811. VisitPNumber = dto.VisitPNumber,
  812. SpecialNeeds = dto.SpecialNeeds,
  813. OtherNeeds = dto.OtherNeeds,
  814. Remark = dto.Remark,
  815. JietuanOperator = dto.JietuanOperator,
  816. TellPhone = dto.TellPhone,
  817. WeChatNo = dto.WeChatNo,
  818. CGRWSPBMMC = dto.CGRWSPBMMC,
  819. CGRWSPWH = dto.CGRWSPWH,
  820. ZZSCBMMC = dto.ZZSCBMMC,
  821. ZZSCSPWH = dto.ZZSCSPWH,
  822. TontractTime = string.IsNullOrEmpty(dto.TontractTime) ? null : Convert.ToDateTime(dto.TontractTime),
  823. IsBid = dto.IsBid,
  824. PaymentMoney = dto.PaymentMoney,
  825. PayDay = dto.PayDay,
  826. OpRoyaltyLv = dto.OpRoyaltyLv,
  827. OpRoyaltyRemark = dto.opRoyaltyRemark,
  828. Officialneeds = dto.Officialneeds,
  829. VisitStartDate = startTime,
  830. VisitEndDate = endTime,
  831. });
  832. if (updateStatus)
  833. {
  834. result.Code = 0;
  835. result.Msg = "修改成功!";
  836. }
  837. else
  838. {
  839. result.Msg = "修改失败!";
  840. }
  841. }
  842. else if (dto.Status == 3) //删除
  843. {
  844. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  845. {
  846. DeleteUserId = dto.UserId,
  847. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  848. IsDel = 1
  849. });
  850. if (deleteStatus)
  851. {
  852. result.Code = 0;
  853. result.Msg = "删除成功!";
  854. }
  855. else
  856. {
  857. result.Msg = "删除失败!";
  858. }
  859. }
  860. }
  861. return result;
  862. }
  863. /// <summary>
  864. /// 团组信息操作 - 删除
  865. /// </summary>
  866. /// <param name="dto"></param>
  867. /// <returns></returns>
  868. public async Task<Result> GroupDel(GroupDelDto dto)
  869. {
  870. var result = new Result() { Code = -2, Msg = "未知错误" };
  871. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  872. {
  873. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  874. {
  875. DeleteUserId = dto.UserId,
  876. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  877. IsDel = 1
  878. });
  879. if (deleteStatus)
  880. {
  881. result.Code = 0;
  882. result.Msg = "删除成功!";
  883. }
  884. else
  885. {
  886. result.Msg = "删除失败!";
  887. }
  888. }
  889. return result;
  890. }
  891. /// <summary>
  892. /// 获取销售报价号
  893. /// </summary>
  894. /// <returns></returns>
  895. public async Task<Result> GetGroupSalesQuoteNo()
  896. {
  897. var result = new Result() { Code = -2, Msg = "未知错误" };
  898. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  899. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  900. string teamCode;
  901. while (true)
  902. {
  903. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  904. if (!teamCodeItem.Equals(teamCode))
  905. {
  906. break;
  907. }
  908. }
  909. result.Code = 0;
  910. result.Msg = "成功!";
  911. result.Data = teamCode;
  912. return result;
  913. }
  914. /// <summary>
  915. /// 团组删除
  916. /// </summary>
  917. /// <returns></returns>
  918. public async Task<Result> GroupDeleteById()
  919. {
  920. var result = new Result() { Code = -2, Msg = "未知错误" };
  921. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  922. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  923. string teamCode;
  924. while (true)
  925. {
  926. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  927. if (!teamCodeItem.Equals(teamCode))
  928. {
  929. break;
  930. }
  931. }
  932. result.Code = 0;
  933. result.Msg = "成功!";
  934. result.Data = teamCode;
  935. return result;
  936. }
  937. /// <summary>
  938. /// 团组确认出团
  939. /// </summary>
  940. /// <returns></returns>
  941. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  942. {
  943. var result = new Result() { Code = -2, Msg = "未知错误" };
  944. string teamCode = "";
  945. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  946. {
  947. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  948. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  949. while (true)
  950. {
  951. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  952. if (!teamCodeItem.Equals(teamCode))
  953. {
  954. break;
  955. }
  956. }
  957. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  958. {
  959. TourCode = teamCode,
  960. GroupsOperator = dto.GroupsOperator,
  961. GroupsTime = DateTime.Now
  962. });
  963. if (deleteStatus)
  964. {
  965. result.Code = 0;
  966. result.Msg = "确认出团设置成功!";
  967. }
  968. else
  969. {
  970. result.Msg = "确认出团设置失败!";
  971. }
  972. }
  973. result.Code = 0;
  974. result.Msg = "成功!";
  975. result.Data = teamCode;
  976. return result;
  977. }
  978. /// <summary>
  979. /// 获取接团名称List
  980. /// </summary>
  981. /// <param name="dto"></param>
  982. /// <returns></returns>
  983. public async Task<JsonView> GetGroupNameList(GroupNameDto dto)
  984. {
  985. var view = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  986. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  987. {
  988. //2025-02-17 更改团组列表排序功能 按照团出访时间排序(降序)
  989. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  990. Where TeamName != '' And IsDel = 0
  991. Order By VisitStartDate Desc");
  992. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  993. if (_groupNameList.Any())
  994. {
  995. for (int i = 0; i < _groupNameList.Count; i++)
  996. {
  997. var info = _groupNameList[i];
  998. _groupNameList[i].GroupName = FormartTeamName(info.GroupName);
  999. }
  1000. //_groupNameList.Insert(0, new GroupNameView() { Id = 0, GroupName = "未选择" });
  1001. view.Code = StatusCodes.Status200OK;
  1002. view.Msg = "成功!";
  1003. view.Data = _groupNameList;
  1004. }
  1005. else
  1006. {
  1007. view.Msg = "暂无团组信息";
  1008. }
  1009. }
  1010. return view;
  1011. }
  1012. //PostGroupNameScreen
  1013. /// <summary>
  1014. /// 获取接团名称 Page List
  1015. /// </summary>
  1016. /// <param name="dto"></param>
  1017. /// <returns></returns>
  1018. public async Task<JsonView> GetGroupNameList(int portType, int pageIndex, int pageSize, string groupName, int userId)
  1019. {
  1020. var _res = new JsonView() { Code = 400, Msg = MsgTips.Fail };
  1021. string sql = "";
  1022. string sqlWhere = "";
  1023. string mobileSqlWhere = "";
  1024. if (!string.IsNullOrEmpty(groupName))
  1025. {
  1026. sqlWhere += string.Format($@"And TeamName Like '%{groupName}%'");
  1027. mobileSqlWhere += string.Format($@"GroupName Like '%{groupName}%'");
  1028. }
  1029. var userIds = new List<int>() { -1, 21 };
  1030. if (!userIds.Contains(userId))
  1031. {
  1032. sqlWhere += string.Format($@"And JietuanOperator = {userId}");
  1033. }
  1034. sql = string.Format($@"Select ROW_NUMBER()Over(Order By Id Desc) as RowNumber,Id,TeamName GroupName From Grp_DelegationInfo
  1035. Where IsDel = 0 {sqlWhere}");
  1036. if (portType == 1) //web
  1037. { }
  1038. else if (portType == 2 || portType == 3)
  1039. {
  1040. //国交部 7 (主管 22,经理 32)团操操作权限 市场部 6 接团人
  1041. var userInfo = await _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == userId && it.IsDel == 0).FirstAsync();
  1042. if (userInfo != null)
  1043. {
  1044. if (userInfo.DepId == 7)
  1045. {
  1046. if (userInfo.JobPostId != 22 || userInfo.JobPostId != 32)
  1047. {
  1048. if (!string.IsNullOrEmpty(mobileSqlWhere)) mobileSqlWhere = $" Where {mobileSqlWhere}";
  1049. sql = string.Format($@"Select
  1050. ROW_NUMBER()Over(Order By Id Desc) as RowNumber,
  1051. Id,
  1052. GroupName
  1053. From (
  1054. Select
  1055. distinct
  1056. di.Id,
  1057. di.TeamName GroupName
  1058. From Grp_GroupsTaskAssignment gta With(NoLock)
  1059. Inner Join Grp_DelegationInfo di With(NoLock) On gta.DIId = di.Id
  1060. Where gta.IsDel = 0 And di.IsDel = 0 And gta.UId = {userId}
  1061. ) Temp {mobileSqlWhere}");
  1062. }
  1063. }
  1064. }
  1065. }
  1066. RefAsync<int> total = 0;
  1067. var groupNamePageData = await _sqlSugar.SqlQueryable<GroupNamePageView>(sql).ToPageListAsync(pageIndex, pageSize, total);
  1068. _res.Code = 200;
  1069. _res.Data = groupNamePageData;
  1070. _res.Msg = MsgTips.Succeed;
  1071. _res.Count = total;
  1072. return _res;
  1073. }
  1074. /// <summary>
  1075. /// 获取接团名称List And 签证国别
  1076. /// </summary>
  1077. /// <param name="dto"></param>
  1078. /// <returns></returns>
  1079. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  1080. {
  1081. var result = new Result() { Code = -2, Msg = "未知错误" };
  1082. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web
  1083. {
  1084. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  1085. Where TeamName != '' And IsDel = 0
  1086. Order By VisitDate Desc");
  1087. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  1088. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  1089. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  1090. var data = new
  1091. {
  1092. groupNameData = _groupNameList,
  1093. visaNationalityData = _setDataList
  1094. };
  1095. result.Data = data;
  1096. result.Code = 0;
  1097. }
  1098. return result;
  1099. }
  1100. #endregion
  1101. #region 团组&签证
  1102. /// <summary>
  1103. /// 根据团组Id查询客户
  1104. /// </summary>
  1105. /// <param name="dto"></param>
  1106. /// <returns></returns>
  1107. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  1108. {
  1109. var result = new Result() { Code = -2 };
  1110. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  1111. {
  1112. var clientInfos = await _sqlSugar.Queryable<Grp_TourClientList>().Where(x => x.IsDel == 0 && x.DiId == dto.GroupId).ToListAsync();
  1113. var clientIds = clientInfos.Select(x => x.ClientId).ToList();
  1114. var visaClientInfos = await _sqlSugar.Queryable<Crm_DeleClient>().Where(x => x.IsDel == 0 && clientIds.Contains(x.Id))
  1115. .Select(x => new Crm_DeleClient
  1116. {
  1117. DiId = dto.GroupId,
  1118. Id = x.Id,
  1119. FirstName = x.FirstName,
  1120. LastName = x.LastName,
  1121. Tel = x.Tel
  1122. })
  1123. .ToListAsync();
  1124. var clientCertInfos = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(x => x.IsDel == 0 && x.SdId == 773 && clientIds.Contains(x.DcId))
  1125. .Select(x => new Crm_CustomerCert
  1126. {
  1127. DcId = x.DcId,
  1128. CertNo = x.CertNo
  1129. })
  1130. .ToListAsync();
  1131. //解密
  1132. foreach (var item in visaClientInfos)
  1133. {
  1134. EncryptionProcessor.DecryptProperties(item);
  1135. }
  1136. //信息整合
  1137. var view = new List<CrmByGroupIdView>();
  1138. foreach (var item in visaClientInfos)
  1139. {
  1140. var idNo = AesEncryptionHelper.Decrypt(clientCertInfos.FirstOrDefault(x => x.DcId == item.Id)?.CertNo ?? "") ?? "-";
  1141. if (string.IsNullOrEmpty(idNo)) idNo = "-";
  1142. view.Add(new() {
  1143. GrpId = dto.GroupId,
  1144. ClientName = item.LastName + item.FirstName,
  1145. Tel = item.Tel ?? "-",
  1146. CerdNo = idNo
  1147. });
  1148. }
  1149. if (view.Count > 0)
  1150. {
  1151. result.Msg = "成功!";
  1152. result.Data = view;
  1153. }
  1154. else
  1155. {
  1156. result.Msg = "暂无数据!";
  1157. }
  1158. result.Code = 0;
  1159. }
  1160. return result;
  1161. }
  1162. #endregion
  1163. #region 团组&出入境费用
  1164. /// <summary>
  1165. /// 获取单组名称并验证出入境费用明细是否填写
  1166. /// </summary>
  1167. /// <param name="dto"></param>
  1168. /// <returns></returns>
  1169. public async Task<EnterExitCostGroupNameView[]> EnterExitCostGroupNameAsync()
  1170. {
  1171. var groupSql = string.Format(@$"SELECT
  1172. Id,
  1173. TeamName GroupName,
  1174. CityId ProvinceId,
  1175. CASE
  1176. WHEN (
  1177. SELECT
  1178. COUNT(*)
  1179. FROM
  1180. Grp_EnterExitCost
  1181. WHERE
  1182. IsDel = 0
  1183. AND DiId = di.Id
  1184. ) > 0 THEN 'false'
  1185. ELSE 'true'
  1186. END AS [IsNull]
  1187. FROM
  1188. Grp_DelegationInfo di
  1189. WHERE
  1190. di.Isdel = 0
  1191. ORDER BY
  1192. VisitStartDate Desc");
  1193. var groupDatas = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToArrayAsync();
  1194. var provCityDatas = await ProvinceCityBasicSource();
  1195. if (provCityDatas.Any() && groupDatas.Any())
  1196. {
  1197. foreach (var item in groupDatas)
  1198. {
  1199. var provinceId = item.ProvinceId;
  1200. var isDefualtVal = true;
  1201. if (provinceId > 0)
  1202. {
  1203. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1204. if (parentId != null)
  1205. {
  1206. isDefualtVal = false;
  1207. item.ProvinceId = (int)parentId;
  1208. }
  1209. }
  1210. if (isDefualtVal)
  1211. {
  1212. item.ProvinceId = 122; //默认四川
  1213. }
  1214. }
  1215. }
  1216. return groupDatas;
  1217. }
  1218. /// <summary>
  1219. /// 获取单组名称并验证出入境费用明细是否填写
  1220. /// </summary>
  1221. /// <param name="dto"></param>
  1222. /// <returns></returns>
  1223. public async Task<EnterExitCostGroupNameView> EnterExitCostGroupNameInfoAsync(int groupId)
  1224. {
  1225. var groupSql = string.Format(@$"SELECT
  1226. Id,
  1227. TeamName GroupName,
  1228. CityId ProvinceId,
  1229. CASE
  1230. WHEN (
  1231. SELECT
  1232. COUNT(*)
  1233. FROM
  1234. Grp_EnterExitCost
  1235. WHERE
  1236. IsDel = 0
  1237. AND DiId = di.Id
  1238. ) > 0 THEN 'false'
  1239. ELSE 'true'
  1240. END AS [IsNull]
  1241. FROM
  1242. Grp_DelegationInfo di
  1243. WHERE
  1244. di.Isdel = 0
  1245. And Id = {groupId} ");
  1246. var groupData = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).FirstAsync();
  1247. var provCityDatas = await ProvinceCityBasicSource();
  1248. if (provCityDatas.Any() && groupData != null)
  1249. {
  1250. var provinceId = groupData.ProvinceId;
  1251. var isDefualtVal = true;
  1252. if (provinceId > 0)
  1253. {
  1254. var parentId = FindParentIdByChildId(provCityDatas, provinceId);
  1255. if (parentId != null)
  1256. {
  1257. isDefualtVal = false;
  1258. groupData.ProvinceId = (int)parentId;
  1259. }
  1260. }
  1261. if (isDefualtVal)
  1262. {
  1263. groupData.ProvinceId = 0; //
  1264. }
  1265. }
  1266. return groupData;
  1267. }
  1268. /// <summary>
  1269. /// 递归地遍历树状结构,查找子项的父类 Id。
  1270. /// </summary>
  1271. /// <param name="tree"></param>
  1272. /// <param name="childId"></param>
  1273. /// <returns></returns>
  1274. public int? FindParentIdByChildId(List<CityTree> tree, int childId)
  1275. {
  1276. foreach (var node in tree)
  1277. {
  1278. if (node.Child != null && node.Child.Any())
  1279. {
  1280. if (node.Child.Any(c => c.Id == childId))
  1281. {
  1282. return node.Id;
  1283. }
  1284. var parentId = FindParentIdByChildId(node.Child, childId);
  1285. if (parentId.HasValue)
  1286. {
  1287. return parentId;
  1288. }
  1289. }
  1290. }
  1291. return null;
  1292. }
  1293. #endregion
  1294. }
  1295. }