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

main
whb 7 months ago
parent 3f6c283e9a
commit 11117575b8

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

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

@ -1,12 +1,17 @@
package com.gccloud.dataroom.core.module.basic.service;
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.common.service.ISuperService;
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.Caffeine;
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.Set;
@ -19,8 +24,11 @@ import java.util.stream.Collectors;
* @version 1.0
* @date 2022/8/8 15:11
*/
public interface IBasePageService extends ISuperService<PageEntity> {
/**
*
*/
@ -69,12 +77,18 @@ public interface IBasePageService extends ISuperService<PageEntity> {
* @return
*/
default boolean checkNameRepeat(PageEntity entity) {
AssertUtils.isTrue(StringUtils.isNotBlank(entity.getName()), "名称不能为空");
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(PageEntity::getId);
queryWrapper.eq(StringUtils.isNotBlank(entity.getAppCode()), PageEntity::getAppCode, entity.getAppCode())
.eq(PageEntity::getName, entity.getName())
.eq(PageEntity::getType, entity.getType())
//不等于
.ne(StringUtils.isNotBlank(entity.getId()), PageEntity::getId, entity.getId());
return getBaseMapper().selectList(queryWrapper).size() > 0;
}

@ -1,6 +1,7 @@
package com.gccloud.dataroom.core.module.biz.component.service.impl;
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;
@ -11,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@ -40,7 +42,9 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
@Override
public boolean verifyDataPermission(HttpServletRequest request, String pageCode) {
return false;
//todo 校验userId是否正确
return true;
}
@ -50,11 +54,12 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
*/
@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<>();
// newQueryWrapper.eq()
//
LambdaQueryWrapper<BizComponentUser> queryWrapper = new LambdaQueryWrapper<>();
//用户ID
@ -66,12 +71,23 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
//根据创建时间排序
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<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<>();
@ -84,11 +100,16 @@ public class PermissionServiceImpl implements IDataRoomPermissionService {
String newCode = bigScreenPageService.copy(bigScreenPage);
BizComponentUser bizComponentUser = new BizComponentUser();
bizComponentUser.setType("bigScreen");
if (!StringUtils.hasText(userId)){
//throw new EnumConstantNotPresentException(HttpServletRequest.BASIC_AUTH,"userId不能为空");
throw new GlobalException("userId不能为空");
}
bizComponentUser.setUserId(userId);
bizComponentUser.setCode(newCode);
userDao.insert(bizComponentUser);
codeList.add(newCode);
}
}
return codeList;

@ -1,9 +1,12 @@
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.constant.DataRoomConst;
import com.gccloud.dataroom.core.module.basic.entity.PageEntity;
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.DataRoomSearchDTO;
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.ApiOperation;
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.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author hongyang
@ -72,6 +77,10 @@ public class DataRoomPageController {
@GetMapping("/page")
@ApiOperation(value = "大屏/组件分页列表", position = 10, produces = MediaType.APPLICATION_JSON_VALUE)
public MixinsResp<PageVO<PageEntity>> page(DataRoomSearchDTO searchDTO) {
if (!StringUtils.hasText(searchDTO.getUserId()))
{
throw new GlobalException("userId不能为空");
}
PageVO<PageEntity> page = bigScreenPageService.getByCategory(searchDTO);
MixinsResp<PageVO<PageEntity>> resp = new MixinsResp<PageVO<PageEntity>>().setData(page);
@ -185,11 +194,61 @@ public class DataRoomPageController {
return R.success(bgList);
}
@Autowired
private DataRoomBizUserDao userDao;
@ApiPermission
@PostMapping("/name/repeat")
@ApiOperation(value = "大屏/组件名称是否重复", position = 60, produces = MediaType.APPLICATION_JSON_VALUE)
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.common.vo.PageVO;
import java.util.List;
/**
* @author hongyang
* @version 1.0
@ -67,4 +69,5 @@ public interface IDataRoomPageService extends IBasePageService {
*/
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.tomcat.util.http.fileupload.FileItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -79,6 +80,10 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
@Autowired
private DataRoomBizUserDao userDao;
@Value("${gc.starter.file.img}")
private String path;
@Override
public PageEntity getByCode(String code) {
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()))
{
throw new RuntimeException("userId不能为空");
throw new GlobalException("userId不能为空");
}
String code = null;
@ -127,6 +132,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
BizComponentUser bizComponentUser = new BizComponentUser();
bizComponentUser.setUserId(bigScreenPageDTO.getUserId());
bizComponentUser.setCode(code);
bizComponentUser.setParentCode(bigScreenPageDTO.getParentCode());
bizComponentUser.setType(bigScreenPageDTO.getType());
userDao.insert(bizComponentUser);
@ -289,10 +295,12 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
// }
@Override
@Transactional(rollbackFor = Exception.class)
public PageVO<PageEntity> getByCategory(DataRoomSearchDTO searchDTO) {
if (StringUtils.isBlank(searchDTO.getType())) {
throw new GlobalException("类型不能为空");
}
//只查询当前用户的code
// 使用分割type
List<String> types = Lists.newArrayList(searchDTO.getType().split(","));
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -310,15 +318,13 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
return pageVO;
}
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()) {
PageVO<PageEntity> pageVO = new PageVO<>();
pageVO.setList(Lists.newArrayList());
return pageVO;
}
LambdaQueryWrapper<PageEntity> reQueryWrapper = new LambdaQueryWrapper<>();
if (idEntityList.size() == filterByPermission.size()) {
// 说明没有过滤掉任何一个, 按照原来的条件查询
@ -357,13 +363,14 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
}
PageEntity bigScreenEntity = BeanConvertUtils.convert(bigScreenPageDTO, PageEntity.class);
bigScreenEntity.setConfig(bigScreenPageDTO);
AssertUtils.isTrue(!checkNameRepeat(bigScreenEntity), "名称重复");
AssertUtils.isTrue(!checkNameRepeat(bigScreenEntity), "名称重复");
AssertUtils.isTrue(!checkCodeRepeat(bigScreenEntity), "编码重复");
this.updateById(bigScreenEntity);
PAGE_ENTITY_CACHE.invalidate(bigScreenEntity.getCode());
}
// public static final String COPY_SUFFIX = "-副本";
public static final String COPY_SUFFIX = "-副本";
@Override
@ -429,6 +436,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
if (StringUtils.isBlank(copyUrl)) {
screenEntity.setCoverPicture(null);
} else {
//screenEntity.setCoverPicture(path+File.separator+copyUrl);
screenEntity.setCoverPicture(copyUrl);
}
this.save(screenEntity);
@ -441,10 +449,30 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
LambdaQueryWrapper<PageEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PageEntity::getCode, code);
this.remove(queryWrapper);
LambdaQueryWrapper<BizComponentUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
//用户ID
userLambdaQueryWrapper.eq(BizComponentUser::getCode,code);
userDao.delete(userLambdaQueryWrapper);
PAGE_ENTITY_CACHE.invalidate(code);
// 调用拓展接口
dataRoomExtendClient.deleteByCode(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;
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.entity.TypeEntity;
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.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author hongyang
@ -40,7 +48,7 @@ public class TypeController {
public R<List<TypeVO>> list(String type,String userId) {
if (!StringUtils.hasText(userId))
{
throw new RuntimeException("userId不能空");
throw new GlobalException("userId不能为空");
}
List<TypeEntity> entityList = typeService.listByType(type,userId);
@ -74,11 +82,57 @@ public class TypeController {
return R.success();
}
@Autowired
private DataRoomBizUserDao userDao;
@Resource
private IDataRoomPageService bigScreenPageService;
@PostMapping("/nameRepeat")
@ApiOperation(value = "分类名称重复校验", position = 40, produces = MediaType.APPLICATION_JSON_VALUE)
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.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.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.dto.TypeDTO;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
@ -31,9 +34,17 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
@Autowired
private DataRoomBizUserDao userDao;
@Autowired
private IDataRoomPageService service;
@Override
public String add(TypeDTO typeDTO) {
if (!org.springframework.util.StringUtils.hasText(typeDTO.getUserId()))
{
throw new GlobalException("userId不能为空");
}
TypeEntity entity = BeanConvertUtils.convert(typeDTO, TypeEntity.class);
String code = null;
if (StringUtils.isBlank(entity.getCode())) {
@ -47,9 +58,9 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
entity.setCode(CodeGenerateUtils.generate(typeDTO.getType()));
}
}
if (this.checkNameRepeat(null, typeDTO.getType(), entity.getName())) {
throw new GlobalException("分组名称已存在");
}
// if (this.checkNameRepeat(null, typeDTO.getType(), entity.getName())) {
// throw new GlobalException("分组名称已存在");
// }
this.save(entity);
@ -78,19 +89,36 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
}
TypeEntity byId = this.getById(id);
this.removeById(id);
//根据ID查询code 和type,然后删除
String type = byId.getType();
String code = byId.getCode();
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);
this.removeById(id);
}
@Override
@ -105,7 +133,10 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
userLambdaQueryWrapper.eq(BizComponentUser::getType,type);
List<BizComponentUser> bizComponentUserList = userDao.selectList(userLambdaQueryWrapper);
List<String> codeList = bizComponentUserList.stream().map(code -> code.getCode()).collect(Collectors.toList());
if (CollectionUtils.isEmpty(codeList))
{
return Lists.newArrayList();
}
LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>();
@ -129,11 +160,17 @@ public class TypeServiceImpl extends ServiceImpl<DataRoomTypeDao, TypeEntity> im
@Override
public boolean checkNameRepeat(String id, String type, String name) {
LambdaQueryWrapper<TypeEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(TypeEntity::getId);
queryWrapper.eq(TypeEntity::getName, name);
queryWrapper.eq(TypeEntity::getType, type);
queryWrapper.ne(StringUtils.isNotBlank(id), TypeEntity::getId, id);
return this.list(queryWrapper).size() > 0;
}
}

@ -45,9 +45,9 @@ public class DataRoomPermissionClient {
* @param allCode 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) {
return permissionService.filterByPermission(allCode,userId,type);
return permissionService.filterByPermission(allCode,userId,type,parentCode);
}
return allCode;
}

@ -24,6 +24,6 @@ public interface IDataRoomPermissionService {
* @param allCode 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