家族列表增加等级排序

This commit is contained in:
tianfeng 2025-12-29 20:05:18 +08:00
parent c841923919
commit fc92197004
4 changed files with 151 additions and 21 deletions

View File

@ -1,18 +1,17 @@
package com.red.circle.other.app.command.family;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.mybatis.entity.TimestampBaseEntity;
import com.red.circle.other.app.dto.clientobject.family.FamilyListCO;
import com.red.circle.other.app.dto.cmd.family.FamilyListCmd;
import com.red.circle.other.infra.database.rds.entity.family.FamilyBaseInfo;
import com.red.circle.other.infra.database.rds.dao.family.FamilyBaseInfoDAO;
import com.red.circle.other.infra.database.rds.dto.family.FamilyWithLevelDTO;
import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig;
import com.red.circle.other.infra.database.rds.service.family.FamilyBaseInfoService;
import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService;
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.text.StringUtils;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -20,7 +19,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* 家族列表查询.
@ -29,34 +27,41 @@ import org.springframework.util.StringUtils;
@RequiredArgsConstructor
public class FamilyListExe {
private final FamilyBaseInfoService familyBaseInfoService;
private final FamilyLevelConfigService familyLevelConfigService;
private final FamilyMemberInfoService familyMemberInfoService;
private final FamilyBaseInfoDAO familyBaseInfoDAO;
public PageResult<FamilyListCO> execute(FamilyListCmd cmd) {
Page<FamilyBaseInfo> page = new Page<>();
IPage<FamilyBaseInfo> baseInfoIPage = familyBaseInfoService.page(page,
Wrappers.<FamilyBaseInfo>lambdaQuery()
.eq(StringUtils.hasText(cmd.getFamilyAccount()), FamilyBaseInfo::getFamilyAccount, cmd.getFamilyAccount())
.orderByDesc(TimestampBaseEntity::getCreateTime));
Page<FamilyWithLevelDTO> page = new Page<>(cmd.getCurrent(), cmd.getSize());
Long familyAccount = null;
if (StringUtils.isNotBlank(cmd.getFamilyAccount())) {
try {
familyAccount = Long.parseLong(cmd.getFamilyAccount());
} catch (NumberFormatException e) {
return PageResult.newPageResult(0);
}
}
IPage<FamilyWithLevelDTO> familyPage = familyBaseInfoDAO.pageWithLevel(page, familyAccount);
PageResult<FamilyListCO> pageResult = new PageResult<>();
pageResult.setCurrent(page.getCurrent());
pageResult.setSize(page.getSize());
pageResult.setTotal(baseInfoIPage.getTotal());
pageResult.setCurrent(familyPage.getCurrent());
pageResult.setSize(familyPage.getSize());
pageResult.setTotal(familyPage.getTotal());
if (CollectionUtils.isEmpty(baseInfoIPage.getRecords())) {
return PageResult.newPageResult(0);
if (CollectionUtils.isEmpty(familyPage.getRecords())) {
return pageResult;
}
List<FamilyBaseInfo> familyList = baseInfoIPage.getRecords();
List<FamilyWithLevelDTO> familyList = familyPage.getRecords();
Set<Long> familyIds = familyList.stream()
.map(FamilyBaseInfo::getId)
.map(FamilyWithLevelDTO::getId)
.collect(Collectors.toSet());
Set<Long> levelIds = familyList.stream()
.map(FamilyBaseInfo::getFamilyLevelId)
.map(FamilyWithLevelDTO::getFamilyLevelId)
.collect(Collectors.toSet());
Map<Long, Long> memberCountMap = familyMemberInfoService.mapMemberCountByFamilyIds(familyIds);
@ -74,10 +79,13 @@ public class FamilyListExe {
.setFamilyIntro(family.getFamilyIntro())
.setFamilyNotice(family.getFamilyNotice())
.setCurrentMember(currentMember.intValue())
.setFamilyLevel(Optional.ofNullable(levelConfig.getLevelKey())
.setFamilyLevel(Optional.ofNullable(levelConfig)
.map(FamilyLevelConfig::getLevelKey)
.map(key -> Integer.parseInt(key.substring(6)))
.orElse(0))
.setMaxMember(levelConfig.getMaxMember());
.setMaxMember(Optional.ofNullable(levelConfig)
.map(FamilyLevelConfig::getMaxMember)
.orElse(0));
}).toList();
pageResult.setRecords(records);

View File

@ -1,8 +1,12 @@
package com.red.circle.other.infra.database.rds.dao.family;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.red.circle.framework.mybatis.dao.BaseDAO;
import com.red.circle.other.infra.database.rds.dto.family.FamilyWithLevelDTO;
import com.red.circle.other.infra.database.rds.entity.family.FamilyBaseInfo;
import org.apache.ibatis.annotations.Param;
/**
* <p>
@ -16,4 +20,13 @@ public interface FamilyBaseInfoDAO extends BaseDAO<FamilyBaseInfo> {
Long maxAccount();
/**
* 按等级经验分页查询家族列表
*
* @param page 分页参数
* @param familyAccount 家族账号可选
* @return 家族信息列表
*/
IPage<FamilyWithLevelDTO> pageWithLevel(Page<FamilyWithLevelDTO> page, @Param("familyAccount") Long familyAccount);
}

View File

@ -0,0 +1,83 @@
package com.red.circle.other.infra.database.rds.dto.family;
import lombok.Data;
import java.math.BigDecimal;
import java.sql.Timestamp;
/**
* 家族基础信息带等级经验DTO
*/
@Data
public class FamilyWithLevelDTO {
/**
* 家族ID
*/
private Long id;
/**
* 来源系统
*/
private String sysOrigin;
/**
* 家族账号
*/
private String familyAccount;
/**
* 家族头像
*/
private String familyAvatar;
/**
* 家族名称
*/
private String familyName;
/**
* 家族等级ID
*/
private Long familyLevelId;
/**
* 家族状态
*/
private String familyStatus;
/**
* 家族介绍
*/
private String familyIntro;
/**
* 家族公告
*/
private String familyNotice;
/**
* 创建时间
*/
private Timestamp createTime;
/**
* 创建用户
*/
private Long createUser;
/**
* 修改时间
*/
private Timestamp updateTime;
/**
* 修改用户
*/
private Long updateUser;
/**
* 家族经验值
*/
private BigDecimal exp;
}

View File

@ -8,4 +8,30 @@
FROM family_base_info
</select>
<select id="pageWithLevel" resultType="com.red.circle.other.infra.database.rds.dto.family.FamilyWithLevelDTO">
SELECT
fbi.id,
fbi.sys_origin,
fbi.family_account,
fbi.family_avatar,
fbi.family_name,
fbi.family_level_id,
fbi.family_status,
fbi.family_intro,
fbi.family_notice,
fbi.create_time,
fbi.create_user,
fbi.update_time,
fbi.update_user,
IFNULL(fle.exp, 0) AS exp
FROM family_base_info fbi
LEFT JOIN family_level_exp fle ON fbi.id = fle.family_id AND fbi.family_level_id = fle.family_level_id
<where>
<if test="familyAccount != null">
AND fbi.family_account = #{familyAccount}
</if>
</where>
ORDER BY IFNULL(fle.exp, 0) DESC, fbi.create_time DESC
</select>
</mapper>