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.IO; using System.IO.Compression; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api { public class TdevDeviceTempOpsContentController : BaseController { public ILogger _logger { get; } private readonly ITdevDeviceTempOpsContentService _TdevDeviceTempOpsContentService; /// /// 构造函数 /// /// /// public TdevDeviceTempOpsContentController(ITdevDeviceTempOpsContentService TdevDeviceTempOpsContentService, ILogger logger) { _TdevDeviceTempOpsContentService = TdevDeviceTempOpsContentService; _logger = logger; } /// /// 通过id获取设备模板维保内容信息 /// /// /// [HttpGet("GetDeviceTempOpsContentAsync/{id}")] public async Task GetDeviceTempOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TdevDeviceTempOpsContentService.GetConditionAsync(new TdevDeviceTempOpsContentSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有设备模板维保内容 /// /// [HttpGet("GetDeviceTempOpsContentsAsync")] public async Task GetDeviceTempOpsContentsAsync() { try { var contentList = await _TdevDeviceTempOpsContentService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备模板维保内容名称条件查询 /// /// /// [HttpPost("GetDeviceTempOpsContentsByAsync")] public async Task GetDeviceTempOpsContentsByAsync(TdevDeviceTempOpsContentSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TdevDeviceTempOpsContentService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建设备模板维保内容 /// /// /// [HttpPost("CreateDeviceTempOpsContentAsync")] public async Task CreateDeviceTempOpsContentAsync(TdevDeviceTempOpsContentViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TdevDeviceTempOpsContentService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除设备模板维保内容 /// /// /// [HttpDelete("DeleteDeviceTempOpsContentAsync/{id}")] public async Task DeleteDeviceTempOpsContentAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDeviceTempOpsContentService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新设备模板维保内容 /// /// /// /// [HttpPut("UpdateDeviceTempOpsContentAsync/{id}")] public async Task UpdateDeviceTempOpsContentAsync(string id, TdevDeviceTempOpsContentUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TdevDeviceTempOpsContentService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }