DelegationInfoRepository.cs 52 KB

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