Selaa lähdekoodia

优化在职转接-部门

三七 1 päivä sitten
vanhempi
commit
5249f280e5

+ 3 - 7
fs-company/src/main/java/com/fs/company/controller/qw/QwExternalContactTransferLogController.java

@@ -14,7 +14,6 @@ import com.fs.framework.service.TokenService;
 import com.fs.qw.domain.QwExternalContactTransferLog;
 import com.fs.qw.param.QwExternalContactTransferLogParam;
 import com.fs.qw.service.IQwExternalContactTransferLogService;
-import com.fs.qw.service.impl.AsyncQwExternalContactTransferService;
 import com.fs.qw.vo.QwExternalContactTransferLogListVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -42,9 +41,6 @@ public class QwExternalContactTransferLogController extends BaseController
     @Autowired
     private CompanyDeptServiceImpl companyDeptService;
 
-    @Autowired
-    private AsyncQwExternalContactTransferService transferService;
-
     /**
      * 查询转接记录列表
      */
@@ -120,9 +116,9 @@ public class QwExternalContactTransferLogController extends BaseController
     @GetMapping("/sync/{corpId}")
     public R syncTag(@PathVariable("corpId") String corpId)
     {
-        transferService.syncQwExternalContactTransferLog(corpId);
-
-//        return qwExternalContactTransferLogService.syncQwExternalContactTransferLog(corpId);
+//        transferService.syncQwExternalContactTransferLog(corpId);
+//
+         qwExternalContactTransferLogService.syncQwExternalContactTransferLog(corpId);
         return R.ok();
     }
     /**

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

@@ -65,7 +65,7 @@ public interface IQwExternalContactTransferLogService extends IService<QwExterna
      */
     public int deleteQwExternalContactTransferLogById(Long id);
 
-    public R syncQwExternalContactTransferLog(String corpId);
+    public void syncQwExternalContactTransferLog(String corpId);
 
     List<QwExternalContactTransferLogListVO> selectQwExternalContactTransferLogListVO(QwExternalContactTransferLogParam qwExternalContactTransferLog);
 

+ 0 - 174
fs-service/src/main/java/com/fs/qw/service/impl/AsyncQwExternalContactTransferService.java

@@ -1,174 +0,0 @@
-package com.fs.qw.service.impl;
-
-
-import com.fs.course.domain.FsUserCourse;
-import com.fs.qw.domain.QwExternalContact;
-import com.fs.qw.domain.QwExternalContactTransferLog;
-import com.fs.qw.mapper.QwExternalContactTransferLogMapper;
-import com.fs.qw.service.IQwExternalContactService;
-import com.fs.qw.service.IQwExternalContactTransferLogService;
-import com.fs.qwApi.domain.QwGetTransferResult;
-import com.fs.qwApi.param.QwGetTransferParam;
-import com.fs.qwApi.service.QwApiService;
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-@Slf4j
-@Service
-@AllArgsConstructor
-public class AsyncQwExternalContactTransferService {
-
-    @Autowired
-    private QwExternalContactTransferLogMapper qwExternalContactTransferLogMapper;
-
-    @Autowired
-    private QwApiService qwApiService;
-
-    @Autowired
-    private IQwExternalContactService iQwExternalContactService;
-
-    @Autowired
-    private IQwExternalContactTransferLogService iQwExternalContactTransferLogService;
-
-    @Async("scheduledExecutorService")
-    public void syncQwExternalContactTransferLog(String corpId) {
-        try {
-            QwExternalContactTransferLog qwExternalContactTransferLog = new QwExternalContactTransferLog();
-            qwExternalContactTransferLog.setStatus(2);
-            qwExternalContactTransferLog.setCorpId(corpId);
-            List<QwExternalContactTransferLog> qwExternalContactTransferLogs = qwExternalContactTransferLogMapper.selectQwExternalContactTransferLogList(qwExternalContactTransferLog);
-
-            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(transferLog.getExternalContactId());
-                            qwExternalContact.setTransferStatus(customer.getStatus());
-
-                            if (customer.getStatus() == 1) {
-                                qwExternalContact.setUserId(transferLog.getTakeoverUserId());
-                                qwExternalContact.setQwUserId(transferLog.getQwUserId());
-                                qwExternalContact.setCompanyUserId(transferLog.getCompanyUserId());
-                            }
-                            contactList.add(qwExternalContact);
-                        }
-                    }
-
-                    if (!transferLogList.isEmpty()){
-                        log.info("更新{}条外部联系人转移日志",transferLogList.size());
-                        iQwExternalContactTransferLogService.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("转接记录同步失败");
-        }
-    }
-}

+ 4 - 2
fs-service/src/main/java/com/fs/qw/service/impl/QwExternalContactTransferLogServiceImpl.java

@@ -16,6 +16,7 @@ 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.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -117,7 +118,8 @@ public class QwExternalContactTransferLogServiceImpl extends ServiceImpl<QwExter
     }
 
     @Override
-    public R syncQwExternalContactTransferLog(String corpId) {
+    @Async
+    public void syncQwExternalContactTransferLog(String corpId) {
 
         try {
         QwExternalContactTransferLog qwExternalContactTransferLog = new QwExternalContactTransferLog();
@@ -248,7 +250,7 @@ public class QwExternalContactTransferLogServiceImpl extends ServiceImpl<QwExter
             e.printStackTrace();
             log.info("转接记录同步失败");
         }
-        return null;
+
     }
 
     @Override