| | |
| | | */ |
| | | package org.springblade.jfpt.equipment.service.impl; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.core.tool.node.ForestNodeMerger; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.jfpt.alarm.vo.AlarmVO; |
| | | import org.springblade.jfpt.alarm.service.IAlarmService; |
| | | import org.springblade.jfpt.equipment.entity.Equipment; |
| | | import org.springblade.jfpt.equipment.entity.EquipmentPlayInfo; |
| | | import org.springblade.jfpt.equipment.feign.OneNetStudioApi; |
| | | import org.springblade.jfpt.equipment.mapper.EquipmentMapper; |
| | | import org.springblade.jfpt.equipment.service.IEquipmentService; |
| | | import org.springblade.jfpt.equipment.vo.EquipmentVO; |
| | | import org.springblade.jfpt.equipment.vo.EquipmentVOS; |
| | | import org.springblade.jfpt.parcel.vo.ConditionVo; |
| | | import org.springblade.system.cache.SysCache; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 服务实现类 |
| | |
| | | private static final String PARENT_ID = "parentId"; |
| | | |
| | | //时间差 |
| | | private long TIME_DIFFERENCE = 24*3600*1000; |
| | | private long TIME_DIFFERENCE = 150*1000; |
| | | |
| | | @Resource |
| | | private OneNetStudioApi oneNetStudioApi; |
| | | |
| | | @Autowired |
| | | private IAlarmService iAlarmService; |
| | | |
| | | @Override |
| | | public IPage<EquipmentVO> selectEquipmentPage(IPage<EquipmentVO> page, EquipmentVO equipment,List childList) { |
| | |
| | | @Override |
| | | public IPage<EquipmentVO> selectDeptPages(IPage<EquipmentVO> page, EquipmentVO equipment,String pid,String dxdype) { |
| | | |
| | | List deptIdList; |
| | | if (pid != null && !pid.equals("")){ |
| | | deptIdList = SysCache.getDeptChildIds(Long.valueOf(pid)); |
| | | }else{ |
| | | deptIdList = SysCache.getDeptChildIds(null); |
| | | } |
| | | return page.setRecords(baseMapper.selectDeptPages(page,equipment,deptIdList,dxdype)); |
| | | // List deptIdList; |
| | | // if (pid != null && !pid.equals("")){ |
| | | // deptIdList = SysCache.getDeptChildIds(Long.valueOf(pid)); |
| | | // }else{ |
| | | // deptIdList = SysCache.getDeptChildIds(null); |
| | | // } |
| | | return page.setRecords(baseMapper.selectDeptPages(page,equipment,pid,dxdype)); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<EquipmentVO> listAll() { |
| | | return baseMapper.listAll(); |
| | | public List<EquipmentVO> listAll(EquipmentVO equipment) { |
| | | return baseMapper.listAll(equipment); |
| | | } |
| | | |
| | | @Override |
| | | public void updateOne(Equipment equipment) { |
| | | baseMapper.updateOne(equipment); |
| | | } |
| | | |
| | | @Override |
| | | public void saveImg(EquipmentVO equipment) { |
| | | baseMapper.saveImg(equipment); |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | @Override |
| | | public Integer selectEquipmentCount(ConditionVo conditionVo) { |
| | | //先查询所有的设备 |
| | | List<EquipmentVO> equipmentVOS = baseMapper.listAll(); |
| | | long time = new Date().getTime(); |
| | | int equipmentCount = 0; |
| | | long hearbeat = 0; |
| | | //遍历集合数据,对比心跳时间,得出在线的设备数量 |
| | | int status =0; |
| | | if (status==0 && equipmentVOS.size()>0){ |
| | | for (EquipmentVO e:equipmentVOS) { |
| | | try { |
| | | if(null!=e.getHeartbeat()) { |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | //更新设备状态 |
| | | updateEquipmentDtype(); |
| | | //查询在线设备数量 |
| | | Integer equipmentCount = baseMapper.selectOnlineEqNum(); |
| | | //返回数据 |
| | | return equipmentCount; |
| | | } |
| | |
| | | baseMapper.updateexpireTime(expireTime,deviceNumber); |
| | | } |
| | | |
| | | /** |
| | | * 修改设备状态 2021-5-6 arsn修改 |
| | | * @param state 设备状态 |
| | | * @param reason 原因 |
| | | * @param deviceNumber 设备编号 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void updateExstate(String state, String reason, String deviceNumber) { |
| | | baseMapper.updateExstate(state, reason, deviceNumber); |
| | | if(state.equals("系统故障")){ |
| | | String dType = "3"; |
| | | baseMapper.updateExstate(dType, reason, deviceNumber); |
| | | } |
| | | if(state.equals("一键报警")){ |
| | | String dType = "2"; |
| | | baseMapper.updateExstate(dType, reason, deviceNumber); |
| | | } |
| | | if(state.equals("处理完成")){ |
| | | //查询当前设备是否还存在其他报警 |
| | | int eqCount = iAlarmService.selectEqCount(deviceNumber); |
| | | //只有一条记录时才去修改设备的状态 |
| | | if (eqCount==1 || eqCount==0) { |
| | | String dType = "1"; |
| | | baseMapper.updateExstate(dType, reason, deviceNumber); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | public Integer selectEqCg() { |
| | | return baseMapper.selectEqCg(); |
| | | } |
| | | |
| | | /** |
| | | * 获取各个设备状态统计数量 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String, Object> selEqTypeSum() { |
| | | //设备在线数量 |
| | | Integer integerz = baseMapper.selectEqCz(); |
| | | //设备掉线数量 |
| | | Integer integerd = baseMapper.selectEqCd(); |
| | | //设备预警数量 |
| | | Integer alarmSum = baseMapper.selectEqCys(); |
| | | //设备故障数量 |
| | | Integer integerg = baseMapper.selectEqCg(); |
| | | //封装数据 |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("zx", integerz); |
| | | map.put("dx", integerd); |
| | | map.put("yj", alarmSum); |
| | | map.put("gz", integerg); |
| | | //返回数据 |
| | | return map; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 更新设备状态 |
| | | */ |
| | | @Override |
| | | public void updateEquipmentDtype() { |
| | | //查询所有的设备,不包含故障和警情状态 |
| | | List<Equipment> equipment = baseMapper.selAllEq(); |
| | | long time = System.currentTimeMillis(); |
| | | long hearbeat = 0; |
| | | List<Long> equipmentListz = new ArrayList<>(); |
| | | List<Long> equipmentListl = new ArrayList<>(); |
| | | for (Equipment e:equipment) { |
| | | try { |
| | | if(null!=e.getHeartbeat()) { |
| | | hearbeat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(e.getHeartbeat()).getTime(); |
| | | } |
| | | } catch (ParseException parseException) { |
| | | parseException.printStackTrace(); |
| | | } |
| | | //对比心跳时间,在线 |
| | | if (time-hearbeat< TIME_DIFFERENCE){ |
| | | if (null==e.getDtype() || !e.getDtype().equals("1")){ |
| | | //需要修改为上线 |
| | | equipmentListz.add(e.getId()); |
| | | } |
| | | } |
| | | //不在线 |
| | | if (time-hearbeat>=TIME_DIFFERENCE){ |
| | | if (null==e.getDtype() || !e.getDtype().equals("0")){ |
| | | //需要修改为下线 |
| | | equipmentListl.add(e.getId()); |
| | | } |
| | | } |
| | | } |
| | | //批量更新数据 |
| | | if (equipmentListz.size()>0){ |
| | | baseMapper.updateEqListz(equipmentListz); |
| | | // 在 onenet 平台上线 |
| | | oneNetStudioApi.equipmentUp(equipmentListz); |
| | | } |
| | | if (equipmentListl.size()>0){ |
| | | baseMapper.updateEqListl(equipmentListl); |
| | | //去 onenet 平台下线 |
| | | oneNetStudioApi.equipmentDown(equipmentListl); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取设备视频播放的信息 |
| | | * @param equipmentPlayInfo 视频播放地址对象,只需包含设备编号,以及视频播放格式即可 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public EquipmentPlayInfo selectEquimentPlayInfo(EquipmentPlayInfo equipmentPlayInfo) { |
| | | return baseMapper.selectEquimentPlayInfo(equipmentPlayInfo); |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改设备视频播放的信息 |
| | | * @param equipmentPlayInfo 视频播放地址对象 |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateEquipmentPlayInfo(EquipmentPlayInfo equipmentPlayInfo) { |
| | | equipmentPlayInfo.setCreateTime(new Date()); |
| | | //新增或修改 |
| | | int result = null==equipmentPlayInfo.getId()? baseMapper.saveEquipmentPlayInfo(equipmentPlayInfo) |
| | | :baseMapper.updateEquipmentPlayInfo(equipmentPlayInfo); |
| | | //返回 |
| | | return result>0? true:false; |
| | | } |
| | | } |