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 TispContentGroupController : BaseController { public ILogger _logger { get; } private readonly ITispContentGroupService _service; /// /// 构造函数 /// /// /// public TispContentGroupController(ITispContentGroupService service, ILogger logger) { _service = service; _logger = logger; } /// /// 获取所有巡检内容分组 /// /// [HttpPost("GetContentGroupsAsync")] //[Authorize] public async Task GetContentGroupsAsync(TispContentGroupsSearchModel searchModel) { if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode)) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _service.GetContentGroupsAsync(searchModel); 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("CreateContentGroupAsync")] [HttpPost] public async Task CreateContentGroupAsync(TispContentGroupViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _service.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除巡检内容分组 /// /// /// [HttpDelete("DeleteContentGroupAsync/{id}")] public async Task DeleteContentGroupAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新巡检内容分组 /// /// /// /// [HttpPut("UpdateContentGroupAsync/{id}")] public async Task UpdateContentGroupAsync(Guid id, TispContentUpdateGroupViewModel updateModel) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }