Mem_LogisticsentController.cs 12 KB

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