| 
					
				 | 
			
			
				@@ -47,10 +47,8 @@ import java.time.LocalDateTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.ZoneId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.time.format.DateTimeFormatter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.concurrent.CountDownLatch; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.concurrent.ExecutorService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.concurrent.Executors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.concurrent.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.function.Function; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -527,12 +525,139 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 qwSopLogs.size(), (endTime - startTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void qwSopLogsResultNew() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        logger.info("开始执行企业微信群发消息结果查询任务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long startTime = System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<QwSopLogs> qwSopLogsList = qwSopLogsMapper.selectSopLogsByCreateCorpMassSendResult(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (qwSopLogsList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("没有需要查询结果的群发消息记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, List<QwSopLogs>> grouped = qwSopLogsList.stream().collect( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Collectors.groupingBy(log -> log.getQwUserid() + "|" + log.getCorpId() + "|" + log.getMsgId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Map.Entry<String, List<QwSopLogs>> entry : grouped.entrySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String key = entry.getKey(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<QwSopLogs> corpLogs = entry.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] keys = key.split("\\|"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String qwUserid = keys[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String corpId = keys[1]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String msgID = keys[2]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwGetGroupmsgSendParam param = new QwGetGroupmsgSendParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            param.setMsgid(msgID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            param.setUserid(qwUserid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            param.setLimit(1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            fetchAndProcessAllPages(param, corpId, corpLogs, msgID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long endTime = System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        logger.info("企业微信群发消息结果查询任务完成,处理记录总数: {},总耗时: {}ms", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                qwSopLogsList.size(), (endTime - startTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void fetchAndProcessAllPages(QwGetGroupmsgSendParam param, String corpId, List<QwSopLogs> logs, String msgId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String nextCursor = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        do { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            param.setCursor(nextCursor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwGroupmsgSendResult result = qwApiService.getGroupmsgSendResult(param, corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (result == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("接口调用失败: {}", param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (result.getErrCode() == 45033) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Thread.sleep(2000 + new Random().nextInt(1000)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result = qwApiService.getGroupmsgSendResult(param, corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } catch (InterruptedException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Thread.currentThread().interrupt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    logger.error("线程中断", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (result.getErrCode() != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("查询失败: {}, errCode: {}, errMsg: {}", param, result.getErrCode(), result.getErrMsg()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            processPageResult(result, logs, corpId, msgId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            nextCursor = result.getNextCursor(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } while (nextCursor != null && !nextCursor.isEmpty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void processPageResult(QwGroupmsgSendResult result, List<QwSopLogs> logs, String corpId, String msgId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, SendItemResult> sendMap = result.getSendList().stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .collect(Collectors.toMap( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        r -> r.getUserId() + "_" + r.getExternalUserId() + "_" + corpId + "_" + msgId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        Function.identity(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        (a, b) -> a  // 如果重复,保留第一个 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String now = LocalDateTime.now().format(formatter); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 只处理匹配得上的记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<QwSopLogs> matchedLogs = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (QwSopLogs log : logs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String logKey = log.getQwUserid() + "_" + log.getExternalUserId() + "_" + log.getCorpId() + "_" + msgId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            SendItemResult matched = sendMap.get(logKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (matched != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                switch (matched.getStatus()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    case 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSendStatus(5L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setRemark("员工未发送,已作废"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSendStatus(1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setReceivingStatus(1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    case 3: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSendType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSendStatus(3L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setRemark("客户无法接收,补发"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setReceivingStatus(0L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSendTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        log.setSort(30000001); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    default: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                matchedLogs.add(log); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!matchedLogs.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            batchUpdateDatabase(matchedLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 批量更新数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param updateList 需要更新的记录列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void batchUpdateDatabase(List<QwSopLogs> updateList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        int updateBatchSize = 1000; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int updateBatchSize = 500; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (int i = 0; i < updateList.size(); i += updateBatchSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             int endIndex = Math.min(i + updateBatchSize, updateList.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             List<QwSopLogs> batch = updateList.subList(i, endIndex); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -545,7 +670,6 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public int updateQwSopLogsByWatchLogType(String id,String remark) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return qwSopLogsMapper.updateQwSopLogsByWatchLogType(id,remark); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1255,7 +1379,7 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                             if (content == null || content.getSetting() == null) continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                             Long courseId = content.getCourseId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                             for (QwSopTempSetting.Content.Setting set : content.getSetting()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                processContent(set, corpId, templateSop, attachments, courseId,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                                processContent(set, corpId, templateSop, attachments, courseId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                         } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                             logger.error("消息内容解析失败,logId:{}", log.getId(), e); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1337,10 +1461,267 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         logger.info("企业微信群发消息创建任务执行完成,总耗时: {} 毫秒", (endTime - startTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 处理不同类型的内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    private void processContent(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                QwMsgTemplateSop templateSop, List<QwMsgTemplateSop.Attachment> attachments 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                ,Long courseId,CourseConfig config) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        switch (set.getContentType()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            case "1": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                templateSop.setTextContent(set.getValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            case "2": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                handleImageAttachment(set, corpId, attachments); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            case "3": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                handleLinkAttachment(set, corpId, attachments); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            case "4": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                handleMiniProgramAttachment(set, corpId, attachments,courseId,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    // 处理图片附件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    private void handleImageAttachment(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                       List<QwMsgTemplateSop.Attachment> attachments) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        if (StringUtils.isNotEmpty(set.getImgUrl())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                QwUploadImgResult result = qwApiService.uploadimgs(set.getImgUrl(), corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                if (result.getErrcode() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    QwMsgTemplateSop.Attachment attachment = new QwMsgTemplateSop.Attachment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setImagePicUrl(result.getUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                logger.error("图片上传失败", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    // 处理链接附件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    private void handleLinkAttachment(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                      List<QwMsgTemplateSop.Attachment> attachments) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        if (StringUtils.isNotEmpty(set.getLinkImageUrl())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+////                QwUploadImgResult result = qwApiService.uploadimgs(set.getLinkImageUrl(), corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+////                if (result.getErrcode() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    QwMsgTemplateSop.Attachment attachment = new QwMsgTemplateSop.Attachment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setType(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setLinkTitle(set.getLinkTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setLinkPicurl(set.getLinkImageUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setLinkDesc(set.getLinkDescribe()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setLinkUrl(set.getLinkUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+////                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                logger.error("链接图片上传失败", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    private void handleMiniProgramAttachment(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                             List<QwMsgTemplateSop.Attachment> attachments, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                                             Long courseId,CourseConfig config) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        if (StringUtils.isNotEmpty(set.getMiniprogramPage())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                String key = String.format("miniprogram:%s:%s", corpId, courseId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                String mediaId = redisCache.getCacheObject(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                if (StringUtils.isNotEmpty(mediaId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    QwMsgTemplateSop.Attachment attachment = new QwMsgTemplateSop.Attachment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setType(4); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+////                    attachment.setMiniProgramTitle(set.getMiniprogramTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    //强制限制 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    String title = set.getMiniprogramTitle() != null ? set.getMiniprogramTitle() : ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    int maxLength = 20; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setMiniProgramTitle(title.length() > maxLength ? title.substring(0, maxLength) : title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setMiniProgramPicMediaId(mediaId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    if (StringUtil.strIsNullOrEmpty(config.getMiniprogramAppid())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                        logger.error("小程序配置为空,设置成固定的默认值。"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                        attachment.setMiniProgramAppId("wxc84c6f789ba7f176"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                        attachment.setMiniProgramAppId(config.getMiniprogramAppid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachment.setMiniProgramPage(set.getMiniprogramPage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                    logger.error("未找到小程序图片mediaId, corpId:{}, courseId:{}", corpId, courseId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//                logger.error("获取小程序图片mediaId失败", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void createCorpMassSendingByUserLogs(String date) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long startTime = System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        logger.info("开始执行企业微信群发消息创建任务"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<QwSopLogs> qwSopLogsList = qwSopLogsMapper.selectSopLogsByCreateCorpMassSending(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (qwSopLogsList.isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.error("zyp \n【企微官方群发记录为空】"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Map<String, List<QwSopLogs>> grouped = qwSopLogsList.stream().collect( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Collectors.groupingBy(log -> log.getQwUserid() + "|" + log.getCorpId() + "|" + log.getSopId() + "|" + log.getUserLogsId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int threadCount = Math.min(10, Runtime.getRuntime().availableProcessors() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ExecutorService executor = Executors.newFixedThreadPool(threadCount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Queue<QwSopLogs> updateQueue = new ConcurrentLinkedQueue<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 并行提交所有分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<CompletableFuture<Void>> futures = grouped.values().stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .map(group -> CompletableFuture.runAsync(() -> handleGroup(group, updateQueue), executor)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 等待所有任务完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.error("批量并发执行异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            executor.shutdown(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!executor.awaitTermination(300, TimeUnit.SECONDS)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    logger.error("Executor 未完全关闭"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (InterruptedException ie) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Thread.currentThread().interrupt(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 批量更新发送状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        batchUpdate(updateQueue); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        long endTime = System.currentTimeMillis(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        logger.info("企业微信群发任务完成,总耗时:{} 毫秒,更新记录数:{}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                endTime - startTime, updateQueue.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void handleGroup(List<QwSopLogs> logsGroup, Queue<QwSopLogs> updateQueue) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String firstKey = logsGroup.get(0).getCorpId() + "|" + logsGroup.get(0).getQwUserid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] keyParts = firstKey.split("\\|"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String corpId = keyParts[0].trim(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String qwUserid = keyParts[1].trim(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwUser qwUser = qwExternalContactService.getQwUserByRedis(corpId, qwUserid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (qwUser == null || qwUser.getIsDel() != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("员工信息无效-不存在或被删除,corpId:{},userId:{}", corpId, qwUserid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logsGroup.forEach(log -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendStatus(3L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setRemark("员工信息无效"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    updateQueue.add(log); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 提取内容与目标客户列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String contentJson = logsGroup.get(0).getContentJson(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwSopTempSetting.Content content = JSON.parseObject(contentJson, QwSopTempSetting.Content.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (content == null || content.getSetting() == null || content.getSetting().isEmpty()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.warn("消息内容为空或格式异常,key={},json={} ", firstKey, contentJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logsGroup.forEach(log -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendStatus(3L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setRemark("消息内容为空或格式异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    updateQueue.add(log); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwMsgTemplateSop template = new QwMsgTemplateSop(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            template.setChatType("single"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            template.setAllowSelect(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            template.setSender(qwUserid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<String> externalUserIds = logsGroup.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .map(QwSopLogs::getExternalUserId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .filter(Objects::nonNull) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .map(String::trim) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .filter(s -> !s.isEmpty()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            template.setExternalUseridList(externalUserIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<QwMsgTemplateSop.Attachment> attachments = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 解析并填充消息体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (QwSopTempSetting.Content.Setting set : content.getSetting()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                processContent(set, corpId, template, attachments, content.getCourseId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            template.setAttachments(attachments); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 调用企业微信接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            QwAddMsgTemplateResult result = qwApiService.addMsgTemplateBySop(template, corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int errCode = result.getErrCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String errMsg = result.getErrMsg(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Integer nowSort = (errCode == 0 || errCode == 41063) ? 1 : 3; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String remark; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (errCode == 0 || errCode == 41063) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                remark = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else if (errCode == 45033) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                remark = "官方接口达到上限补发"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                remark = "官方有误,sop补发"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            LocalDateTime now = LocalDateTime.now(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String sendTime = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 收集更新项 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (QwSopLogs log : logsGroup) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (errCode == 0 || errCode == 41063) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendStatus(1L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setMsgId(result.getMsgId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendType(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendStatus(3L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setRemark(remark); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setReceivingStatus(0L); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSendTime(sendTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.setSort(nowSort); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                updateQueue.add(log); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (errCode != 0 && errCode != 41063) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("企业微信接口-消息发送失败-进入sop补偿,corpId:{},errCode:{},errMsg:{}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        corpId, errCode, errMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.error("处理分组异常", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 批量更新发送状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void batchUpdate(Collection<QwSopLogs> toUpdate) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (toUpdate.isEmpty()) return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        logger.info("开始批量更新,记录数量:{}", toUpdate.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<QwSopLogs> list = new ArrayList<>(toUpdate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        int batchSize = 500; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (int i = 0; i < list.size(); i += batchSize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            int end = Math.min(i + batchSize, list.size()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<QwSopLogs> subList = list.subList(i, end); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            qwSopLogsMapper.batchUpdateStatus(subList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     // 处理不同类型的内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void processContent(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                QwMsgTemplateSop templateSop, List<QwMsgTemplateSop.Attachment> attachments 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                ,Long courseId,CourseConfig config) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                QwMsgTemplateSop templateSop, List<QwMsgTemplateSop.Attachment> attachments,Long courseId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         switch (set.getContentType()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             case "1": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 templateSop.setTextContent(set.getValue()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1352,7 +1733,7 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 handleLinkAttachment(set, corpId, attachments); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             case "4": 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                handleMiniProgramAttachment(set, corpId, attachments,courseId,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                handleMiniProgramAttachment(set, corpId, attachments,courseId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1382,13 +1763,13 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                QwUploadImgResult result = qwApiService.uploadimgs(set.getLinkImageUrl(), corpId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                if (result.getErrcode() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    QwMsgTemplateSop.Attachment attachment = new QwMsgTemplateSop.Attachment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachment.setType(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachment.setLinkTitle(set.getLinkTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachment.setLinkPicurl(set.getLinkImageUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachment.setLinkDesc(set.getLinkDescribe()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachment.setLinkUrl(set.getLinkUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                QwMsgTemplateSop.Attachment attachment = new QwMsgTemplateSop.Attachment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachment.setType(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachment.setLinkTitle(set.getLinkTitle()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachment.setLinkPicurl(set.getLinkImageUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachment.setLinkDesc(set.getLinkDescribe()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachment.setLinkUrl(set.getLinkUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 logger.error("链接图片上传失败", e); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1396,9 +1777,7 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void handleMiniProgramAttachment(QwSopTempSetting.Content.Setting set, String corpId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                             List<QwMsgTemplateSop.Attachment> attachments, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                             Long courseId,CourseConfig config) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void handleMiniProgramAttachment(QwSopTempSetting.Content.Setting set, String corpId, List<QwMsgTemplateSop.Attachment> attachments,Long courseId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (StringUtils.isNotEmpty(set.getMiniprogramPage())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 String key = String.format("miniprogram:%s:%s", corpId, courseId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1413,16 +1792,8 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     String title = set.getMiniprogramTitle() != null ? set.getMiniprogramTitle() : ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     int maxLength = 20; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     attachment.setMiniProgramTitle(title.length() > maxLength ? title.substring(0, maxLength) : title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     attachment.setMiniProgramPicMediaId(mediaId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (StringUtil.strIsNullOrEmpty(config.getMiniprogramAppid())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        logger.error("小程序配置为空,设置成固定的默认值。"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        attachment.setMiniProgramAppId("wxc84c6f789ba7f176"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        attachment.setMiniProgramAppId(config.getMiniprogramAppid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    attachment.setMiniProgramAppId(set.getMiniprogramAppid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     attachment.setMiniProgramPage(set.getMiniprogramPage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     attachments.add(attachment); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1435,5 +1806,4 @@ public class QwSopLogsServiceImpl implements IQwSopLogsService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |