using AutoMapper; using Bozhon.Wms.Util.Cache; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Wms.Screen.Dto; using Wms.Screen.Dto.ZhongTian; using Wms.Screen.Dto.ZhongTian.Request; using Wms.Screen.Dto.ZhongTian.Response; using Wms.Screen.Service.IService; namespace Wms.Screen.Api.Controllers { /// /// 中天盘条看板 /// [Route("api/[controller]/[action]")] [ApiController] public class ZhongTianPtController : ControllerBase { private IZhongTianPtService _zhongTianPtService; private IMapper _mapper; private IRedisClient _redisClient; public ZhongTianPtController(IZhongTianPtService zhongTianPtService, IMapper mapper, IRedisClient redisClient) { _zhongTianPtService = zhongTianPtService; _mapper = mapper; _redisClient = redisClient; } #region 查询配置文件信息 /// /// 查询配置的车间设备信息 /// /// [HttpPost] public List GetWorkShopWithEquipment() { List workShopWithEquipmentList = new List(); workShopWithEquipmentList.AddRange(InOutEquipment.WorkShopWithEquipment); workShopWithEquipmentList.AddRange(InOutEquipment.YTWorkShopWithEquipment); return workShopWithEquipmentList; } #endregion #region 盘条看板 /// /// 盘条看板 /// /// /// /// /// [HttpPost] public List GetPtInfo(StrRequestDto request) { if (string.IsNullOrEmpty(request.StrRequest)) { return new List { new object(), new object(), new object(), new object(), new object() }; } var result = new List(); if (request.StrRequest.Split(',').Contains("1")) //堆垛机信息 { //查询设备状态 result.Add(_zhongTianPtService.GetPtEquips(new GetEquipsRequest() { WarehouseCodeList = new List() { Const.Pthouse_putong} })); } else { result.Add(""); } //if (strRequest.Split(',').Contains("2")) //出库数据汇总 //{ // //领料 涂布领料汇总,不区分车间 // result.Add(_zhongTianPtService.GetPtBillList(new GetWorkPlanBillListRequest() // { // WarehouseDocumentType = Const.WorkPlanBill, // WarehouseCodeList = new List() { Const.Pthouse_putong }, // WarehouseDocumentStateList = new List() { Const.WarehouseDocumentState_ExecuteCode, Const.WarehouseDocumentState_CreateCode } // })); //} //else //{ // result.Add(""); //} if (request.StrRequest.Split(',').Contains("3")) //任务信息 { List equipNoList = new List(); InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).Distinct().ToList().ForEach( n => equipNoList.AddRange(n.Equipments)); //任务信息:出库和入库任务,目标地址或开始地址是当前车间的设备号 //设备号数据,做成配置 var taskInfos = _zhongTianPtService.GetPtTaskInfo(new GetWcsTaskInfoRequest() { EquipList = equipNoList, TaskTypelist = new List() { TaskType.OutDepot, TaskType.EnterDepot } }); result.Add(taskInfos); } else { result.Add(""); } if (request.StrRequest.Split(',').Contains("4")) //报警信息 { List equipNoList = new List(); InOutEquipment.WorkShopWithEquipment.Where(s => s.InOrOut == "Out" && InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == request.Workshop).FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach( n => equipNoList.AddRange(n.Equipments)); //获取报警信息 //设备号数据,做成配置 result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest { EquCodeList = equipNoList.Distinct().ToList() })); } else { result.Add(""); } return result; } #endregion #region 货位利用率 /// /// 盘条货位利用率 /// /// /// [HttpPost] public PageResult GetPtLocationStateList() { return _zhongTianPtService.GetPtLocationUsageViewList(); } #endregion #region 异常信息汇总 /// /// 盘条异常信息汇总 /// /// [HttpPost] public List GetTotalErrorInfo() { var result = new List(); List equipNoList = new List(); InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "pt").FirstOrDefault().WorkShopList.Contains(s.WorkShop)).ToList().ForEach( n => equipNoList.AddRange(n.Equipments)); //报警信息 result.Add(GetStockInAndOutRecordInfo(new GetEquipsRequest() { EquCodeList = equipNoList.Distinct().ToList() })); return result; } #endregion #region 私有方法:将报表方法提取出来 /// /// 报警信息 /// /// /// private List GetStockInAndOutRecordInfo(GetEquipsRequest reqEntity) { var list = new List(); //读取redis缓存(wcs实时传递设备信息) //var strMsgList = _redisClient.Get(Const.equi_list); //获取单据错误信息 //List ErrorList = new List(); //try //{ // ErrorList = _yongGuanDataService.GetBillErrorInfoList(reqEntity.EquipNo); // if (ErrorList.Count() > 0) // { // list.AddRange(ErrorList.Select(s => new StockInAndOutRecordDto { dateTime = s.CreatedTime.ToString("HH:mm:ss"), Message = s.Msg }).ToList()); // } // //if (ErrorList.Count() > 0) // //{ // // //显示近一天的数据 // // //DateTime end = DateTime.Now.AddDays(1); // // ErrorList = ErrorList.Where(x => x.CreatedTime.Date == DateTime.Now.Date).ToList(); // //} //} //catch (Exception ex) //{ // list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"数据库报警信息读取失败:{ex.Message}" }); //} try { foreach (var equipno in reqEntity.EquCodeList) { var msg1 = _redisClient.Get("equone" + equipno); var msg2 = _redisClient.Get("equsecond" + equipno); if (!string.IsNullOrEmpty(msg1)) { var msgdto = JsonConvert.DeserializeObject(msg1); if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG)) list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG }); } if (!string.IsNullOrEmpty(msg2)) { var msgdto = JsonConvert.DeserializeObject(msg2); if (!string.IsNullOrEmpty(msgdto.STA_ALARMSMSG) && msgdto.InOutTime.Date == DateTime.Now.Date) { list.Add(new StockInAndOutRecordDto { dateTime = msgdto.InOutTime.ToString("HH:mm:ss"), Message = msgdto.STA_ALARMSMSG }); } } } } catch (Exception ex) { list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" }); } if (list.Any()) { list = list.OrderByDescending(p => p.dateTime).ToList(); } return list; } #endregion } }