TdevDeviceTempOpsContentController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Api.Controllers;
  5. using Ropin.Inspection.Model;
  6. using Ropin.Inspection.Service;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.IO.Compression;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. namespace Ropin.Inspection.Api
  14. {
  15. public class TdevDeviceTempOpsContentController : BaseController
  16. {
  17. public ILogger<TdevDeviceTempOpsContentController> _logger { get; }
  18. private readonly ITdevDeviceTempOpsContentService _TdevDeviceTempOpsContentService;
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="TdevDeviceTempOpsContentService"></param>
  23. /// <param name="logger"></param>
  24. public TdevDeviceTempOpsContentController(ITdevDeviceTempOpsContentService TdevDeviceTempOpsContentService, ILogger<TdevDeviceTempOpsContentController> logger)
  25. {
  26. _TdevDeviceTempOpsContentService = TdevDeviceTempOpsContentService;
  27. _logger = logger;
  28. }
  29. /// <summary>
  30. /// 通过id获取设备模板维保内容信息
  31. /// </summary>
  32. /// <param name="id"></param>
  33. /// <returns></returns>
  34. [HttpGet("GetDeviceTempOpsContentAsync/{id}")]
  35. public async Task<ApiResult> GetDeviceTempOpsContentAsync(string id)
  36. {
  37. if (string.IsNullOrEmpty(id))
  38. {
  39. return new ApiResult(ReturnCode.GeneralError);
  40. }
  41. try
  42. {
  43. var content = await _TdevDeviceTempOpsContentService.GetConditionAsync(new TdevDeviceTempOpsContentSearchModel { C_ID = id });
  44. return new ApiResult<TdevDeviceTempOpsContentViewModel>(content.FirstOrDefault());
  45. }
  46. catch (Exception ex)
  47. {
  48. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  49. }
  50. }
  51. /// <summary>
  52. /// 获取所有设备模板维保内容
  53. /// </summary>
  54. /// <returns></returns>
  55. [HttpGet("GetDeviceTempOpsContentsAsync")]
  56. public async Task<ApiResult> GetDeviceTempOpsContentsAsync()
  57. {
  58. try
  59. {
  60. var contentList = await _TdevDeviceTempOpsContentService.GetAllAsync();
  61. return new ApiResult<IEnumerable<TdevDeviceTempOpsContentViewModel>>(contentList);
  62. }
  63. catch (Exception ex)
  64. {
  65. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  66. }
  67. }
  68. /// <summary>
  69. /// 通过设备模板维保内容名称条件查询
  70. /// </summary>
  71. /// <param name="searchModel"></param>
  72. /// <returns></returns>
  73. [HttpPost("GetDeviceTempOpsContentsByAsync")]
  74. public async Task<ApiResult> GetDeviceTempOpsContentsByAsync(TdevDeviceTempOpsContentSearchModel searchModel)
  75. {
  76. if (searchModel == null)
  77. {
  78. return new ApiResult(ReturnCode.ArgsError);
  79. }
  80. searchModel.IsPagination = false;
  81. try
  82. {
  83. var contentList = await _TdevDeviceTempOpsContentService.GetConditionAsync(searchModel);
  84. return new ApiResult<PagesModel<TdevDeviceTempOpsContentViewModel>>(new PagesModel<TdevDeviceTempOpsContentViewModel>(contentList, searchModel));
  85. }
  86. catch (Exception ex)
  87. {
  88. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  89. }
  90. }
  91. /// <summary>
  92. /// 创建设备模板维保内容
  93. /// </summary>
  94. /// <param name="content"></param>
  95. /// <returns></returns>
  96. [HttpPost("CreateDeviceTempOpsContentAsync")]
  97. public async Task<ApiResult> CreateDeviceTempOpsContentAsync(TdevDeviceTempOpsContentViewModel content)
  98. {
  99. if (content == null)
  100. {
  101. return new ApiResult(ReturnCode.ArgsError);
  102. }
  103. try
  104. {
  105. await _TdevDeviceTempOpsContentService.CreateOneAsync(content);
  106. }
  107. catch (Exception ex)
  108. {
  109. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  110. }
  111. return new ApiResult(ReturnCode.Success);
  112. }
  113. /// <summary>
  114. /// 删除设备模板维保内容
  115. /// </summary>
  116. /// <param name="id"></param>
  117. /// <returns></returns>
  118. [HttpDelete("DeleteDeviceTempOpsContentAsync/{id}")]
  119. public async Task<ApiResult> DeleteDeviceTempOpsContentAsync(string id)
  120. {
  121. if (string.IsNullOrEmpty(id))
  122. {
  123. return new ApiResult(ReturnCode.GeneralError);
  124. }
  125. try
  126. {
  127. await _TdevDeviceTempOpsContentService.DeleteAsync(id);
  128. }
  129. catch (Exception ex)
  130. {
  131. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  132. }
  133. return new ApiResult(ReturnCode.Success);
  134. }
  135. /// <summary>
  136. /// 更新设备模板维保内容
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <param name="updateModel"></param>
  140. /// <returns></returns>
  141. [HttpPut("UpdateDeviceTempOpsContentAsync/{id}")]
  142. public async Task<ApiResult> UpdateDeviceTempOpsContentAsync(string id, TdevDeviceTempOpsContentUpdateModel updateModel)
  143. {
  144. if (string.IsNullOrEmpty(id))
  145. {
  146. return new ApiResult(ReturnCode.GeneralError);
  147. }
  148. try
  149. {
  150. await _TdevDeviceTempOpsContentService.UpdateAsync(id, updateModel);
  151. }
  152. catch (Exception ex)
  153. {
  154. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  155. }
  156. return new ApiResult(ReturnCode.Success);
  157. }
  158. }
  159. }