using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;
using Wms.Screen.DataService.Interface;
using Wms.Screen.Dto.ZhongTian.Request;
using Wms.Screen.Dto.ZhongTian.Response;
using Wms.Screen.Dto.ZhongTian;
using Wms.Screen.Service.IService;
using Wms.Screen.DataService.Impl;
using Wms.Screen.Dto;
using System.Linq;
using Newtonsoft.Json;
using CSRedis;
namespace Wms.Screen.Service.Service
{
///
/// 成品
///
public class ZhongTianCpService : IZhongTianCpService
{
private IZhongTianCpDataService _zhongTianCpDataService;
private IMapper _mapper;
public ZhongTianCpService(IZhongTianCpDataService zhongTianCpDataService, IMapper mapper)
{
_zhongTianCpDataService = zhongTianCpDataService;
_mapper = mapper;
}
public List GetCpEquips(GetEquipsRequest reqEntity, CSRedisClient CSRedisClient)
{
var real = new List();
var list = _zhongTianCpDataService.GetCpEquips(reqEntity);
var srm = CSRedisClient.Get("Cp:SrmStatus");
if (srm == null) return real;
var msgdto = JsonConvert.DeserializeObject>(srm);
foreach (var item in msgdto)
{
EquipDto equip = new EquipDto();
switch (item.Item1)
{
case "SRM1":
if (item.Item2 == "Automatic")
{
equip.EquipState = "1";
equip.Code = "SRM1";
equip.ResidueTask = list.Where(p => p.Tunnel == "1").Count();
}
else if (item.Item2 == "Manual")
{
equip.EquipState = "2";
equip.Code = "SRM1";
equip.ResidueTask = list.Where(p => p.Tunnel == "1").Count();
}
else
{
equip.EquipState = "3";
equip.Code = "SRM1";
equip.ResidueTask = list.Where(p => p.Tunnel == "1").Count();
}
real.Add(equip);
break;
case "SRM2":
if (item.Item2 == "Automatic")
{
equip.EquipState = "1";
equip.Code = "SRM2";
equip.ResidueTask = list.Where(p => p.Tunnel == "2").Count();
}
else if (item.Item2 == "Manual")
{
equip.EquipState = "2";
equip.Code = "SRM2";
equip.ResidueTask = list.Where(p => p.Tunnel == "2").Count();
}
else
{
equip.EquipState = "3";
equip.Code = "SRM2";
equip.ResidueTask = list.Where(p => p.Tunnel == "2").Count();
}
real.Add(equip);
break;
case "SRM3":
if (item.Item2 == "Automatic")
{
equip.EquipState = "1";
equip.Code = "SRM3";
equip.ResidueTask = list.Where(p => p.Tunnel == "3").Count();
}
else if (item.Item2 == "Manual")
{
equip.EquipState = "2";
equip.Code = "SRM3";
equip.ResidueTask = list.Where(p => p.Tunnel == "3").Count();
}
else
{
equip.EquipState = "3";
equip.Code = "SRM3";
equip.ResidueTask = list.Where(p => p.Tunnel == "3").Count();
}
real.Add(equip);
break;
case "SRM4":
if (item.Item2 == "Automatic")
{
equip.EquipState = "1";
equip.Code = "SRM4";
equip.ResidueTask = list.Where(p => p.Tunnel == "4").Count();
}
else if (item.Item2 == "Manual")
{
equip.EquipState = "2";
equip.Code = "SRM4";
equip.ResidueTask = list.Where(p => p.Tunnel == "4").Count();
}
else
{
equip.EquipState = "3";
equip.Code = "SRM4";
equip.ResidueTask = list.Where(p => p.Tunnel == "4").Count();
}
real.Add(equip);
break;
case "SRM5":
if (item.Item2 == "Automatic")
{
equip.EquipState = "1";
equip.Code = "SRM5";
equip.ResidueTask = list.Where(p => p.Tunnel == "5").Count();
}
else if (item.Item2 == "Manual")
{
equip.EquipState = "2";
equip.Code = "SRM5";
equip.ResidueTask = list.Where(p => p.Tunnel == "5").Count();
}
else
{
equip.EquipState = "3";
equip.Code = "SRM5";
equip.ResidueTask = list.Where(p => p.Tunnel == "5").Count();
}
real.Add(equip);
break;
default:
break;
}
}
return real.OrderBy(p => p.Code).ToList();
}
///
/// 获取成品任务信息
///
///
///
public List GetCpTaskInfo(GetWcsTaskInfoRequest ReqEntity)
{
List taskInfoDtos = new List();
taskInfoDtos = _zhongTianCpDataService.GetCpRunWcsTaskInfo(ReqEntity);
return taskInfoDtos;
}
public List GetCpBillList(GetWorkPlanBillListRequest reqEntity)
{
var list = _zhongTianCpDataService.GetCpBillList(reqEntity);
return list;
}
public PageResult GetCpLocationUsageViewList()
{
var result = new PageResult() { ReturnValue = new List() };
var list = _zhongTianCpDataService.GetCpLocationUsageReportList();
result.ReturnValue = list.ToList();
result.ItemGroupSum = new List() {
new ItemGroup(){ UnitName="总货位",qty=list.Sum(s=>s.AllLocationTotal)},
new ItemGroup(){ UnitName="有效货位",qty=list.Sum(s=>s.CanUseLocation)},
new ItemGroup(){ UnitName="空余货位",qty=list.Sum(s=>s.SpareLocation)},
new ItemGroup(){ UnitName="锁定货位",qty=list.Sum(s=>s.LockLocation)},
new ItemGroup(){ UnitName="停用货位",qty=list.Sum(s=>s.StopLocation)},
new ItemGroup(){ UnitName="有料货位",qty=list.Sum(s=>s.MaterilLocation)},
new ItemGroup(){ UnitName="有容器货位",qty=list.Sum(s=>s.ContainLocation)}
};
return result;
}
public List GetTrayProductList()
{
List res = new List();
var list = _zhongTianCpDataService.GetTrayProductList();
res.Add(new ItemVal() { Name = "空托盘", Value = list.Where(p => p.ContGrpType == 2).Any() ? list.Where(p => p.ContGrpType == 2).Count() : 0 });
res.Add(new ItemVal() { Name = "中间隔板", Value = list.Where(p => p.ContGrpType == 3).Any() ? list.Where(p => p.ContGrpType == 3).Count() : 0 });
res.Add(new ItemVal() { Name = "成品", Value = list.Where(p => p.ContGrpType == 1).Any() ? list.Where(p => p.ContGrpType == 1).Count() : 0 });
var locationslists = _zhongTianCpDataService.GetLocationList();
res.Add(new ItemVal() { Name = "空位", Value = locationslists.Where(p => p.StateNum == 1 && p.IsStop == 0).Any() ? locationslists.Where(p => p.StateNum == 1 && p.IsStop == 0).Count() : 0 });
return res;
}
public List GetWarningQtyList(MySettings mySettings)
{
List res = new List();
var list = _zhongTianCpDataService.GetTrayProductList();
var qty = list.Where(p => p.ContGrpType == 2).Any() ? list.Where(p => p.ContGrpType == 2).Count() : 0;
res.Add(new WarningQtyModel()
{
Name = "空托盘",
Qty = qty,
WarnQty = mySettings.MaternalCareWarning
});
qty = list.Where(p => p.ContGrpType == 3).Any() ? list.Where(p => p.ContGrpType == 3).Count() : 0;
res.Add(new WarningQtyModel() { Name = "中间隔板", Qty = qty,WarnQty=mySettings.PartitionWarning });
var locationslists = _zhongTianCpDataService.GetLocationList();
qty = locationslists.Where(p => p.StateNum == 1 && p.IsStop == 0).Any() ? locationslists.Where(p => p.StateNum == 1 && p.IsStop == 0).Count() : 0;
res.Add(new WarningQtyModel() { Name = "空位", Qty =qty,WarnQty=mySettings.VacancyWarning });
return res;
}
///
/// 获取产品信息
///
///
public DeliveryDetails GetProductInfoList()
{
var value=RedisHelper.Get("Cp:ProductTaskInfos");
var productInfoListRequset = JsonConvert.DeserializeObject>(value);
var dataInfo=_zhongTianCpDataService.GetProductInfoList(productInfoListRequset);
return dataInfo;
}
}
}