DelegationInfoRepository.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using OASystem.Domain;
  2. using OASystem.Domain.Dtos;
  3. using OASystem.Domain.Dtos.Group;
  4. using OASystem.Domain.Dtos.UserDto;
  5. using OASystem.Domain.Entities.Groups;
  6. using OASystem.Domain.ViewModels.Group;
  7. using OASystem.Infrastructure.Repositories.System;
  8. using Org.BouncyCastle.Utilities.Collections;
  9. using SqlSugar;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. namespace OASystem.Infrastructure.Repositories.Group
  16. {
  17. /// <summary>
  18. /// 接团信息
  19. /// </summary>
  20. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  21. {
  22. private readonly SetDataRepository _setDataRepository;
  23. private readonly UsersRepository _usersRepository;
  24. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository)
  25. : base(sqlSugar)
  26. {
  27. this._setDataRepository = setDataRepository;
  28. this._usersRepository = usersRepository;
  29. }
  30. /// <summary>
  31. /// 获取接团信息List
  32. /// </summary>
  33. /// <param name="dto"></param>
  34. /// <returns></returns>
  35. public async Task<Result> GetGroupList(GroupListDto dto)
  36. {
  37. Result result = new Result() { Code = -2,Msg="未知错误" };
  38. if (dto.PortType == 1) //web
  39. {
  40. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Name TeamType,ssd1.Name TeamLev,TeamName,ClientName,
  41. ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  42. From Grp_DelegationInfo gdi
  43. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  44. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  45. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  46. Where gdi.IsDel = 0
  47. Order By VisitDate Desc");
  48. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  49. if (_DelegationList.Count > 0)
  50. {
  51. result.Code = 0;
  52. result.Msg = "成功!";
  53. result.Data = _DelegationList;
  54. }
  55. else
  56. {
  57. result.Msg = "暂无该团组信息";
  58. }
  59. }
  60. return result;
  61. }
  62. /// <summary>
  63. /// 获取接团信息Info
  64. /// </summary>
  65. /// <param name="dto"></param>
  66. /// <returns></returns>
  67. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  68. {
  69. Result result = new Result() { Code = -2, Msg = "未知错误" };
  70. if (dto.PortType == 1) //web
  71. {
  72. string sql = string.Format(@"Select Id,SalesQuoteNo,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  73. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  74. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  75. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone
  76. From Grp_DelegationInfo Where Id = {0} And IsDel=0",dto.Id);
  77. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).ToListAsync();
  78. if (_DelegationInfo != null)
  79. {
  80. result.Code = 0;
  81. result.Msg = "成功!";
  82. result.Data = _DelegationInfo;
  83. }
  84. else
  85. {
  86. result.Msg = "暂无该团组信息";
  87. }
  88. }
  89. return result;
  90. }
  91. /// <summary>
  92. /// 获取接团信息 编辑
  93. /// 基础 数据源
  94. /// </summary>
  95. /// <param name="dto"></param>
  96. /// <returns></returns>
  97. public async Task<Result> GetGroupEditBasicSource(GroupListDto dto)
  98. {
  99. Result result = new Result() { Code = -2, Msg = "未知错误" };
  100. if (dto.PortType == 1) //web
  101. {
  102. dynamic? teamTypeData1 = null;
  103. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  104. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  105. if (teamTypeData.Count > 0)
  106. {
  107. teamTypeData1 = teamTypeData;
  108. }
  109. dynamic? teamLevData1 = null;
  110. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  111. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  112. if (teamLevData.Count > 0)
  113. {
  114. teamLevData1 = teamLevData;
  115. }
  116. dynamic? userData1 = null;
  117. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  118. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync(); ;
  119. if (userData.Count > 0)
  120. {
  121. userData1 = userData;
  122. }
  123. result.Code = 0;
  124. result.Msg = "成功!";
  125. result.Data = new {
  126. teamTypeData = teamTypeData1,
  127. teamLevData = teamLevData1,
  128. userData = userData1
  129. };
  130. }
  131. return result;
  132. }
  133. /// <summary>
  134. /// 团组信息操作
  135. /// </summary>
  136. /// <param name="dto"></param>
  137. /// <returns></returns>
  138. public async Task<Result> GroupOperation(GroupOperationDto dto)
  139. {
  140. Result result = new Result() { Code = -2, Msg = "未知错误" };
  141. if (dto.PortType == 1) //web
  142. {
  143. Grp_DelegationInfo groupInfo = new Grp_DelegationInfo()
  144. {
  145. SalesQuoteNo = dto.SalesQuoteNo,
  146. TeamLevSId = dto.TeamLevSId,
  147. ClientName = dto.ClientName,
  148. ClientUnit = dto.ClientUnit,
  149. TeamName = dto.TeamName,
  150. TeamDid = dto.TeamDid,
  151. VisitDate = dto.VisitDate,
  152. VisitCountry = dto.VisitCountry,
  153. VisitPurpose = dto.VisitPurpose,
  154. VisitDays = dto.VisitDays,
  155. VisitPNumber = dto.VisitPNumber,
  156. SpecialNeeds = dto.SpecialNeeds,
  157. OtherNeeds = dto.OtherNeeds,
  158. Remark = dto.Remark,
  159. JietuanOperator = dto.UserId,
  160. TellPhone = dto.TellPhone,
  161. CGRWSPBMMC = dto.CGRWSPBMMC,
  162. CGRWSPWH = dto.CGRWSPWH,
  163. ZZSCBMMC = dto.ZZSCBMMC,
  164. ZZSCSPWH = dto.ZZSCSPWH,
  165. TontractTime = dto.TontractTime,
  166. PaymentMoney = dto.PaymentMoney,
  167. PayDay = dto.PayDay
  168. };
  169. if (dto.Status == 1) //添加
  170. {
  171. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  172. Where IsDel = 0
  173. And SalesQuoteNo = '{0}'
  174. And TeamName = '{1}'
  175. And ClientName = '{2}'
  176. And ClientUnit ='{3}'
  177. And VisitDate ='{4}'",dto.SalesQuoteNo,dto.TeamName,dto.ClientName,dto.ClientUnit,dto.VisitDate);
  178. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  179. if (selectGroupInfo != null)
  180. {
  181. result.Msg = "数据已存在,请勿重复添加!";
  182. return result;
  183. }
  184. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  185. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).FirstAsync();
  186. string teamCode = "";
  187. while (true)
  188. {
  189. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  190. if (!teamCodeItem.Equals(teamCode))
  191. {
  192. break;
  193. }
  194. }
  195. groupInfo.TourCode = teamCode;
  196. groupInfo.SalesDate = DateTime.Now;
  197. groupInfo.IsState = 0; //默认团组未完成 0
  198. groupInfo.JietuanTime = DateTime.Now;
  199. groupInfo.IsDel = 0;
  200. groupInfo.BudgetCost = 0.00M;
  201. groupInfo.HotelComplain = 0;
  202. groupInfo.OPComplain = 0;
  203. groupInfo.OAComplain = 0;
  204. groupInfo.AirComplain = 0;
  205. groupInfo.VisaComplain = 0;
  206. groupInfo.CreateUserId = dto.UserId;
  207. groupInfo.CreateTime = DateTime.Now;
  208. groupInfo.DeleteUserId = null;
  209. groupInfo.DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss");
  210. var addId = await _sqlSugar.Insertable(groupInfo).ExecuteReturnIdentityAsync();
  211. if (addId > 0)
  212. {
  213. result.Code = 0;
  214. result.Msg = "添加成功!";
  215. }
  216. else
  217. {
  218. result.Msg = "添加失败!";
  219. }
  220. }
  221. else if (dto.Status == 2) //修改
  222. {
  223. var updateStatus = await UpdateAsync(a => a.Id == dto.Id,a=> groupInfo);
  224. if (updateStatus)
  225. {
  226. result.Code = 0;
  227. result.Msg = "修改成功!";
  228. }
  229. else
  230. {
  231. result.Msg = "修改失败!";
  232. }
  233. }
  234. }
  235. return result;
  236. }
  237. }
  238. }