Mem_PayplatformController.cs 13 KB

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