123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Common.Wechat;
- using Common;
- using System.Data;
- using Common.Model;
- using ZcPeng.PublicLibrary;
- using CoreEntity.Entity;
- using CoreEntity.DAL;
- using System.Collections.Concurrent;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using System.Data.SqlClient;
- using Microsoft.Extensions.Primitives;
- using Microsoft.Extensions.Caching.Memory;
- using Jwt;
- using PublicLibrary.Model;
- using Newtonsoft.Json.Linq;
- using SupplierWeb.Codes.mvc;
- using SupplierWeb.Codes.Auth;
- using Common.Config;
- namespace SupplierWeb.Controllers
- {
- [Route("web/CM_Permission")]
- public class CM_PermissionController : BaseController
- {
- public CM_PermissionController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- private ConcurrentDictionary<String, CM_Permission> PermissionMap = new ConcurrentDictionary<String, CM_Permission>();
- /// <summary>
- /// 角色列表
- /// </summary>
- /// <param name="filters"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortField"></param>
- /// <param name="sortDirection"></param>
- /// <param name="sumFields"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("index")]
- public JsonResult Indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
- {
- //取出参数
- if (data != null)
- {
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取角色列表
- DataTable dt = new DataTable();
- string result;
- IList<CM_Permission> permss = new List<CM_Permission>(0);
- List<SqlParameter> parameters = new List<SqlParameter>();
- string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new CM_Permission(), "A.");
- string direct = " desc ";
- if (sortDirection != 1)
- {
- direct = " asc";
- }
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- string commandText0 = "select * from ";
- string commandText1 = "(" +
- "select A.*,row_number() over" +
- "( order by A.ModuleId " + direct + " ) as rownum from " +
- "CM_Permission as A " +
- " where 1=1 " +
- //" and A.CreationPerson = '" + userids + "'" +
- filterstr +
- ")AAA ";
- string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end;
- string commandText3 = commandText0 + commandText1 + commandText2;
- bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
- #endregion
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<Permission>
- permss = ModelConvertHelper<CM_Permission>.ConvertToModel(dt);
- #region 获取权限的角色列表,角色列表
- //角色列表
- IList<CM_Permission> Permissions = GetPermissions();
- // 把DataTable转换为IList<Permission>
- if (PermissionMap.Count < Permissions.Count)
- {
- foreach (CM_Permission Permission in Permissions)
- {
- PermissionMap.TryAdd(Permission.ModuleId, Permission);
- }
- }
- #region
- foreach (CM_Permission perms in permss)
- {
- string direct1 = " desc ";
- dt = DataAccess.GetDataTable("CM_Permission", "ModuleId", "*", "ModuleId=" + perms.ModuleId, "", "ModuleId" + direct1, 1, 100, out var msg);
- // 把DataTable转换为IList<PermissionRelatePermission>
- if (dt != null && dt.Rows.Count > 0)
- {
- IList<CM_Permission> permRelates = ModelConvertHelper<CM_Permission>.ConvertToModel(dt);
- List<CM_Permission> listPermissions = new List<CM_Permission>();
- List<int> superior_list = new List<int>(0);
- foreach (CM_Permission permsr in permRelates)
- {
- CM_Permission Permission;
- if (PermissionMap.TryGetValue(permsr.ModuleId, out Permission))
- {
- listPermissions.Add(Permission);
- }
- superior_list.Add(Convert.ToInt32(permsr.ModuleId));
- }
- //perms.PermissionList = listPermissions;
- perms.ModuleId = string.Join(",", superior_list.ToArray());
- }
- }
- #endregion
- #endregion
- }
- string result1;
- long totalcount = DataAccess.GetRowCountDefine("select count(ModuleId) from " + commandText1, parameters.ToArray(), out result1);
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- //IList<Menu> menus = Permission.Convert(permss);
- var jsonData = JsonConvert.SerializeObject(permss, timejson);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
- /// <summary>
- /// 新增角色
- /// </summary>
- /// <param name="ModuleId"></param>
- /// <param name="PermissionCode"></param>
- /// <param name="ModuleCode"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("add")]
- public JsonResult Addp(
- string ModuleId, string ParentModuleId,
- string ModuleCode, [FromBody]dynamic data
- )
- {
- if (data != null)
- {
- ModuleId = data.ModuleId;
- ParentModuleId = data.ParentModuleId;
- ModuleCode = data.ModuleCode;
- }
- #region 添加功能
- String uuid = System.Guid.NewGuid().ToString("N");
- string commandText = "INSERT INTO CM_Permission (ModuleId," +
- "ParentModuleId,ModuleCode)" +
- " VALUES ('" + uuid + "',@ParentModuleId,@ModuleCode)";
- string result;
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "ModuleId", uuid });
- parameters.Add(new List<Object>() { "ParentModuleId", ParentModuleId });
- parameters.Add(new List<Object>() { "ModuleCode", ModuleCode });
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- #endregion
- //#region 添加角色
- //int id = BaseDAL.GetId(Config.TablePrefix + "Permission");
- //PermissionDAL.SavePermissionsRelatePermission(id, ModuleIdis);
- //#endregion
- return Json(new
- {
- success = success
- });
- }
- /// <summary>
- /// 修改角色
- /// </summary>
- /// <param name="ModuleId"></param>
- /// <param name="PermissionCode"></param>
- /// <param name="ModuleCode"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("edit")]
- public JsonResult editp(String ModuleId, String ParentModuleId,
- string ModuleCode, [FromBody]dynamic data)
- {
- if (data != null)
- {
- ModuleId = data.ModuleId;
- ParentModuleId = data.ParentModuleId;
- ModuleCode = data.ModuleCode;
- }
- #region 编辑用户
- string commandText = "UPDATE CM_Permission " +
- " SET ParentModuleId = @ParentModuleId,ModuleCode = @ModuleCode WHERE ModuleId= @ModuleId";
- string result;
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "ModuleId", ModuleId });
- parameters.Add(new List<Object>() { "ParentModuleId", ParentModuleId });
- parameters.Add(new List<Object>() { "ModuleCode", ModuleCode });
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- #endregion
- return Json(new
- {
- success = success
- });
- }
- /// <summary>
- /// 删除角色
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("delete")]
- public ActionResult Delete(string id)
- {
- //准备SQL语句
- string commandText = "DELETE FROM CM_Permission WHERE ModuleId = @ModuleId";
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "ModuleId", id });
- string result = "";
- //转换参数
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- //执行并返回结果
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
-
- return Content("{success:" + success + "}");
- }
-
- public IList<CM_Permission> GetTopPermissions()
- {
- IList<CM_Permission> permsList = new List<CM_Permission>(0);
- DataTable dt = new DataTable();
- string result = string.Empty;
- var sortDirection = 1;
- var pageIndex = 1;
- var pageSize = Config.MaxPageSize;
- string direct = " desc ";
- if (sortDirection != 1)
- direct = " asc";
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- string commandText = "select * from (" +
- "select A.*, row_number() over" +
- "( order by A.ModuleId " + direct + " ) as rownum" +
- " from CM_Permission A ) AAA" +
- " where AAA.rownum>" + start + " and AAA.rownum<" + end +
- " ";
- List<List<Object>> parameters1 = new List<List<Object>>();
- parameters1.Add(new List<Object>() { "ModuleId", 0 });
- bool result1 = DataAccess.GetValues(commandText, ref dt, DataAccess.ToParameters(parameters1).ToArray(), out result);
- if (result1 && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<Permission>
- permsList = ModelConvertHelper<CM_Permission>.ConvertToModel(dt);
- }
- return permsList;
- }
- public static IList<CM_Permission> GetPermissions()
- {
- IList<CM_Permission> PermissionList = new List<CM_Permission>(0);
- DataTable result;
- string direct = " desc ";
- result = DataAccess.GetDataTable("CM_Permission", "Id", "ModuleId,ModuleCode,PermissionCode", "", "", "Id" + direct, 1, 100, out var msg);
- if (result != null && result.Rows.Count > 0)
- {
- // 把DataTable转换为IList<Permission>
- PermissionList = ModelConvertHelper<CM_Permission>.ConvertToModel(result);
- }
- return PermissionList;
- }
- }
- }
|