燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-06-05 aaa42c070d59c46ff0ed42a1d2748df6dd6a06d7
添加Voc操作接口
已添加1个文件
已修改3个文件
147 ■■■■ 文件已修改
src/main/java/com/yssh/dao/VocValsMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/scheduled/ReadCsvTask.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/service/VocValsService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapping/VocValsMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/yssh/dao/VocValsMapper.java
@@ -22,6 +22,14 @@
    public List<VocVals> selectByTime(String time, Double startVal);
    /**
     * æ ¹æ®æ—¶é—´ç»Ÿè®¡
     *
     * @param time æ—¶é—´ï¼ˆç¤ºä¾‹ï¼š2023060514)
     * @return è¡Œæ•°
     */
    public int countByTime(String time);
    /**
     * æ’入一条数据
     *
     * @param vv Voc实体类
src/main/java/com/yssh/scheduled/ReadCsvTask.java
@@ -8,8 +8,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -43,43 +41,36 @@
    @Autowired
    private IWarningAnalyseService warningAnalyseService;
    private final SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHH");
    @Scheduled(cron = "${csv.cron}")
    public void corpReserveDataSync() {
        /*Date date = DateUtils.getNowDate();
        String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
        String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv";
        File file = new File(filePath);
        if (!file.exists()) {
            logger.error(file.getAbsolutePath() + " is not exist ï¼");
            return;
        }
        //创建表
        String newTableName = TableStrategy.getTableStrategy(time);
        suYuanService.createNewTable(newTableName);
          dictRecordService.insertDictRecord(new DictRecord(1L, newTableName, Long.parseLong(time), ""));
        EasyCsv.read(filePath, SuYuan.class, new CsvParser(suYuanService, time)).doRead();
        //计算预警/报警,并且进行入库操作
        try {
            Thread.sleep(1000 * 60 * 1);
        } catch (InterruptedException e) {
            logger.error("睡眠一分钟后执行预警/报警计算,并且进行入库操作出现异常,异常原因是:", e);
            e.printStackTrace();
        loadVoc();
        loadCsv();
    }
    private void loadVoc() {
        Calendar calendar = getCalendar(96);
        for (int i = 0; i < 192; i++) {
            calendar.add(Calendar.HOUR, -1);
            String time = format.format(calendar.getTime());
            String filePath = csvFilePathConfig.getVocPath() + File.separator + time + ".csv";
            File file = new File(filePath);
            if (!file.exists()) {
                logger.error(file.getAbsolutePath() + " is not exist ï¼");
                continue;
            }
        }
        warningAnalyseService.warningOperationStorage(date);*/
    }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, 1);
        // æµ‹è¯• -> 2023-04-23 19:00
        //calendar.set(Calendar.MONTH, 3);
        //calendar.set(Calendar.DAY_OF_MONTH, 23);
        //calendar.set(Calendar.HOUR_OF_DAY, 20);
    private void loadCsv() {
        Calendar calendar = getCalendar(1);
        for (int i = 0; i < 25; i++) {
            calendar.add(Calendar.HOUR, -1);
            String time = dateFormat.format(calendar.getTime());
            String time = format.format(calendar.getTime());
            String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv";
            File file = new File(filePath);
@@ -109,4 +100,41 @@
            warningAnalyseService.warningOperationStorage(calendar.getTime());
        }
    }
    private Calendar getCalendar(int start) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.HOUR, start);
        // æµ‹è¯• -> 2023-04-23 19:00
        //calendar.set(Calendar.MONTH, 3);
        //calendar.set(Calendar.DAY_OF_MONTH, 23);
        //calendar.set(Calendar.HOUR_OF_DAY, 20);
        return calendar;
    }
    private void loadCsv_old() {
        Date date = DateUtils.getNowDate();
        String time = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, date);
        String filePath = csvFilePathConfig.getFilePath() + "\\\\" + time + ".csv";
        File file = new File(filePath);
        if (!file.exists()) {
            logger.error(file.getAbsolutePath() + " is not exist ï¼");
            return;
        }
        //创建表
        String newTableName = TableStrategy.getTableStrategy(time);
        suYuanService.createNewTable(newTableName);
        dictRecordService.insertDictRecord(new DictRecord(1L, newTableName, Long.parseLong(time), ""));
        EasyCsv.read(filePath, SuYuan.class, new CsvParser(suYuanService, time)).doRead();
        //计算预警/报警,并且进行入库操作
        try {
            Thread.sleep(1000 * 60 * 1);
        } catch (InterruptedException e) {
            logger.error("睡眠一分钟后执行预警/报警计算,并且进行入库操作出现异常,异常原因是:", e);
            e.printStackTrace();
        }
        warningAnalyseService.warningOperationStorage(date);
    }
}
src/main/java/com/yssh/service/VocValsService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,39 @@
package com.yssh.service;
import com.yssh.dao.VocValsMapper;
import com.yssh.entity.VocVals;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class VocValsService implements VocValsMapper {
    @Resource
    VocValsMapper vocValsMapper;
    @Override
    public List<VocVals> selectByTime(String time, Double startVal) {
        return vocValsMapper.selectByTime(time, startVal);
    }
    @Override
    public int countByTime(String time) {
        return vocValsMapper.countByTime(time);
    }
    @Override
    public int insert(VocVals vv) {
        return vocValsMapper.insert(vv);
    }
    @Override
    public int inserts(List<VocVals> list) {
        return vocValsMapper.inserts(list);
    }
    @Override
    public int deleteLastYear() {
        return vocValsMapper.deleteLastYear();
    }
}
src/main/resources/mapping/VocValsMapper.xml
@@ -20,6 +20,12 @@
        </where>
    </select>
    <select id="countByTime" resultType="java.lang.Integer">
        select count(*)
        from voc_vals
        where date_format(create_time, '%Y%m%d%H') = ${time}
    </select>
    <insert id="insert" parameterType="com.yssh.entity.VocVals" useGeneratedKeys="true" keyProperty="id">
        insert into voc_vals (x, y, val, create_time) values
        (${x}, ${y}, ${val}, ${createTime});