ZhongTianHjController.cs 9.6 KB

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