using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Util; using WMS.Info; using System.Reflection; using System.ComponentModel; using SqlSugar; namespace WMS.Core { public class SysDataBLLCore { private const ERedisCacheNo RedisCacheNo = ERedisCacheNo.System; const string CacheKeys = " SysDataGetList, SysDataGetModelMap"; public static List GetList() { try { List list = RedisCache.Read>("SysDataGetList", RedisCacheNo); if (list == null || list.Count == 0) { list = SysDbCore.GetDbCtx().Queryable().Where(it => it.F_ISDELETE == 0).OrderBy(it => it.F_SORTNUM).ToList(); RedisCache.Write>("SysDataGetList", list, RedisCacheNo); } return list; } catch (Exception ex) { throw ex; } } public static Dictionary> GetModelMap() { string cachekey = System.Reflection.MethodBase.GetCurrentMethod().Name; Dictionary> dic = RedisCache.Read>>("SysDataGetModelMap", RedisCacheNo); if (dic == null || dic.Count == 0) { dic = new Dictionary>(); List list = SysDataBLLCore.GetList(); var plist = list.FindAll(it => it.F_ISSTOP == 0 && it.F_PNO == "0"); foreach (var p in plist) { var dtllist = list.FindAll(a => a.F_PNO == p.F_NO); dic.Add(p.F_NO, dtllist.ToDictionary(v => v.F_NO, v => v)); } RedisCache.Write("SysDataGetModelMap", dic, RedisCacheNo); } return dic; } public static void AtSysData(LoginUserInfo loginuser) { try { var Ctx = SysDbCore.GetDbCtx(); var asmtypes = Assembly.Load("WMS.Info").GetTypes(); Ctx.Deleteable().ExecuteCommand(); foreach (var t in asmtypes) { if (t.BaseType == typeof(Enum)) { object[] tAttr = t.GetCustomAttributes(typeof(DescriptionAttribute), true); if (tAttr == null || tAttr.Length <= 0) { continue; } DescriptionAttribute HeaddescAttr = tAttr[0] as DescriptionAttribute; if (HeaddescAttr == null) { continue; } string HeadNo = t.Name; string HeadDesc = HeaddescAttr.Description; SYS_DATA hdata = new SYS_DATA() { F_ADDTIME = DateTime.Now, F_ADDUSERNO = loginuser.UserNo, F_EDITTIME = DateTime.Now, F_EDITUSERNO = loginuser.UserNo, F_ISDELETE = 0, F_ISSTOP = 0, F_MEMO = "", F_NAME = HeadDesc, F_CODE = HeadNo, F_NO = HeadNo, F_NUM = 0, F_PNO = "0", F_SORTNUM = 0, }; Ctx.Insertable(hdata).ExecuteCommand(); foreach (var value in Enum.GetValues(t)) { object[] objAttrs = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true); string EnumDescription = value.ToString(); if (objAttrs != null && objAttrs.Length > 0) { DescriptionAttribute descAttr = objAttrs[0] as DescriptionAttribute; EnumDescription = descAttr == null ? value.ToString() : descAttr.Description; } SYS_DATA dtldata = new SYS_DATA() { F_ADDTIME = DateTime.Now, F_ADDUSERNO = "Super", F_EDITTIME = DateTime.Now, F_EDITUSERNO = "Super", F_ISDELETE = 0, F_ISSTOP = 0, F_MEMO = "", F_NAME = EnumDescription, F_NO = HeadNo + "_" + value.ToString(), F_NUM = Convert.ToInt32(value), F_CODE = value.ToString(), F_PNO = HeadNo, F_SORTNUM = Convert.ToInt32(value), }; Ctx.Insertable(dtldata).ExecuteCommand(); } } } RedisCache.RemoveCacheKeys(CacheKeys, RedisCacheNo); } catch (Exception ex) { throw ex; } } public TempPolicy GetPolicyItem(string ID) { SqlSugarClient ctx = SysDbCore.GetDbCtx(); TempPolicy t = new TempPolicy(); try { var head = ctx.Queryable().Where(v => v.ID == ID).First(); if (head == null) throw SysExCore.ThrowFailException("未找到相关规则"); var lst = ctx.Queryable().Where(v => v.POLICY == head.ID).OrderBy(v => v.SEQ).ToList(); string where = string.Empty; string order = string.Empty; int whereindex = 1; int orderindex = 1; foreach (var item in lst) { if (item.TYPE == 1) { where += whereindex + " > " + item.SQL + "\r\n"; whereindex++; } if (item.TYPE == 2) { order += orderindex + " > " + item.REMARK + "\r\n"; orderindex++; } } t.ID = head.ID; t.ISEDIT = head.ISEDIT; t.ORDERSTR = order; t.WHERESTR = where; } catch (Exception ex) { } finally { ctx.Dispose(); } return t; } public string UpEdit(string ID) { SqlSugarClient ctx = SysDbCore.GetDbCtx(); try { var policy = ctx.Queryable().Where(v => v.ID == ID).First(); if (policy == null) throw new Exception("未找到选中规则"); // 将选中的类型规则全部禁用 int res = ctx.Updateable(v => new ALCTPOLICY { ISEDIT = 1 }).Where(v => v.DEFINE01 == policy.DEFINE01).ExecuteCommand(); // 将选中的项目启用 res = ctx.Updateable(v => new ALCTPOLICY { ISEDIT = 0 }).Where(v => v.ID == policy.ID).ExecuteCommand(); if (res > 0) return "操作成功"; else throw new Exception("操作失败"); } catch (Exception ex) { throw SysExCore.ThrowFailException(ex.Message); } finally { ctx.Dispose(); } } public List GetOutInTree() { List treeList = new List(); string guidid = Guid.NewGuid().ToString(); SqlSugarClient ctx = SysDbCore.GetDbCtx(); try { var polity = ctx.Queryable().Where(v => 1 == 1).ToList(); treeList.Add(new TreeModel { id = "1", text = "入库", value = "1", showcheck = false, checkstate = 0, isexpand = true, parentId = "0" }); treeList.Add(new TreeModel { id = "2", text = "出库", value = "2", showcheck = false, checkstate = 0, isexpand = true, parentId = "0" }); treeList.Add(new TreeModel { id = "3", text = "空托", value = "3", showcheck = false, checkstate = 0, isexpand = true, parentId = "0" }); string paid = ""; foreach (ALCTPOLICY item in polity) { paid = ""; if (item.DEFINE01 == "入库") { paid = "1"; }else if (item.DEFINE01 == "出库") { paid = "2"; } else if (item.DEFINE01 == "空托") { paid = "3"; } TreeModel node = new TreeModel { id = item.ID, text = item.NAME, value = item.ID, showcheck = false, checkstate = 0, isexpand = true, parentId = paid }; treeList.Add(node); } } catch (Exception ex) { throw SysExCore.ThrowFailException(ex.Message); } finally { ctx.Dispose(); } return treeList.ToTree("0"); } } }