生成featureCode
This commit is contained in:
parent
092abb12a8
commit
b8ba4ab2d8
@ -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<SubmitPermissionPointInfoVO> children;
|
||||
|
||||
public List<SubmitPermissionPointInfoVO> flatPermissionPoint() {
|
||||
List<SubmitPermissionPointInfoVO> 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<SubmitPermissionPointInfoVO> flatPermissionPoint() {
|
||||
List<SubmitPermissionPointInfoVO> flatResult = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(permissionPoints)) {
|
||||
permissionPoints.forEach(p -> flatResult.addAll(p.flatPermissionPoint()));
|
||||
}
|
||||
return flatResult;
|
||||
}
|
||||
}
|
||||
@ -33,4 +33,8 @@ public class SaasFeatureApply extends BaseEntity<SaasFeatureApply> implements Se
|
||||
* 状态 0:初始化 1:权限配置 2:已发布dev 3:已发布test 4:已发布pre 5:已发布生产 6:产品已验收名称
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
private Long createBy;
|
||||
}
|
||||
|
||||
@ -38,10 +38,6 @@ public class SaasFeatureApplyDetail extends BaseEntity<SaasFeatureApplyDetail> i
|
||||
*/
|
||||
private String icon;
|
||||
/**
|
||||
* 菜单上级id
|
||||
*/
|
||||
private Long parentId;
|
||||
/**
|
||||
* 链接地址
|
||||
*/
|
||||
private String linkUrl;
|
||||
@ -62,9 +58,9 @@ public class SaasFeatureApplyDetail extends BaseEntity<SaasFeatureApplyDetail> i
|
||||
*/
|
||||
private String appIdentity;
|
||||
/**
|
||||
* 路径
|
||||
* 权限点路径
|
||||
*/
|
||||
private String path;
|
||||
private String featurePath;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@ -81,6 +77,10 @@ public class SaasFeatureApplyDetail extends BaseEntity<SaasFeatureApplyDetail> i
|
||||
* 类型 0.模块 1.菜单 2页面 3功能
|
||||
*/
|
||||
private Integer featureType;
|
||||
|
||||
private String fitOuTypeBit;
|
||||
|
||||
private String fitOuNodeTypeBit;
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
@ -105,6 +105,14 @@ public class SaasFeatureApplyDetail extends BaseEntity<SaasFeatureApplyDetail> i
|
||||
* 网关专属字段,是否授权 0:无需要授权 1:需要授权
|
||||
*/
|
||||
private Integer needAuth;
|
||||
/**
|
||||
* 业务id
|
||||
*/
|
||||
private String businessNo;
|
||||
/**
|
||||
* 父级id
|
||||
*/
|
||||
private String parentBusinessNo;
|
||||
/**
|
||||
* 授权策略类型,允许为空 1-平台授权型 2-客户授权型 3-免授权型
|
||||
*/
|
||||
|
||||
@ -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<String> getPermissionCode(String terminal, int size);
|
||||
}
|
||||
@ -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<String> getPermissionCode(String terminal, int size) {
|
||||
if (size <= 0 || size >= 99999) {
|
||||
throw new ServiceException("参数错误");
|
||||
}
|
||||
List<SaasFeatureApplyDetail> 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<String> 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<String> generateCode(String terminal, int maxCode, int maxLength, int size) {
|
||||
List<String> 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;
|
||||
}
|
||||
}
|
||||
@ -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<SaasFeatureApplyDetail> details = validAndBuildApplyDetail(apply, saasFeatureApply.getId(), now);
|
||||
saasFeatureApplyDetailDao.saveBatch(details);
|
||||
return saasFeatureApply.getId();
|
||||
}
|
||||
|
||||
private List<SaasFeatureApplyDetail> validAndBuildApplyDetail(SubmitPermissionPointApplyVO apply, Long applyId, Date now) {
|
||||
List<SaasFeatureApplyDetail> details = new ArrayList<>();
|
||||
List<SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO> permissionPoints = apply.getPermissionPoints();
|
||||
List<SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO> flatPoints = apply.flatPermissionPoint();
|
||||
Map<String, List<SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO>> pointMap = flatPoints.stream()
|
||||
.collect(Collectors.groupingBy(SubmitPermissionPointApplyVO.SubmitPermissionPointInfoVO::getTerminal));
|
||||
Map<String, List<String>> 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<SaasFeatureApplyDetail> details) {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user