|
|
@@ -0,0 +1,300 @@
|
|
|
+package com.ydtech.modules.equity.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.ydtech.core.page.PageResult;
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
+import com.ydtech.modules.admin.model.SysUser;
|
|
|
+import com.ydtech.modules.admin.service.SysUserService;
|
|
|
+import com.ydtech.modules.equity.components.EquityApiConfigurationProperties;
|
|
|
+import com.ydtech.modules.equity.components.EquityRequestApiComponents;
|
|
|
+import com.ydtech.modules.equity.model.InsAreaCompanyEquity;
|
|
|
+import com.ydtech.modules.equity.model.request.ThreeOrderVo;
|
|
|
+import com.ydtech.modules.equity.model.request.ThreePointVo;
|
|
|
+import com.ydtech.modules.equity.model.request.ThreeRightsInfoPageVo;
|
|
|
+import com.ydtech.modules.equity.model.request.ThreeUserOrderVo;
|
|
|
+import com.ydtech.modules.equity.model.response.LocalEquityPackagePage;
|
|
|
+import com.ydtech.modules.equity.model.response.PageResultResponse;
|
|
|
+import com.ydtech.modules.equity.model.response.PointRatioDto;
|
|
|
+import com.ydtech.modules.equity.model.vo.AddEquityPageQueryVo;
|
|
|
+import com.ydtech.modules.equity.model.vo.EquityPageQueryVo;
|
|
|
+import com.ydtech.modules.equity.model.vo.EquitySaveVo;
|
|
|
+import com.ydtech.modules.equity.service.EquityService;
|
|
|
+import com.ydtech.modules.equity.service.InsAreaCompanyEquityService;
|
|
|
+import com.ydtech.modules.order.constants.BusinessConstant;
|
|
|
+import com.ydtech.modules.order.entity.InsAreaCompany;
|
|
|
+import com.ydtech.modules.order.entity.InsOrders;
|
|
|
+import com.ydtech.modules.order.entity.vo.FeeOrderNewVo;
|
|
|
+import com.ydtech.modules.order.service.InsAreaCompanyService;
|
|
|
+import com.ydtech.modules.order.service.InsOrdersService;
|
|
|
+import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
|
|
|
+import com.ydtech.modules.protocols.entity.po.PtlAgreementProductCostsNew;
|
|
|
+import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
|
|
|
+import com.ydtech.modules.protocols.service.PtlAgreementProductCostsNewService;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class EquityServiceImpl implements EquityService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquityRequestApiComponents equityRequestApiComponents;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsFeeOrderNewService insFeeOrderNewService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsAreaCompanyService insAreaCompanyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsOrdersService insOrdersService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementProductCostsNewService agreementProductCostsNewService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsAreaCompanyEquityService insAreaCompanyEquityService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquityApiConfigurationProperties properties;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EquityPageQueryVo equityInfo(EquityPageQueryVo pageQueryVo) {
|
|
|
+
|
|
|
+ // 通过订单号获取优惠信息
|
|
|
+ InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getOne(new LambdaQueryWrapper<InsFeeOrderNew>()
|
|
|
+ .eq(InsFeeOrderNew::getInsOrderNo, pageQueryVo.getCompanyId()));
|
|
|
+ // 获取费用信息
|
|
|
+ LambdaQueryWrapper<PtlAgreementProductCostsNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PtlAgreementProductCostsNew::getId, insFeeOrderNew.getCostsId());
|
|
|
+ PtlAgreementProductCostsNew agreementProductCostsNew = agreementProductCostsNewService.getOne(wrapper);
|
|
|
+ if(Objects.isNull(agreementProductCostsNew)){
|
|
|
+ throw new SystemException("费用信息异常!");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(agreementProductCostsNew.getLdProportion())){
|
|
|
+ throw new SystemException("先去设置代理人的留点比例!");
|
|
|
+ }
|
|
|
+
|
|
|
+ FeeOrderNewVo feeOrderNewVo = this.newConvertOrderFeeVoData(insFeeOrderNew,agreementProductCostsNew);
|
|
|
+ // 获取佣金
|
|
|
+ List<FeeOrderNewVo.ExportFee> feeList = feeOrderNewVo.getExportFee();
|
|
|
+ BigDecimal totalAmount = BigDecimal.valueOf(0);
|
|
|
+ for (FeeOrderNewVo.ExportFee fee : feeList) {
|
|
|
+ if(BusinessConstant.FEE_INSURANCE_TYPE_4.equals(fee.getInsuranceType())){
|
|
|
+ totalAmount = fee.getTotalAmount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int pageNum = pageQueryVo.getPageNum();
|
|
|
+ int pageSize = pageQueryVo.getPageSize();
|
|
|
+ PageResult pageResult = new PageResult();
|
|
|
+ ThreeRightsInfoPageVo threeRightsInfoPageVo = new ThreeRightsInfoPageVo(pageQueryVo, properties.getAppkey(), totalAmount);
|
|
|
+ PageResultResponse response = equityRequestApiComponents.equityPage(threeRightsInfoPageVo);
|
|
|
+ pageResult.setPageNum(pageNum);
|
|
|
+ pageResult.setPageSize(pageSize);
|
|
|
+ pageResult.setTotalSize(response.total);
|
|
|
+ pageResult.setContent(response.getRecords());
|
|
|
+ pageQueryVo.setPageResult(pageResult);
|
|
|
+ pageQueryVo.setFeeOrderNewVo(feeOrderNewVo);
|
|
|
+ // 获取积分兑换比例(接口获取)
|
|
|
+ ThreePointVo threePointVo = new ThreePointVo();
|
|
|
+ threePointVo.setThreeUserId(properties.getAppkey());
|
|
|
+ PointRatioDto pointRatioDto = equityRequestApiComponents.getPointRatio(threePointVo);
|
|
|
+ pageQueryVo.setPointProportion(new BigDecimal(pointRatioDto.getDenominator()));
|
|
|
+
|
|
|
+ // 获取权益包
|
|
|
+ InsAreaCompanyEquity equity = insAreaCompanyEquityService.getById(pageQueryVo.getCompanyId());
|
|
|
+ if(Objects.nonNull(equity)){
|
|
|
+ String equityInfo = equity.getEquityInfo();
|
|
|
+ LocalEquityPackagePage packagevo = JSON.parseObject(equityInfo, LocalEquityPackagePage.class);
|
|
|
+ pageQueryVo.setEquityInfoVo(packagevo);
|
|
|
+ }
|
|
|
+ return pageQueryVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EquityPageQueryVo addEquityInfo(AddEquityPageQueryVo pageQueryVo) {
|
|
|
+ EquityPageQueryVo pageQueryDto = new EquityPageQueryVo();
|
|
|
+ // 获取费用信息
|
|
|
+ LambdaQueryWrapper<PtlAgreementProductCostsNew> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(PtlAgreementProductCostsNew::getId, pageQueryVo.getCostsId());
|
|
|
+ PtlAgreementProductCostsNew agreementProductCostsNew = agreementProductCostsNewService.getOne(wrapper);
|
|
|
+ if(Objects.isNull(agreementProductCostsNew)){
|
|
|
+ throw new SystemException("费用信息异常!");
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(agreementProductCostsNew.getLdProportion())){
|
|
|
+ throw new SystemException("先去设置代理人的留点比例!");
|
|
|
+ }
|
|
|
+ BigDecimal amount = pageQueryVo.getTotalAmount().subtract(pageQueryVo.getTotalAmount().multiply(new BigDecimal(agreementProductCostsNew.getLdProportion()).divide(new BigDecimal(100))));
|
|
|
+ int pageNum = pageQueryVo.getPageNum();
|
|
|
+ int pageSize = pageQueryVo.getPageSize();
|
|
|
+ PageResult pageResult = new PageResult();
|
|
|
+ ThreeRightsInfoPageVo threeRightsInfoPageVo = new ThreeRightsInfoPageVo(pageQueryVo, properties.getAppkey(), amount);
|
|
|
+ PageResultResponse response = equityRequestApiComponents.equityPage(threeRightsInfoPageVo);
|
|
|
+ pageResult.setPageNum(pageNum);
|
|
|
+ pageResult.setPageSize(pageSize);
|
|
|
+ pageResult.setTotalSize(response.total);
|
|
|
+ pageResult.setContent(response.getRecords());
|
|
|
+ pageQueryDto.setPageResult(pageResult);
|
|
|
+ // 获取积分兑换比例(接口获取)
|
|
|
+ ThreePointVo threePointVo = new ThreePointVo();
|
|
|
+ threePointVo.setThreeUserId(properties.getAppkey());
|
|
|
+ PointRatioDto pointRatioDto = equityRequestApiComponents.getPointRatio(threePointVo);
|
|
|
+ pageQueryDto.setPointProportion(new BigDecimal(pointRatioDto.getDenominator()));
|
|
|
+ pageQueryDto.setAmount(amount);
|
|
|
+ return pageQueryDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveEquity(EquitySaveVo equitySaveVo) {
|
|
|
+
|
|
|
+ InsAreaCompanyEquity equity = insAreaCompanyEquityService.getById(equitySaveVo.getCompanyId());
|
|
|
+ if (Objects.isNull(equity)) {
|
|
|
+ equity = new InsAreaCompanyEquity();
|
|
|
+ equity.setType(1);
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(equitySaveVo, equity);
|
|
|
+ equity.setSubOrderNo(equitySaveVo.getCompanyId());
|
|
|
+ equity.setStatus(0);
|
|
|
+ LocalEquityPackagePage packagevo = equitySaveVo.getEquityInfo();
|
|
|
+ equity.setEquityInfo(JSON.toJSONString(packagevo));
|
|
|
+ equity.setEquityId(packagevo.getId());
|
|
|
+ equity.setEquityName(packagevo.getEquityPackageName());
|
|
|
+ insAreaCompanyEquityService.saveOrUpdate(equity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public InsAreaCompanyEquity createEquityOrder(String companyId) {
|
|
|
+ // 获取权益包
|
|
|
+ InsAreaCompanyEquity equity = insAreaCompanyEquityService.getById(companyId);
|
|
|
+ if(Objects.isNull(equity)){
|
|
|
+ throw new SystemException("客户权益未保存成功!");
|
|
|
+ }
|
|
|
+ InsAreaCompany insAreaCompany = insAreaCompanyService.getById(companyId);
|
|
|
+ InsOrders orders = insOrdersService.getById(insAreaCompany.getOrderno());
|
|
|
+ SysUser user = sysUserService.getByUserId(orders.getUserid());
|
|
|
+ if(Objects.isNull(equity)){return null;}
|
|
|
+ if(!equity.getStatus().equals(1)){
|
|
|
+ ThreeUserOrderVo threeUserOrderVo = new ThreeUserOrderVo(companyId, equity,properties.getAppkey(),user);
|
|
|
+ equityRequestApiComponents.createOrder(threeUserOrderVo);
|
|
|
+ equity.setStatus(1);
|
|
|
+ insAreaCompanyEquityService.updateById(equity);
|
|
|
+ }
|
|
|
+ return equity;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void confirmEquityOrder(String companyId) {
|
|
|
+ // 获取权益包
|
|
|
+ InsAreaCompanyEquity equity = insAreaCompanyEquityService.getById(companyId);
|
|
|
+ if(Objects.isNull(equity) || !equity.getStatus().equals(1)){throw new SystemException("权益包订单异常");}
|
|
|
+ ThreeOrderVo threeOrderVo = new ThreeOrderVo(properties.getAppkey(), companyId);
|
|
|
+ equityRequestApiComponents.confirmOrder(threeOrderVo);
|
|
|
+ equity.setStatus(2);
|
|
|
+ insAreaCompanyEquityService.updateById(equity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delEquity(String companyId) {
|
|
|
+ insAreaCompanyEquityService.removeById(companyId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveEquityType(String companyId, Integer type) {
|
|
|
+ InsAreaCompanyEquity equity = new InsAreaCompanyEquity();
|
|
|
+ equity.setSubOrderNo(companyId);
|
|
|
+ equity.setType(type);
|
|
|
+ insAreaCompanyEquityService.save(equity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算费用
|
|
|
+ *
|
|
|
+ * @param insFeeOrderNew
|
|
|
+ * @param agreementProductCostsNew
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FeeOrderNewVo newConvertOrderFeeVoData(InsFeeOrderNew insFeeOrderNew, PtlAgreementProductCostsNew agreementProductCostsNew) {
|
|
|
+
|
|
|
+ FeeOrderNewVo feeOrderNewVo = new FeeOrderNewVo();
|
|
|
+ List<FeeOrderNewVo.ExportFee> exportFeeList = new ArrayList<>();
|
|
|
+ // 出口费用
|
|
|
+ // 交强
|
|
|
+ FeeOrderNewVo.ExportFee jqExportFee = this.assignExportFee(BusinessConstant.FEE_INSURANCE_TYPE_1,
|
|
|
+ insFeeOrderNew.getJqExportSuperviseCostsPremiums(), insFeeOrderNew.getJqExportOtherCostsPremiums(),
|
|
|
+ new BigDecimal(agreementProductCostsNew.getLdProportion())
|
|
|
+ );
|
|
|
+
|
|
|
+ //商业
|
|
|
+ FeeOrderNewVo.ExportFee syExportFee = this.assignExportFee(BusinessConstant.FEE_INSURANCE_TYPE_2,
|
|
|
+ insFeeOrderNew.getSyExportSuperviseCostsPremiums(), insFeeOrderNew.getSyExportOtherCostsPremiums(),
|
|
|
+ new BigDecimal(agreementProductCostsNew.getLdProportion())
|
|
|
+ );
|
|
|
+
|
|
|
+ //非车
|
|
|
+ FeeOrderNewVo.ExportFee noExportFee = this.assignExportFee(BusinessConstant.FEE_INSURANCE_TYPE_3,
|
|
|
+ insFeeOrderNew.getNoExportSuperviseCostsPremiums(), insFeeOrderNew.getNoExportOtherCostsPremiums(),
|
|
|
+ new BigDecimal(agreementProductCostsNew.getLdProportion()));
|
|
|
+
|
|
|
+ exportFeeList.add(jqExportFee);
|
|
|
+ exportFeeList.add(syExportFee);
|
|
|
+ exportFeeList.add(noExportFee);
|
|
|
+ //出口费用合计
|
|
|
+ FeeOrderNewVo.ExportFee exportFeeTotal = assignExportFeeTotal(exportFeeList);
|
|
|
+ exportFeeList.add(exportFeeTotal);
|
|
|
+
|
|
|
+ feeOrderNewVo.setExportFee(exportFeeList);
|
|
|
+ return feeOrderNewVo;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 费用合计
|
|
|
+ * @param exportFeeList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private FeeOrderNewVo.ExportFee assignExportFeeTotal(List<FeeOrderNewVo.ExportFee> exportFeeList) {
|
|
|
+ FeeOrderNewVo.ExportFee exportFee = new FeeOrderNewVo.ExportFee();
|
|
|
+ exportFee.setInsuranceType(BusinessConstant.FEE_INSURANCE_TYPE_4);
|
|
|
+ //总费用合计
|
|
|
+ BigDecimal totalAmount = exportFeeList.stream().map(FeeOrderNewVo.ExportFee::getTotalAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ exportFee.setTotalAmount(Optional.of(totalAmount).orElse(BigDecimal.ZERO));
|
|
|
+ return exportFee;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 费用计算
|
|
|
+ *
|
|
|
+ * @param title
|
|
|
+ * @param superviseCostsPremiums
|
|
|
+ * @param otherCostsPremiums
|
|
|
+ * @param ldProportion
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public FeeOrderNewVo.ExportFee assignExportFee(String title,
|
|
|
+ BigDecimal superviseCostsPremiums,
|
|
|
+ BigDecimal otherCostsPremiums,
|
|
|
+ BigDecimal ldProportion) {
|
|
|
+ FeeOrderNewVo.ExportFee exportFee = new FeeOrderNewVo.ExportFee();
|
|
|
+ exportFee.setInsuranceType(title);
|
|
|
+ //手续费
|
|
|
+ exportFee.setSuperviseCostsPremiums(superviseCostsPremiums);
|
|
|
+ //跟单费
|
|
|
+ exportFee.setOtherCostsPremiums(otherCostsPremiums);
|
|
|
+ //总费用
|
|
|
+ BigDecimal totalAmount = superviseCostsPremiums.add(otherCostsPremiums);
|
|
|
+ exportFee.setTotalAmount(totalAmount.subtract(totalAmount.multiply(ldProportion.divide(new BigDecimal(100)))));
|
|
|
+ return exportFee;
|
|
|
+ }
|
|
|
+}
|