feat:余额统计

This commit is contained in:
dzc committed 2025-07-09 17:05:22 +08:00
1 parent 2257a55a3e
commit b3b016c4dd
6 files changed
+105 -1

No files matched your search

@@ -0,0 +1,23 @@
package com.bsd.pjcloud.wallet.api.vo;
import lombok.Data;
@Data
public class WalletQbTotalVo {
/**
* 总余额
*/
private Integer total = 0;
/**
* 饭卡钱包余额
*/
private Integer eatTotal = 0;
/**
* 消费钱包余额
*/
private Integer payTotal = 0;
}
@@ -18,6 +18,7 @@ import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTopupActionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletQbTotalVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.service.WalletCodeUseService;
import com.bsd.pjcloud.wallet.service.WalletManageService;
@@ -201,6 +202,12 @@ public class WalletManageController {
return R.ok(walletManageService.scopePageList(page, dto, DataScope.of()));
}
@Operation(summary = "分页查询", description = "分页查询")
@PostMapping("/qb-total")
public R<WalletQbTotalVo> qbTotal(@RequestBody WalletManageBalanceDto dto) {
return R.ok(walletManageService.qbTotal(dto, DataScope.of()));
}
@Operation(summary = "钱包记录分页", description = "钱包记录分页")
@PostMapping("/page-join-qb")
public R<Page<WalletManageVo>> pageJoinQb(@ParameterObject Page page, @RequestBody WalletManageBalanceDto dto) {
@@ -167,4 +167,6 @@ public interface WalletManageMapper extends PjcloudBaseMapper<WalletManageEntity
Page<WalletManageVo> activeBalancePage(Page page, @Param("dto") WalletTopupActionDto dto, @Param("unactiveDayNumberStr") String unactiveDayNumberStr);
List<WalletManageVo> activeBalanceList(@Param("dto") WalletTopupActionDto dto, @Param("unactiveDayNumberStr") String unactiveDayNumberStr);
Integer selectTotalBalance(@Param("dto") WalletManageBalanceDto dto);
}
@@ -9,6 +9,7 @@ import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTopupActionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletQbTotalVo;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
@@ -68,6 +69,8 @@ public interface WalletManageService extends IService<WalletManageEntity> {
Page<WalletManageVo> scopeQbPage(Page page, WalletManageBalanceDto dto, DataScope dataScope);
WalletQbTotalVo qbTotal(WalletManageBalanceDto dto, DataScope dataScope);
/**
* 不活跃用户钱包
*/
@@ -40,6 +40,7 @@ import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletManageBalanceVo;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletQbTotalVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTypeMapper;
@@ -51,7 +52,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -59,6 +59,8 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* 钱包管理
@@ -306,6 +308,30 @@ public class WalletManageServiceImpl extends ServiceImpl<WalletManageMapper, Wal
return walletPage;
}
@Override
public WalletQbTotalVo qbTotal(WalletManageBalanceDto dto, DataScope dataScope) {
WalletQbTotalVo result = new WalletQbTotalVo();
// 查询钱包类表
List<WalletTypeEntity> walletTypeList = walletTypeService.list();
// 查询所有钱包类型的流水记录
for (WalletTypeEntity i : walletTypeList) {
WalletManageBalanceDto walletBalanceDto = BeanUtils.toBean(dto, WalletManageBalanceDto.class);
walletBalanceDto.setWalletTypeId(i.getId());
Integer total = baseMapper.selectTotalBalance(walletBalanceDto);
if (ObjectUtil.isEmpty(total)) total = 0;
if (ObjectUtil.equals(i.getUniqueCode(), WalletTypeEnum.EAT.getCode())) {
result.setEatTotal(total);
}
if (ObjectUtil.equals(i.getUniqueCode(), WalletTypeEnum.PAY.getCode())) {
result.setPayTotal(total);
}
}
result.setTotal(result.getEatTotal() + result.getPayTotal());
return result;
}
/**
* 不活跃用户钱包
*/
@@ -192,4 +192,47 @@
</if>
</where>
</select>
<select id="selectTotalBalance" resultType="java.lang.Integer">
SELECT
SUM(a.balance)
FROM wallet_transaction a
LEFT JOIN wallet_manage m on a.wallet_id = m.id
<where>
a.del_flag = 0
<if test="dto.walletRecordMonth != null">
AND a.create_time = (
SELECT MAX(sub.create_time)
FROM wallet_transaction sub
LEFT JOIN wallet_manage wallet on wallet.id = sub.wallet_id
WHERE sub.user_id = a.user_id
AND DATE_FORMAT(sub.create_time, '%Y-%m') &lt;= #{dto.walletRecordMonth}
<if test="dto.userId != null">
AND sub.user_id = #{dto.userId}
</if>
<if test="dto.userIds != null and dto.userIds.size() != 0">
and sub.user_id in
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.walletTypeId != null">
AND wallet.wallet_type_id = #{dto.walletTypeId}
</if>
)
</if>
<if test="dto.userId != null">
AND a.user_id = #{dto.userId}
</if>
<if test="dto.walletTypeId != null">
AND m.wallet_type_id = #{dto.walletTypeId}
</if>
<if test="dto.userIds != null and dto.userIds.size() != 0">
and a.user_id in
<foreach collection="dto.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
</select>
</mapper>