From a619299816f2f632c7c6ba3a1bb869e2c212797d Mon Sep 17 00:00:00 2001
From: fcx <2246384483@qq.com>
Date: 星期五, 19 十二月 2025 14:12:33 +0800
Subject: [PATCH] 对添加巡检单物料编码进行去重

---
 StandardPda/MES.Service/service/QC/SJService.cs |  210 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 192 insertions(+), 18 deletions(-)

diff --git a/StandardPda/MES.Service/service/QC/SJService.cs b/StandardPda/MES.Service/service/QC/SJService.cs
index 2e2c364..cf35419 100644
--- a/StandardPda/MES.Service/service/QC/SJService.cs
+++ b/StandardPda/MES.Service/service/QC/SJService.cs
@@ -1,9 +1,10 @@
-锘縰sing MES.Service.DB;
+锘匡豢using MES.Service.DB;
 using MES.Service.Dto.service;
 using MES.Service.Modes;
 using MES.Service.util;
 using SqlSugar;
 using System.Data;
+using System.Runtime.InteropServices.JavaScript;
 
 namespace MES.Service.service.QC;
 
@@ -35,7 +36,113 @@
     }
 
     //鑾峰彇鎵�鏈夋暟鎹垎椤�
-    public (List<SJPageResult> item, int TotalCount) getPage(SJPageResult queryObj)
+    //public (List<SJPageResult> item, int TotalCount) getPage(SJPageResult queryObj)
+    //{
+    //    var db = SqlSugarHelper.GetInstance();
+
+    //    string[]? lineNo = null;
+
+    //    // if (StringUtil.IsNotNullOrEmpty(queryObj.StatusUser))
+    //    //     lineNo = _baseService.getUserLineNo(queryObj.StatusUser);
+
+    //    var totalCount = 0;
+
+    //    var data = db.Queryable<SJPageResult>()
+    //        .WhereIF(lineNo != null && lineNo.Length > 0,
+    //            a => lineNo.Contains(a.line))
+    //        .WhereIF(queryObj.Id != null, a => a.Id == queryObj.Id)
+    //        .WhereIF(StringUtil.IsNotNullOrEmpty(queryObj.BillNo),
+    //            a => a.BillNo == queryObj.BillNo)
+    //        // .WhereIF(
+    //        //     StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //        //     "鏈畬鎴�".Equals(queryObj.Result),
+    //        //     a => a.Result == queryObj.Result && (a.FSubmit == 0 || a.FSubmit == null))
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //            "鏈畬鎴�".Equals(queryObj.Result),
+    //            a => a.FSubmit == 0 || a.FSubmit == null)
+    //        // .WhereIF(
+    //        //     StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //        //     !"鏈畬鎴�".Equals(queryObj.Result),
+    //        //     a => a.Result != "鏈畬鎴�" && a.FSubmit == 1)
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //            !"鏈畬鎴�".Equals(queryObj.Result),
+    //            a => a.FSubmit == 1)
+    //        .OrderBy(a => a.BillNo, OrderByType.Desc)
+    //        .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+    //    return (data, totalCount);
+    //}
+
+    //public (List<SJPageResult> item, int TotalCount) getPage(SJPageResult queryObj)
+    //{
+    //    var db = SqlSugarHelper.GetInstance();
+
+    //    string[]? lineNo = null;
+
+    //    // if (StringUtil.IsNotNullOrEmpty(queryObj.StatusUser))
+    //    //     lineNo = _baseService.getUserLineNo(queryObj.StatusUser);
+
+    //    var totalCount = 0;
+    //    string searchValue = queryObj.searchValue?.Trim();
+
+    //    // ========= 鏋勫缓鍩虹 query =========
+    //    var query = db.Queryable<SJPageResult>()
+    //        .WhereIF(lineNo != null && lineNo.Length > 0,
+    //            a => lineNo.Contains(a.line))
+    //        .WhereIF(queryObj.Id != null,
+    //            a => a.Id == queryObj.Id)
+    //        .WhereIF(StringUtil.IsNotNullOrEmpty(queryObj.BillNo),
+    //            a => a.BillNo == queryObj.BillNo)
+    //        // 鏈畬鎴�
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //            "鏈畬鎴�".Equals(queryObj.Result),
+    //            a => a.FSubmit == 0 || a.FSubmit == null)
+    //        // 宸插畬鎴�
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
+    //            !"鏈畬鎴�".Equals(queryObj.Result),
+    //            a => a.FSubmit == 1);
+
+    //    // ========= SearchValue 鍒ゆ柇 =========
+
+    //    // SearchValue 涓虹┖锛氳繑鍥炲叏閮�
+    //    if (string.IsNullOrWhiteSpace(searchValue))
+    //    {
+    //        var allData = query
+    //            .OrderBy(a => a.BillNo, OrderByType.Desc)
+    //            .ToPageList(
+    //                Math.Max(queryObj.PageIndex, 1),
+    //                Math.Max(queryObj.Limit, 1),
+    //                ref totalCount
+    //            );
+
+    //        return (allData, totalCount);
+    //    }
+
+    //    // SearchValue 涓嶄负绌猴細妯$硦鏌� BILL_NO / ITEM_NO
+    //    query = query.Where(a =>
+    //        SqlFunc.Like(SqlFunc.Trim(a.BillNo).ToLower(), $"%{searchValue.ToLower()}%") ||
+    //        SqlFunc.Like(SqlFunc.Trim(a.ItemNo).ToLower(), $"%{searchValue.ToLower()}%")
+    //    );
+
+    //    // ========= 鎵ц鍒嗛〉 =========
+    //    var data = query
+    //        .OrderBy(a => a.BillNo, OrderByType.Desc)
+    //        .ToPageList(
+    //            Math.Max(queryObj.PageIndex, 1),
+    //            Math.Max(queryObj.Limit, 1),
+    //            ref totalCount
+    //        );
+
+    //    return (data, totalCount);
+    //}
+
+
+
+    public (List<SJPageResult> item, int TotalCount) getPage(SJPageResult2 queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
 
@@ -45,34 +152,85 @@
         //     lineNo = _baseService.getUserLineNo(queryObj.StatusUser);
 
         var totalCount = 0;
+        string searchValue = queryObj.searchValue?.Trim();
 
-        var data = db.Queryable<SJPageResult>()
+        // 鑾峰彇鎼滅储閫夐」绱㈠紩 (0:椤圭洰, 1:绾夸綋, 2:宸ュ崟鍙�, 3:鐗╂枡鍙�, 4:鐗╂枡鍚�)
+        int selectedIndex = queryObj.selectedIndex ?? 0;
+
+        // ========= 鏋勫缓鍩虹 query =========
+        var query = db.Queryable<SJPageResult>()
             .WhereIF(lineNo != null && lineNo.Length > 0,
                 a => lineNo.Contains(a.line))
-            .WhereIF(queryObj.Id != null, a => a.Id == queryObj.Id)
+            .WhereIF(queryObj.Id != null,
+                a => a.Id == queryObj.Id)
             .WhereIF(StringUtil.IsNotNullOrEmpty(queryObj.BillNo),
                 a => a.BillNo == queryObj.BillNo)
-            // .WhereIF(
-            //     StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
-            //     "鏈畬鎴�".Equals(queryObj.Result),
-            //     a => a.Result == queryObj.Result && (a.FSubmit == 0 || a.FSubmit == null))
+            // 鏈畬鎴�
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
                 "鏈畬鎴�".Equals(queryObj.Result),
                 a => a.FSubmit == 0 || a.FSubmit == null)
-            // .WhereIF(
-            //     StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
-            //     !"鏈畬鎴�".Equals(queryObj.Result),
-            //     a => a.Result != "鏈畬鎴�" && a.FSubmit == 1)
+            // 宸插畬鎴�
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.Result) &&
                 !"鏈畬鎴�".Equals(queryObj.Result),
-                a =>   a.FSubmit == 1)
+                a => a.FSubmit == 1);
+
+        // ========= SearchValue 鍒ゆ柇 =========
+
+        // SearchValue 涓虹┖锛氳繑鍥炲叏閮�
+        if (string.IsNullOrWhiteSpace(searchValue))
+        {
+            var allData = query
+                .OrderBy(a => a.BillNo, OrderByType.Desc)
+                .ToPageList(
+                    Math.Max(queryObj.PageIndex, 1),
+                    Math.Max(queryObj.Limit, 1),
+                    ref totalCount
+                );
+
+            return (allData, totalCount);
+        }
+
+        // SearchValue 涓嶄负绌猴細鏍规嵁selectedIndex杩涜涓嶅悓瀛楁鐨勬ā绯婃煡璇�
+        switch (queryObj.selectedIndex)
+        {
+            case 2: // 宸ュ崟鍙�
+                query = query.Where(a => SqlFunc.Like(a.daa001.ToLower(), $"%{searchValue.ToLower()}%"));
+                break;
+            case 3: // 鐗╂枡鍙�
+                query = query.Where(a => SqlFunc.Like(a.ItemNo.ToLower(), $"%{searchValue.ToLower()}%"));
+                break;
+            case 4: // 鐗╂枡鍚嶇О
+                query = query.Where(a => SqlFunc.Like(a.Daa003.ToLower(), $"%{searchValue.ToLower()}%"));
+                break;
+            case 0: // 椤圭洰缂栫爜
+                query = query.Where(a => SqlFunc.Like(a.PROJECT_CODE.ToLower(), $"%{searchValue.ToLower()}%"));
+                break;
+            case 1: // 绾夸綋
+                query = query.Where(a => SqlFunc.Like(a.line.ToLower(), $"%{searchValue.ToLower()}%"));
+                break;
+            default:
+                return (new List<SJPageResult>(), 0);
+        }
+
+        // ========= 鎵ц鍒嗛〉 =========
+        var data = query
             .OrderBy(a => a.BillNo, OrderByType.Desc)
-            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+            .ToPageList(
+                Math.Max(queryObj.PageIndex, 1),
+                Math.Max(queryObj.Limit, 1),
+                ref totalCount
+            );
 
         return (data, totalCount);
     }
+
+
+
+
+
+
 
 
     //SetQSItem
@@ -135,7 +293,8 @@
                     Picture = b.Picture,
                     Picturename = b.Picturename,
                     result = "鏈娴�",
-                    isCheck = 0
+                    isCheck = 0,
+                    UP_FILE=b.UP_FILE
                 }).ToList();
     }
 
@@ -231,7 +390,7 @@
         });
 
         item.Items = getQSItems(qsItemIpiReq.Id, null);
-        var sjPageResult = new SJPageResult
+        var sjPageResult = new SJPageResult2
             { Id = item.From.Id, Limit = 1, PageIndex = 1 };
         var pageResult = getPage(sjPageResult);
         item.Result = pageResult.item[0];
@@ -255,7 +414,7 @@
 
             // 2. 鏌ユ壘 MesQa 瀵瑰簲涓昏〃ID锛堥�氳繃 item.ItemNo锛�
             var mesQa = db.Queryable<MesQa>()
-                .Where(q => q.ItemNo == item.ItemNo)
+                .Where(q => q.ItemNo == item.ItemNo && q.QsType== "1")
                 .Select(q => new { q.Id })
                 .First();
 
@@ -576,7 +735,6 @@
             SqlSugarHelper.UseTransactionWithOracle(db =>
             {
                 return db.Updateable<QsItemIpiReq>()
-                    .SetColumns(s => s.Fsubmit == 1)
                     .SetColumns(s => s.FsubmitBy == rkjDto.userNo)
                     .SetColumns(s => s.FsubmitDate == DateTime.Now)
                     .Where(s => s.Id == rkjDto.gid)
@@ -769,6 +927,22 @@
         return msg;
     }
 
+    /// <summary>
+    /// 鑾峰彇棣栨鍗曟墍鏈変笉鑹弿杩�
+    /// </summary>
+    /// <param name="id">妫�楠屽崟ID</param>
+    /// <returns>涓嶈壇鎻忚堪鏁版嵁琛�</returns>
+    public DataTable getBlmsItem(string id)
+    {
+        OracleSQLHelper SQLHelper = new();
+        // 鏌ヨ棣栨妫�楠屽崟鐨勪笉鑹弿杩�
+        var sql1 = string.Format(
+            @"select PROJ_NAME, REMARKS 
+              from QS_ITEM_IPI_ITEM f 
+              where PID = '" + id + "' and REMARKS is not null  order by PROJ_NAME");
+
+        return SQLHelper.ExecuteQuery(sql1);
+    }
 
 
 }
\ No newline at end of file

--
Gitblit v1.9.3