diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/entity/device/DeviceAlarmClockRecordEntity.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/entity/device/DeviceAlarmClockRecordEntity.java index 40239e2..036b087 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/entity/device/DeviceAlarmClockRecordEntity.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/entity/device/DeviceAlarmClockRecordEntity.java @@ -81,7 +81,7 @@ public class DeviceAlarmClockRecordEntity extends GenericEntity { @Column(name = "alarm_type", nullable = false) private Integer alarmType; - @Comment("服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐") + @Comment("服务端配合操作的动作:0:无相关动作(文本播放或者音乐) 1:IOT控制 2天气 4U3D动作 5音乐") @Column(name = "action_type") private Integer actionType; diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/request/device/DeviceAlarmClockRecordRequest.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/request/device/DeviceAlarmClockRecordRequest.java index e3bfd95..57a8f71 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/request/device/DeviceAlarmClockRecordRequest.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/request/device/DeviceAlarmClockRecordRequest.java @@ -111,7 +111,7 @@ public class DeviceAlarmClockRecordRequest implements java.io.Serializable { */ private Integer alarmType; /** - *服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐 + *服务端配合操作的动作:0:无相关动作(文本播放或者音乐) 1:IOT控制 2天气 4U3D动作 5音乐 */ private Integer actionType; /** diff --git a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/device/DeviceAlarmClockRecordResp.java b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/device/DeviceAlarmClockRecordResp.java index 48595d9..cf3b0e5 100644 --- a/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/device/DeviceAlarmClockRecordResp.java +++ b/iot-common/iot-data/src/main/java/com/qiuguo/iot/data/resp/device/DeviceAlarmClockRecordResp.java @@ -94,7 +94,7 @@ public class DeviceAlarmClockRecordResp { */ private Integer alarmType; /** - *服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐 + *服务端配合操作的动作:0:无相关动作(文本播放或者音乐) 1:IOT控制 2天气 4U3D动作 5音乐 */ private Integer actionType; /** diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/AlarmClockActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/AlarmClockActionCommand.java index f7d5179..7e50e6d 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/AlarmClockActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/AlarmClockActionCommand.java @@ -1,5 +1,6 @@ package com.qiuguo.iot.box.websocket.api.command; +import cn.hutool.extra.spring.SpringUtil; import com.qiuguo.iot.base.enums.AlarmRepeatEnum; import com.qiuguo.iot.base.enums.AskTypeEnum; import com.qiuguo.iot.base.enums.YesNo; @@ -48,12 +49,13 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom public Mono process(Action action, BaseSession baseSession) { log.info("闹钟 Action:{}", action.getAsk()); + if(StringUtils.isEmpty(action.getNoTimeAsk())){ + log.info("一个提醒后无有效动作"); + return Mono.just(false); + } ActionTime actionTime = action.getTime(); - action.setNoTimeAsk( - action.getNoTimeAsk() - .replace(action.getAction(), "") - .replace("我", "") - ); + + DeviceAlarmClockRecordRequest request; Integer day = null; if(actionTime.getDayOfWeek().size() > 0) { @@ -70,6 +72,7 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom ); request.setUserId(baseSession.getUserId()); request.setDeviceId(baseSession.getDeviceId()); + request.setRepeat(AlarmRepeatEnum.EVERY_DAY.getCode()); day = repeatDay; }else { @@ -98,6 +101,25 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom }); } } + + if(action. + getSystemTalkAnswerConfigEntity(). + getAnswerType(). + equals(AskTypeEnum.ALARM_CLOCK.getCode()) + ){ + action.setNoTimeAsk( + action.getNoTimeAsk() + .replace(action.getAction(), "") + .replace("我", "") + ); + request.setActionType(YesNo.NO.getCode()); + request.setAlarmType(YesNo.NO.getCode()); + }else{ + request.setAlarmType(YesNo.YES.getCode()); + request.setActionType(action.getSystemTalkAnswerConfigEntity().getAnswerType()); + action.getSystemTalkAnswerConfigEntity().setAnswerValueFaild("已有相关提醒"); + } + Integer rDay = day; return deviceAlarmClockRecordService .selectDeviceAlarmClockRecordByRequest(request) @@ -110,12 +132,14 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom alarmClock.setUserId(baseSession.getUserId()); alarmClock.setDeviceId(baseSession.getDeviceId()); alarmClock.setRepeatDay(rDay); - + alarmClock.setActionType(request.getActionType()); + alarmClock.setAlarmType(request.getAlarmType()); + if(!AskTypeEnum.TTS.getCode().equals(request.getActionType())){ + alarmClock.setAction(action.getNoTimeAsk()); + } alarmClock.setTime( Date.from(actionTime.getDetailTime().getLocalDateTime().atZone(ZoneId.systemDefault()).toInstant()) ); - - alarmClock.setAlarmType(YesNo.NO.getCode()); alarmClock.setRepeat(request.getRepeat()); if(!alarmClock.getRepeat().equals(AlarmRepeatEnum.ONE.getCode())){ alarmClock.setTitle("循环闹钟"); @@ -153,8 +177,8 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom }else{ //更新闹钟 Boolean isUpdate = false; - if(StringUtils.isEmpty(alarmClock.getReadText()) && - StringUtils.isEmpty(action.getNoTimeAsk()) && + if(StringUtils.isNotEmpty(alarmClock.getReadText()) && + StringUtils.isNotEmpty(action.getNoTimeAsk()) && !alarmClock.getReadText().contains(action.getNoTimeAsk())){ alarmClock.setReadText(alarmClock.getReadText() + "," + action.getNoTimeAsk()); log.info("修改提醒文案:{}", alarmClock); @@ -251,13 +275,29 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom SimpleDateFormat df = new SimpleDateFormat("H:m"); String v = df.format(alarm.getTime()); String[] p = v.split(":"); + if(!alarm.getRepeat().equals(AlarmRepeatEnum.ONE.getCode())){ + df = new SimpleDateFormat("yyyy-MM-dd"); + v = df.format(alarm.getTime()); + p = v.split("-"); + actionResp.setYear(Integer.parseInt(p[0])); + actionResp.setMonth(Integer.parseInt(p[1])); + actionResp.setDay(Integer.parseInt(p[2])); + } + actionResp.setHour(Integer.parseInt(p[0])); actionResp.setMinute(Integer.parseInt(p[1])); - actionResp.setType(alarm.getRepeat());; - actionResp.setReadText(alarm.getReadText()); + actionResp.setType(alarm.getRepeat()); + if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.ALARM_CLOCK.getCode())){ + actionResp.setReadText(alarm.getReadText()); + }else{ + df = new SimpleDateFormat("yyyy年M月d日H点m分"); + msg = df.format(alarm.getTime()) + alarm.getAction(); + } + actionResp.setSound(alarm.getSound()); actionResp.setAlarmType(YesNo.NO.getCode()); actionResp.setDayOfWeek(dayOfWeek); + actionResp.setAlarmType(alarm.getAlarmType()); //读取星期 resp.setAction(actionResp); resp.setType(AskTypeEnum.ALARM_CLOCK.getCode()); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/IotActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/IotActionCommand.java index eb51c68..4cdfcde 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/IotActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/IotActionCommand.java @@ -33,6 +33,9 @@ public class IotActionCommand extends ActionCommand implements IActionCommand{ @Resource protected DeviceUserBindService deviceUserBindService; + @Resource + private AlarmClockActionCommand alarmClockActionCommand; + public Mono process(Action action, BaseSession baseSession) { log.info("IOT物联网 Action:{}", action.getAsk()); @@ -60,6 +63,7 @@ public class IotActionCommand extends ActionCommand implements IActionCommand{ //判断action是否有所有、全部。一切 if(YesNo.YES.getCode().equals(action.getIgnore())){ //忽略词,控制所有设备 + return controllerDevice(action, binds.getData(), 0, baseSession); }else{ return baseWebSocketService.sendMessage(action, @@ -95,6 +99,11 @@ public class IotActionCommand extends ActionCommand implements IActionCommand{ List deviceUserBindEntitys, int i, BaseSession baseSession){ + if(action.getTime() != null){ + //定时查询天气 + log.info("定期执行物联网操作1"); + return alarmClockActionCommand.process(action, baseSession); + } if(i < deviceUserBindEntitys.size()){ DeviceUserBindEntity deviceUserBindEntity = deviceUserBindEntitys.get(i++); action.setDeviceUserBindEntity(deviceUserBindEntity); @@ -106,7 +115,11 @@ public class IotActionCommand extends ActionCommand implements IActionCommand{ } protected Mono controllerDevice(Action action, DeviceUserBindEntity deviceUserBindEntity, BaseSession baseSession) { - + if(action.getTime() != null){ + //定时查询天气 + log.info("定期执行物联网操作1"); + return alarmClockActionCommand.process(action, baseSession); + } SystemTalkBindDeviceRequest systemTalkBindDeviceRequest = new SystemTalkBindDeviceRequest(); systemTalkBindDeviceRequest.setCategoryCode(deviceUserBindEntity.getCategoryCode()); systemTalkBindDeviceRequest.setSystemTalkId(action.getSystemTalkAnswerConfigEntity().getId()); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java index ca9e03e..332c202 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/MusicActionCommand.java @@ -24,6 +24,8 @@ import java.util.ArrayList; public class MusicActionCommand extends ActionCommand implements IActionCommand{ @Resource protected MusicService musicService; + @Resource + private AlarmClockActionCommand alarmClockActionCommand; public Mono process(Action action, BaseSession baseSession) { log.info("音乐acion:{}", action.getAsk()); @@ -32,6 +34,11 @@ public class MusicActionCommand extends ActionCommand implements IActionCommand search = search.replaceAll(action.getPName(), ""); } BoxMessageResp resp = new BoxMessageResp(); + if(action.getTime() != null){ + //定时查询天气 + log.info("定期打开音乐播放"); + return alarmClockActionCommand.process(action, baseSession); + } if(action.getSystemTalkAnswerConfigEntity().getPlayType().equals(PlayEnum.START.getCode())){ return musicService.searchMusic(search, 1).defaultIfEmpty(new ArrayList<>()).flatMap(resultSongs -> { //BoxMessageResp resp = new BoxMessageResp(); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/U3DActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/U3DActionCommand.java index 0393083..e3eaef8 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/U3DActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/U3DActionCommand.java @@ -35,6 +35,9 @@ public class U3DActionCommand extends ActionCommand implements IActionCommand{ @Resource protected U3dActionService u3dActionService; + @Resource + private AlarmClockActionCommand alarmClockActionCommand; + public Mono process(Action action, BaseSession baseSession) { log.info("U3d Action:{}", action.getAsk()); @@ -60,6 +63,11 @@ public class U3DActionCommand extends ActionCommand implements IActionCommand{ resp.setText("抱歉,我还么学会跳舞"); return baseWebSocketService.sendMessage(action, baseSession, resp); }else{ + if(action.getTime() != null){ + // + log.info("定期跳舞"); + return alarmClockActionCommand.process(action, baseSession); + } return u3dActionService.selectU3dActionById(systemTalkBindU3d.getU3dActionId()) .flatMap(u3d -> { //获取跳舞配置,并随机一个 @@ -86,7 +94,11 @@ public class U3DActionCommand extends ActionCommand implements IActionCommand{ //return baseWebSocketService.sendMessage(action, baseSession, resp); }else{ //推送MQ换装 - + if(action.getTime() != null){ + //定时查询天气 + log.info("定期换装"); + return alarmClockActionCommand.process(action, baseSession); + } DeviceUserTalkRecordEntity talkRecord = new DeviceUserTalkRecordEntity(); talkRecord.setAskType(AskTypeEnum.U3D.getCode()); talkRecord.setAskValue(action.getAsk()); diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/WeatherActionCommand.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/WeatherActionCommand.java index 98274c1..b5da3f6 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/WeatherActionCommand.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/command/WeatherActionCommand.java @@ -17,6 +17,7 @@ import com.qiuguo.iot.third.nlp.action.Action; import com.qiuguo.iot.third.nlp.action.ActionTime; import com.qiuguo.iot.third.service.WeatherService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import reactor.core.publisher.Mono; @@ -35,6 +36,9 @@ public class WeatherActionCommand extends ActionCommand implements IActionComma @Value("${Ali.accesskeySecret}") private String accessKeySecret; + @Autowired + AlarmClockActionCommand alarmClockActionCommand; + protected static com.aliyun.alimt20181012.Client transClient = null; protected static com.aliyun.teautil.models.RuntimeOptions transRuntime = new com.aliyun.teautil.models.RuntimeOptions(); public Mono process(Action action, BaseSession baseSession) { @@ -59,7 +63,11 @@ public class WeatherActionCommand extends ActionCommand implements IActionComma return baseWebSocketService.sendMessage(action, baseSession, "该城市不支持天气查询", action.getSystemTalkAnswerConfigEntity().getAnswerType()); //return Mono.empty(); } - + if(action.getTime() != null){ + //定时查询天气 + log.info("定期查询天气"); + return alarmClockActionCommand.process(action, baseSession); + } TianqiapiItemResp item = null; if(StringUtils.isNotEmpty(action.getTime().getDateTime())){ diff --git a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/box/resp/ActionResp.java b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/box/resp/ActionResp.java index 2164912..d5f49e4 100644 --- a/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/box/resp/ActionResp.java +++ b/iot-modules/iot-box-websocket-api/src/main/java/com/qiuguo/iot/box/websocket/api/domain/box/resp/ActionResp.java @@ -26,6 +26,18 @@ public class ActionResp { * 分钟 */ Integer minute; + /** + * 年 + */ + Integer year; + /** + * 月 + */ + Integer month; + /** + * 天 + */ + Integer day; /** * 重复的星期 */