| | |
| | | import org.springblade.jfpt.equipment.service.IEquipmentService; |
| | | import org.springblade.jfpt.equipment.vo.EquipmentVO; |
| | | import org.springblade.jfpt.equipment.vo.EquipmentVOS; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Service |
| | | public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService { |
| | | private static final String PARENT_ID = "parentId"; |
| | | |
| | | //时间差 |
| | | private long TIME_DIFFERENCE = 24*3600*1000; |
| | | |
| | | @Override |
| | | public IPage<EquipmentVO> selectEquipmentPage(IPage<EquipmentVO> page, EquipmentVO equipment,List childList) { |
| | |
| | | baseMapper.updateChannel(heartbeat, deviceNumber); |
| | | } |
| | | |
| | | /** |
| | | * 查询在线设备总数 |
| | | * @param status 状态码 0:本日 1:本周 2:本月 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer selectEquipmentCount(Integer status) { |
| | | //先查询所有的设备 |
| | | List<EquipmentVO> equipmentVOS = baseMapper.listAll(); |
| | | long time = new Date().getTime(); |
| | | int equipmentCount = 0; |
| | | long hearbeat = 0; |
| | | //遍历集合数据,对比心跳时间,得出在线的设备数量 |
| | | if (status==0){ |
| | | for (EquipmentVO e:equipmentVOS) { |
| | | try { |
| | | hearbeat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(e.getHeartbeat()).getTime(); |
| | | } catch (ParseException parseException) { |
| | | parseException.printStackTrace(); |
| | | } |
| | | //对比心跳时间 |
| | | if (time-hearbeat<TIME_DIFFERENCE){ |
| | | equipmentCount+=1; |
| | | } |
| | | } |
| | | } |
| | | //返回数据 |
| | | return equipmentCount; |
| | | } |
| | | } |