Commit 85e72158 by jianan

4and5-保单发佣明细报表14

parent 440785ab
......@@ -62,10 +62,12 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
private AclUserDALService userDalService;
@Autowired
private AclPractitionerSubordinateSystemDALService aclPractitionerSubordinateSystemDalService;
@Autowired
public void setAclCustomerFortuneDalService(AclCustomerFortuneDALService customerFortuneDalService) {
this.customerFortuneDalService = customerFortuneDalService;
}
@Autowired
public void setAclCustomerFortuneWithdrawDalService(AclCustomerFortuneWithdrawDALService customerFortuneWithdrawDalService) {
this.customerFortuneWithdrawDalService = customerFortuneWithdrawDalService;
......@@ -77,29 +79,30 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
@Autowired
public void setAgmsFortuneDalService(AgmsFortuneDALService agmsFortuneDalService){
public void setAgmsFortuneDalService(AgmsFortuneDALService agmsFortuneDalService) {
this.agmsFortuneDalService = agmsFortuneDalService;
}
@Autowired
public void setSystemConfigService(SystemConfigService systemConfigService){
public void setSystemConfigService(SystemConfigService systemConfigService) {
this.systemConfigService = systemConfigService;
}
@Autowired
public void setAclCustomerFortunePayoutBatchDALService(AclCustomerFortunePayoutBatchDALService customerFortunePayoutBatchDalService){
public void setAclCustomerFortunePayoutBatchDALService(AclCustomerFortunePayoutBatchDALService customerFortunePayoutBatchDalService) {
this.customerFortunePayoutBatchDalService = customerFortunePayoutBatchDalService;
}
@Autowired
public void setAclUserDALService(AclUserDALService userDalService){
public void setAclUserDALService(AclUserDALService userDalService) {
this.userDalService = userDalService;
}
@Autowired
public void setAclCustomerFortuneStatisticDALService(AclCustomerFortuneStatisticDALService customerFortuneStatisticDalService){
public void setAclCustomerFortuneStatisticDALService(AclCustomerFortuneStatisticDALService customerFortuneStatisticDalService) {
this.customerFortuneStatisticDalService = customerFortuneStatisticDalService;
}
@Autowired
private PoOrderDALService poOrderDALService;
@Autowired
......@@ -126,7 +129,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
List<AclCustomerFortune> customerFortunes = customerFortuneDalService.findByIds(fortuneIds);
//已作废的记录不能修改状态
for (AclCustomerFortune customerFortune: customerFortunes) {
for (AclCustomerFortune customerFortune : customerFortunes) {
if ("0".equals(customerFortune.getStatus())) {
responseVO.setCommonResult(new CommonResult(false, ZHBErrorConfig.getErrorInfo("830039")));
return responseVO;
......@@ -154,8 +157,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
CommonResult commonResult = new CommonResult();
boolean success = true;
String message = ZHBErrorConfig.getErrorInfo("800000");
if (("2").equals(requestVO.getPaymentStatus())){
if (CommonUtil.isNullOrBlank(requestVO.getPayoutBatch())){
if (("2").equals(requestVO.getPaymentStatus())) {
if (CommonUtil.isNullOrBlank(requestVO.getPayoutBatch())) {
message = ZHBErrorConfig.getErrorInfo("830021");
success = false;
}
......@@ -166,7 +169,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
Long[] fortuneIds = requestVO.getFortuneIds();
List<AclCustomerFortuneWithdraw> withdraws = customerFortuneWithdrawDalService.findByFortuneIds(fortuneIds);
for (AclCustomerFortuneWithdraw withdraw : withdraws) {
if (withdraw.getIsPaid()==1){
if (withdraw.getIsPaid() == 1) {
message = ZHBErrorConfig.getErrorInfo("830024");
commonResult.setSuccess(false);
commonResult.setMessage(message);
......@@ -179,11 +182,11 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
private Long findPayoutBatchIdByPayoutBatch(String payoutBatch, Long loginId) {
if (CommonUtil.isNullOrBlank(payoutBatch)){
if (CommonUtil.isNullOrBlank(payoutBatch)) {
return null;
}
AclCustomerFortunePayoutBatch customerFortunePayoutBatch = customerFortunePayoutBatchDalService.findByPayoutYearmonth(payoutBatch);
if (customerFortunePayoutBatch == null){
if (customerFortunePayoutBatch == null) {
customerFortunePayoutBatch = new AclCustomerFortunePayoutBatch();
customerFortunePayoutBatch.setPayoutYearmonth(payoutBatch);
customerFortunePayoutBatch.setCreatedBy(loginId);
......@@ -196,23 +199,23 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
@Override
public void canPaymentUpDate(String paymentStatus, Long payoutBatchId , Long loginId, List<AclCustomerFortune> customerFortunes) {
public void canPaymentUpDate(String paymentStatus, Long payoutBatchId, Long loginId, List<AclCustomerFortune> customerFortunes) {
System.out.println("canPaymentUpDate");
//将查询出来的财富列表根据customerId经行分类
Map<Long,List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(customerFortunes,"customerId");
Map<Long, List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(customerFortunes, "customerId");
//获得所有需要修改佣金发放状的customerIds
Set<Long> customerIds = customerFortuneMap.keySet();
//可直接修改的withdraw记录
Map<Long,Long> customerWithdrawMap = directModificationCustomerWithdrawMap(customerIds, payoutBatchId);
Map<Long, Long> customerWithdrawMap = directModificationCustomerWithdrawMap(customerIds, payoutBatchId);
//没有最后一笔提现 记录客户信息和此次提现的财富记录 customerId fortunes
Map<Long,List<AclCustomerFortune>> newCustomerWithdrawMap = new HashMap<>(16);
Map<Long, List<AclCustomerFortune>> newCustomerWithdrawMap = new HashMap<>(16);
//可直接修改的fortune记录(需修改佣金发放状态)
List<AclCustomerFortune> fortuneUpdates = new ArrayList<>();
//记录可直接修改的fortune对应的withdraw
List<Long> withdrawUpdateIds = new ArrayList<>();
for(Map.Entry<Long, List<AclCustomerFortune>> customerFortune:customerFortuneMap.entrySet()){
for (Map.Entry<Long, List<AclCustomerFortune>> customerFortune : customerFortuneMap.entrySet()) {
//获取需要修改佣金发放状态的经纪人
Long customerId = customerFortune.getKey();
//此customer最后一笔提现记录id
......@@ -222,7 +225,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//获取休要修改的佣金发放状态的财富记录
List<AclCustomerFortune> fortunes = customerFortune.getValue();
//判断这些财富记录中佣金发放状态和要修改的状态是否一致,如一致,则不需要修改
for(AclCustomerFortune fortune : fortunes) {
for (AclCustomerFortune fortune : fortunes) {
//不一致,进行修改,并保存需修改的fortune和记录需要新生成的fortune
if (!paymentStatus.equals(fortune.getStatus())) {
fortune.setCommissionPayoutStatus(paymentStatus);
......@@ -230,18 +233,18 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
fortune.setCommissionPayoutBy(loginId);
fortune.setCommissionPayoutAt(new Date());
fortune.setPayoutBatchId(payoutBatchId);
if (CommonUtil.isNullOrZero(withdrawId)){
if (CommonUtil.isNullOrZero(withdrawId)) {
//需生成新的withdraw
newFortunes.add(fortune);
}else {
} else {
//可直接修改fortune
fortune.setWithdrawedId(withdrawId);
fortuneUpdates.add(fortune);
withdrawUpdateIds.add(withdrawId);
}
}else {
} else {
//paymentStatus一致,都是可发放,判断其支付批次,是否一致,一致不需要修改,不一致需要修改两笔withdraw
if (!payoutBatchId.equals(fortune.getPayoutBatchId())){
if (!payoutBatchId.equals(fortune.getPayoutBatchId())) {
//订单原来所属withdraw
withdrawUpdateIds.add(fortune.getWithdrawedId());
fortune.setCommissionPayoutAt(new Date());
......@@ -249,12 +252,12 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
fortune.setPayoutBatchId(payoutBatchId);
fortune.setStatus("2");
fortune.setCommissionPayoutStatus("2");
if (CommonUtil.isNullOrZero(withdrawId)){
if (CommonUtil.isNullOrZero(withdrawId)) {
//需生成新的withdraw
newFortunes.add(fortune);
fortune.setWithdrawedId(null);
fortuneUpdates.add(fortune);
}else {
} else {
//可直接修改fortune
fortune.setWithdrawedId(withdrawId);
fortuneUpdates.add(fortune);
......@@ -264,8 +267,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
}
//记录客户信息和此次提现的财富记录
if (!newFortunes.isEmpty()){
newCustomerWithdrawMap.put(customerId,newFortunes);
if (!newFortunes.isEmpty()) {
newCustomerWithdrawMap.put(customerId, newFortunes);
}
}
......@@ -278,25 +281,25 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
//重新计算受到影响的withdraw
withdrawUpdateIds.removeAll(Collections.singleton(null));
if (!withdrawUpdateIds.isEmpty()){
if (!withdrawUpdateIds.isEmpty()) {
Collections.sort(withdrawUpdateIds);
}
recalculateWithdraw(withdrawUpdateIds,customerIds,loginId);
recalculateWithdraw(withdrawUpdateIds, customerIds, loginId);
//更新生成新的提现记录,及支付记录,fortune中记录对应的withdraw.id
insertWithdraw(newCustomerWithdrawMap,loginId);
insertWithdraw(newCustomerWithdrawMap, loginId);
}
private Map<Long, Long> directModificationCustomerWithdrawMap(Set<Long> customerIds, Long payoutBatchId) {
//查询这些customerId是这个批次的最后一笔未完成的提现记录(ag_acl_customer_fortune_withdraw)
Map<Long,Long> customerWithdrawNoPayMap = customerFortuneWithdrawDalService.findFinalWithdrawNoPayByCustomerIds(customerIds, payoutBatchId);
Map<Long, Long> customerWithdrawNoPayMap = customerFortuneWithdrawDalService.findFinalWithdrawNoPayByCustomerIds(customerIds, payoutBatchId);
//查询这些customerId最后一笔已完成的提现记录(ag_acl_customer_fortune_withdraw)
// Map<Long,Long> customerWithdrawPayMap = customerFortuneWithdrawDalService.findFinalWithdrawPayByCustomerIds(customerIds);
Map<Long,Long> customerWithdrawMap = new HashMap<>(16);
Map<Long, Long> customerWithdrawMap = new HashMap<>(16);
//循环未完成记录,并于已完成的记录经行比较,如果未完成的id大于已完成的,则可以直接修改withdraw;如果未完成的id小于已完成的id,则需要生成新的withdraw
for (Map.Entry<Long,Long> customerWithdrawNoPay: customerWithdrawNoPayMap.entrySet()){
for (Map.Entry<Long, Long> customerWithdrawNoPay : customerWithdrawNoPayMap.entrySet()) {
// Long payWithdrewId = customerWithdrawPayMap.get(customerWithdrawNoPay.getKey());
// if (CommonUtil.isNullOrZero(payWithdrewId)){
customerWithdrawMap.put(customerWithdrawNoPay.getKey(),customerWithdrawNoPay.getValue());
customerWithdrawMap.put(customerWithdrawNoPay.getKey(), customerWithdrawNoPay.getValue());
continue;
// }
// if (BigDecimal.valueOf(payWithdrewId).compareTo(BigDecimal.valueOf(customerWithdrawNoPay.getValue())) > 0){
......@@ -307,13 +310,13 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
return customerWithdrawMap;
}
private void noPaymentUpDate(String paymentStatus,Long payoutBatchId, Long loginId, List<AclCustomerFortune> customerFortunes) {
private void noPaymentUpDate(String paymentStatus, Long payoutBatchId, Long loginId, List<AclCustomerFortune> customerFortunes) {
System.out.println("noPaymentUpDate");
//需要修改的fortune记录(需修改佣金发放状态)
List<AclCustomerFortune> fortuneUpdates = new ArrayList<>();
//需要重新计算的withdraw.id
List<Long> withdrawUpdateIds = new ArrayList<>();
for(AclCustomerFortune fortune : customerFortunes){
for (AclCustomerFortune fortune : customerFortunes) {
//不一致,进行修改,并保存需修改的fortune和需重新计算的withdrawIds
if (!paymentStatus.equals(fortune.getStatus())) {
if ("0".equals(paymentStatus)) {
......@@ -342,15 +345,15 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//批量更新需要修改的fortune记录
customerFortuneDalService.updateBatch(fortuneUpdates);
//重新计算受到影响的withdraw
if (!withdrawUpdateIds.isEmpty()){
if (!withdrawUpdateIds.isEmpty()) {
Collections.sort(withdrawUpdateIds);
}
recalculateWithdraw(withdrawUpdateIds,null,loginId);
recalculateWithdraw(withdrawUpdateIds, null, loginId);
}
private void recalculateWithdraw(List<Long> withdrawUpdateIds,Set<Long> customerIds,Long loginId) {
private void recalculateWithdraw(List<Long> withdrawUpdateIds, Set<Long> customerIds, Long loginId) {
//重新统计提现记录
if (withdrawUpdateIds.isEmpty()){
if (withdrawUpdateIds.isEmpty()) {
return;
}
System.out.println("recalculateWithdraw");
......@@ -365,20 +368,20 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
// withdraws.forEach(p-> System.out.println(p.toString()));
//查询出修改withdraw的customerId
if (customerIds == null){
Map<Long,List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(fortunes,"customerId");
if (customerIds == null) {
Map<Long, List<AclCustomerFortune>> customerFortuneMap = changeCustomerFortunesByFieldName(fortunes, "customerId");
customerIds = customerFortuneMap.keySet();
}
//如果customerIds为null,则此次需修改的withdraw提现金额为0
if (customerIds.isEmpty()){
if (customerIds.isEmpty()) {
//修改withdraws/pays提现金额为0
updateWithdrawAmountToZero(withdraws,pays,loginId);
updateWithdrawAmountToZero(withdraws, pays, loginId);
return;
}
//查询customerIds的基本财富信息(历史累积财富 已退保财富 已提现财富 等) customerId CustomerFortuneStatisticalInfo
Map<Long,CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(customerIds);
Map<Long, CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(customerIds);
//按withdrawedId经行整理
Map<Long, List<AclCustomerFortune>> withdrawsFortunes = changeCustomerFortunesByFieldName(fortunes,"withdrawedId");
Map<Long, List<AclCustomerFortune>> withdrawsFortunes = changeCustomerFortunesByFieldName(fortunes, "withdrawedId");
for (AclCustomerFortuneWithdraw withdraw : withdraws) {
//withdrawId
Long withdrawId = withdraw.getId();
......@@ -443,8 +446,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
customerFortuneDalService.updateBatch(fortuneUpdates);
}
private void updateWithdrawAmountToZero(List<AclCustomerFortuneWithdraw> withdraws, List<AclCustomerFortunePay> pays,Long loginId) {
withdraws.forEach(w->{
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());
......@@ -452,7 +455,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
w.setTaxAmount(BigDecimal.ZERO);
w.setPaidAmount(BigDecimal.ZERO);
});
pays.forEach(pay->{
pays.forEach(pay -> {
pay.setWithdrawAmount(BigDecimal.ZERO);
pay.setPayAmount(BigDecimal.ZERO);
pay.setTaxAmount(BigDecimal.ZERO);
......@@ -465,8 +468,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
customerFortunePayDalService.updateAll(pays);
}
private void insertWithdraw(Map<Long, List<AclCustomerFortune>> newCustomerWithdrawMap,Long loginId) {
if (newCustomerWithdrawMap.isEmpty()){
private void insertWithdraw(Map<Long, List<AclCustomerFortune>> newCustomerWithdrawMap, Long loginId) {
if (newCustomerWithdrawMap.isEmpty()) {
return;
}
System.out.println("insertWithdraw");
......@@ -474,8 +477,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
List<AclCustomerFortune> fortuneList = new ArrayList<>();
//查询customerIds的基本财富信息(历史累积财富 已退保财富 已提现财富 等) customerId CustomerFortuneStatisticalInfo
Map<Long,CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(newCustomerWithdrawMap.keySet());
for (Map.Entry<Long, List<AclCustomerFortune>> customerWithdraw: newCustomerWithdrawMap.entrySet()){
Map<Long, CustomerFortuneStatisticalInfo> customerFortuneStatisticalMap = agmsFortuneDalService.findFortuneStatisticalByCustomers(newCustomerWithdrawMap.keySet());
for (Map.Entry<Long, List<AclCustomerFortune>> customerWithdraw : newCustomerWithdrawMap.entrySet()) {
Long customerId = customerWithdraw.getKey();
List<AclCustomerFortune> fortunes = customerWithdraw.getValue();
//基本财富信息(历史累积财富 已退保财富 已提现财富 等)
......@@ -491,7 +494,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
BigDecimal withdrawAfterAmount = withdrawBeforeAmount.subtract(withdrawAmount);
//重新计算税额
BigDecimal yearDrawnFortune = customerFortuneStatisticalInfo.getYearDrawnFortune();
BigDecimal taxAmount = calcuPersonalTax(withdrawAmount,yearDrawnFortune);
BigDecimal taxAmount = calcuPersonalTax(withdrawAmount, yearDrawnFortune);
//可提现金额
BigDecimal paidAmount = withdrawAmount.subtract(taxAmount);
//保存withdraw记录
......@@ -506,7 +509,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
withdraw.setRequestorName(customerFortuneStatisticalInfo.getCustomerName());
withdraw.setRequestorIdTypeId(customerFortuneStatisticalInfo.getCustomerIdTypeId());
withdraw.setRequestorId(customerFortuneStatisticalInfo.getCustomerIdNo());
withdraw.setRequestorBirthdate(CommonUtil.stringParseDate("yyyy-MM-dd",customerFortuneStatisticalInfo.getCustomerBirthdate()));
withdraw.setRequestorBirthdate(CommonUtil.stringParseDate("yyyy-MM-dd", customerFortuneStatisticalInfo.getCustomerBirthdate()));
withdraw.setRequestorGender(customerFortuneStatisticalInfo.getCustomerGender());
withdraw.setStatus(0);
withdraw.setCreatedAt(new Date());
......@@ -544,7 +547,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//drawnFortune为此次提现额
//yearDrawnFortune今年已提现费用
//计算今年已交税额
if (!CommonUtil.isNullOrZero(yearDrawnFortune)){
if (!CommonUtil.isNullOrZero(yearDrawnFortune)) {
yearDrawnFortune = BigDecimal.ZERO;
}
BigDecimal yearTax = calculateTax(yearDrawnFortune);
......@@ -553,19 +556,19 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
BigDecimal tax = calculateTax(amount);
//总税额减去已交税额
tax=tax.subtract(yearTax);
return tax.setScale(2,BigDecimal.ROUND_HALF_UP);
tax = tax.subtract(yearTax);
return tax.setScale(2, BigDecimal.ROUND_HALF_UP);
}
private BigDecimal calculateTax(BigDecimal yearTax) {
List<MdIncometaxRate> incometaxs = systemConfigService.findIncometax();
//累计提现金额 /1.06* (1-20%)*(1-25%) = 应纳税所得额
yearTax=yearTax.divide(BigDecimal.valueOf(1.06),3,BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(0.6));
for (MdIncometaxRate incometax: incometaxs){
if (incometax.getTaxableFrom().compareTo(yearTax)<=0 && yearTax.compareTo(incometax.getTaxableTo()) < 0){
yearTax = yearTax.divide(BigDecimal.valueOf(1.06), 3, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(0.6));
for (MdIncometaxRate incometax : incometaxs) {
if (incometax.getTaxableFrom().compareTo(yearTax) <= 0 && yearTax.compareTo(incometax.getTaxableTo()) < 0) {
//已交税额
yearTax = yearTax.multiply(BigDecimal.valueOf(incometax.getTaxRate()))
.divide(BigDecimal.valueOf(100),3,BigDecimal.ROUND_HALF_UP)
.divide(BigDecimal.valueOf(100), 3, BigDecimal.ROUND_HALF_UP)
.subtract(incometax.getEstDeductable());
break;
}
......@@ -575,19 +578,20 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
/**
* 根据name(字段名整理fortune记录)
*
* @param customerFortunes 未整理的fortune记录
* @param fieldName 根据哪个字段名整理
* @return 整理后的fortune
*/
private Map<Long, List<AclCustomerFortune>> changeCustomerFortunesByFieldName(List<AclCustomerFortune> customerFortunes,String fieldName) {
private Map<Long, List<AclCustomerFortune>> changeCustomerFortunesByFieldName(List<AclCustomerFortune> customerFortunes, String fieldName) {
Map<Long, List<AclCustomerFortune>> map = new HashMap<>(16);
for (AclCustomerFortune list: customerFortunes) {
List<AclCustomerFortune> customerFortuneList = map.get(getFieldValueByName(fieldName,list));
for (AclCustomerFortune list : customerFortunes) {
List<AclCustomerFortune> customerFortuneList = map.get(getFieldValueByName(fieldName, list));
customerFortuneList = Optional.ofNullable(customerFortuneList).orElse(new ArrayList<>());
if (customerFortuneList.isEmpty()){
if (customerFortuneList.isEmpty()) {
customerFortuneList.add(list);
map.put(getFieldValueByName(fieldName,list),customerFortuneList);
}else {
map.put(getFieldValueByName(fieldName, list), customerFortuneList);
} else {
customerFortuneList.add(list);
}
}
......@@ -596,13 +600,13 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
/**
* 根据属性名获取属性值
* */
*/
private Long getFieldValueByName(String fieldName, Object o) {
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase();
String getter = "get" + firstLetter + fieldName.substring(1);
Method method = o.getClass().getMethod(getter);
return (Long) method.invoke(o, new Object[] {});
return (Long) method.invoke(o, new Object[]{});
} catch (Exception e) {
return null;
}
......@@ -610,13 +614,13 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
@Override
public CommissionPayoutStatusQueryResponseVO commissionPayoutStatusQuery(CommissionPayoutStatusQueryRequestVO requestVO){
public CommissionPayoutStatusQueryResponseVO commissionPayoutStatusQuery(CommissionPayoutStatusQueryRequestVO requestVO) {
CommissionPayoutStatusQueryResponseVO responseVO = new CommissionPayoutStatusQueryResponseVO();
CommissionPayoutStatusQueryInfo info = new CommissionPayoutStatusQueryInfo();
BeanUtils.copyProperties(requestVO,info);
BeanUtils.copyProperties(requestVO, info);
//体系查询调整,如果体系为S3,则需要查询它下面的所有子集
PractitionerSubordinateInfo practitionerSubordinateInfo = new PractitionerSubordinateInfo();
BeanUtils.copyProperties(requestVO,practitionerSubordinateInfo);
BeanUtils.copyProperties(requestVO, practitionerSubordinateInfo);
practitionerSubordinateInfo.setDeptId(requestVO.getInsurerBranchDeptId());
List<Long> subsystemIdList = aclPractitionerSubordinateSystemDalService.getLongs(practitionerSubordinateInfo);
info.setSubsystemIdList(subsystemIdList);
......@@ -632,8 +636,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
Long orderId = commissionPayoutStatus.getOrderId();
totalReferralAmount = totalReferralAmount.add(commissionPayoutStatus.getReferralAmount() == null ? BigDecimal.ZERO : commissionPayoutStatus.getReferralAmount());
if(orderId != null){
if (orderIdList.contains(orderId)){
if (orderId != null) {
if (orderIdList.contains(orderId)) {
continue;
}
orderIdList.add(orderId);
......@@ -670,13 +674,13 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
@Override
public WithdrawQueryResponseVO withdrawQuery(WithdrawQueryRequestVO requestVO){
public WithdrawQueryResponseVO withdrawQuery(WithdrawQueryRequestVO requestVO) {
WithdrawQueryResponseVO responseVO = new WithdrawQueryResponseVO();
WithdrawQueryInfo info = new WithdrawQueryInfo();
BeanUtils.copyProperties(requestVO,info);
BeanUtils.copyProperties(requestVO, info);
//体系查询调整,如果体系为S3,则需要查询它下面的所有子集
PractitionerSubordinateInfo practitionerSubordinateInfo = new PractitionerSubordinateInfo();
BeanUtils.copyProperties(requestVO,practitionerSubordinateInfo);
BeanUtils.copyProperties(requestVO, practitionerSubordinateInfo);
practitionerSubordinateInfo.setDeptId(requestVO.getInsurerBranchDeptId());
List<Long> subsystemIdList = aclPractitionerSubordinateSystemDalService.getLongs(practitionerSubordinateInfo);
info.setSubsystemIdList(subsystemIdList);
......@@ -685,9 +689,9 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
responseVO.setTotalPeople(withdraws.size());
BigDecimal totalReferralAmount = withdraws.stream()
.map(f -> f.getReferralAmount() == null ? BigDecimal.ZERO : f.getReferralAmount())
.reduce(BigDecimal.ZERO,BigDecimal::add);
.reduce(BigDecimal.ZERO, BigDecimal::add);
responseVO.setTotalReferralAmount(totalReferralAmount);
responseVO.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000")));
responseVO.setCommonResult(new CommonResult(true, ZHBErrorConfig.getErrorInfo("800000")));
responseVO.setWithdraws(withdraws);
return responseVO;
}
......@@ -700,10 +704,10 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
List<FortunePayToOrderInfo> fortunePayToOrderInfos = agmsFortuneDalService.fortunePayToOrder(new Long[]{payId});
BigDecimal totalOrderPrice = fortunePayToOrderInfos.stream()
.map(f -> f.getOrderPrice() == null ? BigDecimal.ZERO : f.getOrderPrice())
.reduce(BigDecimal.ZERO,BigDecimal::add);
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal totalReferralAmount = fortunePayToOrderInfos.stream()
.map(f -> f.getReferralAmount() == null ? BigDecimal.ZERO : f.getReferralAmount())
.reduce(BigDecimal.ZERO,BigDecimal::add);
.reduce(BigDecimal.ZERO, BigDecimal::add);
responseVO.setTotalSingular(fortunePayToOrderInfos.size());
responseVO.setTotalOrderPrice(totalOrderPrice);
responseVO.setTotalReferralAmount(totalReferralAmount);
......@@ -724,30 +728,30 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//查询所有pay记录和withdraw记录
List<AclCustomerFortunePay> customerFortunePays = customerFortunePayDalService.findByIds(payIds);
Long[] withdrawIds = new Long[customerFortunePays.size()];
for(int i = 0; i < customerFortunePays.size();i++){
for (int i = 0; i < customerFortunePays.size(); i++) {
withdrawIds[i] = customerFortunePays.get(i).getWithdrawId();
}
List<AclCustomerFortuneWithdraw> customerFortuneWithdraws = customerFortuneWithdrawDalService.findByIds(Arrays.asList(withdrawIds));
//查询经纪人的静态记录
Long[] customerIds = new Long[customerFortunePays.size()];
for(int i = 0; i < customerFortunePays.size();i++){
for (int i = 0; i < customerFortunePays.size(); i++) {
customerIds[i] = customerFortunePays.get(i).getCustomerId();
}
List<AclCustomerFortuneStatistic> customerFortuneStatistics = customerFortuneStatisticDalService.findByCustomerIds(customerIds);
//fortune记录
List<AclCustomerFortune> fortunes = customerFortuneDalService.findByWithdrawIds(Arrays.asList(withdrawIds));
//更新静态表
for (AclCustomerFortuneStatistic statistic: customerFortuneStatistics){
for (AclCustomerFortuneStatistic statistic : customerFortuneStatistics) {
Long customerId = statistic.getCustomerId();
BeanPropertyValueEqualsPredicate predicateClause = new BeanPropertyValueEqualsPredicate( "customerId", customerId);
List<AclCustomerFortuneWithdraw> withdraws = (List<AclCustomerFortuneWithdraw>) CollectionUtils.select(customerFortuneWithdraws,predicateClause);
if (withdraws.isEmpty()){
BeanPropertyValueEqualsPredicate predicateClause = new BeanPropertyValueEqualsPredicate("customerId", customerId);
List<AclCustomerFortuneWithdraw> withdraws = (List<AclCustomerFortuneWithdraw>) CollectionUtils.select(customerFortuneWithdraws, predicateClause);
if (withdraws.isEmpty()) {
continue;
}
for (AclCustomerFortuneWithdraw withdraw: withdraws) {
for (AclCustomerFortuneWithdraw withdraw : withdraws) {
// if (CommonUtil.isNullOrZero(withdraw.getIsPaid())){
BigDecimal drawnFortune = statistic.getDrawnFortune();
if (CommonUtil.isNullOrZero(drawnFortune)){
if (CommonUtil.isNullOrZero(drawnFortune)) {
drawnFortune = BigDecimal.ZERO;
}
drawnFortune = drawnFortune.add(withdraw.getWithdrawAmount());
......@@ -787,7 +791,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
boolean success = true;
String message = ZHBErrorConfig.getErrorInfo("800000");
Long[] payIds = requestVO.getPayIds();
if (payIds == null || payIds.length == 0){
if (payIds == null || payIds.length == 0) {
success = false;
message = ZHBErrorConfig.getErrorInfo("830022");
}
......@@ -804,9 +808,9 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
Long orderId = requestVO.getOrderId();
//判断此订单是否可以退保
//保单财富以进行提现申请,无法进行退保
PoOrder poOrder = poOrderDALService.findByIdAndStatus(orderId,3);
if(poOrder == null){
resp.setCommonResult(new CommonResult(false,ZHBErrorConfig.getErrorInfo("830065")));
PoOrder poOrder = poOrderDALService.findByIdAndStatus(orderId, 3);
if (poOrder == null) {
resp.setCommonResult(new CommonResult(false, ZHBErrorConfig.getErrorInfo("830065")));
return resp;
}
......@@ -816,11 +820,11 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//财富此订单对应的财富
List<AclCustomerFortune> fortunes = customerFortuneDalService.findByOrderId(orderId);
for (AclCustomerFortune fortune : fortunes){
for (AclCustomerFortune fortune : fortunes) {
//查询财富对应的customer的statistic
AclCustomerFortuneStatistic statistic = customerFortuneStatisticDalService.findByCustomerId(fortune.getCustomerId());
BigDecimal cancelledFortune = statistic.getCancelledFortune();
if (CommonUtil.isNullOrZero(cancelledFortune)){
if (CommonUtil.isNullOrZero(cancelledFortune)) {
cancelledFortune = BigDecimal.ZERO;
}
cancelledFortune = cancelledFortune
......@@ -830,7 +834,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
//生成对应的负向记录 (commission_amount/fyc_amount/referral_amount)
AclCustomerFortune fortuneNew = new AclCustomerFortune();
org.springframework.beans.BeanUtils.copyProperties(fortune,fortuneNew);
org.springframework.beans.BeanUtils.copyProperties(fortune, fortuneNew);
Double commissionAmount = -fortune.getCommissionAmount().doubleValue();
fortuneNew.setCommissionAmount(BigDecimal.valueOf(commissionAmount));
......@@ -855,11 +859,11 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
PoOrder order = poOrderDALService.findByOrderId(orderId);
Integer configLevel = order.getConfigLevel();
String name = "";
if(configLevel == 2){
if (configLevel == 2) {
Long productId = order.getProductId();
Product product = productDALService.findById(productId);
name = product.getName();
}else if (configLevel == 3){
} else if (configLevel == 3) {
Long planId = order.getPlanId();
ProductPlan productPlan = productPlanDALService.findById(planId);
name = productPlan.getName();
......@@ -867,15 +871,15 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
String messageText = "订单id:" + order.getId() + "<br>" +
"订单号:" + order.getOrderNo() + "<br>" +
"产品名称:" + name + "<br>" +
"产品金额:" + order.getOrderPrice() + "<br>" ;
"产品金额:" + order.getOrderPrice() + "<br>";
List<AclPolicyholder> policyHolders = aclPolicyholderService.findByOrderId(orderId);
for(AclPolicyholder policyHolder : policyHolders){
for (AclPolicyholder policyHolder : policyHolders) {
Integer type = policyHolder.getType();
if (type == 2){
if (type == 2) {
messageText += "投标人:<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:" + policyHolder.getName() +
"&nbsp;&nbsp;&nbsp;&nbsp;电话" + policyHolder.getMobileNo() + "<br>";
}else if (type == 3){
} else if (type == 3) {
messageText += "被保人:<br>" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;姓名:" + policyHolder.getName();
if (!CommonUtil.isNullOrBlank(policyHolder.getMobileNo())) {
......@@ -886,7 +890,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
String subject = "回退财富";
sendService.sendEmailOrSMS("email", email, "3", messageText, null, subject, ccAddresses, "回复财富", 99, null);
resp.setCommonResult(new CommonResult(true,ZHBErrorConfig.getErrorInfo("800000")));
resp.setCommonResult(new CommonResult(true, ZHBErrorConfig.getErrorInfo("800000")));
return resp;
}
......@@ -894,21 +898,21 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
public ExportFortunePayResponseVO exportFortunePay(ExportFortunePayRequestVO requestVO, HttpServletResponse response) {
ExportFortunePayResponseVO responseVO = new ExportFortunePayResponseVO();
WithdrawQueryInfo info = new WithdrawQueryInfo();
BeanUtils.copyProperties(requestVO,info);
BeanUtils.copyProperties(requestVO, info);
//体系查询调整,如果体系为S3,则需要查询它下面的所有子集
PractitionerSubordinateInfo practitionerSubordinateInfo = new PractitionerSubordinateInfo();
BeanUtils.copyProperties(requestVO,practitionerSubordinateInfo);
BeanUtils.copyProperties(requestVO, practitionerSubordinateInfo);
practitionerSubordinateInfo.setDeptId(requestVO.getInsurerBranchDeptId());
List<Long> subsystemIdList = aclPractitionerSubordinateSystemDalService.getLongs(practitionerSubordinateInfo);
info.setSubsystemIdList(subsystemIdList);
List<WithdrawLabelInfo> withdraws = agmsFortuneDalService.transformForWithdrawLabel(info);
Long[] payIds = new Long[withdraws.size()];
for (int i = 0; i < withdraws.size(); i ++){
for (int i = 0; i < withdraws.size(); i++) {
payIds[i] = withdraws.get(i).getPayId();
}
List<FortunePayToOrderInfo> fortunePayToOrderInfos = agmsFortuneDalService.fortunePayToOrder(payIds);
createCSV(fortunePayToOrderInfos,response);
createCSV(fortunePayToOrderInfos, response);
responseVO.setCommonResult(new CommonResult(true, ZHBErrorConfig.getErrorInfo("800000")));
return responseVO;
}
......@@ -1001,7 +1005,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
exportSalaryDetailsSheet2queryOrganization(dataList);
}
// 3.遍历数据,产生数据行
if ( null != dataList) {
if (null != dataList) {
for (int i = 0; i < dataList.size(); i++) {
Map<String, Object> values = dataList.get(i);
rownum = sheet2.createRow(i + 1);
......@@ -1053,8 +1057,14 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
}
//续期辅导人 [25]
if (null != item.get("25") && StringUtils.isNotBlank(item.get("25").toString())) {
practitioner = aclPractitionerMap.get(Long.valueOf(item.get("25").toString()));
item.put("25", practitioner != null ? practitioner.getName() : null);
String[] ids = item.get("25").toString().split(",");
for (int j = 0; j < ids.length; j++) {
practitioner = aclPractitionerMap.get(Long.valueOf(ids[j]));
if (practitioner != null) {
ids[j] = practitioner.getName();
}
}
item.put("25", Joiner.on(",").join(Arrays.asList(ids)));
}
//推荐人 [30]
if (null != item.get("30") && StringUtils.isNotBlank(item.get("30").toString())) {
......@@ -1106,6 +1116,9 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
item.put("57", this.processMerge(item.get("57"), aclPractitionerMap));
item.put("58", this.processMerge(item.get("58"), aclPractitionerMap));
item.put("59", this.processMerge(item.get("59"), aclPractitionerMap));
//71-72
item.put("71", this.processMerge(item.get("71"), aclPractitionerMap));
item.put("72", this.processMerge(item.get("72"), aclPractitionerMap));
}
}
......@@ -1192,8 +1205,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(os != null){
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
......@@ -1230,7 +1243,7 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
private void createCSV(List<FortunePayToOrderInfo> fortunePayToOrderInfos, HttpServletResponse response) {
String charset = "UTF-8"; // 读取字符编码
String[] columnName = new String[]{"序号","预计发佣年月","经纪人","佣金","应发佣金","首年销售佣金(fyc)","保单号","保费","佣金率","发佣状态","佣金类型","手机号","职级","分公司","营业部","体系","购买方案"};
String[] columnName = new String[]{"序号", "预计发佣年月", "经纪人", "佣金", "应发佣金", "首年销售佣金(fyc)", "保单号", "保费", "佣金率", "发佣状态", "佣金类型", "手机号", "职级", "分公司", "营业部", "体系", "购买方案"};
String tableName = "YD_Export_Fortune_Pay";
String CSV_COLUMN_SEPARATOR = ",";//CSV文件列分隔符
String CSV_ROW_SEPARATOR = "\r\n";//CSV文件行分隔符
......@@ -1251,16 +1264,16 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
buf.append(info.getCommissionAmount() == null ? 0 : info.getCommissionAmount()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getReferralAmount() == null ? 0 : info.getReferralAmount()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getFycAmount() == null ? 0 : info.getFycAmount()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getPolicyNo() == null ? "": "P_" +info.getPolicyNo()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getPolicyNo() == null ? "" : "P_" + info.getPolicyNo()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getOrderPrice() == null ? 0 : info.getOrderPrice()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getCommissionRate() == null ? 0: info.getCommissionRate()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getCommissionRate() == null ? 0 : info.getCommissionRate()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getCommissionPayoutStatus()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getCommissionType() == null ? "": info.getCommissionType()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getCommissionType() == null ? "" : info.getCommissionType()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getMobileNo()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getPractitionerLevel() == null ? "" : info.getPractitionerLevel()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getInsurerBranchName() == null ? "" : info.getInsurerBranchName()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getInsurerBranchDeptName() == null ? "" : info.getInsurerBranchDeptName()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getSubordinateSystemName() == null ? "": info.getSubordinateSystemName()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getSubordinateSystemName() == null ? "" : info.getSubordinateSystemName()).append(CSV_COLUMN_SEPARATOR);
buf.append(info.getProductName() == null ? "" : info.getProductName()).append(CSV_COLUMN_SEPARATOR);
buf.append(CSV_ROW_SEPARATOR);
}
......@@ -1282,8 +1295,8 @@ public class AgmsFortuneServiceImpl implements AgmsFortuneService {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}finally {
if(os != null){
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
......
......@@ -453,13 +453,17 @@
sum(case when drop_option_code ='C01' then f.referral_amount else null end) '23' /*首年销售佣金*/,
sum(case when drop_option_code ='C02' then f.referral_amount else null end) '24' /*续年销售佣金*/,
if(f.commission_period!=1,l.mentor_id,'') '25' /*续期辅导人*/,
if(f.commission_period!=1,
(SELECT group_concat(calculation_rate) from ag_acl_customer_fortune where order_id=f.order_id and drop_option_code ='C06' and practitioner_id = l.mentor_id),
'') '26' /*续期辅导奖金率*/,
if(f.commission_period!=1,
(SELECT group_concat(referral_amount) from ag_acl_customer_fortune where order_id=f.order_id and drop_option_code ='C06' and practitioner_id = l.mentor_id),
'') '27' /*续期辅导奖*/,
(SELECT group_concat(t.practitioner_id) from ag_acl_customer_fortune t
where t.drop_option_code ='R03' and order_id=f.order_id and t.sale_practitioner_id=l.practitioner_id
) '25' /*续期辅导人*/,
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, referral_amount))
from ag_acl_customer_fortune t
where t.drop_option_code ='R03' and order_id=f.order_id and t.sale_practitioner_id=l.practitioner_id
) '26' /*续期辅导奖金率*/,
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, referral_amount))
from ag_acl_customer_fortune t
where t.drop_option_code ='R03' and order_id=f.order_id and t.sale_practitioner_id=l.practitioner_id
) '27' /*续期辅导奖*/,
sum(case when drop_option_code ='C04' then f.calculation_rate else null end) '28' /*'经纪人月销售加码奖金%'*/,
sum(case when drop_option_code ='C04' then f.referral_amount else null end) '29' /*经纪人月销售加码奖金*/,
......@@ -607,13 +611,13 @@
sum(case when drop_option_code ='S01' then f.referral_amount else null end) '67' /*S01-首年度销售佣金*/,
sum(case when drop_option_code ='S03' then f.referral_amount else null end) '68' /*S03-首年度辅导奖金*/,
sum(case when drop_option_code ='R01' then f.referral_amount else null end) '69' /*R01-首年度直接销售佣金(旧)*/,
sum(case when drop_option_code ='C95' then f.referral_amount else null end) '69' /*R01-首年度直接销售佣金(旧)*/,
sum(case when drop_option_code ='R02' then f.referral_amount else null end) '70' /*R02-续年度直接销售拥金(旧)*/,
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, calculation_rate))
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, referral_amount))
from ag_acl_customer_fortune t
where t.drop_option_code ='R03' and order_id=f.order_id and t.practitioner_id=l.mentor_id
where t.drop_option_code ='R03' and order_id=f.order_id and t.sale_practitioner_id=l.practitioner_id
) '71' /*R03-续年度辅导佣金(旧)*/,
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, calculation_rate))
(SELECT group_concat(CONCAT_WS('-', t.practitioner_id, referral_amount))
from ag_acl_customer_fortune t
where t.drop_option_code ='R04' and order_id=f.order_id and t.sale_practitioner_id=l.practitioner_id
) '72' /*R04-续年度绩效奖金(旧)*/,
......
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