mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 13:42:07 +08:00
1、充值活动controller单元测试完善;2、充值明细无用方法移除、service/controller单元测试完善;
This commit is contained in:
-29
@@ -1,29 +1,17 @@
|
|||||||
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||||
|
|
||||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||||
import com.cf.imes.framework.common.pojo.PageParam;
|
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.framework.excel.core.util.ExcelUtils;
|
|
||||||
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
import com.cf.imes.module.system.service.funds.recharge.RechargeDetailsService;
|
import com.cf.imes.module.system.service.funds.recharge.RechargeDetailsService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
import static com.cf.imes.framework.common.pojo.CommonResult.success;
|
||||||
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gqr
|
* @author Gqr
|
||||||
@@ -38,23 +26,6 @@ public class RechargeDetailsController {
|
|||||||
@Resource
|
@Resource
|
||||||
private RechargeDetailsService rechargeDetailsService;
|
private RechargeDetailsService rechargeDetailsService;
|
||||||
|
|
||||||
@GetMapping("/page")
|
|
||||||
@Operation(summary = "获取充值明细分页")
|
|
||||||
public CommonResult<PageResult<RechargeDetailRespVO>> getRechargeDetailsPage(@Valid RechargeDetailsPageReqVO pageReqVO) {
|
|
||||||
return success(rechargeDetailsService.getRechargeDetailsPage(pageReqVO));
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/export")
|
|
||||||
@Operation(summary = "导出充值明细")
|
|
||||||
@OperateLog(type = EXPORT)
|
|
||||||
public void exportRechargeDetails(@Valid RechargeDetailsPageReqVO pageReqVO,
|
|
||||||
HttpServletResponse response) throws IOException {
|
|
||||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
||||||
List<RechargeDetailRespVO> list = rechargeDetailsService.getRechargeDetailsPage(pageReqVO).getList();
|
|
||||||
// 导出 Excel
|
|
||||||
ExcelUtils.write(response, "充值明细表.xls", "数据", RechargeDetailRespVO.class, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/balance")
|
@GetMapping("/balance")
|
||||||
@Operation(summary = "获取管理端充值明细余额信息")
|
@Operation(summary = "获取管理端充值明细余额信息")
|
||||||
public CommonResult<RechargeDetailsBalanceInfoRespVO> getManageRechargeDetailsBalanceInfo() {
|
public CommonResult<RechargeDetailsBalanceInfoRespVO> getManageRechargeDetailsBalanceInfo() {
|
||||||
|
|||||||
-10
@@ -1,12 +1,9 @@
|
|||||||
package com.cf.imes.module.system.dal.mysql.pay;
|
package com.cf.imes.module.system.dal.mysql.pay;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.statistics.vo.OrgStatusGroupStatisticsReqVO;
|
import com.cf.imes.module.system.controller.admin.statistics.vo.OrgStatusGroupStatisticsReqVO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.funds.statistics.FundsTradeTypeGroupStatisticsDO;
|
import com.cf.imes.module.system.dal.dataobject.funds.statistics.FundsTradeTypeGroupStatisticsDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderDO;
|
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderRechargeDetailDO;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -21,13 +18,6 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface PayOrderMapper extends BaseMapper<PayOrderDO> {
|
public interface PayOrderMapper extends BaseMapper<PayOrderDO> {
|
||||||
/**
|
|
||||||
* 获取充值明细分页
|
|
||||||
*
|
|
||||||
* @param reqVO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
IPage<PayOrderRechargeDetailDO> getRechargeDetailsPage(@Param("page") IPage<PayOrderRechargeDetailDO> page, @Param("reqVO") RechargeDetailsPageReqVO reqVO);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询充值总额
|
* 查询充值总额
|
||||||
|
|||||||
-9
@@ -1,9 +1,6 @@
|
|||||||
package com.cf.imes.module.system.service.funds.recharge;
|
package com.cf.imes.module.system.service.funds.recharge;
|
||||||
|
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充值明细 Service 接口
|
* 充值明细 Service 接口
|
||||||
@@ -12,12 +9,6 @@ import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDeta
|
|||||||
* @since 2025/9/11 16:20
|
* @since 2025/9/11 16:20
|
||||||
*/
|
*/
|
||||||
public interface RechargeDetailsService {
|
public interface RechargeDetailsService {
|
||||||
/**
|
|
||||||
* 查询充值明细分页
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
PageResult<RechargeDetailRespVO> getRechargeDetailsPage(RechargeDetailsPageReqVO reqVO);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取管理端充值余额信息
|
* 获取管理端充值余额信息
|
||||||
|
|||||||
-8
@@ -1,9 +1,6 @@
|
|||||||
package com.cf.imes.module.system.service.funds.recharge;
|
package com.cf.imes.module.system.service.funds.recharge;
|
||||||
|
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
|
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
|
||||||
import com.cf.imes.module.system.service.pay.PayOrderService;
|
import com.cf.imes.module.system.service.pay.PayOrderService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -23,11 +20,6 @@ public class RechargeDetailsServiceImpl implements RechargeDetailsService {
|
|||||||
@Resource
|
@Resource
|
||||||
private PurchaseService purchaseService;
|
private PurchaseService purchaseService;
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<RechargeDetailRespVO> getRechargeDetailsPage(RechargeDetailsPageReqVO reqVO) {
|
|
||||||
return payOrderService.getRechargeDetailsPage(reqVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RechargeDetailsBalanceInfoRespVO getManageRechargeDetailsBalanceInfo() {
|
public RechargeDetailsBalanceInfoRespVO getManageRechargeDetailsBalanceInfo() {
|
||||||
RechargeDetailsBalanceInfoRespVO rechargeDetailsBalanceInfoRespVO = new RechargeDetailsBalanceInfoRespVO();
|
RechargeDetailsBalanceInfoRespVO rechargeDetailsBalanceInfoRespVO = new RechargeDetailsBalanceInfoRespVO();
|
||||||
|
|||||||
-11
@@ -1,9 +1,6 @@
|
|||||||
package com.cf.imes.module.system.service.pay;
|
package com.cf.imes.module.system.service.pay;
|
||||||
|
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
import com.cf.imes.framework.pay.core.client.dto.order.PayOrderRespDTO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.pay.vo.PayProductOrderUnifiedReqVO;
|
import com.cf.imes.module.system.controller.admin.pay.vo.PayProductOrderUnifiedReqVO;
|
||||||
import com.cf.imes.module.system.controller.admin.pay.vo.PayRechargeOrderReqVO;
|
import com.cf.imes.module.system.controller.admin.pay.vo.PayRechargeOrderReqVO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderDO;
|
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderDO;
|
||||||
@@ -73,14 +70,6 @@ public interface PayOrderService {
|
|||||||
*/
|
*/
|
||||||
int expirePayOrder();
|
int expirePayOrder();
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询充值明细分页
|
|
||||||
*
|
|
||||||
* @param reqVO
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
PageResult<RechargeDetailRespVO> getRechargeDetailsPage(RechargeDetailsPageReqVO reqVO);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理端查询充值总额
|
* 管理端查询充值总额
|
||||||
*
|
*
|
||||||
|
|||||||
+1
-76
@@ -8,16 +8,12 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import com.cf.imes.framework.common.exception.ServiceException;
|
import com.cf.imes.framework.common.exception.ServiceException;
|
||||||
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||||
import com.cf.imes.framework.common.pojo.PageResult;
|
|
||||||
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
|
||||||
import com.cf.imes.framework.common.util.validation.ValidationUtils;
|
import com.cf.imes.framework.common.util.validation.ValidationUtils;
|
||||||
import com.cf.imes.framework.id.core.util.SnowflakeSerialNoWorker3rd;
|
import com.cf.imes.framework.id.core.util.SnowflakeSerialNoWorker3rd;
|
||||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||||
@@ -28,8 +24,6 @@ import com.cf.imes.framework.redis.config.ChenfengCacheProperties;
|
|||||||
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
|
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
|
||||||
import com.cf.imes.framework.redis.util.RedisLockUtil;
|
import com.cf.imes.framework.redis.util.RedisLockUtil;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.delay.vo.PreviouProductDelayRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.delay.vo.PreviouProductDelayRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailRespVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsPageReqVO;
|
|
||||||
import com.cf.imes.module.system.controller.admin.pay.vo.PayOrderUnifiedReqDTO;
|
import com.cf.imes.module.system.controller.admin.pay.vo.PayOrderUnifiedReqDTO;
|
||||||
import com.cf.imes.framework.common.exception.PayException;
|
import com.cf.imes.framework.common.exception.PayException;
|
||||||
import com.cf.imes.framework.pay.core.enums.order.PayOrderStatusRespEnum;
|
import com.cf.imes.framework.pay.core.enums.order.PayOrderStatusRespEnum;
|
||||||
@@ -37,8 +31,6 @@ import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
|||||||
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO;
|
||||||
import com.cf.imes.module.system.controller.admin.funds.products.vo.product.ProductProcessorRespVO;
|
import com.cf.imes.module.system.controller.admin.funds.products.vo.product.ProductProcessorRespVO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.funds.delay.ProductDelayRecordDO;
|
import com.cf.imes.module.system.dal.dataobject.funds.delay.ProductDelayRecordDO;
|
||||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
|
||||||
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderRechargeDetailDO;
|
|
||||||
import com.cf.imes.module.system.enums.pay.PayProductChannelCodeEnumNew;
|
import com.cf.imes.module.system.enums.pay.PayProductChannelCodeEnumNew;
|
||||||
import com.cf.imes.module.system.enums.pay.ProductDurationUnitEnum;
|
import com.cf.imes.module.system.enums.pay.ProductDurationUnitEnum;
|
||||||
import com.cf.imes.module.system.service.funds.delay.ProductDelayService;
|
import com.cf.imes.module.system.service.funds.delay.ProductDelayService;
|
||||||
@@ -79,7 +71,6 @@ import jakarta.validation.Validator;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -111,9 +102,6 @@ import static com.cf.imes.module.system.enums.ErrorCodeConstants.PAY_RECHARGE_OR
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class PayOrderServiceImpl implements PayOrderService {
|
public class PayOrderServiceImpl implements PayOrderService {
|
||||||
|
|
||||||
// 外部payNo正则
|
|
||||||
private static final Pattern pattern = Pattern.compile("P(\\d+)O");
|
|
||||||
|
|
||||||
// 自动生成定价id正则
|
// 自动生成定价id正则
|
||||||
private static final Pattern productMonthDetailIdPattern = Pattern.compile("^1759029544(\\d+)$");
|
private static final Pattern productMonthDetailIdPattern = Pattern.compile("^1759029544(\\d+)$");
|
||||||
private static final Pattern productYearDetailIdPattern = Pattern.compile("^1759993429(\\d+)$");
|
private static final Pattern productYearDetailIdPattern = Pattern.compile("^1759993429(\\d+)$");
|
||||||
@@ -528,7 +516,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
throw exception(PAY_ORDER_NOT_EXIST, outTradeNo);
|
throw exception(PAY_ORDER_NOT_EXIST, outTradeNo);
|
||||||
}
|
}
|
||||||
// 订单已被更新成功,直接支付成功了
|
// 订单已被更新成功,直接支付成功了
|
||||||
if (PayOrderStatusEnum.SUCCESS.getStatus().equals(payOrderDO.getStatus())) {
|
if (PayOrderStatusEnum.SUCCESS.equals(payOrderDO.getStatus())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,22 +573,6 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 从payNo中解析组织id
|
|
||||||
*
|
|
||||||
* @param outTradeNo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Long getOrganIdFromPayNo(String outTradeNo) {
|
|
||||||
Matcher matcher = pattern.matcher(outTradeNo);
|
|
||||||
|
|
||||||
if (matcher.find()) {
|
|
||||||
return Long.valueOf(matcher.group(1)); // 提取 P 和 O 中间的数字
|
|
||||||
} else {
|
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付成功回调处理
|
* 支付成功回调处理
|
||||||
*
|
*
|
||||||
@@ -850,20 +822,6 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验获取当前token请求下的组织id
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Long validOrganId() {
|
|
||||||
// 校验token
|
|
||||||
Long organId = OrganContextHolder.getOrganId();
|
|
||||||
if (ObjectUtil.isNull(organId)) {
|
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
return organId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int expirePayOrder() {
|
public int expirePayOrder() {
|
||||||
// 1、查询过期的待支付订单
|
// 1、查询过期的待支付订单
|
||||||
@@ -935,39 +893,6 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageResult<RechargeDetailRespVO> getRechargeDetailsPage(RechargeDetailsPageReqVO reqVO) {
|
|
||||||
// 分页查询
|
|
||||||
Page<PayOrderRechargeDetailDO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
|
|
||||||
IPage<PayOrderRechargeDetailDO> rechargeDetailsPage = payOrderMapper.getRechargeDetailsPage(page, reqVO);
|
|
||||||
|
|
||||||
// 构建回调数据
|
|
||||||
List<RechargeDetailRespVO> resultList = new ArrayList<>();
|
|
||||||
for (PayOrderRechargeDetailDO detailDO : rechargeDetailsPage.getRecords()) {
|
|
||||||
RechargeDetailRespVO respVO = BeanUtils.toBean(detailDO, RechargeDetailRespVO.class);
|
|
||||||
|
|
||||||
// 根据是否关联购买记录判断是充值还是购买软件
|
|
||||||
if (ObjectUtil.isNotNull(detailDO.getPurchaseId())) {
|
|
||||||
respVO.setTradeType(TradeTypeEnum.PRODUCT.getCode());
|
|
||||||
// 产品购买有充值记录的,充值支付就是支付单的金额
|
|
||||||
respVO.setRechargeSpent(detailDO.getPrice());
|
|
||||||
} else {
|
|
||||||
respVO.setTradeType(TradeTypeEnum.RECHARGE.getCode());
|
|
||||||
BigDecimal zero = BigDecimal.ZERO;
|
|
||||||
respVO.setRechargeSpent(zero);
|
|
||||||
respVO.setTotalAmount(zero);
|
|
||||||
respVO.setAccountBalanceSpent(zero);
|
|
||||||
respVO.setGiftMoneySpent(zero);
|
|
||||||
}
|
|
||||||
OrganizationDO organ = organService.getOrganWithDeleted(detailDO.getOrganId());
|
|
||||||
if (ObjectUtil.isNotNull(organ)) {
|
|
||||||
respVO.setOrganName(organ.getName());
|
|
||||||
}
|
|
||||||
resultList.add(respVO);
|
|
||||||
}
|
|
||||||
return new PageResult<>(resultList, rechargeDetailsPage.getTotal());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal getRechargeTotalAmount() {
|
public BigDecimal getRechargeTotalAmount() {
|
||||||
return payOrderMapper.getRechargeTotalAmount();
|
return payOrderMapper.getRechargeTotalAmount();
|
||||||
|
|||||||
-21
@@ -1,27 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?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" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.cf.imes.module.system.dal.mysql.pay.PayOrderMapper">
|
<mapper namespace="com.cf.imes.module.system.dal.mysql.pay.PayOrderMapper">
|
||||||
<select id="getRechargeDetailsPage" resultType="com.cf.imes.module.system.dal.dataobject.pay.PayOrderRechargeDetailDO">
|
|
||||||
select o.id, o.organ_id, o.pay_no, o.price, o.purchase_id, o.channel_code, o.creator, o.create_time, p.total_amount, p.account_balance_spent, p.gift_money_spent, p.payment_method
|
|
||||||
from pay_order o
|
|
||||||
left join purchase_record p on o.purchase_id = p.id
|
|
||||||
where o.status = '${@com.cf.imes.module.system.enums.pay.PayOrderStatusEnum@SUCCESS.status}'
|
|
||||||
|
|
||||||
<if test="reqVO.organId != null">
|
|
||||||
AND o.organ_id = #{reqVO.organId}
|
|
||||||
</if>
|
|
||||||
<if test="reqVO.productPrice != null">
|
|
||||||
AND p.total_amount = #{reqVO.productPrice}
|
|
||||||
</if>
|
|
||||||
<if test="reqVO.operator != null and reqVO.operator != ''">
|
|
||||||
AND o.creator = #{reqVO.operator}
|
|
||||||
</if>
|
|
||||||
<if test="reqVO.createTime != null and reqVO.createTime.length == 2">
|
|
||||||
AND o.create_time >= #{reqVO.createTime[0]}
|
|
||||||
AND o.create_time <= #{reqVO.createTime[1]}
|
|
||||||
</if>
|
|
||||||
order by o.id desc;
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="getRechargeTotalAmount" resultType="java.math.BigDecimal">
|
<select id="getRechargeTotalAmount" resultType="java.math.BigDecimal">
|
||||||
select sum(price) from pay_order
|
select sum(price) from pay_order
|
||||||
|
|||||||
+164
@@ -0,0 +1,164 @@
|
|||||||
|
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.common.pojo.PageResult;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||||
|
import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||||
|
import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||||
|
import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||||
|
import com.cf.imes.module.system.service.funds.recharge.RechargeActiveService;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2025/10/27 9:29
|
||||||
|
*/
|
||||||
|
@WebMvcTest(controllers = RechargeActiveController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||||
|
class RechargeActiveControllerTest {
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private RechargeActiveService rechargeActiveService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCreateRechargeActive() throws Exception {
|
||||||
|
RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||||
|
vo.setActivityName("充值活动");
|
||||||
|
vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||||
|
vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||||
|
vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||||
|
vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
vo.setStartTime(now);
|
||||||
|
vo.setEndTime(now);
|
||||||
|
|
||||||
|
// mock Service 返回
|
||||||
|
when(rechargeActiveService.create(any())).thenReturn(100L);
|
||||||
|
|
||||||
|
mockMvc.perform(put("/system/recharge-active")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(objectMapper.writeValueAsString(vo)))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(100));
|
||||||
|
|
||||||
|
// 验证 Service 调用
|
||||||
|
verify(rechargeActiveService, times(1)).create(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdateRechargeActive() throws Exception {
|
||||||
|
RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||||
|
vo.setId(1L);
|
||||||
|
vo.setActivityName("更新充值活动");
|
||||||
|
vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||||
|
vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||||
|
vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||||
|
vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
vo.setStartTime(now);
|
||||||
|
vo.setEndTime(now);
|
||||||
|
|
||||||
|
// mock Service 返回
|
||||||
|
doNothing().when(rechargeActiveService).update(any());
|
||||||
|
|
||||||
|
mockMvc.perform(post("/system/recharge-active")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(objectMapper.writeValueAsString(vo)))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(true));
|
||||||
|
|
||||||
|
// 验证 Service 调用
|
||||||
|
verify(rechargeActiveService, times(1)).update(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDeleteRechargeActive() throws Exception {
|
||||||
|
Long id = 3L;
|
||||||
|
doNothing().when(rechargeActiveService).delete(anyLong());
|
||||||
|
|
||||||
|
mockMvc.perform(delete("/system/recharge-active/{id}", id))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data").value(true));
|
||||||
|
|
||||||
|
verify(rechargeActiveService, times(1)).delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetRechargeActive() throws Exception {
|
||||||
|
Long id = 123L;
|
||||||
|
GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO()
|
||||||
|
.setId(id);
|
||||||
|
when(rechargeActiveService.get(id)).thenReturn(mockDO);
|
||||||
|
|
||||||
|
mockMvc.perform(get("/system/recharge-active/{id}", id))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.id").value(123L));
|
||||||
|
|
||||||
|
verify(rechargeActiveService, times(1)).get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetRechargeActivePage() throws Exception {
|
||||||
|
RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||||
|
PageResult<GiftMoneyDetailsDO> mockPage = new PageResult<>();
|
||||||
|
mockPage.setTotal(1L);
|
||||||
|
mockPage.setList(List.of(new GiftMoneyDetailsDO().setId(1L)));
|
||||||
|
when(rechargeActiveService.getPage(any())).thenReturn(mockPage);
|
||||||
|
|
||||||
|
mockMvc.perform(get("/system/recharge-active/page")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(objectMapper.writeValueAsString(reqVO)))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.data.list[0].id").value(1L));
|
||||||
|
|
||||||
|
verify(rechargeActiveService, times(1)).getPage(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetAvailableRechargeActivePage_success() throws Exception {
|
||||||
|
// 模拟 service 返回数据
|
||||||
|
GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO();
|
||||||
|
mockDO.setId(1L);
|
||||||
|
mockDO.setRechargeAmount(new BigDecimal("50.00"));
|
||||||
|
mockDO.setActivityName("新人充值活动");
|
||||||
|
|
||||||
|
when(rechargeActiveService.getAvailableRechargeActiveList())
|
||||||
|
.thenReturn(List.of(mockDO));
|
||||||
|
|
||||||
|
// 发起请求
|
||||||
|
mockMvc.perform(get("/system/recharge-active/available")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code=0
|
||||||
|
.andExpect(jsonPath("$.data[0].activityName").value("新人充值活动"))
|
||||||
|
.andExpect(jsonPath("$.data[0].rechargeAmount").value(50.00));
|
||||||
|
}
|
||||||
|
}
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||||
|
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||||
|
import com.cf.imes.module.system.service.funds.recharge.RechargeDetailsService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2025/10/27 10:56
|
||||||
|
*/
|
||||||
|
@WebMvcTest(controllers = RechargeDetailsController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||||
|
class RechargeDetailsControllerTest {
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private RechargeDetailsService rechargeDetailsService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetManageRechargeDetailsBalanceInfo_success() throws Exception {
|
||||||
|
// 构造 mock 返回对象
|
||||||
|
RechargeDetailsBalanceInfoRespVO respVO = new RechargeDetailsBalanceInfoRespVO();
|
||||||
|
respVO.setRechargeAmount(new BigDecimal("100.00"));
|
||||||
|
respVO.setRechargeUsageAmount(new BigDecimal("60.00"));
|
||||||
|
|
||||||
|
when(rechargeDetailsService.getManageRechargeDetailsBalanceInfo()).thenReturn(respVO);
|
||||||
|
|
||||||
|
// 执行 GET /recharge/balance
|
||||||
|
mockMvc.perform(get("/system/rechargeDetails/balance")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code = 0
|
||||||
|
.andExpect(jsonPath("$.data.rechargeAmount").value(100.00))
|
||||||
|
.andExpect(jsonPath("$.data.rechargeUsageAmount").value(60.00));
|
||||||
|
|
||||||
|
// 验证 Service 调用
|
||||||
|
verify(rechargeDetailsService, times(1)).getManageRechargeDetailsBalanceInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package com.cf.imes.module.system.service.funds.recharge;
|
||||||
|
|
||||||
|
import com.cf.imes.framework.test.core.ut.BaseDbUnitTest;
|
||||||
|
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||||
|
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
|
||||||
|
import com.cf.imes.module.system.service.pay.PayOrderService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gqr
|
||||||
|
* @since 2025/10/27 10:44
|
||||||
|
*/
|
||||||
|
@Import(RechargeDetailsServiceImpl.class)
|
||||||
|
class RechargeDetailsServiceImplTest extends BaseDbUnitTest {
|
||||||
|
@Resource
|
||||||
|
private RechargeDetailsService detailsService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private PayOrderService payOrderService;
|
||||||
|
|
||||||
|
@MockitoBean
|
||||||
|
private PurchaseService purchaseService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetManageRechargeDetailsBalanceInfo() {
|
||||||
|
// 模拟依赖返回值
|
||||||
|
when(payOrderService.getRechargeTotalAmount()).thenReturn(new BigDecimal("200.00"));
|
||||||
|
when(purchaseService.getTotalRechargeUsageAmount()).thenReturn(new BigDecimal("50.00"));
|
||||||
|
|
||||||
|
// 调用被测方法
|
||||||
|
RechargeDetailsBalanceInfoRespVO result = detailsService.getManageRechargeDetailsBalanceInfo();
|
||||||
|
|
||||||
|
// 验证逻辑
|
||||||
|
assertEquals(new BigDecimal("200.00"), result.getRechargeAmount());
|
||||||
|
assertEquals(new BigDecimal("50.00"), result.getRechargeUsageAmount());
|
||||||
|
verify(payOrderService).getRechargeTotalAmount();
|
||||||
|
verify(purchaseService).getTotalRechargeUsageAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user