ZhongTianPtDataService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using wms.sqlsugar.model.pt;
  7. using Wms.Screen.DataService.Interface;
  8. using Wms.Screen.Dto.ZhongTian;
  9. using Wms.Screen.Dto.ZhongTian.Request;
  10. using Wms.Screen.Dto.ZhongTian.Response;
  11. using Wms.Screen.SqlSugar.ZhongTian;
  12. using Wms.Screen.SqlSugar.ZhongTian.PT;
  13. using BillInvnow = wms.sqlsugar.model.pt.BillInvnow;
  14. using WCS_TaskOld = wms.sqlsugar.model.pt.WCS_TaskOld;
  15. namespace Wms.Screen.DataService.Impl
  16. {
  17. public class ZhongTianPtDataService : IZhongTianPtDataService
  18. {
  19. private SqlSugarClient _db;
  20. public ZhongTianPtDataService(SqlSugarClient db)
  21. {
  22. _db = db;
  23. }
  24. public List<WCS_TaskOld> GetPtEquips(GetEquipsRequest reqEntity)
  25. {
  26. var list = _db.Queryable<WCS_TaskOld>().Where(p => p.Status != (int)TaskStatus.Finish && p.Status != (int)TaskStatus.Cancel &&
  27. (p.Type == TaskType.OutDepot || p.Type == TaskType.EnterDepot) && !string.IsNullOrEmpty(p.Tunnel))
  28. .SplitTable(tabs => tabs.Take(2))
  29. .ToList();
  30. return list;
  31. }
  32. public List<TaskInfoDto> GetPtRunWcsTaskInfo(GetWcsTaskInfoRequest request)
  33. {
  34. var list = _db.Queryable<WCS_TaskOld>().SplitTable(p => p.Take(2))
  35. .LeftJoin<BillInvnow>((taskold, now) => taskold.BarCode == now.ContGrpBarCode)
  36. .Where(taskold => taskold.Status < (int)TaskStatus.Finish)
  37. .WhereIF(request.TaskType > 0, (taskold, now) => taskold.Type == request.TaskType)
  38. .WhereIF(request.TaskTypelist != null && request.TaskTypelist.Any(), (taskold, now) => request.TaskTypelist.Contains(taskold.Type))
  39. .OrderBy((taskold, now) => taskold.AddTime, OrderByType.Desc)
  40. .Select((taskold, now) => new TaskInfoDto
  41. {
  42. TaskCode = taskold.ID.ToString(),
  43. TaskState = taskold.Status == (int)TaskStatus.NewBuild ? "新建" : "执行中",
  44. TaskType = taskold.Type == TaskType.EnterDepot ? "入库" : taskold.Type == TaskType.OutDepot ? "出库" : "移动",
  45. HWBarCode = taskold.BarCode,
  46. HWSpec = now.HWTypeCode,
  47. BeginPosition = taskold.AddrFrom,
  48. EndPosition = taskold.AddrTo,
  49. CreatedTime = taskold.AddTime,
  50. Tunnel = taskold.Tunnel,
  51. AddTime = taskold.AddTime.ToString("HH:mm:ss")
  52. }).Distinct().ToList();
  53. return list;
  54. }
  55. public List<ZTBillDto> GetPtBillList(GetWorkPlanBillListRequest reqEntity)
  56. {
  57. var list = _db.Queryable<BillDocsinfo, BillInvnow, BaseMatinfo, BaseWarehouse>
  58. ((doc, barcode, material, house) => new object[] {
  59. JoinType.Left, doc.DocsNo == barcode.InDocsNo,
  60. JoinType.Left, barcode.MatId == material.Id,
  61. JoinType.Left, doc.WarehouseId == house.Id
  62. })
  63. .Where((doc, barcode, material, house) => doc.IsStop == 1)
  64. .WhereIF(!string.IsNullOrEmpty(reqEntity.WarehouseDocumentType), (doc, barcode, material, house) => doc.TypeNum == int.Parse(reqEntity.WarehouseDocumentType))
  65. .WhereIF(reqEntity.WarehouseDocumentTypeList != null && reqEntity.WarehouseDocumentTypeList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseDocumentTypeList.Contains(doc.TypeNum.ToString()))
  66. .WhereIF(reqEntity.WarehouseDocumentStateList != null && reqEntity.WarehouseDocumentStateList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseDocumentStateList.Contains(doc.StateNum.ToString()))
  67. .WhereIF(reqEntity.WarehouseCodeList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseCodeList.Contains(house.Code))
  68. .Select((doc, barcode, material, house) => new ZTBillDto
  69. {
  70. OutDocumentCode = doc.DocsNo,
  71. MaterialName = material.Name,
  72. MaterialCode = material.Code,
  73. StockQuantity = 0,
  74. TypeCode = doc.TypeNum.ToString(),
  75. StateCode = doc.StateNum == DocState.DocState_Create.GetHashCode() ? "新建" : "执行中"
  76. }).Distinct().ToList();
  77. return list;
  78. }
  79. public List<BaseWarecell> GetLocationList()
  80. {
  81. return _db.Queryable<BaseWarecell>().ToList();
  82. }
  83. public List<BillInvnow> GetBillInvnowList()
  84. {
  85. return _db.Queryable<BillInvnow>().ToList();
  86. }
  87. public List<WCS_TaskOld> GeHistoryTaskInfo(GeHistoryTaskInfoRequest request)
  88. {
  89. return _db.Queryable<WCS_TaskOld>().SplitTable(tabs => tabs.Take(3)).Where(p => p.Status == 99 && request.BusTypeList.Contains(p.BusType) && request.StartTime <= p.EndTime && p.EndTime <= request.EndTime).ToList();
  90. }
  91. public List<ZtLocationUsageReportViewDto> GetPtLocationUsageReportList()
  92. {
  93. int _sort = 1;
  94. var list = _db.Queryable<BaseWarehouse, BaseWarecell, BillInvnow>((wareHouse, location, groupStock) => new object[]
  95. {
  96. JoinType.Left,wareHouse.Id == location.WarehouseId,
  97. JoinType.Left,location.ContGrpId == groupStock.ContGrpId && groupStock.InvStateCode == InvEcecState.InvEcecState_In.ToString()
  98. })
  99. .Where((wareHouse, location, groupStock) => location.TypeNum == LocationType.LocationType_StorageLocation.GetHashCode())
  100. .GroupBy((wareHouse, location, groupStock) => new
  101. {
  102. location.IsStop,
  103. location.Tunnel,
  104. location.StateNum,
  105. wareHouse.Id,
  106. wareHouse.Name,
  107. location.ContGrpId,
  108. location.Size
  109. }).Select((wareHouse, location, groupStock) => new
  110. {
  111. Status = location.IsStop,
  112. Tunnel = location.Tunnel,
  113. LocationLock = location.StateNum,
  114. WareHouseId = wareHouse.Id,
  115. Name = wareHouse.Name,
  116. GroupStockType = location.ContGrpId,
  117. Size = location.Size,
  118. Total = SqlFunc.AggregateDistinctCount(location.Id)
  119. }).ToList();
  120. //基表:巷道和仓库名称为维度查找总货位
  121. var baseTemp = list.GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  122. //关联表:巷道和仓库名称为维度,查找可用货位:未停用.已锁定也算有效货位
  123. var useLocation = list.Where(s => s.Status == 1).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList(); //&& s.LocationLock == DictionaryConst.LocationLockNoneCode
  124. //关联表:巷道和仓库名称为维度,查找锁定货位
  125. var lockLocation = list.Where(s => s.Status == 1 && s.LocationLock != LocationLock.LocationLock_None.GetHashCode()).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  126. //关联表:巷道和仓库名称为维度,查找停用货位
  127. var stopLocation = list.Where(s => s.Status == 0).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  128. //关联表:巷道和仓库名称为维度,查找物料货位
  129. var materialLocation = list.Where(s => s.Status == 1 && s.GroupStockType == 2 && s.LocationLock == LocationLock.LocationLock_None.GetHashCode()).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  130. //关联表:巷道和仓库名称为维度,查找容器货位
  131. var containerLocation = list.Where(s => s.Status == 1 && s.GroupStockType == 1 && s.LocationLock == LocationLock.LocationLock_None.GetHashCode()).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  132. //关联表:巷道和仓库名称为维度,查找小货位数量
  133. var littleSizeLocation = list.Where(s => s.Status == 1 && s.Size == 1 && s.LocationLock == LocationLock.LocationLock_None.GetHashCode() && s.GroupStockType != 2 && s.GroupStockType != 1).GroupBy(s => new { s.Tunnel, s.WareHouseId, s.Name }).Select(m => new { Name = m.Key.Name, Tunnel = m.Key.Tunnel, Total = m.Sum(n => n.Total) }).ToList();
  134. var locationUsageReportViewDtos = from basetemp in baseTemp
  135. join uselocation in useLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = uselocation.Tunnel, Name = uselocation.Name } into useinfo
  136. join locklocation in lockLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = locklocation.Tunnel, Name = locklocation.Name } into lockinfo
  137. join stoplocation in stopLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = stoplocation.Tunnel, Name = stoplocation.Name } into stopinfo
  138. join materiallocation in materialLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = materiallocation.Tunnel, Name = materiallocation.Name } into materialinfo
  139. join containerlocation in containerLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = containerlocation.Tunnel, Name = containerlocation.Name } into containerinfo
  140. join littlesizelocation in littleSizeLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = littlesizelocation.Tunnel, Name = littlesizelocation.Name } into littlesizeinfo
  141. orderby basetemp.Name + basetemp.Tunnel
  142. select new ZtLocationUsageReportViewDto()
  143. {
  144. Sort = _sort++,
  145. Tunnel = basetemp.Tunnel.ToString(),
  146. WarehouseName = basetemp.Name,
  147. AllLocationTotal = basetemp.Total,
  148. CanUseLocation = useinfo.FirstOrDefault() == null ? 0 : useinfo.First().Total,
  149. LockLocation = lockinfo.FirstOrDefault() == null ? 0 : lockinfo.First().Total,
  150. StopLocation = stopinfo.FirstOrDefault() == null ? 0 : stopinfo.First().Total,
  151. MaterilLocation = materialinfo.FirstOrDefault() == null ? 0 : materialinfo.First().Total,
  152. ContainLocation = containerinfo.FirstOrDefault() == null ? 0 : containerinfo.First().Total,
  153. LittleSizeLocation = littlesizeinfo.FirstOrDefault() == null ? 0 : littlesizeinfo.First().Total,
  154. InStates = "启用",
  155. OutStates = "启用"
  156. };
  157. return locationUsageReportViewDtos.OrderBy(p => p.WarehouseName).ToList();
  158. }
  159. public List<BoilerNoMatCodeModel> GetBoilerNoMatCodeQtyList()
  160. {
  161. var lists= _db.Queryable<BillInvnow>().Where(o => o.InvStateCode == "InvEcecState_In")
  162. .Where(it => SqlFunc.Subqueryable<SqlSugar.ZhongTian.PT.SysConfig>().Where(s => s.default5 == it.BoilerNo && s.default1 == "ProductPinKu").Any())
  163. .GroupBy(x => new { x.BoilerNo, x.MatCode })
  164. .Select(x => new BoilerNoMatCodeModel
  165. {
  166. BoilerNo = x.BoilerNo,
  167. MatCode = x.MatCode,
  168. Qty = SqlFunc.AggregateCount(x.MatCode)
  169. }).OrderBy(x=>x.BoilerNo).OrderBy(x=>x.MatCode).ToList();
  170. return lists;
  171. }
  172. }
  173. }