From f4fb143d106e331b19d4292e20693ae2e3331cbd Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期五, 21 十一月 2025 15:40:57 +0800
Subject: [PATCH] 开工后不能调机报工

---
 Services/MesInvItemBarcodesManager.cs |   85 +++++++++++++++++++++++++++++++++---------
 1 files changed, 66 insertions(+), 19 deletions(-)

diff --git a/Services/MesInvItemBarcodesManager.cs b/Services/MesInvItemBarcodesManager.cs
index ab3cc5d..e82315e 100644
--- a/Services/MesInvItemBarcodesManager.cs
+++ b/Services/MesInvItemBarcodesManager.cs
@@ -288,24 +288,71 @@
             .Where(s => s.Daa001 == query.orderNo)
             .First();
 
+        if (womdaa.Daa018 != "寮�宸�" && query.type != "tiaoji") throw new Exception("宸ュ崟鏈紑宸�");
+        if (womdaa.Daa018 == "寮�宸�" && query.type == "tiaoji") throw new Exception("宸ュ崟宸插紑宸�");
+
         if (womdaa == null) throw new Exception("宸ュ崟鍗曞彿涓嶅瓨鍦�");
+
+        var okQty = query.currentCjNum - query.initCjNum - query.bf;//鑹搧鏁伴噺
+
+        // 鍒ゆ柇鏄惁涓鸿皟鏈烘姤宸�
+        string remark = "";
+        if (query.type == "tiaoji")
+            remark = "璋冩満鎶ュ伐";
+        else
+            remark = "寮�宸ユ姤宸�";
 
         // 鍒涘缓鎶ュ伐璁板綍
         var mesReporting = new MesReporting
+            {
+                CheckType = 1,
+                // ItemNoCade = itemBarCode,
+                // CreateBy = strings[0],
+                BgDate = DateTime.Now,
+                // BgPerson = strings[0],
+                AddressCode = womdaa.AddressCode,
+                MachineNo = womdaa.MachineNo,
+                BfQty = query.bf,//涓嶈壇鏁伴噺
+                OkQty = okQty,//鑹搧鏁伴噺
+                CsQty = query.initCjNum,//鍒濆閲囬泦鏁�
+                CjQty = query.currentCjNum,//鎶ュ伐鏃堕噰闆嗘暟
+                ItemNo = womdaa.Daa002,
+                BillNo = womdaa.Daa001,
+                BgPerson = query.staffNo,
+                Remark = remark // 鏂板锛氳皟鏈烘姤宸ユ椂鍐欏叆澶囨敞
+            };
+
+        //闈炶皟鏈烘姤宸ヨЕ鍙戞洿鏂板伐鍗曡壇鍝佸拰涓嶈壇鍝佹暟閲�
+        if (query.type != "tiaoji")
+        { 
+            // 鏇存柊宸ュ崟Daa011涓哄師鍊煎姞涓婃湰娆¤壇鍝佹暟閲忥紝Daa012涓哄師鍊煎姞涓婃湰娆′笉鑹搧鏁伴噺
+            Db.Updateable<Womdaa>()
+            .SetColumns(x => x.Daa011 == (womdaa.Daa011 ?? 0) + (okQty ?? 0))
+            .SetColumns(x => x.Daa012 == (womdaa.Daa012 ?? 0) + (query.bf ?? 0))
+            .Where(x => x.Daa001 == womdaa.Daa001)
+            .ExecuteCommand();
+        }
+
+        // 鍒ゆ柇鏄惁鍏ㄩ儴瀹屽伐锛岃嫢鏄垯鍐欏叆瀹為檯瀹屽伐鏃ユ湡
+        var womdaaAfter = Db.Queryable<Womdaa>()
+            .Where(s => s.Daa001 == query.orderNo)
+            .First();
+        if (womdaaAfter != null && womdaaAfter.Daa011 >= womdaaAfter.Daa008)
         {
-            CheckType = 1,
-            // ItemNoCade = itemBarCode,
-            // CreateBy = strings[0],
-            BgDate = DateTime.Now,
-            // BgPerson = strings[0],
-            AddressCode = womdaa.AddressCode,
-            MachineNo = womdaa.MachineNo,
-            BfQty = query.bf,
-            // OkQty = print,
-            ItemNo = womdaa.Daa002,
-            BillNo = womdaa.Daa001,
-            BgPerson = query.staffNo // 鏂板锛氭姤宸ヤ汉缂栧彿
-        };
+            var finishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            Db.Updateable<Womdaa>()
+                .SetColumns(x => x.Daa017 == DateTime.Parse(finishTime))
+                .SetColumns(x => x.Daa018 == "瀹屽伐")
+                .Where(x => x.Daa001 == womdaaAfter.Daa001)
+                .ExecuteCommand();
+
+            // 鍚屾鏇存柊MES_ORDER_STA鐨凟ND_TIME
+            Db.Updateable<object>()
+                .AS("MES_ORDER_STA")
+                .SetColumns("END_TIME", finishTime)
+                .Where($"ORDER_NO = '{womdaaAfter.Daa001}'")
+                .ExecuteCommand();
+        }
 
         // 鎻掑叆鎶ュ伐璁板綍鍜屾潯鐮佽褰�
         return Db.Insertable(mesReporting)
@@ -326,7 +373,7 @@
         var s1 = DateTime.Now.ToString("yyyy-MM-dd");
 
         // 鑾峰彇鏁伴噰鏁版嵁
-        var CjQty = Db.Queryable<MesNumerical>()
+        var CjQty = Db.Queryable<MesNumericalBycl>()
             .Where(s =>
                 s.MachineNo == mesReporting.MachineNo && s.EditDate == s1)
             .OrderByDescending(s => s.CjTiem)
@@ -362,12 +409,12 @@
 
         // 鏇存柊鎶ュ伐璁板綍
         Db.Updateable<MesReporting>()
-            .SetColumns(a => a.BlQty == BlQty.ToString())
-            .SetColumns(a => a.CsQty == anchors.InitialValue.ToString())
-            .SetColumns(a => a.JtQty == jt.ToString())
+            .SetColumns(a => a.BlQty == BlQty)
+            .SetColumns(a => a.CsQty == (anchors.InitialValue ?? 0))
+            .SetColumns(a => a.JtQty == jt)
             // .SetColumns(a => a.BfQty == bfQty)
-            .SetColumns(a => a.CjQty == ljcj.ToString())
-            .SetColumns(a => a.DyQty == DyQty.ToString())
+            .SetColumns(a => a.CjQty == ljcj)
+            .SetColumns(a => a.DyQty == DyQty)
             .Where(a => a.ItemNoCade == mesReporting.ItemNoCade)
             .ExecuteCommand();
     }

--
Gitblit v1.9.3