Browse Source

04-02 退款订单同步展示到资金流水账

lijianlin/feature-20260401-现金管理四期
lijianlin 7 days ago
parent
commit
03fbac8a77
  1. 66
      src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java
  2. 7
      src/main/resources/application-test.yml
  3. 88
      src/main/resources/cashMapper/CashRefundMapper.xml

66
src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java

@ -947,41 +947,6 @@ public class CashRefundServiceImpl implements RefundService {
}
List<FundsDTO> list = cashRefundMapper.selectfunds(fundsDTO);
// 2. 收集 status == 6 的记录 ID
List<Integer> needQueryIds = new ArrayList<>();
for (FundsDTO dto : list) {
if (dto.getStatus() != null && dto.getStatus() == 6) {
needQueryIds.add(dto.getId());
}
}
// 3. 批量查询 refundDetail 信息用于负数处理
if (!needQueryIds.isEmpty()) {
List<FundsDTO> detailList = cashRefundMapper.selectRefundCount(needQueryIds);
Map<Integer, FundsDTO> detailMap = new HashMap<>();
for (FundsDTO detail : detailList) {
// 假设 detail.getRelatedId() 对应主表的 id
detailMap.put(detail.getRelatedId(), detail);
}
// 回填 refundAmount取负 refundCurrency
for (FundsDTO dto : list) {
if (dto.getStatus() != null && dto.getStatus() == 6) {
FundsDTO detail = detailMap.get(dto.getId());
if (detail != null) {
BigDecimal amount = detail.getRefundAmount();
if (amount != null) {
dto.setRefundAmount(amount.negate()); // 转为负数
} else {
dto.setRefundAmount(null); // 或设为 BigDecimal.ZERO
}
dto.setRefundCurrency(detail.getRefundCurrency());
}
}
}
}
// 4. 收集所有需要转换的 regionId currencyId
Set<Integer> regionIds = new HashSet<>();
Set<Integer> currencyIds = new HashSet<>();
@ -1033,6 +998,37 @@ public class CashRefundServiceImpl implements RefundService {
// 8. 返回分页结果
return new PageInfo<>(list);
}
/**
* 复制 FundsDTO 对象浅拷贝
*/
private FundsDTO copyFundsDTO(FundsDTO source) {
FundsDTO target = new FundsDTO();
target.setId(source.getId());
target.setPayTime(source.getPayTime());
target.setOrderCode("TK" + source.getOrderCode());
target.setReceivedMarket(source.getReceivedMarket());
target.setPerformanceMarket(source.getPerformanceMarket());
target.setName(source.getName());
target.setJwcode(source.getJwcode());
target.setIncomeType(source.getIncomeType());
target.setGoodNum(source.getGoodNum());
target.setPayType(source.getPayType());
target.setReceivedCurrency(source.getReceivedCurrency());
target.setPaymentAmount(source.getPaymentAmount());
target.setHandlingCharge(source.getHandlingCharge());
target.setReceivedAmount(source.getReceivedAmount());
target.setMarket(source.getMarket());
target.setMarketName(source.getMarketName());
target.setMarkets(source.getMarkets());
target.setPerformanceMarkets(source.getPerformanceMarkets());
target.setPaymentCurrency(source.getPaymentCurrency());
target.setPaymentCurrencyName(source.getPaymentCurrencyName());
target.setReceivedCurrencyName(source.getReceivedCurrencyName());
target.setStatus(source.getStatus());
target.setStatusName(source.getStatusName());
return target;
}
/**
* 计算用户指定钱包列表的总可用余额
* @param jwcode 用户标识

7
src/main/resources/application-test.yml

@ -81,9 +81,10 @@ spring:
data:
redis:
database: 0
host: localhost
port: 6379
password: 123456
host: 54.255.212.181
port: 10703
password: Ngc0FYUTA6h3wC5J
lettuce:
pool:

88
src/main/resources/cashMapper/CashRefundMapper.xml

@ -446,6 +446,7 @@
</select>
<select id="selectfunds" resultType="com.example.demo.domain.vo.cash.FundsDTO">
SELECT * FROM (
SELECT
crc.id,
crc.jwcode,
@ -459,19 +460,20 @@
crc.order_code,
crc.payment_currency,
ROUND(crc.payment_amount / 100.0, 2) as paymentAmount,
crc.received_currency,
ROUND(crc.received_amount / 100.0, 2) as receivedAmount,
ROUND(crc.handling_charge / 100.0, 2) as handlingCharge,
ROUND(crc.permanent_gold / 100.0, 2) as permanentGold,
ROUND(crc.free_gold / 100.0, 2) as freeGold,
crc.pay_type,
crc.pay_time,
crc.status
crc.status,
NULL as refundCurrency,
NULL as refundAmount,
NULL as relatedId,
0 as isRefundRow
FROM cash_record_collection crc
<where>
WHERE 1=1
<if test="jwcode != null">
and crc.jwcode = #{jwcode}
</if>
@ -508,16 +510,74 @@
#{statuses}
</foreach>
</if>
</where>
<choose>
<when test="sortField != null and sortField.length > 0 or sortOrder != null and sortOrder.length > 0">
ORDER BY ${sortField} ${sortOrder}
</when>
<otherwise>
ORDER BY crc.create_time DESC
</otherwise>
</choose>
UNION ALL
SELECT
crc.id,
crc.jwcode,
crc.income_type,
crc.remark,
crc.good_num,
crc.performance_market,
crc.received_market,
crc.name,
crc.market,
CONCAT('TK', crc.order_code) as order_code,
NULL as payment_currency,
NULL as paymentAmount,
crc.received_currency as received_currency,
ROUND(-crr.refund_amount / 100.0, 2) as receivedAmount,
NULL as handlingCharge,
NULL as permanentGold,
NULL as freeGold,
NULL as pay_type,
crr.refund_time as pay_time,
crc.status,
crr.refund_currency as refundCurrency,
ROUND(crr.refund_amount / 100.0, 2) as refundAmount,
crr.related_id as relatedId,
1 as isRefundRow
FROM cash_record_refund crr
INNER JOIN cash_record_collection crc ON crr.related_id = crc.id
WHERE crc.status =6 and crr.status =41
<if test="jwcode != null">
and crc.jwcode = #{jwcode}
</if>
<if test="markets!= null and markets.size > 0">
AND crc.received_market IN
<foreach collection="markets" item="markets" open="(" separator="," close=")">
#{markets}
</foreach>
</if>
<if test="performanceMarkets!= null and performanceMarkets.size > 0">
AND crc.performance_market IN
<foreach collection="performanceMarkets" item="performanceMarkets" open="(" separator="," close=")">
#{performanceMarkets}
</foreach>
</if>
<if test="localMarket != null and localMarket.size > 0">
AND crc.market IN
<foreach collection="localMarket" item="localMarket" open="(" separator="," close=")">
#{localMarket}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and crc.`pay_time` BETWEEN #{startTime} AND #{endTime}
</if>
<if test="payType!= null and payType.length > 0">
AND crc.pay_type like CONCAT('%', #{payType}, '%')
</if>
<if test="orderCode!= null and orderCode.length > 0">
AND crc.order_code like CONCAT('%', #{orderCode}, '%')
</if>
) AS combined_result
ORDER BY
id,
isRefundRow DESC,
pay_time DESC
</select>
<select id="selectRefundCount" resultType="com.example.demo.domain.vo.cash.FundsDTO">
select crr.refund_currency,
crr.refund_amount,

Loading…
Cancel
Save