From e937af660a22640ace71147853cb70078673928f Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期二, 12 八月 2025 16:17:30 +0800
Subject: [PATCH] 111

---
 MES.Service/service/QC/XJService.cs     |  136 +++++++-----
 MES.Service/Modes/QsItemOqcReq.cs       |    1 
 MES.Service/Modes/QsQaItemXj.cs         |    2 
 MES.Service/service/QC/RKJService.cs    |  422 ++++++++++++++++++++++++++++++++---------
 MES.Service/Dto/service/SJPageResult.cs |    6 
 5 files changed, 415 insertions(+), 152 deletions(-)

diff --git a/MES.Service/Dto/service/SJPageResult.cs b/MES.Service/Dto/service/SJPageResult.cs
index 13a94fb..f48f3af 100644
--- a/MES.Service/Dto/service/SJPageResult.cs
+++ b/MES.Service/Dto/service/SJPageResult.cs
@@ -100,4 +100,10 @@
     /// </summary>
     [SugarColumn(ColumnName = "DAA008")]
     public decimal? Daa008 { get; set; }
+    
+    /// <summary>
+    ///     绾夸綋鍚嶇О
+    /// </summary>
+    [SugarColumn(ColumnName = "LINE_NAME")]
+    public string? LineName { get; set; }
 }
\ No newline at end of file
diff --git a/MES.Service/Modes/QsItemOqcReq.cs b/MES.Service/Modes/QsItemOqcReq.cs
index b1fb7b6..c97a1af 100644
--- a/MES.Service/Modes/QsItemOqcReq.cs
+++ b/MES.Service/Modes/QsItemOqcReq.cs
@@ -135,4 +135,5 @@
     [SugarColumn(IsIgnore = true)] public string? LineNo { get; set; }
 
     [SugarColumn(IsIgnore = true)] public decimal? Quantity { get; set; }
+    [SugarColumn(IsIgnore = true)] public string? CreateUser { get; set; }
 }
\ No newline at end of file
diff --git a/MES.Service/Modes/QsQaItemXj.cs b/MES.Service/Modes/QsQaItemXj.cs
index a54b53a..ac83f3c 100644
--- a/MES.Service/Modes/QsQaItemXj.cs
+++ b/MES.Service/Modes/QsQaItemXj.cs
@@ -134,4 +134,6 @@
     [SugarColumn(IsIgnore = true)] public string? ItemName { get; set; }
 
     [SugarColumn(IsIgnore = true)] public string? ItemModel { get; set; }
+    [SugarColumn(IsIgnore = true)] public string? LineName { get; set; }
+    [SugarColumn(IsIgnore = true)] public string? CreateUser { get; set; }
 }
\ No newline at end of file
diff --git a/MES.Service/service/QC/RKJService.cs b/MES.Service/service/QC/RKJService.cs
index 442754b..8ed4bca 100644
--- a/MES.Service/service/QC/RKJService.cs
+++ b/MES.Service/service/QC/RKJService.cs
@@ -67,107 +67,159 @@
     //鏍规嵁妫�楠屾爣鍑嗘潵璁$畻妫�楠屼釜鏁�
     public List<QsItemOqcItem> SetItems(string itemNo, decimal quantity)
     {
+        // 鍙傛暟楠岃瘉
+        if (string.IsNullOrWhiteSpace(itemNo))
+            throw new ArgumentException("鐗╂枡缂栧彿涓嶈兘涓虹┖", nameof(itemNo));
+        
+        if (quantity <= 0)
+            throw new ArgumentException("鏁伴噺蹇呴』澶т簬0", nameof(quantity));
+
         var db = SqlSugarHelper.GetInstance();
 
-        var count = db.Queryable<MesQa>().Where(s => s.QsType == "3"
-            && s.ItemNo == itemNo && s.Fsubmit == 1).Count();
+        // 楠岃瘉鐗╂枡鏄惁瀛樺湪妫�楠屾爣鍑�
+        var count = db.Queryable<MesQa>()
+            .Where(s => s.QsType == "3" && s.ItemNo == itemNo && s.Fsubmit == 1)
+            .Count();
 
-        if (count <= 0) return [];
+        if (count <= 0) 
+            return [];
 
-        var qsItemOqcItems = db
-            .Queryable<MesQualityStandard>()
-            .Where(b => b.QsType == "3"
-                        && b.ItemNo == itemNo).Select(
-                b => new QsItemOqcItem
-                {
-                    ProjName = b.ProjName,
-                    ItemMod = b.ItemMod,
-                    InspectionMethod = b.InspectionMethod,
-                    UsingInstruments = b.UsingInstruments,
-                    LevelNum = SqlFunc.IsNull(
-                        SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
-                        b.InspectionLevel),
-                    MaxValue = b.MaxValue,
-                    StandardValue = b.StandardValue,
-                    MinValue = b.MinValue,
-                    Notes = b.Notes,
-                    FcheckLevel = b.FcheckLevel,
-                    FacLevel = b.FacLevel,
-                    QsCode = b.QsCode,
-                    QsName = b.QsName,
-                    Result = "鏈娴�",
-                    isCheck = 0,
-                    Picture = b.Picture,
-                    Picturename = b.Picturename
-                }).ToList();
-
-        qsItemOqcItems.ForEach(item =>
-        {
-            string LEV = null;
-            switch (item.FcheckLevel)
+        // 鑾峰彇璐ㄩ噺鏍囧噯
+        var qsItemOqcItems = db.Queryable<MesQualityStandard>()
+            .Where(b => b.QsType == "3" && b.ItemNo == itemNo)
+            .Select(b => new QsItemOqcItem
             {
-                case string s when s.Contains("S1"):
-                    LEV = "B.FLEVEL_S1";
-                    break;
-                case string s when s.Contains("S2"):
-                    LEV = "B.FLEVEL_S2";
-                    break;
-                case string s when s.Contains("S3"):
-                    LEV = "B.FLEVEL_S3";
-                    break;
-                case string s when s.Contains("S4"):
-                    LEV = "B.FLEVEL_S4";
-                    break;
-                case string s when s.Contains("(I)"):
-                    LEV = "B.FLEVEL_I";
-                    break;
-                case string s when s.Contains("(II)"):
-                    LEV = "B.FLEVEL_II";
-                    break;
-                case string s when s.Contains("(III)"):
-                    LEV = "B.FLEVEL_III";
-                    break;
-                default:
-                    LEV = ""; // 榛樿鍊�
-                    break;
+                ProjName = b.ProjName,
+                ItemMod = b.ItemMod,
+                InspectionMethod = b.InspectionMethod,
+                UsingInstruments = b.UsingInstruments,
+                LevelNum = SqlFunc.IsNull(
+                    SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
+                    b.InspectionLevel),
+                MaxValue = b.MaxValue,
+                StandardValue = b.StandardValue,
+                MinValue = b.MinValue,
+                Notes = b.Notes,
+                FcheckLevel = b.FcheckLevel,
+                FacLevel = b.FacLevel,
+                QsCode = b.QsCode,
+                QsName = b.QsName,
+                Result = "鏈娴�",
+                isCheck = 0,
+                Picture = b.Picture,
+                Picturename = b.Picturename
+            }).ToList();
+
+        if (!qsItemOqcItems.Any())
+            return [];
+
+        // 澶勭悊姣忎釜妫�楠岄」鐩�
+        foreach (var item in qsItemOqcItems)
+        {
+            try
+            {
+                ProcessQualityItem(db, item, quantity);
             }
-
-            var sql =
-                "SELECT " + LEV +
-                " FROM MES_QM_AQL1 A LEFT JOIN MES_QM_AQL2 B ON B.AQL1_ID=A.ID WHERE A.SAMPLE_SIZE_NO='" +
-                item.QsCode + "' AND B.LOT_FROM<= " + quantity + "   AND " +
-                quantity + "<=B.LOT_TO";
-
-            var maxBillNo = db.Ado.SqlQuerySingle<string>(sql);
-
-
-            var result = ExtractSubstring(item.FacLevel, '(', ')');
-
-
-            sql = "SELECT FSAMPLE_SIZE_WORD, " + result +
-                  " Result FROM MES_QM_AQL1 A LEFT JOIN MES_QM_AQL3 C ON C.AQL1_ID=A.ID WHERE A.SAMPLE_SIZE_NO= '" +
-                  item.QsCode + "'  AND SAMPLE_SIZE_WORD= '" + maxBillNo + "'";
-            var resultClass = db.Ado.SqlQuerySingle<ResultClass>(sql);
-
-            item.LevelNum = resultClass.FSAMPLE_SIZE_WORD;
-            item.FreQty = resultClass.Result;
-        });
+            catch (Exception ex)
+            {
+                // 璁板綍閿欒浣嗙户缁鐞嗗叾浠栭」鐩�
+                item.LevelNum = 1; // 璁剧疆榛樿鍊�
+                item.FreQty = 0;
+                item.Notes = $"澶勭悊寮傚父: {ex.Message}";
+            }
+        }
 
         return qsItemOqcItems;
     }
 
+    private void ProcessQualityItem(ISqlSugarClient db, QsItemOqcItem item, decimal quantity)
+    {
+        // 楠岃瘉蹇呰瀛楁
+        if (string.IsNullOrWhiteSpace(item.FcheckLevel) || string.IsNullOrWhiteSpace(item.QsCode))
+        {
+            item.LevelNum = 1;
+            item.FreQty = 0;
+            return;
+        }
+
+        // 鑾峰彇妫�楠岀骇鍒搴旂殑鏁版嵁搴撳瓧娈�
+        var levelField = GetLevelField(item.FcheckLevel);
+        
+        // 浣跨敤鍙傛暟鍖栨煡璇㈤槻姝QL娉ㄥ叆
+        var sql = $"SELECT {levelField} FROM MES_QM_AQL1 A LEFT JOIN MES_QM_AQL2 B ON B.AQL1_ID = A.ID " +
+                  $"WHERE A.SAMPLE_SIZE_NO = @QsCode AND B.LOT_FROM <= @Quantity AND @Quantity <= B.LOT_TO";
+        
+        var aqlResult = db.Ado.SqlQuerySingle<string>(sql, new { QsCode = item.QsCode, Quantity = quantity });
+
+        if (string.IsNullOrWhiteSpace(aqlResult))
+        {
+            item.LevelNum = 1;
+            item.FreQty = 0;
+            return;
+        }
+
+        // 鎻愬彇FacLevel涓殑鍊�
+        var facLevelValue = ExtractSubstring(item.FacLevel ?? "", '(', ')');
+        if (string.IsNullOrWhiteSpace(facLevelValue))
+        {
+            item.LevelNum = decimal.TryParse(aqlResult, out var level) ? level : 1;
+            item.FreQty = 0;
+            return;
+        }
+
+        // 鑾峰彇鏍锋湰澶у皬鍜岀粨鏋�
+        var resultSql = $"SELECT FSAMPLE_SIZE_WORD, {facLevelValue} as Result FROM MES_QM_AQL1 A " +
+                       $"LEFT JOIN MES_QM_AQL3 C ON C.AQL1_ID = A.ID " +
+                       $"WHERE A.SAMPLE_SIZE_NO = @QsCode AND SAMPLE_SIZE_WORD = @LevelValue";
+        
+        var resultQuery = db.Ado.SqlQuerySingle<ResultClass>(resultSql, 
+            new { QsCode = item.QsCode, LevelValue = aqlResult });
+
+        if (resultQuery != null)
+        {
+            item.LevelNum = resultQuery.FSAMPLE_SIZE_WORD;
+            item.FreQty = resultQuery.Result;
+        }
+        else
+        {
+            item.LevelNum = 1;
+            item.FreQty = 0;
+        }
+    }
+
+    private string GetLevelField(string checkLevel)
+    {
+        if (string.IsNullOrWhiteSpace(checkLevel))
+            return "B.FLEVEL_S1";
+
+        return checkLevel switch
+        {
+            var s when s.Contains("S1") => "B.FLEVEL_S1",
+            var s when s.Contains("S2") => "B.FLEVEL_S2", 
+            var s when s.Contains("S3") => "B.FLEVEL_S3",
+            var s when s.Contains("S4") => "B.FLEVEL_S4",
+            var s when s.Contains("(I)") => "B.FLEVEL_I",
+            var s when s.Contains("(II)") => "B.FLEVEL_II",
+            var s when s.Contains("(III)") => "B.FLEVEL_III",
+            _ => "B.FLEVEL_S1"
+        };
+    }
+
     private string ExtractSubstring(string input, char startChar, char endChar)
     {
-        var startIndex = input.IndexOf(startChar);
-        var endIndex = input.IndexOf(endChar, startIndex);
-
-        if (startIndex == -1 || endIndex == -1)
-            // 濡傛灉鏈壘鍒拌捣濮嬪瓧绗︽垨缁撴潫瀛楃锛屽垯杩斿洖绌哄瓧绗︿覆鎴栬�呮姏鍑哄紓甯革紝鏍规嵁瀹為檯鎯呭喌閫夋嫨
+        if (string.IsNullOrWhiteSpace(input))
             return string.Empty;
-        // 鎴栬�呮姏鍑哄紓甯�
-        // throw new ArgumentException("Start or end character not found");
-        // 鎻愬彇瀛愬瓧绗︿覆
+
+        var startIndex = input.IndexOf(startChar);
+        var endIndex = input.IndexOf(endChar, startIndex + 1);
+
+        if (startIndex == -1 || endIndex == -1 || endIndex <= startIndex)
+            return string.Empty;
+
         var length = endIndex - startIndex - 1;
+        if (length <= 0)
+            return string.Empty;
+
         return input.Substring(startIndex + 1, length);
     }
 
@@ -462,27 +514,28 @@
         var totalCount = 0;
         
 
-        var query = db.Queryable<QsItemOqcReq, MesItems, Womdaa,MesLine>((a, b, da,c) =>
+        var query = db.Queryable<QsItemOqcReq, MesItems, Womdaa,MesLine,SysUser>((a, b, da,c,us) =>
             new JoinQueryInfos(
                 JoinType.Left, a.ItemNo == b.ItemNo,       // 鍏宠仈鐗╂枡淇℃伅
                 JoinType.Left, a.BillNo == da.Daa001,       // 鍏宠仈宸ュ崟淇℃伅
-                JoinType.Left, da.Daa015 == c.LineNo        // 鍏宠仈宸ュ崟淇℃伅
+                JoinType.Left, da.Daa015 == c.LineNo,        // 鍏宠仈宸ュ崟淇℃伅
+                JoinType.Left, us.Fcode == a.CreateBy         // 鍏宠仈宸ュ崟淇℃伅
             ))
             // 鐢ㄦ埛绾夸綋杩囨护鏉′欢
             //.WhereIF(lineNo != null && lineNo.Length > 0 && !"PL017".Equals(queryObj.createUser),
             //    (a, b, da) => lineNo.Contains(da.Daa015))
             // ID绮剧‘鏌ヨ
             .WhereIF(!string.IsNullOrEmpty(queryObj.id),
-                (a, b, da,c) => a.Id.ToString() == queryObj.id)
+                (a, b, da,c,us) => a.Id.ToString() == queryObj.id)
             // 瀹屾垚鐘舵�佽繃婊�
-            .WhereIF("鏈畬鎴�".Equals(queryObj.result), (a, b, da,c) => a.FcheckResu == null)
-            .WhereIF(!"鏈畬鎴�".Equals(queryObj.result), (a, b, da,c) => a.FcheckResu != null)
+            .WhereIF("鏈畬鎴�".Equals(queryObj.result), (a, b, da,c,us) => a.FcheckResu == null)
+            .WhereIF(!"鏈畬鎴�".Equals(queryObj.result), (a, b, da,c,us) => a.FcheckResu != null)
             // 鎼滅储鏉′欢锛堢墿鏂欏悕绉�/缂栧彿锛�
             .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue),
-                (a, b, da,c) => b.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()) ||
-                                a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
+                (a, b, da,c,us) => b.ItemName.ToLower().Contains(queryObj.SearchValue.ToLower()) ||
+                                   a.ItemNo.ToLower().Contains(queryObj.SearchValue.ToLower()))
             // 鏌ヨ瀛楁
-            .Select((a, b, da,c) => new QsItemOqcReq
+            .Select((a, b, da,c,us) => new QsItemOqcReq
             {
                 Id = a.Id,
                 BillNo = a.BillNo,
@@ -491,6 +544,7 @@
                 ItemModel = b.ItemModel,
                 CreateDate = a.CreateDate,
                 CreateBy = a.CreateBy,
+                CreateUser = us.Fname,
                 FcheckResu = a.FcheckResu,
                 FcheckBy = a.FcheckBy,
                 FcheckDate = a.FcheckDate,
@@ -630,11 +684,189 @@
         });
     }
 
+    // 鍘熷saveItem鏂规硶锛堝凡浼樺寲锛屽浠界増鏈湪saveItemOriginal锛�
     public int saveItem(RKJDto rkjDto)
     {
         var items = rkjDto.items;
         var userNo = rkjDto.userNo;
 
+        return SqlSugarHelper.UseTransactionWithOracle(db =>
+        {
+            var commit = 0;
+            
+            // 1. 娓呯┖鐜版湁鐨勬楠岃缁嗚褰曪紙瀛欒〃锛�
+            commit += db.Deleteable<QsItemOqcItemDetail>()
+                .Where(s => s.Gid == rkjDto.gid)
+                .ExecuteCommand();
+            
+            // 2. 娓呯┖鐜版湁鐨勬楠岄」鐩褰曪紙瀛愯〃锛�
+            commit += db.Deleteable<QsItemOqcItem>()
+                .Where(s => s.Pid == rkjDto.gid)
+                .ExecuteCommand();
+            
+            // 3. 鎵归噺鎻掑叆items
+            foreach (var item in items) item.Pid = rkjDto.gid;
+            commit += db.Insertable(items).ExecuteCommand();
+
+            // 4. 鑾峰彇闇�瑕佸鐞嗙殑妫�楠岄」鐩紙鍙煡璇㈠繀瑕佸瓧娈垫彁鍗囨�ц兘锛�
+            var processItems = db.Queryable<QsItemOqcItem>()
+                .Where(s => s.Pid == rkjDto.gid && 
+                           s.MaxValue == null && s.StandardValue == null && s.MinValue == null)
+                .Select(s => new { s.Id, s.LevelNum })
+                .ToList();
+
+            if (!processItems.Any())
+            {
+                return Convert.ToInt32(rkjDto.gid);
+            }
+
+            // 5. 鎵归噺鍒涘缓鎵�鏈塓sItemOqcItemDetail
+            var allDetails = new List<QsItemOqcItemDetail>();
+            foreach (var item in processItems)
+            {
+                var levelNum = (int)(item.LevelNum ?? 1);
+                for (int i = 0; i < levelNum; i++)
+                {
+                    allDetails.Add(new QsItemOqcItemDetail
+                    {
+                        Gid = rkjDto.gid,
+                        Pid = item.Id,
+                        Fstand = "鈭�",
+                        FcheckResu = "1",
+                        CreateBy = userNo,
+                        CreateDate = DateTime.Now
+                    });
+                }
+            }
+
+            // 6. 鎵归噺鎻掑叆鎵�鏈塪etails
+            if (allDetails.Any())
+            {
+                commit += db.Insertable(allDetails).ExecuteCommand();
+            }
+
+            // 7. 鎵归噺鏇存柊IsPass鐘舵�佷负鍚堟牸锛堝洜涓烘墍鏈塪etail閮芥槸鍚堟牸鐨勶級
+            var itemIds = processItems.Select(x => x.Id).ToList();
+            if (itemIds.Any())
+            {
+                commit += db.Updateable<QsItemOqcItem>()
+                    .SetColumns(s => s.IsPass == 1)
+                    .Where(s => itemIds.Contains(s.Id))
+                    .ExecuteCommand();
+            }
+
+            // 8. 妫�鏌ュ苟鏇存柊涓绘楠屽崟鐘舵��
+            commit += UpdateMainInspectionStatus(db, rkjDto.gid, userNo);
+
+            return Convert.ToInt32(rkjDto.gid);
+        });
+    }
+
+    private int UpdateMainInspectionStatus(ISqlSugarClient db, decimal? gid, string userNo)
+    {
+        // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勬楠岄」鐩�
+        var unfinishedCount = db.Queryable<QsItemOqcItem>()
+            .Where(s => s.Pid == gid && s.IsPass == null)
+            .Count();
+
+        if (unfinishedCount > 0)
+        {
+            return 0; // 杩樻湁鏈畬鎴愮殑椤圭洰锛屼笉鏇存柊涓绘楠屽崟鐘舵��
+        }
+
+        // 鑾峰彇妫�楠屽崟鐨勬楠岄」鐩�绘暟鍜屽悎鏍兼暟
+        var totalCount = db.Queryable<QsItemOqcItem>()
+            .Where(s => s.Pid == gid)
+            .Count();
+
+        if (totalCount == 0)
+        {
+            return 0; // 娌℃湁妫�楠岄」鐩�
+        }
+
+        var passedCount = db.Queryable<QsItemOqcItem>()
+            .Where(s => s.Pid == gid && s.IsPass == 1)
+            .Count();
+
+        // 纭畾妫�楠岀粨鏋�
+        var checkResult = totalCount == passedCount ? "鍚堟牸" : "涓嶅悎鏍�";
+
+        // 鏇存柊涓绘楠屽崟鐘舵��
+        var updateResult = db.Updateable<QsItemOqcReq>()
+            .SetColumns(s => s.FcheckResu == checkResult)
+            .SetColumns(s => s.FcheckDate == DateTime.Now)
+            .SetColumns(s => s.FcheckBy == userNo)
+            .SetColumns(s => s.LastupdateBy == userNo)
+            .SetColumns(s => s.LastupdateDate == DateTime.Now)
+            .Where(s => s.Id == gid)
+            .ExecuteCommand();
+
+        // 濡傛灉妫�楠屼笉鍚堟牸锛岀敓鎴愬紓甯稿绛栬褰�
+        if (checkResult.Equals("涓嶅悎鏍�"))
+        {
+            GenerateQualityIssueRecord(db, gid, userNo);
+        }
+
+        return updateResult;
+    }
+
+    private void GenerateQualityIssueRecord(ISqlSugarClient db, decimal? gid, string userNo)
+    {
+        try
+        {
+            var qsItemOqcReq = db.Queryable<QsItemOqcReq>()
+                .Single(s => s.Id == gid);
+
+            if (qsItemOqcReq == null) return;
+
+            var mesInvItemIns = db.Queryable<MesInvItemIns>()
+                .Single(s => s.BillNo == qsItemOqcReq.BillNo);
+
+            if (mesInvItemIns == null) return;
+
+            var mesSchemeResult = db.Queryable<Womdaa>()
+                .Single(s => s.Daa001 == mesInvItemIns.CbillNo);
+
+            if (mesSchemeResult == null) return;
+
+            var entity = new MesQaItemsDetect02
+            {
+                LineNo = mesSchemeResult.Daa015,
+                ReleaseNo = qsItemOqcReq.ReleaseNo,
+                LotNo = qsItemOqcReq.BillNo,
+                FcheckDate = qsItemOqcReq.FcheckDate,
+                FcheckMemo = qsItemOqcReq.Remarks,
+                Gid = qsItemOqcReq.Id,
+                FcheckResu = "涓嶅悎鏍�",
+                FcheckLevel = "涓ラ噸",
+                CreateDate = DateTime.Now,
+                Factory = "10000",
+                Company = "1000",
+                Ftype = "4",
+                Fversion = 0,
+                Modify1Flag = 0,
+                IpqcStatus = 0,
+                Fsubmit = 1,
+                CreateBy = userNo,
+                FcheckBy = userNo
+            };
+
+            db.Insertable(entity).ExecuteCommand();
+        }
+        catch (Exception ex)
+        {
+            // 璁板綍寮傚父浣嗕笉褰卞搷涓绘祦绋�
+            // 鍙互鑰冭檻娣诲姞鏃ュ織璁板綍
+            Console.WriteLine($"鐢熸垚璐ㄩ噺寮傚父璁板綍澶辫触: {ex.Message}");
+        }
+    }
+
+    // 澶囦唤锛氬師濮嬬増鏈殑saveItem鏂规硶
+    public int saveItemOriginal(RKJDto rkjDto)
+    {
+        var items = rkjDto.items;
+        var userNo = rkjDto.userNo;
+
         SqlSugarHelper.UseTransactionWithOracle(db =>
         {
             foreach (var item in items) item.Pid = rkjDto.gid;
diff --git a/MES.Service/service/QC/XJService.cs b/MES.Service/service/QC/XJService.cs
index d4c8dc3..deed3d0 100644
--- a/MES.Service/service/QC/XJService.cs
+++ b/MES.Service/service/QC/XJService.cs
@@ -107,7 +107,8 @@
                 }).ToList();
     }
 
-    public (List<QsQaItemXj> items, int totalCount) getPage(XJPageResult queryObj)
+    public (List<QsQaItemXj> items, int totalCount) getPage(
+        XJPageResult queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
 
@@ -120,13 +121,14 @@
         //if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
         //    lineNo = _baseService.getUserLineNo(queryObj.createUser);
 
-       var query= db
+        var query = db
             .Queryable<QsQaItemXj, Womdaa, MesLine,
-                MesItems>((s, a, c, b) =>
+                MesItems, SysUser>((s, a, c, b, us) =>
                 new JoinQueryInfos(
                     JoinType.Inner, s.BillNo == a.Daa001,
                     JoinType.Left, a.Daa015 == c.LineNo,
-                    JoinType.Left, s.ItemId == b.Id
+                    JoinType.Left, s.ItemId == b.Id,
+                    JoinType.Left, us.Fcode == s.CreateBy
                 )
             )
             //.WhereIF(lineNo != null && lineNo.Length > 0,
@@ -134,17 +136,20 @@
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 "鏈畬鎴�".Equals(queryObj.result),
-                (s, a, c, b) => s.SubmitStatus == 0 || s.SubmitStatus == null)
+                (s, a, c, b, us) =>
+                    s.SubmitStatus == 0 || s.SubmitStatus == null)
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 !"鏈畬鎴�".Equals(queryObj.result),
-                (s, a, c, b) => s.SubmitStatus == 1)
-            .WhereIF(id > 0, (s, a, c, b) => s.Id == id)
-            .Select((s, a, c, b) => new QsQaItemXj
+                (s, a, c, b, us) => s.SubmitStatus == 1)
+            .WhereIF(id > 0, (s, a, c, b, us) => s.Id == id)
+            .Select((s, a, c, b, us) => new QsQaItemXj
             {
                 Daa020 = c.LineNo,
                 Id = s.Id,
                 PlanQty = a.Daa008,
+                LineName = c.LineName,
+                CreateUser = us.Fname,
                 CreateBy = s.CreateBy,
                 CreateDate = s.CreateDate,
                 ReleaseNo = s.ReleaseNo,
@@ -156,7 +161,8 @@
                 CheckResult = s.CheckResult,
                 Remarks = s.Remarks
             }).OrderBy(s => s.CreateDate, OrderByType.Desc);
-        var items = query.ToPageList(queryObj.PageIndex, queryObj.Limit,ref totalCount);
+        var items = query.ToPageList(queryObj.PageIndex, queryObj.Limit,
+            ref totalCount);
 
         return (items, totalCount);
     }
@@ -174,29 +180,28 @@
         return db
             .Queryable<MesQualityStandard>()
             .Where(b => b.QsType == "2"
-                        && b.ItemNo == itemNo).Select(
-                b => new QsQaItemXj01
-                {
-                    ProjName = b.ProjName,
-                    ItemMod = b.ItemMod,
-                    InspectionMethod = b.InspectionMethod,
-                    UsingInstruments = b.UsingInstruments,
-                    LevelNum = SqlFunc.IsNull(
-                        SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
-                        b.InspectionLevel),
-                    MaxValue = b.MaxValue,
-                    StandardValue = b.StandardValue,
-                    MinValue = b.MinValue,
-                    Notes = b.Notes,
-                    FcheckLevel = b.FcheckLevel,
-                    FacLevel = b.FacLevel,
-                    QsCode = b.QsCode,
-                    QsName = b.QsName,
-                    result = "鏈娴�",
-                    isCheck = 0,
-                    Picture = b.Picture,
-                    Picturename = b.Picturename
-                }).ToList();
+                        && b.ItemNo == itemNo).Select(b => new QsQaItemXj01
+            {
+                ProjName = b.ProjName,
+                ItemMod = b.ItemMod,
+                InspectionMethod = b.InspectionMethod,
+                UsingInstruments = b.UsingInstruments,
+                LevelNum = SqlFunc.IsNull(
+                    SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
+                    b.InspectionLevel),
+                MaxValue = b.MaxValue,
+                StandardValue = b.StandardValue,
+                MinValue = b.MinValue,
+                Notes = b.Notes,
+                FcheckLevel = b.FcheckLevel,
+                FacLevel = b.FacLevel,
+                QsCode = b.QsCode,
+                QsName = b.QsName,
+                result = "鏈娴�",
+                isCheck = 0,
+                Picture = b.Picture,
+                Picturename = b.Picturename
+            }).ToList();
     }
 
     public List<QsQaItemXj01> getJYItem(decimal? pid, decimal? id)
@@ -292,7 +297,7 @@
 
         return Convert.ToInt32(xj.Id);
     }
-    
+
     public bool XJQaSubmit(LLJDto rkjDto)
     {
         var useTransactionWithOracle =
@@ -357,20 +362,22 @@
 
             // 鑾峰彇妫�楠岄」鐩暟鎹�
             var jyItems = getJYItemOptimized(db, xjDto.gid.Value);
-            
+
             if (jyItems.Any())
             {
                 // 澶勭悊涓氬姟閫昏緫璁$畻
-                var allDetails = PrepareDetailsData(jyItems, xjDto.gid.Value, userNo);
+                var allDetails =
+                    PrepareDetailsData(jyItems, xjDto.gid.Value, userNo);
 
                 if (allDetails.Count > 0)
                 {
                     // 鎵归噺鎻掑叆妫�楠岃鎯�
                     db.Insertable(allDetails).ExecuteCommand();
-                    
+
                     // 璁$畻缁撴灉
-                    var (pidResults, fcheckResu) = CalculateResults(allDetails, jyItems);
-                    
+                    var (pidResults, fcheckResu) =
+                        CalculateResults(allDetails, jyItems);
+
                     // 鎵归噺鏇存柊妫�楠岄」鐩粨鏋�
                     foreach (var (pidValue, result) in pidResults)
                     {
@@ -381,7 +388,9 @@
                     }
 
                     // 鏇存柊涓昏〃妫�楠岀粨鏋�
-                    var totalSum = jyItems.Where(x => x.MaxValue == null && x.StandardValue == null && x.MinValue == null)
+                    var totalSum = jyItems.Where(x =>
+                            x.MaxValue == null && x.StandardValue == null &&
+                            x.MinValue == null)
                         .Sum(x => x.LevelNum);
                     if (totalSum == allDetails.Count)
                     {
@@ -400,33 +409,39 @@
             return Convert.ToInt32(xjDto.gid);
         });
     }
-    
-    private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db, decimal xjId)
+
+    private List<QsQaItemXj01> getJYItemOptimized(ISqlSugarClient db,
+        decimal xjId)
     {
         return db.Queryable<QsQaItemXj01>()
             .Where(a => a.Pid == xjId)
             .ToList();
     }
-    
-    private (bool isValid, string errorMsg) ValidateItemsData(List<QsQaItemXj01> items)
+
+    private (bool isValid, string errorMsg) ValidateItemsData(
+        List<QsQaItemXj01> items)
     {
         if (items == null || !items.Any()) return (false, "妫�楠岄」鐩笉鑳戒负绌�");
-        
-        var invalidItems = items.Where(x => x.LevelNum <= 0 || string.IsNullOrEmpty(x.ProjName)).ToList();
-        if (invalidItems.Any()) 
+
+        var invalidItems = items
+            .Where(x => x.LevelNum <= 0 || string.IsNullOrEmpty(x.ProjName))
+            .ToList();
+        if (invalidItems.Any())
             return (false, $"瀛樺湪{invalidItems.Count}涓棤鏁堢殑妫�楠岄」鐩�");
-        
+
         return (true, "");
     }
 
-    private List<QsQaItemXj02> PrepareDetailsData(List<QsQaItemXj01> jyItems, decimal gid, string userNo)
+    private List<QsQaItemXj02> PrepareDetailsData(List<QsQaItemXj01> jyItems,
+        decimal gid, string userNo)
     {
         var allDetails = new List<QsQaItemXj02>();
         var now = DateTime.Now;
-        
+
         foreach (var s in jyItems)
         {
-            if (s.MaxValue != null || s.StandardValue != null || s.MinValue != null)
+            if (s.MaxValue != null || s.StandardValue != null ||
+                s.MinValue != null)
                 continue;
 
             for (var i = 0; i < s.LevelNum; i++)
@@ -442,15 +457,17 @@
                 });
             }
         }
+
         return allDetails;
     }
 
-    private (List<(decimal pid, int result)> pidResults, string fcheckResu) CalculateResults(
-        List<QsQaItemXj02> allDetails, List<QsQaItemXj01> jyItems)
+    private (List<(decimal pid, int result)> pidResults, string fcheckResu)
+        CalculateResults(
+            List<QsQaItemXj02> allDetails, List<QsQaItemXj01> jyItems)
     {
         var pidGroups = allDetails.GroupBy(x => x.Pid).ToList();
         var pidResults = new List<(decimal pid, int result)>();
-        
+
         foreach (var group in pidGroups)
         {
             var count = group.Count();
@@ -459,11 +476,16 @@
             pidResults.Add((group.Key.Value, result));
         }
 
-        var totalSum = jyItems.Where(x => x.MaxValue == null && x.StandardValue == null && x.MinValue == null)
+        var totalSum = jyItems.Where(x =>
+                x.MaxValue == null && x.StandardValue == null &&
+                x.MinValue == null)
             .Sum(x => x.LevelNum);
         var totalCount = allDetails.Count;
         var totalPassCount = allDetails.Count(x => x.Fstand == "鈭�");
-        var fcheckResu = (totalSum == totalCount && totalCount == totalPassCount) ? "鍚堟牸" : "涓嶅悎鏍�";
+        var fcheckResu =
+            (totalSum == totalCount && totalCount == totalPassCount)
+                ? "鍚堟牸"
+                : "涓嶅悎鏍�";
 
         return (pidResults, fcheckResu);
     }
@@ -547,8 +569,8 @@
 
         if (count == passCount) result = 1;
 
-        var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle(
-            db =>
+        var useTransactionWithOracle =
+            SqlSugarHelper.UseTransactionWithOracle(db =>
             {
                 var commit = 0;
                 commit += db.Updateable<QsQaItemXj01>()

--
Gitblit v1.9.3