ZhongTianHjDataService.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using Dm;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Wms.Screen.DataService.Interface;
  8. using Wms.Screen.Dto;
  9. using Wms.Screen.Dto.ZhongTian;
  10. using Wms.Screen.Dto.ZhongTian.Request;
  11. using Wms.Screen.Dto.ZhongTian.Response;
  12. using Wms.Screen.SqlSugar.ZhongTian;
  13. using Wms.Screen.Util.Extensions;
  14. using static Dm.net.buffer.ByteArrayBuffer;
  15. using BillInvnow = wms.sqlsugar.model.hj.BillInvnow;
  16. namespace Wms.Screen.DataService.Impl
  17. {
  18. public class ZhongTianHjDataService : IZhongTianHjDataService
  19. {
  20. private SqlSugarClient _db;
  21. public ZhongTianHjDataService(SqlSugarClient db)
  22. {
  23. _db = db;
  24. }
  25. public List<WCS_TaskOld> GetHjEquips(GetEquipsRequest reqEntity)
  26. {
  27. var list = _db.Queryable<WCS_TaskOld>().Where(p => p.Status != TaskStatus.Finish && p.Status != TaskStatus.Cancel &&
  28. (p.Type == TaskType.OutDepot || p.Type == TaskType.EnterDepot || p.Type == TaskType.EmptyInit) && !string.IsNullOrEmpty(p.Tunnel))
  29. .SplitTable(tabs => tabs.Take(1))
  30. .ToList();
  31. return list;
  32. }
  33. public List<TaskInfoDto> GetHjRunWcsTaskInfo(GetWcsTaskInfoRequest reqEntity)
  34. {
  35. //var list = _db.Queryable<WCS_TaskInfo, BillInvnow>((wcstask, code) => new object[] {
  36. // JoinType.Left, wcstask.BarCode == code.ContGrpBarCode
  37. // })
  38. // .Where(wcstask => wcstask.Status != TaskStatus.Finish && wcstask.Status != TaskStatus.Cancel)
  39. // //.WhereIF(reqEntity.EquipList != null && reqEntity.EquipList.Any(), (wcstask, code) => reqEntity.EquipList.Contains(wcstask.AddrFrom) || reqEntity.EquipList.Contains(wcstask.AddrTo))
  40. // .WhereIF(reqEntity.TaskType > 0, (wcstask, code) => wcstask.Type == reqEntity.TaskType)
  41. // .WhereIF(reqEntity.TaskTypelist != null && reqEntity.TaskTypelist.Any(), (wcstask, code) => reqEntity.TaskTypelist.Contains(wcstask.Type))
  42. // .OrderBy((wcstask, code) => wcstask.AddTime, OrderByType.Desc)
  43. // .Select((wcstask, code) => new TaskInfoDto
  44. // {
  45. // TaskCode = wcstask.ID.ToString(),
  46. // TaskState = wcstask.Status == TaskStatus.NewBuild ? "新建" : wcstask.Status == TaskStatus.WaitingToExecute ? "待执行" : wcstask.Status == TaskStatus.AGVExecution ? "AGV执行中" : wcstask.Status == TaskStatus.StackerExecution ? "堆垛机执行" : wcstask.Status == TaskStatus.ConveyorExecution ? "输送机执行中" : wcstask.Status == TaskStatus.StackerCompleted ? "堆垛机完成" : "状态类型错误",
  47. // TaskType = wcstask.Type == TaskType.EnterDepot ? "入库" : wcstask.Type == TaskType.OutDepot ? "出库" : wcstask.Type == TaskType.EmptyInit ? "空轮初始化入库" : "移动",
  48. // HWBarCode = wcstask.BarCode,
  49. // HWSpec = code.HWTypeCode,
  50. // BeginPosition = wcstask.AddrFrom,
  51. // EndPosition = wcstask.AddrTo,
  52. // CreatedTime = wcstask.AddTime,
  53. // Tunnel = wcstask.Tunnel,
  54. // AddTime = wcstask.AddTime.ToString("HH:mm:ss")
  55. // }).Distinct().ToList();
  56. var list = _db.Queryable<WCS_TaskOld>().SplitTable(p => p.Take(2))
  57. .LeftJoin<BillInvnow>((taskold, now) => taskold.BarCode == now.ContGrpBarCode)
  58. .Where(taskold => taskold.Status < TaskStatus.Finish)
  59. .WhereIF(reqEntity.TaskType > 0, (taskold, now) => taskold.Type == reqEntity.TaskType)
  60. .WhereIF(reqEntity.TaskTypelist != null && reqEntity.TaskTypelist.Any(), (taskold, now) => reqEntity.TaskTypelist.Contains(taskold.Type))
  61. .OrderBy((taskold, now) => taskold.AddTime, OrderByType.Desc)
  62. .Select((taskold, now) => new TaskInfoDto
  63. {
  64. TaskCode = taskold.ID.ToString(),
  65. TaskState = taskold.Status == TaskStatus.NewBuild ? "新建" : "执行中",
  66. TaskType = taskold.Type == TaskType.EnterDepot ? "入库" : taskold.Type == TaskType.OutDepot ? "出库" : taskold.Type == TaskType.EmptyInit ? "空轮初始化入库" : "移动",
  67. HWBarCode = taskold.BarCode,
  68. HWSpec = now.HWTypeCode,
  69. BeginPosition = taskold.AddrFrom,
  70. EndPosition = taskold.AddrTo,
  71. CreatedTime = taskold.AddTime,
  72. Tunnel = taskold.Tunnel,
  73. AddTime = taskold.AddTime.ToString("HH:mm:ss")
  74. }).Distinct().ToList();
  75. return list;
  76. }
  77. public List<ZTBillDto> GetHjBillList(GetWorkPlanBillListRequest reqEntity)
  78. {
  79. var list = _db.Queryable<BillDocsinfo, BillInvnow, BaseMatinfo, BaseWarehouse>
  80. ((doc, barcode, material, house) => new object[] {
  81. JoinType.Left, doc.DocsNo == barcode.InDocsNo,
  82. JoinType.Left, barcode.MatId == material.Id,
  83. JoinType.Left, doc.WarehouseId == house.Id
  84. })
  85. .Where((doc, barcode, material, house) => doc.IsStop == 0)
  86. //.WhereIF(!string.IsNullOrEmpty(reqEntity.WarehouseDocumentType), (doc, barcode, material, house) => doc.TypeNum == int.Parse(reqEntity.WarehouseDocumentType))
  87. //.WhereIF(reqEntity.WarehouseDocumentTypeList != null && reqEntity.WarehouseDocumentTypeList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseDocumentTypeList.Contains(doc.TypeNum.ToString()))
  88. .WhereIF(reqEntity.WarehouseDocumentStateList != null && reqEntity.WarehouseDocumentStateList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseDocumentStateList.Contains(doc.StateNum.ToString()))
  89. //.WhereIF(reqEntity.WarehouseCodeList.Any(), (doc, barcode, material, house) => reqEntity.WarehouseCodeList.Contains(house.Code))
  90. .Select((doc, barcode, material, house) => new ZTBillDto
  91. {
  92. OutDocumentCode = doc.DocsNo,
  93. MaterialName = material.Name,
  94. MaterialCode = material.Code,
  95. StockQuantity = 0,
  96. TypeCode = doc.TypeNum.ToString(),
  97. StateCode = doc.StateNum == DocState.DocState_Create.GetHashCode() ? "新建" : "执行中"
  98. }).Distinct().ToList();
  99. return list;
  100. }
  101. //public List<BaseWareLocation> GetLocationList(GetLocationListRequest reqEntity)
  102. //{
  103. // var list = _db.Queryable<BaseWareLocation, BaseWareZone, BaseWarehouse>
  104. // ((location, zone, house) => new object[] {
  105. // JoinType.Inner,location.ZoneId == zone.Id,
  106. // JoinType.Inner,zone.WareId == house.Id
  107. // })
  108. // .Where((location, zone, house) => location.LocationType == reqEntity.LocationType)
  109. // .WhereIF(!string.IsNullOrEmpty(reqEntity.WareshouseCode), (location, zone, house) => house.Code == reqEntity.WareshouseCode)
  110. // .Select((location, zone, house) => location).ToList();
  111. // return list;
  112. //}
  113. public List<SysConfig> GetSysConfig(string code, string configType)
  114. {
  115. return _db.Queryable<SysConfig>().WhereIF(!string.IsNullOrEmpty(code), s => s.Code.Contains(code))
  116. .WhereIF(!string.IsNullOrEmpty(configType), s => s.SType.Contains(configType)).ToList();
  117. }
  118. //public int GetEmtpyLocationCountByTunnel(List<string> tunnels, int size)
  119. //{
  120. // return _db.Queryable<BaseWareLocation>()
  121. // .Where((p) => p.LocationLock == LocationLock.LocationLock_None.GetHashCode() &&
  122. // p.LocationState == LocationState.LocationState_Empty.GetHashCode() &&
  123. // p.LocationType == LocationType.LocationType_StorageLocation.GetHashCode() &&
  124. // p.Size >= size
  125. // && tunnels.Contains(p.Tunnel.ToString()))
  126. // .Count();
  127. //}
  128. public int GetRuningInTaskCountByTunnel(int tunnel, string warehousecode, int size)
  129. {
  130. var listCount = _db.Queryable<WCS_TaskInfo>().Where(p => p.Type == TaskType.EnterDepot
  131. && p.Tunnel == tunnel.ToString()
  132. && p.Status != TaskStatus.Finish
  133. && p.Status != TaskStatus.Cancel
  134. && p.WarehouseCode == warehousecode
  135. ).Count();
  136. return listCount;
  137. }
  138. public bool IsHjHouse()
  139. {
  140. return _db.Queryable<BaseWarehouse>().Where(p => p.Code == Const.Hjhouse_putong).Any();
  141. }
  142. public List<BaseWarecell> GetLocationList()
  143. {
  144. return _db.Queryable<BaseWarecell>().ToList();
  145. }
  146. public List<BillInvnow> GetBillInvnowList()
  147. {
  148. return _db.Queryable<BillInvnow>().ToList();
  149. }
  150. public List<TunelCount> GetTunelCountList()
  151. {
  152. return _db.Queryable<BillInvnow, BaseWarecell>((billInvnow, warecell) => new object[] {
  153. JoinType.Left,billInvnow.ContGrpId == warecell.ContGrpId && billInvnow.WarehouseId ==warecell.WarehouseId ,
  154. })
  155. .GroupBy((billInvnow, warecell) => new { billInvnow.ContGrpType, warecell.Tunnel })
  156. .Select((billInvnow, warecell) => new TunelCount
  157. {
  158. ContGrpType=billInvnow.ContGrpType,
  159. Tunnel= warecell.Tunnel,
  160. Qty= SqlFunc.AggregateCount(billInvnow.ContGrpType)
  161. })
  162. .ToList();
  163. }
  164. public List<WCS_TaskOld> GeHistoryTaskInfo(GeHistoryTaskInfoRequest request)
  165. {
  166. return _db.Queryable<WCS_TaskOld>().SplitTable(tabs => tabs.Take(3)).Where(p => request.BusTypeList.Contains(p.BusType) && request.StartTime <= p.AddTime && p.EditTime <= request.EndTime).ToList();
  167. }
  168. public List<ZtLocationUsageReportViewDto> GetHjLocationUsageReportList()
  169. {
  170. int _sort = 1;
  171. var list = _db.Queryable<BaseWarehouse, BaseWarecell, BillInvnow>((wareHouse, location, groupStock) => new object[]
  172. {
  173. JoinType.Left,wareHouse.Id == location.WarehouseId,
  174. JoinType.Left,location.ContGrpId == groupStock.ContGrpId && groupStock.InvStateCode == InvEcecState.InvEcecState_In.ToString()
  175. })
  176. .Where((wareHouse, location, groupStock) => location.TypeNum == LocationType.LocationType_StorageLocation.GetHashCode())
  177. .GroupBy((wareHouse, location, groupStock) => new
  178. {
  179. location.IsStop,
  180. location.Tunnel,
  181. location.StateNum,
  182. wareHouse.Id,
  183. wareHouse.Name,
  184. location.ContGrpId,
  185. location.Size
  186. }).Select((wareHouse, location, groupStock) => new
  187. {
  188. Status = location.IsStop,
  189. Tunnel = location.Tunnel,
  190. LocationLock = location.StateNum,
  191. WareHouseId = wareHouse.Id,
  192. Name = wareHouse.Name,
  193. GroupStockType = location.ContGrpId,
  194. Size = location.Size,
  195. Total = SqlFunc.AggregateDistinctCount(location.Id)
  196. }).ToList();
  197. //基表:巷道和仓库名称为维度查找总货位
  198. 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();
  199. //关联表:巷道和仓库名称为维度,查找可用货位:未停用.已锁定也算有效货位
  200. 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
  201. //关联表:巷道和仓库名称为维度,查找锁定货位
  202. 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();
  203. //关联表:巷道和仓库名称为维度,查找停用货位
  204. 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();
  205. //关联表:巷道和仓库名称为维度,查找物料货位
  206. 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();
  207. //关联表:巷道和仓库名称为维度,查找容器货位
  208. 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();
  209. //关联表:巷道和仓库名称为维度,查找小货位数量
  210. 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();
  211. var locationUsageReportViewDtos = from basetemp in baseTemp
  212. join uselocation in useLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = uselocation.Tunnel, Name = uselocation.Name } into useinfo
  213. join locklocation in lockLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = locklocation.Tunnel, Name = locklocation.Name } into lockinfo
  214. join stoplocation in stopLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = stoplocation.Tunnel, Name = stoplocation.Name } into stopinfo
  215. join materiallocation in materialLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = materiallocation.Tunnel, Name = materiallocation.Name } into materialinfo
  216. join containerlocation in containerLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = containerlocation.Tunnel, Name = containerlocation.Name } into containerinfo
  217. join littlesizelocation in littleSizeLocation.DefaultIfEmpty() on new { Tunnel = basetemp.Tunnel, Name = basetemp.Name } equals new { Tunnel = littlesizelocation.Tunnel, Name = littlesizelocation.Name } into littlesizeinfo
  218. orderby basetemp.Name + basetemp.Tunnel
  219. select new ZtLocationUsageReportViewDto()
  220. {
  221. Sort = _sort++,
  222. Tunnel = basetemp.Tunnel.ToString(),
  223. WarehouseName = basetemp.Name,
  224. AllLocationTotal = basetemp.Total,
  225. CanUseLocation = useinfo.FirstOrDefault() == null ? 0 : useinfo.First().Total,
  226. LockLocation = lockinfo.FirstOrDefault() == null ? 0 : lockinfo.First().Total,
  227. StopLocation = stopinfo.FirstOrDefault() == null ? 0 : stopinfo.First().Total,
  228. MaterilLocation = materialinfo.FirstOrDefault() == null ? 0 : materialinfo.First().Total,
  229. ContainLocation = containerinfo.FirstOrDefault() == null ? 0 : containerinfo.First().Total,
  230. LittleSizeLocation = littlesizeinfo.FirstOrDefault() == null ? 0 : littlesizeinfo.First().Total,
  231. InStates = "启用",
  232. OutStates = "启用"
  233. };
  234. return locationUsageReportViewDtos.OrderBy(p => p.WarehouseName).ToList();
  235. }
  236. }
  237. }