| | |
| | | if (!CollectionUtils.isEmpty(macList)) {
|
| | | list = historyMinutelyService.getDevicesAvgDataToExcel(parameters);
|
| | | }
|
| | | for (Map<String, Object> map : list) {
|
| | | map.put("value", map.remove(sensorKey));
|
| | | }
|
| | | return new ResultBean<List<Map<String, Object>>>(list);
|
| | | }
|
| | |
|
| | |
| | | LocalDateTime end = value.with(TemporalAdjusters.lastDayOfMonth());
|
| | | parameters.put("start", start);
|
| | | parameters.put("end", end);
|
| | | int day=end.getDayOfMonth();
|
| | | List<String> timeList=new ArrayList<>();
|
| | | for(int i=0;i<=day-1;i++){
|
| | | timeList.add(start.plusDays(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
| | | }
|
| | | parameters.put("timeList", timeList);
|
| | | }else if("day".equals(parameters.get("type"))){
|
| | | String time = parameters.get("time")+"T00:00:00";
|
| | | LocalDateTime value = LocalDateTime.parse(time);
|
| | | LocalDateTime end=value.plusHours(23);
|
| | | parameters.put("timeUnits", "hourly");
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H");
|
| | | parameters.put("typeFormat", "%Y-%m-%d %H:%i");
|
| | | parameters.put("start", time);
|
| | | parameters.put("end", end);
|
| | | List<String> timeList=new ArrayList<>();
|
| | | for(int i=0;i<=23;i++){
|
| | | timeList.add(value.plusHours(i).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")));
|
| | | }
|
| | | parameters.put("timeList", timeList);
|
| | | }
|
| | | return historyMinutelyMapper.getDevicesAvgDataToExcel(parameters);
|
| | | }
|
| | |
| | | hm.time
|
| | | </select>
|
| | |
|
| | | <select id="getDevicesAvgDataToExcel" resultType="java.util.Map">
|
| | | SELECT
|
| | | d.name,DATE_FORMAT(time, #{typeFormat}) time,
|
| | | <select id="getDevicesAvgDataToExcel" resultType="java.util.LinkedHashMap">
|
| | | select
|
| | | rs.monitorPointName,rs.name,
|
| | | <foreach collection="timeList" separator="," item="time">
|
| | | max(case time when #{time} then rs.${sensorKey} else null end) as #{time}
|
| | | </foreach>
|
| | | from
|
| | | (SELECT
|
| | | m.name as monitorPointName,d.name,DATE_FORMAT(time, #{typeFormat}) time,
|
| | | <foreach collection="sensorKeys" separator="," item="sensorKey">
|
| | | AVG(json->'$.${sensorKey}[0]') AS '${sensorKey}'
|
| | | </foreach>
|
| | | FROM
|
| | | history_${timeUnits} h,
|
| | | device d
|
| | | device d,
|
| | | monitor_point m
|
| | | WHERE
|
| | | h.mac=d.mac
|
| | | AND
|
| | | h.time >= #{start}
|
| | | AND d.monitor_point_id=m.id
|
| | | AND h.time >= #{start}
|
| | | AND h.time <![CDATA[<=]]> #{end}
|
| | | AND h.mac in
|
| | | <foreach collection="macs" open="(" separator="," close=")"
|
| | |
| | | #{mac}
|
| | | </foreach>
|
| | | GROUP BY
|
| | | h.mac,d.name,DATE_FORMAT(time, #{typeFormat})
|
| | | h.mac,m.name,d.name,DATE_FORMAT(time, #{typeFormat})
|
| | | ORDER BY
|
| | | h.mac
|
| | | h.mac) rs
|
| | | GROUP BY rs.monitorPointName,rs.name
|
| | | order by rs.name
|
| | | </select>
|
| | |
|
| | | </mapper> |