Mem_TerminaldocController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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_Terminaldoc")]
  30. public class Mem_TerminaldocController : BaseController
  31. {
  32. public Mem_TerminaldocController(IMemoryCache cache, IApiClient client) : base(cache, client)
  33. {
  34. }
  35. private ConcurrentDictionary<int, Mem_Terminaldoc> Mem_TerminaldocMap = new ConcurrentDictionary<int, Mem_Terminaldoc>();
  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_Terminaldoc> permss = new List<Mem_Terminaldoc>(0);
  65. List<SqlParameter> parameters = new List<SqlParameter>();
  66. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Terminaldoc(), "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.TerminalKey " + direct + " ) as rownum from " +
  78. "Mem_Terminaldoc 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.TerminalKey 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_Terminaldoc>.ConvertToModel(dt);
  91. }
  92. string result1;
  93. long totalcount = DataAccess.GetRowCountDefine("select count(TerminalKey) 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="TerminalKey"></param>
  111. /// <param name="TerminalName"></param>
  112. /// <param name="TerminalDesc"></param>
  113. /// <param name="ParentTerminalKey"></param>
  114. /// <param name="TerminalCode"></param>
  115. /// <param name="HasLowLevel"></param>
  116. /// <param name="SourceTerminalCode"></param>
  117. /// <param name="SourceTerminalKey"></param>
  118. /// <param name="data"></param>
  119. /// <returns></returns>
  120. [AuthPermission]
  121. [HttpPost, Route("add")]
  122. public JsonResult Add(
  123. Int32 TerminalKey, string TerminalName, string TerminalDesc,
  124. Int32 ParentTerminalKey, Int32 TerminalCode,int HasLowLevel,
  125. Int32 SourceTerminalCode, string SourceTerminalKey, [FromBody]dynamic data
  126. )
  127. {
  128. if (data != null)
  129. {
  130. if (data.TerminalKey != null) { TerminalKey = data.TerminalKey; } else { TerminalKey = 0; }
  131. if (data.TerminalName != null) { TerminalName = data.TerminalName; } else { TerminalName = ""; }
  132. if (data.TerminalDesc != null) { TerminalDesc = data.TerminalDesc; } else { TerminalDesc = ""; }
  133. if (data.ParentTerminalKey != null) { ParentTerminalKey = data.ParentTerminalKey; } else { ParentTerminalKey = 0; }
  134. if (data.TerminalCode != null) { TerminalCode = data.TerminalCode; } else { TerminalCode = 0; }
  135. if (data.HasLowLevel != null) { HasLowLevel = data.HasLowLevel; } else { HasLowLevel =0; }
  136. if (data.SourceTerminalCode != null) { SourceTerminalCode = data.SourceTerminalCode; } else { SourceTerminalCode = 0; }
  137. if (data.SourceTerminalKey != null) { SourceTerminalKey = data.SourceTerminalKey; } else { SourceTerminalKey = ""; }
  138. }
  139. #region 添加机构节点
  140. //String uuid = System.Guid.NewGuid().ToString("N");
  141. int newid =Convert.ToInt32(ReturnMaxID("TerminalKey", "Mem_Terminaldoc"))+1;
  142. string commandText = "INSERT INTO Mem_Terminaldoc (TerminalKey," +
  143. "TerminalName,TerminalDesc,ParentTerminalKey,TerminalCode,HasLowLevel," +
  144. "SourceTerminalCode,SourceTerminalKey)" +
  145. " VALUES ('"+ newid + "',@TerminalName,@TerminalDesc,@ParentTerminalKey,@TerminalCode," +
  146. "@HasLowLevel,@SourceTerminalCode,@SourceTerminalKey)";
  147. string result;
  148. //string result1;
  149. //准备参数
  150. List<List<Object>> parameters = new List<List<Object>>();
  151. //parameters.Add(new List<Object>() { "TerminalKey", TerminalKey });
  152. parameters.Add(new List<Object>() { "TerminalName", TerminalName });
  153. parameters.Add(new List<Object>() { "TerminalDesc", TerminalDesc });
  154. parameters.Add(new List<Object>() { "ParentTerminalKey", ParentTerminalKey });
  155. parameters.Add(new List<Object>() { "TerminalCode", TerminalCode });
  156. parameters.Add(new List<Object>() { "HasLowLevel", HasLowLevel });
  157. parameters.Add(new List<Object>() { "SourceTerminalCode", SourceTerminalCode });
  158. parameters.Add(new List<Object>() { "SourceTerminalKey", SourceTerminalKey });
  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,success1
  165. success = success
  166. });
  167. }
  168. /// <summary>
  169. /// 平台终端列表修改
  170. /// </summary>
  171. /// <param name="TerminalKey"></param>
  172. /// <param name="TerminalName"></param>
  173. /// <param name="TerminalDesc"></param>
  174. /// <param name="ParentTerminalKey"></param>
  175. /// <param name="TerminalCode"></param>
  176. /// <param name="HasLowLevel"></param>
  177. /// <param name="SourceTerminalCode"></param>
  178. /// <param name="SourceTerminalKey"></param>
  179. /// <param name="data"></param>
  180. /// <returns></returns>
  181. [AuthPermission]
  182. [HttpPost, Route("edit")]
  183. public JsonResult edit(
  184. Int32 TerminalKey, string TerminalName, string TerminalDesc,
  185. Int32 ParentTerminalKey, Int32 TerminalCode, int HasLowLevel,
  186. Int32 SourceTerminalCode, string SourceTerminalKey, [FromBody]dynamic data
  187. )
  188. {
  189. if (data != null)
  190. {
  191. if (data.TerminalKey != null) { TerminalKey = data.TerminalKey; } else { TerminalKey = 0; }
  192. if (data.TerminalName != null) { TerminalName = data.TerminalName; } else { TerminalName = ""; }
  193. if (data.TerminalDesc != null) { TerminalDesc = data.TerminalDesc; } else { TerminalDesc = ""; }
  194. if (data.ParentTerminalKey != null) { ParentTerminalKey = data.ParentTerminalKey; } else { ParentTerminalKey = 0; }
  195. if (data.TerminalCode != null) { TerminalCode = data.TerminalCode; } else { TerminalCode = 0; }
  196. if (data.HasLowLevel != null) { HasLowLevel = data.HasLowLevel; } else { HasLowLevel = 0; }
  197. if (data.SourceTerminalCode != null) { SourceTerminalCode = data.SourceTerminalCode; } else { SourceTerminalCode = 0; }
  198. if (data.SourceTerminalKey != null) { SourceTerminalKey = data.SourceTerminalKey; } else { SourceTerminalKey = ""; }
  199. }
  200. //string[] RoleIdss = RoleId.Split(",");
  201. //int[] RoleIdis = Array.ConvertAll(RoleIdss, s => Convert.ToInt32(s));
  202. #region 编辑用户
  203. string commandText = "UPDATE Mem_Terminaldoc " +
  204. " SET TerminalName = @TerminalName,";
  205. commandText += " TerminalDesc = @TerminalDesc" +
  206. ",ParentTerminalKey = @ParentTerminalKey" +
  207. " ,TerminalCode = @TerminalCode" +
  208. ",HasLowLevel = @HasLowLevel" +
  209. ",SourceTerminalCode = @SourceTerminalCode" +
  210. ",SourceTerminalKey = @SourceTerminalKey" +
  211. " WHERE TerminalKey= @TerminalKey";
  212. string result;
  213. //准备参数
  214. List<List<Object>> parameters = new List<List<Object>>();
  215. parameters.Add(new List<Object>() { "TerminalKey", TerminalKey });
  216. parameters.Add(new List<Object>() { "TerminalName", TerminalName });
  217. parameters.Add(new List<Object>() { "TerminalDesc", TerminalDesc });
  218. parameters.Add(new List<Object>() { "ParentTerminalKey", ParentTerminalKey });
  219. parameters.Add(new List<Object>() { "TerminalCode", TerminalCode });
  220. parameters.Add(new List<Object>() { "HasLowLevel", HasLowLevel });
  221. parameters.Add(new List<Object>() { "SourceTerminalCode", SourceTerminalCode });
  222. parameters.Add(new List<Object>() { "SourceTerminalKey", SourceTerminalKey });
  223. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  224. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  225. #endregion
  226. #region 角色
  227. //RoleDAL.SaveRolesRelatePermission(OrgId, RoleIdis);
  228. #endregion
  229. return Json(new
  230. {
  231. success = success,
  232. result = result,
  233. });
  234. }
  235. /// <summary>
  236. /// 组织机构删除
  237. /// </summary>
  238. /// <param name="id"></param>
  239. /// <returns></returns>
  240. [AuthPermission]
  241. [HttpPost, Route("delete")]
  242. public ActionResult Delete(string id)
  243. {
  244. //SQL语句
  245. string commandText = "DELETE FROM Mem_Terminaldoc WHERE TerminalKey = @id";
  246. //string commandText1 = "DELETE FROM Mem_TerminaldocRole WHERE TerminalKey = @id";
  247. //准备参数
  248. List<List<Object>> parameters = new List<List<Object>>();
  249. parameters.Add(new List<Object>() { "id", id });
  250. string result = "";
  251. //string result1 = "";
  252. //参数转换
  253. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  254. //执行并返回结果
  255. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  256. //int success1 = DataAccess.ExecuteCommand(commandText1, parameters1, out result1);
  257. //如果Mem_Terminaldoc和Mem_TerminaldocRole表记录都删除成功
  258. int success2 = 0;
  259. if (success > 0 )
  260. {
  261. success2 = success;//此处应该是success2 = success+success1,由于不清楚前端是怎么接收处理的,暂且这么处理。
  262. }
  263. else
  264. {
  265. success2 = -1;
  266. }
  267. return Content("{success:" + success2 + "}");
  268. }
  269. /// <summary>
  270. /// 获取最大的id
  271. /// </summary>
  272. /// <param name="field"></param>
  273. /// <param name="tablename"></param>
  274. /// <returns></returns>
  275. public object ReturnMaxID(string field,string tablename)
  276. {
  277. string result;
  278. List<SqlParameter> parameters = new List<SqlParameter>();
  279. bool boolen = DataAccess.GetOneValue("select max("+ field + ") from "+ tablename, parameters.ToArray(), out object objValue, out result);
  280. if (boolen == true)
  281. {
  282. return objValue;
  283. }
  284. else
  285. {
  286. return result;
  287. }
  288. }
  289. [HttpGet]
  290. [Route("getterms")]
  291. public ActionResult getTerms()
  292. {
  293. IList<Option> options = new List<Option>();
  294. IList<Mem_Terminaldoc> terms = TerminalDAL.getTerms();
  295. foreach(var term in terms)
  296. {
  297. var option = new Option() { label = term.TerminalName,
  298. value = term.TerminalCode.ToString(), disabled = false };
  299. options.Add(option);
  300. }
  301. var jsonData = JsonConvert.SerializeObject(options);
  302. return Content(jsonData
  303. );
  304. }
  305. [HttpGet]
  306. [Route("getgender")]
  307. public ActionResult getgender()
  308. {
  309. IList<Option> options = new List<Option>();
  310. IList<Mem_Terminaldoc> terms = TerminalDAL.getTerms();
  311. var option = new Option()
  312. {
  313. label = "男",
  314. value = "1",
  315. disabled = false
  316. };
  317. options.Add(option);
  318. var option1 = new Option()
  319. {
  320. label = "女",
  321. value = "0",
  322. disabled = false
  323. };
  324. options.Add(option1);
  325. var option2 = new Option()
  326. {
  327. label = "未知",
  328. value = "2",
  329. disabled = false
  330. };
  331. options.Add(option2);
  332. var option3 = new Option()
  333. {
  334. label = "空",
  335. value = "",
  336. disabled = false
  337. };
  338. options.Add(option3);
  339. var option4 = new Option()
  340. {
  341. label = "空",
  342. value = " ",
  343. disabled = false
  344. };
  345. options.Add(option4);
  346. var jsonData = JsonConvert.SerializeObject(options);
  347. return Content(jsonData
  348. );
  349. }
  350. [HttpGet]
  351. [Route("getSourcePlatForms")]
  352. public ActionResult getSourcePlatForms()
  353. {
  354. IList<Option> options = new List<Option>();
  355. IList<Mem_DataDictory> terms = Mem_DataDictoryDAL.getDatas(" and parentid= '783' ");
  356. foreach (var term in terms)
  357. {
  358. var option = new Option()
  359. {
  360. label = term.Text,
  361. value = term.Value.ToString(),
  362. disabled = term.IsHide?true:false
  363. };
  364. options.Add(option);
  365. }
  366. var jsonData = JsonConvert.SerializeObject(options);
  367. return Content(jsonData
  368. );
  369. }
  370. }
  371. }