using System; using System.Collections.Generic; using System.Linq; using HH.WCS.Mobox3.HD.util; using SqlSugar; using HH.WCS.Mobox3.HD.models; using HH.WCS.Mobox3.HD.wms; using static HH.WCS.Mobox3.HD.api.DigitHelper; using static HH.WCS.Mobox3.HD.api.DigitHelper.GJSpecStatisticData; using System.Reflection; using HH.WCS.Mobox3.HD.device; using static HH.WCS.Mobox3.HD.core.Monitor; using Newtonsoft.Json; using static HH.WCS.Mobox3.HD.api.WmsController; namespace HH.WCS.Mobox3.HD.api { public class DigitHelper { /// /// 1.查询当前备货区所有成品信息 /// /// /// public static List queryAllFinishProduct(AreaModel model) { BaseItemInfo itemInfo = new BaseItemInfo(); var db = new SqlHelper().GetInstance(); List itemInfoList = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == model.areaCode && l.N_CURRENT_NUM > 0) .Select( (l, lc, ci) => new BaseItemInfo { areaCode = l.S_AREA_CODE, trayCode = lc.S_CNTR_CODE, locCode = l.S_CODE, workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, dePartNo = ci.S_DEPART_NO, partDrawNo = ci.S_PARTDRAW_NO, partName = ci.S_PART_NAME, itemCode = ci.S_ITEM_CODE, itemName = ci.S_ITEM_NAME, weight = ci.F_WEIGHT, quantity = ci.F_QTY, } ).ToList(); return itemInfoList; } /// /// 2.查询三个立体库的汇总数据 /// /// public static LTKSummaryData queryLTKSummaryData() { LTKSummaryData summaryData = new LTKSummaryData(); var db = new SqlHelper().GetInstance(); List areaCodes = Settings.getStoreAreaCodes(0, 1); var query = db.Queryable().Where(a => areaCodes.Contains(a.S_AREA_CODE)); int sum = query.Count(); // 三个立体库总货位数 int usageNum = query.Where(a => a.N_CURRENT_NUM > 0).Count(); // 三个立体库总共已使用库位数 double usageRate = Math.Round((double)usageNum / sum * 100, 2); //三个立体库库位使用率(=已使用库位数/总库位数) int semiProdNum = 0; double semiProdProp = 0; { //三个立体库合计半成品所占库位数 semiProdNum = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && ci.S_ITEM_TYPE == "半成品").Count(); //个立体库合计半成品所占库位数在总体中占比 semiProdProp = Math.Round((double)semiProdNum / sum * 100, 2); } int finishProdNum = 0; double finishProdProp; { //三个立体库合计成品所占库位数 finishProdNum = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && ci.S_ITEM_TYPE == "成品").Count(); ; //三个立体库合计成品所占库位数在总体中占比 finishProdProp = Math.Round((double)finishProdNum / sum * 100, 2); } summaryData.sum = sum; summaryData.usageNum = usageNum; summaryData.usageRate = usageRate + "%"; summaryData.semiProdNum = semiProdNum; summaryData.semiProdProp = semiProdProp + "%"; summaryData.finishProdNum = finishProdNum; summaryData.finishProdProp = finishProdProp + "%"; return summaryData; } /// /// 3.按图号汇总成品、半成品所占库位数量列表 /// /// public static List queryLTKWorkNoSummaryData1(ItemTypeModel model) { var db = new SqlHelper().GetInstance(); // 三个立体库总货位数 List areaCodes = Settings.getStoreAreaCodes(0, 1); List workSummaryDatas = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE && ci.S_ITEM_TYPE == model.itemType) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && ci.S_ITEM_TYPE == model.itemType) .GroupBy((l, lc, ci) => new { ci.S_WORK_NO, ci.S_WORK_NAME }) .Select( (l, lc, ci) => new WorkNoSummaryData() { workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, amount = SqlFunc.AggregateCount(ci.S_WORK_NO) } ) .MergeTable() .OrderByDescending(a => a.amount) .Take(5) .ToList(); if (workSummaryDatas != null && workSummaryDatas.Count > 0) { float sum = workSummaryDatas.Sum(a => a.amount); foreach (var item in workSummaryDatas) { item.proportion = Math.Round((double)item.amount / sum * 100, 2) + "%"; } } return workSummaryDatas; } /// /// 4.按工作号汇总成品、半成品所占库位数量、占比 /// /// public static List queryLTKWorkNoSummaryData() { var db = new SqlHelper().GetInstance(); // 三个立体库总货位数 List areaCodes = Settings.getStoreAreaCodes(0, 1); List summaryDatas = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 ) .GroupBy((l, lc, ci) => new { ci.S_WORK_NO, ci.S_WORK_NAME }) .Select( (l, lc, ci) => new WorkNoSummaryData() { workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, amount = SqlFunc.AggregateCount(ci.S_PARTDRAW_NO) } ) .MergeTable() .OrderByDescending(a => a.amount) .Take(5) .ToList(); if (summaryDatas != null && summaryDatas.Count > 0) { float sum = summaryDatas.Sum(a => a.amount); foreach (var item in summaryDatas) { item.proportion = Math.Round((double)item.amount / sum * 100, 2) + "%"; } } return summaryDatas; } /// /// 4.1.按工作号汇总成品、半成品所占库位数量、占比 /// /// public static List queryWorkNoAndItemTypeLTKSummaryData(AreaModel model) { var db = new SqlHelper().GetInstance(); // 三个立体库总货位数 List areaCodes = Settings.getStoreAreaCodes(0, 1); var queryable = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.N_CURRENT_NUM > 0); if (model.areaCode == null) { queryable = queryable.Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE)); } else { queryable = queryable.Where((l, lc, ci) => l.S_AREA_CODE == model.areaCode); } List summaryDatas = queryable .GroupBy((l, lc, ci) => new { l.S_AREA_CODE, ci.S_WORK_NO, ci.S_ITEM_TYPE }) .Select( (l, lc, ci) => new WorkNoSummaryData() { areaCode = l.S_AREA_CODE, workNo = ci.S_WORK_NO, type = ci.S_ITEM_TYPE, amount = SqlFunc.AggregateCount(ci.S_PARTDRAW_NO) } ) .MergeTable() .OrderByDescending(a => a.amount) .ToList(); if (summaryDatas != null && summaryDatas.Count > 0) { float sum = summaryDatas.Sum(a => a.amount); foreach (var item in summaryDatas) { item.areaName = LocationHelper.GetArea(item.areaCode).S_NAME; item.proportion = Math.Round((double)item.amount / sum * 100, 2) + "%"; } } return summaryDatas; } /// /// 5.根据在库时长汇总成品、半成品的所占库位数量 /// /// public static StorageTimeSummaryData storageTimeSummary() { StorageTimeSummaryData summaryData = new StorageTimeSummaryData(); var db = new SqlHelper().GetInstance(); // 三个立体库总货位数 List areaCodes = Settings.getStoreAreaCodes(0, 1); var query = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE)); int sum = query.Count(); // 总库位数 int usageNum = query.Where((l, lc, ci) => l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")).Count(); // 使用数 string usageRate = Math.Round((double)usageNum / sum * 100, 2) + "%"; // 使用率 int amountA = 0; string proportionA = null; { var queryWrapper = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")); amountA = queryWrapper.Where("DATEDIFF(day, l.T_FULL_TIME, GETDATE()) <= 7").Count(); proportionA = Math.Round((double)amountA / sum * 100, 2) + "%"; } int amountB = 0; string proportionB = null; { var queryWrapper = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")); amountB = queryWrapper.Where("DATEDIFF(day, l.T_FULL_TIME, GETDATE()) > 7 and DATEDIFF(day, T_FULL_TIME, GETDATE()) <= 15").Count(); proportionB = Math.Round((double)amountB / sum * 100, 2) + "%"; } int amountC = 0; string proportionC = null; { var queryWrapper = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")); amountC = queryWrapper.Where("DATEDIFF(day, l.T_FULL_TIME, GETDATE()) > 15 and DATEDIFF(day, T_FULL_TIME, GETDATE()) <= 30").Count(); proportionC = Math.Round((double)amountC / sum * 100, 2) + "%"; } int amountD = 0; string proportionD = null; { var queryWrapper = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")); amountD = queryWrapper.Where("DATEDIFF(day, l.T_FULL_TIME, GETDATE()) > 30 and DATEDIFF(day, T_FULL_TIME, GETDATE()) <= 90").Count(); proportionD = Math.Round((double)amountD / sum * 100, 2) + "%"; } int amountE = 0; string proportionE = null; { var queryWrapper = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => areaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0 && (ci.S_ITEM_TYPE == "成品" || ci.S_ITEM_TYPE == "半成品")); amountE = queryWrapper.Where("DATEDIFF(day, l.T_FULL_TIME, GETDATE()) > 90").Count(); proportionE = Math.Round((double)amountE / sum * 100, 2) + "%"; } summaryData.sum = sum; summaryData.usageNum = usageNum; summaryData.usageRate = usageRate; summaryData.amountA = amountA; summaryData.proportionA = proportionA; summaryData.amountB = amountB; summaryData.proportionB = proportionB; summaryData.amountC = amountC; summaryData.proportionC = proportionC; summaryData.amountD = amountD; summaryData.proportionD = proportionD; summaryData.amountE = amountE; summaryData.proportionE = proportionE; return summaryData; } /// /// 6.按图号汇总三个立体库的出库(入库)数量和占比 /// /// public static List outInStockDrawNoSummary(ActModel actModel) { var db = new SqlHelper().GetInstance(); // 三个立体库总货位数 List areaCodes = Settings.getStoreAreaCodes(0, 1); var query = db.Queryable().Where(a => areaCodes.Contains(a.S_AREA_CODE)); DateTime date = DateTime.Parse(actModel.dataDate).Date; string sql = null; if (actModel.actType.Equals("入库")) { sql = "CONVERT(date, T_IN_TIME) = @date"; } else { sql = "CONVERT(date, T_OUT_TIME) = @date"; } List drawSummaryDatas = query.Where(sql, new { date }).GroupBy(a => new { a.S_PARTDRAW_NO, a.S_PART_NAME ,a.S_WORK_NO }) .Select( a => new DrawSummaryData() { partDrawNo = a.S_PARTDRAW_NO, partName = a.S_PART_NAME, workNo = a.S_WORK_NO, amount = SqlFunc.AggregateCount(a.S_PARTDRAW_NO) } ).OrderByDescending(a => a.amount).Take(5).ToList(); if (drawSummaryDatas != null && drawSummaryDatas.Count > 0) { float sum = drawSummaryDatas.Sum(a => a.amount); foreach (var item in drawSummaryDatas) { if (item.partDrawNo == null) { drawSummaryDatas.Remove(item); continue; } item.proportion = Math.Round((double)item.amount / sum * 100, 2) + "%"; } } return drawSummaryDatas; } /// /// 7.查询今日出厂的成品信息 /// /// public static List queryOutFactoryFinishProdList(DateModel model) { var db = new SqlHelper().GetInstance(); DateTime date = DateTime.Parse(model.dataDate).Date; List areaCodes = Settings.getDispatchAreaCodes(); var query = db.Queryable().Where(a => areaCodes.Contains(a.S_AREA_CODE)); List outStockDatas = new List(); { outStockDatas = query.Where("CONVERT(date, T_OUT_TIME) = @date", new { date }).GroupBy(a => new { a.S_WORK_NO, a.S_WORK_NAME, a.S_DEPART_NO }) .Select( a => new WorkNoOutStockData() { workNo = a.S_WORK_NO, workName = a.S_WORK_NAME, dePartNo = a.S_DEPART_NO, quantity = SqlFunc.AggregateSumNoNull(a.F_QTY), weight = SqlFunc.AggregateSumNoNull(a.F_WEIGHT) } ).ToList(); } foreach (var item in outStockDatas) { item.accuQuantity = db.Queryable().Where(a => areaCodes.Contains(a.S_AREA_CODE) && a.S_ACT_TYPE == "出库" && a.S_WORK_NO == item.workNo).Sum(a => a.F_QTY); } return outStockDatas; } /// /// 8.查询当前立体库汇总数据 /// /// public static AreaSummaryData queryLTKAreaSummaryData(AreaModel model) { AreaSummaryData areaSummaryData = new AreaSummaryData(); var db = new SqlHelper().GetInstance(); var query = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode); { int sum = query.Count(); int usageNum = query.Where(a => a.N_CURRENT_NUM > 0).Count(); double usageRate = Math.Round((double)usageNum / sum * 100, 2); areaSummaryData.sum = sum; areaSummaryData.usageNum = usageNum; areaSummaryData.usageRate = usageRate.ToString(); } List summaryDatas = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.N_CURRENT_NUM > 0 && ci.S_ITEM_TYPE == "成品" && l.S_AREA_CODE == model.areaCode) .GroupBy((l, lc, ci) => new { ci.S_WORK_NO, ci.S_WORK_NAME }) .Select( (l, lc, ci) => new WorkNoSummaryData() { workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, amount = SqlFunc.AggregateCount(ci.S_PARTDRAW_NO) } ) .MergeTable() .OrderByDescending(a => a.amount) .Take(5) .ToList(); areaSummaryData.workNoSummaryData = summaryDatas; return areaSummaryData; } /// /// 9.查询出入库信息汇总 /// /// public static List outInStackSummary(OutInStockModel model) { var db = new SqlHelper().GetInstance(); DateTime date = DateTime.Parse(model.dataDate).Date; var query = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode && a.S_ACT_TYPE == model.actType); List outStockDatas = new List(); { outStockDatas = query.Where("(CONVERT(date, T_OUT_TIME) = @date or CONVERT(date, T_IN_TIME) = @date)", new { date }).GroupBy(a => new { a.S_WORK_NO }) .Where(a => a.S_WORK_NO != null) .Select( a => new DrawSummaryData() { workNo = a.S_WORK_NO, amount = SqlFunc.AggregateCount(a.S_CODE), } ).ToList(); } return outStockDatas; } /// /// 10.查询当前执行中和待执行任务列表汇总 /// /// public static List queryProceedTaskList(AreaModel model) { var db = new SqlHelper().GetInstance(); List wcsTasks = db.Queryable().Where(a => (a.S_START_AREA == model.areaCode || a.S_END_AREA == model.areaCode) && a.N_B_STATE < 3).OrderByDescending(a => a.T_CREATE).Take(10).ToList(); List proceedTasks = new List(); foreach (var item in wcsTasks) { ProceedTaskData proceedTask = new ProceedTaskData() { taskType = item.S_TYPE, taskStatus = item.S_B_STATE, }; var cntrItemRels = ItemHelper.GetCntrItemByCntrCode(item.S_CNTR_CODE); if (cntrItemRels != null && cntrItemRels.Count > 0) { proceedTask.prodName = cntrItemRels[0].S_WORK_NAME; proceedTask.quantity = cntrItemRels[0].F_QTY; } proceedTasks.Add(proceedTask); } return proceedTasks; } /// /// 11.查询库位数据 /// /// public static AreaLocData queryAreaLocData(AreaModel model) { AreaLocData areaLocData = new AreaLocData(); var db = new SqlHelper().GetInstance(); var rows = db.Queryable() .Where(a => a.S_AREA_CODE == model.areaCode) .GroupBy(l => new { l.N_ROW, l.N_LAYER }) .OrderBy(a => new { a.N_ROW, a.N_LAYER }) .Select(g => new { row = g.N_ROW, layer = g.N_LAYER, }).ToList(); Dictionary areaData = new Dictionary(); if (rows.Count > 0) { rows.ForEach(it => { string locData = ""; List locList = db.Queryable() .Where(a => a.S_AREA_CODE == model.areaCode && a.N_ROW == it.row && a.N_LAYER == it.layer) .OrderBy(a => new { a.N_COL }) .ToList(); if (locList.Count > 0) { foreach (var loc in locList) { if (loc.N_CURRENT_NUM > 0) { var locCntrs = LocationHelper.GetLocCntr(loc.S_CODE); if (locCntrs.Count > 0) { var cntrItemRels = ContainerHelper.GetCntrItemRel(locCntrs[0].S_CNTR_CODE); if (cntrItemRels.Count > 0) { string workNo = cntrItemRels[0].S_WORK_NO; if (workNo != null) { if (workNo.Contains("001")) { locData = locData + "4"; } else if (workNo.Contains("002")) { locData = locData + "2"; } else if (workNo.Contains("003")) { locData = locData + "3"; } else { locData = locData + "1"; } } else { locData = locData + "5"; } } else { locData = locData + "5"; } } else { locData = locData + "1"; } } else { locData = locData + "0"; } } areaData.Add(it.row + "-" + it.layer, locData); } }); var area = db.Queryable().Where(a => a.S_CODE == model.areaCode).First(); if (area != null) { areaLocData.areaCode = model.areaCode; areaLocData.areaName = area.S_NAME; areaLocData.areaData = areaData; } } return areaLocData; } /// /// 12.统计各库区库位总数、使用数量和使用率 /// /// public static List statisticsAllArea() { var db = new SqlHelper().GetInstance(); List areaSummaryDatas = db.Queryable().GroupBy(a => new { a.S_AREA_CODE }) .Select( a => new AreaSummaryData() { areaCode = a.S_AREA_CODE, sum = SqlFunc.AggregateCount(a.S_CODE), } ).ToList(); if (areaSummaryDatas != null && areaSummaryDatas.Count > 0) { foreach (var item in areaSummaryDatas) { var area = db.Queryable().Where(a => a.S_CODE == item.areaCode).First(); if (area == null) { continue; } item.areaName = area.S_NAME; item.usageNum = db.Queryable().Where(a => a.S_AREA_CODE == item.areaCode && a.N_CURRENT_NUM > 0).Count(); item.usageRate = Math.Round((double)item.usageNum / item.sum * 100, 2) + "%"; } } return areaSummaryDatas; } /// /// 13.查询立体库库位数据 /// /// public static LTKLocationData queryLTKLocData(LocModel model) { var db = new SqlHelper().GetInstance(); string areaName = db.Queryable().Where(a => a.S_CODE == model.areaCode).First().S_NAME; LTKLocationData locItemData = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == model.areaCode && l.S_CODE == model.locCode) .Select( (l, lc, ci) => new LTKLocationData() { areaName = areaName, areaCode = l.S_AREA_CODE, areaType = "立体库", trayCode = lc.S_CNTR_CODE, locCode = l.S_CODE, inStockTime = l.T_FULL_TIME, itemCode = ci.S_ITEM_CODE, itemName = ci.S_ITEM_NAME, itemType = ci.S_ITEM_TYPE, workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, dePartNo = ci.S_DEPART_NO, partDrawNo = ci.S_PARTDRAW_NO, partName = ci.S_PART_NAME, weight = ci.F_WEIGHT, quantity = ci.F_QTY } ) .First(); if (locItemData != null) { TimeSpan? storagDuration = DateTime.Now - locItemData.inStockTime; if (storagDuration != null) { locItemData.storagDuration = ((TimeSpan)storagDuration).Hours + "h"; } } return locItemData; } /// /// 14.查询钢卷库库位数据 /// /// public static GJKLocationData queryGJKLocData(LocModel model) { var db = new SqlHelper().GetInstance(); string areaName = db.Queryable().Where(a => a.S_CODE == model.areaCode).First().S_NAME; GJKLocationData locationData = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == model.areaCode && l.S_CODE == model.locCode) .Select( (l, lc, ci) => new GJKLocationData { areaName = areaName, areaCode = l.S_AREA_CODE, areaType = "钢卷库", locCode = l.S_CODE, inStockTime = l.T_FULL_TIME, itemCode = ci.S_ITEM_CODE, itemName = ci.S_ITEM_NAME, itemType = ci.S_ITEM_TYPE, workNo = ci.S_WORK_NO, workName = ci.S_WORK_NAME, coilNo = ci.S_COIL_NO, spec = ci.S_ITEM_SPEC, width = ci.S_WIDTH, heatNo = ci.S_HEAT_NO, shootNo = ci.S_SHOOT_NO, weight = ci.F_WEIGHT, quantity = ci.F_QTY, initWeight = ci.F_INIT_WEIGHT } ).First(); return locationData; } /// /// 15.查询模具库库位数据 /// /// public static MJKLocationData queryMJKLocData(LocModel model) { MJKLocationData locationData = null; var db = new SqlHelper().GetInstance(); string areaName = db.Queryable().Where(a => a.S_CODE == model.areaCode).First().S_NAME; Location location = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode && a.S_CODE == model.locCode).Includes(a => a.LocCntrRel, a => a.CntrItemRel).First(); if (location != null) { locationData = new MJKLocationData() { areaName = areaName, areaCode = model.areaCode, areaType = "模具库", locCode = location.S_CODE, }; if (location.LocCntrRel != null) { locationData.trayCode = location.LocCntrRel.S_CNTR_CODE; var mouldCntr = MouldHelper.GetMouldCntr(new MouldCntr() { S_CNTR_CODE = location.LocCntrRel.S_CNTR_CODE }); if (mouldCntr != null) { locationData.mouldNo = mouldCntr.S_MOULD_NO; } } } return locationData; } /// /// 16.查询钢卷库区汇总数据 /// /// public static List queryGJKAreaSummaryData(AreaListModel model) { List gjkAreaSummaryDatas = new List(); var db = new SqlHelper().GetInstance(); List gjAreaCodes = model.areaCodes; if (gjAreaCodes == null) { gjAreaCodes = Settings.getStoreAreaCodes(1, 2); } foreach (var areaCode in gjAreaCodes) { int stockNum = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == areaCode && l.N_CURRENT_NUM > 0 ).Count(); int intactNum = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == areaCode && l.N_CURRENT_NUM > 0 && ci.F_WEIGHT == ci.F_INIT_WEIGHT).Count(); int noIntactNum = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => l.S_AREA_CODE == areaCode && l.N_CURRENT_NUM > 0 && ci.F_WEIGHT != ci.F_INIT_WEIGHT).Count(); // 按钢卷号分组查询今日出库的最大钢卷重量(去除剪切位出库) var outCoilNoList = db.Queryable().Where(a => a.S_AREA_CODE == areaCode && a.S_LOC_CODE != "剪切货位" && a.S_ACT_TYPE == "出库").Where("(CONVERT(date, T_OUT_TIME) = @date)", new { DateTime.Parse(model.dataDate).Date }) .GroupBy(a => a.S_COIL_NO) .Select(group => new { S_COIL_NO = group.S_COIL_NO, F_WEIGHT = SqlFunc.AggregateMax(group.F_WEIGHT) }).ToList(); // 计算今日钢卷消耗量 float consumeWeight = 0; foreach (var item in outCoilNoList) { consumeWeight = consumeWeight + item.F_WEIGHT; } GJKAreaSummaryData locationData = new GJKAreaSummaryData() { areaCode = areaCode, stockNum = stockNum, intactNum = intactNum, noIntactNum = noIntactNum, consumeWeight = consumeWeight, dataDate = model.dataDate, }; gjkAreaSummaryDatas.Add(locationData); } return gjkAreaSummaryDatas; } /// /// 17.查询模具库区汇总数据 /// /// public static MJKAreaSummaryData queryMJKAreaSummaryData(AreaModel model) { var db = new SqlHelper().GetInstance(); int stockMouldNum = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode && a.N_CURRENT_NUM > 0).Count(); int lendMouldNum = db.Queryable().Where(a => a.S_ABLE_FLAG == "否").Count(); MJKAreaSummaryData areaSummaryData = new MJKAreaSummaryData() { stockMouldNum = stockMouldNum, lendMouldNum = lendMouldNum }; return areaSummaryData; } /* /// /// 18.查询发货库区汇总数据 /// /// public static FHQAreaSummaryData queryFHQAreaSummaryData(AreaModel model) { var db = new SqlHelper().GetInstance(); int finishProdNum = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode && a.N_CURRENT_NUM > 0).Count(); int lendMouldNum = db.Queryable().Where(a => a.S_ABLE_FLAG == "否").Count(); FHQAreaSummaryData areaSummaryData = new FHQAreaSummaryData() { finishProdNum = finishProdNum, occupyLocNum = lendMouldNum, leisureLocNum = lendMouldNum }; return areaSummaryData; }*/ /// /// 18.钢卷按规格分类统计 /// /// public static GJSpecStatisticData steelCoilSpecStatistic(AreaModel model) { GJSpecStatisticData gJSpecStatisticData = new GJSpecStatisticData(); var db = new SqlHelper().GetInstance(); List gjAreaCodes = new List(); if (model.areaCode == null) { gjAreaCodes = Settings.getStoreAreaCodes(1, 2); } else { gjAreaCodes.Add(model.areaCode); } int stockNum = db.Queryable().Where(a => gjAreaCodes.Contains(a.S_AREA_CODE) && a.N_CURRENT_NUM > 0).Count(); List gJSpecStatisticList = db.Queryable() .LeftJoin((l, lc) => l.S_CODE == lc.S_LOC_CODE) .LeftJoin((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) .Where((l, lc, ci) => gjAreaCodes.Contains(l.S_AREA_CODE) && l.N_CURRENT_NUM > 0) .GroupBy((l, lc, ci) => ci.S_ITEM_SPEC) .Select( (l, lc, ci) => new GJSpecTypeStatistic { coilSpec = ci.S_ITEM_SPEC, weight = SqlFunc.AggregateSum(ci.F_WEIGHT), proportion = SqlFunc.AggregateCount(l.S_CODE).ToString(), } ).ToList(); foreach (var item in gJSpecStatisticList) { item.proportion = Math.Round(double.Parse(item.proportion) / stockNum * 100, 2) + "%"; } gJSpecStatisticData.dataDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); gJSpecStatisticData.coilSpecTypeList = gJSpecStatisticList; return gJSpecStatisticData; } /// /// 查询堆垛机状态信息 /// /// public static List getDDJStatusInfos() { var ddjPlcInfos = Settings.devicePlcInfos.Where(a => a.deviceType == 1).ToList(); List dDJStatusInfos = new List(); foreach (var item in ddjPlcInfos) { LogHelper.Info("读取堆垛机 " + item.deviceNo, "数字孪生"); short[] resSignal1 = S7Helper.ReadInt(item.deviceNo, 551, 0, 8); int resSignal2 = S7Helper.ReadDint(item.deviceNo, 551, 16); short[] resSignal3 = S7Helper.ReadInt(item.deviceNo, 551, 20, 3); LogHelper.Info("读取堆垛机 " + item.deviceNo + " 信号: resSignal1:" + JsonConvert.SerializeObject(resSignal1) + " resSignal2(任务号):" + JsonConvert.SerializeObject(resSignal2) + " resSignal3:" + JsonConvert.SerializeObject(resSignal3), "数字孪生"); if (resSignal1 != null && resSignal2 != 0 && resSignal3 != null) { ResSignalInfo resSignalInfo = new ResSignalInfo() { HandShake = resSignal1[0], SRM_Num = resSignal1[1], Auto = resSignal1[2], Alarm_Code = resSignal1[3], State = resSignal1[4], TaskStatus1 = resSignal1[5], Loaded1 = resSignal1[6], Busines1 = resSignal1[7], TaskId1 = resSignal2, Row = resSignal3[0], Layer = resSignal3[1], b_Fork1Pos = resSignal3[2], }; LogHelper.Info("查询堆垛机信息:"+ JsonConvert.SerializeObject(resSignalInfo), "数字孪生"); // FromWcs(DB550)下发任务数据 short[] resSignal = S7Helper.ReadInt(item.deviceNo, 550, 8, 8); DDJStatusInfo info = new DDJStatusInfo() { deviceNo = resSignalInfo.SRM_Num.ToString(), auto = resSignalInfo.Auto.ToString(), status = resSignalInfo.State.ToString(), alertorInfo = resSignalInfo.Alarm_Code.ToString(), Loaded1 = resSignalInfo.Loaded1.ToString(), Busines1 = resSignalInfo.Busines1.ToString(), Row = resSignalInfo.Row.ToString(), Layer = resSignalInfo.Layer.ToString(), b_Fork1Pos = resSignalInfo.b_Fork1Pos.ToString(), TaskId1 = resSignalInfo.TaskId1.ToString(), dataDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), }; if (resSignal != null) { info.Source_Z_S1 = resSignal[0].ToString(); info.Source_X_S1 = resSignal[1].ToString(); info.Source_Y_S1 = resSignal[2].ToString(); info.Dest_Z_S1 = resSignal[4].ToString(); info.Dest_X_S1 = resSignal[5].ToString(); info.Dest_Y_S1 = resSignal[6].ToString(); } dDJStatusInfos.Add(info); } } return dDJStatusInfos; } /// /// 查询接驳位物料信息 /// /// public static JBItemInfo queryJBItemInfo(string locCode) { var db = new SqlHelper().GetInstance(); var location = LocationHelper.GetLoc(locCode); JBItemInfo jBItemInfo = new JBItemInfo() { locCode = locCode, isHave = location.N_CURRENT_NUM > 0 ? "是" : "否", }; var itemInfo = db.Queryable() .LeftJoin((a, b) => a.S_CNTR_CODE == b.S_CNTR_CODE ) .Where((a,b)=> a.S_LOC_CODE == locCode) .GroupBy((a, b) => new { b.S_WORK_NO }) .Select((a,b) => new { workNo = b.S_WORK_NO, weight = SqlFunc.AggregateSum(b.F_WEIGHT), }) .First(); if (itemInfo != null) { jBItemInfo.workNo = itemInfo.workNo; jBItemInfo.weight = itemInfo.weight; } return jBItemInfo; } /// /// 查询钢卷出入库记录 /// /// /// public static List queryGjOutInStockRecord(AreaModel model) { var db = new SqlHelper().GetInstance(); var query = db.Queryable().Where(a => a.S_AREA_CODE == model.areaCode && a.S_ACT_TYPE == model.actType); if (model.actType == "出库") { query = query.Where("(CONVERT(date, T_OUT_TIME) = @date)", new { DateTime.Parse(model.dataDate).Date }); } else if (model.actType == "入库") { query = query.Where("(CONVERT(date, T_IN_TIME) = @date)", new { DateTime.Parse(model.dataDate).Date }); } return query.Select(a => new GjOutInStockRecord { S_CODE = a.S_CODE, S_COIL_NO = a.S_COIL_NO, S_AREA_CODE = a.S_AREA_CODE, S_LOC_CODE = a.S_LOC_CODE, S_ACT_TYPE = a.S_ACT_TYPE, S_ITEM_CODE = a.S_ITEM_CODE, S_ITEM_NAME = a.S_ITEM_NAME, S_WORK_NO = a.S_WORK_NO, S_WORK_NAME = a.S_WORK_NAME, F_WEIGHT = a.F_WEIGHT, F_QTY = a.F_QTY, T_IN_TIME = a.T_IN_TIME, T_OUT_TIME = a.T_OUT_TIME, }).ToList(); } /// /// 查询汇总的钢卷重量数据 /// /// public static ResponseResult querySummaryGJKWeightData() { ResponseResult result = new ResponseResult(); var db = new SqlHelper().GetInstance(); var gjAreaCodes = Settings.getStoreAreaCodes(1, 2); // 按钢卷号分组查询今日出库的最大钢卷重量(去除剪切位出库) var coilWeightSummary = db.Queryable() .LeftJoin((a, b) => a.S_CODE == b.S_LOC_CODE) .LeftJoin((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE) .Where((a, b, c) => gjAreaCodes.Contains(a.S_AREA_CODE) && a.N_CURRENT_NUM > 0 && c.S_CNTR_CODE != null) .GroupBy((a, b, c) => c.S_WORK_NO) .Select((a, b, c) => new { workNo = c.S_WORK_NO.Trim(), weight = SqlFunc.AggregateMax(c.F_WEIGHT) }).ToList(); result.result= coilWeightSummary; return result; } public class GjOutInStockRecord { public string S_CODE { get; set; } //记录编码 public string S_COIL_NO { get; set; } // 钢卷号 public string S_AREA_CODE { get; set; } //库区编码 public string S_LOC_CODE { get; set; } //库位编码 public string S_ACT_TYPE { get; set; } //行为类型 入库、出库 public string S_ITEM_CODE { get; set; } //物料编码 public string S_ITEM_NAME { get; set; } //物料名称 public string S_WORK_NO { get; set; } //工作号 public string S_WORK_NAME { get; set; } //工作名称 public float F_WEIGHT { get; set; } //重量 public float F_QTY { get; set; } //数量 public DateTime? T_IN_TIME { get; set; } //入库时间 public DateTime? T_OUT_TIME { get; set; } // 出库时间 } public class JBItemInfo { public string locCode { get; set; } // 接驳位编码 public string isHave { get; set; } // 是否有货 是/否 public string workNo { get; set; } // 工作号 public float weight { get; set; } // 货物重量 } public class DDJStatusInfo { public string deviceNo { get; set; } // 设备号 public string auto { get; set; } // 堆垛机当前模式指示 1 联机自动;2手动;3半自动;4维修; public string status { get; set; } // 1:状态正常,允许任务下发 public string alertorInfo { get; set; } // 堆垛机报警代码 0:默认;1:正常 ;其他数字故障信息 public string Loaded1 { get; set; } // 载货台有无货 1:有货;0:无货 public string Busines1 { get; set; } // 工位1特殊业务状态反馈 [1:满入,2.空取,3:放货阻塞,4:取货阻塞] public string Row { get; set; } // 堆垛机当前列(行走方向) public string Layer { get; set; } // 堆垛机当前层(升降方向) public string b_Fork1Pos { get; set; } // 堆垛机货叉1位置 [1:左远,2.左近,3:居中,4:右近,5:右远] public string TaskId1 { get; set; } // 任务号 public string Source_Z_S1 { get; set; } // 取货排 1/2/3/4 public string Source_X_S1 { get; set; } // 取货列 public string Source_Y_S1 { get; set; } // 取货层 public string Dest_Z_S1 { get; set; } // 放货排 public string Dest_X_S1 { get; set; } // 放货列 public string Dest_Y_S1 { get; set; } // 放货层 public string dataDate { get; set; } // 数据日期 } public class GJSpecStatisticData { public string dataDate { get; set; } public List coilSpecTypeList { get; set; } public class GJSpecTypeStatistic { public string coilSpec { get; set; } public float weight { get; set; } public string proportion { get; set; } } } public class FHQAreaSummaryData { public int finishProdNum { get; set; } public int occupyLocNum { get; set; } public int leisureLocNum { get; set; } } public class MJKAreaSummaryData { public int stockMouldNum { get; set; } public int lendMouldNum { get; set; } } public class GJKAreaSummaryData { public string areaCode { get; set; } // 库区编码 public int stockNum { get; set; } // 在库数量 public int intactNum { get; set; } // 完整数量 public int noIntactNum { get; set; } // 非完整数量 public float consumeWeight { get; set; } // 今日钢卷消耗量 public string dataDate { get; set; } } /// /// 模具库货位数据 /// public class MJKLocationData { public string areaName { get; set; } public string areaCode { get; set; } public string areaType { get; set; } public string locCode { get; set; } public string trayCode { get; set; } public string mouldNo { get; set; } } /// /// 钢卷库货位数据 /// public class GJKLocationData { public string areaName { get; set; } public string areaCode { get; set; } public string areaType { get; set; } public string locCode { get; set; } public DateTime? inStockTime { get; set; } public string itemCode { get; set; } public string itemName { get; set; } public string itemType { get; set; } public string workNo { get; set; } public string workName { get; set; } public string coilNo { get; set; } public string spec { get; set; } public string width { get; set; } public string heatNo { get; set; } public string shootNo { get; set; } public float weight { get; set; } public float quantity { get; set; } public float initWeight { get; set; } } /// /// 立体库货位数据 /// public class LTKLocationData { public string areaName { get; set; } public string areaCode { get; set; } public string areaType { get; set; } public string trayCode { get; set; } public string locCode { get; set; } public DateTime? inStockTime { get; set; } public string itemCode { get; set; } public string itemName { get; set; } public string itemType { get; set; } public string workNo { get; set; } public string workName { get; set; } public string dePartNo { get; set; } public string partDrawNo { get; set; } public string partName { get; set; } public float weight { get; set; } public float quantity { get; set; } public string storagDuration { get; set; } } public class LocModel { public string areaCode { get; set; } public string locCode { get; set; } } public class AreaLocData { public string areaCode { get; set; } public string areaName { get; set; } public object areaData { get; set; } } public class ProceedTaskData { public string taskType { get; set; } public string prodName { get; set; } public float quantity { get; set; } public string taskStatus { get; set; } } public class OutInStockModel { public string areaCode { get; set; } public string dataDate { get; set; } public string actType { get; set; } } public class AreaSummaryData { public string areaCode { get; set; } public string areaName { get; set; } public int sum { get; set; } public int usageNum { get; set; } public string usageRate { get; set; } public List workNoSummaryData { get; set; } } public class WorkNoOutStockData { public string workNo { get; set; } public string workName { get; set; } public string dePartNo { get; set; } public float quantity { get; set; } public float weight { get; set; } public float accuQuantity { get; set; } // 累计数量 } public class DateModel { public string dataDate { get; set; } // 数据日期(yyyy-MM-dd) } public class ActModel { public string actType { get; set; } // 类型 入库 出库 public string dataDate { get; set; } // 数据日期(yyyy-MM-dd) } public class StorageTimeSummaryData { public int amountA { get; set; } // 在库时长7日内数量 public string proportionA { get; set; } // 在库时长7日内占比 public int amountB { get; set; } // 在库时长8-15日数量 public string proportionB { get; set; } // 在库时长8-15日占比 public int amountC { get; set; } // 在库时长16-30日数量 public string proportionC { get; set; } // 在库时长16-30日占比 public int amountD { get; set; } // 在库时长30-90日数量 public string proportionD { get; set; } // 在库时长30-90日占比 public int amountE { get; set; } // 在库时长91日以上数量 public string proportionE { get; set; } // 在库时长91日以上占比 public int sum { get; set; } // 总库位数 public int usageNum { get; set; } // 使用数 public string usageRate { get; set; } // 使用率 } public class WorkNoSummaryData { public string areaCode { get; set; } public string areaName { get; set; } public string workNo { get; set; } public string workName { get; set; } public string type { get; set; } public float amount { get; set; } public string proportion { get; set; } } public class DrawSummaryData { public string partDrawNo { get; set; } public string partName { get; set; } public string workNo { get; set; } public float amount { get; set; } public string proportion { get; set; } } public class LTKSummaryData { public int sum { get; set; } public int usageNum { get; set; } public string usageRate { get; set; } public int finishProdNum { get; set; } public string finishProdProp { get; set; } public int semiProdNum { get; set; } public string semiProdProp { get; set; } } public class AreaModel { public string areaCode { get; set; } public string dataDate { get; set; }// 数据日期(yyyy-MM-dd) public string actType { get; set; } } public class AreaListModel { public List areaCodes { get; set; } public string dataDate { get; set; } // 数据日期(yyyy-MM-dd) } public class ItemTypeModel { public string itemType { get; set; } } /// /// 成品物料信息 /// public class BaseItemInfo { public string areaCode { get; set; } public string trayCode { get; set; } public string locCode { get; set; } public string workNo { get; set; } public string workName { get; set; } public string dePartNo { get; set; } public string partDrawNo { get; set; } public string partName { get; set; } public string itemCode { get; set; } public string itemName { get; set; } public float weight { get; set; } public float quantity { get; set; } } } }