TispSpotRegionController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.SearchModel;
  6. using Ropin.Inspection.Model.ViewModel;
  7. using Ropin.Inspection.Service.Interface;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Api.Controllers
  13. {
  14. /// <summary>
  15. /// 区域巡检点分配
  16. /// </summary>
  17. public class TispSpotRegionController : BaseController
  18. {
  19. public ILogger<TispSpotRegionController> _logger { get; }
  20. private readonly ITispSpotRegionService _tispSpotRegionService;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="tispSpotRegionService"></param>
  25. /// <param name="logger"></param>
  26. public TispSpotRegionController(ITispSpotRegionService tispSpotRegionService, ILogger<TispSpotRegionController> logger)
  27. {
  28. _tispSpotRegionService = tispSpotRegionService;
  29. _logger = logger;
  30. }
  31. /// <summary>
  32. /// 分组获取巡检区域分配的巡检点列表
  33. /// </summary>
  34. /// <param name="searchViewModel"></param>
  35. /// <returns></returns>
  36. [HttpPost("GetSpotRegionsAsyncByPage")]
  37. public async Task<ApiResult> GetSpotRegionsAsyncByPage(TispSpotRegionSearchModel searchViewModel)
  38. {
  39. try
  40. {
  41. if (null == searchViewModel)
  42. {
  43. return new ApiResult(ReturnCode.ArgsError);
  44. }
  45. var list = await _tispSpotRegionService.GetSpotRegionsAsyncByPage(searchViewModel);
  46. return new ApiResult<PagesModel<TispSpotsRegionViewModel>>(new PagesModel<TispSpotsRegionViewModel>(list?.ToList(), searchViewModel));
  47. }
  48. catch (Exception ex)
  49. {
  50. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  51. }
  52. }
  53. /// <summary>
  54. /// 获取区域和巡检点
  55. /// </summary>
  56. /// <param name="searchViewModel"></param>
  57. /// <returns></returns>
  58. [HttpPost("GetSpotsRegionAsyncByPage")]
  59. public async Task<ApiResult> GetSpotsRegionAsyncByPage(TispSpotRegionSearchModel searchViewModel)
  60. {
  61. try
  62. {
  63. if (null == searchViewModel)
  64. {
  65. return new ApiResult(ReturnCode.ArgsError);
  66. }
  67. var list = await _tispSpotRegionService.GetSpotsRegionAsyncByPage(searchViewModel);
  68. return new ApiResult<PagesModel<TispSpotsRegionViewModel>>(new PagesModel<TispSpotsRegionViewModel>(list?.ToList(), searchViewModel));
  69. }
  70. catch (Exception ex)
  71. {
  72. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  73. }
  74. }
  75. /// <summary>
  76. /// 创建或修改区域的巡检点
  77. /// </summary>
  78. /// <param name="createViewModel"></param>
  79. /// <returns></returns>
  80. [HttpPost("CreateSpotsRegionsAsync")]
  81. public async Task<ApiResult> CreateSpotsRegionsAsync(TispSpotRegionCreateViewModel createViewModel)
  82. {
  83. if (createViewModel == null)
  84. {
  85. return new ApiResult(ReturnCode.ArgsError);
  86. }
  87. if (createViewModel.SpotIdList == null)
  88. {
  89. throw new Exception("请选择巡检点");
  90. }
  91. if (createViewModel.RegionIdList == null)
  92. {
  93. throw new Exception("请选择巡检区域");
  94. }
  95. try
  96. {
  97. await _tispSpotRegionService.CreateSpotsRegionsAsync(createViewModel);
  98. }
  99. catch (Exception ex)
  100. {
  101. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  102. }
  103. return new ApiResult(ReturnCode.Success);
  104. }
  105. }
  106. }