ZhongTianFjController.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 ZhongTianFjController : ControllerBase
  22. {
  23. private IZhongTianFjService _zhongTianFjService;
  24. private IMapper _mapper;
  25. private IRedisClient _redisClient;
  26. public ZhongTianFjController(IZhongTianFjService zhongTianFjService, IMapper mapper, IRedisClient redisClient)
  27. {
  28. _zhongTianFjService = zhongTianFjService;
  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> GetFjInfo(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. //查询设备状态
  65. result.Add(_zhongTianFjService.GetFjEquips(new GetEquipsRequest()
  66. {
  67. WarehouseCodeList = new List<string>() {
  68. Const.Fjhouse_putong}
  69. }));
  70. }
  71. else
  72. {
  73. result.Add("");
  74. }
  75. if (request.StrRequest.Split(',').Contains("2")) //码垛信息
  76. {
  77. result.Add(_zhongTianFjService.GetFjStackInfo(new GetWorkPlanBillListRequest()
  78. {
  79. WarehouseCodeList = new List<string>() { Const.Fjhouse_putong },
  80. }));
  81. }
  82. else
  83. {
  84. result.Add("");
  85. }
  86. if (request.StrRequest.Split(',').Contains("3")) //任务信息
  87. {
  88. List<string> equipNoList = new List<string>();
  89. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach(
  90. n => equipNoList.AddRange(n.Equipments));
  91. //任务信息:出库和入库任务,目标地址或开始地址是当前车间的设备号
  92. //设备号数据,做成配置
  93. var taskInfos = _zhongTianFjService.GetFjTaskInfo(new GetWcsTaskInfoRequest()
  94. {
  95. EquipList = equipNoList,
  96. TaskTypelist = new List<TaskType>() { TaskType.OutDepot, TaskType.EnterDepot }
  97. });
  98. result.Add(taskInfos);
  99. }
  100. else
  101. {
  102. result.Add("");
  103. }
  104. if (request.StrRequest.Split(',').Contains("4")) //报警信息
  105. {
  106. List<string> equipNoList = new List<string>();
  107. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  108. n => equipNoList.AddRange(n.Equipments));
  109. //获取报警信息
  110. //设备号数据,做成配置
  111. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
  112. {
  113. EquCodeList = equipNoList.Distinct().ToList()
  114. }));
  115. }
  116. else
  117. {
  118. result.Add("");
  119. }
  120. return result;
  121. }
  122. #endregion
  123. #region 货位利用率
  124. /// <summary>
  125. /// 分拣货位利用率
  126. /// </summary>
  127. /// <param name="strRequest"></param>
  128. /// <returns></returns>
  129. [HttpPost]
  130. public PageResult<ZtLocationUsageReportViewDto> GetFjLocationStateList()
  131. {
  132. return _zhongTianFjService.GetFjLocationUsageViewList();
  133. }
  134. #endregion
  135. #region 异常信息汇总
  136. /// <summary>
  137. /// 分拣异常信息汇总
  138. /// </summary>
  139. /// <returns></returns>
  140. [HttpPost]
  141. public List<dynamic> GetTotalErrorInfo()
  142. {
  143. var result = new List<dynamic>();
  144. List<string> equipNoList = new List<string>();
  145. InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "fj").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  146. n => equipNoList.AddRange(n.Equipments));
  147. //报警信息
  148. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest()
  149. {
  150. EquCodeList = equipNoList.Distinct().ToList()
  151. }));
  152. return result;
  153. }
  154. #endregion
  155. #region 私有方法:将报表方法提取出来
  156. /// <summary>
  157. /// 报警信息
  158. /// </summary>
  159. /// <param name="reqEntity"></param>
  160. /// <returns></returns>
  161. private List<StockInAndOutRecordDto> GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity)
  162. {
  163. var list = new List<StockInAndOutRecordDto>();
  164. //读取redis缓存(wcs实时传递设备信息)
  165. //var strMsgList = _redisClient.Get(Const.equi_list);
  166. //获取单据错误信息
  167. //List<SqlSugar.Model.BillErrorInfo> ErrorList = new List<SqlSugar.Model.BillErrorInfo>();
  168. //try
  169. //{
  170. // ErrorList = _yongGuanDataService.GetBillErrorInfoList(reqEntity.EquipNo);
  171. // if (ErrorList.Count() > 0)
  172. // {
  173. // list.AddRange(ErrorList.Select(s => new StockInAndOutRecordDto { dateTime = s.CreatedTime.ToString("HH:mm:ss"), Message = s.Msg }).ToList());
  174. // }
  175. // //if (ErrorList.Count() > 0)
  176. // //{
  177. // // //显示近一天的数据
  178. // // //DateTime end = DateTime.Now.AddDays(1);
  179. // // ErrorList = ErrorList.Where(x => x.CreatedTime.Date == DateTime.Now.Date).ToList();
  180. // //}
  181. //}
  182. //catch (Exception ex)
  183. //{
  184. // list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"数据库报警信息读取失败:{ex.Message}" });
  185. //}
  186. try
  187. {
  188. foreach (var equipno in reqEntity.EquCodeList)
  189. {
  190. var msg1 = _redisClient.Get("equone" + equipno);
  191. var msg2 = _redisClient.Get("equsecond" + equipno);
  192. if (!string.IsNullOrEmpty(msg1))
  193. {
  194. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
  195. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG))
  196. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  197. }
  198. if (!string.IsNullOrEmpty(msg2))
  199. {
  200. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg2);
  201. if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date)
  202. {
  203. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG });
  204. }
  205. }
  206. }
  207. }
  208. catch (Exception ex)
  209. {
  210. list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
  211. }
  212. if (list.Any())
  213. {
  214. list = list.OrderByDescending(p => p.dateTime).ToList();
  215. }
  216. return list;
  217. }
  218. #endregion
  219. }
  220. }