diff --git a/src/main/java/com/example/demo/controller/cash/CashRefundController.java b/src/main/java/com/example/demo/controller/cash/CashRefundController.java index 355f73d..53f437b 100644 --- a/src/main/java/com/example/demo/controller/cash/CashRefundController.java +++ b/src/main/java/com/example/demo/controller/cash/CashRefundController.java @@ -7,6 +7,7 @@ import com.example.demo.domain.entity.Admin; import com.example.demo.domain.vo.cash.CashRecordDTO; import com.example.demo.domain.vo.cash.CashRecordDone; import com.example.demo.domain.vo.cash.CashRecordRefund; +import com.example.demo.domain.vo.cash.FundsDTO; import com.example.demo.domain.vo.coin.Page; import com.example.demo.domain.vo.coin.RechargeUser; import com.example.demo.domain.vo.coin.Result; @@ -403,10 +404,31 @@ public class CashRefundController { @PostMapping("/funds") - public Result funds(@RequestBody Page page){ - refundService.funds(page.getPageNum(), page.getPageSize(), page.getFundsDTO()); - return Result.success(refundService.funds(page.getPageNum(), page.getPageSize(), page.getFundsDTO())); + public Result funds(@RequestBody Page page, @RequestHeader(defaultValue = "zh_CN") String lang) { + try { + // 解析语言代码 + String languageCode = parseLanguageCode(lang); + + // 如果不是中文环境,将查询条件中的翻译文本转换为中文简体 + if (!"zh".equalsIgnoreCase(languageCode) && !"zh_cn".equalsIgnoreCase(languageCode)) { + convertTranslatedFundsFieldsToChinese(page.getFundsDTO(), languageCode); + } + + Result result = Result.success(refundService.funds(page.getPageNum(), page.getPageSize(), page.getFundsDTO())); + + // 对返回结果进行多语言转换 + if (result.getCode() == 200 && result.getData() instanceof com.github.pagehelper.PageInfo) { + com.github.pagehelper.PageInfo pageInfo = (com.github.pagehelper.PageInfo) result.getData(); + translateFundsDTOs(pageInfo, lang); + } + + return result; + } catch (Exception e) { + String errorMsg = languageTranslationUtil.translate("查询失败", lang); + return Result.error(errorMsg + ": " + e.getMessage()); + } } + /** * 辅助方法:获取用户真实IP(处理反向代理/负载均衡场景) */ @@ -459,6 +481,45 @@ public class CashRefundController { } /** + * 转换资金数据的多语言字段 + */ + private void translateFundsDTOs(com.github.pagehelper.PageInfo pageInfo, String lang) { + if (pageInfo != null && pageInfo.getList() != null) { + for (FundsDTO funds : pageInfo.getList()) { + translateSingleFundsDTO(funds, lang); + } + } + } + + /** + * 转换单个资金数据的多语言字段 + */ + private void translateSingleFundsDTO(FundsDTO funds, String lang) { + if (funds != null) { + // 翻译市场名称 + if (funds.getMarket() != null) { + funds.setMarket(languageTranslationUtil.translate(funds.getMarket(), lang)); + } + // 翻译支付币种 + if (funds.getPaymentCurrency() != null) { + funds.setPaymentCurrency(languageTranslationUtil.translate(funds.getPaymentCurrency(), lang)); + } + // 翻译到账币种 + if (funds.getReceivedCurrency() != null) { + funds.setReceivedCurrency(languageTranslationUtil.translate(funds.getReceivedCurrency(), lang)); + } + // 翻译退款币种 + if (funds.getRefundCurrency() != null) { + funds.setRefundCurrency(languageTranslationUtil.translate(funds.getRefundCurrency(), lang)); + } + // 翻译支付方式 + if (funds.getPayType() != null) { + funds.setPayType(languageTranslationUtil.translate(funds.getPayType(), lang)); + } + } + } + + /** * 解析语言代码 */ private String parseLanguageCode(String langHeader) { @@ -539,4 +600,46 @@ public class CashRefundController { } } } + + /** + * 将资金查询条件中的翻译字段转换为中文简体 + */ + private void convertTranslatedFundsFieldsToChinese(FundsDTO fundsDTO, String languageCode) { + if (fundsDTO != null) { + // 转换市场名称 + if (fundsDTO.getMarket() != null && !fundsDTO.getMarket().isEmpty()) { + String chineseMarket = translationService.findChineseSimplifiedByTranslation( + fundsDTO.getMarket(), languageCode); + fundsDTO.setMarket(chineseMarket); + } + + // 转换支付币种 + if (fundsDTO.getPaymentCurrency() != null && !fundsDTO.getPaymentCurrency().isEmpty()) { + String chinesePaymentCurrency = translationService.findChineseSimplifiedByTranslation( + fundsDTO.getPaymentCurrency(), languageCode); + fundsDTO.setPaymentCurrency(chinesePaymentCurrency); + } + + // 转换到账币种 + if (fundsDTO.getReceivedCurrency() != null && !fundsDTO.getReceivedCurrency().isEmpty()) { + String chineseReceivedCurrency = translationService.findChineseSimplifiedByTranslation( + fundsDTO.getReceivedCurrency(), languageCode); + fundsDTO.setReceivedCurrency(chineseReceivedCurrency); + } + + // 转换退款币种 + if (fundsDTO.getRefundCurrency() != null && !fundsDTO.getRefundCurrency().isEmpty()) { + String chineseRefundCurrency = translationService.findChineseSimplifiedByTranslation( + fundsDTO.getRefundCurrency(), languageCode); + fundsDTO.setRefundCurrency(chineseRefundCurrency); + } + + // 转换支付方式 + if (fundsDTO.getPayType() != null && !fundsDTO.getPayType().isEmpty()) { + String chinesePayType = translationService.findChineseSimplifiedByTranslation( + fundsDTO.getPayType(), languageCode); + fundsDTO.setPayType(chinesePayType); + } + } + } }