From 58787157e2609916c06d3ed7d19b6403e9cd5d31 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期四, 26 九月 2024 20:29:35 +0800
Subject: [PATCH] 入库检增加检验结果清除

---
 MES.Service/service/QC/RKJService.cs |  161 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 152 insertions(+), 9 deletions(-)

diff --git a/MES.Service/service/QC/RKJService.cs b/MES.Service/service/QC/RKJService.cs
index 3adbcee..ccbfbe3 100644
--- a/MES.Service/service/QC/RKJService.cs
+++ b/MES.Service/service/QC/RKJService.cs
@@ -314,6 +314,22 @@
 
     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();
@@ -418,7 +434,90 @@
         //     //鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥
         //     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 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();
+        }
+        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)
@@ -480,8 +579,8 @@
 
         var qsItemOqcReqs = db
             .Queryable<QsItemOqcReq, MesItems, MesInvItemIns, MesInvTransaction,
-                RKJDaa001, Womdaa>(
-                (a, b, c, ca, m, da) => new JoinQueryInfos(
+                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,
@@ -489,22 +588,24 @@
                     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.Daa001 == c.RbillNo,
+                    JoinType.Left, da.Daa015 == z.LineNo
                 ))
             // .WhereIF(lineNo != null && lineNo.Length > 0,
             //     (a, b, c, ca, m, da) => lineNo.Contains(da.Daa015))
-            .Where((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) => a.Id.ToString() == 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) => a.FcheckResu == null)
+                (a, b, c, ca, m, da, z) => a.FcheckResu == null)
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 !"鏈畬鎴�".Equals(queryObj.result),
-                (a, b, c, ca, m, da) => a.FcheckResu != null)
-            .Select((a, b, c, ca, m, da) => new QsItemOqcReq
+                (a, b, c, ca, m, da, z) => a.FcheckResu != null)
+            .Select((a, b, c, ca, m, da, z) => new QsItemOqcReq
             {
                 BillNo = a.BillNo,
                 Remarks = a.Remarks,
@@ -522,7 +623,8 @@
                 ItemInId = m.ItemInId,
                 Daa015 = da.Daa015,
                 LineNo = c.LineNo,
-                Quantity = m.Quantity
+                Quantity = m.Quantity,
+                Bgr = c.Bgr
             })
             .OrderBy(a => a.CreateDate, OrderByType.Desc)
             .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
@@ -591,6 +693,22 @@
     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 =>
         {
@@ -690,4 +808,29 @@
 
         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, MesInvItemInCDetails>(
+                (a, b, c) => new JoinQueryInfos(
+                    JoinType.Inner, a.BillNo == b.BillNo,
+                    JoinType.Inner, b.Id == c.ItemInId
+                ))
+            .Where((a, b, c) => a.Id == gid)
+            .Count() > 0;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3