SysAdminRoleController.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * 后台角色
  3. */
  4. using System;
  5. using System.Web;
  6. using System.Collections.Generic;
  7. using Microsoft.AspNetCore.Mvc;
  8. using Microsoft.AspNetCore.Http;
  9. using MySystem.Models.Bs;
  10. using Library;
  11. using LitJson;
  12. using Microsoft.AspNetCore.Authorization;
  13. using MySystem.Service.Bs;
  14. using System.Linq;
  15. namespace MySystem.Areas.Api.Controllers.v1
  16. {
  17. [Area("Api")]
  18. [Route("/v1/QrCodePlateMain/[controller]/[action]")]
  19. public class SysAdminRoleController : BaseController
  20. {
  21. public SysAdminRoleController(IHttpContextAccessor accessor) : base(accessor)
  22. {
  23. }
  24. #region 系统管理-角色管理-角色列表
  25. [Authorize]
  26. public JsonResult SysAdminRoleList(string value)
  27. {
  28. value = PublicFunction.DesDecrypt(value);
  29. JsonData data = JsonMapper.ToObject(value);
  30. Dictionary<string, object> Other = new Dictionary<string, object>();
  31. List<Dictionary<string, object>> dataList = SysAdminRoleListDo(value, out Other);
  32. return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList, Other = Other });
  33. }
  34. private List<Dictionary<string, object>> SysAdminRoleListDo(string value, out Dictionary<string, object> Other)
  35. {
  36. JsonData data = JsonMapper.ToObject(value);
  37. string Name = data["Name"].ToString(); //角色名称
  38. int pageSize = int.Parse(function.CheckInt(data["page_size"].ToString()));
  39. int pageNum = int.Parse(function.CheckInt(data["page_num"].ToString()));
  40. List<RelationData> relationData = new List<RelationData>();
  41. List<Dictionary<string, object>> dataList = new List<Dictionary<string, object>>();
  42. string condition = "";
  43. if (!string.IsNullOrEmpty(data["Name"].ToString()))
  44. {
  45. condition += " and Name like '%" + Name + "%'";
  46. }
  47. Other = new Dictionary<string, object>();
  48. int count = 0;
  49. List<Dictionary<string, object>> source = SysAdminRoleService.List(relationData, condition, out count, pageNum, pageSize);
  50. foreach (Dictionary<string, object> subdata in source)
  51. {
  52. Dictionary<string, object> curData = new Dictionary<string, object>();
  53. curData.Add("Id", int.Parse(subdata["Id"].ToString())); //Id
  54. curData.Add("Name", subdata["Name"].ToString()); //角色名称
  55. curData.Add("Details", subdata["Details"].ToString()); //描述
  56. curData.Add("RightInfo", subdata["RightInfo"].ToString()); //权限字符串
  57. dataList.Add(curData);
  58. }
  59. Other.Add("Count", count); //总数
  60. return dataList;
  61. }
  62. #endregion
  63. #region 系统管理-角色管理-添加系统角色信息
  64. [Authorize]
  65. public JsonResult AddSysAdminRoleInfo(string value)
  66. {
  67. value = PublicFunction.DesDecrypt(value);
  68. JsonData data = JsonMapper.ToObject(value);
  69. AppResultJson result = AddSysAdminRoleInfoDo(value);
  70. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  71. }
  72. private AppResultJson AddSysAdminRoleInfoDo(string value)
  73. {
  74. JsonData data = JsonMapper.ToObject(value);
  75. string Name = data["Name"].ToString(); //角色名称
  76. string Details = data["Details"].ToString(); //详情
  77. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  78. Dictionary<string, object> fields = new Dictionary<string, object>();
  79. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  80. fields.Add("CreateMan", sys.AdminName + "_" + sys.RealName); //操作人
  81. fields.Add("Name", Name); //角色名称
  82. fields.Add("Details", Details); //详情
  83. fields.Add("RightInfo", RightInfo); //权限字符串
  84. var Id = int.Parse(SysAdminRoleService.Add(fields).Data.ToString());
  85. if (Id > 0)
  86. {
  87. return new AppResultJson() { Status = "1", Info = "成功", Data = Id };
  88. }
  89. else
  90. {
  91. return new AppResultJson() { Status = "-1", Info = "失败", Data = Id };
  92. }
  93. }
  94. #endregion
  95. #region 系统管理-角色管理-编辑系统角色信息
  96. [Authorize]
  97. public JsonResult EditSysAdminRoleInfo(string value)
  98. {
  99. value = PublicFunction.DesDecrypt(value);
  100. JsonData data = JsonMapper.ToObject(value);
  101. AppResultJson result = EditSysAdminRoleInfoDo(value);
  102. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  103. }
  104. private AppResultJson EditSysAdminRoleInfoDo(string value)
  105. {
  106. JsonData data = JsonMapper.ToObject(value);
  107. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  108. string Name = data["Name"].ToString(); //角色名称
  109. string Details = data["Details"].ToString(); //详情
  110. string RightInfo = data["RightInfo"].ToString(); //权限字符串
  111. var sysAdminRole = bsdb.SysAdminRole.FirstOrDefault(m => m.Id == SysAdminRoleId) ?? new SysAdminRole();
  112. if (sysAdminRole.Id > 0)
  113. {
  114. var sys = SysAdminService.Query(AppConfig.LoginSession.sysId);
  115. sysAdminRole.UpdateMan = sys.AdminName + "_" + sys.RealName;
  116. if (!string.IsNullOrEmpty(Name))
  117. {
  118. sysAdminRole.Name = Name;
  119. }
  120. if (!string.IsNullOrEmpty(Details))
  121. {
  122. sysAdminRole.Details = Details;
  123. }
  124. if (!string.IsNullOrEmpty(RightInfo))
  125. {
  126. sysAdminRole.RightInfo = RightInfo;
  127. }
  128. }
  129. bsdb.SaveChanges();
  130. return new AppResultJson() { Status = "1", Info = "成功" };
  131. }
  132. #endregion
  133. #region 系统管理-角色管理-删除系统角色信息
  134. [Authorize]
  135. public JsonResult DeleteSysAdminRoleInfo(string value)
  136. {
  137. value = PublicFunction.DesDecrypt(value);
  138. JsonData data = JsonMapper.ToObject(value);
  139. AppResultJson result = DeleteSysAdminRoleInfoDo(value);
  140. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  141. }
  142. private AppResultJson DeleteSysAdminRoleInfoDo(string value)
  143. {
  144. JsonData data = JsonMapper.ToObject(value);
  145. int SysAdminRoleId = int.Parse(data["SysAdminRoleId"].ToString()); //角色Id
  146. SysAdminRoleService.Delete(SysAdminRoleId);
  147. return new AppResultJson() { Status = "1", Info = "成功" };
  148. }
  149. #endregion
  150. }
  151. }