三七 2 天之前
父節點
當前提交
d8b0a97205

+ 80 - 8
fs-company/src/main/java/com/fs/company/controller/company/CompanyVoiceRoboticController.java

@@ -25,22 +25,22 @@ import com.fs.company.service.ICompanyVoiceRoboticCallLogCallphoneService;
 import com.fs.company.service.ICompanyVoiceRoboticCalleesService;
 import com.fs.company.service.ICompanyVoiceRoboticService;
 import com.fs.company.service.ICompanyVoiceRoboticWxService;
-import com.fs.company.vo.CalleeRoboticCallOutCountVO;
-import com.fs.company.vo.CdrBodyVo;
-import com.fs.company.vo.CdrDetailVo;
-import com.fs.company.vo.WorkflowExecRecordVo;
+import com.fs.company.service.impl.CompanyUserServiceImpl;
+import com.fs.company.vo.*;
+import com.fs.crm.domain.CrmCustomerProperty;
+import com.fs.crm.service.ICrmCustomerPropertyService;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
+import com.fs.sop.domain.QwSopTemp;
+import com.fs.voice.utils.StringUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -66,6 +66,11 @@ public class CompanyVoiceRoboticController extends BaseController
     private TokenService tokenService;
     @Autowired
     private ICompanyVoiceRoboticCallLogCallphoneService companyVoiceRoboticCallLogCallphoneService;
+    @Autowired
+    private CompanyUserServiceImpl companyUserService;
+
+    @Autowired
+    private ICrmCustomerPropertyService crmCustomerPropertyService;
 
     /**
      * 查询机器人外呼任务列表
@@ -77,8 +82,55 @@ public class CompanyVoiceRoboticController extends BaseController
         companyVoiceRobotic.setCompanyId(loginUser.getCompany().getCompanyId());
         startPage();
         List<CompanyVoiceRobotic> list = companyVoiceRoboticService.selectCompanyVoiceRoboticListCompany(companyVoiceRobotic);
+        fillUserInfo(list);
+        return getDataTable(list);
+    }
+
+    @PreAuthorize("@ss.hasPermi('system:companyVoiceRobotic:myList')")
+    @GetMapping("/myList")
+    public TableDataInfo myList(CompanyVoiceRobotic companyVoiceRobotic){
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        companyVoiceRobotic.setCompanyId(loginUser.getCompany().getCompanyId());
+        companyVoiceRobotic.setCreateUser(loginUser.getUser().getUserId());
+        startPage();
+        List<CompanyVoiceRobotic> list = companyVoiceRoboticService.selectCompanyVoiceRoboticListCompany(companyVoiceRobotic);
+        fillUserInfo(list);
         return getDataTable(list);
     }
+
+    /**
+     * 填充创建人信息
+     */
+    private void fillUserInfo(List<CompanyVoiceRobotic> list) {
+        if (list == null || list.isEmpty()) {
+            return;
+        }
+
+        Set<Long> userIds = list.stream()
+                .map(CompanyVoiceRobotic::getCreateUser)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        if (userIds.isEmpty()) {
+            return;
+        }
+
+        Map<Long, DocCompanyUserVO> userMap = companyUserService
+                .selectDocCompanyUserListByUserIds(userIds)
+                .stream()
+                .collect(Collectors.toMap(DocCompanyUserVO::getUserId, Function.identity()));
+
+        list.forEach(item -> {
+            if (item.getCreateUser() != null) {
+                DocCompanyUserVO user = userMap.get(item.getCreateUser());
+                if (user != null) {
+                    item.setCreateByName(user.getNickName());
+                    item.setCreateByDeptName(user.getDeptName());
+                }
+            }
+        });
+    }
+
     /**
      * 查询机器人外呼任务列表
      */
@@ -95,6 +147,22 @@ public class CompanyVoiceRoboticController extends BaseController
         startPage();
         List<CompanyVoiceRoboticCallees> list = companyVoiceRoboticCalleesService.selectCompanyVoiceRoboticCalleesListByRoboticId(id);
         if (list != null && !list.isEmpty() && id != null) {
+
+            List<Long> customerIds = list.stream()
+                    .map(CompanyVoiceRoboticCallees::getUserId)
+                    .filter(Objects::nonNull)
+                    .distinct()
+                    .collect(Collectors.toList());
+
+            Map<Long, List<CrmCustomerProperty>> propertyMap = new HashMap<>();
+            if (!customerIds.isEmpty()) {
+                List<CrmCustomerProperty> allProperties = crmCustomerPropertyService.selectCrmCustomerPropertyByCustomerIds(customerIds);
+                propertyMap = allProperties.stream()
+                        .collect(Collectors.groupingBy(CrmCustomerProperty::getCustomerId));
+            }
+
+
+
             LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
             Long companyId = loginUser.getCompany().getCompanyId();
             List<Long> calleeIds = list.stream().map(CompanyVoiceRoboticCallees::getId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
@@ -104,6 +172,10 @@ public class CompanyVoiceRoboticController extends BaseController
                 for (CompanyVoiceRoboticCallees row : list) {
                     long n = row.getId() == null ? 0L : countMap.getOrDefault(row.getId(), 0L);
                     row.setRoboticCallOutCount((int) n);
+
+                    if (row.getUserId() != null) {
+                        row.setTagList(propertyMap.getOrDefault(row.getUserId(), new ArrayList<>()));
+                    }
                 }
             }
         }

+ 60 - 0
fs-company/src/main/java/com/fs/company/controller/company/CompanyWorkflowController.java

@@ -8,11 +8,14 @@ import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.company.domain.CompanyVoiceRobotic;
 import com.fs.company.domain.CompanyWorkflow;
 import com.fs.company.domain.CompanyWorkflowNodeType;
 import com.fs.company.param.CompanyWorkflowSaveParam;
 import com.fs.company.param.CompanyWorkflowUpdateBindWCParam;
 import com.fs.company.service.ICompanyWorkflowService;
+import com.fs.company.service.impl.CompanyUserServiceImpl;
+import com.fs.company.vo.DocCompanyUserVO;
 import com.fs.company.vo.OptionVO;
 import com.fs.framework.security.LoginUser;
 import com.fs.framework.service.TokenService;
@@ -20,6 +23,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * AI工作流Controller
@@ -36,6 +44,9 @@ public class CompanyWorkflowController extends BaseController {
     @Autowired
     private TokenService tokenService;
 
+    @Autowired
+    private CompanyUserServiceImpl companyUserService;
+
     /**
      * 查询AI工作流列表
      */
@@ -45,9 +56,58 @@ public class CompanyWorkflowController extends BaseController {
         fsAiWorkflow.setCompanyId(loginUser.getCompany().getCompanyId());
         startPage();
         List<CompanyWorkflow> list = companyWorkflowService.selectCompanyWorkflowList(fsAiWorkflow);
+        fillUserInfo(list);
+        return getDataTable(list);
+    }
+
+    /**
+     * 查询AI工作流列表
+     */
+    @GetMapping("/myList")
+    public TableDataInfo myList(CompanyWorkflow fsAiWorkflow) {
+        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
+        fsAiWorkflow.setCompanyId(loginUser.getCompany().getCompanyId());
+        fsAiWorkflow.setCompanyUserId(loginUser.getUser().getUserId());
+        startPage();
+        List<CompanyWorkflow> list = companyWorkflowService.selectCompanyWorkflowList(fsAiWorkflow);
+        fillUserInfo(list);
         return getDataTable(list);
     }
 
+
+    /**
+     * 填充创建人信息
+     */
+    private void fillUserInfo(List<CompanyWorkflow> list) {
+        if (list == null || list.isEmpty()) {
+            return;
+        }
+
+        Set<Long> userIds = list.stream()
+                .map(CompanyWorkflow::getCompanyUserId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        if (userIds.isEmpty()) {
+            return;
+        }
+
+        Map<Long, DocCompanyUserVO> userMap = companyUserService
+                .selectDocCompanyUserListByUserIds(userIds)
+                .stream()
+                .collect(Collectors.toMap(DocCompanyUserVO::getUserId, Function.identity()));
+
+        list.forEach(item -> {
+            if (item.getCompanyUserId() != null) {
+                DocCompanyUserVO user = userMap.get(item.getCompanyUserId());
+                if (user != null) {
+                    item.setCreateByName(user.getNickName());
+                    item.setCreateByDeptName(user.getDeptName());
+                }
+            }
+        });
+    }
+
     /**
      * 导出AI工作流列表
      */

+ 5 - 0
fs-company/src/main/java/com/fs/company/controller/crm/CrmCustomerController.java

@@ -112,6 +112,11 @@ public class CrmCustomerController extends BaseController
 
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         crmCustomer.setCompanyId(loginUser.getCompany().getCompanyId());
+
+        if (!CompanyUser.isAdmin(loginUser.getUser().getUserType())) {
+            crmCustomer.setCustomerUserId(loginUser.getUser().getUserId());
+        }
+
         PageHelper.startPage(1, 1000);
         if(!StringUtils.isEmpty(crmCustomer.getReceiveTimeRange())){
             crmCustomer.setReceiveTimeList(crmCustomer.getReceiveTimeRange().split("--"));

+ 6 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRobotic.java

@@ -138,4 +138,10 @@ public class CompanyVoiceRobotic {
 
     /** 删除标志 0正常 1删除 */
     private Integer delFlag;
+
+    @TableField(exist = false)
+    private String createByName;
+
+    @TableField(exist = false)
+    private String createByDeptName;
 }

+ 6 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyVoiceRoboticCallees.java

@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
+import com.fs.crm.domain.CrmCustomerProperty;
 import lombok.Data;
 
+import java.util.List;
+
 /**
  * 任务外呼电话对象 company_voice_robotic_callees
  *
@@ -71,4 +74,7 @@ public class CompanyVoiceRoboticCallees{
     /** 本任务下该 callee 的 AI 外呼呼出次数(非表字段,来自 call_log 统计) */
     @TableField(exist = false)
     private Integer roboticCallOutCount;
+
+    @TableField(exist = false)
+    private List<CrmCustomerProperty> tagList ;
 }

+ 8 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyWorkflow.java

@@ -1,6 +1,7 @@
 package com.fs.company.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
@@ -53,6 +54,13 @@ public class CompanyWorkflow extends BaseEntity {
     private String endNodeKey;
     private Long companyId;
 
+
+    @TableField(exist = false)
+    private String createByName;
+
+    @TableField(exist = false)
+    private String createByDeptName;
+
     public Boolean isStartNode(String nodeKey) {
         return nodeKey.equals(startNodeKey);
     }

+ 3 - 0
fs-service/src/main/java/com/fs/crm/mapper/CrmCustomerMapper.java

@@ -233,6 +233,9 @@ public interface CrmCustomerMapper extends BaseMapper<CrmCustomer> {
             "<if test = 'maps.customerName != null and  maps.customerName !=\"\"    '> " +
             "and c.customer_name like CONCAT('%',#{maps.customerName},'%') " +
             "</if>" +
+            "<if test = 'maps.customerUserId != null and maps.customerUserId !=\"\"     '> " +
+            "and c.receive_user_id =#{maps.customerUserId} " +
+            "</if>" +
             "<if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=\"\"    '> " +
             "and cu.nick_name like CONCAT(#{maps.companyUserNickName},'%') " +
             "</if>" +

+ 1 - 0
fs-service/src/main/java/com/fs/crm/mapper/CrmCustomerPropertyMapper.java

@@ -13,6 +13,7 @@ public interface CrmCustomerPropertyMapper extends BaseMapper<CrmCustomerPropert
     List<CrmCustomerProperty> selectCrmCustomerPropertyList(CrmCustomerProperty crmCustomerProperty);
 
     List<CrmCustomerProperty> selectCrmCustomerPropertyByCustomerId(Long customerId);
+    List<CrmCustomerProperty> selectCrmCustomerPropertyByCustomerIds(List<Long> customerIds);
 
     CrmCustomerProperty selectByCustomerIdAndPropertyId(@Param("customerId") Long customerId, @Param("propertyId") Long propertyId);
 

+ 3 - 2
fs-service/src/main/java/com/fs/crm/service/ICrmCustomerPropertyService.java

@@ -9,8 +9,8 @@ import java.util.Map;
 
 /**
  * 客户属性服务接口
- * @author 
- * @date 
+ * @author
+ * @date
  */
 public interface ICrmCustomerPropertyService extends IService<CrmCustomerProperty> {
 
@@ -62,6 +62,7 @@ public interface ICrmCustomerPropertyService extends IService<CrmCustomerPropert
      * @return 客户属性列表
      */
     List<CrmCustomerProperty> selectCrmCustomerPropertyByCustomerId(Long customerId);
+    List<CrmCustomerProperty> selectCrmCustomerPropertyByCustomerIds(List<Long> customerIds);
 
     /**
      * 添加客户属性

+ 9 - 3
fs-service/src/main/java/com/fs/crm/service/impl/CrmCustomerPropertyServiceImpl.java

@@ -23,9 +23,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -74,6 +72,14 @@ public class CrmCustomerPropertyServiceImpl extends ServiceImpl<CrmCustomerPrope
         return baseMapper.selectCrmCustomerPropertyByCustomerId(customerId);
     }
 
+    @Override
+    public List<CrmCustomerProperty> selectCrmCustomerPropertyByCustomerIds(List<Long> customerIds) {
+        if (customerIds == null || customerIds.isEmpty()) {
+            return new ArrayList<>();
+        }
+        return baseMapper.selectCrmCustomerPropertyByCustomerIds(customerIds);
+    }
+
     @Override
     public int addCustomerProperty(Long customerId, Long propertyId, String propertyName, String propertyValue, String propertyValueType, String tradeType, String createBy) {
         CrmCustomerProperty property = new CrmCustomerProperty();

+ 366 - 0
fs-service/src/main/resources/mapper/crm/CrmCustomerMapper.xml

@@ -717,5 +717,371 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     </select>
 
+    <select id="selectTransferCustomerList" resultType="com.fs.crm.vo.CrmLineCustomerListQueryVO">
+        select c.*,u.nick_name as company_user_nick_name,u2.nick_name as create_user_name
+        from  crm_customer c
+        left join company_user u on u.user_id=c.receive_user_id
+        left join company_user u2 on u2.user_id=c.create_user_id
+        where c.is_del = 0 and (u.status = 1 or u.del_flag = 2)
+        <if test="maps.isLine != null">
+            and c.is_line = #{maps.isLine}
+        </if>
+        <if test="maps.customerCode != null and  maps.customerCode !='' ">
+            and c.customer_code like CONCAT('%',#{maps.customerCode},'%')
+        </if>
+        <if test="maps.customerName != null and  maps.customerName !='' ">
+            and c.customer_name like CONCAT('%',#{maps.customerName},'%')
+        </if>
+        <if test="maps.customerCompanyName != null and  maps.customerCompanyName !='' ">
+            and c.customer_company_name like CONCAT('%',#{maps.customerCompanyName},'%')
+        </if>
+        <if test="maps.companyUserNickName != null and  maps.companyUserNickName !=''">
+            and u.nick_name like CONCAT('%',#{maps.companyUserNickName},'%')
+        </if>
+        <if test="maps.createUserName != null and  maps.createUserName !='' ">
+            and u2.nick_name like CONCAT('%',#{maps.createUserName},'%')
+        </if>
+        <if test="maps.mobile != null and  maps.mobile !='' ">
+            and c.mobile like CONCAT('%',#{maps.mobile},'%')
+        </if>
+        <if test="maps.receiveUserId == -1">
+            and c.receive_user_id is NULL
+        </if>
+        <if test="maps.receiveUserId == 0">
+            and c.receive_user_id is NOT NULL
+        </if>
+        <if test="maps.receiveUserId != null and maps.receiveUserId != 0 and maps.receiveUserId != -1">
+            and c.receive_user_id = #{maps.receiveUserId}
+        </if>
+        <if test="maps.status != null and maps.status !='' ">
+            and c.status =#{maps.status}
+        </if>
+        <if test="maps.isReceive != null ">
+            and c.is_receive =#{maps.isReceive}
+        </if>
+        <if test="maps.customerType != null ">
+            and c.customer_type =#{maps.customerType}
+        </if>
+        <if test="maps.companyId != null ">
+            and c.company_id =#{maps.companyId}
+        </if>
+        <if test="maps.source != null and maps.source !='' ">
+            and c.source =#{maps.source}
+        </if>
+        <if test="maps.tags != null ">
+            and
+            <foreach collection="maps.tags.split(',')" item="tag" open="(" close=")" separator="OR">
+                find_in_set(#{tag},c.tags)
+            </foreach>
+        </if>
+        <if test="maps.isPool != null ">
+            and c.is_pool = #{maps.isPool}
+        </if>
+        <if test="maps.createTime != null ">
+            and  DATE_FORMAT(c.create_time, '%Y-%m-%d')  = DATE_FORMAT(#{maps.createTime}, '%Y-%m-%d')
+        </if>
+        <if test="maps.beginTime != null and maps.beginTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d')
+        </if>
+        <if test="maps.endTime != null and maps.endTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')
+        </if>
+        <if test="maps.beginReceiveTime != null and maps.beginReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d') &gt;= date_format(#{maps.beginReceiveTime},'%y%m%d')
+        </if>
+        <if test="maps.endReceiveTime != null and maps.endReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d') &lt;= date_format(#{maps.endReceiveTime},'%y%m%d')
+        </if>
+
+
+        ${maps.params.dataScope}
+        <if test="maps.orderBy != null and maps.orderBy != ''">
+            order by c.next_time ${maps.orderBy} ,c.customer_id desc
+        </if>
+        <if test="maps.orderBy == null or maps.orderBy == ''">
+            order by c.customer_id desc
+        </if>
+    </select>
+
+    <select id="selectCrmCustomerListByUnPool" resultType="com.fs.crm.vo.CrmCustomerUnPoolListQueryVO">
+        WITH RankedCustomers AS (
+        select c.*,ROW_NUMBER() OVER (PARTITION BY c.customer_id ORDER BY c.create_time DESC) AS rn from (
+        <if test="param1 != null">
+            (SELECT
+            *,
+            '领取未跟进' AS pool_type,
+            (receive_time+ INTERVAL ${param1.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(MINUTE, NOW(), (receive_time + INTERVAL ${param1.limitDay} DAY)) AS `time`
+            from crm_customer n
+            WHERE n.is_del = 0
+            AND n.is_pool = 0
+            AND n.is_receive = 1
+            <if test="param2 != null">
+                AND n.visit_status IS NULL
+                AND n.receive_user_id IS NOT NULL
+                AND n.customer_id NOT IN (SELECT v.customer_id FROM `crm_customer_visit` v GROUP BY v.customer_id HAVING v.customer_id is NOT NULL)
+            </if>
+
+            )
+
+        </if>
+        <if test="param2 != null">
+            UNION(
+            SELECT *,
+            '未继续跟进' AS pool_type,
+            (GREATEST(
+            IFNULL(visit_time, '1000-01-01'),
+            IFNULL(sys_visit_time, '1000-01-01')
+            ) + INTERVAL ${param2.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(
+            MINUTE,
+            NOW(),
+            (GREATEST(
+            IFNULL(visit_time, '1000-01-01'),
+            IFNULL(sys_visit_time, '1000-01-01')
+            ) + INTERVAL ${param2.limitDay} DAY)
+            ) AS `time`
+            FROM crm_customer
+            WHERE is_del = 0
+            AND is_pool = 0
+            AND visit_status IS NOT NULL
+            AND visit_time IS NOT NULL
+            )
+        </if>
+        <if test="param3!=null">
+            UNION(SELECT c.*,
+            '未有商机' AS pool_type,
+            (c.create_time + INTERVAL ${param3.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(MINUTE, NOW(), (c.create_time + INTERVAL ${param3.limitDay} DAY)) AS `time`
+            FROM `crm_customer` c
+            WHERE c.is_del = 0
+            AND c.is_pool = 0
+            AND c.customer_id NOT IN (
+            SELECT b.customer_id FROM crm_business b WHERE b.create_time > (NOW()-INTERVAL ${param3.limitDay} DAY)
+            AND b.customer_id
+            IS NOT NULL GROUP BY b.customer_id)
+            )
+        </if>
+
+        ) as c
+        where c.is_del = 0 and c.is_pool_rule = 1
+        <if test="param.customerCode != null  and param.customerCode != ''"> and c.customer_code = #{param.customerCode}</if>
+        <if test="param.customerName != null  and param.customerName !=''"> and c.customer_name like concat('%', #{param.customerName}, '%')</if>
+        <if test="param.customerCompanyName != null  and param.customerCompanyName !=''"> and c.customer_company_name like concat('%', #{param.customerCompanyName}, '%')</if>
+        <if test="param.mobile != null  and param.mobile != ''"> and c.mobile= #{param.mobile}</if>
+        <if test="param.sex != null "> and c.sex =#{param.sex}</if>
+        <if test="param.weixin != null  and param.weixin != ''"> and c.weixin= #{param.weixin}</if>
+        <if test="param.createUserId != null "> and c.create_user_id = #{param.createUserId}</if>
+        <if test="param.receiveUserId != null "> and c.receive_user_id = #{param.receiveUserId}</if>
+        <if test="param.customerUserId != null "> and c.customer_user_id = #{param.customerUserId}</if>
+        <if test="param.deptId != null "> and c.dept_id = #{deptId}</if>
+        <if test="param.customerType != null "> and c.customer_type = #{param.customerType}</if>
+        <if test="param.companyId != null "> and c.company_id = #{param.companyId}</if>
+        <if test="param.source != null and param.source != ''"> and c.source = #{param.source}</if>
+        <if test="param.tags != null  and param.tags != ''"> and c.tags = #{param.tags}</if>
+        <if test="param.beginTime != null and param.beginTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &gt;= date_format(#{param.beginTime},'%y%m%d')
+        </if>
+        <if test="param.endTime != null and param.endTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &lt;= date_format(#{param.endTime},'%y%m%d')
+        </if>
+        <if test="param.beginReceiveTime != null and param.beginReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d%H%i%s') &gt;= date_format(#{param.beginReceiveTime},'%y%m%d%H%i%s')
+        </if>
+        <if test="param.endReceiveTime != null and param.endReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d%H%i%s') &lt;= date_format(#{param.endReceiveTime},'%y%m%d%H%i%s')
+        </if>
+        <if test="param.companyUserNickName != null and  param.companyUserNickName !='' ">
+            and cu.nick_name like CONCAT('%',#{param.companyUserNickName},'%')
+        </if>
+        )
+        SELECT r.*,cu.nick_name as company_user_nick_name
+        FROM RankedCustomers r
+        left join company_user cu on cu.user_id=r.receive_user_id
+        WHERE r.rn = 1
+        <if test="param.orderBy != null and param.orderBy != ''">
+            order by r.next_time ${param.orderBy} ,r.`time` asc
+        </if>
+        <if test="param.orderBy == null or param.orderBy == ''">
+            order by r.`time` asc
+        </if>
+        limit #{param.start}, #{param.pageSize};
+    </select>
+
+    <select id="countCrmCustomerListByUnPool" resultType="long">
+        WITH RankedCustomers AS (
+        select c.*,ROW_NUMBER() OVER (PARTITION BY c.customer_id ORDER BY c.create_time DESC) AS rn from (
+        <if test="param1 != null">
+            (SELECT *,
+            (receive_time+ INTERVAL ${param1.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(MINUTE, NOW(), (receive_time + INTERVAL ${param1.limitDay} DAY)) AS `time`
+            from crm_customer
+            WHERE is_del = 0
+            AND is_pool = 0
+            AND is_receive = 1
+            <if test="param2 != null">
+                AND visit_status IS NULL
+                AND receive_user_id IS NOT NULL
+                AND customer_id NOT IN (SELECT v.customer_id FROM `crm_customer_visit` v GROUP BY v.customer_id HAVING v.customer_id is NOT NULL)
+            </if>
+            )
+
+        </if>
+        <if test="param2 != null">
+            UNION(
+            SELECT *,
+            (GREATEST(
+            IFNULL(visit_time, '1000-01-01'),
+            IFNULL(sys_visit_time, '1000-01-01')
+            ) + INTERVAL ${param2.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(
+            MINUTE,
+            NOW(),
+            (GREATEST(
+            IFNULL(visit_time, '1000-01-01'),
+            IFNULL(sys_visit_time, '1000-01-01')
+            ) + INTERVAL ${param2.limitDay} DAY)
+            ) AS `time`
+            FROM crm_customer
+            WHERE is_del = 0
+            AND is_pool = 0
+            AND visit_status IS NOT NULL
+            AND visit_time IS NOT NULL
+            )
+        </if>
+        <if test="param3!=null">
+            UNION(SELECT c.*,
+            (c.create_time + INTERVAL ${param3.limitDay} DAY) AS pooling_time,
+            TIMESTAMPDIFF(MINUTE, NOW(), (c.create_time + INTERVAL ${param3.limitDay} DAY)) AS `time`
+            FROM `crm_customer` c
+            WHERE c.is_del = 0
+            AND c.is_pool = 0
+            AND c.customer_id NOT IN (
+            SELECT b.customer_id FROM crm_business b WHERE b.create_time > (NOW()-INTERVAL ${param3.limitDay} DAY)
+            AND b.customer_id
+            IS NOT NULL GROUP BY b.customer_id)
+            )
+        </if>
+        ) as c
+        where c.is_del = 0 and c.is_pool_rule = 1
+        <if test="param.customerCode != null  and param.customerCode != ''"> and c.customer_code = #{param.customerCode}</if>
+        <if test="param.customerName != null  and param.customerName !=''"> and c.customer_name like concat('%', #{param.customerName}, '%')</if>
+        <if test="param.customerCompanyName != null  and param.customerCompanyName !=''"> and c.customer_company_name like concat('%', #{param.customerCompanyName}, '%')</if>
+        <if test="param.mobile != null  and param.mobile != ''"> and c.mobile= #{param.mobile}</if>
+        <if test="param.sex != null "> and c.sex =#{param.sex}</if>
+        <if test="param.weixin != null  and param.weixin != ''"> and c.weixin= #{param.weixin}</if>
+        <if test="param.createUserId != null "> and c.create_user_id = #{param.createUserId}</if>
+        <if test="param.receiveUserId != null "> and c.receive_user_id = #{param.receiveUserId}</if>
+        <if test="param.customerUserId != null "> and c.customer_user_id = #{param.customerUserId}</if>
+        <if test="param.deptId != null "> and c.dept_id = #{deptId}</if>
+        <if test="param.customerType != null "> and c.customer_type = #{param.customerType}</if>
+        <if test="param.companyId != null "> and c.company_id = #{param.companyId}</if>
+        <if test="param.source != null and param.source != ''"> and c.source = #{param.source}</if>
+        <if test="param.tags != null  and param.tags != ''"> and c.tags = #{param.tags}</if>
+        <if test="param.beginTime != null and param.beginTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &gt;= date_format(#{param.beginTime},'%y%m%d')
+        </if>
+        <if test="param.endTime != null and param.endTime !='' ">
+            and date_format(c.create_time,'%y%m%d') &lt;= date_format(#{param.endTime},'%y%m%d')
+        </if>
+        <if test="param.beginReceiveTime != null and param.beginReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d%H%i%s') &gt;= date_format(#{param.beginReceiveTime},'%y%m%d%H%i%s')
+        </if>
+        <if test="param.endReceiveTime != null and param.endReceiveTime !='' ">
+            and date_format(c.receive_time,'%y%m%d%H%i%s') &lt;= date_format(#{param.endReceiveTime},'%y%m%d%H%i%s')
+        </if>
+        <if test="param.companyUserNickName != null and  param.companyUserNickName !='' ">
+            and cu.nick_name like CONCAT('%',#{param.companyUserNickName},'%')
+        </if>
+        )
+        SELECT count(1)
+        FROM RankedCustomers r
+        left join company_user cu on cu.user_id=r.receive_user_id
+        WHERE r.rn = 1
+
+        ;
+    </select>
+
+    <update id="recoverCrmLineCustomerList">
+        update crm_customer c set  c.is_pool = 1,c.pool_time = now()
+        <where>
+            <if test="maps.isLine != null">
+                and c.is_line = #{maps.isLine}
+            </if>
+            <if test="maps.customerCode != null and  maps.customerCode !='' ">
+                and c.customer_code like CONCAT('%',#{maps.customerCode},'%')
+            </if>
+            <if test="maps.customerName != null and  maps.customerName !='' ">
+                and c.customer_name like CONCAT('%',#{maps.customerName},'%')
+            </if>
+            <if test="maps.mobile != null and  maps.mobile !='' ">
+                and c.mobile like CONCAT('%',#{maps.mobile},'%')
+            </if>
+            <if test="maps.receiveUserId == -1">
+                and c.receive_user_id is NULL
+            </if>
+            <if test="maps.receiveUserId == 0">
+                and c.receive_user_id is NOT NULL
+            </if>
+            <if test="maps.receiveUserId != null and maps.receiveUserId != 0 and maps.receiveUserId != -1">
+                and c.receive_user_id = #{maps.receiveUserId}
+            </if>
+            <if test="maps.status != null and maps.status !='' ">
+                and c.status =#{maps.status}
+            </if>
+            <if test="maps.isReceive != null ">
+                and c.is_receive =#{maps.isReceive}
+            </if>
+            <if test="maps.customerType != null ">
+                and c.customer_type =#{maps.customerType}
+            </if>
+            <if test="maps.companyId != null ">
+                and c.company_id =#{maps.companyId}
+            </if>
+            <if test="maps.source != null and maps.source !='' ">
+                and c.source =#{maps.source}
+            </if>
+            <if test="maps.tags != null ">
+                and
+                <foreach collection="maps.tags.split(',')" item="tag" open="(" close=")" separator="OR">
+                    find_in_set(#{tag},c.tags)
+                </foreach>
+            </if>
+            <if test="maps.isPool != null ">
+                and c.is_pool = #{maps.isPool}
+            </if>
+            <if test="maps.createTime != null ">
+                and  DATE_FORMAT(c.create_time, '%Y-%m-%d')  = DATE_FORMAT(#{maps.createTime}, '%Y-%m-%d')
+            </if>
+            <if test="maps.beginTime != null and maps.beginTime !='' ">
+                and date_format(c.create_time,'%y%m%d') &gt;= date_format(#{maps.beginTime},'%y%m%d')
+            </if>
+            <if test="maps.endTime != null and maps.endTime !='' ">
+                and date_format(c.create_time,'%y%m%d') &lt;= date_format(#{maps.endTime},'%y%m%d')
+            </if>
+        </where>
+    </update>
+
+    <select id="selectCrmCustomerByCondition" resultType="com.fs.crm.domain.CrmCustomer">
+        <include refid="selectCrmCustomerVo"/>
+        where is_del = 0
+        <if test="(customerCompanyName != null and  customerCompanyName !='') and (mobile != null and  mobile !='')">
+            and(
+            <if test="customerCompanyName != null and  customerCompanyName !=''">
+                customer_company_name like #{customerCompanyName}
+            </if>
+            <if test="mobile != null and  mobile !=''">
+                or mobile like #{mobile}
+            </if>
+            )
+        </if>
+        <if test="(customerCompanyName != null and  customerCompanyName !='') and (mobile == null or  mobile =='')">
+            and customer_company_name like #{customerCompanyName}
+        </if>
+        <if test="(customerCompanyName == null or  customerCompanyName =='') and (mobile != null and  mobile !='')">
+            and mobile like #{mobile}
+        </if>
+
+    </select>
 
 </mapper>

+ 11 - 0
fs-service/src/main/resources/mapper/crm/CrmCustomerPropertyMapper.xml

@@ -137,6 +137,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         limit 1
     </select>
 
+    <select id="selectCrmCustomerPropertyByCustomerIds" resultMap="CrmCustomerPropertyResult">
+        <include refid="selectCrmCustomerPropertyVo"/>
+        where customer_id in
+        <foreach item="customerId" collection="list" open="(" separator="," close=")">
+            #{customerId}
+        </foreach>
+        and deleted = 0
+        order by customer_id desc, id desc
+    </select>
+
+
     <delete id="deleteByCustomerIdAndPropertyId">
         delete from crm_customer_property where customer_id = #{customerId} and property_id = #{propertyId}
     </delete>