BaseInvService.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using SqlSugar;
  2. using WMS.BZModels;
  3. using WMS.Info;
  4. using WMS.BZSqlSugar;
  5. using WMS.BZModels.Models.KLHC;
  6. using System.Diagnostics;
  7. using Mapster;
  8. using System;
  9. using WMS.BZModels.Dto.KLHC.BillInvDtos;
  10. namespace WMS.BZServices.KLHC
  11. {
  12. public class BaseInvService
  13. {
  14. private readonly Repository<BillInvnow> _billInvnowrepository;
  15. private readonly Repository<BillInvflow> _billInvflowrepository;
  16. private readonly BillLogService _billLogService;
  17. public BaseInvService(Repository<BillInvnow> billInvnowrepository, BillLogService billLogService, Repository<BillInvflow> billInvflowrepository)
  18. {
  19. _billInvnowrepository = billInvnowrepository;
  20. _billLogService = billLogService;
  21. _billInvflowrepository = billInvflowrepository;
  22. }
  23. public PagedInfo<BillInvNowDto> GetPageList(Pagination pagination, BillInvNowQueryDto billInvNowQueryDto)
  24. {
  25. ISugarQueryable<BillInvNowDto> sugarQueryable = GetQueryable(billInvNowQueryDto);
  26. var list = sugarQueryable.ToPage(pagination);
  27. return list;
  28. }
  29. public IList<BillInvNowDto> GetList(BillInvNowQueryDto billInvNowQueryDto)
  30. {
  31. ISugarQueryable<BillInvNowDto> sugarQueryable = GetQueryable(billInvNowQueryDto);
  32. var list = sugarQueryable.ToList();
  33. return list;
  34. }
  35. private ISugarQueryable<BillInvNowDto> GetQueryable(BillInvNowQueryDto billInvNowQueryDto)
  36. {
  37. var predicate = Expressionable.Create<BillInvnow, BaseWarecell, BaseWarehouse>();
  38. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.KeyWord), (billInvnow, warecell, warehouse) => billInvnow.RFIDBarCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.ContGrpBarCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatCode.Contains(billInvNowQueryDto.KeyWord) || billInvnow.MatName.Contains(billInvNowQueryDto.KeyWord) || billInvnow.InvBarCode.Contains(billInvNowQueryDto.KeyWord));
  39. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Id), (billInvnow, warecell, warehouse) => billInvnow.Id.ToString().Contains(billInvNowQueryDto.Id));
  40. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.WarehouseId), (billInvnow, warecell, warehouse) => billInvnow.WarehouseId.ToString().Contains(billInvNowQueryDto.WarehouseId));
  41. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ContGrpId), (billInvnow, warecell, warehouse) => billInvnow.ContGrpId.ToString().Contains(billInvNowQueryDto.ContGrpId));
  42. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.EquContGrpId), (billInvnow, warecell, warehouse) => billInvnow.ContGrpId.ToString().Equals(billInvNowQueryDto.EquContGrpId));
  43. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.MatCode), (billInvnow, warecell, warehouse) => billInvnow.MatCode.Equals(billInvNowQueryDto.MatCode));
  44. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.MatName), (billInvnow, warecell, warehouse) => billInvnow.MatName.Equals(billInvNowQueryDto.MatName));
  45. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.RFIDBarCode), (billInvnow, warecell, warehouse) => billInvnow.RFIDBarCode.Contains(billInvNowQueryDto.RFIDBarCode));
  46. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.InvBarCode), (billInvnow, warecell, warehouse) => billInvnow.InvBarCode.Contains(billInvNowQueryDto.InvBarCode));
  47. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutRow), (billInvnow, warecell, warehouse) => billInvnow.PutRow.Equals(billInvNowQueryDto.PutRow));
  48. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutCol), (billInvnow, warecell, warehouse) => billInvnow.PutCol.Equals(billInvNowQueryDto.PutCol));
  49. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.PutLayer), (billInvnow, warecell, warehouse) => billInvnow.PutLayer.Equals(billInvNowQueryDto.PutLayer));
  50. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Grade), (billInvnow, warecell, warehouse) => billInvnow.Grade.Contains(billInvNowQueryDto.Grade));
  51. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.OneInTimeBegin.HasValue, (billInvnow, warecell, warehouse) => billInvnow.OneInTime >= billInvNowQueryDto.OneInTimeBegin);
  52. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.OneInTimeEnd.HasValue, (billInvnow, warecell, warehouse) => billInvnow.OneInTime <= billInvNowQueryDto.OneInTimeEnd);
  53. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.ProductTimeBegin.HasValue, (billInvnow, warecell, warehouse) => billInvnow.ProductTime >= billInvNowQueryDto.ProductTimeBegin);
  54. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.ProductTimeEnd.HasValue, (billInvnow, warecell, warehouse) => billInvnow.ProductTime <= billInvNowQueryDto.ProductTimeEnd);
  55. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Tunnel), (billInvnow, warecell, warehouse) => warecell.Tunnel.Equals(billInvNowQueryDto.Tunnel));
  56. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.Code), (billInvnow, warecell, warehouse) => warecell.Code.Contains(billInvNowQueryDto.Code));
  57. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsSurplus), (billInvnow, warecell, warehouse) => billInvnow.IsSurplus.Equals(billInvNowQueryDto.IsSurplus));
  58. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsRework), (billInvnow, warecell, warehouse) => billInvnow.IsRework.Equals(billInvNowQueryDto.IsRework));
  59. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsFail), (billInvnow, warecell, warehouse) => billInvnow.IsFail.Equals(billInvNowQueryDto.IsFail));
  60. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsFast), (billInvnow, warecell, warehouse) => billInvnow.IsFast.Equals(billInvNowQueryDto.IsFast));
  61. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.IsBack), (billInvnow, warecell, warehouse) => billInvnow.IsBack.Equals(billInvNowQueryDto.IsBack));
  62. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ExecStateCode), (billInvnow, warecell, warehouse) => billInvnow.ExecStateCode.Equals(billInvNowQueryDto.ExecStateCode));
  63. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.SetGrpCode), (billInvnow, warecell, warehouse) => billInvnow.SetGrpCode.Equals(billInvNowQueryDto.SetGrpCode));
  64. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ContGrpType), (billInvnow, warecell, warehouse) => billInvnow.ContGrpType.Equals(billInvNowQueryDto.ContGrpType));
  65. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.HWBarCode), (billInvnow, warecell, warehouse) => billInvnow.HWBarCode.Contains(billInvNowQueryDto.HWBarCode));
  66. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.ContGrpBarCode), (billInvnow, warecell, warehouse) => billInvnow.ContGrpBarCode.Contains(billInvNowQueryDto.ContGrpBarCode));
  67. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.BomMatCode), (billInvnow, warecell, warehouse) => billInvnow.BomMatCode.Equals(billInvNowQueryDto.BomMatCode));
  68. if (!string.IsNullOrEmpty(billInvNowQueryDto?.InvStateCode))
  69. {
  70. var enums = (InvState)Enum.ToObject(typeof(InvState), Convert.ToInt32(billInvNowQueryDto?.InvStateCode));
  71. predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvNowQueryDto?.InvStateCode), (billInvnow, warecell, warehouse) => billInvnow.InvStateCode.Equals(enums.ToString()));
  72. }
  73. if (!string.IsNullOrEmpty(billInvNowQueryDto.IsManualOut) && billInvNowQueryDto.IsManualOut == "1")
  74. {
  75. predicate = predicate.AndIF(billInvNowQueryDto != null && billInvNowQueryDto.IsManualOut == "1", (billInvnow, warecell, warehouse) => SqlFunc.Subqueryable<BaseWarehouse>().Where(s => s.Id == billInvnow.WarehouseId && s.TypeNum == 1).Any());
  76. }
  77. var sugarQueryable = _billInvnowrepository.Context.Queryable<BillInvnow, BaseWarecell, BaseWarehouse>((billInvnow, warecell, warehouse) => new object[] {
  78. JoinType.Left,billInvnow.ContGrpId == warecell.ContGrpId && billInvnow.WarehouseId ==warecell.WarehouseId , JoinType.Left, billInvnow.WarehouseId==warehouse.Id
  79. , JoinType.Left, warecell.WarehouseId==warehouse.Id}).Where(predicate.ToExpression())
  80. .Select((billInvnow, warecell, warehouse) => new BillInvNowDto
  81. {
  82. Id = billInvnow.Id.ToString(),
  83. WarehouseId = billInvnow.WarehouseId.ToString(),
  84. WarehouseName = warehouse.Name,
  85. WarehouseTypeNum = warehouse.TypeNum,
  86. WarehouseCode = warehouse.Code,
  87. ContGrpId = billInvnow.ContGrpId.ToString(),
  88. ContGrpBarCode = billInvnow.ContGrpBarCode,
  89. ContGrpType = (int)billInvnow.ContGrpType,
  90. BoxBarCode = billInvnow.BoxBarCode,
  91. BomDocsNo = billInvnow.BomDocsNo,
  92. BomMatId = billInvnow.BomMatId.ToString(),
  93. BomMatCode = billInvnow.BomMatCode,
  94. BomMatName = billInvnow.BomMatName,
  95. BomSetId = billInvnow.BomSetId.ToString(),
  96. ExecStateCode = billInvnow.ExecStateCode,
  97. InvStateCode = billInvnow.InvStateCode,
  98. ExecDocsNo = billInvnow.ExecDocsNo,
  99. ExecDocsRowNo = billInvnow.ExecDocsRowNo,
  100. ExecDocsTypeCode = billInvnow.ExecDocsTypeCode,
  101. InvInOut = (int)billInvnow.InvInOut,
  102. ExecWho = billInvnow.ExecWho,
  103. ExecTime = billInvnow.ExecTime,
  104. PutRow = billInvnow.PutRow,
  105. PutCol = billInvnow.PutCol,
  106. PutLayer = billInvnow.PutLayer,
  107. InvBarCode = billInvnow.InvBarCode,
  108. InDocsNo = billInvnow.InDocsNo,
  109. InDocsRowNo = billInvnow.InDocsRowNo,
  110. SuppCode = billInvnow.SuppCode,
  111. SuppName = billInvnow.SuppName,
  112. CustCode = billInvnow.CustCode,
  113. CustName = billInvnow.CustName,
  114. MatId = billInvnow.MatId.ToString(),
  115. MatCode = billInvnow.MatCode,
  116. MatName = billInvnow.MatName,
  117. TolWQty = billInvnow.TolWQty,
  118. NetWQty = billInvnow.NetWQty,
  119. TareWQty = billInvnow.TareWQty,
  120. LengthQty = billInvnow.LengthQty,
  121. CaQty = billInvnow.CaQty,
  122. SolderQty = billInvnow.SolderQty,
  123. ContUsageQty = billInvnow.ContUsageQty,
  124. BatchNo = billInvnow.BatchNo,
  125. ProductTime = billInvnow.ProductTime,
  126. OneInTime = billInvnow.OneInTime,
  127. RodBarCode = billInvnow.RodBarCode,
  128. HWBarCode = billInvnow.HWBarCode,
  129. RFIDBarCode = billInvnow.RFIDBarCode,
  130. CLBarCode = billInvnow.CLBarCode,
  131. HWTypeCode = billInvnow.HWTypeCode,
  132. BoilerNo = billInvnow.BoilerNo,
  133. PackNo = billInvnow.PackNo,
  134. BrandNo = billInvnow.BrandNo,
  135. ExecStd = billInvnow.ExecStd,
  136. LicenceCode = billInvnow.LicenceCode,
  137. IsSurplus = billInvnow.IsSurplus,
  138. IsRework = billInvnow.IsRework,
  139. IsBlack = billInvnow.IsBlack,
  140. IsCore = billInvnow.IsCore,
  141. IsFast = billInvnow.IsFast,
  142. IsFail = billInvnow.IsFail,
  143. FailReason = billInvnow.FailReason,
  144. SilkTypeCode = billInvnow.SilkTypeCode,
  145. Grade = billInvnow.Grade,
  146. IsBack = billInvnow.IsBack,
  147. BackReason = billInvnow.BackReason,
  148. IsTorsChk = billInvnow.IsTorsChk,
  149. TorsChkQty = billInvnow.TorsChkQty,
  150. TorsChkTime = billInvnow.TorsChkTime,
  151. TorsChkValue = billInvnow.TorsChkValue,
  152. TorsChkMachCode = billInvnow.TorsChkMachCode,
  153. ProcessDocsCode = billInvnow.ProcessDocsCode,
  154. ProductMachCode = billInvnow.ProductMachCode,
  155. ProductLineNo = billInvnow.ProductLineNo,
  156. SetGrpCode = billInvnow.SetGrpCode,
  157. SideNum = billInvnow.SideNum,
  158. AddWho = billInvnow.AddWho,
  159. AddTime = billInvnow.AddTime,
  160. EditWho = billInvnow.EditWho,
  161. EditTime = billInvnow.EditTime,
  162. Size = billInvnow.Size,
  163. Memo = billInvnow.Memo,
  164. Tunnel = warecell.Tunnel,
  165. Code = warecell.Code,
  166. CellState = warecell.IsStop,
  167. }).MergeTable();
  168. return sugarQueryable;
  169. }
  170. public void ChangeSetGrp(LoginUserInfo loginUser, ChangeSetGrpModel entity)
  171. {
  172. if (string.IsNullOrWhiteSpace(entity.SetGrp))
  173. {
  174. throw new ArgumentException("跺型编码不能为空");
  175. }
  176. if (string.IsNullOrWhiteSpace(entity.NewSetGrp))
  177. {
  178. throw new ArgumentException("修改的跺型编码不能为空");
  179. }
  180. if (string.IsNullOrWhiteSpace(entity.WarehouseId))
  181. {
  182. throw new ArgumentException("仓库不能为空");
  183. }
  184. var predicate = Expressionable.Create<BillInvnow>();
  185. predicate.And(it => it.WarehouseId.ToString().ToUpper() == entity.WarehouseId.ToUpper());
  186. predicate.And(it => it.InvStateCode == InvState.InvEcecState_In.ToString());
  187. predicate.And(it => it.SetGrpCode == entity.SetGrp);
  188. var lists = _billInvnowrepository.Queryable().Where(predicate.ToExpression());
  189. if (lists == null || !lists.Any())
  190. {
  191. throw new ArgumentException("没有该跺型的数据。");
  192. }
  193. _billLogService.WriteLog(loginUser, entity, $"跺型由:{entity.SetGrp}改为:{entity.NewSetGrp} ", "WMS.BZServices.FJ.BaseInvService", "ChangeSetGrp", new Stopwatch(), ELogType.Work, null);
  194. _billInvnowrepository.UpdateModelColumns(p => new BillInvnow
  195. {
  196. SetGrpCode = entity.NewSetGrp
  197. }, predicate.ToExpression());
  198. }
  199. public void UpdateStockState(string Code, int Status, string userId)
  200. {
  201. var stock = _billInvnowrepository.GetFirst(p => p.ContGrpBarCode == Code);
  202. if (stock == null)
  203. {
  204. throw new ArgumentException("组盘信息不存在!");
  205. }
  206. var invstatus = ((InvState)Status).ToString();
  207. var InvStateCode = invstatus + "";
  208. var p = _billInvnowrepository.UpdateSetColumnsTrue(p => new BillInvnow()
  209. {
  210. InvStateCode = InvStateCode,
  211. EditTime = DateTime.Now
  212. }, p => p.ContGrpBarCode == stock.ContGrpBarCode);
  213. if (!p)
  214. {
  215. throw new ArgumentException(stock.ContGrpBarCode + "更新失败!");
  216. }
  217. var flow = stock.Adapt<BillInvflow>();
  218. flow.Id = IdFactory.NewId();
  219. flow.AddTime = DateTime.Now;
  220. flow.EditTime = DateTime.Now;
  221. flow.InvStateCode = invstatus;
  222. _billInvflowrepository.Insert(flow);
  223. }
  224. public void Deletes(string[] ids, string userId)
  225. {
  226. if (ids == null || ids.Length == 0)
  227. {
  228. throw BZSysExCore.ThrowFailException("库存Id不能为空!");
  229. }
  230. var list = _billInvnowrepository.Queryable().Where(o => ids.Contains(o.Id.ToString())).ToList();
  231. if (!list.Any())
  232. {
  233. throw new ArgumentException("没有选择库存数据!");
  234. }
  235. _billInvnowrepository.UseTranAction(() =>
  236. {
  237. foreach (var item in list)
  238. {
  239. _billInvnowrepository.Deleteable().Where(it => it.Id == item.Id).ExecuteCommand();
  240. }
  241. });
  242. }
  243. public List<EnumEntity> InvStateList()
  244. {
  245. return BZModels.Extensions.EnumToList<InvState>();
  246. }
  247. public List<EnumEntity> TaskStatusList()
  248. {
  249. return BZModels.Extensions.EnumToList<BZModels.TaskStatus>();
  250. }
  251. public List<EnumEntity> TaskTypeList()
  252. {
  253. return BZModels.Extensions.EnumToList<TaskType>();
  254. }
  255. public List<EnumEntity2> TaskBusTypeList()
  256. {
  257. return BZModels.Extensions.EnumToListDesc<TaskBusType>();
  258. }
  259. public List<EnumEntity> FackbeekTypeList()
  260. {
  261. return BZModels.Extensions.EnumToList<FackbeekType>();
  262. }
  263. public List<EnumEntity> ContGrpTypeList()
  264. {
  265. return BZModels.Extensions.EnumToList<ContGrpType>();
  266. }
  267. public List<EnumEntity> DocTypeList()
  268. {
  269. return BZModels.Extensions.EnumToList<DocType>();
  270. }
  271. public List<EnumEntity> DocStateList()
  272. {
  273. return BZModels.Extensions.EnumToList<DocState>();
  274. }
  275. public List<EnumEntity> LocationStateList()
  276. {
  277. return BZModels.Extensions.EnumToList<LocationState>();
  278. }
  279. public List<EnumEntity> AutoManualOutTypeList()
  280. {
  281. return BZModels.Extensions.EnumToList<AutoManualOutType>();
  282. }
  283. }
  284. }