From a8f45fa02822529485ea0bf08ee1d5d5d1a35e15 Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期五, 21 十一月 2025 15:34:20 +0800
Subject: [PATCH] 更换提示顺序
---
Services/WomdaaManager.cs | 305 +++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 258 insertions(+), 47 deletions(-)
diff --git a/Services/WomdaaManager.cs b/Services/WomdaaManager.cs
index 28046f6..eb09f37 100644
--- a/Services/WomdaaManager.cs
+++ b/Services/WomdaaManager.cs
@@ -25,12 +25,13 @@
list = list.Where(p => p.Daa018 != null && query.OrderStatus.Contains(p.Daa018)).ToList();
}
- //// 鍒嗙粍閫昏緫锛堝闇�鍒嗙粍锛屾寜鍒�鍏稩D鍒嗙粍鍙栫涓�鏉★級
- //var vOrders = list.GroupBy(p => p.cutterId)
- // .Select(g => g.First()).ToList();
+ // 鎸夊伐鍗旾D鍒嗙粍锛屽彧淇濈暀姣忕粍涓渶鏃╂姤宸ョ殑涓�鏉�
+ list = list
+ .GroupBy(p => p.ID)
+ .Select(g => g.OrderBy(x => x.BgDate).First())
+ .OrderBy(x => x.BgDate)
+ .ToList();
- //return vOrders;
- // 濡傞渶鍒嗙粍鍙姞鍒嗙粍閫昏緫锛屽惁鍒欑洿鎺ヨ繑鍥�
return list;
}
@@ -97,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();
@@ -110,12 +110,88 @@
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 = vOrderBycl.preStartCjNum ?? (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)
+ {
+ if (string.IsNullOrEmpty(vOrderBycl.Daa016)) // 娌℃湁寮�宸ユ椂闂�
+ {
+ // 娌℃湁鎶ュ伐璁板綍涓旀病鏈夊紑宸ユ椂闂达紝鍒濆閲囬泦鏁颁负璋冩満鏃堕棿鍓嶄竴鏉$殑閲囬泦鏁伴噺
+ vOrderBycl.InitCjNum = vOrderBycl.preStartTjNum;
+ }
+ else
+ {
+ // 娌℃湁鎶ュ伐璁板綍锛屽垵濮嬮噰闆嗘暟涓哄紑宸ユ椂闂村墠涓�鏉$殑閲囬泦鏁伴噺
+ 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;
+ 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>
@@ -144,43 +220,167 @@
.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;
- //DevMachine
var devMachine = Db.Queryable<DevMacBycl>()
.Where(s => s.MachineNo == VOrdrerBycl.MachineNo)
.First();
-
var sql = string.Format(
"select FINAL_RESULT from MES_EQ_SPOT_CHECKS where department_no = 'XS0101' and EQ_NO = '{0}' and substr(SUBMIT_DATE, 1, 10) = to_char(sysdate, 'yyyy-mm-dd')",
devMachine.UniqueBarcode);
var sqlQuerySingle = Db.Ado.SqlQuerySingle<string>(sql);
-
VOrdrerBycl.finalResult = sqlQuerySingle;
+ // 鏌ヨMES_NUMERICAL_BYCL琛紝鑾峰彇寮�宸ユ暟閲囧拰褰撳墠鏁伴噰
+ var numericalList = Db.Queryable<MesNumericalBycl>()
+ .Where(x => x.OrderId == VOrdrerBycl.ID)
+ .OrderBy(x => x.CjTiem)
+ .ToList();
+
+ if (numericalList.Count > 0)
+ {
+ // 鍏堟寜閲囬泦鏃堕棿鍗囧簭鎺掑簭
+ var sortedList = numericalList
+ .OrderBy(x => DateTime.TryParse(x.CjTiem, out var dt) ? dt : DateTime.MinValue)
+ .ToList();
+
+ // 寮�宸ユ暟閲囷細鏈�鏃╀竴鏉�
+ VOrdrerBycl.StartCjNum = VOrdrerBycl.preStartCjNum ?? (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)
+ {
+ if (string.IsNullOrEmpty(VOrdrerBycl.Daa016)) // 娌℃湁寮�宸ユ椂闂�
+ {
+ // 娌℃湁鎶ュ伐璁板綍涓旀病鏈夊紑宸ユ椂闂达紝鍒濆閲囬泦鏁颁负璋冩満鏃堕棿鍓嶄竴鏉$殑閲囬泦鏁伴噺
+ VOrdrerBycl.InitCjNum = VOrdrerBycl.preStartTjNum;
+ }
+ else
+ {
+ // 娌℃湁鎶ュ伐璁板綍锛屽垵濮嬮噰闆嗘暟涓哄紑宸ユ椂闂村墠涓�鏉$殑閲囬泦鏁伴噺
+ 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>
@@ -216,41 +416,52 @@
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)
+ string billNo, string machineNo, DateTime? from, DateTime? to, int pageIndex, int pageSize)
{
var query = Db.Queryable<MesReporting>()
- .Where(x => x.BillNo == billNo);
+ // 鍏宠仈鍛樺伐淇℃伅琛紝浣跨敤鎶ュ伐浜虹紪鐮佸尮閰嶅憳宸ョ紪鐮�
+ .LeftJoin<MesStaff>((r, s) => r.BgPerson == s.StaffNo)
+ .Where((r, s) => r.BillNo == billNo);
if (!string.IsNullOrWhiteSpace(machineNo))
- query = query.Where(x => x.MachineNo == machineNo);
+ query = query.Where((r, s) => r.MachineNo == machineNo);
if (from.HasValue)
- query = query.Where(x => x.BgDate >= from.Value);
+ query = query.Where((r, s) => r.BgDate >= from.Value);
if (to.HasValue)
- query = query.Where(x => x.BgDate < to.Value.AddDays(1));
+ query = query.Where((r, s) => r.BgDate < to.Value.AddDays(1));
var totalCount = query.Count();
- var tbBillList = query.OrderBy(x => x.BgDate, OrderByType.Desc)
- .Select(x => new MesReportingBgDto
+ var tbBillList = query.OrderBy((r, s) => r.BgDate, OrderByType.Desc)
+ .Select((r, s) => new MesReportingBgDto
{
- Id = (long)x.Id,
- BillNo = x.BillNo,
- ItemNo = x.ItemNo,
- MachineNo = x.MachineNo,
- StaffNo = x.BgPerson,
- StaffName = x.BgPerson, // 濡傛湁鐙珛濮撳悕瀛楁鍙浛鎹�
- BgDate = x.BgDate,
- KgQty = SqlFunc.ToInt32(x.CjQty),
- InitialValue = SqlFunc.ToInt32(x.CsQty),
- ProductionCount = SqlFunc.ToInt32(x.CjQty),
- SQuantity = SqlFunc.ToInt32(x.OkQty),
- OkQty = SqlFunc.ToInt32(x.OkQty),
- NgQty = SqlFunc.ToInt32(x.BfQty)
+ Id = (long)r.Id,
+ BillNo = r.BillNo,
+ ItemNo = r.ItemNo,
+ MachineNo = r.MachineNo,
+ StaffNo = r.BgPerson,//鎶ュ伐浜虹紪鍙�
+ StaffName = SqlFunc.IsNullOrEmpty(s.StaffName) ? r.BgPerson : s.StaffName, // 濡傛湁鐙珛濮撳悕瀛楁鍙浛鎹�
+ BgDate = r.BgDate,//鎶ュ伐鏃堕棿
+ CsQty = SqlFunc.ToInt32(r.CsQty),//鍒濆閲囬泦鏁�
+ CjQty = SqlFunc.ToInt32(r.CjQty),//鎶ュ伐鏃堕噰闆嗘暟
+ BfQty = SqlFunc.ToInt32(r.BfQty),//涓嶈壇鏁伴噺
+ OkQty = SqlFunc.ToInt32(r.OkQty)//鑹搧鏁伴噺
})
- .ToPageList((pageIndex < 1 ? 1 : pageIndex), (pageSize < 1 ? 200 : (pageSize > 1000 ? 1000 : pageSize)), ref totalCount);
+ .ToPageList((pageIndex < 1 ? 1 : pageIndex),
+ (pageSize < 1 ? 200 : (pageSize > 1000 ? 1000 : pageSize)), ref totalCount);
return (tbBillList, totalCount);
}
--
Gitblit v1.9.3