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

ModuleButtonInfoController.cs 12KB

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