From dabfdd9dbf0364b1134daaad86af7e13f6437295 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期四, 30 十月 2025 12:40:30 +0800
Subject: [PATCH] XJ,SJ,RKJ检验项目序号,LLJ单个检验项目FTP附件信息

---
 StandardInterface/MES.Service/service/QC/XJService.cs |  250 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 238 insertions(+), 12 deletions(-)

diff --git a/StandardInterface/MES.Service/service/QC/XJService.cs b/StandardInterface/MES.Service/service/QC/XJService.cs
index 0d1564e..210860e 100644
--- a/StandardInterface/MES.Service/service/QC/XJService.cs
+++ b/StandardInterface/MES.Service/service/QC/XJService.cs
@@ -153,10 +153,23 @@
                 )
             );
             
-        // 娣诲姞绾夸綋绛涢�夋潯浠�
+        // 娣诲姞绾夸綋绛涢�夋潯浠讹紙鍩轰簬鐢ㄦ埛鏉冮檺锛�
         if (lineNo != null && lineNo.Length > 0)
         {
             query = query.Where((s, a, c, b) => lineNo.Contains(c.LineNo));
+        }
+        
+        // 娣诲姞QC绛涢�夋潯浠讹細杞﹂棿鍜岀嚎浣�
+        if (!string.IsNullOrEmpty(queryObj.departmentId))
+        {
+            // 濡傛灉鎸囧畾浜嗚溅闂达紝绛涢�夎杞﹂棿涓嬬殑绾夸綋
+            query = query.Where((s, a, c, b) => c.DepotId.ToString() == queryObj.departmentId);
+        }
+        
+        if (!string.IsNullOrEmpty(queryObj.lineId))
+        {
+            // 濡傛灉鎸囧畾浜嗙嚎浣擄紝鐩存帴绛涢�夌嚎浣�
+            query = query.Where((s, a, c, b) => c.LineNo == queryObj.lineId);
         }
         
         // 娣诲姞鐘舵�佺瓫閫夋潯浠� - 鏄庣‘鍖归厤鍓嶇浼犻�掔殑鍊�
@@ -170,6 +183,49 @@
             {
                 query = query.Where((s, a, c, b) => s.Fsubmit == 1);
             }
+        }
+        
+        // 娣诲姞鎼滅储鏉′欢 - 鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+        if (!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField))
+        {
+            switch (queryObj.searchField)
+            {
+                case "billNo":  // 宸ュ崟
+                    query = query.Where((s, a, c, b) => s.BillNo.Contains(queryObj.SearchValue));
+                    break;
+                case "releaseNo":  // 妫�楠屽崟鍙�
+                    query = query.Where((s, a, c, b) => s.ReleaseNo.Contains(queryObj.SearchValue));
+                    break;
+                case "daa020":    // 浜х嚎
+                    query = query.Where((s, a, c, b) => c.LineNo.Contains(queryObj.SearchValue));
+                    break;
+                case "itemNo":  // 鐗╂枡缂栫爜
+                    query = query.Where((s, a, c, b) => s.ItemNo.Contains(queryObj.SearchValue));
+                    break;
+                case "itemName":  // 鐗╂枡鍚嶇О
+                    query = query.Where((s, a, c, b) => b.ItemName.Contains(queryObj.SearchValue));
+                    break;
+                default:
+                    // 濡傛灉娌℃湁鎸囧畾瀛楁鎴栧瓧娈典笉鍖归厤锛屼娇鐢ㄥ師鏈夌殑妯$硦鏌ヨ閫昏緫浣滀负鍏滃簳鏂规
+                    query = query.Where((s, a, c, b) => 
+                        s.ItemNo.Contains(queryObj.SearchValue) ||
+                        b.ItemName.Contains(queryObj.SearchValue) ||
+                        s.BillNo.Contains(queryObj.SearchValue) ||
+                        s.ReleaseNo.Contains(queryObj.SearchValue) ||
+                        c.LineNo.Contains(queryObj.SearchValue));
+                    break;
+            }
+        }
+        // 涓轰簡鍏煎鏃х増鏈紝濡傛灉娌℃湁浼犻�� searchField锛屼娇鐢ㄥ師鏉ョ殑鏌ヨ閫昏緫
+        else if (string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue))
+        {
+            // 淇濇寔鍘熸湁鐨勫瀛楁妯$硦鏌ヨ閫昏緫
+            query = query.Where((s, a, c, b) => 
+                s.ItemNo.Contains(queryObj.SearchValue) ||
+                b.ItemName.Contains(queryObj.SearchValue) ||
+                s.BillNo.Contains(queryObj.SearchValue) ||
+                s.ReleaseNo.Contains(queryObj.SearchValue) ||
+                c.LineNo.Contains(queryObj.SearchValue));
         }
         
         // 娣诲姞ID绛涢�夋潯浠�
@@ -244,6 +300,7 @@
         var qsQaItemXj01s = db.Queryable<QsQaItemXj01>()
             .WhereIF(pid > 0, a => a.Pid == pid)
             .WhereIF(id > 0, a => a.Id == id)
+            .OrderBy(a => a.Forder ?? 0)
             .ToList();
 
         var array = qsQaItemXj01s.Select(s => s.Id).ToArray();
@@ -280,8 +337,10 @@
                 s.imageData = Convert.ToBase64String(s.Picture);
         });
 
-        //鎺掑簭锛屾湭瀹屾垚鐨勬帓鍦ㄥ墠闈�
-        qsQaItemXj01s = qsQaItemXj01s.OrderBy(s => s.isCheck).ToList();
+        //鎺掑簭锛氬彧鎸塅ORDER椤哄簭鎺掑簭
+        qsQaItemXj01s = qsQaItemXj01s
+            .OrderBy(s => s.Forder ?? 0)
+            .ToList();
 
         return qsQaItemXj01s;
     }
@@ -375,8 +434,35 @@
         var xjDto = new XJDto();
 
         var db = SqlSugarHelper.GetInstance();
-        var qsQaItemXj01 =
-            db.Queryable<QsQaItemXj01>().Single(s => s.Id == id);
+        
+        // 浣跨敤JOIN鏌ヨ鑾峰彇瀛愯〃鏁版嵁鍜屼富琛ㄧ殑ItemNo瀛楁
+        var qsQaItemXj01 = db
+            .Queryable<QsQaItemXj01, QsQaItemXj>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
+            .Where((a, b) => a.Id == id)
+            .Select((a, b) => new QsQaItemXj01
+            {
+                Id = a.Id,
+                Pid = a.Pid,
+                ProjName = a.ProjName,
+                ItemMod = a.ItemMod,
+                InspectionMethod = a.InspectionMethod,
+                UsingInstruments = a.UsingInstruments,
+                LevelNum = a.LevelNum,
+                MaxValue = a.MaxValue,
+                StandardValue = a.StandardValue,
+                MinValue = a.MinValue,
+                Notes = a.Notes,
+                FcheckLevel = a.FcheckLevel,
+                FacLevel = a.FacLevel,
+                QsCode = a.QsCode,
+                QsName = a.QsName,
+                Picture = a.Picture,
+                Picturename = a.Picturename,
+                IsPass = a.IsPass,
+                Remarks = a.Remarks,
+                // 娣诲姞涓昏〃鐨処temNo瀛楁
+                ItemNo = b.ItemNo
+            }).Single();
 
         if (qsQaItemXj01.IsPass == 0)
             qsQaItemXj01.result = "涓嶅悎鏍�";
@@ -390,7 +476,6 @@
                 Convert.ToBase64String(qsQaItemXj01.Picture);
 
         xjDto.ItemXj01 = qsQaItemXj01;
-
 
         xjDto.ItemXj02s = db.Queryable<QsQaItemXj02>().Where(s => s.Pid == id)
             .ToList();
@@ -708,15 +793,24 @@
     /// 鑾峰彇闄勪欢淇℃伅
     /// </summary>
     /// <param name="itemNo">鐗╂枡缂栫爜</param>
+    /// <param name="projName">椤圭洰鍚嶇О锛堝彲閫夛紝鐢ㄤ簬杩囨护锛�</param>
     /// <returns>闄勪欢鍒楄〃</returns>
-    public List<QamftpDto> GetAttachments(string itemNo)
+    public List<QamftpDto> GetAttachments(string itemNo, string projName = null)
     {
         var db = SqlSugarHelper.GetInstance();
         try
         {
-            return db.Queryable<MesQamftp>()
+            var query = db.Queryable<MesQamftp>()
                 .Where(x => x.ItemNo == itemNo)
-                .OrderBy(x => x.Fdate, OrderByType.Desc)
+                .Where(x => x.Ftype == "宸℃");  // 娣诲姞FTYPE = '宸℃'鐨勯檺鍒�
+            
+            // 濡傛灉浼犲叆浜唒rojName锛屽垯鎸塅version杩囨护
+            if (!string.IsNullOrEmpty(projName))
+            {
+                query = query.Where(x => x.Fversion == projName);
+            }
+            
+            return query.OrderBy(x => x.Fdate, OrderByType.Desc)
                 .Select(x => new QamftpDto
                 {
                     Id = x.Id,
@@ -747,8 +841,9 @@
     /// <param name="itemNo">鐗╂枡缂栫爜</param>
     /// <param name="fileName">鏂囦欢鍚�</param>
     /// <param name="ftpServer">FTP鏈嶅姟鍣ㄥ湴鍧�</param>
+    /// <param name="projName">椤圭洰鍚嶇О锛堝彲閫夛紝鐢ㄤ簬璺緞鏋勫缓锛�</param>
     /// <returns>鏂囦欢瀛楄妭鏁扮粍</returns>
-    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer)
+    public byte[] GetFtpFile(string itemNo, string fileName, string ftpServer, string projName = null)
     {
         // 鍙傛暟楠岃瘉
         if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
@@ -762,8 +857,16 @@
         // 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧�
         string normalizedServer = NormalizeFtpServer(ftpServer);
         
-        // 鏋勫缓FTP鏂囦欢璺緞 - 宸℃浣跨敤OPC鐩綍
-        string ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
+        // 鏋勫缓FTP鏂囦欢璺緞 - 宸℃浣跨敤OPC鐩綍锛屽鏋滀紶鍏ヤ簡projName鍒欎娇鐢ㄦ柊鏍煎紡
+        string ftpPath;
+        if (!string.IsNullOrEmpty(projName))
+        {
+            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{projName}/{fileName}";
+        }
+        else
+        {
+            ftpPath = $"{normalizedServer}/OPC/{itemNo}/{fileName}";
+        }
         
         try
         {
@@ -914,5 +1017,128 @@
         };
     }
 
+    /// <summary>
+    /// 涓婁紶鍥剧墖鍒版楠岄」鐩殑PICTURE瀛楁
+    /// </summary>
+    /// <param name="id">妫�楠岄」鐩甀D</param>
+    /// <param name="imageBytes">鍥剧墖瀛楄妭鏁扮粍</param>
+    /// <param name="fileName">鍘熷鏂囦欢鍚�</param>
+    /// <param name="createBy">鍒涘缓浜�</param>
+    /// <returns>鎿嶄綔缁撴灉</returns>
+    public (int status, string message) UploadImageToPicture(decimal id, byte[] imageBytes, string fileName, string createBy)
+    {
+        try
+        {
+            if (imageBytes == null || imageBytes.Length == 0)
+            {
+                return (1, "鍥剧墖鏁版嵁涓虹┖");
+            }
+
+            if (string.IsNullOrEmpty(fileName))
+            {
+                return (1, "鏂囦欢鍚嶄负绌�");
+            }
+
+            // 楠岃瘉鍥剧墖鏍煎紡
+            var allowedExtensions = new[] { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp" };
+            var extension = System.IO.Path.GetExtension(fileName).ToLower();
+            if (!allowedExtensions.Contains(extension))
+            {
+                return (1, "涓嶆敮鎸佺殑鍥剧墖鏍煎紡锛屼粎鏀寔锛歫pg, jpeg, png, gif, bmp, webp");
+            }
+
+            // 楠岃瘉鍥剧墖澶у皬锛堥檺鍒朵负5MB锛�
+            if (imageBytes.Length > 5 * 1024 * 1024)
+            {
+                return (1, "鍥剧墖澶у皬涓嶈兘瓒呰繃5MB");
+            }
+
+            // 鐢熸垚鏃堕棿鎴虫枃浠跺悕锛屾牸寮忥細1746945271304.jpg
+            var timestamp = DateTimeOffset.Now.ToUnixTimeMilliseconds();
+            var timestampFileName = $"{timestamp}{extension}";
+
+            var result = SqlSugarHelper.UseTransactionWithOracle(db =>
+            {
+                // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦�
+                var exists = db.Queryable<QsQaItemXj01>()
+                    .Where(s => s.Id == id)
+                    .Any();
+
+                if (!exists)
+                {
+                    throw new Exception("妫�楠岄」鐩笉瀛樺湪");
+                }
+
+                // 鏇存柊PICTURE瀛楁锛圠ONG RAW绫诲瀷锛夊拰PICTURENAME瀛楁锛堟椂闂存埑鏂囦欢鍚嶏級
+                var updateResult = db.Updateable<QsQaItemXj01>()
+                    .SetColumns(s => s.Picture == imageBytes)
+                    .SetColumns(s => s.Picturename == timestampFileName)
+                    .Where(s => s.Id == id)
+                    .ExecuteCommand();
+
+                return updateResult;
+            });
+
+            if (result > 0)
+            {
+                return (0, "鍥剧墖淇濆瓨鎴愬姛");
+            }
+            else
+            {
+                return (1, "鍥剧墖淇濆瓨澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勬楠岄」鐩�");
+            }
+        }
+        catch (Exception ex)
+        {
+            return (1, $"鍥剧墖淇濆瓨澶辫触锛歿ex.Message}");
+        }
+    }
+
+    /// <summary>
+    /// 鍒犻櫎妫�楠岄」鐩殑鍥剧墖
+    /// </summary>
+    /// <param name="id">妫�楠岄」鐩甀D</param>
+    /// <returns>鎿嶄綔缁撴灉</returns>
+    public (int status, string message) DeleteImageFromPicture(decimal id)
+    {
+        try
+        {
+            var result = SqlSugarHelper.UseTransactionWithOracle(db =>
+            {
+                // 妫�鏌ユ楠岄」鐩槸鍚﹀瓨鍦�
+                var exists = db.Queryable<QsQaItemXj01>()
+                    .Where(s => s.Id == id)
+                    .Any();
+
+                if (!exists)
+                {
+                    throw new Exception("妫�楠岄」鐩笉瀛樺湪");
+                }
+
+                // 娓呯┖PICTURE瀛楁鍜孭ICTURENAME瀛楁
+                var updateResult = db.Updateable<QsQaItemXj01>()
+                    .SetColumns(s => s.Picture == null)
+                    .SetColumns(s => s.Picturename == null)
+                    .Where(s => s.Id == id)
+                    .ExecuteCommand();
+
+                return updateResult;
+            });
+
+            if (result > 0)
+            {
+                return (0, "鍥剧墖鍒犻櫎鎴愬姛");
+            }
+            else
+            {
+                return (1, "鍥剧墖鍒犻櫎澶辫触锛屾湭鎵惧埌瀵瑰簲鐨勬楠岄」鐩�");
+            }
+        }
+        catch (Exception ex)
+        {
+            return (1, $"鍥剧墖鍒犻櫎澶辫触锛歿ex.Message}");
+        }
+    }
+
     
 }
\ No newline at end of file

--
Gitblit v1.9.3