|
|
@@ -25,6 +25,7 @@ import com.jzg.commons.entity.finance.po.*;
|
|
|
import com.jzg.commons.entity.finance.vo.*;
|
|
|
import com.jzg.commons.entity.orders.po.InsOrderAdjust;
|
|
|
import com.jzg.commons.entity.po.EsmInsCompany;
|
|
|
+import com.jzg.commons.entity.po.InsFeeOrders;
|
|
|
import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
import com.jzg.commons.entity.po.SysUploadFiles;
|
|
|
import com.jzg.commons.entity.quote.vo.orders.InsOrdersVo;
|
|
|
@@ -59,6 +60,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
@@ -200,6 +202,10 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
*/
|
|
|
@Override
|
|
|
public HttpResult<List<ContractVO>> queryReceivableContact(InvoicingVo invoicingVo) {
|
|
|
+ List<String> incomeIds = invoicingVo.getIncomeIds();
|
|
|
+ if(CollUtil.isEmpty(incomeIds)){
|
|
|
+ return HttpResult.error("请勾选未结算的订单数据");
|
|
|
+ }
|
|
|
List<InsPlyIncome> insPlyIncomes = baseMapper.queryIncomeByIds(invoicingVo);
|
|
|
List<ContractVO> contractVOS = insPlyIncomes.stream().map(action -> new ContractVO(action.getContactPerson(), action.getContactPersonPhone())).distinct().toList();
|
|
|
log.info("根据订单编号查询得到的对接人信息[{}]个", CollUtil.size(contractVOS));
|
|
|
@@ -763,8 +769,11 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
.map(String::trim)
|
|
|
.distinct() // 可选,去重
|
|
|
.collect(Collectors.toList());
|
|
|
+ // 根据tz要求将从ins_fee_order查费用信息改为从income表查
|
|
|
+ Map<String, Object> map = baseMapper.getIncomeJqSumReceivable(orderNos);
|
|
|
+
|
|
|
// 修改后(返回总手续费 = 交强险+商业险+驾意险 手续费之和)
|
|
|
- Map<String, Object> map = baseMapper.getJqSumReceivable(orderNos);
|
|
|
+// Map<String, Object> map = baseMapper.getJqSumReceivable(orderNos);
|
|
|
if(map == null){
|
|
|
// 订单不存在的时候,直接返回0
|
|
|
log.info("订单不存在。 orderNos=[{}]", JSONUtil.toJsonStr(orderNos));
|
|
|
@@ -1462,34 +1471,43 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
return importExcelResultVo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 平台协议结算
|
|
|
+ *
|
|
|
+ * @param settlementId 平台协议结算记录的序号
|
|
|
+ * @author lipf
|
|
|
+ * @date 2026/6/22 11:40
|
|
|
+ */
|
|
|
@Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean deleteSettlementById(String id) {
|
|
|
- log.info("私有协议-结算记录-删除: id=[{}]",id);
|
|
|
- InsPlyIncomeInvoiceSettlement settlement = insPlyIncomeInvoiceSettlementMapper.selectById(id);
|
|
|
+ public HttpResult<String> deletePlatformSettlementById(String settlementId) {
|
|
|
+ log.info("平台删除结算记录。settlementId=[{}]",settlementId);
|
|
|
+ InsPlyIncomeInvoiceSettlement settlement = insPlyIncomeInvoiceSettlementMapper.selectById(settlementId);
|
|
|
if(settlement == null){
|
|
|
+ log.info("平台删除结算记录.序号为[{}]的结算记录不存在", settlementId);
|
|
|
throw new SystemException("结算记录不存在");
|
|
|
}
|
|
|
String invoiceId = settlement.getInvoiceId();
|
|
|
if (StrUtil.isBlank(invoiceId)){
|
|
|
throw new SystemException("结算记录id不存在");
|
|
|
}
|
|
|
- insPlyIncomeInvoiceMapper.update(null,
|
|
|
- new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
|
|
|
- .set(InsPlyIncomeInvoice::getStatus,"0").eq(InsPlyIncomeInvoice::getId,invoiceId));
|
|
|
-
|
|
|
+ insPlyIncomeInvoiceMapper.deleteById(invoiceId);
|
|
|
// 查询中间表:使用 QueryWrapper,增加逻辑删除过滤
|
|
|
LambdaQueryWrapper<InsPlyIncomeInvoiceLink> linkQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
linkQueryWrapper.eq(InsPlyIncomeInvoiceLink::getInvoiceId, invoiceId);
|
|
|
linkQueryWrapper.eq(InsPlyIncomeInvoiceLink::getIsDelete, SETTLE_STATUS_RESET);
|
|
|
List<InsPlyIncomeInvoiceLink> linkList = insPlyIncomeInvoiceLinkMapper.selectList(linkQueryWrapper);
|
|
|
|
|
|
+ if(CollUtil.isNotEmpty(linkList)){
|
|
|
+ for (InsPlyIncomeInvoiceLink insPlyIncomeInvoiceLink : linkList) {
|
|
|
+ insPlyIncomeInvoiceLinkMapper.deleteByInvoiceId(insPlyIncomeInvoiceLink.getInvoiceId());
|
|
|
+ }
|
|
|
+ }
|
|
|
// 提取incomeId列表
|
|
|
- List<String> incomeIdList = linkList.stream()
|
|
|
+ List<String> incomeIds = linkList.stream()
|
|
|
.map(InsPlyIncomeInvoiceLink::getIncomeId)
|
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
// 构造更新条件,增加主表逻辑删除过滤
|
|
|
LambdaUpdateWrapper<InsPlyIncome> incomeUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
incomeUpdateWrapper.set(InsPlyIncome::getSettlementStatus, SETTLE_STATUS_RESET)
|
|
|
@@ -1498,10 +1516,89 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
.set(InsPlyIncome::getJySuperviseSettlement, SETTLE_STATUS_RESET)
|
|
|
.set(InsPlyIncome::getJyOtherSettlement, SETTLE_STATUS_RESET)
|
|
|
.eq(InsPlyIncome::getIsDelete, SETTLE_STATUS_RESET)
|
|
|
- .in(InsPlyIncome::getId, incomeIdList);
|
|
|
+ .in(InsPlyIncome::getId, incomeIds);
|
|
|
|
|
|
// 执行更新
|
|
|
baseMapper.update(null, incomeUpdateWrapper);
|
|
|
+ insPlyIncomeInvoiceSettlementMapper.deleteById(settlementId);
|
|
|
+ return HttpResult.ok("删除结算记录成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean deleteSettlementById(String settlementId) {
|
|
|
+ log.info("私有协议-结算记录-删除: id=[{}]", settlementId);
|
|
|
+ InsPlyIncomeInvoiceSettlement settlement = insPlyIncomeInvoiceSettlementMapper.selectById(settlementId);
|
|
|
+ if(settlement == null){
|
|
|
+ log.info("序号为[{}]的结算记录不存在", settlementId);
|
|
|
+ throw new SystemException("结算记录不存在");
|
|
|
+ }
|
|
|
+ String invoiceId = settlement.getInvoiceId();
|
|
|
+ if (StrUtil.isBlank(invoiceId)){
|
|
|
+ throw new SystemException("结算记录id不存在");
|
|
|
+ }
|
|
|
+ insPlyIncomeInvoiceMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
|
|
|
+ .set(InsPlyIncomeInvoice::getStatus,"0").eq(InsPlyIncomeInvoice::getId,invoiceId));
|
|
|
+
|
|
|
+ // 查询中间表:使用 QueryWrapper,增加逻辑删除过滤
|
|
|
+ LambdaQueryWrapper<InsPlyIncomeInvoiceLink> linkQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ linkQueryWrapper.eq(InsPlyIncomeInvoiceLink::getInvoiceId, invoiceId);
|
|
|
+ linkQueryWrapper.eq(InsPlyIncomeInvoiceLink::getIsDelete, SETTLE_STATUS_RESET);
|
|
|
+ List<InsPlyIncomeInvoiceLink> linkList = insPlyIncomeInvoiceLinkMapper.selectList(linkQueryWrapper);
|
|
|
+
|
|
|
+ LambdaUpdateWrapper<InsPlyIncome> incomeUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ if (CollUtil.isNotEmpty(linkList)){
|
|
|
+ // 提取incomeId列表
|
|
|
+ List<String> incomeIdList = linkList.stream()
|
|
|
+ .map(InsPlyIncomeInvoiceLink::getIncomeId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 构造更新条件,增加主表逻辑删除过滤
|
|
|
+ incomeUpdateWrapper.set(InsPlyIncome::getSettlementStatus, SETTLE_STATUS_RESET)
|
|
|
+ .set(InsPlyIncome::getSuperviseSettlement, SETTLE_STATUS_RESET)
|
|
|
+ .set(InsPlyIncome::getOtherSettlement, SETTLE_STATUS_RESET)
|
|
|
+ .set(InsPlyIncome::getJySuperviseSettlement, SETTLE_STATUS_RESET)
|
|
|
+ .set(InsPlyIncome::getJyOtherSettlement, SETTLE_STATUS_RESET)
|
|
|
+ .eq(InsPlyIncome::getIsDelete, SETTLE_STATUS_RESET)
|
|
|
+ .in(InsPlyIncome::getId, incomeIdList);
|
|
|
+ // 执行更新
|
|
|
+ baseMapper.update(null, incomeUpdateWrapper);
|
|
|
+ }
|
|
|
+ return insPlyIncomeInvoiceSettlementMapper.deleteById(settlementId) > 0;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean deleteFollowSettlementById(String id) {
|
|
|
+ log.info("私有协议-结算记录-删除: id=[{}]",id);
|
|
|
+ InsPlyIncomeInvoiceSettlement settlement = insPlyIncomeInvoiceSettlementMapper.selectById(id);
|
|
|
+ if(settlement == null){
|
|
|
+ throw new SystemException("结算记录不存在");
|
|
|
+ }
|
|
|
+ String invoiceId = settlement.getInvoiceId();
|
|
|
+ if (StrUtil.isBlank(invoiceId)){
|
|
|
+ throw new SystemException("结算记录id不存在");
|
|
|
+ }
|
|
|
+ insPlyIncomeInvoiceMapper.update(null,
|
|
|
+ new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
|
|
|
+ .set(InsPlyIncomeInvoice::getStatus,"0").eq(InsPlyIncomeInvoice::getId,invoiceId));
|
|
|
+
|
|
|
+ // 查询中间表:使用 QueryWrapper,增加逻辑删除过滤
|
|
|
+ LambdaQueryWrapper<InsPlyFollowInvoiceLink> linkQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ linkQueryWrapper.eq(InsPlyFollowInvoiceLink::getInvoiceId, invoiceId);
|
|
|
+ linkQueryWrapper.eq(InsPlyFollowInvoiceLink::getIsDelete, SETTLE_STATUS_RESET);
|
|
|
+ List<InsPlyFollowInvoiceLink> linkList = insPlyFollowInvoiceLinkMapper.selectList(linkQueryWrapper);
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(linkList)){
|
|
|
+ // 删除中间表
|
|
|
+ List<String> followLinkIds = linkList.stream().map(InsPlyFollowInvoiceLink::getId).collect(Collectors.toList());
|
|
|
+ insPlyFollowInvoiceLinkMapper.deleteByIds(followLinkIds);
|
|
|
+
|
|
|
+ // 删除跟单表
|
|
|
+ List<String> followIds = linkList.stream().map(InsPlyFollowInvoiceLink::getFollowId).collect(Collectors.toList());
|
|
|
+ insFeeFollowOrderMapper.deleteByIds(followIds);
|
|
|
+ }
|
|
|
return insPlyIncomeInvoiceSettlementMapper.deleteById(id) > 0;
|
|
|
}
|
|
|
|
|
|
@@ -2166,68 +2263,243 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
* @date 2026/5/27 20:25
|
|
|
*/
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean batchModify(BatchModifyVo batchModifyVo) {
|
|
|
log.info("批量修改应收订单: batchModifyVo=[{}]", JSONUtil.toJsonStr(batchModifyVo));
|
|
|
List<String> incomeIds = batchModifyVo.getIncomeIds();
|
|
|
- if(CollUtil.isEmpty(incomeIds)) {
|
|
|
+ if (CollUtil.isEmpty(incomeIds)) {
|
|
|
throw new ServiceException("请勾选要批量修改的应收订单");
|
|
|
}
|
|
|
- List<String> insOrders = new ArrayList<>();
|
|
|
- for (String incomeId : batchModifyVo.getIncomeIds()) {
|
|
|
- InsPlyIncome insPlyIncomeSource = baseMapper.selectById(incomeId);
|
|
|
- if(insPlyIncomeSource == null) {
|
|
|
- log.info("批量修改应收订单。序号为[{}]的应收订单不存在", incomeId);
|
|
|
- continue;
|
|
|
+
|
|
|
+ // 一次性查询所有需要修改的记录
|
|
|
+ List<InsPlyIncome> incomeList = baseMapper.selectBatchIds(incomeIds);
|
|
|
+ if (CollUtil.isEmpty(incomeList)) {
|
|
|
+ throw new ServiceException("未找到需要修改的应收订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 收集订单号
|
|
|
+ List<String> orderNos = incomeList.stream()
|
|
|
+ .map(InsPlyIncome::getOrderNo)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量获取税率
|
|
|
+ Map<String, BigDecimal> taxRateMap = orderNos.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ orderNo -> orderNo,
|
|
|
+ this::obtainTaxRate,
|
|
|
+ (v1, v2) -> v1 // 如果有重复,保留第一个
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 准备批量更新的实体列表
|
|
|
+ List<InsPlyIncome> updateList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (InsPlyIncome income : incomeList) {
|
|
|
+ BigDecimal taxRate = taxRateMap.getOrDefault(income.getOrderNo(), BigDecimal.ONE);
|
|
|
+ InsPlyIncome updateIncome = new InsPlyIncome();
|
|
|
+ updateIncome.setId(income.getId());
|
|
|
+
|
|
|
+ boolean hasUpdate = false;
|
|
|
+ String updateFlag = batchModifyVo.getUpdateFlag();
|
|
|
+
|
|
|
+ // 根据 updateFlag 处理不同的更新逻辑
|
|
|
+ if ("1".equals(updateFlag)) {
|
|
|
+ // 修改手续费
|
|
|
+ hasUpdate = handleSuperviseCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ } else if ("2".equals(updateFlag)) {
|
|
|
+ // 修改跟单费
|
|
|
+ hasUpdate = handleOtherCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ } else if ("3".equals(updateFlag)) {
|
|
|
+ // 修改驾意险费用
|
|
|
+ hasUpdate = handleJyCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ } else if ("4".equals(updateFlag)) {
|
|
|
+ // 修改所有
|
|
|
+ boolean superviseUpdated = handleSuperviseCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ boolean otherUpdated = handleOtherCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ boolean jyUpdated = handleJyCosts(updateIncome, income, batchModifyVo, taxRate);
|
|
|
+ hasUpdate = superviseUpdated || otherUpdated || jyUpdated;
|
|
|
}
|
|
|
- insOrders.add(insPlyIncomeSource.getOrderNo());
|
|
|
- BigDecimal taxRate = this.obtainTaxRate(insPlyIncomeSource.getOrderNo());
|
|
|
- if (Objects.nonNull(batchModifyVo.getJqSuperviseCostsProportion()) && batchModifyVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- // modify by lipf 2026年6月18日09:36:01 转换为百分比
|
|
|
- BigDecimal jqSuperviseCostsProportion = BigDecimalUtil.divide(batchModifyVo.getJqSuperviseCostsProportion(), new BigDecimal(100)) ;
|
|
|
- BigDecimal superviseReceivablePremium = BigDecimalUtil.divide(BigDecimalUtil.multiply(new BigDecimal(Objects.toString(insPlyIncomeSource.getJqPremium(),"0") ), jqSuperviseCostsProportion), taxRate) ;
|
|
|
- BigDecimal jqReceivePremiun = BigDecimalUtil.add(superviseReceivablePremium, BigDecimalUtil.toZero(insPlyIncomeSource.getInsFeeOrders() == null? null: insPlyIncomeSource.getInsFeeOrders().getJqFollowPremium()));
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
- .set(InsPlyIncome::getJqSuperviseCostsProportion, jqSuperviseCostsProportion)
|
|
|
- .set(InsPlyIncome::getJqSuperviseCostsPremiums, superviseReceivablePremium)
|
|
|
- .set(InsPlyIncome::getJqReceivablePremium,jqReceivePremiun)
|
|
|
- .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
- }
|
|
|
- if (Objects.nonNull(batchModifyVo.getSySuperviseCostsProportion()) && batchModifyVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- // modify by lipf 2026年6月18日09:36:01 转换为百分比
|
|
|
- BigDecimal sySuperviseCostsProportion = BigDecimalUtil.divide(batchModifyVo.getSySuperviseCostsProportion(), new BigDecimal(100)) ;
|
|
|
- BigDecimal sySuperviseReceivablePremium = BigDecimalUtil.divide(BigDecimalUtil.multiply(new BigDecimal(Objects.toString(insPlyIncomeSource.getSyPremium(),"0")), sySuperviseCostsProportion), taxRate) ;
|
|
|
- BigDecimal syReceivePremiun = BigDecimalUtil.add(sySuperviseReceivablePremium, BigDecimalUtil.toZero(insPlyIncomeSource.getInsFeeOrders() != null? insPlyIncomeSource.getInsFeeOrders().getSyFollowPremium() : null));
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
- .set(InsPlyIncome::getSySuperviseCostsProportion, sySuperviseCostsProportion)
|
|
|
- .set(InsPlyIncome::getSySuperviseCostsPremiums, sySuperviseReceivablePremium)
|
|
|
- .set(InsPlyIncome::getSyReceivablePremium,syReceivePremiun)
|
|
|
- .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
- }
|
|
|
- if (batchModifyVo.getSigningTime() != null){
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
- .set(InsPlyIncome::getSigningTime, batchModifyVo.getSigningTime())
|
|
|
- .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
-
|
|
|
- }
|
|
|
- if(StrUtil.isNotEmpty(batchModifyVo.getContractUserName())){
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
- .set(InsPlyIncome::getContactPerson, batchModifyVo.getContractUserName())
|
|
|
- .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
-
|
|
|
- }
|
|
|
- if(StrUtil.isNotEmpty(batchModifyVo.getContractPhone())){
|
|
|
- baseMapper.update(null, new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
- .set(InsPlyIncome::getContactPersonPhone, batchModifyVo.getContractPhone())
|
|
|
- .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
- }
|
|
|
- }
|
|
|
- batchModifyVo.setOrderNos(insOrders);
|
|
|
+
|
|
|
+ // 处理公共字段更新
|
|
|
+ if (batchModifyVo.getSigningTime() != null) {
|
|
|
+ updateIncome.setSigningTime(batchModifyVo.getSigningTime());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(batchModifyVo.getContractUserName())) {
|
|
|
+ updateIncome.setContactPerson(batchModifyVo.getContractUserName());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(batchModifyVo.getContractPhone())) {
|
|
|
+ updateIncome.setContactPersonPhone(batchModifyVo.getContractPhone());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasUpdate) {
|
|
|
+ updateList.add(updateIncome);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新
|
|
|
+ if (CollUtil.isNotEmpty(updateList)) {
|
|
|
+ this.updateBatchById(updateList);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新关联订单
|
|
|
+ batchModifyVo.setOrderNos(orderNos);
|
|
|
HttpResult<String> updateOrdersRes = insFeeOrdersClient.updateOrdersBatch(batchModifyVo);
|
|
|
log.info("更新车险订单的结果:updateOrdersRes=[{}]", JSONUtil.toJsonStr(updateOrdersRes));
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理手续费更新
|
|
|
+ */
|
|
|
+ private boolean handleSuperviseCosts(InsPlyIncome updateIncome, InsPlyIncome sourceIncome,
|
|
|
+ BatchModifyVo batchModifyVo, BigDecimal taxRate) {
|
|
|
+ boolean hasUpdate = false;
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJqSuperviseCostsProportion()) &&
|
|
|
+ batchModifyVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getJqPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "jqFollow");
|
|
|
+
|
|
|
+ updateIncome.setJqSuperviseCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setJqSuperviseCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setJqReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getSySuperviseCostsProportion()) &&
|
|
|
+ batchModifyVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getSySuperviseCostsProportion().divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getSyPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "syFollow");
|
|
|
+
|
|
|
+ updateIncome.setSySuperviseCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setSySuperviseCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setSyReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasUpdate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理跟单费更新
|
|
|
+ */
|
|
|
+ private boolean handleOtherCosts(InsPlyIncome updateIncome, InsPlyIncome sourceIncome,
|
|
|
+ BatchModifyVo batchModifyVo, BigDecimal taxRate) {
|
|
|
+ boolean hasUpdate = false;
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJqOtherCostsProportion()) &&
|
|
|
+ batchModifyVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getJqOtherCostsProportion().divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getJqPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "jqCommission");
|
|
|
+
|
|
|
+ updateIncome.setJqOtherCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setJqOtherCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setJqReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getSyOtherCostsProportion()) &&
|
|
|
+ batchModifyVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getSyOtherCostsProportion().divide(new BigDecimal(100), 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getSyPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "syCommission");
|
|
|
+
|
|
|
+ updateIncome.setSyOtherCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setSyOtherCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setSyReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasUpdate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理驾意险费用更新
|
|
|
+ */
|
|
|
+ private boolean handleJyCosts(InsPlyIncome updateIncome, InsPlyIncome sourceIncome,
|
|
|
+ BatchModifyVo batchModifyVo, BigDecimal taxRate) {
|
|
|
+ boolean hasUpdate = false;
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJySuperviseCostsProportion()) &&
|
|
|
+ batchModifyVo.getJySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getJySuperviseCostsProportion().divide(new BigDecimal(100));
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getJyPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "jyCommission");
|
|
|
+
|
|
|
+ updateIncome.setJySuperviseCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setJySuperviseCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setJyReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJyOtherCostsProportion()) &&
|
|
|
+ batchModifyVo.getJyOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ BigDecimal proportion = batchModifyVo.getJyOtherCostsProportion().divide(new BigDecimal(100));
|
|
|
+ BigDecimal premium = calculatePremium(sourceIncome.getJyPremium(), proportion, taxRate);
|
|
|
+ BigDecimal receivable = calculateReceivable(premium, sourceIncome.getInsFeeOrders(), "jyFollow");
|
|
|
+
|
|
|
+ updateIncome.setJyOtherCostsProportion(proportion.toString());
|
|
|
+ updateIncome.setJyOtherCostsPremiums(premium.toString());
|
|
|
+ updateIncome.setJyReceivablePremium(receivable.toString());
|
|
|
+ hasUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasUpdate;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算保费
|
|
|
+ */
|
|
|
+ private BigDecimal calculatePremium(String premiumStr, BigDecimal proportion, BigDecimal taxRate) {
|
|
|
+ BigDecimal premium = new BigDecimal(Objects.toString(premiumStr, "0"));
|
|
|
+ return premium.multiply(proportion).divide(taxRate, 2, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算应收金额
|
|
|
+ */
|
|
|
+ private BigDecimal calculateReceivable(BigDecimal premium, InsFeeOrders insFeeOrders, String type) {
|
|
|
+ BigDecimal followPremium = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (insFeeOrders != null) {
|
|
|
+ switch (type) {
|
|
|
+ case "jqFollow":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getJqFollowPremium());
|
|
|
+ break;
|
|
|
+ case "syFollow":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getSyFollowPremium());
|
|
|
+ break;
|
|
|
+ case "jqCommission":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getJqCommissionPremium());
|
|
|
+ break;
|
|
|
+ case "syCommission":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getSyCommissionPremium());
|
|
|
+ break;
|
|
|
+ case "jyCommission":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getJyCommissionPremium());
|
|
|
+ break;
|
|
|
+ case "jyFollow":
|
|
|
+ followPremium = BigDecimalUtil.toZero(insFeeOrders.getJyFollowPremium());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return premium.add(followPremium);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理跟单费开票业务
|
|
|
* 包含:创建发票主表记录、批量创建跟单订单明细、建立发票与明细的关联关系
|
|
|
@@ -2562,8 +2834,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
vo.setPartnerCompanyId(partnerCompanyId);
|
|
|
vo.setReceivablePremium(receivable);
|
|
|
vo.setInvoiced(invoiced);
|
|
|
- // 未开票金额 = 应收保费 - 已开票金额
|
|
|
- vo.setUninvoiced(receivable.subtract(invoiced));
|
|
|
+ vo.setUninvoiced(BigDecimal.ZERO);
|
|
|
|
|
|
// --- 查询数据库获取对账信息 ---
|
|
|
// 构造查询条件:年、月、合作方ID
|
|
|
@@ -2578,6 +2849,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
vo.setReconciliationAmount(dbOrder.getReconciliationAmount());
|
|
|
vo.setFalselyIncreasedDifference(dbOrder.getFalselyIncreasedDifference());
|
|
|
vo.setFalselyIncreasedReason(dbOrder.getFalselyIncreasedReason());
|
|
|
+ // 未开票金额 = 应收保费 - 已开票金额,这是原逻辑
|
|
|
+ // 现在按wwq的要求改成:未开票金额 = 对账金额 - 已开票金额
|
|
|
+ vo.setUninvoiced(dbOrder.getReconciliationAmount().subtract(invoiced));
|
|
|
} else {
|
|
|
// 数据库无记录,使用默认值或DTO里的值
|
|
|
vo.setReconciliationAmount(null);
|
|
|
@@ -3312,8 +3586,6 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
Map<String, BigDecimal> sxfInvoicedAmountMap = calRes.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getAmount, (o1,o2)->o1));
|
|
|
calRes = baseMapper.queryInvoicedAmount(systemCode, List.of(2, 4), queryVo.getInvoiceStartTime(), queryVo.getInvoiceEndTime(), queryVo.getAgreementType());
|
|
|
Map<String, BigDecimal> gdfInvoicedAmountMap = calRes.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getAmount, (o1,o2)->o1));
|
|
|
- calRes = baseMapper.queryInvoicedAmount(systemCode, List.of(4, 6), queryVo.getInvoiceStartTime(), queryVo.getInvoiceEndTime(), queryVo.getAgreementType());
|
|
|
- Map<String, BigDecimal> ptInvoicedAmountMap =calRes.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getAmount, (o1,o2)->o1));
|
|
|
|
|
|
// 结算费用
|
|
|
List<CalRes> sxfList = baseMapper.querySettledAmount(systemCode, queryVo.getInvoiceStartTime(), queryVo.getInvoiceEndTime(), queryVo.getAgreementType(), CollUtil.newArrayList("1", "3"));
|
|
|
@@ -3329,13 +3601,14 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
companySuperviseSettlementReportDto.setSxfInvoicedAmount(Objects.toString(sxf,BigDecimal.ZERO+""));
|
|
|
BigDecimal gdf = gdfInvoicedAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
|
|
|
companySuperviseSettlementReportDto.setGdfInvoicedAmount(Objects.toString(gdf,BigDecimal.ZERO+""));
|
|
|
- BigDecimal pt = ptInvoicedAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
|
|
|
- companySuperviseSettlementReportDto.setPtInvoicedAmount(Objects.toString(pt,BigDecimal.ZERO+""));
|
|
|
+ // 平台就没有未结算的,只要结算就是已结算的
|
|
|
+ companySuperviseSettlementReportDto.setPtInvoicedAmount(companySuperviseSettlementReportDto.getTotalReceivable());
|
|
|
|
|
|
CompanySuperviseSettlementReportDto dto;
|
|
|
dto = companyMap.get(companyId);
|
|
|
companySuperviseSettlementReportDto.setSxfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getSuperviseFee()),sxf).toString());
|
|
|
companySuperviseSettlementReportDto.setGdfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getFollowFee()),gdf).toString());
|
|
|
+ companySuperviseSettlementReportDto.setPtUnInvoicedAmount(BigDecimal.ZERO.toString());
|
|
|
|
|
|
BigDecimal sxfS = sxfSettledAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
|
|
|
BigDecimal gdfS = gdfSettledAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
|
|
|
@@ -3563,6 +3836,18 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
action.setCompanyName(esmInsCompany.getNameSimple());
|
|
|
}
|
|
|
action.setCompanyALlName(allCompanyHierarchyPaths.get(action.getCompanyId()));
|
|
|
+ String invoiceIds = action.getInvoiceIds();
|
|
|
+ if(StrUtil.isNotEmpty(invoiceIds)){
|
|
|
+ List<String> invoiceIdList = Arrays.asList(invoiceIds.split(","));
|
|
|
+ log.info("invoiceIdList.size=[{}]", CollUtil.size(invoiceIdList));
|
|
|
+ log.info("invoiceIdList=[{}]", JSONUtil.toJsonStr(invoiceIdList));
|
|
|
+ BigDecimal amount = baseMapper.querySettledAmountByInvoiceIds(invoiceIdList);
|
|
|
+ action.setSettledAmount(Objects.toString(amount,"0"));
|
|
|
+ action.setUnSettledAmount(BigDecimalUtil.subtract(new BigDecimal(action.getTotalReceivable()),amount).toString());
|
|
|
+ }else{
|
|
|
+ action.setSettledAmount("0");
|
|
|
+ action.setUnSettledAmount(BigDecimalUtil.subtract(new BigDecimal(action.getTotalReceivable()),BigDecimal.ZERO).toString());
|
|
|
+ }
|
|
|
}).toList();
|
|
|
receiverSettlementReport.setRecords(records);
|
|
|
}
|
|
|
@@ -3572,7 +3857,8 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
@Override
|
|
|
public void exportReceiverSettlementReportExcel(Page page, SettlementReportQueryVo settlementReportQueryVo) {
|
|
|
settlementReportQueryVo.setSystemCode(baseController.getSystemCode());
|
|
|
- Page<ReceiverSettlementReportDto> receiverSettlementReport = baseMapper.getReceiverSettlementReport(page, settlementReportQueryVo);
|
|
|
+ // modify by lipf 2026年6月22日16:24:15 无法通过一个sql查询出所有要求的数据, 只能通过多个sql对数据进行聚合
|
|
|
+ Page<ReceiverSettlementReportDto> receiverSettlementReport = this.receiverSettlementReport(page, settlementReportQueryVo);
|
|
|
List<ReceiverSettlementReportDto> receiverSettlementReportDtos = receiverSettlementReport.getRecords();
|
|
|
EasyExcelUtils.exportForWeb(ServletUtils.getResponse(), ReceiverSettlementReportDto.class, receiverSettlementReportDtos, "对接人结算报表");
|
|
|
}
|