|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.OutputStream; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Calendar; | 
|---|
|  |  |  | import java.util.HashMap; | 
|---|
|  |  |  | import java.util.LinkedHashMap; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.ServletOutputStream; | 
|---|
|  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import org.apache.commons.collections.CollectionUtils; | 
|---|
|  |  |  | import org.apache.commons.lang.StringUtils; | 
|---|
|  |  |  | import org.springframework.util.ObjectUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.CrossOrigin; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String type = parameters.get("type").toString(); | 
|---|
|  |  |  | String time = parameters.get("time").toString(); | 
|---|
|  |  |  | System.out.println(parameters); | 
|---|
|  |  |  | String timeb = ""; | 
|---|
|  |  |  | if (parameters.get("timeb") == null) { | 
|---|
|  |  |  | timeb = parameters.get("time").toString(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public interface HistoryMinutelyMapper { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Double> getSersionAvgByDevice(Map<String, Object> parameters); | 
|---|
|  |  |  | Map<String, Double> getSersionAvgByDevice(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Double> getAvgByDevice(Map<String, Object> parameters); | 
|---|
|  |  |  | Map<String, Double> getAvgByDevice(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getMonitorPointOrDeviceAvgData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getAreaAvgDataByAreaCode(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getAreaAvgDataByAreaCode(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @param sensorKeys | 
|---|
|  |  |  | * @param timePeriod | 
|---|
|  |  |  | * @param dataCondition | 
|---|
|  |  |  | * @return {format_time:string,e1:double,e2...............} | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | List<Map<String, Object>> selectLineChartDateByCrieria(@Param("sensorKeys") List<String> sensorKeys, @Param("timePeriod") TimePeriod timePeriod, @Param("dataCondition") DataCondition dataCondition); | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @param sensorKeys | 
|---|
|  |  |  | * @param timePeriod | 
|---|
|  |  |  | * @param dataCondition | 
|---|
|  |  |  | * @return {format_time:string,e1:double,e2...............} | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | List<Map<String, Object>> selectLineChartDateByCrieria(@Param("sensorKeys") List<String> sensorKeys, @Param("timePeriod") TimePeriod timePeriod, @Param("timeUnits") String timeUnits, @Param("dataCondition") DataCondition dataCondition); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getSensorData(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getSensorData(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getSensorData2020(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getSensorData2020(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getDevicesAvgDataToExcel(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getDevicesAvgDataToExcel(Map<String, Object> parameters); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Map<String, Object>> getDevicesSensorsAvgDataToExcel(Map<String, Object> parameters); | 
|---|
|  |  |  | List<Map<String, Object>> getDevicesSensorsAvgDataToExcel(Map<String, Object> parameters); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.time.Instant; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.LocalDateTime; | 
|---|
|  |  |  | import java.time.ZoneId; | 
|---|
|  |  |  | import java.time.ZonedDateTime; | 
|---|
|  |  |  | import java.time.format.DateTimeFormatter; | 
|---|
|  |  |  | import java.time.temporal.TemporalAdjusters; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | 
|---|
|  |  |  | // String type = (String) parameters.get("type"); | 
|---|
|  |  |  | // parameters.putAll(getElementByType(type)); | 
|---|
|  |  |  | ParameterUtils.getElementByType(parameters); | 
|---|
|  |  |  | if (parameters.containsKey("timeUnits")) { | 
|---|
|  |  |  | if ("minutely".equals(parameters.get("timeUnits"))) { | 
|---|
|  |  |  | if (parameters.containsKey("time")) { | 
|---|
|  |  |  | String[] timeStr = parameters.get("time").toString().split("-"); | 
|---|
|  |  |  | int year = Integer.valueOf(timeStr[0]); | 
|---|
|  |  |  | int month = Integer.valueOf(timeStr[1]); | 
|---|
|  |  |  | String yearAndMonth; | 
|---|
|  |  |  | if (month < 10) { | 
|---|
|  |  |  | yearAndMonth = "minutely_" + year + "0" + month; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | yearAndMonth = "minutely_" + year + month; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (year >= 2020) { | 
|---|
|  |  |  | parameters.put("timeUnits", yearAndMonth); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String time = (String) parameters.get("time"); | 
|---|
|  |  |  | String format = (String) parameters.get("format"); | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public Map<String, List<Double>> queryOneLineChartDateByCrieria(List<String> sensorKeys, TimePeriod timePeriod, DataCondition dataCondition) { | 
|---|
|  |  |  | List<String> timeList = ReportTimeFormat.makeTimeList(timePeriod); | 
|---|
|  |  |  | List<Map<String, Object>> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKeys, timePeriod, dataCondition); | 
|---|
|  |  |  | Instant instant = timePeriod.getStartTime().toInstant(); | 
|---|
|  |  |  | ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault()); | 
|---|
|  |  |  | LocalDate localDate = zdt.toLocalDate(); | 
|---|
|  |  |  | int year = localDate.getYear(); | 
|---|
|  |  |  | int month = localDate.getMonthValue(); | 
|---|
|  |  |  | String timeUnits; | 
|---|
|  |  |  | if (year < 2020) { | 
|---|
|  |  |  | timeUnits = "minutely"; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (month < 10) { | 
|---|
|  |  |  | timeUnits = "minutely_" + year + "0" + month; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | timeUnits = "minutely_" + year + month; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> lineChartDatas = historyMinutelyMapper.selectLineChartDateByCrieria(sensorKeys, timePeriod, timeUnits, dataCondition); | 
|---|
|  |  |  | Map<String, List<Double>> lineChartDatasWithEmpty = new HashMap<>(); | 
|---|
|  |  |  | // lineChartDatasWithEmpty 初始化 | 
|---|
|  |  |  | sensorKeys.forEach(sensorKey -> { | 
|---|
|  |  |  | 
|---|
|  |  |  | DATE_FORMAT(time,'${@com.moral.common.util.ReportTimeFormat@toMySqlTimeFormat(timePeriod.timeUnits)}') as | 
|---|
|  |  |  | format_time | 
|---|
|  |  |  | FROM | 
|---|
|  |  |  | `history_minutely` hmi | 
|---|
|  |  |  | history_${timeUnits} hmi | 
|---|
|  |  |  | <where> | 
|---|
|  |  |  | and hmi.time >= #{timePeriod.startTime} | 
|---|
|  |  |  | and hmi.time <![CDATA[<=]]> #{timePeriod.endTime} | 
|---|