1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.by4cloud.platformx.business.service.impl;
 
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
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.entity.BusinessCustomer;
import com.by4cloud.platformx.business.mapper.BipBanklViewMapper;
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.common.core.util.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * 客商信息
 *
 * @author platformx
 * @date 2026-05-07 10:13:22
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BusinessCustomerServiceImpl extends ServiceImpl<BusinessCustomerMapper, BusinessCustomer> implements BusinessCustomerService {
 
    private final BipViewMapper bipViewMapper;
    private final BipBanklViewMapper bipBanklViewMapper;
 
    @Override
    public R syncMainBusCus(String compId) {
        List<BusinessCustomer> bcList = baseMapper.selectList(Wrappers.<BusinessCustomer>lambdaQuery()
                .eq(StrUtil.isNotEmpty(compId),BusinessCustomer::getCompId,compId)
                .and(wrapper -> wrapper.isNull(BusinessCustomer::getCreditCode)
                .or().isNull(BusinessCustomer::getLegalPerson)
                .or().isNull(BusinessCustomer::getBankName)
                .or().isNull(BusinessCustomer::getBankAccount)
                .or().isNull(BusinessCustomer::getRegisterName))
        );
        if (ArrayUtil.isNotEmpty(bcList.toArray())){
            for (BusinessCustomer bc:bcList
                 ) {
                log.info("开始同步{}信息",bc.getCompanyName());
                CustInfoVo custInfo = bipViewMapper.selectBaseInfoByCustName(bc.getCompanyName());
                if (ObjUtil.isNotNull(custInfo)){
                    bc.setCreditCode(custInfo.getCertificateId());
                    bc.setRegisterName(custInfo.getCustName());
                    bc.setLegalPerson(custInfo.getLegalPerson());
                    bc.setAddress(custInfo.getRegistrationAddress());
                    baseMapper.updateById(bc);
                    log.info("{}同步名称、法人、地址、信用码信息成功",bc.getCompanyName());
                }
                List<CustBankVo> bankVoList = bipViewMapper.selectBankByCustName(bc.getCompanyName());
                if (ArrayUtil.isNotEmpty(bankVoList.toArray())){
                    if (StrUtil.isEmpty(bc.getBankAccount())){
                        bc.setBankAccount(bankVoList.get(0).getBankAccount());
                        baseMapper.updateById(bc);
                        log.info("{}同步银行卡号信息成功",bc.getCompanyName());
                    }
                    List<BankNameVo> bankNameVoList = bipBanklViewMapper.selectBankByCode(bankVoList.get(0).getBankName());
                    if (ArrayUtil.isNotEmpty(bankNameVoList.toArray())){
                        bc.setBankName(bankNameVoList.get(0).getBankNameName());
                        baseMapper.updateById(bc);
                        log.info("{}同步银行名称信息成功",bc.getCompanyName());
                    }
                }
 
            }
        }
        return R.ok();
    }
 
    @Override
    public BusinessCustomerMainVo queryMainBC(String companyName) {
        BusinessCustomerMainVo bc = new BusinessCustomerMainVo();
        bc.setCompanyName(companyName);
        log.info("主数据查询{}信息",companyName);
        CustInfoVo custInfo = bipViewMapper.selectBaseInfoByCustName(companyName);
        if (ObjUtil.isNotNull(custInfo)){
            bc.setCreditCode(custInfo.getCertificateId());
            bc.setRegisterName(custInfo.getCustName());
            bc.setLegalPerson(custInfo.getLegalPerson());
            bc.setAddress(custInfo.getRegistrationAddress());
            log.info("{}主数据查询名称、法人、地址、信用码信息成功",companyName);
        }
        List<CustBankVo> bankVoList = bipViewMapper.selectBankByCustName(bc.getCompanyName());
        if (ArrayUtil.isNotEmpty(bankVoList.toArray())){
            if (StrUtil.isEmpty(bc.getBankAccount())){
                bc.setBankAccount(bankVoList.get(0).getBankAccount());
                log.info("{}主数据查询银行卡号信息成功",companyName);
            }
            List<BankNameVo> bankNameVoList = bipBanklViewMapper.selectBankByCode(bankVoList.get(0).getBankName());
            if (ArrayUtil.isNotEmpty(bankNameVoList.toArray())){
                bc.setBankName(bankNameVoList.get(0).getBankNameName());
                log.info("{}主数据查询银行名称信息成功",companyName);
            }
        }
        return bc;
    }
}