From 8276722de62e0be1e68adf65f150686a236268bd Mon Sep 17 00:00:00 2001
From: zjh <2207896513@qq.com>
Date: 星期五, 18 七月 2025 10:08:44 +0800
Subject: [PATCH] 产测接口代码提交

---
 StandardPda/MES.Service/service/QC/RKJService.cs |  319 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 260 insertions(+), 59 deletions(-)

diff --git a/StandardPda/MES.Service/service/QC/RKJService.cs b/StandardPda/MES.Service/service/QC/RKJService.cs
index 8656f8a..5cb1599 100644
--- a/StandardPda/MES.Service/service/QC/RKJService.cs
+++ b/StandardPda/MES.Service/service/QC/RKJService.cs
@@ -57,11 +57,10 @@
     public List<RkDaa002> GetDaa001s(string lineNo)
     {
         var db = SqlSugarHelper.GetInstance();
-        // return db.Queryable<RKJDaa001>()
-        //     .Where(t => t.LineNo == lineNo)
-        //     .OrderBy(t => t.BillNo, OrderByType.Desc)
-        //     .ToList();
-        return null;
+        return db.Queryable<RkDaa002>()
+            .Where(t => lineNo.Contains(t.Daa020))
+            .OrderBy(t => t.BillNo, OrderByType.Desc)
+            .ToList();
     }
 
     //鏍规嵁妫�楠屾爣鍑嗘潵璁$畻妫�楠屼釜鏁�
@@ -77,60 +76,65 @@
         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();
+                        && 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)
             {
-                case string s when s.Contains("S1"):
+                case null:
+                    LEV = ""; // 榛樿鍊�
+                    break;
+                case { } s when s.Contains("S1"):
                     LEV = "B.FLEVEL_S1";
                     break;
-                case string s when s.Contains("S2"):
+                case { } s when s.Contains("S2"):
                     LEV = "B.FLEVEL_S2";
                     break;
-                case string s when s.Contains("S3"):
+                case { } s when s.Contains("S3"):
                     LEV = "B.FLEVEL_S3";
                     break;
-                case string s when s.Contains("S4"):
+                case { } s when s.Contains("S4"):
                     LEV = "B.FLEVEL_S4";
                     break;
-                case string s when s.Contains("(I)"):
+                case { } s when s.Contains("(I)"):
                     LEV = "B.FLEVEL_I";
                     break;
-                case string s when s.Contains("(II)"):
+                case { } s when s.Contains("(II)"):
                     LEV = "B.FLEVEL_II";
                     break;
-                case string s when s.Contains("(III)"):
+                case { } s when s.Contains("(III)"):
                     LEV = "B.FLEVEL_III";
                     break;
                 default:
                     LEV = ""; // 榛樿鍊�
                     break;
             }
+
+            if (string.IsNullOrEmpty(LEV))
+                throw new Exception(item.QsCode + "涓嬬殑妫�楠屾按骞崇淮鎶ょ殑涓嶆纭�");
 
             var sql =
                 "SELECT " + LEV +
@@ -140,9 +144,15 @@
 
             var maxBillNo = db.Ado.SqlQuerySingle<string>(sql);
 
+            if (string.IsNullOrEmpty(maxBillNo))
+                throw new Exception(
+                    item.QsCode + "涓嬫病鏈�" + quantity + "杩欎釜鑼冨洿鐨勬娊鏍峰熀鍑�");
 
             var result = ExtractSubstring(item.FacLevel, '(', ')');
 
+            if (string.IsNullOrEmpty(result))
+                throw new Exception(item.QsCode +
+                                    "缁存姢鐨勬帴鏀舵按骞充笉姝g‘锛屽簲璇ユ槸0.010---(AQL_0_0010)杩欐牱");
 
             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= '" +
@@ -302,6 +312,17 @@
 
     public int SetQSItemDetail(QsItemOqcItemDetail detail)
     {
+        var db = SqlSugarHelper.GetInstance();
+
+        var qsItemOqcReq = db.Queryable<QsItemOqcReq>()
+            .Where(o => o.Id == detail.Gid)
+            .First();
+
+        if (qsItemOqcReq == null) throw new Exception("璇ユ楠屽崟涓嶅瓨鍦紝璇峰洖鍒板叆搴撴鍒楄〃閲嶆柊鏌ョ湅");
+
+        if (!string.IsNullOrEmpty(qsItemOqcReq.FcheckResu))
+            throw new Exception("璇ユ楠屽崟宸�" + qsItemOqcReq.FcheckResu + "锛屼笉杩愯淇敼缁撴灉");
+
         var oracle = SqlSugarHelper.UseTransactionWithOracle(db =>
         {
             List<QsItemOqcItemDetail> result = new();
@@ -355,8 +376,8 @@
             result = 1;
         else if (count - passCount < QsItemOqcItem.FreQty) result = 1;
 
-        var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle(
-            db =>
+        var useTransactionWithOracle =
+            SqlSugarHelper.UseTransactionWithOracle(db =>
             {
                 var commit = 0;
                 commit += db.Updateable<QsItemOqcItem>()
@@ -402,11 +423,110 @@
                 .ExecuteCommand();
         });
 
-        if (FcheckResu.Equals("涓嶅悎鏍�"))
-            //鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥
-            saveDetect02(detail.Gid, detail.CreateBy);
+        // if (FcheckResu.Equals("涓嶅悎鏍�"))
+        //     //鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥
+        //     saveDetect02(detail.Gid, detail.CreateBy);
+
+        setBarCodes(FcheckResu, detail, db);
 
         return useTransactionWithOracle;
+    }
+
+    /// <summary>
+    ///     褰撴楠屽崟涓嶅悎鏍兼椂锛�
+    ///     鍙栨秷mes_inv_item_barcodes 鐨勬姤宸ユ爣璇� WORK_FLG
+    ///     womdaa 宸茬敓浜ч噺 DAA011鍔犲洖鏉$爜鎶ュ伐鏁伴噺
+    ///     MES_SCGD_GX 妫�楠屾爣璇� CHECK_FLAG锛�('鈭�','脳')
+    ///     閫氳繃mes_inv_item_in_c_details2鐨凪ES_SCGD_GX_ID杩炴帴
+    /// </summary>
+    private void setBarCodes(string? FcheckResu, QsItemOqcItemDetail detail,
+        SqlSugarClient db)
+    {
+        var oqcReqList = db
+            .Queryable<QsItemOqcReq, MesInvItemIns, Womdaa>((a, b, c) =>
+                new JoinQueryInfos(
+                    JoinType.Left, a.BillNo == b.BillNo,
+                    JoinType.Left, c.Daa001 == b.RbillNo
+                ))
+            .Where(a => a.Id == detail.Gid)
+            .Select((a, b, c) =>
+                new
+                {
+                    a.Id,
+                    a.BillNo,
+                    c.Daa001
+                })
+            .ToList();
+
+        if (oqcReqList.Count <= 0) return;
+
+        var qsItemOqcReq = oqcReqList.First(); // 鑾峰彇绗竴涓厓绱�  
+
+        if (qsItemOqcReq.Id is null or 0) return;
+
+        var mesInvItemInsList = db
+            .Queryable<MesInvItemIns, MesInvItemInCDetails2>((a, b) =>
+                new JoinQueryInfos(
+                    JoinType.Left, a.Id == b.ItemInId))
+            .Where((a, b) => a.BillNo == qsItemOqcReq.BillNo)
+            .Select((a, b) => new
+                { b.ItemBarcode, b.Quantity, b.MesScgdGxId })
+            .ToList();
+
+        var barCodes = mesInvItemInsList.Select(s => s.ItemBarcode).ToList();
+
+        var count = db.Queryable<MesInvItemBarcodes>()
+            .Where(s => barCodes.Contains(s.ItemBarcode) && s.WorkFlg == 0)
+            .Count();
+
+        var gxId = mesInvItemInsList.Select(s => s.MesScgdGxId).ToList();
+
+        var sumQty = mesInvItemInsList.Sum(s => s.Quantity);
+
+        if ("鍚堟牸".Equals(FcheckResu))
+        {
+            //鏍规嵁宸ュ簭id鏇存柊宸ュ簭琛ㄧ殑妫�楠岀粨鏋�
+            db.Updateable<MesScgdGx>()
+                .SetColumns(s => s.CheckFlag == "鈭�")
+                .Where(s => gxId.Contains(s.Id))
+                .ExecuteCommand();
+
+            if (count <= 0) return;
+
+            //鍙栨秷mes_inv_item_barcodes 鐨勬姤宸ユ爣璇� WORK_FLG 浣跨敤鏉$爜
+            var executeCommand = db.Updateable<MesInvItemBarcodes>()
+                .SetColumns(a => a.WorkFlg == 1)
+                .Where(a => barCodes.Contains(a.ItemBarcode))
+                .ExecuteCommand();
+
+            if (executeCommand > 0)
+                //womdaa 宸茬敓浜ч噺 DAA011鍔犲洖鏉$爜鎶ュ伐鏁伴噺
+                db.Updateable<Womdaa>()
+                    .SetColumns(b => b.Daa011 == b.Daa011 + sumQty)
+                    .Where(b => b.Daa001 == qsItemOqcReq.Daa001)
+                    .ExecuteCommand();
+        }
+        else if ("涓嶅悎鏍�".Equals(FcheckResu))
+        {
+            //鏍规嵁宸ュ簭id鏇存柊宸ュ簭琛ㄧ殑妫�楠岀粨鏋�
+            db.Updateable<MesScgdGx>()
+                .SetColumns(s => s.CheckFlag == "脳")
+                .Where(s => gxId.Contains(s.Id))
+                .ExecuteCommand();
+
+            //鍙栨秷mes_inv_item_barcodes 鐨勬姤宸ユ爣璇� WORK_FLG 浣跨敤鏉$爜
+            var executeCommand = db.Updateable<MesInvItemBarcodes>()
+                .SetColumns(a => a.WorkFlg == 0)
+                .Where(a => barCodes.Contains(a.ItemBarcode))
+                .ExecuteCommand();
+
+            if (executeCommand > 0)
+                //womdaa 宸茬敓浜ч噺 DAA011鍔犲洖鏉$爜鎶ュ伐鏁伴噺
+                db.Updateable<Womdaa>()
+                    .SetColumns(b => b.Daa011 == b.Daa011 - sumQty)
+                    .Where(b => b.Daa001 == qsItemOqcReq.Daa001)
+                    .ExecuteCommand();
+        }
     }
 
     public int saveDetect02(decimal? gid, string? createBy)
@@ -454,26 +574,59 @@
     }
 
 
-    public List<QsItemOqcReq> getPage(XJPageResult queryObj)
+    public (List<QsItemOqcReq> items, int TotalCount) getPage(
+        XJPageResult queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
 
-        return db
-            .Queryable<QsItemOqcReq, Womdaa, MesItems, MesInvItemIns, Womdab,
-                MesInvTransaction, RKJDaa001>(
-                (a, da, b, c, d, ca, m) => new JoinQueryInfos(
-                    JoinType.Left, da.Daa001 == a.BillNo,
-                    JoinType.Left, a.ItemId == b.Id,
+        var totalCount = 0;
+
+        string[]? lineNo = null;
+
+        if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
+            lineNo = _baseService.getUserLineNo(queryObj.createUser);
+
+        var qsItemOqcReqs = db
+            .Queryable<QsItemOqcReq, MesItems, MesInvItemIns, MesInvTransaction,
+                RKJDaa001, Womdaa, VLineUser>((a, b, c, ca, m, da, z) =>
+                new JoinQueryInfos(
+                    JoinType.Left, a.ItemNo == b.ItemNo,
                     JoinType.Left, a.BillNo == c.BillNo,
-                    JoinType.Left, c.CbillNo == d.Dab001,
                     JoinType.Left,
                     c.TransctionNo == ca.TransactionNo.ToString() &&
-                    c.Company == ca.Company && c.Factory == ca.Factory,
-                    JoinType.Left, c.Id == m.ItemInId && a.ItemNo == m.ItemNo
+                    c.Company == ca.Company &&
+                    c.Factory == ca.Factory,
+                    JoinType.Left, c.Id == m.ItemInId && a.ItemNo == m.ItemNo,
+                    JoinType.Left, da.Daa001 == c.RbillNo,
+                    JoinType.Left, da.Daa015 == z.LineNo //,
+                    //JoinType.Left,c.Bgr == d.UserNo
                 ))
-            .Select((a, da, b, c, d, ca, m) => new QsItemOqcReq
+            // .WhereIF(lineNo != null && lineNo.Length > 0,
+            //     (a, b, c, ca, m, da) => lineNo.Contains(da.Daa015))
+            .WhereIF(!"PL017".Equals(queryObj.createUser),
+                (a, b, c, ca, m, da, z) => lineNo.Contains(da.Daa015))
+            .WhereIF(!string.IsNullOrEmpty(queryObj.id),
+                (a, b, c, ca, m, da, z) => a.Id.ToString() == queryObj.id)
+            .WhereIF(
+                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                "鏈畬鎴�".Equals(queryObj.result),
+                (a, b, c, ca, m, da, z) => a.FcheckResu == null)
+            .WhereIF(
+                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                !"鏈畬鎴�".Equals(queryObj.result),
+                (a, b, c, ca, m, da, z) => a.FcheckResu != null)
+            //鍔犵瓫閫夋潯浠�,鏍规嵁渚涘簲鍟嗭紝鐗╂枡缂栫爜锛岀墿鏂欏悕绉版悳绱�
+            //.WhereIF(queryObj.SearchValue!=null && queryObj.SearchValue!="", (a) => a.SuppName == queryObj.SearchValue|| a.ItemName == queryObj.SearchValue || a.ItemNo == queryObj.SearchValue )
+            .WhereIF(queryObj.SearchValue != null && queryObj.SearchValue != "",
+                (a, b, c, ca, m, da, z) =>
+                    b.ItemName.ToLower()
+                        .Contains(queryObj.SearchValue.ToLower())
+                    || a.ItemNo.ToLower()
+                        .Contains(queryObj.SearchValue.ToLower()))
+            .Select((a, b, c, ca, m, da, z) => new QsItemOqcReq
             {
                 BillNo = a.BillNo,
+                Fsubmit = a.Fsubmit,
                 Remarks = a.Remarks,
                 Id = a.Id,
                 CreateDate = a.CreateDate,
@@ -483,19 +636,19 @@
                 FcheckBy = a.FcheckBy,
                 FcheckDate = a.FcheckDate,
                 ReleaseNo = a.ReleaseNo,
-                // 娣诲姞鍏朵粬瀛楁
-                // 濡傛灉鍦� QsItemOqcReq 涓畾涔変簡棰濆瀛楁锛屽垯闇�瑕佸皢瀹冧滑璧嬪��
-                // 渚嬪:
                 ItemName = b.ItemName,
                 ItemModel = b.ItemModel,
-                TaskNo = c.TaskNo,
-                CbillNo = c.CbillNo,
-                Dab001 = d.Dab001,
+                //Dab001 = m.LotNo,
+                ItemInId = m.ItemInId,
                 Daa015 = da.Daa015,
                 LineNo = c.LineNo,
                 Quantity = m.Quantity
-            }).OrderBy(a => a.CreateDate, OrderByType.Desc)
-            .ToPageList(queryObj.PageIndex, queryObj.Limit);
+                //Bgr = d.UserName
+            })
+            .OrderBy(a => a.CreateDate, OrderByType.Desc)
+            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+        return (qsItemOqcReqs, totalCount);
     }
 
     //鍒犻櫎涓昏〃骞朵笖杩炵骇鍒犻櫎瀛愯〃鍜屽瓩琛�
@@ -558,6 +711,19 @@
 
     public int UpdateQSItemDetail(QsItemOqcItemDetail detail)
     {
+        if (isRk(detail.ItemInId)) throw new Exception("宸叉湁鏉$爜鍏ュ簱锛屼笉鍏佽淇敼妫�楠岀粨鏋�");
+
+        var db = SqlSugarHelper.GetInstance();
+
+        var qsItemOqcReq = db.Queryable<QsItemOqcReq>()
+            .Where(o => o.Id == detail.Gid)
+            .First();
+
+        if (qsItemOqcReq == null) throw new Exception("璇ユ楠屽崟涓嶅瓨鍦紝璇峰洖鍒板叆搴撴鍒楄〃閲嶆柊鏌ョ湅");
+
+        if (!string.IsNullOrEmpty(qsItemOqcReq.FcheckResu))
+            throw new Exception("璇ユ楠屽崟宸�" + qsItemOqcReq.FcheckResu + "锛屼笉杩愯淇敼缁撴灉");
+
         var withOracle = SqlSugarHelper.UseTransactionWithOracle(db =>
         {
             return db.Updateable<QsItemOqcItemDetail>()
@@ -576,6 +742,14 @@
         withOracle += autoResult(detail);
 
         return withOracle;
+    }
+
+    //淇敼缁撴灉鍓嶉獙璇佹槸鍚﹀叆搴�
+    private bool isRk(decimal? ItemInId)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        return db.Queryable<MesInvItemInCDetails>()
+            .Where(s => s.ItemInId == ItemInId).Count() > 0;
     }
 
 
@@ -648,4 +822,31 @@
 
         return Convert.ToInt32(rkjDto.gid);
     }
+
+    public int cleanReqResult(RKJDto dto)
+    {
+        if (isRk(dto.gid)) throw new Exception("宸叉湁鏉$爜鍏ュ簱锛屼笉鍏佽娓呴櫎妫�楠岀粨鏋�");
+
+
+        return SqlSugarHelper.UseTransactionWithOracle(db =>
+        {
+            return db.Updateable<QsItemOqcReq>()
+                .SetColumns(s => s.FcheckResu == null)
+                .Where(s => s.Id == dto.gid).ExecuteCommand();
+        });
+    }
+
+    private bool isRk(int? gid)
+    {
+        var db = SqlSugarHelper.GetInstance();
+        return db
+            .Queryable<QsItemOqcReq, MesInvItemIns, MesInvItemInCDetails2,
+                MesInvItemStocks>((a, b, c, d) => new JoinQueryInfos(
+                JoinType.Inner, a.BillNo == b.BillNo,
+                JoinType.Inner, b.Id == c.ItemInId,
+                JoinType.Inner, c.ItemBarcode == d.ItemBarcode
+            ))
+            .Where((a, b, c, d) => a.Id == gid)
+            .Count() > 0;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3