From 47a458ca867f700ad8dfe8bccdbb6bf59ca2d301 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Tue, 11 May 2021 15:54:02 +0800
Subject: [PATCH] APP接口调整

---
 blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java |  120 ++++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 96 insertions(+), 24 deletions(-)

diff --git a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java
index 24d78b1..ef97b44 100644
--- a/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java
+++ b/blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/equipment/service/impl/EquipmentServiceImpl.java
@@ -35,9 +35,7 @@
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  *  服务实现类
@@ -153,28 +151,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;
 	}
@@ -195,6 +197,10 @@
 	public void updateExstate(String state, String reason, String 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("处理完成")){
@@ -222,4 +228,70 @@
 	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 = 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);
+		}
+	}
 }

--
Gitblit v1.9.3