Ver código fonte

1、优化床垫清单审核速度
2、修复床网保存,因公式缺少导致报错问题

MY 1 mês atrás
pai
commit
c9fd88935f

+ 1 - 2
JLHHJSvr/Excutor/MattressJS2AuditExcutor.cs

@@ -45,8 +45,7 @@ namespace JLHHJSvr.Excutor
                     }
                 }
 
-                var mattressHelper = HelperBase.GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
-
+                var mattressHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
                 using (cmd.Transaction = con.BeginTransaction())
                 {
                     try

+ 2 - 1
JLHHJSvr/Excutor/MattressJSAuditExcutor.cs

@@ -7,6 +7,7 @@ using JLHHJSvr.Com.Model;
 using JLHHJSvr.Helper;
 using JLHHJSvr.LJException;
 using LJLib.DAL.SQL;
+using LJLib.Net.SPI.Com;
 using LJLib.Net.SPI.Server;
 using LJLib.SQLEX;
 
@@ -45,7 +46,7 @@ namespace JLHHJSvr.Excutor
                     }
                 }
 
-                var mattressHelper = HelperBase.GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
+                var mattressHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
 
                 using (cmd.Transaction = con.BeginTransaction())
                 {

+ 2 - 1
JLHHJSvr/Helper/BedNetHelper.cs

@@ -1991,7 +1991,8 @@ namespace JLHHJSvr.Helper
             {
                 cmd.CommandText = $@"{expression}";
                 cmd.Parameters.Clear();
-                return cmd.ExecuteScalar();
+                var result = cmd.ExecuteScalar();
+                return result != null && result != DBNull.Value ? result : 0;
             }
             catch (Exception ex)
             {

+ 114 - 0
JLHHJSvr/Helper/InterfaceHelper.cs

@@ -65,6 +65,120 @@ namespace JLHHJSvr.Helper
 
             AutoUpdateBcp(mattress.mattressid);
         }
+
+        #region 清单审核
+        /// <summary>
+        /// 产品补充审核
+        /// </summary>
+        /// <param name="mattressid"></param>
+        /// <exception cref="LJCommonException"></exception>
+        public void MattressJSAudit(int mattressid)
+        {
+            // 检查锁
+            if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
+
+            var mattress = new u_mattress() { mattressid = mattressid };
+            DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,version");
+
+            if (mattress.js1_flag == 1)
+            {
+                throw new LJCommonException("床垫已技术1审核,不能技术1审核!");
+            }
+
+            //if (mattress.yw_flag == 0)
+            //{
+            //    throw new LJCommonException("床垫未业务审核,不能技术1审核!");
+            //}
+
+            mattress.js1_flag = 1;
+            mattress.js1_auditingdate = context.opdate;
+            mattress.js1_auditingrep = context.tokendata.username;
+            mattress.version++;
+
+            DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
+        }
+        /// <summary>
+        /// 产品补充撤审
+        /// </summary>
+        /// <param name="mattressid"></param>
+        /// <exception cref="LJCommonException"></exception>
+        public void MattressJSCancelAudit(int mattressid)
+        {
+            // 检查锁
+            if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
+
+            var mattress = new u_mattress() { mattressid = mattressid };
+            DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,creatmtrl_flag");
+
+            //if (mattress.creatmtrl_flag == 1)
+            //{
+            //    throw new LJCommonException("床垫已生成产品,不能技术1撤审!");
+            //}
+
+            if (mattress.js1_flag == 0)
+            {
+                throw new LJCommonException("床垫未技术1撤审,不能技术1撤审!");
+            }
+
+            mattress.js1_flag = 0;
+            mattress.js1_auditingdate = null;
+            mattress.js1_auditingrep = string.Empty;
+            mattress.version++;
+
+            DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
+        }
+        /// <summary>
+        /// 清单补充审核
+        /// </summary>
+        /// <param name="mattressid"></param>
+        /// <exception cref="LJCommonException"></exception>
+        public void MattressJS2Audit(int mattressid)
+        {
+            // 检查锁
+            if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
+
+            var mattress = new u_mattress() { mattressid = mattressid };
+            DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
+
+            if (mattress.js2_flag == 1)
+            {
+                throw new LJCommonException("床垫已技术2审核,不能技术2审核!");
+            }
+
+            mattress.js2_flag = 1;
+            mattress.js2_auditingdate = context.opdate;
+            mattress.js2_auditingrep = context.tokendata.username;
+            mattress.version++;
+
+            DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
+        }
+        /// <summary>
+        /// 清单补充撤审
+        /// </summary>
+        /// <param name="mattressid"></param>
+        /// <exception cref="LJCommonException"></exception>
+        public void MattressJS2CancelAudit(int mattressid)
+        {
+            // 检查锁
+            if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
+
+            var mattress = new u_mattress() { mattressid = mattressid };
+            DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
+
+            if (mattress.js2_flag == 0)
+            {
+                throw new LJCommonException("床垫未技术2审核,不能技术2撤审!");
+            }
+
+            mattress.js2_flag = 0;
+            mattress.js2_auditingdate = null;
+            mattress.js2_auditingrep = string.Empty;
+            mattress.version++;
+
+            DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
+        }
+        #endregion
+
         #region 保存半成品部件
         public void SaveMattressBcp(u_semi_finished_product mattress)
         {

+ 105 - 0
JLHHJSvr/Helper/LockHelper.cs

@@ -68,6 +68,7 @@ namespace JLHHJSvr.Helper
                         //if (arg_rslt != 1) throw new LJCommonException(arg_msg);
                     }
                 }
+                RebuildBillRelation(cmd, keyword, billid);
             }
             finally
             {
@@ -103,6 +104,7 @@ namespace JLHHJSvr.Helper
                         //if (arg_rslt != 1) throw new LJCommonException(arg_msg);
                     }
                 }
+                DeleteBillRelation(cmd, keyword, billid);
             }
             finally
             {
@@ -152,6 +154,7 @@ namespace JLHHJSvr.Helper
         /// <returns></returns>
         public static bool CheckIsLock(SqlCommand cmd, string keyword, int billid, string opemp,out string arg_msg)
         {
+            return CheckIsLockPro(cmd,keyword, billid, opemp, out arg_msg);
             arg_msg = string.Empty;
             //return false;
             var item = CheckLockAll(cmd, keyword, billid, opemp);
@@ -241,5 +244,107 @@ namespace JLHHJSvr.Helper
             return dependencies;
         }
         #endregion
+
+        #region FAST
+        /// <summary>
+        /// 重建单据依赖关系(递归方式)
+        /// </summary>
+        public static void RebuildBillRelation(SqlCommand cmd,string keyword,int billid)
+        {
+            // 递归构建关系
+            var visited = new HashSet<string>();
+            BuildRelationRecursive(cmd, keyword, billid, visited, keyword, billid);
+        }
+
+        private static void DeleteBillRelation(SqlCommand cmd, string keyword, int billid)
+        {
+            cmd.CommandText = @"
+        DELETE FROM u_bill_relation
+        WHERE src_keyword = @keyword
+          AND src_billid  = @billid";
+            cmd.CommandType = CommandType.Text;
+            cmd.Parameters.Clear();
+            cmd.Parameters.AddWithValue("@keyword", keyword);
+            cmd.Parameters.AddWithValue("@billid", billid);
+            cmd.ExecuteNonQuery();
+        }
+
+        private static void BuildRelationRecursive(SqlCommand cmd,string curKeyword,int curBillid,HashSet<string> visited,string rootKeyword,int rootBillid)
+        {
+            var key = $"{curKeyword}:{curBillid}";
+            if (!visited.Add(key)) return; // 防止循环爆栈
+
+            var deps = BuildDependencies(cmd, curKeyword, curBillid);
+            foreach (var dep in deps)
+            {
+                // 1. 写入关系表
+                InsertRelation(cmd,rootKeyword,rootBillid,dep.keyword,dep.billid);
+                // 2. 继续递归
+                BuildRelationRecursive(cmd,dep.keyword,dep.billid,visited,rootKeyword,rootBillid);
+            }
+        }
+
+        private static void InsertRelation(SqlCommand cmd,string srcKeyword,int srcBillid,string dstKeyword,int dstBillid)
+        {
+            cmd.CommandText = @"
+        IF NOT EXISTS (
+            SELECT 1 FROM u_bill_relation 
+            WHERE src_keyword=@src_keyword
+              AND src_billid=@src_billid
+              AND dst_keyword=@dst_keyword
+              AND dst_billid=@dst_billid
+        )
+        INSERT INTO u_bill_relation
+        (src_keyword, src_billid, dst_keyword, dst_billid)
+        VALUES
+        (@src_keyword, @src_billid, @dst_keyword, @dst_billid);";
+            cmd.Parameters.Clear();
+            cmd.CommandType = CommandType.Text;
+            cmd.Parameters.AddWithValue("@src_keyword", srcKeyword);
+            cmd.Parameters.AddWithValue("@src_billid", srcBillid);
+            cmd.Parameters.AddWithValue("@dst_keyword", dstKeyword);
+            cmd.Parameters.AddWithValue("@dst_billid", dstBillid);
+            cmd.ExecuteNonQuery();
+        }
+
+        public static bool CheckIsLockPro(SqlCommand cmd,string keyword,int billid,string opemp,out string msg)
+        {
+            msg = "";
+            cmd.CommandText = @"SELECT TOP 1 keyword
+	                                ,billid
+	                                ,billcode
+	                                ,opemp
+                                FROM u_lock_table
+                                WHERE is_locked = 1
+	                                AND opemp <> @opemp
+	                                AND (
+		                                (
+			                                keyword = @keyword
+			                                AND billid = @billid
+			                                )
+		                                OR EXISTS (
+			                                SELECT 1
+			                                FROM u_bill_relation
+			                                WHERE src_keyword = @keyword
+				                                AND src_billid = @billid
+				                                AND dst_keyword = u_lock_table.keyword
+				                                AND dst_billid = u_lock_table.billid
+			                                )
+		                                )";
+            cmd.Parameters.Clear();
+            cmd.Parameters.AddWithValue("@keyword", keyword);
+            cmd.Parameters.AddWithValue("@billid", billid);
+            cmd.Parameters.AddWithValue("@opemp", opemp);
+            using (var reader = cmd.ExecuteReader())
+            {
+                if (reader.Read())
+                {
+                    msg = $"单据被用户【{reader["opemp"]}】编辑中";
+                    return true;
+                }
+            }
+            return false;
+        }
+        #endregion
     }
 }

+ 1 - 112
JLHHJSvr/Helper/MattressHelper.cs

@@ -2509,117 +2509,6 @@ namespace JLHHJSvr.Helper
 
             DbSqlHelper.Update(cmd, mattress, "yw_flag,yw_auditingdate,yw_auditingrep,version");
         }
-        /// <summary>
-        /// 产品补充审核
-        /// </summary>
-        /// <param name="mattressid"></param>
-        /// <exception cref="LJCommonException"></exception>
-        public void MattressJSAudit(int mattressid)
-        {
-            // 检查锁
-            if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
-
-            var mattress = new u_mattress() { mattressid = mattressid };
-            DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,version");
-
-            if (mattress.js1_flag == 1)
-            {
-                throw new LJCommonException("床垫已技术1审核,不能技术1审核!");
-            }
-
-            //if (mattress.yw_flag == 0)
-            //{
-            //    throw new LJCommonException("床垫未业务审核,不能技术1审核!");
-            //}
-
-            mattress.js1_flag = 1;
-            mattress.js1_auditingdate = context.opdate;
-            mattress.js1_auditingrep = context.tokendata.username;
-            mattress.version++;
-
-            DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
-
-        }
-        /// <summary>
-        /// 产品补充撤审
-        /// </summary>
-        /// <param name="mattressid"></param>
-        /// <exception cref="LJCommonException"></exception>
-        public void MattressJSCancelAudit(int mattressid)
-        {
-            // 检查锁
-            if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
-
-            var mattress = new u_mattress() { mattressid = mattressid };
-            DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,creatmtrl_flag");
-
-            //if (mattress.creatmtrl_flag == 1)
-            //{
-            //    throw new LJCommonException("床垫已生成产品,不能技术1撤审!");
-            //}
-
-            if (mattress.js1_flag == 0)
-            {
-                throw new LJCommonException("床垫未技术1撤审,不能技术1撤审!");
-            }
-
-            mattress.js1_flag = 0;
-            mattress.js1_auditingdate = null;
-            mattress.js1_auditingrep = string.Empty;
-            mattress.version++;
-
-            DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
-        }
-        /// <summary>
-        /// 清单补充审核
-        /// </summary>
-        /// <param name="mattressid"></param>
-        /// <exception cref="LJCommonException"></exception>
-        public void MattressJS2Audit(int mattressid)
-        {
-            // 检查锁
-            if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
-
-            var mattress = new u_mattress() { mattressid = mattressid };
-            DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
-
-            if (mattress.js2_flag == 1)
-            {
-                throw new LJCommonException("床垫已技术2审核,不能技术2审核!");
-            }
-
-            mattress.js2_flag = 1;
-            mattress.js2_auditingdate = context.opdate;
-            mattress.js2_auditingrep = context.tokendata.username;
-            mattress.version++;
-
-            DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
-        }
-        /// <summary>
-        /// 清单补充撤审
-        /// </summary>
-        /// <param name="mattressid"></param>
-        /// <exception cref="LJCommonException"></exception>
-        public void MattressJS2CancelAudit(int mattressid)
-        {
-            // 检查锁
-            if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
-
-            var mattress = new u_mattress() { mattressid = mattressid };
-            DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
-
-            if (mattress.js2_flag == 0)
-            {
-                throw new LJCommonException("床垫未技术2审核,不能技术2撤审!");
-            }
-
-            mattress.js2_flag = 0;
-            mattress.js2_auditingdate = null;
-            mattress.js2_auditingrep = string.Empty;
-            mattress.version++;
-
-            DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
-        }
         #endregion
 
 
@@ -2771,7 +2660,7 @@ namespace JLHHJSvr.Helper
             // 处理子规格
             ProcessSubSpecs(mattress, ifErp);
             // 解锁
-            if(!ignoreLock) LockHelper.UnLockBill(cmd, BillKeyWord, mattress.mattressid, context.tokendata.username, 0);
+            if (!ignoreLock) LockHelper.UnLockBill(cmd, BillKeyWord, mattress.mattressid, context.tokendata.username, 0);
         }
         /// <summary>
         /// 初始化子规格