足力健后端,使用.netcore版本,合并1个项目使用

ModuleButtonInfoController.cs 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IRepositories;
  4. using System.Linq;
  5. using System.Model;
  6. using System.Security.Claims;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9. using System.Common;
  10. using Microsoft.AspNetCore.Authorization;
  11. using Microsoft.AspNetCore.Mvc;
  12. using TVShoppingCallCenter_ZLJ.Models.Dtos;
  13. using System.Linq.Expressions;
  14. namespace TVShoppingCallCenter_ZLJ.Controllers.System
  15. {
  16. [Authorize]
  17. [Produces("application/json")]
  18. [Route("api/[controller]")]
  19. public class ModuleButtonInfoController : BaseController
  20. {
  21. private readonly ISys_ModuleButtonInfoRepository _sys_modulebuttoninfoRepository;
  22. public ModuleButtonInfoController(ISys_ModuleButtonInfoRepository sys_modulebuttoninfoRepository)
  23. {
  24. _sys_modulebuttoninfoRepository = sys_modulebuttoninfoRepository;
  25. }
  26. [HttpGet("getlist")]
  27. public async Task<IActionResult> GetListAsync(int menuid = 0)
  28. {
  29. var list_ModuleInfoButton= new List<T_Sys_ModuleButtonInfo>();
  30. Expression<Func<T_Sys_ModuleButtonInfo, bool>> eq = a => a.F_State != (int)EnumDelState.Delete;
  31. if (menuid>0)
  32. eq = eq.And(b => b.F_MenuId == menuid);
  33. list_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetListALL(eq, o => o.F_Sort, SqlSugar.OrderByType.Asc);
  34. List<ModuleInfoButtonDto> list_ModuleInfoButtonDto = new List<ModuleInfoButtonDto>();
  35. foreach (var entity in list_ModuleInfoButton)
  36. {
  37. ModuleInfoButtonDto _dto = new ModuleInfoButtonDto
  38. {
  39. id = entity.F_Id,
  40. moduleid = entity.F_MenuId.Value,
  41. name = entity.F_ButtonName,
  42. jsevent = entity.F_JSEvent,
  43. icon = entity.F_Icon,
  44. url = entity.F_UrlAddress,
  45. flag = entity.F_State.Value,
  46. remark = entity.F_Remark,
  47. sort = entity.F_Sort.Value
  48. };
  49. list_ModuleInfoButtonDto.Add(_dto);
  50. }
  51. return Success("获取按钮", list_ModuleInfoButtonDto);
  52. }
  53. /// <summary>
  54. /// 通过菜单的moduleId获取对应菜单下的所有按钮信息 V6.0全盘优化
  55. /// </summary>
  56. /// <param name="moduleId"></param>
  57. /// <returns></returns>
  58. [HttpGet("gettreegridjson")]
  59. public async Task<ActionResult> GetTreeGridJsonAsync(int moduleId = 0)
  60. {
  61. var list_ModuleInfoButton = new List<T_Sys_ModuleButtonInfo>();
  62. Expression<Func<T_Sys_ModuleButtonInfo, bool>> eq = a => a.F_State != (int)EnumDelState.Delete;
  63. if (moduleId > 0)
  64. eq = eq.And(b => b.F_MenuId == moduleId);
  65. list_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetListALL(eq, o => o.F_Sort, SqlSugar.OrderByType.Asc);
  66. var treeList = new List<TreeGridModel>();
  67. foreach (var item in list_ModuleInfoButton)
  68. {
  69. TreeGridModel treeModel = new TreeGridModel();
  70. treeModel.id = item.F_Id.ToString();
  71. treeModel.isLeaf = false;
  72. treeModel.parentId = "0";
  73. treeModel.expanded = false;
  74. treeModel.entityJson = item.ToJson();
  75. treeList.Add(treeModel);
  76. }
  77. return Content(treeList.TreeGridJson());
  78. }
  79. /// <summary>
  80. /// 获取菜单按钮实体
  81. /// </summary>
  82. /// <param name="mId"></param>
  83. /// <returns></returns>
  84. [HttpGet("getmodule")]
  85. public async Task<IActionResult> GetModuleAsync(int mid = 0)
  86. {
  87. var entity = (await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == mid && x.F_State != (int)EnumDelState.Delete));
  88. if (entity != null)
  89. {
  90. ModuleInfoButtonDto _dto = new ModuleInfoButtonDto
  91. {
  92. id = entity.F_Id,
  93. moduleid = entity.F_MenuId.Value,
  94. name = entity.F_ButtonName,
  95. jsevent = entity.F_JSEvent,
  96. code = entity.F_ButtonCode,
  97. icon = entity.F_Icon,
  98. url = entity.F_UrlAddress,
  99. flag = entity.F_State.Value,
  100. remark = entity.F_Remark,
  101. sort = entity.F_Sort.Value
  102. };
  103. return Success("加载按钮成功", _dto);
  104. }
  105. else
  106. {
  107. return Error("加载按钮失败");
  108. }
  109. }
  110. /// <summary>
  111. /// 添加按钮
  112. /// </summary>
  113. /// <param name="input"></param>
  114. /// <returns></returns>
  115. [HttpPost("addmodule")]
  116. public async Task<IActionResult> AddModule(ModuleInfoButtonDto input)
  117. {
  118. if (input.moduleid<=0)
  119. return Error("参数错误");
  120. if (string.IsNullOrEmpty(input.name))
  121. return Error("请输入按钮名称");
  122. if (string.IsNullOrEmpty(input.code))
  123. return Error("请输入按钮代码");
  124. var entity_ModuleInfoButton = new T_Sys_ModuleButtonInfo();
  125. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  126. entity_ModuleInfoButton.F_ButtonCode = input.code;
  127. entity_ModuleInfoButton.F_ButtonName = input.name;
  128. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  129. entity_ModuleInfoButton.F_Icon = input.icon;
  130. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  131. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  132. entity_ModuleInfoButton.F_Remark = input.remark;
  133. entity_ModuleInfoButton.F_Sort = input.sort;
  134. entity_ModuleInfoButton.F_CreateOn = DateTime.Now.ToLocalTime();
  135. entity_ModuleInfoButton.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  136. var res = await _sys_modulebuttoninfoRepository.Add(entity_ModuleInfoButton);
  137. if (res>0)
  138. {
  139. return Success("按钮添加成功");
  140. }
  141. else
  142. {
  143. return Error("菜单按钮添加失败,请重试!");
  144. }
  145. }
  146. /// <summary>
  147. /// 更新按钮
  148. /// </summary>
  149. /// <param name="input"></param>
  150. /// <returns></returns>
  151. [HttpPost("updatemodule")]
  152. public async Task<IActionResult> UpdateModule(ModuleInfoButtonDto input)
  153. {
  154. if(input.id<=0)
  155. return Error("参数错误");
  156. if (input.moduleid <= 0)
  157. return Error("菜单参数错误");
  158. if (string.IsNullOrEmpty(input.name))
  159. return Error("请输入按钮名称");
  160. if (string.IsNullOrEmpty(input.code))
  161. return Error("请输入按钮代码");
  162. var entity_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == input.id && x.F_State != (int)EnumDelState.Delete);
  163. if (entity_ModuleInfoButton == null)
  164. return Error("获取信息失败");
  165. entity_ModuleInfoButton.F_Id = input.id;
  166. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  167. entity_ModuleInfoButton.F_ButtonCode = input.code;
  168. entity_ModuleInfoButton.F_ButtonName = input.name;
  169. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  170. entity_ModuleInfoButton.F_Icon = input.icon;
  171. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  172. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  173. entity_ModuleInfoButton.F_Remark = input.remark;
  174. entity_ModuleInfoButton.F_Sort = input.sort;
  175. entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime();
  176. entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  177. if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton))
  178. {
  179. return Success("按钮修改成功");
  180. }
  181. else
  182. {
  183. return Error("按钮修改失败,请重试!");
  184. }
  185. }
  186. /// <summary>
  187. /// 删除菜单按钮
  188. /// </summary>
  189. /// <param name="ids"></param>
  190. /// <returns></returns>
  191. [HttpPost("delmodule")]
  192. public async Task<IActionResult> DelModuleAsync(int[] ids)
  193. {
  194. var res = 0;
  195. if (ids != null && ids.Length > 0)
  196. {
  197. foreach (var item in ids)
  198. {
  199. var ml = await _sys_modulebuttoninfoRepository.GetSingle(x => x.F_Id == item);
  200. ml.F_State = (int)EnumDelState.Delete;
  201. ml.F_DeleteOn = DateTime.Now.ToLocalTime();
  202. ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  203. if (_sys_modulebuttoninfoRepository.Update(ml).Result)
  204. res += 1;
  205. }
  206. if (res == ids.Length)
  207. return Success("删除成功");
  208. else if (res > 0 && res < ids.Length)
  209. return Error("部分删除失败,请查看后重新操作");
  210. else
  211. return Error("删除失败,请查看后重新操作");
  212. }
  213. else
  214. {
  215. return Error("请选择要删除的记录");
  216. }
  217. }
  218. /// <summary>
  219. /// 编辑菜单按钮
  220. /// </summary>
  221. /// <param name="input"></param>
  222. /// <returns></returns>
  223. [HttpPost("editmodule")]
  224. public async Task<IActionResult> EditModuleAsync(ModuleInfoButtonDto input)
  225. {
  226. if (input.id <= 0)
  227. return Error("参数错误");
  228. if (input.moduleid <= 0)
  229. return Error("菜单参数错误");
  230. if (string.IsNullOrEmpty(input.name))
  231. return Error("请输入按钮名称");
  232. if (string.IsNullOrEmpty(input.code))
  233. return Error("请输入按钮代码");
  234. var entity_ModuleInfoButton = await _sys_modulebuttoninfoRepository.GetSingle(x=>x.F_Id==input.id && x.F_State != (int)EnumDelState.Delete);
  235. if (entity_ModuleInfoButton != null)
  236. {
  237. entity_ModuleInfoButton.F_MenuId = input.moduleid;
  238. entity_ModuleInfoButton.F_ButtonCode = input.code;
  239. entity_ModuleInfoButton.F_ButtonName = input.name;
  240. entity_ModuleInfoButton.F_JSEvent = input.jsevent;
  241. entity_ModuleInfoButton.F_Icon = input.icon;
  242. entity_ModuleInfoButton.F_UrlAddress = HttpUtility.UrlDecode(input.url);
  243. entity_ModuleInfoButton.F_State = Convert.ToInt32(input.flag);
  244. entity_ModuleInfoButton.F_Remark = input.remark;
  245. entity_ModuleInfoButton.F_Sort = input.sort;
  246. entity_ModuleInfoButton.F_LastModifyOn = DateTime.Now.ToLocalTime();
  247. entity_ModuleInfoButton.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  248. if (await _sys_modulebuttoninfoRepository.Update(entity_ModuleInfoButton))
  249. {
  250. return Success("按钮修改成功");
  251. }
  252. else
  253. {
  254. return Error("按钮修改失败,请重试!");
  255. }
  256. }
  257. else
  258. {
  259. return Error("菜单对象获取失败");
  260. }
  261. }
  262. }
  263. }