Commit 211b316e by zhangxingmin

Merge remote-tracking branch 'origin/dev' into prod

parents 2dbc395a 492c4f21
......@@ -425,7 +425,8 @@ public class ApiCommissionExpectedController {
commissionExpectedQueryRequest.setPolicyNoList(queryPolicyNoList);
commissionExpectedQueryRequest.setQueryFlag(queryFlag);
QueryWrapper<CommissionExpected> queryWrapper = commissionExpectedService.getQueryWrapper(commissionExpectedQueryRequest);
//显式选择需要的字段
queryWrapper.select("expected_amount", "paid_amount","paid_ratio", "commission_ratio", "policy_no","status");
// 先查询所有符合条件的记录ID(用于统计)
List<CommissionExpected> allCommissionExpectedList = commissionExpectedService.list(queryWrapper);
......
......@@ -133,8 +133,8 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
// 查询统计信息
ApiSalarySplitStatisticsDto statisticsDto = new ApiSalarySplitStatisticsDto();
FortuneAccount fortuneAccount = fortuneAccountService.queryOne(request.getFortuneAccountBizId());
// 出账币种
statisticsDto.setBeSplitCurrency(fortuneAccount != null ? fortuneAccount.getCurrency() : "");
// 发放币种
statisticsDto.setBeSplitCurrency(fortuneAccount != null ? fortuneAccount.getPayoutCurrency() : "");
BigDecimal beSplitAmount = BigDecimal.ZERO;
if (fortuneAccount != null) {
......@@ -147,7 +147,7 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal fortuneAmount = fortuneAccount.getHkdAmount() != null ? fortuneAccount.getHkdAmount() : BigDecimal.ZERO;
BigDecimal fortuneAmount = fortuneAccount.getPayoutAmount() != null ? fortuneAccount.getPayoutAmount() : BigDecimal.ZERO;
beSplitAmount = fortuneAmount.subtract(splitTotal);
if (beSplitAmount.compareTo(BigDecimal.ZERO) < 0) {
beSplitAmount = BigDecimal.ZERO; // 防止负数
......@@ -231,7 +231,7 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
}
// 3. 计算剩余可拆金额(账户总额 - 本次拟拆分总额)
BigDecimal fortuneAmount = fortuneAccount.getHkdAmount() != null ? fortuneAccount.getHkdAmount() : BigDecimal.ZERO;
BigDecimal fortuneAmount = fortuneAccount.getPayoutAmount() != null ? fortuneAccount.getPayoutAmount() : BigDecimal.ZERO;
BigDecimal beSplitAmount = fortuneAmount.subtract(splitTotal);
if (beSplitAmount.compareTo(BigDecimal.ZERO) < 0) {
beSplitAmount = BigDecimal.ZERO; // 防止负数
......@@ -239,7 +239,7 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
// 4. 封装响应
ApiQueryRemainingResponse response = new ApiQueryRemainingResponse();
response.setCurrency(fortuneAccount.getCurrency());
response.setCurrency(fortuneAccount.getPayoutCurrency());
response.setFromAmount(beSplitAmount);
return Result.success(response);
}
......@@ -260,7 +260,7 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
//原币种金额
convertRequest.setAmount(request.getFromAmount());
//原币种
convertRequest.setFromCurrency(fortuneAccount.getCurrency());
convertRequest.setFromCurrency(fortuneAccount.getPayoutCurrency());
//目标币种
convertRequest.setToCurrency(request.getToCurrency());
//调用远程转换接口
......@@ -296,11 +296,13 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
// 查询数据
List<ApiSalarySplitSummaryPageDto> dataList = iSalarySplitService.summaryList(request);
log.info("导出-薪资拆分应发信息汇总列表:dataList,{}", JSON.toJSONString(dataList));
Map<String, String> map = getBillOrgDict();
List<ApiSalarySplitSummaryExcelDto> excelDtoList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(dataList)) {
excelDtoList = dataList.stream().map(dto -> {
ApiSalarySplitSummaryExcelDto excelDto = new ApiSalarySplitSummaryExcelDto();
BeanUtils.copyProperties(dto,excelDto);
excelDto.setBillOrg(map != null ? map.get(dto.getBillOrg()) : "");
return excelDto;
}).collect(Collectors.toList());
}
......@@ -309,9 +311,9 @@ public class ApiSalarySplitServiceImpl implements ApiSalarySplitService {
ExportParam exportParam = new ExportParam();
// 指定需要导出的字段(字段名必须与 DTO 中的属性名一致)
exportParam.setFieldNames(Arrays.asList(
"salarySplitNo","businessNo","brokerName","team","fromAmount",
"salarySplitNo","businessNo","brokerName","internalNumber","team","fromAmount",
"currency","exchangeRate","toAmount","toCurrency",
"fortuneAccountMonth","billOrg","hkdAmount"
"fortuneAccountMonth","billOrg","amount"
));
exportParam.setFileName("薪资拆分应发信息汇总");
exportParam.setUploadToOss(true);
......
......@@ -10,40 +10,40 @@ public class ApiSalarySplitSummaryExcelDto {
@Excel(name = "发放编号", orderNum = "1")
private String salarySplitNo;
@Excel(name = "业务编号", orderNum = "1")
@Excel(name = "业务编号", orderNum = "2")
private String businessNo;
@Excel(name = "转介人", orderNum = "2")
@Excel(name = "转介人", orderNum = "3")
private String brokerName;
@Excel(name = "内部编号", orderNum = "3")
@Excel(name = "内部编号", orderNum = "4")
private String internalNumber;
@Excel(name = "所属团队", orderNum = "4")
@Excel(name = "所属团队", orderNum = "5")
private String team;
@Excel(name = "原币种金额", orderNum = "5")
@Excel(name = "原币种金额", orderNum = "6")
private BigDecimal fromAmount;
@Excel(name = "原币种", orderNum = "6")
@Excel(name = "原币种", orderNum = "7")
private String currency;
@Excel(name = "汇率(原币种->目标币种)", orderNum = "7")
@Excel(name = "汇率(原币种->目标币种)", orderNum = "8")
private BigDecimal exchangeRate;
@Excel(name = "目标金额", orderNum = "8")
@Excel(name = "目标金额", orderNum = "9")
private BigDecimal toAmount;
@Excel(name = "目标币种", orderNum = "9")
@Excel(name = "目标币种", orderNum = "10")
private String toCurrency;
@Excel(name = "出账月(实)", orderNum = "10")
@Excel(name = "出账月(实)", orderNum = "11")
private String fortuneAccountMonth;
@Excel(name = "出账机构", orderNum = "11")
@Excel(name = "出账机构", orderNum = "12")
private String billOrg;
@Excel(name = "本期总出账金额(原币种)", orderNum = "12")
private BigDecimal hkdAmount;
@Excel(name = "本期总出账金额(原币种)", orderNum = "13")
private BigDecimal amount;
}
......@@ -94,7 +94,7 @@ public class ApiSalarySplitSummaryPageDto {
private String status;
/**
* 出账总额
* 出账总额(发放币种金额总额)
*/
private BigDecimal amount;
......@@ -104,7 +104,7 @@ public class ApiSalarySplitSummaryPageDto {
private BigDecimal hkdAmount;
/**
* 出账币种(币种)
* 出账币种(发放币种)
*/
private String currency;
......
......@@ -25,11 +25,14 @@ public class FortuneAccountExportDTO implements Serializable {
private String teamBizId;
@ExcelProperty("出账币种")
private String currency;
@ExcelProperty("发放币种")
private String payoutCurrency;
@ExcelProperty("出账总额")
private BigDecimal amount;
@ExcelProperty("发放金额")
private BigDecimal payoutAmount;
@ExcelProperty("出账港币总额")
private BigDecimal hkdAmount;
private List<Fortune> fortuneList;
......
......@@ -54,17 +54,17 @@ public class FortuneAccount implements Serializable {
private String teamBizId;
/**
* 出账币种
* 发放币种
*/
private String currency;
private String payoutCurrency;
/**
* 出账总
* 发放金
*/
private BigDecimal amount;
private BigDecimal payoutAmount;
/**
* 港币出账金额
* 港币金额
*/
private BigDecimal hkdAmount;
......
......@@ -15,6 +15,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yd.base.feign.client.exchangerate.ApiExchangeRateFeignClient;
import com.yd.base.feign.dto.ApiQueryBatchExchangeRateDTO;
import com.yd.base.feign.request.exchangerate.ApiQueryBatchExchangeRateRequest;
import com.yd.base.feign.response.exchangerate.ApiQueryBatchExchangeRateResponse;
import com.yd.common.constant.CommonConstant;
import com.yd.common.constant.RedisConstants;
import com.yd.common.enums.ResultCode;
......@@ -969,34 +972,118 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
return commissionStatistics;
}
// @Override
// public CommissionExpectedStatisticsVO getExpectedStatisticsNew(List<CommissionExpected> allExpectedList) {
// // 空集合直接返回空统计
// if (CollectionUtils.isEmpty(allExpectedList)) {
// return emptyStatistics();
// }
//
// // 查询所有记录(包含失效状态)
//// List<CommissionExpected> allExpectedList = this.listByIds(expectedIds);
//// if (CollectionUtils.isEmpty(allExpectedList)) {
//// return emptyStatistics();
//// }
//
// // 过滤掉已失效的记录(status = "3")
// List<CommissionExpected> validList = allExpectedList.stream()
// .filter(e -> !"3".equals(e.getStatus()))
// .collect(Collectors.toList());
//
// if (validList.isEmpty()) {
// return emptyStatistics();
// }
//
// // 手动聚合计算
// BigDecimal totalAmount = BigDecimal.ZERO;
// BigDecimal totalPaidAmount = BigDecimal.ZERO;
// //累计已入账来佣比例(同保单多个入账项目累计的实佣率)
// BigDecimal totalPaidRatio = BigDecimal.ZERO;
// //累计来佣比例(同保单多个入账项目累计的产品来佣率)
// BigDecimal totalCommissionRatio = BigDecimal.ZERO;
// Set<String> policyNoSet = new HashSet<>();
//
// for (CommissionExpected expected : validList) {
// totalAmount = totalAmount.add(ObjectUtils.defaultIfNull(expected.getExpectedAmount(), BigDecimal.ZERO));
// totalPaidAmount = totalPaidAmount.add(ObjectUtils.defaultIfNull(expected.getPaidAmount(), BigDecimal.ZERO));
// totalPaidRatio = totalPaidRatio.add(ObjectUtils.defaultIfNull(expected.getPaidRatio(), BigDecimal.ZERO));
// totalCommissionRatio = totalCommissionRatio.add(ObjectUtils.defaultIfNull(expected.getCommissionRatio(), BigDecimal.ZERO));
// if (StringUtils.isNotBlank(expected.getPolicyNo())) {
// policyNoSet.add(expected.getPolicyNo());
// }
// }
//
// // 计算总保费(HKD)
// BigDecimal totalPremium = BigDecimal.ZERO;
// BigDecimal fromTotalPremium = BigDecimal.ZERO;
// if (CollectionUtils.isNotEmpty(policyNoSet)) {
// List<Policy> policyList = policyService.lambdaQuery()
// .select(Policy::getPolicyNo,
// Policy::getTotalPaymentPremium,
// Policy::getCurrency)
// .in(Policy::getPolicyNo, policyNoSet)
// .list();
// if (CollectionUtils.isNotEmpty(policyList)) {
// for (Policy policy : policyList) {
// // 获取保单币种到港币的汇率
// BigDecimal rate = queryExchangeRateByFeign(policy.getCurrency(), "HKD");
// if (rate == null) rate = BigDecimal.ONE;
// totalPremium = totalPremium.add(policy.getTotalPaymentPremium().multiply(rate));
// fromTotalPremium = fromTotalPremium.add(policy.getTotalPaymentPremium());
// }
// }
// }
//
// // 组装返回对象
// CommissionExpectedStatisticsVO vo = new CommissionExpectedStatisticsVO();
// vo.setTotalAmount(totalAmount);
// vo.setTotalPaidAmount(totalPaidAmount);
// vo.setPendingPaidAmountS(totalAmount.subtract(totalPaidAmount));
//
// if (totalAmount.compareTo(BigDecimal.ZERO) > 0) {
// BigDecimal ratio = totalPaidAmount.divide(totalAmount, 4, RoundingMode.HALF_UP)
// .multiply(BigDecimal.valueOf(100));
// vo.setPaidAmountRatio(ratio);
// } else {
// vo.setPaidAmountRatio(BigDecimal.ZERO);
// }
//
// // 待入账金额归零 = 已入账来佣比例(累计实佣率)>= 累计产品来佣率
//// if (totalPaidRatio.compareTo(totalCommissionRatio) >= 0){
//// vo.setPendingPaidAmount(BigDecimal.ZERO);
//// }
// vo.setPendingPaidAmount(totalAmount);
// vo.setTotalPolicyCount(policyNoSet.size());
// vo.setTotalPremium(totalPremium);
// vo.setFromTotalPremium(fromTotalPremium);
// vo.setPolicyNos(null); // 原字段可能用于其他逻辑,此处置空
// return vo;
// }
@Override
public CommissionExpectedStatisticsVO getExpectedStatisticsNew(List<CommissionExpected> allExpectedList) {
// 空集合直接返回空统计
long t0 = System.currentTimeMillis();
log.info("getExpectedStatisticsNew 开始, 输入大小: {}", allExpectedList == null ? 0 : allExpectedList.size());
if (CollectionUtils.isEmpty(allExpectedList)) {
return emptyStatistics();
}
// 查询所有记录(包含失效状态)
// List<CommissionExpected> allExpectedList = this.listByIds(expectedIds);
// if (CollectionUtils.isEmpty(allExpectedList)) {
// return emptyStatistics();
// }
// 过滤掉已失效的记录(status = "3")
long t1 = System.currentTimeMillis();
List<CommissionExpected> validList = allExpectedList.stream()
.filter(e -> !"3".equals(e.getStatus()))
.collect(Collectors.toList());
log.info("过滤 status=3 耗时: {} ms, 有效数量: {}", System.currentTimeMillis() - t1, validList.size());
if (validList.isEmpty()) {
return emptyStatistics();
}
long t2 = System.currentTimeMillis();
// 手动聚合计算
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal totalPaidAmount = BigDecimal.ZERO;
//累计已入账来佣比例(同保单多个入账项目累计的实佣率)
BigDecimal totalPaidRatio = BigDecimal.ZERO;
//累计来佣比例(同保单多个入账项目累计的产品来佣率)
BigDecimal totalCommissionRatio = BigDecimal.ZERO;
Set<String> policyNoSet = new HashSet<>();
......@@ -1009,25 +1096,64 @@ public class CommissionExpectedServiceImpl extends ServiceImpl<CommissionExpecte
policyNoSet.add(expected.getPolicyNo());
}
}
log.info("内存聚合耗时: {} ms, 保单数: {}", System.currentTimeMillis() - t2, policyNoSet.size());
// 计算总保费(HKD)
long t3 = System.currentTimeMillis();
// 计算总保费
BigDecimal totalPremium = BigDecimal.ZERO;
BigDecimal fromTotalPremium = BigDecimal.ZERO;
if (CollectionUtils.isNotEmpty(policyNoSet)) {
List<Policy> policyList = policyService.lambdaQuery()
.select(Policy::getPolicyNo,
Policy::getTotalPaymentPremium,
Policy::getCurrency)
.in(Policy::getPolicyNo, policyNoSet)
.list();
log.info("查询保单信息耗时: {} ms, 结果数量: {}", System.currentTimeMillis() - t3, policyList.size());
if (CollectionUtils.isNotEmpty(policyList)) {
// 1. 收集所有需要查询的币种(去重)
Set<String> currencies = policyList.stream()
.map(Policy::getCurrency)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toSet());
// 2. 构建批量查询请求(币种 -> HKD)
ApiQueryBatchExchangeRateRequest batchRequest = new ApiQueryBatchExchangeRateRequest();
List<ApiQueryBatchExchangeRateDTO> dtoList = new ArrayList<>();
for (String currency : currencies) {
ApiQueryBatchExchangeRateDTO dto = new ApiQueryBatchExchangeRateDTO();
dto.setBaseCurrency(currency);
dto.setTargetCurrency("HKD");
dtoList.add(dto);
}
batchRequest.setRateDTOList(dtoList);
// 3. 调用批量汇率接口
Result<ApiQueryBatchExchangeRateResponse> batchResult = apiExchangeRateFeignClient.queryBatchExchangeRate(batchRequest);
Map<String, BigDecimal> rateMap = new HashMap<>();
if (batchResult != null && batchResult.getCode() == 200 && batchResult.getData() != null) {
List<ApiQueryBatchExchangeRateDTO> resultList = batchResult.getData().getRateDTOList();
for (ApiQueryBatchExchangeRateDTO result : resultList) {
if (result.getExchangeRate() != null) {
rateMap.put(result.getBaseCurrency(), result.getExchangeRate());
}
}
}
// 4. 循环计算总保费,从 map 中取汇率
long t4 = System.currentTimeMillis();
for (Policy policy : policyList) {
// 获取保单币种到港币的汇率
BigDecimal rate = queryExchangeRateByFeign(policy.getCurrency(), "HKD");
if (rate == null) rate = BigDecimal.ONE;
BigDecimal rate = rateMap.getOrDefault(policy.getCurrency(), BigDecimal.ONE);
totalPremium = totalPremium.add(policy.getTotalPaymentPremium().multiply(rate));
fromTotalPremium = fromTotalPremium.add(policy.getTotalPaymentPremium());
}
log.info("汇率计算及保费累加耗时: {} ms", System.currentTimeMillis() - t4);
}
}
// 组装返回对象
CommissionExpectedStatisticsVO vo = new CommissionExpectedStatisticsVO();
vo.setTotalAmount(totalAmount);
......
......@@ -167,8 +167,9 @@ public class FortuneAccountServiceImpl extends ServiceImpl<FortuneAccountMapper,
fortuneAccount.setBrokerBizId(accountExportDTO.getBrokerBizId());
fortuneAccount.setTeam(accountExportDTO.getTeam());
fortuneAccount.setTeamBizId(accountExportDTO.getTeamBizId());
fortuneAccount.setCurrency(accountExportDTO.getCurrency());
fortuneAccount.setHkdAmount(accountExportDTO.getAmount());
fortuneAccount.setPayoutCurrency(accountExportDTO.getPayoutCurrency());
fortuneAccount.setPayoutAmount(accountExportDTO.getPayoutAmount());
fortuneAccount.setHkdAmount(accountExportDTO.getHkdAmount());
fortuneAccount.setFortuneAccountDate(this.getActualPayoutDate(accountExportDTO.getActualPayoutDate()));
// 出账状态默认待出账
fortuneAccount.setStatus(FortuneStatusEnum.CHECKED.getItemValue());
......
......@@ -431,7 +431,7 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
for (Map.Entry<String, List<Fortune>> entry : fortuneMap.entrySet()) {
String broker = entry.getKey().split("_")[0];
String actualPayoutDate = entry.getKey().split("_")[1];
String currency = entry.getKey().split("_")[2];
String payoutCurrency = entry.getKey().split("_")[2];
List<Fortune> brokerFortunes = entry.getValue();
FortuneAccountExportDTO accountDTO = new FortuneAccountExportDTO();
......@@ -443,15 +443,19 @@ public class FortuneServiceImpl extends ServiceImpl<FortuneMapper, Fortune>
if (CollUtil.isNotEmpty(brokerFortunes)) {
accountDTO.setTeam(brokerFortunes.get(0).getTeam());
accountDTO.setTeamBizId(brokerFortunes.get(0).getTeamBizId());
accountDTO.setCurrency(currency);
accountDTO.setPayoutCurrency(payoutCurrency);
accountDTO.setActualPayoutDate(LocalDate.parse(actualPayoutDate));
}
// 计算出账总额
BigDecimal totalAmount = brokerFortunes.stream()
.map(Fortune::getCurrentPaymentHkdAmount)
.reduce(BigDecimal.ZERO, BigDecimal::add);
accountDTO.setAmount(totalAmount);
// 计算出账港币总额、发放币种总额
BigDecimal totalHkdAmount = BigDecimal.ZERO;
BigDecimal totalPayoutAmount = BigDecimal.ZERO;
for (Fortune fortune : brokerFortunes) {
totalHkdAmount = totalHkdAmount.add(fortune.getCurrentPaymentHkdAmount());
totalPayoutAmount = totalPayoutAmount.add(fortune.getPayoutAmount());
}
accountDTO.setHkdAmount(totalHkdAmount);
accountDTO.setPayoutAmount(totalPayoutAmount);
// 按fortune项目分组并累加金额
Map<String, BigDecimal> fortuneAmountMap = brokerFortunes.stream()
......
......@@ -51,10 +51,16 @@ public class FortuneAccountVO {
private String team;
/**
* 出账币种
* 发放币种
*/
@Schema(description = "出账币种")
private String currency;
@Schema(description = "发放币种")
private String payoutCurrency;
/**
* 发放金额
*/
@Schema(description = "发放金额")
private BigDecimal payoutAmount;
/**
* 港币出账金额
......
......@@ -11,8 +11,8 @@
<result property="brokerBizId" column="broker_biz_id" />
<result property="team" column="team" />
<result property="teamBizId" column="team_biz_id" />
<result property="currency" column="currency" />
<result property="amount" column="amount" />
<result property="payoutCurrency" column="payout_currency" />
<result property="payoutAmount" column="payout_amount" />
<result property="hkdAmount" column="hkd_amount" />
<result property="status" column="status" />
<result property="fortuneAccountDate" column="fortune_account_date" />
......@@ -27,7 +27,7 @@
<sql id="Base_Column_List">
id,fortune_account_biz_id,broker,broker_biz_id,team,team_biz_id,
currency,amount,hkd_amount,status,fortune_account_date,content,remark,
payout_currency,payout_amount,hkd_amount,status,fortune_account_date,content,remark,
is_deleted,creator_id,updater_id,create_time,update_time
</sql>
</mapper>
......@@ -26,9 +26,9 @@
fa.fortune_account_date,
ss.bill_org,
fa.status,
fa.amount,
fa.payout_amount as amount,
fa.hkd_amount,
fa.currency,
fa.payout_currency as currency,
DATE_FORMAT(fa.fortune_account_date, '%Y%m') as fortune_account_month,
fa.business_no
from salary_split ss
......@@ -109,9 +109,9 @@
fa.fortune_account_date,
ss.bill_org,
fa.status,
fa.amount,
fa.payout_amount as amount,
fa.hkd_amount,
fa.currency,
fa.payout_currency as currency,
DATE_FORMAT(fa.fortune_account_date, '%Y%m') as fortune_account_month,
fa.business_no
from salary_split ss
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment