DelegationInfoRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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.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.Groups
  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).FirstAsync();
  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> GroupEditBasicSource(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. {
  127. teamTypeData = teamTypeData1,
  128. teamLevData = teamLevData1,
  129. userData = userData1
  130. };
  131. }
  132. return result;
  133. }
  134. /// <summary>
  135. /// 团组信息操作
  136. /// </summary>
  137. /// <param name="dto"></param>
  138. /// <returns></returns>
  139. public async Task<Result> GroupOperation(GroupOperationDto dto)
  140. {
  141. Result result = new Result() { Code = -2, Msg = "未知错误" };
  142. if (dto.PortType == 1) //web
  143. {
  144. Grp_DelegationInfo groupInfo = new Grp_DelegationInfo()
  145. {
  146. SalesQuoteNo = dto.SalesQuoteNo,
  147. TeamLevSId = dto.TeamLevSId,
  148. ClientName = dto.ClientName,
  149. ClientUnit = dto.ClientUnit,
  150. TeamName = dto.TeamName,
  151. TeamDid = dto.TeamDid,
  152. VisitDate = dto.VisitDate,
  153. VisitCountry = dto.VisitCountry,
  154. VisitPurpose = dto.VisitPurpose,
  155. VisitDays = dto.VisitDays,
  156. VisitPNumber = dto.VisitPNumber,
  157. SpecialNeeds = dto.SpecialNeeds,
  158. OtherNeeds = dto.OtherNeeds,
  159. Remark = dto.Remark,
  160. JietuanOperator = dto.UserId,
  161. TellPhone = dto.TellPhone,
  162. CGRWSPBMMC = dto.CGRWSPBMMC,
  163. CGRWSPWH = dto.CGRWSPWH,
  164. ZZSCBMMC = dto.ZZSCBMMC,
  165. ZZSCSPWH = dto.ZZSCSPWH,
  166. TontractTime = dto.TontractTime,
  167. PaymentMoney = dto.PaymentMoney,
  168. PayDay = dto.PayDay
  169. };
  170. if (dto.Status == 1) //添加
  171. {
  172. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  173. Where IsDel = 0
  174. And SalesQuoteNo = '{0}'
  175. And TeamName = '{1}'
  176. And ClientName = '{2}'
  177. And ClientUnit ='{3}'
  178. And VisitDate ='{4}'", dto.SalesQuoteNo, dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  179. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  180. if (selectGroupInfo != null)
  181. {
  182. result.Msg = "数据已存在,请勿重复添加!";
  183. return result;
  184. }
  185. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  186. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  187. string teamCode = "";
  188. while (true)
  189. {
  190. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  191. if (!teamCodeItem.Equals(teamCode))
  192. {
  193. break;
  194. }
  195. }
  196. groupInfo.TourCode = teamCode;
  197. groupInfo.SalesDate = DateTime.Now;
  198. groupInfo.IsState = 0; //默认团组未完成 0
  199. groupInfo.JietuanTime = DateTime.Now;
  200. groupInfo.IsDel = 0;
  201. groupInfo.BudgetCost = 0.00M;
  202. groupInfo.HotelComplain = 0;
  203. groupInfo.OPComplain = 0;
  204. groupInfo.OAComplain = 0;
  205. groupInfo.AirComplain = 0;
  206. groupInfo.VisaComplain = 0;
  207. groupInfo.CreateUserId = dto.UserId;
  208. groupInfo.CreateTime = DateTime.Now;
  209. groupInfo.DeleteUserId = null;
  210. groupInfo.DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss");
  211. var addId = await _sqlSugar.Insertable(groupInfo).ExecuteReturnIdentityAsync();
  212. if (addId > 0)
  213. {
  214. result.Code = 0;
  215. result.Msg = "添加成功!";
  216. }
  217. else
  218. {
  219. result.Msg = "添加失败!";
  220. }
  221. } //增加
  222. else if (dto.Status == 2) //修改
  223. {
  224. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => groupInfo);
  225. if (updateStatus)
  226. {
  227. result.Code = 0;
  228. result.Msg = "修改成功!";
  229. }
  230. else
  231. {
  232. result.Msg = "修改失败!";
  233. }
  234. }
  235. else if (dto.Status == 3) //删除
  236. {
  237. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo {
  238. DeleteUserId = dto.UserId,
  239. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  240. IsDel = 1
  241. });
  242. if (deleteStatus)
  243. {
  244. result.Code = 0;
  245. result.Msg = "删除成功!";
  246. }
  247. else
  248. {
  249. result.Msg = "删除失败!";
  250. }
  251. }
  252. }
  253. return result;
  254. }
  255. /// <summary>
  256. /// 获取销售报价号
  257. /// </summary>
  258. /// <returns></returns>
  259. public async Task<Result> GetGroupSalesQuoteNo()
  260. {
  261. Result result = new Result() { Code = -2, Msg = "未知错误" };
  262. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  263. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  264. string teamCode = "";
  265. while (true)
  266. {
  267. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  268. if (!teamCodeItem.Equals(teamCode))
  269. {
  270. break;
  271. }
  272. }
  273. result.Code = 0;
  274. result.Msg = "成功!";
  275. result.Data = teamCode;
  276. return result;
  277. }
  278. /// <summary>
  279. /// 团组删除
  280. /// </summary>
  281. /// <returns></returns>
  282. public async Task<Result> GroupDeleteById()
  283. {
  284. Result result = new Result() { Code = -2, Msg = "未知错误" };
  285. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  286. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  287. string teamCode = "";
  288. while (true)
  289. {
  290. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  291. if (!teamCodeItem.Equals(teamCode))
  292. {
  293. break;
  294. }
  295. }
  296. result.Code = 0;
  297. result.Msg = "成功!";
  298. result.Data = teamCode;
  299. return result;
  300. }
  301. }
  302. }