feat:批量充值统计

This commit is contained in:
dzc committed 2025-01-13 11:00:47 +08:00
1 parent d9e8663468
commit d6d36d689f
19 files changed
+460 -22

No files matched your search

@@ -0,0 +1,17 @@
package com.bsd.pjcloud.wallet.api.vo.recharge;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import java.util.List;
@Data
public class WalletRechargeApplyCompareAceVo {
private Page<WalletRechargeApplyCompareVo> page;
private List<String> tableList;
private List<String> tableListStr;
}
@@ -0,0 +1,61 @@
package com.bsd.pjcloud.wallet.api.vo.recharge;
import java.util.HashMap;
public class WalletRechargeApplyCompareVo extends HashMap<String, Object> {
/**
* 用户id
*/
private Long userId;
/**
* 用户昵称
*/
private String username;
/**
* 用户头像
*/
private String userAvatar;
/**
* 用户手机号
*/
private String userMobile;
public void setUserId(Long userId) {
this.userId = userId;
this.put("userId", userId);
}
public Long getUserId() {
return (Long) this.get("userId");
}
public void setUsername(String username) {
this.username = username;
this.put("username", username);
}
public String getUsername() {
return (String) this.get("username");
}
public void setUserAvatar(String userAvatar) {
this.userAvatar = userAvatar;
this.put("userAvatar", userAvatar);
}
public String getUserAvatar() {
return (String) this.get("userAvatar");
}
public String getUserMobile() {
return (String) this.get("userMobile");
}
public void setUserMobile(String userMobile) {
this.userMobile = userMobile;
this.put("userMobile", userMobile);
}
}
@@ -0,0 +1,27 @@
package com.bsd.pjcloud.wallet.api.vo.recharge;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class WalletRechargeApplySelectCompareVo {
@Schema(description = "用户id")
private Long userId;
@Schema(description = "用户名")
private String username;
@Schema(description = "用户头像")
private String userAvatar;
@Schema(description = "当前月的金额")
private Integer price;
@Schema(description = "总金额(加上倒入)")
private Integer totalPrice;
@Schema(description = "充值月", requiredMode = Schema.RequiredMode.REQUIRED)
private String monthTimeStr;
}
@@ -1,9 +1,17 @@
package com.bsd.pjcloud.wallet.api.vo.recharge;
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import lombok.Data;
@Data
public class WalletRechargeImportVo extends WalletRechargeImportEntity {
public class WalletRechargeImportVo extends WalletRechargeImportEntity implements BaseUserInterface {
/**
* 用户相关
*/
private String username;
private String userMobile;
private String userAvatar;
}
@@ -1,4 +1,4 @@
package com.bsd.pjcloud.wallet.api.vo;
package com.bsd.pjcloud.wallet.api.vo.transaction;
import com.bsd.pjcloud.admin.api.vo.base.BaseDeptInterface;
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
@@ -3,7 +3,6 @@ package com.bsd.pjcloud.wallet.controller;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
@@ -9,13 +9,12 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.excel.annotation.RequestExcel;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.common.security.service.PjcloudUser;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.flow.task.dto.ProcessNodeRecordAssignUserParamDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyService;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyComposeService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -37,6 +36,7 @@ import java.util.List;
public class WalletRechargeApplyController {
private final WalletRechargeApplyService walletRechargeApplyService;
private final WalletRechargeApplyComposeService walletTransactionComposeService;
/* ************************************* start callback start ************************************* */
@Inner(value = false)
@@ -46,6 +46,12 @@ public class WalletRechargeApplyController {
}
/* ************************************* start callback start ************************************* */
@GetMapping("/compare-page-join")
@Operation(summary = "批量充值/扣款记录")
public R comparePageJoin(@ParameterObject Page page, @ParameterObject WalletRechargeApplyDto dto) {
return R.ok(walletTransactionComposeService.pageJoin(page, dto));
}
@Operation(summary = "提交申请", description = "提交申请")
@SysLog("提交申请")
@GetMapping("/apply")
@@ -9,10 +9,8 @@ import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.MchManageDto;
import com.bsd.pjcloud.wallet.api.entity.MchManageEntity;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@@ -10,10 +10,13 @@ import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Objects;
@Mapper
@@ -57,4 +60,8 @@ public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransac
list.setRecords(BeanUtils.toBean(list.getRecords(), WalletTransactionVo.class));
return list;
}
Integer getTransactionPriceCount(@Param("month") String importTimeStr, @Param("walletId") Long walletId, @Param("bizType") String bizType);
List<WalletRechargeApplySelectCompareVo> selectCompare(@Param("bizType") String bizType, @Param("dateTime") String monthTimeStr, @Param("userIdList") List<Long> userIdList);
}
@@ -1,11 +1,18 @@
package com.bsd.pjcloud.wallet.mapper.recharge;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WalletRechargeImportMapper extends PjcloudBaseMapper<WalletRechargeImportEntity> {
default Page<WalletRechargeImportVo> pageJoin(Page page, WalletRechargeImportDto dto) {
MPJLambdaWrapper<WalletRechargeImportEntity> wrapper = new MPJLambdaWrapper<WalletRechargeImportEntity>();
return selectJoinPage(page, WalletRechargeImportVo.class, wrapper);
}
}
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyCompareAceVo;
public interface WalletRechargeApplyComposeService {
WalletRechargeApplyCompareAceVo pageJoin(Page page, WalletRechargeApplyDto dto);
}
@@ -44,4 +44,6 @@ public interface WalletRechargeApplyService extends IService<WalletRechargeApply
* 审批回调
*/
void applyCallback(ProcessNodeRecordAssignUserParamDto dto);
void updateBeforePrice(WalletRechargeApplyEntity detail);
}
@@ -1,8 +1,14 @@
package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
public interface WalletRechargeImportService extends IService<WalletRechargeImportEntity> {
Page<WalletRechargeImportVo> pageJoin(Page page, WalletRechargeImportDto dto);
}
@@ -1,13 +1,11 @@
package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
public interface WalletTransactionService extends IService<WalletTransactionEntity> {
@@ -14,9 +14,6 @@ import com.bsd.pjcloud.common.core.constant.CacheConstants;
import com.bsd.pjcloud.common.core.exception.CheckedException;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
import com.bsd.pjcloud.hard.api.feign.RemoteHardOrderService;
import com.bsd.pjcloud.hard.api.utils.HardUtil;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
@@ -25,18 +22,15 @@ import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTypeMapper;
import com.bsd.pjcloud.wallet.service.WalletManageService;
import com.bsd.pjcloud.wallet.service.WalletTransactionService;
import com.bsd.pjcloud.wallet.service.WalletTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -0,0 +1,200 @@
package com.bsd.pjcloud.wallet.service.impl.recharge;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyCompareAceVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyCompareVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyComposeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class WalletRechargeApplyComposeServiceImpl implements WalletRechargeApplyComposeService {
private final WalletRechargeImportServiceImpl rechargeImportService;
private final WalletRechargeApplyServiceImpl rechargeApplyService;
private final WalletTransactionMapper walletTransactionMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public WalletRechargeApplyCompareAceVo pageJoin(Page page, WalletRechargeApplyDto dto) {
if (ObjectUtil.isEmpty(dto.getBizType())) dto.setBizType(WalletBizEnum.BATCH.getCode());
WalletRechargeApplyCompareAceVo result = new WalletRechargeApplyCompareAceVo();
WalletRechargeApplyEntity topUpApplyDetail = rechargeApplyService.getById(dto.getId());
// 上个月
LocalDate prentMonthDateTime = topUpApplyDetail.getImportTime().minusMonths(1);
String prentMonthDateTimeStr = LocalDateTimeUtil.format(prentMonthDateTime, DatePattern.NORM_MONTH_PATTERN);
if (ObjectUtil.isEmpty(topUpApplyDetail)) return result;
if (ObjectUtil.isEmpty(topUpApplyDetail.getImportTime())) return result;
rechargeApplyService.updateBeforePrice(topUpApplyDetail);
Page<WalletRechargeApplyCompareVo> resultVo = new Page<>();
List<WalletRechargeApplyCompareVo> resultList = new ArrayList<>();
// 刚刚倒入的数据
String monthTimeStr = LocalDateTimeUtil.format(topUpApplyDetail.getImportTime(), DatePattern.NORM_MONTH_PATTERN);
WalletRechargeImportDto importDto = new WalletRechargeImportDto();
IPage<WalletRechargeImportVo> userPage = rechargeImportService.pageJoin(page, importDto);
List<WalletRechargeImportVo> userList = userPage.getRecords();
resultVo.setTotal(userPage.getTotal());
List<Long> userIdList = userList.stream().map(WalletRechargeImportEntity::getUserId).collect(Collectors.toList());
Map<String, List<WalletRechargeApplySelectCompareVo>> compareMonthMap = new LinkedHashMap<>();
// 本月
List<WalletRechargeApplySelectCompareVo> monthList = walletTransactionMapper.selectCompare(dto.getBizType(), monthTimeStr, userIdList);
List<WalletRechargeApplySelectCompareVo> currentMonthList = new ArrayList<>();
for (WalletRechargeImportVo v : userList) {
WalletRechargeApplySelectCompareVo item = new WalletRechargeApplySelectCompareVo();
item.setUserId(v.getUserId());
List<WalletRechargeApplySelectCompareVo> targetList = monthList.stream().filter(i -> ObjectUtil.equals(i.getUserId(), v.getUserId())).toList();
if (ObjectUtil.isNotEmpty(targetList)) {
WalletRechargeApplySelectCompareVo target = targetList.stream().findFirst().get();
if (ObjectUtil.isNotEmpty(target)) {
item.setPrice(v.getPrice());
Integer beforePrice = ObjectUtil.isEmpty(v.getBeforePrice()) ? 0 : v.getBeforePrice();
item.setTotalPrice(v.getPrice() + beforePrice);
}
}
if (ObjectUtil.isAllEmpty(item.getPrice(), item.getTotalPrice())) {
item.setPrice(v.getPrice());
item.setTotalPrice(v.getPrice());
}
currentMonthList.add(item);
}
compareMonthMap.put(monthTimeStr, currentMonthList);
// 比较月(上个月)
List<String> compareMonths = Arrays.asList(prentMonthDateTimeStr);
compareMonths.forEach(v -> {
List<WalletRechargeApplySelectCompareVo> selectList = walletTransactionMapper.selectCompare(dto.getBizType(), v, userIdList);
selectList.forEach(j -> {
j.setMonthTimeStr(v);
WalletRechargeImportVo target = userList.stream().filter(i -> ObjectUtil.equals(i.getUserId(), j.getUserId())).findFirst().get();
if (ObjectUtil.isNotEmpty(target) && ObjectUtil.isNotEmpty(target.getPrice())) {
j.setTotalPrice(j.getPrice() + target.getPrice());
} else {
j.setTotalPrice(j.getPrice());
}
});
compareMonthMap.put(v, selectList);
});
// 合并
List<String> merge = new ArrayList<>(compareMonths);
merge.add(merge.size(), monthTimeStr);
for (int i = 0; i < userList.size(); i++) {
WalletRechargeImportVo targetI = userList.get(i);
WalletRechargeApplyCompareVo item = new WalletRechargeApplyCompareVo();
item.setUserId(targetI.getUserId());
item.setUsername(targetI.getUsername());
item.setUserAvatar(targetI.getUserAvatar());
item.setUserMobile(targetI.getUserMobile());
for (int j = 0; j < merge.size(); j++) {
List<WalletRechargeApplySelectCompareVo> targetIList = compareMonthMap.get(merge.get(j));
List<WalletRechargeApplySelectCompareVo> prenIList = null;
if (j != 0) {
prenIList = compareMonthMap.get(merge.get(j - 1));
}
getItem(targetI, targetIList, prenIList, merge.get(j), item);
}
resultList.add(item);
}
merge.add("currentImport");
String currentImportKey = "currentImport";
for (WalletRechargeApplyCompareVo v : resultList) {
v.put(currentImportKey + "_price", 0);
List<WalletRechargeImportVo> targetList = userList.stream()
.filter(i -> ObjectUtil.equals(i.getUserId(), v.getUserId()))
.collect(Collectors.toList());
if (ObjectUtil.isNotEmpty(targetList)) {
WalletRechargeImportVo target = targetList.stream().findFirst().get();
v.put(currentImportKey + "_price", target.getPrice());
}
}
resultVo.setRecords(resultList);
List<String> tableListStr = new ArrayList<>();
tableListStr.add(merge.get(0) + "(上个月总充值金额)");
tableListStr.add(merge.get(1) + "(当前月总充值金额)");
tableListStr.add("当前导入金额");
result.setPage(resultVo);
result.setTableList(merge);
result.setTableListStr(tableListStr);
return result;
}
private void getItem(WalletRechargeImportVo user,
List<WalletRechargeApplySelectCompareVo> monthList,
List<WalletRechargeApplySelectCompareVo> prenMonthList,
String monthTimeStr,
WalletRechargeApplyCompareVo result
) {
Optional<WalletRechargeApplySelectCompareVo> first = monthList.stream().filter(v -> ObjectUtil.equals(v.getUserId(), user.getUserId())).findFirst();
WalletRechargeApplySelectCompareVo target = null;
if (!first.isPresent()) {
target = BeanUtils.toBean(user, WalletRechargeApplySelectCompareVo.class);
target.setPrice(0);
target.setTotalPrice(0);
} else {
target = first.get();
}
result.put(monthTimeStr + "_price", target.getTotalPrice());
result.put(monthTimeStr + "_transaction_price", getTransactionPrice(target, prenMonthList));
result.put(monthTimeStr + "_transaction_percent", getTransactionPercent(target, prenMonthList));
}
private Integer getTransactionPrice(WalletRechargeApplySelectCompareVo target, List<WalletRechargeApplySelectCompareVo> prenList) {
if (ObjectUtil.isEmpty(prenList)) return null;
Optional<WalletRechargeApplySelectCompareVo> first = prenList.stream().filter(v -> ObjectUtil.equals(v.getUserId(), target.getUserId())).findFirst();
if (!first.isPresent()) {
return null;
}
Integer price = first.get().getTotalPrice();
return target.getTotalPrice() - price;
}
private String getTransactionPercent(WalletRechargeApplySelectCompareVo target, List<WalletRechargeApplySelectCompareVo> prenList) {
if (ObjectUtil.isEmpty(prenList)) return null;
Optional<WalletRechargeApplySelectCompareVo> first = prenList.stream().filter(v -> ObjectUtil.equals(v.getUserId(), target.getUserId())).findFirst();
if (!first.isPresent()) {
return null;
}
Integer price = first.get().getTotalPrice();
Integer increase = target.getTotalPrice() - price;
Double res = (increase.doubleValue() / price.doubleValue()) * 100.0;
DecimalFormat df = new DecimalFormat("#.00");
return df.format(res);
}
}
@@ -29,13 +29,12 @@ import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletBizRechargeEnum;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeApplyDto;
import com.bsd.pjcloud.wallet.api.dto.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.WalletFreezeEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.entity.WalletTypeEntity;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
import com.bsd.pjcloud.wallet.mapper.recharge.WalletRechargeApplyMapper;
import com.bsd.pjcloud.wallet.service.WalletManageService;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyService;
@@ -72,6 +71,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
private final WalletTransactionService walletTransactionService;
private final WalletTypeService walletTypeService;
private final WalletTransactionMapper walletTransactionMapper;
private final RemoteUserService userService;
private final RemoteDeptService deptService;
@@ -245,6 +246,31 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
}
}
@Override
public void updateBeforePrice(WalletRechargeApplyEntity detail) {
if (!ObjectUtil.equals(detail.getProcessStatus(), TaskCheckStatusEnum.PADDING.getCode())) {
return;
}
String importTimeStr = LocalDateTimeUtil.format(detail.getImportTime(), DatePattern.NORM_MONTH_PATTERN);
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>()
.eq(WalletRechargeImportEntity::getApplyId, detail.getId())
);
if (ObjectUtil.isEmpty(importList)) return;
List<WalletRechargeImportEntity> saveList = new ArrayList<>();
for (WalletRechargeImportEntity v : importList) {
WalletRechargeImportEntity item = new WalletRechargeImportEntity();
item.setId(v.getId());
WalletManageEntity wallet = walletManageService.getWallet(v.getUserId(), detail.getWalletTypeId());
if (ObjectUtil.isEmpty(wallet)) continue;
Integer price = walletTransactionMapper.getTransactionPriceCount(importTimeStr, wallet.getId(), WalletBizEnum.BATCH.getCode());
if (ObjectUtil.isNotEmpty(price)) {
item.setBeforePrice(price);
}
saveList.add(item);
}
rechargeImportService.saveBatch(saveList);
}
private boolean isCheckData(Long walletId) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<WalletRechargeApplyEntity>()
.eq(WalletRechargeApplyEntity::getUserId, walletId)
@@ -1,16 +1,57 @@
package com.bsd.pjcloud.wallet.service.impl.recharge;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.entity.SysUser;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
import com.bsd.pjcloud.admin.api.utils.DataUtil;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeImportDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeImportEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.mapper.recharge.WalletRechargeImportMapper;
import com.bsd.pjcloud.wallet.service.WalletRechargeImportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
/**
* 充值导入表
*
* @author dzc
* @date 2024-12-31 14:24:39
*/
@Validated
@Slf4j
@RequiredArgsConstructor
@Service
public class WalletRechargeImportServiceImpl extends ServiceImpl<WalletRechargeImportMapper, WalletRechargeImportEntity> implements WalletRechargeImportService {
private final RemoteUserService userService;
private final RemoteDeptService deptService;
@Override
public Page<WalletRechargeImportVo> pageJoin(Page page, WalletRechargeImportDto dto) {
Page<WalletRechargeImportVo> list = baseMapper.pageJoin(page, dto);
if (ObjectUtil.isNotEmpty(list.getRecords())) {
// 用户
List<Long> userIds = list.getRecords().stream().map(WalletRechargeImportVo::getUserId).distinct().toList();
if (ObjectUtil.isNotEmpty(userIds)) {
R<List<SysUser>> userList = userService.getUserById(new ArrayList<>(userIds));
if (ObjectUtil.isNotEmpty(userList.getData())) {
DataUtil.convertUserList(list.getRecords(), CollectionUtils.convertMap(userList.getData(), SysUser::getUserId));
}
}
}
return list;
}
}
@@ -8,9 +8,39 @@
<result property="walletId" column="wallet_id"/>
<result property="bizType" column="biz_type"/>
<result property="bizId" column="biz_id"/>
<result property="no" column="no"/>
<result property="title" column="title"/>
<result property="price" column="price"/>
<result property="balance" column="balance"/>
</resultMap>
<select id="getTransactionPriceCount" resultType="java.lang.Integer">
select sum(a.price)
from wallet_transaction a
<where>
<if test="month != null and month != '' ">
and DATE_FORMAT(a.create_time, '%Y-%m') = #{month}
</if>
<if test="walletId != null">
and a.wallet_id = #{walletId}
</if>
<if test="bizType != null and bizType != '' ">
and a.biz_type = #{bizType}
</if>
</where>
</select>
<select id="selectCompare" resultType="com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo">
SELECT w.user_id,
SUM(a.price) as price
FROM wallet_transaction a
INNER JOIN
wallet_manage w ON w.id = a.wallet_id
WHERE biz_type = #{bizType}
and DATE_FORMAT(a.create_time, '%Y-%m') = #{dateTime}
and w.user_id in
<foreach collection="userIdList" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
GROUP BY w.user_id
</select>
</mapper>