diff --git a/src/main/java/com/xydl/cac/controller/IedDlController.java b/src/main/java/com/xydl/cac/controller/IedDlController.java index 9526783..ec675c0 100644 --- a/src/main/java/com/xydl/cac/controller/IedDlController.java +++ b/src/main/java/com/xydl/cac/controller/IedDlController.java @@ -76,6 +76,16 @@ public class IedDlController extends BasicController { return Response.success(result); } + @PostMapping("rebuildData") + @ApiOperation("rebuildData") + public Response rebuildData(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception { + if (id == null) { + throw new BusinessException("id不能为空!"); + } + recordService.rebuildData(id); + return Response.success("OK"); + } + @GetMapping("listFiles") @ApiOperation("查询文件和目录") public Response> listFiles(Integer iedId, String path) throws Exception { diff --git a/src/main/java/com/xydl/cac/iec/IEDCollectService.java b/src/main/java/com/xydl/cac/iec/IEDCollectService.java index 5c7cfd8..b2965a5 100644 --- a/src/main/java/com/xydl/cac/iec/IEDCollectService.java +++ b/src/main/java/com/xydl/cac/iec/IEDCollectService.java @@ -228,7 +228,7 @@ public class IEDCollectService { record.setPath(_bizConfig.getDataNginxPath() + relativePath); record.setCreateTime(new Date()); log.info("采集到" + record.getRemotePath()); - _spectrogramHandler.processFile(record, localFullPath); + _spectrogramHandler.processFile(record); _dlRecordService.add(record); } } diff --git a/src/main/java/com/xydl/cac/service/IedDlRecordService.java b/src/main/java/com/xydl/cac/service/IedDlRecordService.java index 658a42a..0597284 100644 --- a/src/main/java/com/xydl/cac/service/IedDlRecordService.java +++ b/src/main/java/com/xydl/cac/service/IedDlRecordService.java @@ -1,6 +1,7 @@ package com.xydl.cac.service; import com.xydl.cac.entity.IedDlRecord; +import com.xydl.cac.exception.BusinessException; import org.springframework.data.domain.Page; public interface IedDlRecordService { @@ -12,4 +13,6 @@ public interface IedDlRecordService { boolean exist(IedDlRecord item); void update(IedDlRecord item); + + void rebuildData(Integer id) throws BusinessException; } diff --git a/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java b/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java index 6256300..08e2645 100644 --- a/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java +++ b/src/main/java/com/xydl/cac/service/impl/IedDlRecordServiceImpl.java @@ -2,6 +2,7 @@ package com.xydl.cac.service.impl; import com.xydl.cac.entity.IedDlConfig; import com.xydl.cac.entity.IedDlRecord; +import com.xydl.cac.exception.BusinessException; import com.xydl.cac.repository.IedDlRecordRepository; import com.xydl.cac.service.IedDlConfigService; import com.xydl.cac.service.IedDlRecordService; @@ -17,6 +18,7 @@ import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import javax.persistence.criteria.Predicate; import java.util.List; +import java.util.Optional; @Service @Slf4j @@ -83,4 +85,15 @@ public class IedDlRecordServiceImpl implements IedDlRecordService { repository.save(item); } + @Override + public void rebuildData(Integer id) throws BusinessException { + Optional optional = repository.findById(id); + if (!optional.isPresent()) { + throw new BusinessException("未找到该记录"); + } + IedDlRecord record = optional.get(); + spectrogramHandler.processFile(record); + repository.save(record); + } + } diff --git a/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java b/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java index 565227f..af604ea 100644 --- a/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java +++ b/src/main/java/com/xydl/cac/spectrogram/SpectrogramHandler.java @@ -1,5 +1,6 @@ package com.xydl.cac.spectrogram; +import com.xydl.cac.config.BizConfig; import com.xydl.cac.entity.IedDlRecord; import com.xydl.cac.entity.constants.Constants; import com.xydl.cac.model.spectrogram.SouthYsp; @@ -13,13 +14,16 @@ import javax.annotation.Resource; @Slf4j public class SpectrogramHandler { + @Resource + BizConfig bizConfig; @Resource ProcessorYsp processorYsp; - public void processFile(IedDlRecord record, String localFilePath) { + public void processFile(IedDlRecord record) { if (record.getTypeId() == null) { return; } + String localFilePath = record.getPath().replaceFirst(bizConfig.getDataNginxPath(), bizConfig.getDatapath()); try { // 油色谱谱图 if (record.getTypeId() == Constants.TypeYSP) {