using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Api.Controllers; using Ropin.Inspection.Model; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api { public class TmtnDevOpsContentController : BaseController { public ILogger _logger { get; } private readonly ITmtnDevOpsContentService _TmtnDevOpsContentService; /// /// 构造函数 /// /// /// public TmtnDevOpsContentController(ITmtnDevOpsContentService TmtnDevOpsContentService, ILogger logger) { _TmtnDevOpsContentService = TmtnDevOpsContentService; _logger = logger; } /// /// 通过id获取运维内容信息 /// /// /// [HttpGet("GetDevOpsContentAsync/{id}")] public async Task GetDevOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnDevOpsContentService.GetConditionAsync(new TmtnDevOpsContentSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有运维内容 /// /// [HttpGet("GetDevOpsContentsAsync")] public async Task GetDevOpsContentsAsync() { try { var contentList = await _TmtnDevOpsContentService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过运维内容名称条件查询 /// /// /// [HttpPost("GetDevOpsContentsByAsync")] public async Task GetDevOpsContentsByAsync(TmtnDevOpsContentSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TmtnDevOpsContentService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建运维内容 /// /// /// [HttpPost("CreateDevOpsContentAsync")] public async Task CreateDevOpsContentAsync(TmtnDevOpsContentViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TmtnDevOpsContentService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除运维内容 /// /// /// [HttpDelete("DeleteDevOpsContentAsync/{id}")] public async Task DeleteDevOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOpsContentService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新运维内容 /// /// /// /// [HttpPut("UpdateDevOpsContentAsync/{id}")] public async Task UpdateDevOpsContentAsync(string id, TmtnDevOpsContentUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOpsContentService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }