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/RKJService.cs |  268 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 231 insertions(+), 37 deletions(-)

diff --git a/StandardInterface/MES.Service/service/QC/RKJService.cs b/StandardInterface/MES.Service/service/QC/RKJService.cs
index 1365909..e3c8ff7 100644
--- a/StandardInterface/MES.Service/service/QC/RKJService.cs
+++ b/StandardInterface/MES.Service/service/QC/RKJService.cs
@@ -291,7 +291,8 @@
                 a.FcheckLevel,
                 a.FacLevel,
                 a.QsCode,
-                a.QsName
+                a.QsName,
+                a.Forder
             }).Select((a, b) => new QsItemOqcItem
             {
                 ProjName = a.ProjName,
@@ -308,13 +309,11 @@
                 FacLevel = a.FacLevel,
                 QsCode = a.QsCode,
                 QsName = a.QsName,
+                Forder = a.Forder,
                 isCheck = SqlFunc.AggregateCount(b.Id),
-                Result = a.IsPass == 1 &&
-                         a.LevelNum == SqlFunc.AggregateCount(b.Id) ? "鍚堟牸"
-                    : a.IsPass == 0 &&
-                      a.LevelNum == SqlFunc.AggregateCount(b.Id) ? "涓嶅悎鏍�"
-                    : "鏈畬鎴�"
-            }).OrderBy("result desc").ToList();
+                Result = SqlFunc.AggregateCount(b.Id) == 0 ? "鏈畬鎴�" :
+                         a.IsPass == 1 ? "鍚堟牸" : "涓嶅悎鏍�"
+            }).OrderBy("FORDER").ToList();
     }
 
     public dynamic save(RKJDto rkjDto)
@@ -562,12 +561,12 @@
         var qsItemOqcReq =
             db.Queryable<QsItemOqcReq>().Single(s => s.Id == gid);
 
-        var mesInvItemIns = db.Queryable<MesInvItemIns>()
-            .Single(s => s.BillNo == qsItemOqcReq.BillNo);
+        //var mesInvItemIns = db.Queryable<MesInvItemIns>()
+        // .Single(s => s.BillNo == qsItemOqcReq.BillNo);
 
         var mesSchemeResult = db.Queryable<Womdaa>()
-            .Single(s => s.Daa001 == mesInvItemIns.CbillNo);
-
+            //.Single(s => s.Daa001 == mesInvItemIns.CbillNo);
+            .Single(s => s.Daa001 == qsItemOqcReq.BillNo);
         var entity = new MesQaItemsDetect02();
         // entity.ItemNo = mesSchemeResult.BoardItem;
         // entity.BoardItem = mesSchemeResult.BoardItem;
@@ -594,9 +593,9 @@
         entity.CreateBy = createBy;
         entity.FcheckBy = createBy;
 
-        return SqlSugarHelper.UseTransactionWithOracle(db => db
-            .Insertable(entity)
-            .ExecuteCommand());
+        // 璺宠繃MES_QA_ITEMS_DETECT_02琛ㄧ殑鎻掑叆鎿嶄綔
+        // 涓嶅啀鑷姩鐢熸垚鍏ュ簱妫�寮傚父瀵圭瓥璁板綍
+        return 0;
     }
 
 
@@ -611,31 +610,57 @@
         if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
             lineNo = _baseService.getUserLineNo(queryObj.createUser);
 
+
         return db
-            .Queryable<QsItemOqcReq, Womdaa, MesItems>((a, da, b) =>
+            .Queryable<QsItemOqcReq, Womdaa, MesItems, MesLine>((a, da, b, m) =>
                 new JoinQueryInfos(
                     JoinType.Left, da.Daa001 == a.BillNo,
-                    JoinType.Left, a.ItemId == b.Id
+                    JoinType.Left, a.ItemId == b.Id,
+                    JoinType.Left, da.Daa015 == m.LineNo
                 ))
             .WhereIF(lineNo != null && lineNo.Length > 0,
-                (a, da, b) => lineNo.Contains(da.Daa015))
+                (a, da, b, m) => lineNo.Contains(da.Daa015))
+            // 娣诲姞QC绛涢�夋潯浠讹細杞﹂棿鍜岀嚎浣�
+            .WhereIF(!string.IsNullOrEmpty(queryObj.departmentId),
+                (a, da, b, m) => m.DepotId.ToString() == queryObj.departmentId)
+            .WhereIF(!string.IsNullOrEmpty(queryObj.lineId),
+                (a, da, b, m) => m.LineNo == queryObj.lineId)
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 "鏈畬鎴�".Equals(queryObj.result),
-                (a, da, b) => a.FcheckResu == null || a.FcheckResu == "")
+                (a, da, b, m) => a.FcheckResu == null || a.FcheckResu == "")
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 !"鏈畬鎴�".Equals(queryObj.result),
-                (a, da, b) => a.FcheckResu != null && a.FcheckResu != "")
-            .WhereIF(id > 0, (a, da, b) => a.Id == id)
-            // 娣诲姞fsubmit瀛楁杩囨护閫昏緫
+                (a, da, b, m) => a.FcheckResu != null && a.FcheckResu != "")
+            .WhereIF(id > 0, (a, da, b, m) => a.Id == id)
+            // 娣诲姞fsubmit瀛楁杩囨护閫昏緫 - 鍙湁鍦ㄦ槑纭寚瀹歠submit鍙傛暟鏃舵墠杩囨护锛屼笖娌℃湁浼犻�抜d鏃舵墠杩囨护
             .WhereIF(
-                StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1",
-                (a, da, b) => a.Fsubmit == 1)
+                id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "1",
+                (a, da, b, m) => a.Fsubmit == 1)
             .WhereIF(
-                StringUtil.IsNullOrEmpty(queryObj.fsubmit) || queryObj.fsubmit == "0",
-                (a, da, b) => a.Fsubmit == 0 || a.Fsubmit == null)
-            .Select((a, da, b) => new QsItemOqcReq
+                id <= 0 && StringUtil.IsNotNullOrEmpty(queryObj.fsubmit) && queryObj.fsubmit == "0",
+                (a, da, b, m) => a.Fsubmit == 0 || a.Fsubmit == null)
+            // 娣诲姞鎼滅储鏉′欢 - 鏍规嵁閫夋嫨鐨勬悳绱㈠瓧娈佃繘琛岀簿纭悳绱�
+            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "billNo",  // 宸ュ崟
+                (a, da, b, m) => a.BillNo.Contains(queryObj.SearchValue))
+            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "releaseNo",  // 妫�楠屽崟鍙�
+                (a, da, b, m) => a.ReleaseNo.Contains(queryObj.SearchValue))
+            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "daa015",  // 浜х嚎
+                (a, da, b, m) => da.Daa015.Contains(queryObj.SearchValue))
+            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemNo",  // 鐗╂枡缂栫爜
+                (a, da, b, m) => a.ItemNo.Contains(queryObj.SearchValue))
+            .WhereIF(!string.IsNullOrEmpty(queryObj.SearchValue) && !string.IsNullOrEmpty(queryObj.searchField) && queryObj.searchField == "itemName",  // 鐗╂枡鍚嶇О
+                (a, da, b, m) => b.ItemName.Contains(queryObj.SearchValue))
+            // 涓轰簡鍏煎鏃х増鏈紝濡傛灉娌℃湁浼犻�� searchField锛屼娇鐢ㄥ師鏉ョ殑鏌ヨ閫昏緫
+            .WhereIF(string.IsNullOrEmpty(queryObj.searchField) && !string.IsNullOrEmpty(queryObj.SearchValue),
+                (a, da, b, m) => 
+                    a.ItemNo.Contains(queryObj.SearchValue) ||
+                    b.ItemName.Contains(queryObj.SearchValue) ||
+                    a.BillNo.Contains(queryObj.SearchValue) ||
+                    a.ReleaseNo.Contains(queryObj.SearchValue) ||
+                    da.Daa015.Contains(queryObj.SearchValue))
+            .Select((a, da, b, m) => new QsItemOqcReq
             {
                 Id = a.Id,
                 ReleaseNo = a.ReleaseNo,
@@ -694,8 +719,36 @@
         var rkjDto = new RKJDto();
 
         var db = SqlSugarHelper.GetInstance();
-        var qsItemOqcItem =
-            db.Queryable<QsItemOqcItem>().Single(s => s.Id == id);
+        
+        // 浣跨敤JOIN鏌ヨ鑾峰彇瀛愯〃鏁版嵁鍜屼富琛ㄧ殑ItemNo瀛楁
+        var qsItemOqcItem = db
+            .Queryable<QsItemOqcItem, QsItemOqcReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
+            .Where((a, b) => a.Id == id)
+            .Select((a, b) => new QsItemOqcItem
+            {
+                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,
+                FreQty = a.FreQty,
+                // 娣诲姞涓昏〃鐨処temNo瀛楁
+                ItemNo = b.ItemNo
+            }).Single();
 
         if (qsItemOqcItem.IsPass == 0)
             qsItemOqcItem.Result = "涓嶅悎鏍�";
@@ -715,7 +768,6 @@
         qsItemOqcItem.Unqualified = count;
 
         rkjDto.ItemXj01 = qsItemOqcItem;
-
 
         rkjDto.ItemXj02s = db.Queryable<QsItemOqcItemDetail>()
             .Where(s => s.Pid == id)
@@ -944,14 +996,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)
+                .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
                 {
@@ -982,24 +1044,33 @@
     /// </summary>
     /// <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 projName = null)
     {
         // 鍙傛暟楠岃瘉
-        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(ftpServer))
+        if (string.IsNullOrEmpty(itemNo) || string.IsNullOrEmpty(fileName))
         {
-            throw new ArgumentException("鍙傛暟涓嶈兘涓虹┖: itemNo, fileName, ftpServer");
+            throw new ArgumentException("鍙傛暟涓嶈兘涓虹┖: itemNo, fileName");
         }
         
         string ftpUser = "hm_ftp";
         string ftpPwd = "dell_123";
+        string ftpServer = "ftp://192.168.1.100"; // 榛樿FTP鏈嶅姟鍣ㄥ湴鍧�
         
         // 鏍囧噯鍖朏TP鏈嶅姟鍣ㄥ湴鍧�
         string normalizedServer = NormalizeFtpServer(ftpServer);
         
-        // 鏋勫缓FTP鏂囦欢璺緞 - RKJ浣跨敤FQC鏂囦欢澶�
-        string ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}";
+        // 鏋勫缓FTP鏂囦欢璺緞 - RKJ浣跨敤FQC鏂囦欢澶癸紝濡傛灉鏈塸rojName鍒欎娇鐢╬rojName浣滀负璺緞鐨勬渶鍚庝竴娈�
+        string ftpPath;
+        if (!string.IsNullOrEmpty(projName))
+        {
+            ftpPath = $"{normalizedServer}/FQC/{itemNo}/{projName}/{fileName}";
+        }
+        else
+        {
+            ftpPath = $"{normalizedServer}/FQC/{itemNo}/{fileName}";
+        }
         
         try
         {
@@ -1155,4 +1226,127 @@
                 .ExecuteCommand();
         });
     }
+
+    /// <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<QsItemOqcItem>()
+                    .Where(s => s.Id == id)
+                    .Any();
+
+                if (!exists)
+                {
+                    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;
+            });
+
+            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<QsItemOqcItem>()
+                    .Where(s => s.Id == id)
+                    .Any();
+
+                if (!exists)
+                {
+                    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();
+
+                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