From b8ba4ab2d8aa90a75c1e5a18e9cbf6e962b35419 Mon Sep 17 00:00:00 2001 From: yangsong Date: Wed, 27 Sep 2023 11:04:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E6=88=90featureCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/SubmitPermissionPointApplyVO.java | 31 +++++++++++++++++++ .../repository/entity/SaasFeatureApply.java | 4 +++ .../entity/SaasFeatureApplyDetail.java | 20 ++++++++---- .../SaasFeatureApplyDetailService.java | 5 ++- .../SaasFeatureApplyDetailServiceImpl.java | 27 ++++++++++++---- .../impl/SaasFeatureApplyServiceImpl.java | 31 ++++++++++++++++--- 6 files changed, 101 insertions(+), 17 deletions(-) diff --git a/tyr-api/src/main/java/cn/axzo/tyr/client/model/vo/SubmitPermissionPointApplyVO.java b/tyr-api/src/main/java/cn/axzo/tyr/client/model/vo/SubmitPermissionPointApplyVO.java index dec2c8dd..5c0f54e8 100644 --- a/tyr-api/src/main/java/cn/axzo/tyr/client/model/vo/SubmitPermissionPointApplyVO.java +++ b/tyr-api/src/main/java/cn/axzo/tyr/client/model/vo/SubmitPermissionPointApplyVO.java @@ -1,5 +1,6 @@ package cn.axzo.tyr.client.model.vo; +import java.util.ArrayList; import java.util.List; import javax.validation.Valid; @@ -7,6 +8,8 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import org.apache.commons.collections4.CollectionUtils; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -29,6 +32,16 @@ public class SubmitPermissionPointApplyVO { @NotNull private Long businessTypeId; + /** + * 5:运营人员,目前固定传5 + */ + private Integer identityType; + + /** + * 人员id + */ + private Long identityId; + @NotNull private Long createBy; @@ -45,6 +58,7 @@ public class SubmitPermissionPointApplyVO { @Data public static class SubmitPermissionPointInfoVO { + private Long permissionPointId; /** * 权限点名称 */ @@ -143,6 +157,15 @@ public class SubmitPermissionPointApplyVO { @Valid private List children; + public List flatPermissionPoint() { + List flatResult = new ArrayList<>(); + flatResult.add(this); + if (CollectionUtils.isNotEmpty(children)) { + children.forEach(c -> flatResult.addAll(c.flatPermissionPoint())); + } + return flatResult; + } + public Long mergeFitOuTypeBit() { if (this.fitOuTypeList == null || this.fitOuTypeList.isEmpty()) { return null; @@ -158,4 +181,12 @@ public class SubmitPermissionPointApplyVO { return this.fitOuNodeTypeList.stream().mapToLong(Long::longValue).sum(); } } + + public List flatPermissionPoint() { + List flatResult = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(permissionPoints)) { + permissionPoints.forEach(p -> flatResult.addAll(p.flatPermissionPoint())); + } + return flatResult; + } } \ No newline at end of file diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApply.java b/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApply.java index 5bbc54ba..776c8ff0 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApply.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApply.java @@ -33,4 +33,8 @@ public class SaasFeatureApply extends BaseEntity implements Se * 状态 0:初始化 1:权限配置 2:已发布dev 3:已发布test 4:已发布pre 5:已发布生产 6:产品已验收名称 */ private Integer status; + /** + * 创建人id + */ + private Long createBy; } diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApplyDetail.java b/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApplyDetail.java index 7d05c709..f49d20be 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApplyDetail.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/repository/entity/SaasFeatureApplyDetail.java @@ -38,10 +38,6 @@ public class SaasFeatureApplyDetail extends BaseEntity i */ private String icon; /** - * 菜单上级id - */ - private Long parentId; - /** * 链接地址 */ private String linkUrl; @@ -62,9 +58,9 @@ public class SaasFeatureApplyDetail extends BaseEntity i */ private String appIdentity; /** - * 路径 + * 权限点路径 */ - private String path; + private String featurePath; /** * 描述 */ @@ -81,6 +77,10 @@ public class SaasFeatureApplyDetail extends BaseEntity i * 类型 0.模块 1.菜单 2页面 3功能 */ private Integer featureType; + + private String fitOuTypeBit; + + private String fitOuNodeTypeBit; /** * 创建人id */ @@ -105,6 +105,14 @@ public class SaasFeatureApplyDetail extends BaseEntity i * 网关专属字段,是否授权 0:无需要授权 1:需要授权 */ private Integer needAuth; + /** + * 业务id + */ + private String businessNo; + /** + * 父级id + */ + private String parentBusinessNo; /** * 授权策略类型,允许为空 1-平台授权型 2-客户授权型 3-免授权型 */ diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasFeatureApplyDetailService.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasFeatureApplyDetailService.java index c2544834..e0a6e770 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasFeatureApplyDetailService.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasFeatureApplyDetailService.java @@ -1,5 +1,7 @@ package cn.axzo.tyr.server.service; +import java.util.List; + /** * SaasFeatureApplyDetailService * @@ -9,8 +11,9 @@ package cn.axzo.tyr.server.service; public interface SaasFeatureApplyDetailService { /** * 生成当前最大的featureCode + * 不支持并发 * @param terminal * @return */ - String getPermissionCode(String terminal); + List getPermissionCode(String terminal, int size); } \ No newline at end of file diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyDetailServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyDetailServiceImpl.java index 76ff964f..fe9203b0 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyDetailServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyDetailServiceImpl.java @@ -1,5 +1,6 @@ package cn.axzo.tyr.server.service.impl; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -9,6 +10,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import org.springframework.stereotype.Service; +import cn.axzo.basics.common.exception.ServiceException; import cn.axzo.tyr.server.repository.dao.SaasFeatureApplyDetailDao; import cn.axzo.tyr.server.repository.entity.SaasFeatureApplyDetail; import cn.axzo.tyr.server.service.SaasFeatureApplyDetailService; @@ -29,13 +31,16 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail private final SaasFeatureApplyDetailDao saasFeatureApplyDetailDao; @Override - public String getPermissionCode(String terminal) { + public List getPermissionCode(String terminal, int size) { + if (size <= 0 || size >= 99999) { + throw new ServiceException("参数错误"); + } List features = saasFeatureApplyDetailDao.lambdaQuery().eq(SaasFeatureApplyDetail::getTerminal, terminal) .ne(SaasFeatureApplyDetail::getFeatureCode, StringUtils.EMPTY) .list(); String start = "00001"; if (CollectionUtils.isEmpty(features)) { - return terminal.substring(3) + "_" + start; + return generateCode(terminal, 0, start.length(), size); } List featureCodeList = features.stream().map(e -> { int index = e.getFeatureCode().lastIndexOf("_"); @@ -45,13 +50,23 @@ public class SaasFeatureApplyDetailServiceImpl implements SaasFeatureApplyDetail return e.getFeatureCode().substring(index + 1); }).filter(s ->StringUtils.isNotBlank(s) && NumberUtils.isDigits(s)).collect(Collectors.toList()); if (CollectionUtils.isEmpty(featureCodeList)) { - return terminal.substring(3) + "_" + start; + return generateCode(terminal, 0, start.length(), size); } int maxLength = featureCodeList.stream().map(String::length).max(Integer::compareTo).get(); int maxCode = featureCodeList.stream().filter(e -> Objects.equals(maxLength, e.length())).map(Integer::parseInt).max(Integer::compareTo).get(); - if (String.valueOf(maxCode + 1).length() > maxLength) { - return terminal.substring(3) + "_" + StringUtils.leftPad(String.valueOf(1), maxLength + 1, "0"); + return generateCode(terminal, maxCode, maxLength, size); + } + + private List generateCode(String terminal, int maxCode, int maxLength, int size) { + List result = new ArrayList<>(); + for (int i = 1; i <= size; i++) { + if (String.valueOf(maxCode + i).length() > maxLength) { + // 这里使用 maxLength + 1,不支持批量生成太多 + result.add(terminal.substring(3) + "_" + StringUtils.leftPad(String.valueOf(1), maxLength + 1, "0")); + } else { + result.add(terminal.substring(3) + "_" + StringUtils.leftPad(String.valueOf(maxCode + i), maxLength, "0")); + } } - return terminal.substring(3) + "_" + StringUtils.leftPad(String.valueOf(maxCode + 1), maxLength, "0"); + return result; } } \ No newline at end of file diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyServiceImpl.java index 4fef6260..3383575d 100644 --- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyServiceImpl.java +++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasFeatureApplyServiceImpl.java @@ -1,6 +1,7 @@ package cn.axzo.tyr.server.service.impl; -import java.util.Date; +import java.util.*; +import java.util.stream.Collectors; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -10,6 +11,8 @@ import cn.axzo.tyr.client.model.vo.SubmitPermissionPointApplyVO; import cn.axzo.tyr.server.repository.dao.SaasFeatureApplyDao; import cn.axzo.tyr.server.repository.dao.SaasFeatureApplyDetailDao; import cn.axzo.tyr.server.repository.entity.SaasFeatureApply; +import cn.axzo.tyr.server.repository.entity.SaasFeatureApplyDetail; +import cn.axzo.tyr.server.service.SaasFeatureApplyDetailService; import cn.axzo.tyr.server.service.SaasFeatureApplyService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -26,6 +29,7 @@ import lombok.extern.slf4j.Slf4j; public class SaasFeatureApplyServiceImpl implements SaasFeatureApplyService { private final SaasFeatureApplyDao saasFeatureApplyDao; private final SaasFeatureApplyDetailDao saasFeatureApplyDetailDao; + private final SaasFeatureApplyDetailService saasFeatureApplyDetailService; @Override @@ -37,9 +41,28 @@ public class SaasFeatureApplyServiceImpl implements SaasFeatureApplyService { saasFeatureApply.setStatus(PermissionPointApplyStatus.INITIALIZED.getCode()); saasFeatureApply.setCreateAt(now); saasFeatureApply.setUpdateAt(now); + saasFeatureApply.setCreateBy(apply.getCreateBy()); saasFeatureApplyDao.save(saasFeatureApply); - //保存申请 - //保存申请明细 - return null; + List details = validAndBuildApplyDetail(apply, saasFeatureApply.getId(), now); + saasFeatureApplyDetailDao.saveBatch(details); + return saasFeatureApply.getId(); + } + + private List validAndBuildApplyDetail(SubmitPermissionPointApplyVO apply, Long applyId, Date now) { + List details = new ArrayList<>(); + List permissionPoints = apply.getPermissionPoints(); + List flatPoints = apply.flatPermissionPoint(); + Map> pointMap = flatPoints.stream() + .collect(Collectors.groupingBy(SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO::getTerminal)); + Map> featureCodes = new HashMap<>(); + pointMap.forEach((k, v) -> featureCodes.put(k, saasFeatureApplyDetailService.getPermissionCode(k, v.size()))); + for (SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO pp : permissionPoints) { + + } + return details; + } + + private void handleApplyDetail(String featurePath, SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO point, List details) { + } } \ No newline at end of file