| | |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.ConvertUtils; |
| | | import com.moral.util.DateUtils; |
| | | import com.sun.javafx.collections.MappingChange; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import java.beans.PropertyDescriptor; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Type; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | return deviceInfo; |
| | | } |
| | | |
| | | @Autowired |
| | | private HistoryHourlyMapper historyHourlyMapper; |
| | | @Override |
| | | public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData) { |
| | | public Map<String, Object> adjustDeviceData(Map<String, Object> deviceData,String code) { |
| | | String mac = deviceData.remove("mac").toString(); |
| | | //从redis获取校准公式 |
| | | Map<String, Object> adjustFormula = redisTemplate.opsForHash().entries(RedisConstants.ADJUST + "_" + mac); |
| | |
| | | Map<String, Object> aqiMap = null; |
| | | if (govMpInfo.get("guid") != null) { |
| | | aqiMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMpInfo.get("guid").toString()); |
| | | } |
| | | if (code.equals("2")){ |
| | | if (ObjectUtils.isEmpty(aqiMap.get("a21005")) || ObjectUtils.isEmpty(aqiMap.get("a21026")) |
| | | || ObjectUtils.isEmpty(aqiMap.get("a21004")) || ObjectUtils.isEmpty(aqiMap.get("a34002")) |
| | | || ObjectUtils.isEmpty(aqiMap.get("a34004")) || ObjectUtils.isEmpty(aqiMap.get("a05024")) |
| | | || ObjectUtils.isEmpty(aqiMap)){ |
| | | HashMap<String, Object> result = new HashMap<>(); |
| | | String dataTime = deviceData.get("DataTime").toString(); |
| | | Date time = DateUtils.getDate(dataTime, DateUtils.yyyyMMddHHmmss_EN); |
| | | String yearAndMonth = DateUtils.dateToDateString(DateUtils.addHours(time, -1), DateUtils.yyyyMM_EN); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00"); |
| | | String format = simpleDateFormat.format(DateUtils.addHours(time, -1)); |
| | | result.put("timeUnits",yearAndMonth); |
| | | result.put("mac",mac); |
| | | result.put("time",format); |
| | | Map<String, Object> map = historyHourlyMapper.selectHistoryHourly(result); |
| | | if (!ObjectUtils.isEmpty(map)){ |
| | | return JSON.parseObject(map.get("value").toString(), Map.class); |
| | | } |
| | | } |
| | | } |
| | | return adjustDataUtils.adjust(deviceData, adjustFormula, ObjectUtils.isEmpty(aqiMap) ? null : aqiMap); |
| | | } |
| | |
| | | String sensorCode = sensor.getCode(); |
| | | //转换公式 |
| | | String formula = sensor.getFormula(); |
| | | //转换单位前因子值 |
| | | String sensorValue = (String) deviceData.get(sensorCode); |
| | | double value = Double.parseDouble(sensorValue); |
| | | //单位转换 |
| | | if (formula != null) { |
| | | //转换后因子值 |
| | | sensorValue = formula.replace("{0}", sensorValue); |
| | | expression = AviatorEvaluator.compile(sensorValue); |
| | | value = Double.parseDouble(expression.execute().toString()); |
| | | } |
| | | int sensorState = judgeState(list, value); |
| | | if (sensorState > state) { |
| | | state = sensorState; |
| | | |
| | | //设备所传因子与配置型号因子不一致的处理逻辑 |
| | | if (deviceData.get(sensorCode) != null) { |
| | | String sensorValue = String.valueOf(deviceData.get(sensorCode)); |
| | | double value = Double.parseDouble(sensorValue); |
| | | if (formula != null) { |
| | | //转换后因子值 |
| | | sensorValue = formula.replace("{0}", sensorValue); |
| | | expression = AviatorEvaluator.compile(sensorValue); |
| | | value = Double.parseDouble(expression.execute().toString()); |
| | | } |
| | | int sensorState = judgeState(list, value); |
| | | if (sensorState > state) { |
| | | state = sensorState; |
| | | } |
| | | } |
| | | } |
| | | //修改设备状态 |
| | |
| | | @Override |
| | | public List<Map<String, Object>> selectMonitorPiontAndDeviceByOrgId(int orgId) { |
| | | QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>(); |
| | | monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | monitorPointQueryWrapper.eq("organization_id",orgId); |
| | | monitorPointQueryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | monitorPointQueryWrapper.eq("organization_id", orgId); |
| | | List<MonitorPoint> monitorPointList = monitorPointMapper.selectList(monitorPointQueryWrapper); |
| | | List<Map<String, Object>> resultList = new ArrayList<>(); |
| | | for (MonitorPoint monitorPoint:monitorPointList) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | for (MonitorPoint monitorPoint : monitorPointList) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap = JSON.parseObject(JSON.toJSONString(monitorPoint), Map.class); |
| | | int mp_id = monitorPoint.getId(); |
| | | QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>(); |
| | | deviceQueryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | deviceQueryWrapper.eq("monitor_point_id",mp_id); |
| | | deviceQueryWrapper.eq("monitor_point_id", mp_id); |
| | | List<Device> devices = new ArrayList<>(); |
| | | devices = deviceMapper.selectList(deviceQueryWrapper); |
| | | resultMap.put("devices",devices); |
| | | resultMap.put("devices", devices); |
| | | resultList.add(resultMap); |
| | | } |
| | | return resultList; |
| | |
| | | for (int i = levels.size() - 1; i >= 0; i--) { |
| | | Double level = Double.parseDouble(levels.get(i).toString()); |
| | | if (data >= level) { |
| | | state = i + 1; |
| | | state = i + 2; |
| | | break; |
| | | } |
| | | } |