DelegationInfoRepository.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. using OASystem.Domain;
  2. using OASystem.Domain.Dtos;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Dtos.UserDto;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.CRM;
  7. using OASystem.Domain.ViewModels.Groups;
  8. using OASystem.Infrastructure.Repositories.System;
  9. using Org.BouncyCastle.Asn1.Cms;
  10. using Org.BouncyCastle.Utilities.Collections;
  11. using Serilog;
  12. using SqlSugar;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading.Tasks;
  18. namespace OASystem.Infrastructure.Repositories.Groups
  19. {
  20. /// <summary>
  21. /// 接团信息
  22. /// </summary>
  23. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  24. {
  25. private readonly SetDataRepository _setDataRepository;
  26. private readonly UsersRepository _usersRepository;
  27. //public readonly Logs _logs;
  28. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository)
  29. : base(sqlSugar)
  30. {
  31. this._setDataRepository = setDataRepository;
  32. this._usersRepository = usersRepository;
  33. }
  34. #region 团组
  35. /// <summary>
  36. /// 获取接团信息List
  37. /// </summary>
  38. /// <param name="dto"></param>
  39. /// <returns></returns>
  40. public async Task<Result> GetGroupList(GroupListDto dto)
  41. {
  42. Result result = new Result() { Code = -2, Msg = "未知错误" };
  43. if (dto.PortType == 1 || dto.PortType == 2) //web
  44. {
  45. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Name TeamType,ssd1.Name TeamLev,TeamName,ClientName,
  46. ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  47. From Grp_DelegationInfo gdi
  48. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  49. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  50. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  51. Where gdi.IsDel = 0
  52. Order By VisitDate Desc");
  53. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  54. if (_DelegationList.Count > 0)
  55. {
  56. result.Code = 0;
  57. result.Msg = "成功!";
  58. result.Data = _DelegationList;
  59. }
  60. else
  61. {
  62. result.Msg = "暂无该团组信息";
  63. }
  64. }
  65. return result;
  66. }
  67. /// <summary>
  68. /// 获取接团信息Info
  69. /// </summary>
  70. /// <param name="dto"></param>
  71. /// <returns></returns>
  72. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  73. {
  74. Result result = new Result() { Code = -2, Msg = "未知错误" };
  75. if (dto.PortType == 1 || dto.PortType == 2) //web
  76. {
  77. string sql = string.Format(@"Select Id,SalesQuoteNo,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  78. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  79. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  80. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone
  81. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  82. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  83. if (_DelegationInfo != null)
  84. {
  85. result.Code = 0;
  86. result.Msg = "成功!";
  87. result.Data = _DelegationInfo;
  88. }
  89. else
  90. {
  91. result.Msg = "暂无该团组信息";
  92. }
  93. }
  94. return result;
  95. }
  96. /// <summary>
  97. /// 获取接团信息 编辑
  98. /// 基础 数据源
  99. /// </summary>
  100. /// <param name="dto"></param>
  101. /// <returns></returns>
  102. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  103. {
  104. Result result = new Result() { Code = -2, Msg = "未知错误" };
  105. try
  106. {
  107. if (dto.PortType == 1 || dto.PortType == 2) //web
  108. {
  109. dynamic? teamTypeData1 = null;
  110. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  111. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  112. if (teamTypeData.Count > 0)
  113. {
  114. teamTypeData1 = teamTypeData;
  115. }
  116. dynamic? teamLevData1 = null;
  117. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  118. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  119. if (teamLevData.Count > 0)
  120. {
  121. teamLevData1 = teamLevData;
  122. }
  123. dynamic? userData1 = null;
  124. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  125. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync(); ;
  126. if (userData.Count > 0)
  127. {
  128. userData1 = userData;
  129. }
  130. result.Code = 0;
  131. result.Msg = "成功!";
  132. result.Data = new
  133. {
  134. teamTypeData = teamTypeData1,
  135. teamLevData = teamLevData1,
  136. userData = userData1
  137. };
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. return result;
  145. }
  146. /// <summary>
  147. /// 团组信息操作
  148. /// </summary>
  149. /// <param name="dto"></param>
  150. /// <returns></returns>
  151. public async Task<Result> GroupOperation(GroupOperationDto dto)
  152. {
  153. Result result = new Result() { Code = -2, Msg = "未知错误" };
  154. if (dto.PortType == 1 || dto.PortType == 2) //web
  155. {
  156. Grp_DelegationInfo groupInfo = new Grp_DelegationInfo()
  157. {
  158. SalesQuoteNo = dto.SalesQuoteNo,
  159. TeamLevSId = dto.TeamLevSId,
  160. ClientName = dto.ClientName,
  161. ClientUnit = dto.ClientUnit,
  162. TeamName = dto.TeamName,
  163. TeamDid = dto.TeamDid,
  164. VisitDate = Convert.ToDateTime(dto.VisitDate),
  165. VisitCountry = dto.VisitCountry,
  166. VisitPurpose = dto.VisitPurpose,
  167. VisitDays = dto.VisitDays,
  168. VisitPNumber = dto.VisitPNumber,
  169. SpecialNeeds = dto.SpecialNeeds,
  170. OtherNeeds = dto.OtherNeeds,
  171. Remark = dto.Remark,
  172. JietuanOperator = dto.UserId,
  173. TellPhone = dto.TellPhone,
  174. CGRWSPBMMC = dto.CGRWSPBMMC,
  175. CGRWSPWH = dto.CGRWSPWH,
  176. ZZSCBMMC = dto.ZZSCBMMC,
  177. ZZSCSPWH = dto.ZZSCSPWH,
  178. TontractTime = Convert.ToDateTime(dto.TontractTime),
  179. PaymentMoney = dto.PaymentMoney,
  180. PayDay = dto.PayDay
  181. };
  182. if (dto.Status == 1) //添加
  183. {
  184. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  185. Where IsDel = 0
  186. And TeamName = '{0}'
  187. And ClientName = '{1}'
  188. And ClientUnit ='{2}'
  189. And VisitDate ='{3}'",dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  190. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  191. if (selectGroupInfo != null)
  192. {
  193. result.Msg = "数据已存在,请勿重复添加!";
  194. return result;
  195. }
  196. //string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  197. //var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  198. //string SalesQuoteNo = "";
  199. //while (true)
  200. //{
  201. // SalesQuoteNo = Tools.CommonFun.GetRandomStr(6);
  202. // if (!teamCodeItem.Equals(SalesQuoteNo))
  203. // {
  204. // break;
  205. // }
  206. //}
  207. groupInfo.SalesQuoteNo = dto.SalesQuoteNo;
  208. groupInfo.TourCode = "";
  209. groupInfo.SalesDate = DateTime.Now;
  210. groupInfo.IsState = 0; //默认团组未完成 0
  211. groupInfo.JietuanTime = DateTime.Now;
  212. groupInfo.IsDel = 0;
  213. groupInfo.BudgetCost = 0.00M;
  214. groupInfo.HotelComplain = 0;
  215. groupInfo.OPComplain = 0;
  216. groupInfo.OAComplain = 0;
  217. groupInfo.AirComplain = 0;
  218. groupInfo.VisaComplain = 0;
  219. groupInfo.CreateUserId = dto.UserId;
  220. groupInfo.CreateTime = DateTime.Now;
  221. groupInfo.DeleteUserId = null;
  222. groupInfo.DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss");
  223. var addId = await _sqlSugar.Insertable(groupInfo).ExecuteReturnIdentityAsync();
  224. if (addId > 0)
  225. {
  226. result.Code = 0;
  227. result.Msg = "添加成功!";
  228. }
  229. else
  230. {
  231. result.Msg = "添加失败!";
  232. }
  233. }
  234. else if (dto.Status == 2) //修改
  235. {
  236. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  237. {
  238. SalesQuoteNo = dto.SalesQuoteNo,
  239. TeamLevSId = dto.TeamLevSId,
  240. ClientName = dto.ClientName,
  241. ClientUnit = dto.ClientUnit,
  242. TeamName = dto.TeamName,
  243. TeamDid = dto.TeamDid,
  244. VisitDate = Convert.ToDateTime(dto.VisitDate),
  245. VisitCountry = dto.VisitCountry,
  246. VisitPurpose = dto.VisitPurpose,
  247. VisitDays = dto.VisitDays,
  248. VisitPNumber = dto.VisitPNumber,
  249. SpecialNeeds = dto.SpecialNeeds,
  250. OtherNeeds = dto.OtherNeeds,
  251. Remark = dto.Remark,
  252. JietuanOperator = dto.UserId,
  253. TellPhone = dto.TellPhone,
  254. CGRWSPBMMC = dto.CGRWSPBMMC,
  255. CGRWSPWH = dto.CGRWSPWH,
  256. ZZSCBMMC = dto.ZZSCBMMC,
  257. ZZSCSPWH = dto.ZZSCSPWH,
  258. TontractTime = Convert.ToDateTime(dto.TontractTime),
  259. PaymentMoney = dto.PaymentMoney,
  260. PayDay = dto.PayDay
  261. });
  262. if (updateStatus)
  263. {
  264. result.Code = 0;
  265. result.Msg = "修改成功!";
  266. }
  267. else
  268. {
  269. result.Msg = "修改失败!";
  270. }
  271. }
  272. else if (dto.Status == 3) //删除
  273. {
  274. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  275. {
  276. DeleteUserId = dto.UserId,
  277. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  278. IsDel = 1
  279. });
  280. if (deleteStatus)
  281. {
  282. result.Code = 0;
  283. result.Msg = "删除成功!";
  284. }
  285. else
  286. {
  287. result.Msg = "删除失败!";
  288. }
  289. }
  290. }
  291. return result;
  292. }
  293. /// <summary>
  294. /// 团组信息操作 - 删除
  295. /// </summary>
  296. /// <param name="dto"></param>
  297. /// <returns></returns>
  298. public async Task<Result> GroupDel(GroupDelDto dto)
  299. {
  300. Result result = new Result() { Code = -2, Msg = "未知错误" };
  301. if (dto.PortType == 1 || dto.PortType == 2) //web
  302. {
  303. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  304. {
  305. DeleteUserId = dto.UserId,
  306. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  307. IsDel = 1
  308. });
  309. if (deleteStatus)
  310. {
  311. result.Code = 0;
  312. result.Msg = "删除成功!";
  313. }
  314. else
  315. {
  316. result.Msg = "删除失败!";
  317. }
  318. }
  319. return result;
  320. }
  321. /// <summary>
  322. /// 获取销售报价号
  323. /// </summary>
  324. /// <returns></returns>
  325. public async Task<Result> GetGroupSalesQuoteNo()
  326. {
  327. Result result = new Result() { Code = -2, Msg = "未知错误" };
  328. string teamCodeSql = string.Format("Select SalesQuoteNo From Grp_DelegationInfo");
  329. var teamCodeItem = await _sqlSugar.SqlQueryable<SalesQuoteNoView>(teamCodeSql).ToListAsync();
  330. string teamCode = "";
  331. while (true)
  332. {
  333. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  334. if (!teamCodeItem.Equals(teamCode))
  335. {
  336. break;
  337. }
  338. }
  339. result.Code = 0;
  340. result.Msg = "成功!";
  341. result.Data = teamCode;
  342. return result;
  343. }
  344. /// <summary>
  345. /// 团组删除
  346. /// </summary>
  347. /// <returns></returns>
  348. public async Task<Result> GroupDeleteById()
  349. {
  350. Result result = new Result() { Code = -2, Msg = "未知错误" };
  351. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  352. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  353. string teamCode = "";
  354. while (true)
  355. {
  356. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  357. if (!teamCodeItem.Equals(teamCode))
  358. {
  359. break;
  360. }
  361. }
  362. result.Code = 0;
  363. result.Msg = "成功!";
  364. result.Data = teamCode;
  365. return result;
  366. }
  367. /// <summary>
  368. /// 团组确认出团
  369. /// </summary>
  370. /// <returns></returns>
  371. public async Task<Result> ConfirmationGroup(ConfirmationGroupDto dto)
  372. {
  373. Result result = new Result() { Code = -2, Msg = "未知错误" };
  374. string teamCode = "";
  375. if (dto.PortType == 1 || dto.PortType == 2) //web
  376. {
  377. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  378. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  379. while (true)
  380. {
  381. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  382. if (!teamCodeItem.Equals(teamCode))
  383. {
  384. break;
  385. }
  386. }
  387. var deleteStatus = await UpdateAsync(a => a.Id == dto.GroupId, a => new Grp_DelegationInfo
  388. {
  389. TourCode = teamCode,
  390. GroupsOperator = dto.GroupsOperator,
  391. GroupsTime = DateTime.Now
  392. });
  393. if (deleteStatus)
  394. {
  395. result.Code = 0;
  396. result.Msg = "确认出团成功!";
  397. }
  398. else
  399. {
  400. result.Msg = "确认出团失败!";
  401. }
  402. }
  403. result.Code = 0;
  404. result.Msg = "成功!";
  405. result.Data = teamCode;
  406. return result;
  407. }
  408. /// <summary>
  409. /// 获取接团名称List
  410. /// </summary>
  411. /// <param name="dto"></param>
  412. /// <returns></returns>
  413. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  414. {
  415. Result result = new Result() { Code = -2, Msg = "未知错误" };
  416. if (dto.PortType == 1 || dto.PortType == 2) //web
  417. {
  418. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  419. Where TeamName != '' And IsDel = 0
  420. Order By Id Desc");
  421. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  422. if (_groupNameList.Count > 0)
  423. {
  424. result.Code = 0;
  425. result.Msg = "成功!";
  426. result.Data = _groupNameList;
  427. }
  428. else
  429. {
  430. result.Msg = "暂无团组信息";
  431. }
  432. }
  433. return result;
  434. }
  435. /// <summary>
  436. /// 获取接团名称List And 签证国别
  437. /// </summary>
  438. /// <param name="dto"></param>
  439. /// <returns></returns>
  440. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  441. {
  442. Result result = new Result() { Code = -2, Msg = "未知错误" };
  443. if (dto.PortType == 1 || dto.PortType == 2) //web
  444. {
  445. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  446. Where TeamName != '' And IsDel = 0
  447. Order By Id Desc");
  448. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  449. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  450. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  451. var data = new {
  452. groupNameData = _groupNameList,
  453. visaNationalityData = _setDataList
  454. };
  455. result.Data = data;
  456. result.Code = 0;
  457. }
  458. return result;
  459. }
  460. #endregion
  461. #region 团组&签证
  462. /// <summary>
  463. /// 根据团组Id查询客户
  464. /// </summary>
  465. /// <param name="dto"></param>
  466. /// <returns></returns>
  467. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  468. {
  469. Result result = new Result() { Code = -2 };
  470. if (dto.PortType == 1 || dto.PortType == 2)
  471. {
  472. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  473. From Grp_DelegationJoinCustomer gdjc
  474. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  475. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  476. Where gdjc.GrpDCId = {0}", dto.GroupId);
  477. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  478. if (clientList.Count > 0)
  479. {
  480. result.Code = 0;
  481. result.Msg = "成功!";
  482. result.Data = clientList;
  483. }
  484. else
  485. {
  486. result.Msg = "暂无数据!";
  487. }
  488. }
  489. return result;
  490. }
  491. #endregion
  492. }
  493. }