ZhongTianCpController.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using AutoMapper;
  2. using Bozhon.Wms.Util.Cache;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Newtonsoft.Json;
  5. using System.Collections.Generic;
  6. using System;
  7. using Wms.Screen.Dto.ZhongTian.Request;
  8. using Wms.Screen.Dto.ZhongTian.Response;
  9. using Wms.Screen.Dto.ZhongTian;
  10. using Wms.Screen.Service.IService;
  11. using System.Linq;
  12. using Wms.Screen.Dto;
  13. using Wms.Screen.Service.Service;
  14. namespace Wms.Screen.Api.Controllers
  15. {
  16. /// <summary>
  17. /// 中天成品看板
  18. /// </summary>
  19. [Route("api/[controller]/[action]")]
  20. [ApiController]
  21. public class ZhongTianCpController : ControllerBase
  22. {
  23. private IZhongTianCpService _zhongTianCpService;
  24. private IMapper _mapper;
  25. private IRedisClient _redisClient;
  26. public ZhongTianCpController(IZhongTianCpService zhongTianCpService, IMapper mapper, IRedisClient redisClient)
  27. {
  28. _zhongTianCpService = zhongTianCpService;
  29. _mapper = mapper;
  30. _redisClient = redisClient;
  31. }
  32. #region 查询配置文件信息
  33. /// <summary>
  34. /// 查询配置的车间设备信息
  35. /// </summary>
  36. /// <returns></returns>
  37. [HttpPost]
  38. public List<WorkShopWithEquipment> GetWorkShopWithEquipment()
  39. {
  40. List<WorkShopWithEquipment> workShopWithEquipmentList = new List<WorkShopWithEquipment>();
  41. workShopWithEquipmentList.AddRange(InOutEquipment.WorkShopWithEquipment);
  42. workShopWithEquipmentList.AddRange(InOutEquipment.YTWorkShopWithEquipment);
  43. return workShopWithEquipmentList;
  44. }
  45. #endregion
  46. #region 成品看板
  47. /// <summary>
  48. /// 成品看板
  49. /// </summary>
  50. /// <param name="strRequest"></param>
  51. /// <param name="workshop"></param>
  52. /// <param name="boardCode"></param>
  53. /// <returns></returns>
  54. [HttpPost]
  55. public List<dynamic> GetCpInfo(StrRequestDto request)
  56. {
  57. if (string.IsNullOrEmpty(request.StrRequest))
  58. {
  59. return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
  60. }
  61. var result = new List<dynamic>();
  62. if (request.StrRequest.Split(',').Contains("1")) //查询设备状态
  63. {
  64. result.Add(_zhongTianCpService.GetCpEquips(new GetEquipsRequest()
  65. {
  66. WarehouseCodeList = new List<string>() {
  67. Const.Cphouse_putong}
  68. }));
  69. }
  70. else
  71. {
  72. result.Add("");
  73. }
  74. if (request.StrRequest.Split(',').Contains("2")) //库龄统计占比
  75. {
  76. //领料 涂布领料汇总,不区分车间
  77. result.Add(_zhongTianCpService.GetCpBillList(new GetWorkPlanBillListRequest()
  78. {
  79. WarehouseDocumentType = Const.WorkPlanBill,
  80. WarehouseCodeList = new List<string>() { Const.Cphouse_putong },
  81. WarehouseDocumentStateList = new List<string>() { Const.WarehouseDocumentState_ExecuteCode, Const.WarehouseDocumentState_CreateCode }
  82. }));
  83. }
  84. else
  85. {
  86. result.Add("");
  87. }
  88. if (request.StrRequest.Split(',').Contains("3")) //任务信息
  89. {
  90. List<string> equipNoList = new List<string>();
  91. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach(
  92. n => equipNoList.AddRange(n.Equipments));
  93. //任务信息:出库和入库任务,目标地址或开始地址是当前车间的设备号
  94. //设备号数据,做成配置
  95. var taskInfos = _zhongTianCpService.GetCpTaskInfo(new GetWcsTaskInfoRequest()
  96. {
  97. EquipList = equipNoList,
  98. TaskTypelist = new List<TaskType> { TaskType.OutDepot, TaskType.EnterDepot }
  99. });
  100. result.Add(taskInfos);
  101. }
  102. else
  103. {
  104. result.Add("");
  105. }
  106. if (request.StrRequest.Split(',').Contains("4")) //报警信息
  107. {
  108. List<string> equipNoList = new List<string>();
  109. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  110. n => equipNoList.AddRange(n.Equipments));
  111. //获取报警信息
  112. //设备号数据,做成配置
  113. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
  114. {
  115. EquCodeList = equipNoList.Distinct().ToList()
  116. }));
  117. }
  118. else
  119. {
  120. result.Add("");
  121. }
  122. return result;
  123. }
  124. #endregion
  125. #region 货位利用率
  126. /// <summary>
  127. /// 成品货位利用率
  128. /// </summary>
  129. /// <param name="strRequest"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. public PageResult<ZtLocationUsageReportViewDto> GetCpLocationStateList()
  133. {
  134. return _zhongTianCpService.GetCpLocationUsageViewList();
  135. }
  136. #endregion
  137. #region 异常信息汇总
  138. /// <summary>
  139. /// 成品异常信息汇总
  140. /// </summary>
  141. /// <returns></returns>
  142. [HttpPost]
  143. public List<dynamic> GetTotalErrorInfo()
  144. {
  145. var result = new List<dynamic>();
  146. List<string> equipNoList = new List<string>();
  147. InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "cp").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  148. n => equipNoList.AddRange(n.Equipments));
  149. //报警信息
  150. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest()
  151. {
  152. EquCodeList = equipNoList.Distinct().ToList()
  153. }));
  154. return result;
  155. }
  156. #endregion
  157. #region 私有方法:将报表方法提取出来
  158. /// <summary>
  159. /// 报警信息
  160. /// </summary>
  161. /// <param name="reqEntity"></param>
  162. /// <returns></returns>
  163. private List<StockInAndOutRecordDto> GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity)
  164. {
  165. var list = new List<StockInAndOutRecordDto>();
  166. //读取redis缓存(wcs实时传递设备信息)
  167. //var strMsgList = _redisClient.Get(Const.equi_list);
  168. //获取单据错误信息
  169. //List<SqlSugar.Model.BillErrorInfo> ErrorList = new List<SqlSugar.Model.BillErrorInfo>();
  170. //try
  171. //{
  172. // ErrorList = _yongGuanDataService.GetBillErrorInfoList(reqEntity.EquipNo);
  173. // if (ErrorList.Count() > 0)
  174. // {
  175. // list.AddRange(ErrorList.Select(s => new StockInAndOutRecordDto { dateTime = s.CreatedTime.ToString("HH:mm:ss"), Message = s.Msg }).ToList());
  176. // }
  177. // //if (ErrorList.Count() > 0)
  178. // //{
  179. // // //显示近一天的数据
  180. // // //DateTime end = DateTime.Now.AddDays(1);
  181. // // ErrorList = ErrorList.Where(x => x.CreatedTime.Date == DateTime.Now.Date).ToList();
  182. // //}
  183. //}
  184. //catch (Exception ex)
  185. //{
  186. // list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"数据库报警信息读取失败:{ex.Message}" });
  187. //}
  188. try
  189. {
  190. foreach (var equipno in reqEntity.EquCodeList)
  191. {
  192. var msg1 = _redisClient.Get("equone" + equipno);
  193. var msg2 = _redisClient.Get("equsecond" + equipno);
  194. if (!string.IsNullOrEmpty(msg1))
  195. {
  196. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
  197. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG))
  198. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  199. }
  200. if (!string.IsNullOrEmpty(msg2))
  201. {
  202. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg2);
  203. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date)
  204. {
  205. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  206. }
  207. }
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
  213. }
  214. if (list.Any())
  215. {
  216. list = list.OrderByDescending(p => p.dateTime).ToList();
  217. }
  218. return list;
  219. }
  220. #endregion
  221. }
  222. }