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/Mem_ProductCategory")] public class mem_ProductCategoryController : BaseController { public mem_ProductCategoryController(IMemoryCache cache, IApiClient client) : base(cache, client) { } private ConcurrentDictionary Mem_ProductCategoryMap = new ConcurrentDictionary(); /// /// 获取组织机构列表 /// /// /// /// /// /// /// /// /// [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(); pageIndex = data.pageIndex; pageSize = data.pageSize; sortField = data.sortField; sortDirection = data.sortDirection; sumFields = data.sumFields.ToObject(); } #region 获取机构列表 DataTable dt = new DataTable(); string result; IList permss = new List(0); List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_ProductCategory(), "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.CategoryCode " + direct + " ) as rownum from " + "Mem_ProductCategory as A " + " where 1=1 " + //" and A.CreationPerson = '" + userids + "'" + filterstr + ")AAA "; string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end + " ORDER BY AAA.CategoryCode desc"; 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 permss = ModelConvertHelper.ConvertToModel(dt); } string result1; long totalcount = DataAccess.GetRowCountDefine("select count(CategoryCode) from " + commandText1, parameters.ToArray(), out result1); IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; //IList menus = Permission.Convert(permss); var jsonData = JsonConvert.SerializeObject(permss, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } /// /// 组织机构添加 /// /// /// /// /// /// /// /// /// /// /// [AuthPermission] [HttpPost, Route("add")] public JsonResult Addp( string CategoryCode, string CategoryName, string SortKey, string SyncStatus, string CateGoryKey, string ParentCatgoryKey, string CateGoryType, string CateGoryTypeName, string ParentCatgoryCode, [FromBody]dynamic data ) { if (data != null) { CategoryCode = data.CategoryCode; CategoryName = data.CategoryName; SortKey = data.SortKey; SyncStatus = data.SyncStatus; CateGoryKey = data.CateGoryKey; CateGoryType = data.CateGoryType; CateGoryTypeName = data.CateGoryTypeName; ParentCatgoryCode = data.ParentCatgoryCode; ParentCatgoryKey = data.ParentCatgoryKey; } String uuid = System.Guid.NewGuid().ToString("N"); string commandText = "INSERT INTO Mem_ProductCategory (CategoryCode," + "CategoryName,SortKey,SyncStatus,CateGoryKey,CateGoryType,CateGoryTypeName,ParentCatgoryCode,ParentCatgoryKey)" + " VALUES ('"+ uuid + "',@CategoryName,@SortKey,@SyncStatus,@CateGoryKey,@CateGoryType,@CateGoryTypeName,@ParentCatgoryCode,@ParentCatgoryKey)"; string result; //string result1; //准备参数 List> parameters = new List>(); parameters.Add(new List() { "CategoryCode", CategoryCode }); parameters.Add(new List() { "CategoryName", CategoryName }); parameters.Add(new List() { "SortKey", SortKey }); parameters.Add(new List() { "SyncStatus", SyncStatus }); parameters.Add(new List() { "CateGoryKey", CateGoryKey }); parameters.Add(new List() { "CateGoryType", CateGoryType }); parameters.Add(new List() { "CateGoryTypeName", CateGoryTypeName }); parameters.Add(new List() { "ParentCatgoryCode", ParentCatgoryCode }); parameters.Add(new List() { "ParentCatgoryKey", ParentCatgoryKey }); List parameters1 = DataAccess.ToParameters(parameters); int success = DataAccess.ExecuteCommand(commandText, parameters1, out result); return Json(new { //success = success,success1 success = success }); } ///// ///// 获取角色 ///// ///// //[HttpGet, Route("roles")] //public ActionResult Roles() //{ // var permss = GetTopRoles(); // IList