南昌市物联网技防平台-后台
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java
@@ -21,6 +21,7 @@
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.service.IAlarmService;
import org.springblade.jfpt.alarm.vo.AlarmVO;
import org.springblade.jfpt.equipment.entity.Equipment;
import org.springblade.jfpt.equipment.mapper.EquipmentMapper;
@@ -29,16 +30,14 @@
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.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
 *  服务实现类
@@ -52,6 +51,9 @@
   //时间差
   private long TIME_DIFFERENCE = 24*3600*1000;
   @Autowired
   private IAlarmService iAlarmService;
   @Override
   public IPage<EquipmentVO> selectEquipmentPage(IPage<EquipmentVO> page, EquipmentVO equipment,List childList) {
@@ -154,28 +156,32 @@
    */
   @Override
   public Integer selectEquipmentCount(ConditionVo conditionVo) {
      //更新设备状态
      updateEquipmentDtype();
      //先查询所有的设备
      List<EquipmentVO> equipmentVOS = baseMapper.listAlls();
      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;
            }
         }
      }
      Integer equipmentCount = baseMapper.selectEqCz();
      System.out.println("equipmentCount = " + equipmentCount);
//      long time = new Date().getTime();
//      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 (null!=e.getDtype()) {
//               if (time - hearbeat < TIME_DIFFERENCE && e.getDtype()!="2" && e.getDtype()!="3") {
//                  equipmentCount += 1;
//               }
//            }
//         }
//      }
      //返回数据
      return equipmentCount;
   }
@@ -203,8 +209,13 @@
         baseMapper.updateExstate(dType, reason, deviceNumber);
      }
      if(state.equals("处理完成")){
         String dType = "1";
         baseMapper.updateExstate(dType, reason, deviceNumber);
         //查询当前设备是否还存在其他报警
         int eqCount = iAlarmService.selectEqCount(deviceNumber);
         //只有一条记录时才去修改设备的状态
         if (eqCount==1) {
            String dType = "1";
            baseMapper.updateExstate(dType, reason, deviceNumber);
         }
      }
   }
@@ -251,4 +262,46 @@
      //返回数据
      return map;
   }
   /**
    * 更新设备状态
    */
   @Override
   public void updateEquipmentDtype() {
      //查询所有的设备,不包含故障和警情状态
      List<Equipment> equipment = baseMapper.selAllEq();
      long time = new Date().getTime();
      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()!="1"){
               equipmentListz.add(e.getId());
            }
         }
         //不在线
         if (time-hearbeat>=TIME_DIFFERENCE){
            if (null==e.getDtype() || e.getDtype()!="0"){
               equipmentListl.add(e.getId());
            }
         }
      }
      //批量更新数据
      if (equipmentListz.size()>0){
         baseMapper.updateEqListz(equipmentListz);
      }
      if (equipmentListl.size()>0){
         baseMapper.updateEqListl(equipmentListl);
      }
   }
}