|
|
@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.common.core.constant.GlobalConstants;
|
|
|
import org.dromara.common.core.context.PlatformContext;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.enums.IsDefault;
|
|
|
import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
@@ -31,19 +32,23 @@ import org.dromara.customer.mapper.*;
|
|
|
import org.dromara.customer.service.ICustomerInfoService;
|
|
|
import org.dromara.customer.utils.qcc.QccUtils;
|
|
|
import org.dromara.customer.utils.qcc.domain.CompanyInfoResponse;
|
|
|
+import org.dromara.product.api.RemoteOrderInfoService;
|
|
|
+import org.dromara.product.api.RemoteProductService;
|
|
|
+import org.dromara.product.api.domain.dto.HotProductRankingDto;
|
|
|
+import org.dromara.product.api.domain.dto.LatestOrderDto;
|
|
|
+import org.dromara.product.api.domain.dto.OrderAmountTrendDto;
|
|
|
+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.RemoteComStaffVo;
|
|
|
-import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
|
|
-import org.dromara.system.api.domain.dto.AddressAreaDTO;
|
|
|
-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;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.Duration;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -85,12 +90,27 @@ 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;
|
|
|
|
|
|
@DubboReference
|
|
|
private RemoteAddressAreaService remoteAddressAreaService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteOrderInfoService remoteOrderInfoService;
|
|
|
+
|
|
|
+ @DubboReference
|
|
|
+ private RemoteProductService remoteProductService;
|
|
|
+
|
|
|
private static final String CUSTOMER_NO_KEY = "customer_info:customer_no";
|
|
|
private static final String CONTACT_NO_KEY = "customer_contact:contact_no";
|
|
|
|
|
|
@@ -447,8 +467,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
|
|
|
// === 远程调用获取名称 ===
|
|
|
- Map<Long, String> comStaffMap = staffIds.isEmpty() ? Collections.emptyMap() : remoteComStaffService.selectStaffNameByIds(comStaffIds);
|
|
|
- Map<Long, String> comDeptMap = deptIds.isEmpty() ? Collections.emptyMap() : remoteDeptService.selectDeptNameByIds(comDeptIds);
|
|
|
+ Map<Long, String> comStaffMap = comStaffIds.isEmpty() ? Collections.emptyMap() : remoteComStaffService.selectStaffNameByIds(comStaffIds);
|
|
|
+ Map<Long, String> comDeptMap = comDeptIds.isEmpty() ? Collections.emptyMap() : remoteDeptService.selectDeptNameByIds(comDeptIds);
|
|
|
records.forEach(v -> {
|
|
|
v.setSalesPersonName(comStaffMap.get(v.getSalesPersonId()));
|
|
|
v.setServiceStaffName(comStaffMap.get(v.getServiceStaffId()));
|
|
|
@@ -726,9 +746,10 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
LambdaQueryWrapper<CustomerInfo> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.orderByDesc(CustomerInfo::getId);
|
|
|
-
|
|
|
// 数据权限过滤:只能查看自己创建的、或者是业务负责人、或者是客服支持的客户
|
|
|
- if (bo.getCreateBy() != null || bo.getSalesPersonId() != null || bo.getServiceStaffId() != null) {
|
|
|
+ // 超级管理员或租户管理员可查看全部数据
|
|
|
+ if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()
|
|
|
+ && (bo.getCreateBy() != null || bo.getSalesPersonId() != null || bo.getServiceStaffId() != null)) {
|
|
|
lqw.and(wrapper -> {
|
|
|
boolean first = true;
|
|
|
if (bo.getCreateBy() != null) {
|
|
|
@@ -756,7 +777,6 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
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());
|
|
|
@@ -857,6 +877,33 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
|
|
|
String customerNo = entity.getCustomerNo();
|
|
|
|
|
|
+ // 团队成员初始化逻辑
|
|
|
+ Set<Long> staffIds = new HashSet<>();
|
|
|
+ if (entity.getSalesPersonId() != null) {
|
|
|
+ staffIds.add(entity.getSalesPersonId());
|
|
|
+ }
|
|
|
+ if (entity.getServiceStaffId() != null) {
|
|
|
+ staffIds.add(entity.getServiceStaffId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只有当有相关人员时才进行远程查询和入库
|
|
|
+ Map<Long, String> staffNameMap = Collections.emptyMap();
|
|
|
+ if (!staffIds.isEmpty()) {
|
|
|
+ staffNameMap = remoteComStaffService.selectStaffNameByIds(staffIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用提取的方法处理负责人
|
|
|
+ if (entity.getSalesPersonId() != null) {
|
|
|
+ saveOrUpdateTeamMember(customerNo, entity.getSalesPersonId(),
|
|
|
+ staffNameMap.get(entity.getSalesPersonId()), "1", 1, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用提取的方法处理客服
|
|
|
+ if (entity.getServiceStaffId() != null) {
|
|
|
+ saveOrUpdateTeamMember(customerNo, entity.getServiceStaffId(),
|
|
|
+ staffNameMap.get(entity.getServiceStaffId()), "3", 0, 1);
|
|
|
+ }
|
|
|
+
|
|
|
/*新增客户时给每个客户创建自己的组织架构*/
|
|
|
RemoteDeptVo remoteDeptVo = new RemoteDeptVo();
|
|
|
remoteDeptVo.setParentId(0L);
|
|
|
@@ -964,6 +1011,95 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 保存或更新团队成员信息
|
|
|
+ * 如果成员已存在但被删除,则恢复;否则新增
|
|
|
+ *
|
|
|
+ * @param objectNo 客户编号
|
|
|
+ * @param userNo 人员ID
|
|
|
+ * @param realName 人员姓名
|
|
|
+ * @param roleCode 角色编码 (1:负责人, 2:客服)
|
|
|
+ * @param izManager 是否主管
|
|
|
+ * @param updateAccredit 授权更新标识
|
|
|
+ */
|
|
|
+ /**
|
|
|
+ * 保存或更新团队成员信息(公用方法)
|
|
|
+ * 确保一个客户的团队中只能有一个 roleCode=1 的负责人和一个 roleCode=2 的客服支持
|
|
|
+ *
|
|
|
+ * @param objectNo 客户编号
|
|
|
+ * @param userNo 人员ID
|
|
|
+ * @param realName 人员姓名
|
|
|
+ * @param roleCode 角色编码 (1:负责人, 2:客服)
|
|
|
+ * @param izManager 是否主管
|
|
|
+ * @param updateAccredit 授权更新标识
|
|
|
+ */
|
|
|
+ public void saveOrUpdateTeamMember(String objectNo, Long userNo, String realName,
|
|
|
+ String roleCode, Integer izManager, Integer updateAccredit) {
|
|
|
+ if (userNo == null || StringUtils.isBlank(objectNo)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 查找该客户下指定角色的现有成员(包括已删除的)
|
|
|
+ TeamMemberVo existing = teamMemberMapper.selectByObjectNoAndRoleCodeWithDeleted(objectNo, roleCode);
|
|
|
+
|
|
|
+ if (existing != null && !existing.getUserNo().equals(userNo)) {
|
|
|
+ // 2. 如果存在不同的人员占据该角色,先将其软删除或更新状态
|
|
|
+ teamMemberMapper.update(null, new LambdaUpdateWrapper<TeamMember>()
|
|
|
+ .set(TeamMember::getIsDelete, 1)
|
|
|
+ .eq(TeamMember::getId, existing.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查找新人员是否已在该客户团队中(任意角色)
|
|
|
+ TeamMemberVo existingUser = teamMemberMapper.selectByObjectNoAndUserNoWithDeleted(objectNo, userNo);
|
|
|
+
|
|
|
+ if (existingUser != null) {
|
|
|
+ // 如果角色相同,恢复并更新
|
|
|
+ if (Objects.equals(existingUser.getRoleCode(), roleCode)) {
|
|
|
+ teamMemberMapper.restoreMemberById(
|
|
|
+ existingUser.getId(),
|
|
|
+ userNo,
|
|
|
+ realName,
|
|
|
+ roleCode,
|
|
|
+ updateAccredit,
|
|
|
+ izManager,
|
|
|
+ LoginHelper.getUserId(),
|
|
|
+ LoginHelper.getDeptId(),
|
|
|
+ PlatformContext.getPlatform()
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 角色不同(如同一个人既是负责人又是客服),新增一条记录
|
|
|
+ TeamMember member = new TeamMember();
|
|
|
+ member.setDataType(12);
|
|
|
+ member.setObjectNo(objectNo);
|
|
|
+ member.setUserNo(userNo);
|
|
|
+ member.setRealName(realName);
|
|
|
+ member.setRoleCode(roleCode);
|
|
|
+ member.setIzManager(izManager);
|
|
|
+ member.setUpdateAccredit(updateAccredit);
|
|
|
+ member.setPlatformCode(PlatformContext.getPlatform());
|
|
|
+ member.setCreateUserId(LoginHelper.getUserId());
|
|
|
+ member.setCreateOrgId(LoginHelper.getDeptId());
|
|
|
+ member.setIsDelete(0);
|
|
|
+ teamMemberMapper.insert(member);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 5. 如果人员不存在,执行新增
|
|
|
+ TeamMember member = new TeamMember();
|
|
|
+ member.setDataType(12); // 12 代表客户类型
|
|
|
+ member.setObjectNo(objectNo);
|
|
|
+ member.setUserNo(userNo);
|
|
|
+ member.setRealName(realName);
|
|
|
+ member.setRoleCode(roleCode);
|
|
|
+ member.setIzManager(izManager);
|
|
|
+ member.setUpdateAccredit(updateAccredit);
|
|
|
+ member.setPlatformCode(PlatformContext.getPlatform());
|
|
|
+ member.setCreateUserId(LoginHelper.getUserId());
|
|
|
+ member.setCreateOrgId(LoginHelper.getDeptId());
|
|
|
+ member.setIsDelete(0);
|
|
|
+ teamMemberMapper.insert(member);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改客户信息
|
|
|
*
|
|
|
@@ -1091,6 +1227,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
if (null == salesInfoVo.getCreditManagementId()) {
|
|
|
throw new ServiceException("ERP销售人员信用等级不能为空");
|
|
|
}
|
|
|
+ if (null == salesInfoVo.getOrderAudit()) {
|
|
|
+ throw new ServiceException("ERP销售人员订单审核方式不能为空");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return baseMapper.update(null,
|
|
|
@@ -1543,24 +1682,23 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- if (salesPersonId == null ) {
|
|
|
- log.warn("转移业务人员失败,业务人员 ID 为空");
|
|
|
- throw new ServiceException("业务人员不能为空");
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
+ // 获取新业务员的姓名
|
|
|
+ Map<Long, String> staffMap = remoteComStaffService.selectStaffNameByIds(Collections.singleton(salesPersonId));
|
|
|
+ String realName = staffMap.get(salesPersonId);
|
|
|
+
|
|
|
List<CustomerInfo> updateList = new ArrayList<>();
|
|
|
- CustomerInfo customerInfo = null;
|
|
|
for (Long customerId : customerIds) {
|
|
|
- if (customerId == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ if (customerId == null) continue;
|
|
|
|
|
|
- customerInfo = baseMapper.selectById(customerId);
|
|
|
+ CustomerInfo customerInfo = baseMapper.selectById(customerId);
|
|
|
if (customerInfo != null) {
|
|
|
customerInfo.setSalesPersonId(salesPersonId);
|
|
|
customerInfo.setBelongingDepartmentId(deptId);
|
|
|
updateList.add(customerInfo);
|
|
|
+
|
|
|
+ // 同步更新团队成员:角色 1 为负责人
|
|
|
+ saveOrUpdateTeamMember(customerInfo.getCustomerNo(), salesPersonId, realName, "1", 1, 1);
|
|
|
} else {
|
|
|
log.warn("客户 ID: {} 不存在,跳过更新", customerId);
|
|
|
}
|
|
|
@@ -1573,17 +1711,12 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
updateList.size(), salesPersonId, deptId);
|
|
|
return updateList.size();
|
|
|
} else {
|
|
|
- log.error("批量更新客户信息失败");
|
|
|
throw new ServiceException("批量更新客户信息失败");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- log.info("没有需要更新的客户销售信息");
|
|
|
return 0;
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
- log.error("转移业务人员失败,客户 IDs: {}, 业务员 ID: {}, 部门 ID: {}, 错误:{}",
|
|
|
- customerIds, salesPersonId, deptId, e.getMessage(), e);
|
|
|
+ log.error("转移业务人员失败,错误:{}", e.getMessage(), e);
|
|
|
throw new ServiceException("转移业务人员失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
@@ -1591,28 +1724,26 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int transferServiceStaff(List<Long> customerIds, Long serviceStaffId) {
|
|
|
- if (CollUtil.isEmpty(customerIds)) {
|
|
|
- log.warn("转移客服人员失败,客户 ID 列表为空");
|
|
|
+ if (CollUtil.isEmpty(customerIds) || serviceStaffId == null) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- if (serviceStaffId == null) {
|
|
|
- log.warn("转移客服人员失败,客服人员 ID 为空");
|
|
|
- throw new ServiceException("客服人员和不能为空");
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
+ // 获取新客服的姓名
|
|
|
+ Map<Long, String> staffMap = remoteComStaffService.selectStaffNameByIds(Collections.singleton(serviceStaffId));
|
|
|
+ String realName = staffMap.get(serviceStaffId);
|
|
|
+
|
|
|
List<CustomerInfo> updateList = new ArrayList<>();
|
|
|
- CustomerInfo customerInfo = null;
|
|
|
for (Long customerId : customerIds) {
|
|
|
- if (customerId == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ if (customerId == null) continue;
|
|
|
|
|
|
- customerInfo = baseMapper.selectById(customerId);
|
|
|
+ CustomerInfo customerInfo = baseMapper.selectById(customerId);
|
|
|
if (customerInfo != null) {
|
|
|
customerInfo.setServiceStaffId(serviceStaffId);
|
|
|
updateList.add(customerInfo);
|
|
|
+
|
|
|
+ // 同步更新团队成员:角色 3 为客服支持
|
|
|
+ saveOrUpdateTeamMember(customerInfo.getCustomerNo(), serviceStaffId, realName, "3", 0, 1);
|
|
|
} else {
|
|
|
log.warn("客户 ID: {} 不存在,跳过更新", customerId);
|
|
|
}
|
|
|
@@ -1625,25 +1756,14 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
updateList.size(), serviceStaffId);
|
|
|
return updateList.size();
|
|
|
} else {
|
|
|
- log.error("批量更新客户信息失败");
|
|
|
throw new ServiceException("批量更新客户信息失败");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- log.info("没有需要更新的客户销售信息");
|
|
|
return 0;
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
- log.error("转移客服人员失败,客户 IDs: {}, 客服人员 ID: {}, 错误:{}",
|
|
|
- customerIds, serviceStaffId, e.getMessage(), e);
|
|
|
+ log.error("转移客服人员失败,错误:{}", e.getMessage(), e);
|
|
|
throw new ServiceException("转移客服人员失败:" + e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
- // 直接进行批量更新
|
|
|
-// return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
|
|
|
-// .set(CustomerInfo::getServiceStaffId, serviceStaffId)
|
|
|
-// .in(CustomerInfo::getId, customerIds)
|
|
|
-// );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1660,6 +1780,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);
|
|
|
@@ -1669,6 +1790,26 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
customerBusinessInfo.setBusinessCustomerName(bo.getBusinessCustomerName());
|
|
|
customerBusinessInfo.setSocialCreditCode(bo.getSocialCreditCode());
|
|
|
customerBusinessInfoMapper.insert(customerBusinessInfo);
|
|
|
+ // 将业务员和客服加入团队成员
|
|
|
+ Set<Long> staffIds = new HashSet<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getSalesPersonId())) {
|
|
|
+ staffIds.add(bo.getSalesPersonId());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getServiceStaffId())) {
|
|
|
+ staffIds.add(bo.getServiceStaffId());
|
|
|
+ }
|
|
|
+ Map<Long, String> staffNameMap = Collections.emptyMap();
|
|
|
+ if (!staffIds.isEmpty()) {
|
|
|
+ staffNameMap = remoteComStaffService.selectStaffNameByIds(staffIds);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getSalesPersonId())) {
|
|
|
+ saveOrUpdateTeamMember(add.getCustomerNo(), bo.getSalesPersonId(),
|
|
|
+ staffNameMap.get(bo.getSalesPersonId()), "1", 1, 1);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getServiceStaffId())) {
|
|
|
+ saveOrUpdateTeamMember(add.getCustomerNo(), bo.getServiceStaffId(),
|
|
|
+ staffNameMap.get(bo.getServiceStaffId()), "3", 0, 1);
|
|
|
+ }
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
@@ -1701,6 +1842,26 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
customerBusinessInfo.setSocialCreditCode(bo.getSocialCreditCode());
|
|
|
customerBusinessInfoMapper.updateById(customerBusinessInfo);
|
|
|
}
|
|
|
+ // 将业务员和客服加入团队成员
|
|
|
+ Set<Long> staffIds = new HashSet<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getSalesPersonId())) {
|
|
|
+ staffIds.add(bo.getSalesPersonId());
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getServiceStaffId())) {
|
|
|
+ staffIds.add(bo.getServiceStaffId());
|
|
|
+ }
|
|
|
+ Map<Long, String> staffNameMap = Collections.emptyMap();
|
|
|
+ if (!staffIds.isEmpty()) {
|
|
|
+ staffNameMap = remoteComStaffService.selectStaffNameByIds(staffIds);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getSalesPersonId())) {
|
|
|
+ saveOrUpdateTeamMember(update.getCustomerNo(), bo.getSalesPersonId(),
|
|
|
+ staffNameMap.get(bo.getSalesPersonId()), "1", 1, 1);
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(bo.getServiceStaffId())) {
|
|
|
+ saveOrUpdateTeamMember(update.getCustomerNo(), bo.getServiceStaffId(),
|
|
|
+ staffNameMap.get(bo.getServiceStaffId()), "3", 0, 1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return flag;
|
|
|
@@ -1745,17 +1906,35 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
|
|
|
if (existing != null) {
|
|
|
- teamMemberMapper.restoreMemberById(
|
|
|
- existing.getId(),
|
|
|
- userNo,
|
|
|
- realName,
|
|
|
- roleCode,
|
|
|
- updateAccredit,
|
|
|
- izManager,
|
|
|
- LoginHelper.getUserId(),
|
|
|
- LoginHelper.getDeptId(),
|
|
|
- PlatformContext.getPlatform()
|
|
|
- );
|
|
|
+ // 如果角色相同,恢复并更新
|
|
|
+ if (Objects.equals(existing.getRoleCode(), roleCode)) {
|
|
|
+ teamMemberMapper.restoreMemberById(
|
|
|
+ existing.getId(),
|
|
|
+ userNo,
|
|
|
+ realName,
|
|
|
+ roleCode,
|
|
|
+ updateAccredit,
|
|
|
+ izManager,
|
|
|
+ LoginHelper.getUserId(),
|
|
|
+ LoginHelper.getDeptId(),
|
|
|
+ PlatformContext.getPlatform()
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ // 角色不同(如同一个人既是负责人又是客服),新增一条记录
|
|
|
+ TeamMember member = new TeamMember();
|
|
|
+ member.setDataType(12);
|
|
|
+ member.setObjectNo(objectNo);
|
|
|
+ member.setUserNo(userNo);
|
|
|
+ member.setRealName(realName);
|
|
|
+ member.setRoleCode(roleCode);
|
|
|
+ member.setIzManager(izManager);
|
|
|
+ member.setUpdateAccredit(updateAccredit);
|
|
|
+ member.setPlatformCode(PlatformContext.getPlatform());
|
|
|
+ member.setCreateUserId(LoginHelper.getUserId());
|
|
|
+ member.setCreateOrgId(LoginHelper.getDeptId());
|
|
|
+ member.setIsDelete(0);
|
|
|
+ teamMemberMapper.insert(member);
|
|
|
+ }
|
|
|
} else {
|
|
|
TeamMember member = new TeamMember();
|
|
|
member.setDataType(12);
|
|
|
@@ -1794,4 +1973,417 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
public CustomerInfoVo selectCustomerByName(String customerName) {
|
|
|
return baseMapper.selectVoOne(new LambdaQueryWrapper<CustomerInfo>().eq(CustomerInfo::getCustomerName, customerName));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<CustomerIndexDataVo> customerIndexData() {
|
|
|
+ CustomerIndexDataVo vo = new CustomerIndexDataVo();
|
|
|
+
|
|
|
+ // 1. 总客户数
|
|
|
+ vo.setTotalCustomers(baseMapper.selectCount(null));
|
|
|
+
|
|
|
+ // 2. 订单统计
|
|
|
+ OrderStatusCountDto orderStatusCount = remoteOrderInfoService.getOrderStatusCount(null);
|
|
|
+ vo.setTotalOrders(orderStatusCount.getOrderCount());
|
|
|
+
|
|
|
+ // 3. 商品总量
|
|
|
+ vo.setTotalProducts(remoteProductService.getTotalProductCount());
|
|
|
+
|
|
|
+ // 4. 本月营收(从订单金额趋势汇总)
|
|
|
+ List<OrderAmountTrendDto> orderAmountTrend = remoteOrderInfoService.getOrderAmountTrend(null);
|
|
|
+ BigDecimal monthlyRevenue = orderAmountTrend.stream()
|
|
|
+ .map(OrderAmountTrendDto::getAmount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ vo.setMonthlyRevenue(monthlyRevenue);
|
|
|
+
|
|
|
+ // 5. 最近七天客户趋势
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate sevenDaysAgo = today.minusDays(6);
|
|
|
+ List<CustomerInfo> recentCustomers = baseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<CustomerInfo>()
|
|
|
+ .ge(CustomerInfo::getCreateTime, java.sql.Date.valueOf(sevenDaysAgo))
|
|
|
+ .le(CustomerInfo::getCreateTime, java.sql.Date.valueOf(today))
|
|
|
+ );
|
|
|
+ Map<LocalDate, Long> dailyCustomerMap = new LinkedHashMap<>();
|
|
|
+ LocalDate cursor = sevenDaysAgo;
|
|
|
+ while (!cursor.isAfter(today)) {
|
|
|
+ dailyCustomerMap.put(cursor, 0L);
|
|
|
+ cursor = cursor.plusDays(1);
|
|
|
+ }
|
|
|
+ for (CustomerInfo c : recentCustomers) {
|
|
|
+ if (c.getCreateTime() != null) {
|
|
|
+ LocalDate createDate = c.getCreateTime().toInstant()
|
|
|
+ .atZone(ZoneId.systemDefault()).toLocalDate();
|
|
|
+ dailyCustomerMap.merge(createDate, 1L, Long::sum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> weekDayNames = Arrays.asList("周一", "周二", "周三", "周四", "周五", "周六", "周日");
|
|
|
+ List<CustomerIndexDataVo.TrendItem> customerTrend = new ArrayList<>();
|
|
|
+ int idx = 0;
|
|
|
+ for (Map.Entry<LocalDate, Long> entry : dailyCustomerMap.entrySet()) {
|
|
|
+ CustomerIndexDataVo.TrendItem item = new CustomerIndexDataVo.TrendItem();
|
|
|
+ // 使用星期几作为标签,与前端保持一致
|
|
|
+ item.setDate(weekDayNames.get(idx % 7));
|
|
|
+ item.setValue(BigDecimal.valueOf(entry.getValue()));
|
|
|
+ customerTrend.add(item);
|
|
|
+ idx++;
|
|
|
+ }
|
|
|
+ vo.setCustomerTrend(customerTrend);
|
|
|
+
|
|
|
+ // 6. 本月订单金额趋势(转换DTO->VO)
|
|
|
+ List<CustomerIndexDataVo.TrendItem> orderTrendItems = orderAmountTrend.stream().map(dto -> {
|
|
|
+ CustomerIndexDataVo.TrendItem item = new CustomerIndexDataVo.TrendItem();
|
|
|
+ item.setDate(dto.getDate());
|
|
|
+ item.setValue(dto.getAmount());
|
|
|
+ return item;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setOrderAmountTrend(orderTrendItems);
|
|
|
+
|
|
|
+ // 7. 客户类型分布
|
|
|
+ List<CustomerInfo> allCustomers = baseMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<CustomerInfo>()
|
|
|
+ .isNotNull(CustomerInfo::getCustomerTypeId)
|
|
|
+ .select(CustomerInfo::getCustomerTypeId)
|
|
|
+ );
|
|
|
+ Map<Long, Long> typeCountMap = allCustomers.stream()
|
|
|
+ .filter(c -> c.getCustomerTypeId() != null)
|
|
|
+ .collect(Collectors.groupingBy(CustomerInfo::getCustomerTypeId, Collectors.counting()));
|
|
|
+
|
|
|
+ // 查询字典获取类型名称
|
|
|
+ List<RemoteDictDataVo> enterpriseTypeDicts = remoteDictService.selectDictDataByType("Q0001");
|
|
|
+ Map<String, String> dictMap = CollUtil.emptyIfNull(enterpriseTypeDicts).stream()
|
|
|
+ .collect(Collectors.toMap(RemoteDictDataVo::getDictValue, RemoteDictDataVo::getDictLabel, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ List<CustomerIndexDataVo.TypeDistribution> typeDistributions = typeCountMap.entrySet().stream()
|
|
|
+ .map(entry -> {
|
|
|
+ CustomerIndexDataVo.TypeDistribution td = new CustomerIndexDataVo.TypeDistribution();
|
|
|
+ String typeName = dictMap.get(String.valueOf(entry.getKey()));
|
|
|
+ td.setName(typeName != null ? typeName : "其他");
|
|
|
+ td.setValue(entry.getValue());
|
|
|
+ return td;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setCustomerTypeDistribution(typeDistributions);
|
|
|
+
|
|
|
+ // 8. 最新订单明细
|
|
|
+ List<LatestOrderDto> latestOrders = remoteOrderInfoService.getLatestOrders(null, 10);
|
|
|
+ List<CustomerIndexDataVo.LatestOrder> orderList = latestOrders.stream().map(dto -> {
|
|
|
+ CustomerIndexDataVo.LatestOrder order = new CustomerIndexDataVo.LatestOrder();
|
|
|
+ order.setOrderNo(dto.getOrderNo());
|
|
|
+ order.setCustomer(dto.getCustomerName());
|
|
|
+ order.setProduct(dto.getProductName());
|
|
|
+ order.setAmount(dto.getAmount());
|
|
|
+ order.setStatus(dto.getOrderStatus());
|
|
|
+ order.setDate(dto.getOrderTime());
|
|
|
+ return order;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setLatestOrders(orderList);
|
|
|
+
|
|
|
+ // 9. 热销商品排行榜
|
|
|
+ List<HotProductRankingDto> hotProductRankings = remoteOrderInfoService.getHotProductRankings(null, 6);
|
|
|
+ // 计算最大销量用于百分比
|
|
|
+ long maxSales = hotProductRankings.stream()
|
|
|
+ .mapToLong(HotProductRankingDto::getSalesCount)
|
|
|
+ .max().orElse(1L);
|
|
|
+ List<CustomerIndexDataVo.HotProduct> hotProducts = hotProductRankings.stream().map(dto -> {
|
|
|
+ CustomerIndexDataVo.HotProduct hp = new CustomerIndexDataVo.HotProduct();
|
|
|
+ hp.setName(dto.getProductName());
|
|
|
+ hp.setSales(dto.getSalesCount());
|
|
|
+ // 百分比 = 当前销量 / 最大销量 * 100
|
|
|
+ int percentage = maxSales > 0
|
|
|
+ ? (int) Math.round(dto.getSalesCount() * 100.0 / maxSales)
|
|
|
+ : 0;
|
|
|
+ hp.setPercentage(percentage);
|
|
|
+ return hp;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ vo.setHotProductRankings(hotProducts);
|
|
|
+
|
|
|
+ return R.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否需要确认订单
|
|
|
+ @Override
|
|
|
+ public Boolean isNeedAffirmOrder(Long customerId) {
|
|
|
+ boolean affirmFlag = false;
|
|
|
+ CustomerInfoVo customerInfoVo = baseMapper.selectVoById(customerId);
|
|
|
+ if (ObjectUtils.isNotEmpty(customerInfoVo)) {
|
|
|
+ CustomerSalesInfoVo salesInfoVo = customerSalesInfoMapper.selectVoOne(new LambdaQueryWrapper<CustomerSalesInfo>().eq(CustomerSalesInfo::getCustomerId, customerInfoVo.getId()).last("LIMIT 1"));
|
|
|
+ if (ObjectUtils.isNotEmpty(salesInfoVo) && ObjectUtils.isNotEmpty(salesInfoVo.getOrderAudit())) {
|
|
|
+ if ("1".equals(salesInfoVo.getOrderAudit())) {//下单后需要客服确认
|
|
|
+ affirmFlag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|