From 3b3d2378bd52268dad426c70b853473eccee3b87 Mon Sep 17 00:00:00 2001
From: xwt <2740516069@qq.com>
Date: 星期一, 15 九月 2025 09:24:03 +0800
Subject: [PATCH] 首检穴模数

---
 StandardInterface/MES.Service/Modes/HoleNumberInfo.cs      |   32 ++++++++
 StandardInterface/MES.Service/Modes/QsItemIpiReq.cs        |   15 +++
 StandardInterface/MES.Service/Modes/QsItemIpiItemDetail.cs |    2 
 StandardInterface/MES.Service/Modes/QsItemIpiItem.cs       |   25 ++++++
 StandardInterface/MES.Service/service/QC/SJService.cs      |  115 ++++++++++++++++++++++++++++
 StandardInterface/MESApplication/appsettings.json          |    2 
 6 files changed, 187 insertions(+), 4 deletions(-)

diff --git a/StandardInterface/MES.Service/Modes/HoleNumberInfo.cs b/StandardInterface/MES.Service/Modes/HoleNumberInfo.cs
new file mode 100644
index 0000000..a681908
--- /dev/null
+++ b/StandardInterface/MES.Service/Modes/HoleNumberInfo.cs
@@ -0,0 +1,32 @@
+namespace MES.Service.Modes;
+
+/// <summary>
+/// 绌村彿淇℃伅
+/// </summary>
+public class HoleNumberInfo
+{
+    /// <summary>
+    /// 缂栧彿锛�1,2,3...锛�
+    /// </summary>
+    public int Index { get; set; }
+
+    /// <summary>
+    /// 绌村彿锛�1-8寰幆锛�
+    /// </summary>
+    public int HoleNumber { get; set; }
+
+    /// <summary>
+    /// 鏄惁琚牭浣�
+    /// </summary>
+    public bool IsBlocked { get; set; }
+
+    /// <summary>
+    /// 璁板綍鍊�
+    /// </summary>
+    public string? RecordValue { get; set; }
+
+    /// <summary>
+    /// 妫�楠岀粨鏋�
+    /// </summary>
+    public string? CheckResult { get; set; }
+}
diff --git a/StandardInterface/MES.Service/Modes/QsItemIpiItem.cs b/StandardInterface/MES.Service/Modes/QsItemIpiItem.cs
index b8c95f5..14193e6 100644
--- a/StandardInterface/MES.Service/Modes/QsItemIpiItem.cs
+++ b/StandardInterface/MES.Service/Modes/QsItemIpiItem.cs
@@ -118,6 +118,18 @@
     [Column("ITEM_ID")]
     [SugarColumn(ColumnName = "ITEM_ID")]
     public decimal? ItemId { get; set; }
+    /// <summary>
+    ///     绌存暟
+    /// </summary>
+    [Column("MNUM")]
+    [SugarColumn(ColumnName = "MNUM")]
+    public decimal? Mnum { get; set; }
+    /// <summary>
+    ///     鍫电┐鍙�
+    /// </summary>
+    [Column("DNUM")]
+    [SugarColumn(ColumnName = "DNUM")]
+    public string? Dnum { get; set; }
 
     /// <summary>
     ///     鏍囧噯鍊�
@@ -168,6 +180,19 @@
     [StringLength(200, ErrorMessage = "澶囨敞涓嶈兘瓒呭嚭200")]
     public string? Remarks { get; set; }
 
+    /// <summary>
+    ///     閫佹鎵规暟
+    /// </summary>
+    [Column("SNUM")]
+    [SugarColumn(ColumnName = "SNUM")]
+    public decimal? Snum { get; set; }
+
+    /// <summary>
+    ///     绌村彿淇℃伅锛堢敤浜庡墠绔樉绀猴級
+    /// </summary>
+    [SugarColumn(IsIgnore = true)]
+    public List<HoleNumberInfo>? HoleNumbers { get; set; }
+
     [SugarColumn(IsIgnore = true)] public string? result { get; set; }
     [SugarColumn(IsIgnore = true)] public string? imageData { get; set; }
 }
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/Modes/QsItemIpiItemDetail.cs b/StandardInterface/MES.Service/Modes/QsItemIpiItemDetail.cs
index 0d1c504..63bff91 100644
--- a/StandardInterface/MES.Service/Modes/QsItemIpiItemDetail.cs
+++ b/StandardInterface/MES.Service/Modes/QsItemIpiItemDetail.cs
@@ -88,4 +88,6 @@
     [SugarColumn(IsIgnore = true)] public decimal? IsPass { get; set; }
 
     [SugarColumn(IsIgnore = true)] public int? count { get; set; }
+    
+    [SugarColumn(IsIgnore = true)] public int? startIndex { get; set; }
 }
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/Modes/QsItemIpiReq.cs b/StandardInterface/MES.Service/Modes/QsItemIpiReq.cs
index 4e21245..86b6d58 100644
--- a/StandardInterface/MES.Service/Modes/QsItemIpiReq.cs
+++ b/StandardInterface/MES.Service/Modes/QsItemIpiReq.cs
@@ -155,4 +155,19 @@
     [SugarColumn(ColumnName = "SJ_MJ")]
     [StringLength(10, ErrorMessage = "妫�楠岀被鍨嬮暱搴︿笉鑳借秴鍑�10")]
     public string? SJ_MJ { get; set; }
+
+    /// <summary>
+    ///     绌存暟
+    /// </summary>
+    [Column("MNUM")]
+    [SugarColumn(ColumnName = "MNUM")]
+    public decimal? Mnum { get; set; }
+
+    /// <summary>
+    ///     鍫电┐鍙�
+    /// </summary>
+    [Column("DNUM")]
+    [SugarColumn(ColumnName = "DNUM")]
+    [StringLength(100, ErrorMessage = "鍫电┐鍙烽暱搴︿笉鑳借秴鍑�100")]
+    public string? Dnum { get; set; }
 }
\ No newline at end of file
diff --git a/StandardInterface/MES.Service/service/QC/SJService.cs b/StandardInterface/MES.Service/service/QC/SJService.cs
index dcc7beb..e53d43e 100644
--- a/StandardInterface/MES.Service/service/QC/SJService.cs
+++ b/StandardInterface/MES.Service/service/QC/SJService.cs
@@ -178,10 +178,38 @@
     public List<QsItemIpiItem> getQSItems(decimal? pid, decimal? id)
     {
         var db = SqlSugarHelper.GetInstance();
+        
+        // 浣跨敤JOIN鏌ヨ鑾峰彇瀛愯〃鏁版嵁鍜屼富琛ㄧ殑MNUM銆丏NUM瀛楁
         var qsItemIpiItems = db
-            .Queryable<QsItemIpiItem>()
-            .WhereIF(pid > 0, a => a.Pid == pid)
-            .WhereIF(id > 0, a => a.Id == id).ToList();
+            .Queryable<QsItemIpiItem, QsItemIpiReq>((a, b) => new JoinQueryInfos(JoinType.Left, a.Pid == b.Id))
+            .WhereIF(pid > 0, (a, b) => a.Pid == pid)
+            .WhereIF(id > 0, (a, b) => a.Id == id)
+            .Select((a, b) => new QsItemIpiItem
+            {
+                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,
+                ItemId = a.ItemId,
+                Mnum = b.Mnum,  // 浠庝富琛ㄨ幏鍙朚NUM
+                Dnum = b.Dnum,  // 浠庝富琛ㄨ幏鍙朌NUM
+                Snum = a.Snum,  // 閫佹鎵规暟
+                Remarks = a.Remarks
+            }).ToList();
 
         var array = qsItemIpiItems.Select(s => s.Id).ToArray();
         var qsItemIpiItemDetails = db.Queryable<QsItemIpiItemDetail>()
@@ -227,6 +255,16 @@
 
         //鎺掑簭锛屾湭瀹屾垚鐨勬帓鍦ㄥ墠闈�
         qsItemIpiItems = qsItemIpiItems.OrderBy(s => s.isCheck).ToList();
+
+        // 涓烘瘡涓楠岄」鐩敓鎴愮┐鍙蜂俊鎭�
+        qsItemIpiItems.ForEach(item =>
+        {
+            if (item.Mnum > 0 && item.Snum > 0)
+            {
+                // 浣跨敤SNUM浣滀负閫佹鎵规暟鏉ヨ绠楁�荤紪鍙锋暟閲�
+                item.HoleNumbers = GenerateHoleNumbers(item.Mnum, item.Dnum, item.Snum);
+            }
+        });
 
         return qsItemIpiItems;
     }
@@ -313,6 +351,10 @@
         var oracle = SqlSugarHelper.UseTransactionWithOracle(db =>
         {
             List<QsItemIpiItemDetail> result = new();
+            
+            // 鑾峰彇璧峰绱㈠紩锛屽鏋滄病鏈夋寚瀹氬垯浠�0寮�濮�
+            int startIndex = detail.startIndex ?? 0;
+            
             for (var i = 0; i < detail.count; i++)
             {
                 var item = new QsItemIpiItemDetail();
@@ -322,6 +364,9 @@
                 item.FcheckResu = detail.FcheckResu;
                 item.CreateBy = detail.UpdateBy;
                 item.CreateDate = DateTime.Now;
+                
+                // 濡傛灉鏈夎捣濮嬬储寮曪紝鍙互鍦ㄨ繖閲岃缃浉鍏崇殑绱㈠紩淇℃伅
+                // 娉ㄦ剰锛氳繖閲屽彧鏄ず渚嬶紝瀹為檯鍙兘闇�瑕佹牴鎹笟鍔¢渶姹傝皟鏁�
                 result.Add(item);
             }
 
@@ -571,4 +616,68 @@
             throw new Exception(ex.Message);
         }
     }
+
+    /// <summary>
+    /// 鐢熸垚绌村彿淇℃伅
+    /// </summary>
+    /// <param name="mnum">寮�绌存�绘暟</param>
+    /// <param name="dnum">鍫电┐鍙凤紙閫楀彿鍒嗛殧锛�</param>
+    /// <param name="snum">閫佹鎵规暟</param>
+    /// <returns>绌村彿淇℃伅鍒楄〃</returns>
+    private List<HoleNumberInfo> GenerateHoleNumbers(decimal? mnum, string? dnum, decimal? snum)
+    {
+        var result = new List<HoleNumberInfo>();
+        
+        if (mnum == null || mnum <= 0 || snum == null || snum <= 0)
+            return result;
+
+        // 瑙f瀽鍫电┐鍙�
+        var blockedHoles = new HashSet<int>();
+        if (!string.IsNullOrEmpty(dnum))
+        {
+            var holeNumbers = dnum.Split(',', StringSplitOptions.RemoveEmptyEntries);
+            foreach (var holeStr in holeNumbers)
+            {
+                if (int.TryParse(holeStr.Trim(), out int holeNum))
+                {
+                    blockedHoles.Add(holeNum);
+                }
+            }
+        }
+
+        int totalHoles = (int)mnum.Value;
+        int batchCount = (int)snum.Value; // 閫佹鎵规暟
+        
+        // 璁$畻鎬荤紪鍙锋暟閲忥細寮�绌存�绘暟 脳 閫佹鎵规暟
+        int totalIndexes = totalHoles * batchCount;
+        
+        for (int i = 1; i <= totalIndexes; i++)
+        {
+            // 绌村彿寰幆锛�1-8, 1-8...
+            int holeNumber = ((i - 1) % totalHoles) + 1;
+            bool isBlocked = blockedHoles.Contains(holeNumber);
+            
+            result.Add(new HoleNumberInfo
+            {
+                Index = i,
+                HoleNumber = holeNumber,
+                IsBlocked = isBlocked,
+                RecordValue = isBlocked ? "/" : null,
+                CheckResult = isBlocked ? "/" : null
+            });
+        }
+
+        // 鎺掑簭锛氬牭绌存帓鏈�鍚庝紭鍏堢骇绗竴锛岀劧鍚庣┐鍙蜂粠灏忓埌澶ф帓锛岀┐鍙风浉鍚岀殑鎺掍竴璧�
+        result = result.OrderBy(x => x.IsBlocked)            // 鍫电┐鎺掓渶鍚庯紙false鍦ㄥ墠锛宼rue鍦ㄥ悗锛�
+                      .ThenBy(x => x.HoleNumber)             // 绌村彿浠庡皬鍒板ぇ
+                      .ToList();
+
+        // 閲嶆柊璁剧疆Index锛屼繚鎸佽繛缁紪鍙�
+        for (int i = 0; i < result.Count; i++)
+        {
+            result[i].Index = i + 1;
+        }
+
+        return result;
+    }
 }
\ No newline at end of file
diff --git a/StandardInterface/MESApplication/appsettings.json b/StandardInterface/MESApplication/appsettings.json
index 28cfc2a..59a3601 100644
--- a/StandardInterface/MESApplication/appsettings.json
+++ b/StandardInterface/MESApplication/appsettings.json
@@ -10,6 +10,6 @@
   "AppSettings": {
     "TestErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfo",
     "ProductionErpUrl": "http://192.168.11.120:8098/WebService1.asmx/mesToErpinfoFormal",
-    "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = hm_prd; Password=hmprd"
+    "DataBaseConn": "Data Source = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))(CONNECT_DATA = (SERVICE_NAME = ORCL))); Persist Security Info=True;User ID = test_dev; Password=hmprd"
   }
 }

--
Gitblit v1.9.3