MediaSuppliersRepository.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. return result;
  72. }
  73. /// <summary>
  74. /// 分页查询
  75. /// </summary>
  76. /// <param name="dto"></param>
  77. /// <returns></returns>
  78. public async Task<JsonView> PageItem(MediaSupplierPageItemDto dto)
  79. {
  80. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  81. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  82. var search = dto.Search;
  83. RefAsync<int> total = 0;
  84. var infos = await _sqlSugar.Queryable<Res_MediaSuppliers>()
  85. .LeftJoin<Sys_Users>((ms, u) => ms.CreateUserId == u.Id)
  86. .Where((ms, u) => ms.IsDel == 0)
  87. .WhereIF(!string.IsNullOrEmpty(search), (ms, u) => ms.UnitName.Contains(search) || ms.Contact.Contains(search) || ms.Tel.Contains(search))
  88. .OrderByDescending((ms, u) => ms.CreateTime)
  89. .Select((ms, u) => new
  90. {
  91. ms.Id,
  92. ms.Privince,
  93. ms.City,
  94. ms.UnitName,
  95. ms.Contact,
  96. ms.Sex,
  97. ms.Post,
  98. ms.Tel,
  99. CreateUserName = u.CnName,
  100. ms.CreateTime
  101. })
  102. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  103. result.Code = 200;
  104. result.Data = infos;
  105. result.Count = total;
  106. return result;
  107. }
  108. /// <summary>
  109. /// 操作(添加 Or 编辑)
  110. /// </summary>
  111. /// <param name="dto"></param>
  112. /// <returns></returns>
  113. public async Task<JsonView> AddOrEdit(MediaSupplierAddOrEditDto dto)
  114. {
  115. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  116. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  117. var userId = dto.CurrUserId;
  118. if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
  119. var info = _mapper.Map<Res_MediaSuppliers>(dto);
  120. info.CreateUserId = userId;
  121. if (info.Id < 1) //添加
  122. {
  123. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  124. if (add > 0)
  125. {
  126. result.Code = 200;
  127. result.Msg = $"操作成功!";
  128. }
  129. }
  130. else if (info.Id > 0) //编辑
  131. {
  132. var upd = await _sqlSugar.Updateable(info).IgnoreColumns(x => new { x.CreateUserId, x.CreateTime }).ExecuteCommandAsync();
  133. if (upd > 0)
  134. {
  135. result.Code = 200;
  136. result.Msg = $"操作成功!";
  137. }
  138. }
  139. return result;
  140. }
  141. /// <summary>
  142. /// 软删除
  143. /// </summary>
  144. /// <param name="dto"></param>
  145. /// <returns></returns>
  146. public async Task<JsonView> SoftDel(MediaSupplierSoftDelDto dto)
  147. {
  148. var result = new JsonView() { Code = 400, Msg = "操作失败" };
  149. int userId = dto.CurrUserId, id = dto.Id;
  150. if (!_portIds.Contains(dto.PortType)) { result.Msg = MsgTips.Port; return result; }
  151. if (userId < 1) { result.Msg = MsgTips.UserId; return result; }
  152. if (id < 1) { result.Msg = MsgTips.Id; return result; }
  153. var status = await _sqlSugar.Updateable<Res_MediaSuppliers>()
  154. .SetColumns(x => new Res_MediaSuppliers() { DeleteUserId = userId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  155. .Where(x => x.Id == id)
  156. .ExecuteCommandAsync();
  157. if (status > 0)
  158. {
  159. result.Code = 200;
  160. result.Msg = $"操作成功!";
  161. }
  162. return result;
  163. }
  164. }
  165. }