| | |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.MybatisPLUSUtils; |
| | | import io.lettuce.core.GeoCoordinates; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | * @since 2021-07-15 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class HistoryFiveMinutelyServiceImpl extends ServiceImpl<HistoryFiveMinutelyMapper, HistoryFiveMinutely> implements HistoryFiveMinutelyService { |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | //查询所有设备对应的数据 |
| | | List<DeviceAndFiveMinuteDataDTO> dtos = new ArrayList<>(); |
| | | if (form.getChooseTime().equals("true")){ |
| | | if (form.getChooseTime().equals("true")) { |
| | | String time = form.getTime(); |
| | | String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); |
| | | for (Device device : devices) { |
| | |
| | | // List<WindData> windData = historyFiveMinutelyMapper.getAreaWindData(params); |
| | | // return getWindData(windData); |
| | | String chooseTime = params.get("chooseTime").toString(); |
| | | List<WindData> windData=null; |
| | | if (chooseTime.equals("true")){ |
| | | List<WindData> windData = null; |
| | | if (chooseTime.equals("true")) { |
| | | String time = params.get("time").toString(); |
| | | String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); |
| | | params.put("timeUnits", timeUnits); |
| | | windData = historyHourlyMapper.getArea(params); |
| | | }else { |
| | | } else { |
| | | String timeUnits = DateUtils.dateToDateString(new Date(), DateUtils.yyyyMM_EN); |
| | | params.put("timeUnits", timeUnits); |
| | | //风场数据 |
| | | windData = historyFiveMinutelyMapper.getAreaWindData(params); |
| | | } |
| | | |
| | | log.info("风场数据:{}", windData); |
| | | return getWindData(windData); |
| | | } |
| | | |
| | |
| | | // Map<String, Object> datas = queryLastDataByMac(mac); |
| | | String chooseTime = params.get("chooseTime").toString(); |
| | | String mac = params.get("mac").toString(); |
| | | Map<String, Object> datas=null; |
| | | if (chooseTime.equals("true")){ |
| | | Map<String, Object> datas = null; |
| | | if (chooseTime.equals("true")) { |
| | | String time = params.get("time").toString(); |
| | | String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN); |
| | | String dbDataStr = historyHourlyMapper.queryLastHourlyMac(mac, time, timeUnits); |
| | | if (dbDataStr==null){ |
| | | if (dbDataStr == null) { |
| | | return null; |
| | | } |
| | | // String dbDataStr = historyFiveMinutelyMapper.queryLastFiveMinutely(mac, time, timeUnits); |
| | | datas = JSON.parseObject(dbDataStr, HashMap.class); |
| | | datas.put("dataTime",time); |
| | | }else { |
| | | datas.put("dataTime", time); |
| | | } else { |
| | | datas = queryLastDataByMac(mac); |
| | | } |
| | | //构建返回对象 |
| | | Map<String, Object> result = new HashMap<>(); |
| | | //创建返回因子code集合 |
| | | List<String> sensorCodes = Arrays.asList("a34004", "a34002", "a21005", "a21004", "a21026", "a05024", "a99054","a01008","a01007"); |
| | | List<String> sensorCodes = Arrays.asList("a34004", "a34002", "a21005", "a21004", "a21026", "a05024", "a99054", "a01008", "a01007"); |
| | | //获取设备信息 |
| | | Device device = deviceService.getDeviceUnitAlramInforByMac(mac); |
| | | //转换数据单位和名称 |
| | |
| | | if (dataO != null) { |
| | | String data = String.valueOf(dataO); |
| | | //转换单位 |
| | | if (!sensor.getShowUnitKey().equals(sensor.getUnitKey()) ) |
| | | if (!sensor.getShowUnitKey().equals(sensor.getUnitKey())) |
| | | data = UnitConvertUtils.calculate(data, sensor.getFormula()); |
| | | //拼接单位 |
| | | data = data +" "+ sensor.getShowUnit(); |
| | | data = data + " " + sensor.getShowUnit(); |
| | | result.put(sensor.getCode(), data); |
| | | }else{ |
| | | result.put(sensor.getCode(),"-"); |
| | | } else { |
| | | result.put(sensor.getCode(), "-"); |
| | | } |
| | | } |
| | | //添加设备名称 |
| | | result.put("name",device.getName()); |
| | | result.put("name", device.getName()); |
| | | //添加时间 |
| | | result.put("dataTime",datas.get("dataTime")); |
| | | result.put("dataTime", datas.get("dataTime")); |
| | | //排序 |
| | | return orderSixParam(result); |
| | | } |
| | | |
| | | //对六参以及时间进行排序 |
| | | private Map<String,Object> orderSixParam(Map<String,Object> data){ |
| | | private Map<String, Object> orderSixParam(Map<String, Object> data) { |
| | | LinkedHashMap result = new LinkedHashMap(); |
| | | Object PM2_5 = data.get("a34004"); |
| | | Object PM10 = data.get("a34002"); |
| | |
| | | Object a01007 = data.get("a01007"); |
| | | Object name = data.get("name"); |
| | | Object time = data.get("dataTime"); |
| | | if(name!=null) |
| | | result.put("名称",name); |
| | | if(PM2_5!=null) |
| | | result.put("PM2.5",PM2_5); |
| | | if(PM10!=null) |
| | | result.put("PM10",PM10); |
| | | if(SO2!=null) |
| | | result.put("二氧化硫(SO₂)",SO2); |
| | | if(NO2!=null) |
| | | result.put("二氧化氮(NO₂)",NO2); |
| | | if(CO!=null) |
| | | result.put("一氧化碳(CO)",CO); |
| | | if(O3!=null) |
| | | result.put("臭氧(O₃)",O3); |
| | | if(time!=null) |
| | | result.put("时间",time); |
| | | if (a01008!=null) |
| | | result.put("风向",a01008); |
| | | if (a01007!=null) |
| | | result.put("风速",a01007); |
| | | if (name != null) |
| | | result.put("名称", name); |
| | | if (PM2_5 != null) |
| | | result.put("PM2.5", PM2_5); |
| | | if (PM10 != null) |
| | | result.put("PM10", PM10); |
| | | if (SO2 != null) |
| | | result.put("二氧化硫(SO₂)", SO2); |
| | | if (NO2 != null) |
| | | result.put("二氧化氮(NO₂)", NO2); |
| | | if (CO != null) |
| | | result.put("一氧化碳(CO)", CO); |
| | | if (O3 != null) |
| | | result.put("臭氧(O₃)", O3); |
| | | if (time != null) |
| | | result.put("时间", time); |
| | | if (a01008 != null) |
| | | result.put("风向", a01008); |
| | | if (a01007 != null) |
| | | result.put("风速", a01007); |
| | | return result; |
| | | } |
| | | |