DelegationInfoRepository.cs 21 KB

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