| | |
| | | package com.moral.service.impl; |
| | | |
| | | import com.moral.mapper.*; |
| | | import io.swagger.models.auth.In; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.NumberFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Instant; |
| | |
| | | |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import org.apache.jasper.compiler.JspUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | |
| | | import com.moral.mapper.MonitorPointMapper; |
| | | import com.moral.mapper.ProvinceMapper; |
| | | import com.moral.mapper.SensorMapper; |
| | | import com.moral.mapper.ShAreaMapper; |
| | | import com.moral.service.HistoryMinutelyService; |
| | | import com.sun.org.apache.bcel.internal.generic.ANEWARRAY; |
| | | |
| | | import static com.moral.common.bean.Constants.NULL_VALUE; |
| | | import static org.springframework.util.ObjectUtils.isEmpty; |
| | |
| | | |
| | | @Resource |
| | | private MonitorPointMapper monitorPointMapper; |
| | | @Resource |
| | | HistoryFiveMinutelyMapper historyFiveMinutelyMapper; |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getFiveMinutesDataByMacsAndTime(Map<String, Object> parameters) { |
| | | ValidateUtil.notNull(parameters,"查询五分钟数据参数为空"); |
| | | return historyFiveMinutelyMapper.getFiveMinutesDataByMacsAndTime(parameters); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getDayAQIByDevice(Map<String, Object> parameters) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> get(Map<String, Object> parameters) throws Exception { |
| | | convertQueryParam(parameters); |
| | | if (!ObjectUtils.isEmpty(parameters.get("compensate"))) { |
| | | parameters.put("timeUnits", "10min"); |
| | | } |
| | | return historyMinutelyMapper.getMultiDeviceSensorData(parameters); |
| | | } |
| | | |
| | | @Override |
| | | public void convertQueryParam(Map<String, Object> parameters) throws ParseException { |
| | | if (!parameters.containsKey("field")) { |
| | | // String type = (String) parameters.get("type"); |
| | | // parameters.putAll(getElementByType(type)); |
| | | ParameterUtils.getElementByType(parameters); |
| | | if (parameters.containsKey("timeUnits")) { |
| | | if ("minutely".equals(parameters.get("timeUnits"))) { |
| | |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getMultiDeviceSensorData(Map<String, Object> parameters) throws Exception { |
| | | String sensorKey = parameters.get("sensorKey").toString(); |
| | | String[] macs = parameters.get("macs").toString().split(","); |
| | | List<String> sensorKeys = new ArrayList<>(); |
| | | sensorKeys.add(sensorKey); |
| | | parameters.put("sensorKeys", sensorKeys); |
| | | parameters.put("sensors", sensorKeys); |
| | | String type = parameters.get("type").toString(); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (int i = 0; i < 31; i++) { |
| | | list.add(null); |
| | | } |
| | | for (String mac : macs) { |
| | | parameters.put("mac", mac); |
| | | List<Map<String, Object>> data = getMonitorPointOrDeviceAvgData(parameters); |
| | | List<Map<String, Object>> l = new ArrayList<>(); |
| | | for (int i = 0; i < 31; i++) { |
| | | l.add(null); |
| | | } |
| | | for (Map<String, Object> dataMap : data) { |
| | | String time = dataMap.get("time").toString(); |
| | | Integer t = Integer.valueOf(time.substring(time.length() - 2)); |
| | | dataMap.put("time", t); |
| | | if ("day".equals(type)) { |
| | | l.set(t, dataMap); |
| | | } else { |
| | | l.set(t - 1, dataMap); |
| | | } |
| | | } |
| | | for (int i = 0; i < l.size(); i++) { |
| | | if (l.get(i) == null) { |
| | | Map<String, Object> m = new HashMap<>(); |
| | | List<String> v = new ArrayList<>(); |
| | | v.add(""); |
| | | if ("day".equals(type)) { |
| | | m.put("time", i); |
| | | } else { |
| | | m.put("time", i + 1); |
| | | } |
| | | m.put("values", v); |
| | | l.set(i, m); |
| | | } |
| | | } |
| | | data = l; |
| | | for (Map<String, Object> map : data) { |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | if (map != null) { |
| | | int t = Integer.valueOf(map.get("time").toString()); |
| | | hashMap.put("time", t); |
| | | String value; |
| | | if (map.get(sensorKey) == null) { |
| | | value = ""; |
| | | } else { |
| | | value = map.get(sensorKey).toString(); |
| | | } |
| | | List<String> values; |
| | | |
| | | if ("day".equals(type)) { |
| | | t = t + 1; |
| | | } |
| | | if (list.get(t - 1) != null) { |
| | | values = (ArrayList<String>) list.get(t - 1).get("values"); |
| | | } else { |
| | | values = new ArrayList<>(); |
| | | } |
| | | values.add(value); |
| | | hashMap.put("values", values); |
| | | list.set(t - 1, hashMap); |
| | | } |
| | | } |
| | | } |
| | | boolean flag = false; |
| | | Iterator<Map<String, Object>> iterator = list.iterator(); |
| | | int digit = 0; |
| | | while (iterator.hasNext()) { |
| | | Map<String, Object> next = iterator.next(); |
| | | ArrayList<String> values = (ArrayList<String>) next.get("values"); |
| | | for (String value : values) { |
| | | if ("".equals(value)) { |
| | | flag = true; |
| | | } else { |
| | | digit = value.split("\\.")[1].length(); |
| | | flag = false; |
| | | break; |
| | | } |
| | | } |
| | | if (flag) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | NumberFormat nf = NumberFormat.getNumberInstance(); |
| | | nf.setMaximumFractionDigits(digit); |
| | | for (Map<String, Object> map : list) { |
| | | int time = Integer.valueOf(map.get("time").toString()); |
| | | ArrayList<String> values = (ArrayList<String>) map.get("values"); |
| | | if (values.size() > 1) { |
| | | int length = 0; |
| | | double sum = 0.0; |
| | | for (String value : values) { |
| | | if (!"".equals(value)) { |
| | | Double v = Double.valueOf(value); |
| | | length += 1; |
| | | sum += v; |
| | | } |
| | | } |
| | | Double avg = sum / length; |
| | | String format = nf.format(avg); |
| | | values.add(format); |
| | | map.put("values", values); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getDevicesSensorsToExcel(Map<String, Object> parameters) { |
| | | String[] sensorKeys = parameters.get("sensorKey").toString().split(","); |
| | | parameters.put("sensorKeys", Arrays.asList(sensorKeys)); |
| | | return null; |
| | | } |
| | | } |