suntianwu 3 vuotta sitten
vanhempi
commit
e39fe582cc

+ 1 - 4
src/main/java/com/care/common/cache/RedisKeyConstant.java

@@ -34,10 +34,7 @@ public class RedisKeyConstant {
     //工单处理,同一工单仅1个人处理
     //工单处理,同一工单仅1个人处理
     public static final String DO_ORDER = "SEAT_DO_ORDER:LOCK";
     public static final String DO_ORDER = "SEAT_DO_ORDER:LOCK";
 
 
-//    //生成工单,同一设备同时只能生成一个工单
-//    public static final String CREATE_ORDER = "CREATE_ORDER:LOCK";
-
-    //PeopleEvent信息处理
+    //生成工单,同一设备同时只能生成一个工单
     public static final String CREATE_ORDER = "CREATE_ORDER:LOCK";
     public static final String CREATE_ORDER = "CREATE_ORDER:LOCK";
 
 
     //设备监测信息
     //设备监测信息

+ 58 - 74
src/main/java/com/care/mqtt/service/MqttMsgService.java

@@ -161,86 +161,70 @@ public class MqttMsgService {
     }
     }
 
 
     private void handlePeopleEvent(Map msg,CareDevice careDevice,Date date){
     private void handlePeopleEvent(Map msg,CareDevice careDevice,Date date){
-//        String key = RedisKeyConstant.CREATE_ORDER + ":" + careDevice.getId();
-//        String requestId = UUID.randomUUID().toString();
-//        boolean result = redisUtil.tryLock(key,requestId,10);
-//        try {
-//            if (result) {
-                Integer amount = (Integer) msg.get("amount");
-                List<Map> targets = (List) msg.get("targets");
-                String moveState = DeviceMoveStateEnum.STATIC.getValue();
-                if(amount == 0){ //无人
-                    moveState = DeviceMoveStateEnum.NONE.getValue();
-                } else { //有人,静止或活动
-                    for(Map target : targets) {
-                        Integer tid = (Integer) target.get("tid");
-                        Integer cls = (Integer) target.get("cls");
-                        double x = Double.parseDouble(String.valueOf(target.get("x"))) ;
-                        double y = Double.parseDouble(String.valueOf(target.get("y"))) ;
-                        if (cls == 1) { //是人
-                            //先查是否存在
-                            Integer lastIndex = (Integer)redisUtil.hget(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX,careDevice.getDevCode() + "_" + tid);
-                            logger.warn("lastIndex:{}",lastIndex);
-                            if(lastIndex == null) {//之前没有存储redis,则存储第一个
-                                redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, 1 + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
-                                redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
-                            } else{
-                                //计算当前和最近之间时间,若超过1秒,删除之前的存储的,重新计数存储当前的
-                                String lastContent = (String)redisUtil.hget(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO,lastIndex + "@" + careDevice.getDevCode() + "_" + tid );
-                                logger.warn("lastIndex:{},lastContent:{}",lastIndex,lastContent);
-                                long duration = (date.getTime() - Long.parseLong(lastContent.split("_")[0]));
-                                logger.warn("lastIndex:{},duration:{}",lastIndex,duration);
-                                if (duration > 1000) { //超过1秒,删除之前的存储的,从头开始
-                                    logger.warn("超过3000,lastIndex:{},duration:{}",lastIndex,duration);
-                                    delBeforeContent(lastIndex,careDevice.getDevCode(),tid);
-                                    redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, 1 + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y, RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
-                                    redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
-                                } else {
-                                    //存储以供后面计算
-                                    redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, (lastIndex + 1) + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y, RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
-                                    redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , lastIndex + 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
-                                    if(lastIndex >= 9) {
-                                        int currIndex = lastIndex + 1;//当前是第10个或以上 开始计算
-                                        //求前5个点平均坐标和后5个点的平均坐标,二者之间的距离即结果
-                                        double distance = getDistance(currIndex,careDevice.getDevCode(),tid);
-                                        logger.warn("计算结果:lastIndex:{},duration:{},distance{}",lastIndex,duration,distance);
-                                        if(distance > 0.3){
-                                            moveState = DeviceMoveStateEnum.MOVE.getValue();
-                                            //存储行走距离明细表
-                                            CareWalkingDistanceDetail careWalkingDistanceDetail = new CareWalkingDistanceDetail();
-                                            careWalkingDistanceDetail.setDevId(careDevice.getId());
-                                            careWalkingDistanceDetail.setTid(tid);
-                                            careWalkingDistanceDetail.setDevScene(careDevice.getDevScene());
-                                            careWalkingDistanceDetail.setWalkingDistance(distance);
-                                            //careWalkingDistanceDetail.setWalkingDuration(duration); 时间计算暂时不要
-                                            careWalkingDistanceDetail.setCreateTime(date);
-                                            careWalkingDistanceDetail.setModifyTime(date);
-                                            careWalkingDistanceDetailService.save(careWalkingDistanceDetail);
-                                        }
-                                    }
+
+        Integer amount = (Integer) msg.get("amount");
+        List<Map> targets = (List) msg.get("targets");
+        String moveState = DeviceMoveStateEnum.STATIC.getValue();
+        if(amount == 0){ //无人
+            moveState = DeviceMoveStateEnum.NONE.getValue();
+        } else { //有人,静止或活动
+            for(Map target : targets) {
+                Integer tid = (Integer) target.get("tid");
+                Integer cls = (Integer) target.get("cls");
+                double x = Double.parseDouble(String.valueOf(target.get("x"))) ;
+                double y = Double.parseDouble(String.valueOf(target.get("y"))) ;
+                if (cls == 1) { //是人
+                    //先查是否存在
+                    Integer lastIndex = (Integer)redisUtil.hget(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX,careDevice.getDevCode() + "_" + tid);
+                    logger.warn("lastIndex:{}",lastIndex);
+                    String lastContent = (String)redisUtil.hget(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO,lastIndex + "@" + careDevice.getDevCode() + "_" + tid );
+                    if(lastIndex == null || StringUtils.isEmpty(lastContent)) {//之前没有存储redis,则存储第一个
+                        redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, 1 + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
+                        redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
+                    } else{
+                        //计算当前和最近之间时间,若超过1秒,删除之前的存储的,重新计数存储当前的
+                        logger.warn("lastIndex:{},lastContent:{}",lastIndex,lastContent);
+                        long duration = (date.getTime() - Long.parseLong(lastContent.split("_")[0]));
+                        logger.warn("lastIndex:{},duration:{}",lastIndex,duration);
+                        if (duration > 1000) { //超过1秒,删除之前的存储的,从头开始
+                            logger.warn("超过3000,lastIndex:{},duration:{}",lastIndex,duration);
+                            delBeforeContent(lastIndex,careDevice.getDevCode(),tid);
+                            redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, 1 + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y, RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
+                            redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
+                        } else {
+                            //存储以供后面计算
+                            redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO, (lastIndex + 1) + "@" + careDevice.getDevCode() + "_" + tid , System.currentTimeMillis() +  "_" + x + "_" + y, RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_TIME);
+                            redisUtil.hset(RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_LAST_INDEX, careDevice.getDevCode() + "_" + tid , lastIndex + 1 , RedisKeyConstant.PEOPLEEVENT_ACTIVE_INFO_ACTIVE_LAST_INDEX_TIME);
+                            if(lastIndex >= 9) {
+                                int currIndex = lastIndex + 1;//当前是第10个或以上 开始计算
+                                //求前5个点平均坐标和后5个点的平均坐标,二者之间的距离即结果
+                                double distance = getDistance(currIndex,careDevice.getDevCode(),tid);
+                                logger.warn("计算结果:lastIndex:{},duration:{},distance{}",lastIndex,duration,distance);
+                                if(distance > 0.3){
+                                    moveState = DeviceMoveStateEnum.MOVE.getValue();
+                                    //存储行走距离明细表
+                                    CareWalkingDistanceDetail careWalkingDistanceDetail = new CareWalkingDistanceDetail();
+                                    careWalkingDistanceDetail.setDevId(careDevice.getId());
+                                    careWalkingDistanceDetail.setTid(tid);
+                                    careWalkingDistanceDetail.setDevScene(careDevice.getDevScene());
+                                    careWalkingDistanceDetail.setWalkingDistance(distance);
+                                    //careWalkingDistanceDetail.setWalkingDuration(duration); 时间计算暂时不要
+                                    careWalkingDistanceDetail.setCreateTime(date);
+                                    careWalkingDistanceDetail.setModifyTime(date);
+                                    careWalkingDistanceDetailService.save(careWalkingDistanceDetail);
                                 }
                                 }
                             }
                             }
                         }
                         }
                     }
                     }
                 }
                 }
+            }
+        }
 
 
-                if(!moveState.equals(careDevice.getMoveStatus())){
-                    //更新数据库dev
-                    careDevice.setMoveStatus(moveState);
-                    careDeviceService.updateById(careDevice);
-                }
-//            } else {
-//                try {
-//                    Thread.sleep(3000);
-//                    handlePeopleEvent(msg,careDevice,date);
-//                } catch (Exception e){
-//                    e.printStackTrace();
-//                }
-//
-//            }
-//        }  finally {
-//            redisUtil.releaseLock(key,requestId);
-//        }
+        if(!moveState.equals(careDevice.getMoveStatus())){
+            //更新数据库dev
+            careDevice.setMoveStatus(moveState);
+            careDeviceService.updateById(careDevice);
+        }
 
 
     }
     }