燕山石化溯源三维电子沙盘-【后端】-服务
1
13693261870
2023-08-10 c7cc3d90df2a412063188e5cdf025de6cd5bfcd9
src/main/java/com/yssh/service/XlsReportService.java
@@ -5,6 +5,7 @@
import com.yssh.entity.xls.DayExcel;
import com.yssh.entity.xls.MonthExcel;
import com.yssh.entity.xls.WeekExcel;
import com.yssh.entity.xls.XlsReport;
import com.yssh.mapper.XlsReportMapper;
import com.yssh.utils.CalculateUtils;
import com.yssh.utils.DateUtils;
@@ -54,15 +55,6 @@
    private double bjz;
    /**
     * Excel是否已存在
     */
    private boolean xlsExists(String type, String name) {
        int rows = mapper.reportExists(type, name);
        return rows > 0;
    }
    /**
     * 获取导出路径
     */
    private String getExpPath(String type) {
@@ -103,9 +95,32 @@
        String strData = DateUtils.parseDateToStr("month".equals(type) ? DateUtils.YYYYMM : DateUtils.YYYYMMDD, date);
        String target = String.format("%s\\%s.xlsx", getExpPath(type), strData);
        createExcel(source, target, list);
        File f = new File(target);
        if (!f.exists() || f.isDirectory()) {
            createExcel(source, target, list);
        }
        return String.format("%s\\%s.xlsx", type, strData);
    }
    /**
     * 保存结果
     */
    private <T> void saveResult(String type, Date date, List<T> list) throws Exception {
        date = DateUtils.trimTime(date);
        String filePath = createExcel(type, date, list);
        String name = filePath.replace(type + "\\", "");
        int rows = mapper.reportExists(type, name);
        if (rows > 0) return;
        XlsReport xls = new XlsReport();
        xls.setName(name);
        xls.setType(type);
        xls.setPath(filePath);
        xls.setCreateTime(date);
        mapper.insertReport(xls);
    }
    /**
@@ -132,61 +147,86 @@
    }
    /**
     * 创建日报:DayExcel day = new DayExcel("AI-" + (i < 10 ? "0" : "") + i, "lj", "ljtb", "ys", "3m/s", "东南", "°c");
     * 创建日报:new DayExcel("AI-" + (i < 10 ? "0" : "") + i, "lj", "ljtb", "ys", "3m/s", "东南", "°c");
     */
    public void createDayReport(Date date) {
        try {
            Date yesterday = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE);
            String yyyy = DateUtils.parseDateToStr(DateUtils.YYYY, yesterday); // 2023
            String yyyymmdd = DateUtils.parseDateToStr(DateUtils.YYYYMMDD, yesterday); // 20230724
            String yyyy_mm_dd = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, yesterday); // 2023-07-24
            Integer start = Integer.parseInt(yyyy + "010100"); // 2023010100
            // String yyyy_mm_dd = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, yesterday); // 2023-07-24
            Integer yearStart = Integer.parseInt(yyyy + "010100"); // 2023010100
            Integer dayStart = Integer.parseInt(yyyymmdd + "00"); // 2023072400
            Integer end = Integer.parseInt(yyyymmdd + "23"); // 2023072423
            String lastYear = DateUtils.parseDateToStr(DateUtils.YYYY, DateUtils.lastYear(yesterday)); // 2022
            List<DayExcel> list = new ArrayList<>();
            for (int i = 1; i < 47; i++) {
                String name = "AI-" + (i < 10 ? "0" : "") + i;
                double rjz = mapper.selectDayAvg(yyyymmdd + "%", name);
                double lj = mapper.selectAccumulate(start, end, name);
                double lastLj = mapper.selectYearAccumulate(lastYear + "%", name);
                double ljtb = CalculateUtils.round2((lj - lastLj) / lastLj * 100);
                double rjz = mapper.selectDayAvg(yyyymmdd + "%", name); // 日均值
                double lj = mapper.selectAccumulate(yearStart, end, name); // 累计
                double lastLj = mapper.selectYearAccumulate(lastYear + "%", name); // 去年累计
                double ljtb = CalculateUtils.round2((lj - lastLj) / lastLj * 100); // 累计同比
                MonitorPointPosition point = commonService.select3dCheckPointByName(name);
                String id = point.getId().substring(0, point.getId().lastIndexOf("_") + 1) + "0";
                List<SuYuan700> suList = mapper.selectSuYuanByTime(id, yyyy_mm_dd + " 00:00:00", yyyy_mm_dd + " 23:00:00");
                // List<SuYuan700> suList = mapper.selectSuYuanByTime(id, yyyy_mm_dd + " 00:00:00", yyyy_mm_dd + " 23:00:00");
                List<SuYuan700> suList = mapper.selectSuYuanByStartAndEnd(id, name, yjz, dayStart, end);
                String ys = getYs(suList);
                list.add(new DayExcel("" + rjz, "" + lj, ljtb + "%", ys, "", "", ""));
            }
            String filePath = createExcel("day", yesterday, list);
            saveResult("day", yesterday, list);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    /**
     * 创建周报
     * 创建周报:new WeekExcel("AI-" + (i < 10 ? "0" : "") + i, "zhb", "ztq", "ztb", "zhb2", "lj", "ljtb", "syn", "ys", "fs", "fx", "°c");
     */
    public void createWeekReport(Date date) {
        try {
            Date start = DateUtils.getAPeriodOfTime(date, -7, Calendar.DATE);
            Date end = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE);
            Date mon = DateUtils.getAPeriodOfTime(date, -7, Calendar.DATE);
            Date sun = DateUtils.getAPeriodOfTime(date, -1, Calendar.DATE);
            Date lastMon = DateUtils.getAPeriodOfTime(date, -14, Calendar.DATE);
            Date lastSun = DateUtils.getAPeriodOfTime(date, -8, Calendar.DATE);
            Date lastYearMon = DateUtils.getAPeriodOfTime(mon, -1, Calendar.YEAR);
            Date lastYearSun = DateUtils.getAPeriodOfTime(sun, -1, Calendar.YEAR);
            Integer intMon = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, mon) + "00"); // 2023072400
            Integer intSun = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, sun) + "23"); // 2023073023
            Integer intLastMon = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, lastMon) + "00"); // 2023071700
            Integer intLastSun = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, lastSun) + "23"); // 2023072323
            Integer intLastYearMon = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, lastYearMon) + "00"); // 2022071700
            Integer intLastYearSun = Integer.parseInt(DateUtils.parseDateToStr(DateUtils.YYYYMMDD, lastYearSun) + "23"); // 2022072323
            String yyyy = DateUtils.parseDateToStr(DateUtils.YYYY, sun); // 2023
            Integer yearStart = Integer.parseInt(yyyy + "010100"); // 2023010100
            String lastYear = DateUtils.parseDateToStr(DateUtils.YYYY, DateUtils.lastYear(sun)); // 2022
            List<WeekExcel> list = new ArrayList<>();
            for (int i = 1; i < 47; i++) {
                WeekExcel day = new WeekExcel("AI-" + (i < 10 ? "0" : "") + i, "zhb", "ztq", "ztb", "zhb2", "lj", "ljtb", "syn", "ys", "fs", "fx", "°c");
                list.add(day);
                String name = "AI-" + (i < 10 ? "0" : "") + i;
                double sz = mapper.selectAccumulate(intMon, intSun, name); // 上周
                double ssz = mapper.selectAccumulate(intLastMon, intLastSun, name); // 上上周
                double zhb = CalculateUtils.round2((sz - ssz) / ssz * 100); // 周环比
                double qntq = mapper.selectAccumulate(intLastYearMon, intLastYearSun, name); // 去年同期
                double ztb = CalculateUtils.round2((sz - qntq) / qntq * 100); // 周同比
                double lj = mapper.selectAccumulate(yearStart, intSun, name); // 累计
                double lastLj = mapper.selectYearAccumulate(lastYear + "%", name); // 去年累计
                double ljtb = CalculateUtils.round2((lj - lastLj) / lastLj * 100); // 累计同比
                MonitorPointPosition point = commonService.select3dCheckPointByName(name);
                String id = point.getId().substring(0, point.getId().lastIndexOf("_") + 1) + "0";
                List<SuYuan700> suList = mapper.selectSuYuanByStartAndEnd(id, name, yjz, intMon, intSun);
                String ys = getYs(suList);
                list.add(new WeekExcel("" + sz, zhb + "%", "", ztb + "%", "", "" + lj, "" + ljtb, "", ys, "", "", ""));
            }
            String filePath = createExcel("week", end, list);
            saveResult("week", sun, list);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    /**
     * 创建月报
     * 创建月报:new MonthExcel("AI-" + (i < 10 ? "0" : "") + i, "yhb", "ytq", "ytb", "yhb2", "lj", "ljtb", "qyn", "ys", "fs", "fx", "°c");
     */
    public void createMonthReport(Date date) {
        try {
@@ -196,8 +236,7 @@
            List<MonthExcel> list = new ArrayList<>();
            for (int i = 1; i < 47; i++) {
                MonthExcel day = new MonthExcel("AI-" + (i < 10 ? "0" : "") + i, "yhb", "ytq", "ytb", "yhb2", "lj", "ljtb", "qyn", "ys", "fs", "fx", "°c");
                list.add(day);
                //
            }
            String filePath = createExcel("month", end, list);