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 TmtnSpotDevOpsContentController : BaseController { public ILogger _logger { get; } private readonly ITmtnSpotDevOpsContentService _TmtnSpotDevOpsContentService; /// /// 构造函数 /// /// /// public TmtnSpotDevOpsContentController(ITmtnSpotDevOpsContentService TmtnSpotDevOpsContentService, ILogger logger) { _TmtnSpotDevOpsContentService = TmtnSpotDevOpsContentService; _logger = logger; } /// /// 通过id获取运维点运维内容信息 /// /// /// [HttpGet("GetSpotDevOpsContentAsync/{id}")] public async Task GetSpotDevOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnSpotDevOpsContentService.GetConditionAsync(new TmtnSpotDevOpsContentSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有运维点运维内容 /// /// [HttpGet("GetSpotDevOpsContentsAsync")] public async Task GetSpotDevOpsContentsAsync() { try { var contentList = await _TmtnSpotDevOpsContentService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过运维点运维内容名称条件查询 /// /// /// [HttpPost("GetSpotDevOpsContentsByAsync")] public async Task GetSpotDevOpsContentsByAsync(TmtnSpotDevOpsContentSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TmtnSpotDevOpsContentService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建运维点运维内容 /// /// /// [HttpPost("CreateSpotDevOpsContentAsync")] public async Task CreateSpotDevOpsContentAsync(TmtnSpotDevOpsContentViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TmtnSpotDevOpsContentService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除运维点运维内容 /// /// /// [HttpDelete("DeleteSpotDevOpsContentAsync/{id}")] public async Task DeleteSpotDevOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnSpotDevOpsContentService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新运维点运维内容 /// /// /// /// [HttpPut("UpdateSpotDevOpsContentAsync/{id}")] public async Task UpdateSpotDevOpsContentAsync(string id, TmtnSpotDevOpsContentUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnSpotDevOpsContentService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }