ZhongTianFjService.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using AutoMapper;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Security.Claims;
  9. using System.Text;
  10. using WCS.FJ.Protocol.DataStructure;
  11. using Wms.Screen.DataService.Impl;
  12. using Wms.Screen.DataService.Interface;
  13. using Wms.Screen.Dto;
  14. using Wms.Screen.Dto.ZhongTian;
  15. using Wms.Screen.Dto.ZhongTian.Request;
  16. using Wms.Screen.Dto.ZhongTian.Response;
  17. using Wms.Screen.Service.IService;
  18. using Wms.Screen.Util.Extensions;
  19. namespace Wms.Screen.Service.Service
  20. {
  21. /// <summary>
  22. /// 分拣
  23. /// </summary>
  24. public class ZhongTianFjService : IZhongTianFjService
  25. {
  26. private IZhongTianFjDataService _zhongTianFjDataService;
  27. private IMapper _mapper;
  28. Dictionary<string, List<string>> _dicDevices;
  29. private readonly FreeRedis.RedisClient _freeRedisClient;
  30. static Dictionary<string, string> FjEquipsValues = new Dictionary<string, string>
  31. {
  32. { "SRM","堆垛机"}, { "RGV","RGV"}, { "Robot","机械手"}, { "Truss","桁架"},
  33. };
  34. public ZhongTianFjService(IZhongTianFjDataService zhongTianFjDataService, IMapper mapper, Dictionary<string, List<string>> dicDevices, FreeRedis.RedisClient freeRedisClient)
  35. {
  36. _zhongTianFjDataService = zhongTianFjDataService;
  37. _mapper = mapper;
  38. _dicDevices = dicDevices;
  39. _freeRedisClient = freeRedisClient;
  40. }
  41. public List<FJEquipDto> GetFjEquips(GetEquipsRequest reqEntity)
  42. {
  43. var real = new List<FJEquipDto>();
  44. var list = _zhongTianFjDataService.GetFjEquips(reqEntity);
  45. _dicDevices.TryGetValue(reqEntity.WarehouseCodeList[1], out var deviceslists);
  46. var status = _freeRedisClient.Get("Sorting:EquipmentStatus");
  47. if (!string.IsNullOrWhiteSpace(status) && status != "[]")
  48. {
  49. var dtolist = JsonConvert.DeserializeObject<List<BusinessDto4>>(status);
  50. foreach (var item in FjEquipsValues.Keys)
  51. {
  52. FJEquipDto fJEquipDto = new FJEquipDto();
  53. foreach (var device in deviceslists)
  54. {
  55. if (device.Contains(item))
  56. {
  57. fJEquipDto.Title = FjEquipsValues[item];
  58. var dto = dtolist?.FirstOrDefault(o => o.Code == device);
  59. fJEquipDto.Data.Add(new EquipDto()
  60. {
  61. Code = device,
  62. EquipState = dto != null && dto.Time.Date == DateTime.Now.Date ? EquipStatus( dto.Status) : "3",
  63. ResidueTask = list.Where(o => o.Device == device).Count()
  64. });
  65. }
  66. }
  67. real.Add(fJEquipDto);
  68. }
  69. }
  70. return real;
  71. }
  72. private string EquipStatus(string status)
  73. {
  74. if (status == "3")//报警
  75. {
  76. return "3";
  77. }
  78. else if(status == "4" || status == "5") //维护 手动
  79. {
  80. return "2";
  81. }
  82. else
  83. {
  84. return "1";
  85. }
  86. }
  87. public List<TaskInfoDto> GetFjTaskInfo(GetWcsTaskInfoRequest ReqEntity)
  88. {
  89. List<TaskInfoDto> taskInfoDtos = new List<TaskInfoDto>();
  90. taskInfoDtos = _zhongTianFjDataService.GetFjRunWcsTaskInfo(ReqEntity);
  91. var Len = _freeRedisClient.LLen("Packs");
  92. var dataPack = _freeRedisClient.LIndex<DeviceDataPack>("Packs", Len - 1);
  93. return taskInfoDtos;
  94. }
  95. public List<StackDto> GetFjStackInfo(GetWorkPlanBillListRequest reqEntity)
  96. {
  97. var list = _zhongTianFjDataService.GetFjStackInfo(reqEntity);
  98. return list;
  99. }
  100. public PageResult<ZtLocationUsageReportViewDto> GetFjLocationUsageViewList(string warehouse)
  101. {
  102. var result = new PageResult<ZtLocationUsageReportViewDto>() { ReturnValue = new List<ZtLocationUsageReportViewDto>() };
  103. var list = _zhongTianFjDataService.GetFjLocationUsageReportList(warehouse);
  104. result.ReturnValue = list.ToList();
  105. result.ItemGroupSum = new List<ItemGroup>() {
  106. new ItemGroup(){ UnitName="总货位",qty=list.Sum(s=>s.AllLocationTotal)},
  107. new ItemGroup(){ UnitName="有效货位",qty=list.Sum(s=>s.CanUseLocation)},
  108. new ItemGroup(){ UnitName="空余货位",qty=list.Sum(s=>s.SpareLocation)},
  109. new ItemGroup(){ UnitName="锁定货位",qty=list.Sum(s=>s.LockLocation)},
  110. new ItemGroup(){ UnitName="停用货位",qty=list.Sum(s=>s.StopLocation)},
  111. new ItemGroup(){ UnitName="有料货位",qty=list.Sum(s=>s.MaterilLocation)},
  112. new ItemGroup(){ UnitName="有容器货位",qty=list.Sum(s=>s.ContainLocation)}
  113. };
  114. return result;
  115. }
  116. public List<MantuoBarCodeRateDto> GetMantuoBarCodeRate(string warehouse)
  117. {
  118. return _zhongTianFjDataService.GetMantuoBarCodeRate(warehouse);
  119. }
  120. public List<BomSetGrpCurrentMaterialRateDto> GetBomSetGrpCurrentMaterialRateList(string warehouse)
  121. {
  122. return _zhongTianFjDataService.GetBomSetGrpCurrentMaterialRateList(warehouse);
  123. }
  124. public List<ItemVal> GetLocaitonList(string warehouse)
  125. {
  126. List<ItemVal> res = new List<ItemVal>();
  127. var list = _zhongTianFjDataService.GetLocationList(warehouse);
  128. res.Add(new ItemVal() { Name = "空", Value = list.Where(p => p.StateNum == 1).Any() ? list.Where(p => p.StateNum == 1).Count() : 0 });
  129. res.Add(new ItemVal() { Name = "满", Value = list.Where(p => p.StateNum == 2).Any() ? list.Where(p => p.StateNum == 2).Count() : 0 });
  130. res.Add(new ItemVal() { Name = "锁定", Value = list.Where(p => p.StateNum == 3 || p.StateNum == 4).Any() ? list.Where(p => p.StateNum == 3 || p.StateNum == 4).Count() : 0 });
  131. res.Add(new ItemVal() { Name = "禁用", Value = list.Where(p => p.IsStop == 1).Any() ? list.Where(p => p.IsStop == 1).Count() : 0 });
  132. return res;
  133. }
  134. public GetFullWeightDistRes GetInvSetGrpList()
  135. {
  136. GetFullWeightDistRes res = new GetFullWeightDistRes() { xData = new List<string>(), yData = new List<decimal>() };
  137. List<ItemVal> listtemp = new List<ItemVal>();
  138. var list = _zhongTianFjDataService.GetInvSetGrpList();
  139. foreach (var item in list)
  140. {
  141. res.xData.Add(item.SetGrpCode);
  142. res.yData.Add(item.Qty);
  143. }
  144. return res;
  145. }
  146. public GeFJHistoryTaskInfoRes GeHistoryTaskInfo(GeFJHistoryTaskInfoRequest request)
  147. {
  148. GeFJHistoryTaskInfoRes res = new GeFJHistoryTaskInfoRes();
  149. var lists = _zhongTianFjDataService.GeHistoryTaskInfo(request);
  150. string[] XAxis = new string[7]; //lists.OrderBy(o => o.CreateTime).Select(o => o.CreateTime.ToString("M-dd")).Distinct().ToArray();
  151. int[] Outints = new int[7];
  152. int[] EnterDepots = new int[7];
  153. int[] TransferDepots = new int[7];
  154. int[] SetPlate = new int[7];
  155. for (int i = 0; i < (request.EndTime - request.StartTime).TotalDays; i++)
  156. {
  157. var date = request.StartTime.AddDays(i);
  158. XAxis[i] = date.ToString("yyyy-MM-dd");
  159. Outints[i] = lists.Where(o => o.BusType == "车间叫料" && o.CreateTime.Date == date.Date).Sum(o => o.Count);
  160. EnterDepots[i] = lists.Where(o => o.BusType == "码垛入库" && o.CreateTime.Date == date.Date).Sum(o => o.Count);
  161. SetPlate[i] = lists.Where(o => o.Type == (int)TaskType.SetPlate && o.CreateTime.Date == date.Date).Sum(o => o.Count);
  162. }
  163. res.DateList.AddRange(XAxis);
  164. res.StockInList.AddRange(EnterDepots);
  165. res.StockOutList.AddRange(Outints);
  166. res.SetPlateList.AddRange(SetPlate);
  167. return res;
  168. }
  169. }
  170. }