xw 1 день назад
Родитель
Сommit
ef45af8d14

+ 9 - 0
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -1149,6 +1149,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         }
         // 顺序处理每个 Setting,避免过多的并行导致线程开销
         for (QwSopTempSetting.Content.Setting setting : settings) {
+            if ("1".equals(setting.getContentType()) || "15".equals(setting.getContentType())) {
+                setting.applyRandomTextValue();
+            }
             switch (setting.getContentType()) {
                 //直播小程序单独
                 case "12":
@@ -1228,6 +1231,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
 
         // 顺序处理每个 Setting,避免过多的并行导致线程开销
         for (QwSopTempSetting.Content.Setting setting : settings) {
+            if ("1".equals(setting.getContentType()) || "15".equals(setting.getContentType())) {
+                setting.applyRandomTextValue();
+            }
             switch (setting.getContentType()) {
                 //直播小程序单独
                 case "12":
@@ -1323,6 +1329,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         }
         // 顺序处理每个 Setting,避免过多的并行导致线程开销
         for (QwSopTempSetting.Content.Setting setting : settings) {
+            if ("1".equals(setting.getContentType()) || "15".equals(setting.getContentType())) {
+                setting.applyRandomTextValue();
+            }
             switch (setting.getContentType()) {
                 //文字和短链一起
                 case "1":

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

@@ -150,6 +150,7 @@ public class AsyncQwAiChatSopService {
 
                     List<QwSopTempSetting.Content.Setting> settingList =new ArrayList<>();
                     QwSopTempSetting.Content.Setting setting = JSON.parseObject(content.getContent(), QwSopTempSetting.Content.Setting.class);
+                    setting.applyRandomTextValue();
 
                     LocalDateTime dateTime = LocalDateTime.of(currentDate, localTime);
                     LocalDateTime expiryDateTime = dateTime.plusMinutes(setting.getIntervalTime());

+ 33 - 0
fs-service/src/main/java/com/fs/qw/vo/QwSopCourseFinishTempSetting.java

@@ -1,10 +1,14 @@
 package com.fs.qw.vo;
 
 import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
 
 /**
 * 企微sop附件的消息内容
@@ -65,6 +69,12 @@ public class QwSopCourseFinishTempSetting implements Serializable,Cloneable{
         private String contentType;
         //文本
         private String value;
+
+        /** 是否开启随机发送:1-开启,0-关闭 */
+        private Integer isRandomSend;
+
+        /** 随机发送备选文案列表 */
+        private List<String> randomValueList;
         //图片
         private String imgUrl;
 
@@ -146,6 +156,25 @@ public class QwSopCourseFinishTempSetting implements Serializable,Cloneable{
          */
         private String content;
 
+        public boolean isRandomSendEnabled() {
+            return Objects.equals(isRandomSend, 1) || "1".equals(String.valueOf(isRandomSend));
+        }
+
+        public void applyRandomTextValue() {
+            if (!"1".equals(contentType) && !"15".equals(contentType)) {
+                return;
+            }
+            if (!isRandomSendEnabled() || randomValueList == null || randomValueList.isEmpty()) {
+                return;
+            }
+            List<String> validList = randomValueList.stream()
+                    .filter(StringUtils::isNotBlank)
+                    .collect(Collectors.toList());
+            if (!validList.isEmpty()) {
+                value = validList.get(ThreadLocalRandom.current().nextInt(validList.size()));
+            }
+        }
+
         @Override
         public Setting clone() {
             try {
@@ -160,6 +189,10 @@ public class QwSopCourseFinishTempSetting implements Serializable,Cloneable{
                 clone.setMiniprogramTitle(this.getMiniprogramTitle());
                 clone.setMiniprogramPicUrl(this.getMiniprogramPicUrl());
                 clone.setMiniprogramPage(this.getMiniprogramPage());
+                clone.setIsRandomSend(this.getIsRandomSend());
+                if (this.randomValueList != null) {
+                    clone.randomValueList = new ArrayList<>(this.randomValueList);
+                }
                 return clone;
             } catch (CloneNotSupportedException e) {
                 throw new AssertionError();

+ 35 - 0
fs-service/src/main/java/com/fs/qw/vo/QwSopTempSetting.java

@@ -1,10 +1,14 @@
 package com.fs.qw.vo;
 
 import lombok.Data;
+import org.apache.commons.lang3.StringUtils;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.stream.Collectors;
 
 /**
 * 企微sop附件的消息内容
@@ -89,6 +93,12 @@ public class QwSopTempSetting implements Serializable{
             private String contentType;
             //文本
             private String value;
+
+            /** 是否开启随机发送:1-开启,0-关闭 */
+            private Integer isRandomSend;
+
+            /** 随机发送备选文案列表 */
+            private List<String> randomValueList;
             //图片
             private String imgUrl;
             //链接标题
@@ -167,6 +177,27 @@ public class QwSopTempSetting implements Serializable{
             /** 订阅号文章链接(contentType=13时使用,透传给小程序端用于跳转) */
             private String articleUrl;
 
+            public boolean isRandomSendEnabled() {
+                return Objects.equals(isRandomSend, 1) || "1".equals(String.valueOf(isRandomSend));
+            }
+
+            /**
+             * 随机发送:从备选文案中随机选取一条写入 value
+             */
+            public void applyRandomTextValue() {
+                if (!"1".equals(contentType) && !"15".equals(contentType)) {
+                    return;
+                }
+                if (!isRandomSendEnabled() || randomValueList == null || randomValueList.isEmpty()) {
+                    return;
+                }
+                List<String> validList = randomValueList.stream()
+                        .filter(StringUtils::isNotBlank)
+                        .collect(Collectors.toList());
+                if (!validList.isEmpty()) {
+                    value = validList.get(ThreadLocalRandom.current().nextInt(validList.size()));
+                }
+            }
 
             @Override
             public Setting clone() {
@@ -185,6 +216,10 @@ public class QwSopTempSetting implements Serializable{
                     clone.setMiniprogramPage(this.getMiniprogramPage());
                     clone.setFileUrl(this.getFileUrl());
                     clone.setFileName(this.getFileName());
+                    clone.setIsRandomSend(this.getIsRandomSend());
+                    if (this.randomValueList != null) {
+                        clone.randomValueList = new ArrayList<>(this.randomValueList);
+                    }
                     return clone;
                 } catch (CloneNotSupportedException e) {
                     throw new AssertionError();

+ 4 - 0
fs-service/src/main/java/com/fs/sop/service/impl/SopUserLogsInfoServiceImpl.java

@@ -618,6 +618,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                     QwSopCourseFinishTempSetting setting = new QwSopCourseFinishTempSetting();
                     List<QwSopCourseFinishTempSetting.Setting> list = JSONArray.parseArray(param.getSetting(), QwSopCourseFinishTempSetting.Setting.class);
                     for (QwSopCourseFinishTempSetting.Setting st : list) {
+                        st.applyRandomTextValue();
 
                         //过滤违禁词
                         if ("1".equals(st.getContentType())) {
@@ -840,6 +841,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                     }
 
                     for (QwSopCourseFinishTempSetting.Setting st : list) {
+                        st.applyRandomTextValue();
 
                         //过滤违禁词
                         if ("1".equals(st.getContentType())) {
@@ -1103,6 +1105,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
 
                 List<QwSopCourseFinishTempSetting.Setting> list = JSONArray.parseArray(param.getSetting(),QwSopCourseFinishTempSetting.Setting.class);
                 for (QwSopCourseFinishTempSetting.Setting st : list) {
+                    st.applyRandomTextValue();
 
                     //过滤违禁词
                     if ("1".equals(st.getContentType())){
@@ -1694,6 +1697,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
         List<QwSopCourseFinishTempSetting.Setting> list = JSONArray.parseArray(param.getSetting(),QwSopCourseFinishTempSetting.Setting.class);
 
         for (QwSopCourseFinishTempSetting.Setting st : list) {
+            st.applyRandomTextValue();
 
             //过滤违禁词
             if ("1".equals(st.getContentType())){