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.IO; using System.Text; using Newtonsoft.Json; using System.Data; using ZcPeng.PublicLibrary; using CoreEntity.Entity; using CoreEntity.DAL; using Common.Model; using Newtonsoft.Json.Converters; using System.Data.SqlClient; using SupplierWeb.Codes.mvc; using System.Collections.Concurrent; using Microsoft.Extensions.Caching.Memory; using Microsoft.AspNetCore.Authorization; using PublicLibrary.Common; using PublicLibrary.Model; using Microsoft.Extensions.Primitives; using LigerRM.Common; namespace SupplierWeb.Controllers { [Route("web/user")] ///超级管理员,采购管理员能进入查看账户号,密码等 public class UserController : BaseController { public UserController(IMemoryCache cache, IApiClient client) : base(cache, client) { } private ConcurrentDictionary roleMap = new ConcurrentDictionary(); ////内部管理用户列表 //[HttpGet, Route("index")] //public ActionResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize, // string sortField, Int32 sortDirection, string[] sumFields, string callback) //{ // var r = this.indexp(filters, pageIndex, pageSize, // sortField, sortDirection, sumFields,null); // return Content(callback + "(" + JsonConvert.SerializeObject(r.Value) // + ")"); //} ////内部管理用户列表 [AuthPermission] [HttpPost, Route("index/{roleId}/{staffId}")] public JsonResult indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize, string sortField, Int32 sortDirection, string[] sumFields, string roleId, string staffId, [FromBody]dynamic data) { string roleIdstr = getStaff(staffId, "roleid"); string useridstr = getStaff(staffId, "userid"); //判断参数是否合法 if (string.IsNullOrEmpty(roleIdstr)) { return Json(new { timeout = 1, msg = "没有登陆" }); } if (data != null) { //Newtonsoft.Json.Linq.JArray filters = data.filters.ToObject(); pageIndex = data.pageIndex; pageSize = data.pageSize; sortField = data.sortField; sortDirection = data.sortDirection; sumFields = data.sumFields.ToObject(); } #region 获取user List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Account()); if (roleId == "" || roleId == null) { filterstr += " and roleid != 3 "; } else if (roleId == "2") { filterstr += " and roleid = " + roleId; } else { filterstr += " and roleid != 3 " + " and roleid in(1,6,7)"; } if (roleIdstr != "1" && roleIdstr != "6" && roleIdstr != "7") { filterstr += " and id = " + useridstr; } DataTable dt = new DataTable(); string result = string.Empty; 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 *, row_number() over" + "( order by " + sortField + " " + direct + " ) as rownum" + " from " + Config.TablePrefix + "Account " + " where 1 = 1 " + filterstr + ")AAA"; string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end + " "; string commandText3 = commandText0 + commandText1 + commandText2;//-tanyang bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result); #endregion // 把DataTable转换为IList IList users = new List(); if (dt != null && dt.Rows.Count > 0) { // 把DataTable转换为IList users = ModelConvertHelper.ConvertToModel(dt); } IList roles = RoleDAL.GetRoles(); if (roleMap.Count < roles.Count) { foreach (Role role in roles) { roleMap.TryAdd(role.Id, role); } } string result1; long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1, parameters.ToArray(), out result1); foreach (Account user in users) { Role role; if (roleMap.TryGetValue(user.RoleId, out role)) { user.RoleName = role.RoleRemark; } } IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; var jsonData = JsonConvert.SerializeObject(users, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } [AuthPermission] [HttpPost, Route("index")] public JsonResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize, string sortField, Int32 sortDirection, string[] sumFields, string roleId, string staffId, [FromBody]dynamic data) { //string roleIdstr = getStaff(staffId, "roleid"); string useridstr = getStaff(staffId, "userid"); //判断参数是否合法 if (string.IsNullOrEmpty(useridstr)) { return Json(new { timeout = 1, msg = "没有登陆" }); } if (data != null) { //Newtonsoft.Json.Linq.JArray filters = data.filters.ToObject(); pageIndex = data.pageIndex; pageSize = data.pageSize; sortField = data.sortField; sortDirection = data.sortDirection; sumFields = data.sumFields.ToObject(); } #region 获取user List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Account()); DataTable dt = new DataTable(); string result = string.Empty; 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 *, row_number() over" + "( order by " + sortField + " " + direct + " ) as rownum" + " from " + Config.TablePrefix + "Account " + " where 1 = 1 " + filterstr + ")AAA"; string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end + " "; string commandText3 = commandText0 + commandText1 + commandText2;//-tanyang bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result); #endregion // 把DataTable转换为IList IList users = new List(); if (dt != null && dt.Rows.Count > 0) { // 把DataTable转换为IList users = ModelConvertHelper.ConvertToModel(dt); } IList roles = RoleDAL.GetRoles(); if (roleMap.Count < roles.Count) { foreach (Role role in roles) { roleMap.TryAdd(role.Id, role); } } string result1; long totalcount = DataAccess.GetRowCountDefine("select count(*) from (" + commandText1, parameters.ToArray(), out result1); foreach (Account user in users) { Role role; if (roleMap.TryGetValue(user.RoleId, out role)) { user.RoleName = role.RoleRemark; } } IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; var jsonData = JsonConvert.SerializeObject(users, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } ////角色列表 [AllowAnonymous] [HttpGet, Route("role/{0}")] public ActionResult role(string callback) { #region 获取role IList roles = RoleDAL.GetRoles(); #endregion IList