using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; 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 TispRouteController : BaseController { public ILogger _logger { get; } private readonly ITispRouteService _tispRouteService; /// /// 构造函数 /// /// /// public TispRouteController(ITispRouteService tispRouteService, ILogger logger) { _tispRouteService = tispRouteService; _logger = logger; } /// /// 通过ID获取巡检路线信息 /// /// /// [HttpGet("GetRouteAsync/{id}")] public async Task GetRouteAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _tispRouteService.GetByIdAsync(id); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有巡检路线 /// /// [HttpGet("GetRoutesAsync")] public async Task GetRoutesAsync() { try { var contentList = await _tispRouteService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过巡检路线名称条件查询 /// /// /// [HttpPost("GetRoutesByAsync")] public async Task GetRoutesByAsync(TispRouteSearchModel searchModel) { if (searchModel == null|| string.IsNullOrEmpty(searchModel.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _tispRouteService.GetRoutesConditionAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建巡检路线 /// /// /// [Route("CreateRouteAsync")] [HttpPost] public async Task CreateRouteAsync(TispRouteCreateViewModel content) { if (content == null && string.IsNullOrEmpty(content.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } try { TispRouteViewModel mode = new TispRouteViewModel { C_StoreCode = content.C_StoreCode, C_Name = content.C_Name,C_ImageUrl = content.C_ImageUrl,C_Remark=content.C_Remark }; await _tispRouteService.CreateOneAsync(mode); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除巡检路线 /// /// /// [HttpDelete("DeleteRouteAsync/{id}")] public async Task DeleteRouteAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _tispRouteService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新巡检路线 /// /// /// /// [HttpPut("UpdateRouteAsync/{id}")] public async Task UpdateRouteAsync(Guid id, TispRouteUpdateViewModel updateModel) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _tispRouteService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }