DelegationInfoRepository.cs 47 KB

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