using AutoMapper;
using Bozhon.Wms.Util.Cache;
using CSRedis;
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 zt.screen.api.Controllers
{
///
/// 中天盘条看板
///
[Route("api/[controller]/[action]")]
[ApiController]
public class ZhongTianPtController : ControllerBase
{
private IZhongTianPtService _zhongTianPtService;
private IMapper _mapper;
private readonly CSRedisClient _CSRedisClient;
private readonly FreeRedis.RedisClient _freeRedisClient;
public ZhongTianPtController(IZhongTianPtService zhongTianPtService, IMapper mapper, CSRedisClient cSRedisClient, FreeRedis.RedisClient freeRedisClient)
{
_zhongTianPtService = zhongTianPtService;
_mapper = mapper;
_CSRedisClient = cSRedisClient;
_freeRedisClient = freeRedisClient;
}
#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")) //堆垛机状态
{
//查询设备状态 ,读redis
result.Add(_zhongTianPtService.GetPtEquips(new GetEquipsRequest()
{
}, _freeRedisClient));
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("2")) //根据物料号显示当前库存数量
{
result.Add(_zhongTianPtService.GetMatCodeBarDatas());
}
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("");
}
if (request.StrRequest.Split(',').Contains("5")) //同炉号各规格数量
{
result.Add(_zhongTianPtService.GetBoilerNoMatCodeQtyList());
}
else
{
result.Add("");
}
return result;
}
[HttpPost]
public List GetPtStatsInfo(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.GetLocaitonList());
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("2")) //空满轮占比
{
//领料 涂布领料汇总,不区分车间
// result.Add(_zhongTianPtService.GetEmptyFullDist());
result.Add("");
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("3")) //7天出入库统计
{
var taskInfos = _zhongTianPtService.GeHistoryTaskInfo(new GeHistoryTaskInfoRequest()
{
BusTypeList = new List() { "采购入库单", "生产领料" },
StartTime = DateTime.Now.AddDays(-7),
EndTime = DateTime.Now.AddDays(1)
});
result.Add(taskInfos);
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("4")) //物料重量分布
{
var taskInfos = _zhongTianPtService. GetInvReports();
result.Add(taskInfos);
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("5")) //报警信息
{
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();
try
{
foreach (var equipno in reqEntity.EquCodeList)
{
var msg1 = _CSRedisClient.Get("Pt:EquipmentAlarm:" + equipno); //设备报警
if (!string.IsNullOrEmpty(msg1))
{
var msgdto = JsonConvert.DeserializeObject(msg1);
if (msgdto.Msg == "0" || msgdto.Msg == "无")
{
continue;
}
if (!string.IsNullOrEmpty(msgdto.Msg) && msgdto.Time.Date == DateTime.Now.Date)
list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = msgdto.Code + "," + msgdto.Msg });
}
}
var msg2 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorld"); //业务报警
var msgdto2 = JsonConvert.DeserializeObject>(msg2);
if (msgdto2.Any())
{
foreach (var item in msgdto2)
{
if (!string.IsNullOrEmpty(item.Con) && item.Time.Date == DateTime.Now.Date)
{
item.Con = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
if (item.Con.StartsWith("[SRM1]") || item.Con.StartsWith("[SRM2]") || item.Con.StartsWith("[SRM3]") || item.Con.StartsWith("[SRM4]"))
{
item.Con = item.Con.Substring(item.Con.LastIndexOf("]") + 1);
}
else if (item.Con.StartsWith("1011") || item.Con.StartsWith("1012") || item.Con.StartsWith("1014") || item.Con.StartsWith("1016"))
{
item.Con = item.Con.Substring(4);
}
else if (item.Con.StartsWith("SRM1") || item.Con.StartsWith("SRM2") || item.Con.StartsWith("SRM3") || item.Con.StartsWith("SRM4"))
{
item.Con = item.Con.Substring(4);
}
list.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = item.DevNo + "," + item.Con });
}
}
}
var msg3 = _CSRedisClient.Get("Pt:BusinessAlarm:MainWorldd"); //AGV交互报错信息
if (msg3 != null)
{
var msgdto3 = JsonConvert.DeserializeObject>(msg3);
if (msgdto3.Any())
{
List agv = new List();
foreach (var item in msgdto3)
{
if (!string.IsNullOrEmpty(item.Con) && (DateTime.Now - item.Time).Minutes.ToString().GetHashCode() < 2)
{
var mes = item.Con.Substring(item.Con.LastIndexOf("内容:") + 3);
if (mes.StartsWith("[1011]--"))
{
mes = mes.Substring(mes.LastIndexOf("--") + 2);
}
agv.Add(new StockInAndOutRecordDto { dateTime = item.Time.ToString("HH:mm:ss"), Message = "海康报错信息" + "," + mes });
}
}
if (agv.Any())
{
var agv1 = agv.Select(p => p.Message).Distinct().ToList();
foreach (var item in agv1)
{
list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = item });
}
}
}
}
for (int i = 1; i < 20; i++) //WMS业务报警
{
var msg = RedisHelper.Get("Pt:WMSErrorInfo:" + i); //WMS业务报警
if (msg != null)
{
var msgdto = JsonConvert.DeserializeObject(msg);
list.Add(new StockInAndOutRecordDto { dateTime = msgdto.Time.ToString("HH:mm:ss"), Message = "WMS业务报警:" + msgdto.Con });
}
if (i == 5 && DateTime.Now.Hour == 0 && DateTime.Now.Minute < 10)//凌晨清理下报警
{
RedisHelper.Del("Pt:WMSErrorInfo:" + i);
}
}
}
catch (Exception ex)
{
list.Add(new StockInAndOutRecordDto { dateTime = DateTime.Now.ToString("HH:mm:ss"), Message = $"缓存报警读取失败:{ex.Message}" });
}
if (list.Any())
{
list = list.OrderBy(p => p.Code).ToList();
}
return list;
}
#endregion
}
}