update:更新Layui版本
add:新增日历功能 add:预埋日历提醒到QQ功能
This commit is contained in:
51
src/main/java/com/yutou/tools/bean/CalendarTask.java
Normal file
51
src/main/java/com/yutou/tools/bean/CalendarTask.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.yutou.tools.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
@Data
|
||||
public class CalendarTask {
|
||||
public static final int TYPE_DAY=Calendar.DATE;
|
||||
public static final int TYPE_WEEK=Calendar.WEEK_OF_MONTH;
|
||||
public static final int TYPE_MONTH=Calendar.MONTH;
|
||||
|
||||
public static final int MODEL_ONE=0;
|
||||
public static final int MODEL_LOOP=1;
|
||||
|
||||
private int id;
|
||||
private int type;
|
||||
private int model=MODEL_ONE;
|
||||
private String title;
|
||||
private String content;
|
||||
private Date startTime;
|
||||
private Date endTime;
|
||||
private int time;
|
||||
private boolean qqbot;
|
||||
|
||||
public Date getEndTime() {
|
||||
if(endTime==null){
|
||||
Calendar calendar=Calendar.getInstance(Locale.CHINA);
|
||||
calendar.setTime(new Date());
|
||||
calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH)+1);
|
||||
endTime= calendar.getTime();
|
||||
}
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
if(startTime==null){
|
||||
startTime=new Date();
|
||||
}
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
if(time==0){
|
||||
time = (int) ((getEndTime().getTime() - getStartTime().getTime())/1000/60/60/24);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
}
|
||||
15
src/main/java/com/yutou/tools/bean/QQTimerTaskBean.java
Normal file
15
src/main/java/com/yutou/tools/bean/QQTimerTaskBean.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.yutou.tools.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
public class QQTimerTaskBean implements Serializable {
|
||||
private UUID uuid;
|
||||
private Date timer;
|
||||
private long qqNumber;
|
||||
private Object task;
|
||||
}
|
||||
88
src/main/java/com/yutou/tools/other/CalendarController.java
Normal file
88
src/main/java/com/yutou/tools/other/CalendarController.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.yutou.tools.other;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.aliyuncs.utils.StringUtils;
|
||||
import com.yutou.tools.bean.CalendarTask;
|
||||
import com.yutou.tools.utils.CalendarTools;
|
||||
import com.yutou.tools.utils.RedisTools;
|
||||
import com.yutou.tools.utils.Tools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
@Controller
|
||||
public class CalendarController {
|
||||
@ResponseBody
|
||||
@RequestMapping("/calendar/all.do")
|
||||
public JSONObject getCalendar(){
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject holiday= CalendarTools.getHoliday();
|
||||
json.put("data",holiday);
|
||||
return json;
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/calendar/set.do")
|
||||
public JSONObject setCalendar(String startDate
|
||||
,String title
|
||||
,String content
|
||||
,String type
|
||||
,String model
|
||||
,String day
|
||||
,String qqbot
|
||||
){
|
||||
JSONObject json = new JSONObject();
|
||||
String[] dates=startDate.split(" - ");
|
||||
Date sDate = Tools.timeToDate(dates[0].split(" ")[0], dates[0].split(" ")[1]);
|
||||
Date endDate = Tools.timeToDate(dates[1].split(" ")[0], dates[1].split(" ")[1]);
|
||||
CalendarTask task=new CalendarTask();
|
||||
task.setModel(Integer.parseInt(model));
|
||||
task.setType(Integer.parseInt(type));
|
||||
task.setTitle(title);
|
||||
task.setContent(content);
|
||||
task.setStartTime(sDate);
|
||||
task.setEndTime(endDate);
|
||||
task.setTime(Integer.parseInt(day));
|
||||
task.setQqbot(!StringUtils.isEmpty(qqbot));
|
||||
CalendarTools.addTask(task);
|
||||
json.put("code",0);
|
||||
json.put("msg","任务添加成功");
|
||||
json.put("data",task);
|
||||
return json;
|
||||
}
|
||||
@RequestMapping("/calendar/list.do")
|
||||
@ResponseBody
|
||||
public JSONObject list(){
|
||||
JSONObject json=new JSONObject();
|
||||
JSONArray array=new JSONArray();
|
||||
Set<String> set = RedisTools.list_get(CalendarTools.REDIS_TAG);
|
||||
for (String s : set) {
|
||||
JSONObject task = JSONObject.parseObject(s);
|
||||
array.add(task);
|
||||
}
|
||||
json.put("code",0);
|
||||
json.put("msg","ok");
|
||||
json.put("data",array);
|
||||
return json;
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/calendar/del.do")
|
||||
public JSONObject del(int id){
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("msg","删除失败");
|
||||
Set<String> set = RedisTools.list_get(CalendarTools.REDIS_TAG);
|
||||
for (String s : set) {
|
||||
CalendarTask calendar=JSONObject.parseObject(s,CalendarTask.class);
|
||||
if(calendar.getId()==id){
|
||||
json.put("msg","删除成功");
|
||||
RedisTools.list_remove(CalendarTools.REDIS_TAG,s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
json.put("code",0);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
104
src/main/java/com/yutou/tools/utils/CalendarTools.java
Normal file
104
src/main/java/com/yutou/tools/utils/CalendarTools.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.tools.bean.CalendarTask;
|
||||
import com.yutou.tools.interfaces.ITimerTask;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public class CalendarTools {
|
||||
public static final String REDIS_TAG = "Calendar";
|
||||
|
||||
public static JSONObject getHoliday() {
|
||||
int year = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.YEAR);
|
||||
return getHoliday(year + "");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static JSONObject getHoliday(String year) {
|
||||
String get = HttpTools.get(String.format("https://timor.tech/api/holiday/year/%s", year));
|
||||
JSONObject json = JSONObject.parseObject(get);
|
||||
JSONObject date = new JSONObject();
|
||||
JSONArray dateHoliday = new JSONArray();
|
||||
JSONObject holiday = json.getJSONObject("holiday");
|
||||
JSONArray a1=new JSONArray();
|
||||
JSONArray a2=new JSONArray();
|
||||
for (CalendarTask task : getTasks()) {
|
||||
for (String datum : getMouthData(task)) {
|
||||
date.put(new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat("yyyy-M-d").parse(datum.split(" ")[0])), task.getTitle());
|
||||
a1.add(datum.split(" ")[0]);
|
||||
a2.add(datum.split(" ")[0]);
|
||||
}
|
||||
}
|
||||
|
||||
for (String key : holiday.keySet()) {
|
||||
JSONObject _tmp = holiday.getJSONObject(key);
|
||||
date.put(year + "-" + key, _tmp.getString("name"));
|
||||
String _key=new SimpleDateFormat("yyyy-M-d").format(new SimpleDateFormat("yyyy-MM-dd").parse(year + "-" + key));
|
||||
if(_tmp.getBooleanValue("holiday")){
|
||||
a1.add(_key);
|
||||
}else{
|
||||
a2.add(_key);
|
||||
}
|
||||
}
|
||||
dateHoliday.add(a1);
|
||||
dateHoliday.add(a2);
|
||||
JSONObject tmp = new JSONObject();
|
||||
tmp.put("date", date);
|
||||
tmp.put("holiday", dateHoliday);
|
||||
return tmp;
|
||||
}
|
||||
public static boolean addTask(CalendarTask task){
|
||||
task.setId(RedisTools.list_get(REDIS_TAG).size()+1);
|
||||
String json = JSONObject.toJSONString(task);
|
||||
RedisTools.list_add(REDIS_TAG,json);
|
||||
return true;
|
||||
}
|
||||
public static List<CalendarTask> getTasks(){
|
||||
List<CalendarTask> list=new ArrayList<>();
|
||||
Set<String> set = RedisTools.list_get(REDIS_TAG);
|
||||
for (String s : set) {
|
||||
list.add(JSONObject.parseObject(s,CalendarTask.class));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public static boolean removeTask(CalendarTask task){
|
||||
for (String s : RedisTools.list_get(REDIS_TAG)) {
|
||||
CalendarTask tmp=JSONObject.parseObject(s,CalendarTask.class);
|
||||
if(tmp.getId()==task.getId()){
|
||||
RedisTools.list_remove(REDIS_TAG,s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getMouthData(CalendarTask task) {
|
||||
List<String> list = new ArrayList<>();
|
||||
Calendar calendar = Calendar.getInstance(Locale.CHINA);
|
||||
calendar.setTime(task.getStartTime());
|
||||
list.add(new SimpleDateFormat("yyyy-M-d HH:mm:ss",Locale.CHINA).format(calendar.getTime()));
|
||||
while (true) {
|
||||
calendar.set(task.getType(),calendar.get(task.getType())+task.getTime());
|
||||
if(calendar.getTime().getTime()>task.getEndTime().getTime()){
|
||||
break;
|
||||
}
|
||||
list.add(new SimpleDateFormat("yyyy-M-d HH:mm:ss",Locale.CHINA).format(calendar.getTime()));
|
||||
if(task.getModel()==CalendarTask.MODEL_ONE){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
17
src/main/java/com/yutou/tools/utils/TimerTask.java
Normal file
17
src/main/java/com/yutou/tools/utils/TimerTask.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.tools.utils;
|
||||
|
||||
public class TimerTask {
|
||||
private static TimerTask task;
|
||||
|
||||
private TimerTask(){
|
||||
|
||||
}
|
||||
public static TimerTask getInstance(){
|
||||
if(task == null){
|
||||
task=new TimerTask();
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -473,4 +474,17 @@ public class Tools {
|
||||
calendar.setTime(new Date());
|
||||
return calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
}
|
||||
public static Date timeToDate(String date,String time){
|
||||
String form;
|
||||
if(StringUtils.isEmpty(time)){
|
||||
form="yyyy-MM-dd";
|
||||
}else{
|
||||
form="yyyy-MM-dd HH:mm:ss";
|
||||
}
|
||||
try {
|
||||
return new SimpleDateFormat(form).parse(date+" "+time);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user