123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- 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<TispRouteController> _logger { get; }
- private readonly ITispRouteService _tispRouteService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="tispRouteService"></param>
- /// <param name="logger"></param>
- public TispRouteController(ITispRouteService tispRouteService, ILogger<TispRouteController> logger)
- {
- _tispRouteService = tispRouteService;
- _logger = logger;
- }
- /// <summary>
- /// 通过ID获取巡检路线信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetRouteAsync/{id}")]
- public async Task<ApiResult> GetRouteAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _tispRouteService.GetByIdAsync(id);
- return new ApiResult<TispRouteViewModel>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有巡检路线
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetRoutesAsync")]
- public async Task<ApiResult> GetRoutesAsync()
- {
- try
- {
- var contentList = await _tispRouteService.GetAllAsync();
- return new ApiResult<IEnumerable<TispRouteViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过巡检路线名称条件查询
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetRoutesByAsync")]
- public async Task<ApiResult> 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<IEnumerable<TispRouteViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建巡检路线
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [Route("CreateRouteAsync")]
- [HttpPost]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 删除巡检路线
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteRouteAsync/{id}")]
- public async Task<ApiResult> 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);
- }
- /// <summary>
- /// 更新巡检路线
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateRouteAsync/{id}")]
- public async Task<ApiResult> 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);
- }
- }
- }
|