MediaSuppliersRepository.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using OASystem.Domain.Entities.Resource;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using AutoMapper;
  8. using OASystem.Domain.Dtos.Resource;
  9. using EyeSoft.Extensions;
  10. using OASystem.Domain;
  11. using OASystem.Domain.ViewModels.Resource;
  12. using OASystem.Domain.AesEncryption;
  13. namespace OASystem.Infrastructure.Repositories.Resource
  14. {
  15. /// <summary>
  16. /// 策划部供应商资料
  17. /// 仓储
  18. /// </summary>
  19. public class MediaSuppliersRepository : BaseRepository<Res_MediaSuppliers, Res_MediaSuppliers>
  20. {
  21. private readonly IMapper _mapper;
  22. private readonly List<int> _portIds;
  23. public MediaSuppliersRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  24. {
  25. _mapper = mapper;
  26. _portIds = new List<int> { 1, 2, 3 };
  27. }
  28. /// <summary>
  29. /// 初始化数据
  30. /// </summary>
  31. /// <returns></returns>
  32. public async Task<JsonView> Init()
  33. {
  34. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  35. var typeData = await _sqlSugar.Queryable<Sys_SetData>()
  36. .Where(x => x.IsDel == 0 && x.STid == 21)
  37. .Select(x => new { x.Id, Text = x.Name })
  38. .ToListAsync();
  39. result.Code = 200;
  40. result.Data = typeData;
  41. return result;
  42. }
  43. /// <summary>
  44. /// 详情
  45. /// </summary>
  46. /// <param name="dto"></param>
  47. /// <returns></returns>
  48. public async Task<JsonView> Info(MediaSupplierInfoDto dto)
  49. {
  50. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  51. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  52. if (dto.Id < 1) { result.Msg = MsgTips.Id; return result; }
  53. var info = await _sqlSugar.Queryable<Res_MediaSuppliers>()
  54. .Where(x => x.IsDel == 0 && x.Id == dto.Id)
  55. .Select(x => new MediaSupplierInfoView()
  56. {
  57. Id = x.Id,
  58. TypeId = x.TypeId,
  59. Privince = x.Privince,
  60. City = x.City,
  61. UnitName = x.UnitName,
  62. UnitAbbreviation = x.UnitAbbreviation,
  63. UnitAddress = x.UnitAddress,
  64. Contact = x.Contact,
  65. Sex = x.Sex,
  66. Post = x.Post,
  67. Fax = x.Fax,
  68. Tel = x.Tel,
  69. Email = x.Email,
  70. WeChat = x.WeChat,
  71. Remark = x.Remark
  72. })
  73. .FirstAsync();
  74. EncryptionProcessor.DecryptProperties(info);
  75. result.Code = 200;
  76. result.Data = info;
  77. result.Msg = MsgTips.Succeed;
  78. return result;
  79. }
  80. /// <summary>
  81. /// 分页查询
  82. /// </summary>
  83. /// <param name="dto"></param>
  84. /// <returns></returns>
  85. public async Task<JsonView> PageItem(MediaSupplierPageItemDto dto)
  86. {
  87. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  88. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  89. var typeLabel = new List<int>();
  90. if (!string.IsNullOrEmpty(dto.TypeLabel))
  91. {
  92. typeLabel = dto.TypeLabel.Split(',')
  93. .Select(s =>
  94. {
  95. int value = 0;
  96. if (int.TryParse(s, out value)) return value;
  97. return value;
  98. })
  99. .Where(i => i != 0)
  100. .ToList();
  101. }
  102. var search = AesEncryptionHelper.Encrypt(dto.Search);
  103. RefAsync<int> total = 0;
  104. var infos = await _sqlSugar.Queryable<Res_MediaSuppliers>()
  105. .LeftJoin<Sys_Users>((ms, u) => ms.CreateUserId == u.Id)
  106. .Where((ms, u) => ms.IsDel == 0)
  107. .WhereIF(typeLabel.Count > 0 , (ms, u) => typeLabel.Contains(ms.TypeId))
  108. .WhereIF(!string.IsNullOrEmpty(search), (ms, u) => ms.UnitName.Contains(search) || ms.Contact.Contains(search) || ms.Tel.Contains(search))
  109. .OrderByDescending((ms, u) => ms.CreateTime)
  110. .Select((ms, u) => new PageItemView()
  111. {
  112. Id = ms.Id,
  113. Privince = ms.Privince,
  114. City = ms.City,
  115. UnitName = ms.UnitName,
  116. Contact = ms.Contact,
  117. Sex = ms.Sex,
  118. Post = ms.Post,
  119. Tel = ms.Tel,
  120. CreateUserName = u.CnName,
  121. CreateTime = ms.CreateTime
  122. })
  123. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  124. foreach (var info in infos) EncryptionProcessor.DecryptProperties(info);
  125. result.Msg = MsgTips.Succeed;
  126. result.Code = 200;
  127. result.Data = infos;
  128. result.Count = total;
  129. return result;
  130. }
  131. /// <summary>
  132. /// 操作(添加 Or 编辑)
  133. /// </summary>
  134. /// <param name="dto"></param>
  135. /// <returns></returns>
  136. public async Task<JsonView> AddOrEdit(MediaSupplierAddOrEditDto dto)
  137. {
  138. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  139. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  140. var userId = dto.CurrUserId;
  141. if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
  142. var info = _mapper.Map<Res_MediaSuppliers>(dto);
  143. info.CreateUserId = userId;
  144. EncryptionProcessor.DecryptProperties(info);
  145. if (info.Id < 1) //添加
  146. {
  147. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  148. if (add < 1) return result;
  149. }
  150. else //编辑
  151. {
  152. var upd = await _sqlSugar.Updateable(info).IgnoreColumns(x => new { x.CreateUserId, x.CreateTime }).ExecuteCommandAsync();
  153. if (upd < 1) return result;
  154. }
  155. result.Code = 200;
  156. result.Msg = $"操作成功!";
  157. return result;
  158. }
  159. /// <summary>
  160. /// 软删除
  161. /// </summary>
  162. /// <param name="dto"></param>
  163. /// <returns></returns>
  164. public async Task<JsonView> SoftDel(MediaSupplierSoftDelDto dto)
  165. {
  166. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  167. int userId = dto.CurrUserId, id = dto.Id;
  168. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  169. if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
  170. if (id < 1) { result.Msg = MsgTips.Id; return result; }
  171. var status = await _sqlSugar.Updateable<Res_MediaSuppliers>()
  172. .SetColumns(x => new Res_MediaSuppliers() { IsDel = 1, DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  173. .Where(x => x.Id == id)
  174. .ExecuteCommandAsync();
  175. if (status > 0)
  176. {
  177. result.Code = 200;
  178. result.Msg = $"操作成功!";
  179. }
  180. return result;
  181. }
  182. }
  183. }