using Microsoft.AspNetCore.Authorization; 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 TispContentController : BaseController { private readonly ILogger _logger; private readonly ITispContentService _tispContentService; /// /// 构造函数 /// /// /// public TispContentController(ITispContentService tispContentService, ILogger logger) { _tispContentService = tispContentService; _logger = logger; } /// /// 通过ID获取巡检内容信息 /// /// /// [HttpGet("GetContentAsync/{id}")] public async Task GetContentAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _tispContentService.GetByIdAsync(id); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有巡检内容 /// /// [HttpGet("GetContentsAsync/{storeCode}")] public async Task GetContentsAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _tispContentService.GetAllAsync(storeCode); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过内容条件查询,不分页 /// /// /// [HttpPost("GetContentsByAsync")] public async Task GetContentsByAsync(TispContentSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _tispContentService.GetContentsConditionAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建巡检内容 /// /// /// [Route("CreateContentAsync")] [HttpPost] public async Task CreateContentAsync([FromBody] TispContentViewModel content) { if (content == null || string.IsNullOrEmpty(content.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } try { await _tispContentService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除巡检内容 /// /// /// [HttpDelete("DeleteContentAsync/{id}")] public async Task DeleteContentAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _tispContentService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新巡检内容 /// /// /// /// [HttpPut("UpdateContentAsync/{id}")] public async Task UpdateContentAsync(Guid id, TispContentUpdateViewModel updateModel) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _tispContentService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }