|
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.hfln.portal.common.constant.UserConstants;
|
|
|
import com.hfln.portal.common.constant.mqtt.topic.TopicConstants;
|
|
|
+import com.hfln.portal.common.constant.redis.RedisCacheConstant;
|
|
|
import com.hfln.portal.common.dto.data.device.DeviceDTO;
|
|
|
import com.hfln.portal.common.dto.data.event.EventListDTO;
|
|
|
import com.hfln.portal.common.dto.data.event.StayTimeDTO;
|
|
@@ -53,10 +54,12 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -76,7 +79,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
private DevGroupService devGroupService;
|
|
|
|
|
|
@Autowired
|
|
|
- private EventService eventService;
|
|
|
+ private EventListService eventListService;
|
|
|
|
|
|
@Autowired
|
|
|
private OssFileService ossFileService;
|
|
@@ -374,14 +377,48 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
@Override
|
|
|
public Boolean handleEvent(Long eventListId) {
|
|
|
- //获取当前操作者手机号
|
|
|
- String phone = (String) StpUtil.getSession().get(UserConstants.SA_USER_PHONE);
|
|
|
-
|
|
|
- LambdaUpdateWrapper<EventList> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(EventList::getEventListId, eventListId)
|
|
|
- .set(EventList::getIsHandle, 1)
|
|
|
- .set(EventList::getRemark, PhoneUtils.maskPhone(phone));
|
|
|
- return this.eventService.update(updateWrapper);
|
|
|
+
|
|
|
+ //1.查询事件信息
|
|
|
+ EventList eventList = eventListService.getById(eventListId);
|
|
|
+ if (eventList == null){
|
|
|
+ throw new BizException(ErrorEnum.FALLING_EVENT_NOT_EXIST.getErrorCode(), ErrorEnum.FALLING_EVENT_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2.构建 Redis key 和 当前处理人
|
|
|
+ String redisKey = RedisCacheConstant.FALLING_EVENTS_KEY_PRE + ":" + eventListId;
|
|
|
+ String userId = String.valueOf(StpUtil.getSession().get(UserConstants.SA_USER_ID));
|
|
|
+
|
|
|
+ // 3.如果事件未处理
|
|
|
+ if(eventList.getIsHandle() == 0) {
|
|
|
+ // 获取当前处理者手机号
|
|
|
+ String phone = String.valueOf(StpUtil.getSession().get(UserConstants.SA_USER_PHONE));
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<EventList> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(EventList::getEventListId, eventListId)
|
|
|
+ .set(EventList::getIsHandle, 1)
|
|
|
+ .set(EventList::getRemark, PhoneUtils.maskPhone(phone));
|
|
|
+
|
|
|
+ // 存入 Redis Set
|
|
|
+ redisTemplate.opsForSet().add(redisKey, userId);
|
|
|
+
|
|
|
+ // 计算 TTL 并设置过期时间
|
|
|
+ LocalDateTime createTime = eventList.getCreateTime(); // 事件发生时间
|
|
|
+ LocalDateTime now = LocalDateTime.now(); // 接口调用时间
|
|
|
+ long ttlSeconds = Duration.between(now, createTime.plusSeconds(600)).getSeconds(); //剩余时间
|
|
|
+
|
|
|
+ if(ttlSeconds > 0){
|
|
|
+ redisTemplate.expire(redisKey, ttlSeconds, TimeUnit.SECONDS);
|
|
|
+ } else {
|
|
|
+ // 已超时 直接删除key
|
|
|
+ redisTemplate.delete(redisKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.eventListService.update(updateWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4.如果事件已处理
|
|
|
+ redisTemplate.opsForSet().add(redisKey, userId);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
@@ -839,10 +876,27 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
@Override
|
|
|
public QueryUserPermissionDTO queryUserPermission(QueryUserVoipParam param){
|
|
|
+ // 1.根据设备id查询设备信息
|
|
|
+ DevInfo devInfo = devInfoService.queryOneByClientId(param.getClientId());
|
|
|
+ if (devInfo == null) {
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2.校验用户是否为主绑人
|
|
|
+ if (devInfo.getUserId().equals(param.getUserId())) {
|
|
|
+ QueryUserPermissionDTO DTO = new QueryUserPermissionDTO();
|
|
|
+ DTO.setMessageFlag(0);
|
|
|
+ DTO.setServiceNumberFlag(0);
|
|
|
+ DTO.setVoipFlag(0);
|
|
|
+ return DTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.用户不为主绑人,则查询分享记录获取权限
|
|
|
LambdaQueryWrapper<DevShare> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(DevShare::getDevId, param.getDevId());
|
|
|
+ queryWrapper.eq(DevShare::getDevId, devInfo.getDevId());
|
|
|
queryWrapper.eq(DevShare::getSharedUserId, param.getUserId());
|
|
|
queryWrapper.eq(DevShare::getState, DevShare.Constants.ShareStatus.SHARED);
|
|
|
+ queryWrapper.eq(DevShare::getIsDeleted, BasePO.DeleteFlag.NOT_DELETED);
|
|
|
DevShare devShare = devShareService.getOne(queryWrapper);
|
|
|
|
|
|
if (devShare == null){
|