using AutoMapper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
using System.Text;
using WCS.FJ.Protocol.DataStructure;
using Wms.Screen.DataService.Impl;
using Wms.Screen.DataService.Interface;
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;
using Wms.Screen.Util.Extensions;
namespace Wms.Screen.Service.Service
{
///
/// 分拣
///
public class ZhongTianFjService : IZhongTianFjService
{
private IZhongTianFjDataService _zhongTianFjDataService;
private IMapper _mapper;
Dictionary> _dicDevices;
private readonly FreeRedis.RedisClient _freeRedisClient;
static Dictionary FjEquipsValues = new Dictionary
{
{ "SRM","堆垛机"}, { "RGV","RGV"}, { "Robot","机械手"}, { "Truss","桁架"},
};
public ZhongTianFjService(IZhongTianFjDataService zhongTianFjDataService, IMapper mapper, Dictionary> dicDevices, FreeRedis.RedisClient freeRedisClient)
{
_zhongTianFjDataService = zhongTianFjDataService;
_mapper = mapper;
_dicDevices = dicDevices;
_freeRedisClient = freeRedisClient;
}
public List GetFjEquips(GetEquipsRequest reqEntity)
{
var real = new List();
var list = _zhongTianFjDataService.GetFjEquips(reqEntity);
_dicDevices.TryGetValue(reqEntity.WarehouseCodeList[1], out var deviceslists);
var status = _freeRedisClient.Get("Sorting:EquipmentStatus");
if (!string.IsNullOrWhiteSpace(status) && status != "[]")
{
var dtolist = JsonConvert.DeserializeObject>(status);
foreach (var item in FjEquipsValues.Keys)
{
FJEquipDto fJEquipDto = new FJEquipDto();
foreach (var device in deviceslists)
{
if (device.Contains(item))
{
fJEquipDto.Title = FjEquipsValues[item];
var dto = dtolist?.FirstOrDefault(o => o.Code == device);
fJEquipDto.Data.Add(new EquipDto()
{
Code = device,
EquipState = dto != null && dto.Time.Date == DateTime.Now.Date ? EquipStatus( dto.Status) : "3",
ResidueTask = list.Where(o => o.Device == device).Count()
});
}
}
real.Add(fJEquipDto);
}
}
return real;
}
private string EquipStatus(string status)
{
if (status == "3")//报警
{
return "3";
}
else if(status == "4" || status == "5") //维护 手动
{
return "2";
}
else
{
return "1";
}
}
public List GetFjTaskInfo(GetWcsTaskInfoRequest ReqEntity)
{
List taskInfoDtos = new List();
taskInfoDtos = _zhongTianFjDataService.GetFjRunWcsTaskInfo(ReqEntity);
var Len = _freeRedisClient.LLen("Packs");
var dataPack = _freeRedisClient.LIndex("Packs", Len - 1);
return taskInfoDtos;
}
public List GetFjStackInfo(GetWorkPlanBillListRequest reqEntity)
{
var list = _zhongTianFjDataService.GetFjStackInfo(reqEntity);
return list;
}
public PageResult GetFjLocationUsageViewList(string warehouse)
{
var result = new PageResult() { ReturnValue = new List() };
var list = _zhongTianFjDataService.GetFjLocationUsageReportList(warehouse);
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 GetMantuoBarCodeRate(string warehouse)
{
return _zhongTianFjDataService.GetMantuoBarCodeRate(warehouse);
}
public List GetBomSetGrpCurrentMaterialRateList(string warehouse)
{
return _zhongTianFjDataService.GetBomSetGrpCurrentMaterialRateList(warehouse);
}
public List GetLocaitonList(string warehouse)
{
List res = new List();
var list = _zhongTianFjDataService.GetLocationList(warehouse);
res.Add(new ItemVal() { Name = "空", Value = list.Where(p => p.StateNum == 1).Any() ? list.Where(p => p.StateNum == 1).Count() : 0 });
res.Add(new ItemVal() { Name = "满", Value = list.Where(p => p.StateNum == 2).Any() ? list.Where(p => p.StateNum == 2).Count() : 0 });
res.Add(new ItemVal() { Name = "锁定", Value = list.Where(p => p.StateNum == 3 || p.StateNum == 4).Any() ? list.Where(p => p.StateNum == 3 || p.StateNum == 4).Count() : 0 });
res.Add(new ItemVal() { Name = "禁用", Value = list.Where(p => p.IsStop == 1).Any() ? list.Where(p => p.IsStop == 1).Count() : 0 });
return res;
}
public GetFullWeightDistRes GetInvSetGrpList()
{
GetFullWeightDistRes res = new GetFullWeightDistRes() { xData = new List(), yData = new List() };
List listtemp = new List();
var list = _zhongTianFjDataService.GetInvSetGrpList();
foreach (var item in list)
{
res.xData.Add(item.SetGrpCode);
res.yData.Add(item.Qty);
}
return res;
}
public GeFJHistoryTaskInfoRes GeHistoryTaskInfo(GeFJHistoryTaskInfoRequest request)
{
GeFJHistoryTaskInfoRes res = new GeFJHistoryTaskInfoRes();
var lists = _zhongTianFjDataService.GeHistoryTaskInfo(request);
string[] XAxis = new string[7]; //lists.OrderBy(o => o.CreateTime).Select(o => o.CreateTime.ToString("M-dd")).Distinct().ToArray();
int[] Outints = new int[7];
int[] EnterDepots = new int[7];
int[] TransferDepots = new int[7];
int[] SetPlate = new int[7];
for (int i = 0; i < (request.EndTime - request.StartTime).TotalDays; i++)
{
var date = request.StartTime.AddDays(i);
XAxis[i] = date.ToString("yyyy-MM-dd");
Outints[i] = lists.Where(o => o.BusType == "车间叫料" && o.CreateTime.Date == date.Date).Sum(o => o.Count);
EnterDepots[i] = lists.Where(o => o.BusType == "码垛入库" && o.CreateTime.Date == date.Date).Sum(o => o.Count);
SetPlate[i] = lists.Where(o => o.Type == (int)TaskType.SetPlate && o.CreateTime.Date == date.Date).Sum(o => o.Count);
}
res.DateList.AddRange(XAxis);
res.StockInList.AddRange(EnterDepots);
res.StockOutList.AddRange(Outints);
res.SetPlateList.AddRange(SetPlate);
return res;
}
}
}