1. 增加用户族谱表
This commit is contained in:
2026-04-13 18:28:21 +08:00
parent 8d9e64c776
commit 2e298448c9
9 changed files with 458 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity;
import org.springblade.modules.market.pojo.vo.MarketUserHierarchyVO;
import java.util.List;
/**
* 用户层级表 Mapper 接口
*
* @author BladeX
* @since 2026-04-13
*/
public interface MarketUserHierarchyMapper extends BaseMapper<MarketUserHierarchyEntity> {
/**
* 自定义分页
*
* @param page 分页参数
* @param hierarchy 查询参数
* @return List<HierarchyVO>
*/
List<MarketUserHierarchyVO> selectHierarchyPage(IPage page, MarketUserHierarchyVO hierarchy);
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.market.mapper.MarketUserHierarchyMapper">
<!-- 通用查询映射结果 -->
<resultMap id="hierarchyResultMap" type="org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity">
<result column="id" property="id"/>
<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"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
</resultMap>
<select id="selectHierarchyPage" resultMap="hierarchyResultMap">
select * from user_hierarchy where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,46 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity;
import java.io.Serial;
/**
* 用户层级表 数据传输对象实体类
*
* @author BladeX
* @since 2026-04-13
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MarketUserHierarchyDTO extends MarketUserHierarchyEntity {
@Serial
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,86 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.EqualsAndHashCode;
import org.springblade.common.handler.PgLongArrayToListTypeHandler;
import org.springblade.core.mp.base.BaseEntity;
import java.io.Serial;
import java.util.List;
/**
* 用户层级表 实体类
*
* @author BladeX
* @since 2026-04-13
*/
@Data
@TableName("user_hierarchy")
@Schema(description = "Hierarchy对象")
@EqualsAndHashCode(callSuper = true)
public class MarketUserHierarchyEntity extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 父节点
*/
private Long pid;
/**
* 根节点
*/
private Long rootId;
/**
* 用户层级
*/
@Schema(description = "用户层级")
private Integer level;
/**
* 族谱父级ID数组(存储从根节点到父级的完整路径)
*/
@TableField(typeHandler = PgLongArrayToListTypeHandler.class)
@Schema(description = "族谱父级ID数组(存储从根节点到父级的完整路径)")
private List<Long> ancestors;
/**
* 是否白名单
*/
@Schema(description = "是否白名单")
private Integer isWhitelist;
/**
* 备注
*/
@Schema(description = "备注")
private String remarks;
}

View File

@@ -0,0 +1,46 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity;
import java.io.Serial;
/**
* 用户层级表 视图实体类
*
* @author BladeX
* @since 2026-04-13
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MarketUserHierarchyVO extends MarketUserHierarchyEntity {
@Serial
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,56 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity;
import org.springblade.modules.market.pojo.vo.MarketUserHierarchyVO;
/**
* 用户层级表 服务类
*
* @author BladeX
* @since 2026-04-13
*/
public interface IMarketUserHierarchyService extends BaseService<MarketUserHierarchyEntity> {
/**
* 自定义分页
*
* @param page 分页参数
* @param hierarchy 查询参数
* @return IPage<HierarchyVO>
*/
IPage<MarketUserHierarchyVO> selectHierarchyPage(IPage<MarketUserHierarchyVO> page, MarketUserHierarchyVO hierarchy);
void init(Long userId);
boolean isSameLineage(Long userId1, Long userId2);
boolean isTradingAllowed(Long userId1, Long userId2);
}

View File

@@ -0,0 +1,108 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.service.impl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.modules.market.mapper.MarketUserHierarchyMapper;
import org.springblade.modules.market.pojo.entity.MarketUserHierarchyEntity;
import org.springblade.modules.market.pojo.vo.MarketUserHierarchyVO;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.market.service.IMarketUserHierarchyService;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.List;
import java.util.Objects;
/**
* 用户层级表 服务实现类
*
* @author BladeX
* @since 2026-04-13
*/
@Slf4j
@Service
@AllArgsConstructor
public class MarketUserHierarchyServiceImpl extends BaseServiceImpl<MarketUserHierarchyMapper, MarketUserHierarchyEntity> implements IMarketUserHierarchyService {
private IMarketInfoService marketInfoService;
@Override
public IPage<MarketUserHierarchyVO> selectHierarchyPage(IPage<MarketUserHierarchyVO> page, MarketUserHierarchyVO hierarchy) {
return page.setRecords(baseMapper.selectHierarchyPage(page, hierarchy));
}
@Override
public void init(Long userId) {
if (getById(userId) != null) {
return;
}
List<Long> ids = marketInfoService.selectAncestorIds(userId);
MarketUserHierarchyEntity hierarchy = new MarketUserHierarchyEntity();
hierarchy.setId(userId);
hierarchy.setRootId(userId);
hierarchy.setLevel(ids.size() + 1);
if (!ids.isEmpty()) {
hierarchy.setPid(ids.get(0));
hierarchy.setRootId(ids.get(ids.size() - 1));
hierarchy.setAncestors(ids);
}
try {
save(hierarchy);
} catch (DuplicateKeyException e) {
// 并发插入冲突,重新读取即可
log.warn("Concurrent init for user {}, ignored.", userId);
}
}
@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) {
if (Objects.isNull(userId1) || Objects.isNull(userId2)) {
throw new ServiceException("参数错误");
}
MarketUserHierarchyEntity h1 = getById(userId1);
if (h1.getIsWhitelist() == 1) {
return true;
}
MarketUserHierarchyEntity h2 = getById(userId2);
if (h2.getIsWhitelist() == 1) {
return true;
}
return h1.getRootId().equals(h2.getRootId());
}
}