|  | @@ -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);
 | 
												
													
														
															|  | 
 |  | +        }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 |