6 Commits

  1. 15
      src/main/java/com/example/demo/controller/cash/CashCollectionController.java
  2. 34
      src/main/java/com/example/demo/domain/DTO/AddFundsDTO.java
  3. 2
      src/main/java/com/example/demo/domain/vo/cash/CashCollection.java
  4. 7
      src/main/java/com/example/demo/mapper/cash/CashCollectionMapper.java
  5. 8
      src/main/java/com/example/demo/service/cash/CashCollectionService.java
  6. 26
      src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java
  7. 67
      src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java
  8. 7
      src/main/resources/application-test.yml
  9. 5
      src/main/resources/cashMapper/CashCollectionMapper.xml
  10. 88
      src/main/resources/cashMapper/CashRefundMapper.xml

15
src/main/java/com/example/demo/controller/cash/CashCollectionController.java

@ -3,6 +3,7 @@ package com.example.demo.controller.cash;
import com.example.demo.Util.JWTUtil; import com.example.demo.Util.JWTUtil;
import com.example.demo.Util.LanguageTranslationUtil; import com.example.demo.Util.LanguageTranslationUtil;
import com.example.demo.config.interfac.Log; import com.example.demo.config.interfac.Log;
import com.example.demo.domain.DTO.AddFundsDTO;
import com.example.demo.domain.DTO.PerformanceDTO; import com.example.demo.domain.DTO.PerformanceDTO;
import com.example.demo.domain.entity.*; import com.example.demo.domain.entity.*;
import com.example.demo.domain.vo.cash.*; import com.example.demo.domain.vo.cash.*;
@ -432,6 +433,20 @@ public class CashCollectionController {
return Result.error("查询失败" + ": " + e.getMessage()); return Result.error("查询失败" + ": " + e.getMessage());
} }
} }
/**
*新增流水-其他收入
*/
@PostMapping("/addExFund")
public Result addExFund(@RequestBody CashCollection addFundsDTO, @RequestHeader(defaultValue = "zh_CN") String lang) {
try {
String result = cashCollectionService.addExFund(addFundsDTO);
return Result.success(result);
} catch (Exception e) {
String errorMsg = languageTranslationUtil.translate(e.getMessage(), lang);
return Result.error(errorMsg);
}
}
/** /**
* 查询所有钱包类型 * 查询所有钱包类型

34
src/main/java/com/example/demo/domain/DTO/AddFundsDTO.java

@ -0,0 +1,34 @@
package com.example.demo.domain.DTO;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
/**
* @program: gold-java
* @ClassName addFundsDTO
* @description:
* @author: Ethan
* @create: 202604-02 16:56
* @Version 1.0
**/
@Data
@NoArgsConstructor
public class AddFundsDTO {
private String performanceMarket; //业绩归属地区
private String incomeType; //收入类别
private Integer goodNum; //商品数量
private String payType; //付款方式
private Integer paymentCurrency; //付款币种
private BigDecimal paymentAmount; //付款金额
@ExcelIgnore
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
private Date payTime; //付款时间
private BigDecimal handlingCharge; //手续费
private String remark; //备注
}

2
src/main/java/com/example/demo/domain/vo/cash/CashCollection.java

@ -34,6 +34,8 @@ public class CashCollection implements Serializable {
private Integer orderType; // 订单类型1-收款2-退款 private Integer orderType; // 订单类型1-收款2-退款
private Integer jwcode; // 精网号 private Integer jwcode; // 精网号
private String name; // 姓名 private String name; // 姓名
private String performanceMarket; //业绩归属地区
private String incomeType; //收入类别
@ExcelIgnore @ExcelIgnore
private String market; // 所属地区 private String market; // 所属地区
private String marketName; // 所属地区名称 private String marketName; // 所属地区名称

7
src/main/java/com/example/demo/mapper/cash/CashCollectionMapper.java

@ -3,10 +3,7 @@ package com.example.demo.mapper.cash;
//import com.example.demo.domain.DTO.PaymentDTO; //import com.example.demo.domain.DTO.PaymentDTO;
import com.example.demo.domain.DTO.*; import com.example.demo.domain.DTO.*;
import com.example.demo.domain.entity.*; import com.example.demo.domain.entity.*;
import com.example.demo.domain.vo.cash.CashCollection;
import com.example.demo.domain.vo.cash.PerformanceVO;
import com.example.demo.domain.vo.cash.UserWalletRecordVO;
import com.example.demo.domain.vo.cash.UserWalletVO;
import com.example.demo.domain.vo.cash.*;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -125,4 +122,6 @@ public interface CashCollectionMapper {
// 根据精网号列表查询用户的所有钱包信息 // 根据精网号列表查询用户的所有钱包信息
List<UserWalletVO> selectUserWalletsByJwcodes(@Param("jwcodeList") List<Integer> jwcodeList, List<UserWalletVO> selectUserWalletsByJwcodes(@Param("jwcodeList") List<Integer> jwcodeList,
@Param("market") String market); @Param("market") String market);
// 添加流水--其他收入
void addExFund(@Param("addFundsDTO") CashCollection addFundsDTO);
} }

8
src/main/java/com/example/demo/service/cash/CashCollectionService.java

@ -1,13 +1,11 @@
package com.example.demo.service.cash; package com.example.demo.service.cash;
import com.example.demo.domain.DTO.AddFundsDTO;
import com.example.demo.domain.DTO.PerformanceDTO; import com.example.demo.domain.DTO.PerformanceDTO;
import com.example.demo.domain.entity.CashRecord; import com.example.demo.domain.entity.CashRecord;
import com.example.demo.domain.entity.GOrder; import com.example.demo.domain.entity.GOrder;
import com.example.demo.domain.entity.RechargeActivity; import com.example.demo.domain.entity.RechargeActivity;
import com.example.demo.domain.vo.cash.CashCollection;
import com.example.demo.domain.vo.cash.PerformanceVO;
import com.example.demo.domain.vo.cash.UserWalletRecordVO;
import com.example.demo.domain.vo.cash.UserWalletVO;
import com.example.demo.domain.vo.cash.*;
import com.example.demo.domain.vo.coin.Result; import com.example.demo.domain.vo.coin.Result;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -56,4 +54,6 @@ public interface CashCollectionService {
// 根据精网号和地区查询用户的所有钱包 ID 和金币数量包含用户名和地区分页 // 根据精网号和地区查询用户的所有钱包 ID 和金币数量包含用户名和地区分页
PageInfo<UserWalletVO> selectUserWallets(Integer jwcode, String market, Integer pageNum, Integer pageSize); PageInfo<UserWalletVO> selectUserWallets(Integer jwcode, String market, Integer pageNum, Integer pageSize);
// 添加流水--其他收入
String addExFund(CashCollection addFundsDTO);
} }

26
src/main/java/com/example/demo/serviceImpl/cash/CashCollectionServiceImpl.java

@ -3,6 +3,7 @@ package com.example.demo.serviceImpl.cash;
import com.example.demo.Util.JWTUtil; import com.example.demo.Util.JWTUtil;
import com.example.demo.Util.LanguageTranslationUtil; import com.example.demo.Util.LanguageTranslationUtil;
import com.example.demo.config.RabbitMQConfig; import com.example.demo.config.RabbitMQConfig;
import com.example.demo.domain.DTO.AddFundsDTO;
import com.example.demo.domain.DTO.PerformanceDTO; import com.example.demo.domain.DTO.PerformanceDTO;
import com.example.demo.domain.entity.*; import com.example.demo.domain.entity.*;
import com.example.demo.domain.vo.cash.*; import com.example.demo.domain.vo.cash.*;
@ -682,6 +683,31 @@ public class CashCollectionServiceImpl implements CashCollectionService {
return resultPageInfo; return resultPageInfo;
} }
//新增流水--其他收入
@Override
public String addExFund(CashCollection addFundsDTO) {
if (addFundsDTO.getPerformanceMarket() == null|| addFundsDTO.getPerformanceMarket().isEmpty())
throw new IllegalArgumentException("业绩归属地区不能为空");
if (addFundsDTO.getIncomeType() == null|| addFundsDTO.getIncomeType().isEmpty())
throw new IllegalArgumentException("收入类别不能为空");
if (addFundsDTO.getPayType() == null|| addFundsDTO.getPayType().isEmpty())
throw new IllegalArgumentException("付款方式不能为空");
if (addFundsDTO.getPaymentCurrency() == null)
throw new IllegalArgumentException("币种不能为空");
if (addFundsDTO.getPaymentAmount() == null)
throw new IllegalArgumentException("付款金额不能为空");
//生成订单号后半部分
String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
//构建订单信息
addFundsDTO.setOrderCode("QT_" + orderNumber); //订单号
addFundsDTO.setOrderType(1);
addFundsDTO.setReceivedMarket(addFundsDTO.getPerformanceMarket());
addFundsDTO.setReceivedAmount(addFundsDTO.getPaymentAmount());
cashCollectionMapper.addExFund(addFundsDTO);
return "添加成功";
}
/** /**
* 校验钱包 ID 和到账地区的对应关系 * 校验钱包 ID 和到账地区的对应关系
* @param walletId 钱包 ID * @param walletId 钱包 ID

67
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); 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 // 4. 收集所有需要转换的 regionId currencyId
Set<Integer> regionIds = new HashSet<>(); Set<Integer> regionIds = new HashSet<>();
Set<Integer> currencyIds = new HashSet<>(); Set<Integer> currencyIds = new HashSet<>();
@ -1033,6 +998,38 @@ public class CashRefundServiceImpl implements RefundService {
// 8. 返回分页结果 // 8. 返回分页结果
return new PageInfo<>(list); 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 用户标识 * @param jwcode 用户标识

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

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

5
src/main/resources/cashMapper/CashCollectionMapper.xml

@ -421,6 +421,11 @@
INSERT INTO user_wallet_record (jwcode, wallet_id, type, amount, order_code, description, status, create_time) INSERT INTO user_wallet_record (jwcode, wallet_id, type, amount, order_code, description, status, create_time)
VALUES (#{jwcode}, #{walletId}, #{type}, #{amount}, #{orderCode}, #{description}, #{status}, NOW()) VALUES (#{jwcode}, #{walletId}, #{type}, #{amount}, #{orderCode}, #{description}, #{status}, NOW())
</insert> </insert>
<!--新增流水——其他收入-->
<insert id="addExFund">
insert into cash_record_collection
</insert>
<!-- 根据精网号和钱包 ID 查询用户钱包明细列表 --> <!-- 根据精网号和钱包 ID 查询用户钱包明细列表 -->
<select id="selectWalletRecordsByJwcodeAndWalletId" resultType="com.example.demo.domain.vo.cash.UserWalletRecordVO"> <select id="selectWalletRecordsByJwcodeAndWalletId" resultType="com.example.demo.domain.vo.cash.UserWalletRecordVO">

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

@ -446,6 +446,7 @@
</select> </select>
<select id="selectfunds" resultType="com.example.demo.domain.vo.cash.FundsDTO"> <select id="selectfunds" resultType="com.example.demo.domain.vo.cash.FundsDTO">
SELECT * FROM (
SELECT SELECT
crc.id, crc.id,
crc.jwcode, crc.jwcode,
@ -459,19 +460,20 @@
crc.order_code, crc.order_code,
crc.payment_currency, crc.payment_currency,
ROUND(crc.payment_amount / 100.0, 2) as paymentAmount, ROUND(crc.payment_amount / 100.0, 2) as paymentAmount,
crc.received_currency, crc.received_currency,
ROUND(crc.received_amount / 100.0, 2) as receivedAmount, ROUND(crc.received_amount / 100.0, 2) as receivedAmount,
ROUND(crc.handling_charge / 100.0, 2) as handlingCharge, ROUND(crc.handling_charge / 100.0, 2) as handlingCharge,
ROUND(crc.permanent_gold / 100.0, 2) as permanentGold, ROUND(crc.permanent_gold / 100.0, 2) as permanentGold,
ROUND(crc.free_gold / 100.0, 2) as freeGold, ROUND(crc.free_gold / 100.0, 2) as freeGold,
crc.pay_type, crc.pay_type,
crc.pay_time, crc.pay_time,
crc.status
crc.status,
NULL as refundCurrency,
NULL as refundAmount,
NULL as relatedId,
0 as isRefundRow
FROM cash_record_collection crc FROM cash_record_collection crc
<where>
WHERE 1=1
<if test="jwcode != null"> <if test="jwcode != null">
and crc.jwcode = #{jwcode} and crc.jwcode = #{jwcode}
</if> </if>
@ -508,16 +510,74 @@
#{statuses} #{statuses}
</foreach> </foreach>
</if> </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>
<select id="selectRefundCount" resultType="com.example.demo.domain.vo.cash.FundsDTO"> <select id="selectRefundCount" resultType="com.example.demo.domain.vo.cash.FundsDTO">
select crr.refund_currency, select crr.refund_currency,
crr.refund_amount, crr.refund_amount,

Loading…
Cancel
Save