package com.ydtech.modules.fnc.service.impl;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ydtech.constants.InsuranceEnum;
import com.ydtech.constants.enums.dict.agreement.ProductsType;
import com.ydtech.core.page.HttpResult;
import com.ydtech.exception.SystemException;
import com.ydtech.modules.admin.model.report.financialReceivables.*;
import com.ydtech.modules.admin.utils.SliceUpDateUtil;
import com.ydtech.modules.base.controller.BaseController;
import com.ydtech.modules.esm.model.EsmInsCompany;
import com.ydtech.modules.esm.service.EsmInsCompanyService;
import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
import com.ydtech.modules.fnc.entity.*;
import com.ydtech.modules.fnc.service.*;
import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
import com.ydtech.modules.ins.model.vo.res.*;
import com.ydtech.modules.inv.model.dto.*;
import com.ydtech.modules.inv.utils.EasyExcelUtils;
import com.ydtech.modules.order.entity.BasePageResult;
import com.ydtech.modules.order.entity.InsOrders;
import com.ydtech.modules.order.entity.api.dajia.response.NVHLODR1001Response;
import com.ydtech.modules.order.entity.api.zhongmei.response.SubmitResponse;
import com.ydtech.modules.order.entity.crawler.response.CrawlerVerifyPaymentResponse;
import com.ydtech.modules.order.entity.dto.DrivingInsuranceDto;
import com.ydtech.modules.order.service.InsAreaCompanyService;
import com.ydtech.modules.order.service.InsOrdersService;
import com.ydtech.modules.protocol.entity.constants.PtlApiType;
import com.ydtech.modules.protocol.entity.po.PtlAgreement;
import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
import com.ydtech.modules.protocol.service.PtlAgreementService;
import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
import com.ydtech.utils.BigDecimalUtils;
import com.ydtech.utils.SnowFlakeUtil;
import com.ydtech.utils.StringOperations;
import com.ydtech.utils.excel.ExcelEasypoiUtils;
import com.ydtech.utils.excel.ExcelStyleUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
*
* 保司结算手续费 服务实现类
*
*
* @author gws
* @since 2024-01-05
*/
@Slf4j
@Service
public class InsPlyIncomeServiceImpl extends ServiceImpl implements InsPlyIncomeService {
@Autowired
@Lazy
private InsOrdersService insOrdersService;
@Autowired
private InsAreaCompanyService insAreaCompanyService;
@Autowired
private InsFeeOrderNewService insFeeOrderNewService;
@Autowired
private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
@Autowired
private SettlementDocumentaryLogService settlementDocumentaryLogService;
@Autowired
private PtlAgreementService ptlAgreementService;
@Autowired
private EsmInsCompanyService EsmInsCompanyService;
@Autowired
private ImportAsyncService importAsyncService;
@Autowired
private IncomeTaskRelationshipService incomeTaskRelationshipService;
@Autowired
private SettlementDocumentaryFeesSumService settlementDocumentaryFeesSumService;
@Autowired
private InsPlyIncomeLogService insPlyIncomeLogService;
@Value("${upload.file.path}")
private String uploadPath;
@Value("${upload.file.url}")
private String uploadUrl;
public HttpResult> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo) {
try {
Page page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
PageInfo> pageHelper = null;
PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
List list = this.baseMapper.selectByCondition(insPlyIncomeVo);
pageHelper = new PageInfo(list);
BasePageResult pageResult = new BasePageResult(insPlyIncomeVo.getPageNum(),
insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
return HttpResult.ok(pageResult);
} catch (Exception e) {
e.printStackTrace();
return HttpResult.error("查询异常");
}
}
@Override
public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
return;
}
String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
if (StringUtils.isNotEmpty(agreeType)) {
// 判断协议类型 平台 保险
if ("1".equals(agreeType)) {
this.savePinTai(order, insFeeOrderNew, insAreaCompany); //手续费不分非车不非车 跟单也不分
} else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
this.saveInsuranceProcedures(order, insFeeOrderNew, insAreaCompany);
}
if (insFeeOrderNew.getJqOtherCostsPremiums() != null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { //跟单费
this.saveOtherAmount(order, insFeeOrderNew, insAreaCompany);
}
if (insFeeOrderNew.getNoSuperviseCostsPremiums() != null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
this.saveNoSupervise(order, insFeeOrderNew, insAreaCompany);
}
if (insFeeOrderNew.getNoOtherCostsPremiums() != null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车跟单费
this.saveNoOtherAmount(order, insFeeOrderNew, insAreaCompany);
}
}
}
}
private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
InsPlyIncome insPlyIncome = new InsPlyIncome();
insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
String noPolicyno = this.setNoPolicyno(insAreaCompany);
if (StringUtils.isNotEmpty(noPolicyno)) {
insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
}
insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
//add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
//this.saveRiskCode(order.getProductid(), insPlyIncome);
insPlyIncome.setPayDate(insAreaCompany.getPayDate());
insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
insPlyIncome.setLicenseno(order.getLicenseno());
insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
insPlyIncome.setNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
insPlyIncome.setCreateTime(LocalDateTime.now());
insPlyIncome.setDocumentaryFeesStatus("0");
insPlyIncome.setInsuredName(order.getInsuredname());
insPlyIncome.setHandlingFeesStatus("0");
insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
insPlyIncome.setIsNotCar("1");
insPlyIncome.setIsNotDocumentary("1");
insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
insPlyIncome.setNoOtherCostsPremium(insFeeOrderNew.getNoOtherCostsPremiums());
insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion());
this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
this.getDeptId(insPlyIncome);
baseMapper.insert(insPlyIncome);
InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
insPlyIncomeLog.setId(null);
insPlyIncomeLog.setOperationStatus("1");
insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
}
private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
InsPlyIncome insPlyIncome = new InsPlyIncome();
insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
String noPolicyno = this.setNoPolicyno(insAreaCompany);
if (StringUtils.isNotEmpty(noPolicyno)) {
insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
}
// insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
//add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
//this.saveRiskCode(order.getProductid(), insPlyIncome);
insPlyIncome.setPayDate(insAreaCompany.getPayDate());
insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
insPlyIncome.setLicenseno(order.getLicenseno());
insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
insPlyIncome.setCreateTime(LocalDateTime.now());
insPlyIncome.setDocumentaryFeesStatus("0");
insPlyIncome.setHandlingFeesStatus("0");
insPlyIncome.setIsNotCar("1");
insPlyIncome.setIsNotDocumentary("0");
insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
insPlyIncome.setUserId(insFeeOrderNew.getUserId());
insPlyIncome.setInsuredName(order.getInsuredname());
insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums());
insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());
this.getDeptId(insPlyIncome);
this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
baseMapper.insert(insPlyIncome);
InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
insPlyIncomeLog.setId(null);
insPlyIncomeLog.setOperationStatus("1");
insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
}
private void saveRiskCode(String productid, InsPlyIncome insPlyIncome) {
if (ProductsType.PT_0330.getCode().equals(productid)) {
insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
}
if (ProductsType.PT_034001.getCode().equals(productid)) {
insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
}
if (ProductsType.PT_034002.getCode().equals(productid)) {
insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
}
if (ProductsType.PT_0330034002.getCode().equals(productid)) {
insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
}
if (ProductsType.PT_0330034001.getCode().equals(productid)) {
insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
}
}
private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
null);
BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
insFeeOrderNew.getJqOtherCostsProportion(), null);
BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
//交强不含税保费
BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
insAreaCompany.getTaxamount(),
allNoTaxPremium, null, otherProportion, null, otherAmount, otherAmount, null, null, LocalDateTime.now(), null, null, null, "0"
, "0", "0", "1");
//add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
//this.saveRiskCode(order.getProductid(), insPlyIncome);
insPlyIncome.setTaxPremium(allPremium);
insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
insPlyIncome.setUserId(insFeeOrderNew.getUserId());
insPlyIncome.setInsuredName(order.getInsuredname());
this.getDeptId(insPlyIncome);
this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
baseMapper.insert(insPlyIncome);
InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
insPlyIncomeLog.setId(null);
insPlyIncomeLog.setOperationStatus("1");
insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
}
private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
// 保险手续费
BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
insFeeOrderNew.getSySuperviseCostsPremiums(), null);
BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
insFeeOrderNew.getSySuperviseCostsProportion(), null);
BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
//不含税保费
InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
insAreaCompany.getTaxamount()
, allNoTaxPremium, handlingProportion, null, handlingAmount, null, handlingAmount, null, null, LocalDateTime.now(), null,
null, null, "0", "0", "0", "0");
BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
//add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
//this.saveRiskCode(order.getProductid(), insPlyIncome);
insPlyIncome.setTaxPremium(allTaxPremium);
insPlyIncome.setUserId(insFeeOrderNew.getUserId());
insPlyIncome.setInsuredName(order.getInsuredname());
insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
this.getDeptId(insPlyIncome);
baseMapper.insert(insPlyIncome);
InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
insPlyIncomeLog.setId(null);
insPlyIncomeLog.setOperationStatus("1");
insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
}
private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
if (insAreaCompany.getJypremium() == null || insAreaCompany.getJypremium().compareTo(BigDecimal.ZERO) == 0) { // 非车跟单费
return null;
}
String crossInsurance = insAreaCompany.getCrossInsurance();
if (StringUtils.isEmpty(crossInsurance)) {
return null;
}
JSONArray objects = JSON.parseArray(crossInsurance);
if (objects.isEmpty()) {
return null;
}
if (ObjectUtils.isEmpty(insAreaCompany.getApiType()) || PtlApiType.PTL_API_2.getCode() == insAreaCompany.getApiType()) {
List drivingInsurancesDTOS = objects.toJavaList(CrawlerVerifyPaymentResponse.DrivingInsurancesDTO.class);
return drivingInsurancesDTOS.get(0).getApplication();
}
// 永诚
if(insAreaCompany.getCompanyId().contains(InsuranceEnum.AICS.getCode())){
List javaList = objects.toJavaList(DrivingInsuranceDto.class);
return javaList.get(0).getPolicyNumber();
}
// 大家
if(insAreaCompany.getCompanyId().contains(InsuranceEnum.DJPC.getCode())){
List javaList = objects.toJavaList(NVHLODR1001Response.policyInfosDTO.class);
return javaList.get(0).getPlyNo();
}
// 国任
if(insAreaCompany.getCompanyId().contains(InsuranceEnum.XDCX.getCode())){
List javaList = objects.toJavaList(DrivingInsuranceDto.class);
return javaList.get(0).getPolicyNumber();
}
// 中煤
if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZMBX.getCode())){
List javaList = objects.toJavaList(SubmitResponse.AccidentNo.class);
return javaList.get(0).getRideProposalNo();
}
// 紫金
if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZKIC.getCode())){
List javaList = objects.toJavaList(DrivingInsuranceDto.class);
return javaList.get(0).getPolicyNumber();
}
return null;
}
private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
// 不含税保费
BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(),
insFeeOrderNew.getNoNoTaxPremium());
BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(),
insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(),
insFeeOrderNew.getNoOtherCostsProportion(), null);
String noPolicyno = this.setNoPolicyno(insAreaCompany);
InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
insAreaCompany.getSypolicyno(),
noPolicyno, null, null, null, order.getProductid(), insAreaCompany.getPayDate(), insAreaCompany.getSigningTime(),
insAreaCompany.getCompanyId(),
null, insFeeOrderNew.getAgreementId(), order.getLicenseno(), insAreaCompany.getTaxamount(), allNoTaxPremium,
handlingProportion,
otherProportion, handlingAmount, otherAmount, allAmount, null, null, LocalDateTime.now(), null, null, null, "0", "0", "0", "0");
insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
insPlyIncome.setSyReceivableProportion(syReceivableProportion);
insPlyIncome.setNoReceivableProportion(noReceivableProportion);
// 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
insPlyIncome.setReceivableAmount(allAmount);
insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
insPlyIncome.setUserId(insFeeOrderNew.getUserId());
insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
this.getDeptId(insPlyIncome);
//add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
//this.saveRiskCode(order.getProductid(), insPlyIncome);
insPlyIncome.setInsuredName(order.getInsuredname());
this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
baseMapper.insert(insPlyIncome);
InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
insPlyIncomeLog.setId(null);
insPlyIncomeLog.setOperationStatus("1");
insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
}
private void getDeptId(InsPlyIncome insPlyIncome) {
PtlAgreement ptlAgreement = ptlAgreementService.getById(insPlyIncome.getAgreementId());
String deptId = ptlAgreement.getDeptId();
insPlyIncome.setDeptId(deptId);
}
private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew, String companyId, InsPlyIncome insPlyIncome) {
PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
if (ObjectUtils.isNotEmpty(ptlAgreementQueryVo)) {
if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())) {
// 合作公司id
String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
String name = esmInsCompany.getNamesimple(); //合作名称
insPlyIncome.setPartnerCompaniesName(name);
insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
}
if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())) {
String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
insPlyIncome.setCompanyName(name);
}
}
}
private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
BigDecimal total = BigDecimal.ZERO;
if (value1 != null) {
total = total.add(value1);
}
if (value2 != null) {
total = total.add(value2);
}
if (value3 != null) {
total = total.add(value3);
}
return total;
}
private String judgeAgreeType(Long agreementId) {
if (agreementId == null) {
return null;
}
HttpResult byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
PtlAgreement agreement = byAgreementId.getData().getAgreement();
String agreementType = agreement.getAgreementType();
if (StringUtils.isNotEmpty(agreementType)) {
return agreementType;
}
}
return null;
}
public HttpResult> queryNew(InsPlyIncomeVo insPlyIncomeVo) {
try {
HashMap params = new HashMap<>();
PageInfo> pageHelper = null;
PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
params.put("pageNum", insPlyIncomeVo.getPageNum());
params.put("pageSize", insPlyIncomeVo.getPageSize());
params = this.saveParams(insPlyIncomeVo, params);
if (StringUtils.isNotEmpty(insPlyIncomeVo.getIds())) {
params.put("ids", insPlyIncomeVo.getIds().split(","));
}
if (StringUtils.isNotEmpty(insPlyIncomeVo.getId())) {
SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity =
settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
// 通过任务id查询 明细
String taskId = settlementDocumentaryFeesEntity.getTaskId();
List incomeIds = incomeTaskRelationshipService.getByTaskId(taskId);
if (!CollectionUtils.isEmpty(incomeIds)) {
params.put("incomeIds", incomeIds);
params.remove("handlingFeesStatus");
params.remove("id");
}
}
List list = this.baseMapper.queryNew(params);
pageHelper = new PageInfo(list);
BasePageResult pageResult = new BasePageResult(insPlyIncomeVo.getPageNum(),
insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
return HttpResult.ok(pageResult);
} catch (Exception e) {
e.printStackTrace();
return HttpResult.error("查询异常");
}
}
@Override
public HashMap totalAmount(List selectIds) {
HashMap params = new HashMap<>();
params.put("selectIds", selectIds);
HashMap resultMap = baseMapper.totalAmount(params);
return resultMap;
}
@Override
@Transactional
public HttpResult