From bdfcb2760a617d0fb95ee934696a3dde477d7e68 Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期五, 29 八月 2025 17:56:58 +0800
Subject: [PATCH] 1、获取检验项目前先删除

---
 MES.Service/service/QC/XJService.cs |  208 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 169 insertions(+), 39 deletions(-)

diff --git a/MES.Service/service/QC/XJService.cs b/MES.Service/service/QC/XJService.cs
index 9acfaa9..a688673 100644
--- a/MES.Service/service/QC/XJService.cs
+++ b/MES.Service/service/QC/XJService.cs
@@ -1,9 +1,10 @@
-锘縰sing DnsClient.Protocol;
+锘縰sing System.Data;
 using MES.Service.DB;
 using MES.Service.Dto.service;
 using MES.Service.Modes;
 using MES.Service.util;
 using SqlSugar;
+using DbType = System.Data.DbType;
 
 namespace MES.Service.service.QC;
 
@@ -45,11 +46,10 @@
 
         //in鐨勫啓娉� https://www.donet5.com/Home/Doc?typeId=1187
 
-        return db.Queryable<Womdaa, MesItems>(
-                (a, c) =>
-                    new JoinQueryInfos(
-                        JoinType.Left, a.Daa002 == c.Id.ToString() ))
-            .Where(a => a.Daa001 == daa001 )
+        return db.Queryable<Womdaa, MesItems>((a, c) =>
+                new JoinQueryInfos(
+                    JoinType.Left, a.Daa002 == c.Id.ToString()))
+            .Where(a => a.Daa001 == daa001)
             .Select((a, c) => new Womdaa
             {
                 Daa001 = a.Daa001,
@@ -72,7 +72,7 @@
 
         return db.Queryable<Womdaa, MesLine>((a, b) =>
                 new JoinQueryInfos(JoinType.Left, a.Daa015 == b.LineNo))
-           .GroupBy((a, b) => new
+            .GroupBy((a, b) => new
             {
                 a.Daa015, b.LineName
             })
@@ -87,12 +87,12 @@
     {
         var db = SqlSugarHelper.GetInstance();
         return db.Queryable<Womdaa>().Where(a =>
-                a.Daa015 == daa020 && 
-                a.Daa002 == item )
+                a.Daa015 == daa020 &&
+                a.Daa002 == item)
             .Select<Womdaa>(a => new Womdaa
             {
-                Daa001 = a.Daa001,
-               // DetailMem = a.DetailMem
+                Daa001 = a.Daa001
+                // DetailMem = a.DetailMem
             }).ToList();
     }
 
@@ -102,7 +102,7 @@
         return db.Queryable<Womdaa>()
             .Where(a =>
                 a.Daa015 == lineNo)
-           .Select<Womdaa>(a =>
+            .Select<Womdaa>(a =>
                 new Womdaa
                 {
                     Daa002 = a.Daa002,
@@ -111,6 +111,62 @@
                 }).OrderBy(a => a.Daa002).ToList();
     }
 
+    public List<QsQaItemXj> getPage(XJPageResult queryObj)
+    {
+        var db = SqlSugarHelper.GetInstance();
+
+        var id = Convert.ToDecimal(queryObj.id);
+
+        string[]? lineNo = null;
+
+        if (StringUtil.IsNotNullOrEmpty(queryObj.createUser))
+            lineNo = _baseService.getUserLineNo(queryObj.createUser);
+
+        return db
+            .Queryable<QsQaItemXj, Womdaa>((s, a) =>
+                new JoinQueryInfos(
+                    JoinType.Inner, s.BillNo == a.Daa001
+                )
+            )
+            .WhereIF(lineNo != null && lineNo.Length > 0,
+                (s, a) => lineNo.Contains(a.Daa015))
+            .WhereIF(
+                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                "鏈畬鎴�".Equals(queryObj.result),
+                (s, a) =>  s.Fsubmit == null ||
+                          s.Fsubmit == 0)
+            .WhereIF(
+                StringUtil.IsNotNullOrEmpty(queryObj.result) &&
+                !"鏈畬鎴�".Equals(queryObj.result),
+                (s, a) => s.Fsubmit == 1)
+            .WhereIF(id > 0, (s, a) => s.Id == id)
+            .Select((s, a) => new QsQaItemXj
+            {
+                CatQty = a.Daa008,
+                MoidNum = s.MoidNum,
+                Daa020 = a.Daa015,
+                // DetailMem = a.DetailMem,
+                TaskNo = a.Daa001,
+                Id = s.Id,
+                CreateBy = s.CreateBy,
+                CreateDate = s.CreateDate,
+                ReleaseNo = s.ReleaseNo,
+                ItemNo = s.ItemNo,
+                ItemUnit = s.ItemUnit,
+                BillNo = s.BillNo,
+                FcheckBy = s.FcheckBy,
+                FcheckResu = s.FcheckResu,
+                Remarks = s.Remarks,
+                PlanQty = a.Daa008, // 宸ュ崟鏁伴噺
+                ItemModel = a.Daa004, // 瑙勬牸
+                ItemName = a.Daa003, // 浜у搧鍚嶇О
+                ItemId = a.Daa002 // 浜у搧鍚嶇О
+                // Fsubmit = s.Fsubmit // 鑻ラ渶瑕佽繑鍥� Fsubmit 瀛楁
+            })
+            .OrderBy(s => s.CreateDate, OrderByType.Desc)
+            .ToPageList(queryObj.PageIndex, queryObj.Limit);
+    }
+    /*
     public List<QsQaItemXj> getPage(XJPageResult queryObj)
     {
         var db = SqlSugarHelper.GetInstance();
@@ -156,7 +212,7 @@
                 FcheckBy = s.FcheckBy,
                 FcheckResu = s.FcheckResu,
                 Remarks = s.Remarks,
-              
+
                 PlanQty = a.Daa008,//宸ュ崟鏁伴噺
                 ItemModel = a.Daa004,//瑙勬牸
                 ItemName = a.Daa003,//浜у搧鍚嶇О
@@ -164,6 +220,7 @@
             }).OrderBy(s => s.CreateDate, OrderByType.Desc)
             .ToPageList(queryObj.PageIndex, queryObj.Limit);
     }
+    */
 
 
     public List<QsQaItemXj01> setJYItem(decimal itemId)
@@ -171,36 +228,37 @@
         var db = SqlSugarHelper.GetInstance();
 
         var count = db.Queryable<MesQa>().Where(s => s.QsType == "2"
-                                                     && s.ItemId == itemId && s.Fsubmit == 1).Count();
+            && s.ItemId == itemId && s.Fsubmit == 1).Count();
 
         if (count <= 0) return new List<QsQaItemXj01>();
 
         return db
             .Queryable<MesQualityStandard>()
             .Where(b => b.QsType == "2"
-                        && b.ItemId == itemId).Select(
-                b => new QsQaItemXj01
-                {
-                    ProjName = b.ProjName,
-                    ItemMod = b.ItemMod,
-                    InspectionMethod = b.InspectionMethod,
-                    UsingInstruments = b.UsingInstruments,
-                    LevelNum = SqlFunc.IsNull(
-                        SqlFunc.IsNull( Convert.ToDecimal(b.LevelNum) * Convert.ToDecimal(b.InspectionLevel) , 1),
-                        Convert.ToDecimal(b.InspectionLevel)),
-                    MaxValue = Convert.ToDecimal(b.MaxValue),
-                    StandardValue = Convert.ToDecimal(b.StandardValue),
-                    MinValue = Convert.ToDecimal(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.ItemId == itemId).Select(b => new QsQaItemXj01
+            {
+                ProjName = b.ProjName,
+                ItemMod = b.ItemMod,
+                InspectionMethod = b.InspectionMethod,
+                UsingInstruments = b.UsingInstruments,
+                LevelNum = SqlFunc.IsNull(
+                    SqlFunc.IsNull(
+                        Convert.ToDecimal(b.LevelNum) *
+                        Convert.ToDecimal(b.InspectionLevel), 1),
+                    Convert.ToDecimal(b.InspectionLevel)),
+                MaxValue = Convert.ToDecimal(b.MaxValue),
+                StandardValue = Convert.ToDecimal(b.StandardValue),
+                MinValue = Convert.ToDecimal(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)
@@ -301,6 +359,15 @@
     {
         var items = xjDto.items;
         var userNo = xjDto.userNo;
+        
+        var db = SqlSugarHelper.GetInstance();
+        db.Deleteable<QsQaItemXj01>()
+            .Where(s => s.Pid == xjDto.gid)
+            .ExecuteCommand();
+        
+        db.Deleteable<QsQaItemXj02>()
+            .Where(s => s.Gid == xjDto.gid)
+            .ExecuteCommand();
 
         SqlSugarHelper.UseTransactionWithOracle(db =>
         {
@@ -407,8 +474,8 @@
 
         if (count == passCount) result = 1;
 
-        var useTransactionWithOracle = SqlSugarHelper.UseTransactionWithOracle(
-            db =>
+        var useTransactionWithOracle =
+            SqlSugarHelper.UseTransactionWithOracle(db =>
             {
                 var commit = 0;
                 commit += db.Updateable<QsQaItemXj01>()
@@ -537,4 +604,67 @@
                 .ExecuteCommand();
         });
     }
+
+    public bool XJQaSubmit(QsItem item)
+    {
+        var (factory, company) = UserUtil.GetFactory(item.userNo);
+        try
+        {
+            // 瀹氫箟杈撳嚭鍙傛暟
+            var outputResult = new SugarParameter("o_Result", null,
+                DbType.Int32, ParameterDirection.Output,
+                4000);
+
+            var outputMessage = new SugarParameter("o_Msg", null, DbType.String,
+                ParameterDirection.Output, 4000);
+
+            // 瀹氫箟杈撳叆鍙傛暟
+            var parameters = new List<SugarParameter>
+            {
+                new("p_Id", item.gid, DbType.Int32, ParameterDirection.Input),
+                new("p_Flag", 1, DbType.Int32, ParameterDirection.Input),
+                new("p_User", item.userNo, DbType.String,
+                    ParameterDirection.Input),
+                outputResult,
+                outputMessage
+            };
+
+            var db = SqlSugarHelper.GetInstance();
+
+            // 浣跨敤 SqlSugar 鎵ц瀛樺偍杩囩▼
+            db.Ado.ExecuteCommand(
+                "BEGIN PRC_WOMDAA_XJ_UPDATE_RES(:p_Id,:p_Flag,:p_User,:o_Result, :o_Msg); END;",
+                parameters.ToArray());
+
+            // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+            var resultValue = outputResult.Value?.ToString();
+            var messageValue = outputMessage.Value?.ToString();
+
+            if ("1".Equals(resultValue)) throw new Exception(messageValue);
+            if ("0".Equals(resultValue)) throw new Exception(messageValue);
+
+            return true;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception(ex.Message);
+        }
+    }
+
+    public List<MesLine> getWorkshop()
+    {
+        var db = SqlSugarHelper.GetInstance();
+
+        return db.Queryable<Womdaa, MesLine>((a, b) =>
+                new JoinQueryInfos(JoinType.Left, a.Daa015 == b.LineNo))
+            .GroupBy((a, b) => new
+            {
+                a.Daa015, b.LineName
+            })
+            .Select((a, b) => new MesLine
+            {
+                LineNo = a.Daa015,
+                LineName = b.LineName
+            }).OrderBy("a.Daa015").ToList();
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3