using AutoMapper; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; 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.SqlSugar.ZhongTian; using Wms.Screen.Util.Extensions; namespace Wms.Screen.Service.Service { public class ZhongTianHjService : IZhongTianHjService { private readonly IZhongTianHjDataService _zhongTianHjDataService; private readonly IMapper _mapper; public ZhongTianHjService(IMapper mapper, IZhongTianHjDataService zhongTianHjDataService) { _mapper = mapper; _zhongTianHjDataService = zhongTianHjDataService; } public List GetHjEquips(GetEquipsRequest reqEntity) { var real = new List(); var list = _zhongTianHjDataService.GetHjEquips(reqEntity); var tun1 = list.Where(p => p.Tunnel == "1").Count(); var tun2 = list.Where(p => p.Tunnel == "2").Count(); var tun3 = list.Where(p => p.Tunnel == "3").Count(); var srm = RedisHelper.Get("Alloy:SrmStatus"); var msgdto = JsonConvert.DeserializeObject>(srm); foreach (var item in msgdto) { EquipDto equip = new EquipDto(); if (item.Item1 == "SRM3") { if (item.Item2 == "Automatic") { equip.EquipState = "1"; equip.Code = "SRM3"; equip.ResidueTask = tun3; } else if (item.Item2 == "Manual") { equip.EquipState = "2"; equip.Code = "SRM3"; equip.ResidueTask = tun3; } else { equip.EquipState = "3"; equip.Code = "SRM3"; equip.ResidueTask = tun3; } } else if (item.Item1 == "SRM2") { if (item.Item2 == "Automatic") { equip.EquipState = "1"; equip.Code = "SRM2"; equip.ResidueTask = tun2; } else if (item.Item2 == "Manual") { equip.EquipState = "2"; equip.Code = "SRM2"; equip.ResidueTask = tun2; } else { equip.EquipState = "3"; equip.Code = "SRM2"; equip.ResidueTask = tun2; } } else if (item.Item1 == "SRM1") { if (item.Item2 == "Automatic") { equip.EquipState = "1"; equip.Code = "SRM1"; equip.ResidueTask = tun1; } else if (item.Item2 == "Manual") { equip.EquipState = "2"; equip.Code = "SRM1"; equip.ResidueTask = tun1; } else { equip.EquipState = "3"; equip.Code = "SRM1"; equip.ResidueTask = tun1; } } else { continue; } real.Add(equip); } return real; } /// /// 获取合金任务货位分布 /// /// /// public List GetLocaitonList() { List res = new List(); var list = _zhongTianHjDataService.GetLocationList(); 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 List GetEmptyFullDist() { List res = new List(); var list = _zhongTianHjDataService.GetBillInvnowList(); 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 == 1).Any() ? list.Where(p => p.ContGrpType == 1).Count() : 0 }); return res; } public List GetTunelCountList() { List res = new List(); var list = _zhongTianHjDataService.GetTunelCountList(); foreach (var item in list) { if (item.Tunnel.HasValue) { res.Add(new ItemVal() { Name = item.Tunnel + "巷道" + (item.ContGrpType == 2 ? "空轮" : "满轮"), Value = item.Qty }); } } return res; } /// /// 获取历史任务信息 /// /// /// public GeHistoryTaskInfoRes GeHistoryTaskInfo(GeHistoryTaskInfoRequest ReqEntity) { GeHistoryTaskInfoRes res = new GeHistoryTaskInfoRes(); var list = _zhongTianHjDataService.GeHistoryTaskInfo(ReqEntity); res.DateList = new List() { DateTime.Now.AddDays(-6).ToShortDateString(), DateTime.Now.AddDays(-5).ToShortDateString(),DateTime.Now.AddDays(-4).ToShortDateString(),DateTime.Now.AddDays(-3).ToShortDateString(), DateTime.Now.AddDays(-2).ToShortDateString(),DateTime.Now.AddDays(-1).ToShortDateString(),DateTime.Now.ToShortDateString()}; res.StockInList = new List() { list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-6).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-6).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-5).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-5).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-4).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-4).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-3).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-3).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-2).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-2).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-1).Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.AddDays(-1).Date).Count():0 , list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.Date).Any() ? list.Where(p=>p.BusType == "镀铜一楼取满" && p.AddTime.Date == DateTime.Now.Date).Count():0 , }; res.StockOutList = new List() { list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-6).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-6).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-5).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-5).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-4).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-4).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-3).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-3).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-2).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-2).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-1).Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.AddDays(-1).Date).Count():0 , list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.Date).Any() ? list.Where(p=>p.BusType == "二楼湿拉自动叫料出库" && p.AddTime.Date == DateTime.Now.Date).Count():0 , }; return res; } /// /// 获取合金任务信息 /// /// /// public List GetHjTaskInfo(GetWcsTaskInfoRequest ReqEntity) { List taskInfoDtos = new List(); taskInfoDtos = _zhongTianHjDataService.GetHjRunWcsTaskInfo(ReqEntity); return taskInfoDtos; } /// /// 获取合金重量轮分布 /// /// /// public GetFullWeightDistRes GetFullWeightDist() { GetFullWeightDistRes res = new GetFullWeightDistRes() { xData = new List(), yData = new List() }; List listtemp = new List(); var list = _zhongTianHjDataService.GetBillInvnowList().Where(p => p.ContGrpType == 1 && p.InvStateCode == "InvEcecState_In"); foreach (var item in list.GroupBy(p => p.MatCode)) { res.xData.Add(item.Key); res.yData.Add(item.Sum(q => q.NetWQty)); } return res; } public List GetHjBillList(GetWorkPlanBillListRequest reqEntity) { var list = _zhongTianHjDataService.GetHjBillList(reqEntity); if (list.Any()) { foreach (var item in list) { if (item.TypeCode == DocType.DocType_HJ_CopperProductStockIn.GetHashCode().ToString()) { item.TypeCode = DocType.DocType_HJ_CopperProductStockIn.GetDescription(); } else if (item.TypeCode == DocType.DocType_HJ_WetLinePickMaterApply.GetHashCode().ToString()) { item.TypeCode = DocType.DocType_HJ_WetLinePickMaterApply.GetDescription(); } else if (item.TypeCode == DocType.DocType_HJ_WetLineBack.GetHashCode().ToString()) { item.TypeCode = DocType.DocType_HJ_WetLineBack.GetDescription(); } else if (item.TypeCode == DocType.DocType_HJ_WetLineLeft.GetHashCode().ToString()) { item.TypeCode = DocType.DocType_HJ_WetLineLeft.GetDescription(); } } } return list; } public Result GetEmtpyLocationCountByTunnel(List tunnels, int size) { var result = new Result() { ReturnValue = 0 }; //var model = _zhongTianHjDataService.GetEmtpyLocationCountByTunnel(tunnels, size); //result.ReturnValue = model; return result; } public Result GetRuningInTaskCountByTunnel(int tunnel, string warehousecode, int size) { var result = new Result() { ReturnValue = 0 }; var model = _zhongTianHjDataService.GetRuningInTaskCountByTunnel(tunnel, warehousecode, size); if (model != null) { result.ReturnValue = model; } return result; } public PageResult GetHjLocationUsageViewList() { var result = new PageResult() { ReturnValue = new List() }; //查询巷道的禁用/启用信息 //var configTunnelList = _zhongTianHjDataService.GetTunnelConfigList(new DetailCodeRequest() { Code = "" })?.ReturnValue; var list = _zhongTianHjDataService.GetHjLocationUsageReportList(); //if (configTunnelList != null && configTunnelList.Any()) //{ // //更新巷道状态 // list.ForEach(s => // { // var conf = configTunnelList.Where(m => m.WarehouseName == s.WarehouseName && m.Tunnel == s.Tunnel.Substring(0, 1)).FirstOrDefault(); // if (conf != null) // { // s.InStates = conf.InStates; // s.OutStates = conf.OutStates; // } // }); //} 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; } } }