浏览代码

优化在职转接-部门

三七 1 天之前
父节点
当前提交
f0d5b6aca1

+ 2 - 2
fs-admin/src/main/resources/application.yml

@@ -4,10 +4,10 @@ server:
 # Spring配置
 spring:
   profiles:
-    active: dev
+#    active: dev
 #    active: druid-hdt
 #    active: druid-yzt
-#    active: druid-sxjz
+    active: druid-sxjz-test
 #    active: druid-sft
 #    active: druid-fby
 #    active: dev

+ 10 - 1
fs-service/src/main/java/com/fs/qw/domain/QwExternalContactTransferLog.java

@@ -1,9 +1,14 @@
 package com.fs.qw.domain;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
 import lombok.Data;
 
+import java.util.Date;
+
 /**
  * 转接记录对象 qw_external_contact_transfer_log
  *
@@ -11,7 +16,7 @@ import lombok.Data;
  * @date 2024-06-27
  */
 @Data
-public class QwExternalContactTransferLog extends BaseEntity
+public class QwExternalContactTransferLog
 {
     private static final long serialVersionUID = 1L;
 
@@ -46,6 +51,10 @@ public class QwExternalContactTransferLog extends BaseEntity
     @Excel(name = "状态")
     private Integer status;
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @TableField(fill = FieldFill.INSERT)
+    private Date createTime;
+
     private String takeoverUserId;
     private String handoverUserId;
     private Long qwUserId;

+ 3 - 1
fs-service/src/main/java/com/fs/qw/mapper/QwExternalContactTransferLogMapper.java

@@ -1,5 +1,7 @@
 package com.fs.qw.mapper;
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwExternalContactTransferLog;
 import com.fs.qw.param.QwExternalContactTransferLogParam;
 import com.fs.qw.vo.QwExternalContactTransferLogListVO;
@@ -16,7 +18,7 @@ import java.util.List;
  * @date 2024-06-27
  */
 @Repository
-public interface QwExternalContactTransferLogMapper
+public interface QwExternalContactTransferLogMapper extends BaseMapper<QwExternalContactTransferLog>
 {
     /**
      * 查询转接记录

+ 3 - 1
fs-service/src/main/java/com/fs/qw/service/IQwExternalContactTransferLogService.java

@@ -1,6 +1,8 @@
 package com.fs.qw.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.common.core.domain.R;
+import com.fs.qw.domain.QwExternalContact;
 import com.fs.qw.domain.QwExternalContactTransferLog;
 import com.fs.qw.param.QwExternalContactTransferLogParam;
 import com.fs.qw.vo.QwExternalContactTransferLogListVO;
@@ -13,7 +15,7 @@ import java.util.List;
  * @author fs
  * @date 2024-06-27
  */
-public interface IQwExternalContactTransferLogService
+public interface IQwExternalContactTransferLogService extends IService<QwExternalContactTransferLog>
 {
     /**
      * 查询转接记录

+ 130 - 19
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactTransferLogServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.qw.service.impl;
 
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
 import com.fs.qw.domain.QwExternalContact;
@@ -7,15 +8,20 @@ import com.fs.qw.domain.QwExternalContactTransferLog;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwExternalContactTransferLogMapper;
 import com.fs.qw.param.QwExternalContactTransferLogParam;
+import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.service.IQwExternalContactTransferLogService;
 import com.fs.qw.vo.QwExternalContactTransferLogListVO;
 import com.fs.qwApi.domain.QwGetTransferResult;
 import com.fs.qwApi.param.QwGetTransferParam;
 import com.fs.qwApi.service.QwApiService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * 转接记录Service业务层处理
@@ -23,8 +29,9 @@ import java.util.List;
  * @author fs
  * @date 2024-06-27
  */
+@Slf4j
 @Service
-public class QwExternalContactTransferLogServiceImpl implements IQwExternalContactTransferLogService
+public class QwExternalContactTransferLogServiceImpl extends ServiceImpl<QwExternalContactTransferLogMapper, QwExternalContactTransferLog> implements IQwExternalContactTransferLogService
 {
     @Autowired
     private QwExternalContactTransferLogMapper qwExternalContactTransferLogMapper;
@@ -33,6 +40,9 @@ public class QwExternalContactTransferLogServiceImpl implements IQwExternalConta
 
     @Autowired
     private QwExternalContactMapper qwExternalContactMapper;
+
+    @Autowired
+    private IQwExternalContactService iQwExternalContactService;
     /**
      * 查询转接记录
      *
@@ -108,34 +118,135 @@ public class QwExternalContactTransferLogServiceImpl implements IQwExternalConta
 
     @Override
     public R syncQwExternalContactTransferLog(String corpId) {
+
+        try {
         QwExternalContactTransferLog qwExternalContactTransferLog = new QwExternalContactTransferLog();
-//        qwExternalContactTransferLog.setCompanyId(companyId);
         qwExternalContactTransferLog.setStatus(2);
         List<QwExternalContactTransferLog> qwExternalContactTransferLogs = qwExternalContactTransferLogMapper.selectQwExternalContactTransferLogList(qwExternalContactTransferLog);
-        for (QwExternalContactTransferLog externalContactTransferLog : qwExternalContactTransferLogs) {
-            QwGetTransferParam getTransferParam = new QwGetTransferParam();
-            getTransferParam.setTakeover_userid(externalContactTransferLog.getTakeoverUserId());
-            getTransferParam.setHandover_userid(externalContactTransferLog.getHandoverUserId());
-            QwGetTransferResult transfer = qwApiService.getTransfer(getTransferParam, corpId);
-            List<QwGetTransferResult.Customer> customers = transfer.getCustomer();
-            for (QwGetTransferResult.Customer customer: customers) {
-                if (customer.getExternal_userid().equals(externalContactTransferLog.getExternalUserId())){
-                    if (customer.getStatus()!=2){
-                        externalContactTransferLog.setStatus(customer.getStatus());
-                        qwExternalContactTransferLogMapper.updateQwExternalContactTransferLog(externalContactTransferLog);
+
+        Map<String, List<QwExternalContactTransferLog>> groupedLogs = qwExternalContactTransferLogs.stream()
+                .collect(Collectors.groupingBy(log ->
+                        log.getCorpId() + "/-/" + log.getTakeoverUserId() + "/-/" + log.getHandoverUserId()
+                ));
+
+        for (Map.Entry<String, List<QwExternalContactTransferLog>> entry : groupedLogs.entrySet()) {
+
+
+            try {
+                // 拆分key
+                String[] keyParts = entry.getKey().split("/-/");
+                String keyPartsCorpId = keyParts[0];
+                String keyPartsTakeoverUserId = keyParts[1];
+                String keyPartsHandoverUserId = keyParts[2];
+
+                List<QwExternalContactTransferLog> transferLogListEntry = entry.getValue();
+
+
+                QwGetTransferParam getTransferParam = new QwGetTransferParam();
+                getTransferParam.setTakeover_userid(keyPartsTakeoverUserId);
+                getTransferParam.setHandover_userid(keyPartsHandoverUserId);
+
+
+                // 第一次请求游标为空
+                String cursor = null;
+                List<QwGetTransferResult.Customer> allCustomers = new ArrayList<>();
+
+                int page = 0;
+                do {
+                    page++;
+
+                    // 设置游标(第一次请求可能不需要设置或设为空)
+                    if (cursor != null) {
+                        getTransferParam.setCursor(cursor);
+                    }
+
+                    // 调用接口
+                    QwGetTransferResult transfer = qwApiService.getTransfer(getTransferParam, keyPartsCorpId);
+
+                    // 检查接口返回是否成功
+                    if (transfer.getErrcode() != 0) {
+                        log.error("获取转移记录失败: errcode={}, errmsg={}, takeover_userid={}, handover_userid={}",
+                                transfer.getErrcode(), transfer.getErrmsg(),
+                                keyPartsTakeoverUserId, keyPartsHandoverUserId);
+                        break;
+                    }
+
+                    // 获取当前页数据
+                    List<QwGetTransferResult.Customer> customers = transfer.getCustomer();
+                    if (customers != null && !customers.isEmpty()) {
+                        allCustomers.addAll(customers);
+                        log.info("第 {} 页获取到 {} 条转移记录", page, customers.size());
+                    } else {
+                        log.info("第 {} 页没有数据", page);
+                        // 如果没有数据,也退出循环
+                        break;
+                    }
+
+                    // 更新游标,准备下一次请求
+                    cursor = transfer.getNext_cursor();
+
+                    // 添加短暂延时,避免请求过快
+                    try {
+                        Thread.sleep(200);
+                    } catch (InterruptedException e) {
+                        Thread.currentThread().interrupt();
+                        break;
+                    }
+
+                    // 如果next_cursor为空或没有更多数据,则退出循环
+                } while (cursor != null && !cursor.isEmpty() && !"0".equals(cursor));
+
+                List<QwExternalContactTransferLog> transferLogList=new ArrayList<>();
+
+                List<QwExternalContact> contactList = new ArrayList<>();
+
+
+                Map<String, QwGetTransferResult.Customer> allCustomersMap = allCustomers.stream()
+                        .collect(Collectors.toMap(
+                                QwGetTransferResult.Customer::getExternal_userid,
+                                customer -> customer
+                        ));
+
+                for (QwExternalContactTransferLog transferLog : transferLogListEntry) {
+
+                    QwGetTransferResult.Customer customer = allCustomersMap.get(transferLog.getExternalUserId());
+
+                    if (customer != null && customer.getStatus() != 2) {
+                        transferLog.setStatus(customer.getStatus());
+                        transferLogList.add(transferLog);
+
                         QwExternalContact qwExternalContact = new QwExternalContact();
-                        qwExternalContact.setId(externalContactTransferLog.getExternalContactId());
+                        qwExternalContact.setId(transferLog.getExternalContactId());
                         qwExternalContact.setTransferStatus(customer.getStatus());
-                        if (customer.getStatus()==1){
-                            qwExternalContact.setUserId(externalContactTransferLog.getTakeoverUserId());
-                            qwExternalContact.setQwUserId(externalContactTransferLog.getQwUserId());
-                            qwExternalContact.setCompanyUserId(externalContactTransferLog.getCompanyUserId());
+
+                        if (customer.getStatus() == 1) {
+                            qwExternalContact.setUserId(transferLog.getTakeoverUserId());
+                            qwExternalContact.setQwUserId(transferLog.getQwUserId());
+                            qwExternalContact.setCompanyUserId(transferLog.getCompanyUserId());
                         }
-                        qwExternalContactMapper.updateQwExternalContact(qwExternalContact);
+                        contactList.add(qwExternalContact);
                     }
                 }
+
+                if (!transferLogList.isEmpty()){
+                    log.info("更新{}条外部联系人转移日志",transferLogList.size());
+                    super.updateBatchById(transferLogList,300);
+                }
+                if (!contactList.isEmpty()){
+                    log.info("更新{}条外部联系人",contactList.size());
+                    iQwExternalContactService.updateBatchById(contactList,300);
+                }
+            }catch (Exception e){
+                log.error("查询转接记录失败:"+entry);
             }
 
+
+        }
+
+                log.info("转接记录同步成功");
+            } catch (Exception e){
+            e.printStackTrace();
+            log.info("转接记录同步失败");
         }
         return null;
     }

+ 6 - 1
fs-service/src/main/resources/mapper/course/FsCourseWatchLogMapper.xml

@@ -158,7 +158,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="maps.qwUserName != null  and maps.qwUserName != '' ">
                 and qu.qw_user_name = #{maps.qwUserName}
             </if>
-
+            <if test='maps.cuDeptIdList != null and !maps.cuDeptIdList.isEmpty() and  maps.userType != "00" '>
+                AND cu.dept_id IN
+                <foreach collection='maps.cuDeptIdList' item='item' open='(' separator=',' close=')'>
+                    #{item}
+                </foreach>
+            </if>
         </where>
          order by l.finish_time desc,l.update_time desc,l.create_time desc
     </select>

+ 7 - 0
fs-service/src/main/resources/mapper/sop/QwSopTempMapper.xml

@@ -43,6 +43,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="sort != null "> and sort = #{sort}</if>
             <if test="companyId != null "> and company_id = #{companyId}</if>
             <if test="sendType != null "> and send_type = #{sendType}</if>
+            <if test="createBy != null "> and create_by = #{createBy}</if>
+            <if test="cuDeptIdList != null and !cuDeptIdList.isEmpty()">
+                AND create_by_dept IN
+                <foreach collection='cuDeptIdList' item='item' open='(' separator=',' close=')'>
+                    #{item}
+                </foreach>
+            </if>
         </where>
         order by sort,create_time desc
     </select>