ACLConstService.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using Mapster;
  2. using NPOI.OpenXmlFormats.Spreadsheet;
  3. using SqlSugar;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using WMS.BZModels;
  10. using WMS.BZModels.Dto.UserCenterManager.ACLConstDtos;
  11. using WMS.BZModels.Dto.UserCenterManager.UserInfoDtos;
  12. using WMS.BZModels.Models.UserCenterManager;
  13. using WMS.Info;
  14. using WMS.BZSqlSugar;
  15. namespace WMS.BZServices.UserCenterManager
  16. {
  17. public class ACLConstService
  18. {
  19. private readonly Repository<AclConst> _aclConstRepository;
  20. private readonly SysModuleService _sysModuleService;
  21. public ACLConstService(Repository<AclConst> aclConstRepository, SysModuleService sysModuleService)
  22. {
  23. _aclConstRepository = aclConstRepository;
  24. _sysModuleService = sysModuleService;
  25. }
  26. /// <summary>
  27. /// 获取列表数据
  28. /// <summary>
  29. /// <returns></returns>
  30. public IList<ACLConstDto> GetList(string keyword)
  31. {
  32. if (string.IsNullOrEmpty(keyword))
  33. {
  34. return _aclConstRepository.Queryable().ToList().Adapt<List<ACLConstDto>>();
  35. }
  36. else
  37. {
  38. var lst = _aclConstRepository.Queryable().Where(it => it.Name.Contains(keyword)).Select(v => v.Code).ToList();
  39. var lists = _aclConstRepository.Queryable().Where(v => lst.Contains(v.PNO) || v.Name.Contains(keyword)).ToList();
  40. return lists.Adapt<List<ACLConstDto>>();
  41. }
  42. }
  43. /// <summary>
  44. /// 删除实体数据
  45. /// <param name="keyValue">主键</param>
  46. /// <summary>
  47. /// <returns></returns>
  48. public void DeleteEntity(string keyValue)
  49. {
  50. _aclConstRepository.Deleteable().Where(it => it.Code == keyValue).ExecuteCommand();
  51. }
  52. public void Save(LoginUserInfo loginUser, string keyValue, AclConst entity)
  53. {
  54. try
  55. {
  56. if (string.IsNullOrWhiteSpace(entity.Code))
  57. {
  58. throw new ArgumentException("菜单编号为空。");
  59. }
  60. if (string.IsNullOrWhiteSpace(entity.PNO))
  61. {
  62. throw new ArgumentException("父菜单编号为空。");
  63. }
  64. if (string.IsNullOrWhiteSpace(entity.Name))
  65. {
  66. throw new ArgumentException("菜单名称为空。");
  67. }
  68. DateTime nowdt = DateTime.Now;
  69. if (keyValue.IsEmpty() || keyValue == "undefined")
  70. {
  71. if (_aclConstRepository.Queryable().Any(o => o.Code == entity.Code))
  72. {
  73. throw new ArgumentException("菜单编号已存在。");
  74. }
  75. var sort = _aclConstRepository.Queryable().Count(o => o.PNO == entity.PNO) + 1;
  76. entity.Id = IdFactory.NewId();
  77. entity.AddTime = DateTime.Now;
  78. entity.AddWho = loginUser.UserNo;
  79. entity.EditTime = DateTime.Now;
  80. entity.EditWho = loginUser.UserNo;
  81. entity.AppTypeNum = 1;
  82. entity.SortNum = sort;
  83. entity.ACLItem = entity.Code;
  84. var searchentity = entity.Adapt<AclConst>();
  85. searchentity.Id = IdFactory.NewId();
  86. searchentity.Code = entity.Code + "_lr_search";
  87. searchentity.ACLItem = searchentity.Code;
  88. searchentity.PNO = entity.Code;
  89. searchentity.SortNum = 0;
  90. searchentity.Name = "查看";
  91. _aclConstRepository.Deleteable().Where(it => it.Code == searchentity.Code).ExecuteCommand();
  92. _aclConstRepository.Insert(entity);
  93. _aclConstRepository.Insert(searchentity);
  94. }
  95. else
  96. {
  97. entity.Id = Convert.ToInt64(keyValue);
  98. entity.EditTime = DateTime.Now;
  99. entity.EditWho = loginUser.UserNo;
  100. _aclConstRepository.UpdateEntity(entity);
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. throw ex;
  106. }
  107. }
  108. /// <summary>
  109. /// 保存实体数据(新增、修改)
  110. /// <param name="keyValue">主键</param>
  111. /// <summary>
  112. /// <returns></returns>
  113. public void SaveEntity(LoginUserInfo loginUserInfo, string keyValue, AclConst entity)
  114. {
  115. if (entity == null)
  116. {
  117. throw new ArgumentException("输入数据为空");
  118. }
  119. if (string.IsNullOrWhiteSpace(entity.Code))
  120. {
  121. throw new ArgumentException("编号为空");
  122. }
  123. if (string.IsNullOrWhiteSpace(entity.Name))
  124. {
  125. throw new ArgumentException("名称为空");
  126. }
  127. entity.EditTime = DateTime.Now;
  128. entity.EditWho = loginUserInfo.UserNo;
  129. if (string.IsNullOrEmpty(keyValue))
  130. {
  131. entity.Id = IdFactory.NewId();
  132. entity.AddTime = DateTime.Now;
  133. entity.AddWho = loginUserInfo.UserNo;
  134. _aclConstRepository.Insert(entity);
  135. }
  136. else
  137. {
  138. entity.Id = Convert.ToInt64(keyValue);
  139. _aclConstRepository.UpdateEntity(entity);
  140. }
  141. }
  142. public void SaveWebACLConst(LoginUserInfo loginUser)
  143. {
  144. var list = _sysModuleService.GetList();
  145. if (list == null)
  146. {
  147. return;
  148. }
  149. _aclConstRepository.Deleteable().Where(it => it.AppTypeNum == (int)EAppType.PC).ExecuteCommand();
  150. List<AclConst> aclConstList = new List<AclConst>();
  151. foreach (var item in list)
  152. {
  153. if (item.Code.Contains("Web_DevelopmentM"))
  154. {
  155. continue;
  156. }
  157. aclConstList.Add(new AclConst()
  158. {
  159. ACLItem = item.Code,
  160. AddTime = DateTime.Now,
  161. AddWho = loginUser.UserNo,
  162. AppTypeNum = (int)EAppType.PC,
  163. Code = item.Code,
  164. EditTime = DateTime.Now,
  165. EditWho = loginUser.UserNo,
  166. Name = item.Name,
  167. PNO = item.PNO,
  168. SortNum = item.SortNum
  169. });
  170. }
  171. _aclConstRepository.Insert(aclConstList);
  172. }
  173. public void SaveWebACLBtnConst(LoginUserInfo loginUser, string keyValue, List<AclConst> AclList)
  174. {
  175. _aclConstRepository.Deleteable().Where(it => it.PNO == keyValue).ExecuteCommand();
  176. List<AclConst> list = new List<AclConst>();
  177. if (AclList == null)
  178. {
  179. return;
  180. }
  181. AclList.ForEach(it =>
  182. {
  183. int i = 0;
  184. it.AddTime = DateTime.Now;
  185. it.AddWho = loginUser.UserNo;
  186. it.AppTypeNum = (int)EAppType.PC;
  187. it.EditTime = DateTime.Now;
  188. it.EditWho = loginUser.UserNo;
  189. it.PNO = keyValue;
  190. it.SortNum = i++;
  191. it.Code = it.ACLItem;
  192. });
  193. _aclConstRepository.Insert(AclList);
  194. }
  195. }
  196. }