using AutoMapper; using Bozhon.Wms.Util.Cache; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System.Collections.Generic; using System; using Wms.Screen.Dto.ZhongTian.Request; using Wms.Screen.Dto.ZhongTian.Response; using Wms.Screen.Dto.ZhongTian; using Wms.Screen.Service.IService; using System.Linq; using Wms.Screen.Dto; using Wms.Screen.Service.Service; namespace Wms.Screen.Api.Controllers { /// /// 中天成品看板 /// [Route("api/[controller]/[action]")] [ApiController] public class ZhongTianCpController : ControllerBase { private IZhongTianCpService _zhongTianCpService; private IMapper _mapper; private IRedisClient _redisClient; public ZhongTianCpController(IZhongTianCpService zhongTianCpService, IMapper mapper, IRedisClient redisClient) { _zhongTianCpService = zhongTianCpService; _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 GetCpInfo(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(_zhongTianCpService.GetCpEquips(new GetEquipsRequest() { WarehouseCodeList = new List() { Const.Cphouse_putong} })); } else { result.Add(""); } if (request.StrRequest.Split(',').Contains("2")) //库龄统计占比 { //领料 涂布领料汇总,不区分车间 result.Add(_zhongTianCpService.GetCpBillList(new GetWorkPlanBillListRequest() { WarehouseDocumentType = Const.WorkPlanBill, WarehouseCodeList = new List() { Const.Cphouse_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 = _zhongTianCpService.GetCpTaskInfo(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 GetCpLocationStateList() { return _zhongTianCpService.GetCpLocationUsageViewList(); } #endregion #region 异常信息汇总 /// /// 成品异常信息汇总 /// /// [HttpPost] public List GetTotalErrorInfo() { var result = new List(); List equipNoList = new List(); InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "cp").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 } }