|
@@ -9,11 +9,11 @@ import com.hfln.portal.common.dto.data.group.GroupDTO;
|
|
|
import com.hfln.portal.common.request.group.*;
|
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
|
import com.hfln.portal.domain.gateway.GroupGateway;
|
|
|
+import com.hfln.portal.infrastructure.mapper.GroupDevMapMapper;
|
|
|
import com.hfln.portal.infrastructure.po.DevGroup;
|
|
|
import com.hfln.portal.infrastructure.po.DevInfo;
|
|
|
import com.hfln.portal.infrastructure.po.GroupDevMap;
|
|
|
import com.hfln.portal.infrastructure.po.GroupShare;
|
|
|
-import com.hfln.portal.infrastructure.mapper.GroupDevMapMapper;
|
|
|
import com.hfln.portal.infrastructure.service.DevGroupService;
|
|
|
import com.hfln.portal.infrastructure.service.DevInfoService;
|
|
|
import com.hfln.portal.infrastructure.service.GroupShareService;
|
|
@@ -22,6 +22,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -51,18 +52,26 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
|
|
|
@Override
|
|
|
public Boolean addGroup(GroupAddParams request) {
|
|
|
- //1.设置群组属性
|
|
|
+
|
|
|
+ //1.校验:当前用户的群组名称是否已存在
|
|
|
+ boolean exists = devGroupService.lambdaQuery()
|
|
|
+ .eq(DevGroup::getUserId, request.getUserId())
|
|
|
+ .eq(DevGroup::getGroupName, request.getGroupName())
|
|
|
+ .eq(DevGroup::getIsDeleted, 0)
|
|
|
+ .exists();
|
|
|
+ if (exists){
|
|
|
+ throw new BizException(ErrorEnum.GROUP_NAME_IS_EXIST.getErrorCode(), ErrorEnum.GROUP_NAME_IS_EXIST.getErrorMessage());
|
|
|
+ }
|
|
|
+ //2.设置群组属性
|
|
|
DevGroup devGroup = new DevGroup();
|
|
|
devGroup.setGroupName(request.getGroupName());
|
|
|
devGroup.setUserId(request.getUserId());
|
|
|
- if (Objects.isNull(request.getUserId())) {
|
|
|
- throw new BizException(ErrorEnum.USER_IS_NOT_EXIST.getErrorCode(), ErrorEnum.USER_IS_NOT_EXIST.getErrorMessage());
|
|
|
- }
|
|
|
devGroup.setGroupUuid(UUID.randomUUID().toString().replace("-", ""));
|
|
|
devGroup.setIsDeleted(0);
|
|
|
- //2.把群组名称和UUID存储数据库
|
|
|
+
|
|
|
// TODO mqtt消息 主题 /mps/add_group
|
|
|
|
|
|
+ //3.把群组名称和UUID存储数据库
|
|
|
return devGroupService.save(devGroup);
|
|
|
}
|
|
|
|
|
@@ -74,6 +83,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Boolean deleteGroup(Long groupId) {
|
|
|
//TODO MQTT消息 主题 /mps/delete_group
|
|
|
//1.查询群组信息
|
|
@@ -175,7 +185,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<GroupDTO> queryGroupList(Long userId) {
|
|
|
- // 1. 查询被分享群组
|
|
|
+ // 1. 查询被分享群组的uuid集合
|
|
|
List<String> groupUUids = groupShareService.queryGroupUUidByUserId(userId);
|
|
|
|
|
|
// 2. 获取用户自己创建的群组和被分享的群组
|
|
@@ -293,9 +303,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
@Override
|
|
|
public Boolean addDeviceToGroup(AddDeviceToGroupParams params) {
|
|
|
// 1. 查询设备和群组是否存在
|
|
|
- DevInfo devInfo = devInfoService.getOne(
|
|
|
- Wrappers.<DevInfo>lambdaQuery()
|
|
|
- .eq(DevInfo::getDevId, params.getDevId()));
|
|
|
+ DevInfo devInfo = devInfoService.getById(params.getDevId());
|
|
|
if (Objects.isNull(devInfo)) {
|
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
@@ -307,8 +315,8 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
|
|
|
// 2. 检查设备是否已经添加到群组中
|
|
|
LambdaQueryWrapper<GroupDevMap> queryWrapper = Wrappers.<GroupDevMap>lambdaQuery()
|
|
|
- .eq(GroupDevMap::getDevId, devInfo.getClientId())
|
|
|
- .eq(GroupDevMap::getGroupUuid, devGroup.getGroupUuid());
|
|
|
+ .eq(GroupDevMap::getDevId, params.getDevId())
|
|
|
+ .eq(GroupDevMap::getGroupId, params.getGroupId());
|
|
|
|
|
|
GroupDevMap groupDevMap = groupDevMapMapper.selectOne(queryWrapper);
|
|
|
|
|
@@ -316,7 +324,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
if (Objects.nonNull(groupDevMap)) {
|
|
|
// 检查是否已添加(is_delete为0)
|
|
|
if (groupDevMap.getIsDeleted() == 0) {
|
|
|
- throw new BizException(ErrorEnum.ERROR_BIZ_FAIL.getErrorCode(), "请勿重复添加设备");
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_ALREADY_IN_GROUP.getErrorCode(), ErrorEnum.DEVICE_ALREADY_IN_GROUP.getErrorMessage());
|
|
|
}
|
|
|
// 如果是逻辑删除状态,恢复关系
|
|
|
else {
|
|
@@ -355,7 +363,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
|
|
|
// 2. 如果关联关系不存在,返回错误
|
|
|
if (Objects.isNull(groupDevMap)) {
|
|
|
- throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST_GROUP.getErrorCode(), "设备未加入此群组");
|
|
|
+ throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST_GROUP.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST_GROUP.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
// 3. 创建更新条件
|
|
@@ -378,7 +386,8 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
// 1. 验证群组是否存在
|
|
|
DevGroup devGroup = devGroupService.getOne(
|
|
|
Wrappers.<DevGroup>lambdaQuery()
|
|
|
- .eq(DevGroup::getGroupUuid, request.getGroupUuid()));
|
|
|
+ .eq(DevGroup::getGroupUuid, request.getGroupUuid())
|
|
|
+ .eq(DevGroup::getIsDeleted, 0));
|
|
|
if (Objects.isNull(devGroup)) {
|
|
|
throw new BizException(ErrorEnum.GROUP_IS_NOT_EXIST.getErrorCode(), ErrorEnum.GROUP_IS_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
@@ -427,7 +436,7 @@ public class GroupGatewayImpl implements GroupGateway {
|
|
|
|
|
|
// 2. 检查分享状态
|
|
|
if (groupShare.getState() != 0) {
|
|
|
- throw new BizException(ErrorEnum.SHARE_IS_EXPIRED.getErrorCode(), ErrorEnum.SHARE_IS_EXPIRED.getErrorMessage());
|
|
|
+ throw new BizException(ErrorEnum.SHARE_IS_HANDLED.getErrorCode(), ErrorEnum.SHARE_IS_HANDLED.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
// 3. 更新分享记录
|