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 TdevMaintenancePlanContentController : BaseController { public ILogger _logger { get; } private readonly ITdevMaintenancePlanContentService _TdevMaintenancePlanContentService; /// /// 构造函数 /// /// /// public TdevMaintenancePlanContentController(ITdevMaintenancePlanContentService TdevMaintenancePlanContentService, ILogger logger) { _TdevMaintenancePlanContentService = TdevMaintenancePlanContentService; _logger = logger; } /// /// 通过id获取设备维保计划内容信息 /// /// /// [HttpGet("GetMaintenancePlanContentAsync/{id}")] public async Task GetMaintenancePlanContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TdevMaintenancePlanContentService.GetConditionAsync(new TdevMaintenancePlanContentSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有设备维保计划内容 /// /// [HttpGet("GetMaintenancePlanContentsAsync")] public async Task GetMaintenancePlanContentsAsync() { try { var contentList = await _TdevMaintenancePlanContentService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备维保计划内容名称条件查询 /// /// /// [HttpPost("GetMaintenancePlanContentsByAsync")] public async Task GetMaintenancePlanContentsByAsync(TdevMaintenancePlanContentSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TdevMaintenancePlanContentService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建设备维保计划内容 /// /// /// [HttpPost("CreateMaintenancePlanContentAsync")] public async Task CreateMaintenancePlanContentAsync(TdevMaintenancePlanContentViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TdevMaintenancePlanContentService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除设备维保计划内容 /// /// /// [HttpDelete("DeleteMaintenancePlanContentAsync/{id}")] public async Task DeleteMaintenancePlanContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevMaintenancePlanContentService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新设备维保计划内容 /// /// /// /// [HttpPut("UpdateMaintenancePlanContentAsync/{id}")] public async Task UpdateMaintenancePlanContentAsync(string id, TdevMaintenancePlanContentUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevMaintenancePlanContentService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }