diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/u3d/U3dMsg.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/u3d/U3dMsg.java index 0ac8ec7..f3c3f9f 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/u3d/U3dMsg.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/u3d/U3dMsg.java @@ -15,22 +15,22 @@ public class U3dMsg { /** * msgType=0,1,3时数字人ID,msgType=3时设备所在虚拟世界ID */ - private Long metaId; + private String metaId; /** * 状态ID */ - private Long statusId; + private String statusId; /** * 场景ID */ - private Long scenceId; + private String scenceId; /** * 类型ID */ - private Long typeId; + private String typeId; /** * 扩展参数 diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ChinesePartSpeechEnum.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ChinesePartSpeechEnum.java index f12751c..f76b0fa 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ChinesePartSpeechEnum.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/enums/ChinesePartSpeechEnum.java @@ -201,7 +201,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{ if(actions.getB() == 1 && actions.getA() == 0){ //本名称没有找到对应的动作 action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity()); actions.getActions().add(action); actions.setLastName(action.getName());//lastName = action.getName(); @@ -266,7 +266,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{ if(actions.getB() == 1 && actions.getA() == 0){ //本名称没有找到对应的动作 action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity()); actions.getActions().add(action); actions.setLastName(action.getName()); @@ -416,7 +416,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{ List systemTalkAnswerConfigEntities, List includs, List commands){ - SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(actions.getName(), keyGroup); + SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup); if(entity != null){ if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){ systemTalkAnswerConfigEntities.add(entity); @@ -689,7 +689,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{ if(actions.getB() == 1 && actions.getA() == 0){ //本名称没有找到对应的动作 action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity()); actions.getActions().add(action); actions.setLastName(action.getName()); @@ -703,7 +703,7 @@ public enum ChinesePartSpeechEnum implements IChinesePartSpeech{ int index = Integer.parseInt(key.replace(">", "")); action.setDeviceUserBindEntity(includs.get(index)); actions.setName(""); - action.setName(action.getDeviceUserBindEntity().getBindName()); + action.setName(action.getDeviceUserBindEntity() == null ? null : action.getDeviceUserBindEntity().getBindName()); actions.setB(1); return action; } diff --git a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/NlpService.java b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/NlpService.java index 584a08f..fd30d2e 100644 --- a/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/NlpService.java +++ b/iot-common/iot-third/src/main/java/com/qiuguo/iot/third/service/NlpService.java @@ -139,11 +139,11 @@ public class NlpService { actions.setLastSystemTalkAnswerConfigEntity(action.getSystemTalkAnswerConfigEntity()); actions.setLastDeviceUserBindEntity(action.getDeviceUserBindEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); systemTalkAnswerConfigEntities.clear(); }else if(actions.getLastSystemTalkAnswerConfigEntity() != null){ action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity()); } @@ -162,7 +162,7 @@ public class NlpService { if(StringUtils.isNotEmpty(action.getName()) && actions.getA() == 0){ //这说明已经匹配到设备了,但是没有匹配到动作 action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); actions.setLastSystemTalkAnswerConfigEntity(null); actions.setLastName(""); actions.setLastDeviceUserBindEntity(null); @@ -193,10 +193,10 @@ public class NlpService { if(systemTalkAnswerConfigEntities.size() > 0){//指令按照优先级排序 systemTalkAnswerConfigEntities.sort(Comparator.comparing(SystemTalkAnswerConfigEntity::getKeyOrder)); action.setSystemTalkAnswerConfigEntity(systemTalkAnswerConfigEntities.get(0)); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); }else if(actions.getLastSystemTalkAnswerConfigEntity() != null){ action.setSystemTalkAnswerConfigEntity(actions.getLastSystemTalkAnswerConfigEntity()); - action.setAction(action.getSystemTalkAnswerConfigEntity().getAskKey()); + action.setAction(action.getSystemTalkAnswerConfigEntity() == null ? null : action.getSystemTalkAnswerConfigEntity().getAskKey()); action.setDeviceUserBindEntity(actions.getLastDeviceUserBindEntity()); } if(actions.getA() + actions.getB() > 0){ diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java index 26f2d22..b0da0de 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/handler/BaseWebSocketProcess.java @@ -98,11 +98,11 @@ public class BaseWebSocketProcess { if(U3dMsgTypeEnum.IOT.getCode().equals(u3dMsg.getMsgType())){ //物联网操作 DeviceUserBindRequest deviceBindRequest = new DeviceUserBindRequest(); - deviceBindRequest.setU3dId(u3dMsg.getMetaId()); - deviceBindRequest.setScenceId(u3dMsg.getScenceId()); + deviceBindRequest.setU3dId(Long.getLong(u3dMsg.getMetaId())); + deviceBindRequest.setScenceId(Long.getLong(u3dMsg.getScenceId())); deviceUserBindService.selectDeviceUserBindByRequest(deviceBindRequest).map(db ->{ SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest(); - systemTalkBindDeviceRequest.setU3dStatusId(u3dMsg.getStatusId()); + systemTalkBindDeviceRequest.setU3dStatusId(Long.getLong(u3dMsg.getStatusId())); systemTalkBindDeviceRequest.setCategoryCode(db.getCategoryCode()); systemTalkBindDeviceService.selectSystemTalkBindDeviceByRequest(systemTalkBindDeviceRequest).map(sd -> { TuyaQuery query = new TuyaQuery(); @@ -170,9 +170,9 @@ public class BaseWebSocketProcess { U3dMsg u3dMsg = new U3dMsg(); u3dMsg.setMsgType(U3dMsgTypeEnum.IOT.getCode()); - u3dMsg.setMetaId(metaId); - u3dMsg.setScenceId(action.getDeviceUserBindEntity().getScenceId()); - u3dMsg.setStatusId(systemTalkBindDeviceEntity.getU3dStatusId()); + u3dMsg.setMetaId(String.valueOf(metaId)); + u3dMsg.setScenceId(String.valueOf(action.getDeviceUserBindEntity().getScenceId())); + u3dMsg.setStatusId(String.valueOf(systemTalkBindDeviceEntity.getU3dStatusId())); sendMq(JSONObject.toJSONString(u3dMsg)); } @@ -180,10 +180,10 @@ public class BaseWebSocketProcess { U3dMsg u3dMsg = new U3dMsg(); u3dMsg.setMsgType(systemTalkBindU3dEntity.getU3dType()); - u3dMsg.setMetaId(metaId); - u3dMsg.setScenceId(0L); + u3dMsg.setMetaId(String.valueOf(metaId)); + u3dMsg.setScenceId("0"); u3dMsg.setExParam(systemTalkBindU3dEntity.getAnswerAction()); - u3dMsg.setStatusId(systemTalkBindU3dEntity.getU3dStatusId()); + u3dMsg.setStatusId(String.valueOf(systemTalkBindU3dEntity.getU3dStatusId())); sendMq(JSONObject.toJSONString(u3dMsg)); } @@ -204,23 +204,21 @@ public class BaseWebSocketProcess { protected void processAction(Actions actions, Long userId, BaseSession baseSession) { if(actions.getActions() == null || actions.getActions().size() == 0){ //调用千问回答\ - log.info("调用千问"); + log.info("调用千问{}", actions.getRecordText()); Action action = new Action(); action.setAsk(actions.getRecordText()); action.setAction(actions.getRecordText()); toQianWen(action, baseSession); return; } - boolean isToQianWen = false; + //boolean isToQianWen = false; for (Action action : actions.getActions() ) { log.info("匹配到自定义指令{}", action.getSystemTalkAnswerConfigEntity()); if(action.getSystemTalkAnswerConfigEntity() == null){ - if(!isToQianWen){ - isToQianWen = true;; - log.info("调用千问,千问只能调用一边"); - toQianWen(action, baseSession); - } + log.info("调用千问{}", action.getAsk()); + toQianWen(action, baseSession); + return; // }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.IOT.getCode())){ @@ -276,8 +274,12 @@ public class BaseWebSocketProcess { } }else{ + if(StringUtils.isEmpty(action.getName())){ + sendMessage(action, baseSession, "请说明确的设备名称", action.getSystemTalkAnswerConfigEntity().getAnswerType()); + }else{ + sendMessage(action, baseSession, "未找到对应的设备", action.getSystemTalkAnswerConfigEntity().getAnswerType()); + } - sendMessage(action, baseSession, "未找到对应的设备", action.getSystemTalkAnswerConfigEntity().getAnswerType()); } }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.WEATHER.getCode())){ @@ -286,7 +288,8 @@ public class BaseWebSocketProcess { if(action.getLbs() != null && action.getLbs().size() > 0){ //根据地址查询天气 // city = ; - req.setCity(action.getLbs().get(action.getLbs().size() - 1)); + req.setCity(action.getLbs().get(action.getLbs().size() - 1).replace("市", "") + .replace("区", "").replace("县", "")); }else{ //使用IP查询天气 req.setIp("115.205.2.137"); @@ -378,19 +381,19 @@ public class BaseWebSocketProcess { }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.TTS.getCode())){ if(!action.getAction().equals(action.getAsk())){ - if(!isToQianWen){ + toQianWen(action, baseSession); + return; + /*if(!isToQianWen){ isToQianWen = true; toQianWen(action, baseSession); - } - + }*/ }else{ sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode()); } - }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.QIU_GUO.getCode())){ sendMessage(action, baseSession, action.getSystemTalkAnswerConfigEntity().getAnswerValue(), AskTypeEnum.TTS.getCode()); }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.TIME.getCode())){ - DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy年M月d日 H时m分 星期E"); + DateTimeFormatter df = DateTimeFormatter.ofPattern(action.getSystemTalkAnswerConfigEntity().getAnswerValue()); sendMessage(action, baseSession, action.getTime().getDetailTime().format(df), AskTypeEnum.TTS.getCode()); }else if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.U3D.getCode())){ SystemTalkBindU3dRequest request = new SystemTalkBindU3dRequest();