using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; 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.Controllers { public class TprdLogController : BaseController { public readonly ILogger _logger ; private readonly ITprdLogService _TprdLogService; /// /// 构造函数 /// /// /// public TprdLogController(ITprdLogService TprdLogService, ILogger logger) { _TprdLogService = TprdLogService; _logger = logger; } /// /// 通过ID获取器具日志 /// /// /// [HttpGet("GetLogAsync/{id}")] public async Task GetLogAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TprdLogService.GetByIdAsync(id); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有器具日志 /// /// [HttpGet("GetLogsAsync")] public async Task GetLogsAsync() { try { var contentList = await _TprdLogService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过名称条件查询 /// /// /// [HttpPost("GetLogsByAsync")] public async Task GetLogsByAsync(TprdLogSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TprdLogService.GetConditionAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建器具日志 /// /// /// [HttpPost("CreateLogAsync")] public async Task CreateLogAsync(TprdLogViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TprdLogService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除器具日志 /// /// /// [HttpDelete("DeleteLogAsync/{id}")] public async Task DeleteLogAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _TprdLogService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新器具日志 /// /// /// /// [HttpPut("UpdateLogAsync/{id}")] public async Task UpdateLogAsync(Guid id, TprdLogUpdateModel updateModel) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _TprdLogService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }