闹钟增加物联网、U3D、音乐、天气等功能
This commit is contained in:
parent
2bf59f6942
commit
f9ceb81a00
@ -7,8 +7,8 @@ package com.qiuguo.iot.base.enums;
|
||||
// 0:响铃一次(time指定的时间) 1:每天 2:指定星期
|
||||
public enum AlarmRepeatEnum {
|
||||
ONE(0, "指定时间响铃一次"),
|
||||
EVERY_DAY(1, "每天"),
|
||||
WEEK(2, "指定星期"),
|
||||
EVERY_DAY(1, "循环"),
|
||||
SKIP_FREE(2, "循环跳过节假日"),
|
||||
;
|
||||
AlarmRepeatEnum(Integer c, String n){
|
||||
code = c;
|
||||
@ -16,4 +16,6 @@ public enum AlarmRepeatEnum {
|
||||
}
|
||||
private Integer code;
|
||||
private String name;
|
||||
|
||||
public Integer getCode() {return code;}
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
package com.qiuguo.iot.base.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Data
|
||||
public class ReturnDate {
|
||||
LocalDateTime localDateTime;
|
||||
/**
|
||||
* 0:上午、1:下午、2:晚上
|
||||
*/
|
||||
int ampm;
|
||||
/**
|
||||
* 0:无感 1:月 2:时 3:分
|
||||
*/
|
||||
int type;
|
||||
|
||||
public ReturnDate(LocalDateTime lt, int a, int t) {
|
||||
localDateTime = lt;
|
||||
ampm = a;
|
||||
type = t;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,17 +1,24 @@
|
||||
package com.qiuguo.iot.base.utils;
|
||||
|
||||
import com.qiuguo.iot.base.date.DateEnum;
|
||||
import com.qiuguo.iot.base.model.ReturnDate;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChineseDateTimeUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 基于当前时间的字符串转时间
|
||||
* @param c 时间字符串
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime getDateWithString(String c){
|
||||
return getDateTime(c.replace("的", ""), DateTimeUtils.getNowLocalDateTime(), 0, 0);
|
||||
public static ReturnDate getDateWithString(String c, List<Integer> dayOfWeek, List<Integer> dayOfMonth){
|
||||
return getDateTime(c.replace("的", ""), DateTimeUtils.getNowLocalDateTime(), 0, 0, dayOfWeek, dayOfMonth, false);
|
||||
}
|
||||
|
||||
private static int checkDayOfMonth(LocalDateTime localDateTime, int i){
|
||||
@ -42,18 +49,8 @@ public class ChineseDateTimeUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
private static LocalDateTime setDayOfMonth(String c, String key, LocalDateTime localDateTime, int ampm){
|
||||
int index = c.indexOf(key);
|
||||
int i = checkDayOfMonth(localDateTime, ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
|
||||
|
||||
|
||||
return getDateTime(
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withDayOfMonth(i).withHour(0).withMinute(0).withSecond(0),
|
||||
ampm,
|
||||
1);
|
||||
}
|
||||
|
||||
private static int checkDayOfWeek(int i){
|
||||
if(i > 7){
|
||||
i = 7;
|
||||
@ -62,30 +59,7 @@ public class ChineseDateTimeUtils {
|
||||
}
|
||||
return i;
|
||||
}
|
||||
private static LocalDateTime setDayOfWeek(String c, String key, LocalDateTime localDateTime){
|
||||
c = c.replace(key, "");
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c).intValue());
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
i = now - i;
|
||||
return localDateTime.minusDays(i);
|
||||
}
|
||||
|
||||
private static LocalDateTime setNextDayOfWeek(String c, String key, LocalDateTime localDateTime){
|
||||
c = c.replace(key, "");
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c).intValue());
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
i = 7 - now + i;
|
||||
return localDateTime.plusDays(i);
|
||||
}
|
||||
|
||||
private static LocalDateTime setLastDayOfWeek(String c, String key, LocalDateTime localDateTime){
|
||||
c = c.replace(key, "");
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c).intValue());
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
|
||||
i = 7 - i + now;
|
||||
return localDateTime.minusDays(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* 汉语时间字符串转时间
|
||||
@ -93,134 +67,163 @@ public class ChineseDateTimeUtils {
|
||||
* @param localDateTime 时间基础
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime getDateWithStringAndLocalDateTime(String c, LocalDateTime localDateTime){
|
||||
return getDateTime(c.replace("的", ""), localDateTime, 0, 0);
|
||||
public static ReturnDate getDateWithStringAndLocalDateTime(String c,
|
||||
LocalDateTime localDateTime,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth){
|
||||
return getDateTime(c.replace("的", ""), localDateTime, 0, 0, dayOfWeek, dayOfMonth, false);
|
||||
}
|
||||
/**
|
||||
* 汉语时间字符串转时间
|
||||
* @param c 时间字符串
|
||||
* @param localDateTime 时间基础
|
||||
* @param ampm 0:上午、1:下午、2:晚上
|
||||
* @param type 0:无感 1:月 2:时 3:分
|
||||
* @param type 0:无感 1:月 2:时 3:分 4:周几 5月几
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime getDateWithStringAndLocalDateTime(String c, LocalDateTime localDateTime, int ampm, int type){
|
||||
return getDateTime(c.replace("的", ""), localDateTime, ampm, type);
|
||||
public static ReturnDate getDateWithStringAndLocalDateTime(String c,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
int type, List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
return getDateTime(c.replace("的", ""), localDateTime, ampm, type, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
|
||||
private static LocalDateTime getDateTime(String c, LocalDateTime localDateTime, int ampm, int type){
|
||||
private static ReturnDate getDateTime(String c,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
int type,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
DateEnum dateEnu = null;
|
||||
for(DateEnum enum1 : DateEnum.values()){
|
||||
if(c.startsWith(enum1.getCode())){
|
||||
dateEnu = enum1;
|
||||
localDateTime = dateEnu.getDateTime(localDateTime);
|
||||
c = c.substring(enum1.getCode().length());
|
||||
localDateTime = getDateTime(c, localDateTime, dateEnu.getAmPm(), 0);
|
||||
break;
|
||||
return getDateTime(c, localDateTime, dateEnu.getAmPm(), 0, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
}
|
||||
if(dateEnu == null){
|
||||
if(dateEnu == null && StringUtils.isNotEmpty(c)){
|
||||
if(c.contains("年后")){
|
||||
return setYears(c, "年后", localDateTime, -1);
|
||||
return new ReturnDate(setYears(c, "年后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("年前")){
|
||||
return setYears(c, "年前", localDateTime, 1);
|
||||
return new ReturnDate(setYears(c, "年前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("年")){
|
||||
return setYear(c, "年", localDateTime, ampm);
|
||||
return setYear(c, "年", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("个月后")){
|
||||
return setMonths(c, "个月后", localDateTime, -1);
|
||||
return new ReturnDate(setMonths(c, "个月后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("个月前")){
|
||||
return setMonths(c, "个月前", localDateTime, 1);
|
||||
return new ReturnDate(setMonths(c, "个月前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("月后")){
|
||||
return setMonths(c, "月后", localDateTime, -1);
|
||||
return new ReturnDate(setMonths(c, "月后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("月前")){
|
||||
return setMonths(c, "月前", localDateTime, 1);
|
||||
return new ReturnDate(setMonths(c, "月前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("月份")){
|
||||
return setMonth(c, "月份", localDateTime, ampm);
|
||||
return setMonth(c, "月份", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("月")){
|
||||
return setMonth(c, "月", localDateTime, ampm);
|
||||
return setMonth(c, "月", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("上周")){//
|
||||
return setLastDayOfWeek(c, "上周", localDateTime);
|
||||
return setLastDayOfWeek(c, "上周", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("下周")){//
|
||||
return setNextDayOfWeek(c, "下周", localDateTime);
|
||||
return setNextDayOfWeek(c, "下周", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("上星期")){//
|
||||
return setLastDayOfWeek(c, "上星期", localDateTime);
|
||||
return setLastDayOfWeek(c, "上星期", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("下星期")){//
|
||||
return setNextDayOfWeek(c, "下星期", localDateTime);
|
||||
return setNextDayOfWeek(c, "下星期", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("周后")){//
|
||||
return setWeeks(c, "周后", localDateTime, -1);
|
||||
return new ReturnDate(setWeeks(c, "周后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("周前")){//
|
||||
return setWeeks(c, "周前", localDateTime, 1);
|
||||
return new ReturnDate(setWeeks(c, "周前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("星期后")){//
|
||||
return setWeeks(c, "周后", localDateTime, -1);
|
||||
return new ReturnDate(setWeeks(c, "周后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("星期前")){//
|
||||
return setWeeks(c, "星期前", localDateTime, 1);
|
||||
return new ReturnDate(setWeeks(c, "星期前", localDateTime, 1), ampm, type);
|
||||
}else if(c.indexOf("每周") == 0){//周几
|
||||
return setDayOfWeek(c, "每周", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.indexOf("周") == 0){//周几
|
||||
return setDayOfWeek(c, "周", localDateTime);
|
||||
return setDayOfWeek(c, "周", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.indexOf("周") > 0){//几周
|
||||
return setWeeks(c, "周", localDateTime, -1);
|
||||
return new ReturnDate(setWeeks(c, "周", localDateTime, -1), ampm, type);
|
||||
}else if(c.indexOf("每星期") == 0){//星期几
|
||||
return setDayOfWeek(c, "每星期", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.indexOf("星期") == 0){//星期几
|
||||
return setDayOfWeek(c, "星期", localDateTime);
|
||||
return setDayOfWeek(c, "星期", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.indexOf("星期") > 0){//几星期
|
||||
return setWeeks(c, "星期", localDateTime, -1);
|
||||
return new ReturnDate(setWeeks(c, "星期", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("天后")){
|
||||
return setDays(c, "天后", localDateTime, -1);
|
||||
return new ReturnDate(setDays(c, "天后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("天前")){
|
||||
return setDays(c, "天前", localDateTime, 1);
|
||||
return new ReturnDate(setDays(c, "天前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("每天")){
|
||||
int day = 1;
|
||||
while(day < 8){
|
||||
dayOfWeek.add(day);
|
||||
day++;
|
||||
}
|
||||
|
||||
return new ReturnDate(localDateTime, ampm, type);
|
||||
}else if(c.contains("天")){
|
||||
return setDayOfMonth(c, "天", localDateTime, ampm);
|
||||
return setDayOfMonth(c, "天", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("号")){
|
||||
return setDayOfMonth(c, "号", localDateTime, ampm);
|
||||
return setDayOfMonth(c, "号", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("日")){
|
||||
return setDayOfMonth(c, "日", localDateTime, ampm);
|
||||
return setDayOfMonth(c, "日", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("小时后")){
|
||||
return setHours(c, "小时后", localDateTime, -1);
|
||||
return new ReturnDate(setHours(c, "小时后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("小时前")){
|
||||
return setHours(c, "小时前", localDateTime, 1);
|
||||
return new ReturnDate(setHours(c, "小时前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("小时")){
|
||||
return setHours(c, "小时", localDateTime, -1);
|
||||
return new ReturnDate(setHours(c, "小时", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("点钟后")){
|
||||
return setHours(c, "点钟后", localDateTime, -1);
|
||||
return new ReturnDate(setHours(c, "点钟后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("点钟前")){
|
||||
return setHours(c, "点钟前", localDateTime, 1);
|
||||
return new ReturnDate(setHours(c, "点钟前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("点钟")){
|
||||
return setHour(c, "点钟", localDateTime, ampm);
|
||||
return setHour(c, "点钟", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("点前")){
|
||||
return setHours(c, "点前", localDateTime, 1);
|
||||
return new ReturnDate(setHours(c, "点前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("点后")){
|
||||
return setHours(c, "点后", localDateTime, -1);
|
||||
return new ReturnDate(setHours(c, "点后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("点")){
|
||||
return setHour(c, "点", localDateTime, ampm);
|
||||
return setHour(c, "点", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("时后")){
|
||||
return setHours(c, "时后", localDateTime, -1);
|
||||
return new ReturnDate(setHours(c, "时后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("时前")){
|
||||
return setHours(c, "时前", localDateTime, 1);
|
||||
return new ReturnDate(setHours(c, "时前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("时")){
|
||||
return setHour(c, "时", localDateTime, ampm);
|
||||
return setHour(c, "时", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("分钟后")){
|
||||
return setMinutes(c, "分钟后", localDateTime, -1);
|
||||
return new ReturnDate(setMinutes(c, "分钟后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("分钟前")){
|
||||
return setMinutes(c, "分钟前", localDateTime, 1);
|
||||
return new ReturnDate(setMinutes(c, "分钟前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("分钟")){
|
||||
return setMinute(c, "分钟", localDateTime, ampm);
|
||||
return setMinute(c, "分钟", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("分")){
|
||||
return setMinute(c, "分", localDateTime, ampm);
|
||||
return setMinute(c, "分", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}else if(c.contains("秒后")){
|
||||
return setSeconds(c, "秒后", localDateTime, -1);
|
||||
return new ReturnDate(setSeconds(c, "秒后", localDateTime, -1), ampm, type);
|
||||
}else if(c.contains("秒前")){
|
||||
return setSeconds(c, "秒前", localDateTime, 1);
|
||||
return new ReturnDate(setSeconds(c, "秒前", localDateTime, 1), ampm, type);
|
||||
}else if(c.contains("秒")){
|
||||
return setSecond(c, "秒", localDateTime);
|
||||
return new ReturnDate(setSecond(c, "秒", localDateTime), ampm, type);
|
||||
}else if(c.length() > 0){
|
||||
//最后一个数字转换
|
||||
Integer i = ChineseToAlaboUtils.getLong(c).intValue();
|
||||
if(i > 0){
|
||||
if(type == 1){
|
||||
return localDateTime.withDayOfMonth(checkDayOfMonth(localDateTime, i));
|
||||
return new ReturnDate(localDateTime.withDayOfMonth(checkDayOfMonth(localDateTime, i)), ampm, type);
|
||||
}else if(type == 2){
|
||||
return localDateTime.withMinute(checkMinuteAndSecond(i));
|
||||
return new ReturnDate(localDateTime.withMinute(checkMinuteAndSecond(i)), ampm, type);
|
||||
}else if(type == 3){
|
||||
return localDateTime.withSecond(checkMinuteAndSecond(i));
|
||||
}
|
||||
return new ReturnDate(localDateTime.withSecond(checkMinuteAndSecond(i)), ampm, type);
|
||||
}else if(type == 4){
|
||||
return setDayOfWeek(c, "周", localDateTime, ampm, dayOfWeek, dayOfMonth, isBetween);
|
||||
}/*else if(type == 5){
|
||||
return setDayOfMonth(c, "月", localDateTime, ampm, dayOfWeek, dayOfMonth);
|
||||
}*/
|
||||
}
|
||||
|
||||
}else{
|
||||
@ -228,7 +231,130 @@ public class ChineseDateTimeUtils {
|
||||
}
|
||||
|
||||
}
|
||||
return localDateTime;
|
||||
return new ReturnDate(localDateTime, ampm, type);
|
||||
}
|
||||
|
||||
private static ReturnDate setDayOfMonth(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
int index = c.indexOf(key);
|
||||
if(index >= 0){
|
||||
c = c.substring(index + key.length());
|
||||
}
|
||||
int i = checkDayOfMonth(localDateTime, ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
|
||||
if(!dayOfMonth.contains(i)){
|
||||
dayOfMonth.add(i);
|
||||
}
|
||||
|
||||
return getDateTime(
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withDayOfMonth(i).withHour(0).withMinute(0).withSecond(0),
|
||||
ampm,
|
||||
1, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
|
||||
private static void addBetweanDay(List<Integer> day, int max){
|
||||
List<Integer> newList = day.stream().sorted().collect(Collectors.toList());
|
||||
int n = newList.size() - 1;
|
||||
|
||||
while(n >= 0){
|
||||
if(newList.get(n).intValue() == max){
|
||||
//
|
||||
n--;
|
||||
if(n >= 0){
|
||||
n = newList.get(n);
|
||||
}
|
||||
break;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
while(n < max){
|
||||
if(!day.contains(n)){
|
||||
day.add(n);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
private static ReturnDate setDayOfWeek(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
int index = c.indexOf(key);
|
||||
if(index >= 0){
|
||||
c = c.substring(index + key.length());
|
||||
}
|
||||
|
||||
//c = c.replace(key, "");
|
||||
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c.substring(0, 1)).intValue());
|
||||
if(!dayOfWeek.contains(i)){
|
||||
dayOfWeek.add(i);
|
||||
}
|
||||
if(isBetween){
|
||||
addBetweanDay(dayOfWeek, i);
|
||||
}
|
||||
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
i = now - i;
|
||||
return getDateTime(c.substring(1), localDateTime.minusDays(i), ampm, 4, dayOfWeek, dayOfMonth, isBetween);
|
||||
|
||||
}
|
||||
|
||||
private static ReturnDate setNextDayOfWeek(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
//c = c.replace(key, "");
|
||||
int index = c.indexOf(key);
|
||||
if(index >= 0){
|
||||
c = c.substring(index + key.length());
|
||||
}
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c.substring(0, 1)).intValue());
|
||||
/*if(!dayOfWeek.contains(i)){
|
||||
dayOfWeek.add(i);
|
||||
}
|
||||
if(isBetween){
|
||||
addBetweanDay(dayOfWeek, i);
|
||||
}*/
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
i = 7 - now + i;
|
||||
return getDateTime(c.substring(1), localDateTime.plusDays(i), ampm, 4, dayOfWeek, dayOfMonth, isBetween);
|
||||
//return localDateTime.plusDays(i);
|
||||
}
|
||||
|
||||
private static ReturnDate setLastDayOfWeek(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween){
|
||||
int index = c.indexOf(key);
|
||||
if(index >= 0){
|
||||
c = c.substring(index + key.length());
|
||||
}
|
||||
int i = checkDayOfWeek(ChineseToAlaboUtils.getLong(c.substring(0, 1)).intValue());
|
||||
/*if(!dayOfWeek.contains(i)){
|
||||
dayOfWeek.add(i);
|
||||
}
|
||||
if(isBetween){
|
||||
addBetweanDay(dayOfWeek, i);
|
||||
}*/
|
||||
int now = localDateTime.getDayOfWeek().getValue();
|
||||
|
||||
i = 7 - i + now;
|
||||
return getDateTime(c.substring(1), localDateTime.minusDays(i), ampm, 4, dayOfWeek, dayOfMonth, isBetween);
|
||||
//return localDateTime.minusDays(i);
|
||||
}
|
||||
|
||||
private static LocalDateTime setSecond(String c, String 秒, LocalDateTime localDateTime) {
|
||||
@ -265,14 +391,20 @@ public class ChineseDateTimeUtils {
|
||||
return localDateTime.minusWeeks(i);
|
||||
}
|
||||
|
||||
private static LocalDateTime setYear(String c, String key, LocalDateTime localDateTime, int ampm) {
|
||||
private static ReturnDate setYear(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween) {
|
||||
int index = c.indexOf(key);
|
||||
int i = ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue();
|
||||
return getDateTime(
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withYear(i),
|
||||
ampm,
|
||||
0);
|
||||
0, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
|
||||
|
||||
@ -306,14 +438,19 @@ public class ChineseDateTimeUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
private static LocalDateTime setMonth(String c, String key, LocalDateTime localDateTime, int ampm) {
|
||||
private static ReturnDate setMonth(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm, List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween) {
|
||||
int index = c.indexOf(key);
|
||||
int i = checkMonth(ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
|
||||
return getDateTime(
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withMonth(i),
|
||||
ampm,
|
||||
1);
|
||||
1, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
|
||||
private static int checkMinuteAndSecond(int i){
|
||||
@ -325,17 +462,29 @@ public class ChineseDateTimeUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
private static LocalDateTime setMinute(String c, String key, LocalDateTime localDateTime, int ampm) {
|
||||
private static ReturnDate setMinute(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween) {
|
||||
int index = c.indexOf(key);
|
||||
int i = checkMinuteAndSecond(ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue());
|
||||
return getDateTime(
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withMinute(i),
|
||||
ampm,
|
||||
3);
|
||||
3, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
|
||||
private static LocalDateTime setHour(String c, String key, LocalDateTime localDateTime, int ampm) {
|
||||
private static ReturnDate setHour(String c,
|
||||
String key,
|
||||
LocalDateTime localDateTime,
|
||||
int ampm,
|
||||
List<Integer> dayOfWeek,
|
||||
List<Integer> dayOfMonth,
|
||||
Boolean isBetween) {
|
||||
int index = c.indexOf(key);
|
||||
int i = ChineseToAlaboUtils.getLong(c.substring(0, index)).intValue();
|
||||
if(i > 23){
|
||||
@ -360,6 +509,6 @@ public class ChineseDateTimeUtils {
|
||||
c.substring(index + key.length()),
|
||||
localDateTime.withHour(i).withMinute(0).withSecond(0),
|
||||
ampm,
|
||||
2);
|
||||
2, dayOfWeek, dayOfMonth, isBetween);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
package com.qiuguo.iot.data.entity.device;
|
||||
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
|
||||
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
|
||||
import org.hswebframework.web.api.crud.entity.GenericEntity;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Table;import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* </p>*闹钟音乐表
|
||||
* @author wulin
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Comment("闹钟音乐表")
|
||||
@Table(name = "device_alarm_clock_music")
|
||||
@EnableEntityEvent
|
||||
public class DeviceAlarmClockMusicEntity extends GenericEntity<Long> {
|
||||
@Comment("id")
|
||||
@Column(name = "id", length = 11, nullable = false, unique = true)
|
||||
private Long id;
|
||||
|
||||
@Comment("是否删除:0 否 1 删除")
|
||||
@Column(name = "is_delete", nullable = false)
|
||||
private Integer isDelete;
|
||||
|
||||
@Comment("创建时间")
|
||||
@Column(name = "create_time")
|
||||
private Date createTime;
|
||||
|
||||
@Comment("修改时间")
|
||||
@Column(name = "modify_time")
|
||||
private Date modifyTime;
|
||||
|
||||
@Comment("音乐地址")
|
||||
@Column(name = "url", length = 255, nullable = false)
|
||||
private String url;
|
||||
|
||||
@Comment("音乐名称")
|
||||
@Column(name = "name", length = 100, nullable = false)
|
||||
private String name;
|
||||
|
||||
@Comment("备注说明")
|
||||
@Column(name = "remark", length = 255)
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@ -9,7 +9,7 @@ import java.util.Date;
|
||||
* <p>
|
||||
* </p>*闹钟记录表
|
||||
* @author wulin
|
||||
* @since 2023-11-13
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ -42,10 +42,14 @@ public class DeviceAlarmClockRecordEntity extends GenericEntity<Long> {
|
||||
private Long userId;
|
||||
|
||||
@Comment("第一次响铃的时间,循环响铃的时间(只取时间)")
|
||||
@Column(name = "time")
|
||||
@Column(name = "time", nullable = false)
|
||||
private Date time;
|
||||
|
||||
@Comment("重复次数:0:响铃一次(time指定的时间) 1:每天 2:指定星期 3 跳过节假日")
|
||||
@Comment("提醒的时间数。一天从0分钟开始,最大1440分钟")
|
||||
@Column(name = "times")
|
||||
private Integer times;
|
||||
|
||||
@Comment("重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日")
|
||||
@Column(name = "repeat", nullable = false)
|
||||
private Integer repeat;
|
||||
|
||||
@ -73,4 +77,16 @@ public class DeviceAlarmClockRecordEntity extends GenericEntity<Long> {
|
||||
@Column(name = "sound_name", length = 100, nullable = false)
|
||||
private String soundName;
|
||||
|
||||
@Comment("本地直接文本播放提醒的0:本地直接响铃提醒 1 请求服务器后动作")
|
||||
@Column(name = "alarm_type", nullable = false)
|
||||
private Integer alarmType;
|
||||
|
||||
@Comment("服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐")
|
||||
@Column(name = "action_type")
|
||||
private Integer actionType;
|
||||
|
||||
@Comment("服务端配合的动作内容;")
|
||||
@Column(name = "action", length = 255)
|
||||
private String action;
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.qiuguo.iot.data.request.device;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
*闹钟音乐请求类
|
||||
* @author wulin
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
|
||||
@Data
|
||||
public class DeviceAlarmClockMusicRequest implements java.io.Serializable {
|
||||
|
||||
private int currPage = 1;
|
||||
private int pageSize = 10;
|
||||
private String sort;
|
||||
private String order;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
*是否删除:0 否 1 删除
|
||||
*/
|
||||
private Integer isDelete;
|
||||
/**
|
||||
*创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
*创建时间搜索开始
|
||||
*/
|
||||
|
||||
private Date createTimeStart;
|
||||
|
||||
/**
|
||||
*创建时间搜索结束
|
||||
*/
|
||||
private Date createTimeEnd;
|
||||
/**
|
||||
*修改时间
|
||||
*/
|
||||
private Date modifyTime;
|
||||
/**
|
||||
*修改时间搜索开始
|
||||
*/
|
||||
|
||||
private Date modifyTimeStart;
|
||||
|
||||
/**
|
||||
*修改时间搜索结束
|
||||
*/
|
||||
private Date modifyTimeEnd;
|
||||
/**
|
||||
*音乐地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
*音乐名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
*备注说明
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
@ -5,7 +5,7 @@ import java.util.Date;
|
||||
* <p>
|
||||
*闹钟记录请求类
|
||||
* @author wulin
|
||||
* @since 2023-11-13
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
|
||||
@ -75,7 +75,11 @@ public class DeviceAlarmClockRecordRequest implements java.io.Serializable {
|
||||
*/
|
||||
private Date timeEnd;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:每天 2:指定星期 3 跳过节假日
|
||||
*提醒的时间数。一天从0分钟开始,最大1440分钟
|
||||
*/
|
||||
private Integer times;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日
|
||||
*/
|
||||
private Integer repeat;
|
||||
/**
|
||||
@ -102,4 +106,16 @@ public class DeviceAlarmClockRecordRequest implements java.io.Serializable {
|
||||
*响铃名称
|
||||
*/
|
||||
private String soundName;
|
||||
/**
|
||||
*本地直接文本播放提醒的0:本地直接响铃提醒 1 请求服务器后动作
|
||||
*/
|
||||
private Integer alarmType;
|
||||
/**
|
||||
*服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐
|
||||
*/
|
||||
private Integer actionType;
|
||||
/**
|
||||
*服务端配合的动作内容;
|
||||
*/
|
||||
private String action;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.qiuguo.iot.data.resp.device;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockMusicEntity;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* </p>*闹钟音乐返回类
|
||||
* @author wulin
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class DeviceAlarmClockMusicResp {
|
||||
public DeviceAlarmClockMusicResp(){
|
||||
}
|
||||
public DeviceAlarmClockMusicResp(DeviceAlarmClockMusicEntity entity){
|
||||
id = entity.getId();
|
||||
createTime = entity.getCreateTime();
|
||||
modifyTime = entity.getModifyTime();
|
||||
url = entity.getUrl();
|
||||
name = entity.getName();
|
||||
remark = entity.getRemark();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
*创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
*修改时间
|
||||
*/
|
||||
private Date modifyTime;
|
||||
/**
|
||||
*音乐地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
*音乐名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
*备注说明
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
@ -1,12 +1,12 @@
|
||||
package com.qiuguo.iot.data.resp.device;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
|
||||
/**
|
||||
* <p>
|
||||
* </p>*闹钟记录返回类
|
||||
* @author wulin
|
||||
* @since 2023-11-13
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Data
|
||||
@ -20,6 +20,7 @@ public class DeviceAlarmClockRecordResp {
|
||||
deviceId = entity.getDeviceId();
|
||||
userId = entity.getUserId();
|
||||
time = entity.getTime();
|
||||
times = entity.getTimes();
|
||||
repeat = entity.getRepeat();
|
||||
repeatDay = entity.getRepeatDay();
|
||||
title = entity.getTitle();
|
||||
@ -27,6 +28,9 @@ public class DeviceAlarmClockRecordResp {
|
||||
soundType = entity.getSoundType();
|
||||
sound = entity.getSound();
|
||||
soundName = entity.getSoundName();
|
||||
alarmType = entity.getAlarmType();
|
||||
actionType = entity.getActionType();
|
||||
action = entity.getAction();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +58,11 @@ public class DeviceAlarmClockRecordResp {
|
||||
*/
|
||||
private Date time;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:每天 2:指定星期 3 跳过节假日
|
||||
*提醒的时间数。一天从0分钟开始,最大1440分钟
|
||||
*/
|
||||
private Integer times;
|
||||
/**
|
||||
*重复次数:0:响铃一次(time指定的时间) 1:循环 2循环 跳过节假日
|
||||
*/
|
||||
private Integer repeat;
|
||||
/**
|
||||
@ -81,4 +89,16 @@ public class DeviceAlarmClockRecordResp {
|
||||
*响铃名称
|
||||
*/
|
||||
private String soundName;
|
||||
/**
|
||||
*本地直接文本播放提醒的0:本地直接响铃提醒 1 请求服务器后动作
|
||||
*/
|
||||
private Integer alarmType;
|
||||
/**
|
||||
*服务端配合操作的动作:1:IOT控制 2天气 4U3D动作 5音乐
|
||||
*/
|
||||
private Integer actionType;
|
||||
/**
|
||||
*服务端配合的动作内容;
|
||||
*/
|
||||
private String action;
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
package com.qiuguo.iot.data.service.device;
|
||||
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockMusicEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceAlarmClockMusicRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.ezorm.core.param.Sort;
|
||||
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
|
||||
import org.hswebframework.ezorm.rdb.mapping.ReactiveUpdate;
|
||||
import org.hswebframework.ezorm.rdb.operator.dml.query.SortOrder;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
||||
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 闹钟音乐服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceAlarmClockMusicService extends GenericReactiveCrudService<DeviceAlarmClockMusicEntity, Long> {
|
||||
|
||||
|
||||
public Mono<DeviceAlarmClockMusicEntity> selectDeviceAlarmClockMusicByRequest(DeviceAlarmClockMusicRequest request){
|
||||
ReactiveQuery<DeviceAlarmClockMusicEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
if(request.getId() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getId, request.getId());
|
||||
}
|
||||
if(request.getIsDelete() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getIsDelete, request.getIsDelete());
|
||||
}
|
||||
if(request.getCreateTime() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getCreateTime, request.getCreateTime());
|
||||
}
|
||||
if(request.getModifyTime() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getModifyTime, request.getModifyTime());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getUrl())){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getUrl, request.getUrl());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getName())){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getName, request.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getRemark())){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getRemark, request.getRemark());
|
||||
}
|
||||
SortOrder sortOrder = null;
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
|
||||
sortOrder = SortOrder.desc(request.getOrder());
|
||||
}else{
|
||||
sortOrder = SortOrder.asc(request.getOrder());
|
||||
}
|
||||
reactiveQuery = reactiveQuery.orderBy(sortOrder);
|
||||
}
|
||||
return reactiveQuery.fetchOne();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<PagerResult<DeviceAlarmClockMusicEntity>> selectDeviceAlarmClockMusicsByRequest(DeviceAlarmClockMusicRequest request){
|
||||
ReactiveQuery<DeviceAlarmClockMusicEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
if(request.getId() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getId, request.getId());
|
||||
}
|
||||
if(request.getIsDelete() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockMusicRequest::getIsDelete, request.getIsDelete());
|
||||
}
|
||||
if(request.getCreateTimeStart() != null){
|
||||
reactiveQuery = reactiveQuery.gte(DeviceAlarmClockMusicRequest::getCreateTime, request.getCreateTimeStart());
|
||||
}
|
||||
if(request.getCreateTimeEnd() != null){
|
||||
reactiveQuery = reactiveQuery.lte(DeviceAlarmClockMusicRequest::getCreateTime, request.getCreateTimeEnd());
|
||||
}
|
||||
if(request.getModifyTimeStart() != null){
|
||||
reactiveQuery = reactiveQuery.gte(DeviceAlarmClockMusicRequest::getModifyTime, request.getModifyTimeStart());
|
||||
}
|
||||
if(request.getModifyTimeEnd() != null){
|
||||
reactiveQuery = reactiveQuery.lte(DeviceAlarmClockMusicRequest::getModifyTime, request.getModifyTimeEnd());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getUrl())){
|
||||
reactiveQuery = reactiveQuery.$like$(DeviceAlarmClockMusicRequest::getUrl, request.getUrl());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getName())){
|
||||
reactiveQuery = reactiveQuery.$like$(DeviceAlarmClockMusicRequest::getName, request.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getRemark())){
|
||||
reactiveQuery = reactiveQuery.$like$(DeviceAlarmClockMusicRequest::getRemark, request.getRemark());
|
||||
}
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
Sort sort = new Sort();
|
||||
sort.setName(request.getOrder());
|
||||
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
|
||||
sort.desc();
|
||||
}else{
|
||||
sort.asc();
|
||||
}
|
||||
param.setSorts(Arrays.asList(sort));
|
||||
}
|
||||
param.setPageIndex(request.getCurrPage());
|
||||
param.setPageSize(request.getPageSize());
|
||||
param.setPaging(true);
|
||||
param.setFirstPageIndex(1);
|
||||
return queryPager(param);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<DeviceAlarmClockMusicEntity> selectDeviceAlarmClockMusicById(Long id){
|
||||
return createQuery()
|
||||
.and("is_delete", 0)
|
||||
.and("id", id)
|
||||
.fetchOne();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> insertDeviceAlarmClockMusic(DeviceAlarmClockMusicEntity entity){
|
||||
entity.setId(null);
|
||||
entity.setCreateTime(null);
|
||||
entity.setModifyTime(null);
|
||||
return insert(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> updateDeviceAlarmClockMusicById(DeviceAlarmClockMusicEntity entity){
|
||||
ReactiveUpdate<DeviceAlarmClockMusicEntity> update = createUpdate()
|
||||
.set(DeviceAlarmClockMusicEntity::getModifyTime, new Date());
|
||||
if(entity.getIsDelete() != null){
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getIsDelete, entity.getIsDelete());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getUrl())){
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getUrl, entity.getUrl());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getName())){
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getName, entity.getName());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getRemark())){
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getRemark, entity.getRemark());
|
||||
}
|
||||
return update.where(DeviceAlarmClockMusicEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> updateCoverDeviceAlarmClockMusicById(DeviceAlarmClockMusicEntity entity){
|
||||
ReactiveUpdate<DeviceAlarmClockMusicEntity> update = createUpdate()
|
||||
.set(DeviceAlarmClockMusicEntity::getModifyTime, new Date());
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getIsDelete, entity.getIsDelete());
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getUrl, entity.getUrl());
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getName, entity.getName());
|
||||
update = update.set(DeviceAlarmClockMusicEntity::getRemark, entity.getRemark());
|
||||
return update.where(DeviceAlarmClockMusicEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Mono<Integer> deleteDeviceAlarmClockMusicById(Long id){
|
||||
return createUpdate()
|
||||
.set("is_delete", 1)
|
||||
.set("modify_time", new Date())
|
||||
.where("id", id)
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
public Mono<DeviceAlarmClockMusicEntity> selectDeviceAlarmClockMusicByRand() {
|
||||
ReactiveQuery<DeviceAlarmClockMusicEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
Sort sort = new Sort();
|
||||
sort.setName("RAND()");
|
||||
sort.setType("RAND()");
|
||||
param.setSorts(Arrays.asList(sort));
|
||||
param.setPageIndex(1);
|
||||
param.setPageSize(1);
|
||||
param.setFirstPageIndex(1);
|
||||
return queryPager(param).flatMap(d -> {
|
||||
return Mono.just(d.getData().get(RandomUtil.randomInt(d.getData().size())));
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,6 @@ package com.qiuguo.iot.data.service.device;
|
||||
|
||||
import java.util.Date;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
|
||||
import com.qiuguo.iot.data.request.device.DeviceAlarmClockRecordRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.ezorm.core.param.Sort;
|
||||
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
|
||||
@ -16,16 +14,17 @@ import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
||||
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockRecordEntity;
|
||||
import com.qiuguo.iot.data.request.device.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.Date;
|
||||
/**
|
||||
* <p>
|
||||
* 闹钟记录服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-11-13
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@Service
|
||||
@ -57,6 +56,9 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(request.getTime() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getTime, request.getTime());
|
||||
}
|
||||
if(request.getTimes() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getTimes, request.getTimes());
|
||||
}
|
||||
if(request.getRepeat() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getRepeat, request.getRepeat());
|
||||
}
|
||||
@ -78,6 +80,15 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(StringUtils.isNotEmpty(request.getSoundName())){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getSoundName, request.getSoundName());
|
||||
}
|
||||
if(request.getAlarmType() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getAlarmType, request.getAlarmType());
|
||||
}
|
||||
if(request.getActionType() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getActionType, request.getActionType());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getAction())){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getAction, request.getAction());
|
||||
}
|
||||
SortOrder sortOrder = null;
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
if(StringUtils.isNotEmpty(request.getSort()) && request.getSort().compareTo("0") == 0){
|
||||
@ -125,6 +136,9 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(request.getTimeEnd() != null){
|
||||
reactiveQuery = reactiveQuery.lte(DeviceAlarmClockRecordRequest::getTime, request.getTimeEnd());
|
||||
}
|
||||
if(request.getTimes() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getTimes, request.getTimes());
|
||||
}
|
||||
if(request.getRepeat() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getRepeat, request.getRepeat());
|
||||
}
|
||||
@ -146,6 +160,15 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(StringUtils.isNotEmpty(request.getSoundName())){
|
||||
reactiveQuery = reactiveQuery.$like$(DeviceAlarmClockRecordRequest::getSoundName, request.getSoundName());
|
||||
}
|
||||
if(request.getAlarmType() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getAlarmType, request.getAlarmType());
|
||||
}
|
||||
if(request.getActionType() != null){
|
||||
reactiveQuery = reactiveQuery.and(DeviceAlarmClockRecordRequest::getActionType, request.getActionType());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(request.getAction())){
|
||||
reactiveQuery = reactiveQuery.$like$(DeviceAlarmClockRecordRequest::getAction, request.getAction());
|
||||
}
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
if(StringUtils.isNotEmpty(request.getOrder())){
|
||||
Sort sort = new Sort();
|
||||
@ -186,7 +209,7 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
|
||||
public Mono<Integer> updateDeviceAlarmClockRecordById(DeviceAlarmClockRecordEntity entity){
|
||||
ReactiveUpdate<DeviceAlarmClockRecordEntity> update = createUpdate()
|
||||
.set(DeviceAlarmClockRecordEntity::getModifyTime, new Date());
|
||||
.set(DeviceAlarmClockRecordEntity::getModifyTime, new Date());
|
||||
if(entity.getIsDelete() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getIsDelete, entity.getIsDelete());
|
||||
}
|
||||
@ -199,6 +222,9 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(entity.getTime() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getTime, entity.getTime());
|
||||
}
|
||||
if(entity.getTimes() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getTimes, entity.getTimes());
|
||||
}
|
||||
if(entity.getRepeat() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getRepeat, entity.getRepeat());
|
||||
}
|
||||
@ -220,6 +246,15 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
if(StringUtils.isNotEmpty(entity.getSoundName())){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getSoundName, entity.getSoundName());
|
||||
}
|
||||
if(entity.getAlarmType() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getAlarmType, entity.getAlarmType());
|
||||
}
|
||||
if(entity.getActionType() != null){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getActionType, entity.getActionType());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(entity.getAction())){
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getAction, entity.getAction());
|
||||
}
|
||||
return update.where(DeviceAlarmClockRecordEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
@ -227,11 +262,12 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
|
||||
public Mono<Integer> updateCoverDeviceAlarmClockRecordById(DeviceAlarmClockRecordEntity entity){
|
||||
ReactiveUpdate<DeviceAlarmClockRecordEntity> update = createUpdate()
|
||||
.set(DeviceAlarmClockRecordEntity::getModifyTime, new Date());
|
||||
.set(DeviceAlarmClockRecordEntity::getModifyTime, new Date());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getIsDelete, entity.getIsDelete());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getDeviceId, entity.getDeviceId());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getUserId, entity.getUserId());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getTime, entity.getTime());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getTimes, entity.getTimes());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getRepeat, entity.getRepeat());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getRepeatDay, entity.getRepeatDay());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getTitle, entity.getTitle());
|
||||
@ -239,6 +275,9 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getSoundType, entity.getSoundType());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getSound, entity.getSound());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getSoundName, entity.getSoundName());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getAlarmType, entity.getAlarmType());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getActionType, entity.getActionType());
|
||||
update = update.set(DeviceAlarmClockRecordEntity::getAction, entity.getAction());
|
||||
return update.where(DeviceAlarmClockRecordEntity::getId, entity.getId()).and("is_delete", 0).execute();
|
||||
}
|
||||
|
||||
@ -251,7 +290,4 @@ public class DeviceAlarmClockRecordService extends GenericReactiveCrudService<De
|
||||
.where("id", id)
|
||||
.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.qiuguo.iot.data.service.system;
|
||||
|
||||
import com.qiuguo.iot.base.enums.AskTypeEnum;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.data.entity.device.DeviceAlarmClockMusicEntity;
|
||||
import com.qiuguo.iot.data.entity.system.SystemTalkAnswerConfigEntity;
|
||||
import com.qiuguo.iot.data.entity.user.UserHandlingDeviceEntity;
|
||||
import com.qiuguo.iot.data.request.system.SystemTalkAnswerConfigRequest;
|
||||
@ -331,4 +332,23 @@ public class SystemTalkAnswerConfigService extends GenericReactiveCrudService<Sy
|
||||
public List<SystemTalkAnswerConfigEntity> getCommandList() {
|
||||
return groupCommand;
|
||||
}
|
||||
|
||||
public Mono<SystemTalkAnswerConfigEntity> selectSystemTalkAnswerConfigByRand() {
|
||||
ReactiveQuery<SystemTalkAnswerConfigEntity> reactiveQuery = createQuery();
|
||||
reactiveQuery = reactiveQuery.and("is_delete", 0);
|
||||
QueryParamEntity param = QueryParamEntity.of(reactiveQuery.getParam());
|
||||
Sort sort = new Sort();
|
||||
sort.setName("RAND()");
|
||||
sort.setType("RAND()");
|
||||
param.setSorts(Arrays.asList(sort));
|
||||
param.setPageIndex(1);
|
||||
param.setPageSize(1);
|
||||
param.setFirstPageIndex(1);
|
||||
Mono<PagerResult<SystemTalkAnswerConfigEntity>> data = queryPager(param);
|
||||
|
||||
return data.flatMap(r ->
|
||||
Mono.just(r.getData().get(0))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -412,19 +412,25 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
List<SystemTalkAnswerConfigEntity> systemTalkAnswerConfigEntities,
|
||||
List<DeviceUserBindEntity> includs,
|
||||
List<SystemTalkAnswerConfigEntity> commands){
|
||||
SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup);
|
||||
if(entity != null){
|
||||
if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){
|
||||
systemTalkAnswerConfigEntities.add(entity);
|
||||
actions.setA(1);
|
||||
}else{
|
||||
log.info("COMMAND_N自定义指令");
|
||||
}
|
||||
if(TIME.getCode().equals(actions.getLastCode())){
|
||||
//上个是时间词,可能后面数字也是时间词
|
||||
return t.getAction(keyGroup, key, actions, action, systemTalkAnswerConfigEntities, includs, commands);
|
||||
}else{
|
||||
SystemTalkAnswerConfigEntity entity = getSystemTalkWithKey(key, keyGroup);
|
||||
if(entity != null){
|
||||
if(!entity.getAnswerType().equals(AskTypeEnum.COMMAND_N.getCode())){
|
||||
systemTalkAnswerConfigEntities.add(entity);
|
||||
actions.setA(1);
|
||||
}else{
|
||||
log.info("COMMAND_N自定义指令");
|
||||
}
|
||||
|
||||
}else {
|
||||
action.setStatus(key);
|
||||
}else {
|
||||
action.setStatus(key);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
return action;
|
||||
|
||||
}
|
||||
},
|
||||
/*o(20, "拟声词"){
|
||||
@ -438,7 +444,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
List<SystemTalkAnswerConfigEntity> commands){
|
||||
return action;
|
||||
}
|
||||
},
|
||||
},*/
|
||||
p(21, "介词"){
|
||||
@Override
|
||||
public Action getAction(ConcurrentHashMap<String, SystemTalkAnswerConfigEntity> keyGroup,
|
||||
@ -452,7 +458,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
}
|
||||
},
|
||||
|
||||
r(22, "代词"){
|
||||
/*r(22, "代词"){
|
||||
@Override
|
||||
public Action getAction(ConcurrentHashMap<String, SystemTalkAnswerConfigEntity> keyGroup,
|
||||
String key,
|
||||
@ -501,7 +507,17 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
if(action.getTime() == null){
|
||||
action.setTime(new ActionTime());
|
||||
}
|
||||
action.getTime().setTime(key);
|
||||
if(StringUtils.isNotEmpty(actions.getLastKey()) &&
|
||||
(actions.getLastKey().contains("到") ||
|
||||
actions.getLastKey().contains("至")
|
||||
)
|
||||
){
|
||||
action.getTime().setTime(key, true);
|
||||
}else{
|
||||
action.getTime().setTime(key, false);
|
||||
}
|
||||
action.setNoTimeAsk(action.getNoTimeAsk().substring(action.getNoTimeAsk().indexOf(key) + key.length()));
|
||||
action.setNoTimeAsk(action.getNoTimeAsk().replaceAll(key, ""));
|
||||
return action;
|
||||
}
|
||||
},//LAC TIME
|
||||
@ -517,7 +533,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
return t.getAction(keyGroup, key, actions, action, systemTalkAnswerConfigEntities, includs, commands);
|
||||
}
|
||||
},//LAC TIME
|
||||
/* u(26, "助词"){
|
||||
u(26, "助词"){
|
||||
@Override
|
||||
public Action getAction(ConcurrentHashMap<String, SystemTalkAnswerConfigEntity> keyGroup,
|
||||
String key,
|
||||
@ -529,7 +545,7 @@ public enum ActionPartSpeechEnum implements IChinesePartSpeech{
|
||||
return action;
|
||||
}
|
||||
},
|
||||
vg(27, "动语素"){
|
||||
/*vg(27, "动语素"){
|
||||
@Override
|
||||
public Action getAction(ConcurrentHashMap<String, SystemTalkAnswerConfigEntity> keyGroup,
|
||||
String key,
|
||||
|
||||
@ -36,6 +36,10 @@ public class Action {
|
||||
* 动作程度结果(名词,量词)
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 替换时间词后的文案
|
||||
*/
|
||||
private String noTimeAsk;
|
||||
/**
|
||||
* 具体时间
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.qiuguo.iot.third.nlp.action;
|
||||
|
||||
import com.qiuguo.iot.base.model.ReturnDate;
|
||||
import com.qiuguo.iot.base.utils.ChineseDateTimeUtils;
|
||||
import com.qiuguo.iot.base.utils.DateTimeUtils;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
@ -10,6 +11,8 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Data
|
||||
@ -31,23 +34,39 @@ public class ActionTime {
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private LocalDateTime detailTime;
|
||||
private ReturnDate detailTime;
|
||||
|
||||
public void setTime(String t){
|
||||
LocalDateTime localDateTime;
|
||||
/**
|
||||
* 循环的周天
|
||||
*/
|
||||
List<Integer> dayOfWeek = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 循环的月天
|
||||
*/
|
||||
List<Integer> dayOfMonth = new ArrayList<>();
|
||||
|
||||
|
||||
public void setTime(String t, Boolean isBetween){
|
||||
ReturnDate returnDate;
|
||||
if(StringUtils.isNotEmpty(time)){
|
||||
localDateTime = detailTime;
|
||||
returnDate = ChineseDateTimeUtils.getDateWithStringAndLocalDateTime(t,
|
||||
detailTime.getLocalDateTime(),
|
||||
detailTime.getAmpm(),
|
||||
detailTime.getType(),
|
||||
dayOfWeek,
|
||||
dayOfMonth, isBetween);
|
||||
}else{
|
||||
time = t;
|
||||
localDateTime = DateTimeUtils.getNowLocalDateTime();
|
||||
returnDate = ChineseDateTimeUtils.getDateWithString(time, dayOfWeek, dayOfMonth);
|
||||
}
|
||||
|
||||
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
localDateTime = ChineseDateTimeUtils.getDateWithStringAndLocalDateTime(t, localDateTime);
|
||||
detailTime = localDateTime;
|
||||
dateTime = localDateTime.format(df);
|
||||
dateDetailTime = localDateTime.format(df1);
|
||||
|
||||
detailTime = returnDate;
|
||||
dateTime = returnDate.getLocalDateTime().format(df);
|
||||
dateDetailTime = returnDate.getLocalDateTime().format(df1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -30,6 +30,15 @@ public class Actions {
|
||||
* 记录最后一个匹配的名词
|
||||
*/
|
||||
String lastName = "";
|
||||
/**
|
||||
* 上一个词的属性
|
||||
*/
|
||||
Integer lastCode;
|
||||
|
||||
/**
|
||||
* 上一个词
|
||||
*/
|
||||
String lastKey;
|
||||
/**
|
||||
* 记录匹配到的最后一个系统配置指令
|
||||
*/
|
||||
|
||||
@ -147,6 +147,7 @@ public class NlpService {
|
||||
Action action = new Action();
|
||||
action.setLanguage(isEng ? LanguageEnum.ENGLISH.getCode() : LanguageEnum.CHINESE.getCode());
|
||||
actions.setRecordText(recordText);
|
||||
action.setNoTimeAsk(recordText);
|
||||
action.setLbs(new ArrayList<>());
|
||||
action.setAsk(actions.getRecordText());
|
||||
List<SystemTalkAnswerConfigEntity> systemTalkAnswerConfigEntities = new ArrayList<>();
|
||||
@ -157,13 +158,22 @@ public class NlpService {
|
||||
//空格跳过
|
||||
continue;
|
||||
}
|
||||
action = ActionPartSpeechEnum.getEnumWithCode(key.getType()).getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
|
||||
ActionPartSpeechEnum actionPartSpeechEnum = ActionPartSpeechEnum.getEnumWithCode(key.getType());
|
||||
|
||||
action = actionPartSpeechEnum.getAction(systemTalkAnswerConfigService.getSystemTalkWithKeyGroup(),
|
||||
key.getKey(),
|
||||
actions,
|
||||
action,
|
||||
systemTalkAnswerConfigEntities,
|
||||
includs,
|
||||
commands);
|
||||
if(!key.getType().equals(ActionPartSpeechEnum.u.getCode()) &&
|
||||
!key.getType().equals(ActionPartSpeechEnum.w.getCode())){//组词忽略记录
|
||||
actions.setLastCode(actionPartSpeechEnum.getCode());
|
||||
actions.setLastKey(key.getKey());
|
||||
}
|
||||
|
||||
if(actions.getA() + actions.getB() == 2){
|
||||
actions.setA(0);
|
||||
actions.setB(0);
|
||||
|
||||
@ -1,19 +1,118 @@
|
||||
package com.qiuguo.iot.box.websocket.api.command;
|
||||
|
||||
import com.qiuguo.iot.base.enums.AlarmRepeatEnum;
|
||||
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.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;
|
||||
import com.qiuguo.iot.data.service.system.SystemTalkAnswerConfigService;
|
||||
import com.qiuguo.iot.third.nlp.action.Action;
|
||||
import com.qiuguo.iot.third.nlp.action.ActionTime;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AlarmClockActionCommand extends ActionCommand implements IActionCommand{
|
||||
|
||||
@Resource
|
||||
DeviceAlarmClockRecordService deviceAlarmClockRecordService;
|
||||
|
||||
@Resource
|
||||
DeviceAlarmClockMusicService deviceAlarmClockMusicService;
|
||||
|
||||
@Resource
|
||||
SystemTalkAnswerConfigService systemTalkAnswerConfigService;
|
||||
|
||||
|
||||
public Mono<Boolean> process(Action action, BaseSession baseSession) {
|
||||
log.info("闹钟 Action:{}", action.getAsk());
|
||||
|
||||
ActionTime actionTime = action.getTime();
|
||||
action.setNoTimeAsk(
|
||||
action.getNoTimeAsk()
|
||||
.replace(action.getAction(), "")
|
||||
.replace("我", "")
|
||||
);
|
||||
if(actionTime.getDayOfWeek().size() > 0){
|
||||
//循环闹钟
|
||||
Integer repeatDay = 0;
|
||||
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.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{
|
||||
//提醒时间
|
||||
//Long nowTime = LocalDateTime.now().getLong();
|
||||
}
|
||||
return baseWebSocketService.sendMessage(action,
|
||||
baseSession ,
|
||||
action.getSystemTalkAnswerConfigEntity().getAnswerValue(),
|
||||
|
||||
@ -51,18 +51,18 @@ public class TimeActionCommand extends ActionCommand implements IActionCommand{
|
||||
}
|
||||
if(baseSession instanceof BoxSession){
|
||||
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()));
|
||||
dateTimeResp.setYear(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getYear()));
|
||||
dateTimeResp.setMonth(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getMonthValue()));
|
||||
dateTimeResp.setDay(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getDayOfMonth()));
|
||||
dateTimeResp.setHour(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getHour()));
|
||||
dateTimeResp.setMinute(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getMinute()));
|
||||
dateTimeResp.setSecond(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getSecond()));
|
||||
dateTimeResp.setWeak(String.valueOf(action.getTime().getDetailTime().getLocalDateTime().getDayOfWeek().getValue()));
|
||||
|
||||
BoxMessageResp resp = new BoxMessageResp();
|
||||
resp.setType(action.getSystemTalkAnswerConfigEntity().getAnswerType());
|
||||
|
||||
resp.setText(action.getAsk().replaceAll(action.getAction(), getDayOfWeek(action.getTime().getDetailTime().format(df))));
|
||||
resp.setText(action.getAsk().replaceAll(action.getAction(), getDayOfWeek(action.getTime().getDetailTime().getLocalDateTime().format(df))));
|
||||
resp.setTime(dateTimeResp);
|
||||
return baseWebSocketService.sendMessage(
|
||||
action,
|
||||
@ -73,7 +73,7 @@ public class TimeActionCommand extends ActionCommand implements IActionCommand{
|
||||
return baseWebSocketService.sendMessage(
|
||||
action,
|
||||
baseSession,
|
||||
action.getTime().getDetailTime().format(df),
|
||||
action.getTime().getDetailTime().getLocalDateTime().format(df),
|
||||
AskTypeEnum.TIME.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,10 +80,14 @@ public class WebsocketController {
|
||||
if(type == 0){
|
||||
systemTalkAnswerConfigService.initGroup();
|
||||
return Mono.just("重新读取指令完成");
|
||||
}else{
|
||||
}else if(type == 1){
|
||||
return reactiveStringRedisTemplate.opsForValue().delete(RedisConstans.ALI_TTS_TOKEN).flatMap(m -> {
|
||||
return Mono.just("Redis key已清除:" + RedisConstans.ALI_TTS_TOKEN);
|
||||
});
|
||||
}else{
|
||||
return systemTalkAnswerConfigService.selectSystemTalkAnswerConfigByRand().flatMap(m -> {
|
||||
return Mono.just(m.getAskKey());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ public class MysqlMain {
|
||||
}
|
||||
List<TablesBean> list = new ArrayList<>();
|
||||
|
||||
list.add(new TablesBean("device_alarm_clock_record"));
|
||||
list.add(new TablesBean("device_alarm_clock_music"));
|
||||
//list.add(new TablesBean("system_same_talk"));
|
||||
|
||||
List<TablesBean> list2 = new ArrayList<TablesBean>();
|
||||
|
||||
@ -0,0 +1,91 @@
|
||||
package com.admin.service.impl;
|
||||
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import reactor.core.publisher.Mono;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.exception.BusinessException;
|
||||
/**
|
||||
* <p>
|
||||
* 闹钟音乐Controller类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-11-14
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/DeviceAlarmClockMusic")
|
||||
public class DeviceAlarmClockMusicController{
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceAlarmClockMusicService deviceAlarmClockMusicService;
|
||||
@PostMapping("/info")
|
||||
public Mono<DeviceAlarmClockMusicResp> selectDeviceAlarmClockMusicByRequest(@RequestBody DeviceAlarmClockMusicRequest request){
|
||||
return deviceAlarmClockMusicService.selectDeviceAlarmClockMusicByRequest(request).map(d -> {return new DeviceAlarmClockMusicResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Mono<PagerResult<DeviceAlarmClockMusicResp>> selectDeviceAlarmClockMusicsByRequest(@RequestBody DeviceAlarmClockMusicRequest request){
|
||||
return deviceAlarmClockMusicService.selectDeviceAlarmClockMusicsByRequest(request).map(d -> {
|
||||
PagerResult<DeviceAlarmClockMusicResp> result = new PagerResult<>();
|
||||
result.setPageIndex(d.getPageIndex());
|
||||
result.setPageSize(d.getPageSize());
|
||||
result.setTotal(d.getTotal());
|
||||
List<DeviceAlarmClockMusicResp> ds = d.getData().stream().map(new Function<DeviceAlarmClockMusicEntity, DeviceAlarmClockMusicResp>() {
|
||||
@Override
|
||||
public DeviceAlarmClockMusicResp apply(DeviceAlarmClockMusicEntity entity) {
|
||||
return new DeviceAlarmClockMusicResp(entity);
|
||||
}
|
||||
}
|
||||
|
||||
).collect(Collectors.toList());
|
||||
result.setData(ds);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/id")
|
||||
public Mono<DeviceAlarmClockMusicResp> selectDeviceAlarmClockMusicById(@RequestParam Long id){
|
||||
return deviceAlarmClockMusicService.selectDeviceAlarmClockMusicById(id).map(d -> {return new DeviceAlarmClockMusicResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public Mono<Integer> insertDeviceAlarmClockMusic(@RequestBody DeviceAlarmClockMusicEntity entity){
|
||||
return deviceAlarmClockMusicService.insertDeviceAlarmClockMusic(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/update")
|
||||
public Mono<Integer> updateDeviceAlarmClockMusicById(@RequestBody DeviceAlarmClockMusicEntity entity){
|
||||
return deviceAlarmClockMusicService.updateDeviceAlarmClockMusicById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/updateCover")
|
||||
public Mono<Integer> updateCoverDeviceAlarmClockMusicById(@RequestBody DeviceAlarmClockMusicEntity entity){
|
||||
return deviceAlarmClockMusicService.updateCoverDeviceAlarmClockMusicById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Mono<Integer> deleteDeviceAlarmClockMusicById(@RequestParam Long id){
|
||||
return deviceAlarmClockMusicService.deleteDeviceAlarmClockMusicById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,91 +0,0 @@
|
||||
package com.admin.service.impl;
|
||||
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import reactor.core.publisher.Mono;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.hswebframework.web.api.crud.entity.PagerResult;
|
||||
import org.hswebframework.web.exception.BusinessException;
|
||||
/**
|
||||
* <p>
|
||||
* 闹钟记录Controller类
|
||||
* </p>
|
||||
*
|
||||
* @author wulin
|
||||
* @since 2023-11-13
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/DeviceAlarmClockRecord")
|
||||
public class DeviceAlarmClockRecordController{
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceAlarmClockRecordService deviceAlarmClockRecordService;
|
||||
@PostMapping("/info")
|
||||
public Mono<DeviceAlarmClockRecordResp> selectDeviceAlarmClockRecordByRequest(@RequestBody DeviceAlarmClockRecordRequest request){
|
||||
return deviceAlarmClockRecordService.selectDeviceAlarmClockRecordByRequest(request).map(d -> {return new DeviceAlarmClockRecordResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/list")
|
||||
public Mono<PagerResult<DeviceAlarmClockRecordResp>> selectDeviceAlarmClockRecordsByRequest(@RequestBody DeviceAlarmClockRecordRequest request){
|
||||
return deviceAlarmClockRecordService.selectDeviceAlarmClockRecordsByRequest(request).map(d -> {
|
||||
PagerResult<DeviceAlarmClockRecordResp> result = new PagerResult<>();
|
||||
result.setPageIndex(d.getPageIndex());
|
||||
result.setPageSize(d.getPageSize());
|
||||
result.setTotal(d.getTotal());
|
||||
List<DeviceAlarmClockRecordResp> ds = d.getData().stream().map(new Function<DeviceAlarmClockRecordEntity, DeviceAlarmClockRecordResp>() {
|
||||
@Override
|
||||
public DeviceAlarmClockRecordResp apply(DeviceAlarmClockRecordEntity entity) {
|
||||
return new DeviceAlarmClockRecordResp(entity);
|
||||
}
|
||||
}
|
||||
|
||||
).collect(Collectors.toList());
|
||||
result.setData(ds);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/id")
|
||||
public Mono<DeviceAlarmClockRecordResp> selectDeviceAlarmClockRecordById(@RequestParam Long id){
|
||||
return deviceAlarmClockRecordService.selectDeviceAlarmClockRecordById(id).map(d -> {return new DeviceAlarmClockRecordResp(d);});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/save")
|
||||
public Mono<Integer> insertDeviceAlarmClockRecord(@RequestBody DeviceAlarmClockRecordEntity entity){
|
||||
return deviceAlarmClockRecordService.insertDeviceAlarmClockRecord(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/update")
|
||||
public Mono<Integer> updateDeviceAlarmClockRecordById(@RequestBody DeviceAlarmClockRecordEntity entity){
|
||||
return deviceAlarmClockRecordService.updateDeviceAlarmClockRecordById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/updateCover")
|
||||
public Mono<Integer> updateCoverDeviceAlarmClockRecordById(@RequestBody DeviceAlarmClockRecordEntity entity){
|
||||
return deviceAlarmClockRecordService.updateCoverDeviceAlarmClockRecordById(entity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Mono<Integer> deleteDeviceAlarmClockRecordById(@RequestParam Long id){
|
||||
return deviceAlarmClockRecordService.deleteDeviceAlarmClockRecordById(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user