MediaSuppliersRepository.cs 6.2 KB

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