ControlItemServices.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Autofac;
  6. using System.Reflection;
  7. using System.Data.Entity;
  8. using EMIS.DataLogic.Repositories;
  9. using EMIS.ViewModel.CacheManage;
  10. using Bowin.Common.Cache;
  11. using EMIS.Utility;
  12. using EMIS.Utility.FormValidate;
  13. using EMIS.ViewModel.SystemView;
  14. using EMIS.DataLogic.SystemSetting;
  15. namespace EMIS.CommonLogic.SystemServices
  16. {
  17. public class ControlItemServices : BaseServices, IControlItemServices
  18. {
  19. public ControlItemDAL ControlItemDAL { get; set; }
  20. /// <summary>
  21. /// 刷新对应的菜单项
  22. /// </summary>
  23. public void RefreshCache()
  24. {
  25. var key = "ControlItem_MenuNoList";
  26. var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo == null)
  27. .Select(x => x.MenuNo).Distinct().ToList();
  28. CacheHelper.Remove(key);
  29. CacheHelper.Add(key, result);
  30. key = "ControlItem_ContextMenuNoList";
  31. var contextMenuResult = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo != null)
  32. .Select(x => new ContextMenuNoView { MenuNo = x.MenuNo, ContextMenuNo = x.ContextMnuNo })
  33. .Distinct().ToList();
  34. CacheHelper.Remove(key);
  35. CacheHelper.Add(key, contextMenuResult);
  36. }
  37. /// <summary>
  38. /// 获取需要进行逻辑控制的菜单
  39. /// </summary>
  40. /// <returns></returns>
  41. public List<string> GetNeedControlMenuNo()
  42. {
  43. var key = "ControlItem_MenuNoList";
  44. var cachedValue = CacheHelper.Get(key);
  45. if (cachedValue == null)
  46. {
  47. var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo == null)
  48. .Select(x => x.MenuNo).Distinct().ToList();
  49. CacheHelper.Add(key, result);
  50. return result;
  51. }
  52. else
  53. {
  54. return (List<string>)cachedValue;
  55. }
  56. }
  57. /// <summary>
  58. /// 控制菜单,如果不能通过将抛出异常,否则就算通过
  59. /// </summary>
  60. /// <param name="menuNo"></param>
  61. public void CheckControlItems(string menuNo)
  62. {
  63. var user = CustomPrincipal.Current;
  64. var controlItemList = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.MenuNo == menuNo
  65. && x.ContextMnuNo == null).ToList();
  66. var messageList = new List<string>();
  67. foreach (var controlItem in controlItemList)
  68. {
  69. if (!string.IsNullOrEmpty(controlItem.Sys_ControlItem.ClassName))
  70. {
  71. try
  72. {
  73. var retValue = ReflectorHelper.RunMethod(controlItem.Sys_ControlItem.ClassName, user.UserID);
  74. if (retValue.GetType() == typeof(bool) && (bool)retValue == false)
  75. {
  76. messageList.Add(controlItem.Sys_ControlItem.Message);
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. throw ex;
  82. }
  83. }
  84. }
  85. if (messageList.Count > 0)
  86. {
  87. throw new Exception(string.Join("", messageList));
  88. }
  89. }
  90. /// <summary>
  91. /// 获取需要进行逻辑控制的菜单
  92. /// </summary>
  93. /// <returns></returns>
  94. public List<ContextMenuNoView> GetNeedControlContextMenuNo()
  95. {
  96. var key = "ControlItem_ContextMenuNoList";
  97. var cachedValue = CacheHelper.Get(key);
  98. if (cachedValue == null)
  99. {
  100. var result = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true && x.ContextMnuNo != null)
  101. .Select(x => new ContextMenuNoView { MenuNo = x.MenuNo, ContextMenuNo = x.ContextMnuNo })
  102. .Distinct().ToList();
  103. CacheHelper.Add(key, result);
  104. return result;
  105. }
  106. else
  107. {
  108. return (List<ContextMenuNoView>)cachedValue;
  109. }
  110. }
  111. /// <summary>
  112. /// 控制按钮,如果不能通过将抛出异常,否则就算通过
  113. /// </summary>
  114. /// <param name="contextMenuNoView"></param>
  115. public void CheckControlItems(ContextMenuNoView contextMenuNoView)
  116. {
  117. var user = CustomPrincipal.Current;
  118. var controlItemList = ControlItemDAL.GetControlItemDetailList(x => x.Sys_ControlItem.IsEnable == true
  119. && x.MenuNo == contextMenuNoView.MenuNo && x.ContextMnuNo == contextMenuNoView.ContextMenuNo).ToList();
  120. var messageList = new List<string>();
  121. foreach (var controlItem in controlItemList)
  122. {
  123. if (!string.IsNullOrEmpty(controlItem.Sys_ControlItem.ClassName))
  124. {
  125. try
  126. {
  127. var retValue = ReflectorHelper.RunMethod(controlItem.Sys_ControlItem.ClassName, user.UserID);
  128. if (retValue.GetType() == typeof(bool) && (bool)retValue == false)
  129. {
  130. messageList.Add(controlItem.Sys_ControlItem.Message);
  131. }
  132. }
  133. catch (Exception ex)
  134. {
  135. throw ex;
  136. }
  137. }
  138. }
  139. if (messageList.Count > 0)
  140. {
  141. throw new Exception(string.Join("", messageList));
  142. }
  143. }
  144. /// <summary>
  145. /// 查询相应控制类型的控制信息List
  146. /// </summary>
  147. /// <param name="controlItemType"></param>
  148. /// <returns></returns>
  149. public IList<Entities.Sys_ControlItem> GetControlItemList(ViewModel.SYS_ControlItemType controlItemType)
  150. {
  151. return ControlItemDAL.GetControlItemList(x => x.ControlItemTypeID == (int)controlItemType).ToList();
  152. }
  153. /// <summary>
  154. /// 查询登录控制类型的控制信息List
  155. /// </summary>
  156. /// <returns></returns>
  157. public IList<Entities.Sys_ControlItem> GetLoginControlItemList()
  158. {
  159. return ControlItemDAL.GetControlItemList(x => x.IsLoginControl == true && x.IsEnable == true).ToList();
  160. }
  161. /// <summary>
  162. /// 查询相应用户ID的登录控制信息
  163. /// </summary>
  164. /// <param name="userID"></param>
  165. public void CheckLoginControlItems(Guid userID)
  166. {
  167. var messageList = new List<string>();
  168. var controlItemList = this.GetLoginControlItemList();
  169. foreach (var controlItem in controlItemList)
  170. {
  171. if (!string.IsNullOrEmpty(controlItem.ClassName))
  172. {
  173. try
  174. {
  175. var retValue = ReflectorHelper.RunMethod(controlItem.ClassName, userID);
  176. if (retValue.GetType() == typeof(bool) && (bool)retValue == false)
  177. {
  178. messageList.Add(controlItem.Message);
  179. }
  180. }
  181. catch (Exception ex)
  182. {
  183. throw ex;
  184. }
  185. }
  186. }
  187. if (messageList.Count > 0)
  188. {
  189. throw new Exception(string.Join("\n", messageList));
  190. }
  191. }
  192. }
  193. }