Bladeren bron

1.修改通话记录统计展示

jzp 3 dagen geleden
bovenliggende
commit
111b12ea51

+ 73 - 35
fs-company/src/main/java/com/fs/company/controller/qw/QwUserVoiceLogController.java

@@ -1,9 +1,12 @@
 package com.fs.company.controller.qw;
 
 import com.fs.common.annotation.Log;
+import com.fs.common.constant.HttpStatus;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
+import com.fs.common.core.page.PageDomain;
 import com.fs.common.core.page.TableDataInfo;
+import com.fs.common.core.page.TableSupport;
 import com.fs.common.enums.BusinessType;
 import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.StringUtils;
@@ -25,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -73,16 +77,6 @@ public class QwUserVoiceLogController extends BaseController
     @PostMapping("/newList")
     public TableDataInfo newList(@RequestBody QwUserVoiceLogVo qwUserVoiceLog)
     {
-        if(qwUserVoiceLog.getCompanyUserId() == null && qwUserVoiceLog.getDeptId() != null){
-            //获取部门下的所有用户
-            CompanyUser usermap=new CompanyUser();
-            usermap.setDeptId(qwUserVoiceLog.getDeptId());
-            List<CompanyUser> users = userService.getUserListByDeptId(usermap);
-            List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
-            if (!userIds.isEmpty()) {
-                qwUserVoiceLog.setCompanyUserIds(userIds.toArray(new Long[0]));
-            }
-        }
         PageHelper.startPage(qwUserVoiceLog.getPageNum(), qwUserVoiceLog.getPageSize());
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwUserVoiceLog.setCompanyId(loginUser.getCompany().getCompanyId());
@@ -154,34 +148,88 @@ public class QwUserVoiceLogController extends BaseController
     @GetMapping("/totalList")
     public TableDataInfo totalList(QwUserVoiceLogTotalVo qwUserVoiceLog)
     {
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwUserVoiceLog.setCompanyId(loginUser.getCompany().getCompanyId());
         qwUserVoiceLog.setQwUserId(1L);
         List<QwUserVoiceLogTotalVo> list = qwUserVoiceLogService.selectQwUserVoiceLogTotalList(qwUserVoiceLog);
-        return getDataTable(list);
+        list.forEach(item->{
+            if(item.getQwExternalContact() != null){
+                if (item.getQwExternalContact().getTagIds() != null && !Objects.equals(item.getQwExternalContact().getTagIds(), "[]")) {
+                    QwTagSearchParam param = new QwTagSearchParam();
+                    Gson gson = new Gson();
+                    List<String> tagIds = gson.fromJson(
+                            item.getQwExternalContact().getTagIds(),
+                            new TypeToken<List<String>>() {
+                            }.getType()
+                    );
+                    param.setTagIds(tagIds);
+                    item.setTagIdsName(iQwTagService.selectQwTagListByTagIds(param));
+                }
+            }
+        });
+
+        // 获取分页参数
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        Integer pageNum = pageDomain.getPageNum();
+        Integer pageSize = pageDomain.getPageSize();
+
+        int total = list.size();
+        // 在内存中进行分页处理
+        if (pageNum != null && pageSize != null) {
+            int fromIndex = (pageNum - 1) * pageSize;
+            int toIndex = Math.min(fromIndex + pageSize, total);
+
+            // 确保索引不越界
+            if (fromIndex < total) {
+                list = list.subList(fromIndex, toIndex);
+            } else {
+                list = new ArrayList<>(); // 返回空列表
+            }
+        }
+
+        // 构造返回结果
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(list);
+        rspData.setTotal(total);
+        return rspData;
     }
 
 
     @GetMapping("/sellTotalList")
     public TableDataInfo sellTotalList(QwUserVoiceLogTotalVo qwUserVoiceLog)
     {
-        if(qwUserVoiceLog.getCompanyUserId() == null && qwUserVoiceLog.getDeptId() != null){
-            //获取部门下的所有用户
-            CompanyUser usermap=new CompanyUser();
-            usermap.setDeptId(qwUserVoiceLog.getDeptId());
-            List<CompanyUser> users = userService.getUserListByDeptId(usermap);
-            List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
-            if (!userIds.isEmpty()) {
-                qwUserVoiceLog.setCompanyUserIds(userIds.toArray(new Long[0]));
-            }
-        }
-
-        startPage();
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwUserVoiceLog.setCompanyId(loginUser.getCompany().getCompanyId());
         List<QwUserVoiceLogTotalVo> list = qwUserVoiceLogService.selectQwUserVoiceLogTotalList(qwUserVoiceLog);
-        return getDataTable(list);
+
+        // 获取分页参数
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        Integer pageNum = pageDomain.getPageNum();
+        Integer pageSize = pageDomain.getPageSize();
+
+        int total = list.size();
+        // 在内存中进行分页处理
+        if (pageNum != null && pageSize != null) {
+            int fromIndex = (pageNum - 1) * pageSize;
+            int toIndex = Math.min(fromIndex + pageSize, total);
+
+            // 确保索引不越界
+            if (fromIndex < total) {
+                list = list.subList(fromIndex, toIndex);
+            } else {
+                list = new ArrayList<>(); // 返回空列表
+            }
+        }
+
+        // 构造返回结果
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(list);
+        rspData.setTotal(total);
+        return rspData;
     }
 
     @PreAuthorize("@ss.hasPermi('qw:qwUserVoiceLog:sellTotalExport')")
@@ -189,16 +237,6 @@ public class QwUserVoiceLogController extends BaseController
     @GetMapping("/sellTotalExport")
     public AjaxResult sellTotalExport(QwUserVoiceLogTotalVo qwUserVoiceLog)
     {
-        if(qwUserVoiceLog.getCompanyUserId() == null && qwUserVoiceLog.getDeptId() != null){
-            //获取部门下的所有用户
-            CompanyUser usermap=new CompanyUser();
-            usermap.setDeptId(qwUserVoiceLog.getDeptId());
-            List<CompanyUser> users = userService.getUserListByDeptId(usermap);
-            List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
-            if (!userIds.isEmpty()) {
-                qwUserVoiceLog.setCompanyUserIds(userIds.toArray(new Long[0]));
-            }
-        }
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwUserVoiceLog.setCompanyId(loginUser.getCompany().getCompanyId());
         List<QwUserVoiceLogTotalVo> list = qwUserVoiceLogService.selectQwUserVoiceLogTotalList(qwUserVoiceLog);

+ 41 - 14
fs-service/src/main/java/com/fs/qw/service/impl/QwUserVoiceLogServiceImpl.java

@@ -22,10 +22,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -133,23 +130,53 @@ public class QwUserVoiceLogServiceImpl extends ServiceImpl<QwUserVoiceLogMapper,
         if(list != null && !list.isEmpty()){
             List<CompanyUser> companyUserList = companyUserMapper.selectCompanyUserByIds(list);
 
-            qwUserVoiceLogTotalVos.forEach(m-> {
-                companyUserList.forEach(n-> {
-                    if(m.getCompanyUserId() != null && n.getUserId() != null && m.getCompanyUserId().equals(n.getUserId())){
-                        m.setCompanyUserName(n.getNickName());
+            // 优化:使用Map提高查找效率,避免双重循环
+            Map<Long, CompanyUser> companyUserMap = companyUserList.stream()
+                    .collect(Collectors.toMap(CompanyUser::getUserId, user -> user, (existing, replacement) -> existing));
+
+            // 如果有部门过滤条件,则预先过滤用户列表
+            if (qwUserVoiceLog.getDeptId() != null) {
+                companyUserMap.entrySet().removeIf(entry ->
+                        entry.getValue().getDeptId() == null ||
+                                !entry.getValue().getDeptId().equals(qwUserVoiceLog.getDeptId()));
+            }
+
+            // 设置用户姓名和部门ID
+            qwUserVoiceLogTotalVos.forEach(logVo -> {
+                CompanyUser user = companyUserMap.get(logVo.getCompanyUserId());
+                if (user != null) {
+                    logVo.setCompanyUserName(user.getNickName());
+                    if (user.getDeptId() != null) {
+                        logVo.setDeptId(user.getDeptId());
                     }
-                });
+                }
             });
+
+            // 如果有部门过滤条件,过滤掉没有部门ID的记录
+            if (qwUserVoiceLog.getDeptId() != null) {
+                qwUserVoiceLogTotalVos = qwUserVoiceLogTotalVos.stream()
+                        .filter(m -> m.getDeptId() != null)
+                        .collect(Collectors.toList());
+            }
         }
+
         List<QwCompany> companyList = qwCompanyService.selectQwCompanyList(new QwCompany());
-        qwUserVoiceLogTotalVos.forEach(m -> companyList.forEach(n ->{
-            if(m.getCorpId().equals(n.getCorpId())){
-                m.setCorpName(n.getCorpName());
+        // 优化:使用Map提高查找效率
+        Map<String, String> corpIdToNameMap = companyList.stream()
+                .collect(Collectors.toMap(QwCompany::getCorpId, QwCompany::getCorpName, (existing, replacement) -> existing));
+
+        qwUserVoiceLogTotalVos.forEach(m -> {
+            String corpName = corpIdToNameMap.get(m.getCorpId());
+            if (corpName != null) {
+                m.setCorpName(corpName);
             }
-        }));
+        });
+
         String companyUserName = qwUserVoiceLog.getCompanyUserName();
         if(companyUserName != null && !companyUserName.isEmpty()){
-            qwUserVoiceLogTotalVos = qwUserVoiceLogTotalVos.stream().filter(n -> n.getCompanyUserName().contains(companyUserName)).collect(Collectors.toList());
+            qwUserVoiceLogTotalVos = qwUserVoiceLogTotalVos.stream()
+                    .filter(n -> n.getCompanyUserName() != null && n.getCompanyUserName().contains(companyUserName))
+                    .collect(Collectors.toList());
         }
         return qwUserVoiceLogTotalVos;
     }

+ 23 - 0
fs-service/src/main/java/com/fs/qw/vo/QwUserVoiceLogTotalVo.java

@@ -8,6 +8,8 @@ import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwUser;
 import lombok.EqualsAndHashCode;
 
+import java.util.List;
+
 @EqualsAndHashCode(callSuper = true)
 public class QwUserVoiceLogTotalVo extends BaseEntity {
 
@@ -87,6 +89,27 @@ public class QwUserVoiceLogTotalVo extends BaseEntity {
 
     private Long deptId;
 
+
+    private List<String> tagIds;
+
+    private List<String> tagIdsName;
+
+    public List<String> getTagIds() {
+        return tagIds;
+    }
+
+    public void setTagIds(List<String> tagIds) {
+        this.tagIds = tagIds;
+    }
+
+    public List<String> getTagIdsName() {
+        return tagIdsName;
+    }
+
+    public void setTagIdsName(List<String> tagIdsName) {
+        this.tagIdsName = tagIdsName;
+    }
+
     public String getCorpName() {
         return corpName;
     }

+ 10 - 6
fs-service/src/main/resources/mapper/qw/QwUserVoiceLogMapper.xml

@@ -97,19 +97,23 @@
         where id = #{id}
     </select>
     <select id="selectQwUserVoiceLogTotalList" resultMap="QwUserVoiceLogVoTotalResult">
-
-        SELECT
-        SUM(duration) duration,qu.qw_user_name,uvl.corp_id,qu.qw_user_id,uvl.company_user_id,
+        SELECT uvl.id, ext_id, uvl.qw_user_id, duration, title, uvl.status, uvl.corp_id,
+               uvl.company_id, uvl.company_user_id, uvl.create_time,qec.`name`,qec.tag_ids,qu.qw_user_name,
+        SUM(duration) duration,
         COUNT(CASE WHEN uvl.status=1 THEN 1 END) AS connectCount,
         COUNT(CASE WHEN uvl.status=2 THEN 1 END) AS noConnectCount
         FROM qw_user_voice_log uvl
         LEFT JOIN qw_user qu ON uvl.qw_user_id = qu.id
+        left join qw_external_contact qec on uvl.ext_id = qec.id
+
         <where>
             <if test="companyId != null ">and uvl.company_id = #{companyId}</if>
             <if test="companyUserId != null ">and uvl.company_user_id = #{companyUserId}</if>
-            <if test="companyUserId == null and companyUserIds != null and companyUserIds.length > 0"> and uvl.company_user_id in
-                <foreach collection="companyUserIds" item="userId" open="(" separator="," close=")">
-                    #{userId}
+            <if test="tagIds != null">
+                and
+                <foreach collection="tagIds" item="tagId" separator="and">
+                    <!-- 使用JSON_CONTAINS检查JSON数组中是否包含指定元素 -->
+                    JSON_CONTAINS(qec.tag_ids, CONCAT('"', #{tagId}, '"'))
                 </foreach>
             </if>
             <if test="qwUserName != null ">and qu.qw_user_name like concat(#{qwUserName}, '%')</if>