1. 增加用户族谱表
This commit is contained in:
2026-04-13 18:48:29 +08:00
parent 2e298448c9
commit db722f6aff
5 changed files with 14 additions and 24 deletions

View File

@@ -6,7 +6,6 @@ CREATE TABLE user_hierarchy
root_id int8 NULL, root_id int8 NULL,
level int4 NOT NULL, level int4 NOT NULL,
ancestors int8[] NOT NULL DEFAULT '{}'::int8[], ancestors int8[] NOT NULL DEFAULT '{}'::int8[],
is_whitelist int4 DEFAULT 0, -- 是否白名单
remarks text, -- 备注 remarks text, -- 备注
create_user int8, -- 创建人 create_user int8, -- 创建人
create_dept int8, -- 创建部门 create_dept int8, -- 创建部门

View File

@@ -8,7 +8,6 @@
<result column="pid" property="pid"/> <result column="pid" property="pid"/>
<result column="level" property="level"/> <result column="level" property="level"/>
<result column="ancestors" property="ancestors" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/> <result column="ancestors" property="ancestors" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/>
<result column="is_whitelist" property="isWhiteList"/>
<result column="remarks" property="remarks"/> <result column="remarks" property="remarks"/>
<result column="create_user" property="createUser"/> <result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/> <result column="create_dept" property="createDept"/>

View File

@@ -72,11 +72,6 @@ public class MarketUserHierarchyEntity extends BaseEntity {
@TableField(typeHandler = PgLongArrayToListTypeHandler.class) @TableField(typeHandler = PgLongArrayToListTypeHandler.class)
@Schema(description = "族谱父级ID数组(存储从根节点到父级的完整路径)") @Schema(description = "族谱父级ID数组(存储从根节点到父级的完整路径)")
private List<Long> ancestors; private List<Long> ancestors;
/**
* 是否白名单
*/
@Schema(description = "是否白名单")
private Integer isWhitelist;
/** /**
* 备注 * 备注
*/ */

View File

@@ -49,8 +49,6 @@ public interface IMarketUserHierarchyService extends BaseService<MarketUserHiera
void init(Long userId); void init(Long userId);
boolean isSameLineage(Long userId1, Long userId2); boolean isInDirectLineage(Long userId1, Long userId2);
boolean isTradingAllowed(Long userId1, Long userId2);
} }

View File

@@ -83,26 +83,25 @@ public class MarketUserHierarchyServiceImpl extends BaseServiceImpl<MarketUserHi
} }
@Override @Override
public boolean isSameLineage(Long userId1, Long userId2) { public boolean isInDirectLineage(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) {
if (Objects.isNull(userId1) || Objects.isNull(userId2)) { if (Objects.isNull(userId1) || Objects.isNull(userId2)) {
throw new ServiceException("参数错误"); throw new ServiceException("参数错误");
} }
if (Objects.equals(userId1, userId2)) {
return true;
}
MarketUserHierarchyEntity h1 = getById(userId1); MarketUserHierarchyEntity h1 = getById(userId1);
if (h1.getIsWhitelist() == 1) {
return true;
}
MarketUserHierarchyEntity h2 = getById(userId2); MarketUserHierarchyEntity h2 = getById(userId2);
if (h2.getIsWhitelist() == 1) { int level1 = h1.getLevel();
return true; 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());
} }
} }