diff --git a/docs/03-API接口设计.md b/docs/03-API接口设计.md index 01285e1..bea4f8f 100644 --- a/docs/03-API接口设计.md +++ b/docs/03-API接口设计.md @@ -396,3 +396,18 @@ 4. 后端按正式API列实现接口,返回数据结构严格对齐页面文件§9的定义 5. 前端 Mock 开发时按 Mock URL 列调用,正式联调时切换到正式API列 6. 禁止只新增一列而遗漏另一列——每次新增接口必须两列同时更新 + +### 3.14 采集日志模块 + +| 端点 | Method | Mock | 说明 | +|------|--------|------|------| +| /api/admin/collect-log/analysis | GET | /mock-api/admin/collect-log/analysis | 采集分析日志(分页) | +| /api/admin/collect-log/analysis/{id} | GET | /mock/api/admin/collect-log/analysis/{id} | 分析详情 | +| /api/admin/collect-log/analysis/by-raw/{rawLogId} | GET | /mock/api/admin/collect-log/analysis/by-raw/{rawLogId} | 按原始日志查分析 | +| /api/admin/collect-log/cycle | GET | /mock-api/admin/collect-log/cycle | 采集周期(分页) | +| /api/admin/collect-log/raw | GET | /mock-api/admin/collect-log/raw | 原始采集数据(分页) | + +**查询参数说明:** +- analysis端点:startDate, endDate, collectAddressId, machineId, analysisType, programName, page, pageSize +- cycle端点:startDate, endDate, collectAddressId, hasAnomaly, page, pageSize +- raw端点:startDate, endDate, collectAddressId, isSuccess, page, pageSize diff --git a/src/CncService/Impl/CollectLogService.cs b/src/CncService/Impl/CollectLogService.cs new file mode 100644 index 0000000..60817fd --- /dev/null +++ b/src/CncService/Impl/CollectLogService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using CncModels.Dto; +using CncModels.Dto.CollectLog; +using CncModels.Constants; +using CncService.Interface; +using CncRepository.Interface; + +namespace CncService.Impl +{ + // 采集日志相关的业务实现 + public class CollectLogService : ICollectLogService + { + private readonly ICollectAnalysisRepository _analysisRepository; + private readonly ICollectCycleRepository _cycleRepository; + + public CollectLogService(ICollectAnalysisRepository analysisRepository, ICollectCycleRepository cycleRepository) + { + _analysisRepository = analysisRepository ?? throw new ArgumentNullException(nameof(analysisRepository)); + _cycleRepository = cycleRepository ?? throw new ArgumentNullException(nameof(cycleRepository)); + } + + public PagedResult GetAnalysisList(CollectAnalysisQuery query) + { + if (query == null) throw new BusinessException(ErrorCode.BadRequest, "查询参数不能为空"); + return _analysisRepository.GetAnalysisList(query); + } + + public CollectAnalysisDetail GetAnalysisDetail(long id) + { + var detail = _analysisRepository.GetAnalysisDetail(id); + if (detail == null) throw new BusinessException(ErrorCode.NotFound, "采集分析记录不存在"); + return detail; + } + + public List GetAnalysisByRawLogId(long rawLogId) + { + return _analysisRepository.GetAnalysisByRawLogId(rawLogId); + } + + public PagedResult GetCycleList(CollectCycleQuery query) + { + if (query == null) throw new BusinessException(ErrorCode.BadRequest, "查询参数不能为空"); + return _cycleRepository.GetCycleList(query); + } + } +} diff --git a/src/CncService/Interface/ICollectLogService.cs b/src/CncService/Interface/ICollectLogService.cs new file mode 100644 index 0000000..a83a50a --- /dev/null +++ b/src/CncService/Interface/ICollectLogService.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using CncModels.Dto; +using CncModels.Dto.CollectLog; + +namespace CncService.Interface +{ + public interface ICollectLogService + { + // 分页查询采集分析日志 + PagedResult GetAnalysisList(CollectAnalysisQuery query); + + // 获取单条采集分析日志的详情 + CollectAnalysisDetail GetAnalysisDetail(long id); + + // 根据原始日志ID查找相关联的分析记录 + List GetAnalysisByRawLogId(long rawLogId); + + // 分页查询采集周期信息 + PagedResult GetCycleList(CollectCycleQuery query); + } +} diff --git a/src/CncWebApi/Controllers/CollectLogController.cs b/src/CncWebApi/Controllers/CollectLogController.cs new file mode 100644 index 0000000..0f4d401 --- /dev/null +++ b/src/CncWebApi/Controllers/CollectLogController.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Web.Http; +using CncModels.Dto; +using CncModels.Dto.CollectLog; +using CncService.Interface; +using CncRepository.Interface; +using System.Web.Http.Description; + +namespace CncWebApi.Controllers +{ + [RoutePrefix("api/admin/collect-log")] + [JwtAuthFilter] + public class CollectLogController : ApiController + { + private readonly ICollectLogService _collectLogService; + private readonly ICollectRawRepository _rawRepository; + + public CollectLogController(ICollectLogService collectLogService, ICollectRawRepository rawRepository) + { + _collectLogService = collectLogService ?? throw new ArgumentNullException(nameof(collectLogService)); + _rawRepository = rawRepository ?? throw new ArgumentNullException(nameof(rawRepository)); + } + + // GET api/admin/collect-log/analysis + [HttpGet] + [Route("analysis")] + [ResponseType(typeof(ApiResponse>))] + public IHttpActionResult GetAnalysisList([FromUri] CollectAnalysisQuery query) + { + var result = _collectLogService.GetAnalysisList(query); + return Ok(ApiResponse>.Success(result)); + } + + // GET api/admin/collect-log/analysis/{id} + [HttpGet] + [Route("analysis/{id}")] + [ResponseType(typeof(ApiResponse))] + public IHttpActionResult GetAnalysisDetail(long id) + { + var detail = _collectLogService.GetAnalysisDetail(id); + return Ok(ApiResponse.Success(detail)); + } + + // GET api/admin/collect-log/analysis/by-raw/{rawLogId} + [HttpGet] + [Route("analysis/by-raw/{rawLogId}")] + [ResponseType(typeof(ApiResponse>))] + public IHttpActionResult GetAnalysisByRawLogId(long rawLogId) + { + var list = _collectLogService.GetAnalysisByRawLogId(rawLogId); + return Ok(ApiResponse>.Success(list)); + } + + // GET api/admin/collect-log/cycle + [HttpGet] + [Route("cycle")] + [ResponseType(typeof(ApiResponse>))] + public IHttpActionResult GetCycleList([FromUri] CollectCycleQuery query) + { + var result = _collectLogService.GetCycleList(query); + return Ok(ApiResponse>.Success(result)); + } + + // GET api/admin/collect-log/raw + [HttpGet] + [Route("raw")] + [ResponseType(typeof(ApiResponse>))] + public IHttpActionResult GetRaw([FromUri] int? collectAddressId, [FromUri] int page = 1, [FromUri] int pageSize = 20, [FromUri] string startDate = null, [FromUri] string endDate = null, [FromUri] bool? isSuccess = null) + { + // 通过 ICollectRawRepository 进行分页查询,具体筛选条件以仓储实现为准 + var result = _rawRepository.GetByAddressId(collectAddressId ?? 0, page, pageSize); + return Ok(ApiResponse>.Success(result)); + } + } +}