Mem_DataDictoryController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.Key != null) { Key = data.Key; } else { Key = ""; }
  132. if (data.Text != null) { Text = data.Text; } else { Text = ""; }
  133. if (data.Value != null) { Value = data.Value; } else { Value = ""; }
  134. if (data.Remark != null) { Remark = data.Remark; } else { Remark = ""; }
  135. if (data.ParentId != null) { ParentId = data.ParentId; } else { ParentId = 0; }
  136. if (data.SortKey != null) { SortKey = data.SortKey; } else { SortKey = 0; }
  137. if (data.IsHide != null) { IsHide = data.IsHide; } else { IsHide = 0; }
  138. if (data.SyncStatus != null) { SyncStatus = data.SyncStatus; } else { SyncStatus = ""; }
  139. }
  140. #region 添加
  141. //String uuid = System.Guid.NewGuid().ToString("N");
  142. //int newid = Convert.ToInt32(ReturnMaxID("Id", "Mem_DataDictory")) + 1;
  143. string commandText = "INSERT INTO Mem_DataDictory (" +
  144. "[Key],Text,[Value],Remark,ParentId,SortKey,IsHide,SyncStatus)" +
  145. " VALUES (@Key,@Text,@Value,@Remark,@ParentId,@SortKey,@IsHide,@SyncStatus )";
  146. string result;
  147. //准备参数
  148. List<List<Object>> parameters = new List<List<Object>>();
  149. parameters.Add(new List<Object>() { "Key", Key });
  150. parameters.Add(new List<Object>() { "Text", Text });
  151. parameters.Add(new List<Object>() { "Value", Value });
  152. parameters.Add(new List<Object>() { "Remark", Remark });
  153. parameters.Add(new List<Object>() { "ParentId", ParentId });
  154. parameters.Add(new List<Object>() { "SortKey", SortKey });
  155. parameters.Add(new List<Object>() { "IsHide", IsHide });
  156. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  157. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  158. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  159. #endregion
  160. return Json(new
  161. {
  162. success = success
  163. });
  164. }
  165. /// <summary>
  166. /// 修改
  167. /// </summary>
  168. /// <param name="Id"></param>
  169. /// <param name="Key"></param>
  170. /// <param name="Text"></param>
  171. /// <param name="Value"></param>
  172. /// <param name="Remark"></param>
  173. /// <param name="ParentId"></param>
  174. /// <param name="SortKey"></param>
  175. /// <param name="IsHide"></param>
  176. /// <param name="SyncStatus"></param>
  177. /// <param name="data"></param>
  178. /// <returns></returns>
  179. [AuthPermission]
  180. [HttpPost, Route("edit")]
  181. public JsonResult editp(
  182. Int32 Id, String Key, String Text,
  183. string Value, string Remark, Int32 ParentId, Int32 SortKey,
  184. Int32 IsHide, string SyncStatus, [FromBody]dynamic data
  185. )
  186. {
  187. if (data != null)
  188. {
  189. if (data.Key != null) { Key = data.Key; } else { Key = ""; }
  190. if (data.Text != null) { Text = data.Text; } else { Text = ""; }
  191. if (data.Value != null) { Value = data.Value; } else { Value = ""; }
  192. if (data.Remark != null) { Remark = data.Remark; } else { Remark = ""; }
  193. if (data.ParentId != null) { ParentId = data.ParentId; } else { ParentId = 0; }
  194. if (data.SortKey != null) { SortKey = data.SortKey; } else { SortKey = 0; }
  195. if (data.IsHide != null) { IsHide = data.IsHide; } else { IsHide = 0; }
  196. if (data.SyncStatus != null) { SyncStatus = data.SyncStatus; } else { SyncStatus = ""; }
  197. }
  198. #region 编辑用户
  199. string commandText = "UPDATE Mem_DataDictory " +
  200. " SET Id=@Id, [Key] = @Key,";
  201. commandText += " Text = @Text" +
  202. ",[Value] = @Value" +
  203. " ,Remark = @Remark" +
  204. ",ParentId = @ParentId" +
  205. ",SortKey = @SortKey" +
  206. ",IsHide = @IsHide" +
  207. ",SyncStatus = @SyncStatus" +
  208. " WHERE Id= @Id";
  209. string result;
  210. //准备参数
  211. List<List<Object>> parameters = new List<List<Object>>();
  212. parameters.Add(new List<Object>() { "Key", Key });
  213. parameters.Add(new List<Object>() { "Text", Text });
  214. parameters.Add(new List<Object>() { "Value", Value });
  215. parameters.Add(new List<Object>() { "Remark", Remark });
  216. parameters.Add(new List<Object>() { "ParentId", ParentId });
  217. parameters.Add(new List<Object>() { "SortKey", SortKey });
  218. parameters.Add(new List<Object>() { "IsHide", IsHide });
  219. parameters.Add(new List<Object>() { "SyncStatus", SyncStatus });
  220. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  221. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  222. #endregion
  223. return Json(new
  224. {
  225. success = success,
  226. result = result,
  227. });
  228. }
  229. /// <summary>
  230. /// 组织机构删除
  231. /// </summary>
  232. /// <param name="id"></param>
  233. /// <returns></returns>
  234. [AuthPermission]
  235. [HttpPost, Route("delete")]
  236. public ActionResult Delete(string id)
  237. {
  238. //SQL语句
  239. string commandText = "DELETE FROM Mem_DataDictory WHERE Id = @id";
  240. string commandText1 = "DELETE FROM Mem_DataDictoryRole WHERE Id = @id";
  241. //准备参数
  242. List<List<Object>> parameters = new List<List<Object>>();
  243. parameters.Add(new List<Object>() { "id", id });
  244. string result = "";
  245. string result1 = "";
  246. //参数转换
  247. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  248. //执行并返回结果
  249. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  250. int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
  251. //如果Mem_DataDictory和Mem_DataDictoryRole表记录都删除成功
  252. int success2 = 0;
  253. if (success > 0 && success1 > 0)
  254. {
  255. success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
  256. }
  257. else
  258. {
  259. success2 = -1;
  260. }
  261. return Content("{success:" + success2 + "}");
  262. }
  263. /// <summary>
  264. /// 获取最大的id
  265. /// </summary>
  266. /// <param name="field"></param>
  267. /// <param name="tablename"></param>
  268. /// <returns></returns>
  269. public object ReturnMaxID(string field, string tablename)
  270. {
  271. string result;
  272. List<SqlParameter> parameters = new List<SqlParameter>();
  273. bool boolen = DataAccess.GetOneValue("select max(" + field + ") from " + tablename, parameters.ToArray(), out object objValue, out result);
  274. if (boolen == true)
  275. {
  276. return objValue;
  277. }
  278. else
  279. {
  280. return result;
  281. }
  282. }
  283. }
  284. }