Browse Source

1.17 资金流水账映射

lijianlin/feature-20260113-现金管理0109
huangqizhen 1 month ago
parent
commit
527efd9304
  1. 16
      src/main/java/com/example/demo/controller/cash/CashRefundController.java
  2. 56
      src/main/java/com/example/demo/controller/coin/ExportController.java
  3. 21
      src/main/java/com/example/demo/domain/DTO/Currency.java
  4. 40
      src/main/java/com/example/demo/domain/DTO/FundDTO.java
  5. 21
      src/main/java/com/example/demo/domain/vo/bean/Region.java
  6. 9
      src/main/java/com/example/demo/domain/vo/cash/FundsDTO.java
  7. 6
      src/main/java/com/example/demo/mapper/coin/RefundMapper.java
  8. 69
      src/main/java/com/example/demo/serviceImpl/cash/CashRefundServiceImpl.java
  9. 20
      src/main/resources/mapper/RefundMapper.xml

16
src/main/java/com/example/demo/controller/cash/CashRefundController.java

@ -498,11 +498,11 @@ public class CashRefundController {
if (funds != null) { if (funds != null) {
// 翻译市场名称 // 翻译市场名称
if (funds.getMarket() != null) { if (funds.getMarket() != null) {
funds.setMarket(languageTranslationUtil.translate(funds.getMarket(), lang));
funds.setMarketName(languageTranslationUtil.translate(funds.getMarketName(), lang));
} }
// 翻译支付币种 // 翻译支付币种
if (funds.getPaymentCurrency() != null) { if (funds.getPaymentCurrency() != null) {
funds.setPaymentCurrency(languageTranslationUtil.translate(funds.getPaymentCurrency(), lang));
funds.setPaymentCurrencyName(languageTranslationUtil.translate(funds.getPaymentCurrencyName(), lang));
} }
// 翻译到账币种 // 翻译到账币种
if (funds.getReceivedCurrency() != null) { if (funds.getReceivedCurrency() != null) {
@ -607,17 +607,17 @@ public class CashRefundController {
private void convertTranslatedFundsFieldsToChinese(FundsDTO fundsDTO, String languageCode) { private void convertTranslatedFundsFieldsToChinese(FundsDTO fundsDTO, String languageCode) {
if (fundsDTO != null) { if (fundsDTO != null) {
// 转换市场名称 // 转换市场名称
if (fundsDTO.getMarket() != null && !fundsDTO.getMarket().isEmpty()) {
if (fundsDTO.getMarketName() != null && !fundsDTO.getMarketName().isEmpty()) {
String chineseMarket = translationService.findChineseSimplifiedByTranslation( String chineseMarket = translationService.findChineseSimplifiedByTranslation(
fundsDTO.getMarket(), languageCode);
fundsDTO.setMarket(chineseMarket);
fundsDTO.getMarketName(), languageCode);
fundsDTO.setMarketName(chineseMarket);
} }
// 转换支付币种 // 转换支付币种
if (fundsDTO.getPaymentCurrency() != null && !fundsDTO.getPaymentCurrency().isEmpty()) {
if (fundsDTO.getPaymentCurrencyName() != null && !fundsDTO.getPaymentCurrencyName().isEmpty()) {
String chinesePaymentCurrency = translationService.findChineseSimplifiedByTranslation( String chinesePaymentCurrency = translationService.findChineseSimplifiedByTranslation(
fundsDTO.getPaymentCurrency(), languageCode);
fundsDTO.setPaymentCurrency(chinesePaymentCurrency);
fundsDTO.getPaymentCurrencyName(), languageCode);
fundsDTO.setPaymentCurrencyName(chinesePaymentCurrency);
} }
// 转换到账币种 // 转换到账币种

56
src/main/java/com/example/demo/controller/coin/ExportController.java

@ -11,6 +11,7 @@ import com.example.demo.domain.DTO.CashDTO;
import com.example.demo.domain.vo.bean.*; import com.example.demo.domain.vo.bean.*;
import com.example.demo.domain.vo.cash.CashCollection; import com.example.demo.domain.vo.cash.CashCollection;
import com.example.demo.domain.vo.cash.CashRecordDTO; import com.example.demo.domain.vo.cash.CashRecordDTO;
import com.example.demo.domain.vo.cash.FundsDTO;
import com.example.demo.domain.vo.cash.PerformanceVO; import com.example.demo.domain.vo.cash.PerformanceVO;
import com.example.demo.domain.vo.coin.ConsumeUser; import com.example.demo.domain.vo.coin.ConsumeUser;
import com.example.demo.domain.vo.coin.RechargeUser; import com.example.demo.domain.vo.coin.RechargeUser;
@ -398,6 +399,36 @@ public class ExportController {
redisLockUtil.unlock(lockKey, requestId); redisLockUtil.unlock(lockKey, requestId);
} }
} }
@PostMapping("/exportFunds")
public Result exportFunds(@Valid @RequestBody FundDTO dto, @RequestHeader(defaultValue = "zh_CN") String lang) {
String lockKey = "export:lock:" + dto.getToken();
String requestId = UUID.randomUUID().toString();
long expireTime = 5000;
dto.setLang(lang);// 设置语言参数
// 解析语言代码
String languageCode = parseLanguageCode(lang);
// 如果非中文环境将查询条件中的翻译文本转换为中文简体
if (!"zh".equalsIgnoreCase(languageCode) && !"zh_cn".equalsIgnoreCase(languageCode)) {
convertFundsTranslatedFieldsToChinese(dto.getFundsDTO(), languageCode);
}
try {
// 尝试获取锁
if (!redisLockUtil.tryLock(lockKey, requestId, expireTime)) {
String errorMsg = languageTranslationUtil.translate("操作太频繁,请稍后重试", lang);
throw new BusinessException(errorMsg);
}
// 执行业务逻辑
// return exportService.addExportPerformance(dto);
return null;
} finally {
// 释放锁
redisLockUtil.unlock(lockKey, requestId);
}
}
/** /**
* 解析语言代码 * 解析语言代码
@ -779,4 +810,29 @@ public class ExportController {
} }
} }
} }
/**
* 将资金流水账中的翻译字段转换为中文简体
*/
private void convertFundsTranslatedFieldsToChinese(FundsDTO fundsDTO, String languageCode) {
if (fundsDTO != null) {
// 翻译地区
if (fundsDTO.getMarketName() != null && !fundsDTO.getMarketName().isEmpty()) {
String chineseMarketName = translationService.findChineseSimplifiedByTranslation(
fundsDTO.getMarketName(), languageCode);
fundsDTO.setMarketName(chineseMarketName);
}
// 翻译付款币种
if (fundsDTO.getPaymentCurrencyName() != null && !fundsDTO.getPaymentCurrencyName().isEmpty()) {
String chinesePaymentCurrency = translationService.findChineseSimplifiedByTranslation(
fundsDTO.getPaymentCurrencyName(), languageCode);
fundsDTO.setPaymentCurrencyName(chinesePaymentCurrency);
}
// 翻译到账币种
if (fundsDTO.getReceivedCurrency() != null && !fundsDTO.getReceivedCurrency().isEmpty()) {
String chineseReceivedCurrency = translationService.findChineseSimplifiedByTranslation(
fundsDTO.getReceivedCurrency(), languageCode);
fundsDTO.setReceivedCurrency(chineseReceivedCurrency);
}
}
}
} }

21
src/main/java/com/example/demo/domain/DTO/Currency.java

@ -0,0 +1,21 @@
package com.example.demo.domain.DTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @program: GOLD
* @ClassName Currency
* @description:
* @author: huangqizhen
* @create: 202601-18 13:24
* @Version 1.0
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Currency {
private Integer id;
private String name;
}

40
src/main/java/com/example/demo/domain/DTO/FundDTO.java

@ -0,0 +1,40 @@
package com.example.demo.domain.DTO;
import com.example.demo.domain.vo.cash.FundsDTO;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @program: GOLD
* @ClassName FundsDTO
* @description:
* @author: huangqizhen
* @create: 202601-18 09:23
* @Version 1.0
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FundDTO {
private String token;
private String url = "";
private String fileName = "";
private Integer sort = 0;
private String field = "";
private Integer account;
private Integer type = 15; //类型
private Integer state = 0; //状态
private String text = ""; //关键词搜索
private Integer dataNum = 0;
private String deptid = "";
private FundsDTO fundsDTO;
private String lang;
@NotNull(message = "page不能为空")
private Integer page = 1;
@NotNull(message = "pageSize不能为空")
private Integer pageSize = 5000;
}

21
src/main/java/com/example/demo/domain/vo/bean/Region.java

@ -0,0 +1,21 @@
package com.example.demo.domain.vo.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @program: GOLD
* @ClassName Region
* @description:
* @author: huangqizhen
* @create: 202601-18 13:18
* @Version 1.0
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Region {
private Integer id;
private String name;
}

9
src/main/java/com/example/demo/domain/vo/cash/FundsDTO.java

@ -25,10 +25,11 @@ public class FundsDTO {
private Integer id; private Integer id;
private Integer jwcode; private Integer jwcode;
private String name; private String name;
private String market;
private Integer market;
private String marketName;
private List<String> markets; private List<String> markets;
private String orderCode; private String orderCode;
private String paymentCurrency;
private Integer paymentCurrency;
private BigDecimal paymentAmount; private BigDecimal paymentAmount;
private String receivedCurrency; private String receivedCurrency;
private BigDecimal receivedAmount; private BigDecimal receivedAmount;
@ -48,4 +49,8 @@ public class FundsDTO {
private String refundCurrency; private String refundCurrency;
private BigDecimal refundAmount; private BigDecimal refundAmount;
private Integer relatedId; private Integer relatedId;
private String token;
private String lang;
private String paymentCurrencyName;
private PerformanceVO performanceVO;
} }

6
src/main/java/com/example/demo/mapper/coin/RefundMapper.java

@ -1,11 +1,14 @@
package com.example.demo.mapper.coin; package com.example.demo.mapper.coin;
import com.example.demo.domain.DTO.Currency;
import com.example.demo.domain.entity.UserGoldRecord; import com.example.demo.domain.entity.UserGoldRecord;
import com.example.demo.domain.vo.bean.Region;
import com.example.demo.domain.vo.coin.ConsumeUser; import com.example.demo.domain.vo.coin.ConsumeUser;
import com.example.demo.domain.vo.coin.Gold; import com.example.demo.domain.vo.coin.Gold;
import com.example.demo.domain.vo.coin.RefundUser; import com.example.demo.domain.vo.coin.RefundUser;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -38,4 +41,7 @@ public interface RefundMapper {
Gold sumGold(RefundUser refundUser); Gold sumGold(RefundUser refundUser);
List<Region> selectByIds(ArrayList<Integer> regionIds);
List<Currency> selectByCIds(ArrayList<Integer> currencyIds);
} }

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

@ -8,6 +8,7 @@ import com.example.demo.config.RabbitMQConfig;
import com.example.demo.domain.entity.Market; import com.example.demo.domain.entity.Market;
import com.example.demo.domain.entity.User; import com.example.demo.domain.entity.User;
import com.example.demo.domain.entity.UserGoldRecord; import com.example.demo.domain.entity.UserGoldRecord;
import com.example.demo.domain.vo.bean.Region;
import com.example.demo.domain.vo.cash.*; import com.example.demo.domain.vo.cash.*;
import com.example.demo.domain.vo.coin.Messages; import com.example.demo.domain.vo.coin.Messages;
import com.example.demo.domain.vo.coin.Result; import com.example.demo.domain.vo.coin.Result;
@ -25,6 +26,7 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import com.example.demo.domain.DTO.Currency;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -582,52 +584,85 @@ CashRecordDone cashRecordDone1 = new CashRecordDone();
@Override @Override
public PageInfo<FundsDTO> funds(Integer pageNum, Integer pageSize, FundsDTO fundsDTO) { public PageInfo<FundsDTO> funds(Integer pageNum, Integer pageSize, FundsDTO fundsDTO) {
// 1. 分页查询主数据
// 1. 分页查询主数据
PageHelper.startPage(pageNum, pageSize); PageHelper.startPage(pageNum, pageSize);
if(fundsDTO.getStatuses()==null||fundsDTO.getStatuses().isEmpty()){
List<Integer> list_a = Arrays.asList(4,6);
fundsDTO.setStatuses(list_a);
}
if (fundsDTO.getStatuses() == null || fundsDTO.getStatuses().isEmpty()) {
fundsDTO.setStatuses(Arrays.asList(4, 6));
}
List<FundsDTO> list = cashRefundMapper.selectfunds(fundsDTO); List<FundsDTO> list = cashRefundMapper.selectfunds(fundsDTO);
// 2. 收集 status == 6 的记录 ID注意status int
// 2. 收集 status == 6 的记录 ID
List<Integer> needQueryIds = new ArrayList<>(); List<Integer> needQueryIds = new ArrayList<>();
for (FundsDTO dto : list) { for (FundsDTO dto : list) {
if (dto.getStatus() != null && dto.getStatus()==6) {
if (dto.getStatus() != null && dto.getStatus() == 6) {
needQueryIds.add(dto.getId()); needQueryIds.add(dto.getId());
} }
} }
// 3. 批量查询额外信息关键必须有返回对象的方法
// 3. 批量查询 refundDetail 信息用于负数处理
if (!needQueryIds.isEmpty()) { if (!needQueryIds.isEmpty()) {
// 👇 请替换为你的实际 Mapper 方法返回 List<RefundDetailDTO>
List<FundsDTO> detailList = cashRefundMapper.selectRefundCount(needQueryIds); List<FundsDTO> detailList = cashRefundMapper.selectRefundCount(needQueryIds);
// 4. 构建 HashMap: id -> RefundDetailDTO
Map<Integer, FundsDTO> detailMap = new HashMap<>(); Map<Integer, FundsDTO> detailMap = new HashMap<>();
for (FundsDTO detail : detailList) { for (FundsDTO detail : detailList) {
detailMap.put(detail.getRelatedId(), detail); // 假设 detail getId()
// 假设 detail.getRelatedId() 对应主表的 id
detailMap.put(detail.getRelatedId(), detail);
} }
// 5. 回填到账金额和到账币种
// 回填 refundAmount取负 refundCurrency
for (FundsDTO dto : list) { for (FundsDTO dto : list) {
if (dto.getStatus() != null && dto.getStatus()==6) {
if (dto.getStatus() != null && dto.getStatus() == 6) {
FundsDTO detail = detailMap.get(dto.getId()); FundsDTO detail = detailMap.get(dto.getId());
if (detail != null) { if (detail != null) {
// 将到账金额转为负数正数 负数
BigDecimal amount = detail.getRefundAmount(); BigDecimal amount = detail.getRefundAmount();
if (amount != null) { if (amount != null) {
dto.setRefundAmount(amount.negate()); // 👈 关键负数
dto.setRefundAmount(amount.negate()); // 转为负数
} else { } else {
dto.setRefundAmount(null); // 或设为 BigDecimal.ZERO根据业务需求
dto.setRefundAmount(null); // 或设为 BigDecimal.ZERO
} }
// 币种保持不变
dto.setRefundCurrency(detail.getRefundCurrency()); dto.setRefundCurrency(detail.getRefundCurrency());
} }
} }
} }
} }
// 4. 收集所有需要转换的 regionId currencyId
Set<Integer> regionIds = new HashSet<>();
Set<Integer> currencyIds = new HashSet<>();
for (FundsDTO dto : list) {
if (dto.getMarket() != null) {
regionIds.add(dto.getMarket());
}
if (dto.getPaymentCurrency() != null) {
currencyIds.add(dto.getPaymentCurrency());
}
}
// 5. 批量查询地区字典
Map<Integer, String> regionMap = new HashMap<>();
if (!regionIds.isEmpty()) {
List<Region> regions = refundMapper.selectByIds(new ArrayList<>(regionIds));
for (Region region : regions) {
regionMap.put(region.getId(), region.getName());
}
}
// 6. 批量查询币种字典
Map<Integer, String> currencyMap = new HashMap<>();
if (!currencyIds.isEmpty()) {
List<Currency> currencies = refundMapper.selectByCIds(new ArrayList<>(currencyIds));
for (Currency currency : currencies) {
currencyMap.put(currency.getId(), currency.getName()); // getCode()按需调整
}
}
// 7. 回填地区名称和币种名称到 DTO
for (FundsDTO dto : list) {
dto.setMarketName(regionMap.get(dto.getMarket()));
dto.setPaymentCurrencyName(currencyMap.get(dto.getPaymentCurrency()));
}
// 8. 返回分页结果
return new PageInfo<>(list); return new PageInfo<>(list);
} }

20
src/main/resources/mapper/RefundMapper.xml

@ -291,4 +291,24 @@
ugr.create_time DESC ugr.create_time DESC
</trim> </trim>
</select> </select>
<select id="selectByIds" resultType="com.example.demo.domain.vo.bean.Region">
select id, name
from market
<where>
id IN
<foreach item="id" collection="regionIds" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>
<select id="selectByCIds" resultType="com.example.demo.domain.DTO.Currency">
select id,rate_name as name
from rate
<where>
id IN
<foreach item="id" collection="currencyIds" separator="," open="(" close=")">
#{id}
</foreach>
</where>
</select>
</mapper> </mapper>
Loading…
Cancel
Save