SysDataBLLCore.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using WMS.Util;
  7. using WMS.Info;
  8. using System.Reflection;
  9. using System.ComponentModel;
  10. using SqlSugar;
  11. namespace WMS.Core
  12. {
  13. public class SysDataBLLCore
  14. {
  15. private const ERedisCacheNo RedisCacheNo = ERedisCacheNo.System;
  16. const string CacheKeys = " SysDataGetList, SysDataGetModelMap";
  17. public static List<SYS_DATA> GetList()
  18. {
  19. try
  20. {
  21. List<SYS_DATA> list = RedisCache.Read<List<SYS_DATA>>("SysDataGetList", RedisCacheNo);
  22. if (list == null || list.Count == 0)
  23. {
  24. list = SysDbCore.GetDbCtx().Queryable<SYS_DATA>().Where(it => it.F_ISDELETE == 0).OrderBy(it => it.F_SORTNUM).ToList();
  25. RedisCache.Write<List<SYS_DATA>>("SysDataGetList", list, RedisCacheNo);
  26. }
  27. return list;
  28. }
  29. catch (Exception ex)
  30. {
  31. throw ex;
  32. }
  33. }
  34. public static Dictionary<string, Dictionary<string, SYS_DATA>> GetModelMap()
  35. {
  36. string cachekey = System.Reflection.MethodBase.GetCurrentMethod().Name;
  37. Dictionary<string, Dictionary<string, SYS_DATA>> dic = RedisCache.Read<Dictionary<string, Dictionary<string, SYS_DATA>>>("SysDataGetModelMap", RedisCacheNo);
  38. if (dic == null || dic.Count == 0)
  39. {
  40. dic = new Dictionary<string, Dictionary<string, SYS_DATA>>();
  41. List<SYS_DATA> list = SysDataBLLCore.GetList();
  42. var plist = list.FindAll(it => it.F_ISSTOP == 0 && it.F_PNO == "0");
  43. foreach (var p in plist)
  44. {
  45. var dtllist = list.FindAll(a => a.F_PNO == p.F_NO);
  46. dic.Add(p.F_NO, dtllist.ToDictionary(v => v.F_NO, v => v));
  47. }
  48. RedisCache.Write("SysDataGetModelMap", dic, RedisCacheNo);
  49. }
  50. return dic;
  51. }
  52. public static void AtSysData(LoginUserInfo loginuser)
  53. {
  54. try
  55. {
  56. var Ctx = SysDbCore.GetDbCtx();
  57. var asmtypes = Assembly.Load("WMS.Info").GetTypes();
  58. Ctx.Deleteable<SYS_DATA>().ExecuteCommand();
  59. foreach (var t in asmtypes)
  60. {
  61. if (t.BaseType == typeof(Enum))
  62. {
  63. object[] tAttr = t.GetCustomAttributes(typeof(DescriptionAttribute), true);
  64. if (tAttr == null || tAttr.Length <= 0)
  65. {
  66. continue;
  67. }
  68. DescriptionAttribute HeaddescAttr = tAttr[0] as DescriptionAttribute;
  69. if (HeaddescAttr == null)
  70. {
  71. continue;
  72. }
  73. string HeadNo = t.Name;
  74. string HeadDesc = HeaddescAttr.Description;
  75. SYS_DATA hdata = new SYS_DATA()
  76. {
  77. F_ADDTIME = DateTime.Now,
  78. F_ADDUSERNO = loginuser.UserNo,
  79. F_EDITTIME = DateTime.Now,
  80. F_EDITUSERNO = loginuser.UserNo,
  81. F_ISDELETE = 0,
  82. F_ISSTOP = 0,
  83. F_MEMO = "",
  84. F_NAME = HeadDesc,
  85. F_CODE = HeadNo,
  86. F_NO = HeadNo,
  87. F_NUM = 0,
  88. F_PNO = "0",
  89. F_SORTNUM = 0,
  90. };
  91. Ctx.Insertable<SYS_DATA>(hdata).ExecuteCommand();
  92. foreach (var value in Enum.GetValues(t))
  93. {
  94. object[] objAttrs = value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
  95. string EnumDescription = value.ToString();
  96. if (objAttrs != null && objAttrs.Length > 0)
  97. {
  98. DescriptionAttribute descAttr = objAttrs[0] as DescriptionAttribute;
  99. EnumDescription = descAttr == null ? value.ToString() : descAttr.Description;
  100. }
  101. SYS_DATA dtldata = new SYS_DATA()
  102. {
  103. F_ADDTIME = DateTime.Now,
  104. F_ADDUSERNO = "Super",
  105. F_EDITTIME = DateTime.Now,
  106. F_EDITUSERNO = "Super",
  107. F_ISDELETE = 0,
  108. F_ISSTOP = 0,
  109. F_MEMO = "",
  110. F_NAME = EnumDescription,
  111. F_NO = HeadNo + "_" + value.ToString(),
  112. F_NUM = Convert.ToInt32(value),
  113. F_CODE = value.ToString(),
  114. F_PNO = HeadNo,
  115. F_SORTNUM = Convert.ToInt32(value),
  116. };
  117. Ctx.Insertable<SYS_DATA>(dtldata).ExecuteCommand();
  118. }
  119. }
  120. }
  121. RedisCache.RemoveCacheKeys(CacheKeys, RedisCacheNo);
  122. }
  123. catch (Exception ex)
  124. {
  125. throw ex;
  126. }
  127. }
  128. public TempPolicy GetPolicyItem(string ID)
  129. {
  130. SqlSugarClient ctx = SysDbCore.GetDbCtx();
  131. TempPolicy t = new TempPolicy();
  132. try
  133. {
  134. var head = ctx.Queryable<ALCTPOLICY>().Where(v => v.ID == ID).First();
  135. if (head == null)
  136. throw SysExCore.ThrowFailException("未找到相关规则");
  137. var lst = ctx.Queryable<ALCTPOLICYITEM>().Where(v => v.POLICY == head.ID).OrderBy(v => v.SEQ).ToList();
  138. string where = string.Empty;
  139. string order = string.Empty;
  140. int whereindex = 1;
  141. int orderindex = 1;
  142. foreach (var item in lst)
  143. {
  144. if (item.TYPE == 1)
  145. {
  146. where += whereindex + " > " + item.SQL + "\r\n";
  147. whereindex++;
  148. }
  149. if (item.TYPE == 2)
  150. {
  151. order += orderindex + " > " + item.REMARK + "\r\n";
  152. orderindex++;
  153. }
  154. }
  155. t.ID = head.ID;
  156. t.ISEDIT = head.ISEDIT;
  157. t.ORDERSTR = order;
  158. t.WHERESTR = where;
  159. }
  160. catch (Exception ex)
  161. {
  162. }
  163. finally { ctx.Dispose(); }
  164. return t;
  165. }
  166. public string UpEdit(string ID)
  167. {
  168. SqlSugarClient ctx = SysDbCore.GetDbCtx();
  169. try
  170. {
  171. var policy = ctx.Queryable<ALCTPOLICY>().Where(v => v.ID == ID).First();
  172. if (policy == null)
  173. throw new Exception("未找到选中规则");
  174. // 将选中的类型规则全部禁用
  175. int res = ctx.Updateable<ALCTPOLICY>(v => new ALCTPOLICY
  176. {
  177. ISEDIT = 1
  178. }).Where(v => v.DEFINE01 == policy.DEFINE01).ExecuteCommand();
  179. // 将选中的项目启用
  180. res = ctx.Updateable<ALCTPOLICY>(v => new ALCTPOLICY
  181. {
  182. ISEDIT = 0
  183. }).Where(v => v.ID == policy.ID).ExecuteCommand();
  184. if (res > 0)
  185. return "操作成功";
  186. else
  187. throw new Exception("操作失败");
  188. }
  189. catch (Exception ex)
  190. {
  191. throw SysExCore.ThrowFailException(ex.Message);
  192. }
  193. finally
  194. {
  195. ctx.Dispose();
  196. }
  197. }
  198. public List<TreeModel> GetOutInTree()
  199. {
  200. List<TreeModel> treeList = new List<TreeModel>();
  201. string guidid = Guid.NewGuid().ToString();
  202. SqlSugarClient ctx = SysDbCore.GetDbCtx();
  203. try
  204. {
  205. var polity = ctx.Queryable<ALCTPOLICY>().Where(v => 1 == 1).ToList();
  206. treeList.Add(new TreeModel
  207. {
  208. id = "1",
  209. text = "入库",
  210. value = "1",
  211. showcheck = false,
  212. checkstate = 0,
  213. isexpand = true,
  214. parentId = "0"
  215. });
  216. treeList.Add(new TreeModel
  217. {
  218. id = "2",
  219. text = "出库",
  220. value = "2",
  221. showcheck = false,
  222. checkstate = 0,
  223. isexpand = true,
  224. parentId = "0"
  225. });
  226. treeList.Add(new TreeModel
  227. {
  228. id = "3",
  229. text = "空托",
  230. value = "3",
  231. showcheck = false,
  232. checkstate = 0,
  233. isexpand = true,
  234. parentId = "0"
  235. });
  236. string paid = "";
  237. foreach (ALCTPOLICY item in polity)
  238. {
  239. paid = "";
  240. if (item.DEFINE01 == "入库")
  241. {
  242. paid = "1";
  243. }else if (item.DEFINE01 == "出库")
  244. {
  245. paid = "2";
  246. }
  247. else if (item.DEFINE01 == "空托")
  248. {
  249. paid = "3";
  250. }
  251. TreeModel node = new TreeModel
  252. {
  253. id = item.ID,
  254. text = item.NAME,
  255. value = item.ID,
  256. showcheck = false,
  257. checkstate = 0,
  258. isexpand = true,
  259. parentId = paid
  260. };
  261. treeList.Add(node);
  262. }
  263. }
  264. catch (Exception ex)
  265. {
  266. throw SysExCore.ThrowFailException(ex.Message);
  267. }
  268. finally { ctx.Dispose(); }
  269. return treeList.ToTree("0");
  270. }
  271. }
  272. }