Mem_DataDictoryController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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_DataDictory")]
  30. public class Mem_DataDictoryController : BaseController
  31. {
  32. public Mem_DataDictoryController(IMemoryCache cache, IApiClient client) : base(cache, client)
  33. {
  34. }
  35. private ConcurrentDictionary<int, Mem_DataDictory> Mem_DataDictoryMap = new ConcurrentDictionary<int, Mem_DataDictory>();
  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_DataDictory> permss = new List<Mem_DataDictory>(0);
  65. List<SqlParameter> parameters = new List<SqlParameter>();
  66. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_DataDictory(), "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.Id " + direct + " ) as rownum from " +
  78. "Mem_DataDictory as A " +
  79. " where 1=1 " +
  80. filterstr +
  81. ")AAA ";
  82. string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end
  83. + " ORDER BY AAA.Id desc";
  84. string commandText3 = commandText0 + commandText1 + commandText2;
  85. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  86. #endregion
  87. if (dt != null && dt.Rows.Count > 0)
  88. {
  89. // 把DataTable转换为IList<T>
  90. permss = ModelConvertHelper<Mem_DataDictory>.ConvertToModel(dt);
  91. }
  92. string result1;
  93. long totalcount = DataAccess.GetRowCountDefine("select count(Id) from " + commandText1, parameters.ToArray(), out result1);
  94. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  95. {
  96. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  97. };
  98. //IList<Menu> menus = Permission.Convert(permss);
  99. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  100. return Json(new
  101. {
  102. items = JsonConvert.DeserializeObject(jsonData),
  103. sum = new { },
  104. totalCount = totalcount
  105. });
  106. }
  107. /// <summary>
  108. /// 新增
  109. /// </summary>
  110. /// <param name="Id"></param>
  111. /// <param name="Key"></param>
  112. /// <param name="Text"></param>
  113. /// <param name="Value"></param>
  114. /// <param name="Remark"></param>
  115. /// <param name="ParentId"></param>
  116. /// <param name="SortKey"></param>
  117. /// <param name="IsHide"></param>
  118. /// <param name="SyncStatus"></param>
  119. /// <param name="data"></param>
  120. /// <returns></returns>
  121. [AuthPermission]
  122. [HttpPost, Route("add")]
  123. public JsonResult Addp(
  124. Int32 Id, String Key, String Text,
  125. string Value, string Remark,Int32 ParentId, Int32 SortKey,
  126. Int32 IsHide, string SyncStatus, [FromBody]dynamic data
  127. )
  128. {
  129. if (data != null)
  130. {
  131. if (data.Id != null) { Id = data.Id; } else { Id = 0; }
  132. if (data.Key != null) { Key = data.Key; } else { Key = ""; }
  133. if (data.Text != null) { Text = data.Text; } else { Text = ""; }
  134. if (data.Value != null) { Value = data.Value; } else { Value = ""; }
  135. if (data.Remark != null) { Remark = data.Remark; } else { Remark = ""; }
  136. if (data.ParentId != null) { ParentId = data.ParentId; } else { ParentId = 0; }
  137. if (data.SortKey != null) { SortKey = data.SortKey; } else { SortKey = 0; }
  138. if (data.IsHide != null) { IsHide = data.IsHide; } else { IsHide = 0; }
  139. if (data.SyncStatus != null) { SyncStatus = data.SyncStatus; } else { SyncStatus = ""; }
  140. }
  141. #region 添加机构节点
  142. //String uuid = System.Guid.NewGuid().ToString("N");
  143. int newid = Convert.ToInt32(ReturnMaxID("Id", "Mem_DataDictory")) + 1;
  144. string commandText = "INSERT INTO Mem_DataDictory (Id," +
  145. "[Key],Text,[Value],Remark,ParentId,SortKey,IsHide,SyncStatus)" +
  146. " VALUES ("+ newid + ",@Key,@Text,@Value,@Remark,@ParentId,@SortKey,@IsHide,@SyncStatus )";
  147. string result;
  148. //准备参数
  149. List<List<Object>> parameters = new List<List<Object>>();
  150. parameters.Add(new List<Object>() { "Id", Id });
  151. parameters.Add(new List<Object>() { "Key", Key });
  152. parameters.Add(new List<Object>() { "Text", Text });
  153. parameters.Add(new List<Object>() { "Value", Value });
  154. parameters.Add(new List<Object>() { "Remark", Remark });
  155. parameters.Add(new List<Object>() { "ParentId", ParentId });
  156. parameters.Add(new List<Object>() { "SortKey", SortKey });
  157. parameters.Add(new List<Object>() { "IsHide", IsHide });
  158. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  159. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  160. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  161. #endregion
  162. return Json(new
  163. {
  164. success = success
  165. });
  166. }
  167. /// <summary>
  168. /// 修改
  169. /// </summary>
  170. /// <param name="Id"></param>
  171. /// <param name="Key"></param>
  172. /// <param name="Text"></param>
  173. /// <param name="Value"></param>
  174. /// <param name="Remark"></param>
  175. /// <param name="ParentId"></param>
  176. /// <param name="SortKey"></param>
  177. /// <param name="IsHide"></param>
  178. /// <param name="SyncStatus"></param>
  179. /// <param name="data"></param>
  180. /// <returns></returns>
  181. [AuthPermission]
  182. [HttpPost, Route("edit")]
  183. public JsonResult editp(
  184. Int32 Id, String Key, String Text,
  185. string Value, string Remark, Int32 ParentId, Int32 SortKey,
  186. Int32 IsHide, string SyncStatus, [FromBody]dynamic data
  187. )
  188. {
  189. if (data != null)
  190. {
  191. if (data.Id != null) { Id = data.Id; } else { Id = 0; }
  192. if (data.Key != null) { Key = data.Key; } else { Key = ""; }
  193. if (data.Text != null) { Text = data.Text; } else { Text = ""; }
  194. if (data.Value != null) { Value = data.Value; } else { Value = ""; }
  195. if (data.Remark != null) { Remark = data.Remark; } else { Remark = ""; }
  196. if (data.ParentId != null) { ParentId = data.ParentId; } else { ParentId = 0; }
  197. if (data.SortKey != null) { SortKey = data.SortKey; } else { SortKey = 0; }
  198. if (data.IsHide != null) { IsHide = data.IsHide; } else { IsHide = 0; }
  199. if (data.SyncStatus != null) { SyncStatus = data.SyncStatus; } else { SyncStatus = ""; }
  200. }
  201. #region 编辑用户
  202. string commandText = "UPDATE Mem_DataDictory " +
  203. " SET Id=@Id, [Key] = @Key,";
  204. commandText += " Text = @Text" +
  205. ",[Value] = @Value" +
  206. " ,Remark = @Remark" +
  207. ",ParentId = @ParentId" +
  208. ",SortKey = @SortKey" +
  209. ",IsHide = @IsHide" +
  210. ",SyncStatus = @SyncStatus" +
  211. " WHERE Id= @Id";
  212. string result;
  213. //准备参数
  214. List<List<Object>> parameters = new List<List<Object>>();
  215. parameters.Add(new List<Object>() { "Id", Id });
  216. parameters.Add(new List<Object>() { "Key", Key });
  217. parameters.Add(new List<Object>() { "Text", Text });
  218. parameters.Add(new List<Object>() { "Value", Value });
  219. parameters.Add(new List<Object>() { "Remark", Remark });
  220. parameters.Add(new List<Object>() { "ParentId", ParentId });
  221. parameters.Add(new List<Object>() { "SortKey", SortKey });
  222. parameters.Add(new List<Object>() { "IsHide", IsHide });
  223. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  224. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  225. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  226. #endregion
  227. return Json(new
  228. {
  229. success = success,
  230. result = result,
  231. });
  232. }
  233. /// <summary>
  234. /// 组织机构删除
  235. /// </summary>
  236. /// <param name="id"></param>
  237. /// <returns></returns>
  238. [AuthPermission]
  239. [HttpPost, Route("delete")]
  240. public ActionResult Delete(string id)
  241. {
  242. //SQL语句
  243. string commandText = "DELETE FROM Mem_DataDictory WHERE Id = @id";
  244. string commandText1 = "DELETE FROM Mem_DataDictoryRole WHERE Id = @id";
  245. //准备参数
  246. List<List<Object>> parameters = new List<List<Object>>();
  247. parameters.Add(new List<Object>() { "id", id });
  248. string result = "";
  249. string result1 = "";
  250. //参数转换
  251. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  252. //执行并返回结果
  253. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  254. int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
  255. //如果Mem_DataDictory和Mem_DataDictoryRole表记录都删除成功
  256. int success2 = 0;
  257. if (success > 0 && success1 > 0)
  258. {
  259. success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
  260. }
  261. else
  262. {
  263. success2 = -1;
  264. }
  265. return Content("{success:" + success2 + "}");
  266. }
  267. /// <summary>
  268. /// 获取最大的id
  269. /// </summary>
  270. /// <param name="field"></param>
  271. /// <param name="tablename"></param>
  272. /// <returns></returns>
  273. public object ReturnMaxID(string field, string tablename)
  274. {
  275. string result;
  276. List<SqlParameter> parameters = new List<SqlParameter>();
  277. bool boolen = DataAccess.GetOneValue("select max(" + field + ") from " + tablename, parameters.ToArray(), out object objValue, out result);
  278. if (boolen == true)
  279. {
  280. return objValue;
  281. }
  282. else
  283. {
  284. return result;
  285. }
  286. }
  287. }
  288. }