123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- 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<SYS_DATA> GetList()
- {
- try
- {
- List<SYS_DATA> list = RedisCache.Read<List<SYS_DATA>>("SysDataGetList", RedisCacheNo);
- if (list == null || list.Count == 0)
- {
- list = SysDbCore.GetDbCtx().Queryable<SYS_DATA>().Where(it => it.F_ISDELETE == 0).OrderBy(it => it.F_SORTNUM).ToList();
- RedisCache.Write<List<SYS_DATA>>("SysDataGetList", list, RedisCacheNo);
- }
- return list;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public static Dictionary<string, Dictionary<string, SYS_DATA>> GetModelMap()
- {
- string cachekey = System.Reflection.MethodBase.GetCurrentMethod().Name;
- Dictionary<string, Dictionary<string, SYS_DATA>> dic = RedisCache.Read<Dictionary<string, Dictionary<string, SYS_DATA>>>("SysDataGetModelMap", RedisCacheNo);
- if (dic == null || dic.Count == 0)
- {
- dic = new Dictionary<string, Dictionary<string, SYS_DATA>>();
- List<SYS_DATA> 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<SYS_DATA>().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<SYS_DATA>(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<SYS_DATA>(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<ALCTPOLICY>().Where(v => v.ID == ID).First();
- if (head == null)
- throw SysExCore.ThrowFailException("未找到相关规则");
- var lst = ctx.Queryable<ALCTPOLICYITEM>().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<ALCTPOLICY>().Where(v => v.ID == ID).First();
- if (policy == null)
- throw new Exception("未找到选中规则");
- // 将选中的类型规则全部禁用
- int res = ctx.Updateable<ALCTPOLICY>(v => new ALCTPOLICY
- {
- ISEDIT = 1
- }).Where(v => v.DEFINE01 == policy.DEFINE01).ExecuteCommand();
- // 将选中的项目启用
- res = ctx.Updateable<ALCTPOLICY>(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<TreeModel> GetOutInTree()
- {
- List<TreeModel> treeList = new List<TreeModel>();
- string guidid = Guid.NewGuid().ToString();
- SqlSugarClient ctx = SysDbCore.GetDbCtx();
- try
- {
- var polity = ctx.Queryable<ALCTPOLICY>().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");
- }
- }
- }
|