CM_OrgManPermissionController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using System.Data;
  11. using Common.Model;
  12. using ZcPeng.PublicLibrary;
  13. using CoreEntity.Entity;
  14. using CoreEntity.DAL;
  15. using System.Collections.Concurrent;
  16. using Newtonsoft.Json.Converters;
  17. using Newtonsoft.Json;
  18. using System.Data.SqlClient;
  19. using Microsoft.Extensions.Primitives;
  20. using Microsoft.Extensions.Caching.Memory;
  21. using Jwt;
  22. using PublicLibrary.Model;
  23. using Newtonsoft.Json.Linq;
  24. using SupplierWeb.Codes.mvc;
  25. using SupplierWeb.Codes.Auth;
  26. using Common.Config;
  27. namespace SupplierWeb.Controllers
  28. {
  29. [Route("web/CM_OrgManPermission")]
  30. public class CM_OrgManPermissionController : BaseController
  31. {
  32. public CM_OrgManPermissionController(IMemoryCache cache, IApiClient client) : base(cache, client)
  33. {
  34. }
  35. private ConcurrentDictionary<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
  36. public class TempTableResult
  37. {
  38. public int id { get; set; }
  39. public string permissionName { get; set; }
  40. public string permissionUrl { get; set; }
  41. public int roleId { get; set; }
  42. public int checkedValue { get; set; }
  43. public string permissionRule { get; set; }
  44. public string permissionRuleType { get; set; }
  45. public int relateId { get; set; }
  46. public string AuthType { get; set; }
  47. }
  48. public class TreeNode
  49. {
  50. public string parentValue { get; set; }
  51. public string label { get; set; }
  52. public int value { get; set; }
  53. }
  54. public class TempQuery
  55. {
  56. public int[] data { get; set; }
  57. public int OrgId { get; set; }
  58. }
  59. public class SortContent
  60. {
  61. public Object content { get; set; }//权限内容
  62. public string code { get; set; }//权限id
  63. public int sort { get; set; }//权限序号
  64. }
  65. /// 供应商,采购,供应商业务员挂靠,资料管理员,财务,仓库 等角色权限列表
  66. /// 权限列表
  67. //[HttpGet, Route("index")]
  68. //public ActionResult index(string[] filters, Int32 pageIndex, Int32 pageSize,
  69. // string sortField, Int32 sortDirection, string[] sumFields, string callback)
  70. //{
  71. // var r = this.indexp(filters, pageIndex, pageSize,
  72. // sortField, sortDirection, sumFields, null);
  73. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  74. // + ")");
  75. //}
  76. /// 供应商,采购,供应商业务员挂靠,资料管理员,财务,仓库 等角色权限列表
  77. /// 权限列表
  78. [AuthPermission]
  79. [HttpPost, Route("index")]
  80. public JsonResult indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  81. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  82. {
  83. if (data != null)
  84. {
  85. //Newtonsoft.Json.Linq.JArray
  86. filters = data.filters.ToObject<QueryFilter[]>();
  87. pageIndex = data.pageIndex;
  88. pageSize = data.pageSize;
  89. sortField = data.sortField;
  90. sortDirection = data.sortDirection;
  91. sumFields = data.sumFields.ToObject<string[]>();
  92. }
  93. #region 获取权限列表
  94. DataTable dt = new DataTable();
  95. string result;
  96. IList<Permission> permss = new List<Permission>(0);
  97. List<SqlParameter> parameters = new List<SqlParameter>();
  98. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Permission(), "A.");
  99. string direct = " desc ";
  100. if (sortDirection != 1)
  101. direct = " asc";
  102. int start = (pageIndex - 1) * pageSize;
  103. int end = (start + 1 + pageSize);
  104. string commandText0 = "select * from ";
  105. string commandText1 = "(" +
  106. "select A.*,row_number() over" +
  107. "( order by " + sortField + " " + direct + " ) as rownum from " +
  108. Config.TablePrefix + "Permission as A " +
  109. " where 1=1 " +
  110. filterstr +
  111. ")AAA ";
  112. string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end;
  113. string commandText3 = commandText0 + commandText1 + commandText2;//-tanyang
  114. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  115. #endregion
  116. if (dt != null && dt.Rows.Count > 0)
  117. {
  118. // 把DataTable转换为IList<Permission>
  119. permss = ModelConvertHelper<Permission>.ConvertToModel(dt);
  120. #region 获取权限的角色列表,角色列表
  121. //角色列表
  122. IList<Role> roles = RoleDAL.GetRoles();
  123. // 把DataTable转换为IList<Role>
  124. if (roleMap.Count < roles.Count)
  125. {
  126. foreach (Role role in roles)
  127. {
  128. roleMap.TryAdd(role.Id, role);
  129. }
  130. }
  131. foreach (Permission perms in permss)
  132. {
  133. string direct1 = " desc ";
  134. dt = DataAccess.GetDataTable(Config.TablePrefix + "RoleRelatePermission", "Id", "*", "PermissionId=" + perms.Id + " and IsDelete = 0 ", "", "Id" + direct1, 1, 100, out var msg);
  135. // 把DataTable转换为IList<RoleRelatePermission>
  136. if (dt != null && dt.Rows.Count > 0)
  137. {
  138. IList<RoleRelatePermission> permRelates = ModelConvertHelper<RoleRelatePermission>.ConvertToModel(dt);
  139. List<int> superior_list = new List<int>(0);
  140. foreach (RoleRelatePermission permsr in permRelates)
  141. {
  142. superior_list.Add(permsr.RoleId);
  143. }
  144. //perms.RoleList = listRoles;
  145. perms.Roleids = string.Join(",", superior_list.ToArray());
  146. }
  147. }
  148. #endregion
  149. }
  150. string result1;
  151. long totalcount = DataAccess.GetRowCountDefine("select count(Id) from " + commandText1, parameters.ToArray(), out result1);
  152. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  153. {
  154. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  155. };
  156. //IList<Menu> menus = Permission.Convert(permss);
  157. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  158. return Json(new
  159. {
  160. items = JsonConvert.DeserializeObject(jsonData),
  161. sum = new { },
  162. totalCount = totalcount
  163. });
  164. }
  165. /// <summary>
  166. /// 新增
  167. /// </summary>
  168. /// <param name="PermissionName"></param>
  169. /// <param name="PermissionUrl"></param>
  170. /// <param name="AuthType"></param>
  171. /// <param name="ActionType"></param>
  172. /// <param name="Icon"></param>
  173. /// <param name="ParentId"></param>
  174. /// <param name="Roleids"></param>
  175. /// <param name="data"></param>
  176. /// <param name="IsDelete"></param>
  177. /// <returns></returns>
  178. [AuthPermission]
  179. [HttpPost, Route("add")]
  180. public JsonResult addp(
  181. string PermissionName, string PermissionUrl,
  182. string AuthType, Int32 ActionType,
  183. string Icon
  184. , string ParentId, string Roleids, [FromBody]dynamic data
  185. , Int32 IsDelete = 0
  186. )
  187. {
  188. if (data != null)
  189. {
  190. //Newtonsoft.Json.Linq.JArray
  191. PermissionName = data.PermissionName;
  192. PermissionUrl = data.PermissionUrl;
  193. AuthType = data.AuthType;
  194. if (ActionType != 0)
  195. {
  196. ActionType = data.ActionType;
  197. }
  198. Icon = data.Icon;
  199. ParentId = data.ParentId;
  200. Roleids = data.Roleids;
  201. IsDelete = (data.IsDelete == null) ? 0 : data.IsDelete;
  202. }
  203. string[] RoleIdss = Roleids.Split(",");
  204. int[] RoleIdis = Array.ConvertAll(RoleIdss, s => Convert.ToInt32(s));
  205. #region 添加权限节点
  206. string commandText = "INSERT INTO " + Config.TablePrefix + "Permission (permissionname,permissionurl," +
  207. "AuthType,ActionType," +
  208. "Icon,ParentId," +
  209. "isdelete)"
  210. + " VALUES (@permissionname,@permissionurl,@AuthType,@ActionType,@Icon,@ParentId,@isdelete)";
  211. string result;
  212. //准备参数
  213. List<List<Object>> parameters = new List<List<Object>>();
  214. parameters.Add(new List<Object>() { "permissionname", PermissionName });
  215. parameters.Add(new List<Object>() { "permissionurl", PermissionUrl });
  216. parameters.Add(new List<Object>() { "AuthType", AuthType });
  217. parameters.Add(new List<Object>() { "ActionType", ActionType });
  218. parameters.Add(new List<Object>() { "Icon", Icon });
  219. parameters.Add(new List<Object>() { "ParentId", ParentId != null ? Convert.ToInt32(ParentId) : 0 });
  220. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  221. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  222. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  223. #endregion
  224. #region 添加角色
  225. int id = BaseDAL.GetId(Config.TablePrefix + "Permission");
  226. RoleDAL.SaveRolesRelatePermission(id, RoleIdis);
  227. #endregion
  228. return Json(new
  229. {
  230. success = success
  231. });
  232. }
  233. ////编辑权限
  234. //[HttpGet, Route("edit")]
  235. //public ActionResult edit(Int32 Id,
  236. // string PermissionName, string PermissionUrl, string Icon
  237. // , string ParentId, string Roleids
  238. // , string callback, Int32 IsDelete
  239. // )
  240. //{
  241. // var r = this.editp(Id, PermissionName, PermissionUrl, Icon
  242. // , ParentId, Roleids, null
  243. // , IsDelete);
  244. // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value)
  245. // + ")");
  246. //}
  247. [AuthPermission]
  248. [HttpPost, Route("edit")]
  249. public JsonResult editp(Int32 Id,
  250. string PermissionName, string PermissionUrl,
  251. string AuthType,
  252. string Icon,
  253. string ParentId, string Roleids,
  254. [FromBody]dynamic data
  255. , Int32 IsDelete
  256. )
  257. {
  258. if (data != null)
  259. {
  260. //Newtonsoft.Json.Linq.JArray
  261. Id = data.Id;
  262. PermissionName = data.PermissionName;
  263. PermissionUrl = data.PermissionUrl;
  264. AuthType = data.AuthType;
  265. Icon = data.Icon;
  266. ParentId = data.ParentId;
  267. Roleids = data.Roleids;
  268. IsDelete = data.IsDelete == null ? 0 : data.IsDelete;
  269. }
  270. string[] RoleIdss = Roleids.Split(",");
  271. int[] RoleIdis = Array.ConvertAll(RoleIdss, s => Convert.ToInt32(s));
  272. #region 编辑用户
  273. string commandText = "UPDATE " + Config.TablePrefix + "Permission " +
  274. " SET permissionname = @permissionname,";
  275. if (PermissionUrl != null)
  276. commandText += "permissionurl = @permissionurl,";
  277. commandText += " ParentId = @ParentId" +
  278. ",Icon = @Icon" +
  279. " ,isdelete = @isdelete" +
  280. ",AuthType = @AuthType" +
  281. " WHERE id= @Id";
  282. string result;
  283. //准备参数
  284. List<List<Object>> parameters = new List<List<Object>>();
  285. parameters.Add(new List<Object>() { "permissionname", PermissionName });
  286. parameters.Add(new List<Object>() { "permissionurl", PermissionUrl });
  287. parameters.Add(new List<Object>() { "AuthType", AuthType });
  288. parameters.Add(new List<Object>() { "ParentId", ParentId });
  289. parameters.Add(new List<Object>() { "Icon", Icon });
  290. parameters.Add(new List<Object>() { "isdelete", IsDelete });
  291. parameters.Add(new List<Object>() { "Id", Id });
  292. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  293. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  294. #endregion
  295. #region 角色
  296. RoleDAL.SaveRolesRelatePermission(Id, RoleIdis);
  297. #endregion
  298. return Json(new
  299. {
  300. success = success
  301. });
  302. }
  303. /// <summary>
  304. /// 删除权限
  305. /// </summary>
  306. /// <param name="Id"></param>
  307. /// <param name="callback"></param>
  308. /// <returns></returns>
  309. [AuthPermission]
  310. [HttpGet, Route("delete/{0}")]
  311. public ActionResult Delete(Int32 Id, string callback)
  312. {
  313. string commandText = "DELETE FROM " + Config.TablePrefix + "Permission WHERE Id = @Id";
  314. //准备参数
  315. List<List<Object>> parameters = new List<List<Object>>();
  316. parameters.Add(new List<Object>() { "Id", Id });
  317. string result = "";
  318. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  319. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  320. return Content(callback + "({"
  321. + success
  322. + "})");
  323. }
  324. /// <summary>
  325. /// 删除权限
  326. /// </summary>
  327. /// <param name="Id"></param>
  328. /// <returns></returns>
  329. [AuthPermission]
  330. [HttpPost, Route("delete")]
  331. public ActionResult Delete(Int32 Id)
  332. {
  333. string commandText = "DELETE FROM " + Config.TablePrefix + "Permission WHERE Id = @Id";
  334. //准备参数
  335. List<List<Object>> parameters = new List<List<Object>>();
  336. parameters.Add(new List<Object>() { "Id", Id });
  337. string result = "";
  338. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  339. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  340. return Content("{success:"
  341. + success
  342. + "}");
  343. }
  344. /// <summary>
  345. /// 权限列表
  346. /// </summary>
  347. /// <param name="staffid"></param>
  348. /// <returns></returns>
  349. [HttpGet, Route("menus")]
  350. public ActionResult menus(string staffid)
  351. {
  352. HttpRequest request = HttpContext.Request;
  353. StringValues oo;
  354. request.Headers.TryGetValue("token", out oo);
  355. if (oo.Count > 0 && oo.ToArray()[0] != "")
  356. {
  357. staffid = oo.ToArray()[0];
  358. }
  359. //取token
  360. var token = (string)_cache.Get(staffid);
  361. var secret = TokenConfig.SecretKey;
  362. Dictionary<string, object> data;
  363. Object roleid;
  364. Int64 roleid1;
  365. string jsonData = "";
  366. if (token != null)
  367. {
  368. try
  369. {
  370. data = JsonWebToken.DecodeToObject<Dictionary<string, object>>(token, secret);
  371. data.TryGetValue("roleid", out roleid);
  372. roleid1 = (Int64)roleid;
  373. var options = RoleDAL.GetPermissions(roleid1);
  374. var permissions = Permission.Convert(options);
  375. jsonData = JsonConvert.SerializeObject(permissions);
  376. }
  377. catch (SignatureVerificationException)
  378. {
  379. // Given token is either expired or hashed with an unsupported algorithm.
  380. }
  381. }
  382. return Content(jsonData
  383. );
  384. }
  385. /// <summary>
  386. /// 权限列表
  387. /// </summary>
  388. /// <param name="staffid"></param>
  389. /// <param name="callback"></param>
  390. /// <returns></returns>
  391. [HttpGet, Route("menus1")]
  392. public ActionResult menus1(string staffid, string callback)
  393. {
  394. var jsonData = "";
  395. return Content(callback + "(" + jsonData
  396. + ")");
  397. }
  398. /// <summary>
  399. /// 父权限列表
  400. /// </summary>
  401. /// <param name="callback"></param>
  402. /// <returns></returns>
  403. [HttpGet, Route("parents/{0}")]
  404. public ActionResult parents(string callback)
  405. {
  406. var permss = RoleDAL.GetTopPermissions();
  407. IList<Option> options = new List<Option>();
  408. foreach (Permission perms in permss)
  409. {
  410. var option = new Option() { label = perms.PermissionName, value = perms.Id.ToString(), disabled = perms.IsDelete };
  411. options.Add(option);
  412. }
  413. var jsonData = JsonConvert.SerializeObject(options);
  414. return Content(callback + "(" + jsonData
  415. + ")");
  416. }
  417. /// <summary>
  418. /// 父权限列表
  419. /// </summary>
  420. /// <returns></returns>
  421. [HttpGet, Route("parents")]
  422. public ActionResult parents()
  423. {
  424. var permss = RoleDAL.GetTopPermissions();
  425. IList<Option> options = new List<Option>();
  426. foreach (Permission perms in permss)
  427. {
  428. var option = new Option() { label = perms.PermissionName, value = perms.Id.ToString(), disabled = perms.IsDelete };
  429. options.Add(option);
  430. }
  431. var jsonData = JsonConvert.SerializeObject(options);
  432. return Content(jsonData
  433. );
  434. }
  435. /// <summary>
  436. /// 获取组织机构
  437. /// </summary>
  438. /// <returns></returns>
  439. [HttpGet]
  440. [Route("getOrg")]
  441. public JsonResult getOrg()
  442. {
  443. var sql = $"select OrgName as label,'1' as parentValue,(ROW_NUMBER() over(order by OrgId))+1 as value from CM_Org";
  444. DataTable dt = new DataTable();
  445. var param = new List<SqlParameter>();
  446. DataAccess.GetValues(sql, ref dt, param.ToArray(), out _);
  447. IList<TreeNode> result = new List<TreeNode>();
  448. if (dt != null && dt.Rows.Count > 0)
  449. {
  450. result = ModelConvertHelper<TreeNode>.ConvertToModel(dt);
  451. }
  452. result.Add(new TreeNode { parentValue = "0", label = "亮健好医药有限公司", value = 1 });
  453. return Json(new
  454. {
  455. //httpCode = 200,
  456. //message = "获取成功",
  457. result
  458. });
  459. }
  460. /// <summary>
  461. /// 根据角色查询功能列表
  462. /// </summary>
  463. /// <param name="data"></param>
  464. /// <returns></returns>
  465. [AuthPermission]
  466. [HttpPost]
  467. [Route("table")]
  468. public JsonResult Table([FromBody] dynamic data)
  469. {
  470. QueryFilter[] jArray = JsonConvert.DeserializeObject<QueryFilter[]>(data.filters.ToString());
  471. var a = "";
  472. List<QueryFilter> filterList = new List<QueryFilter>();
  473. var i = 0;
  474. foreach (QueryFilter filter in jArray)
  475. {
  476. if (filter.field == "OrgId")
  477. a = filter.value.ToString();
  478. else
  479. {
  480. filterList.Add(filter);
  481. i++;
  482. }
  483. }
  484. var OrgId = int.Parse(a) - 1;
  485. var param = new List<SqlParameter>();
  486. var filterstr = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param, new TempTableResult(), "A.");
  487. filterstr = filterstr.Replace("A.permissionRule", "B.PermissionRule");
  488. filterstr = filterstr.Replace("A.permissionRuleType", "B.PermissionRuleType");
  489. var sql = $"select case when B.orgmanmoduleId is null then 0 else A.id end as checkedValue,A.*," +
  490. $"B.OrgManModuleId as relateId from sup_Permission A left join CM_OrgManPermission B on " +
  491. $"B.MODULEID = A.Id and B.OrgId='"+ OrgId + "' where A.IsDelete <> 1" +
  492. $"" + filterstr;
  493. DataTable dt = new DataTable();
  494. param.Add(new SqlParameter("OrgId", OrgId));
  495. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  496. IList<TempTableResult> result = new List<TempTableResult>();
  497. if (dt != null && dt.Rows.Count > 0)
  498. {
  499. result = ModelConvertHelper<TempTableResult>.ConvertToModel(dt);
  500. }
  501. var countSql =
  502. $"select count(1) from sup_Permission where IsDelete <> 1";
  503. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out var msg1);
  504. return Json(new
  505. {
  506. items = result,
  507. sum = new { },
  508. totalCount = count,
  509. msg
  510. });
  511. }
  512. [AuthPermission]
  513. [HttpPost]
  514. [Route("setOrg")]
  515. public JsonResult setOrg([FromBody] TempQuery data)
  516. {
  517. var param = new List<SqlParameter>();
  518. param.Add(new SqlParameter("OrgId", data.OrgId));
  519. string uuid = System.Guid.NewGuid().ToString("N");
  520. var sql = "update CM_OrgManPermission set IsDelete =1 where OrgId=@OrgId; ";
  521. var index = 0;
  522. foreach (var item in data.data)
  523. {
  524. index++;
  525. param.Add(new SqlParameter($"{index}", item));
  526. sql += $" if (exists(select * from CM_OrgManPermission where OrgId = @OrgId and ModuleId = '"+index+"' and IsDelete = 1)) " +
  527. " begin " +
  528. $" update CM_OrgManPermission set IsDelete = 0 where OrgId = @OrgId and ModuleId = '" + index + "'} and IsDelete = 1 " +
  529. " end " +
  530. " else " +
  531. " begin " +
  532. $" insert into CM_OrgManPermission (OrgManModuleId,ModuleId, OrgId) values ('"+uuid+ "','" + index + "',@OrgId) end ";
  533. }
  534. DataAccess.ExecuteCommand(sql, param.ToArray(), out var x);
  535. return Json(new
  536. {
  537. success = true
  538. });
  539. }
  540. [HttpGet, Route("authtype")]
  541. public ActionResult AuthType()
  542. {
  543. IList<Option> options = new List<Option>();
  544. var option = new Option() { label = "界面", value = "U", disabled = false };
  545. options.Add(option);
  546. var option1 = new Option() { label = "操作", value = "O", disabled = false };
  547. options.Add(option1);
  548. var option2 = new Option() { label = "按钮", value = "A", disabled = false };
  549. options.Add(option2);
  550. var jsonData = JsonConvert.SerializeObject(options);
  551. return Content(jsonData
  552. );
  553. }
  554. [HttpGet, Route("permissions")]
  555. public ActionResult Permissions()
  556. {
  557. string roleid = getStaff("roleid");
  558. if (roleid == null || roleid == "")
  559. {
  560. return Json(new { success = false, msg = "没有登陆" });
  561. }
  562. Dictionary<string, Permission> permission = PermissionHelper.Permissions(Convert.ToInt32(roleid));
  563. return Json(permission);
  564. }
  565. [AuthPermission]
  566. [HttpPost]
  567. [Route("setSort")]
  568. public JsonResult setSort([FromBody]dynamic data)
  569. {
  570. SortContent[] dataItems = new SortContent[] { };
  571. if (data != null)
  572. {
  573. //Newtonsoft.Json.Linq.JArray
  574. dataItems = data.data.ToObject<SortContent[]>();
  575. }
  576. List<DataAccessCommand> list = new List<DataAccessCommand>();
  577. foreach (SortContent item in dataItems)
  578. {
  579. var param = new List<SqlParameter>();
  580. param.Add(new SqlParameter("Id", item.code));
  581. param.Add(new SqlParameter("Sort", item.sort));
  582. var sql = "update " + Config.TablePrefix + "Permission set Sort=@Sort where Id=@Id; ";
  583. list.Add(new DataAccessCommand(sql, param, CommandType.Text, false));
  584. }
  585. var success = DataAccess.ExecuteBatchCommands(list, out var x);
  586. return Json(new
  587. {
  588. success,
  589. msg = x
  590. });
  591. }
  592. [AuthPermission]
  593. [HttpPost]
  594. [Route("editroleperm")]
  595. public JsonResult editRolePerm([FromBody] TempTableResult entity)
  596. {
  597. var sql = "update " + Config.TablePrefix + "RoleRelatePermission set " +
  598. " PermissionRule = a1,PermissionRuleType = a2 " +
  599. " from (select @PermissionRule as a1 ,@PermissionRuleType as a2 )A " +
  600. " where Id = @relateId";
  601. var param = new List<SqlParameter>();
  602. param.Add(new SqlParameter("@PermissionRule", entity.permissionRule));
  603. param.Add(new SqlParameter("@PermissionRuleType", entity.permissionRuleType));
  604. var ss = new SqlParameter("@relateId", SqlDbType.Int);
  605. ss.Value = entity.relateId;
  606. param.Add(ss);
  607. List<DataAccessCommand> list = new List<DataAccessCommand>(0);
  608. list.Add(new DataAccessCommand(sql, param, CommandType.Text, false));
  609. var success = DataAccess.ExecuteBatchCommands(list, out var msg);
  610. return Json(new
  611. {
  612. success,
  613. msg
  614. });
  615. }
  616. [AuthPermission]
  617. [HttpGet]
  618. [Route("getruletype")]
  619. public ActionResult getRuleType()
  620. {
  621. IList<Option> options = new List<Option>();
  622. var option = new Option() { label = "SQL", value = "S", disabled = false };
  623. options.Add(option);
  624. var option1 = new Option() { label = "JSON", value = "J", disabled = false };
  625. options.Add(option1);
  626. var jsonData = JsonConvert.SerializeObject(options);
  627. return Content(jsonData
  628. );
  629. }
  630. }
  631. }