jinpengyong
2023-10-25 1de4906d90e268579128b9fae911ea48c6f22469
chore:新五分钟数据接口
1 files added
3 files modified
123 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/HistoryFiveMinutelyController.java 15 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/vo/historyFiveMinutely/QueryFiveDataByMacVO.java 47 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryFiveMinutelyService.java 4 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java 57 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/HistoryFiveMinutelyController.java
@@ -1,20 +1,25 @@
package com.moral.api.controller;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.moral.api.pojo.dto.historyFiveMinutely.DeviceAndFiveMinuteDataDTO;
import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm;
import com.moral.api.pojo.vo.historyFiveMinutely.DeviceAndFiveMinuteDataVO;
import com.moral.api.pojo.vo.historyFiveMinutely.QueryFiveDataByMacVO;
import com.moral.api.service.HistoryFiveMinutelyService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
@@ -81,6 +86,16 @@
        }
        return  ResultMessage.ok(popDataByMac);
    }
    @GetMapping("queryFiveDataByMac")
    @ApiOperation("新五分钟数据弹框")
    public ResultMessage queryFiveDataByMac(@RequestParam @ApiParam(value = "mac",name = "mac号") String mac,
                                            @RequestParam @ApiParam(value = "chooseTime",name = "选取历史数据") String chooseTime,
                                            @RequestParam @ApiParam(value = "time",name = "时间") String time){
        QueryFiveDataByMacVO queryFiveDataByMacVO = historyFiveMinutelyService.queryFiveDataByMac(mac, chooseTime, time);
        return ResultMessage.ok(ObjectUtils.isEmpty(queryFiveDataByMacVO)?"0":queryFiveDataByMacVO);
    }
}
screen-api/src/main/java/com/moral/api/pojo/vo/historyFiveMinutely/QueryFiveDataByMacVO.java
New file
@@ -0,0 +1,47 @@
package com.moral.api.pojo.vo.historyFiveMinutely;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="QueryFiveDataByMacVO - 五分钟数据", description="QueryFiveDataByMacVO - 五分钟数据")
public class QueryFiveDataByMacVO implements Serializable{
    @ApiModelProperty(value = "设备名称")
    private String name;
    @ApiModelProperty(value = "时间")
    private String  dataTime;
    @ApiModelProperty(value = "pm25")
    private String a34004;
    @ApiModelProperty(value = "pm10")
    private String a34002;
    @ApiModelProperty(value = "二氧化硫")
    private String a21026;
    @ApiModelProperty(value = "二氧化氮")
    private String a21004;
    @ApiModelProperty(value = "一氧化碳")
    private String a21005;
    @ApiModelProperty(value = "臭氧")
    private String a05024;
    @ApiModelProperty(value = "风向")
    private String a01008;
    @ApiModelProperty(value = "风速")
    private String a01007;
}
screen-api/src/main/java/com/moral/api/service/HistoryFiveMinutelyService.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.moral.api.pojo.dto.historyFiveMinutely.DeviceAndFiveMinuteDataDTO;
import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm;
import com.moral.api.pojo.vo.historyFiveMinutely.QueryFiveDataByMacVO;
import java.util.Date;
import java.util.List;
@@ -49,4 +50,7 @@
            */
    Map<String,Object> getPopDataByMac(Map<String, Object> params);
   QueryFiveDataByMacVO queryFiveDataByMac(String name,String chooseTime,String time);
}
screen-api/src/main/java/com/moral/api/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -17,6 +17,7 @@
import com.moral.api.pojo.ext.wind.WindListExt;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.pojo.form.historyFiveMinutely.QueryDeviceAndFiveMinuteDataForm;
import com.moral.api.pojo.vo.historyFiveMinutely.QueryFiveDataByMacVO;
import com.moral.api.pojo.vo.user.QxUser;
import com.moral.api.service.DeviceService;
import com.moral.api.service.HistoryFiveMinutelyService;
@@ -250,6 +251,62 @@
        return orderSixParam(result);
    }
    @Override
    public QueryFiveDataByMacVO queryFiveDataByMac(String mac, String chooseTime, String time) {
        Map<String, Object> datas = null;
        if (chooseTime.equals("true")) {
            String timeUnits = DateUtils.stringToDateString(time, "yyyy-MM-dd HH:mm", DateUtils.yyyyMM_EN);
            String dbDataStr = historyHourlyMapper.queryLastHourlyMac(mac, time, timeUnits);
            if (dbDataStr == null) {
                return null;
            }
            datas = JSON.parseObject(dbDataStr, HashMap.class);
            datas.put("dataTime", time);
        } else {
            datas = queryLastDataByMac(mac);
            if (ObjectUtils.isEmpty(datas)){
                return null;
            }
        }
        //构建返回对象
        Map<String, Object> result = new HashMap<>();
        //创建返回因子code集合
        List<String> sensorCodes = Arrays.asList("a34004", "a34002", "a21005", "a21004", "a21026", "a05024", "a99054", "a01008", "a01007");
        //获取设备信息
        Device device = deviceService.getDeviceUnitAlramInforByMac(mac);
        //转换数据单位和名称
        for (Sensor sensor : device.getVersion().getSensors()) {
            if (!sensorCodes.contains(sensor.getCode()))
                continue;
            Object dataO = datas.get(sensor.getCode());
            if (dataO != null) {
                String data = String.valueOf(dataO);
                result.put(sensor.getCode(), data);
            } else {
                if (sensor.getCode().equals("a01008") ||sensor.getCode().equals("a01007")){
                    result.put(sensor.getCode(), "-");
                }else {
                    result.put(sensor.getCode(), "0");
                }
            }
        }
        QueryFiveDataByMacVO queryFiveDataByMacVO = new QueryFiveDataByMacVO();
        queryFiveDataByMacVO.setName(device.getName());
        queryFiveDataByMacVO.setDataTime(datas.get("dataTime").toString());
        queryFiveDataByMacVO.setA34004(result.get("a34004").toString());
        queryFiveDataByMacVO.setA34002(result.get("a34002").toString());
        queryFiveDataByMacVO.setA21026(result.get("a21026").toString());
        queryFiveDataByMacVO.setA21004(result.get("a21004").toString());
        queryFiveDataByMacVO.setA21005(result.get("a21005").toString());
        queryFiveDataByMacVO.setA05024(result.get("a05024").toString());
        queryFiveDataByMacVO.setA01008(result.get("a01008").toString());
        queryFiveDataByMacVO.setA01007(result.get("a01007").toString());
        return queryFiveDataByMacVO;
    }
    //对六参以及时间进行排序
    private Map<String, Object> orderSixParam(Map<String, Object> data) {
        LinkedHashMap result = new LinkedHashMap();