|
@@ -1,7 +1,22 @@
|
|
|
package com.ips.system.service.impl;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.ips.common.utils.DateUtils;
|
|
|
+import com.ips.common.utils.StringUtils;
|
|
|
+import com.ips.system.domain.AlgorithmConfig;
|
|
|
+import com.ips.system.dto.AlgorithmParamsDto;
|
|
|
+import com.ips.system.service.IAlgorithmConfigService;
|
|
|
+import com.ips.system.utils.AlgorithmCaller;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ips.system.mapper.TimeFrequencyImagesMapper;
|
|
@@ -17,9 +32,14 @@ import com.ips.system.service.ITimeFrequencyImagesService;
|
|
|
@Service
|
|
|
public class TimeFrequencyImagesServiceImpl implements ITimeFrequencyImagesService
|
|
|
{
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
@Autowired
|
|
|
private TimeFrequencyImagesMapper timeFrequencyImagesMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAlgorithmConfigService algorithmConfigService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 查询时频图生成
|
|
|
*
|
|
@@ -93,4 +113,61 @@ public class TimeFrequencyImagesServiceImpl implements ITimeFrequencyImagesServi
|
|
|
{
|
|
|
return timeFrequencyImagesMapper.deleteTimeFrequencyImagesById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String run(Long id) {
|
|
|
+ TimeFrequencyImages timeFrequencyImages = timeFrequencyImagesMapper.selectTimeFrequencyImagesById(id);
|
|
|
+ if(timeFrequencyImages == null || timeFrequencyImages.getAlgorithmId() == null){
|
|
|
+ return "无法找到该任务,id:"+id;
|
|
|
+ }
|
|
|
+ Long algorithmId = timeFrequencyImages.getAlgorithmId();
|
|
|
+ AlgorithmConfig algorithmConfig = algorithmConfigService.selectAlgorithmConfigById(algorithmId);
|
|
|
+ timeFrequencyImages.setStartTime(new Date());
|
|
|
+ timeFrequencyImages.setStatus("1");
|
|
|
+ this.updateTimeFrequencyImages(timeFrequencyImages);
|
|
|
+
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ // 异步逻辑
|
|
|
+ doRun(algorithmConfig, timeFrequencyImages);
|
|
|
+ });
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doRun(AlgorithmConfig algorithmConfig, TimeFrequencyImages timeFrequencyImages) {
|
|
|
+ String algorithmPath = algorithmConfig.getAlgorithmPath();
|
|
|
+
|
|
|
+ // 组装json
|
|
|
+ String inputPath = timeFrequencyImages.getInputPath();
|
|
|
+ String outputPath = timeFrequencyImages.getOutputPath();
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ Map<String, Object> params = new HashMap<>(0);
|
|
|
+
|
|
|
+ String errorMsg = "";
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(timeFrequencyImages.getAlgorithmParams())) {
|
|
|
+
|
|
|
+ params = objectMapper.readValue(
|
|
|
+ timeFrequencyImages.getAlgorithmParams(),
|
|
|
+ new TypeReference<Map<String, Object>>() {
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ AlgorithmParamsDto algorithmParamsDto = new AlgorithmParamsDto(inputPath, outputPath, params);
|
|
|
+ // 对象 → JSON 字符串
|
|
|
+ String json = objectMapper.writeValueAsString(algorithmParamsDto);
|
|
|
+ // 处理算法
|
|
|
+ errorMsg = AlgorithmCaller.executeAlgorithm(algorithmConfig.getAlgorithmName(),algorithmPath, json);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ logger.error("格式化失败", e);
|
|
|
+ errorMsg = "格式化失败";
|
|
|
+ }
|
|
|
+ //处理结果
|
|
|
+ if (StringUtils.isEmpty(errorMsg)) {
|
|
|
+ timeFrequencyImages.setStatus("2");
|
|
|
+ } else {
|
|
|
+ timeFrequencyImages.setStatus("3");
|
|
|
+ }
|
|
|
+ timeFrequencyImages.setEndTime(new Date());
|
|
|
+ this.updateTimeFrequencyImages(timeFrequencyImages);
|
|
|
+ }
|
|
|
}
|