refactor(权限点): 兼容处理适用单位和节点
This commit is contained in:
parent
7d5e63be73
commit
2919d720ac
@ -5,6 +5,7 @@ import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -122,14 +123,14 @@ public class PermissionPointDTO {
|
||||
|
||||
|
||||
/**
|
||||
* 适用单位类型-65535:所有 1:总包 2:建设单位 4:监理单位 8:劳务分包 16:专业分包
|
||||
* 适用单位类型-65535:所有 1:总包 2:建设单位 4:监理单位 8:劳务分包 16:专业分包 32-班组
|
||||
*/
|
||||
private Long fitOuTypeBit;
|
||||
private List<Long> fitOuTypeList;
|
||||
|
||||
/**
|
||||
* 适用节点类型 65535:所有 1:部门 2:班组 4:小组
|
||||
*/
|
||||
private Long fitOuNodeTypeBit;
|
||||
private List<Long> fitOuNodeTypeList;
|
||||
|
||||
/**
|
||||
* 所属应用
|
||||
@ -159,4 +160,19 @@ public class PermissionPointDTO {
|
||||
/** 业务编码 **/
|
||||
private String businessNo;
|
||||
|
||||
public Long mergeFitOuTypeBit() {
|
||||
if (this.fitOuTypeList == null || this.fitOuTypeList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return this.fitOuTypeList.stream().mapToLong(Long::longValue).sum();
|
||||
}
|
||||
|
||||
|
||||
public Long mergeFitOuNodeTypeBit() {
|
||||
if (this.fitOuNodeTypeList == null || this.fitOuNodeTypeList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return this.fitOuNodeTypeList.stream().mapToLong(Long::longValue).sum();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package cn.axzo.tyr.client.model.permission;
|
||||
|
||||
import cn.hutool.core.math.BitStatusUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -124,14 +126,14 @@ public class PermissionPointVO {
|
||||
|
||||
|
||||
/**
|
||||
* 适用单位类型-65535:所有 1:总包 2:建设单位 4:监理单位 8:劳务分包 16:专业分包
|
||||
* 适用单位类型-65535:所有 1:总包 2:建设单位 4:监理单位 8:劳务分包 16:专业分包 32-班组
|
||||
*/
|
||||
private Long fitOuTypeBit;
|
||||
private List<Long> fitOuTypeList;
|
||||
|
||||
/**
|
||||
* 适用节点类型 65535:所有 1:部门 2:班组 4:小组
|
||||
*/
|
||||
private Long fitOuNodeTypeBit;
|
||||
private List<Long> fitOuNodeTypeList;
|
||||
|
||||
/**
|
||||
* 所属应用
|
||||
@ -161,4 +163,39 @@ public class PermissionPointVO {
|
||||
/** 授权策略类型描述 **/
|
||||
private String delegatedTypeDesc;
|
||||
|
||||
public void applyFitOuTypeBit(long fitOuTypeBit) {
|
||||
//这个最值需要处理
|
||||
if (fitOuTypeBit > 63L) {
|
||||
fitOuTypeBit = 63L;
|
||||
}
|
||||
long mask = 1L;
|
||||
ArrayList<Long> list = new ArrayList<>();
|
||||
while (mask <= 32) {
|
||||
long bitValue = fitOuTypeBit & mask;
|
||||
if (bitValue != 0) {
|
||||
list.add(bitValue);
|
||||
}
|
||||
mask = mask << 1;
|
||||
}
|
||||
this.fitOuTypeList = list;
|
||||
}
|
||||
|
||||
public void applyFitOuNodeTypeBit(long fitOuNodeTypeBit) {
|
||||
//这个最值需要处理
|
||||
if (fitOuNodeTypeBit > 7L) {
|
||||
fitOuNodeTypeBit = 7L;
|
||||
}
|
||||
long mask = 1L;
|
||||
ArrayList<Long> list = new ArrayList<>();
|
||||
while (mask <= 32) {
|
||||
long bitValue = fitOuNodeTypeBit & mask;
|
||||
if (bitValue != 0) {
|
||||
list.add(bitValue);
|
||||
}
|
||||
mask = mask << 1;
|
||||
}
|
||||
this.fitOuNodeTypeList = list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -202,6 +202,8 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
||||
}
|
||||
PermissionPointVO vo = BeanMapper.copyBean(feature, PermissionPointVO.class);
|
||||
vo.setFeatureTypeDesc(FeatureType.apply(vo.getFeatureType()).getDesc());
|
||||
vo.applyFitOuTypeBit(feature.getFitOuTypeBit());
|
||||
vo.applyFitOuNodeTypeBit(feature.getFitOuNodeTypeBit());
|
||||
|
||||
//补充上级信息
|
||||
//最顶级二层
|
||||
@ -253,6 +255,8 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
||||
private PermissionPointDTO doUpdate(PermissionPointDTO dto) {
|
||||
SaasFeature feature = getAndCheck(dto.getId());
|
||||
SaasFeature saasFeature = BeanMapper.copyBean(dto, SaasFeature.class);
|
||||
saasFeature.setFitOuTypeBit(dto.mergeFitOuTypeBit());
|
||||
saasFeature.setFitOuNodeTypeBit(dto.mergeFitOuNodeTypeBit());
|
||||
//清理不可直接更新的数据
|
||||
saasFeature.setParentId(null);
|
||||
saasFeature.setPath(null);
|
||||
@ -276,6 +280,8 @@ public class PermissionPointServiceImpl implements PermissionPointService {
|
||||
|
||||
private PermissionPointDTO doInsert(PermissionPointDTO dto) {
|
||||
SaasFeature saasFeature = BeanMapper.copyBean(dto, SaasFeature.class);
|
||||
saasFeature.setFitOuTypeBit(dto.mergeFitOuTypeBit());
|
||||
saasFeature.setFitOuNodeTypeBit(dto.mergeFitOuNodeTypeBit());
|
||||
SaasFeature parent;
|
||||
if (dto.getParentId() == null || dto.getParentId() < 1) {
|
||||
parent = new SaasFeature();
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.axzo.tyr.server.permission;
|
||||
|
||||
import cn.axzo.tyr.client.model.permission.PermissionPointVO;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @author: ZhanSiHu
|
||||
* @date: 2023/9/13 18:43
|
||||
*/
|
||||
public class SimpleTest {
|
||||
|
||||
@Test
|
||||
public void testSplitBit() {
|
||||
|
||||
PermissionPointVO vo = new PermissionPointVO();
|
||||
vo.applyFitOuTypeBit(34L);
|
||||
System.out.println(vo.getFitOuTypeList());
|
||||
vo.applyFitOuTypeBit(65535L);
|
||||
System.out.println(vo.getFitOuTypeList());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user