From f3d66a78795d59b753bf8d700ea48fc403347ee9 Mon Sep 17 00:00:00 2001 From: wulin Date: Sat, 18 Nov 2023 17:57:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=96=AD=E5=8F=A5=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/base/constans/RedisConstans.java | 2 ++ .../qiuguo/iot/base/utils/StringUtils.java | 12 ++++++- .../model/system/SystemTalkAnswerConfig.java | 6 ++++ .../system/SystemTalkAnswerConfigService.java | 7 ++++ .../iot/third/enums/ActionPartSpeechEnum.java | 2 +- ...Service.java => TongYiQianWenService.java} | 3 +- .../third/service/TongYiXinChenService.java | 2 -- .../iot/third/service/IpServiceTest.java | 7 ++-- .../api/service/BaseWebSocketService.java | 34 +++++++++++++++++-- 9 files changed, 62 insertions(+), 13 deletions(-) rename iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/{QWenService.java => TongYiQianWenService.java} (98%) diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/RedisConstans.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/RedisConstans.java index 67c95c8..d004b80 100644 --- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/RedisConstans.java +++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/constans/RedisConstans.java @@ -28,6 +28,8 @@ public class RedisConstans { public static String USER_BOX_INFO = "user_box_info:"; + public static String TONGYI_TALK_CONTENT = "tongyi_talk_content:"; + public static String TY_QUEUE_LIST = "ty_queue_list:"; //通义千问的前缀 /** * 阿里语音合成token diff --git a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java index 9c4a1e7..f3841c2 100644 --- a/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java +++ b/iot-common/iot-base/src/main/java/com/qiuguo/iot/base/utils/StringUtils.java @@ -53,7 +53,17 @@ public class StringUtils extends cn.hutool.core.util.StrUtil{ int b = old.lastIndexOf("\n"); int c = old.lastIndexOf(";"); int n = old.lastIndexOf("\\n"); - int m = Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n); + int o = old.lastIndexOf("!"); + int m = Math.max(Math.max(Math.max(Math.max(Math.max(d, j), Math.max(a, b)), c), n), o); + if(m < 0){ + //支持英文 + d = old.lastIndexOf(","); + j = old.lastIndexOf("."); + a = old.lastIndexOf(":"); + c = old.lastIndexOf(";"); + o = old.lastIndexOf("!"); + m = Math.max(Math.max(Math.max(Math.max(d, j), a), c), o); + } if (m > 0) { //清空 m++; diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/model/system/SystemTalkAnswerConfig.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/model/system/SystemTalkAnswerConfig.java index c59d5e7..7d706b5 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/model/system/SystemTalkAnswerConfig.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/model/system/SystemTalkAnswerConfig.java @@ -3,10 +3,16 @@ package com.qiuguo.iot.data.model.system; import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity; import lombok.Data; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ConcurrentHashMap; @Data public class SystemTalkAnswerConfig { ConcurrentHashMap exCommand; + /** + * 名字有长到段的排序 + */ + List keys;// SystemTalkAnswerConfigEntity systemTalkAnswerConfig; } diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java index e7e2096..515efbd 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/service/system/SystemTalkAnswerConfigService.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; /** *

@@ -86,6 +87,12 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService { + //systemTalkAnswerConfig.getExCommand() + systemTalkAnswerConfig.setKeys( + systemTalkAnswerConfig.getExCommand().keySet().stream().collect(Collectors.toList())); + systemTalkAnswerConfig.getKeys().sort((a, b) ->{ + return b.length() - a.length(); + }); log.info("配置扩展最多读取{}条,实际读取了:{},id:{}的{}条扩展指令", MAX_COUT, systemTalkAnswerConfig.getSystemTalkAnswerConfig().getAskKey(), diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java index 9f79e6f..921187f 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ActionPartSpeechEnum.java @@ -851,7 +851,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{ return entity.getSystemTalkAnswerConfig(); }else{ //找到扩展指令 - for (String key1 :entity.getExCommand().keySet()){ + for (String key1 :entity.getKeys()){ if(ask.contains(key1)){ return entity.getExCommand().get(key1); diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/QWenService.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiQianWenService.java similarity index 98% rename from iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/QWenService.java rename to iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiQianWenService.java index 9054c80..a6d2560 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/QWenService.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiQianWenService.java @@ -12,7 +12,6 @@ import com.qiuguo.iot.data.resp.qg.algorithm.QGResponse; import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest; import com.qiuguo.iot.data.resp.qg.algorithm.QWenReplyResponse; import com.qiuguo.iot.third.nlp.AliYunQianWen; -import io.reactivex.functions.Consumer; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.data.redis.core.ReactiveValueOperations; @@ -28,7 +27,7 @@ import java.util.stream.Collectors; @Slf4j @Service -public class QWenService implements ITongYi{ +public class TongYiQianWenService implements ITongYi{ @Resource private ReactiveStringRedisTemplate reactiveStringRedisTemplate; diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiXinChenService.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiXinChenService.java index 1dcf565..1074832 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiXinChenService.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/TongYiXinChenService.java @@ -32,8 +32,6 @@ import java.util.stream.Collectors; @Service public class TongYiXinChenService implements ITongYi{ - - protected static ConcurrentHashMap qianwenGroup = new ConcurrentHashMap<>(); @Override diff --git a/iot-common/iot-third/src/test/java/com/qiuguo/iot/third/service/IpServiceTest.java b/iot-common/iot-third/src/test/java/com/qiuguo/iot/third/service/IpServiceTest.java index 589e523..45a4bd6 100644 --- a/iot-common/iot-third/src/test/java/com/qiuguo/iot/third/service/IpServiceTest.java +++ b/iot-common/iot-third/src/test/java/com/qiuguo/iot/third/service/IpServiceTest.java @@ -4,26 +4,23 @@ import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest; import com.qiuguo.iot.data.resp.third.ThirdIpInfoResp; import com.qiuguo.iot.data.resp.third.ThirdRpcResp; import org.junit.jupiter.api.Test; -import org.springframework.beans.BeanUtils; import org.springframework.boot.test.context.SpringBootTest; import reactor.core.publisher.Mono; import javax.annotation.Resource; -import static org.junit.jupiter.api.Assertions.*; - /** * @author simon * @date 2023/9/21 * @description **/ -@SpringBootTest(classes = {IpService.class,QWenService.class}) +@SpringBootTest(classes = {IpService.class, TongYiQianWenService.class}) class IpServiceTest { @Resource private IpService ipService; @Resource - private QWenService qWenService; + private TongYiQianWenService qWenService; @Test void aa() { diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java index 478d175..0145d9f 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/service/BaseWebSocketService.java @@ -289,8 +289,8 @@ public class BaseWebSocketService implements IActionSendMessage { * @param baseSession * @param baseMessageResp * @param builder - * @param text - * @param n + * @param text 字符的总长度 + * @param n 从第几个字符开始 * @param length * @return */ @@ -390,4 +390,34 @@ public class BaseWebSocketService implements IActionSendMessage { }); } + /*public static void main(String[] args) { + String v = "我来讲一个英文故事给你听吧!Once upon a time, there was a little girl named Goldilocks. She went for a walk in the forest. Pretty soon, she came upon a house. She knocked and, when no one answered, she walked right in. At the table in the kitchen, there were three bowls of porridge. Goldilocks was hungry. She tasted the porridge from the first bowl. \"This porridge is too hot!\"she exclaimed. So, she tasted the porridge from the second bowl. \"This porridge is too cold,\"she said. So, she tasted the last bowl of porridge. \"Ahhh, this porridge is just right!\"she exclaimed happily. \"What a lovely house this is!\"she said to herself. She looked into the living room. There were chairs, a couch, and a rocking chair. Goldilocks walked over to the rocking chair. It was too big. Then she saw a chair that looked just right. She sat down in it and it was just right. Next, she saw a bed. The first bed she saw was too hard. The next bed was too soft. But the last bed was just right. Goldilocks lay down and went fast asleep. Suddenly, she heard a great noise downstairs. Someone was coming! She jumped out of bed, ran into the bathroom, and hid behind the door. Three bears entered the house. They came into the kitchen. \"Someone has been eating my porridge,\"said the first bear. \"Someone has been eating my porridge,\"said the second bear. \"Someone has been eating my porridge,\"said the third bear. \"And someone has been sitting in my chair.\"\"And someone has been sitting in my chair.\"\"And someone has been sitting in my chair.\"\"And someone has been sleeping in my bed.\"\"And someone has been sleeping in my bed.\"\"And someone has been sleeping in my bed.\"They followed the trail of footprints upstairs. When they got to the bedroom, Goldilocks heard them say, \"Someone has been sleeping in my bed.\"Goldilocks trembled with fear. She opened the bathroom door very slowly and peeked out. She saw three angry bears looking at her. She closed the door quickly and hid behind it. The bears broke down the door, and Goldilocks ran out of the house as fast as she could. She ran so fast that she fell down and broke all the bones in her body. And that is the end of the story of Goldilocks and the Three Bears."; + StringBuilder sb = new StringBuilder(); + pro(v, 0, v.length(), sb, 50); + } + + public static void pro(String text, int n, int length, StringBuilder builder, int ONE_MAX_TEXT){ + if(n < length){ + int start = n; + n += ONE_MAX_TEXT; + if(n > length){ + n = length; + } + String message = text.substring(start, n); + int status = 0; + if(n == length){ + status = 1; + } + message = StringUtils.getSendStr(builder, message, status == 1 ? true : false); + int m = n; + if(StringUtils.isNotEmpty(message)){ + + System.out.println(message); + pro(text, n, length, builder, ONE_MAX_TEXT); + }else if(n < length){ + pro(text, n, length, builder, ONE_MAX_TEXT); + } + } + }*/ + }