dcb
9 天以前 0e6106783b59c2c4e173ad4b709c1415686e7505
停止实时模拟时更新停止时间
已修改2个文件
16 ■■■■ 文件已修改
src/main/java/com/se/nsl/service/RealTimeSimulationAsyncService.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/SimuMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/nsl/service/RealTimeSimulationAsyncService.java
@@ -19,12 +19,15 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.web.client.ResourceAccessException;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -58,7 +61,7 @@
    // 存储任务执行状态
    private final Map<Integer, TaskStatus> taskStatusMap = new ConcurrentHashMap<>();
    // 存储任务执行的Future对象,用于取消任务
    private final Map<String, Future<?>> taskFutureMap = new ConcurrentHashMap<>();
//    private final Map<String, Future<?>> taskFutureMap = new ConcurrentHashMap<>();
    @Async("realTimeExecutor")
    public void startSimulation(Simu simu) throws IOException {
@@ -111,6 +114,8 @@
    //更新模拟任务的运行状态到数据库
    private void updateTaskStatus(Simu simu, String result) {
        simu.setResult(result);
        Timestamp now = Timestamp.from(Instant.now());
        simu.setUpdateTime(now);
        simuMapper.updateResult(simu);
    }
@@ -313,7 +318,7 @@
    //将雨量计中空值(intensity为-1)的部分填充值
    private void fillEmptyValue(List<RainRecord> rainRecords) {
        double[] rainValues = rainRecords.stream().mapToDouble(r -> r.getIntensity()).toArray();
        double[] rainValues = rainRecords.stream().mapToDouble(RainRecord::getIntensity).toArray();
        double[] forwardValues = forwardFill(rainValues);
        double[] backwordValues = backwordFill(rainValues);
        for (int i = 0; i < rainRecords.size(); i++) {
@@ -386,6 +391,7 @@
        input.setFilterObject(filterObject);
        String url = rtsConfig.getUrl();
        String token = rtsConfig.getToken();
        try {
        ResponseEntity<String> post = HttpRequestUtil.post(url, input, String.class, token);
        String body = post.getBody();
        JsonNode jsonNode = mapper.readTree(body);
@@ -393,6 +399,9 @@
        if (!pageData.isEmpty()) {
            return pageData.get(0).get("value").asDouble();
        }
        } catch (ResourceAccessException e) {
            log.error("无法获取到雨量站数据:", e);
        }
        return -1D;
    }
src/main/resources/mapper/SimuMapper.xml
@@ -85,6 +85,7 @@
    </update>
    <update id="updateResult" parameterType="com.se.nsl.domain.po.Simu">
        update nsl.tbl_yj_tr_simulate set result=#{result} where id = #{id}
        update nsl.tbl_yj_tr_simulate set result=#{result},update_time=#{updateTime}
        where id = #{id}
    </update>
</mapper>