浏览代码

移除冗余代码,与业务解耦

1811872455@163.com 1 天之前
父节点
当前提交
72416f3ed5

+ 1 - 1
storlead-api/pom.xml

@@ -32,7 +32,7 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <configuration>
-                    <mainClass>com.storlead.api.StorleadMailServiceApplication</mainClass>
+                    <mainClass>com.storlead.StorleadMailServiceApplication</mainClass>
                 </configuration>
             </plugin>
         </plugins>

+ 1 - 3
storlead-api/src/main/java/com/storlead/api/StorleadMailServiceApplication.java → storlead-api/src/main/java/com/storlead/StorleadMailServiceApplication.java

@@ -1,8 +1,6 @@
-package com.storlead.api;
-
+package com.storlead;
 import lombok.extern.slf4j.Slf4j;
 import org.mybatis.spring.annotation.MapperScan;
-import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;

+ 1 - 29
storlead-api/src/main/resources/application-dev.yml

@@ -65,6 +65,7 @@ spring:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
     dynamic:
+      primary: master
       druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
         # 连接池的配置信息
         # 初始化大小,最小,最大
@@ -99,35 +100,6 @@ spring:
           url: jdbc:mysql://mysql.test.storlead.com:39091/sp_sales_test?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
           username: root
           password: rCgRgLjH99Xvg5BN
-        management:
-          driver-class-name: com.mysql.jdbc.Driver
-          url: jdbc:mysql://mysql.test.storlead.com:39091/storlead_test?useSSL=false&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&noDatetimeStringSync=true&serverTimezone=Asia/Shanghai
-          username: root
-          password: rCgRgLjH99Xvg5BN
-        otr:
-          driver-class-name: com.mysql.jdbc.Driver
-          url: jdbc:mysql://mysql.test.storlead.com:39091/storlead_test?useSSL=false&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&noDatetimeStringSync=true&serverTimezone=Asia/Shanghai
-          username: root
-          password: rCgRgLjH99Xvg5BN
-        oa:
-          driver-class-name: com.mysql.jdbc.Driver
-          url: jdbc:mysql://139.159.206.64:65369/storlead_ecology_prod?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
-          username: storlead_ecology
-          password: 3raNoDvbo7jqbwtedQGQ
-#          url: jdbc:mysql://mysql.test.storlead.com:39091/sp_tems_test?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
-#          username: root
-#          password: rCgRgLjH99Xvg5BN
-#          driver-class-name: com.mysql.jdbc.Driver
-#        master:
-#          url: jdbc:mysql://139.159.206.64:65369/sp_tems_prod?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&rewriteBatchedStatements=true
-#          username: storlead_tems
-#          password: DW8YRN*5!6u&Ajswgjt
-#          driver-class-name: com.mysql.jdbc.Driver
-#        project:
-#          driver-class-name: com.mysql.jdbc.Driver
-#          url: jdbc:mysql://mysql.test.storlead.com:39091/sp_project_dev?useSSL=false&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&noDatetimeStringSync=true&serverTimezone=Asia/Shanghai
-#          username: root
-#          password: rCgRgLjH99Xvg5BN
 #mybatis plus 设置
 mybatis-plus:
   mapper-locations: classpath*:/mapper/*Mapper.xml,classpath*:/mapper/*/*Mapper.xml

+ 1 - 0
storlead-api/src/main/resources/application-prod.yml

@@ -67,6 +67,7 @@ spring:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
     dynamic:
+      primary: master
       druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
         # 连接池的配置信息
         # 初始化大小,最小,最大

+ 1 - 0
storlead-api/src/main/resources/application-test.yml

@@ -64,6 +64,7 @@ spring:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
     dynamic:
+      primary: master
       druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
         # 连接池的配置信息
         # 初始化大小,最小,最大

+ 2 - 2
storlead-api/src/main/resources/application.yml

@@ -67,10 +67,10 @@ storlead:
       - system_oss_config
       - sys_app
   datasource:
-    # 子模块默认数据源(未标注 @DS 时生效;标注 @DS 则以注解为准)
+    # 邮件服务默认走主库 master(未标注 @DS 时生效;标注 @DS 则以注解为准)
     module-default-enabled: true
     module-defaults:
       - packages:
           - com.storlead.sales.mail.service
           - com.storlead.sales.mail.mapper
-        datasource: sales
+        datasource: master

+ 0 - 50
storlead-framework/storlead-mybatis/src/main/java/com/storlead/framework/mybatis/entity/SysBaseField.java

@@ -64,56 +64,6 @@ public class SysBaseField implements Serializable {
     private Integer sort;
 
 
-    public static  <T>  void dictFileds(List<T> tList) {
-        if (CollectionUtils.isEmpty(tList)) {
-            return;
-        }
-//        for (T t : tList) {
-        try {
-            long be = System.currentTimeMillis();
-            log.debug("dictUtils---convertDict");
-            Object myClassInstance = SpringContextUtils.getBean("dictUtils");
-            Class<?> clazz = myClassInstance.getClass();
-            Method method = clazz.getMethod("convertDictls",List.class);
-            // 调用未编写的方法
-            method.invoke(myClassInstance,tList);
-            log.debug("-------------------耗时 ==: "+(System.currentTimeMillis() - be));
-        } catch (Exception e1) {
-            log.error("方法不存在",e1);
-        }
-//        }
-    }
-
-    public void dictFiled() {
-        dictFileds(Arrays.asList(this));
-    }
-
-    public static void dictFiled(Object t) {
-        dictFileds(Arrays.asList(t));
-    }
-
-    public static  <T> void orgFileds(Object... vars) {
-        orgFileds(Arrays.asList(vars));
-    }
-    public static  <T>  void orgFileds(List<T> tList) {
-        if (CollectionUtils.isEmpty(tList)) {
-            return;
-        }
-        try {
-            log.debug("dictUtils---convertDict");
-            Object myClassInstance = SpringContextUtils.getBean("orgAnnotateConvertUtils");
-            Class<?> clazz = myClassInstance.getClass();
-            Method method = clazz.getMethod("convertOrg",List.class);
-            // 调用未编写的方法
-            method.invoke(myClassInstance,tList);
-        } catch (Exception e1) {
-            log.error("方法不存在",e1);
-        }
-    }
-    @SneakyThrows
-    public void orgFiled() {
-        orgFileds(Arrays.asList(this));
-    }
 
     // Method to set empty strings to null
     public void setEmptyStringsToNull() {

+ 0 - 17
storlead-framework/storlead-mybatis/src/main/java/com/storlead/framework/mybatis/service/MyBaseService.java

@@ -42,31 +42,14 @@ public interface MyBaseService <T> extends IService<T> {
 
     Boolean lgDelete(Long id);
 
-    Boolean lgCustomerDelete(Long customerId);
-
-    Boolean lgCustomerListDelete(List<Long> customerIdList);
-
     Boolean lgDelete(List<Long> ids);
 
     List<T> listByIds(List<Long> ids);
 
-    Boolean changeCustomerId(Long fromId, Long customerId);
-
     T getNextById(Serializable currentId, LambdaQueryWrapper<T> queryWrapper);
 
     T getPreviousById(Serializable currentId, LambdaQueryWrapper<T> queryWrapper);
 
-//    T getOldEntityById(Class<T> clazz, Long id);
-
     Class<T> getEntityClass();
 
-    boolean changeResourceTypeId(String resourceType, Long fromId, Long id);
-
-    boolean deleteByResourceId(String resourceType, Long resourceTypeId);
-
-    boolean deleteByResourceIds(String resourceType, List<Long> resourceTypeIds);
-
-    List<T> listByResourceId(String resourceType, Long resourceTypeId);
-
-    List<T> listByResourceIds(String resourceType, List<Long> resourceTypeIds);
 }

+ 18 - 105
storlead-framework/storlead-mybatis/src/main/java/com/storlead/framework/mybatis/service/impl/MyBaseServiceImpl.java

@@ -131,30 +131,6 @@ public class MyBaseServiceImpl<M extends MyBaseMapper<T>, T extends SysBaseField
         return this.update(updateWrapper);
     }
 
-    @Override
-    public Boolean lgCustomerDelete(Long customerId) {
-        if (Objects.isNull(customerId)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("customer_id",customerId);
-        updateWrapper.set("is_delete",CommonConstant.DEL_FLAG_1);
-        updateWrapper.set("update_time", DateUtils.now());
-        return this.update(updateWrapper);
-    }
-
-    @Override
-    public Boolean lgCustomerListDelete(List<Long> customerIdList) {
-        if (CollectionUtils.isEmpty(customerIdList)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.in("customer_id",customerIdList);
-        updateWrapper.set("is_delete",CommonConstant.DEL_FLAG_1);
-        updateWrapper.set("update_time",DateUtils.now());
-        return this.update(updateWrapper);
-    }
-
     @Override
     public Boolean lgDelete(List<Long> ids) {
         if (CollectionUtils.isEmpty(ids)) {
@@ -176,77 +152,14 @@ public class MyBaseServiceImpl<M extends MyBaseMapper<T>, T extends SysBaseField
         return this.list(query);
     }
 
-    @Override
-    public Boolean changeCustomerId(Long fromId, Long customerId) {
-        if (Objects.isNull(customerId) || Objects.isNull(fromId)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("customer_id",fromId);
-        updateWrapper.set("customer_id",customerId);
-        return this.update(updateWrapper);
-    }
-
-    @Override
-    public boolean changeResourceTypeId(String resourceType, Long fromId, Long id) {
-        if (Objects.isNull(id) || Objects.isNull(fromId)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("resource_type",resourceType);
-        updateWrapper.eq("resource_type_id",fromId);
-        updateWrapper.set("resource_type_id",id);
-        return this.update(updateWrapper);
-    }
-
-    @Override
-    public boolean deleteByResourceId(String resourceType, Long resourceTypeId) {
-        if (Objects.isNull(resourceTypeId)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("resource_type",resourceType);
-        updateWrapper.eq("resource_type_id",resourceTypeId);
-        updateWrapper.set("is_delete",CommonConstant.DEL_FLAG_1);
-        return this.update(updateWrapper);
-    }
-
-    @Override
-    public boolean deleteByResourceIds(String resourceType, List<Long> resourceTypeIds) {
-        if (CollectionUtils.isEmpty(resourceTypeIds)) {
-            return false;
-        }
-        UpdateWrapper updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("resource_type",resourceType);
-        updateWrapper.in("resource_type_id",resourceTypeIds);
-        updateWrapper.set("is_delete",CommonConstant.DEL_FLAG_1);
-        return this.update(updateWrapper);
-    }
-
-    @Override
-    public List<T> listByResourceId(String resourceType, Long resourceTypeId) {
-        QueryWrapper wrapper = new QueryWrapper();
-        wrapper.eq("resource_type",resourceType);
-        wrapper.eq("resource_type_id",resourceTypeId);
-        return this.baseMapper.selectList(wrapper);
-    }
-
-    @Override
-    public List<T> listByResourceIds(String resourceType, List<Long> resourceTypeIds) {
-        QueryWrapper wrapper = new QueryWrapper();
-        wrapper.eq("resource_type",resourceType);
-        wrapper.in("resource_type_id",resourceTypeIds);
-        return this.baseMapper.selectList(wrapper);
-    }
-
     private <E extends QueryBaseEntity> void assemblyDataSource(LambdaQueryWrapper<T> wrapper,E e,String mergeSql) {
         try {
             log.error("进入assemblyDataSource---LambdaQueryWrapper");
-            Object myClassInstance = SpringContextUtils.getBean("dataScope");
-            Class<?> clazz = myClassInstance.getClass();
-            Method method = clazz.getMethod("assemblyDataWrapperPurview", LambdaQueryWrapper.class,QueryBaseEntity.class,String.class);
-            // 调用未编写的方法
-            method.invoke(myClassInstance,wrapper,e,mergeSql);
+//            Object myClassInstance = SpringContextUtils.getBean("dataScope");
+//            Class<?> clazz = myClassInstance.getClass();
+//            Method method = clazz.getMethod("assemblyDataWrapperPurview", LambdaQueryWrapper.class,QueryBaseEntity.class,String.class);
+//            // 调用未编写的方法
+//            method.invoke(myClassInstance,wrapper,e,mergeSql);
         } catch (Exception e1) {
             log.error("方法不存在",e1);
         }
@@ -255,11 +168,11 @@ public class MyBaseServiceImpl<M extends MyBaseMapper<T>, T extends SysBaseField
     private <E extends QueryBaseEntity> void assemblyDataOnlySource(LambdaQueryWrapper<T> wrapper,String mergeSql) {
         try {
             log.error("进入assemblyDataSource---LambdaQueryWrapper");
-            Object myClassInstance = SpringContextUtils.getBean("dataScope");
-            Class<?> clazz = myClassInstance.getClass();
-            Method method = clazz.getMethod("assemblyDataOnlyWrapper", LambdaQueryWrapper.class,String.class);
-            // 调用未编写的方法
-            method.invoke(myClassInstance,wrapper,mergeSql);
+//            Object myClassInstance = SpringContextUtils.getBean("dataScope");
+//            Class<?> clazz = myClassInstance.getClass();
+//            Method method = clazz.getMethod("assemblyDataOnlyWrapper", LambdaQueryWrapper.class,String.class);
+//            // 调用未编写的方法
+//            method.invoke(myClassInstance,wrapper,mergeSql);
         } catch (Exception e1) {
             log.error("方法不存在",e1);
         }
@@ -269,14 +182,14 @@ public class MyBaseServiceImpl<M extends MyBaseMapper<T>, T extends SysBaseField
         try {
             log.error("assemblyDataSource---QueryBaseEntity");
 
-            // 假设我们有一个类名为"MyClass"但没有编写该类的实例
-            Class<?> clazz = Class.forName("DataScope");
-            // 使用反射创建一个实例
-            Object myClassInstance = clazz.newInstance();
-            // 使用反射获取方法
-            Method method = clazz.getMethod("assemblyDataEntityPurview", QueryBaseEntity.class);
-            // 调用未编写的方法
-            method.invoke(myClassInstance, e);
+//            // 假设我们有一个类名为"MyClass"但没有编写该类的实例
+//            Class<?> clazz = Class.forName("DataScope");
+//            // 使用反射创建一个实例
+//            Object myClassInstance = clazz.newInstance();
+//            // 使用反射获取方法
+//            Method method = clazz.getMethod("assemblyDataEntityPurview", QueryBaseEntity.class);
+//            // 调用未编写的方法
+//            method.invoke(myClassInstance, e);
         } catch (Exception e1) {
             log.error("方法不存在",e1);
         }

+ 0 - 20
storlead-mail/src/main/java/com/storlead/sales/mail/controller/UserMailTrackRecordController.java

@@ -1,20 +0,0 @@
-package com.storlead.sales.mail.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- * 当前收取邮件的最新邮件记录 前端控制器
- * </p>
- *
- * @author chenkq
- * @since 2024-11-19
- */
-@RestController
-@RequestMapping("/user-mail-track-record-entity")
-public class UserMailTrackRecordController {
-
-}

+ 94 - 0
storlead-mail/src/main/java/com/storlead/sales/mail/dispatch/AutoSendDelayEmailTaskJob.java

@@ -0,0 +1,94 @@
+package com.storlead.sales.mail.dispatch;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.storlead.framework.common.constant.CommonConstant;
+import com.storlead.framework.common.util.encryptor.AccessKeyEncryptor;
+import com.storlead.sales.mail.entity.EmailsEntity;
+import com.storlead.sales.mail.entity.SmtpPopSettingsEntity;
+import com.storlead.sales.mail.enums.EmailBoxEnum;
+import com.storlead.sales.mail.service.EmailsService;
+import com.storlead.sales.mail.service.SmtpPopSettingsService;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @program: sp-sales-platform
+ * @description:
+ * @author: chenkq
+ * @create: 2024-11-01 15:27
+ */
+@Slf4j
+@Component
+@NoArgsConstructor
+@DisallowConcurrentExecution
+public class AutoSendDelayEmailTaskJob implements Job {
+    @Resource
+    private EmailsService emailsService;
+
+    @Resource
+    private Environment environment;
+
+    @Resource
+    private SmtpPopSettingsService smtpPopSettingsService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        String active = environment.getProperty("spring.profiles.active");
+        if("dev".equals(active)) {
+            return ;
+        }
+        log.info("定时发送邮件任务开始");
+        LambdaQueryWrapper<EmailsEntity> wrapper = new LambdaQueryWrapper<>();
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime triggerTime = now;
+        wrapper.select(EmailsEntity::getId,EmailsEntity::getSmtpPopId,EmailsEntity::getOwnerBy);
+        wrapper.le(EmailsEntity::getDelaySendTime,triggerTime);
+        wrapper.eq(EmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
+        wrapper.eq(EmailsEntity::getStatus,-1);
+        wrapper.eq(EmailsEntity::getFolder, EmailBoxEnum.SENTING.code);
+        wrapper.isNotNull(EmailsEntity::getDelaySendTime);
+        List<EmailsEntity> emailsls = emailsService.list(wrapper);
+        if (CollectionUtils.isEmpty(emailsls)) {
+            return;
+        }
+        LambdaUpdateWrapper<EmailsEntity> upEntity = new LambdaUpdateWrapper<>();
+        upEntity.set(EmailsEntity::getStatus,0);
+        upEntity.in(EmailsEntity::getId,emailsls.stream().map(EmailsEntity::getId).collect(Collectors.toList()));
+        emailsService.update(upEntity);
+
+        List<SmtpPopSettingsEntity> smtpPopls = smtpPopSettingsService.listByIds(emailsls.stream().map(EmailsEntity::getSmtpPopId).collect(Collectors.toList()));
+        if (CollectionUtils.isEmpty(smtpPopls)) {
+            return;
+        }
+        Map<Long,SmtpPopSettingsEntity> smtpPopMap = smtpPopls.stream().collect(Collectors.toMap(SmtpPopSettingsEntity::getId, a ->a));
+        log.info("定时发送邮件任务,共{}条",emailsls.size());
+        for (EmailsEntity emailVal : emailsls) {
+            EmailsEntity email = emailsService.getById(emailVal.getId());
+            SmtpPopSettingsEntity smtpPop = smtpPopMap.get(email.getSmtpPopId());
+            AccessKeyEncryptor accessKeyEncryptor = AccessKeyEncryptor.getAccessKeyEncryptor("");
+            String pass = accessKeyEncryptor.decrypt(smtpPop.getEmailPassword());
+            smtpPop.setEmailPassword(pass);
+            emailsService.sendEmail(email,smtpPop);
+        }
+    }
+
+    public static void main(String[] args) {
+        String env = System.getProperty("app.env");
+
+        log.error("env ="+env);
+    }
+}

+ 136 - 0
storlead-mail/src/main/java/com/storlead/sales/mail/dispatch/DelayDeleteServerEmailTaskJob.java

@@ -0,0 +1,136 @@
+package com.storlead.sales.mail.dispatch;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.storlead.framework.common.util.encryptor.AccessKeyEncryptor;
+import com.storlead.sales.mail.connection.config.MailProperties;
+import com.storlead.sales.mail.entity.EmailsEntity;
+import com.storlead.sales.mail.entity.SmtpPopSettingsEntity;
+import com.storlead.sales.mail.service.EmailsService;
+import com.storlead.sales.mail.service.SmtpPopSettingsService;
+import com.sun.mail.imap.IMAPFolder;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import javax.mail.*;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @program: sp-sales-platform
+ * @description:
+ * @author: chenkq
+ * @create: 2025-03-12 09:47
+ */
+@Slf4j
+@Component
+@NoArgsConstructor
+@DisallowConcurrentExecution
+public class DelayDeleteServerEmailTaskJob implements Job {
+
+    @Resource
+    private SmtpPopSettingsService smtpPopSettingsService;
+
+    @Resource
+    private EmailsService emailsService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        List<EmailsEntity> taskEntities =  emailsService.getDelayDeleteMail();
+        if (CollectionUtil.isNotEmpty(taskEntities)) {
+            Map<Long,List<EmailsEntity>> attachmentsMap = taskEntities.stream().collect(Collectors.groupingBy(EmailsEntity::getSmtpPopId));
+            for (Map.Entry<Long, List<EmailsEntity>> entry : attachmentsMap.entrySet()) {
+                SmtpPopSettingsEntity smtpPop = smtpPopSettingsService.getById(entry.getKey());
+                if (Objects.nonNull(smtpPop) && Integer.valueOf(0).equals(smtpPop.getIsDeleteMail())) {
+                    continue;
+                }
+                List<EmailsEntity>  entryls = entry.getValue();
+                if (!CollectionUtils.isEmpty(entryls)) {
+                    AccessKeyEncryptor accessKeyEncryptor = AccessKeyEncryptor.getAccessKeyEncryptor("");
+                    String pass = accessKeyEncryptor.decrypt(smtpPop.getEmailPassword());
+                    smtpPop.setEmailPassword(pass);
+                    MailProperties properties1 = new MailProperties(smtpPop);
+                    Properties properties = new Properties();
+                    properties.put("mail.imap.host", properties1.getHost());
+                    properties.put("mail.imap.port", properties1.getPort());
+                    properties.put("mail.imap.starttls.enable", "true");
+                    properties.put("mail.imap.ssl.trust", "*");
+                    properties.put("mail.imap.ssl.enable", "true");
+
+                    Authenticator auth = new Authenticator() {
+                        protected PasswordAuthentication getPasswordAuthentication() {
+                            return new PasswordAuthentication(properties1.getEmailAddress(), properties1.getEmailPassword());
+                        }
+                    };
+                    Session session = Session.getInstance(properties,auth);
+                    List<EmailsEntity> inEntryls = entryls.stream().filter(e ->e.getFolder().equals("INBOX")).collect(Collectors.toList());
+                    if (!CollectionUtils.isEmpty(inEntryls)) {
+                        expungeMailData(inEntryls,properties1,session,"INBOX");
+                    }
+                    List<EmailsEntity> outEntryls = entryls.stream().filter(e ->e.getFolder().equals("SENT")).collect(Collectors.toList());
+                    if (!CollectionUtils.isEmpty(outEntryls)) {
+                        expungeMailData(outEntryls,properties1,session,"SENT");
+                    }
+                }
+            }
+        }
+    }
+
+    public void expungeMailData(List<EmailsEntity> entryls,MailProperties properties1,Session session,String folder) {
+        try {
+            // 连接 IMAP 服务器
+            Store store = session.getStore(properties1.getProtocol().toLowerCase());
+            store.connect(properties1.getEmailAddress(), properties1.getEmailPassword());
+            // 打开 INBOX 目录(可写模式)
+            if ("SENT".equals(folder)) {
+                folder = "Sent Items";
+            }
+            IMAPFolder inbox = (IMAPFolder)store.getFolder(folder);
+            inbox.open(Folder.READ_WRITE);
+            int totalDeleted = 0;
+            List<Long> deleteIds = new ArrayList<>();
+            List<Long> nullIds = new ArrayList<>();
+            // 遍历 Message-ID 进行搜索并彻底删除
+            for (EmailsEntity entity : entryls) {
+                Message message = inbox.getMessageByUID(Long.parseLong(entity.getMsgUid()));
+                if (Objects.nonNull(message)) {
+                    message.setFlag(Flags.Flag.DELETED, true);
+                    totalDeleted++;
+                    log.error(" - 彻底删除邮件: " + message.getSubject());
+                    deleteIds.add(entity.getId());
+                } else {
+                    nullIds.add(entity.getId());
+                }
+            }
+            if (!CollectionUtils.isEmpty(nullIds)) {
+                LambdaUpdateWrapper<EmailsEntity> nullUp = new LambdaUpdateWrapper<>();
+                nullUp.set(EmailsEntity::getDeleteTag,2);
+                nullUp.in(EmailsEntity::getId,nullIds);
+                emailsService.update(nullUp);
+            }
+            // 确保邮件彻底删除
+            if (totalDeleted > 0) {
+                inbox.expunge();
+                if (!CollectionUtils.isEmpty(nullIds)) {
+                    LambdaUpdateWrapper<EmailsEntity> deleteUp = new LambdaUpdateWrapper<>();
+                    deleteUp.set(EmailsEntity::getDeleteTag,1);
+                    deleteUp.in(EmailsEntity::getId,deleteIds);
+                    emailsService.update(deleteUp);
+                }
+                log.error("已彻底删除 " + totalDeleted + " 封邮件!");
+            }
+            // 关闭连接
+            inbox.close(true);
+            store.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 52 - 0
storlead-mail/src/main/java/com/storlead/sales/mail/dispatch/EmailPullHeadContentTaskJob.java

@@ -0,0 +1,52 @@
+package com.storlead.sales.mail.dispatch;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.storlead.sales.mail.entity.SmtpPopSettingsEntity;
+import com.storlead.sales.mail.service.*;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.DisallowConcurrentExecution;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @program: sp-sales-platform
+ * @description:
+ * @author: chenkq
+ * @create: 2024-08-27 17:52
+ */
+@Slf4j
+@Component
+@NoArgsConstructor
+@DisallowConcurrentExecution
+public class EmailPullHeadContentTaskJob implements Job {
+
+    @Resource
+    private SmtpPopSettingsService smtpPopSettingsService;
+
+    @Resource
+    private EmailsService emailsService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+
+        LambdaQueryWrapper<SmtpPopSettingsEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(SmtpPopSettingsEntity::getIsDelete,0);
+//      lambdaQueryWrapper.eq(SmtpPopSettingsEntity::getUseDefault,Integer.valueOf(1));
+        lambdaQueryWrapper.eq(SmtpPopSettingsEntity::getEnabled,1);
+        lambdaQueryWrapper.ne(SmtpPopSettingsEntity::getEmailAddress,"system@storlead.com");
+        List<SmtpPopSettingsEntity> settingsEntities = smtpPopSettingsService.list(lambdaQueryWrapper);
+        if (CollectionUtils.isEmpty(settingsEntities)) {
+            return;
+        }
+        for (SmtpPopSettingsEntity smtpPop : settingsEntities) {
+             emailsService.receiveEmails(smtpPop,true);
+        }
+    }
+}

+ 0 - 65
storlead-mail/src/main/java/com/storlead/sales/mail/mapper/EmailsMapper.java

@@ -27,30 +27,6 @@ import java.util.Set;
  */
 public interface EmailsMapper extends MyBaseMapper<EmailsEntity> {
 
-    void updateCleanBindCustomerMail();
-
-    void updateBindCustomerMail();
-
-    void updateBindLiaisonMail();
-
-    /**
-     * 绑定客户邮件关系
-     * @param mailId
-     * @param mailAddress
-     * @param userId
-     */
-    Set<Long> getMailCustomerIdByMailIdAndUserId(@Param("mailId") Long mailId, @Param("mailAddress") String mailAddress, @Param("userId") Long userId);
-
-    /**
-     * 绑定联系人邮箱和客户关系
-     * @param mailId
-     * @param mailAddress
-     * @param userId
-     */
-    List<MailLiaisonVO> getLiaisonMailCustomerIdByMailIdAndUserId(@Param("mailId") Long mailId, @Param("mailAddress") String mailAddress, @Param("userId") Long userId);
-
-    void bindMailCustomerIdByMailId(@Param("mailId") Long mailId,@Param("customerIds") String customerId,@Param("liaisonIds") String liaisonIds);
-
     EmailsEntity getEmailsByMessageId(@Param("messageId") String messageId,@Param("folder") String folder,@Param("smtpPopId") Long smtpPopId);
 
     List<String> getEmailMessageIdsByMessageIds(@Param("messageIds") List<String> messageIds,@Param("folder") String folder,@Param("smtpPopId") Long smtpPopId);
@@ -61,50 +37,9 @@ public interface EmailsMapper extends MyBaseMapper<EmailsEntity> {
 
     IPage<EmailsEntity> pageList(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);
 
-
-    IPage<EmailsEntity> pageListCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);
-
-    IPage<EmailsEntity> pageListAllCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);
-
-    IPage<EmailsEntity> pageListNew(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);
-
-    IPage<EmailsEntity> pageListNewAllCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);
-
-    /**
-     * 汇总邮件数量
-     * @param stmpPopIdk
-     * @param ownerBy
-     * @return
-     */
-    NewMailCountTipVO countMailSummaryNum(Long smtpPopId, Long ownerBy);
-
-    /**
-     * 汇总未跟进数
-     * @param stmpPopId
-     * @param ownerBy
-     * @return
-     */
-    NewMailCountTipVO countCustomerAndClueNumber(Long smtpPopId, Long ownerBy);
-
-    /**
-     * 汇总客户邮件数
-     * @param stmpPopId
-     * @param ownerBy
-     * @return
-     */
-    NewMailCountTipVO countCustomerFollowUpMailNum(Long smtpPopId, Long ownerBy);
-
-    LocalDateTime selectCustomerLastFollowUpTime(Long customerId);
-
     List<EmailsEntity> selectDelayDeleteMail();
 
     List<UserClickTitleVO> selectUserClickTitle(@Param("ownerBy") Long ownerBy,@Param("title") String title);
 
-    IPage<CustomerEmailVo> selectCustomerEmailPage(Page<CustomerEmailVo> page,@Param("query") MailListDTO dto);
-
-    List<Long> selectCusIdByMailId(@Param("mailIdls") List<Long> mailIdls);
-
-    List<CustomerMailVO> selectCusInfoByCusId(@Param("customerIdls") List<Long> customerIdls);
-
     Integer countSmtpMailCount(@Param("userId") Long userId);
 }

+ 2 - 43
storlead-mail/src/main/java/com/storlead/sales/mail/service/impl/EmailsServiceImpl.java

@@ -575,23 +575,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
                 if (!CollectionUtils.isEmpty(ids)) {
                     mesageIds.addAll(ids);
                 }
-                List<String> messageIds = new ArrayList<>();
-//                if (!CollectionUtils.isEmpty(messagels)) {
-//                    List<String> varIdls = new ArrayList<>();
-//                    for (Message message : messagels) {
-//                        String [] varIds = message.getHeader("Message-ID");
-//                        if (Objects.isNull(varIds)) {
-//                            continue;
-//                        }
-//                        varIdls.add(varIds[0]);
-//                    }
-//                    if (!CollectionUtils.isEmpty(varIdls)) {
-//                        messageIds = this.getEmailMessageIdsByMessageId(varIdls,boxEnum.code, smtpPop.getId());
-//                        if (Objects.isNull(messageIds)) {
-//                            messageIds = new ArrayList<>();
-//                        }
-//                    }
-//                }
+
                 List<EmailsEntity> entities = new ArrayList<>();
                 for (Message message : messagels) {
                     String[] varIds = message.getHeader("Message-ID");
@@ -715,7 +699,7 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
             Set<Long> toUserIds = new HashSet<>();
             toUserIds.add(userId);
 
-           Object myClassInstance = SpringContextUtils.getBean("messageService");
+            Object myClassInstance = SpringContextUtils.getBean("messageService");
             Class<?> clazz = myClassInstance.getClass();
 
 //            Class<?> clazz = Class.forName("com.storlead.message.service.impl.MessageService");
@@ -820,37 +804,12 @@ public class EmailsServiceImpl extends MyBaseServiceImpl<EmailsMapper, EmailsEnt
             log.error("autoReplyMail errpr ",e);
         }
     }
-    @Override
-    public NewMailCountTipVO countMailSummaryNum(Long smtpPopId, Long ownerBy) {
-        return this.baseMapper.countMailSummaryNum(smtpPopId,ownerBy);
-    }
-
-    @Override
-    public NewMailCountTipVO countCustomerAndClueNumber(Long smtpPopId, Long ownerBy) {
-        return this.baseMapper.countCustomerAndClueNumber(smtpPopId,ownerBy);
-    }
-
-    @Override
-    public NewMailCountTipVO countCustomerFollowUpMailNum(Long smtpPopId, Long ownerBy) {
-        return this.baseMapper.countCustomerFollowUpMailNum(smtpPopId,ownerBy);
-    }
-
-    @Override
-    public LocalDateTime getCustomerLastFollowUpTime(Long customerId) {
-        return this.baseMapper.selectCustomerLastFollowUpTime(customerId);
-    }
 
     @Override
     public List<EmailsEntity> getDelayDeleteMail() {
         return this.baseMapper.selectDelayDeleteMail();
     }
 
-    @Override
-    public IPage<CustomerEmailVo> selectCustomerEmailPage(Page<CustomerEmailVo> page, MailListDTO dto) {
-        return this.baseMapper.selectCustomerEmailPage(page,dto);
-    }
-
-
     @Override
     public void receiveBodyContentEmails(SmtpPopSettingsEntity smtpPop,List<EmailsEntity> emailsls,EmailBoxEnum boxEnum) {
         receiveBodyContent(smtpPop,emailsls,boxEnum);

+ 0 - 615
storlead-mail/src/main/resources/mapper/EmailsMapper.xml

@@ -49,39 +49,6 @@
             id, smtp_pop_id, msg_uid,source_type,message_id,follow_up_id,follow_up_time,is_receipt,is_only_head,is_track,delete_tag,read_remind,delay_send_time,customer_ids,liaison_ids, is_star,is_trash,subject,`from`, from_name, recipient, recipient_name, recipient_cc, recipient_cc_name, recipient_bcc, recipient_bcc_name, folder,custom_folder_id, content,remark, sent_date, recipient_date, email_size, is_read, reply_msg_id, status, owner_by, create_time, update_time, is_delete, enabled, create_by, update_by, sort
         </sql>
 
-    <select id="updateCleanBindCustomerMail">
---         UPDATE emails e
---         SET e.customer_id = NULL;
-    </select>
-    <select id="updateBindCustomerMail">
-        UPDATE emails e
-            LEFT JOIN customer_company c ON e.from = c.email
-            SET e.customer_id = c.customer_id
-        WHERE c.customer_id IS NOT NULL AND e.customer_id is null and c.is_delete = 0;
-    </select>
-
-    <select id="updateBindLiaisonMail">
-        UPDATE emails e
-            LEFT JOIN liaison l ON e.from = l.email
-            SET e.customer_id = l.customer_id, e.liaison_id = l.id
-        WHERE l.customer_id IS NOT NULL AND (e.customer_id is null or e.liaison_id is null)  and l.is_delete = 0;
-    </select>
-
-    <select id="getMailCustomerIdByMailIdAndUserId" resultType="java.lang.Long">
-        SELECT customer_id FROM customer_company WHERE email is not null AND email != '' AND FIND_IN_SET(LOWER(email),#{mailAddress}) and is_delete = 0
-    </select>
-
-    <select id="getLiaisonMailCustomerIdByMailIdAndUserId" resultType="com.storlead.sales.mail.pojo.vo.MailLiaisonVO">
-       SELECT id as liaisonId,customer_id as customerId FROM liaison WHERE  email is not null AND email != '' AND FIND_IN_SET(LOWER(email),#{mailAddress})  and is_delete = 0
-    </select>
-
-    <select id="bindMailCustomerIdByMailId">
-        update emails
-        set customer_ids= #{customerIds}
-        , liaison_ids = #{liaisonIds}
-        where id =  #{mailId}
-    </select>
-
     <select id="getEmailsIdByMessageId" resultType="java.lang.Long">
         select id from emails where message_id = #{messageId} and smtp_pop_id = #{smtpPopId} limit 1
     </select>
@@ -115,23 +82,6 @@
         e.sent_date, e.recipient_date, e.email_size, e.is_read, e.reply_msg_id, e.status, e.owner_by, e.create_time, e.update_time,
         e.is_delete, e.enabled, e.create_by, e.update_by, e.sort from  emails as e
         <where>
-            <if test="(dto.customerName != null and dto.customerName != '') or dto.customerId != null">
-                AND EXISTS (select 1 from customer as c
-                <where>
-                    <if test="dto.customerName != null and dto.customerName != ''">
-                        AND c.customer_name like concat('%',#{dto.customerName},'%')
-                    </if>
-                    <if test="dto.customerId != null">
-                        and c.id = #{dto.customerId}
-                    </if>
-                    <if test="dto.customerType == null">
-                        <if test="dto.bindCustomer != null and dto.bindCustomer == 1">
-                            and c.owner_by = #{dto.ownerBy}
-                        </if>
-                    </if>
-                    and FIND_IN_SET(c.id,e.customer_ids) > 0 )
-                </where>
-            </if>
             <if test="dto.smtpPopId != null">
                 and e.smtp_pop_id = #{dto.smtpPopId}
             </if>
@@ -156,22 +106,6 @@
             <if test="dto.readStatu != null">
                 and is_read = #{dto.readStatu}
             </if>
-            <if test="dto.followUpState != null">
-                <if test="dto.followUpState == 0">
-                    and e.follow_up_id is null
-                </if>
-                <if test="dto.followUpState == 1">
-                    and e.follow_up_id is not null
-                </if>
-            </if>
-            <if test="dto.customerType == null">
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 0">
-                    and (e.customer_ids = '' or e.customer_ids is null)
-                </if>
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 1">
-                    and e.customer_ids is not null
-                </if>
-            </if>
             <if test="dto.blurry != null and dto.blurry != ''">
                 and (subject like concat('%',#{dto.blurry},'%') or content like concat('%',#{dto.blurry},'%') or `from` like concat('%',#{dto.blurry},'%') or recipient like concat('%',#{dto.blurry},'%'))
             </if>
@@ -181,510 +115,6 @@
     </select>
 
 
-    <select id="pageListCus"  resultMap="BaseResultMap">
-        select e.id, e.smtp_pop_id, e.msg_uid,e.message_id,e.is_receipt,e.is_only_head,e.is_track,e.read_remind,
-        e.delay_send_time,e.customer_ids,e.liaison_ids, e.is_star,e.is_trash,e.subject,e.from, e.from_name, e.recipient,
-        e.recipient_name, e.recipient_cc, e.recipient_cc_name,e. recipient_bcc, e.recipient_bcc_name, e.folder,e.remark,
-        e.sent_date, e.recipient_date, e.email_size, e.is_read, e.reply_msg_id, e.status, e.owner_by, e.create_time, e.update_time,
-        e.is_delete, e.enabled, e.create_by, e.update_by, e.sort,c.id as customer_id from  emails as e
-        left join customer as c
-        on FIND_IN_SET(c.id,e.customer_ids)
-        <where>
-            <if test="dto.ownerBy != null">
-                and e.owner_by = #{dto.ownerBy}
-            </if>
-            <if test="dto.smtpPopId != null">
-                and e.smtp_pop_id = #{dto.smtpPopId}
-            </if>
-            <if test="dto.customerId != null">
-                and c.id = #{dto.customerId}
-            </if>
-            <if test="dto.customerId == null">
-                and e.source_type = 0
-            </if>
-            <if test="dto.folder != null and dto.folder != ''">
-                and e.folder = #{dto.folder}
-            </if>
-            <if test="dto.isStar != null and dto.isStar == 1">
-                and e.is_star = #{dto.isStar}
-            </if>
-            <if test="dto.systemMail != null and dto.systemMail == 1">
-                and e.from = 'system@storlead.com'
-            </if>
-            <if test="dto.systemMail == null">
-                and (e.from is null or e.from <![CDATA[<>]]> 'system@storlead.com')
-            </if>
-            <if test="dto.isTrash != null">
-                and is_trash = #{dto.isTrash}
-            </if>
-            <if test="dto.readStatu != null">
-                and is_read = #{dto.readStatu}
-            </if>
-            <if test="dto.emailAddress != null and dto.emailAddress != ''">
-                and (e.from like concat('%',#{dto.emailAddress},'%') or e.recipient like concat('%',#{dto.emailAddress},'%') or e.recipient_cc like concat('%',#{dto.emailAddress},'%'))
-            </if>
-            <if test="dto.customerName != null and dto.customerName != ''">
-                and c.customer_name like concat('%',#{dto.customerName},'%')
-            </if>
-            <if test="dto.folder != null and dto.folder != ''">
-                and e.folder = #{dto.folder}
-            </if>
-            <if test="dto.followUpState != null">
-                <if test="dto.followUpState == 0">
-                    and e.follow_up_id is null
-                </if>
-                <if test="dto.followUpState == 1">
-                    and c.owner_by = #{dto.ownerBy}
-                    and e.follow_up_id is not null
-                    and c.is_delete  = 0
-                </if>
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 0">
-                    and c.id is null
-                </if>
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 1">
-                    and c.id is not null
-                    and c.owner_by = #{dto.ownerBy}
-                    and c.is_delete  = 0
-                </if>
-            </if>
-            <if test="dto.customerType != null">
-                and c.id is not null
-                and c.owner_by = #{dto.ownerBy}
-                and c.customer_form = #{dto.customerType}
-                <if test="dto.customerLevelDictValue != null and dto.customerLevelDictValue != ''">
-                    and c.customer_level_dict_value = #{dto.customerLevelDictValue}
-                </if>
-
-                <if test="dto.customerSourceDictValue != null and dto.customerSourceDictValue != ''">
-                    and c.customer_source_dict_value = #{dto.customerSourceDictValue}
-                </if>
-
-                <if test="dto.customerTypeDictValue != null and dto.customerTypeDictValue != ''">
-                    and c.customer_type_dict_value = #{dto.customerTypeDictValue}
-                </if>
-                <if test="dto.clueStatusDictValue != null and dto.clueStatusDictValue != ''">
-                    and c.clue_status_dict_value = #{dto.clueStatusDictValue}
-                </if>
-                <if test="dto.continent != null and dto.continent != '' and dto.country != null and dto.country != ''">
-                    and c.continent = #{dto.continent} and c.country = #{dto.country}
-                </if>
-                and c.is_delete = 0
-            </if>
-            <if test="dto.blurry != null and dto.blurry != ''">
-                and (subject like concat('%',#{dto.blurry},'%') or content like concat('%',#{dto.blurry},'%') or `from` like concat('%',#{dto.blurry},'%') or recipient like concat('%',#{dto.blurry},'%'))
-            </if>
-            and e.is_delete = 0
-            <if test="dto.customerType != null">
-                AND e.id IN (
-                    SELECT MAX(e1.id) FROM emails e1
-                    LEFT JOIN customer c1 ON FIND_IN_SET(c1.id, e1.customer_ids)
-                    where e1.is_delete = 0 and c1.is_delete = 0
-                    <if test="dto.ownerBy != null">
-                        and e1.owner_by =  #{dto.ownerBy}
-                    </if>
-                    <if test="dto.folder != null and dto.folder != ''">
-                        and e1.folder = #{dto.folder}
-                    </if>
-                    <if test="dto.isTrash != null">
-                        and e1.is_trash = #{dto.isTrash}
-                    </if>
-                    <if test="dto.smtpPopId != null">
-                        and e1.smtp_pop_id = #{dto.smtpPopId}
-                    </if>
-                    <if test="dto.customerType != null">
-                        and c.customer_form = #{dto.customerType}
-                    </if>
-                    GROUP BY c1.id
-                )
-            </if>
-        </where>
-        order by e.recipient_date desc
-    </select>
-
-
-    <select id="pageListAllCus"  resultMap="BaseResultMap">
-        WITH ranked_emails AS (
-        select e.id, e.smtp_pop_id, e.msg_uid,e.message_id,e.is_receipt,e.is_only_head,e.is_track,e.read_remind,
-        e.delay_send_time,e.customer_ids,e.liaison_ids, e.is_star,e.is_trash,e.subject,e.from, e.from_name, e.recipient,
-        e.recipient_name, e.recipient_cc, e.recipient_cc_name,e. recipient_bcc, e.recipient_bcc_name, e.folder,e.remark,
-        e.sent_date, e.recipient_date, e.email_size, e.is_read, e.reply_msg_id, e.status, e.owner_by, e.create_time,
-        e.update_time,
-        e.is_delete, e.enabled, e.create_by, e.update_by, e.sort,c.id as customer_id
-        ,ROW_NUMBER() OVER (PARTITION BY c.id ORDER BY e.id DESC) AS rn
-        from emails as e
-        left join customer as c
-        on FIND_IN_SET(c.id,e.customer_ids)
-        <where>
-            <if test="dto.ownerBy != null">
-                and e.owner_by = #{dto.ownerBy}
-            </if>
-            <if test="dto.smtpPopId != null">
-                and e.smtp_pop_id = #{dto.smtpPopId}
-            </if>
-            <if test="dto.customerId != null">
-                and c.id = #{dto.customerId}
-            </if>
-            <if test="dto.folder != null and dto.folder != ''">
-                and e.folder = #{dto.folder}
-            </if>
-            <if test="dto.isStar != null and dto.isStar == 1">
-                and e.is_star = #{dto.isStar}
-            </if>
-            <if test="dto.systemMail != null and dto.systemMail == 1">
-                and e.from = 'system@storlead.com'
-            </if>
-            <if test="dto.systemMail == null">
-                and (e.from is null or e.from <![CDATA[<>]]> 'system@storlead.com')
-            </if>
-            <if test="dto.isTrash != null">
-                and is_trash = #{dto.isTrash}
-            </if>
-            <if test="dto.readStatu != null">
-                and is_read = #{dto.readStatu}
-            </if>
-            <if test="dto.emailAddress != null and dto.emailAddress != ''">
-                and (e.from like concat('%',#{dto.emailAddress},'%') or e.recipient like
-                concat('%',#{dto.emailAddress},'%') or e.recipient_cc like concat('%',#{dto.emailAddress},'%'))
-            </if>
-            <if test="dto.customerName != null and dto.customerName != ''">
-                and c.customer_name like concat('%',#{dto.customerName},'%')
-            </if>
-            <if test="dto.folder != null and dto.folder != ''">
-                and e.folder = #{dto.folder}
-            </if>
-            and e.source_type = 0
-            <if test="dto.followUpState != null">
-                <if test="dto.followUpState == 0">
-                    and e.follow_up_id is null
-                </if>
-                <if test="dto.followUpState == 1">
-                    and c.owner_by = #{dto.ownerBy}
-                    and e.follow_up_id is not null
-                    and c.is_delete = 0
-                </if>
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 0">
-                    and c.id is null
-                </if>
-                <if test="dto.bindCustomer != null and dto.bindCustomer == 1">
-                    and c.id is not null
-                    and c.owner_by = #{dto.ownerBy}
-                    and c.is_delete = 0
-                </if>
-            </if>
-            <if test="dto.customerType != null">
-                and c.id is not null
-                and c.owner_by = #{dto.ownerBy}
-                and c.customer_form = #{dto.customerType}
-                <if test="dto.customerLevelDictValue != null and dto.customerLevelDictValue != ''">
-                    and c.customer_level_dict_value = #{dto.customerLevelDictValue}
-                </if>
-
-                <if test="dto.customerSourceDictValue != null and dto.customerSourceDictValue != ''">
-                    and c.customer_source_dict_value = #{dto.customerSourceDictValue}
-                </if>
-
-                <if test="dto.customerTypeDictValue != null and dto.customerTypeDictValue != ''">
-                    and c.customer_type_dict_value = #{dto.customerTypeDictValue}
-                </if>
-                <if test="dto.clueStatusDictValue != null and dto.clueStatusDictValue != ''">
-                    and c.clue_status_dict_value = #{dto.clueStatusDictValue}
-                </if>
-                <if test="dto.continent != null and dto.continent != '' and dto.country != null and dto.country != ''">
-                    and c.continent = #{dto.continent} and c.country = #{dto.country}
-                </if>
-                and c.is_delete = 0
-            </if>
-            <if test="dto.blurry != null and dto.blurry != ''">
-                and (subject like concat('%',#{dto.blurry},'%') or content like concat('%',#{dto.blurry},'%') or `from`
-                like concat('%',#{dto.blurry},'%') or recipient like concat('%',#{dto.blurry},'%'))
-            </if>
-            and e.is_delete = 0
-        </where>
-        order by e.recipient_date desc
-        )
-        SELECT * FROM ranked_emails re
-        WHERE re.rn = 1
-    </select>
-
-
-    <select id="pageListNew"  resultMap="BaseResultMap">
-        select e1.*,cb.id as customer_mail_id,cb.follow_up_id,cb.follow_up_time,GROUP_CONCAT(DISTINCT cb.customer_id ORDER BY e1.id ASC) as customer_ids  from
-            (
-            select e.id, e.smtp_pop_id, e.msg_uid,e.message_id,e.is_receipt,e.is_only_head,e.is_track,e.read_remind,
-            e.delay_send_time, e.is_star,e.is_trash,e.subject,e.from, e.from_name, e.recipient,
-            e.recipient_name, e.recipient_cc, e.recipient_cc_name,e. recipient_bcc, e.recipient_bcc_name, e.folder,e.remark,
-            e.sent_date, e.recipient_date, e.email_size, e.is_read, e.reply_msg_id, e.status, e.owner_by, e.create_time, e.update_time,
-            e.is_delete, e.enabled, e.create_by, e.update_by, e.sort from  emails as e
-            <where>
-                <if test="dto.smtpPopId != null">
-                    and e.smtp_pop_id = #{dto.smtpPopId}
-                </if>
-                <if test="dto.emailAddress != null and dto.emailAddress != ''">
-                    and (e.from like concat('%',#{dto.emailAddress},'%') or e.recipient like concat('%',#{dto.emailAddress},'%') or e.recipient_cc like concat('%',#{dto.emailAddress},'%'))
-                </if>
-                <if test="dto.folder != null and dto.folder != ''">
-                    and e.folder = #{dto.folder}
-                </if>
-                <if test="dto.isStar != null and dto.isStar == 1">
-                    and e.is_star = #{dto.isStar}
-                </if>
-                <if test="dto.systemMail != null and dto.systemMail == 1">
-                    and e.from = 'system@storlead.com'
-                </if>
-                <if test="dto.systemMail == null">
-                    and (e.from is null or e.from <![CDATA[<>]]> 'system@storlead.com')
-                </if>
-                <if test="dto.isTrash != null">
-                    and e.is_trash = #{dto.isTrash}
-                </if>
-                <if test="dto.readStatu != null">
-                    and e.is_read = #{dto.readStatu}
-                </if>
-                <if test="dto.blurry != null and dto.blurry != ''">
-                    and (e.subject like concat('%',#{dto.blurry},'%') or e.content like concat('%',#{dto.blurry},'%'))
-                </if>
-                <if test="dto.folderId != null">
-                    and e.custom_folder_id = #{dto.folderId}
-                </if>
-                <if test="dto.bindCustomer == null and dto.customerId == null">
-                    <if test="dto.folderId == null and dto.isTrash == 0">
-                        and e.custom_folder_id is null
-                    </if>
-                </if>
-                <if test="dto.customerId == null">
-                    and e.source_type = 0
-                </if>
-                and e.is_delete = 0
-            </where>
-        ) as e1
-        left join customer_mail_bing_mark as cb
-        on e1.id = cb.mail_id
-        left join customer as c
-        on cb.customer_id = c.id and c.is_delete = 0
-        <where>
-            <if test="dto.customerId != null">
-                and c.id = #{dto.customerId}
-            </if>
-            <if test="(dto.customerName != null and dto.customerName != '')">
-                and c.customer_name like concat('%',#{dto.customerName},'%')
-                and c.owner_by = #{dto.ownerBy}
-            </if>
-            <if test="dto.customerLevelDictValue != null and dto.customerLevelDictValue != ''">
-                and c.customer_level_dict_value = #{dto.customerLevelDictValue}
-            </if>
-
-            <if test="dto.customerSourceDictValue != null and dto.customerSourceDictValue != ''">
-                and c.customer_source_dict_value = #{dto.customerSourceDictValue}
-            </if>
-
-            <if test="dto.customerTypeDictValue != null and dto.customerTypeDictValue != ''">
-                and c.customer_type_dict_value = #{dto.customerTypeDictValue}
-            </if>
-            <if test="dto.clueStatusDictValue != null and dto.clueStatusDictValue != ''">
-                and c.clue_status_dict_value = #{dto.clueStatusDictValue}
-            </if>
-            <if test="dto.continent != null and dto.continent != '' and dto.country != null and dto.country != ''">
-                and c.continent = #{dto.continent} and c.country = #{dto.country}
-            </if>
-            <if test="dto.customerType != null">
-                and c.customer_form = #{dto.customerType}
-            </if>
-        </where>
-        <if test="dto.customerType == null">
-            GROUP BY e1.id
-        </if>
-        <if test="dto.customerType != null">
-            GROUP BY e1.id,cb.customer_id
-        </if>
-        <if test="dto.followUpState != null and dto.followUpState == 0">
-            <if test="dto.bindCustomer != null and dto.bindCustomer == 0">
-                HAVING customer_ids is null and reply_msg_id is null
-            </if>
-            <if test="dto.bindCustomer != null and dto.bindCustomer == 1">
-                HAVING customer_ids is not null and follow_up_id is null
-            </if>
-        </if>
-        order by e1.recipient_date desc
-    </select>
-
-
-    <select id="pageListNewAllCus"  resultMap="BaseResultMap">
-        WITH ranked_emails AS (
-        select e1.*,cc.customer_id as customer_ids,ROW_NUMBER() OVER (PARTITION BY cc.customer_id ORDER BY e1.id DESC) AS rn
-        from
-        (
-        select e.id, e.smtp_pop_id, e.msg_uid,e.message_id,e.is_receipt,e.is_only_head,e.is_track,e.read_remind,
-        e.delay_send_time, e.is_star,e.is_trash,e.subject,e.from, e.from_name, e.recipient,
-        e.recipient_name, e.recipient_cc, e.recipient_cc_name,e. recipient_bcc, e.recipient_bcc_name, e.folder,e.remark,
-        e.sent_date, e.recipient_date, e.email_size, e.is_read, e.reply_msg_id, e.status, e.owner_by, e.create_time,
-        e.update_time,
-        e.is_delete, e.enabled, e.create_by, e.update_by, e.sort from emails as e
-        <where>
-            <if test="dto.smtpPopId != null">
-                and e.smtp_pop_id = #{dto.smtpPopId}
-            </if>
-            <if test="dto.emailAddress != null and dto.emailAddress != ''">
-                and (e.from like concat('%',#{dto.emailAddress},'%') or e.recipient like
-                concat('%',#{dto.emailAddress},'%') or e.recipient_cc like concat('%',#{dto.emailAddress},'%'))
-            </if>
-            <if test="dto.folder != null and dto.folder != ''">
-                and e.folder = #{dto.folder}
-            </if>
-            <if test="dto.isStar != null and dto.isStar == 1">
-                and e.is_star = #{dto.isStar}
-            </if>
-            <if test="dto.systemMail != null and dto.systemMail == 1">
-                and e.from = 'system@storlead.com'
-            </if>
-            <if test="dto.systemMail == null">
-                and (e.from is null or e.from <![CDATA[<>]]> 'system@storlead.com')
-            </if>
-            <if test="dto.isTrash != null">
-                and e.is_trash = #{dto.isTrash}
-            </if>
-            <if test="dto.readStatu != null">
-                and e.is_read = #{dto.readStatu}
-            </if>
-            <if test="dto.followRemind != null">
-                and e.subject = '跟进提醒'
-            </if>
-            <if test="dto.customerId == null">
-                and e.source_type = 0
-            </if>
-            <if test="dto.blurry != null and dto.blurry != ''">
-                and (e.subject like concat('%',#{dto.blurry},'%') or e.content like concat('%',#{dto.blurry},'%'))
-            </if>
-            and e.is_delete = 0
-        </where>
-        ) as e1
-        left join (
-            SELECT
-            cb.customer_id,
-            cb.mail_id,
-            c.customer_form
-            FROM
-            customer_mail_bing_mark AS cb
-            LEFT JOIN customer AS c ON cb.customer_id = c.id
-            WHERE  c.is_delete = 0
-            AND c.owner_by = #{dto.ownerBy}
-            <if test="dto.customerId != null">
-                and c.id = #{dto.customerId}
-            </if>
-            <if test="(dto.customerName != null and dto.customerName != '')">
-                and c.customer_name like concat('%',#{dto.customerName},'%')
-                and c.owner_by = #{dto.ownerBy}
-            </if>
-            <if test="dto.customerLevelDictValue != null and dto.customerLevelDictValue != ''">
-                and c.customer_level_dict_value = #{dto.customerLevelDictValue}
-            </if>
-
-            <if test="dto.customerSourceDictValue != null and dto.customerSourceDictValue != ''">
-                and c.customer_source_dict_value = #{dto.customerSourceDictValue}
-            </if>
-
-            <if test="dto.customerTypeDictValue != null and dto.customerTypeDictValue != ''">
-                and c.customer_type_dict_value = #{dto.customerTypeDictValue}
-            </if>
-            <if test="dto.clueStatusDictValue != null and dto.clueStatusDictValue != ''">
-                and c.clue_status_dict_value = #{dto.clueStatusDictValue}
-            </if>
-            <if test="dto.customerType != null">
-                and c.customer_form = #{dto.customerType}
-            </if>
-            <if test="dto.continent != null and dto.continent != '' and dto.country != null and dto.country != ''">
-                and c.continent = #{dto.continent} and c.country = #{dto.country}
-            </if>
-        ) as cc
-         on cc.mail_id = e1.id
-         where e1.owner_by = #{dto.ownerBy} and cc.mail_id is not null
-         order by e1.recipient_date desc
-       )
-       SELECT * FROM ranked_emails re
-       WHERE re.rn = 1
-    </select>
-
-    <select id="countMailSummaryNum" resultType="com.storlead.sales.mail.pojo.vo.NewMailCountTipVO">
-        SELECT
-                IFNULL(SUM(CASE WHEN folder = 'INBOX' AND is_read = 0 and is_trash = 0 and `from` <![CDATA[<>]]> 'system@storlead.com' THEN 1 ELSE 0 END),0) AS inboxCount,
-                IFNULL(SUM(CASE WHEN folder = 'SENT' AND is_delete = 0 and is_trash = 0 THEN 1 ELSE 0 END),0) AS sentCount,
-                IFNULL(SUM(CASE WHEN folder = 'SENTING' AND is_delete = 0 and is_trash = 0 THEN 1 ELSE 0 END),0) AS sentingCount,
-                IFNULL(SUM(CASE WHEN folder = 'DRAFT' AND is_delete = 0 and is_trash = 0 THEN 1 ELSE 0 END),0) AS draftCount,
-                IFNULL(SUM(CASE WHEN `subject` = '跟进提醒' AND is_delete = 0 THEN 1 ELSE 0 END),0) AS followUpCount,
-                IFNULL(SUM(CASE WHEN `from` = 'system@storlead.com' AND is_read = 0 THEN 1 ELSE 0 END),0) AS systemCount,
-                IFNULL(SUM(CASE WHEN is_star = 1 THEN 1 ELSE 0 END),0) AS starCount,
-                IFNULL(SUM(CASE WHEN is_trash = 1 THEN 1 ELSE 0 END),0) AS trashCount
-            FROM emails WHERE is_delete = 0 and owner_by = #{ownerBy} and smtp_pop_id = #{smtpPopId} and custom_folder_id is null and source_type = 0
-    </select>
-
-    <select id="countCustomerFollowUpMailNum" resultType="com.storlead.sales.mail.pojo.vo.NewMailCountTipVO">
-        select
-            IFNULL(SUM(CASE WHEN m.customer_ids is null and m.reply_msg_id is null THEN 1 ELSE 0 END),0) AS unknownCount,
-                   IFNULL(SUM(CASE WHEN m.customer_ids is not null and m.follow_up_id is null  THEN 1 ELSE 0 END),0) AS knownCount
-        from (
-        select e1.id,e1.reply_msg_id,cb.follow_up_id as follow_up_id,GROUP_CONCAT(DISTINCT cb.customer_id ORDER BY e1.id ASC) as customer_ids
-        from emails as e1
-        left join customer_mail_bing_mark as cb
-        on e1.id = cb.mail_id
-        left join customer as c
-        on e1.id = cb.mail_id
-        and cb.customer_id = c.id and c.is_delete = 0
-        where e1.owner_by = #{ownerBy} and e1.smtp_pop_id = #{smtpPopId} and e1.from <![CDATA[<>]]> 'system@storlead.com'
-          AND e1.is_delete = 0
-          AND e1.folder = 'INBOX'
-          AND e1.is_trash = 0
-          AND e1.is_delete = 0
-          and e1.source_type = 0
-        GROUP BY e1.id
-        )	as m
-    </select>
-
-    <select id="countCustomerAndClueNumber" resultType="com.storlead.sales.mail.pojo.vo.NewMailCountTipVO">
-        SELECT
-            IFNULL(SUM( CASE WHEN m.customer_form = 10 THEN 1 ELSE 0 END ),0) AS customerCount,
-            IFNULL(SUM( CASE WHEN m.customer_form = 11 THEN 1 ELSE 0 END ),0) AS clueCount
-        FROM
-            (
-                SELECT
-                    cb.customer_id,
-                    c.customer_form,
-                    MAX( cb.mail_id ) AS mail_id
-                FROM
-                    customer_mail_bing_mark AS cb
-                        LEFT JOIN customer AS c ON cb.customer_id = c.id
-                        left join emails as e on e.id = cb.mail_id and e.smtp_pop_id = #{smtpPopId}
-                WHERE c.is_delete = 0
-                 AND c.owner_by = #{ownerBy}
-                 AND e.id is not null
-                GROUP BY
-                    cb.customer_id,
-                    c.customer_form
-            ) AS m
-    </select>
-
-    <select id="selectCustomerLastFollowUpTime" resultType="java.time.LocalDateTime">
-        SELECT
-            max( follow_up_time ) AS follow_up_time
-        FROM
-            (
-                SELECT
-                    max( create_time ) AS follow_up_time
-                FROM
-                    customer_follow_up
-                WHERE
-                    customer_id =  #{customerId}
-                UNION ALL
-                SELECT
-                    max( sent_date ) AS follow_up_time
-                FROM
-                    customer_mail_bing_mark AS mbm
-                        LEFT JOIN emails AS e1 ON e1.id = mbm.mail_id
-                WHERE
-                    mbm.customer_id =  #{customerId}
-                    and e1.source_type = 0
-            ) AS m
-
-    </select>
-
     <!-- 获取删除后需要删除服务器的邮件 -->
     <select id="selectDelayDeleteMail" resultMap="BaseResultMap">
 --         SELECT id,smtp_pop_id, msg_uid, message_id,folder,create_time,sent_date,delete_tag FROM emails e
@@ -756,51 +186,6 @@
         LIMIT 10;
     </select>
 
-    <select id="selectCustomerEmailPage" resultType="com.storlead.sales.mail.pojo.vo.CustomerEmailVo">
-        SELECT
-            cm.mail_id AS mailId,
-            e.from_name AS fromName,
-            e.recipient_date AS recipientDate,
-            e.recipient_name AS recipientName,
-            e.recipient AS recipient,
-            e.subject AS subject,
-            e.in_out_mark AS inOutMark
-        FROM
-            customer_mail_bing_mark AS cm
-            LEFT JOIN emails AS e ON e.id = cm.mail_id
-            WHERE
-            cm.customer_id = #{query.customerId}
-        <if test="query.blurry != null and query.blurry != ''">
-            AND e.`subject` LIKE CONCAT('%',#{query.blurry},'%')
-        </if>
-        <if test="query.liaisonId != null and query.liaisonId != ''">
-            AND FIND_IN_SET(#{query.liaisonId}, cm.`liaison_ids`)
-        </if>
-        <if test="query.beginTime != null and query.endTime != null">
-            and e.recipient_date >= #{query.beginTime}  and e.recipient_date <![CDATA[<=]]> #{query.endTime}
-        </if>
-            AND e.is_delete = 0
-        ORDER BY
-            e.recipient_date
-        DESC
-    </select>
-
-    <select id="selectCusIdByMailId" resultType="java.lang.Long">
-        select customer_id from customer_mail_bing_mark where is_delete = 0
-        and mail_id in
-        <foreach collection="mailIdls" item="mailId" open="(" separator="," close=")">
-            #{mailId}
-        </foreach>
-    </select>
-
-    <select id="selectCusInfoByCusId" resultType="com.storlead.sales.mail.pojo.vo.CustomerMailVO">
-        select customer_name as customerName,country from customer where is_delete = 0
-        and id in
-        <foreach collection="customerIdls" item="customerId" open="(" separator="," close=")">
-            #{customerId}
-        </foreach>
-    </select>
-
     <select id="countSmtpMailCount" resultType="java.lang.Integer">
         select count(1) from smtp_pop_settings where is_delete = 0 and owner_by = #{userId}
     </select>