闹钟测试
This commit is contained in:
parent
f9ceb81a00
commit
ad3412c227
@ -47,7 +47,7 @@ public class DeviceAlarmClockRecordEntity extends GenericEntity<Long> {
|
||||
|
||||
@Comment("提醒的时间数。一天从0分钟开始,最大1440分钟")
|
||||
@Column(name = "times")
|
||||
private Integer times;
|
||||
private Long times;
|
||||
|
||||
@Comment("重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日")
|
||||
@Column(name = "repeat", nullable = false)
|
||||
|
||||
@ -77,7 +77,7 @@ public class DeviceAlarmClockRecordRequest implements java.io.Serializable {
|
||||
/**
|
||||
*提醒的时间数。一天从0分钟开始,最大1440分钟
|
||||
*/
|
||||
private Integer times;
|
||||
private Long times;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日
|
||||
*/
|
||||
|
||||
@ -60,7 +60,7 @@ public class DeviceAlarmClockRecordResp {
|
||||
/**
|
||||
*提醒的时间数。一天从0分钟开始,最大1440分钟
|
||||
*/
|
||||
private Integer times;
|
||||
private Long times;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日
|
||||
*/
|
||||
|
||||
@ -183,6 +183,7 @@ public class DeviceAlarmClockMusicService extends GenericReactiveCrudService<Dev
|
||||
|
||||
|
||||
public Mono<DeviceAlarmClockMusicEntity> selectDeviceAlarmClockMusicByRand() {
|
||||
//后期改成数据库直接返回RAND()
|
||||
ReactiveQuery<DeviceAlarmClockMusicEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
|
||||
@ -5,8 +5,9 @@ import com.qiuguo.iot.base.enums.AskTypeEnum;
|
||||
import com.qiuguo.iot.base.enums.YesNo;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
|
||||
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.data.entity.device.DeviceAlarmClockRecordEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceAlarmClockRecordRequest;
|
||||
import com.qiuguo.iot.data.service.device.DeviceAlarmClockMusicService;
|
||||
import com.qiuguo.iot.data.service.device.DeviceAlarmClockRecordService;
|
||||
@ -18,10 +19,14 @@ import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@ -35,6 +40,10 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom
|
||||
|
||||
@Resource
|
||||
SystemTalkAnswerConfigService systemTalkAnswerConfigService;
|
||||
/**
|
||||
* 超过这个时间的提醒才有效
|
||||
*/
|
||||
private static Long morTime = 50000L;
|
||||
|
||||
|
||||
public Mono<Boolean> process(Action action, BaseSession baseSession) {
|
||||
@ -45,79 +54,217 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom
|
||||
.replace(action.getAction(), "")
|
||||
.replace("我", "")
|
||||
);
|
||||
if(actionTime.getDayOfWeek().size() > 0){
|
||||
DeviceAlarmClockRecordRequest request;
|
||||
Integer day = null;
|
||||
if(actionTime.getDayOfWeek().size() > 0) {
|
||||
//循环闹钟
|
||||
Integer repeatDay = 0;
|
||||
for(Integer d: actionTime.getDayOfWeek()){
|
||||
for (Integer d : actionTime.getDayOfWeek()) {
|
||||
Integer o = 0x01 << d - 1;
|
||||
repeatDay |= o;
|
||||
}
|
||||
Integer times = actionTime.getDetailTime().getLocalDateTime().getHour() * 60 + actionTime.getDetailTime().getLocalDateTime().getMinute();
|
||||
//查询是否存在同样的提醒时间
|
||||
DeviceAlarmClockRecordRequest request = new DeviceAlarmClockRecordRequest();
|
||||
request.setTimes(times);
|
||||
request = new DeviceAlarmClockRecordRequest();
|
||||
request.setTimes(
|
||||
Long.valueOf(actionTime.getDetailTime().getLocalDateTime().getHour() * 60 + actionTime.getDetailTime().getLocalDateTime().getMinute())
|
||||
);
|
||||
request.setUserId(baseSession.getUserId());
|
||||
request.setDeviceId(baseSession.getDeviceId());
|
||||
request.setRepeat(AlarmRepeatEnum.EVERY_DAY.getCode());
|
||||
Integer rDay = repeatDay;
|
||||
return deviceAlarmClockRecordService
|
||||
.selectDeviceAlarmClockRecordByRequest(request)
|
||||
.defaultIfEmpty(new DeviceAlarmClockRecordEntity())
|
||||
.flatMap(alarmClock ->{
|
||||
if(alarmClock.getId() == null){
|
||||
//需要新建
|
||||
alarmClock.setTimes(times);
|
||||
alarmClock.setUserId(baseSession.getUserId());
|
||||
alarmClock.setDeviceId(baseSession.getDeviceId());
|
||||
alarmClock.setRepeatDay(rDay);
|
||||
alarmClock.setTitle("循环闹钟");
|
||||
alarmClock.setSoundType(YesNo.YES.getCode());
|
||||
alarmClock.setSoundName("随机");
|
||||
alarmClock.setAlarmType(YesNo.NO.getCode());
|
||||
alarmClock.setRepeat(AlarmRepeatEnum.EVERY_DAY.getCode());
|
||||
if(StringUtils.isNotEmpty(action.getNoTimeAsk())){
|
||||
alarmClock.setReadText(action.getNoTimeAsk());
|
||||
}
|
||||
String notice = action.getSystemTalkAnswerConfigEntity().getAnswerValue();
|
||||
if(alarmClock.getRepeatDay().intValue() == 0x7f){
|
||||
notice.replace("#day#", "每天");
|
||||
}else{
|
||||
deviceAlarmClockMusicService.selectDeviceAlarmClockMusicByRand();
|
||||
int o = 0x01;
|
||||
int day = alarmClock.getRepeatDay().intValue();
|
||||
String v = "";
|
||||
for(int i = 0; i < 7; i++){
|
||||
if((day & o) == o){
|
||||
v += "周" + (i + 1);
|
||||
o <<= 1;
|
||||
}
|
||||
}
|
||||
notice = notice.replace("#day#", v);
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("H点m分");
|
||||
notice = notice.replace("#time#", actionTime.getDetailTime().getLocalDateTime().format(df));
|
||||
}
|
||||
deviceAlarmClockRecordService.insert(alarmClock);
|
||||
}else{
|
||||
//更新闹钟
|
||||
alarmClock.setRepeatDay(alarmClock.getRepeatDay() | rDay);
|
||||
deviceAlarmClockRecordService.updateDeviceAlarmClockRecordById(alarmClock);
|
||||
}
|
||||
return baseWebSocketService.sendMessage(action,
|
||||
baseSession ,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),
|
||||
AskTypeEnum.ALARM_CLOCK.getCode()).flatMap(m -> {
|
||||
return Mono.empty();
|
||||
});
|
||||
});
|
||||
}else{
|
||||
day = repeatDay;
|
||||
}else {
|
||||
//提醒时间
|
||||
//Long nowTime = LocalDateTime.now().getLong();
|
||||
Duration duration = Duration.between(LocalDateTime.now(), actionTime.getDetailTime().getLocalDateTime());
|
||||
//- ;
|
||||
//相差毫秒数
|
||||
long millis = duration.toMillis();
|
||||
if(millis > morTime) {
|
||||
//大于1分钟
|
||||
request = new DeviceAlarmClockRecordRequest();
|
||||
Date date = Date.from(actionTime.getDetailTime().getLocalDateTime().atZone(ZoneId.systemDefault()).toInstant());
|
||||
request.setTimes(
|
||||
date.getTime()
|
||||
);
|
||||
//request.setTime(Date.from(actionTime.getDetailTime().getLocalDateTime().atZone(ZoneId.systemDefault()).toInstant()));
|
||||
request.setUserId(baseSession.getUserId());
|
||||
request.setDeviceId(baseSession.getDeviceId());
|
||||
request.setRepeat(AlarmRepeatEnum.ONE.getCode());
|
||||
|
||||
}else{
|
||||
return baseWebSocketService.sendMessage(action,
|
||||
baseSession ,
|
||||
"只能设置1分钟后的闹钟!",
|
||||
AskTypeEnum.EXIT.getCode()).flatMap(m -> {
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
return baseWebSocketService.sendMessage(action,
|
||||
baseSession ,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),
|
||||
AskTypeEnum.EXIT.getCode()).flatMap(m -> {
|
||||
return Mono.empty();
|
||||
});
|
||||
Integer rDay = day;
|
||||
return deviceAlarmClockRecordService
|
||||
.selectDeviceAlarmClockRecordByRequest(request)
|
||||
.defaultIfEmpty(new DeviceAlarmClockRecordEntity())
|
||||
.flatMap(alarmClock ->{
|
||||
if(alarmClock.getId() == null){
|
||||
|
||||
//需要新建
|
||||
alarmClock.setTimes(request.getTimes());
|
||||
alarmClock.setUserId(baseSession.getUserId());
|
||||
alarmClock.setDeviceId(baseSession.getDeviceId());
|
||||
alarmClock.setRepeatDay(rDay);
|
||||
|
||||
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("循环闹钟");
|
||||
}else{
|
||||
alarmClock.setTitle("一次性提醒");
|
||||
}
|
||||
log.info("新增闹钟:{}", alarmClock);
|
||||
|
||||
if(StringUtils.isNotEmpty(action.getNoTimeAsk())){
|
||||
//提示文案
|
||||
alarmClock.setReadText(action.getNoTimeAsk());
|
||||
alarmClock.setSoundType(YesNo.NO.getCode());
|
||||
alarmClock.setSoundName("文本提示");
|
||||
return addAlarmClockMessage(
|
||||
action,
|
||||
baseSession,
|
||||
alarmClock,
|
||||
request);
|
||||
}else{
|
||||
//随机音乐
|
||||
alarmClock.setSoundType(YesNo.YES.getCode());
|
||||
return deviceAlarmClockMusicService.selectDeviceAlarmClockMusicByRand().flatMap(
|
||||
music -> {
|
||||
alarmClock.setSoundName(music.getName());
|
||||
alarmClock.setSound(music.getUrl());
|
||||
return addAlarmClockMessage(
|
||||
action,
|
||||
baseSession,
|
||||
alarmClock,
|
||||
request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}else{
|
||||
//更新闹钟
|
||||
Boolean isUpdate = false;
|
||||
if(StringUtils.isEmpty(alarmClock.getReadText()) &&
|
||||
StringUtils.isEmpty(action.getNoTimeAsk()) &&
|
||||
!alarmClock.getReadText().contains(action.getNoTimeAsk())){
|
||||
alarmClock.setReadText(alarmClock.getReadText() + "," + action.getNoTimeAsk());
|
||||
log.info("修改提醒文案:{}", alarmClock);
|
||||
isUpdate = true;
|
||||
}
|
||||
if(!alarmClock.getRepeat().equals(AlarmRepeatEnum.ONE.getCode())){
|
||||
if((alarmClock.getRepeatDay().intValue() & rDay.intValue()) != rDay.intValue()) {
|
||||
alarmClock.setRepeatDay(alarmClock.getRepeatDay() | rDay);
|
||||
log.info("修改闹钟日期:{}", alarmClock);
|
||||
isUpdate = true;
|
||||
}
|
||||
}
|
||||
if(isUpdate){
|
||||
return deviceAlarmClockRecordService.updateDeviceAlarmClockRecordById(alarmClock).flatMap(i -> {
|
||||
action.getSystemTalkAnswerConfigEntity().setAnswerValue("修改闹钟," + action.getSystemTalkAnswerConfigEntity().getAnswerValue());
|
||||
return sendAlarmClockMessage(action, baseSession, alarmClock, request.getRepeat());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
log.info("不修改:{},添加的天数{}", alarmClock, rDay);
|
||||
return baseWebSocketService.sendMessage(action,
|
||||
baseSession ,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValueFaild(),
|
||||
AskTypeEnum.ALARM_CLOCK.getCode()).flatMap(m -> {
|
||||
return Mono.empty();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private Mono<Boolean> addAlarmClockMessage(Action action,
|
||||
BaseSession baseSession,
|
||||
DeviceAlarmClockRecordEntity alarmClock,
|
||||
DeviceAlarmClockRecordRequest request){
|
||||
|
||||
return deviceAlarmClockRecordService.insert(alarmClock).flatMap(i -> {
|
||||
return deviceAlarmClockRecordService.selectDeviceAlarmClockRecordByRequest(request).flatMap(
|
||||
alarm -> {
|
||||
return sendAlarmClockMessage(action, baseSession, alarm, request.getRepeat());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
private Mono<Boolean> sendAlarmClockMessage(Action action,
|
||||
BaseSession baseSession,
|
||||
DeviceAlarmClockRecordEntity alarm,
|
||||
Integer repeat){
|
||||
List<Integer> dayOfWeek = null;
|
||||
String msg = action.getSystemTalkAnswerConfigEntity().getAnswerValue();
|
||||
if(!repeat.equals(AlarmRepeatEnum.ONE.getCode())){
|
||||
if(alarm.getRepeatDay().intValue() == 0x7f){
|
||||
msg.replace("#day#", "每天");
|
||||
dayOfWeek = new ArrayList<Integer>(){
|
||||
{
|
||||
add(1);
|
||||
add(2);
|
||||
add(3);
|
||||
add(4);
|
||||
add(5);
|
||||
add(6);
|
||||
add(7);
|
||||
}
|
||||
};
|
||||
}else{
|
||||
dayOfWeek = new ArrayList<Integer>();
|
||||
int o = 0x01;
|
||||
int day = alarm.getRepeatDay().intValue();
|
||||
String v = "";
|
||||
for(int i = 0; i < 7; i++){
|
||||
if((day & o) == o){
|
||||
v += "周" + (i + 1);
|
||||
o <<= 1;
|
||||
dayOfWeek.add(i + 1);
|
||||
}
|
||||
}
|
||||
msg = msg.replace("#day#", v);
|
||||
SimpleDateFormat df = new SimpleDateFormat("H点m分");
|
||||
msg = msg.replace("#time#", df.format(alarm.getTime()));
|
||||
}
|
||||
}else{
|
||||
msg = msg.replace("#time#", "");
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy年M月d日H点m分");
|
||||
msg = msg.replace("#day#", df.format(alarm.getTime()));
|
||||
}
|
||||
|
||||
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
ActionResp actionResp = new ActionResp();
|
||||
actionResp.setId(alarm.getId());
|
||||
actionResp.setTime(alarm.getTime());
|
||||
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]));
|
||||
actionResp.setType(alarm.getRepeat());;
|
||||
actionResp.setReadText(alarm.getReadText());
|
||||
actionResp.setSound(alarm.getSound());
|
||||
actionResp.setAlarmType(YesNo.NO.getCode());
|
||||
actionResp.setDayOfWeek(dayOfWeek);
|
||||
//读取星期
|
||||
resp.setAction(actionResp);
|
||||
resp.setType(AskTypeEnum.ALARM_CLOCK.getCode());
|
||||
resp.setText(msg);
|
||||
|
||||
return baseWebSocketService.sendMessage(action, baseSession, resp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,20 +4,49 @@ import com.qiuguo.iot.data.resp.u3d.U3dBaseMsg;
|
||||
import com.qiuguo.iot.data.resp.u3d.U3dMsg;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ActionResp {
|
||||
/**
|
||||
* 闹钟类型0,一次闹钟 1 重复闹钟 7跳舞
|
||||
* 闹钟类型0,一次闹钟 1 重复闹钟 2重复跳过节假日(暂时不做) 7跳舞
|
||||
*/
|
||||
Integer type;
|
||||
/**
|
||||
* 时间
|
||||
* 对应ID,闹钟id
|
||||
*
|
||||
*/
|
||||
String time;
|
||||
Long id;
|
||||
/**
|
||||
* 声音地址
|
||||
* 小时
|
||||
*/
|
||||
Integer hour;
|
||||
/**
|
||||
* 分钟
|
||||
*/
|
||||
Integer minute;
|
||||
/**
|
||||
* 重复的星期
|
||||
*/
|
||||
List<Integer> dayOfWeek;
|
||||
/**
|
||||
* 闹铃播报的文案
|
||||
*/
|
||||
/**
|
||||
* 闹钟类型
|
||||
* 0:box直接播报 1 使用id请求服务器获得回应
|
||||
*/
|
||||
Integer alarmType;
|
||||
String readText;
|
||||
/**
|
||||
* 声音URL
|
||||
*/
|
||||
String sound;
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
Date time;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user