Merge branch 'feature/REQ-1102' of axzsource.com:universal/infrastructure/backend/tyr into feature/REQ-1102
This commit is contained in:
commit
9063edc6ef
@ -10,7 +10,6 @@ import cn.axzo.tyr.client.model.product.ProductSearchListReq;
|
||||
import cn.axzo.tyr.client.model.product.ProductSearchPageReq;
|
||||
import cn.axzo.tyr.client.model.product.ProductUpdateReq;
|
||||
import cn.axzo.tyr.client.model.product.ProductVO;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package cn.axzo.tyr.client.feign;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.common.annotation.EnumValidator;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.client.model.dict.request.*;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
@ -37,13 +35,11 @@ public interface SaasBasicDictApi {
|
||||
/**
|
||||
* 获取字典树,需要单侧树时才传type
|
||||
*
|
||||
* @param type
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("api/dict/node-tree")
|
||||
ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(
|
||||
@EnumValidator(enumClass = DictTypeFiledEnum.class, message = "枚举类型错误")
|
||||
DictTypeFiledEnum type);
|
||||
ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(@RequestBody @Validated BasicDictQueryReq req);
|
||||
|
||||
/**
|
||||
* 通过type和code获取字典节点详情
|
||||
@ -57,7 +53,7 @@ public interface SaasBasicDictApi {
|
||||
/**
|
||||
* 添加字典
|
||||
*
|
||||
* @param req 其中name同一个父级节点,名称不能重复,codeMap全局唯一
|
||||
* @param req 其中name,code在同一个父级节点下不能重复
|
||||
* @return 节点id
|
||||
*/
|
||||
@PostMapping("api/dict/create")
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
package cn.axzo.tyr.client.model.dict.request;
|
||||
|
||||
import cn.axzo.tyr.client.common.annotation.EnumValidator;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
@ -15,22 +18,19 @@ import javax.validation.constraints.NotBlank;
|
||||
@Data
|
||||
public class BasicDictCreateReq {
|
||||
|
||||
/**
|
||||
* 工作台类型,"ent", "proj", "oms"
|
||||
*/
|
||||
@NotBlank(message = "工作台类型不能为空")
|
||||
private String workspaceType;
|
||||
|
||||
/**
|
||||
* 类型,"ouType", "terminal"
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 所属上级节点id
|
||||
*/
|
||||
@NotNull(message = "所属上级不能为空")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* type类型不能为空
|
||||
*/
|
||||
@NotNull(message = "type类型不能为空")
|
||||
@EnumValidator(enumClass = DictTypeFiledEnum.class, message = "枚举类型错误")
|
||||
private DictTypeFiledEnum type;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
|
||||
@ -54,4 +54,8 @@ public class BasicDictQueryReq {
|
||||
*/
|
||||
private Boolean status;
|
||||
|
||||
/**
|
||||
* 层级
|
||||
*/
|
||||
private Integer level;
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ package cn.axzo.tyr.server.controller.dict;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.feign.SaasBasicDictApi;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.client.model.dict.request.*;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
@ -33,8 +32,8 @@ public class SaasBasicDictController implements SaasBasicDictApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(DictTypeFiledEnum type) {
|
||||
return saasBasicDictService.getBasicDictNodeTree(type);
|
||||
public ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(BasicDictQueryReq req) {
|
||||
return saasBasicDictService.getBasicDictNodeTree(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package cn.axzo.tyr.server.job;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||
import cn.axzo.tyr.server.repository.entity.*;
|
||||
import cn.axzo.tyr.server.repository.service.*;
|
||||
@ -15,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -50,7 +49,6 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
|
||||
/**
|
||||
* 清洗OMS角色相关数据(注:先通过SQL检查和清除脏数据,要不然无法保证各个实体的关联关系)
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
* @throws Exception
|
||||
@ -62,12 +60,15 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
// 创建角色分组
|
||||
SaasRoleGroup roleGroup = new SaasRoleGroup();
|
||||
roleGroup.setWorkspaceTypeCode("6");
|
||||
roleGroup.setOuTypeCode("7");
|
||||
roleGroup.setName("管理员");
|
||||
roleGroup.setWorkspaceId(-1l);
|
||||
roleGroup.setOuId(-1l);
|
||||
roleGroupDao.save(roleGroup);
|
||||
// 查询OMS的角色 workspaceType=6 OMS的角色
|
||||
List<SaasRole> oldRole = roleDao.lambdaQuery()
|
||||
.eq(SaasRole::getWorkspaceType, 6)
|
||||
.notIn(SaasRole::getRoleType,"super_admin")
|
||||
.notIn(SaasRole::getRoleType, "super_admin")
|
||||
.list();
|
||||
// 重置老角色多余的字段
|
||||
oldRole.forEach(e -> {
|
||||
@ -99,26 +100,59 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
}
|
||||
List<SaasPermissionGroup> permissionGroup = saasPermissionGroupDao.lambdaQuery().in(BaseEntity::getId, pgroupRoleRelation.stream().map(SaasPgroupRoleRelation::getGroupId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(permissionGroup)) {
|
||||
// 删除角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> {
|
||||
pgroupRoleRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
return;
|
||||
}
|
||||
List<SaasPgroupPermissionRelation> pgroupPermissionRelation = pgroupPermissionRelationDao.lambdaQuery().in(SaasPgroupPermissionRelation::getGroupId, permissionGroup.stream().map(BaseEntity::getId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(pgroupPermissionRelation)) {
|
||||
// 如果没查到权限则表示当前权限集是无意义的,删掉
|
||||
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
|
||||
saasPermissionGroupDao.updateBatchById(permissionGroup);
|
||||
permissionGroup.forEach(e -> {
|
||||
// 只能通过这种方式删除 update不能删除
|
||||
saasPermissionGroupDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
// 删除角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
|
||||
pgroupRoleRelation.forEach(e -> {
|
||||
pgroupRoleRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
return;
|
||||
}
|
||||
List<SaasFeature> feature = featureDao.lambdaQuery().in(BaseEntity::getId, pgroupPermissionRelation.stream().map(SaasPgroupPermissionRelation::getFeatureId).collect(Collectors.toList())).list();
|
||||
if (CollectionUtils.isEmpty(feature)) {
|
||||
// 删除权限集权限关联关系
|
||||
pgroupPermissionRelation.forEach(e -> {
|
||||
// 只能通过这种方式删除 update不能删除
|
||||
pgroupPermissionRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
// 如果没查到权限则表示当前权限集是无意义的,删掉
|
||||
permissionGroup.forEach(e -> e.setIsDelete(e.getId()));
|
||||
saasPermissionGroupDao.updateBatchById(permissionGroup);
|
||||
permissionGroup.forEach(e -> {
|
||||
// 只能通过这种方式删除 update不能删除
|
||||
saasPermissionGroupDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
// 删除角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
|
||||
pgroupRoleRelation.forEach(e -> {
|
||||
pgroupRoleRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 创建新的权限集
|
||||
@ -148,15 +182,27 @@ public class OMSRoleJobHandler extends IJobHandler {
|
||||
pgroupPermissionRelationDao.save(saasPgroupPermissionRelation);
|
||||
});
|
||||
// 删除老的权限集权限关联关系
|
||||
pgroupPermissionRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupPermissionRelationDao.updateBatchById(pgroupPermissionRelation);
|
||||
pgroupPermissionRelation.forEach(e -> {
|
||||
pgroupPermissionRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
// 删除老的角色权限集关联关系
|
||||
pgroupRoleRelation.forEach(e -> e.setIsDelete(e.getId()));
|
||||
pgroupRoleRelationDao.updateBatchById(pgroupRoleRelation);
|
||||
pgroupRoleRelation.forEach(e -> {
|
||||
pgroupRoleRelationDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
});
|
||||
// 删除权限集
|
||||
deletePgroup.forEach(e -> e.setIsDelete(e.getId()));
|
||||
saasPermissionGroupDao.updateBatchById(deletePgroup);
|
||||
deletePgroup.forEach(e -> {
|
||||
saasPermissionGroupDao.lambdaUpdate()
|
||||
.eq(BaseEntity::getId, e.getId())
|
||||
.set(BaseEntity::getIsDelete, e.getId())
|
||||
.update();
|
||||
});
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ public class SaasBasicDictDao extends ServiceImpl<SaasBasicDictMapper, SaasBasic
|
||||
.eq(Objects.nonNull(req.getType()), SaasBasicDict::getType, Objects.nonNull(req.getType()) ? req.getType().getValue() : "")
|
||||
.in(Objects.nonNull(req.getCodes()), SaasBasicDict::getCode, req.getCodes())
|
||||
.eq(Objects.nonNull(req.getStatus()), SaasBasicDict::getStatus, Boolean.TRUE.equals(req.getStatus()) ? 1 : 0)
|
||||
.eq(Objects.nonNull(req.getLevel()), SaasBasicDict::getLevel, req.getLevel())
|
||||
.like(Objects.nonNull(req.getName()), SaasBasicDict::getName, req.getName());
|
||||
}
|
||||
List<SaasBasicDict> basicDictList = queryChainWrapper.orderByDesc(SaasBasicDict::getSort).list();
|
||||
|
||||
@ -9,6 +9,7 @@ import cn.axzo.tyr.server.repository.entity.SaasRoleGroup;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasPgroupRoleRelationMapper;
|
||||
import cn.axzo.tyr.server.repository.mapper.SaasRoleGroupMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -34,12 +35,14 @@ public class SaasRoleGroupDao extends ServiceImpl<SaasRoleGroupMapper, SaasRoleG
|
||||
condition.append(" FIND_IN_SET('" + value + "', ou_type_code) OR");
|
||||
}
|
||||
}
|
||||
return this.lambdaQuery()
|
||||
.in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId,req.getIds())
|
||||
.in(CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()),SaasRoleGroup::getWorkspaceTypeCode,req.getWorkspaceTypeCode())
|
||||
.last(CollectionUtils.isNotEmpty(req.getOuTypeCode())," AND (" + condition.substring(0, condition.length() - 2) + ")")
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||
.list();
|
||||
LambdaQueryChainWrapper<SaasRoleGroup> eq = this.lambdaQuery()
|
||||
.in(CollectionUtils.isNotEmpty(req.getIds()), BaseEntity::getId, req.getIds())
|
||||
.in(CollectionUtils.isNotEmpty(req.getWorkspaceTypeCode()), SaasRoleGroup::getWorkspaceTypeCode, req.getWorkspaceTypeCode())
|
||||
.eq(BaseEntity::getIsDelete, TableIsDeleteEnum.NORMAL.value);
|
||||
if(CollectionUtils.isNotEmpty(req.getOuTypeCode())){
|
||||
eq.last(" AND (" + condition.substring(0, condition.length() - 2) + ")");
|
||||
}
|
||||
return eq.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package cn.axzo.tyr.server.service;
|
||||
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.client.model.dict.request.*;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
@ -18,7 +17,7 @@ import java.util.List;
|
||||
public interface SaasBasicDictService {
|
||||
ApiResult<List<BasicDictNodeResp>> getBasicDictNodeList(BasicDictQueryReq req);
|
||||
|
||||
ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(DictTypeFiledEnum type);
|
||||
ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(BasicDictQueryReq req);
|
||||
ApiResult<BasicDictNodeResp> getById(Long id);
|
||||
|
||||
ApiResult<BasicDictNodeResp> getBasicDictNode(BasicDictNodeReq req);
|
||||
|
||||
@ -29,19 +29,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.axzo.tyr.server.common.constants.PermissionConstant.FEATURE_BIZ_NO_PREFIX;
|
||||
import static cn.axzo.tyr.server.common.constants.PermissionConstant.FEATURE_NO_PARENT;
|
||||
import static cn.axzo.tyr.server.common.constants.PermissionConstant.FEATURE_PATH_DELIMITER;
|
||||
import static cn.axzo.tyr.server.common.constants.PermissionConstant.FEATURE_TOP_PATH;
|
||||
import static cn.axzo.tyr.server.common.constants.PermissionConstant.*;
|
||||
|
||||
/**
|
||||
* 权限点服务实现
|
||||
@ -98,7 +90,7 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
||||
Map<String, List<PermissionPointTreeNode>> mappingNode = nodesResult.stream()
|
||||
.collect(Collectors.groupingBy(PermissionPointTreeNode::getTerminal));
|
||||
//构建workspace-terminal工作台层级
|
||||
List<BasicDictTreeResp> dictList = saasBasicDictService.getBasicDictNodeTree(DictTypeFiledEnum.TERMINAL).getData();
|
||||
List<BasicDictTreeResp> dictList = saasBasicDictService.getBasicDictNodeTree(BasicDictQueryReq.builder().type(DictTypeFiledEnum.TERMINAL).build()).getData();
|
||||
//遍历所有workspace和terminal-构建顶层两级
|
||||
List<PermissionPointTreeNode> result = new ArrayList<>();
|
||||
for (BasicDictTreeResp workspace : dictList) {
|
||||
|
||||
@ -8,6 +8,7 @@ import cn.axzo.tyr.client.model.product.ProductFeatureRelationVO;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasProductModuleFeatureRelation;
|
||||
import cn.axzo.tyr.server.repository.service.SaasProductModuleFeatureRelationDao;
|
||||
import cn.axzo.tyr.server.service.ProductFeatureRelationService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -44,7 +45,10 @@ public class ProductFeatureRelationServiceImpl implements ProductFeatureRelation
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ApiResult<Boolean> updateFeatureRelation(List<ProductFeatureRelationUpdateReq> req) {
|
||||
List<Long> productIds = req.stream().map(ProductFeatureRelationUpdateReq::getProductModuleId).distinct().collect(Collectors.toList());
|
||||
saasProductModuleFeatureRelationDao.removeByIds(productIds);
|
||||
if(!CollectionUtils.isEmpty(productIds)) {
|
||||
saasProductModuleFeatureRelationDao.remove(new LambdaQueryWrapper<SaasProductModuleFeatureRelation>()
|
||||
.in(SaasProductModuleFeatureRelation::getProductModuleId, productIds));
|
||||
}
|
||||
List<SaasProductModuleFeatureRelation> saveList = new ArrayList<>();
|
||||
req.forEach(i -> i.getFeatureIds().forEach(featureId -> {
|
||||
SaasProductModuleFeatureRelation relation = new SaasProductModuleFeatureRelation();
|
||||
|
||||
@ -1,14 +1,17 @@
|
||||
package cn.axzo.tyr.server.service.impl;
|
||||
|
||||
import cn.axzo.basics.common.BeanMapper;
|
||||
import cn.axzo.framework.domain.ServiceException;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.tyr.client.model.DictTypeFiledEnum;
|
||||
import cn.axzo.tyr.client.model.dict.request.*;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictNodeResp;
|
||||
import cn.axzo.tyr.client.model.dict.response.BasicDictTreeResp;
|
||||
import cn.axzo.tyr.server.repository.SaasBasicDictDao;
|
||||
import cn.axzo.tyr.server.repository.entity.SaasBasicDict;
|
||||
import cn.axzo.tyr.server.service.SaasBasicDictService;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -41,20 +44,13 @@ public class SaasBasicDictServiceImpl implements SaasBasicDictService {
|
||||
/**
|
||||
* 获取节点树
|
||||
*
|
||||
* @param type
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(DictTypeFiledEnum type) {
|
||||
public ApiResult<List<BasicDictTreeResp>> getBasicDictNodeTree(BasicDictQueryReq req) {
|
||||
// 获取所有节点
|
||||
List<BasicDictNodeResp> basicDictNodeList = saasBasicDictDao.getBasicDictNodeList(null);
|
||||
// 单侧树
|
||||
if (Objects.nonNull(type)) {
|
||||
List<BasicDictNodeResp> unilateralTreeNodeList = basicDictNodeList.stream()
|
||||
.filter(b -> b.getType().equals(type.getValue()) || b.getType().equals(DictTypeFiledEnum.WORKSPACE.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
return ApiResult.ok(constructDictTree(unilateralTreeNodeList));
|
||||
}
|
||||
List<BasicDictNodeResp> basicDictNodeList = saasBasicDictDao.getBasicDictNodeList(req);
|
||||
return ApiResult.ok(constructDictTree(basicDictNodeList));
|
||||
}
|
||||
|
||||
@ -79,6 +75,18 @@ public class SaasBasicDictServiceImpl implements SaasBasicDictService {
|
||||
root.add(treeNode);
|
||||
}
|
||||
});
|
||||
|
||||
// 若没有顶级节点(即一级节点),则需要查询一级节点
|
||||
if (CollectionUtil.isEmpty(root)) {
|
||||
List<Long> parentIds = nodeList.stream().map(BasicDictNodeResp::getParentId).distinct().collect(Collectors.toList());
|
||||
List<SaasBasicDict> parentDicts = saasBasicDictDao.listByIds(parentIds);
|
||||
parentDicts.forEach(s -> {
|
||||
BasicDictTreeResp parentTreeNode = BeanMapper.copyBean(s, BasicDictTreeResp.class, (s1, b) -> b.setStatus(s1.getStatus() == 1));
|
||||
root.add(parentTreeNode);
|
||||
map.put(parentTreeNode.getId(), parentTreeNode);
|
||||
});
|
||||
}
|
||||
|
||||
map.values().forEach(treeNode -> {
|
||||
BasicDictTreeResp parent = map.get(treeNode.getParentId());
|
||||
if (Objects.nonNull(parent)) {
|
||||
@ -103,8 +111,50 @@ public class SaasBasicDictServiceImpl implements SaasBasicDictService {
|
||||
return ApiResult.ok(saasBasicDictDao.getBasicDictNode(req));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字典节点
|
||||
*
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ApiResult<Long> create(BasicDictCreateReq req) {
|
||||
SaasBasicDict parent = saasBasicDictDao.getById(req.getParentId());
|
||||
if (Objects.isNull(parent)) {
|
||||
throw new ServiceException("不存在给定的上级节点");
|
||||
}
|
||||
// 获取所属父节点下所有同级节点,name和code在同级节点中不能重复
|
||||
List<BasicDictNodeResp> brotherNodeList = saasBasicDictDao.getBasicDictNodeList(
|
||||
BasicDictQueryReq.builder()
|
||||
.parentId(req.getParentId())
|
||||
.type(req.getType())
|
||||
.build());
|
||||
brotherNodeList.forEach(n -> {
|
||||
if (n.getName().equals(req.getName())) {
|
||||
throw new ServiceException("该节点下已存在名称为" + req.getName() + "的节点");
|
||||
}
|
||||
if (n.getCode().equals(req.getCode())) {
|
||||
throw new ServiceException("该节点下已存在code为" + req.getName() + "的节点");
|
||||
}
|
||||
});
|
||||
int count = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// 生成唯一的unique_code,若生成了与数据库中已存在uniqueCode
|
||||
String uniqueCode = RandomUtil.randomString(10);
|
||||
SaasBasicDict saasBasicDict = BeanMapper.copyBean(req, SaasBasicDict.class, (b, s) -> {
|
||||
s.setWorkspaceType(parent.getWorkspaceType());
|
||||
s.setType(b.getType().getValue());
|
||||
s.setUniqueCode(uniqueCode);
|
||||
s.setLevel(parent.getLevel() + 1);
|
||||
s.setPath(String.join(",", parent.getPath(), uniqueCode));
|
||||
});
|
||||
try {
|
||||
boolean save = saasBasicDictDao.save(saasBasicDict);
|
||||
} catch (MybatisPlusException e) {
|
||||
// if ()
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user