Mem_AreaMapController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_AreaMap")]
  30. public class mem_AreaMapController : BaseController
  31. {
  32. public mem_AreaMapController(IMemoryCache cache, IApiClient client) : base(cache, client)
  33. {
  34. }
  35. private ConcurrentDictionary<int, Mem_AreaMap> Mem_AreaMapMap = new ConcurrentDictionary<int, Mem_AreaMap>();
  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_AreaMap> permss = new List<Mem_AreaMap>(0);
  65. List<SqlParameter> parameters = new List<SqlParameter>();
  66. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_AreaMap(), "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.AreaCode " + direct + " ) as rownum from " +
  78. "Mem_AreaMap 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.AreaCode 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_AreaMap>.ConvertToModel(dt);
  91. }
  92. string result1;
  93. long totalcount = DataAccess.GetRowCountDefine("select count(AreaCode) 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="LogisticsEntKey"></param>
  111. /// <param name="LogisticsEntCode"></param>
  112. /// <param name="LogisticsEntName"></param>
  113. /// <param name="LogisticsEntCodeExt"></param>
  114. /// <param name="data"></param>
  115. /// <returns></returns>
  116. [AuthPermission]
  117. [HttpPost, Route("add")]
  118. public JsonResult Addp(
  119. string AreaCode, string AreaName, string ParentCode, Int32 Level, string RelateID,
  120. string MappingCode, [FromBody]dynamic data
  121. )
  122. {
  123. if (data != null)
  124. {
  125. if (data.AreaCode != null) { AreaCode = data.AreaCode; } else { AreaCode = ""; }
  126. if (data.AreaName != null) { AreaName = data.AreaName; } else { AreaName = ""; }
  127. if (data.ParentCode != null) { ParentCode = data.ParentCode; } else { ParentCode = ""; }
  128. if (data.Level != null) { Level = data.Level; } else { Level = 0; }
  129. if (data.RelateID != null) { RelateID = data.RelateID; } else { RelateID = ""; }
  130. if (data.MappingCode != null) { MappingCode = data.MappingCode; } else { MappingCode = ""; }
  131. }
  132. #region 添加机构节点
  133. //String uuid = System.Guid.NewGuid().ToString("N");
  134. int newid = Convert.ToInt32(ReturnMaxID("AreaCode", "Mem_AreaMap")) + 1;
  135. string commandText = "INSERT INTO Mem_AreaMap (AreaCode," +
  136. "AreaName,ParentCode,Level,RelateID,MappingCode)" +
  137. " VALUES (" + newid + ",@AreaCode,@AreaName,@ParentCode,@Level,@RelateID,@MappingCode)";
  138. string result;
  139. //string result1;
  140. //准备参数
  141. List<List<Object>> parameters = new List<List<Object>>();
  142. parameters.Add(new List<Object>() { "AreaCode", AreaCode });
  143. parameters.Add(new List<Object>() { "AreaName", AreaName });
  144. parameters.Add(new List<Object>() { "ParentCode", ParentCode });
  145. parameters.Add(new List<Object>() { "Level", Level });
  146. parameters.Add(new List<Object>() { "RelateID", RelateID });
  147. parameters.Add(new List<Object>() { "MappingCode", MappingCode });
  148. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  149. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  150. #endregion
  151. return Json(new
  152. {
  153. success = success
  154. });
  155. }
  156. /// <summary>
  157. /// 修改
  158. /// </summary>
  159. /// <param name="LogisticsEntKey"></param>
  160. /// <param name="LogisticsEntCode"></param>
  161. /// <param name="LogisticsEntName"></param>
  162. /// <param name="LogisticsEntCodeExt"></param>
  163. /// <param name="data"></param>
  164. /// <returns></returns>
  165. [AuthPermission]
  166. [HttpPost, Route("edit")]
  167. public JsonResult editp(
  168. string AreaCode, string AreaName, string ParentCode, Int32 Level, string RelateID,
  169. string MappingCode, [FromBody]dynamic data
  170. )
  171. {
  172. if (data != null)
  173. {
  174. if (data.AreaCode != null) { AreaCode = data.AreaCode; } else { AreaCode = ""; }
  175. if (data.AreaName != null) { AreaName = data.AreaName; } else { AreaName = ""; }
  176. if (data.ParentCode != null) { ParentCode = data.ParentCode; } else { ParentCode = ""; }
  177. if (data.Level != null) { Level = data.Level; } else { Level = 0; }
  178. if (data.RelateID != null) { RelateID = data.RelateID; } else { RelateID = ""; }
  179. if (data.MappingCode != null) { MappingCode = data.MappingCode; } else { MappingCode = ""; }
  180. }
  181. #region 编辑用户
  182. string commandText = "UPDATE Mem_AreaMap " +
  183. " SET AreaCode=@AreaCode, AreaName = @AreaName,";
  184. commandText += " ParentCode = @ParentCode" +
  185. ",Level = @Level" +
  186. ",RelateID = @RelateID" +
  187. ",MappingCode = @MappingCode" +
  188. " WHERE AreaCode= @AreaCode";
  189. string result;
  190. //准备参数
  191. List<List<Object>> parameters = new List<List<Object>>();
  192. parameters.Add(new List<Object>() { "AreaCode", AreaCode });
  193. parameters.Add(new List<Object>() { "AreaName", AreaName });
  194. parameters.Add(new List<Object>() { "ParentCode", ParentCode });
  195. parameters.Add(new List<Object>() { "Level", Level });
  196. parameters.Add(new List<Object>() { "RelateID", RelateID });
  197. parameters.Add(new List<Object>() { "MappingCode", MappingCode });
  198. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  199. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  200. #endregion
  201. return Json(new
  202. {
  203. success = success,
  204. result = result,
  205. });
  206. }
  207. /// <summary>
  208. /// 组织机构删除
  209. /// </summary>
  210. /// <param name="id"></param>
  211. /// <returns></returns>
  212. [AuthPermission]
  213. [HttpPost, Route("delete")]
  214. public ActionResult Delete(string id)
  215. {
  216. //SQL语句
  217. string commandText = "DELETE FROM Mem_AreaMap WHERE AreaCode = @id";
  218. //string commandText1 = "DELETE FROM Mem_AreaMapRole WHERE AreaCode = @id";
  219. //准备参数
  220. List<List<Object>> parameters = new List<List<Object>>();
  221. parameters.Add(new List<Object>() { "id", id });
  222. string result = "";
  223. //string result1 = "";
  224. //参数转换
  225. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  226. //执行并返回结果
  227. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  228. //int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
  229. //如果Mem_AreaMap和Mem_AreaMapRole表记录都删除成功
  230. int success2 = 0;
  231. if (success > 0)
  232. {
  233. success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
  234. }
  235. else
  236. {
  237. success2 = -1;
  238. }
  239. return Content("{success:" + success2 + "}");
  240. }
  241. /// <summary>
  242. /// 获取最大的id
  243. /// </summary>
  244. /// <param name="field"></param>
  245. /// <param name="tablename"></param>
  246. /// <returns></returns>
  247. public object ReturnMaxID(string field, string tablename)
  248. {
  249. string result;
  250. List<SqlParameter> parameters = new List<SqlParameter>();
  251. bool boolen = DataAccess.GetOneValue("select max(" + field + ") from " + tablename, parameters.ToArray(), out object objValue, out result);
  252. if (boolen == true)
  253. {
  254. return objValue;
  255. }
  256. else
  257. {
  258. return result;
  259. }
  260. }
  261. }
  262. }