yzc 1 жил өмнө
parent
commit
0c936c5a61

+ 0 - 11
hx-form/src/main/java/com/fjhx/form/entity/EmailCount.java

@@ -1,11 +0,0 @@
-package com.fjhx.form.entity;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter
-@Setter
-public class EmailCount {
-    private Integer count;
-    private Long userId;
-}

+ 1 - 2
hx-form/src/main/java/com/fjhx/form/mapper/EmployeeProductivityMapper.java

@@ -1,6 +1,5 @@
 package com.fjhx.form.mapper;
 
-import com.fjhx.form.entity.EmailCount;
 import com.fjhx.form.entity.EmployeeProductivity;
 import com.ruoyi.common.core.domain.BaseSelectDto;
 import com.ruoyi.common.utils.wrapper.IWrapper;
@@ -14,5 +13,5 @@ public interface EmployeeProductivityMapper {
 
     List<EmployeeProductivity> getList(@Param("ew") IWrapper<Object> wrapper, @Param("dto") BaseSelectDto dto);
 
-    List<EmailCount> getUserEmailCount(@Param("ew") IWrapper<Object> wrapper);
+    List<EmployeeProductivity> getUserEmailCount(@Param("ew") IWrapper<Object> wrapper);
 }

+ 20 - 22
hx-form/src/main/java/com/fjhx/form/service/impl/EmployeeProductivityServiceImpl.java

@@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.customer.service.customer.CustomerService;
-import com.fjhx.form.entity.EmailCount;
 import com.fjhx.form.entity.EmployeeProductivity;
 import com.fjhx.form.mapper.EmployeeProductivityMapper;
 import com.fjhx.form.service.EmployeeProductivityService;
@@ -17,6 +16,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -42,35 +42,33 @@ public class EmployeeProductivityServiceImpl implements EmployeeProductivityServ
         }
         List<Long> userIds = salesmanList.stream().map(EmployeeProductivity::getUserId).collect(Collectors.toList());
 
-        //获取邮件数列表
+        //获取邮件数列表
         DynamicDataSourceContextHolder.push(SourceConstant.MAIL);
-        List<EmailCount> receiveEmailCount = employeeProductivityMapper.getUserEmailCount(IWrapper.getWrapper()
-                .in("t1.user_id", userIds)
-                .ge("t1.send_date", dto.getBeginTime())
-                .le("t1.send_date", dto.getEndTime())
-                .apply("t1.from_email != t1.mail_user")
-                .groupBy("t1.user_id")
-        );
-        //获取发邮件数列表
-        List<EmailCount> sendEmailCount = employeeProductivityMapper.getUserEmailCount(IWrapper.getWrapper()
-                .in("t1.user_id", userIds)
-                .ge("t1.send_date", dto.getBeginTime())
-                .le("t1.send_date", dto.getEndTime())
-                .apply("t1.from_email = t1.mail_user")
-                .groupBy("t1.user_id")
+        List<EmployeeProductivity> emailCountList = employeeProductivityMapper.getUserEmailCount(IWrapper.getWrapper()
+                .in("emb.user_id", userIds)
+                .ge("em.send_date", dto.getBeginTime())
+                .le("em.send_date", dto.getEndTime())
+                .groupBy("emb.user_id")
         );
         DynamicDataSourceContextHolder.poll();
 
-        Map<Long, Integer> receiveEmailCountMap = receiveEmailCount.stream().collect(Collectors.toMap(EmailCount::getUserId, EmailCount::getCount));
-        Map<Long, Integer> sendEmailCountMap = sendEmailCount.stream().collect(Collectors.toMap(EmailCount::getUserId, EmailCount::getCount));
+        Map<Long, EmployeeProductivity> emailCountMap = emailCountList.stream().collect(Collectors.toMap(EmployeeProductivity::getUserId, Function.identity()));
 
         //赋值数据
         for (EmployeeProductivity employeeProductivity : salesmanList) {
             Long userId = employeeProductivity.getUserId();
-            //赋值发件数
-            employeeProductivity.setSendEmailCount(sendEmailCountMap.getOrDefault(userId, 0));
-            //赋值收件数
-            employeeProductivity.setReceiveEmailCount(receiveEmailCountMap.getOrDefault(userId, 0));
+
+            //初始默认0
+            employeeProductivity.setSendEmailCount(0);
+            employeeProductivity.setReceiveEmailCount(0);
+
+            EmployeeProductivity emailCount = emailCountMap.get(userId);
+            if (ObjectUtil.isNotEmpty(emailCount)) {
+                //赋值发件数
+                employeeProductivity.setSendEmailCount(emailCount.getSendEmailCount());
+                //赋值收件数
+                employeeProductivity.setReceiveEmailCount(emailCount.getReceiveEmailCount());
+            }
         }
         return salesmanList;
     }

+ 8 - 17
hx-form/src/main/resources/mapper/EmployeeProductivityMapper.xml

@@ -194,23 +194,14 @@
         JOIN sys_role sr ON sr.role_id = sur.role_id
         ${ew.customSqlSegment}
     </select>
-    <select id="getUserEmailCount" resultType="com.fjhx.form.entity.EmailCount">
-        SELECT count(1) count,
-	t1.user_id
-        FROM
-            (
-            SELECT
-            em.id, em.send_date, em.from_email, emb.user_id, CONCAT( emb.mail_user_prefix, '@', ed.domain_name ) AS mail_user
-            FROM
-            enterprise_message em
-            JOIN enterprise_mailbox emb ON em.mailbox_id = emb.id
-            JOIN enterprise_domain ed ON emb.domain_id = ed.id UNION ALL
-            SELECT
-            pm.id, pm.send_date, pm.from_email, pmb.user_id, pmb.mail_user
-            FROM
-            personal_message pm
-            JOIN personal_mailbox pmb ON pm.mailbox_id = pmb.id
-            ) t1
+    <select id="getUserEmailCount" resultType="com.fjhx.form.entity.EmployeeProductivity">
+        SELECT emb.user_id,
+               IFNULL(sum(if(em.from_email = CONCAT(emb.mail_user_prefix, '@', ed.domain_name), 1, 0)),
+                      0)                                                                                      as sendEmailCount,
+               IFNULL(sum(if(em.from_email != CONCAT( emb.mail_user_prefix, '@', ed.domain_name ), 1, 0)), 0) as receiveEmailCount
+        FROM enterprise_message em
+                 JOIN enterprise_mailbox emb ON em.mailbox_id = emb.id
+                 JOIN enterprise_domain ed ON emb.domain_id = ed.id
             ${ew.customSqlSegment}
     </select>
 </mapper>