From 02893d929e7d2b650dc32ff14e6b12e6ca39dc75 Mon Sep 17 00:00:00 2001
From: fcx <2246384483@qq.com>
Date: 星期二, 02 十二月 2025 17:15:40 +0800
Subject: [PATCH] 1.新增获取巡检单所有不良描述

---
 StandardPda/MES.Service/service/QC/XJService.cs |  376 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 309 insertions(+), 67 deletions(-)

diff --git a/StandardPda/MES.Service/service/QC/XJService.cs b/StandardPda/MES.Service/service/QC/XJService.cs
index 9ed2beb..87d9c7b 100644
--- a/StandardPda/MES.Service/service/QC/XJService.cs
+++ b/StandardPda/MES.Service/service/QC/XJService.cs
@@ -3,6 +3,7 @@
 using MES.Service.Modes;
 using MES.Service.util;
 using SqlSugar;
+using System.Data;
 
 namespace MES.Service.service.QC;
 
@@ -61,7 +62,8 @@
                              statusArray.Contains(a.Daa018))
             .GroupBy((a, b) => new
             {
-                b.LineNo, b.LineName
+                b.LineNo,
+                b.LineName
             })
             .Select((a, b) => new MesLine
             {
@@ -106,56 +108,197 @@
                 }).ToList();
     }
 
-    public List<QsQaItemXj> getPage(XJPageResult queryObj)
+    //public (List<QsQaItemXj> item, int TotalCount) getPage(XJPageResult queryObj)
+    //{
+    //    var db = SqlSugarHelper.GetInstance();
+
+    //    var id = Convert.ToDecimal(queryObj.id);
+
+    //    var totalCount = 0;
+
+    //    string[]? lineNo = null;
+
+    //    // if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
+    //    //     lineNo = _baseService.getUserLineNo(queryObj.createUser);
+
+    //    var pageList = db
+    //        .Queryable<QsQaItemXj, Womdaa,
+    //            MesItems>((s, a,  b) =>
+    //            new JoinQueryInfos(
+    //                JoinType.Inner, s.BillNo == a.Daa001,
+    //                JoinType.Left, s.ItemId == b.Id
+    //            )
+    //        )
+
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+    //            "鏈畬鎴�".Equals(queryObj.result),
+    //            (s, a,  b) => s.Fsubmit == null || s.Fsubmit == 0)
+    //        // .WhereIF(
+    //        //     StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+    //        //     !"鏈畬鎴�".Equals(queryObj.result),
+    //        //     (s, a,  b) => s.FcheckResu != null)
+    //        .WhereIF(
+    //            StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+    //            !"鏈畬鎴�".Equals(queryObj.result),
+    //            (s, a,  b) => s.Fsubmit == 1)
+    //        .WhereIF(id > 0, (s, a, b) => s.Id == id)
+    //        .Select((s, a,  b) => new QsQaItemXj
+    //        {
+    //            Id = s.Id,
+    //            PlanQty = a.Daa008,
+    //            CreateBy = s.CreateBy,
+    //            CreateDate = s.CreateDate,
+    //            ReleaseNo = s.ReleaseNo,
+    //            ItemNo = s.ItemNo,
+    //            BillNo = s.BillNo,
+    //            ItemName = b.ItemName,
+    //            ItemModel = b.ItemModel,
+    //            FcheckBy = s.FcheckBy,
+    //            FcheckResu = s.FcheckResu,
+    //            Remarks = s.Remarks,
+    //            Fsubmit = s.Fsubmit,
+    //            FcheckDate = s.FcheckDate,
+    //            FsubmitBy = s.FsubmitBy
+    //        }).OrderBy(s => s.CreateDate, OrderByType.Desc)
+    //        .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+    //    return (pageList, totalCount);
+    //}
+
+    public (List<QsQaItemXj> item, int TotalCount) getPage(XJPageResult queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
 
         var id = Convert.ToDecimal(queryObj.id);
+        var totalCount = 0;
 
-        string[]? lineNo = null;
-
-        if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
-            lineNo = _baseService.getUserLineNo(queryObj.createUser);
-
-        return db
-            .Queryable<QsQaItemXj, Womdaa, MesLine,
-                MesItems>((s, a, c, b) =>
+        var pageList = db
+            .Queryable<QsQaItemXj, Womdaa, MesItems>((s, a, b) =>
                 new JoinQueryInfos(
                     JoinType.Inner, s.BillNo == a.Daa001,
-                    JoinType.Left, a.Daa015 == c.LineNo,
                     JoinType.Left, s.ItemId == b.Id
                 )
             )
-            .WhereIF(lineNo != null && lineNo.Length > 0,
-                (s, a, c, b) => lineNo.Contains(c.LineNo))
+
+            // 猸� 妯$硦鎼滅储锛圔illNo 鎴� ItemNo 鏂板
+            .WhereIF(
+                StringUtil.IsNotNullOrEmpty(queryObj.SearchValue),
+                (s, a, b) =>
+                    s.BillNo.Contains(queryObj.SearchValue) ||
+                    s.ItemNo.Contains(queryObj.SearchValue)
+            )
+
+            // 猸� 鐘舵�佺瓫閫夛細鏈畬鎴�
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 "鏈畬鎴�".Equals(queryObj.result),
-                (s, a, c, b) => s.FcheckResu == null)
+                (s, a, b) => s.Fsubmit == null || s.Fsubmit == 0
+            )
+
+            // 猸� 鐘舵�佺瓫閫夛細宸插畬鎴�
             .WhereIF(
                 StringUtil.IsNotNullOrEmpty(queryObj.result) &&
                 !"鏈畬鎴�".Equals(queryObj.result),
-                (s, a, c, b) => s.FcheckResu != null)
-            .WhereIF(id > 0, (s, a, c, b) => s.Id == id)
-            .Select((s, a, c, b) => new QsQaItemXj
+                (s, a, b) => s.Fsubmit == 1
+            )
+
+            // 猸� ID 鏌ヨ锛堝崟鏉★級
+            .WhereIF(id > 0, (s, a, b) => s.Id == id)
+
+            // 猸� select 瀹炰綋杩斿洖
+            .Select((s, a, b) => new QsQaItemXj
             {
-                Daa020 = c.LineNo,
                 Id = s.Id,
-                PlanQty = a.Daa008,
+                ReleaseNo = s.ReleaseNo,
+                FcheckDate = s.FcheckDate,
+                FcheckBy = s.FcheckBy,
+                ItemNo = s.ItemNo,
+                FcheckResu = s.FcheckResu,
                 CreateBy = s.CreateBy,
                 CreateDate = s.CreateDate,
-                ReleaseNo = s.ReleaseNo,
-                ItemNo = s.ItemNo,
+                LastupdateBy = s.LastupdateBy,
+                LastupdateDate = s.LastupdateDate,
+                Modify1By = s.Modify1By,
+                ItemUnit = s.ItemUnit,
                 BillNo = s.BillNo,
+                MoidNum = s.MoidNum,
+                FsubmitBy = s.FsubmitBy,
+                FsubmitDate = s.FsubmitDate,
+                Fsubmit = s.Fsubmit,
+                Remarks = s.Remarks,
+                ItemId = s.ItemId,
+
+                // 猸� 棰濆瀛楁锛堟潵鑷繛琛級
+                PlanQty = a.Daa008,
                 ItemName = b.ItemName,
-                ItemModel = b.ItemModel,
-                FcheckBy = s.FcheckBy,
-                FcheckResu = s.FcheckResu,
-                Remarks = s.Remarks
-            }).OrderBy(s => s.CreateDate, OrderByType.Desc)
-            .ToPageList(queryObj.PageIndex, queryObj.Limit);
+                ItemModel = b.ItemModel
+            })
+
+            .OrderBy(s => s.CreateDate, OrderByType.Desc)
+
+            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
+
+        return (pageList, totalCount);
     }
 
+
+    public object CloseInspection(XJCloseInspectionDto dto)
+    {
+        try
+        {
+            var db = SqlSugarHelper.GetInstance();
+
+            var sql = string.Format(
+                @"UPDATE QS_QA_ITEM_XJ
+              SET FSUBMIT = 1,
+                  FCHECK_RESU = '鎵嬪姩鍏抽棴'
+              WHERE ID = '{0}'",
+                dto.id);
+
+            db.Ado.ExecuteCommand(sql);
+
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = "鍏抽棴鎴愬姛"
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    public bool XJQaSubmit(LLJDto rkjDto)
+    {
+        var useTransactionWithOracle =
+            SqlSugarHelper.UseTransactionWithOracle(db =>
+            {
+                return db.Updateable<QsQaItemXj>()
+                    .SetColumns(s => s.Fsubmit == 1)
+                    .SetColumns(s => s.FsubmitBy == rkjDto.userNo)
+                    .SetColumns(s => s.FsubmitDate == DateTime.Now)
+                    .Where(s => s.Id == rkjDto.gid)
+                    .ExecuteCommand();
+            });
+
+        return useTransactionWithOracle > 0;
+    }
 
     public List<QsQaItemXj01> setJYItem(string itemNo)
     {
@@ -169,29 +312,28 @@
         return db
             .Queryable<MesQualityStandard>()
             .Where(b => b.QsType == "2"
-                        && b.ItemNo == itemNo).Select(
-                b => new QsQaItemXj01
-                {
-                    ProjName = b.ProjName,
-                    ItemMod = b.ItemMod,
-                    InspectionMethod = b.InspectionMethod,
-                    UsingInstruments = b.UsingInstruments,
-                    LevelNum = SqlFunc.IsNull(
-                        SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
-                        b.InspectionLevel),
-                    MaxValue = b.MaxValue,
-                    StandardValue = b.StandardValue,
-                    MinValue = b.MinValue,
-                    Notes = b.Notes,
-                    FcheckLevel = b.FcheckLevel,
-                    FacLevel = b.FacLevel,
-                    QsCode = b.QsCode,
-                    QsName = b.QsName,
-                    result = "鏈娴�",
-                    isCheck = 0,
-                    Picture = b.Picture,
-                    Picturename = b.Picturename
-                }).ToList();
+                        && b.ItemNo == itemNo).Select(b => new QsQaItemXj01
+            {
+                ProjName = b.ProjName,
+                ItemMod = b.ItemMod,
+                InspectionMethod = b.InspectionMethod,
+                UsingInstruments = b.UsingInstruments,
+                LevelNum = SqlFunc.IsNull(
+                    SqlFunc.IsNull(b.LevelNum * b.InspectionLevel, 1),
+                    b.InspectionLevel),
+                MaxValue = b.MaxValue,
+                StandardValue = b.StandardValue,
+                MinValue = b.MinValue,
+                Notes = b.Notes,
+                FcheckLevel = b.FcheckLevel,
+                FacLevel = b.FacLevel,
+                QsCode = b.QsCode,
+                QsName = b.QsName,
+                result = "鏈娴�",
+                isCheck = 0,
+                Picture = b.Picture,
+                Picturename = b.Picturename
+            }).ToList();
     }
 
     public List<QsQaItemXj01> getJYItem(decimal? pid, decimal? id)
@@ -288,36 +430,92 @@
         return Convert.ToInt32(xj.Id);
     }
 
+    //public int saveItem(XJDto xjDto)
+    //{
+    //    var items = xjDto.items;
+    //    var userNo = xjDto.userNo;
+
+    //    SqlSugarHelper.UseTransactionWithOracle(db =>
+    //    {
+    //        foreach (var item in items) item.Pid = xjDto.gid;
+
+    //        return db.Insertable(items).ExecuteCommand();
+    //    });
+
+    //    xjDto.items = getJYItem(xjDto.gid, null);
+
+    //    xjDto.items.ForEach(s =>
+    //    {
+    //        if (s.MaxValue != null || s.StandardValue != null ||
+    //            s.MinValue != null) return;
+    //        var detail = new QsQaItemXj02();
+    //        detail.Pid = s.Id;
+    //        detail.Gid = xjDto.gid;
+    //        detail.Fstand = "鈭�";
+    //        detail.FcheckResu = "1";
+    //        detail.UpdateBy = xjDto.userNo;
+    //        detail.count = (int?)s.LevelNum;
+    //        SetQSItemDetail(detail);
+    //    });
+
+    //    return Convert.ToInt32(xjDto.gid);
+    //}
+
     public int saveItem(XJDto xjDto)
     {
         var items = xjDto.items;
         var userNo = xjDto.userNo;
 
-        SqlSugarHelper.UseTransactionWithOracle(db =>
+        // 鉁� 浣跨敤 lambda 杩斿洖鎻掑叆鏉℃暟锛屼繚璇� Func<SqlSugarClient, int> 姣忔潯璺緞閮芥湁杩斿洖鍊�
+        int insertCount = SqlSugarHelper.UseTransactionWithOracle(db =>
         {
-            foreach (var item in items) item.Pid = xjDto.gid;
+            // 1锔忊儯 妫�鏌ヨ〃閲屾槸鍚﹀瓨鍦ㄧ浉鍚� gid 鐨勬暟鎹�
+            var existingCount = db.Queryable<QsQaItemXj01>()
+                                  .Count(s => s.Pid == xjDto.gid);
+
+            // 2锔忊儯 濡傛灉瀛樺湪锛屽垯鍏堝垹闄�
+            if (existingCount > 0)
+            {
+                db.Deleteable<QsQaItemXj01>()
+                  .Where(s => s.Pid == xjDto.gid)
+                  .ExecuteCommand();
+            }
+
+            // 3锔忊儯 缁欐瘡鏉℃槑缁嗚缃� Pid 骞舵彃鍏ワ紝杩斿洖鎻掑叆鏉℃暟
+            foreach (var item in items)
+            {
+                item.Pid = xjDto.gid;
+            }
 
             return db.Insertable(items).ExecuteCommand();
         });
 
+        // 4锔忊儯 閲嶆柊鑾峰彇鎻掑叆鍚庣殑鏄庣粏
         xjDto.items = getJYItem(xjDto.gid, null);
 
-        xjDto.items.ForEach(s =>
+        // 5锔忊儯 瀵规病鏈� Max/Min/StandardValue 鐨勬槑缁嗙敓鎴愰粯璁ゆ娴嬬粨鏋�
+        foreach (var s in xjDto.items)
         {
-            if (s.MaxValue != null || s.StandardValue != null ||
-                s.MinValue != null) return;
-            var detail = new QsQaItemXj02();
-            detail.Pid = s.Id;
-            detail.Gid = xjDto.gid;
-            detail.Fstand = "鈭�";
-            detail.FcheckResu = "1";
-            detail.UpdateBy = xjDto.userNo;
-            detail.count = (int?)s.LevelNum;
-            SetQSItemDetail(detail);
-        });
+            if (s.MaxValue != null || s.StandardValue != null || s.MinValue != null)
+                continue;
 
-        return Convert.ToInt32(xjDto.gid);
+            var detail = new QsQaItemXj02
+            {
+                Pid = s.Id,
+                Gid = xjDto.gid,
+                Fstand = "鈭�",
+                FcheckResu = "1",
+                UpdateBy = xjDto.userNo,
+                count = (int?)s.LevelNum
+            };
+            SetQSItemDetail(detail);
+        }
+
+        // 6锔忊儯 杩斿洖鎻掑叆鏉℃暟
+        return insertCount;
     }
+
+
 
 
     public XJDto getXjDetail02ById(decimal? id)
@@ -398,8 +596,8 @@
 
         if (count == passCount) result = 1;
 
-        var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle(
-            db =>
+        var useTransactionWithOracle =
+            SqlSugarHelper.UseTransactionWithOracle(db =>
             {
                 var commit = 0;
                 commit += db.Updateable<QsQaItemXj01>()
@@ -516,6 +714,45 @@
         });
     }
 
+    /// <summary>
+    /// 鑾峰彇棣栨鍗曟墍鏈変笉鑹弿杩�
+    /// </summary>
+    /// <param name="id">妫�楠屽崟ID</param>
+    /// <returns>涓嶈壇鎻忚堪鏁版嵁琛�</returns>
+    public DataTable getBlmsItem1(string id)
+    {
+        OracleSQLHelper SQLHelper = new();
+        // 鏌ヨ棣栨妫�楠屽崟鐨勪笉鑹弿杩�
+        var sql1 = string.Format(
+            @"select PROJ_NAME, REMARKS 
+              from QS_QA_ITEM_XJ01 f 
+              where PID = '" + id + "' and REMARKS is not null  order by PROJ_NAME");
+
+        return SQLHelper.ExecuteQuery(sql1);
+    }
+
+
+
+    /// <summary>
+    /// 鑾峰彇宸℃妫�鍗曟墍鏈変笉鑹弿杩�
+    /// </summary>
+    /// <param name="id">妫�楠屽崟ID</param>
+    /// <returns>涓嶈壇鎻忚堪鏁版嵁琛�</returns>
+    public DataTable ggetBlmsItem1(string id)
+    {
+        OracleSQLHelper SQLHelper = new();
+        // 鏌ヨ棣栨妫�楠屽崟鐨勪笉鑹弿杩�
+        var sql1 = string.Format(
+            @"select PROJ_NAME, REMARKS 
+              from QS_QA_ITEM_XJ01 f 
+              where PID = '" + id + "' and REMARKS is not null  order by PROJ_NAME");
+
+        return SQLHelper.ExecuteQuery(sql1);
+    }
+
+
+
+
     //瀛欒〃淇敼澶囨敞瀛楁
     public int saveRemarksById(XJDto dto)
     {
@@ -527,5 +764,10 @@
                 .Where(it => it.Id == dto.id)
                 .ExecuteCommand();
         });
+
+
+
+
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3