Prechádzať zdrojové kódy

1、新增删除缓存
2、床垫清单,生成配置严格按照报价明细顺序
3、床垫清单,刷新配置和刷新清单新增请求日志
4、保存物料和保存部门新增删除旧资料缓存

MY 1 mesiac pred
rodič
commit
aa2a0508b4

+ 1 - 5
JLHHJSvr/Com/RefreshMattressInterface.cs

@@ -7,17 +7,13 @@ using LJLib.Net.SPI.Com;
 
 namespace JLHHJSvr.Com
 {
-    public sealed class RefreshMattressInterfaceRequest : ILJRequest<RefreshMattressInterfaceResponse>
+    public sealed class RefreshMattressInterfaceRequest : ILJTokenRequest<RefreshMattressInterfaceResponse>
     {
         public override string GetApiName()
         {
             return "RefreshMattressInterface";
         }
         /// <summary>
-        /// 登录token
-        /// </summary>
-        public string token { get; set; }
-        /// <summary>
         /// 单据id
         /// </summary>
         public int? mattressid { get; set; }

+ 1 - 5
JLHHJSvr/Com/RefreshMattressInterfaceQd.cs

@@ -7,17 +7,13 @@ using LJLib.Net.SPI.Com;
 
 namespace JLHHJSvr.Com
 {
-    public sealed class RefreshMattressInterfaceQdRequest : ILJRequest<RefreshMattressInterfaceQdResponse>
+    public sealed class RefreshMattressInterfaceQdRequest : ILJTokenRequest<RefreshMattressInterfaceQdResponse>
     {
         public override string GetApiName()
         {
             return "RefreshMattressInterfaceQd";
         }
         /// <summary>
-        /// 登录token
-        /// </summary>
-        public string token { get; set; }
-        /// <summary>
         /// 单据id
         /// </summary>
         public int? mattressid { get; set; }

+ 4 - 29
JLHHJSvr/Excutor/SaveDeptExcutor.cs

@@ -5,6 +5,7 @@ using System.Linq;
 using System.Text;
 using JLHHJSvr.BLL;
 using JLHHJSvr.Com;
+using JLHHJSvr.Helper;
 using JLHHJSvr.LJException;
 using JLHHJSvr.Tools;
 using LJLib.DAL.SQL;
@@ -49,41 +50,15 @@ namespace JLHHJSvr.Excutor
                 // 初始化属性
                 AutoInit.AutoInitS(cmd, request.dept);
 
+                var helper = HelperBase.GetHelper<BasicInfoHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
+
                 using (cmd.Transaction = con.BeginTransaction())
                 {
                     try
                     {
                         var dtNow = DateTime.Now;
 
-                        if (request.dept.deptid == null || request.dept.deptid <= 0)
-                        {
-
-                            cmd.CommandText = @"SELECT COUNT(deptname) AS cnt FROM u_dept WHERE deptname = @deptname";
-                            cmd.Parameters.Clear();
-                            cmd.Parameters.AddWithValue("@deptname", request.dept.deptname);
-                            var cnt = Convert.ToInt32(cmd.ExecuteScalar());
-                            if (cnt > 0)
-                            {
-                                throw new LJCommonException("存在重复部门名称,请检查!");
-                            }
-
-                            //新建
-                            request.dept.createtime = dtNow;
-                            request.dept.deptid = BllHelper.GetID(cmd, "u_dept");
-                            
-                            var fields = "deptid,deptname,profitrate,pricelistid,springtypeid,createtime,moneyrate,discount,flag,if_rate_auto,manage_amt,mtrltype,managerate,com_profitrate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate,taxes_rate";
-                            DbSqlHelper.Insert(cmd, "u_dept", null, request.dept, fields);
-                        }
-                        else
-                        {
-                            //修改
-                            request.dept.moddate = dtNow;
-                            request.dept.modemp = tokendata.username;
-
-                            var fields = "deptname,profitrate,pricelistid,springtypeid,moneyrate,discount,flag,if_rate_auto,manage_amt,mtrltype,moddate,modemp,managerate,com_profitrate,dannum1_rate,dannum2_rate,dannum3_rate,dannum4_rate,taxes_rate";
-                            DbSqlHelper.Update(cmd, "u_dept", null, request.dept, "deptid", fields);
-                        }
-
+                        helper.SaveDept(request.dept);
                         cmd.Transaction.Commit();
                     }
                     catch (Exception e)

+ 6 - 41
JLHHJSvr/Excutor/SaveMtrlDefExcutor.cs

@@ -5,11 +5,14 @@ using System.Linq;
 using System.Text;
 using JLHHJSvr.BLL;
 using JLHHJSvr.Com;
+using JLHHJSvr.Com.Model;
+using JLHHJSvr.Helper;
 using JLHHJSvr.LJException;
 using JLHHJSvr.Tools;
 using LJLib.DAL.SQL;
 using LJLib.Net.SPI.Server;
 using LJLib.SQLEX;
+using static JLHHJSvr.Helper.CacheHelper;
 
 namespace JLHHJSvr.Excutor
 {
@@ -45,51 +48,13 @@ namespace JLHHJSvr.Excutor
 
                 AutoInit.AutoInitS(cmd, request.mtrl);
 
+                var helper = HelperBase.GetHelper<BasicInfoHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
+
                 using (cmd.Transaction = con.BeginTransaction())
                 {
                     try
                     {
-                        if (request.mtrl.mtrlid <= 0)
-                        {
-                            request.mtrl.mtrlid = BllHelper.GetID(cmd, "u_mtrl_price");
-
-                            request.mtrl.createtime = dtNow;
-                            request.mtrl.createby = tokendata.username;
-
-                            var fields = @"mtrlid,mtrltype,name,priceunit,shrinkage,gram_weight,cloth_width,if_inputqty,if_areaprice,createtime,createby,thickness,dscrp,erp_mtrlid,fjcnt,isuse,handtype,lastdate,erp_mtrlengname,if_subspecs,extra_cost,is_singleqty";
-                            DbSqlHelper.Insert(cmd, "u_mtrl_price", null, request.mtrl, fields);
-
-                            var fields2 = @"mtrlid,pricelistid,price,pricetype,price_formula,qty_formula";
-
-                            if(request.mtrl.mxlist != null && request.mtrl.mxlist.Any())
-                            {
-                                foreach (var mx in request.mtrl.mxlist)
-                                {
-                                    AutoInit.AutoInitS(cmd, mx);
-                                    mx.mtrlid = request.mtrl.mtrlid;
-
-                                    DbSqlHelper.Insert(cmd, "u_mtrl_price_pricelist", null, mx, fields2);
-                                }
-                            }
-                        }
-                        else
-                        {
-                            //修改
-                            var fields = @"mtrltype,name,priceunit,shrinkage,gram_weight,cloth_width,if_inputqty,if_areaprice,thickness,dscrp,erp_mtrlid,fjcnt,isuse,handtype,lastdate,erp_mtrlengname,if_subspecs,extra_cost,is_singleqty";
-                            DbSqlHelper.Update(cmd, "u_mtrl_price", null, request.mtrl, "mtrlid", fields);
-
-                            var fields2 = @"price,pricetype,price_formula,qty_formula";
-
-                            if (request.mtrl.mxlist != null && request.mtrl.mxlist.Any())
-                            {
-                                foreach (var mx in request.mtrl.mxlist)
-                                {
-                                    AutoInit.AutoInitS(cmd, mx);
-                                    DbSqlHelper.Update(cmd, "u_mtrl_price_pricelist", null, mx, "mtrlid,pricelistid", fields2);
-                                }
-                            }
-                        }
-
+                        helper.SaveMtrlDef(request.mtrl);
                         cmd.Transaction.Commit();
                     }
                     catch (Exception e)

+ 36 - 0
JLHHJSvr/Helper/CacheHelper.cs

@@ -93,6 +93,42 @@ namespace JLHHJSvr.Helper
             var service = (ICacheService<TKey, TValue>)serviceObj;
             return service.Get(cmd, (TKey)key);
         }
+        public void RemoveData<TMapping, TEntity>(object key)
+        where TEntity : class, new()
+        where TMapping : new()
+        {
+            // 找到接口中的 TKey
+            var mappingType = typeof(TMapping);
+            var iface = mappingType.GetInterfaces()
+                .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICacheMapping<,>));
+
+            if (iface == null)
+                throw new InvalidOperationException($"{mappingType.Name} must implement ICacheMapping<TKey, TValue>");
+
+            var keyType = iface.GetGenericArguments()[0];
+
+            // 检查键类型是否匹配
+            if (!keyType.IsInstanceOfType(key))
+                throw new ArgumentException($"Key type {keyType.Name} does not match expected type");
+
+            // 获取私有泛型方法
+            var method = typeof(CacheHelper).GetMethod(nameof(RemoveInternal), BindingFlags.Instance | BindingFlags.NonPublic);
+            var gm = method.MakeGenericMethod(keyType, typeof(TEntity), mappingType);
+
+            // 调用方法
+            gm.Invoke(this, new object[] { key });
+        }
+
+        private void RemoveInternal<TKey, TValue, TMapping>(object key)
+            where TMapping : ICacheMapping<TKey, TValue>, new()
+            where TValue : class, new()
+        {
+            var mappingType = typeof(TMapping);
+
+            if (!_cacheServiceRegistry.TryGetValue(mappingType, out var serviceObj)) return;
+            var service = (ICacheService<TKey, TValue>)serviceObj;
+            service.Remove((TKey)key);
+        }
         #endregion
     }
 }

+ 4 - 4
JLHHJSvr/Helper/InterfaceHelper.cs

@@ -1148,7 +1148,7 @@ namespace JLHHJSvr.Helper
                 "织唛斜标", "客供标", "空白牛皮纸包角", "空白珍珠包角"
             });
             // 按照nameSet排序
-            Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
+            //Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
             //var fuliaoList = mxlist.Where(t => t.formulatype == 2).OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue).ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null).ToList();
             var resultDict = new Dictionary<int, u_mattress_mx_mtrl>();
             foreach (var item in mxlist.Where(t => t.formulatype == 2))
@@ -1169,9 +1169,9 @@ namespace JLHHJSvr.Helper
                 fuliaoList.Add(kvp.Value);
             }
 
-            fuliaoList = fuliaoList.OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue)
-              .ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null)
-              .ToList();
+            //fuliaoList = fuliaoList.OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue)
+            //  .ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null)
+            //  .ToList();
 
             var extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
             var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });

+ 5 - 0
JLHHJSvr/LJFrameWork/ljlib.cache/Caching/CacheService.cs

@@ -25,5 +25,10 @@ namespace LJLib
             }
             return ObjectHelper.DeepCopy(value);
         }
+
+        public void Remove(TKey key)
+        {
+            if (_cache.ContainsKey(key)) _cache.Remove(key);
+        }
     }
 }

+ 1 - 0
JLHHJSvr/LJFrameWork/ljlib.cache/Caching/ICacheService.cs

@@ -10,5 +10,6 @@ namespace LJLib
     public interface ICacheService<TKey, TValue> where TValue : class, new()
     {
         TValue Get(SqlCommand cmd, TKey key);
+        void Remove(TKey key);
     }
 }