快乐的昕的电脑
2025-10-24 3244edf4bdbe0889cbdc85bd8fe161de0ecc3580
Services/MesOrderStaManager.cs
@@ -150,15 +150,12 @@
        // ================== 不合格后重新送检(Flag == 2)==================
        else if (entity.Flag == 2)
        {
            // 首检不合格后直接生成新的首检单:
            // 1. 加锁防并发
            // 2. 若不存在首检 -> 直接生成
            // 3. 若存在且为“不合格” -> 先作废旧单(Fcancel='Y')再生成新单(绕过存储过程内部只允许一单的限制)
            // 4. 若已合格 -> 不生成
            Db.Ado.ExecuteCommand("SELECT ID FROM WOMDAA WHERE DAA001 = :BILL_NO FOR UPDATE",
            // 加锁防并发
            Db.Ado.ExecuteCommand(
                "SELECT ID FROM WOMDAA WHERE DAA001 = :BILL_NO FOR UPDATE",
                new SugarParameter("BILL_NO", womdaa.Daa001));
            // 最新未作废首检单
            // 查询最新未作废首检单
            var latestFirst = Db.Queryable<MesQaItemsDetect02>()
                .Where(s => s.Aufnr == womdaa.Daa001
                            && s.Ftype == "首检"
@@ -166,25 +163,16 @@
                .OrderBy(s => s.CreateDate, OrderByType.Desc)
                .First();
            var needCreate = false;
            // 只要最新首检单为“不合格”,则创建新单
            if (latestFirst != null && latestFirst.FcheckResu == "不合格")
            {
                // 作废旧单
                //Db.Updateable<MesQaItemsDetect02>()
                //    .SetColumns(s => s.Fcancel == "Y")
                //    .Where(s => s.Id == latestFirst.Id && (s.Fcancel == null || s.Fcancel != "Y"))
                //    .ExecuteCommand();
            if (latestFirst == null)
            {
                // 没有任何有效首检单,需要创建
                needCreate = true;
            }
            else if (latestFirst.FcheckResu == "不合格")
            {
                // 旧单不合格,先作废再创建新单
                Db.Updateable<MesQaItemsDetect02>()
                    .SetColumns(s => s.Fcancel == "Y")
                    .Where(s => s.Id == latestFirst.Id && (s.Fcancel == null || s.Fcancel != "Y"))
                    .ExecuteCommand();
                needCreate = true;
            }
            if (needCreate)
            {
                // 创建新首检单
                Db.Ado.ExecuteCommand(
                    "BEGIN AUTOMATIC_IPQC_FIRST_CHECK(:BILL_NO); END;",
                    new SugarParameter("BILL_NO", womdaa.Daa001, System.Data.DbType.String));
@@ -206,9 +194,7 @@
                        .ExecuteCommand();
                }
            }
        // 已有且合格 -> 不执行创建
        // 若最新已合格则不生成新单,直接继续后续流程(不覆盖其备注)
    }
        }
        // ========= 首检不合格清空送检时间处理(Flag != 2 时才清空;并生成统一 remark) =========
        string remarkToSet = null;      // 最终要写入 MES_ORDER_STA.remark 的内容