feat:部门交易记录

This commit is contained in:
dzc committed 2025-01-23 13:12:31 +08:00
1 parent ec5e245fb0
commit 7e1be7ef2f
17 files changed
+350 -32

No files matched your search

@@ -30,6 +30,12 @@ public enum HardOrderStatusEnum {
);
}
public static List<String> getPayErrorCodes() {
return List.of(
HardOrderStatusEnum.REFUND.type
);
}
public static HardOrderStatusEnum valueOfByType(Integer type) {
if (ObjectUtil.isEmpty(type)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
@@ -0,0 +1,17 @@
package com.bsd.pjcloud.hard.api.dto.order;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class HardOrderSumAndCountDto {
private List<Long> deptIds;
private List<String> orderStatusCodes;
private LocalDateTime[] createTimeList;
}
@@ -0,0 +1,33 @@
package com.bsd.pjcloud.hard.api.vo.order;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class HardDeptTotalVo {
@Schema(description = "部门id")
private Long deptId;
@Schema(description = "部门名")
private String deptName;
@Schema(description = "充值金额")
private Long walletPrice = 0L;
@Schema(description = "充值次数")
private Long walletCount = 0L;
@Schema(description = "消费金额")
private Long orderPayPrice = 0L;
@Schema(description = "消费次数")
private Long orderPayCount = 0L;
@Schema(description = "退款金额")
private Long orderRefundPrice = 0L;
@Schema(description = "退款次数")
private Long orderRefundCont = 0L;
}
@@ -0,0 +1,18 @@
package com.bsd.pjcloud.hard.api.vo.order;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class HardOrderSumAndCountVo {
@Schema(description = "部门id")
private Long deptId;
@Schema(description = "部门操作金额")
private Long sum;
@Schema(description = "部门操作金额数量")
private Long count;
}
@@ -13,6 +13,7 @@ import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.hard.api.constant.HardTypeEnum;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.vo.order.HardDeptTotalVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo;
import com.bsd.pjcloud.hard.service.HardOrderTotalService;
@@ -56,6 +57,13 @@ public class HardOrderTotalController {
return R.ok(HardOrderTotalService.pageListCs(page, dto));
}
@GetMapping("/page-list-dept")
@Operation(summary = "部门交易记录")
public R<Page<HardDeptTotalVo>> pageListDept(@ParameterObject Page page, @ParameterObject HardOrderDto dto) {
dto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
return R.ok(HardOrderTotalService.pageListDept(page, dto));
}
@Operation(summary = "设备交易记录导出", description = "退款导出")
@GetMapping("/export-sb")
@PreAuthorize("@pms.hasPermission('hard_hardTotal_export_sb')")
@@ -7,11 +7,13 @@ import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderSumAndCountDto;
import com.bsd.pjcloud.hard.api.entity.HardManagerEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
@@ -85,4 +87,6 @@ public interface HardOrderMapper extends PjcloudBaseMapper<HardOrderEntity> {
Page<HardOrderCsVo> pageListCs(Page page, @Param("dto") HardOrderDto dto);
List<HardOrderCsVo> listCs(@Param("dto") HardOrderDto dto);
List<HardOrderSumAndCountVo> sumAndCount(@Param("dto") HardOrderSumAndCountDto dto);
}
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.hard.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.vo.order.HardDeptTotalVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo;
@@ -16,4 +17,6 @@ public interface HardOrderTotalService {
Page<HardOrderCsVo> pageListCs(Page page, HardOrderDto dto);
List<HardOrderCsVo> listCs(HardOrderDto dto);
Page<HardDeptTotalVo> pageListDept(Page page, HardOrderDto dto);
}
@@ -3,25 +3,37 @@ package com.bsd.pjcloud.hard.service.impl.order;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.admin.api.entity.SysDept;
import com.bsd.pjcloud.admin.api.feign.RemoteDeptService;
import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.core.util.CollectionUtils;
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
import com.bsd.pjcloud.hard.api.dto.HardManagerDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
import com.bsd.pjcloud.hard.api.dto.order.HardOrderSumAndCountDto;
import com.bsd.pjcloud.hard.api.entity.HardManagerEntity;
import com.bsd.pjcloud.hard.api.utils.HardUtil;
import com.bsd.pjcloud.hard.api.vo.order.HardDeptTotalVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderCsVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSbVo;
import com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo;
import com.bsd.pjcloud.hard.mapper.HardManagerMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.HardOrderTotalService;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletTransactionService;
import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo;
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;
import java.util.concurrent.CompletableFuture;
@Validated
@Slf4j
@@ -33,6 +45,8 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
private final HardManagerMapper hardManagerMapper;
private final RemoteMchService remoteMchService;
private final RemoteWalletTransactionService remoteWalletTransactionService;
private final RemoteDeptService remoteDeptService;
@Override
public Page<HardOrderSbVo> pageListSb(Page page, HardOrderDto dto) {
@@ -117,4 +131,71 @@ public class HardOrderTotalServiceImpl implements HardOrderTotalService {
}
return list;
}
@Override
public Page<HardDeptTotalVo> pageListDept(Page page, HardOrderDto dto) {
// 查询部门
CompletableFuture<List<SysDept>> deptFuture = CompletableFuture.supplyAsync(() ->
remoteDeptService.getInnerAllDept().getData()
);
CompletableFuture<List<HardDeptTotalVo>> resultListFuture = deptFuture.thenApply(deptList -> {
if (ObjectUtil.isEmpty(deptList)) return null;
List<Long> deptIds = deptList.stream().map(SysDept::getDeptId).filter(ObjectUtil::isNotEmpty).distinct().toList();
List<HardDeptTotalVo> resultList = deptList.stream().map(v -> {
HardDeptTotalVo item = new HardDeptTotalVo();
item.setDeptId(v.getDeptId());
item.setDeptName(v.getName());
return item;
}).toList();
// 查询钱包流水
CompletableFuture<List<WalletTransactionSumAndCountVo>> walletFuture = CompletableFuture.supplyAsync(() -> {
WalletTransactionSumAndCountDto walletDto = new WalletTransactionSumAndCountDto();
walletDto.setDeptIds(deptIds);
return remoteWalletTransactionService.sumAndCount(walletDto).getData();
});
// 查询订单支付流水
CompletableFuture<List<HardOrderSumAndCountVo>> payFuture = CompletableFuture.supplyAsync(() -> {
HardOrderSumAndCountDto payDto = new HardOrderSumAndCountDto();
payDto.setDeptIds(deptIds);
payDto.setOrderStatusCodes(HardOrderStatusEnum.getPaySuccessCodes());
return hardOrderMapper.sumAndCount(payDto);
});
// 查询订单退款流水
CompletableFuture<List<HardOrderSumAndCountVo>> refundFuture = CompletableFuture.supplyAsync(() -> {
HardOrderSumAndCountDto refundDto = new HardOrderSumAndCountDto();
refundDto.setDeptIds(deptIds);
refundDto.setOrderStatusCodes(HardOrderStatusEnum.getPayErrorCodes());
return hardOrderMapper.sumAndCount(refundDto);
});
CompletableFuture<Void> allFutures = CompletableFuture.allOf(walletFuture, payFuture, refundFuture);
allFutures.join();
List<WalletTransactionSumAndCountVo> walletList = walletFuture.join();
List<HardOrderSumAndCountVo> payList = payFuture.join();
List<HardOrderSumAndCountVo> refundList = refundFuture.join();
// 聚合一下数据
for (HardDeptTotalVo v : resultList) {
if (ObjectUtil.isNotEmpty(walletList)) {
walletList.stream().filter(i -> ObjectUtil.equals(i.getDeptId(), v.getDeptId())).findFirst().ifPresent(i -> {
v.setWalletPrice(i.getSum());
v.setWalletCount(i.getCount());
});
}
if (ObjectUtil.isNotEmpty(payList)) {
payList.stream().filter(i -> ObjectUtil.equals(i.getDeptId(), v.getDeptId())).findFirst().ifPresent(i -> {
v.setOrderPayPrice(i.getSum());
v.setOrderPayCount(i.getCount());
});
}
if (ObjectUtil.isNotEmpty(refundList)) {
refundList.stream().filter(i -> ObjectUtil.equals(i.getDeptId(), v.getDeptId())).findFirst().ifPresent(i -> {
v.setOrderRefundPrice(i.getSum());
v.setOrderRefundCont(i.getCount());
});
}
}
return resultList;
});
List<HardDeptTotalVo> resultList = resultListFuture.join();
return null;
}
}
@@ -137,4 +137,32 @@
</where>
group by a.merchant_id
</select>
<select id="sumAndCount" resultType="com.bsd.pjcloud.hard.api.vo.order.HardOrderSumAndCountVo">
select
a.dept_id,
sum(a.pay_price) as sum,
count(0) as count
from hard_order a
<where>
a.del_flag = 0 and a.dept_id is not null
<if test="dto.orderStatusCodes != null and dto.orderStatusCodes.size() != 0">
and a.order_status in
<foreach collection="dto.orderStatusCodes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
and a.dept_id in
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</where>
group by a.dept_id
</select>
</mapper>
@@ -47,6 +47,10 @@ public interface RemoteDeptService {
@GetMapping("/dept/list")
R<List<SysDept>> getAllDept(@RequestParam("parentDeptId") Long parentDeptId);
@NoToken
@GetMapping("/dept/inner-all-dept")
R<List<SysDept>> getInnerAllDept();
/**
* 通过部门ID获取负责人列表
*
@@ -97,6 +101,7 @@ public interface RemoteDeptService {
/**
* 查询部门所属的分组部门
*
* @param deptId
* @return
*/
@@ -216,4 +216,10 @@ public class SysDeptController {
public R<SysDept> getParentDeptHardGroup(@RequestParam("deptId") Long deptId) {
return R.ok(sysDeptService.getParentDeptHardGroup(deptId));
}
@Inner
@GetMapping("/inner-all-dept")
public R<List<SysDept>> getInnerAllDept() {
return R.ok(sysDeptService.list());
}
}
@@ -0,0 +1,27 @@
package com.bsd.pjcloud.wallet.api.dto;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class WalletTransactionSumAndCountDto {
/**
* 类型 - 收入
*/
public static final Integer TYPE_INCOME = 1;
/**
* 类型 - 支出
*/
public static final Integer TYPE_EXPENSE = 2;
private Integer type;
private List<Long> deptIds;
private List<String> bizTypes;
private LocalDateTime[] createTimeList;
}
@@ -4,11 +4,15 @@ import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.feign.annotation.NoToken;
import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
@FeignClient(contextId = "remoteWalletTransactionService", value = ServiceNameConstants.WALLET_SERVICE)
public interface RemoteWalletTransactionService {
@@ -20,4 +24,8 @@ public interface RemoteWalletTransactionService {
@PostMapping("/wallet-transaction/reduce-balance")
R<WalletTransactionEntity> reduceWalletBalance(@RequestBody WalletBalanceTransactionDto dto);
@NoToken
@PostMapping("/wallet-transaction/sum-and-count")
R<List<WalletTransactionSumAndCountVo>> sumAndCount(@RequestBody WalletTransactionSumAndCountDto dto);
}
@@ -0,0 +1,18 @@
package com.bsd.pjcloud.wallet.api.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class WalletTransactionSumAndCountVo {
@Schema(description = "部门id")
private Long deptId;
@Schema(description = "部门操作金额")
private Long sum;
@Schema(description = "部门操作金额数量")
private Long count;
}
@@ -13,8 +13,11 @@ import com.bsd.pjcloud.common.security.util.SecurityUtils;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.dto.WalletBalanceTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
import com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
import com.bsd.pjcloud.wallet.service.WalletTransactionService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
@@ -44,6 +47,8 @@ public class WalletTransactionController {
private final WalletTransactionService walletTransactionService;
private final WalletTransactionMapper walletTransactionMapper;
/* ************************************* start 远程调用 start ************************************* */
@Inner
@PostMapping("/add-balance")
@@ -60,6 +65,12 @@ public class WalletTransactionController {
if (ObjectUtil.isEmpty(walletTransaction)) return R.failed("扣减钱包余额");
return R.ok(walletTransaction);
}
@Inner
@PostMapping("/sum-and-count")
public R<List<WalletTransactionSumAndCountVo>> sumAndCount(@RequestBody WalletTransactionSumAndCountDto dto) {
return R.ok(walletTransactionMapper.sumAndCount(dto));
}
/* ************************************* end 远程调用 end ************************************* */
/* ************************************* start app start ************************************* */
@@ -7,9 +7,11 @@ import com.bsd.pjcloud.common.core.util.BeanUtils;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionDto;
import com.bsd.pjcloud.wallet.api.dto.WalletTransactionSumAndCountDto;
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.WalletTransactionSumAndCountVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo;
import com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -69,4 +71,6 @@ public interface WalletTransactionMapper extends PjcloudBaseMapper<WalletTransac
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);
List<WalletTransactionSumAndCountVo> sumAndCount(@Param("dto") WalletTransactionSumAndCountDto dto);
}
@@ -2,8 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper">
<resultMap id="walletTransactionMap" type="com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity">
<resultMap id="walletTransactionMap" type="com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity">
<id property="id" column="id"/>
<result property="walletId" column="wallet_id"/>
<result property="bizType" column="biz_type"/>
@@ -11,36 +10,78 @@
<result property="title" column="title"/>
<result property="price" column="price"/>
<result property="balance" column="balance"/>
</resultMap>
</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>
<sql id="selectA">
</sql>
<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>
<sql id="whereA">
</sql>
<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>
<select id="sumAndCount" resultType="com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo">
select
a.dept_id,
sum(a.price) as sum,
count(0) as count
from wallet_transaction a
<where>
a.del_flag = 0 and a.dept_id is not null
<if test="dto.type != null">
<if test="dto.type == 1">
and a.price &gt; 0
</if>
<if test="dto.type == 2">
and a.price &lt; 0
</if>
</if>
<if test="dto.bizTypes != null and dto.bizTypes.size() != 0">
and a.biz_type in
<foreach collection="dto.bizTypes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
and a.dept_id in
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</where>
group by a.dept_id
</select>
</mapper>