| | |
| | | .ToList(); |
| | | |
| | | // 开工数采:最早一条 |
| | | vOrderBycl.StartCjNum = sortedList.First().CjNum ?? 0; |
| | | vOrderBycl.StartCjNum = vOrderBycl.preStartCjNum ?? (sortedList.First().CjNum ?? 0); |
| | | // 当前数采:最新一条 |
| | | vOrderBycl.CurrentCjNum = sortedList.Last().CjNum ?? 0; |
| | | } |
| | |
| | | |
| | | // 查询报工记录,获取最后一条报工记录 |
| | | var lastReport = Db.Queryable<MesReporting>() |
| | | .AS("MES_REPORTING") // 强制表名 |
| | | .Where(r => r.BillNo == query.orderNo) |
| | | .OrderBy(r => r.BgDate, OrderByType.Desc) |
| | | .First(); |
| | | |
| | | if (lastReport == null || !lastReport.BgDate.HasValue) |
| | | { |
| | | // 没有报工记录或报工时间无效,初始采集数为开工采数 |
| | | vOrderBycl.InitCjNum = vOrderBycl.StartCjNum; |
| | | } |
| | | else |
| | | { |
| | | // 有报工记录,初始采集数为上一次报工时间后最近一条齿轮数采表的采集数量 |
| | | // 1. 精确匹配报工时间 |
| | | var exactMatch = numericalList |
| | | .Select(x => new { Item = x, ParsedTime = DateTime.TryParse(x.CjTiem, out var dt) ? dt : (DateTime?)null }) |
| | | .Where(x => x.ParsedTime.HasValue && x.ParsedTime.Value == lastReport.BgDate.Value) |
| | | .OrderBy(x => x.ParsedTime) |
| | | .Select(x => x.Item) |
| | | .FirstOrDefault(); |
| | | |
| | | if (exactMatch != null) |
| | | if (string.IsNullOrEmpty(vOrderBycl.Daa016)) // 没有开工时间 |
| | | { |
| | | vOrderBycl.InitCjNum = exactMatch.CjNum ?? vOrderBycl.StartCjNum; |
| | | // 没有报工记录且没有开工时间,初始采集数为调机时间前一条的采集数量 |
| | | vOrderBycl.InitCjNum = vOrderBycl.preStartTjNum; |
| | | } |
| | | else |
| | | { |
| | | // 2. 找报工时间之后的第一条(采集时间降序,取最新一条) |
| | | var afterReportNum = numericalList |
| | | .Select(x => new { Item = x, ParsedTime = DateTime.TryParse(x.CjTiem, out var dt) ? dt : (DateTime?)null }) |
| | | .Where(x => x.ParsedTime.HasValue && x.ParsedTime.Value > lastReport.BgDate.Value) |
| | | .OrderByDescending(x => x.ParsedTime) |
| | | .Select(x => x.Item) |
| | | .FirstOrDefault(); |
| | | |
| | | vOrderBycl.InitCjNum = afterReportNum?.CjNum ?? vOrderBycl.StartCjNum; |
| | | // 没有报工记录,初始采集数为开工时间前一条的采集数量 |
| | | vOrderBycl.InitCjNum = vOrderBycl.preStartCjNum; |
| | | } |
| | | |
| | | //// 没有报工记录,初始采集数为开工采数 |
| | | //VOrdrerBycl.InitCjNum = VOrdrerBycl.StartCjNum; |
| | | } |
| | | else |
| | | { |
| | | // 有报工记录,初始采集数为报工时间点前(含)最近一条齿轮数采表的采集数量 |
| | | var beforeOrEqualReportNum = numericalList |
| | | .Select(x => new { Item = x, ParsedTime = DateTime.TryParse(x.CjTiem, out var dt) ? dt : (DateTime?)null }) |
| | | .Where(x => x.ParsedTime.HasValue && x.ParsedTime.Value <= lastReport.BgDate.Value) |
| | | .OrderByDescending(x => x.ParsedTime) // 降序,取第一条 |
| | | .Select(x => x.Item) |
| | | .FirstOrDefault(); |
| | | |
| | | vOrderBycl.InitCjNum = beforeOrEqualReportNum?.CjNum ?? vOrderBycl.StartCjNum; |
| | | } |
| | | |
| | | var startCjNum = vOrderBycl.StartCjNum; |
| | |
| | | .Where(a => a.OrderId == VOrdrerBycl.ID |
| | | && a.IsShow == 0).First(); |
| | | |
| | | VOrdrerBycl.todayRunTime = 0; |
| | | VOrdrerBycl.TodayFaultNum = 0; |
| | | // 保留视图里的 todayRunTime 和 JDL,不做任何赋值和转换 |
| | | // VOrdrerBycl.todayRunTime 保持原值 |
| | | // VOrdrerBycl.JDL 保持原值 |
| | | //VOrdrerBycl.TodayFaultNum = 0; |
| | | |
| | | if (mesOrderSelect != null) |
| | | { |
| | | VOrdrerBycl.todayRunTime = mesOrderSelect.TjTime; |
| | | VOrdrerBycl.TodayFaultNum = mesOrderSelect.TjCount; |
| | | |
| | | if (mesOrderSelect.TjTime is null or 0) |
| | | { |
| | | VOrdrerBycl.JDL = 100; |
| | | } |
| | | else |
| | | { |
| | | var round = Math.Round(mesOrderSelect.TjTime.Value / 1440, 2); |
| | | var round1 = (1 - round) * 100; |
| | | VOrdrerBycl.JDL = round1; |
| | | } |
| | | } |
| | | |
| | | VOrdrerBycl.wjQty = VOrdrerBycl.Daa008 - VOrdrerBycl.Daa011; |
| | |
| | | .ToList(); |
| | | |
| | | // 开工数采:最早一条 |
| | | VOrdrerBycl.StartCjNum = sortedList.First().CjNum ?? 0; |
| | | VOrdrerBycl.StartCjNum = VOrdrerBycl.preStartCjNum ?? (sortedList.First().CjNum ?? 0); |
| | | // 当前数采:最新一条 |
| | | VOrdrerBycl.CurrentCjNum = sortedList.Last().CjNum ?? 0; |
| | | } |
| | |
| | | VOrdrerBycl.CurrentCjNum = 0; |
| | | } |
| | | |
| | | // 查询最后一条报工记录 |
| | | // 计算当天停机次数 |
| | | //VOrdrerBycl.TodayDowntimeCount = GetTodayDowntimeCount(numericalList); |
| | | |
| | | //计算日停机次数、todayOnlineTime(总在线时长)、todayRunTime(实际运行时长)、稼动率(百分比,保留两位小数) |
| | | VOrdrerBycl.TodayDowntimeCount = GetTodayDowntimeStats(numericalList).downtimeCount; |
| | | VOrdrerBycl.TodayOnlineTime = GetTodayDowntimeStats(numericalList).todayOnlineTime; |
| | | VOrdrerBycl.todayRunTime = GetTodayDowntimeStats(numericalList).todayRunTime; |
| | | VOrdrerBycl.JDL = GetTodayDowntimeStats(numericalList).utilizationRate; |
| | | |
| | | Console.WriteLine($"orderNo: [{query.orderNo}]"); |
| | | |
| | | // 查询报工记录,获取最后一条报工记录 |
| | | var lastReport = Db.Queryable<MesReporting>() |
| | | .Where(r => r.BillNo == query.orderNo) |
| | | .Where(r => r.BillNo.Trim().ToUpper() == query.orderNo.Trim().ToUpper()) |
| | | .OrderBy(r => r.BgDate, OrderByType.Desc) |
| | | .First(); |
| | | |
| | | if (lastReport == null || !lastReport.BgDate.HasValue) |
| | | if (lastReport == null || !lastReport.BgDate.HasValue)//没有报工记录 |
| | | { |
| | | // 没有报工记录,初始采集数为开工采数 |
| | | VOrdrerBycl.InitCjNum = VOrdrerBycl.StartCjNum; |
| | | if (string.IsNullOrEmpty(VOrdrerBycl.Daa016)) // 没有开工时间 |
| | | { |
| | | // 没有报工记录且没有开工时间,初始采集数为调机时间前一条的采集数量 |
| | | VOrdrerBycl.InitCjNum = VOrdrerBycl.preStartTjNum; |
| | | } |
| | | else |
| | | { |
| | | // 没有报工记录,初始采集数为开工时间前一条的采集数量 |
| | | VOrdrerBycl.InitCjNum = VOrdrerBycl.preStartCjNum; |
| | | |
| | | //// 没有报工记录,初始采集数为开工采数 |
| | | //VOrdrerBycl.InitCjNum = VOrdrerBycl.StartCjNum; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 有报工记录,初始采集数为上一次报工时间后最近一条齿轮数采表的采集数量 |
| | | var afterReportNum = numericalList |
| | | // 有报工记录,初始采集数为报工时间点前(含)最近一条齿轮数采表的采集数量 |
| | | var beforeOrEqualReportNum = numericalList |
| | | .Select(x => new { Item = x, ParsedTime = DateTime.TryParse(x.CjTiem, out var dt) ? dt : (DateTime?)null }) |
| | | .Where(x => x.ParsedTime.HasValue && x.ParsedTime.Value > lastReport.BgDate.Value) |
| | | .OrderByDescending(x => x.ParsedTime) |
| | | .Where(x => x.ParsedTime.HasValue && x.ParsedTime.Value <= lastReport.BgDate.Value) |
| | | .OrderByDescending(x => x.ParsedTime) // 降序,取第一条 |
| | | .Select(x => x.Item) |
| | | .FirstOrDefault(); |
| | | |
| | | VOrdrerBycl.InitCjNum = afterReportNum?.CjNum ?? VOrdrerBycl.StartCjNum; |
| | | VOrdrerBycl.InitCjNum = beforeOrEqualReportNum?.CjNum ?? VOrdrerBycl.StartCjNum; |
| | | } |
| | | |
| | | // 报工时采集数就是主界面的当前采数 |
| | | // VOrdrerBycl.CurrentCjNum 已赋值,无需额外处理 |
| | | |
| | | return VOrdrerBycl; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计算日停机次数 |
| | | /// </summary> |
| | | /// <param name="numericalList"></param> |
| | | /// <returns></returns> |
| | | public int GetTodayDowntimeCount(List<MesNumericalBycl> numericalList) |
| | | { |
| | | var today = DateTime.Now.Date; |
| | | // 1. 只保留当天数据,并转换为 DateTime |
| | | var todayTimes = numericalList |
| | | .Where(x => DateTime.TryParse(x.CjTiem, out var dt) && dt.Date == today) |
| | | .Select(x => DateTime.Parse(x.CjTiem)) |
| | | .OrderBy(x => x) |
| | | .ToList(); |
| | | |
| | | if (todayTimes.Count < 2) |
| | | return 0; |
| | | |
| | | int downtimeCount = 0; |
| | | for (int i = 1; i < todayTimes.Count; i++) |
| | | { |
| | | var diff = (todayTimes[i] - todayTimes[i - 1]).TotalMinutes; |
| | | if (diff > 3) |
| | | downtimeCount++; |
| | | } |
| | | return downtimeCount; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计算日停机次数、todayOnlineTime(总在线时长)、todayRunTime(实际运行时长)、稼动率(百分比,保留两位小数) |
| | | /// </summary> |
| | | public (int downtimeCount, double todayOnlineTime, double todayRunTime, double utilizationRate) GetTodayDowntimeStats(List<MesNumericalBycl> numericalList) |
| | | { |
| | | var today = DateTime.Now.Date; |
| | | var todayTimes = numericalList |
| | | .Where(x => DateTime.TryParse(x.CjTiem, out var dt) && dt.Date == today) |
| | | .Select(x => DateTime.Parse(x.CjTiem)) |
| | | .OrderBy(x => x) |
| | | .ToList(); |
| | | |
| | | int downtimeCount = 0; |
| | | double downtimeMinutes = 0; |
| | | double todayOnlineTime = 0; |
| | | double todayRunTime = 0; |
| | | double utilizationRate = 0; |
| | | |
| | | if (todayTimes.Count < 2) |
| | | return (0, 0, 0, 0); |
| | | |
| | | for (int i = 1; i < todayTimes.Count; i++) |
| | | { |
| | | var diff = (todayTimes[i] - todayTimes[i - 1]).TotalMinutes; |
| | | if (diff > 3) |
| | | { |
| | | downtimeCount++; |
| | | downtimeMinutes += diff; |
| | | } |
| | | } |
| | | |
| | | todayOnlineTime = (todayTimes.Last() - todayTimes.First()).TotalMinutes; |
| | | todayRunTime = todayOnlineTime - downtimeMinutes; |
| | | if (todayOnlineTime > 0) |
| | | utilizationRate = Math.Round(todayRunTime / todayOnlineTime * 100, 2); |
| | | |
| | | return (downtimeCount, todayOnlineTime, todayRunTime, utilizationRate); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | CsQty = SqlFunc.ToInt32(r.CsQty),//初始采集数 |
| | | CjQty = SqlFunc.ToInt32(r.CjQty),//报工时采集数 |
| | | BfQty = SqlFunc.ToInt32(r.BfQty),//不良数量 |
| | | OkQty = SqlFunc.ToInt32(r.OkQty)//良品数量 |
| | | OkQty = SqlFunc.ToInt32(r.OkQty),//良品数量 |
| | | REMARK = r.Remark //备注 |
| | | }) |
| | | .ToPageList((pageIndex < 1 ? 1 : pageIndex), |
| | | (pageSize < 1 ? 200 : (pageSize > 1000 ? 1000 : pageSize)), ref totalCount); |