jinpengyong
2024-01-30 cdec9062c85f52d43e8d74e82cbcf9f8606ebb01
chore:设备在线率接口提交
5 files added
9 files modified
713 ■■■■■ changed files
screen-api/src/main/java/com/moral/api/controller/DeviceOnlineRateController.java 55 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/dto/OnlineRatePageCond.java 41 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/entity/HistoryMinutely.java 37 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java 3 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/pojo/dust/OnlineRateLogsForm.java 24 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/DeviceService.java 19 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java 1 ●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java 13 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java 379 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java 39 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/vo/OnlineRateVo.java 66 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/DeviceMapper.xml 9 ●●●●● patch | view | raw | blame | history
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml 18 ●●●●● patch | view | raw | blame | history
screen-api/src/main/java/com/moral/api/controller/DeviceOnlineRateController.java
New file
@@ -0,0 +1,55 @@
package com.moral.api.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.List;
import java.util.Map;
import javax.validation.Valid;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.dto.OnlineRatePageCond;
import com.moral.api.service.DeviceService;
import com.moral.api.vo.OnlineRateVo;
import com.moral.constant.ResultMessage;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName DeviceOnlineRateController
 * @date 2024.01.26 10:02
 */
@RestController
@RequestMapping("/onlineRate")
@Api(tags = {"设备在线率"})
public class DeviceOnlineRateController {
    @Autowired
    private DeviceService deviceService;
    @PostMapping("/page")
    @ApiOperation("分页")
    public ResultMessage page(@Valid @RequestBody OnlineRatePageCond onlineRatePageCond) {
        List<OnlineRateVo> rsList = deviceService.getPage(onlineRatePageCond);
//        PageResult<OnlineRateVo> result = new PageResult<>(page);
//        result.setList(page.getRecords());
        return ResultMessage.ok(rsList);
    }
    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResultMessage get(@RequestParam @ApiParam(value = "mac",name = "mac")String mac,
                             @RequestParam @ApiParam(value = "startTime",name = "开始时间") String startTime,
                             @RequestParam @ApiParam(value = "endTime",name = "结束时间") String endTime,
                             @RequestParam @ApiParam(value = "type",name = "时间类型") String type){
        Map<String, Object> detail = deviceService.detail(mac, startTime, endTime, type);
        return ResultMessage.ok(detail);
    }
}
screen-api/src/main/java/com/moral/api/dto/OnlineRatePageCond.java
New file
@@ -0,0 +1,41 @@
package com.moral.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import com.moral.api.pojo.query.PageCond;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName OnlineRatePageCond
 * @date 2024.01.26 11:04
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="OnlineRate - 分页查询对象", description="OnlineRate - 分页查询对象")
public class OnlineRatePageCond implements Serializable {
    @ApiModelProperty(value = "组织id")
    private  Integer organizationId;
//    @ApiModelProperty(value = "分页参数")
//    private PageCond page;
    @ApiModelProperty(value = "开始时间")
    private  String startTime;
    @ApiModelProperty(value = "结束时间")
    private  String endTime;
}
screen-api/src/main/java/com/moral/api/entity/HistoryMinutely.java
New file
@@ -0,0 +1,37 @@
package com.moral.api.entity;
import lombok.Data;
import java.util.Date;
import com.baomidou.mybatisplus.extension.activerecord.Model;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName HistoryMinutely
 * @date 2024.01.30 13:21
 */
@Data
public class HistoryMinutely extends Model<HistoryMinutely> {
    private static final long serialVersionUID = 1L;
    /**
     * 设备mac
     */
    private String mac;
    /**
     * 时间
     */
    private Date time;
    /**
     * 数据
     */
    private String value;
}
screen-api/src/main/java/com/moral/api/mapper/DeviceMapper.java
@@ -4,10 +4,13 @@
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moral.api.pojo.dto.dataDisplay.HeatMapDTO;
import com.moral.api.pojo.vo.device.AppDeviceVo;
import com.moral.api.vo.OnlineRateVo;
import io.lettuce.core.dynamic.annotation.Param;
/**
@@ -45,4 +48,10 @@
    List<HeatMapDTO> getHeatMapV1(HashMap<String,Object> params);
    //设备在线率分页
    Page<OnlineRateVo> getPage(Page page, @Param("organizationId")Integer organizationId);
    //设备在线率不分页
    List<OnlineRateVo> getList(@Param("organizationId")Integer organizationId);
}
screen-api/src/main/java/com/moral/api/mapper/HistoryHourlyMapper.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moral.api.entity.HistoryHourly;
import com.moral.api.entity.HistoryMinutely;
import com.moral.api.pojo.dto.Wind.WindData;
import org.apache.ibatis.annotations.Param;
@@ -46,4 +47,6 @@
    List<HistoryHourly> listResult(Map<String, Object> params);
    List<HistoryHourly> listLikeResult(Map<String, Object> params);
    List<HistoryMinutely> HistoryMinutelyQuery(Map<String, Object> params);
}
screen-api/src/main/java/com/moral/api/pojo/dust/OnlineRateLogsForm.java
New file
@@ -0,0 +1,24 @@
package com.moral.api.pojo.dust;
import lombok.Data;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName OnlineRateLogsForm
 * @date 2024.01.30 09:37
 */
@Data
public class OnlineRateLogsForm {
    //时间类型
    private  String  date;
    //上线日期
    private  String  startTime;
    //离线日期
    private  String endTime;
    //离线时长
    private  String  mun;
}
screen-api/src/main/java/com/moral/api/service/DeviceService.java
@@ -1,8 +1,11 @@
package com.moral.api.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.dto.OnlineRatePageCond;
import com.moral.api.entity.Device;
import com.baomidou.mybatisplus.extension.service.IService;
import com.moral.api.pojo.vo.device.AppDeviceVo;
import com.moral.api.vo.OnlineRateVo;
import java.util.List;
import java.util.Map;
@@ -66,4 +69,20 @@
     */
    List<Device> getOrganizationDevice(Integer id);
    /**
     * 设备在线率
     * @param onlineRatePageCond
     * @return
     */
    List<OnlineRateVo> getPage(OnlineRatePageCond onlineRatePageCond);
    /**
     * 设备在线率详情
     * @param mac
     * @param startTime
     * @param endTime
     * @param type
     * @return
     */
    Map<String,Object>  detail(String mac,String startTime,String endTime, String type);
}
screen-api/src/main/java/com/moral/api/service/HistoryDailyService.java
@@ -7,6 +7,7 @@
import com.moral.api.entity.Device;
import com.moral.api.entity.HistoryDaily;
import com.baomidou.mybatisplus.extension.service.IService;
import com.moral.api.entity.HistoryMinutely;
/**
 * <p>
screen-api/src/main/java/com/moral/api/service/HistoryHourlyService.java
@@ -1,6 +1,7 @@
package com.moral.api.service;
import com.moral.api.entity.HistoryHourly;
import com.moral.api.entity.HistoryMinutely;
import com.moral.api.vo.HistoryHourlyVo;
import java.util.Date;
@@ -125,4 +126,16 @@
    boolean historyHourly(HistoryHourlyVo historyHourlyVo);
    /**
     * @Description: 根据一个mac查询时间段内的分钟数据
     * @Param: [mac, startDate, endDate]
     * @return: java.util.Map<java.lang.String,com.moral.api.entity.HistoryDaily>
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    List<HistoryMinutely> getHistoryMinutely(String mac, Date startDate, Date endDate);
}
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -4,32 +4,45 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.config.mybatis.MybatisPlusConfig;
import com.moral.api.dto.OnlineRatePageCond;
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryFiveMinutelyMapper;
import com.moral.api.mapper.HistoryHourlyMapper;
import com.moral.api.mapper.OrganizationUnitAlarmMapper;
import com.moral.api.mapper.UnitConversionMapper;
import com.moral.api.pojo.dust.OnlineRateLogsForm;
import com.moral.api.pojo.vo.device.AppDeviceVo;
import com.moral.api.pojo.vo.user.QxUser;
import com.moral.api.service.DeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.HistoryDailyService;
import com.moral.api.service.HistoryFiveMinutelyService;
import com.moral.api.service.HistoryHourlyService;
import com.moral.api.service.HistoryMonthlyService;
import com.moral.api.service.SensorService;
import com.moral.api.service.UnitConversionService;
import com.moral.api.vo.OnlineRateVo;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.constant.SeparateTableType;
import com.moral.util.DateUtils;
import com.moral.util.MybatisPLUSUtils;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.kafka.streams.state.internals.metrics.Sensors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -61,6 +74,12 @@
    @Autowired
    HistoryHourlyMapper historyHourlyMapper;
    @Autowired
    HistoryHourlyService historyHourlyService;
    @Autowired
    HistoryDailyService historyDailyService;
    @Autowired
    HistoryFiveMinutelyMapper historyFiveMinutelyMapper;
@@ -536,6 +555,366 @@
        return devices;
    }
    /**
     * 在线率
     * @param onlineRatePageCond
     * @return
     */
    @Override
    public List<OnlineRateVo> getPage(OnlineRatePageCond onlineRatePageCond) {
        int nh = 1000 * 60 * 60;
        String startTime = onlineRatePageCond.getStartTime();
        String endTime = onlineRatePageCond.getEndTime();
        Date start = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
        Date end = DateUtils.getDate(endTime, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
        long diff = end.getTime() - start.getTime(); //获取毫秒
        long hour = (diff / nh)+1; //获取间隔几个小时
        List<OnlineRateVo> OnlineRateVoList = deviceMapper.getList(onlineRatePageCond.getOrganizationId());
        if (!ObjectUtils.isEmpty(OnlineRateVoList)){
            for (OnlineRateVo onlineRateVo : OnlineRateVoList) {
                List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(onlineRateVo.getMac(), start, end);
                ArrayList<Date> dates = new ArrayList<>();
                ArrayList<Date> dates1 = new ArrayList<>();
                ArrayList<Date> dates2 = new ArrayList<>();
                ArrayList<Integer> list = new ArrayList<>();
                Date start1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
                if (!ObjectUtils.isEmpty(valueByMacAndTime)){
                    for (HistoryHourly historyHourly : valueByMacAndTime) {
                        dates.add(historyHourly.getTime());
                    }
                    boolean flag= true;
                    int i = 0;
                    while (DateUtils.isTimeBeforE(end,start1)){
                        if (dates.contains(start1)){
                            if (flag){
                                list.add(i);
                            }else {
                                i++;
                                list.add(i);
                                dates2.add(start1);
                                flag= true;
                            }
                        }else {
                            if (flag){
                                i++;
                                list.add(i);
                                dates1.add(start1);
                                flag=false;
                            }else {
                                list.add(i);
                            }
                        }
                        start1 = DateUtils.getDateAddHour(start1,1);
                    }
                    if (!ObjectUtils.isEmpty(dates2)){
                        onlineRateVo.setStartTime(DateUtils.dateToDateString(dates2.get(dates2.size()-1)));
                    }
                    if (!ObjectUtils.isEmpty(dates1)){
                        onlineRateVo.setEndTime(DateUtils.dateToDateString(dates1.get(dates1.size()-1)));
                    }
//               it.setEndTime(DateUtils.dateToDateString(dates1.get(dates1.size()-1)));
                    onlineRateVo.setNum(dates1.size()+"");
                    onlineRateVo.setOnlineTime(valueByMacAndTime.size());
                    double number = (double) valueByMacAndTime.size() / hour * 100;
                    String result = String.format("%.2f", number);
                    onlineRateVo.setOnlineRate(result+"%");
                }
            }
        }
     /*   Page<OnlineRateVo> page = deviceMapper.getPage(onlineRatePageCond.getPage().convertPage(), onlineRatePageCond.getOrganizationId());
        if(CollectionUtils.isNotEmpty(page.getRecords())){
            page.getRecords().forEach(it->{
                Date start1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
                List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(it.getMac(), start, end);
                ArrayList<Date> dates = new ArrayList<>();
                ArrayList<Date> dates1 = new ArrayList<>();
                ArrayList<Date> dates2 = new ArrayList<>();
                ArrayList<Integer> list = new ArrayList<>();
                if (!ObjectUtils.isEmpty(valueByMacAndTime)){
                    for (HistoryHourly historyHourly : valueByMacAndTime) {
                        dates.add(historyHourly.getTime());
                    }
                    boolean flag= true;
                    int i = 0;
                    while (DateUtils.isTimeBeforE(end,start1)){
                    if (dates.contains(start1)){
                        if (flag){
                          list.add(i);
                        }else {
                          i++;
                          list.add(i);
                          dates2.add(start1);
                          flag= true;
                        }
                    }else {
                        if (flag){
                            i++;
                            list.add(i);
                            dates1.add(start1);
                            flag=false;
                        }else {
                          list.add(i);
                        }
                    }
                        start1 = DateUtils.getDateAddHour(start1,1);
                    }
                    if (!ObjectUtils.isEmpty(dates2)){
                        it.setStartTime(DateUtils.dateToDateString(dates2.get(dates2.size()-1)));
                    }
                    if (!ObjectUtils.isEmpty(dates1)){
                        it.setEndTime(DateUtils.dateToDateString(dates1.get(dates1.size()-1)));
                    }
//                    it.setEndTime(DateUtils.dateToDateString(dates1.get(dates1.size()-1)));
                    it.setNum(dates1.size()+"");
                    it.setOnlineTime(valueByMacAndTime.size());
                    double number = (double) valueByMacAndTime.size() / hour * 100;
                    String result = String.format("%.2f", number);
                    it.setOnlineRate(result+"%");
                }
            });
        }*/
        return OnlineRateVoList;
    }
    /**
     * 设备在线率详情
     *
     * @param mac
     * @param startTime
     * @param endTime
     * @param type
     * @return
     */
    @Override
    public Map<String,Object> detail(String mac, String startTime, String endTime, String type) {
        int nh = 1000 * 60 * 60;
        long nd = 1000 * 24 * 60 * 60;
        long nm = 1000 * 60;
        HashMap<String, Object> rsMap = new HashMap<>();
        Map<String, Object> map = new TreeMap<>(
                new Comparator<String>() {
                    @Override
                    public int compare(String o1, String o2) {
                        return o2.compareTo(o1);
                    }
                }
        );
//        HashMap<String, Object> map = new HashMap<>();
        //离线数据
        ArrayList<Date> EndDates = new ArrayList<>();
        //在线数据
        ArrayList<Date> StartDates = new ArrayList<>();
        ArrayList<Date> dates = new ArrayList<>();
        if (type.equals("hour")){
            Date start = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN);
            Date end = DateUtils.getDate(endTime, DateUtils.yyyy_MM_dd_HH_EN);
            List<HistoryHourly> valueByMacAndTime = historyHourlyService.getValueByMacAndTime(mac, start, end);
            if (!ObjectUtils.isEmpty(valueByMacAndTime)){
                for (HistoryHourly historyHourly : valueByMacAndTime) {
                    map.put(DateUtils.dateToDateString(historyHourly.getTime()),1);
                    dates.add(historyHourly.getTime());
                }
                boolean flag= true;
                while (DateUtils.isTimeBeforE(end,start)){
                    if (dates.contains(start)){
                        if (!flag){
                            StartDates.add(start);
                            flag= true;
                        }
                    }else {
                        if (flag){
                            EndDates.add(start);
                            flag=false;
                        }
                        map.put(DateUtils.dateToDateString(start),0);
                    }
                    start = DateUtils.getDateAddHour(start,1);
                }
            }
            //表格
            ArrayList<OnlineRateLogsForm> OrfList = new ArrayList<>();
            if (!ObjectUtils.isEmpty(EndDates)){
                for (int i = 0; i < EndDates.size(); i++) {
                    OnlineRateLogsForm onlineRateLogsForm = new OnlineRateLogsForm();
                    onlineRateLogsForm.setEndTime(DateUtils.dateToDateString(EndDates.get(i)));
                    onlineRateLogsForm.setStartTime(ObjectUtils.isEmpty(StartDates)?"-":DateUtils.dateToDateString(StartDates.get(i)));
//                    if (!ObjectUtils.isEmpty(StartDates)){
//                        long l = EndDates.get(i).getTime() - StartDates.get(i).getTime();
//                        onlineRateLogsForm.setMun(Long.toString(l/nh));
//                        StartDates.remove(i);
//                    }else {
//                        onlineRateLogsForm.setMun("-");
//                    }
                    onlineRateLogsForm.setDate("小时");
                    OrfList.add(onlineRateLogsForm);
                }
            }
            //折线图
            ArrayList<String> list1 = new ArrayList<>();
            ArrayList<Integer> list2 = new ArrayList<>();
            Set<String> strings = map.keySet();
            for (String string : strings) {
                list1.add(string);
                list2.add(Integer.parseInt(map.get(string).toString()));
            }
            rsMap.put("lineChart1",list1);
            rsMap.put("lineChart2",list2);
            rsMap.put("tabulation",OrfList);
            //离线多少个小时
            int endNumber = map.size() - dates.size();
            double number = (double) dates.size() / map.size() * 100;
            String result = String.format("%.2f", number);
            rsMap.put("pieChart1",endNumber);
            rsMap.put("pieChart2",dates.size());
            rsMap.put("code","共"+map.size()+"小时,"+"在线"+dates.size()+"小时,"+"在线率"+result);
        } else if (type.equals("day")){
            Date start = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_EN);
            Date end = DateUtils.getDate(endTime, DateUtils.yyyy_MM_dd_EN);
            List<HistoryDaily> historyDailys = historyDailyService.getHistoryDailyByMacAndTimeSlot(mac, start, end);
            if (!ObjectUtils.isEmpty(historyDailys)){
                for (HistoryDaily historyDaily : historyDailys) {
                    map.put(DateUtils.dateToDateString(historyDaily.getTime()),1);
                    dates.add(historyDaily.getTime());
                }
                boolean flag= true;
                while (DateUtils.isTimeBeforE(end,start)){
                    if (dates.contains(start)){
                        if (!flag){
                            StartDates.add(start);
                            flag= true;
                        }
                    }else {
                        if (flag){
                            EndDates.add(start);
                            flag=false;
                        }
                        map.put(DateUtils.dateToDateString(start),0);
                    }
//                    start = DateUtils.getDateAddHour(start,24);
                    start = DateUtils.getDateOfDay(start,1);
                }
            }
            //表格
            ArrayList<OnlineRateLogsForm> OrfList = new ArrayList<>();
            if (!ObjectUtils.isEmpty(EndDates)){
                for (int i = 0; i < EndDates.size(); i++) {
                    OnlineRateLogsForm onlineRateLogsForm = new OnlineRateLogsForm();
                    onlineRateLogsForm.setEndTime(DateUtils.dateToDateString(EndDates.get(i)));
//                    onlineRateLogsForm.setStartTime(ObjectUtils.isEmpty(StartDates)?"-":DateUtils.dateToDateString(StartDates.get(i)));
                    if (ObjectUtils.isEmpty(StartDates)){
                        onlineRateLogsForm.setStartTime("-");
                        onlineRateLogsForm.setMun("-");
                    }else {
                        if (EndDates.size()>StartDates.size()&& i==EndDates.size()-1){
                            onlineRateLogsForm.setStartTime("-");
                            onlineRateLogsForm.setMun("-");
                        }
                        onlineRateLogsForm.setStartTime(DateUtils.dateToDateString(StartDates.get(i)));
                        long l = EndDates.get(i).getTime() - StartDates.get(i).getTime();
                        onlineRateLogsForm.setMun(Long.toString(l/nd));
                    }
//                    if (!ObjectUtils.isEmpty(StartDates)){
//                        long l = EndDates.get(i).getTime() - StartDates.get(i).getTime();
//                        onlineRateLogsForm.setMun(Long.toString(l/nd));
//                    }else {
//                        onlineRateLogsForm.setMun("-");
//                    }
                    onlineRateLogsForm.setDate("天");
                    OrfList.add(onlineRateLogsForm);
                }
            }
            //折线图
            ArrayList<String> list1 = new ArrayList<>();
            ArrayList<Integer> list2 = new ArrayList<>();
            Set<String> strings = map.keySet();
            for (String string : strings) {
                list1.add(string);
                list2.add(Integer.parseInt(map.get(string).toString()));
            }
            rsMap.put("lineChart1",list1);
            rsMap.put("lineChart2",list2);
            rsMap.put("tabulation",OrfList);
            //离线多少天
            int endNumber = map.size() - dates.size();
            double number = (double) dates.size() / map.size() * 100;
            String result = String.format("%.2f", number);
            rsMap.put("pieChart1",endNumber);
            rsMap.put("pieChart2",dates.size());
            rsMap.put("code","共"+map.size()+"天,"+"在线"+dates.size()+"天,"+"在线率"+result);
        }else {
            Date start = DateUtils.getDate(startTime,"yyyy-MM-dd HH:mm:00");
            Date end = DateUtils.getDate(endTime, "yyyy-MM-dd HH:mm:00");
            List<HistoryMinutely> historyMinutelys = historyHourlyService.getHistoryMinutely(mac, start, end);
            if (!ObjectUtils.isEmpty(historyMinutelys)){
                for (HistoryMinutely historyMinutely : historyMinutelys) {
                    map.put(DateUtils.dateToDateString(historyMinutely.getTime()),1);
                    dates.add(historyMinutely.getTime());
                }
                boolean flag= true;
                while (DateUtils.isTimeBeforE(end,start)){
                    if (dates.contains(start)){
                        if (!flag){
                            StartDates.add(start);
                            flag= true;
                        }
                    }else {
                        if (flag){
                            EndDates.add(start);
                            flag=false;
                        }
                        map.put(DateUtils.dateToDateString(start),0);
                    }
//                    start = DateUtils.getDateAddHour(start,24);
                    start = DateUtils.getDateOfMin(start,1);
                }
            }
            //表格
            ArrayList<OnlineRateLogsForm> OrfList = new ArrayList<>();
            if (!ObjectUtils.isEmpty(EndDates)){
                for (int i = 0; i < EndDates.size(); i++) {
                    OnlineRateLogsForm onlineRateLogsForm = new OnlineRateLogsForm();
                    onlineRateLogsForm.setEndTime(DateUtils.dateToDateString(EndDates.get(i)));
                    onlineRateLogsForm.setStartTime(ObjectUtils.isEmpty(StartDates)?"-":DateUtils.dateToDateString(StartDates.get(i)));
//                    if (!ObjectUtils.isEmpty(StartDates)){
//                        long l = EndDates.get(i).getTime() - StartDates.get(i).getTime();
//                        onlineRateLogsForm.setMun(Long.toString(l/nm));
//                    }else {
//                        onlineRateLogsForm.setMun("-");
//                    }
                    onlineRateLogsForm.setDate("分钟");
                    OrfList.add(onlineRateLogsForm);
                }
            }
            //折线图
            ArrayList<String> list1 = new ArrayList<>();
            ArrayList<Integer> list2 = new ArrayList<>();
            Set<String> strings = map.keySet();
            for (String string : strings) {
                list1.add(string);
                list2.add(Integer.parseInt(map.get(string).toString()));
            }
            rsMap.put("lineChart1",list1);
            rsMap.put("lineChart2",list2);
            rsMap.put("tabulation",OrfList);
            //离线多少天
            int endNumber = map.size() - dates.size();
            double number = (double) dates.size() / map.size() * 100;
            String result = String.format("%.2f", number);
            rsMap.put("pieChart1",endNumber);
            rsMap.put("pieChart2",dates.size());
            rsMap.put("code","共"+map.size()+"分钟,"+"在线"+dates.size()+"分钟,"+"在线率"+result);
        }
        return rsMap;
    }
    private Device getDeviceUnitAlramInforByMacFromDb(String mac){
        QueryWrapper<Device> wrapper = new QueryWrapper<>();
        wrapper.eq("mac",mac);
screen-api/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -858,6 +858,24 @@
        }
        return result;
    }
    /**
     * @Description: 多表查询,传入表名集合,以及条件wrapper,返回数据
     * @Param: [wrapper, tableNames]
     * @return: java.util.List<com.moral.api.entity.HistoryHourly>
     * @Author: 陈凯裕
     * @Date: 2021/9/23
     */
    private List<HistoryMinutely> HistoryMinutelyQuery(Map<String, Object> params, List<String> tableNames) {
        List<HistoryMinutely> result = new ArrayList<>();
        for (String tableName : tableNames) {
            params.put("table",tableName);
            List<HistoryMinutely> historyMinutelies = historyHourlyMapper.HistoryMinutelyQuery(params);
            result.addAll(historyMinutelies);
        }
        return result;
    }
    private List<HistoryHourly> multiTableQueryLike(Map<String, Object> params, List<String> tableNames) {
        List<HistoryHourly> result = new ArrayList<>();
        for (String tableName : tableNames) {
@@ -920,4 +938,25 @@
        }
        return true;
    }
    /**
     * @param mac
     * @param startDate
     * @param endDate
     * @Description: 根据一个mac查询时间段内分钟的数据
     * @Param: [mac, startDate, endDate]
     * @return: java.util.Map<java.lang.String, com.moral.api.entity.HistoryDaily>
     * @Author: 陈凯裕
     * @Date: 2021/9/26
     */
    @Override
    public List<HistoryMinutely> getHistoryMinutely(String mac, Date startDate, Date endDate) {
        Map<String, Object> mapParams = new HashMap<>();
        mapParams.put("startDate",startDate);
        mapParams.put("endDate",endDate);
        mapParams.put("mac",mac);
        List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(startDate, endDate, SeparateTableType.MONTH);
        List<HistoryMinutely> datas = HistoryMinutelyQuery(mapParams, tableNames);
        return datas;
    }
}
screen-api/src/main/java/com/moral/api/vo/OnlineRateVo.java
New file
@@ -0,0 +1,66 @@
package com.moral.api.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Objects;
/**
 * Description //todo
 *
 * @author swb
 * @ClassName onlineRateVo
 * @date 2024.01.26 10:54
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="onlineRate - 分页VO对象", description="onlineRate - 分页VO对象")
public class OnlineRateVo implements Serializable {
    @ApiModelProperty(value = "设备名称")
    private  String name;
    @ApiModelProperty(value = "最近掉线时间")
    private String  endTime;
    @ApiModelProperty(value = "最近上线时间")
    private  String startTime;
    @ApiModelProperty(value = "掉线次数")
    private  String  num;
    @ApiModelProperty(value = "在线率")
    private  String onlineRate;
    @ApiModelProperty(value = "在线时间")
    private  Integer  onlineTime;
    @ApiModelProperty(value = "状态")
    private  String  state;
    private  String  mac;
    public String getEndTime(){
        return Objects.isNull(this.endTime)?"-":this.endTime;
    }
    public String getStartTime(){
        return Objects.isNull(this.startTime)?"-":this.startTime;
    }
    public String getNum(){
        return Objects.isNull(this.num)?"-":this.num;
    }
    public String getOnlineRate(){
        return Objects.isNull(this.onlineRate)?"0%":this.onlineRate;
    }
    public Integer getOnlineTime(){
        return Objects.isNull(this.onlineTime)?0:this.onlineTime;
    }
}
screen-api/src/main/resources/mapper/DeviceMapper.xml
@@ -268,4 +268,13 @@
        d.is_delete = 0
        order by d.mac
    </select>
    <select id="getPage" resultType="com.moral.api.vo.OnlineRateVo">
        select d.name,d.state,d.mac from device as d where organization_id=#{organizationId}
    </select>
    <select id="getList" resultType="com.moral.api.vo.OnlineRateVo">
        select d.name,d.state,d.mac from device as d where organization_id=#{organizationId}
    </select>
</mapper>
screen-api/src/main/resources/mapper/HistoryHourlyMapper.xml
@@ -128,4 +128,22 @@
        order by time desc
    </select>
    <select id="HistoryMinutelyQuery" resultType="com.moral.api.entity.HistoryMinutely">
        SELECT mac,time,value,version FROM history_minutely${table}
        WHERE 1 =1
        <if test="macs != null and macs.size!=0">
            and mac in
            <foreach collection="macs" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="mac != null and mac != ''">
            and mac = #{mac}
        </if>
        and time BETWEEN #{startDate} and #{endDate}
        order by time desc
    </select>
</mapper>