From 4910c0fa81d93635e19a57c073c3a62c76053320 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期五, 25 七月 2025 13:24:18 +0800
Subject: [PATCH] 1.巡检扫描工位

---
 service/QC/LljService.cs |  195 ++++++++++++++++++++++++++++++------------------
 1 files changed, 121 insertions(+), 74 deletions(-)

diff --git a/service/QC/LljService.cs b/service/QC/LljService.cs
index d46b42c..5d687f7 100644
--- a/service/QC/LljService.cs
+++ b/service/QC/LljService.cs
@@ -1,12 +1,12 @@
-锘縰sing System.Data;
+锘縰sing MES.Service.Models;
 using Microsoft.IdentityModel.Tokens;
 using NewPdaSqlServer.DB;
 using NewPdaSqlServer.Dto.service;
 using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
 using NewPdaSqlServer.util;
 using SqlSugar;
-using DbType = System.Data.DbType;
-
+using static Azure.Core.HttpHeader;
 
 namespace NewPdaSqlServer.service.QC;
 
@@ -17,7 +17,7 @@
         var parsedGuid = Guid.Empty;
         if (!queryObj.id.IsNullOrEmpty())
         {
-            bool isValid = Guid.TryParse(queryObj.id, out parsedGuid);
+            var isValid = Guid.TryParse(queryObj.id, out parsedGuid);
             if (!isValid)
                 throw new ApplicationException("GUID杞崲閿欒");
         }
@@ -26,16 +26,26 @@
         var totalCount = 0;
 
         var pageList = Db.Queryable<LLJView>()
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                "鏈畬鎴�".Equals(queryObj.result),
-                a => a.FcheckResu == null)
-            .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
-                !"鏈畬鎴�".Equals(queryObj.result),
-                a => a.FcheckResu != null)
+            //.WhereIF(
+            //    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+            //    "鏈畬鎴�".Equals(queryObj.result),
+            //    a => (a.STATUS ?? "") != "宸叉彁浜�")
+            //    //a => (a.FcheckResu ?? "") == ""|| (a.FcheckResu ?? "") == "妫�楠屼腑")
+            //.WhereIF(
+            //    StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+            //    !"鏈畬鎴�".Equals(queryObj.result),
+            //    a => (a.STATUS ?? "") == "宸叉彁浜�")
+
+            .WhereIF(!string.IsNullOrWhiteSpace(queryObj.keyword), a =>
+                a.ItemNo.Contains(queryObj.keyword) ||
+                a.ItemName.Contains(queryObj.keyword) ||
+                a.LotNo.Contains(queryObj.keyword) ||
+                a.ReleaseNo.Contains(queryObj.keyword) ||
+                a.SuppName.Contains(queryObj.keyword) 
+            )
             .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
-                a => a.guid == parsedGuid)
+                a => a.guid == parsedGuid )
+            .Where(a => (a.fsubmit ?? 0) == 0)
             .OrderByDescending(a => a.CreateDate)
             .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
 
@@ -62,7 +72,7 @@
                     FcheckItem = b.FcheckItem,
                     FdownAllow = b.FdownAllow,
                     FcheckLevel = b.FREQUENCY,
-                    Fstand = Convert.ToInt32(b.FSTAND),
+                    Fstand = b.FSTAND,
                     FupAllow = b.FupAllow,
                     SampleSizeNo = b.SampleSizeNo,
                     FenterQty = 0,
@@ -74,7 +84,7 @@
 
         mesQaIqcItem.ForEach(item =>
         {
-            string LEV = item.FcheckLevel switch
+            var LEV = item.FcheckLevel switch
             {
                 null => "" // 榛樿鍊�
                 ,
@@ -147,7 +157,7 @@
         {
             foreach (var item in items) item.ReleaseNo = rkjDto.releaseNo;
 
-            return db.Insertable(items).ExecuteCommand();
+            return db.Insertable(items).IgnoreColumns(true).ExecuteCommand();
         });
 
         rkjDto.items = GetItems(rkjDto.releaseNo, null);
@@ -189,49 +199,45 @@
     }
 
     public List<MesQaItemsDetectDetail5> GetItems(string? releaseNo,
-        decimal? id)
+        string? id)
     {
-        return Db.Queryable<MesQaItemsDetectDetail5, MesQaItemsDetectDetail12>(
-                (a, b) =>
-                    new JoinQueryInfos(JoinType.Left, a.Guid == b.ParentGuid))
-            .Where((a, b) => a.ReleaseNo == releaseNo)
-            // .WhereIF(id > 0, (a, b) => a.Id == id)
-            .GroupBy((a, b) => new
-            {
-                a.Guid,
-                a.ReleaseNo,
-                a.FacLevel,
-                a.FcheckItem,
-                a.FcheckTool,
-                a.FdownAllow,
-                a.FcheckLevel,
-                a.Fstand,
-                a.FupAllow,
-                a.SampleSizeNo,
-                a.FspecRequ,
-                a.FreQty,
-                a.CheckQyt,
-                a.FcheckResu
-            }).Select((a, b) => new MesQaItemsDetectDetail5
-            {
-                Guid = a.Guid,
-                ReleaseNo = a.ReleaseNo,
-                CheckQyt = a.CheckQyt,
-                FacLevel = a.FacLevel,
-                FcheckItem = a.FcheckItem,
-                FcheckTool = a.FcheckTool,
-                FdownAllow = a.FdownAllow,
-                FcheckLevel = a.FcheckLevel,
-                Fstand = a.Fstand,
-                FupAllow = a.FupAllow,
-                SampleSizeNo = a.SampleSizeNo,
-                FspecRequ = a.FspecRequ,
-                FreQty = a.FreQty,
-                Factory = "1000",
-                Company = "1000",
-                FenterQty = SqlFunc.AggregateCount(b.Guid),
-                FcheckResu = a.FcheckResu
-            }).ToList();
+        var parsedGuid = Guid.Empty;
+
+        var sql = string.Format(@"SELECT [a].[guid]           AS [Guid],
+       [a].[parent_guid]    AS [ParentGuid],
+       [a].[release_no]     AS [ReleaseNo],
+       [a].[check_qyt]      AS [CheckQyt],
+       [a].[fac_level]      AS [FacLevel],
+       [a].[fcheck_item]    AS [FcheckItem],
+       [a].[fcheck_tool]    AS [FcheckTool],
+       [a].[fdown_allow]    AS [FdownAllow],
+       [a].[fcheck_level]   AS [FcheckLevel],
+       [a].[fstand]         AS [Fstand],
+       [a].[fup_allow]      AS [FupAllow],
+       [a].[sample_size_no] AS [SampleSizeNo],
+       [a].[fspec_requ]     AS [FspecRequ],
+       [a].[fre_qty]        AS [FreQty],
+       N'1000'              AS [Factory],
+       N'1000'              AS [Company],
+       COUNT([b].[guid])    AS [FenterQty],
+       [a].[fcheck_resu]    AS [FcheckResu],
+       [a].[forder]         AS [Order],
+       [a].[ybsl]           AS [Ybsl],
+       ISNULL((SELECT COUNT(1)
+FROM MES_QA_ITEMS_DETECT_DETAIL13 C
+WHERE C.parent_guid = A.guid),0) AS [YbslIn]
+FROM [MES_QA_ITEMS_DETECT_DETAIL5] [a]
+         Left JOIN [MES_QA_ITEMS_DETECT_DETAIL12] [b] ON ([a].[guid] = [b].[parent_guid])
+WHERE ([a].[release_no] = N'{0}')
+GROUP BY [a].[guid], [a].[parent_guid], [a].[release_no], [a].[fac_level], [a].[fcheck_item], [a].[fcheck_tool],
+         [a].[fdown_allow], [a].[fcheck_level], [a].[fstand], [a].[fup_allow], [a].[sample_size_no], [a].[fspec_requ],
+         [a].[fre_qty], [a].[check_qyt], [a].[fcheck_resu], [a].[forder], [a].[ybsl]
+ORDER BY [a].[forder] ASC", releaseNo);
+
+        var Ybsl_In = Db.Ado.SqlQuery<MesQaItemsDetectDetail5>(sql).ToList();
+
+        return Ybsl_In;
+
     }
 
     public int SetQSItemDetail(MesQaItemsDetectDetail12 detail)
@@ -243,6 +249,8 @@
             {
                 var item = new MesQaItemsDetectDetail12();
                 item.ParentGuid = detail.ParentGuid;
+                item.GrandpaGuid = detail.GrandpaGuid;
+                item.FcheckItem = detail.FcheckItem;
                 item.Fstand = detail.Fstand;
                 item.FcheckResu = detail.FcheckResu;
                 item.CreateBy = detail.LastupdateBy;
@@ -250,7 +258,7 @@
                 result.Add(item);
             }
 
-            return db.Insertable(result).ExecuteCommand();
+            return db.Insertable(result).PageSize(1).IgnoreColumnsNull().ExecuteCommand();
         });
 
         detail.CreateBy = detail.LastupdateBy;
@@ -302,6 +310,7 @@
                 commit += db.Updateable<MesQaItemsDetectDetail5>()
                     .SetColumns(s => s.FcheckResu == result)
                     .SetColumns(s => s.FenterQty == count)
+                    .SetColumns(s => s.FngRate == (s.CheckQyt == 0 ? (decimal?)null : (decimal?)(Convert.ToDouble(noCount) / Convert.ToDouble(count))))
                     .Where(s => s.Guid == detail.ParentGuid)
                     .ExecuteCommand();
 
@@ -402,12 +411,9 @@
     {
         var rkjDto = new LLJDto();
 
-        bool isValid = Guid.TryParse(id, out var parsedGuid);
+        var isValid = Guid.TryParse(id, out var parsedGuid);
 
-        if (!isValid)
-        {
-            throw new Exception("GUID杞崲閿欒");
-        }
+        if (!isValid) throw new Exception("GUID杞崲閿欒");
 
         var qsItemOqcItem =
             Db.Queryable<MesQaItemsDetectDetail5>()
@@ -436,6 +442,16 @@
         rkjDto.ItemXj02s = Db.Queryable<MesQaItemsDetectDetail12>()
             .Where(s => s.ParentGuid == parsedGuid)
             .ToList();
+
+        foreach (var mesQaItemsDetectDetail12 in rkjDto.ItemXj02s)
+        {
+            //this.formData.fupAllow && this.formData.fdownAllow && this.formData.fstand
+            mesQaItemsDetectDetail12.isNumber = true;
+            if (qsItemOqcItem.FupAllow.IsNullOrEmpty()
+                && qsItemOqcItem.FdownAllow.IsNullOrEmpty()
+                && qsItemOqcItem.Fstand == null)
+                mesQaItemsDetectDetail12.isNumber = false;
+        }
 
         return rkjDto;
     }
@@ -502,10 +518,9 @@
     //瀛愯〃淇敼澶囨敞瀛楁
     public int saveRemarksPid(LLJDto dto)
     {
-        bool isValid = Guid.TryParse(dto.pid, out var parsedGuid);
+        var isValid = Guid.TryParse(dto.pid, out var parsedGuid);
 
         if (isValid)
-        {
             return UseTransaction(db =>
             {
                 return db.Updateable<MesQaItemsDetectDetail5>()
@@ -514,7 +529,6 @@
                     .Where(it => it.Guid == parsedGuid)
                     .ExecuteCommand();
             });
-        }
 
         throw new Exception("GUID杞崲閿欒");
     }
@@ -562,7 +576,7 @@
             throw new Exception("璇ユ楠屽崟宸叉彁浜�");
 
         if (mesQaItemsDetect01.FcheckDate == null)
-            throw new Exception("璇ユ娴嬪崟鏈緭鍏ユ楠屾棩鏈燂紝璇锋牳瀵广��");
+            throw new Exception("璇ユ娴嬪崟娌℃湁妫�楠屽畬鎴愶紝璇锋牳瀵广��");
 
         if (mesQaItemsDetect01.FcheckBy.IsNullOrEmpty())
             throw new Exception("璇ユ娴嬪崟鏈緭鍏ユ楠屼汉鍛橈紝璇锋牳瀵广��");
@@ -577,11 +591,9 @@
         {
             mesQaItemsDetectDetail5.FenterQty ??= 0;
             if (mesQaItemsDetectDetail5.FenterQty == 0)
-            {
                 throw new Exception("妫�楠岄」鐩�:" +
                                     mesQaItemsDetectDetail5.FcheckItem +
                                     " 宸插綍鍏ユ暟閲忎负0锛岃纭銆�");
-            }
         }
 
         var com = UseTransaction(db =>
@@ -643,7 +655,7 @@
                         TotalOkRkQty = SqlFunc.AggregateSum(b.OkRkqty)
                     })
                     .First();
-                
+
                 var totalQuantity = first.TotalQuantity ?? 0;
                 var totalOkRkQty = first.TotalOkRkQty ?? 0;
 
@@ -658,12 +670,13 @@
                 executeCommand += db.Updateable<MesInvItemArnDetail>()
                     .SetColumns(s => s.CheckStates == "涓嶅悎鏍煎緟瀹℃壒")
                     .SetColumns(s => s.Ischeck == 1)
-                    .SetColumns(s => s.CheckRes == mesQaItemsDetect01.FcheckResu)
+                    .SetColumns(
+                        s => s.CheckRes == mesQaItemsDetect01.FcheckResu)
                     .SetColumns(s => s.CheckDate == DateTime.Now)
                     .Where(s => s.ParentGuid == mesInvItemArn.Guid
                                 && s.ItemId == mesQaItemsDetect01.ItemId)
                     .ExecuteCommand();
-                
+
                 executeCommand += db.Updateable<MesQaItemsDetect01>()
                     .SetColumns(s => s.IqcDate == DateTime.Now)
                     .SetColumns(s => s.FcheckDate == DateTime.Now)
@@ -672,7 +685,7 @@
                     .ExecuteCommand();
             }
 
-            if (executeCommand >=3)
+            if (executeCommand >= 3)
                 return executeCommand;
 
             throw new Exception("鏇存柊澶辫触");
@@ -680,4 +693,38 @@
 
         return com > 0;
     }
+
+    public int[] getBadge()
+    {
+        var isNullCount = Db.Queryable<MesQaItemsDetect01>()
+            .Where(a => (a.FcheckResu ?? "") == "").Count();
+
+        var isNotNullCount = Db.Queryable<MesQaItemsDetect01>()
+            .Where(a => (a.FcheckResu ?? "") != "").Count();
+
+        return [isNullCount, isNotNullCount];
+    }
+
+
+
+    //鍒犻櫎鐗瑰緛鍊� 
+    public int deleteDetail13(LLJDto dto)
+    {
+        var withOracle = Db.Deleteable<MesQaItemsDetectDetail13>()
+                .Where(s => s.Guid.ToString() == dto.id13)
+                .ExecuteCommand();
+
+        return withOracle;
+    }
+
+    //鏇存柊涓嶅悎鏍兼弿杩�
+    public int updateRemarks(LLJDto dto)
+    {
+        var withOracle = Db.Updateable<MesQaItemsDetect01>()
+                .SetColumns(s => s.FngDesc == dto.Remarks)
+                .Where(s => s.Guid.ToString() == dto.gid)
+                .ExecuteCommand();
+
+        return withOracle;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3