修改大屏管理用户隔离逻辑删除,搜索

main
whb 7 months ago
parent 3f6c283e9a
commit 11117575b8

@ -64,4 +64,8 @@ public class DataRoomGlobalExceptionHandler {
log.error(ExceptionUtils.getStackTrace(e)); log.error(ExceptionUtils.getStackTrace(e));
return R.error("服务器异常"); return R.error("服务器异常");
} }
} }

@ -8,6 +8,7 @@ import com.gccloud.dataroom.core.module.basic.entity.type.BasePageDTOTypeHandler
import com.gccloud.common.entity.SuperEntity; import com.gccloud.common.entity.SuperEntity;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@ -58,5 +59,4 @@ public class PageEntity extends SuperEntity implements Serializable {
private String appCode; private String appCode;
} }

@ -1,12 +1,17 @@
package com.gccloud.dataroom.core.module.basic.service; package com.gccloud.dataroom.core.module.basic.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gccloud.common.exception.GlobalException;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity; import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
import com.gccloud.common.service.ISuperService; import com.gccloud.common.service.ISuperService;
import com.gccloud.common.utils.AssertUtils; import com.gccloud.common.utils.AssertUtils;
import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao;
import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser;
import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -19,8 +24,11 @@ import java.util.stream.Collectors;
* @version 1.0 * @version 1.0
* @date 2022/8/8 15:11 * @date 2022/8/8 15:11
*/ */
public interface IBasePageService extends ISuperService<PageEntity> { public interface IBasePageService extends ISuperService<PageEntity> {
/** /**
* *
*/ */
@ -69,12 +77,18 @@ public interface IBasePageService extends ISuperService<PageEntity> {
* @return * @return
*/ */
default boolean checkNameRepeat(PageEntity entity) { default boolean checkNameRepeat(PageEntity entity) {
AssertUtils.isTrue(StringUtils.isNotBlank(entity.getName()), "名称不能为空"); AssertUtils.isTrue(StringUtils.isNotBlank(entity.getName()), "名称不能为空");
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(PageEntity::getId); queryWrapper.select(PageEntity::getId);
queryWrapper.eq(StringUtils.isNotBlank(entity.getAppCode()), PageEntity::getAppCode, entity.getAppCode()) queryWrapper.eq(StringUtils.isNotBlank(entity.getAppCode()), PageEntity::getAppCode, entity.getAppCode())
.eq(PageEntity::getName, entity.getName()) .eq(PageEntity::getName, entity.getName())
.eq(PageEntity::getType, entity.getType()) .eq(PageEntity::getType, entity.getType())
//不等于
.ne(StringUtils.isNotBlank(entity.getId()), PageEntity::getId, entity.getId()); .ne(StringUtils.isNotBlank(entity.getId()), PageEntity::getId, entity.getId());
return getBaseMapper().selectList(queryWrapper).size() > 0; return getBaseMapper().selectList(queryWrapper).size() > 0;
} }

@ -1,6 +1,7 @@
package com.gccloud.dataroom.core.module.biz.component.service.impl; package com.gccloud.dataroom.core.module.biz.component.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gccloud.common.exception.GlobalException;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity; import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao; import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao;
import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser; import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser;
@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -40,7 +42,9 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
@Override @Override
public boolean verifyDataPermission(HttpServletRequest request, String pageCode) { public boolean verifyDataPermission(HttpServletRequest request, String pageCode) {
return false;
//todo 校验userId是否正确
return true;
} }
@ -50,11 +54,12 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
*/ */
@Override @Override
public List<String> filterByPermission(List<String> allCode, String userId,String type) { public List<String> filterByPermission(List<String> allCode, String userId,String type,String parentCode) {
// LambdaQueryWrapper<BizComponentUser> newQueryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<BizComponentUser> newQueryWrapper = new LambdaQueryWrapper<>();
// newQueryWrapper.eq() // newQueryWrapper.eq()
// //
LambdaQueryWrapper<BizComponentUser> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BizComponentUser> queryWrapper = new LambdaQueryWrapper<>();
//用户ID //用户ID
@ -66,12 +71,23 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
//根据创建时间排序 //根据创建时间排序
queryWrapper.orderByDesc(BizComponentUser::getCreateDate); queryWrapper.orderByDesc(BizComponentUser::getCreateDate);
if (StringUtils.hasText(parentCode)) {
queryWrapper.eq(BizComponentUser::getParentCode,parentCode);
}
if (!CollectionUtils.isEmpty(allCode)) {
queryWrapper.in(BizComponentUser::getCode,allCode);
}
List<BizComponentUser> bizComponentUserList = userDao.selectList(queryWrapper); List<BizComponentUser> bizComponentUserList = userDao.selectList(queryWrapper);
List<String> codeList = bizComponentUserList.stream().map(item -> item.getCode()).collect(Collectors.toList()); List<String> codeList = bizComponentUserList.stream().map(item -> item.getCode()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(codeList))
if (CollectionUtils.isEmpty(bizComponentUserList)&&type.equals("bigScreen") )
{ {
//拷贝三个默认图形 //拷贝三个默认图形
List<String> arrayList = new ArrayList<>(); List<String> arrayList = new ArrayList<>();
@ -84,11 +100,16 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
String newCode = bigScreenPageService.copy(bigScreenPage); String newCode = bigScreenPageService.copy(bigScreenPage);
BizComponentUser bizComponentUser = new BizComponentUser(); BizComponentUser bizComponentUser = new BizComponentUser();
bizComponentUser.setType("bigScreen"); bizComponentUser.setType("bigScreen");
if (!StringUtils.hasText(userId)){
//throw new EnumConstantNotPresentException(HttpServletRequest.BASIC_AUTH,"userId不能为空");
throw new GlobalException("userId不能为空");
}
bizComponentUser.setUserId(userId); bizComponentUser.setUserId(userId);
bizComponentUser.setCode(newCode); bizComponentUser.setCode(newCode);
userDao.insert(bizComponentUser); userDao.insert(bizComponentUser);
codeList.add(newCode); codeList.add(newCode);
} }
} }
return codeList; return codeList;

@ -1,9 +1,12 @@
package com.gccloud.dataroom.core.module.manage.controller; package com.gccloud.dataroom.core.module.manage.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gccloud.dataroom.core.config.DataRoomConfig; import com.gccloud.dataroom.core.config.DataRoomConfig;
import com.gccloud.dataroom.core.constant.DataRoomConst; import com.gccloud.dataroom.core.constant.DataRoomConst;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity; import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
import com.gccloud.dataroom.core.module.basic.entity.PagePreviewEntity; import com.gccloud.dataroom.core.module.basic.entity.PagePreviewEntity;
import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao;
import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser;
import com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO; import com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO;
import com.gccloud.dataroom.core.module.manage.dto.DataRoomSearchDTO; import com.gccloud.dataroom.core.module.manage.dto.DataRoomSearchDTO;
import com.gccloud.dataroom.core.module.manage.service.IDataRoomPagePreviewService; import com.gccloud.dataroom.core.module.manage.service.IDataRoomPagePreviewService;
@ -24,13 +27,15 @@ import com.google.common.collect.Lists;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author hongyang * @author hongyang
@ -72,6 +77,10 @@ public class DataRoomPageController {
@GetMapping("/page") @GetMapping("/page")
@ApiOperation(value = "大屏/组件分页列表", position = 10, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "大屏/组件分页列表", position = 10, produces = MediaType.APPLICATION_JSON_VALUE)
public MixinsResp<PageVO<PageEntity>> page(DataRoomSearchDTO searchDTO) { public MixinsResp<PageVO<PageEntity>> page(DataRoomSearchDTO searchDTO) {
if (!StringUtils.hasText(searchDTO.getUserId()))
{
throw new GlobalException("userId不能为空");
}
PageVO<PageEntity> page = bigScreenPageService.getByCategory(searchDTO); PageVO<PageEntity> page = bigScreenPageService.getByCategory(searchDTO);
MixinsResp<PageVO<PageEntity>> resp = new MixinsResp<PageVO<PageEntity>>().setData(page); MixinsResp<PageVO<PageEntity>> resp = new MixinsResp<PageVO<PageEntity>>().setData(page);
@ -185,11 +194,61 @@ public class DataRoomPageController {
return R.success(bgList); return R.success(bgList);
} }
@Autowired
private DataRoomBizUserDao userDao;
@ApiPermission @ApiPermission
@PostMapping("/name/repeat") @PostMapping("/name/repeat")
@ApiOperation(value = "大屏/组件名称是否重复", position = 60, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "大屏/组件名称是否重复", position = 60, produces = MediaType.APPLICATION_JSON_VALUE)
public R<Boolean> nameRepeat(@RequestBody PageEntity pageEntity) { public R<Boolean> nameRepeat(@RequestBody PageEntity pageEntity) {
boolean repeat = bigScreenPageService.checkNameRepeat(pageEntity);
return R.success(repeat); //获取用户的code 和type
if (!org.springframework.util.StringUtils.hasText(pageEntity.getId()))
{
throw new GlobalException("userId不能为空");
}
LambdaQueryWrapper<BizComponentUser> queryWrapper = new LambdaQueryWrapper<>();
//用户ID
queryWrapper.eq(BizComponentUser::getUserId,pageEntity.getId());
//单独授权码
queryWrapper.select(BizComponentUser::getCode);
//页面类型
queryWrapper.in(org.apache.commons.lang3.StringUtils.isNotBlank(pageEntity.getType()),BizComponentUser::getType, pageEntity.getType());
List<BizComponentUser> bizComponentUserList = userDao.selectList(queryWrapper);
if (bizComponentUserList.isEmpty())
{
return R.success(false);
}
List<String> collect = bizComponentUserList.stream().map(item -> item.getCode()).collect(Collectors.toList());
if (collect.isEmpty())
{
return R.success(false);
}
List<PageEntity> pageEntitieList = bigScreenPageService.selectUserInfoByCode(collect);
if (pageEntitieList.isEmpty())
{
return R.success(false);
}
for (PageEntity entity : pageEntitieList) {
boolean repeat = bigScreenPageService.checkNameRepeat(entity);
if (repeat)
{
return R.success(repeat);
}
}
return R.success(false);
} }
} }

@ -6,6 +6,8 @@ import com.gccloud.dataroom.core.module.manage.dto.DataRoomPageDTO;
import com.gccloud.dataroom.core.module.manage.dto.DataRoomSearchDTO; import com.gccloud.dataroom.core.module.manage.dto.DataRoomSearchDTO;
import com.gccloud.common.vo.PageVO; import com.gccloud.common.vo.PageVO;
import java.util.List;
/** /**
* @author hongyang * @author hongyang
* @version 1.0 * @version 1.0
@ -67,4 +69,5 @@ public interface IDataRoomPageService extends IBasePageService {
*/ */
void deleteByCode(String code); void deleteByCode(String code);
List<PageEntity> selectUserInfoByCode(List<String> collect);
} }

@ -38,6 +38,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.tomcat.util.http.fileupload.FileItem; import org.apache.tomcat.util.http.fileupload.FileItem;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -79,6 +80,10 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
@Autowired @Autowired
private DataRoomBizUserDao userDao; private DataRoomBizUserDao userDao;
@Value("${gc.starter.file.img}")
private String path;
@Override @Override
public PageEntity getByCode(String code) { public PageEntity getByCode(String code) {
if (code.startsWith(IDataRoomPagePreviewService.PREVIEW_KEY)) { if (code.startsWith(IDataRoomPagePreviewService.PREVIEW_KEY)) {
@ -94,7 +99,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
if (!org.springframework.util.StringUtils.hasText(bigScreenPageDTO.getUserId())) if (!org.springframework.util.StringUtils.hasText(bigScreenPageDTO.getUserId()))
{ {
throw new RuntimeException("userId不能为空"); throw new GlobalException("userId不能为空");
} }
String code = null; String code = null;
@ -127,6 +132,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
BizComponentUser bizComponentUser = new BizComponentUser(); BizComponentUser bizComponentUser = new BizComponentUser();
bizComponentUser.setUserId(bigScreenPageDTO.getUserId()); bizComponentUser.setUserId(bigScreenPageDTO.getUserId());
bizComponentUser.setCode(code); bizComponentUser.setCode(code);
bizComponentUser.setParentCode(bigScreenPageDTO.getParentCode());
bizComponentUser.setType(bigScreenPageDTO.getType()); bizComponentUser.setType(bigScreenPageDTO.getType());
userDao.insert(bizComponentUser); userDao.insert(bizComponentUser);
@ -289,10 +295,12 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
// } // }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public PageVO<PageEntity> getByCategory(DataRoomSearchDTO searchDTO) { public PageVO<PageEntity> getByCategory(DataRoomSearchDTO searchDTO) {
if (StringUtils.isBlank(searchDTO.getType())) { if (StringUtils.isBlank(searchDTO.getType())) {
throw new GlobalException("类型不能为空"); throw new GlobalException("类型不能为空");
} }
//只查询当前用户的code
// 使用分割type // 使用分割type
List<String> types = Lists.newArrayList(searchDTO.getType().split(",")); List<String> types = Lists.newArrayList(searchDTO.getType().split(","));
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -310,15 +318,13 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
return pageVO; return pageVO;
} }
List<String> codeList = idEntityList.stream().map(PageEntity::getCode).collect(Collectors.toList()); List<String> codeList = idEntityList.stream().map(PageEntity::getCode).collect(Collectors.toList());
List<String> filterByPermission = permissionClient.filterByPermission(codeList,searchDTO.getUserId(),searchDTO.getType()); List<String> filterByPermission = permissionClient.filterByPermission(codeList,searchDTO.getUserId(),searchDTO.getType(),searchDTO.getParentCode());
if (filterByPermission == null || filterByPermission.isEmpty()) { if (filterByPermission == null || filterByPermission.isEmpty()) {
PageVO<PageEntity> pageVO = new PageVO<>(); PageVO<PageEntity> pageVO = new PageVO<>();
pageVO.setList(Lists.newArrayList()); pageVO.setList(Lists.newArrayList());
return pageVO; return pageVO;
} }
LambdaQueryWrapper<PageEntity> reQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PageEntity> reQueryWrapper = new LambdaQueryWrapper<>();
if (idEntityList.size() == filterByPermission.size()) { if (idEntityList.size() == filterByPermission.size()) {
// 说明没有过滤掉任何一个, 按照原来的条件查询 // 说明没有过滤掉任何一个, 按照原来的条件查询
@ -357,13 +363,14 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
} }
PageEntity bigScreenEntity = BeanConvertUtils.convert(bigScreenPageDTO, PageEntity.class); PageEntity bigScreenEntity = BeanConvertUtils.convert(bigScreenPageDTO, PageEntity.class);
bigScreenEntity.setConfig(bigScreenPageDTO); bigScreenEntity.setConfig(bigScreenPageDTO);
AssertUtils.isTrue(!checkNameRepeat(bigScreenEntity), "名称重复"); AssertUtils.isTrue(!checkNameRepeat(bigScreenEntity), "名称重复");
AssertUtils.isTrue(!checkCodeRepeat(bigScreenEntity), "编码重复"); AssertUtils.isTrue(!checkCodeRepeat(bigScreenEntity), "编码重复");
this.updateById(bigScreenEntity); this.updateById(bigScreenEntity);
PAGE_ENTITY_CACHE.invalidate(bigScreenEntity.getCode()); PAGE_ENTITY_CACHE.invalidate(bigScreenEntity.getCode());
} }
// public static final String COPY_SUFFIX = "-副本";
public static final String COPY_SUFFIX = "-副本"; public static final String COPY_SUFFIX = "-副本";
@Override @Override
@ -429,6 +436,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
if (StringUtils.isBlank(copyUrl)) { if (StringUtils.isBlank(copyUrl)) {
screenEntity.setCoverPicture(null); screenEntity.setCoverPicture(null);
} else { } else {
//screenEntity.setCoverPicture(path+File.separator+copyUrl);
screenEntity.setCoverPicture(copyUrl); screenEntity.setCoverPicture(copyUrl);
} }
this.save(screenEntity); this.save(screenEntity);
@ -441,10 +449,30 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PageEntity::getCode, code); queryWrapper.eq(PageEntity::getCode, code);
this.remove(queryWrapper); this.remove(queryWrapper);
LambdaQueryWrapper<BizComponentUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
//用户ID
userLambdaQueryWrapper.eq(BizComponentUser::getCode,code);
userDao.delete(userLambdaQueryWrapper);
PAGE_ENTITY_CACHE.invalidate(code); PAGE_ENTITY_CACHE.invalidate(code);
// 调用拓展接口 // 调用拓展接口
dataRoomExtendClient.deleteByCode(code); dataRoomExtendClient.deleteByCode(code);
// 移除权限拓展 // 移除权限拓展
dataRoomExtendClient.afterDelete(code); dataRoomExtendClient.afterDelete(code);
} }
@Override
public List<PageEntity> selectUserInfoByCode(List<String> collect) {
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(PageEntity::getCode,collect);
List<PageEntity> list = this.list(queryWrapper);
return list;
}
} }

@ -1,5 +1,11 @@
package com.gccloud.dataroom.core.module.type.controller; package com.gccloud.dataroom.core.module.type.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gccloud.common.exception.GlobalException;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao;
import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser;
import com.gccloud.dataroom.core.module.manage.service.IDataRoomPageService;
import com.gccloud.dataroom.core.module.type.dto.TypeDTO; import com.gccloud.dataroom.core.module.type.dto.TypeDTO;
import com.gccloud.dataroom.core.module.type.entity.TypeEntity; import com.gccloud.dataroom.core.module.type.entity.TypeEntity;
import com.gccloud.dataroom.core.module.type.service.ITypeService; import com.gccloud.dataroom.core.module.type.service.ITypeService;
@ -12,12 +18,14 @@ import com.gccloud.common.vo.R;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author hongyang * @author hongyang
@ -40,7 +48,7 @@ public class TypeController {
public R<List<TypeVO>> list(String type,String userId) { public R<List<TypeVO>> list(String type,String userId) {
if (!StringUtils.hasText(userId)) if (!StringUtils.hasText(userId))
{ {
throw new RuntimeException("userId不能空"); throw new GlobalException("userId不能为空");
} }
List<TypeEntity> entityList = typeService.listByType(type,userId); List<TypeEntity> entityList = typeService.listByType(type,userId);
@ -74,11 +82,57 @@ public class TypeController {
return R.success(); return R.success();
} }
@Autowired
private DataRoomBizUserDao userDao;
@Resource
private IDataRoomPageService bigScreenPageService;
@PostMapping("/nameRepeat") @PostMapping("/nameRepeat")
@ApiOperation(value = "分类名称重复校验", position = 40, produces = MediaType.APPLICATION_JSON_VALUE) @ApiOperation(value = "分类名称重复校验", position = 40, produces = MediaType.APPLICATION_JSON_VALUE)
public R<Boolean> nameRepeat(@RequestBody TypeDTO typeDTO) { public R<Boolean> nameRepeat(@RequestBody TypeDTO typeDTO) {
Boolean flag = typeService.checkNameRepeat(typeDTO.getId(), typeDTO.getType(), typeDTO.getName());
return R.success(flag);
//获取用户的code 和type
if (!org.springframework.util.StringUtils.hasText(typeDTO.getId()))
{
throw new GlobalException("userId不能为空");
}
LambdaQueryWrapper<BizComponentUser> queryWrapper = new LambdaQueryWrapper<>();
//用户ID
queryWrapper.eq(BizComponentUser::getUserId,typeDTO.getId());
//单独授权码
queryWrapper.select(BizComponentUser::getCode);
//页面类型
queryWrapper.in(org.apache.commons.lang3.StringUtils.isNotBlank(typeDTO.getType()),BizComponentUser::getType, typeDTO.getType());
List<BizComponentUser> bizComponentUserList = userDao.selectList(queryWrapper);
if (bizComponentUserList.isEmpty())
{
return R.success(false);
}
List<String> collect = bizComponentUserList.stream().map(item -> item.getCode()).collect(Collectors.toList());
if (collect.isEmpty())
{
return R.success(false);
}
List<PageEntity> pageEntitieList = bigScreenPageService.selectUserInfoByCode(collect);
if (pageEntitieList.isEmpty())
{
return R.success(false);
}
for (PageEntity entity : pageEntitieList) {
Boolean flag = typeService.checkNameRepeat(entity.getId(), entity.getType(), entity.getName());
if (flag)
{
return R.success(flag);
}
}
return R.success(false);
} }

@ -2,8 +2,10 @@ package com.gccloud.dataroom.core.module.type.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao; import com.gccloud.dataroom.core.module.biz.component.dao.DataRoomBizUserDao;
import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser; import com.gccloud.dataroom.core.module.biz.component.entity.BizComponentUser;
import com.gccloud.dataroom.core.module.manage.service.IDataRoomPageService;
import com.gccloud.dataroom.core.module.type.dao.DataRoomTypeDao; import com.gccloud.dataroom.core.module.type.dao.DataRoomTypeDao;
import com.gccloud.dataroom.core.module.type.dto.TypeDTO; import com.gccloud.dataroom.core.module.type.dto.TypeDTO;
import com.gccloud.dataroom.core.module.type.entity.TypeEntity; import com.gccloud.dataroom.core.module.type.entity.TypeEntity;
@ -16,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -31,9 +34,17 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
@Autowired @Autowired
private DataRoomBizUserDao userDao; private DataRoomBizUserDao userDao;
@Autowired
private IDataRoomPageService service;
@Override @Override
public String add(TypeDTO typeDTO) { public String add(TypeDTO typeDTO) {
if (!org.springframework.util.StringUtils.hasText(typeDTO.getUserId()))
{
throw new GlobalException("userId不能为空");
}
TypeEntity entity = BeanConvertUtils.convert(typeDTO, TypeEntity.class); TypeEntity entity = BeanConvertUtils.convert(typeDTO, TypeEntity.class);
String code = null; String code = null;
if (StringUtils.isBlank(entity.getCode())) { if (StringUtils.isBlank(entity.getCode())) {
@ -47,9 +58,9 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
entity.setCode(CodeGenerateUtils.generate(typeDTO.getType())); entity.setCode(CodeGenerateUtils.generate(typeDTO.getType()));
} }
} }
if (this.checkNameRepeat(null, typeDTO.getType(), entity.getName())) { // if (this.checkNameRepeat(null, typeDTO.getType(), entity.getName())) {
throw new GlobalException("分组名称已存在"); // throw new GlobalException("分组名称已存在");
} // }
this.save(entity); this.save(entity);
@ -78,19 +89,36 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
} }
TypeEntity byId = this.getById(id); TypeEntity byId = this.getById(id);
this.removeById(id);
//根据ID查询code 和type,然后删除 //根据ID查询code 和type,然后删除
String type = byId.getType();
String code = byId.getCode(); String code = byId.getCode();
LambdaQueryWrapper<BizComponentUser> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<BizComponentUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(BizComponentUser::getType,type);
lambdaQueryWrapper.eq(BizComponentUser::getCode,code);
lambdaQueryWrapper.eq(BizComponentUser::getCode,code).or(wrapper -> wrapper.eq(BizComponentUser::getParentCode, code));;
List<BizComponentUser> bizComponentUserList = userDao.selectList(lambdaQueryWrapper);
if (!bizComponentUserList.isEmpty())
{
bizComponentUserList.forEach(item->{
if (item.getParentCode()!=null)
{
service.deleteByCode(item.getCode());
}
});
}
//删除大屏表的code
userDao.delete(lambdaQueryWrapper); userDao.delete(lambdaQueryWrapper);
this.removeById(id);
} }
@Override @Override
@ -105,7 +133,10 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
userLambdaQueryWrapper.eq(BizComponentUser::getType,type); userLambdaQueryWrapper.eq(BizComponentUser::getType,type);
List<BizComponentUser> bizComponentUserList = userDao.selectList(userLambdaQueryWrapper); List<BizComponentUser> bizComponentUserList = userDao.selectList(userLambdaQueryWrapper);
List<String> codeList = bizComponentUserList.stream().map(code -> code.getCode()).collect(Collectors.toList()); List<String> codeList = bizComponentUserList.stream().map(code -> code.getCode()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(codeList))
{
return Lists.newArrayList();
}
LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -129,11 +160,17 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
@Override @Override
public boolean checkNameRepeat(String id, String type, String name) { public boolean checkNameRepeat(String id, String type, String name) {
LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(TypeEntity::getId); queryWrapper.select(TypeEntity::getId);
queryWrapper.eq(TypeEntity::getName, name); queryWrapper.eq(TypeEntity::getName, name);
queryWrapper.eq(TypeEntity::getType, type); queryWrapper.eq(TypeEntity::getType, type);
queryWrapper.ne(StringUtils.isNotBlank(id), TypeEntity::getId, id); queryWrapper.ne(StringUtils.isNotBlank(id), TypeEntity::getId, id);
return this.list(queryWrapper).size() > 0; return this.list(queryWrapper).size() > 0;
} }
} }

@ -45,9 +45,9 @@ public class DataRoomPermissionClient {
* @param allCode code * @param allCode code
* @return code * @return code
*/ */
public List<String> filterByPermission(List<String> allCode,String userId,String type) { public List<String> filterByPermission(List<String> allCode,String userId,String type,String parentCode) {
if (permissionService != null) { if (permissionService != null) {
return permissionService.filterByPermission(allCode,userId,type); return permissionService.filterByPermission(allCode,userId,type,parentCode);
} }
return allCode; return allCode;
} }

@ -24,6 +24,6 @@ public interface IDataRoomPermissionService {
* @param allCode code * @param allCode code
* @return code * @return code
*/ */
List<String> filterByPermission(List<String> allCode,String userId,String type) ; List<String> filterByPermission(List<String> allCode,String userId,String type,String parentCode) ;
} }

Loading…
Cancel
Save