LargeScreenControlController.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using log4net;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Ropin.Inspection.Api.Common;
  6. using Ropin.Inspection.Model.SearchModel.LGS;
  7. using Ropin.Inspection.Model.ViewModel.LGS;
  8. using Ropin.Inspection.Model;
  9. using Ropin.Inspection.Service.LGS.Interface;
  10. using System.Threading.Tasks;
  11. using System;
  12. using Ropin.Core.Extensions.Redis;
  13. using Ropin.Inspection.Common.Accessor.Interface;
  14. using System.Security.Claims;
  15. using NPOI.POIFS.Crypt.Dsig;
  16. using System.Collections.Generic;
  17. namespace Ropin.Inspection.Api.Controllers.LGS
  18. {
  19. public class LargeScreenControlController : BaseController
  20. {
  21. private readonly ILargeScreenControlService _repository;
  22. private static readonly ILog log = LogManager.GetLogger(typeof(LargeScreenControlController));
  23. private readonly IRedisBasketRepository _redisService;
  24. private readonly IClaimsAccessor _claims;
  25. /// <summary>
  26. /// 构造函数
  27. /// </summary>
  28. /// <param name="repository"></param>
  29. public LargeScreenControlController(ILargeScreenControlService repository, IRedisBasketRepository redisService, IClaimsAccessor claims)
  30. {
  31. _repository = repository;
  32. _redisService = redisService;
  33. _claims = claims;
  34. }
  35. /// <summary>
  36. /// 创建大屏控件
  37. /// </summary>
  38. /// <param name="content"></param>
  39. /// <returns></returns>
  40. [HttpPost("CreateLargeScreenControlAsync")]
  41. public async Task<ApiResult> CreateLargeScreenControlAsync(LargeScreenControlViewModel content)
  42. {
  43. if (content == null)
  44. {
  45. return new ApiResult(ReturnCode.ArgsError);
  46. }
  47. try
  48. {
  49. await _repository.CreateOneAsync(content);
  50. }
  51. catch (Exception ex)
  52. {
  53. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  54. }
  55. return new ApiResult(ReturnCode.Success);
  56. }
  57. /// <summary>
  58. /// 删除大屏控件
  59. /// </summary>
  60. /// <param name="id"></param>
  61. /// <returns></returns>
  62. [HttpDelete("DeleteLargeScreenControlAsync/{id}")]
  63. public async Task<ApiResult> DeleteLargeScreenControlAsync(string id)
  64. {
  65. if (string.IsNullOrEmpty(id))
  66. {
  67. return new ApiResult(ReturnCode.GeneralError);
  68. }
  69. try
  70. {
  71. await _repository.DeleteAsync(id);
  72. }
  73. catch (Exception ex)
  74. {
  75. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  76. }
  77. return new ApiResult(ReturnCode.Success);
  78. }
  79. /// <summary>
  80. /// 更新大屏控件
  81. /// </summary>
  82. /// <param name="id"></param>
  83. /// <param name="updateModel"></param>
  84. /// <returns></returns>
  85. [HttpPut("UpdateLargeScreenControlAsync/{id}")]
  86. [AllowAnonymous]
  87. public async Task<ApiResult> UpdateLargeScreenControlAsync(string id, LargeScreenControlViewModel updateModel)
  88. {
  89. if (string.IsNullOrEmpty(id))
  90. {
  91. return new ApiResult(ReturnCode.GeneralError);
  92. }
  93. try
  94. {
  95. await _repository.UpdateAsync(updateModel, id);
  96. }
  97. catch (Exception ex)
  98. {
  99. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  100. }
  101. return new ApiResult(ReturnCode.Success);
  102. }
  103. /// <summary>
  104. /// 保存大屏控件
  105. /// </summary>
  106. /// <param name="id"></param>
  107. /// <param name="updateModel"></param>
  108. /// <returns></returns>
  109. [HttpPut("SaveLargeScreenControlAsync/{id}")]
  110. [AllowAnonymous]
  111. public async Task<ApiResult> SaveLargeScreenControlAsync(string id, List<LargeScreenControlViewModel> updateModel)
  112. {
  113. if (string.IsNullOrEmpty(id))
  114. {
  115. return new ApiResult(ReturnCode.ArgsError);
  116. }
  117. try
  118. {
  119. if (updateModel == null || updateModel.Count <= 0)
  120. {
  121. await _repository.DeleteByLargeScreenCodeAsync(id);
  122. }
  123. else
  124. {
  125. await _repository.SaveAsync(updateModel);
  126. }
  127. return new ApiResult(ReturnCode.Success);
  128. }
  129. catch (Exception ex)
  130. {
  131. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  132. }
  133. }
  134. /// <summary>
  135. /// 更新大屏控件样式
  136. /// </summary>
  137. /// <param name="id"></param>
  138. /// <param name="updateModel"></param>
  139. /// <returns></returns>
  140. [HttpPut("UpdateLargeScreenControlStyleAsync/{id}")]
  141. [AllowAnonymous]
  142. public async Task<ApiResult> UpdateLargeScreenControlStyleAsync(string id, LargeScreenControlViewModel updateModel)
  143. {
  144. if (string.IsNullOrEmpty(id)|| updateModel==null||string.IsNullOrEmpty(updateModel.C_Style))
  145. {
  146. return new ApiResult(ReturnCode.GeneralError);
  147. }
  148. try
  149. {
  150. LargeScreenControlViewModel data = await _repository.GetByIdAsync(id);
  151. data.C_Style = updateModel.C_Style;
  152. await _repository.UpdateAsync(updateModel, id);
  153. }
  154. catch (Exception ex)
  155. {
  156. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  157. }
  158. return new ApiResult(ReturnCode.Success);
  159. }
  160. /// <summary>
  161. /// 获取大屏控件列表
  162. /// </summary>
  163. /// <returns></returns>
  164. [HttpPost("GetLargeScreenControlAsync")]
  165. [AllowAnonymous]
  166. public async Task<ApiResult> GetLargeScreenControlAsync(LargeScreenControlSearch searchModel)
  167. {
  168. if (searchModel == null)
  169. {
  170. return new ApiResult(ReturnCode.ArgsError);
  171. }
  172. try
  173. {
  174. var contentList = await _repository.GetConditionAsync(searchModel);
  175. return new ApiResult<PagesModel<LargeScreenControlViewModel>>(new PagesModel<LargeScreenControlViewModel>(contentList, searchModel));
  176. }
  177. catch (Exception ex)
  178. {
  179. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  180. }
  181. }
  182. /// <summary>
  183. /// 通过id获取大屏控件详情
  184. /// </summary>
  185. /// <returns></returns>
  186. [HttpGet("GetLargeScreenControlByIDAsync")]
  187. [AllowAnonymous]
  188. public async Task<ApiResult> GetLargeScreenControlByIDAsync(string Id)
  189. {
  190. if (string.IsNullOrEmpty(Id))
  191. {
  192. return new ApiResult(ReturnCode.ArgsError);
  193. }
  194. try
  195. {
  196. LargeScreenControlViewModel data = await _repository.GetByIdAsync(Id);
  197. return new ApiResult<LargeScreenControlViewModel>(data);
  198. }
  199. catch (Exception ex)
  200. {
  201. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  202. }
  203. }
  204. /// <summary>
  205. /// 将ID值存入缓存中
  206. /// </summary>
  207. /// <returns></returns>
  208. [HttpGet("RedisSetLargeScreenControlID")]
  209. [AllowAnonymous]
  210. public async Task<ApiResult> RedisSetLargeScreenControlID(string Id)
  211. {
  212. if (string.IsNullOrEmpty(Id))
  213. {
  214. return new ApiResult(ReturnCode.ArgsError);
  215. }
  216. try
  217. {
  218. string key= "LargeScreenControl_ID";
  219. await _redisService.Set(key, Id, TimeSpan.FromDays(7));
  220. return new ApiResult(ReturnCode.Success);
  221. }
  222. catch (Exception ex)
  223. {
  224. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  225. }
  226. }
  227. /// <summary>
  228. /// 获取存入缓存中ID
  229. /// </summary>
  230. /// <returns></returns>
  231. [HttpGet("RedisGetLargeScreenControlID")]
  232. [AllowAnonymous]
  233. public async Task<ApiResult> RedisGetLargeScreenControlID()
  234. {
  235. try
  236. {
  237. string key = "LargeScreenControl_ID";
  238. string val= await _redisService.GetValue(key);
  239. var data = new
  240. {
  241. Value = val
  242. };
  243. return new ApiResult<object>(data);
  244. }
  245. catch (Exception ex)
  246. {
  247. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  248. }
  249. }
  250. }
  251. }