Parcourir la source

修复客户认领、退回到客户公海、转移业务员、转移客服人员的功能

沐梦. il y a 1 mois
Parent
commit
c3c939a1b9

+ 10 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/CustomerInfoController.java

@@ -22,6 +22,7 @@ import org.dromara.customer.domain.bo.CustomerListBo;
 import org.dromara.customer.domain.bo.CustomerSalesInfoBo;
 import org.dromara.customer.domain.bo.MessagePublishCustomerBo;
 import org.dromara.customer.domain.dto.SetCustomerInfoTagDto;
+import org.dromara.customer.domain.dto.ReleaseToPoolDto;
 import org.dromara.customer.domain.vo.*;
 import org.dromara.customer.listener.CustomerImportListener;
 import org.dromara.customer.service.ICustomerInfoService;
@@ -239,6 +240,15 @@ public class CustomerInfoController extends BaseController {
         return toAjax(customerInfoService.claimPool(bo));
     }
 
+    /**
+     * 退回客户到公海
+     */
+    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
+    @PostMapping("/releaseToPool")
+    public R<Integer> releaseToPool(@RequestBody ReleaseToPoolDto bo) {
+        return R.ok(customerInfoService.releaseToPool(bo.getCustomerIds(), bo.getReason()));
+    }
+
     /**
      * 导入数据
      *

+ 5 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/bo/CustomerClaimBo.java

@@ -37,4 +37,9 @@ public class CustomerClaimBo implements Serializable {
      * 是否保留已有负责人 (0: 否, 1: 是)
      */
     private String keepOldManager;
+
+    /**
+     * 部门ID
+     */
+    private Long deptId;
 }

+ 22 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/domain/dto/ReleaseToPoolDto.java

@@ -0,0 +1,22 @@
+package org.dromara.customer.domain.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 退回到公海 DTO
+ */
+@Data
+public class ReleaseToPoolDto implements Serializable {
+    /**
+     * 客户ID列表
+     */
+    private List<Long> customerIds;
+
+    /**
+     * 退回原因
+     */
+    private String reason;
+}

+ 9 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/ICustomerInfoService.java

@@ -126,6 +126,15 @@ public interface ICustomerInfoService extends IService<CustomerInfo> {
      */
     Boolean claimPool(CustomerClaimBo claimBo);
 
+    /**
+     * 退回客户到公海
+     *
+     * @param customerIds 客户ID列表
+     * @param reason 退回原因
+     * @return 更新数量
+     */
+    int releaseToPool(List<Long> customerIds, String reason);
+
 
     Map<Long, String> selectCustomerNameByIds(Set<Long> ids);
 

+ 40 - 109
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -499,13 +499,16 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
             Set<Long> deptIds = new HashSet<>();
 
             records.forEach(vo -> {
-                if (vo.getSalesPersonId() != null) staffIds.add(vo.getSalesPersonId());
-                if (vo.getServiceStaffId() != null) staffIds.add(vo.getServiceStaffId());
-                if (vo.getCreditLevelId() != null) creditLevelIds.add(vo.getCreditLevelId());
+                // 如果是公海客户,不处理销售ERP相关内容(负责人、客服、部门、信用等级)
+                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());
-                if (vo.getBelongingDepartmentId() != null) deptIds.add(vo.getBelongingDepartmentId());
             });
 
             // 1. 批量查询业务员和客服名称 (远程调用)
@@ -1232,102 +1235,31 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int transferSalesPerson(List<Long> customerIds, Long salesPersonId, Long deptId) {
-        if (CollUtil.isEmpty(customerIds)) {
-            log.warn("转移业务人员失败,客户 ID 列表为空");
+        if (CollUtil.isEmpty(customerIds) || salesPersonId == null) {
             return 0;
         }
 
-        if (salesPersonId == null || deptId == null) {
-            log.warn("转移业务人员失败,业务人员 ID 或部门 ID 为空");
-            throw new ServiceException("业务人员和所属部门不能为空");
-        }
-
-        try {
-            List<CustomerInfo> updateList = new ArrayList<>();
-            for (Long customerId : customerIds) {
-                if (customerId == null) {
-                    continue;
-                }
-                CustomerInfo 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());
-        }
+        // 直接进行批量更新,不再循环查询
+        return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
+            .set(CustomerInfo::getSalesPersonId, salesPersonId)
+            // 如果传了部门ID则更新,没传则不更新
+            .set(deptId != null, CustomerInfo::getBelongingDepartmentId, deptId)
+            .in(CustomerInfo::getId, customerIds)
+        );
     }
 
     @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 {
-            List<CustomerInfo> updateList = new ArrayList<>();
-            for (Long customerId : customerIds) {
-                if (customerId == null) {
-                    continue;
-                }
-                CustomerInfo 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)
+        );
     }
 
     /**
@@ -1392,34 +1324,33 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
     @Transactional(rollbackFor = Exception.class)
     public Boolean claimPool(CustomerClaimBo claimBo) {
         Long customerId = claimBo.getId();
-        CustomerSalesInfo salesInfo = customerSalesInfoMapper.selectOne(new LambdaQueryWrapper<CustomerSalesInfo>()
-            .eq(CustomerSalesInfo::getCustomerId, customerId));
-
-        if (salesInfo == null) {
-            salesInfo = new CustomerSalesInfo();
-            salesInfo.setCustomerId(customerId);
-            salesInfo.setSalesPersonId(claimBo.getSalesPersonId());
-            salesInfo.setServiceStaffId(claimBo.getServiceStaffId());
-            salesInfo.setStatus("0");
-            boolean insertResult = customerSalesInfoMapper.insert(salesInfo) > 0;
-            CustomerInfo customer = new CustomerInfo();
-            customer.setId(customerId);
-            customer.setSalesPersonId(claimBo.getSalesPersonId());
-            customer.setServiceStaffId(claimBo.getServiceStaffId());
-            customer.setStatus("0");
-            baseMapper.updateById(customer);
-            return insertResult;
-        }
-
-        // 更新销售负责人和客服
+        // 认领操作仅更新客户主表,不再涉及到销售信息表
         CustomerInfo customer = new CustomerInfo();
         customer.setId(customerId);
         customer.setSalesPersonId(claimBo.getSalesPersonId());
         customer.setServiceStaffId(claimBo.getServiceStaffId());
+        customer.setBelongingDepartmentId(claimBo.getDeptId());
         customer.setStatus("0"); // 认领成功后,将客户主表状态改为有效
         return baseMapper.updateById(customer) > 0;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int releaseToPool(List<Long> customerIds, String reason) {
+        if (customerIds == null || customerIds.isEmpty()) {
+            return 0;
+        }
+
+        // 使用 LambdaUpdateWrapper 显式更新字段为 null,因为 updateById 默认忽略 null 值
+        return baseMapper.update(null, new LambdaUpdateWrapper<CustomerInfo>()
+            .set(CustomerInfo::getSalesPersonId, null)
+            .set(CustomerInfo::getServiceStaffId, null)
+            .set(CustomerInfo::getBelongingDepartmentId, null)
+            .set(CustomerInfo::getStatus, "1") // 标记为公海状态
+            .in(CustomerInfo::getId, customerIds)
+        );
+    }
+
     @Override
     public CustomerInfoVo selectCustomerByName(String customerName) {
         return baseMapper.selectVoOne(new LambdaQueryWrapper<CustomerInfo>().eq(CustomerInfo::getCustomerName, customerName));

+ 49 - 0
ruoyi-modules/ruoyi-customer/src/main/resources/mapper/customer/SalesAnnualFinalizationMapper.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.dromara.customer.mapper.SalesAnnualFinalizationMapper">
+
+    <select id="selectSalesAnnualFinalizationList" resultType="org.dromara.customer.domain.vo.SalesAnnualFinalizationVo">
+        SELECT s.*, d.dept_name AS deptName
+        FROM salesannualfinalization s
+        LEFT JOIN com_staff cs ON s.Leader = cs.staff_id
+        LEFT JOIN sys_dept d ON cs.dept_id = d.dept_id
+        <where>
+            s.IsDelete = 0
+            <if test="bo.projectName != null and bo.projectName != ''">
+                AND s.ProjectName LIKE concat('%', #{bo.projectName}, '%')
+            </if>
+            <if test="bo.companyNo != null and bo.companyNo != ''">
+                AND s.CompanyNo = #{bo.companyNo}
+            </if>
+            <if test="bo.customName != null and bo.customName != ''">
+                AND s.CustomName LIKE concat('%', #{bo.customName}, '%')
+            </if>
+            <if test="bo.leader != null">
+                AND s.Leader = #{bo.leader}
+            </if>
+            <if test="bo.deptNo != null and bo.deptNo != ''">
+                AND (s.DeptNo = #{bo.deptNo} OR cs.dept_id = #{bo.deptNo})
+            </if>
+            <if test="bo.projectStatus != null">
+                AND s.ProjectStatus = #{bo.projectStatus}
+            </if>
+            <if test="bo.projectLevel != null">
+                AND s.ProjectLevel = #{bo.projectLevel}
+            </if>
+            <if test="bo.businessType != null">
+                AND s.BusinessType = #{bo.businessType}
+            </if>
+            <if test="bo.finalizationType != null">
+                AND s.FinalizationType = #{bo.finalizationType}
+            </if>
+            <if test="bo.productSupport != null and bo.productSupport != ''">
+                AND s.ProductSupport = #{bo.productSupport}
+            </if>
+            ${bo.params.dataScope}
+        </where>
+        ORDER BY s.create_time DESC
+    </select>
+
+</mapper>