DelegationInfoRepository.cs 55 KB

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