ZhongTianSxController.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. using System.Security.Cryptography.X509Certificates;
  15. namespace Wms.Screen.Api.Controllers
  16. {
  17. /// <summary>
  18. /// 中天时效看板
  19. /// </summary>
  20. [Route("api/[controller]/[action]")]
  21. [ApiController]
  22. public class ZhongTianSxController : ControllerBase
  23. {
  24. private IZhongTianSxService _zhongTianSxService;
  25. private IMapper _mapper;
  26. private IRedisClient _redisClient;
  27. public ZhongTianSxController(IZhongTianSxService zhongTianSxService, IMapper mapper, IRedisClient redisClient)
  28. {
  29. _zhongTianSxService = zhongTianSxService;
  30. _mapper = mapper;
  31. _redisClient = redisClient;
  32. }
  33. #region 查询配置文件信息
  34. /// <summary>
  35. /// 查询配置的车间设备信息
  36. /// </summary>
  37. /// <returns></returns>
  38. [HttpPost]
  39. public List<WorkShopWithEquipment> GetWorkShopWithEquipment()
  40. {
  41. List<WorkShopWithEquipment> workShopWithEquipmentList = new List<WorkShopWithEquipment>();
  42. workShopWithEquipmentList.AddRange(InOutEquipment.WorkShopWithEquipment);
  43. workShopWithEquipmentList.AddRange(InOutEquipment.YTWorkShopWithEquipment);
  44. return workShopWithEquipmentList;
  45. }
  46. #endregion
  47. #region 扭转检测报警看板
  48. /// <summary>
  49. /// 获取扭转检测报警信息
  50. /// </summary>
  51. /// <returns></returns>
  52. [HttpPost]
  53. public PageResult<ReverseErrorInfo> GetReverseErrorInfo()
  54. {
  55. return _zhongTianSxService.GetReverseErrorInfo();
  56. }
  57. #endregion
  58. #region 任务信息看板
  59. /// <summary>
  60. /// 时效任务信息
  61. /// </summary>
  62. /// <param name="request"></param>
  63. /// <returns></returns>
  64. [HttpPost]
  65. public List<dynamic> GetSxInfo(StrRequestDto request)
  66. {
  67. if (string.IsNullOrEmpty(request.StrRequest))
  68. {
  69. return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
  70. }
  71. var result = new List<dynamic>();
  72. if (request.StrRequest.Split(',').Contains("1")) //堆垛机状态
  73. {
  74. //查询设备状态
  75. result.Add(_zhongTianSxService.GetSxEquips(new GetEquipsRequest()
  76. {
  77. WarehouseCodeList = new List<string>() {
  78. Const.Sxhouse_putong }
  79. }));
  80. }
  81. else
  82. {
  83. result.Add("");
  84. }
  85. if (request.StrRequest.Split(',').Contains("2")) //装箱信息
  86. {
  87. result.Add(_zhongTianSxService.GetSxProductPackRule(new GetWorkPlanBillListRequest()
  88. {
  89. }));
  90. }
  91. else
  92. {
  93. result.Add("");
  94. }
  95. if (request.StrRequest.Split(',').Contains("3")) //任务信息
  96. {
  97. List<string> equipNoList = new List<string>();
  98. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach(
  99. n => equipNoList.AddRange(n.Equipments));
  100. //任务信息:出库和入库任务
  101. //设备号数据,做成配置
  102. var taskInfos = _zhongTianSxService.GetSxTaskInfo(new GetWcsTaskInfoRequest()
  103. {
  104. EquipList = equipNoList,
  105. TaskTypelist = new List<TaskType> { TaskType.OutDepot, TaskType.EnterDepot }
  106. });
  107. result.Add(taskInfos);
  108. }
  109. else
  110. {
  111. result.Add("");
  112. }
  113. if (request.StrRequest.Split(',').Contains("4")) //报警信息
  114. {
  115. List<string> equipNoList = new List<string>();
  116. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  117. n => equipNoList.AddRange(n.Equipments));
  118. //获取报警信息
  119. //设备号数据,做成配置
  120. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
  121. {
  122. EquCodeList = equipNoList.Distinct().ToList()
  123. }));
  124. }
  125. else
  126. {
  127. result.Add("");
  128. }
  129. return result;
  130. }
  131. #endregion
  132. #region 包装信息看板
  133. #endregion
  134. #region 货位利用率
  135. /// <summary>
  136. /// 时效货位利用率
  137. /// </summary>
  138. /// <param name="strRequest"></param>
  139. /// <returns></returns>
  140. [HttpPost]
  141. public PageResult<ZtLocationUsageReportViewDto> GetSxLocationStateList()
  142. {
  143. return _zhongTianSxService.GetSxLocationUsageViewList();
  144. }
  145. #endregion
  146. #region 异常信息汇总
  147. /// <summary>
  148. /// 时效异常信息汇总
  149. /// </summary>
  150. /// <returns></returns>
  151. [HttpPost]
  152. public List<dynamic> GetTotalErrorInfo()
  153. {
  154. var result = new List<dynamic>();
  155. List<string> equipNoList = new List<string>();
  156. InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "sx").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  157. n => equipNoList.AddRange(n.Equipments));
  158. //报警信息
  159. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest()
  160. {
  161. EquCodeList = equipNoList.Distinct().ToList()
  162. }));
  163. return result;
  164. }
  165. #endregion
  166. #region 私有方法:将报表方法提取出来
  167. /// <summary>
  168. /// 报警信息
  169. /// </summary>
  170. /// <param name="reqEntity"></param>
  171. /// <returns></returns>
  172. private List<StockInAndOutRecordDto> GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity)
  173. {
  174. var list = new List<StockInAndOutRecordDto>();
  175. //读取redis缓存(wcs实时传递设备信息)
  176. //var strMsgList = _redisClient.Get(Const.equi_list);
  177. //获取单据错误信息
  178. //List<SqlSugar.Model.BillErrorInfo> ErrorList = new List<SqlSugar.Model.BillErrorInfo>();
  179. //try
  180. //{
  181. // ErrorList = _yongGuanDataService.GetBillErrorInfoList(reqEntity.EquipNo);
  182. // if (ErrorList.Count() > 0)
  183. // {
  184. // list.AddRange(ErrorList.Select(s => new StockInAndOutRecordDto { dateTime = s.CreatedTime.ToString("HH:mm:ss"), Message = s.Msg }).ToList());
  185. // }
  186. // //if (ErrorList.Count() > 0)
  187. // //{
  188. // // //显示近一天的数据
  189. // // //DateTime end = DateTime.Now.AddDays(1);
  190. // // ErrorList = ErrorList.Where(x => x.CreatedTime.Date == DateTime.Now.Date).ToList();
  191. // //}
  192. //}
  193. //catch (Exception ex)
  194. //{
  195. // list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"数据库报警信息读取失败:{ex.Message}" });
  196. //}
  197. try
  198. {
  199. foreach (var equipno in reqEntity.EquCodeList)
  200. {
  201. var msg1 = _redisClient.Get("equone" + equipno);
  202. var msg2 = _redisClient.Get("equsecond" + equipno);
  203. if (!string.IsNullOrEmpty(msg1))
  204. {
  205. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
  206. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date)
  207. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  208. }
  209. if (!string.IsNullOrEmpty(msg2))
  210. {
  211. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg2);
  212. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date)
  213. {
  214. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  215. }
  216. }
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
  222. }
  223. if (list.Any())
  224. {
  225. list = list.OrderByDescending(p => p.dateTime).ToList();
  226. }
  227. return list;
  228. }
  229. #endregion
  230. }
  231. }