Commit b5d4e0ce by yao.xiao

保留批次

parent e67e8d7f
...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.security.auth.login.LoginContext;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
...@@ -101,6 +102,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -101,6 +102,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
private SendService sendService; private SendService sendService;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public CommissionPayoutStatusUpdateResponseVO commissionPayoutStatusUpdate(CommissionPayoutStatusUpdateRequestVO requestVO) { public CommissionPayoutStatusUpdateResponseVO commissionPayoutStatusUpdate(CommissionPayoutStatusUpdateRequestVO requestVO) {
CommissionPayoutStatusUpdateResponseVO responseVO = new CommissionPayoutStatusUpdateResponseVO(); CommissionPayoutStatusUpdateResponseVO responseVO = new CommissionPayoutStatusUpdateResponseVO();
CommonResult commonResult = check(requestVO); CommonResult commonResult = check(requestVO);
...@@ -283,7 +285,9 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -283,7 +285,9 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
fortune.setCommissionPayoutStatus(paymentStatus); fortune.setCommissionPayoutStatus(paymentStatus);
fortune.setCommissionPayoutBy(loginId); fortune.setCommissionPayoutBy(loginId);
fortune.setCommissionPayoutAt(new Date()); fortune.setCommissionPayoutAt(new Date());
if (!CommonUtil.isNullOrZero(payoutBatchId)){
fortune.setPayoutBatchId(payoutBatchId); fortune.setPayoutBatchId(payoutBatchId);
}
Long withdrawId = fortune.getWithdrawedId(); Long withdrawId = fortune.getWithdrawedId();
fortune.setWithdrawedId(null); fortune.setWithdrawedId(null);
fortune.setFortunePayedId(null); fortune.setFortunePayedId(null);
...@@ -324,23 +328,29 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -324,23 +328,29 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
Map<Long,List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(fortunes,"customerId"); Map<Long,List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(fortunes,"customerId");
customerIds = customerFortuneMap.keySet(); customerIds = customerFortuneMap.keySet();
} }
//如果customerIds为null,则此次需修改的withdraw提现金额为0
if (customerIds.isEmpty()){
//修改withdraws/pays提现金额为0
updateWithdrawAmountToZero(withdraws,pays,loginId);
return;
}
//查询customerIds的基本财富信息(历史累积财富 已退保财富 已提现财富 等) customerId CustomerFortuneStatisticalInfo //查询customerIds的基本财富信息(历史累积财富 已退保财富 已提现财富 等) customerId CustomerFortuneStatisticalInfo
Map<Long,CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(customerIds); Map<Long,CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(customerIds);
//按withdrawedId经行整理 //按withdrawedId经行整理
Map<Long, List<AclCustomerFortune>> withdrawsFortunes = changeCustomerFortunesByFieldName(fortunes,"withdrawedId"); Map<Long, List<AclCustomerFortune>> withdrawsFortunes = changeCustomerFortunesByFieldName(fortunes,"withdrawedId");
for (AclCustomerFortuneWithdraw withdraw : withdraws) {
for(Map.Entry<Long, List<AclCustomerFortune>> withdrawsFortune: withdrawsFortunes.entrySet()){
//withdrawId //withdrawId
Long withdrawId = withdrawsFortune.getKey(); Long withdrawId = withdraw.getId();
//需要重新计算withdraw根据的fortune记录 //需要重新计算withdraw根据的fortune记录
List<AclCustomerFortune> fortuneWithdraw = withdrawsFortune.getValue(); List<AclCustomerFortune> fortuneWithdraw = withdrawsFortunes.get(withdrawId);
if (fortuneWithdraw.isEmpty()) {
updateWithdrawAmountToZero(withdraws, pays, loginId);
continue;
}
//统计此次提现总金额 //统计此次提现总金额
BigDecimal withdrawAmount = fortuneWithdraw.stream() BigDecimal withdrawAmount = fortuneWithdraw.stream()
.map(item -> item.getReferralAmount() == null ? BigDecimal.ZERO : item.getReferralAmount()) .map(item -> item.getReferralAmount() == null ? BigDecimal.ZERO : item.getReferralAmount())
.reduce(BigDecimal.ZERO, BigDecimal::add); .reduce(BigDecimal.ZERO, BigDecimal::add);
//找到对应的withdraw记录
for (AclCustomerFortuneWithdraw withdraw: withdraws){
if (withdraw.getId().equals(withdrawId)){
//基本财富信息(历史累积财富 已退保财富 已提现财富 等) //基本财富信息(历史累积财富 已退保财富 已提现财富 等)
CustomerFortuneStatisticalInfo customerFortuneStatisticalInfo = customerFortuneStatisticalMap.get(withdraw.getCustomerId()); CustomerFortuneStatisticalInfo customerFortuneStatisticalInfo = customerFortuneStatisticalMap.get(withdraw.getCustomerId());
//根据customerId查询未提现财富金额 可提现财富+不可体现财富+需修改的withdraw原提现金额 //根据customerId查询未提现财富金额 可提现财富+不可体现财富+需修改的withdraw原提现金额
...@@ -351,7 +361,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -351,7 +361,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
BigDecimal withdrawAfterAmount = withdrawBeforeAmount.subtract(withdrawAmount); BigDecimal withdrawAfterAmount = withdrawBeforeAmount.subtract(withdrawAmount);
//重新计算税额 //重新计算税额
BigDecimal yearDrawnFortune = customerFortuneStatisticalInfo.getYearDrawnFortune().subtract(withdraw.getWithdrawAmount()); BigDecimal yearDrawnFortune = customerFortuneStatisticalInfo.getYearDrawnFortune().subtract(withdraw.getWithdrawAmount());
BigDecimal taxAmount = calcuPersonalTax(withdrawAmount,yearDrawnFortune); BigDecimal taxAmount = calcuPersonalTax(withdrawAmount, yearDrawnFortune);
//可提现金额 //可提现金额
BigDecimal paidAmount = withdrawAmount.subtract(taxAmount); BigDecimal paidAmount = withdrawAmount.subtract(taxAmount);
withdraw.setWithdrawBeforeAmount(withdrawBeforeAmount); withdraw.setWithdrawBeforeAmount(withdrawBeforeAmount);
...@@ -362,20 +372,18 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -362,20 +372,18 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
withdraw.setCreatedBy(loginId); withdraw.setCreatedBy(loginId);
withdraw.setCreatedAt(new Date()); withdraw.setCreatedAt(new Date());
//找到对应的pay记录 //找到对应的pay记录
for (AclCustomerFortunePay pay: pays){ for (AclCustomerFortunePay pay : pays) {
if (pay.getWithdrawId().equals(withdrawId)){ if (pay.getWithdrawId().equals(withdrawId)) {
pay.setWithdrawAmount(withdrawAmount); pay.setWithdrawAmount(withdrawAmount);
pay.setPayAmount(paidAmount); pay.setPayAmount(paidAmount);
pay.setTaxAmount(taxAmount); pay.setTaxAmount(taxAmount);
pay.setUpdatedBy(loginId); pay.setUpdatedBy(loginId);
pay.setUpdatedAt(new Date()); pay.setUpdatedAt(new Date());
fortuneWithdraw.forEach(f->f.setFortunePayedId(pay.getId())); fortuneWithdraw.forEach(f -> f.setFortunePayedId(pay.getId()));
fortuneUpdates.addAll(fortuneWithdraw); fortuneUpdates.addAll(fortuneWithdraw);
} }
} }
} }
}
}
//批量更新withdraw记录 //批量更新withdraw记录
customerFortuneWithdrawDalService.updateAll(withdraws); customerFortuneWithdrawDalService.updateAll(withdraws);
// withdraws.forEach(p-> System.out.println(p.toString())); // withdraws.forEach(p-> System.out.println(p.toString()));
...@@ -386,6 +394,28 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService { ...@@ -386,6 +394,28 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
customerFortuneDalService.updateBatch(fortuneUpdates); customerFortuneDalService.updateBatch(fortuneUpdates);
} }
private void updateWithdrawAmountToZero(List<AclCustomerFortuneWithdraw> withdraws, List<AclCustomerFortunePay> pays,Long loginId) {
withdraws.forEach(w->{
w.setWithdrawAmount(BigDecimal.ZERO);
w.setWithdrawAfterAmount(w.getWithdrawBeforeAmount());
w.setCreatedAt(new Date());
w.setCreatedBy(loginId);
w.setTaxAmount(BigDecimal.ZERO);
w.setPaidAmount(BigDecimal.ZERO);
});
pays.forEach(pay->{
pay.setWithdrawAmount(BigDecimal.ZERO);
pay.setPayAmount(BigDecimal.ZERO);
pay.setTaxAmount(BigDecimal.ZERO);
pay.setUpdatedBy(loginId);
pay.setUpdatedAt(new Date());
});
//批量更新withdraw记录
customerFortuneWithdrawDalService.updateAll(withdraws);
//批量更新pay记录
customerFortunePayDalService.updateAll(pays);
}
private void insertWithdraw(Map<Long, List<AclCustomerFortune>> newCustomerWithdrawMap,Long loginId) { private void insertWithdraw(Map<Long, List<AclCustomerFortune>> newCustomerWithdrawMap,Long loginId) {
if (newCustomerWithdrawMap.isEmpty()){ if (newCustomerWithdrawMap.isEmpty()){
return; return;
......
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