DelegationInfoRepository.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 Serilog;
  10. using SqlSugar;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace OASystem.Infrastructure.Repositories.Groups
  17. {
  18. /// <summary>
  19. /// 接团信息
  20. /// </summary>
  21. public class DelegationInfoRepository : BaseRepository<Grp_DelegationInfo, DelegationInfoView>
  22. {
  23. private readonly SetDataRepository _setDataRepository;
  24. private readonly UsersRepository _usersRepository;
  25. //public readonly Logs _logs;
  26. public DelegationInfoRepository(SqlSugarClient sqlSugar, SetDataRepository setDataRepository, UsersRepository usersRepository)
  27. : base(sqlSugar)
  28. {
  29. this._setDataRepository = setDataRepository;
  30. this._usersRepository = usersRepository;
  31. }
  32. /// <summary>
  33. /// 获取接团信息List
  34. /// </summary>
  35. /// <param name="dto"></param>
  36. /// <returns></returns>
  37. public async Task<Result> GetGroupList(GroupListDto dto)
  38. {
  39. Result result = new Result() { Code = -2, Msg = "未知错误" };
  40. if (dto.PortType == 1 || dto.PortType == 2) //web
  41. {
  42. string sql = string.Format(@"Select gdi.Id,SalesQuoteNo,TourCode,ssd.Name TeamType,ssd1.Name TeamLev,TeamName,ClientName,
  43. ClientUnit,VisitDate,VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure
  44. From Grp_DelegationInfo gdi
  45. Inner Join Sys_SetData ssd On gdi.TeamDid = ssd.Id
  46. Inner Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
  47. Left Join Sys_Users su On gdi.JietuanOperator = su.Id
  48. Where gdi.IsDel = 0
  49. Order By VisitDate Desc");
  50. var _DelegationList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
  51. if (_DelegationList.Count > 0)
  52. {
  53. result.Code = 0;
  54. result.Msg = "成功!";
  55. result.Data = _DelegationList;
  56. }
  57. else
  58. {
  59. result.Msg = "暂无该团组信息";
  60. }
  61. }
  62. return result;
  63. }
  64. /// <summary>
  65. /// 获取接团信息Info
  66. /// </summary>
  67. /// <param name="dto"></param>
  68. /// <returns></returns>
  69. public async Task<Result> GetGroupInfo(GroupInfoDto dto)
  70. {
  71. Result result = new Result() { Code = -2, Msg = "未知错误" };
  72. if (dto.PortType == 1 || dto.PortType == 2) //web
  73. {
  74. string sql = string.Format(@"Select Id,SalesQuoteNo,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
  75. ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,
  76. PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
  77. ZZSCBMMC,ZZSCSPWH,Remark,TellPhone
  78. From Grp_DelegationInfo Where Id = {0} And IsDel = 0", dto.Id);
  79. var _DelegationInfo = await _sqlSugar.SqlQueryable<DelegationInfoWebView>(sql).FirstAsync();
  80. if (_DelegationInfo != null)
  81. {
  82. result.Code = 0;
  83. result.Msg = "成功!";
  84. result.Data = _DelegationInfo;
  85. }
  86. else
  87. {
  88. result.Msg = "暂无该团组信息";
  89. }
  90. }
  91. return result;
  92. }
  93. /// <summary>
  94. /// 获取接团信息 编辑
  95. /// 基础 数据源
  96. /// </summary>
  97. /// <param name="dto"></param>
  98. /// <returns></returns>
  99. public async Task<Result> GroupEditBasicSource(GroupListDto dto)
  100. {
  101. Result result = new Result() { Code = -2, Msg = "未知错误" };
  102. try
  103. {
  104. if (dto.PortType == 1 || dto.PortType == 2) //web
  105. {
  106. dynamic? teamTypeData1 = null;
  107. string teamTypeSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 10, 0);
  108. var teamTypeData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamTypeSql).ToListAsync(); ; //团组分类 10
  109. if (teamTypeData.Count > 0)
  110. {
  111. teamTypeData1 = teamTypeData;
  112. }
  113. dynamic? teamLevData1 = null;
  114. string teamLevSql = string.Format(@"Select Id,Name From Sys_SetData Where STid = {0} And IsDel = {1}", 56, 0);
  115. var teamLevData = await _sqlSugar.SqlQueryable<SetDataInfoView>(teamLevSql).ToListAsync(); ; //团组等级 56
  116. if (teamLevData.Count > 0)
  117. {
  118. teamLevData1 = teamLevData;
  119. }
  120. dynamic? userData1 = null;
  121. string userSql = string.Format(@"Select Id,CnName From Sys_Users Where IsDel = {0}", 0);
  122. var userData = await _sqlSugar.SqlQueryable<UserNameView>(userSql).ToListAsync(); ;
  123. if (userData.Count > 0)
  124. {
  125. userData1 = userData;
  126. }
  127. result.Code = 0;
  128. result.Msg = "成功!";
  129. result.Data = new
  130. {
  131. teamTypeData = teamTypeData1,
  132. teamLevData = teamLevData1,
  133. userData = userData1
  134. };
  135. }
  136. }
  137. catch (Exception)
  138. {
  139. throw;
  140. }
  141. return result;
  142. }
  143. /// <summary>
  144. /// 团组信息操作
  145. /// </summary>
  146. /// <param name="dto"></param>
  147. /// <returns></returns>
  148. public async Task<Result> GroupOperation(GroupOperationDto dto)
  149. {
  150. Result result = new Result() { Code = -2, Msg = "未知错误" };
  151. if (dto.PortType == 1 || dto.PortType == 2) //web
  152. {
  153. Grp_DelegationInfo groupInfo = new Grp_DelegationInfo()
  154. {
  155. SalesQuoteNo = dto.SalesQuoteNo,
  156. TeamLevSId = dto.TeamLevSId,
  157. ClientName = dto.ClientName,
  158. ClientUnit = dto.ClientUnit,
  159. TeamName = dto.TeamName,
  160. TeamDid = dto.TeamDid,
  161. VisitDate = Convert.ToDateTime(dto.VisitDate),
  162. VisitCountry = dto.VisitCountry,
  163. VisitPurpose = dto.VisitPurpose,
  164. VisitDays = dto.VisitDays,
  165. VisitPNumber = dto.VisitPNumber,
  166. SpecialNeeds = dto.SpecialNeeds,
  167. OtherNeeds = dto.OtherNeeds,
  168. Remark = dto.Remark,
  169. JietuanOperator = dto.UserId,
  170. TellPhone = dto.TellPhone,
  171. CGRWSPBMMC = dto.CGRWSPBMMC,
  172. CGRWSPWH = dto.CGRWSPWH,
  173. ZZSCBMMC = dto.ZZSCBMMC,
  174. ZZSCSPWH = dto.ZZSCSPWH,
  175. TontractTime = Convert.ToDateTime(dto.TontractTime),
  176. PaymentMoney = dto.PaymentMoney,
  177. PayDay = dto.PayDay
  178. };
  179. if (dto.Status == 1) //添加
  180. {
  181. string selectSql = string.Format(@"Select * From Grp_DelegationInfo
  182. Where IsDel = 0
  183. And SalesQuoteNo = '{0}'
  184. And TeamName = '{1}'
  185. And ClientName = '{2}'
  186. And ClientUnit ='{3}'
  187. And VisitDate ='{4}'", dto.SalesQuoteNo, dto.TeamName, dto.ClientName, dto.ClientUnit, dto.VisitDate);
  188. var selectGroupInfo = await _sqlSugar.SqlQueryable<Grp_DelegationInfo>(selectSql).FirstAsync();
  189. if (selectGroupInfo != null)
  190. {
  191. result.Msg = "数据已存在,请勿重复添加!";
  192. return result;
  193. }
  194. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  195. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  196. string teamCode = "";
  197. while (true)
  198. {
  199. teamCode = Tools.CommonFun.GetRandomStr(6);
  200. if (!teamCodeItem.Equals(teamCode))
  201. {
  202. break;
  203. }
  204. }
  205. groupInfo.TourCode = teamCode;
  206. groupInfo.SalesDate = DateTime.Now;
  207. groupInfo.IsState = 0; //默认团组未完成 0
  208. groupInfo.JietuanTime = DateTime.Now;
  209. groupInfo.IsDel = 0;
  210. groupInfo.BudgetCost = 0.00M;
  211. groupInfo.HotelComplain = 0;
  212. groupInfo.OPComplain = 0;
  213. groupInfo.OAComplain = 0;
  214. groupInfo.AirComplain = 0;
  215. groupInfo.VisaComplain = 0;
  216. groupInfo.CreateUserId = dto.UserId;
  217. groupInfo.CreateTime = DateTime.Now;
  218. groupInfo.DeleteUserId = null;
  219. groupInfo.DeleteTime = new DateTime(1990, 1, 1).ToString("yyyy-MM-dd HH:mm:ss");
  220. var addId = await _sqlSugar.Insertable(groupInfo).ExecuteReturnIdentityAsync();
  221. if (addId > 0)
  222. {
  223. result.Code = 0;
  224. result.Msg = "添加成功!";
  225. }
  226. else
  227. {
  228. result.Msg = "添加失败!";
  229. }
  230. } //增加
  231. else if (dto.Status == 2) //修改
  232. {
  233. var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo {
  234. SalesQuoteNo = dto.SalesQuoteNo,
  235. TeamLevSId = dto.TeamLevSId,
  236. ClientName = dto.ClientName,
  237. ClientUnit = dto.ClientUnit,
  238. TeamName = dto.TeamName,
  239. TeamDid = dto.TeamDid,
  240. VisitDate = Convert.ToDateTime(dto.VisitDate),
  241. VisitCountry = dto.VisitCountry,
  242. VisitPurpose = dto.VisitPurpose,
  243. VisitDays = dto.VisitDays,
  244. VisitPNumber = dto.VisitPNumber,
  245. SpecialNeeds = dto.SpecialNeeds,
  246. OtherNeeds = dto.OtherNeeds,
  247. Remark = dto.Remark,
  248. JietuanOperator = dto.UserId,
  249. TellPhone = dto.TellPhone,
  250. CGRWSPBMMC = dto.CGRWSPBMMC,
  251. CGRWSPWH = dto.CGRWSPWH,
  252. ZZSCBMMC = dto.ZZSCBMMC,
  253. ZZSCSPWH = dto.ZZSCSPWH,
  254. TontractTime = Convert.ToDateTime(dto.TontractTime),
  255. PaymentMoney = dto.PaymentMoney,
  256. PayDay = dto.PayDay
  257. });
  258. if (updateStatus)
  259. {
  260. result.Code = 0;
  261. result.Msg = "修改成功!";
  262. }
  263. else
  264. {
  265. result.Msg = "修改失败!";
  266. }
  267. }
  268. else if (dto.Status == 3) //删除
  269. {
  270. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo {
  271. DeleteUserId = dto.UserId,
  272. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  273. IsDel = 1
  274. });
  275. if (deleteStatus)
  276. {
  277. result.Code = 0;
  278. result.Msg = "删除成功!";
  279. }
  280. else
  281. {
  282. result.Msg = "删除失败!";
  283. }
  284. }
  285. }
  286. return result;
  287. }
  288. /// <summary>
  289. /// 团组信息操作
  290. /// </summary>
  291. /// <param name="dto"></param>
  292. /// <returns></returns>
  293. public async Task<Result> GroupDel(GroupDelDto dto)
  294. {
  295. Result result = new Result() { Code = -2, Msg = "未知错误" };
  296. if (dto.PortType == 1 || dto.PortType == 2) //web
  297. {
  298. var deleteStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
  299. {
  300. DeleteUserId = dto.UserId,
  301. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  302. IsDel = 1
  303. });
  304. if (deleteStatus)
  305. {
  306. result.Code = 0;
  307. result.Msg = "删除成功!";
  308. }
  309. else
  310. {
  311. result.Msg = "删除失败!";
  312. }
  313. }
  314. return result;
  315. }
  316. /// <summary>
  317. /// 获取销售报价号
  318. /// </summary>
  319. /// <returns></returns>
  320. public async Task<Result> GetGroupSalesQuoteNo()
  321. {
  322. Result result = new Result() { Code = -2, Msg = "未知错误" };
  323. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  324. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  325. string teamCode = "";
  326. while (true)
  327. {
  328. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  329. if (!teamCodeItem.Equals(teamCode))
  330. {
  331. break;
  332. }
  333. }
  334. result.Code = 0;
  335. result.Msg = "成功!";
  336. result.Data = teamCode;
  337. return result;
  338. }
  339. /// <summary>
  340. /// 团组删除
  341. /// </summary>
  342. /// <returns></returns>
  343. public async Task<Result> GroupDeleteById()
  344. {
  345. Result result = new Result() { Code = -2, Msg = "未知错误" };
  346. string teamCodeSql = string.Format("Select TourCode From Grp_DelegationInfo");
  347. var teamCodeItem = await _sqlSugar.SqlQueryable<TeamCodeView>(teamCodeSql).ToListAsync();
  348. string teamCode = "";
  349. while (true)
  350. {
  351. teamCode = Tools.CommonFun.GetRandomAllStr(6);
  352. if (!teamCodeItem.Equals(teamCode))
  353. {
  354. break;
  355. }
  356. }
  357. result.Code = 0;
  358. result.Msg = "成功!";
  359. result.Data = teamCode;
  360. return result;
  361. }
  362. }
  363. }