BaseInvService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using SqlSugar;
  2. using wms.sqlsugar.model.pt;
  3. using WMS.BZModels;
  4. using WMS.BZModels.Dto.PT.BillInvDtos;
  5. using WMS.Info;
  6. using WMS.BZSqlSugar;
  7. namespace WMS.BZServices.PT
  8. {
  9. public class BaseInvService
  10. {
  11. private readonly Repository<BillInvnow> _billInvnowrepository;
  12. public BaseInvService(Repository<BillInvnow> billInvnowrepository)
  13. {
  14. _billInvnowrepository = billInvnowrepository;
  15. }
  16. public PagedInfo<BillInvNowDto> GetPageList(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  17. {
  18. ISugarQueryable<BillInvNowDto> sugarQueryable = GetQueryable(billInvNowQueryDto);
  19. var list = sugarQueryable.ToPage(pagination);
  20. return list;
  21. }
  22. public IList<BillInvNowDto> GetList(BillInvNowQueryDto billInvNowQueryDto)
  23. {
  24. ISugarQueryable<BillInvNowDto> sugarQueryable = GetQueryable(billInvNowQueryDto);
  25. var list = sugarQueryable.ToList();
  26. return list;
  27. }
  28. private ISugarQueryable<BillInvNowDto> GetQueryable(BillInvNowQueryDto billInvNowQueryDto)
  29. {
  30. var predicate = Expressionable.Create<BillInvnow, BaseWarecell>();
  31. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), (billInvnow, warecell) => billInvnow.RFIDBarCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.ContGrpBarCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord) || billInvnow.RodBarCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.BoilerNo.Contains(billInvNowQueryDto.KeyWord));
  32. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Id), (billInvnow, warecell) => billInvnow.Id.ToString().Contains(billInvNowQueryDto.Id));
  33. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ContGrpId), (billInvnow, warecell) => billInvnow.ContGrpId.ToString().Contains(billInvNowQueryDto.ContGrpId));
  34. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.EquContGrpId), (billInvnow, warecell) => billInvnow.ContGrpId.ToString().Equals(billInvNowQueryDto.EquContGrpId));
  35. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.MatCode), (billInvnow, warecell) => billInvnow.MatCode.Contains(billInvNowQueryDto.MatCode));
  36. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.MatName), (billInvnow, warecell) => billInvnow.MatName.Contains(billInvNowQueryDto.MatName));
  37. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.BoilerNo), (billInvnow, warecell) => billInvnow.BoilerNo.Contains(billInvNowQueryDto.BoilerNo));
  38. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.RFIDBarCode), (billInvnow, warecell) => billInvnow.RFIDBarCode.Contains(billInvNowQueryDto.RFIDBarCode));
  39. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.InvBarCode), (billInvnow, warecell) => billInvnow.InvBarCode.Contains(billInvNowQueryDto.InvBarCode));
  40. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutRow), (billInvnow, warecell) => billInvnow.PutRow.Equals(billInvNowQueryDto.PutRow));
  41. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutCol), (billInvnow, warecell) => billInvnow.PutCol.Equals(billInvNowQueryDto.PutCol));
  42. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutLayer), (billInvnow, warecell) => billInvnow.PutLayer.Equals(billInvNowQueryDto.PutLayer));
  43. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Grade), (billInvnow, warecell) => billInvnow.Grade.Contains(billInvNowQueryDto.Grade));
  44. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.OneInTimeBegin.HasValue, (billInvnow, warecell) => billInvnow.OneInTime >= billInvNowQueryDto.OneInTimeBegin);
  45. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.OneInTimeEnd.HasValue, (billInvnow, warecell) => billInvnow.OneInTime <= billInvNowQueryDto.OneInTimeEnd);
  46. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.ProductTimeBegin.HasValue, (billInvnow, warecell) => billInvnow.ProductTime >= billInvNowQueryDto.ProductTimeBegin);
  47. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.ProductTimeEnd.HasValue, (billInvnow, warecell) => billInvnow.ProductTime <= billInvNowQueryDto.ProductTimeEnd);
  48. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Tunnel), (billInvnow, warecell) => warecell.Tunnel.Equals(billInvNowQueryDto.Tunnel));
  49. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Code), (billInvnow, warecell) => warecell.Code.Contains(billInvNowQueryDto.Code));
  50. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsSurplus), (billInvnow, warecell) => billInvnow.IsSurplus.Equals(billInvNowQueryDto.IsSurplus));
  51. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsRework), (billInvnow, warecell) => billInvnow.IsRework.Equals(billInvNowQueryDto.IsRework));
  52. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsFail), (billInvnow, warecell) => billInvnow.IsFail.Equals(billInvNowQueryDto.IsFail));
  53. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsFast), (billInvnow, warecell) => billInvnow.IsFast.Equals(billInvNowQueryDto.IsFast));
  54. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsBack), (billInvnow, warecell) => billInvnow.IsBack.Equals(billInvNowQueryDto.IsBack));
  55. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ExecStateCode), (billInvnow, warecell) => billInvnow.ExecStateCode.Equals(billInvNowQueryDto.ExecStateCode));
  56. //predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ContGrpType), (billInvnow, warecell) => billInvnow.ContGrpType.Equals(billInvNowQueryDto.ContGrpType));
  57. if (!string.IsNullOrEmpty(billInvNowQueryDto?.InvStateCode))
  58. {
  59. var enums = (InvState)Enum.ToObject(typeof(InvState), Convert.ToInt32(billInvNowQueryDto?.InvStateCode));
  60. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.InvStateCode), (billInvnow, warecell) => billInvnow.InvStateCode.Equals(enums.ToString()));
  61. }
  62. //if (!string.IsNullOrEmpty(billInvNowQueryDto?.ExecStateCode))
  63. //{
  64. // var enums = (InvLockState)Enum.ToObject(typeof(InvLockState), Convert.ToInt32(billInvNowQueryDto?.ExecStateCode));
  65. // predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ExecStateCode), (billInvnow, warecell) => billInvnow.ExecStateCode.Equals(enums.ToString()));
  66. //}
  67. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow, BaseWarecell>((billInvnow, warecell) => new object[] {
  68. JoinType.Left,billInvnow.ContGrpId == warecell.ContGrpId && billInvnow.WarehouseId ==warecell.WarehouseId }).Where(predicate.ToExpression())
  69. .Select((billInvnow, warecell) => new BillInvNowDto
  70. {
  71. Id = billInvnow.Id.ToString(),
  72. WarehouseId = billInvnow.WarehouseId.ToString(),
  73. ContGrpId = billInvnow.ContGrpId.ToString(),
  74. ContGrpBarCode = billInvnow.ContGrpBarCode,
  75. BoxBarCode = billInvnow.BoxBarCode,
  76. BomDocsNo = billInvnow.BomDocsNo,
  77. BomMatId = billInvnow.BomMatId.ToString(),
  78. BomMatCode = billInvnow.BomMatCode,
  79. BomMatName = billInvnow.BomMatName,
  80. BomSetId = billInvnow.BomSetId.ToString(),
  81. ExecStateCode = billInvnow.ExecStateCode,
  82. InvStateCode = billInvnow.InvStateCode,
  83. ExecDocsNo = billInvnow.ExecDocsNo,
  84. ExecDocsRowNo = billInvnow.ExecDocsRowNo,
  85. ExecDocsTypeCode = billInvnow.ExecDocsTypeCode,
  86. InvInOut = billInvnow.InvInOut,
  87. ExecWho = billInvnow.ExecWho,
  88. ExecTime = billInvnow.ExecTime,
  89. PutRow = billInvnow.PutRow,
  90. PutCol = billInvnow.PutCol,
  91. PutLayer = billInvnow.PutLayer,
  92. InvBarCode = billInvnow.InvBarCode,
  93. InDocsNo = billInvnow.InDocsNo,
  94. InDocsRowNo = billInvnow.InDocsRowNo,
  95. SuppCode = billInvnow.SuppCode,
  96. SuppName = billInvnow.SuppName,
  97. CustCode = billInvnow.CustCode,
  98. CustName = billInvnow.CustName,
  99. MatId = billInvnow.MatId.ToString(),
  100. MatCode = billInvnow.MatCode,
  101. MatName = billInvnow.MatName,
  102. TolWQty = billInvnow.TolWQty,
  103. NetWQty = billInvnow.NetWQty,
  104. TareWQty = billInvnow.TareWQty,
  105. LengthQty = billInvnow.LengthQty,
  106. CaQty = billInvnow.CaQty,
  107. SolderQty = billInvnow.SolderQty,
  108. ContUsageQty = billInvnow.ContUsageQty,
  109. BatchNo = billInvnow.BatchNo,
  110. ProductTime = billInvnow.ProductTime,
  111. OneInTime = billInvnow.OneInTime,
  112. RodBarCode = billInvnow.RodBarCode,
  113. HWBarCode = billInvnow.HWBarCode,
  114. RFIDBarCode = billInvnow.RFIDBarCode,
  115. CLBarCode = billInvnow.CLBarCode,
  116. HWTypeCode = billInvnow.HWTypeCode,
  117. BoilerNo = billInvnow.BoilerNo,
  118. PackNo = billInvnow.PackNo,
  119. BrandNo = billInvnow.BrandNo,
  120. ExecStd = billInvnow.ExecStd,
  121. LicenceCode = billInvnow.LicenceCode,
  122. IsSurplus = billInvnow.IsSurplus,
  123. IsRework = billInvnow.IsRework,
  124. IsBlack = billInvnow.IsBlack,
  125. IsCore = billInvnow.IsCore,
  126. IsFast = billInvnow.IsFast,
  127. IsFail = billInvnow.IsFail,
  128. FailReason = billInvnow.FailReason,
  129. SilkTypeCode = billInvnow.SilkTypeCode,
  130. Grade = billInvnow.Grade,
  131. IsBack = billInvnow.IsBack,
  132. BackReason = billInvnow.BackReason,
  133. IsTorsChk = billInvnow.IsTorsChk,
  134. TorsChkQty = billInvnow.TorsChkQty,
  135. TorsChkTime = billInvnow.TorsChkTime,
  136. TorsChkValue = billInvnow.TorsChkValue,
  137. TorsChkMachCode = billInvnow.TorsChkMachCode,
  138. ProcessDocsCode = billInvnow.ProcessDocsCode,
  139. ProductMachCode = billInvnow.ProductMachCode,
  140. ProductLineNo = billInvnow.ProductLineNo,
  141. //Remark = billInvnow.Remark,
  142. //Default1 = billInvnow.Default1,
  143. //Default2 = billInvnow.Default2,
  144. //Default3 = billInvnow.Default3,
  145. AddWho = billInvnow.AddWho,
  146. AddTime = billInvnow.AddTime,
  147. EditWho = billInvnow.EditWho,
  148. EditTime = billInvnow.EditTime,
  149. Size = billInvnow.Size,
  150. Memo = billInvnow.Memo,
  151. Tunnel = warecell.Tunnel,
  152. Code = warecell.Code,
  153. CellState = warecell.IsStop,
  154. }).MergeTable();
  155. return sugarQueryable;
  156. }
  157. public bool UpdateInvLockState(List<string> tunnels, InvLockState invLockState, string userId)
  158. {
  159. if (!tunnels.Any())
  160. {
  161. throw new ArgumentException("没有选择数据!");
  162. }
  163. var list = _billInvnowrepository.Queryable().Where(o => tunnels.Contains(o.Id.ToString())).ToList();
  164. if (!list.Any())
  165. {
  166. throw new ArgumentException("没有找到数据!");
  167. }
  168. list.ForEach(o =>
  169. {
  170. o.Memo = (!string.IsNullOrWhiteSpace(o.Memo)? o.Memo+"。":"") + "原:"+o.ExecStateCode+",修改为:"+ invLockState.ToString()+",修改人:"+ userId+",修改时间"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"。";
  171. o.ExecStateCode= invLockState.ToString();
  172. o.EditWho = userId;
  173. o.EditTime = DateTime.Now;
  174. });
  175. var result = _billInvnowrepository.UpdateRange(list.ToArray());
  176. return result;
  177. }
  178. }
  179. }