|
|
@@ -1051,4 +1051,109 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
log.info("客户注册成功,客户ID:{},客户名称:{}", customerId, bo.getCustomerName());
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int transferSalesPerson(List<Long> customerIds, Long salesPersonId, Long deptId) {
|
|
|
+ if (CollUtil.isEmpty(customerIds)) {
|
|
|
+ log.warn("转移业务人员失败,客户 ID 列表为空");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (salesPersonId == null || deptId == null) {
|
|
|
+ log.warn("转移业务人员失败,业务人员 ID 或部门 ID 为空");
|
|
|
+ throw new ServiceException("业务人员和所属部门不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<CustomerSalesInfo> updateList = new ArrayList<>();
|
|
|
+ CustomerSalesInfo salesInfo = null;
|
|
|
+ for (Long customerId : customerIds) {
|
|
|
+ if (customerId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ salesInfo = customerSalesInfoMapper.selectByCustomerId(customerId);
|
|
|
+ if (salesInfo != null) {
|
|
|
+ salesInfo.setSalesPersonId(salesPersonId);
|
|
|
+ salesInfo.setBelongingDepartmentId(deptId);
|
|
|
+ updateList.add(salesInfo);
|
|
|
+ } else {
|
|
|
+ log.warn("客户 ID: {} 的销售信息不存在,跳过更新", customerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ boolean success = customerSalesInfoMapper.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)) {
|
|
|
+ log.warn("转移客服人员失败,客户 ID 列表为空");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (serviceStaffId == null) {
|
|
|
+ log.warn("转移客服人员失败,客服人员 ID 为空");
|
|
|
+ throw new ServiceException("客服人员和不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<CustomerSalesInfo> updateList = new ArrayList<>();
|
|
|
+ CustomerSalesInfo salesInfo = null;
|
|
|
+ for (Long customerId : customerIds) {
|
|
|
+ if (customerId == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ salesInfo = customerSalesInfoMapper.selectByCustomerId(customerId);
|
|
|
+ if (salesInfo != null) {
|
|
|
+ salesInfo.setServiceStaffId(serviceStaffId);
|
|
|
+ updateList.add(salesInfo);
|
|
|
+ } else {
|
|
|
+ log.warn("客户 ID: {} 的销售信息不存在,跳过更新", customerId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!updateList.isEmpty()) {
|
|
|
+ boolean success = customerSalesInfoMapper.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());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|