ZhongTianPtController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. using AutoMapper;
  2. using Bozhon.Wms.Util.Cache;
  3. using CSRedis;
  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 zt.screen.api.Controllers
  15. {
  16. /// <summary>
  17. /// 中天盘条看板
  18. /// </summary>
  19. [Route("api/[controller]/[action]")]
  20. [ApiController]
  21. public class ZhongTianPtController : ControllerBase
  22. {
  23. private IZhongTianPtService _zhongTianPtService;
  24. private IMapper _mapper;
  25. private readonly CSRedisClient _CSRedisClient;
  26. private readonly FreeRedis.RedisClient _freeRedisClient;
  27. public ZhongTianPtController(IZhongTianPtService zhongTianPtService, IMapper mapper, CSRedisClient cSRedisClient, FreeRedis.RedisClient freeRedisClient)
  28. {
  29. _zhongTianPtService = zhongTianPtService;
  30. _mapper = mapper;
  31. _CSRedisClient = cSRedisClient;
  32. _freeRedisClient = freeRedisClient;
  33. }
  34. #region 查询配置文件信息
  35. /// <summary>
  36. /// 查询配置的车间设备信息
  37. /// </summary>
  38. /// <returns></returns>
  39. [HttpPost]
  40. public List<WorkShopWithEquipment> GetWorkShopWithEquipment()
  41. {
  42. List<WorkShopWithEquipment> workShopWithEquipmentList = new List<WorkShopWithEquipment>();
  43. workShopWithEquipmentList.AddRange(InOutEquipment.WorkShopWithEquipment);
  44. workShopWithEquipmentList.AddRange(InOutEquipment.YTWorkShopWithEquipment);
  45. return workShopWithEquipmentList;
  46. }
  47. #endregion
  48. #region 盘条看板
  49. /// <summary>
  50. /// 盘条看板
  51. /// </summary>
  52. /// <param name="strRequest"></param>
  53. /// <param name="workshop"></param>
  54. /// <param name="boardCode"></param>
  55. /// <returns></returns>
  56. [HttpPost]
  57. public List<dynamic> GetPtInfo(StrRequestDto request)
  58. {
  59. if (string.IsNullOrEmpty(request.StrRequest))
  60. {
  61. return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
  62. }
  63. var result = new List<dynamic>();
  64. if (request.StrRequest.Split(',').Contains("1")) //堆垛机状态
  65. {
  66. //查询设备状态 ,读redis
  67. result.Add(_zhongTianPtService.GetPtEquips(new GetEquipsRequest()
  68. {
  69. }, _freeRedisClient));
  70. }
  71. else
  72. {
  73. result.Add("");
  74. }
  75. if (request.StrRequest.Split(',').Contains("2")) //根据物料号显示当前库存数量
  76. {
  77. result.Add(_zhongTianPtService.GetMatCodeBarDatas());
  78. }
  79. else
  80. {
  81. result.Add("");
  82. }
  83. if (request.StrRequest.Split(',').Contains("3")) //任务信息
  84. {
  85. //List<string> equipNoList = new List<string>();
  86. //InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach(
  87. // n => equipNoList.AddRange(n.Equipments));
  88. //任务信息:出库和入库任务
  89. //设备号数据,做成配置
  90. var taskInfos = _zhongTianPtService.GetPtTaskInfo(new GetWcsTaskInfoRequest()
  91. {
  92. //EquipList = equipNoList,
  93. TaskTypelist = new List<TaskType> { TaskType.OutDepot, TaskType.EnterDepot }
  94. });
  95. result.Add(taskInfos);
  96. }
  97. else
  98. {
  99. result.Add("");
  100. }
  101. if (request.StrRequest.Split(',').Contains("4")) //报警信息
  102. {
  103. List<string> equipNoList = new List<string>();
  104. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  105. n => equipNoList.AddRange(n.Equipments));
  106. //获取报警信息
  107. //设备号数据,做成配置
  108. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
  109. {
  110. EquCodeList = equipNoList.Distinct().ToList()
  111. }));
  112. }
  113. else
  114. {
  115. result.Add("");
  116. }
  117. if (request.StrRequest.Split(',').Contains("5")) //同炉号各规格数量
  118. {
  119. result.Add(_zhongTianPtService.GetBoilerNoMatCodeQtyList());
  120. }
  121. else
  122. {
  123. result.Add("");
  124. }
  125. return result;
  126. }
  127. [HttpPost]
  128. public List<dynamic> GetPtStatsInfo(StrRequestDto request)
  129. {
  130. if (string.IsNullOrEmpty(request.StrRequest))
  131. {
  132. return new List<dynamic> { new object(), new object(), new object(), new object(), new object() };
  133. }
  134. var result = new List<dynamic>();
  135. if (request.StrRequest.Split(',').Contains("1")) //货位分布占比
  136. {
  137. result.Add(_zhongTianPtService.GetLocaitonList());
  138. }
  139. else
  140. {
  141. result.Add("");
  142. }
  143. if (request.StrRequest.Split(',').Contains("2")) //空满轮占比
  144. {
  145. //领料 涂布领料汇总,不区分车间
  146. // result.Add(_zhongTianPtService.GetEmptyFullDist());
  147. result.Add("");
  148. }
  149. else
  150. {
  151. result.Add("");
  152. }
  153. if (request.StrRequest.Split(',').Contains("3")) //7天出入库统计
  154. {
  155. var taskInfos = _zhongTianPtService.GeHistoryTaskInfo(new GeHistoryTaskInfoRequest()
  156. {
  157. BusTypeList = new List<string>() { "采购入库单", "生产领料" },
  158. StartTime = DateTime.Now.AddDays(-7),
  159. EndTime = DateTime.Now.AddDays(1)
  160. });
  161. result.Add(taskInfos);
  162. }
  163. else
  164. {
  165. result.Add("");
  166. }
  167. if (request.StrRequest.Split(',').Contains("4")) //物料重量分布
  168. {
  169. var taskInfos = _zhongTianPtService. GetInvReports();
  170. result.Add(taskInfos);
  171. }
  172. else
  173. {
  174. result.Add("");
  175. }
  176. if (request.StrRequest.Split(',').Contains("5")) //报警信息
  177. {
  178. List<string> equipNoList = new List<string>();
  179. InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  180. n => equipNoList.AddRange(n.Equipments));
  181. //获取报警信息
  182. //设备号数据,做成配置
  183. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest
  184. {
  185. EquCodeList = equipNoList.Distinct().ToList()
  186. }));
  187. }
  188. else
  189. {
  190. result.Add("");
  191. }
  192. return result;
  193. }
  194. #endregion
  195. #region 货位利用率
  196. /// <summary>
  197. /// 盘条货位利用率
  198. /// </summary>
  199. /// <param name="strRequest"></param>
  200. /// <returns></returns>
  201. [HttpPost]
  202. public PageResult<ZtLocationUsageReportViewDto> GetPtLocationStateList()
  203. {
  204. return _zhongTianPtService.GetPtLocationUsageViewList();
  205. }
  206. #endregion
  207. #region 异常信息汇总
  208. /// <summary>
  209. /// 盘条异常信息汇总
  210. /// </summary>
  211. /// <returns></returns>
  212. [HttpPost]
  213. public List<dynamic> GetTotalErrorInfo()
  214. {
  215. var result = new List<dynamic>();
  216. List<string> equipNoList = new List<string>();
  217. InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "pt").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach(
  218. n => equipNoList.AddRange(n.Equipments));
  219. //报警信息
  220. result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest()
  221. {
  222. EquCodeList = equipNoList.Distinct().ToList()
  223. }));
  224. return result;
  225. }
  226. #endregion
  227. #region 私有方法:将报表方法提取出来
  228. /// <summary>
  229. /// 报警信息
  230. /// </summary>
  231. /// <param name="reqEntity"></param>
  232. /// <returns></returns>
  233. private List<StockInAndOutRecordDto> GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity)
  234. {
  235. var list = new List<StockInAndOutRecordDto>();
  236. try
  237. {
  238. foreach (var equipno in reqEntity.EquCodeList)
  239. {
  240. var msg1 = _CSRedisClient.Get("Pt:EquipmentAlarm:" + equipno); //设备报警
  241. if (!string.IsNullOrEmpty(msg1))
  242. {
  243. var msgdto = JsonConvert.DeserializeObject<I_WCS_PutDevInfoRequestDto>(msg1);
  244. if (msgdto.Msg == "0" || msgdto.Msg == "无")
  245. {
  246. continue;
  247. }
  248. if (!string.IsNullOrEmpty(msgdto.Msg) && msgdto.Time.Date == DateTime.Now.Date)
  249. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = msgdto.Code + "," + msgdto.Msg });
  250. }
  251. }
  252. var msg2 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorld"); //业务报警
  253. var msgdto2 = JsonConvert.DeserializeObject<List<BusinessDto>>(msg2);
  254. if (msgdto2.Any())
  255. {
  256. foreach (var item in msgdto2)
  257. {
  258. if (!string.IsNullOrEmpty(item.Con) && item.Time.Date == DateTime.Now.Date)
  259. {
  260. item.Con = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
  261. if (item.Con.StartsWith("[SRM1]") || item.Con.StartsWith("[SRM2]") || item.Con.StartsWith("[SRM3]") || item.Con.StartsWith("[SRM4]"))
  262. {
  263. item.Con = item.Con.Substring(item.Con.LastIndexOf("]") + 1);
  264. }
  265. else if (item.Con.StartsWith("1011") || item.Con.StartsWith("1012") || item.Con.StartsWith("1014") || item.Con.StartsWith("1016"))
  266. {
  267. item.Con = item.Con.Substring(4);
  268. }
  269. else if (item.Con.StartsWith("SRM1") || item.Con.StartsWith("SRM2") || item.Con.StartsWith("SRM3") || item.Con.StartsWith("SRM4"))
  270. {
  271. item.Con = item.Con.Substring(4);
  272. }
  273. list.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = item.DevNo + "," + item.Con });
  274. }
  275. }
  276. }
  277. var msg3 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorldd"); //AGV交互报错信息
  278. if (msg3 != null)
  279. {
  280. var msgdto3 = JsonConvert.DeserializeObject<List<BusinessDto>>(msg3);
  281. if (msgdto3.Any())
  282. {
  283. List<StockInAndOutRecordDto> agv = new List<StockInAndOutRecordDto>();
  284. foreach (var item in msgdto3)
  285. {
  286. if (!string.IsNullOrEmpty(item.Con) && (DateTime.Now - item.Time).Minutes.ToString().GetHashCode() < 2)
  287. {
  288. var mes = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
  289. if (mes.StartsWith("[1011]--"))
  290. {
  291. mes = mes.Substring(mes.LastIndexOf("--") + 2);
  292. }
  293. agv.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = "海康报错信息" + "," + mes });
  294. }
  295. }
  296. if (agv.Any())
  297. {
  298. var agv1 = agv.Select(p => p.Message).Distinct().ToList();
  299. foreach (var item in agv1)
  300. {
  301. list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = item });
  302. }
  303. }
  304. }
  305. }
  306. for (int i = 1; i < 20; i++) //WMS业务报警
  307. {
  308. var msg = RedisHelper.Get("Pt:WMSErrorInfo:" + i); //WMS业务报警
  309. if (msg != null)
  310. {
  311. var msgdto = JsonConvert.DeserializeObject<BusinessDto2>(msg);
  312. list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = "WMS业务报警:" + msgdto.Con });
  313. }
  314. if (i == 5 && DateTime.Now.Hour == 0 && DateTime.Now.Minute < 10)//凌晨清理下报警
  315. {
  316. RedisHelper.Del("Pt:WMSErrorInfo:" + i);
  317. }
  318. }
  319. }
  320. catch (Exception ex)
  321. {
  322. list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
  323. }
  324. if (list.Any())
  325. {
  326. list = list.OrderBy(p => p.Code).ToList();
  327. }
  328. return list;
  329. }
  330. #endregion
  331. }
  332. }