MediaSuppliersRepository.cs 6.9 KB

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