|
|
@@ -0,0 +1,701 @@
|
|
|
+package com.jzg.organization.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.jzg.commons.constants.dict.InsOrderStatusEnum;
|
|
|
+import com.jzg.commons.core.base.BaseController;
|
|
|
+import com.jzg.commons.core.page.HttpResult;
|
|
|
+import com.jzg.commons.entity.finance.po.*;
|
|
|
+import com.jzg.commons.entity.finance.vo.*;
|
|
|
+import com.jzg.commons.entity.po.EsmInsCompany;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreement;
|
|
|
+import com.jzg.commons.util.AssertionUtils;
|
|
|
+import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
+import com.jzg.organization.client.EsmInsCompanyClient;
|
|
|
+import com.jzg.organization.excel.listener.JyExcelListener;
|
|
|
+import com.jzg.organization.excel.listener.OtherExcelListener;
|
|
|
+import com.jzg.organization.excel.listener.SuperviseExcelListener;
|
|
|
+import com.jzg.organization.mapper.*;
|
|
|
+import com.jzg.organization.service.ReceivableService;
|
|
|
+import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RKeys;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author tz
|
|
|
+ * @description 财务应收模块Service实现
|
|
|
+ * @createDate 2024-06-26 10:49:31
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyIncome> implements ReceivableService {
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseController baseController;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsPlyIncomeInvoiceMapper insPlyIncomeInvoiceMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsPlyIncomeInvoiceLinkMapper insPlyIncomeInvoiceLinkMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsPlyIncomeInvoiceSettlementMapper insPlyIncomeInvoiceSettlementMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private InsPlyIncomeInvoiceSettlementFileMapper insPlyIncomeInvoiceSettlementFileMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EsmInsCompanyClient esmInsCompanyClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PtlAgreementMapper ptlAgreementMapper;
|
|
|
+
|
|
|
+ // 车辆险种手续费结算锁
|
|
|
+ private static final String CAR_INVOICING_COMMISSION_LOCK = "CAR_INVOICING_COMMISSION_LOCK:";
|
|
|
+ // 车辆险种跟单费结算锁
|
|
|
+ private static final String CAR_INVOICING_OTHER_LOCK = "CAR_INVOICING_OTHER_LOCK:";
|
|
|
+ // 驾意险手续费结算锁
|
|
|
+ private static final String JY_INVOICING_COMMISSION_LOCK = "JY_INVOICING_COMMISSION_LOCK:";
|
|
|
+ // 驾意险跟单费结算所
|
|
|
+ private static final String JY_INVOICING_OTHER_LOCK = "JY_INVOICING_OTHER_LOCK:";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public InsPlyIncome getAuditedOrder(String orderNo, String orderStatus, String auditStatus) {
|
|
|
+ return baseMapper.getAuditedOrder(orderNo, orderStatus, auditStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean saveAuditedOrder(InsPlyIncome order) {
|
|
|
+ // 查看当前表是否已经存在了已审核订单数据
|
|
|
+ Long count = baseMapper.selectCount(new LambdaQueryWrapper<InsPlyIncome>().eq(InsPlyIncome::getOrderNo, order.getOrderNo()));
|
|
|
+ // 订单已经录入成功了
|
|
|
+ if (count > 0){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ order.setId(IdGenerate.nextId());
|
|
|
+ return save(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EsmInsCompany> getReceivableCompany(InvoicingVo invoicingVo) {
|
|
|
+ return baseMapper.getReceivableCompany(invoicingVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<InsPlyIncome> getReceivableList(ReceivableQueryVo receivableQueryVo) {
|
|
|
+ return baseMapper.getReceivableList(receivableQueryVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean invoicingCheck(InvoicingVo invoicingVo) {
|
|
|
+ Integer count = baseMapper.invoicingCheck(invoicingVo);
|
|
|
+ RKeys keys = redissonClient.getKeys();
|
|
|
+ Iterable<String> allKeys = null;
|
|
|
+ String redisKey = null;
|
|
|
+ if (invoicingVo.getInvoiceType().equals("1")){
|
|
|
+ redisKey = CAR_INVOICING_COMMISSION_LOCK;
|
|
|
+ }else if (invoicingVo.getInvoiceType().equals("2")){
|
|
|
+ redisKey = CAR_INVOICING_OTHER_LOCK;
|
|
|
+ }else if (invoicingVo.getInvoiceType().equals("3")){
|
|
|
+ redisKey = JY_INVOICING_COMMISSION_LOCK;
|
|
|
+ }else if (invoicingVo.getInvoiceType().equals("4")){
|
|
|
+ redisKey = JY_INVOICING_OTHER_LOCK;
|
|
|
+ }
|
|
|
+ allKeys = keys.getKeysByPattern(redisKey + "*");
|
|
|
+ //提取所有redis的key 然后遍历是否存在重复的id
|
|
|
+ for (String key : allKeys) {
|
|
|
+ // 过滤掉自己的redis key
|
|
|
+ if (!key.equals(key+baseController.getUserName())) {
|
|
|
+ RBucket<Object> bucket = redissonClient.getBucket(key);
|
|
|
+ String incomeIds = bucket.get().toString();
|
|
|
+ incomeIds = incomeIds.substring(1, incomeIds.length() - 1);
|
|
|
+ List<String> incomeIdList = Arrays.stream(incomeIds.split(",")).collect(Collectors.toList());
|
|
|
+ boolean hasDuplicate = invoicingVo.getIncomeIds().stream().anyMatch(incomeIdList::contains);
|
|
|
+ if (hasDuplicate) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (count == 0){
|
|
|
+ // 设置缓存
|
|
|
+ RBucket<Object> bucket = redissonClient.getBucket(redisKey + baseController.getUserName());
|
|
|
+ bucket.set(invoicingVo.getIncomeIds(), 10, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
+
|
|
|
+ return count == 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal getReceivableAmount(InvoicingVo invoicingVo) {
|
|
|
+ String invoiceType = invoicingVo.getInvoiceType();
|
|
|
+ // 私有手续费 应收金额
|
|
|
+ if(invoiceType.equals("1")){
|
|
|
+
|
|
|
+ }else if(invoiceType.equals("2")){
|
|
|
+
|
|
|
+ }else if(invoiceType.equals("3")){
|
|
|
+
|
|
|
+ }else if(invoiceType.equals("4")){
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加发票
|
|
|
+ * @param invoicingVo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean addInvoicing(InvoicingVo invoicingVo) {
|
|
|
+ try {
|
|
|
+ InsPlyIncomeInvoice invoice = new InsPlyIncomeInvoice();
|
|
|
+ invoice.setId(IdGenerate.nextId());
|
|
|
+ invoice.setInvoiceType(invoicingVo.getInvoiceType());
|
|
|
+ invoice.setInvoiceParty(invoicingVo.getInvoiceParty());
|
|
|
+ invoice.setOverinflatedAmount(invoicingVo.getOverinflatedAmount());
|
|
|
+ invoice.setReceivableSupervisePremium(invoicingVo.getReceivablePremium());
|
|
|
+ invoice.setTaxPoint(invoicingVo.getTaxPoint());
|
|
|
+ int insert = insPlyIncomeInvoiceMapper.insert(invoice);
|
|
|
+
|
|
|
+ List<InsPlyIncomeInvoiceLink> invoicingLinkList = new ArrayList();
|
|
|
+
|
|
|
+ invoicingVo.getIncomeIds().forEach(incomeId -> {
|
|
|
+ InsPlyIncomeInvoiceLink link = new InsPlyIncomeInvoiceLink();
|
|
|
+ link.setId(IdGenerate.nextId());
|
|
|
+ link.setInvoiceId(invoice.getId());
|
|
|
+ link.setIncomeId(incomeId);
|
|
|
+ invoicingLinkList.add(link);
|
|
|
+ });
|
|
|
+ insPlyIncomeInvoiceLinkMapper.insert(invoicingLinkList);
|
|
|
+ return insert > 0;
|
|
|
+ }catch (Exception e){
|
|
|
+ // 回滚事务
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal getInvoicingAmount(String invoicingId) {
|
|
|
+ BigDecimal ctualReceivedAmount = new BigDecimal(BigInteger.ZERO);
|
|
|
+
|
|
|
+ // 获取票据的实际收款金额
|
|
|
+ List<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlements = insPlyIncomeInvoiceSettlementMapper.selectList(new LambdaQueryWrapper<InsPlyIncomeInvoiceSettlement>()
|
|
|
+ .eq(InsPlyIncomeInvoiceSettlement::getInvoiceId, invoicingId));
|
|
|
+ for (InsPlyIncomeInvoiceSettlement settlement : insPlyIncomeInvoiceSettlements) {
|
|
|
+ ctualReceivedAmount = ctualReceivedAmount.add(new BigDecimal(settlement.getActualReceivedAmount()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return ctualReceivedAmount;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean updateIncomeSettlementStatus(String invoiceType,List<String> invoiceIds) {
|
|
|
+ long result = 0;
|
|
|
+ switch(invoiceType){
|
|
|
+ case "1":
|
|
|
+ result = baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
+ .in(InsPlyIncome::getId,invoiceIds)
|
|
|
+ .set(InsPlyIncome::getSuperviseSettlement,"1"));
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ result = baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
+ .in(InsPlyIncome::getId,invoiceIds)
|
|
|
+ .set(InsPlyIncome::getOtherSettlement,"1"));
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ result = baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
+ .in(InsPlyIncome::getId,invoiceIds)
|
|
|
+ .set(InsPlyIncome::getJySuperviseSettlement,"1"));
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ result = baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
+ .in(InsPlyIncome::getId,invoiceIds)
|
|
|
+ .set(InsPlyIncome::getJyOtherSettlement,"1"));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ result = 0;
|
|
|
+ }
|
|
|
+ return result > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean settlement(SettlementVo settlementVo) {
|
|
|
+ try {
|
|
|
+ // 获取应收的金额
|
|
|
+ InsPlyIncomeInvoice insPlyIncomeInvoice = insPlyIncomeInvoiceMapper.selectById(settlementVo.getInvoicingId());
|
|
|
+ AssertionUtils.isFail(Objects.isNull(insPlyIncomeInvoice), "发票数据不存在");
|
|
|
+
|
|
|
+ // 实际已经收的了金额
|
|
|
+ BigDecimal ctualReceivedAmount = getInvoicingAmount(settlementVo.getInvoicingId());
|
|
|
+
|
|
|
+ // 剩余的金额
|
|
|
+ BigDecimal surplusPremium = insPlyIncomeInvoice.getReceivableSupervisePremium().subtract(ctualReceivedAmount);
|
|
|
+
|
|
|
+ // 校验是否超出了剩余的金额
|
|
|
+ AssertionUtils.isFail(surplusPremium.compareTo(settlementVo.getActualReceivedAmount()) < 0, "已超出应收金额,请核对!");
|
|
|
+
|
|
|
+ // 处理结算数据
|
|
|
+ // 未完全结算完成
|
|
|
+ InsPlyIncomeInvoiceSettlement settlement = new InsPlyIncomeInvoiceSettlement(settlementVo.getInvoicingId(), settlementVo.getActualReceivedAmount().toString(), DateTime.now());
|
|
|
+ insPlyIncomeInvoiceSettlementMapper.insert(settlement);
|
|
|
+
|
|
|
+ // 添加发票附件
|
|
|
+ List<InsPlyIncomeInvoiceSettlementFile> files = new ArrayList<>();
|
|
|
+ for (String fileId : settlementVo.getAttachmentIds()) {
|
|
|
+ InsPlyIncomeInvoiceSettlementFile file = new InsPlyIncomeInvoiceSettlementFile();
|
|
|
+ file.setId(IdGenerate.nextId());
|
|
|
+ file.setSettlementId(settlement.getId());
|
|
|
+ file.setFileId(fileId);
|
|
|
+ files.add(file);
|
|
|
+ }
|
|
|
+ insPlyIncomeInvoiceSettlementFileMapper.insert(files);
|
|
|
+
|
|
|
+ // 判断是否已经结算完成
|
|
|
+ if (surplusPremium.compareTo(settlementVo.getActualReceivedAmount()) == 0) {
|
|
|
+ // 更新发票状态
|
|
|
+ insPlyIncomeInvoice.setStatus("1");
|
|
|
+ insPlyIncomeInvoiceMapper.updateById(insPlyIncomeInvoice);
|
|
|
+ // 将所有订单进行标记
|
|
|
+ List<String> incomeIds = new ArrayList<>();
|
|
|
+ insPlyIncomeInvoiceLinkMapper.selectList(new LambdaQueryWrapper<InsPlyIncomeInvoiceLink>()
|
|
|
+ .eq(InsPlyIncomeInvoiceLink::getInvoiceId, settlementVo.getInvoicingId()))
|
|
|
+ .forEach(item -> {
|
|
|
+ incomeIds.add(item.getIncomeId());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 判断是需要更新哪个字段
|
|
|
+ this.updateIncomeSettlementStatus(insPlyIncomeInvoice.getInvoiceType(), incomeIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }catch(Exception e){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<InsPlyIncomeInvoiceSettlement> getSettlementList(String invoiceId) {
|
|
|
+ return insPlyIncomeInvoiceSettlementMapper.selectList(new LambdaQueryWrapper<InsPlyIncomeInvoiceSettlement>()
|
|
|
+ .eq(InsPlyIncomeInvoiceSettlement::getInvoiceId, invoiceId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SuperviseExcelVo> importSuperviseExcel(MultipartFile file) {
|
|
|
+ SuperviseExcelListener listener = new SuperviseExcelListener();
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ EasyExcel.read(inputStream, SuperviseExcelVo.class, listener)
|
|
|
+ .sheet()
|
|
|
+ .doRead();
|
|
|
+ List<SuperviseExcelVo> dataList = listener.getDataList();
|
|
|
+ return dataList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OtherExcelVo> importOtherExcel(MultipartFile file) {
|
|
|
+ OtherExcelListener listener = new OtherExcelListener();
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ EasyExcel.read(inputStream, OtherExcelVo.class, listener)
|
|
|
+ .sheet()
|
|
|
+ .doRead();
|
|
|
+ List<OtherExcelVo> dataList = listener.getDataList();
|
|
|
+ return dataList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JyExcelVo> importJyExcel(MultipartFile file) {
|
|
|
+ JyExcelListener listener = new JyExcelListener();
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ EasyExcel.read(inputStream, OtherExcelVo.class, listener)
|
|
|
+ .sheet()
|
|
|
+ .doRead();
|
|
|
+ List<JyExcelVo> dataList = listener.getDataList();
|
|
|
+ return dataList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public ImportExcelResultVo importSuperviseData(MultipartFile file) {
|
|
|
+ ImportExcelResultVo importExcelResultVo = new ImportExcelResultVo();
|
|
|
+
|
|
|
+ List<SuperviseExcelVo> superviseExcelVos = importSuperviseExcel(file);
|
|
|
+ AssertionUtils.isEmpty(superviseExcelVos,"数据处理失败,导入失败");
|
|
|
+
|
|
|
+ // 获取保司名称
|
|
|
+ HttpResult<List<EsmInsCompany>> listHttpResult = esmInsCompanyClient.liveCompanyList();
|
|
|
+ AssertionUtils.isFail(listHttpResult.getCode() != 200,listHttpResult.getMsg());
|
|
|
+ List<EsmInsCompany> esmInsCompanies = listHttpResult.getData();
|
|
|
+
|
|
|
+ int failedNumber = 0;
|
|
|
+ List<Object> failedExcel = new ArrayList<>();
|
|
|
+ List<InsPlyIncome> successExcel = new ArrayList<>();
|
|
|
+ // 处理数据
|
|
|
+ for(SuperviseExcelVo vo : superviseExcelVos){
|
|
|
+ // 出现空数据则失败
|
|
|
+ ImportResultVo resultVo = vo.checkEmpty();
|
|
|
+ if(!resultVo.isSuccess()) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage(resultVo.getMessage());
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //匹配协议号
|
|
|
+ PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
+ .eq(PtlAgreement::getAgreementCode, vo.getAgreementCode()));
|
|
|
+ if (Objects.isNull(ptlAgreement)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配协议编号失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime signDate = null;
|
|
|
+ try {
|
|
|
+ // 解析签单时间
|
|
|
+ signDate = LocalDateTime.parse(vo.getSignDate(), DateTimeFormatter.ofPattern("yyyy-M-d H:m:s"));
|
|
|
+ }catch (DateTimeParseException e){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("解析签单时间失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //匹配保司名称
|
|
|
+ EsmInsCompany matchCompany = esmInsCompanies.stream()
|
|
|
+ .filter(x -> Objects.equals(x.getName(), vo.getInsuranceCompany()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ // 保司匹配失败
|
|
|
+ if (Objects.isNull(matchCompany)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配保司名称失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测是否有重复的保单号
|
|
|
+ InsPlyIncome checkInsPlyIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
+ .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
+ if(!Objects.isNull(checkInsPlyIncome)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("交强保单号重复");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
+ insPlyIncome.setId(IdGenerate.nextId());
|
|
|
+ insPlyIncome.setCompanyId(matchCompany.getId());
|
|
|
+ insPlyIncome.setSigningTime(signDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
+ insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
+ insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
+ insPlyIncome.setJqPremium(vo.getJqPremium().toString());
|
|
|
+ insPlyIncome.setJqSuperviseCostsProportion(vo.getJqSuperviseRatio().toString());
|
|
|
+ successExcel.add(insPlyIncome);
|
|
|
+ }
|
|
|
+
|
|
|
+ importExcelResultVo.setFailedData(failedExcel);
|
|
|
+ importExcelResultVo.setSuccessNumber(successExcel.size());
|
|
|
+ importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
+
|
|
|
+ // 批量插入数据
|
|
|
+ baseMapper.insert(successExcel);
|
|
|
+
|
|
|
+ return importExcelResultVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ImportExcelResultVo importOtherData(MultipartFile file) {
|
|
|
+ ImportExcelResultVo importExcelResultVo = new ImportExcelResultVo();
|
|
|
+
|
|
|
+ List<OtherExcelVo> otherExcelVos = importOtherExcel(file);
|
|
|
+ AssertionUtils.isEmpty(otherExcelVos,"数据处理失败,导入失败");
|
|
|
+
|
|
|
+ // 获取保司名称
|
|
|
+ HttpResult<List<EsmInsCompany>> listHttpResult = esmInsCompanyClient.liveCompanyList();
|
|
|
+ AssertionUtils.isFail(listHttpResult.getCode() != 200,listHttpResult.getMsg());
|
|
|
+ List<EsmInsCompany> esmInsCompanies = listHttpResult.getData();
|
|
|
+
|
|
|
+ int failedNumber = 0;
|
|
|
+ List<Object> failedExcel = new ArrayList<>();
|
|
|
+ List<InsPlyIncome> successExcel = new ArrayList<>();
|
|
|
+ // 处理数据
|
|
|
+ for(OtherExcelVo vo : otherExcelVos){
|
|
|
+ // 出现空数据则失败
|
|
|
+ ImportResultVo resultVo = vo.checkEmpty();
|
|
|
+ if(!resultVo.isSuccess()) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage(resultVo.getMessage());
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //匹配协议号
|
|
|
+ PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
+ .eq(PtlAgreement::getAgreementCode, vo.getAgreementCode()));
|
|
|
+ if (Objects.isNull(ptlAgreement)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配协议编号失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime signDate = null;
|
|
|
+ try {
|
|
|
+ // 解析签单时间
|
|
|
+ signDate = LocalDateTime.parse(vo.getSignDate(), DateTimeFormatter.ofPattern("yyyy-M-d H:m:s"));
|
|
|
+ }catch (DateTimeParseException e){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("解析签单时间失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //匹配保司名称
|
|
|
+ EsmInsCompany matchCompany = esmInsCompanies.stream()
|
|
|
+ .filter(x -> Objects.equals(x.getName(), vo.getInsuranceCompany()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ // 保司匹配失败
|
|
|
+ if (Objects.isNull(matchCompany)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配保司名称失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测是否有重复的保单号
|
|
|
+ InsPlyIncome checkInsPlyIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
+ .eq(InsPlyIncome::getJqPolicyNo, vo.getJqPolicyNo()));
|
|
|
+ if(!Objects.isNull(checkInsPlyIncome)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("车险保单号重复");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
+ insPlyIncome.setId(IdGenerate.nextId());
|
|
|
+ insPlyIncome.setCompanyId(matchCompany.getId());
|
|
|
+ insPlyIncome.setSigningTime(signDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
+ insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
+ insPlyIncome.setJqPolicyNo(vo.getJqPolicyNo());
|
|
|
+ insPlyIncome.setJqPremium(vo.getJqPremium().toString());
|
|
|
+ insPlyIncome.setJqOtherCostsProportion(vo.getJqOtherRatio().toString());
|
|
|
+ successExcel.add(insPlyIncome);
|
|
|
+ }
|
|
|
+
|
|
|
+ importExcelResultVo.setFailedData(failedExcel);
|
|
|
+ importExcelResultVo.setSuccessNumber(successExcel.size());
|
|
|
+ importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
+
|
|
|
+ // 批量插入数据
|
|
|
+ baseMapper.insert(successExcel);
|
|
|
+
|
|
|
+ return importExcelResultVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ImportExcelResultVo importJyData(MultipartFile file) {
|
|
|
+ ImportExcelResultVo importExcelResultVo = new ImportExcelResultVo();
|
|
|
+
|
|
|
+ List<JyExcelVo> jyExcelVos = importJyExcel(file);
|
|
|
+ AssertionUtils.isEmpty(jyExcelVos,"数据处理失败,导入失败");
|
|
|
+
|
|
|
+ // 获取保司名称
|
|
|
+ HttpResult<List<EsmInsCompany>> listHttpResult = esmInsCompanyClient.liveCompanyList();
|
|
|
+ AssertionUtils.isFail(listHttpResult.getCode() != 200,listHttpResult.getMsg());
|
|
|
+ List<EsmInsCompany> esmInsCompanies = listHttpResult.getData();
|
|
|
+
|
|
|
+ int failedNumber = 0;
|
|
|
+ List<Object> failedExcel = new ArrayList<>();
|
|
|
+ List<InsPlyIncome> successExcel = new ArrayList<>();
|
|
|
+ // 处理数据
|
|
|
+ for(JyExcelVo vo : jyExcelVos){
|
|
|
+ // 出现空数据则失败
|
|
|
+ ImportResultVo resultVo = vo.checkEmpty();
|
|
|
+ if(!resultVo.isSuccess()) {
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage(resultVo.getMessage());
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //匹配协议号
|
|
|
+ PtlAgreement ptlAgreement = ptlAgreementMapper.selectOne(new LambdaQueryWrapper<PtlAgreement>()
|
|
|
+ .eq(PtlAgreement::getAgreementCode, vo.getAgreementCode()));
|
|
|
+ if (Objects.isNull(ptlAgreement)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配协议编号失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ LocalDateTime signDate = null;
|
|
|
+ try {
|
|
|
+ // 解析签单时间
|
|
|
+ signDate = LocalDateTime.parse(vo.getSignDate(), DateTimeFormatter.ofPattern("yyyy-M-d H:m:s"));
|
|
|
+ }catch (DateTimeParseException e){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("解析签单时间失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //匹配保司名称
|
|
|
+ EsmInsCompany matchCompany = esmInsCompanies.stream()
|
|
|
+ .filter(x -> Objects.equals(x.getName(), vo.getInsuranceCompany()))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ // 保司匹配失败
|
|
|
+ if (Objects.isNull(matchCompany)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("匹配保司名称失败");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检测是否有重复的保单号
|
|
|
+ InsPlyIncome checkInsPlyIncome = baseMapper.selectOne(new LambdaQueryWrapper<InsPlyIncome>()
|
|
|
+ .eq(InsPlyIncome::getJyPolicyNo, vo.getJyPolicyNo()));
|
|
|
+ if(!Objects.isNull(checkInsPlyIncome)){
|
|
|
+ failedNumber++;
|
|
|
+ vo.setErrorMessage("驾意保单号重复");
|
|
|
+ failedExcel.add(vo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ InsPlyIncome insPlyIncome = new InsPlyIncome();
|
|
|
+ insPlyIncome.setId(IdGenerate.nextId());
|
|
|
+ insPlyIncome.setCompanyId(matchCompany.getId());
|
|
|
+ insPlyIncome.setSigningTime(signDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ insPlyIncome.setAgreementId(ptlAgreement.getId());
|
|
|
+ insPlyIncome.setLicenseNo(vo.getLicenseNo());
|
|
|
+ insPlyIncome.setJyPolicyNo(vo.getJyPolicyNo());
|
|
|
+ insPlyIncome.setJyPremium(vo.getJyPremium().toString());
|
|
|
+ insPlyIncome.setJySuperviseCostsProportion(vo.getJySuperviseRatio().toString());
|
|
|
+ insPlyIncome.setJyOtherCostsProportion(vo.getJyOtherRatio().toString());
|
|
|
+ successExcel.add(insPlyIncome);
|
|
|
+ }
|
|
|
+
|
|
|
+ importExcelResultVo.setFailedData(failedExcel);
|
|
|
+ importExcelResultVo.setSuccessNumber(successExcel.size());
|
|
|
+ importExcelResultVo.setFailedNumber(failedNumber);
|
|
|
+
|
|
|
+ // 批量插入数据
|
|
|
+ baseMapper.insert(successExcel);
|
|
|
+
|
|
|
+ return importExcelResultVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public boolean batchModify(BatchModifyVo batchModifyVo) {
|
|
|
+ List<InsPlyIncome> updateInsPlyIncome = new ArrayList<>();
|
|
|
+
|
|
|
+ for (String incomeId : batchModifyVo.getIncomeIds()){
|
|
|
+ InsPlyIncome insPlyIncome = baseMapper.selectById(incomeId);
|
|
|
+ if (Objects.nonNull(insPlyIncome)){
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJqSuperviseCostsProportion()) && batchModifyVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal superviseReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getJqPremium()),batchModifyVo.getJqSuperviseCostsProportion());
|
|
|
+ insPlyIncome.setJqSuperviseCostsPremiums(superviseReceivablePremium.toString());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(batchModifyVo.getSySuperviseCostsProportion()) && batchModifyVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ BigDecimal otherReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getSyPremium()), batchModifyVo.getSySuperviseCostsProportion());
|
|
|
+ insPlyIncome.setSySuperviseCostsPremiums(otherReceivablePremium.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJqOtherCostsProportion()) && batchModifyVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal otherReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getJqPremium()),batchModifyVo.getJqOtherCostsProportion());
|
|
|
+ insPlyIncome.setJqOtherCostsPremiums(otherReceivablePremium.toString());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(batchModifyVo.getSyOtherCostsProportion()) && batchModifyVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ BigDecimal otherReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getSyPremium()), batchModifyVo.getSyOtherCostsProportion());
|
|
|
+ insPlyIncome.setSySuperviseCostsPremiums(otherReceivablePremium.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJySuperviseCostsProportion()) && batchModifyVo.getJySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal jySuperviseReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getJyPremium()),batchModifyVo.getJySuperviseCostsProportion());
|
|
|
+ insPlyIncome.setJySuperviseCostsPremiums(jySuperviseReceivablePremium.toString());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(batchModifyVo.getJySuperviseCostsProportion()) && batchModifyVo.getJySuperviseCostsProportion().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ BigDecimal jyOtherReceivablePremium = calcReceivableAmount(new BigDecimal(insPlyIncome.getJyPremium()), batchModifyVo.getJySuperviseCostsProportion());
|
|
|
+ insPlyIncome.setJyOtherCostsPremiums(jyOtherReceivablePremium.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (batchModifyVo.getSigningTime() != null){
|
|
|
+ insPlyIncome.setSigningTime(batchModifyVo.getSigningTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ updateInsPlyIncome.add(insPlyIncome);
|
|
|
+ }
|
|
|
+ baseMapper.updateById(updateInsPlyIncome);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量修改
|
|
|
+ baseMapper.update(new InsPlyIncome(), new LambdaUpdateWrapper<InsPlyIncome>()
|
|
|
+ .set(InsPlyIncome::getJqSuperviseCostsProportion, batchModifyVo.getJqSuperviseCostsProportion())
|
|
|
+ .set(InsPlyIncome::getSySuperviseCostsProportion, batchModifyVo.getSySuperviseCostsProportion())
|
|
|
+ .set(InsPlyIncome::getJySuperviseCostsProportion, batchModifyVo.getJySuperviseCostsProportion())
|
|
|
+ .set(InsPlyIncome::getJqOtherCostsProportion, batchModifyVo.getJqOtherCostsProportion())
|
|
|
+ .set(InsPlyIncome::getSyOtherCostsProportion, batchModifyVo.getSyOtherCostsProportion())
|
|
|
+ .set(InsPlyIncome::getJyOtherCostsProportion, batchModifyVo.getJyOtherCostsProportion())
|
|
|
+ .set(InsPlyIncome::getSigningTime, batchModifyVo.getSigningTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
|
|
|
+ .in(InsPlyIncome::getId, batchModifyVo.getIncomeIds()));
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BigDecimal calcReceivableAmount(BigDecimal premium,BigDecimal ratio) {
|
|
|
+ return premium.multiply(ratio);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|