|
|
@@ -41,9 +41,7 @@ import org.dromara.product.api.domain.dto.OrderStatusCountDto;
|
|
|
import org.dromara.system.api.*;
|
|
|
import org.dromara.system.api.domain.bo.RemoteUserBo;
|
|
|
import org.dromara.system.api.domain.dto.AddressAreaDTO;
|
|
|
-import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
|
|
-import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
|
|
-import org.dromara.system.api.domain.vo.RemoteUserWechatVo;
|
|
|
+import org.dromara.system.api.domain.vo.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -92,6 +90,15 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@DubboReference
|
|
|
private RemoteComCustomerLevelService remoteComCustomerLevelService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteComCurrencyService remoteComCurrencyService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteComCustomerTypeService remoteComCustomerTypeService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteProductTaxrateService remoteProductTaxrateService;
|
|
|
+
|
|
|
@DubboReference
|
|
|
private RemoteDictService remoteDictService;
|
|
|
|
|
|
@@ -740,36 +747,6 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
LambdaQueryWrapper<CustomerInfo> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.orderByDesc(CustomerInfo::getId);
|
|
|
|
|
|
- // 数据权限过滤:只能查看自己创建的、或者是业务负责人、或者是客服支持的客户
|
|
|
- if (bo.getCreateBy() != null || bo.getSalesPersonId() != null || bo.getServiceStaffId() != null) {
|
|
|
- lqw.and(wrapper -> {
|
|
|
- boolean first = true;
|
|
|
- if (bo.getCreateBy() != null) {
|
|
|
- if (first) {
|
|
|
- wrapper.eq(CustomerInfo::getCreateBy, bo.getCreateBy());
|
|
|
- first = false;
|
|
|
- } else {
|
|
|
- wrapper.or().eq(CustomerInfo::getCreateBy, bo.getCreateBy());
|
|
|
- }
|
|
|
- }
|
|
|
- if (bo.getSalesPersonId() != null) {
|
|
|
- if (first) {
|
|
|
- wrapper.eq(CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
|
|
|
- first = false;
|
|
|
- } else {
|
|
|
- wrapper.or().eq(CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
|
|
|
- }
|
|
|
- }
|
|
|
- if (bo.getServiceStaffId() != null) {
|
|
|
- if (first) {
|
|
|
- wrapper.eq(CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
|
|
|
- } else {
|
|
|
- wrapper.or().eq(CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getCustomerNo()), CustomerInfo::getCustomerNo, bo.getCustomerNo());
|
|
|
lqw.eq(bo.getBelongCompanyId() != null, CustomerInfo::getBelongCompanyId, bo.getBelongCompanyId());
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getCompanyName()), CustomerInfo::getCompanyName, bo.getCompanyName());
|
|
|
@@ -1756,6 +1733,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
+
|
|
|
CustomerSalesInfoBo customerSalesInfoBo = bo.getCustomerSalesInfoBo();
|
|
|
customerSalesInfoBo.setCustomerId(add.getId());
|
|
|
CustomerSalesInfo bean = BeanUtil.toBean(customerSalesInfoBo, CustomerSalesInfo.class);
|
|
|
@@ -2032,4 +2010,275 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
return affirmFlag;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出模板数据:查询指定数量的客户数据,转换为导入模板格式
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CustomerInfoImportVo> queryImportTemplateList(int limit) {
|
|
|
+ List<CustomerInfoVo> list;
|
|
|
+
|
|
|
+ if (limit <= 0) {
|
|
|
+ // 导出全部
|
|
|
+ list = baseMapper.selectVoList(new LambdaQueryWrapper<>());
|
|
|
+ } else {
|
|
|
+ // 1. 分页查询客户主表数据(带销售信息)
|
|
|
+ PageQuery pageQuery = new PageQuery();
|
|
|
+ pageQuery.setPageNum(1);
|
|
|
+ pageQuery.setPageSize(limit);
|
|
|
+ TableDataInfo<CustomerInfoVo> pageResult = queryPageList(new CustomerInfoBo(), pageQuery);
|
|
|
+ list = pageResult.getRows();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 收集所有需要远程查询的ID
|
|
|
+ Set<Long> companyIds = new HashSet<>();
|
|
|
+ Set<Long> customerLevelIds = new HashSet<>();
|
|
|
+ Set<Long> customerTypeIds = new HashSet<>();
|
|
|
+ Set<Long> industryCategoryIds = new HashSet<>();
|
|
|
+ Set<Long> enterpriseScaleIds = new HashSet<>();
|
|
|
+ Set<Long> comStaffIds = new HashSet<>();
|
|
|
+ Set<Long> creditLevelIds = new HashSet<>();
|
|
|
+ Set<Long> dealCurrencyIds = new HashSet<>();
|
|
|
+ Set<Long> rateIds = new HashSet<>();
|
|
|
+ Set<Long> erpStaffIds = new HashSet<>();
|
|
|
+
|
|
|
+ for (CustomerInfoVo vo : list) {
|
|
|
+ if (vo.getBelongCompanyId() != null) companyIds.add(vo.getBelongCompanyId());
|
|
|
+ if (vo.getCustomerLevelId() != null) customerLevelIds.add(vo.getCustomerLevelId());
|
|
|
+ if (vo.getCustomerTypeId() != null) customerTypeIds.add(vo.getCustomerTypeId());
|
|
|
+ if (vo.getIndustryCategoryId() != null) industryCategoryIds.add(vo.getIndustryCategoryId());
|
|
|
+ if (vo.getEnterpriseScaleId() != null) enterpriseScaleIds.add(vo.getEnterpriseScaleId());
|
|
|
+ if (vo.getSalesPersonId() != null) comStaffIds.add(vo.getSalesPersonId());
|
|
|
+ if (vo.getServiceStaffId() != null) comStaffIds.add(vo.getServiceStaffId());
|
|
|
+
|
|
|
+ CustomerSalesInfoVo salesVo = vo.getCustomerSalesInfoVo();
|
|
|
+ if (salesVo != null) {
|
|
|
+ if (salesVo.getCreditLevelId() != null) creditLevelIds.add(salesVo.getCreditLevelId());
|
|
|
+ if (salesVo.getDealCurrencyId() != null) dealCurrencyIds.add(salesVo.getDealCurrencyId());
|
|
|
+ if (salesVo.getRateId() != null) rateIds.add(salesVo.getRateId());
|
|
|
+ if (salesVo.getSalesPersonId() != null) erpStaffIds.add(salesVo.getSalesPersonId());
|
|
|
+ if (salesVo.getServiceStaffId() != null) erpStaffIds.add(salesVo.getServiceStaffId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 批量查询远程服务获取名称和编码
|
|
|
+ // 公司:通过 selectCompanyList 全量加载后构建Map(因无批量ID查询方法)
|
|
|
+ Map<Long, RemoteComCompanyVo> companyMap = new HashMap<>();
|
|
|
+ if (!companyIds.isEmpty()) {
|
|
|
+ List<RemoteComCompanyVo> companyList = remoteComCompanyService.selectCompanyList();
|
|
|
+ for (RemoteComCompanyVo vo : companyList) {
|
|
|
+ if (companyIds.contains(vo.getId())) {
|
|
|
+ companyMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 客户等级:通过ID批量查询
|
|
|
+ Map<Long, String> customerLevelNameMap = customerLevelIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteComCustomerLevelService.selectCustomerLevelNameByIds(customerLevelIds);
|
|
|
+ Map<Long, RemoteComCustomerLevelVo> customerLevelMap = new HashMap<>();
|
|
|
+ if (!customerLevelIds.isEmpty()) {
|
|
|
+ List<RemoteComCustomerLevelVo> levelList = remoteComCustomerLevelService.selectCustomerLevelList();
|
|
|
+ for (RemoteComCustomerLevelVo vo : levelList) {
|
|
|
+ if (customerLevelIds.contains(vo.getId())) {
|
|
|
+ customerLevelMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 客户类型
|
|
|
+ Map<Long, RemoteComCustomerTypeVo> customerTypeMap = new HashMap<>();
|
|
|
+ if (!customerTypeIds.isEmpty()) {
|
|
|
+ List<RemoteComCustomerTypeVo> typeList = remoteComCustomerTypeService.selectCustomerTypeByIds(customerTypeIds);
|
|
|
+ for (RemoteComCustomerTypeVo vo : typeList) {
|
|
|
+ customerTypeMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 行业类别
|
|
|
+ Map<Long, IndustryCategoryVo> industryCategoryMap = new HashMap<>();
|
|
|
+ if (!industryCategoryIds.isEmpty()) {
|
|
|
+ List<IndustryCategoryVo> industryList = industryCategoryMapper.selectVoByIds(industryCategoryIds);
|
|
|
+ for (IndustryCategoryVo vo : industryList) {
|
|
|
+ industryCategoryMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 企业规模
|
|
|
+ Map<Long, EnterpriseScaleVo> enterpriseScaleMap = new HashMap<>();
|
|
|
+ if (!enterpriseScaleIds.isEmpty()) {
|
|
|
+ List<EnterpriseScaleVo> scaleList = enterpriseScaleMapper.selectVoByIds(enterpriseScaleIds);
|
|
|
+ for (EnterpriseScaleVo vo : scaleList) {
|
|
|
+ enterpriseScaleMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 系统人员(ComStaff)
|
|
|
+ Map<Long, RemoteComStaffVo> comStaffMap = new HashMap<>();
|
|
|
+ if (!comStaffIds.isEmpty()) {
|
|
|
+ List<RemoteComStaffVo> staffList = remoteComStaffService.selectStaffByIds(comStaffIds);
|
|
|
+ for (RemoteComStaffVo vo : staffList) {
|
|
|
+ comStaffMap.put(vo.getStaffId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 信用等级
|
|
|
+ Map<Long, String> creditLevelNameMap = creditLevelIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteCreditLevelService.selectCreditLevelNameByIds(creditLevelIds);
|
|
|
+
|
|
|
+ // 交易币别
|
|
|
+ Map<Long, RemoteComCurrencyVo> currencyMap = new HashMap<>();
|
|
|
+ if (!dealCurrencyIds.isEmpty()) {
|
|
|
+ List<RemoteComCurrencyVo> currencyList = remoteComCurrencyService.selectCurrencyByIds(dealCurrencyIds);
|
|
|
+ for (RemoteComCurrencyVo vo : currencyList) {
|
|
|
+ currencyMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 税码
|
|
|
+ Map<Long, RemoteProductTaxrateVo> taxrateMap = new HashMap<>();
|
|
|
+ if (!rateIds.isEmpty()) {
|
|
|
+ List<RemoteProductTaxrateVo> taxrateList = remoteProductTaxrateService.selectTaxrateByIds(rateIds);
|
|
|
+ for (RemoteProductTaxrateVo vo : taxrateList) {
|
|
|
+ taxrateMap.put(vo.getId(), vo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ERP人员
|
|
|
+ Map<Long, String> erpStaffNameMap = erpStaffIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteErpStaffService.selectStaffNameByIds(erpStaffIds);
|
|
|
+
|
|
|
+ // 信用等级名称 → 数字映射(用于导出)
|
|
|
+ Map<String, String> creditLevelReverseMap = Map.of(
|
|
|
+ "A", "0", "B", "1", "C", "2", "D", "3", "E", "4", "F", "5", "G", "6"
|
|
|
+ );
|
|
|
+
|
|
|
+ // 客户来源字典 (customer_source) - dictValue → dictLabel
|
|
|
+ Map<String, String> customerSourceDictMap = new HashMap<>();
|
|
|
+ List<RemoteDictDataVo> customerSourceDicts = remoteDictService.selectDictDataByType("customer_source");
|
|
|
+ CollUtil.emptyIfNull(customerSourceDicts).forEach(d -> customerSourceDictMap.put(d.getDictValue(), d.getDictLabel()));
|
|
|
+
|
|
|
+ // 销售通路字典 (sell_channel) - dictValue → dictLabel
|
|
|
+ Map<String, String> sellChannelDictMap = new HashMap<>();
|
|
|
+ List<RemoteDictDataVo> sellChannelDicts = remoteDictService.selectDictDataByType("sell_channel");
|
|
|
+ CollUtil.emptyIfNull(sellChannelDicts).forEach(d -> sellChannelDictMap.put(d.getDictValue(), d.getDictLabel()));
|
|
|
+
|
|
|
+ // 4. 构建导出VO列表
|
|
|
+ List<CustomerInfoImportVo> exportList = new ArrayList<>();
|
|
|
+ for (CustomerInfoVo vo : list) {
|
|
|
+ CustomerInfoImportVo importVo = new CustomerInfoImportVo();
|
|
|
+
|
|
|
+ // 公司信息
|
|
|
+ RemoteComCompanyVo companyVo = companyMap.get(vo.getBelongCompanyId());
|
|
|
+ importVo.setCompanyCode(companyVo != null ? companyVo.getCompanyCode() : null);
|
|
|
+ importVo.setCompanyName(companyVo != null ? companyVo.getCompanyName() : vo.getCompanyName());
|
|
|
+
|
|
|
+ // 基本信息
|
|
|
+ importVo.setCustomerNo(vo.getCustomerNo());
|
|
|
+ importVo.setCustomerName(vo.getCustomerName());
|
|
|
+ importVo.setBusinessCustomerName(vo.getBusinessCustomerName());
|
|
|
+ importVo.setShortName(vo.getShortName());
|
|
|
+ importVo.setSocialCreditCode(vo.getSocialCreditCode());
|
|
|
+
|
|
|
+ // 地址信息
|
|
|
+ importVo.setProvinceNo(vo.getRegProvincialNo());
|
|
|
+ importVo.setCityNo(vo.getRegCityNo());
|
|
|
+ importVo.setAreaNo(vo.getRegCountyNo());
|
|
|
+ importVo.setAddress(vo.getAddress());
|
|
|
+
|
|
|
+ // 客户等级
|
|
|
+ RemoteComCustomerLevelVo levelVo = customerLevelMap.get(vo.getCustomerLevelId());
|
|
|
+ importVo.setCustomerLevelNo(levelVo != null ? levelVo.getLevelCode() : null);
|
|
|
+ importVo.setCustomerLevelName(levelVo != null ? levelVo.getLevelName() : customerLevelNameMap.get(vo.getCustomerLevelId()));
|
|
|
+
|
|
|
+ // 客户类型
|
|
|
+ RemoteComCustomerTypeVo typeVo = customerTypeMap.get(vo.getCustomerTypeId());
|
|
|
+ importVo.setCustomerTypeNo(typeVo != null ? typeVo.getTypeCode() : null);
|
|
|
+ importVo.setCustomerTypeName(typeVo != null ? typeVo.getTypeName() : null);
|
|
|
+
|
|
|
+ // 行业类别
|
|
|
+ IndustryCategoryVo industryVo = industryCategoryMap.get(vo.getIndustryCategoryId());
|
|
|
+ importVo.setIndustryCategoryNo(industryVo != null ? industryVo.getIndustryCode() : null);
|
|
|
+ importVo.setIndustryCategory(industryVo != null ? industryVo.getIndustryCategoryName() : vo.getIndustryCategory());
|
|
|
+
|
|
|
+ // 企业规模
|
|
|
+ EnterpriseScaleVo scaleVo = enterpriseScaleMap.get(vo.getEnterpriseScaleId());
|
|
|
+ importVo.setEnterpriseScaleNo(scaleVo != null ? scaleVo.getEnterpriseScaleCode() : null);
|
|
|
+ importVo.setEnterpriseScale(scaleVo != null ? scaleVo.getEnterpriseScaleName() : null);
|
|
|
+
|
|
|
+ // 系统人员(业务负责人)
|
|
|
+ RemoteComStaffVo xtSales = comStaffMap.get(vo.getSalesPersonId());
|
|
|
+ importVo.setXtSalesPersonNo(xtSales != null ? xtSales.getStaffCode() : null);
|
|
|
+ importVo.setXtSalesPersonName(xtSales != null ? xtSales.getStaffName() : vo.getSalesPersonName());
|
|
|
+
|
|
|
+ // 系统人员(客服支持)
|
|
|
+ RemoteComStaffVo xtService = comStaffMap.get(vo.getServiceStaffId());
|
|
|
+ importVo.setXtServiceStaffNo(xtService != null ? xtService.getStaffCode() : null);
|
|
|
+ importVo.setXtServiceStaffName(xtService != null ? xtService.getStaffName() : vo.getServiceStaffName());
|
|
|
+
|
|
|
+ // 销售信息
|
|
|
+ CustomerSalesInfoVo salesVo = vo.getCustomerSalesInfoVo();
|
|
|
+ if (salesVo != null) {
|
|
|
+ // 客户来源(从字典获取,格式:编码,名称,如"0001,主动来电")
|
|
|
+ String customerSourceLabel = customerSourceDictMap.get(salesVo.getCustomerSource());
|
|
|
+ if (StringUtils.isNotBlank(customerSourceLabel)) {
|
|
|
+ String[] parts = customerSourceLabel.split(",");
|
|
|
+ importVo.setSourceNo(parts.length > 0 ? parts[0].trim() : null);
|
|
|
+ importVo.setSourceName(parts.length > 1 ? parts[1].trim() : customerSourceLabel);
|
|
|
+ }
|
|
|
+ // 销售通路(从字典获取,格式:编码,名称)
|
|
|
+ String sellChannelLabel = sellChannelDictMap.get(salesVo.getSellChannel());
|
|
|
+ if (StringUtils.isNotBlank(sellChannelLabel)) {
|
|
|
+ String[] parts = sellChannelLabel.split(",");
|
|
|
+ importVo.setSellChannelNo(parts.length > 0 ? parts[0].trim() : null);
|
|
|
+ importVo.setSellChannel(parts.length > 1 ? parts[1].trim() : sellChannelLabel);
|
|
|
+ }
|
|
|
+ // 单价含税
|
|
|
+ importVo.setUnitPrice(salesVo.getUnitPrice());
|
|
|
+ // 账款额度超限
|
|
|
+ importVo.setCreditLimit(salesVo.getCreditLimit());
|
|
|
+ // 额度超期
|
|
|
+ importVo.setCreditTimeLimit(salesVo.getCreditTimeLimit());
|
|
|
+ // 账款归属
|
|
|
+ importVo.setAccountBelong(salesVo.getAccountBelong());
|
|
|
+
|
|
|
+ // ERP 业务人员(salesPersonNo 在导入时按 staffName 查询)
|
|
|
+ String erpSalesName = erpStaffNameMap.get(salesVo.getSalesPersonId());
|
|
|
+ importVo.setSalesPersonNo(erpSalesName != null ? erpSalesName : salesVo.getSalesPerson());
|
|
|
+ importVo.setSalesPersonName(erpSalesName != null ? erpSalesName : salesVo.getSalesPerson());
|
|
|
+
|
|
|
+ // ERP 业务助理(serviceStaffNo 在导入时按 staffName 查询)
|
|
|
+ String erpServiceName = erpStaffNameMap.get(salesVo.getServiceStaffId());
|
|
|
+ importVo.setServiceStaffNo(erpServiceName != null ? erpServiceName : salesVo.getServiceStaff());
|
|
|
+ importVo.setServiceStaffName(erpServiceName != null ? erpServiceName : salesVo.getServiceStaff());
|
|
|
+
|
|
|
+ // 信用等级:将名称映射回数字
|
|
|
+ String creditLevelName = creditLevelNameMap.get(salesVo.getCreditLevelId());
|
|
|
+ importVo.setCreditLevel(creditLevelName != null ? creditLevelReverseMap.getOrDefault(creditLevelName, creditLevelName) : null);
|
|
|
+
|
|
|
+ // 交易币别:导出 currencyCode
|
|
|
+ RemoteComCurrencyVo currencyVo = currencyMap.get(salesVo.getDealCurrencyId());
|
|
|
+ importVo.setDealCurrency(currencyVo != null ? currencyVo.getCurrencyCode() : null);
|
|
|
+
|
|
|
+ // 税码
|
|
|
+ RemoteProductTaxrateVo taxrateVo = taxrateMap.get(salesVo.getRateId());
|
|
|
+ importVo.setRateName(taxrateVo != null ? taxrateVo.getTaxrateNo() : null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 销售开票类型(直接从 CustomerInfoVo 获取)
|
|
|
+ importVo.setSellInvoiceTypeNo(vo.getSellInvoiceTypeNo());
|
|
|
+ importVo.setSellInvoiceType(vo.getSellInvoiceType());
|
|
|
+
|
|
|
+ exportList.add(importVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return exportList;
|
|
|
+ }
|
|
|
}
|