|
|
@@ -34,7 +34,9 @@ import org.dromara.customer.utils.qcc.domain.CompanyInfoResponse;
|
|
|
import org.dromara.system.api.*;
|
|
|
import org.dromara.system.api.domain.bo.RemoteUserBo;
|
|
|
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.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -57,10 +59,6 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@DubboReference
|
|
|
private RemoteDeptService remoteDeptService;
|
|
|
|
|
|
- @DubboReference
|
|
|
- private RemoteErpDeptService remoteErpDeptService;
|
|
|
- @DubboReference
|
|
|
- private RemoteErpStaffService remoteErpStaffService;
|
|
|
@DubboReference
|
|
|
private RemoteUserService remoteUserService;
|
|
|
@DubboReference
|
|
|
@@ -82,6 +80,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@DubboReference
|
|
|
private RemoteDictService remoteDictService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteAddressAreaService remoteAddressAreaService;
|
|
|
+
|
|
|
private static final String CUSTOMER_NO_KEY = "customer_info:customer_no";
|
|
|
private static final String CONTACT_NO_KEY = "customer_contact:contact_no";
|
|
|
|
|
|
@@ -97,6 +98,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
private final CustomerDeptMapper customerDeptMapper;
|
|
|
private final CustomerDictMapper customerDictMapper;
|
|
|
private final SupplierBusinessInfoMapper supplierBusinessInfoMapper;
|
|
|
+ private final TeamMemberMapper teamMemberMapper;
|
|
|
+ private final CrmStaffMapper crmStaffMapper;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -163,6 +166,21 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
vo.setCooperationName(cooperationMap.get(vo.getStatus()));
|
|
|
}
|
|
|
|
|
|
+ // 补充省份和城市名称
|
|
|
+ Set<Long> areaIds = new HashSet<>();
|
|
|
+ if (StringUtils.isNotBlank(vo.getRegProvincialNo()) && StringUtils.isNumeric(vo.getRegProvincialNo())) {
|
|
|
+ areaIds.add(Long.parseLong(vo.getRegProvincialNo()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(vo.getRegCityNo()) && StringUtils.isNumeric(vo.getRegCityNo())) {
|
|
|
+ areaIds.add(Long.parseLong(vo.getRegCityNo()));
|
|
|
+ }
|
|
|
+ if (!areaIds.isEmpty()) {
|
|
|
+ List<AddressAreaDTO> areaList = remoteAddressAreaService.listByIds(areaIds);
|
|
|
+ Map<String, String> areaMap = areaList.stream().collect(Collectors.toMap(d -> String.valueOf(d.getId()), AddressAreaDTO::getAreaName));
|
|
|
+ vo.setRegProvincialName(areaMap.get(vo.getRegProvincialNo()));
|
|
|
+ vo.setRegCityName(areaMap.get(vo.getRegCityNo()));
|
|
|
+ }
|
|
|
+
|
|
|
// 2. 查询关联信息 - 工商信息 (增加供应商表作为备选)
|
|
|
CustomerBusinessInfo businessInfo = customerBusinessInfoMapper.selectByCustomerId(id);
|
|
|
if (businessInfo == null) {
|
|
|
@@ -173,6 +191,14 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
businessInfo.setCustomerId(id);
|
|
|
// 字段名映射差异处理
|
|
|
businessInfo.setBusinessCustomerName(supplierBiz.getBusinessName());
|
|
|
+ businessInfo.setSocialCreditCode(supplierBiz.getSocialCreditCode());
|
|
|
+ businessInfo.setLegalPersonName(supplierBiz.getLegalPersonName());
|
|
|
+ businessInfo.setRegisteredCapital(supplierBiz.getRegisteredCapital());
|
|
|
+ businessInfo.setEstablishmentDate(supplierBiz.getEstablishmentDate());
|
|
|
+ businessInfo.setRevocationDate(supplierBiz.getRevocationDate());
|
|
|
+ businessInfo.setRegistrationStatus(supplierBiz.getRegistrationStatus());
|
|
|
+ businessInfo.setBusinessAddress(supplierBiz.getBusinessAddress());
|
|
|
+ businessInfo.setBusinessLicense(supplierBiz.getBusinessLicense());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -208,32 +234,43 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
|
|
|
// 补充人员和部门名称
|
|
|
Set<Long> staffIds = new HashSet<>();
|
|
|
- Set<Long> deptIds = new HashSet<>();
|
|
|
if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
- if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
|
|
|
|
|
|
- Map<Long, String> staffMap = staffIds.isEmpty() ? Collections.emptyMap() : remoteErpStaffService.selectStaffNameByIds(staffIds);
|
|
|
- Map<Long, String> deptMap = deptIds.isEmpty() ? Collections.emptyMap() : remoteErpDeptService.selectDeptNameByIds(deptIds);
|
|
|
-
|
|
|
- vo.setSalesPersonName(staffMap.get(vo.getSalesPersonId()));
|
|
|
- vo.setServiceStaffName(staffMap.get(vo.getServiceStaffId()));
|
|
|
- vo.setBelongingDepartmentName(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
-
|
|
|
- if (voObj != null) {
|
|
|
- voObj.setSalesPerson(staffMap.get(vo.getSalesPersonId()));
|
|
|
- voObj.setServiceStaff(staffMap.get(vo.getServiceStaffId()));
|
|
|
- voObj.setBelongingDepartment(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
- // 信用等级名称
|
|
|
- if (voObj.getCreditLevelId() != null) {
|
|
|
- Map<Long, String> creditMap = remoteCreditLevelService.selectCreditLevelNameByIds(Collections.singleton(voObj.getCreditLevelId()));
|
|
|
- voObj.setCreditLevel(creditMap.get(voObj.getCreditLevelId()));
|
|
|
+ // 补充人员信息(包含部门)
|
|
|
+ Map<Long, RemoteComStaffVo> staffFullMap = staffIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ remoteComStaffService.selectStaffByIds(staffIds).stream().collect(Collectors.toMap(RemoteComStaffVo::getStaffId, Function.identity(), (k1, k2) -> k1));
|
|
|
+
|
|
|
+ // 归属部门逻辑:优先从销售信息的 belongingDepartmentId 获取,其次从业务负责人所在部门获取
|
|
|
+ String deptName = null;
|
|
|
+ if (customerSalesInfo.getBelongingDepartmentId() != null) {
|
|
|
+ RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(customerSalesInfo.getBelongingDepartmentId());
|
|
|
+ if (remoteDeptVo != null) {
|
|
|
+ deptName = remoteDeptVo.getDeptName();
|
|
|
}
|
|
|
}
|
|
|
+ if (StringUtils.isBlank(deptName) && vo.getSalesPersonId() != null && staffFullMap.containsKey(vo.getSalesPersonId())) {
|
|
|
+ deptName = staffFullMap.get(vo.getSalesPersonId()).getDeptName();
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setBelongingDepartmentName(deptName);
|
|
|
+ vo.setDeptName(deptName);
|
|
|
+ if (voObj != null) {
|
|
|
+ voObj.setBelongingDepartment(deptName);
|
|
|
+ voObj.setSalesPerson(staffFullMap.get(vo.getSalesPersonId()) != null ? staffFullMap.get(vo.getSalesPersonId()).getStaffName() : null);
|
|
|
+ voObj.setServiceStaff(staffFullMap.get(vo.getServiceStaffId()) != null ? staffFullMap.get(vo.getServiceStaffId()).getStaffName() : null);
|
|
|
+ }
|
|
|
+ vo.setSalesPersonName(staffFullMap.get(vo.getSalesPersonId()) != null ? staffFullMap.get(vo.getSalesPersonId()).getStaffName() : null);
|
|
|
+ vo.setServiceStaffName(staffFullMap.get(vo.getServiceStaffId()) != null ? staffFullMap.get(vo.getServiceStaffId()).getStaffName() : null);
|
|
|
+ // 信用等级名称
|
|
|
+ if (voObj != null && voObj.getCreditLevelId() != null) {
|
|
|
+ Map<Long, String> creditMap = remoteCreditLevelService.selectCreditLevelNameByIds(Collections.singleton(voObj.getCreditLevelId()));
|
|
|
+ voObj.setCreditLevel(creditMap.get(voObj.getCreditLevelId()));
|
|
|
+ }
|
|
|
vo.setCustomerSalesInfoVo(voObj);
|
|
|
}
|
|
|
|
|
|
- // 补充开票类型 (来自主表 sell_invoice_type,独立于销售信息表)
|
|
|
+ // 补充开票类型 (来自主表 sell_invoice_type)
|
|
|
vo.setInvoiceType(vo.getSellInvoiceType());
|
|
|
vo.setInvoiceTypeName(vo.getSellInvoiceType());
|
|
|
|
|
|
@@ -260,6 +297,28 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ // 4. 补全管理信息人名
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+ if (StringUtils.isNotBlank(vo.getCreateBy()) && StringUtils.isNumeric(vo.getCreateBy())) {
|
|
|
+ userIds.add(Long.parseLong(vo.getCreateBy()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(vo.getUpdateBy()) && StringUtils.isNumeric(vo.getUpdateBy())) {
|
|
|
+ userIds.add(Long.parseLong(vo.getUpdateBy()));
|
|
|
+ }
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ Map<Long, String> userMap = remoteUserService.selectUserNamesByIds(new ArrayList<>(userIds));
|
|
|
+ if (vo.getCreateBy() != null) {
|
|
|
+ String name = userMap.get(Long.parseLong(vo.getCreateBy()));
|
|
|
+ if (name == null && "-1".equals(vo.getCreateBy())) name = "系统";
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
@@ -334,32 +393,35 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
));
|
|
|
|
|
|
Set<Long> staffIds = new HashSet<>();
|
|
|
- Set<Long> deptIds = new HashSet<>();
|
|
|
|
|
|
// === 3. 提取人员和部门ID用于查询名称 ===
|
|
|
for (CustomerInfoVo vo : records) {
|
|
|
if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
- if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
|
|
|
+
|
|
|
+ CustomerSalesInfoVo salesVo = salesInfoMap.get(vo.getId());
|
|
|
}
|
|
|
|
|
|
// === 5. 远程调用获取名称 ===
|
|
|
Map<Long, String> companyMap = companyIds.isEmpty()
|
|
|
? Collections.emptyMap()
|
|
|
: remoteComCompanyService.selectCompanyNameByIds(companyIds);
|
|
|
- Map<Long, String> staffMap = staffIds.isEmpty()
|
|
|
- ? Collections.emptyMap()
|
|
|
- : remoteErpStaffService.selectStaffNameByIds(staffIds);
|
|
|
-
|
|
|
- Map<Long, String> deptMap = deptIds.isEmpty()
|
|
|
- ? Collections.emptyMap()
|
|
|
- : remoteErpDeptService.selectDeptNameByIds(deptIds);
|
|
|
+
|
|
|
+ Map<Long, RemoteComStaffVo> staffFullMap = staffIds.isEmpty() ? Collections.emptyMap() :
|
|
|
+ remoteComStaffService.selectStaffByIds(staffIds).stream().collect(Collectors.toMap(RemoteComStaffVo::getStaffId, Function.identity(), (k1, k2) -> k1));
|
|
|
|
|
|
// === 6. 回填人员和部门名称到 vo ===
|
|
|
for (CustomerInfoVo vo : records) {
|
|
|
- vo.setSalesPersonName(staffMap.get(vo.getSalesPersonId()));
|
|
|
- vo.setServiceStaffName(staffMap.get(vo.getServiceStaffId()));
|
|
|
- vo.setBelongingDepartmentName(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
+ RemoteComStaffVo salesPerson = staffFullMap.get(vo.getSalesPersonId());
|
|
|
+ RemoteComStaffVo serviceStaff = staffFullMap.get(vo.getServiceStaffId());
|
|
|
+
|
|
|
+ vo.setSalesPersonName(salesPerson != null ? salesPerson.getStaffName() : null);
|
|
|
+ vo.setServiceStaffName(serviceStaff != null ? serviceStaff.getStaffName() : null);
|
|
|
+
|
|
|
+ // 部门统一使用业务负责人所在的部门
|
|
|
+ String deptName = salesPerson != null ? salesPerson.getDeptName() : null;
|
|
|
+ vo.setBelongingDepartmentName(deptName);
|
|
|
+ vo.setDeptName(deptName);
|
|
|
}
|
|
|
|
|
|
// === 7. 将销售信息回填到客户VO ===
|
|
|
@@ -367,6 +429,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
customerVo.setCompanyName(companyMap.get(customerVo.getBelongCompanyId()));
|
|
|
CustomerSalesInfoVo salesVo = salesInfoMap.get(customerVo.getId());
|
|
|
customerVo.setCustomerSalesInfoVo(salesVo);
|
|
|
+ if (salesVo != null) {
|
|
|
+ salesVo.setBelongingDepartment(customerVo.getDeptName());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return TableDataInfo.build(result);
|
|
|
@@ -554,16 +619,20 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
if (!"true".equals(bo.getIsHighSeas())) {
|
|
|
if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
- if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
|
|
|
if (vo.getCreditLevelId() != null) creditLevelIds.add(vo.getCreditLevelId());
|
|
|
}
|
|
|
if (vo.getBelongCompanyId() != null) companyIds.add(vo.getBelongCompanyId());
|
|
|
if (vo.getEnterpriseTypeId() != null) enterpriseTypeIds.add(vo.getEnterpriseTypeId());
|
|
|
if (vo.getCustomerLevelId() != null) customerLevelIds.add(vo.getCustomerLevelId());
|
|
|
+
|
|
|
+ // 处理部门ID收集
|
|
|
+ if (vo.getBelongingDepartmentId() != null) {
|
|
|
+ deptIds.add(vo.getBelongingDepartmentId());
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
// 1. 批量查询业务员和客服名称 (远程调用)
|
|
|
- Map<Long, String> staffMap = staffIds.isEmpty() ? Collections.emptyMap() : remoteErpStaffService.selectStaffNameByIds(staffIds);
|
|
|
+ Map<Long, String> staffMap = staffIds.isEmpty() ? Collections.emptyMap() : remoteComStaffService.selectStaffNameByIds(staffIds);
|
|
|
|
|
|
// 2. 批量查询信用等级名称 (远程调用)
|
|
|
Map<Long, String> creditLevelMap = creditLevelIds.isEmpty() ? Collections.emptyMap() : remoteCreditLevelService.selectCreditLevelNameByIds(creditLevelIds);
|
|
|
@@ -579,8 +648,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
// 5. 批量查询客户/合作等级名称 (远程调用)
|
|
|
Map<Long, String> customerLevelMap = customerLevelIds.isEmpty() ? Collections.emptyMap() : remoteComCustomerLevelService.selectCustomerLevelNameByIds(customerLevelIds);
|
|
|
|
|
|
- // 6. 批量查询部门名称 (远程调用)
|
|
|
- Map<Long, String> deptMap = deptIds.isEmpty() ? Collections.emptyMap() : remoteErpDeptService.selectDeptNameByIds(deptIds);
|
|
|
+ // 6. 批量查询部门名称 (系统部门)
|
|
|
+ Map<Long, String> deptMap = deptIds.isEmpty() ? Collections.emptyMap() : remoteDeptService.selectDeptNameByIds(deptIds);
|
|
|
|
|
|
// 7. 批量查询合作状态名称 (从客户字典表查询 code='COOPERATION_STATUS')
|
|
|
List<CustomerDict> cooperationDicts = customerDictMapper.selectList(new LambdaQueryWrapper<CustomerDict>()
|
|
|
@@ -607,10 +676,9 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
vo.setCompanyName(companyMap.get(vo.getBelongCompanyId()));
|
|
|
vo.setEnterpriseTypeName(enterpriseTypeMap.get(vo.getEnterpriseTypeId()));
|
|
|
vo.setCustomerLevelName(customerLevelMap.get(vo.getCustomerLevelId()));
|
|
|
- if (StringUtils.isBlank(vo.getDeptName())) {
|
|
|
- vo.setDeptName(deptMap.get(vo.getBelongingDepartmentId()));
|
|
|
- }
|
|
|
vo.setCooperationName(cooperationMap.get(vo.getStatus()));
|
|
|
+
|
|
|
+ // 部门名称已在 Mapper 中通过业务负责人关联查询,此处无需再回填覆盖
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -668,7 +736,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
// 公海客户:负责人和客服均为空(或为0)
|
|
|
lqw.and(w -> w.and(a -> a.isNull(CustomerInfo::getSalesPersonId).or().eq(CustomerInfo::getSalesPersonId, 0))
|
|
|
.and(b -> b.isNull(CustomerInfo::getServiceStaffId).or().eq(CustomerInfo::getServiceStaffId, 0)));
|
|
|
- } else {
|
|
|
+ } else if ("false".equals(isHighSeasStr)) {
|
|
|
// 有效客户:负责人不为空(且不为0) OR 客服不为空(且不为0)
|
|
|
lqw.and(w -> w.and(a -> a.isNotNull(CustomerInfo::getSalesPersonId).ne(CustomerInfo::getSalesPersonId, 0))
|
|
|
.or(b -> b.isNotNull(CustomerInfo::getServiceStaffId).ne(CustomerInfo::getServiceStaffId, 0)));
|
|
|
@@ -1375,14 +1443,47 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean claimPool(CustomerClaimBo claimBo) {
|
|
|
Long customerId = claimBo.getId();
|
|
|
- // 认领操作仅更新客户主表,不再涉及到销售信息表
|
|
|
- CustomerInfo customer = new CustomerInfo();
|
|
|
- customer.setId(customerId);
|
|
|
+ CustomerInfo customer = baseMapper.selectById(customerId);
|
|
|
+ if (customer == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 认领操作更新客户主表
|
|
|
customer.setSalesPersonId(claimBo.getSalesPersonId());
|
|
|
customer.setServiceStaffId(claimBo.getServiceStaffId());
|
|
|
customer.setBelongingDepartmentId(claimBo.getDeptId());
|
|
|
customer.setStatus("0"); // 认领成功后,将客户主表状态改为有效
|
|
|
- return baseMapper.updateById(customer) > 0;
|
|
|
+ boolean updated = baseMapper.updateById(customer) > 0;
|
|
|
+
|
|
|
+ if (updated && claimBo.getSalesPersonId() != null) {
|
|
|
+ // 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return updated;
|
|
|
}
|
|
|
|
|
|
@Override
|