| 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; | 
|     } | 
| } |