LargeScreenControlController.cs 8.7 KB

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