GoodsRepository.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using OASystem.Domain.Entities.PersonnelModule;
  2. using OASystem.Domain.ViewModels.PersonnelModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using AutoMapper;
  9. using OASystem.Domain.Dtos.PersonnelModule;
  10. namespace OASystem.Infrastructure.Repositories.PersonnelModule
  11. {
  12. /// <summary>
  13. /// 物品进销存
  14. /// 仓储
  15. /// </summary>
  16. public class GoodsRepository:BaseRepository<Pm_GoodsInfo,GoodsInfoView>
  17. {
  18. private readonly IMapper _mapper;
  19. private JsonView _jv;
  20. public GoodsRepository(SqlSugarClient sqlSugar,IMapper mapper):base(sqlSugar)
  21. {
  22. _mapper = mapper;
  23. _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "无效请求!" };
  24. }
  25. /// <summary>
  26. /// 基础数据
  27. /// </summary>
  28. /// <returns></returns>
  29. public async Task<JsonView> InitDataSource()
  30. {
  31. var typeData = await _sqlSugar.Queryable<GoodsTypeView>()
  32. .Includes(x => x.SubTypeItems.Where(z => z.IsDel == 0)
  33. //.Select(z => new {
  34. // z.Id,
  35. // z.STid,
  36. // z.Name
  37. //})
  38. .ToList())
  39. .Where(x => x.IsDel == 0 &&
  40. x.Remark.Equals("GoodsType"))
  41. //.Select(x => new {
  42. // x.Id,
  43. // x.Name,
  44. // x.SubTypeItems
  45. //})
  46. .ToListAsync();
  47. _jv.Code = StatusCodes.Status200OK;
  48. _jv.Data = typeData;
  49. _jv.Msg = $"操作成功";
  50. return _jv;
  51. }
  52. /// <summary>
  53. /// 物品列表
  54. /// </summary>
  55. /// <param name="_dto"></param>
  56. /// <returns></returns>
  57. public async Task<JsonView> GoodsList(GoodsListDTO _dto)
  58. {
  59. var ids = new List<int>();
  60. if (!string.IsNullOrEmpty(_dto.TypeIds))
  61. {
  62. var strArray = _dto.TypeIds.Split(',');
  63. foreach (var str in strArray)
  64. {
  65. if (int.TryParse(str, out int id))
  66. {
  67. ids.Add(id);
  68. }
  69. }
  70. }
  71. RefAsync<int> total = 0;
  72. var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
  73. .LeftJoin<Sys_SetData>((gi, sd) => gi.Type == sd.Id)
  74. .LeftJoin<Sys_Users>((gi, sd, u) => gi.LastUpdateUserId == u.Id)
  75. .Where((gi, sd, u) => gi.IsDel == 0)
  76. .WhereIF(ids.Count > 0, (gi, sd, u) => ids.Contains(gi.Type))
  77. .WhereIF(!string.IsNullOrEmpty(_dto.GoodsName), (gi, sd, u) => gi.Name.Contains(_dto.GoodsName))
  78. .Select((gi, sd, u) => new
  79. {
  80. gi.Id,
  81. gi.Name,
  82. gi.Type,
  83. TypeName = sd.Name,
  84. gi.StockQuantity,
  85. LastUpdateUserName = u.CnName,
  86. gi.LastUpdateTime,
  87. gi.Remark,
  88. })
  89. .OrderByDescending(gi => gi.LastUpdateTime)
  90. .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  91. _jv.Code = StatusCodes.Status200OK;
  92. _jv.Data = data;
  93. _jv.Count = total;
  94. _jv.Msg = $"操作成功";
  95. return _jv;
  96. }
  97. /// <summary>
  98. /// 物品入库列表
  99. /// </summary>
  100. /// <param name="_dto"></param>
  101. /// <returns></returns>
  102. public async Task<JsonView> GoodsStorageList(GoodsStorageListDTO _dto)
  103. {
  104. RefAsync<int> total = 0;
  105. var data = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  106. .LeftJoin<Pm_GoodsInfo>((gs, gi) => gs.GoodsId == gi.Id)
  107. .LeftJoin<Sys_Users>((gs, gi, u) => gs.CreateUserId == u.Id)
  108. .Where((gs, gi, u) => gs.IsDel == 0)
  109. .WhereIF(_dto.GoodsId > 0, (gs, gi, u) => gs.GoodsId == _dto.GoodsId)
  110. .Select((gs, gi, u) => new
  111. {
  112. gs.Id,
  113. gs.GoodsId,
  114. GoodsName = gi.Name,
  115. gs.Quantity,
  116. gs.UnitPrice,
  117. gs.TotalPrice,
  118. gs.SupplierName,
  119. gs.SupplierTel,
  120. gs.SupplierAddress,
  121. gs.SupplierSource,
  122. CreateUserName = u.CnName,
  123. gs.CreateTime,
  124. })
  125. .OrderByDescending(gs => gs.CreateTime)
  126. .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  127. _jv.Code = StatusCodes.Status200OK;
  128. _jv.Data = data;
  129. _jv.Count = total;
  130. _jv.Msg = $"操作成功";
  131. return _jv;
  132. }
  133. /// <summary>
  134. /// 物品领用列表
  135. /// </summary>
  136. /// <param name="_dto"></param>
  137. /// <returns></returns>
  138. public async Task<JsonView> GoodsReceiveList(GoodsReceiveListDTO _dto)
  139. {
  140. RefAsync<int> total = 0;
  141. var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
  142. .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
  143. .LeftJoin<Sys_Users>((gr, gi, u1) => gr.AuditUserId == u1.Id)
  144. .LeftJoin<Sys_Users>((gr, gi, u1,u2) => gr.CreateUserId == u2.Id)
  145. .Where((gr, gi, u1, u2) => gr.IsDel == 0)
  146. .WhereIF(_dto.GoodsId > 0, (gr, gi, u1, u2u) => gr.GoodsId == _dto.GoodsId)
  147. .Select((gr, gi, u1, u2) => new
  148. {
  149. gr.Id,
  150. gr.GroupId,
  151. gr.GoodsId,
  152. GoodsName = gi.Name,
  153. gr.Quantity,
  154. gr.Reason,
  155. gr.Remark,
  156. gr.AuditStatus,
  157. AuditStatusText = gr.AuditStatus.GetDescription(),
  158. gr.AuditUserId,
  159. AuditUserName = u1.CnName,
  160. gr.AuditTime,
  161. CreateUserName = u2.CnName,
  162. gr.CreateTime
  163. })
  164. .OrderByDescending(gs => gs.CreateTime)
  165. .ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
  166. _jv.Code = StatusCodes.Status200OK;
  167. _jv.Data = data;
  168. _jv.Count = total;
  169. _jv.Msg = $"操作成功";
  170. return _jv;
  171. }
  172. }
  173. }