DelegationInfoRepository.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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 SalesQuoteNo = '{0}'
  187. And TeamName = '{1}'
  188. And ClientName = '{2}'
  189. And ClientUnit ='{3}'
  190. And VisitDate ='{4}'", dto.SalesQuoteNo, dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  191. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  192. if (selectGroupInfo != null)
  193. {
  194. result.Msg = "数据已存在,请勿重复添加!";
  195. return result;
  196. }
  197. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  198. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  199. string teamCode = "";
  200. while (true)
  201. {
  202. teamCode = Tools.CommonFun.GetRandomStr(6);
  203. if (!teamCodeItem.Equals(teamCode))
  204. {
  205. break;
  206. }
  207. }
  208. groupInfo.TourCode = teamCode;
  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 TourCode From Grp_DelegationInfo");
  329. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(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. /// 获取接团名称List
  369. /// </summary>
  370. /// <param name="dto"></param>
  371. /// <returns></returns>
  372. public async Task<Result> GetGroupNameList(GroupNameDto dto)
  373. {
  374. Result result = new Result() { Code = -2, Msg = "未知错误" };
  375. if (dto.PortType == 1 || dto.PortType == 2) //web
  376. {
  377. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  378. Where TeamName != '' And IsDel = 0
  379. Order By Id Desc");
  380. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  381. if (_groupNameList.Count > 0)
  382. {
  383. result.Code = 0;
  384. result.Msg = "成功!";
  385. result.Data = _groupNameList;
  386. }
  387. else
  388. {
  389. result.Msg = "暂无团组信息";
  390. }
  391. }
  392. return result;
  393. }
  394. /// <summary>
  395. /// 获取接团名称List And 签证国别
  396. /// </summary>
  397. /// <param name="dto"></param>
  398. /// <returns></returns>
  399. public async Task<Result> GetGroupNameAndVisaNationality(GroupNameDto dto)
  400. {
  401. Result result = new Result() { Code = -2, Msg = "未知错误" };
  402. if (dto.PortType == 1 || dto.PortType == 2) //web
  403. {
  404. string sql = string.Format(@"Select Id,TeamName GroupName From Grp_DelegationInfo
  405. Where TeamName != '' And IsDel = 0
  406. Order By Id Desc");
  407. var _groupNameList = await _sqlSugar.SqlQueryable<GroupNameView>(sql).ToListAsync();
  408. string visaSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = 41 And IsDel = 0");
  409. var _setDataList = await _sqlSugar.SqlQueryable<SetDataInfoView>(visaSql).ToListAsync();
  410. var data = new {
  411. groupNameData = _groupNameList,
  412. visaNationalityData = _setDataList
  413. };
  414. result.Data = data;
  415. result.Code = 0;
  416. }
  417. return result;
  418. }
  419. #endregion
  420. #region 团组&签证
  421. /// <summary>
  422. /// 根据团组Id查询客户
  423. /// </summary>
  424. /// <param name="dto"></param>
  425. /// <returns></returns>
  426. public async Task<Result> GetCrmByGroupId(ClientByGroupIdDto dto)
  427. {
  428. Result result = new Result() { Code = -2 };
  429. if (dto.PortType == 1 || dto.PortType == 2)
  430. {
  431. string sql = string.Format(@"Select gdjc.GrpDCId grpId,cdc.Id,cdc.LastName+cdc.FirstName clientName,cdc.Tel,ccc.CertNo CerdNo
  432. From Grp_DelegationJoinCustomer gdjc
  433. Inner join Crm_DeleClient cdc On gdjc.CrmDCId = cdc.Id
  434. Left Join Crm_CustomerCert ccc On ccc.SdId = 773 And cdc.Id = ccc.DcId
  435. Where gdjc.GrpDCId = {0}", dto.GroupId);
  436. var clientList = await _sqlSugar.SqlQueryable<CrmByGroupIdView>(sql).ToListAsync();
  437. if (clientList.Count > 0)
  438. {
  439. result.Code = 0;
  440. result.Msg = "成功!";
  441. result.Data = clientList;
  442. }
  443. else
  444. {
  445. result.Msg = "暂无数据!";
  446. }
  447. }
  448. return result;
  449. }
  450. #endregion
  451. }
  452. }