增加古诗、时间

This commit is contained in:
wulin 2023-10-16 13:29:46 +08:00
parent fd4b22607e
commit ae040421ce
7 changed files with 76 additions and 14 deletions

View File

@ -14,6 +14,7 @@ public enum AskTypeEnum {
U3D(4, "U3D动作"),
MUSIC(5, "音乐,声音"),
TIME(6, "询问时间"),
POEM(7, "古诗"),
UPDATE(100, "固件升级"),
BOX_ON_LINE(101, "Box配网成功"),

View File

@ -69,7 +69,7 @@ public class SystemTalkAnswerConfigEntity extends GenericEntity<Long> {
@Column(name = "key_order", nullable = false)
private Long keyOrder;
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词")
@Comment("回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 7古诗、诗歌、诗 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词")
@Column(name = "answer_type", nullable = false)
private Integer answerType;

View File

@ -54,7 +54,7 @@ public class SystemTalkAnswerConfigRequest implements java.io.Serializable {
//关键字的排序越小越第一个匹配上
private Long keyOrder;
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 7古诗诗歌 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词
private Integer answerType;
/**

View File

@ -32,7 +32,7 @@ public class SystemTalkAnswerConfigResp {
//关键字的排序越小越第一个匹配上
private Long keyOrder;
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词
//回答类型0文本问答 1iOT控制 2天气 3闹钟 4U3D 5音乐声音 6询问时间 7古诗诗歌 100固件升级 101Box上线 200动作后必须跟的名称词 300秋果专有名词 400全部所有一切忽略词
private Integer answerType;
/**

View File

@ -20,4 +20,8 @@ public class BoxMessageResp extends BaseMessageResp {
* 天气
*/
WeatherResp weather;
/**
* 时间
*/
DateTimeResp time;
}

View File

@ -0,0 +1,35 @@
package com.qiuguo.iot.box.websocket.api.domain.box.resp;
import lombok.Data;
@Data
public class DateTimeResp {
/**
*
*/
String year;
/**
*
*/
String month;
/**
*
*/
String day;
/**
*
*/
String hour;
/**
*
*/
String minute;
/**
*
*/
String second;
/**
*
*/
String weak;
}

View File

@ -8,6 +8,7 @@ import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.ActionResp;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.BoxMessageResp;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.DateTimeResp;
import com.qiuguo.iot.box.websocket.api.domain.box.resp.WeatherResp;
import com.qiuguo.iot.data.constants.YunxiRabbitConst;
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
@ -129,7 +130,7 @@ public class BaseWebSocketProcess {
}
}
private void toQianWen(Action action, BaseSession baseSession){
private void toQianWen(Action action, BaseSession baseSession, Integer type){
baseSession.setRequestId(baseSession.getRequestId() + 1);
TongYiCommunicationRest tongYiCommunicationRest = new TongYiCommunicationRest();
tongYiCommunicationRest.setText(action.getAsk());
@ -159,7 +160,7 @@ public class BaseWebSocketProcess {
sb.append(old.substring(m));
old = old.substring(0, m);
normalSendMsg(baseSession, old, AskTypeEnum.TTS.getCode());
normalSendMsg(baseSession, old, type);
}else{
sb.append(message);
}
@ -192,6 +193,7 @@ public class BaseWebSocketProcess {
U3dMsg u3dMsg = new U3dMsg();
u3dMsg.setMsgType(U3dMsgTypeEnum.IOT.getCode());
u3dMsg.setMetaId(String.valueOf(metaId));
u3dMsg.setTime(System.currentTimeMillis());
u3dMsg.setScenceId(String.valueOf(action.getDeviceUserBindEntity().getScenceId()));
u3dMsg.setStatusId(String.valueOf(systemTalkBindDeviceEntity.getU3dStatusId()));
sendMq(JSONObject.toJSONString(u3dMsg));
@ -205,7 +207,7 @@ public class BaseWebSocketProcess {
u3dMsg.setScenceId("0");
u3dMsg.setExParam(systemTalkBindU3dEntity.getAnswerAction());
u3dMsg.setStatusId(String.valueOf(systemTalkBindU3dEntity.getU3dStatusId()));
u3dMsg.setTime(System.currentTimeMillis());
sendMq(JSONObject.toJSONString(u3dMsg));
}
@ -229,7 +231,7 @@ public class BaseWebSocketProcess {
Action action = new Action();
action.setAsk(actions.getRecordText());
action.setAction(actions.getRecordText());
toQianWen(action, baseSession);
toQianWen(action, baseSession, AskTypeEnum.TTS.getCode());
return;
}
//boolean isToQianWen = false;
@ -238,7 +240,7 @@ public class BaseWebSocketProcess {
log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity());
if(action.getSystemTalkAnswerConfigEntity() == null){
log.info("调用千问{}", action.getAsk());
toQianWen(action, baseSession);
toQianWen(action, baseSession, AskTypeEnum.TTS.getCode());
return;
//
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){
@ -415,12 +417,8 @@ public class BaseWebSocketProcess {
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.TTS.getCode())){
if(!action.getAction().equals(action.getAsk())){
toQianWen(action, baseSession);
toQianWen(action, baseSession, AskTypeEnum.TTS.getCode());
return;
/*if(!isToQianWen){
isToQianWen = true;
toQianWen(action, baseSession);
}*/
}else{
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode());
}
@ -428,7 +426,28 @@ public class BaseWebSocketProcess {
sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode());
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.TIME.getCode())){
DateTimeFormatter df = DateTimeFormatter.ofPattern(action.getSystemTalkAnswerConfigEntity().getAnswerValue());
sendMessage(action, baseSession, action.getTime().getDetailTime().format(df), AskTypeEnum.TTS.getCode());
if(this instanceof BoxWebSocketHandler){
DateTimeResp dateTimeResp = new DateTimeResp();
dateTimeResp.setYear(String.valueOf(action.getTime().getDetailTime().getYear()));
dateTimeResp.setMonth(String.valueOf(action.getTime().getDetailTime().getMonthValue()));
dateTimeResp.setDay(String.valueOf(action.getTime().getDetailTime().getDayOfMonth()));
dateTimeResp.setHour(String.valueOf(action.getTime().getDetailTime().getHour()));
dateTimeResp.setMinute(String.valueOf(action.getTime().getDetailTime().getMinute()));
dateTimeResp.setSecond(String.valueOf(action.getTime().getDetailTime().getSecond()));
dateTimeResp.setWeak(String.valueOf(action.getTime().getDetailTime().getDayOfWeek().getValue()));
BoxMessageResp resp = new BoxMessageResp();
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
resp.setText(action.getTime().getDetailTime().format(df));
resp.setTime(dateTimeResp);
sendMessage(action, baseSession, resp);
}else{
sendMessage(action, baseSession, action.getTime().getDetailTime().format(df), AskTypeEnum.TIME.getCode());
}
}else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.U3D.getCode())){
SystemTalkBindU3dRequest request = new SystemTalkBindU3dRequest();
request.setSystemTalkId(action.getSystemTalkAnswerConfigEntity().getId());
@ -465,6 +484,9 @@ public class BaseWebSocketProcess {
return systemTalkBindU3d;
}).subscribe();
}else{
toQianWen(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerType());
return;
}
}
}