南昌市物联网技防平台-后台
zengh
2021-06-01 cd2cfd37366002f790a2ed1435962d4eff7d5cec
blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java
@@ -16,25 +16,24 @@
 */
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.service.IAlarmService;
import org.springblade.jfpt.alarm.vo.AlarmVO;
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.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.*;
@@ -51,6 +50,9 @@
   //时间差
   private long TIME_DIFFERENCE = 150*1000;
   @Resource
   private OneNetStudioApi oneNetStudioApi;
   @Autowired
   private IAlarmService iAlarmService;
@@ -158,30 +160,8 @@
   public Integer selectEquipmentCount(ConditionVo conditionVo) {
      //更新设备状态
      updateEquipmentDtype();
      //先查询所有的设备
      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;
//               }
//            }
//         }
//      }
      //查询在线设备数量
      Integer equipmentCount = baseMapper.selectOnlineEqNum();
      //返回数据
      return equipmentCount;
   }
@@ -271,7 +251,7 @@
   public void updateEquipmentDtype() {
      //查询所有的设备,不包含故障和警情状态
      List<Equipment> equipment = baseMapper.selAllEq();
      long time = new Date().getTime();
      long time = System.currentTimeMillis();
      long hearbeat = 0;
      List<Long> equipmentListz = new ArrayList<>();
      List<Long> equipmentListl = new ArrayList<>();
@@ -284,14 +264,16 @@
            parseException.printStackTrace();
         }
         //对比心跳时间,在线
         if (time-hearbeat<TIME_DIFFERENCE){
            if (null==e.getDtype() || e.getDtype()!="1"){
         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()!="0"){
            if (null==e.getDtype() || !e.getDtype().equals("0")){
               //需要修改为下线
               equipmentListl.add(e.getId());
            }
         }
@@ -299,9 +281,39 @@
      //批量更新数据
      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;
   }
}