DelegationInfoRepository.cs 61 KB

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