feat:
1. 增加用户族谱表
This commit is contained in:
@@ -6,7 +6,6 @@ CREATE TABLE user_hierarchy
|
||||
root_id int8 NULL,
|
||||
level int4 NOT NULL,
|
||||
ancestors int8[] NOT NULL DEFAULT '{}'::int8[],
|
||||
is_whitelist int4 DEFAULT 0, -- 是否白名单
|
||||
remarks text, -- 备注
|
||||
create_user int8, -- 创建人
|
||||
create_dept int8, -- 创建部门
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<result column="pid" property="pid"/>
|
||||
<result column="level" property="level"/>
|
||||
<result column="ancestors" property="ancestors" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/>
|
||||
<result column="is_whitelist" property="isWhiteList"/>
|
||||
<result column="remarks" property="remarks"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_dept" property="createDept"/>
|
||||
|
||||
@@ -72,11 +72,6 @@ public class MarketUserHierarchyEntity extends BaseEntity {
|
||||
@TableField(typeHandler = PgLongArrayToListTypeHandler.class)
|
||||
@Schema(description = "族谱父级ID数组(存储从根节点到父级的完整路径)")
|
||||
private List<Long> ancestors;
|
||||
/**
|
||||
* 是否白名单
|
||||
*/
|
||||
@Schema(description = "是否白名单")
|
||||
private Integer isWhitelist;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
||||
@@ -49,8 +49,6 @@ public interface IMarketUserHierarchyService extends BaseService<MarketUserHiera
|
||||
|
||||
void init(Long userId);
|
||||
|
||||
boolean isSameLineage(Long userId1, Long userId2);
|
||||
|
||||
boolean isTradingAllowed(Long userId1, Long userId2);
|
||||
boolean isInDirectLineage(Long userId1, Long userId2);
|
||||
|
||||
}
|
||||
|
||||
@@ -83,26 +83,25 @@ public class MarketUserHierarchyServiceImpl extends BaseServiceImpl<MarketUserHi
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameLineage(Long userId1, Long userId2) {
|
||||
MarketUserHierarchyEntity h1 = getById(userId1);
|
||||
MarketUserHierarchyEntity h2 = getById(userId2);
|
||||
return h1.getRootId().equals(h2.getRootId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradingAllowed(Long userId1, Long userId2) {
|
||||
public boolean isInDirectLineage(Long userId1, Long userId2) {
|
||||
if (Objects.isNull(userId1) || Objects.isNull(userId2)) {
|
||||
throw new ServiceException("参数错误");
|
||||
}
|
||||
if (Objects.equals(userId1, userId2)) {
|
||||
return true;
|
||||
}
|
||||
MarketUserHierarchyEntity h1 = getById(userId1);
|
||||
if (h1.getIsWhitelist() == 1) {
|
||||
return true;
|
||||
}
|
||||
MarketUserHierarchyEntity h2 = getById(userId2);
|
||||
if (h2.getIsWhitelist() == 1) {
|
||||
return true;
|
||||
int level1 = h1.getLevel();
|
||||
int level2 = h2.getLevel();
|
||||
|
||||
if (level1 == level2) {
|
||||
return false;
|
||||
}
|
||||
return h1.getRootId().equals(h2.getRootId());
|
||||
MarketUserHierarchyEntity source = level1 > level2 ? h1 : h2;
|
||||
MarketUserHierarchyEntity target = level1 > level2 ? h1 : h2;
|
||||
|
||||
return source.getAncestors().contains(target.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user