From e853dd2fecef3a0c446d161248d0498a5a081e66 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期三, 17 十二月 2025 18:49:49 +0800
Subject: [PATCH] SJ,XJ,RKJ优化修改

---
 StandardInterface/MES.Service/service/QC/RKJService.cs |  147 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 114 insertions(+), 33 deletions(-)

diff --git a/StandardInterface/MES.Service/service/QC/RKJService.cs b/StandardInterface/MES.Service/service/QC/RKJService.cs
index 802b8e2..1639a80 100644
--- a/StandardInterface/MES.Service/service/QC/RKJService.cs
+++ b/StandardInterface/MES.Service/service/QC/RKJService.cs
@@ -366,10 +366,16 @@
             if (!string.IsNullOrEmpty(rkjDto.RbillNo))
                 xj.RbillNo = rkjDto.RbillNo;
                 
-            // 纭繚Quantity瀛楁琚纭缃�
+            // 纭繚宸ュ崟鏁伴噺瀛楁琚纭缃紙QUANTITY锛�
             if (xj.Quantity == null && rkjDto.quantity != null)
             {
                 xj.Quantity = rkjDto.quantity;
+            }
+            
+            // 纭繚閫佹鏁伴噺瀛楁琚纭缃紙SJQTY锛�
+            if (xj.Sjqty == null && rkjDto.sjqty != null)
+            {
+                xj.Sjqty = rkjDto.sjqty;
             }
             
             // 纭繚鎻愪氦鐘舵�佽姝g‘璁剧疆锛堥粯璁や负鏈彁浜わ級
@@ -436,7 +442,7 @@
             detail.Pid = s.Id;
             detail.Gid = rkjDto.gid;
             detail.Fstand = "鈭�";
-            detail.FcheckResu = "1";
+            detail.FcheckResu = "OK";
             detail.UpdateBy = rkjDto.userNo;
             detail.count = (int?)s.LevelNum;
             SetQSItemDetail(detail);
@@ -599,7 +605,7 @@
     }
 
 
-    public List<QsItemOqcReq> getPage(XJPageResult queryObj)
+    public (List<QsItemOqcReq>, int) getPage(XJPageResult queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
 
@@ -610,8 +616,9 @@
         if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
             lineNo = _baseService.getUserLineNo(queryObj.createUser);
 
+        var totalCount = 0;
 
-        return db
+        var data = db
             .Queryable<QsItemOqcReq, Womdaa, MesItems, MesLine>((a, da, b, m) =>
                 new JoinQueryInfos(
                     JoinType.Left, da.Daa001 == a.BillNo,
@@ -686,9 +693,38 @@
                 ItemName = b.ItemName,
                 ItemModel = b.ItemModel,
                 Daa015 = da.Daa015,
-                Quantity = a.Quantity
+                Quantity = a.Quantity, // 宸ュ崟鏁伴噺
+                Sjqty = a.Sjqty // 閫佹鏁伴噺
             }).OrderBy(a => a.CreateDate, OrderByType.Desc)
-            .ToPageList(queryObj.PageIndex, queryObj.Limit);
+            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+        // 淇妫�楠岀粨鏋滐細濡傛灉鏄剧ず涓衡�滃悎鏍尖�濅絾娌℃湁妫�楠岄」鐩紝鍒欐敼涓虹┖锛堝緟妫�楠岋級
+        if (data.Count > 0)
+        {
+            var ids = data.Select(d => d.Id).ToList();
+            
+            // 鎵归噺鏌ヨ妫�楠岄」鐩暟閲�
+            var itemCounts = db.Queryable<QsItemOqcItem>()
+                .Where(item => ids.Contains(item.Pid.Value))
+                .GroupBy(item => item.Pid)
+                .Select(g => new { Pid = g.Pid, Count = SqlFunc.AggregateCount(g.Id) })
+                .ToList();
+            
+            // 淇姣忔潯璁板綍鐨勬楠岀粨鏋�
+            foreach (var item in data)
+            {
+                var itemCount = itemCounts.FirstOrDefault(ic => ic.Pid == item.Id);
+                var hasItems = itemCount != null && itemCount.Count > 0;
+                
+                // 濡傛灉娌℃湁妫�楠岄」鐩紝鍒欏皢妫�楠岀粨鏋滄竻绌猴紙鏄剧ず涓哄緟妫�楠岋級
+                if (!hasItems)
+                {
+                    item.FcheckResu = null;
+                }
+            }
+        }
+
+        return (data, totalCount);
     }
 
     //鍒犻櫎涓昏〃骞朵笖杩炵骇鍒犻櫎瀛愯〃鍜屽瓩琛�
@@ -760,6 +796,35 @@
         if (qsItemOqcItem.Picture is { Length: > 0 })
             qsItemOqcItem.imageData =
                 Convert.ToBase64String(qsItemOqcItem.Picture);
+
+        // 浠� QS_ITEM_IPI_IMAGE 琛ㄤ腑鑾峰彇鍥剧墖鍒楄〃锛堝叆搴撴 QS_TYPE=3锛�
+        var imageRecords = db.Queryable<QsItemIpiImage>()
+            .Where(s => s.Fid == id && s.QsType == 3 && s.ImageData != null)
+            .ToList();
+        
+        if (imageRecords.Count > 0)
+        {
+            qsItemOqcItem.imageList = new List<ImageInfo>();
+            foreach (var img in imageRecords)
+            {
+                if (img.ImageData != null && img.ImageData.Length > 0)
+                {
+                    qsItemOqcItem.imageList.Add(new ImageInfo
+                    {
+                        Id = img.Id ?? 0,
+                        FileName = img.Picturename,
+                        Base64Data = Convert.ToBase64String(img.ImageData),
+                        CreateDate = img.CreateDate,
+                        CreateBy = img.CreateBy
+                    });
+                }
+            }
+            // 淇濇寔鍚戝悗鍏煎
+            if (qsItemOqcItem.imageList.Count > 0 && string.IsNullOrEmpty(qsItemOqcItem.imageData))
+            {
+                qsItemOqcItem.imageData = qsItemOqcItem.imageList[0].Base64Data;
+            }
+        }
 
         //鑾峰彇涓嶅悎鏍兼暟
         var count = db.Queryable<QsItemOqcItemDetail>()
@@ -860,7 +925,7 @@
             detail.Pid = s.Id;
             detail.Gid = rkjDto.gid;
             detail.Fstand = "鈭�";
-            detail.FcheckResu = "1";
+            detail.FcheckResu = "OK";
             detail.UpdateBy = rkjDto.userNo;
             detail.count = (int?)s.LevelNum;
             SetQSItemDetail(detail);
@@ -1262,9 +1327,9 @@
     }
 
     /// <summary>
-    /// 涓婁紶鍥剧墖鍒版楠岄」鐩殑PICTURE瀛楁
+    /// 涓婁紶鍥剧墖鍒� QS_ITEM_IPI_IMAGE 琛紙鍏ュ簱妫� QS_TYPE=3锛屾敮鎸佸鍥剧墖锛�
     /// </summary>
-    /// <param name="id">妫�楠岄」鐩甀D</param>
+    /// <param name="id">妫�楠岄」鐩甀D (FID)</param>
     /// <param name="imageBytes">鍥剧墖瀛楄妭鏁扮粍</param>
     /// <param name="fileName">鍘熷鏂囦欢鍚�</param>
     /// <param name="createBy">鍒涘缓浜�</param>
@@ -1303,24 +1368,30 @@
 
             var result = SqlSugarHelper.UseTransactionWithOracle(db =>
             {
-                // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦�
-                var exists = db.Queryable<QsItemOqcItem>()
+                // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦紝骞惰幏鍙栨楠屽崟ID鍜屾楠岄」鐩悕绉�
+                var oqcItem = db.Queryable<QsItemOqcItem>()
                     .Where(s => s.Id == id)
-                    .Any();
+                    .Select(s => new { s.Id, s.Pid, s.ProjName })
+                    .First();
 
-                if (!exists)
+                if (oqcItem == null)
                 {
                     throw new Exception("妫�楠岄」鐩笉瀛樺湪");
                 }
 
-                // 鏇存柊PICTURE瀛楁锛圠ONG RAW绫诲瀷锛夊拰TPICTURENAME瀛楁锛堟椂闂存埑鏂囦欢鍚嶏級
-                var updateResult = db.Updateable<QsItemOqcItem>()
-                    .SetColumns(s => s.Picture == imageBytes)
-                    .SetColumns(s => s.TPicturename == timestampFileName)
-                    .Where(s => s.Id == id)
-                    .ExecuteCommand();
-
-                return updateResult;
+                // 姣忔閮藉垱寤烘柊鐨勫浘鐗囪褰曪紝鏀寔澶氬浘鐗囦笂浼�
+                var newImage = new QsItemIpiImage
+                {
+                    Fid = id,                        // 妫�楠岄」鐩甀D (QS_ITEM_OQC_ITEM.ID)
+                    Gid = oqcItem.Pid,               // 妫�楠屽崟ID (QS_ITEM_OQC_REQ.ID)
+                    QsType = 3,                      // 鍏ュ簱妫�绫诲瀷
+                    ImageData = imageBytes,
+                    Picturename = timestampFileName,
+                    JyName = oqcItem.ProjName,       // 妫�楠岄」鐩悕绉�
+                    CreateDate = DateTime.Now,
+                    CreateBy = createBy
+                };
+                return db.Insertable(newImage).ExecuteCommand();
             });
 
             if (result > 0)
@@ -1329,7 +1400,7 @@
             }
             else
             {
-                return (1, "鍥剧墖淇濆瓨澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勬楠岄」鐩�");
+                return (1, "鍥剧墖淇濆瓨澶辫触");
             }
         }
         catch (Exception ex)
@@ -1339,11 +1410,12 @@
     }
 
     /// <summary>
-    /// 鍒犻櫎妫�楠岄」鐩殑鍥剧墖
+    /// 鍒犻櫎妫�楠岄」鐩殑鍥剧墖锛堜粠 QS_ITEM_IPI_IMAGE 琛ㄤ腑鍒犻櫎锛屽叆搴撴 QS_TYPE=3锛�
     /// </summary>
-    /// <param name="id">妫�楠岄」鐩甀D</param>
+    /// <param name="id">妫�楠岄」鐩甀D (FID)锛屽綋imageId涓虹┖鏃跺垹闄よ妫�楠岄」鐩殑鎵�鏈夊浘鐗�</param>
+    /// <param name="imageId">鍥剧墖ID锛岀敤浜庡垹闄ゅ崟寮犲浘鐗囷紙鍙�夛級</param>
     /// <returns>鎿嶄綔缁撴灉</returns>
-    public (int status, string message) DeleteImageFromPicture(decimal id)
+    public (int status, string message) DeleteImageFromPicture(decimal id, decimal? imageId = null)
     {
         try
         {
@@ -1359,14 +1431,23 @@
                     throw new Exception("妫�楠岄」鐩笉瀛樺湪");
                 }
 
-                // 娓呯┖PICTURE瀛楁鍜孴PICTURENAME瀛楁
-                var updateResult = db.Updateable<QsItemOqcItem>()
-                    .SetColumns(s => s.Picture == null)
-                    .SetColumns(s => s.TPicturename == null)
-                    .Where(s => s.Id == id)
-                    .ExecuteCommand();
+                int deleteResult;
+                if (imageId.HasValue && imageId.Value > 0)
+                {
+                    // 鍒犻櫎鍗曞紶鍥剧墖
+                    deleteResult = db.Deleteable<QsItemIpiImage>()
+                        .Where(s => s.Id == imageId.Value && s.Fid == id && s.QsType == 3)
+                        .ExecuteCommand();
+                }
+                else
+                {
+                    // 鍒犻櫎璇ユ楠岄」鐩殑鎵�鏈夊浘鐗�
+                    deleteResult = db.Deleteable<QsItemIpiImage>()
+                        .Where(s => s.Fid == id && s.QsType == 3)
+                        .ExecuteCommand();
+                }
 
-                return updateResult;
+                return deleteResult;
             });
 
             if (result > 0)
@@ -1375,7 +1456,7 @@
             }
             else
             {
-                return (1, "鍥剧墖鍒犻櫎澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勬楠岄」鐩�");
+                return (0, "娌℃湁鎵惧埌瑕佸垹闄ょ殑鍥剧墖");
             }
         }
         catch (Exception ex)

--
Gitblit v1.9.3