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 ZhongTianFjController : ControllerBase
{
private IZhongTianFjService _zhongTianFjService;
private IMapper _mapper;
private IRedisClient _redisClient;
public ZhongTianFjController(IZhongTianFjService zhongTianFjService, IMapper mapper, IRedisClient redisClient)
{
_zhongTianFjService = zhongTianFjService;
_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 GetFjInfo(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(_zhongTianFjService.GetFjEquips(new GetEquipsRequest()
{
WarehouseCodeList = new List() {
Const.Fjhouse_putong}
}));
}
else
{
result.Add("");
}
if (request.StrRequest.Split(',').Contains("2")) //码垛信息
{
result.Add(_zhongTianFjService.GetFjStackInfo(new GetWorkPlanBillListRequest()
{
WarehouseCodeList = new List() { Const.Fjhouse_putong },
}));
}
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 = _zhongTianFjService.GetFjTaskInfo(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 GetFjLocationStateList()
{
return _zhongTianFjService.GetFjLocationUsageViewList();
}
#endregion
#region 异常信息汇总
///
/// 分拣异常信息汇总
///
///
[HttpPost]
public List GetTotalErrorInfo()
{
var result = new List();
List equipNoList = new List();
InOutEquipment.WorkShopWithEquipment.Where(s => InOutEquipment.DeopWithWOrkShops.Where(m => m.Dept == "fj").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
}
}