shiyunteng
2026-10-30 145580fd820bb31334f2e71643413e846b7ce904
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BusinessCustomerServiceImpl.java
@@ -1,5 +1,6 @@
package com.by4cloud.platformx.business.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
@@ -12,16 +13,18 @@
import com.by4cloud.platformx.business.mapper.BipViewMapper;
import com.by4cloud.platformx.business.mapper.BusinessCustomerMapper;
import com.by4cloud.platformx.business.service.BusinessCustomerService;
import com.by4cloud.platformx.business.vo.BankNameVo;
import com.by4cloud.platformx.business.vo.BusinessCustomerMainVo;
import com.by4cloud.platformx.business.vo.CustBankVo;
import com.by4cloud.platformx.business.vo.CustInfoVo;
import com.by4cloud.platformx.business.vo.*;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.excel.vo.ErrorMessage;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
 * 客商信息
@@ -122,11 +125,14 @@
         return R.failed("客商名称或社会信用代码不能为空");
      }
      BusinessCustomer bc = baseMapper.selectOne(Wrappers.<BusinessCustomer>lambdaQuery().eq(BusinessCustomer::getCompanyName,addDTO.getCompanyName())
            .eq(BusinessCustomer::getCreditCode,addDTO.getCreditCode()).last("limit 1"));
            .eq(BusinessCustomer::getCreditCode,addDTO.getCreditCode())
            .eq(BusinessCustomer::getCompId, SecurityUtils.getUser().getCompId())
            .last("limit 1"));
      if (ObjUtil.isNotNull(bc)){
         return R.failed("客商已存在");
      }
      BusinessCustomer customer = new BusinessCustomer();
      customer.setErpCompanyCode(addDTO.getErpCompanyCode());
      log.info("主数据查询{}信息",addDTO.getCompanyName());
      CustInfoVo custInfo = bipViewMapper.selectBaseInfoByCustName(addDTO.getCompanyName());
      if (ObjUtil.isNotNull(custInfo)){
@@ -166,4 +172,50 @@
      }
      return R.failed("主数据客商信息不存在");
   }
   @Override
   public R importBusinessCustomer(List<BusinessCustomerImportVo> excelVOList, BindingResult bindingResult) {
      List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
      if (CollUtil.isNotEmpty(excelVOList)) {
         Long line = 0L;
         for (BusinessCustomerImportVo excelVO : excelVOList
         ) {
            Set<String> errorMsg = new HashSet<>();
            if (StrUtil.isBlank(excelVO.getCreditCode())||StrUtil.isBlank(excelVO.getErpCompanyCode())){
               errorMsg.add(excelVO.getCompanyName()+"社会信用代码或ERP客户编码不能为空");
               errorMessageList.add(new ErrorMessage(line++, errorMsg));
               continue;
            }
            BusinessCustomer customer = baseMapper.selectOne(Wrappers.<BusinessCustomer>lambdaQuery()
                  .eq(BusinessCustomer::getCreditCode, excelVO.getCreditCode())
                  .last("limit 1"));
            if (ObjUtil.isNull(customer)) {
               customer = BeanUtil.copyProperties(excelVO, BusinessCustomer.class);
               CustInfoVo custInfo = bipViewMapper.selectBaseInfoByCertId(excelVO.getCreditCode());
               if (ObjUtil.isNotNull(custInfo)) {
                  customer.setCreditCode(custInfo.getCertificateId());
                  customer.setRegisterName(custInfo.getCustName());
                  customer.setLegalPerson(custInfo.getLegalPerson());
                  customer.setAddress(custInfo.getRegistrationAddress());
                  customer.setProvince(customer.getCreditCode().substring(2, 4));
                  customer.setInvoiceType("01");
                  log.info("{}主数据查询名称、法人、地址、信用码信息成功", excelVO.getCompanyName());
                  List<CustBankVo> bankVoList = bipViewMapper.selectBankByCustName(excelVO.getCompanyName());
                  if (CollUtil.isNotEmpty(bankVoList)) {
                     customer.setBankAccount(bankVoList.get(0).getBankAccount());
                     log.info("{}主数据查询银行卡号信息成功", excelVO.getCompanyName());
                     List<BankNameVo> bankNameVoList = bipBanklViewMapper.selectBankByCode(bankVoList.get(0).getBankName());
                     if (CollUtil.isNotEmpty(bankNameVoList)) {
                        customer.setBankName(bankNameVoList.get(0).getBankNameName());
                        log.info("{}主数据查询银行名称信息成功", excelVO.getCompanyName());
                     }
                  }
                  customer.setRegisterName(custInfo.getCustName());
                  baseMapper.insert(customer);
               }
            }
         }
      }
      return R.ok();
   }
}