using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model; using Ropin.Inspection.Model.SearchModel; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { /// /// 区域巡检点分配 /// public class TispSpotRegionController : BaseController { public ILogger _logger { get; } private readonly ITispSpotRegionService _tispSpotRegionService; /// /// 构造函数 /// /// /// public TispSpotRegionController(ITispSpotRegionService tispSpotRegionService, ILogger logger) { _tispSpotRegionService = tispSpotRegionService; _logger = logger; } /// /// 分组获取巡检区域分配的巡检点列表 /// /// /// [HttpPost("GetSpotRegionsAsyncByPage")] public async Task GetSpotRegionsAsyncByPage(TispSpotRegionSearchModel searchViewModel) { try { if (null == searchViewModel) { return new ApiResult(ReturnCode.ArgsError); } var list = await _tispSpotRegionService.GetSpotRegionsAsyncByPage(searchViewModel); return new ApiResult>(new PagesModel(list?.ToList(), searchViewModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取区域和巡检点 /// /// /// [HttpPost("GetSpotsRegionAsyncByPage")] public async Task GetSpotsRegionAsyncByPage(TispSpotRegionSearchModel searchViewModel) { try { if (null == searchViewModel) { return new ApiResult(ReturnCode.ArgsError); } var list = await _tispSpotRegionService.GetSpotsRegionAsyncByPage(searchViewModel); return new ApiResult>(new PagesModel(list?.ToList(), searchViewModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建或修改区域的巡检点 /// /// /// [HttpPost("CreateSpotsRegionsAsync")] public async Task CreateSpotsRegionsAsync(TispSpotRegionCreateViewModel createViewModel) { if (createViewModel == null) { return new ApiResult(ReturnCode.ArgsError); } if (createViewModel.SpotIdList == null) { throw new Exception("请选择巡检点"); } if (createViewModel.RegionIdList == null) { throw new Exception("请选择巡检区域"); } try { await _tispSpotRegionService.CreateSpotsRegionsAsync(createViewModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }