From 6f89acbf74c6838db518a9f2b6c83f0ab0d97e7f Mon Sep 17 00:00:00 2001
From: 杨张扬 <634643841@qq.com>
Date: 星期二, 29 七月 2025 18:13:31 +0800
Subject: [PATCH] 余料回库流程增加绑定和解绑,RFID校验必须校验开头

---
 device/TcpServer.cs    |   11 ++
 models/TN_CG_Detail.cs |   10 ++
 api/ApiHelper.cs       |  156 +++++++++++++++++++++++++++++++++++++++
 api/ApiModel.cs        |   18 ++++
 api/MoboxController.cs |   24 ++++++
 5 files changed, 216 insertions(+), 3 deletions(-)

diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs
index b12c74c..ba574df 100644
--- a/api/ApiHelper.cs
+++ b/api/ApiHelper.cs
@@ -326,6 +326,162 @@
         }
 
         /// <summary>
+        /// 浣欐枡瑙g粦鍑哄簱
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        internal static SimpleResult SurplusUnBind(SurplusUnBindInfo model)
+        {
+            LogHelper.Info("瑙﹀彂API锛氫綑鏂欑粦瀹氬叆搴� + JsonConvert.SerializeObject(model), "API");
+            var result = new SimpleResult();//杩斿洖缁撴灉
+            try
+            {
+                if (string.IsNullOrWhiteSpace(model.spec))
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"瑙勬牸鍙傛暟涓嶈兘涓虹┖锛屼篃涓嶈兘涓虹┖瀛楃涓�;
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                if (string.IsNullOrWhiteSpace(model.loc))
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"璐т綅鍙傛暟涓嶈兘涓虹┖锛屼篃涓嶈兘涓虹┖瀛楃涓�;
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                if (model.weight <= 0)
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"閲嶉噺鍙傛暟蹇呴』澶т簬0";
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                var db = new SqlHelper<object>().GetInstance();
+
+                
+                var cgDetail = db.Queryable<TN_CG_Detail>()
+                    .First(a => a.S_LOC_CODE == model.loc
+                    && a.S_USE_TYPE == "浣欐枡" 
+                    &&(a.S_ITEM_SPEC == model.spec || a.S_SPE == model.spec)
+                    && a.F_QTY == model.weight);
+                
+                if (cgDetail == null)
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"搴撲綅{model.loc}瀵瑰簲鐨勭墿鏂欐槑缁嗕笉瀛樺湪锛屾棤闇�嚭搴�;
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                using (var trans = db.Ado.UseTran())
+                {
+                    if (db.Deleteable<TN_CG_Detail>(cgDetail).ExecuteCommand() > 0 )
+                    {
+                        trans.CommitTran();
+                        result.resultCode = 0;
+                        result.resultMsg = $"鍑哄簱鎴愬姛锛岃揣浣嶏細{model.loc}锛岃В缁戠殑璐у搧涓猴細{JsonConvert.SerializeObject(cgDetail)}";
+                        LogHelper.Info(result.resultMsg);
+                        return result;
+                    }
+                    else
+                    {
+                        trans.RollbackTran();
+                        result.resultCode = -1;
+                        result.resultMsg = $"鍑哄簱澶辫触锛岃揣浣嶏細{model.loc}";
+                        LogHelper.Info(result.resultMsg);
+                        return result;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                result.resultCode = -1;
+                result.resultMsg = $"PDA婊℃墭澶嶆鍒ゆ柇锛屽彂鐢熶簡寮傚父锛歿ex.Message}";
+                LogHelper.Info(result.resultMsg);
+                return result;
+            }
+        }
+
+        /// <summary>
+        /// 浣欐枡缁戝畾鍏ュ簱
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        internal static SimpleResult SurplusBind(SurplusBindInfo model)
+        {
+            LogHelper.Info("瑙﹀彂API锛氫綑鏂欑粦瀹氬叆搴� + JsonConvert.SerializeObject(model), "API");
+            var result = new SimpleResult();//杩斿洖缁撴灉
+            try
+            {
+                if (string.IsNullOrWhiteSpace(model.spec))
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"瑙勬牸鍙傛暟涓嶈兘涓虹┖锛屼篃涓嶈兘涓虹┖瀛楃涓�;
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                if (string.IsNullOrWhiteSpace(model.loc))
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"璐т綅鍙傛暟涓嶈兘涓虹┖锛屼篃涓嶈兘涓虹┖瀛楃涓�;
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                if (model.weight <= 0)
+                {
+                    result.resultCode = -1;
+                    result.resultMsg = $"閲嶉噺鍙傛暟蹇呴』澶т簬0";
+                    LogHelper.Info(result.resultMsg);
+                    return result;
+                }
+
+                var db = new SqlHelper<object>().GetInstance();
+
+                var cgDetail = new TN_CG_Detail()
+                {
+                    S_ITEM_SPEC = model.spec,
+                    S_SPE = model.spec,
+                    F_QTY = model.weight,
+                    S_LOC_CODE = model.loc,
+                    S_USE_TYPE = "浣欐枡",
+                };
+
+                using (var trans = db.Ado.UseTran())
+                {
+                    if (db.Insertable<TN_CG_Detail>(cgDetail).ExecuteCommand() > 0 )
+                    {
+                        trans.CommitTran();
+                        result.resultCode = 0;
+                        result.resultMsg = $"鍏ュ簱鎴愬姛锛岃揣浣嶏細{model.loc}锛屽凡缁戝畾璐у搧锛寋JsonConvert.SerializeObject(cgDetail)}";
+                        LogHelper.Info(result.resultMsg);
+                        return result;
+                    }
+                    else
+                    {
+                        trans.RollbackTran();
+                        result.resultCode = -1;
+                        result.resultMsg = $"鍏ュ簱澶辫触锛岃揣浣嶏細{model.loc}";
+                        LogHelper.Info(result.resultMsg);
+                        return result;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                result.resultCode = -1;
+                result.resultMsg = $"PDA婊℃墭澶嶆鍒ゆ柇锛屽彂鐢熶簡寮傚父锛歿ex.Message}";
+                LogHelper.Info(result.resultMsg);
+                return result;
+            }
+        }
+
+        /// <summary>
         /// 绾胯竟绌烘墭鍒扮┖鎵樺爢鍙犲尯
         /// </summary>
         /// <param name="model"></param>
diff --git a/api/ApiModel.cs b/api/ApiModel.cs
index 94dd817..5b3e50f 100644
--- a/api/ApiModel.cs
+++ b/api/ApiModel.cs
@@ -487,5 +487,23 @@
             public int cntCount { get; set; }//瀹瑰櫒鏁伴噺
             public string staff { get; set; } = "None";//鎿嶄綔浜�         }
+
+        public class SurplusBindInfo
+        {
+            public string loc { get; set; }//璐т綅鐐�+
+            public string spec { get; set; }//瑙勬牸
+
+            public float weight { get; set; }//閲嶉噺
+        }
+
+        public class SurplusUnBindInfo
+        {
+            public string loc { get; set; }//璐т綅鐐�+
+            public string spec { get; set; }//瑙勬牸
+
+            public float weight { get; set; }//閲嶉噺
+        }
     }
 }
diff --git a/api/MoboxController.cs b/api/MoboxController.cs
index ead375f..17ab6a9 100644
--- a/api/MoboxController.cs
+++ b/api/MoboxController.cs
@@ -237,5 +237,29 @@
         {
             return ApiHelper.EmptyLineToEmptyMax(model);
         }
+
+        /// <summary>
+        /// 浣欐枡缁戝畾鍏ュ簱
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("SurplusBind")]
+        public SimpleResult SurplusBind(SurplusBindInfo model)
+        {
+            return ApiHelper.SurplusBind(model);
+        }
+
+        /// <summary>
+        /// 浣欐枡瑙g粦鍑哄簱
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("SurplusUnBind")]
+        public SimpleResult SurplusUnBind(SurplusUnBindInfo model)
+        {
+            return ApiHelper.SurplusUnBind(model);
+        }
     }
 }
diff --git a/device/TcpServer.cs b/device/TcpServer.cs
index 1b17450..d6537f0 100644
--- a/device/TcpServer.cs
+++ b/device/TcpServer.cs
@@ -147,13 +147,18 @@
                             saoMa[remote_ip] = 3;//鏈壂鍒扮爜
                         }
 
-                        if (messageBytes.Length >= 21 && isCheck[remote_ip])
+                        if (messageBytes.Length >= 21 
+                            && isCheck[remote_ip] 
+                            && messageBytes[0] == 0xCC 
+                            && messageBytes[1] == 0xFF 
+                            && messageBytes[2] == 0xFF)
                         {
                             byte[] rfid = new byte[12];
                             Array.Copy(messageBytes, 9, rfid, 0, 12);
 
-                            string rfids16 = BitConverter.ToString(rfid);
-                            string rfids = Encoding.ASCII.GetString(rfid);
+                            string rfids16 = BitConverter.ToString(messageBytes);
+                            string rfids = Encoding.ASCII.GetString(rfid);//鎴彇瀛楃涓�+                            
                             LogHelper.Info($"璇诲崱鍣ㄦ牎楠屽搴斿鍣ㄥ彿锛歿rfids}锛屽叾16杩涘埗褰㈠紡锛歿rfids16}");
                             if (ScanCodeHelper.Analysis(remote_ip, rfids))//鏍¢獙RFID
                             {
diff --git a/models/TN_CG_Detail.cs b/models/TN_CG_Detail.cs
index d653164..a506064 100644
--- a/models/TN_CG_Detail.cs
+++ b/models/TN_CG_Detail.cs
@@ -43,5 +43,15 @@
         /// 拆盘时的唯一键,用于追踪被拆的物料
         /// </summary>
         public string S_Separate_ID { get; set; }
+
+        /// <summary>
+        /// 对应货位
+        /// </summary>
+        public string S_LOC_CODE { get; set; }
+
+        /// <summary>
+        /// 货品的使用状态,余料
+        /// </summary>
+        public string S_USE_TYPE { get; set; }
     }
 }

--
Gitblit v1.9.1