TdevBoxDevSpotController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Core.Extensions.Redis;
  5. using Ropin.Inspection.Api.Common;
  6. using Ropin.Inspection.Api.Controllers;
  7. using Ropin.Inspection.Common;
  8. using Ropin.Inspection.Model;
  9. using Ropin.Inspection.Service;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. namespace Ropin.Inspection.Api
  15. {
  16. public class TdevBoxDevSpotController : BaseController
  17. {
  18. public ILogger<TdevBoxDevSpotController> _logger { get; }
  19. private readonly IRedisBasketRepository _redisService;
  20. private readonly ITdevBoxDevSpotService _TdevBoxDevSpotService;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="TdevBoxDevSpotService"></param>
  25. /// <param name="logger"></param>
  26. public TdevBoxDevSpotController(ITdevBoxDevSpotService TdevBoxDevSpotService, IRedisBasketRepository redisService,ILogger<TdevBoxDevSpotController> logger)
  27. {
  28. _TdevBoxDevSpotService = TdevBoxDevSpotService;
  29. _logger = logger;
  30. _redisService = redisService;
  31. }
  32. /// <summary>
  33. /// 创建盒子设备信息
  34. /// </summary>
  35. /// <param name="content">盒子模型</param>
  36. /// <returns></returns>
  37. [HttpPost("CreateBoxDevSpotAsync")]
  38. [AllowAnonymous]
  39. public async Task<ApiResult> CreateBoxDevSpotAsync(TdevBoxDevSpotViewModel content)
  40. {
  41. if (content == null)
  42. {
  43. return new ApiResult(ReturnCode.ArgsError);
  44. }
  45. try
  46. {
  47. await _TdevBoxDevSpotService.CreateOneAsync(content);
  48. await _redisService.Set(RedisEnum.BoxDevSpotUpdateRedisKey, "1", TimeSpan.FromDays(7));
  49. }
  50. catch (Exception ex)
  51. {
  52. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  53. }
  54. return new ApiResult(ReturnCode.Success);
  55. }
  56. /// <summary>
  57. /// 删除盒子设备信息
  58. /// </summary>
  59. /// <param name="id"></param>
  60. /// <returns></returns>
  61. [HttpDelete("DeleteBoxDevSpotAsync/{id}")]
  62. public async Task<ApiResult> DeleteBoxDevSpotAsync(string id)
  63. {
  64. if (string.IsNullOrEmpty(id))
  65. {
  66. return new ApiResult(ReturnCode.GeneralError);
  67. }
  68. try
  69. {
  70. await _TdevBoxDevSpotService.DeleteAsync(id);
  71. }
  72. catch (Exception ex)
  73. {
  74. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  75. }
  76. return new ApiResult(ReturnCode.Success);
  77. }
  78. /// <summary>
  79. /// 更新盒子设备信息
  80. /// </summary>
  81. /// <param name="id"></param>
  82. /// <param name="updateModel"></param>
  83. /// <returns></returns>
  84. [HttpPut("UpdateBoxDevSpotAsync/{id}")]
  85. [AllowAnonymous]
  86. public async Task<ApiResult> UpdateBoxDevSpotAsync(string id, TdevBoxDevSpotUpdateModel updateModel)
  87. {
  88. if (string.IsNullOrEmpty(id))
  89. {
  90. return new ApiResult(ReturnCode.GeneralError);
  91. }
  92. try
  93. {
  94. await _TdevBoxDevSpotService.UpdateAsync(id, updateModel);
  95. await _redisService.Set(RedisEnum.BoxDevSpotUpdateRedisKey, "1", TimeSpan.FromDays(7));
  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. /// 通过id获取盒子设备信息
  105. /// </summary>
  106. /// <returns></returns>
  107. [HttpPost("GetBoxDevSpotAsync")]
  108. [AllowAnonymous]
  109. public async Task<ApiResult> GetBoxDevSpotAsync(TdevBoxDevSpotSearchModel searchModel)
  110. {
  111. if (searchModel == null)
  112. {
  113. return new ApiResult(ReturnCode.ArgsError);
  114. }
  115. try
  116. {
  117. var contentList = await _TdevBoxDevSpotService.GetConditionAsync(searchModel);
  118. return new ApiResult<PagesModel<TdevBoxDevSpotViewModel>>(new PagesModel<TdevBoxDevSpotViewModel>(contentList, searchModel));
  119. }
  120. catch (Exception ex)
  121. {
  122. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  123. }
  124. }
  125. /// <summary>
  126. /// 通过
  127. /// </summary>
  128. /// <param name="id"></param>
  129. /// <returns></returns>
  130. //[HttpGet("GetBoxDevSpotByCodeAsync/{id}")]
  131. //[AllowAnonymous]
  132. //public async Task<ApiResult> GetBoxDevSpotByCodeAsync(string id)
  133. //{
  134. // if (string.IsNullOrEmpty(id))
  135. // {
  136. // return new ApiResult(ReturnCode.GeneralError);
  137. // }
  138. // try
  139. // {
  140. // var content = await _TdevBoxDevSpotService.GetConditionAsync(new TdevBoxDevSpotSearchModel { C_DevSpotCode = id });
  141. // var dev = content.ToList();
  142. // return new ApiResult<IEnumerable<TdevBoxDevSpotViewModel>>(new List<TdevBoxDevSpotViewModel>(dev));
  143. // }
  144. // catch (Exception ex)
  145. // {
  146. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  147. // }
  148. //}
  149. }
  150. }