platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BusinessCustomerServiceImpl.java
@@ -6,6 +6,7 @@
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by4cloud.platformx.business.dto.BusinessCustomerAddDTO;
import com.by4cloud.platformx.business.entity.BusinessCustomer;
import com.by4cloud.platformx.business.mapper.BipBanklViewMapper;
import com.by4cloud.platformx.business.mapper.BipViewMapper;
@@ -114,4 +115,55 @@
      }
      return bc;
   }
   @Override
   public R saveCustomerSgb(BusinessCustomerAddDTO addDTO) {
      if (StrUtil.isBlank(addDTO.getCompanyName())||StrUtil.isBlank(addDTO.getCreditCode())){
         return R.failed("客商名称或社会信用代码不能为空");
      }
      BusinessCustomer bc = baseMapper.selectOne(Wrappers.<BusinessCustomer>lambdaQuery().eq(BusinessCustomer::getCompanyName,addDTO.getCompanyName())
            .eq(BusinessCustomer::getCreditCode,addDTO.getCreditCode()).last("limit 1"));
      if (ObjUtil.isNotNull(bc)){
         return R.failed("客商已存在");
      }
      BusinessCustomer customer = new BusinessCustomer();
      log.info("主数据查询{}信息",addDTO.getCompanyName());
      CustInfoVo custInfo = bipViewMapper.selectBaseInfoByCustName(addDTO.getCompanyName());
      if (ObjUtil.isNotNull(custInfo)){
         if (!addDTO.getCreditCode().equals(custInfo.getCertificateId())){
            return R.failed("主数据社会信用代码与新增的不一致");
         }
         customer.setCompanyName(addDTO.getCompanyName());
         customer.setCreditCode(custInfo.getCertificateId());
         customer.setRegisterName(custInfo.getCustName());
         customer.setLegalPerson(custInfo.getLegalPerson());
         customer.setAddress(custInfo.getRegistrationAddress());
         customer.setProvince(customer.getCreditCode().substring(2,4));
         if (StrUtil.isNotEmpty(addDTO.getSalesModel())&& addDTO.getSalesModel().matches("[0-9]+")){
            customer.setSalesModel(Long.valueOf(addDTO.getSalesModel()));
         }
         if (StrUtil.isNotEmpty(addDTO.getExportServiceAttr())&& addDTO.getExportServiceAttr().matches("[0-9]+")){
            customer.setExportServiceAttr(Long.valueOf(addDTO.getExportServiceAttr()));
         }
         if (StrUtil.isNotEmpty(addDTO.getClassId())&& addDTO.getClassId().matches("[0-9]+")){
            customer.setClassId(Long.valueOf(addDTO.getClassId()));
         }
         customer.setInvoiceType("01");
         log.info("{}主数据查询名称、法人、地址、信用码信息成功",addDTO.getCompanyName());
         List<CustBankVo> bankVoList = bipViewMapper.selectBankByCustName(addDTO.getCompanyName());
         if (CollUtil.isNotEmpty(bankVoList)){
            customer.setBankAccount(bankVoList.get(0).getBankAccount());
            log.info("{}主数据查询银行卡号信息成功",addDTO.getCompanyName());
            List<BankNameVo> bankNameVoList = bipBanklViewMapper.selectBankByCode(bankVoList.get(0).getBankName());
            if (CollUtil.isNotEmpty(bankNameVoList)){
               customer.setBankName(bankNameVoList.get(0).getBankNameName());
               log.info("{}主数据查询银行名称信息成功",addDTO.getCompanyName());
            }
         }
         customer.setRegisterName(custInfo.getCustName());
         baseMapper.insert(customer);
         return R.ok();
      }
      return R.failed("主数据客商信息不存在");
   }
}