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 TispSpotRouteController : BaseController
{
public ILogger _logger { get; }
private readonly ITispSpotRouteService _tispSpotRouteService;
///
/// 构造函数
///
///
///
public TispSpotRouteController(ITispSpotRouteService tispSpotRouteService, ILogger logger)
{
_tispSpotRouteService = tispSpotRouteService;
_logger = logger;
}
///
/// 分组获取巡检路径分配的巡检点列表
///
///
///
[HttpPost("GetSpotRoutesAsyncByPage")]
public async Task GetSpotRoutesAsyncByPage(TispSpotRouteSearchModel searchViewModel)
{
try
{
if (null == searchViewModel)
{
return new ApiResult(ReturnCode.ArgsError);
}
var list = await _tispSpotRouteService.GetSpotRoutesAsyncByPage(searchViewModel);
return new ApiResult>(new PagesModel(list?.ToList(), searchViewModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 获取路径和巡检点
///
///
///
[HttpPost("GetSpotsRouteAsyncByPage")]
public async Task GetSpotsRouteAsyncByPage(TispSpotRouteSearchModel searchViewModel)
{
try
{
if (null == searchViewModel||string.IsNullOrEmpty(searchViewModel.C_StoreCode))
{
return new ApiResult(ReturnCode.ArgsError);
}
var list = await _tispSpotRouteService.GetSpotsRouteAsyncByPage(searchViewModel);
return new ApiResult>(new PagesModel(list?.ToList(), searchViewModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 创建或修改路径的巡检点
///
///
///
[Route("CreateSpotsRoutesAsync")]
[HttpPost]
public async Task CreateSpotsRoutesAsync(TispSpotRouteCreateViewModel createViewModel)
{
if (createViewModel == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
if (createViewModel.spotIdList == null)
{
throw new Exception("请选择巡检点");
}
if (createViewModel.routeIdList == null)
{
throw new Exception("请选择巡检路径");
}
try
{
await _tispSpotRouteService.CreateSpotsRoutesAsync(createViewModel);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
return new ApiResult(ReturnCode.Success);
}
}
}