jinpengyong
2021-08-12 9b790d284324a54bd54de12a336e488e748a2b61
监测因子趋势图时间精简
2 files modified
27 ■■■■ changed files
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java 7 ●●●● patch | view | raw | blame | history
screen-common/src/main/java/com/moral/util/DateUtils.java 20 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -91,7 +91,7 @@
        String sensorCode = params.get("sensorCode").toString();
        String end;
        String timeUnits;
        String dateFormat;
        //返回结果集,time=data
        List<Map<String, Object>> result = new ArrayList<>();
@@ -99,18 +99,21 @@
            if ("hour".equals(type)) {
                end = DateUtils.getDateAddDay(start, 1);
                timeUnits = "hourly";
                dateFormat = "%Y-%m-%d %H";
            } else if ("day".equals(type)) {
                end = DateUtils.getDateAddMonth(start, 1);
                timeUnits = "daily";
                dateFormat = "%Y-%m-%d";
            } else {
                end = DateUtils.getDateAddYear(start, 1);
                timeUnits = "monthly";
                dateFormat = "%Y-%m";
            }
            params.put("timeUnits", timeUnits);
            params.put("start", start);
            params.put("end", end);
            params.put("macs", macs);
            params.put("dateFormat", "%Y-%m-%d %H:%i:%s");
            params.put("dateFormat", dateFormat);
            //获取多设备指定因子数据
            List<Map<String, Object>> list = deviceMapper.getTrendChartData(params);
screen-common/src/main/java/com/moral/util/DateUtils.java
@@ -1367,23 +1367,27 @@
        Calendar cal = Calendar.getInstance();
        String end;
        String dateFormat;
        String df;
        int i;
        if (length == 10) {//日
            end = getDateAddDay(time, 1);
            dateFormat = yyyy_MM_dd_EN;
            dateFormat = yyyy_MM_dd_HH_EN;
            df = yyyy_MM_dd_EN;
            i = Calendar.HOUR_OF_DAY;
        } else if (length == 7) {//月
            end = getDateAddMonth(time, 1);
            dateFormat = yyyy_MM_EN;
            dateFormat = yyyy_MM_dd_EN;
            df = yyyy_MM_EN;
            i = Calendar.DAY_OF_MONTH;
        } else {//年
            end = getDateAddYear(time, 1);
            dateFormat = yyyy;
            dateFormat = yyyy_MM_EN;
            df = yyyy;
            i = Calendar.MONTH;
        }
        cal.setTime(getDate(time, dateFormat));
        for (long d = cal.getTimeInMillis(); d < getDate(end, dateFormat).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) {
            String format = dateToDateString(new Date(d));
        cal.setTime(getDate(time, df));
        for (long d = cal.getTimeInMillis(); d < getDate(end, df).getTime(); cal.set(i, cal.get(i) + 1), d = cal.getTimeInMillis()) {
            String format = dateToDateString(new Date(d),dateFormat);
            result.add(format);
        }
        return result;
@@ -1403,4 +1407,8 @@
        stringBuffer.replace(15, 16, String.valueOf(i));
        return getDate(stringBuffer.toString(), yyyy_MM_dd_HH_mm_EN);
    }
    public static void main(String[] args) {
        System.out.println(getTimeLag("2021"));
    }
}