|
|
@@ -59,6 +59,10 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
@DubboReference
|
|
|
private RemoteDeptService remoteDeptService;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private RemoteErpDeptService remoteErpDeptService;
|
|
|
+ @DubboReference
|
|
|
+ private RemoteErpStaffService remoteErpStaffService;
|
|
|
@DubboReference
|
|
|
private RemoteUserService remoteUserService;
|
|
|
@DubboReference
|
|
|
@@ -134,6 +138,12 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
vo.setIndustryName(industryCategoryVo.getIndustryCategoryName());
|
|
|
}
|
|
|
}
|
|
|
+ // 2. 查询关联信息
|
|
|
+ vo.setCustomerBusinessInfoVo(
|
|
|
+ Optional.ofNullable(customerBusinessInfoMapper.selectByCustomerId(id))
|
|
|
+ .map(entity -> MapstructUtils.convert(entity, CustomerBusinessInfoVo.class))
|
|
|
+ .orElse(null)
|
|
|
+ );
|
|
|
|
|
|
// 企业类型名称 (Q0001)
|
|
|
if (vo.getCustomerTypeId() != null) {
|
|
|
@@ -205,86 +215,111 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
|
|
|
// 销售信息
|
|
|
CustomerSalesInfo customerSalesInfo = customerSalesInfoMapper.selectByCustomerId(id);
|
|
|
- if (customerSalesInfo != null) {
|
|
|
- if (ObjectUtils.isNotEmpty(customerSalesInfo.getCreditAmount()) && ObjectUtils.isNotEmpty(customerSalesInfo.getTemporaryQuota())) {
|
|
|
- customerSalesInfo.setRemainingQuota(customerSalesInfo.getCreditAmount().add(customerSalesInfo.getTemporaryQuota()));
|
|
|
- }
|
|
|
+ if (customerSalesInfo == null) {
|
|
|
+ vo.setCustomerSalesInfoVo(null);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotEmpty(customerSalesInfo.getCreditAmount()) && ObjectUtils.isNotEmpty(customerSalesInfo.getTemporaryQuota())) {
|
|
|
+ customerSalesInfo.setRemainingQuota(customerSalesInfo.getCreditAmount().add(customerSalesInfo.getTemporaryQuota()));
|
|
|
+ }
|
|
|
+ Set<Long> staffIds = new HashSet<>();
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
|
|
|
- CustomerSalesInfoVo voObj = MapstructUtils.convert(customerSalesInfo, CustomerSalesInfoVo.class);
|
|
|
+ if (customerSalesInfo.getSalesPersonId() != null) {
|
|
|
+ staffIds.add(customerSalesInfo.getSalesPersonId());
|
|
|
+ }
|
|
|
+ if (customerSalesInfo.getServiceStaffId() != null) {
|
|
|
+ staffIds.add(customerSalesInfo.getServiceStaffId());
|
|
|
+ }
|
|
|
+ if (customerSalesInfo.getBelongingDepartmentId() != null) {
|
|
|
+ deptIds.add(customerSalesInfo.getBelongingDepartmentId());
|
|
|
+ }
|
|
|
|
|
|
- // 补充客户来源名称 (customer_source)
|
|
|
- if (StringUtils.isNotBlank(customerSalesInfo.getCustomerSource())) {
|
|
|
- List<RemoteDictDataVo> sourceDicts = remoteDictService.selectDictDataByType("customer_source");
|
|
|
- sourceDicts.stream()
|
|
|
- .filter(d -> customerSalesInfo.getCustomerSource().equals(d.getDictValue()))
|
|
|
- .findFirst()
|
|
|
- .ifPresent(d -> vo.setCustomerSourceName(d.getDictLabel()));
|
|
|
- }
|
|
|
+ Map<Long, String> staffMap = staffIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteErpStaffService.selectStaffNameByIds(staffIds);
|
|
|
|
|
|
- // 补充人员和部门名称
|
|
|
- Set<Long> staffIds = new HashSet<>();
|
|
|
- if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
- if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
+ 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));
|
|
|
-
|
|
|
- // 归属部门逻辑:优先从销售信息的 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);
|
|
|
+ // 先转换
|
|
|
+ CustomerSalesInfoVo voObj = MapstructUtils.convert(customerSalesInfo, CustomerSalesInfoVo.class);
|
|
|
+
|
|
|
+ // 再补充名称
|
|
|
+ if (voObj != null) {
|
|
|
+ voObj.setSalesPerson(staffMap.get(customerSalesInfo.getSalesPersonId()));
|
|
|
+ voObj.setServiceStaff(staffMap.get(customerSalesInfo.getServiceStaffId()));
|
|
|
+ voObj.setBelongingDepartment(deptMap.get(customerSalesInfo.getBelongingDepartmentId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setCustomerSalesInfoVo(voObj);
|
|
|
+
|
|
|
+ Set<Long> comStaffIds = new HashSet<>();
|
|
|
+ Set<Long> comDeptIds = new HashSet<>(); //系统的部门
|
|
|
+
|
|
|
+ if (vo.getSalesPersonId() != null) {
|
|
|
+ comStaffIds.add(vo.getSalesPersonId());
|
|
|
+ }
|
|
|
+ if (vo.getServiceStaffId() != null) {
|
|
|
+ comStaffIds.add(vo.getServiceStaffId());
|
|
|
+ }
|
|
|
+ if (vo.getBelongingDepartmentId() != null) {
|
|
|
+ comDeptIds.add(vo.getBelongingDepartmentId());
|
|
|
}
|
|
|
|
|
|
+ Map<Long, String> comStaffMap = comStaffIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteComStaffService.selectStaffNameByIds(comStaffIds);
|
|
|
+
|
|
|
+ Map<Long, String> comDeptMap = comDeptIds.isEmpty()//系统的部门
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteDeptService.selectDeptNameByIds(comDeptIds);
|
|
|
+
|
|
|
+ /*回填系统的人员与部门*/
|
|
|
+ vo.setSalesPersonName(comStaffMap.get(vo.getSalesPersonId()));
|
|
|
+ vo.setServiceStaffName(comStaffMap.get(vo.getServiceStaffId()));
|
|
|
+ vo.setBelongingDepartmentName(comDeptMap.get(vo.getBelongingDepartmentId()));
|
|
|
+
|
|
|
+
|
|
|
// 补充开票类型 (来自主表 sell_invoice_type)
|
|
|
vo.setInvoiceType(vo.getSellInvoiceType());
|
|
|
vo.setInvoiceTypeName(vo.getSellInvoiceType());
|
|
|
|
|
|
// 联系人列表
|
|
|
List<CustomerContact> contactEntities = customerContactMapper.selectListByCustomerId(id);
|
|
|
- vo.setCustomerContactVoList(CollUtil.isEmpty(contactEntities) ? Collections.emptyList() :
|
|
|
- contactEntities.stream().map(c -> MapstructUtils.convert(c, CustomerContactVo.class)).collect(Collectors.toList()));
|
|
|
+ vo.setCustomerContactVoList(
|
|
|
+ contactEntities != null
|
|
|
+ ? contactEntities.stream()
|
|
|
+ .map(contact -> MapstructUtils.convert(contact, CustomerContactVo.class))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ : Collections.emptyList()
|
|
|
+ );
|
|
|
|
|
|
// 发票列表
|
|
|
List<CustomerInvoiceInfo> invoiceEntities = customerInvoiceInfoMapper.selectListByCustomerId(id);
|
|
|
- vo.setCustomerInvoiceInfoVoList(CollUtil.isEmpty(invoiceEntities) ? Collections.emptyList() :
|
|
|
- invoiceEntities.stream().map(i -> MapstructUtils.convert(i, CustomerInvoiceInfoVo.class)).collect(Collectors.toList()));
|
|
|
-
|
|
|
- // 3. 计算部门额度
|
|
|
+ vo.setCustomerInvoiceInfoVoList(
|
|
|
+ invoiceEntities != null
|
|
|
+ ? invoiceEntities.stream()
|
|
|
+ .map(invoice -> MapstructUtils.convert(invoice, CustomerInvoiceInfoVo.class))
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ : Collections.emptyList()
|
|
|
+ );
|
|
|
Long userId = LoginHelper.getLoginUser().getUserId();
|
|
|
- if (Objects.nonNull(userId) && CollUtil.isNotEmpty(contactEntities)) {
|
|
|
- contactEntities.stream()
|
|
|
+ // 2. 使用 Optional 和 Stream 查找并处理
|
|
|
+ if (Objects.nonNull(userId)) { // 或者使用 userId != null
|
|
|
+ Optional<CustomerContact> optionalContact = contactEntities.stream()
|
|
|
.filter(contactEntity -> Objects.equals(contactEntity.getUserId(), userId))
|
|
|
- .findFirst()
|
|
|
- .ifPresent(contact -> {
|
|
|
- CustomerDeptVo customerDeptVo = customerDeptMapper.selectVoById(contact.getDeptId());
|
|
|
- if (customerDeptVo != null) {
|
|
|
- vo.setDeptCredit(customerDeptVo.getResidueYearlyBudget());
|
|
|
- }
|
|
|
- });
|
|
|
+ .findFirst();
|
|
|
+
|
|
|
+ // 3. 只有当找到匹配的 contact 时,才执行后续逻辑
|
|
|
+ optionalContact.ifPresent(contact -> {
|
|
|
+ CustomerDeptVo customerDeptVo = customerDeptMapper.selectVoById(contact.getDeptId());
|
|
|
+ // 建议增加对 customerDeptVo 的非空判断,防止 selectVoById 返回 null
|
|
|
+ if (customerDeptVo != null) {
|
|
|
+ vo.setDeptCredit(customerDeptVo.getResidueYearlyBudget());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
// 4. 补全管理信息人名
|
|
|
Set<Long> userIds = new HashSet<>();
|
|
|
@@ -342,6 +377,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
IndustryCategoryVo::getIndustryCategoryName,
|
|
|
(e, r) -> e
|
|
|
));
|
|
|
+ records.forEach(vo -> vo.setIndustryCategory(industryMap.get(vo.getIndustryCategoryId())));
|
|
|
}
|
|
|
|
|
|
// === 2. 提取客户ID,查询销售信息 ===
|
|
|
@@ -381,39 +417,60 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
(existing, replacement) -> existing // 若有重复,保留第一个
|
|
|
));
|
|
|
|
|
|
+ // === 4. 收集人员和部门ID ===
|
|
|
Set<Long> staffIds = new HashSet<>();
|
|
|
+ Set<Long> deptIds = new HashSet<>();
|
|
|
|
|
|
- // === 3. 提取人员和部门ID用于查询名称 ===
|
|
|
- for (CustomerInfoVo vo : records) {
|
|
|
+ for (CustomerSalesInfoVo vo : salesInfoVos) {
|
|
|
if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
|
|
|
if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
|
|
|
-
|
|
|
- CustomerSalesInfoVo salesVo = salesInfoMap.get(vo.getId());
|
|
|
+ if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
|
|
|
}
|
|
|
|
|
|
// === 5. 远程调用获取名称 ===
|
|
|
Map<Long, String> companyMap = companyIds.isEmpty()
|
|
|
? Collections.emptyMap()
|
|
|
: remoteComCompanyService.selectCompanyNameByIds(companyIds);
|
|
|
-
|
|
|
- List<RemoteComStaffVo> staffVos = staffIds.isEmpty() ? Collections.emptyList() : remoteComStaffService.selectStaffByIds(staffIds);
|
|
|
- Map<Long, RemoteComStaffVo> staffFullMap = CollUtil.isEmpty(staffVos) ? Collections.emptyMap() :
|
|
|
- staffVos.stream().collect(Collectors.toMap(RemoteComStaffVo::getStaffId, Function.identity(), (k1, k2) -> k1));
|
|
|
+ Map<Long, String> staffMap = staffIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteErpStaffService.selectStaffNameByIds(staffIds);
|
|
|
+
|
|
|
+ Map<Long, String> deptMap = deptIds.isEmpty()
|
|
|
+ ? 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<>();
|
|
|
|
|
|
- // === 6. 回填人员和部门名称到 vo ===
|
|
|
for (CustomerInfoVo vo : records) {
|
|
|
- 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);
|
|
|
+ if (vo.getSalesPersonId() != null) comStaffIds.add(vo.getSalesPersonId());
|
|
|
+ if (vo.getServiceStaffId() != null) comStaffIds.add(vo.getServiceStaffId());
|
|
|
+ if (vo.getBelongingDepartmentId() != null) comDeptIds.add(vo.getBelongingDepartmentId());
|
|
|
}
|
|
|
|
|
|
+ // === 远程调用获取名称 ===
|
|
|
+ Map<Long, String> comStaffMap = staffIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteComStaffService.selectStaffNameByIds(comStaffIds);
|
|
|
+
|
|
|
+ Map<Long, String> comDeptMap = deptIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : remoteDeptService.selectDeptNameByIds(comDeptIds);
|
|
|
+
|
|
|
+ // === 回填系统人员和部门名称到 customerInfoVo ===
|
|
|
+ records.forEach(v -> {
|
|
|
+ v.setSalesPersonName(comStaffMap.get(v.getSalesPersonId()));
|
|
|
+ v.setServiceStaffName(comStaffMap.get(v.getServiceStaffId()));
|
|
|
+ v.setBelongingDepartmentName(comDeptMap.get(v.getBelongingDepartmentId()));
|
|
|
+ });
|
|
|
+
|
|
|
// === 7. 将销售信息回填到客户VO ===
|
|
|
for (CustomerInfoVo customerVo : records) {
|
|
|
customerVo.setCompanyName(companyMap.get(customerVo.getBelongCompanyId()));
|
|
|
@@ -612,7 +669,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
if (vo.getBelongCompanyId() != null) companyIds.add(vo.getBelongCompanyId());
|
|
|
if (vo.getCustomerLevelId() != null) customerLevelIds.add(vo.getCustomerLevelId());
|
|
|
-
|
|
|
+
|
|
|
// 处理部门ID收集
|
|
|
if (vo.getBelongingDepartmentId() != null) {
|
|
|
deptIds.add(vo.getBelongingDepartmentId());
|
|
|
@@ -654,13 +711,13 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
vo.setCreditLevelName(creditLevelMap.get(vo.getCreditLevelId()));
|
|
|
vo.setCompanyName(companyMap.get(vo.getBelongCompanyId()));
|
|
|
-
|
|
|
+
|
|
|
// 企业类型翻译
|
|
|
String typeValue = vo.getEnterpriseTypeId() != null ? String.valueOf(vo.getEnterpriseTypeId()) : null;
|
|
|
vo.setEnterpriseTypeName(enterpriseTypeMap.get(typeValue));
|
|
|
|
|
|
vo.setCustomerLevelName(customerLevelMap.get(vo.getCustomerLevelId()));
|
|
|
-
|
|
|
+
|
|
|
// 合作状态翻译
|
|
|
vo.setCooperationName(cooperationMap.get(vo.getStatus()));
|
|
|
});
|
|
|
@@ -708,7 +765,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getRegCityNo()), CustomerInfo::getRegCityNo, bo.getRegCityNo());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getRegCountyNo()), CustomerInfo::getRegCountyNo, bo.getRegCountyNo());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getProvincialCityCounty()), CustomerInfo::getProvincialCityCounty, bo.getProvincialCityCounty());
|
|
|
-
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), CustomerInfo::getStatus, bo.getStatus());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getPlatformCode()), CustomerInfo::getPlatformCode, bo.getPlatformCode());
|
|
|
lqw.eq(bo.getSalesPersonId() != null, CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
|
|
|
lqw.eq(bo.getServiceStaffId() != null, CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
|
|
|
@@ -1295,7 +1352,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
remoteUserBo.setUserName(bo.getPurchasePhone());
|
|
|
remoteUserBo.setNickName(bo.getPurchaseName());
|
|
|
remoteUserBo.setPhonenumber(bo.getPurchasePhone());
|
|
|
- remoteUserBo.setRoleId(1996816313015631873L);
|
|
|
+ remoteUserBo.setRoleId(2049022448332603393L);
|
|
|
+ remoteUserBo.setRoleIds(new Long[]{2049022448332603393L});
|
|
|
remoteUserBo.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
|
remoteUserBo.setUserSonType("3"); // 商城用户
|
|
|
remoteUserBo.setTenantId(LoginHelper.getTenantId());
|
|
|
@@ -1303,6 +1361,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
Long userId = remoteUserService.addUser(remoteUserBo);
|
|
|
|
|
|
|
|
|
+ remoteUserBo.setUserId(userId);
|
|
|
+ remoteUserService.addUserRole(remoteUserBo);
|
|
|
// 添加客户联系人信息
|
|
|
CustomerContact contact = new CustomerContact();
|
|
|
contact.setCustomerId(customerId);
|
|
|
@@ -1335,6 +1395,63 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 个人注册
|
|
|
+ *
|
|
|
+ * @param bo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean selfRegister(CustomerRegisterBo bo) {
|
|
|
+ //先校验验证码是否正确
|
|
|
+ String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + bo.getPurchasePhone());
|
|
|
+ if (code == null) {
|
|
|
+ throw new ServiceException("验证码已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!code.equals(bo.getCode())) {
|
|
|
+ throw new ServiceException("验证码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验密码与确认密码是否一致
|
|
|
+ if (!bo.getPassword().equals(bo.getConfirmPassword())) {
|
|
|
+ throw new ServiceException("密码与确认密码不一致");
|
|
|
+ }
|
|
|
+ // 创建系统用户
|
|
|
+ RemoteUserBo remoteUserBo = new RemoteUserBo();
|
|
|
+ remoteUserBo.setUserName(bo.getPurchasePhone());
|
|
|
+ remoteUserBo.setNickName(bo.getPurchaseName());
|
|
|
+ remoteUserBo.setPhonenumber(bo.getPurchasePhone());
|
|
|
+ remoteUserBo.setRoleId(2049023315869859841L);
|
|
|
+ remoteUserBo.setRoleIds(new Long[]{2049023315869859841L});
|
|
|
+ remoteUserBo.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
|
+ remoteUserBo.setUserSonType("4"); // 商城用户
|
|
|
+ remoteUserBo.setTenantId(LoginHelper.getTenantId());
|
|
|
+ remoteUserBo.setStatus("0"); // 正常状态
|
|
|
+ Long userId = remoteUserService.addUser(remoteUserBo);
|
|
|
+
|
|
|
+
|
|
|
+ // 添加客户联系人信息
|
|
|
+ CustomerContact contact = new CustomerContact();
|
|
|
+ contact.setUserId(userId);
|
|
|
+ contact.setRoleId(1L);
|
|
|
+ contact.setContactName(bo.getPurchaseName());
|
|
|
+ contact.setPhone(bo.getPurchasePhone());
|
|
|
+ contact.setCustomLoginName(bo.getPurchasePhone());
|
|
|
+ contact.setIsPrimary("0"); // 设为主联系人
|
|
|
+ contact.setStatus("0");
|
|
|
+ contact.setDelFlag("0");
|
|
|
+
|
|
|
+ if (customerContactMapper.insert(contact) <= 0) {
|
|
|
+ throw new ServiceException("注册失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (null != code) {
|
|
|
+ RedisUtils.deleteObject(GlobalConstants.CAPTCHA_CODE_KEY + bo.getPurchasePhone());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int transferSalesPerson(List<Long> customerIds, Long salesPersonId, Long deptId) {
|
|
|
@@ -1342,27 +1459,107 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- // 直接进行批量更新,不再循环查询
|
|
|
- return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
|
|
|
- .set(CustomerInfo::getSalesPersonId, salesPersonId)
|
|
|
- // 如果传了部门ID则更新,没传则不更新
|
|
|
- .set(deptId != null, CustomerInfo::getBelongingDepartmentId, deptId)
|
|
|
- .in(CustomerInfo::getId, customerIds)
|
|
|
- );
|
|
|
+ if (salesPersonId == null || deptId == null) {
|
|
|
+ log.warn("转移业务人员失败,业务人员 ID 或部门 ID 为空");
|
|
|
+ throw new ServiceException("业务人员和所属部门不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<CustomerInfo> updateList = new ArrayList<>();
|
|
|
+ CustomerInfo customerInfo = null;
|
|
|
+ for (Long customerId : customerIds) {
|
|
|
+ if (customerId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ customerInfo = baseMapper.selectById(customerId);
|
|
|
+ if (customerInfo != null) {
|
|
|
+ customerInfo.setSalesPersonId(salesPersonId);
|
|
|
+ customerInfo.setBelongingDepartmentId(deptId);
|
|
|
+ updateList.add(customerInfo);
|
|
|
+ } else {
|
|
|
+ log.warn("客户 ID: {} 不存在,跳过更新", customerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ boolean success = baseMapper.updateBatchById(updateList);
|
|
|
+ if (success) {
|
|
|
+ log.info("成功转移 {} 个客户的业务人员,目标业务员 ID: {}, 部门 ID: {}",
|
|
|
+ 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);
|
|
|
+ throw new ServiceException("转移业务人员失败:" + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public int transferServiceStaff(List<Long> customerIds, Long serviceStaffId) {
|
|
|
- if (CollUtil.isEmpty(customerIds) || serviceStaffId == null) {
|
|
|
+ if (CollUtil.isEmpty(customerIds)) {
|
|
|
+ log.warn("转移客服人员失败,客户 ID 列表为空");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (serviceStaffId == null) {
|
|
|
+ log.warn("转移客服人员失败,客服人员 ID 为空");
|
|
|
+ throw new ServiceException("客服人员和不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<CustomerInfo> updateList = new ArrayList<>();
|
|
|
+ CustomerInfo customerInfo = null;
|
|
|
+ for (Long customerId : customerIds) {
|
|
|
+ if (customerId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ customerInfo = baseMapper.selectById(customerId);
|
|
|
+ if (customerInfo != null) {
|
|
|
+ customerInfo.setServiceStaffId(serviceStaffId);
|
|
|
+ updateList.add(customerInfo);
|
|
|
+ } else {
|
|
|
+ log.warn("客户 ID: {} 不存在,跳过更新", customerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ boolean success = baseMapper.updateBatchById(updateList);
|
|
|
+ if (success) {
|
|
|
+ log.info("成功转移 {} 个客户的客服人员,目标客服人员 ID: {}",
|
|
|
+ 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);
|
|
|
+ throw new ServiceException("转移客服人员失败:" + e.getMessage());
|
|
|
}
|
|
|
|
|
|
// 直接进行批量更新
|
|
|
- return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
|
|
|
- .set(CustomerInfo::getServiceStaffId, serviceStaffId)
|
|
|
- .in(CustomerInfo::getId, customerIds)
|
|
|
- );
|
|
|
+// return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
|
|
|
+// .set(CustomerInfo::getServiceStaffId, serviceStaffId)
|
|
|
+// .in(CustomerInfo::getId, customerIds)
|
|
|
+// );
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1410,6 +1607,8 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
CustomerBusinessInfo customerBusinessInfo = customerBusinessInfoMapper.selectOne(new LambdaQueryWrapper<CustomerBusinessInfo>().eq(CustomerBusinessInfo::getCustomerId, update.getId()));
|
|
|
|
|
|
if (customerSalesInfo != null) {
|
|
|
+ customerSalesInfo.setSalesPersonId(customerSalesInfoBo.getSalesPersonId());
|
|
|
+ customerSalesInfo.setServiceStaffId(customerSalesInfoBo.getServiceStaffId());
|
|
|
customerSalesInfo.setCreditLevelId(customerSalesInfoBo.getCreditLevelId());
|
|
|
customerSalesInfoMapper.updateById(customerSalesInfo);
|
|
|
}
|
|
|
@@ -1431,14 +1630,14 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
if (customer == null) {
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 1. 认领操作更新客户主表
|
|
|
customer.setSalesPersonId(claimBo.getSalesPersonId());
|
|
|
customer.setServiceStaffId(claimBo.getServiceStaffId());
|
|
|
customer.setBelongingDepartmentId(claimBo.getDeptId());
|
|
|
customer.setStatus("0"); // 认领成功后,将客户主表状态改为有效
|
|
|
boolean updated = baseMapper.updateById(customer) > 0;
|
|
|
-
|
|
|
+
|
|
|
if (updated && claimBo.getSalesPersonId() != null) {
|
|
|
// 2. 将业务员加入团队成员
|
|
|
// 检查是否已在团队中
|
|
|
@@ -1446,7 +1645,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
.eq(TeamMember::getDataType, 12)
|
|
|
.eq(TeamMember::getObjectNo, customer.getCustomerNo())
|
|
|
.eq(TeamMember::getUserNo, claimBo.getSalesPersonId()));
|
|
|
-
|
|
|
+
|
|
|
if (count == 0) {
|
|
|
TeamMember member = new TeamMember();
|
|
|
member.setDataType(12); // 客户类型
|
|
|
@@ -1456,17 +1655,17 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
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;
|
|
|
}
|
|
|
|