Mem_ProductCategoryController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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/Mem_ProductCategory")]
  30. public class mem_ProductCategoryController : BaseController
  31. {
  32. public mem_ProductCategoryController(IMemoryCache cache, IApiClient client) : base(cache, client)
  33. {
  34. }
  35. private ConcurrentDictionary<int, Mem_ProductCategory> Mem_ProductCategoryMap = new ConcurrentDictionary<int, Mem_ProductCategory>();
  36. /// <summary>
  37. /// 获取组织机构列表
  38. /// </summary>
  39. /// <param name="filters"></param>
  40. /// <param name="pageIndex"></param>
  41. /// <param name="pageSize"></param>
  42. /// <param name="sortField"></param>
  43. /// <param name="sortDirection"></param>
  44. /// <param name="sumFields"></param>
  45. /// <param name="data"></param>
  46. /// <returns></returns>
  47. [AuthPermission]
  48. [HttpPost, Route("index")]
  49. public JsonResult Indexp(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  50. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  51. {
  52. if (data != null)
  53. {
  54. filters = data.filters.ToObject<QueryFilter[]>();
  55. pageIndex = data.pageIndex;
  56. pageSize = data.pageSize;
  57. sortField = data.sortField;
  58. sortDirection = data.sortDirection;
  59. sumFields = data.sumFields.ToObject<string[]>();
  60. }
  61. #region 获取机构列表
  62. DataTable dt = new DataTable();
  63. string result;
  64. IList<Mem_ProductCategory> permss = new List<Mem_ProductCategory>(0);
  65. List<SqlParameter> parameters = new List<SqlParameter>();
  66. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_ProductCategory(), "A.");
  67. string direct = " desc ";
  68. if (sortDirection != 1)
  69. {
  70. direct = " asc";
  71. }
  72. int start = (pageIndex - 1) * pageSize;
  73. int end = (start + 1 + pageSize);
  74. string commandText0 = "select * from ";
  75. string commandText1 = "(" +
  76. "select A.*,row_number() over" +
  77. "( order by A.CategoryCode " + direct + " ) as rownum from " +
  78. "Mem_ProductCategory as A " +
  79. " where 1=1 " +
  80. //" and A.CreationPerson = '" + userids + "'" +
  81. filterstr +
  82. ")AAA ";
  83. string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end
  84. + " ORDER BY AAA.CategoryCode desc";
  85. string commandText3 = commandText0 + commandText1 + commandText2;
  86. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  87. #endregion
  88. if (dt != null && dt.Rows.Count > 0)
  89. {
  90. // 把DataTable转换为IList<T>
  91. permss = ModelConvertHelper<Mem_ProductCategory>.ConvertToModel(dt);
  92. }
  93. string result1;
  94. long totalcount = DataAccess.GetRowCountDefine("select count(CategoryCode) from " + commandText1, parameters.ToArray(), out result1);
  95. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  96. {
  97. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  98. };
  99. //IList<Menu> menus = Permission.Convert(permss);
  100. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  101. return Json(new
  102. {
  103. items = JsonConvert.DeserializeObject(jsonData),
  104. sum = new { },
  105. totalCount = totalcount
  106. });
  107. }
  108. /// <summary>
  109. /// 组织机构添加
  110. /// </summary>
  111. /// <param name="OrgId"></param>
  112. /// <param name="ParentOrgId"></param>
  113. /// <param name="UserId"></param>
  114. /// <param name="OrgCode"></param>
  115. /// <param name="OrgName"></param>
  116. /// <param name="FullCode"></param>
  117. /// <param name="FullName"></param>
  118. /// <param name="RoleId"></param>
  119. /// <param name="data"></param>
  120. /// <returns></returns>
  121. [AuthPermission]
  122. [HttpPost, Route("add")]
  123. public JsonResult Addp(
  124. string CategoryCode, string CategoryName, string SortKey,
  125. string SyncStatus, string CateGoryKey, string ParentCatgoryKey,
  126. string CateGoryType, string CateGoryTypeName, string ParentCatgoryCode, [FromBody]dynamic data
  127. )
  128. {
  129. if (data != null)
  130. {
  131. CategoryCode = data.CategoryCode;
  132. CategoryName = data.CategoryName;
  133. SortKey = data.SortKey;
  134. SyncStatus = data.SyncStatus;
  135. CateGoryKey = data.CateGoryKey;
  136. CateGoryType = data.CateGoryType;
  137. CateGoryTypeName = data.CateGoryTypeName;
  138. ParentCatgoryCode = data.ParentCatgoryCode;
  139. ParentCatgoryKey = data.ParentCatgoryKey;
  140. }
  141. String uuid = System.Guid.NewGuid().ToString("N");
  142. string commandText = "INSERT INTO Mem_ProductCategory (CategoryCode," +
  143. "CategoryName,SortKey,SyncStatus,CateGoryKey,CateGoryType,CateGoryTypeName,ParentCatgoryCode,ParentCatgoryKey)" +
  144. " VALUES ('"+ uuid + "',@CategoryName,@SortKey,@SyncStatus,@CateGoryKey,@CateGoryType,@CateGoryTypeName,@ParentCatgoryCode,@ParentCatgoryKey)";
  145. string result;
  146. //string result1;
  147. //准备参数
  148. List<List<Object>> parameters = new List<List<Object>>();
  149. parameters.Add(new List<Object>() { "CategoryCode", CategoryCode });
  150. parameters.Add(new List<Object>() { "CategoryName", CategoryName });
  151. parameters.Add(new List<Object>() { "SortKey", SortKey });
  152. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  153. parameters.Add(new List<Object>() { "CateGoryKey", CateGoryKey });
  154. parameters.Add(new List<Object>() { "CateGoryType", CateGoryType });
  155. parameters.Add(new List<Object>() { "CateGoryTypeName", CateGoryTypeName });
  156. parameters.Add(new List<Object>() { "ParentCatgoryCode", ParentCatgoryCode });
  157. parameters.Add(new List<Object>() { "ParentCatgoryKey", ParentCatgoryKey });
  158. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  159. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  160. return Json(new
  161. {
  162. //success = success,success1
  163. success = success
  164. });
  165. }
  166. ///// <summary>
  167. ///// 获取角色
  168. ///// </summary>
  169. ///// <returns></returns>
  170. //[HttpGet, Route("roles")]
  171. //public ActionResult Roles()
  172. //{
  173. // var permss = GetTopRoles();
  174. // IList<Option> options = new List<Option>();
  175. // foreach (CM_Role perms in permss)
  176. // {
  177. // var option = new Option() { label = perms.RoleName, value = perms.RoleId.ToString() };
  178. // options.Add(option);
  179. // }
  180. // var jsonData = JsonConvert.SerializeObject(options);
  181. // return Content(jsonData);
  182. //}
  183. /// <summary>
  184. /// 组织机构修改
  185. /// </summary>
  186. /// <param name="OrgId">组织id</param>
  187. /// <param name="ParentOrgId">父组织id</param>
  188. /// <param name="OrgCode"></param>
  189. /// <param name="OrgName"></param>
  190. /// <param name="FullCode"></param>
  191. /// <param name="FullName"></param>
  192. /// <param name="UserId"></param>
  193. /// <param name="data"></param>
  194. /// <param name="IsDelete"></param>
  195. /// <returns></returns>
  196. [AuthPermission]
  197. [HttpPost, Route("edit")]
  198. public JsonResult editp(
  199. string CategoryCode, string CategoryName, string SortKey,
  200. string SyncStatus, string CateGoryKey, string ParentCatgoryKey,
  201. string CateGoryType, string CateGoryTypeName, string ParentCatgoryCode, [FromBody]dynamic data
  202. )
  203. {
  204. if (data != null)
  205. {
  206. CategoryCode = data.CategoryCode;
  207. CategoryName = data.CategoryName;
  208. SortKey = data.SortKey;
  209. SyncStatus = data.SyncStatus;
  210. CateGoryKey = data.CateGoryKey;
  211. CateGoryType = data.CateGoryType;
  212. CateGoryTypeName = data.CateGoryTypeName;
  213. ParentCatgoryCode = data.ParentCatgoryCode;
  214. ParentCatgoryKey = data.ParentCatgoryKey;
  215. }
  216. //string[] RoleIdss = RoleId.Split(",");
  217. //int[] RoleIdis = Array.ConvertAll(RoleIdss, s => Convert.ToInt32(s));
  218. #region 编辑用户
  219. string commandText = "UPDATE Mem_ProductCategory " +
  220. " SET CategoryCode=@CategoryCode, CategoryName = @CategoryName,";
  221. commandText += " SortKey = @SortKey" +
  222. ",SyncStatus = @SyncStatus" +
  223. " ,CateGoryKey = @CateGoryKey" +
  224. ",CateGoryType = @CateGoryType" +
  225. ",CateGoryTypeName = @CateGoryTypeName" +
  226. ",ParentCatgoryCode = @ParentCatgoryCode" +
  227. ",ParentCatgoryKey = @ParentCatgoryKey" +
  228. " WHERE CategoryCode= @CategoryCode";
  229. string result;
  230. //准备参数
  231. List<List<Object>> parameters = new List<List<Object>>();
  232. parameters.Add(new List<Object>() { "CategoryCode", CategoryCode });
  233. parameters.Add(new List<Object>() { "CategoryName", CategoryName });
  234. parameters.Add(new List<Object>() { "SortKey", SortKey });
  235. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  236. parameters.Add(new List<Object>() { "CateGoryKey", CateGoryKey });
  237. parameters.Add(new List<Object>() { "CateGoryType", CateGoryType });
  238. parameters.Add(new List<Object>() { "CateGoryTypeName", CateGoryTypeName });
  239. parameters.Add(new List<Object>() { "ParentCatgoryCode", ParentCatgoryCode });
  240. parameters.Add(new List<Object>() { "ParentCatgoryKey", ParentCatgoryKey });
  241. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  242. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  243. #endregion
  244. #region 角色
  245. //RoleDAL.SaveRolesRelatePermission(OrgId, RoleIdis);
  246. #endregion
  247. return Json(new
  248. {
  249. success = success,
  250. result = result,
  251. });
  252. }
  253. /// <summary>
  254. /// 组织机构删除
  255. /// </summary>
  256. /// <param name="id"></param>
  257. /// <returns></returns>
  258. [AuthPermission]
  259. [HttpPost, Route("delete")]
  260. public ActionResult Delete(string id)
  261. {
  262. //SQL语句
  263. string commandText = "DELETE FROM Mem_ProductCategory WHERE CategoryCode = @id";
  264. //string commandText1 = "DELETE FROM Mem_ProductCategoryRole WHERE CategoryCode = @id";
  265. //准备参数
  266. List<List<Object>> parameters = new List<List<Object>>();
  267. parameters.Add(new List<Object>() { "id", id });
  268. string result = "";
  269. //string result1 = "";
  270. //参数转换
  271. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  272. //执行并返回结果
  273. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  274. //int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
  275. //如果Mem_ProductCategory和Mem_ProductCategoryRole表记录都删除成功
  276. int success2 = 0;
  277. if (success > 0)
  278. {
  279. success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
  280. }
  281. else
  282. {
  283. success2 = -1;
  284. }
  285. return Content("{success:" + success2 + "}");
  286. }
  287. public IList<Mem_ProductCategory> GetTopRoles()
  288. {
  289. IList<Mem_ProductCategory> permsList = new List<Mem_ProductCategory>(0);
  290. DataTable dt = new DataTable();
  291. string result = string.Empty;
  292. var sortDirection = 1;
  293. var pageIndex = 1;
  294. var pageSize = Config.MaxPageSize;
  295. string direct = " desc ";
  296. if (sortDirection != 1)
  297. direct = " asc";
  298. int start = (pageIndex - 1) * pageSize;
  299. int end = (start + 1 + pageSize);
  300. string commandText = "select * from (" +
  301. "select A.*, row_number() over" +
  302. "( order by A.CategoryCode " + direct + " ) as rownum" +
  303. " from Mem_ProductCategory A ) AAA" +
  304. " where AAA.rownum>" + start + " and AAA.rownum<" + end +
  305. " ";
  306. List<List<Object>> parameters1 = new List<List<Object>>();
  307. parameters1.Add(new List<Object>() { "CategoryCode", 0 });
  308. bool result1 = DataAccess.GetValues(commandText, ref dt, DataAccess.ToParameters(parameters1).ToArray(), out result);
  309. if (result1 && dt.Rows.Count > 0)
  310. {
  311. // 把DataTable转换为IList<T>
  312. permsList = ModelConvertHelper<Mem_ProductCategory>.ConvertToModel(dt);
  313. }
  314. return permsList;
  315. }
  316. }
  317. }