|
|
@@ -329,22 +329,12 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
vo.setCreateByName(name);
|
|
|
}
|
|
|
if (vo.getUpdateBy() != null) {
|
|
|
- String name = userMap.get(Long.parseLong(vo.getUpdateBy()));
|
|
|
- if (name == null && "-1".equals(vo.getUpdateBy())) name = "系统";
|
|
|
- vo.setUpdateByName(name);
|
|
|
+ vo.setUpdateByName(userMap.get(Long.parseLong(vo.getUpdateBy())));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 分页查询客户信息列表
|
|
|
- *
|
|
|
- * @param bo 查询条件
|
|
|
- * @param pageQuery 分页参数
|
|
|
- * @return 客户信息分页列表
|
|
|
- */
|
|
|
@Override
|
|
|
public TableDataInfo<CustomerInfoVo> queryPageList(CustomerInfoBo bo, PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<CustomerInfo> lqw = buildQueryWrapper(bo);
|
|
|
@@ -369,7 +359,11 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
IndustryCategoryVo::getIndustryCategoryName,
|
|
|
(e, r) -> e
|
|
|
));
|
|
|
- records.forEach(vo -> vo.setIndustryCategory(industryMap.get(vo.getIndustryCategoryId())));
|
|
|
+ records.forEach(vo -> {
|
|
|
+ String name = industryMap.get(vo.getIndustryCategoryId());
|
|
|
+ vo.setIndustryCategory(name);
|
|
|
+ vo.setIndustryName(name);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// === 2. 提取客户ID,查询销售信息 ===
|
|
|
@@ -383,22 +377,12 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toCollection(() -> new HashSet<>(records.size())));
|
|
|
|
|
|
- if (infoIds.isEmpty()) {
|
|
|
- return TableDataInfo.build(result);
|
|
|
- }
|
|
|
-
|
|
|
- if (companyIds.isEmpty()) {
|
|
|
- return TableDataInfo.build(result);
|
|
|
- }
|
|
|
-
|
|
|
- List<CustomerSalesInfoVo> salesInfoVos = customerSalesInfoMapper.selectVoList(
|
|
|
- new LambdaQueryWrapper<CustomerSalesInfo>()
|
|
|
- .in(CustomerSalesInfo::getCustomerId, infoIds)
|
|
|
- );
|
|
|
-
|
|
|
- if (CollUtil.isEmpty(salesInfoVos)) {
|
|
|
- // 即使没有销售信息,也要返回客户列表(只是销售字段为空)
|
|
|
- return TableDataInfo.build(result);
|
|
|
+ List<CustomerSalesInfoVo> salesInfoVos = Collections.emptyList();
|
|
|
+ if (!infoIds.isEmpty()) {
|
|
|
+ salesInfoVos = customerSalesInfoMapper.selectVoList(
|
|
|
+ new LambdaQueryWrapper<CustomerSalesInfo>()
|
|
|
+ .in(CustomerSalesInfo::getCustomerId, infoIds)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
// === 3. 构建 customerId -> CustomerSalesInfoVo 映射
|
|
|
@@ -406,7 +390,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
.collect(Collectors.toMap(
|
|
|
CustomerSalesInfoVo::getCustomerId,
|
|
|
Function.identity(),
|
|
|
- (existing, replacement) -> existing // 若有重复,保留第一个
|
|
|
+ (existing, replacement) -> existing
|
|
|
));
|
|
|
|
|
|
// === 4. 收集人员和部门ID ===
|
|
|
@@ -431,36 +415,82 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
? Collections.emptyMap()
|
|
|
: remoteErpDeptService.selectDeptNameByIds(deptIds);
|
|
|
|
|
|
- // === 6. 回填人员和部门名称到 salesInfoVo ===
|
|
|
for (CustomerSalesInfoVo vo : salesInfoVos) {
|
|
|
vo.setSalesPerson(staffMap.get(vo.getSalesPersonId()));
|
|
|
vo.setServiceStaff(staffMap.get(vo.getServiceStaffId()));
|
|
|
vo.setBelongingDepartment(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
}
|
|
|
- //系统人员与部门
|
|
|
+
|
|
|
+ // 系统人员与部门,以及客户等级
|
|
|
Set<Long> comStaffIds = new HashSet<>();
|
|
|
Set<Long> comDeptIds = new HashSet<>();
|
|
|
+ Set<Long> customerLevelIds = new HashSet<>();
|
|
|
|
|
|
for (CustomerInfoVo vo : records) {
|
|
|
if (vo.getSalesPersonId() != null) comStaffIds.add(vo.getSalesPersonId());
|
|
|
if (vo.getServiceStaffId() != null) comStaffIds.add(vo.getServiceStaffId());
|
|
|
if (vo.getBelongingDepartmentId() != null) comDeptIds.add(vo.getBelongingDepartmentId());
|
|
|
+ if (vo.getCustomerLevelId() != null) customerLevelIds.add(vo.getCustomerLevelId());
|
|
|
}
|
|
|
|
|
|
// === 远程调用获取名称 ===
|
|
|
- Map<Long, String> comStaffMap = staffIds.isEmpty()
|
|
|
- ? Collections.emptyMap()
|
|
|
- : remoteComStaffService.selectStaffNameByIds(comStaffIds);
|
|
|
+ List<RemoteComStaffVo> comStaffList = comStaffIds.isEmpty()
|
|
|
+ ? Collections.emptyList()
|
|
|
+ : remoteComStaffService.selectStaffByIds(comStaffIds);
|
|
|
+ Map<Long, RemoteComStaffVo> comStaffMap = comStaffList.stream()
|
|
|
+ .collect(Collectors.toMap(RemoteComStaffVo::getStaffId, Function.identity(), (v1, v2) -> v1));
|
|
|
|
|
|
- Map<Long, String> comDeptMap = deptIds.isEmpty()
|
|
|
+ Map<Long, String> comDeptMap = comDeptIds.isEmpty()
|
|
|
? Collections.emptyMap()
|
|
|
: remoteDeptService.selectDeptNameByIds(comDeptIds);
|
|
|
|
|
|
- // === 回填系统人员和部门名称到 customerInfoVo ===
|
|
|
+ Map<Long, String> customerLevelMap = customerLevelIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteComCustomerLevelService.selectCustomerLevelNameByIds(customerLevelIds);
|
|
|
+
|
|
|
+ // 字典翻译
|
|
|
+ List<RemoteDictDataVo> enterpriseTypeDicts = remoteDictService.selectDictDataByType("enterprise_type");
|
|
|
+ Map<String, String> enterpriseTypeMap = enterpriseTypeDicts == null ? Collections.emptyMap() : enterpriseTypeDicts.stream()
|
|
|
+ .collect(Collectors.toMap(RemoteDictDataVo::getDictValue, RemoteDictDataVo::getDictLabel, (k1, k2) -> k1));
|
|
|
+ List<RemoteDictDataVo> q0001Dicts = remoteDictService.selectDictDataByType("Q0001");
|
|
|
+ Map<String, String> q0001Map = q0001Dicts == null ? Collections.emptyMap() : q0001Dicts.stream()
|
|
|
+ .collect(Collectors.toMap(RemoteDictDataVo::getDictValue, RemoteDictDataVo::getDictLabel, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ List<RemoteDictDataVo> cooperationDicts = remoteDictService.selectDictDataByType("cooperation_status");
|
|
|
+ Map<String, String> cooperationMap = cooperationDicts == null ? Collections.emptyMap() : cooperationDicts.stream()
|
|
|
+ .collect(Collectors.toMap(RemoteDictDataVo::getDictValue, RemoteDictDataVo::getDictLabel, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ // === 回填系统人员、部门名称、企业类型、等级、合作状态到 customerInfoVo ===
|
|
|
records.forEach(v -> {
|
|
|
- v.setSalesPersonName(comStaffMap.get(v.getSalesPersonId()));
|
|
|
- v.setServiceStaffName(comStaffMap.get(v.getServiceStaffId()));
|
|
|
- v.setBelongingDepartmentName(comDeptMap.get(v.getBelongingDepartmentId()));
|
|
|
+ RemoteComStaffVo salesPerson = comStaffMap.get(v.getSalesPersonId());
|
|
|
+ RemoteComStaffVo serviceStaff = comStaffMap.get(v.getServiceStaffId());
|
|
|
+
|
|
|
+ if (salesPerson != null) {
|
|
|
+ v.setSalesPersonName(salesPerson.getStaffName());
|
|
|
+ v.setDeptName(salesPerson.getDeptName());
|
|
|
+ }
|
|
|
+ if (serviceStaff != null) {
|
|
|
+ v.setServiceStaffName(serviceStaff.getStaffName());
|
|
|
+ }
|
|
|
+
|
|
|
+ String dName = comDeptMap.get(v.getBelongingDepartmentId());
|
|
|
+ v.setBelongingDepartmentName(dName);
|
|
|
+ if (v.getDeptName() == null) {
|
|
|
+ v.setDeptName(dName);
|
|
|
+ }
|
|
|
+
|
|
|
+ v.setCustomerLevelName(customerLevelMap.get(v.getCustomerLevelId()));
|
|
|
+
|
|
|
+ String typeValue = v.getCustomerTypeId() != null ? String.valueOf(v.getCustomerTypeId()) : null;
|
|
|
+ if (typeValue != null) {
|
|
|
+ String typeName = enterpriseTypeMap.get(typeValue);
|
|
|
+ if (typeName == null) {
|
|
|
+ typeName = q0001Map.get(typeValue);
|
|
|
+ }
|
|
|
+ v.setEnterpriseTypeName(typeName);
|
|
|
+ }
|
|
|
+
|
|
|
+ v.setCooperationName(cooperationMap.get(v.getStatus()));
|
|
|
});
|
|
|
|
|
|
// === 7. 将销售信息回填到客户VO ===
|
|
|
@@ -1730,37 +1760,57 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
customer.setStatus("0"); // 认领成功后,将客户主表状态改为有效
|
|
|
boolean updated = baseMapper.updateById(customer) > 0;
|
|
|
|
|
|
- if (updated && claimBo.getSalesPersonId() != null) {
|
|
|
+ if (updated) {
|
|
|
// 2. 将业务员加入团队成员
|
|
|
- // 检查是否已在团队中
|
|
|
- Long count = teamMemberMapper.selectCount(new LambdaQueryWrapper<TeamMember>()
|
|
|
- .eq(TeamMember::getDataType, 12)
|
|
|
- .eq(TeamMember::getObjectNo, customer.getCustomerNo())
|
|
|
- .eq(TeamMember::getUserNo, claimBo.getSalesPersonId()));
|
|
|
-
|
|
|
- if (count == 0) {
|
|
|
- TeamMember member = new TeamMember();
|
|
|
- member.setDataType(12); // 客户类型
|
|
|
- member.setObjectNo(customer.getCustomerNo());
|
|
|
- member.setUserNo(claimBo.getSalesPersonId());
|
|
|
- member.setRoleCode("B0001"); // 业务负责人
|
|
|
- member.setIzManager(1);
|
|
|
- member.setUpdateAccredit(1);
|
|
|
- member.setPlatformCode(PlatformContext.getPlatform());
|
|
|
-
|
|
|
- // 获取真实姓名:直接从业务人员表获取
|
|
|
- CrmStaff staff = crmStaffMapper.selectById(claimBo.getSalesPersonId());
|
|
|
- if (staff != null) {
|
|
|
- member.setRealName(staff.getStaffName());
|
|
|
- }
|
|
|
-
|
|
|
- teamMemberMapper.insert(member);
|
|
|
+ if (claimBo.getSalesPersonId() != null) {
|
|
|
+ saveOrUpdateTeamMember(customer.getCustomerNo(), claimBo.getSalesPersonId(), "B0001", 1, 1);
|
|
|
+ }
|
|
|
+ // 3. 将客服支持加入团队成员
|
|
|
+ if (claimBo.getServiceStaffId() != null) {
|
|
|
+ saveOrUpdateTeamMember(customer.getCustomerNo(), claimBo.getServiceStaffId(), "3", 0, 0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return updated;
|
|
|
}
|
|
|
|
|
|
+ private void saveOrUpdateTeamMember(String objectNo, Long userNo, String roleCode, Integer izManager, Integer updateAccredit) {
|
|
|
+ TeamMemberVo existing = teamMemberMapper.selectByObjectNoAndUserNoWithDeleted(objectNo, userNo);
|
|
|
+ String realName = "";
|
|
|
+ CrmStaff staff = crmStaffMapper.selectById(userNo);
|
|
|
+ if (staff != null) {
|
|
|
+ realName = staff.getStaffName();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (existing != null) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int releaseToPool(List<Long> customerIds, String reason) {
|