using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model; using Ropin.Inspection.Model.SearchModel; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api.Controllers { public class ReportController : BaseController { public ILogger _logger { get; } private readonly IReportService _service; /// /// 构造函数 /// /// /// public ReportController(IReportService service, ILogger logger) { _service = service; _logger = logger; } /// /// 通过ID获取报表信息 /// /// /// [HttpGet("GetReportDataAsync/{id}")] public async Task GetReportDataAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { object Report = await _service.GetReportDataByIdAsync(id); return new ApiResult(Report); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件获取报表记录,不包含报表数据,带分页 /// /// /// [HttpPost("GetWithoutReportData")] public async Task GetWithoutReportData(ReportSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var reportList = await _service.GetWithoutReportData(searchModel); return new ApiResult>(new PagesModel(reportList?.ToList(), searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 更新巡检记录 /// /// /// /// [HttpPut("UpdateReportAsync/{id}")] public async Task UpdateReportAsync(Guid id, ReportUpdateViewModel updateModel) { if (Guid.Empty == id|| updateModel == null) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除 /// /// /// [HttpDelete("DeleteReportAsync/{id}")] public async Task DeleteReportAsync(Guid id) { if (Guid.Empty == id) { return new ApiResult(ReturnCode.GeneralError); } try { await _service.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } } }