MediaSuppliersRepository.cs 6.2 KB

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