|
@@ -2,6 +2,8 @@ package com.jzg.quotation.summary.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -21,6 +23,8 @@ import com.jzg.commons.entity.po.SysUser;
|
|
|
import com.jzg.commons.entity.po.SysUserAccount;
|
|
import com.jzg.commons.entity.po.SysUserAccount;
|
|
|
import com.jzg.commons.entity.po.SysUserJzgInfo;
|
|
import com.jzg.commons.entity.po.SysUserJzgInfo;
|
|
|
import com.jzg.commons.entity.quote.vo.aggregated.QuoteEchoVo;
|
|
import com.jzg.commons.entity.quote.vo.aggregated.QuoteEchoVo;
|
|
|
|
|
+import com.jzg.commons.entity.rights.po.InsOrderRights;
|
|
|
|
|
+import com.jzg.commons.entity.rights.po.InsOrderRightsPackage;
|
|
|
import com.jzg.commons.entity.vo.*;
|
|
import com.jzg.commons.entity.vo.*;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
import com.jzg.commons.util.AssertionUtils;
|
|
import com.jzg.commons.util.AssertionUtils;
|
|
@@ -30,9 +34,12 @@ import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
import com.jzg.quotation.commons.client.OrgClient;
|
|
import com.jzg.quotation.commons.client.OrgClient;
|
|
|
import com.jzg.quotation.commons.client.PlatformClient;
|
|
import com.jzg.quotation.commons.client.PlatformClient;
|
|
|
import com.jzg.quotation.summary.mapper.InsFeeAuditMapper;
|
|
import com.jzg.quotation.summary.mapper.InsFeeAuditMapper;
|
|
|
|
|
+import com.jzg.quotation.summary.mapper.InsOrderRightsMapper;
|
|
|
|
|
+import com.jzg.quotation.summary.mapper.InsOrderRightsPackageMapper;
|
|
|
import com.jzg.quotation.summary.service.*;
|
|
import com.jzg.quotation.summary.service.*;
|
|
|
import com.jzg.quotation.summary.state.AuditState;
|
|
import com.jzg.quotation.summary.state.AuditState;
|
|
|
import com.jzg.quotation.summary.state.listener.AuditStateListener;
|
|
import com.jzg.quotation.summary.state.listener.AuditStateListener;
|
|
|
|
|
+import com.jzg.quotation.summary.utils.LacalLiveTokenUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.hibernate.validator.internal.util.stereotypes.Lazy;
|
|
import org.hibernate.validator.internal.util.stereotypes.Lazy;
|
|
|
import org.redisson.api.RBucket;
|
|
import org.redisson.api.RBucket;
|
|
@@ -43,11 +50,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.BigInteger;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -94,6 +99,13 @@ public class InsFeeAuditServiceImpl extends ServiceImpl<InsFeeAuditMapper, InsFe
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private AuditStateListener auditStateListener;
|
|
private AuditStateListener auditStateListener;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private LacalLiveTokenUtil lacalLiveTokenUtil;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InsOrderRightsMapper insOrderRightsMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private InsOrderRightsPackageMapper insOrderRightsPackageMapper;
|
|
|
|
|
+
|
|
|
private static final String ORDER_LOCK_PREFIX = "orderLock:";
|
|
private static final String ORDER_LOCK_PREFIX = "orderLock:";
|
|
|
|
|
|
|
|
|
|
|
|
@@ -108,6 +120,29 @@ public class InsFeeAuditServiceImpl extends ServiceImpl<InsFeeAuditMapper, InsFe
|
|
|
param.setCompanyIdList(companyIdList);
|
|
param.setCompanyIdList(companyIdList);
|
|
|
}
|
|
}
|
|
|
Page<FeeAuditVo> page = baseMapper.queryPage(param.getPage(), param);
|
|
Page<FeeAuditVo> page = baseMapper.queryPage(param.getPage(), param);
|
|
|
|
|
+ // 循环每条数据,查询 ins_fee_orders 并计算权益金额
|
|
|
|
|
+ if (CollUtil.isNotEmpty(page.getRecords())) {
|
|
|
|
|
+ for (FeeAuditVo feeAuditVo : page.getRecords()) {
|
|
|
|
|
+ // 查询订单的 ins_fee_orders 数据
|
|
|
|
|
+ InsFeeOrders insFeeOrders = feeOrdersService.getById(feeAuditVo.getOrderNo());
|
|
|
|
|
+ if (insFeeOrders != null) {
|
|
|
|
|
+ // 权益金额 = (交强出口费用 + 商业出口费用 + 驾意出口费用) - (交强出口留点费用 + 商业出口留点费用 + 驾意出口留点费用)
|
|
|
|
|
+ BigDecimal exportTotal = Optional.ofNullable(insFeeOrders.getJqExportPremium()).orElse(BigDecimal.ZERO)
|
|
|
|
|
+ .add(Optional.ofNullable(insFeeOrders.getSyExportPremium()).orElse(BigDecimal.ZERO))
|
|
|
|
|
+ .add(Optional.ofNullable(insFeeOrders.getJyExportPremium()).orElse(BigDecimal.ZERO));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal exportKeepPointTotal = Optional.ofNullable(insFeeOrders.getJqExportKeepPointPremium()).orElse(BigDecimal.ZERO)
|
|
|
|
|
+ .add(Optional.ofNullable(insFeeOrders.getSyExportKeepPointPremium()).orElse(BigDecimal.ZERO))
|
|
|
|
|
+ .add(Optional.ofNullable(insFeeOrders.getJyExportKeepPointPremium()).orElse(BigDecimal.ZERO));
|
|
|
|
|
+
|
|
|
|
|
+ BigDecimal equityAmount = exportTotal.subtract(exportKeepPointTotal);
|
|
|
|
|
+ feeAuditVo.setEquityAmount(equityAmount);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ feeAuditVo.setEquityAmount(BigDecimal.ZERO);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return page;
|
|
return page;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -289,6 +324,105 @@ public class InsFeeAuditServiceImpl extends ServiceImpl<InsFeeAuditMapper, InsFe
|
|
|
HttpResult<SysUserAccount> result = orgClient.accountGet(sysUserResult.getData().getId(), baseController.getToken());
|
|
HttpResult<SysUserAccount> result = orgClient.accountGet(sysUserResult.getData().getId(), baseController.getToken());
|
|
|
AssertionUtils.isFail(result.getCode() != 200,"获取用户账户失败!");
|
|
AssertionUtils.isFail(result.getCode() != 200,"获取用户账户失败!");
|
|
|
userAccount = result.getData();
|
|
userAccount = result.getData();
|
|
|
|
|
+
|
|
|
|
|
+ //计算出口费用减去实际花费的权益金额
|
|
|
|
|
+ try{
|
|
|
|
|
+ // 计算权益金额 = (出口费用总和) - (出口留点费用总和)
|
|
|
|
|
+ BigDecimal jqExportTotal = Optional.ofNullable(feeOrders.getJqExportPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal syExportTotal = Optional.ofNullable(feeOrders.getSyExportPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal jyExportTotal = Optional.ofNullable(feeOrders.getJyExportPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal jqExportKeepPoint = Optional.ofNullable(feeOrders.getJqExportKeepPointPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal syExportKeepPoint = Optional.ofNullable(feeOrders.getSyExportKeepPointPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal jyExportKeepPoint = Optional.ofNullable(feeOrders.getJyExportKeepPointPremium()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal equityAmount = jqExportTotal.add(syExportTotal).add(jyExportTotal)
|
|
|
|
|
+ .subtract(jqExportKeepPoint.add(syExportKeepPoint).add(jyExportKeepPoint));
|
|
|
|
|
+
|
|
|
|
|
+ // 权益金额大于 0,计算实际花费的权益金额并发放权益券
|
|
|
|
|
+ if (equityAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
+ // 获取权益列表
|
|
|
|
|
+ List<InsOrderRights> rightsList = insOrderRightsMapper.queryByOrderNo(param.getOrderNo());
|
|
|
|
|
+ List<InsOrderRightsPackage> rightsPackageList = insOrderRightsPackageMapper.queryByOrderNo(param.getOrderNo());
|
|
|
|
|
+
|
|
|
|
|
+ // 初始化变量
|
|
|
|
|
+ BigDecimal rightsTotalAmount = BigDecimal.ZERO;
|
|
|
|
|
+ BigDecimal rightsPackageTotalAmount = BigDecimal.ZERO;
|
|
|
|
|
+ com.alibaba.fastjson2.JSONObject receiverDTO = new com.alibaba.fastjson2.JSONObject();
|
|
|
|
|
+ JSONArray rightsRequest = new JSONArray();
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历权益单品,计算总金额并构建请求参数
|
|
|
|
|
+ if (CollUtil.isNotEmpty(rightsList)) {
|
|
|
|
|
+ for (InsOrderRights rights : rightsList) {
|
|
|
|
|
+ // 提取接收人信息(取第一条有手机号的记录)
|
|
|
|
|
+ if (StringUtils.isBlank(receiverDTO.getString("phone")) && StringUtils.isNotBlank(rights.getReceiverMobile())) {
|
|
|
|
|
+ receiverDTO.put("phone", rights.getReceiverMobile());
|
|
|
|
|
+ receiverDTO.put("receiverName", rights.getReceiverName());
|
|
|
|
|
+ receiverDTO.put("remark", "车险订单权益赠送");
|
|
|
|
|
+ receiverDTO.put("receiverAmountLimit", equityAmount);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 累加金额
|
|
|
|
|
+ BigDecimal amount = Optional.ofNullable(rights.getAmount()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ Integer count = Optional.ofNullable(rights.getRightsCount()).orElse(0);
|
|
|
|
|
+ rightsTotalAmount = rightsTotalAmount.add(amount.multiply(new BigDecimal(count)));
|
|
|
|
|
+
|
|
|
|
|
+ // 构建权益单品请求参数
|
|
|
|
|
+ JSONObject rightsItem = new JSONObject();
|
|
|
|
|
+ rightsItem.put("rightsContentId", rights.getRightsInfoId());
|
|
|
|
|
+ rightsItem.put("rightsCount", rights.getRightsCount());
|
|
|
|
|
+ rightsItem.put("rightsType", 1);
|
|
|
|
|
+ rightsRequest.add(rightsItem);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历权益套餐,计算总金额并构建请求参数
|
|
|
|
|
+ if (CollUtil.isNotEmpty(rightsPackageList)) {
|
|
|
|
|
+ for (InsOrderRightsPackage pkg : rightsPackageList) {
|
|
|
|
|
+ // 提取接收人信息(取第一条有手机号的记录)
|
|
|
|
|
+ if (StringUtils.isBlank(receiverDTO.getString("phone")) && StringUtils.isNotBlank(pkg.getReceiverMobile())) {
|
|
|
|
|
+ receiverDTO.put("phone", pkg.getReceiverMobile());
|
|
|
|
|
+ receiverDTO.put("receiverName", pkg.getReceiverName());
|
|
|
|
|
+ receiverDTO.put("remark", "车险订单权益赠送");
|
|
|
|
|
+ receiverDTO.put("receiverAmountLimit", equityAmount);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 累加金额
|
|
|
|
|
+ BigDecimal packagePrice = Optional.ofNullable(pkg.getPackagePrice()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ Integer count = Optional.ofNullable(pkg.getRightsCount()).orElse(0);
|
|
|
|
|
+ rightsPackageTotalAmount = rightsPackageTotalAmount.add(packagePrice.multiply(new BigDecimal(count)));
|
|
|
|
|
+
|
|
|
|
|
+ // 构建权益套餐请求参数
|
|
|
|
|
+ JSONObject rightsItem = new JSONObject();
|
|
|
|
|
+ rightsItem.put("rightsContentId", pkg.getRightsPackageId());
|
|
|
|
|
+ rightsItem.put("rightsCount", pkg.getRightsCount());
|
|
|
|
|
+ rightsItem.put("rightsType", 2);
|
|
|
|
|
+ rightsRequest.add(rightsItem);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算权益总花费并校验
|
|
|
|
|
+ BigDecimal totalAmount = rightsTotalAmount.add(rightsPackageTotalAmount);
|
|
|
|
|
+ if (totalAmount.compareTo(equityAmount) > 0) {
|
|
|
|
|
+ AssertionUtils.isFail(true, "权益金额不足!");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 调用权益发放接口
|
|
|
|
|
+ LacalLiveTokenUtil.RightsGrantResponse response = lacalLiveTokenUtil.apiGrant(
|
|
|
|
|
+ receiverDTO, rightsRequest, "订单号:" + param.getOrderNo() + "权益赠送");
|
|
|
|
|
+
|
|
|
|
|
+ // 处理响应结果
|
|
|
|
|
+ if (response != null && Boolean.TRUE.equals(response.getSuccess())) {
|
|
|
|
|
+ // 发放成功后扣除订单总应收保费
|
|
|
|
|
+ feeOrders.setTotalReceivablePremium(
|
|
|
|
|
+ feeOrders.getTotalReceivablePremium().subtract(totalAmount)
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ AssertionUtils.isFail(true, "权益券下发失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e) {
|
|
|
|
|
+ AssertionUtils.isFail(true, "权益券下发失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(Objects.isNull(userAccount)){
|
|
if(Objects.isNull(userAccount)){
|
|
|
userAccount = new SysUserAccount();
|
|
userAccount = new SysUserAccount();
|
|
|
// 新建账户
|
|
// 新建账户
|