From f3d97fe8a7072071ddb1b19e015f8a8f823a5957 Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期三, 19 十一月 2025 15:02:31 +0800
Subject: [PATCH] 调试
---
Services/WomdaaManager.cs | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 215 insertions(+), 25 deletions(-)
diff --git a/Services/WomdaaManager.cs b/Services/WomdaaManager.cs
index a492600..716dbdd 100644
--- a/Services/WomdaaManager.cs
+++ b/Services/WomdaaManager.cs
@@ -25,6 +25,13 @@
list = list.Where(p => p.Daa018 != null && query.OrderStatus.Contains(p.Daa018)).ToList();
}
+ // 鎸夊伐鍗旾D鍒嗙粍锛屽彧淇濈暀姣忕粍涓渶鏃╂姤宸ョ殑涓�鏉�
+ list = list
+ .GroupBy(p => p.ID)
+ .Select(g => g.OrderBy(x => x.BgDate).First())
+ .OrderBy(x => x.BgDate)
+ .ToList();
+
return list;
}
@@ -91,8 +98,7 @@
{
// 鏌ヨ闇�瑕佹樉绀虹殑宸ュ崟ID
var ids = Db.Queryable<MesOrderSelect>()
- .Where(b => b.MachineNo == query.machineNo
- && b.IsShow == 0)
+ .Where(b => b.MachineNo == query.machineNo && b.IsShow == 0)
.Select(s => s.OrderId)
.ToList();
@@ -104,12 +110,77 @@
if (decimals.Count == 0)
return new List<VOrderBycl>();
- // 鏌ヨ宸ュ崟瑙嗗浘锛岀瓫閫夊嚭闇�瑕佹樉绀虹殑宸ュ崟
- return Db.Queryable<VOrderBycl>()
+ // 鏌ヨ榻胯疆鏁伴噰琛�
+ var numericalList = Db.Queryable<MesNumericalBycl>()
+ .Where(x => ids.Contains(x.OrderId ?? 0))
+ .OrderBy(x => x.CjTiem)
+ .ToList();
+
+ var vOrderBycl = new VOrderBycl();
+ if (numericalList.Count > 0)
+ {
+ // 鎸夐噰闆嗘椂闂村崌搴忔帓搴�
+ var sortedList = numericalList
+ .OrderBy(x => DateTime.TryParse(x.CjTiem, out var dt) ? dt : DateTime.MinValue)
+ .ToList();
+
+ // 寮�宸ユ暟閲囷細鏈�鏃╀竴鏉�
+ vOrderBycl.StartCjNum = sortedList.First().CjNum ?? 0;
+ // 褰撳墠鏁伴噰锛氭渶鏂颁竴鏉�
+ vOrderBycl.CurrentCjNum = sortedList.Last().CjNum ?? 0;
+ }
+ else
+ {
+ vOrderBycl.StartCjNum = 0;
+ vOrderBycl.CurrentCjNum = 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
+ {
+ // 鏈夋姤宸ヨ褰曪紝鍒濆閲囬泦鏁颁负鎶ュ伐鏃堕棿鐐瑰墠锛堝惈锛夋渶杩戜竴鏉¢娇杞暟閲囪〃鐨勯噰闆嗘暟閲�
+ 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;
+ var currentCjNum = vOrderBycl.CurrentCjNum;
+ var initCjNum = vOrderBycl.InitCjNum;
+
+ // 鏌ヨ宸ュ崟瑙嗗浘锛岀瓫閫夊嚭闇�瑕佹樉绀虹殑宸ュ崟锛屽彧鍙栨渶鏂颁竴鏉�
+ var orders = Db.Queryable<VOrderBycl>()
.Where(c =>
decimals.Contains(c.ID) &&
(c.EditDate == date || c.EditDate == null))
+ .OrderBy(c => c.BgDate, OrderByType.Desc)
+ .Take(1)
.ToList();
+
+ foreach (var order in orders)
+ {
+ order.StartCjNum = startCjNum;
+ order.CurrentCjNum = currentCjNum;
+ order.InitCjNum = initCjNum;
+ }
+
+ return orders;
}
/// <summary>
@@ -138,24 +209,14 @@
.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;
@@ -171,17 +232,136 @@
var sqlQuerySingle = Db.Ado.SqlQuerySingle<string>(sql);
VOrdrerBycl.finalResult = sqlQuerySingle;
- // 鏂板锛氭煡璇㈡渶鏃╀笌鏈�鏂版暟閲囪褰曪紙鎸夐噰闆嗘椂闂存帓搴忥級
- var baseQuery = Db.Queryable<MesNumericalBycl>()
- .Where(n => n.OrderId == Convert.ToDecimal(query.OrderId) && n.MachineNo == VOrdrerBycl.MachineNo);
+ // 鏌ヨMES_NUMERICAL_BYCL琛紝鑾峰彇寮�宸ユ暟閲囧拰褰撳墠鏁伴噰
+ var numericalList = Db.Queryable<MesNumericalBycl>()
+ .Where(x => x.OrderId == VOrdrerBycl.ID)
+ .OrderBy(x => x.CjTiem)
+ .ToList();
- var startCjNum = baseQuery.OrderBy(n => n.CjTiem).Select(n => n.CjNum).First();
- var currentCjNum = baseQuery.OrderBy(n => n.CjTiem, OrderByType.Desc).Select(n => n.CjNum).First();
+ if (numericalList.Count > 0)
+ {
+ // 鍏堟寜閲囬泦鏃堕棿鍗囧簭鎺掑簭
+ var sortedList = numericalList
+ .OrderBy(x => DateTime.TryParse(x.CjTiem, out var dt) ? dt : DateTime.MinValue)
+ .ToList();
- VOrdrerBycl.StartCjNum = startCjNum;
- VOrdrerBycl.CurrentCjNum = currentCjNum;
+ // 寮�宸ユ暟閲囷細鏈�鏃╀竴鏉�
+ VOrdrerBycl.StartCjNum = sortedList.First().CjNum ?? 0;
+ // 褰撳墠鏁伴噰锛氭渶鏂颁竴鏉�
+ VOrdrerBycl.CurrentCjNum = sortedList.Last().CjNum ?? 0;
+ }
+ else
+ {
+ VOrdrerBycl.StartCjNum = 0;
+ VOrdrerBycl.CurrentCjNum = 0;
+ }
+
+ // 璁$畻褰撳ぉ鍋滄満娆℃暟
+ //VOrdrerBycl.TodayDowntimeCount = GetTodayDowntimeCount(numericalList);
+
+ //璁$畻鏃ュ仠鏈烘鏁般�乼odayOnlineTime锛堟�诲湪绾挎椂闀匡級銆乼odayRunTime锛堝疄闄呰繍琛屾椂闀匡級銆佺鍔ㄧ巼锛堢櫨鍒嗘瘮锛屼繚鐣欎袱浣嶅皬鏁帮級
+ 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.Trim().ToUpper() == query.orderNo.Trim().ToUpper())
+ .OrderBy(r => r.BgDate, OrderByType.Desc)
+ .First();
+
+ if (lastReport == null || !lastReport.BgDate.HasValue)
+ {
+ // 娌℃湁鎶ュ伐璁板綍锛屽垵濮嬮噰闆嗘暟涓哄紑宸ユ椂闂村墠涓�鏉$殑閲囬泦鏁伴噺
+ VOrdrerBycl.InitCjNum = VOrdrerBycl.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();
+
+ VOrdrerBycl.InitCjNum = beforeOrEqualReportNum?.CjNum ?? VOrdrerBycl.StartCjNum;
+ }
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>
+ /// 璁$畻鏃ュ仠鏈烘鏁般�乼odayOnlineTime锛堟�诲湪绾挎椂闀匡級銆乼odayRunTime锛堝疄闄呰繍琛屾椂闀匡級銆佺鍔ㄧ巼锛堢櫨鍒嗘瘮锛屼繚鐣欎袱浣嶅皬鏁帮級
+ /// </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>
@@ -217,6 +397,16 @@
return vPrint;
}
+ /// <summary>
+ /// 鎶ュ伐璁板綍琛�
+ /// </summary>
+ /// <param name="billNo"></param>
+ /// <param name="machineNo"></param>
+ /// <param name="from"></param>
+ /// <param name="to"></param>
+ /// <param name="pageIndex"></param>
+ /// <param name="pageSize"></param>
+ /// <returns></returns>
public (List<MesReportingBgDto> tbBillList, int totalCount) GetByBillNoBG(
string billNo, string machineNo, DateTime? from, DateTime? to, int pageIndex, int pageSize)
{
--
Gitblit v1.9.3