增加设备调用闹钟功能

This commit is contained in:
wulin 2023-11-15 19:05:34 +08:00
parent c76b3fb768
commit ee30856dd1
3 changed files with 44 additions and 6 deletions

View File

@ -275,6 +275,8 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom
SimpleDateFormat df = new SimpleDateFormat("H:m");
String v = df.format(alarm.getTime());
String[] p = v.split(":");
actionResp.setHour(Integer.parseInt(p[0]));
actionResp.setMinute(Integer.parseInt(p[1]));
if(!alarm.getRepeat().equals(AlarmRepeatEnum.ONE.getCode())){
df = new SimpleDateFormat("yyyy-MM-dd");
v = df.format(alarm.getTime());
@ -284,8 +286,7 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom
actionResp.setDay(Integer.parseInt(p[2]));
}
actionResp.setHour(Integer.parseInt(p[0]));
actionResp.setMinute(Integer.parseInt(p[1]));
actionResp.setType(alarm.getRepeat());
if(action.getSystemTalkAnswerConfigEntity().getAnswerType().equals(AskTypeEnum.ALARM_CLOCK.getCode())){
actionResp.setReadText(alarm.getReadText());

View File

@ -6,4 +6,12 @@ import lombok.Data;
public class BoxTalkMessage {
String sn;
String message;
/**
* 消息类型 0 文本类型 1 闹钟
*/
Integer type;
/**
* 消息需要处理的id
*/
Long id;
}

View File

@ -17,11 +17,14 @@ import com.qiuguo.iot.box.websocket.api.domain.user.UserTalkMessage;
import com.qiuguo.iot.box.websocket.api.filter.LogMdcConfiguration;
import com.qiuguo.iot.box.websocket.api.filter.LogWebFilter;
import com.qiuguo.iot.box.websocket.api.service.BaseWebSocketService;
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
import com.qiuguo.iot.data.entity.device.DeviceInfoEntity;
import com.qiuguo.iot.data.entity.device.DeviceUserBindEntity;
import com.qiuguo.iot.data.request.device.DeviceUserBindRequest;
import com.qiuguo.iot.data.service.device.DeviceAlarmClockRecordService;
import com.qiuguo.iot.data.service.device.DeviceInfoService;
import com.qiuguo.iot.data.service.device.DeviceUserBindService;
import com.qiuguo.iot.data.service.device.DeviceUserTalkRecordService;
import com.qiuguo.iot.third.nlp.action.Actions;
import com.qiuguo.iot.third.service.NlpService;
import lombok.extern.slf4j.Slf4j;
@ -67,6 +70,9 @@ public class BoxWebSocketHandler implements WebSocketHandler {
@Resource
private SomeProperties lacProperties;
@Resource
private DeviceAlarmClockRecordService deviceAlarmClockRecordService;
@Override
public Mono<Void> handle(WebSocketSession session) {
@ -151,11 +157,32 @@ public class BoxWebSocketHandler implements WebSocketHandler {
return baseWebSocketService.closeSendMsg(boxSession, "设备信息不全", AskTypeEnum.TIME.getCode());
}
log.info("收到SN:{},消息:{}", boxTalkMessage.getSn(), boxTalkMessage.getMessage());
if(StringUtils.isEmpty(boxTalkMessage.getMessage())){
log.info("收到空字符串,不处理,请求编号+1");
boxSession.setRequestId(boxSession.getRequestId() + 1);
return Mono.empty();
if(boxTalkMessage.getType().equals(YesNo.NO.getCode())){
if(StringUtils.isEmpty(boxTalkMessage.getMessage())){
log.info("收到空字符串,不处理,请求编号+1");
boxSession.setRequestId(boxSession.getRequestId() + 1);
return Mono.empty();
}
}else{
return deviceAlarmClockRecordService.selectDeviceAlarmClockRecordById(boxTalkMessage.getId())
.defaultIfEmpty(new DeviceAlarmClockRecordEntity())
.flatMap(alarm -> {
if(alarm.getId() == null){
log.info("未找到相关闹钟");
return Mono.empty();
}else{
boxTalkMessage.setMessage(alarm.getAction());
return processMessage(boxSession, boxTalkMessage);
}
});
}
return processMessage(boxSession, boxTalkMessage);
}
private Mono<Void> processMessage(BoxSession boxSession, BoxTalkMessage boxTalkMessage){
return nlpService.getActionWithLacSingle(
boxSession.getUserId(),
boxTalkMessage.getMessage(),
@ -166,6 +193,8 @@ public class BoxWebSocketHandler implements WebSocketHandler {
});
}
private Mono<Void> disconnect(BoxSession boxSession){
MDC.put(LogMdcConfiguration.PRINT_LOG_ID, boxSession.getLogId());
BoxSession boxSession1 = baseWebSocketService.getBoxSessionWithSn(boxSession.getSn());