123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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
- {
- /// <summary>
- /// 区域巡检点分配
- /// </summary>
- public class TispSpotRegionController : BaseController
- {
- public ILogger<TispSpotRegionController> _logger { get; }
- private readonly ITispSpotRegionService _tispSpotRegionService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="tispSpotRegionService"></param>
- /// <param name="logger"></param>
- public TispSpotRegionController(ITispSpotRegionService tispSpotRegionService, ILogger<TispSpotRegionController> logger)
- {
- _tispSpotRegionService = tispSpotRegionService;
- _logger = logger;
- }
- /// <summary>
- /// 分组获取巡检区域分配的巡检点列表
- /// </summary>
- /// <param name="searchViewModel"></param>
- /// <returns></returns>
- [HttpPost("GetSpotRegionsAsyncByPage")]
- public async Task<ApiResult> GetSpotRegionsAsyncByPage(TispSpotRegionSearchModel searchViewModel)
- {
- try
- {
- if (null == searchViewModel)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- var list = await _tispSpotRegionService.GetSpotRegionsAsyncByPage(searchViewModel);
- return new ApiResult<PagesModel<TispSpotsRegionViewModel>>(new PagesModel<TispSpotsRegionViewModel>(list?.ToList(), searchViewModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取区域和巡检点
- /// </summary>
- /// <param name="searchViewModel"></param>
- /// <returns></returns>
- [HttpPost("GetSpotsRegionAsyncByPage")]
- public async Task<ApiResult> GetSpotsRegionAsyncByPage(TispSpotRegionSearchModel searchViewModel)
- {
- try
- {
- if (null == searchViewModel)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- var list = await _tispSpotRegionService.GetSpotsRegionAsyncByPage(searchViewModel);
- return new ApiResult<PagesModel<TispSpotsRegionViewModel>>(new PagesModel<TispSpotsRegionViewModel>(list?.ToList(), searchViewModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建或修改区域的巡检点
- /// </summary>
- /// <param name="createViewModel"></param>
- /// <returns></returns>
- [HttpPost("CreateSpotsRegionsAsync")]
- public async Task<ApiResult> 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);
- }
- }
- }
|