TdevBoxDevSpotController.cs 5.4 KB

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