jinpengyong
2024-03-07 36844dfeea0914de1138be9ebdf27c92d745d73a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.moral.api.pojo.vo.monitorPoint;
 
import com.moral.api.entity.Device;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.pojo.vo.device.DeviceVO;
import lombok.Data;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @ClassName MonitorPointsVO
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/7/1 14:33
 * @Version TODO
 **/
@Data
public class MonitorPointsVO {
 
    private List<MonitorPointVO> monitorPoints;
 
    public static MonitorPointsVO convert(List<MonitorPoint> monitorPoints,boolean type){
        MonitorPointsVO monitorPointsVO = new MonitorPointsVO();
        List<MonitorPointVO> monitorPointVOS = new ArrayList<>();
        for (MonitorPoint monitorPoint : monitorPoints) {
            MonitorPointVO monitorPointVO = new MonitorPointVO();
            List<Device> devices = monitorPoint.getDevices();
            List<DeviceVO> deviceVOS = new ArrayList<>();
            for (Device device : devices) {
                DeviceVO deviceVO = deviceConvert(device);
                deviceVOS.add(deviceVO);
            }
            List<Device> resultState = devices.stream().filter(it->!it.getState().equals("0")).collect(Collectors.toList());
            monitorPointVO.setId(monitorPoint.getId());
            StringBuffer stringBuffer = new StringBuffer(monitorPoint.getName());
            if(type){
                stringBuffer.append("(");
                stringBuffer.append("在线:").append(resultState.size()+"台;");
                stringBuffer.append("总:").append(devices.size()+"台");
                stringBuffer.append(")");
            }
            monitorPointVO.setName(stringBuffer.toString());
            monitorPointVO.setLatitude(monitorPoint.getLatitude());
            monitorPointVO.setLongitude(monitorPoint.getLongitude());
            monitorPointVO.setDevices(deviceVOS);
            monitorPointVOS.add(monitorPointVO);
        }
            monitorPointsVO.setMonitorPoints(monitorPointVOS);
        return monitorPointsVO;
    }
 
    private static DeviceVO deviceConvert(Device device){
        DeviceVO vo = new DeviceVO();
        vo.setName(device.getName());
        vo.setMac(device.getMac());
        vo.setState(device.getState());
        vo.setLatitude(device.getLatitude());
        vo.setLongitude(device.getLongitude());
        return vo;
    }
}