移除日历提醒

This commit is contained in:
Yutousama 2022-09-04 11:59:17 +08:00
parent 7885f2bbfb
commit f46c09c6ed
4 changed files with 0 additions and 433 deletions

View File

@ -1,62 +0,0 @@
package com.yutou.qqbot.Controllers;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.data.calendar.CalendarTask;
import com.yutou.qqbot.utlis.AppTools;
import com.yutou.qqbot.utlis.CalendarTools;
import com.yutou.qqbot.utlis.RedisTools;
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){
JSONObject json = new JSONObject();
String[] dates=startDate.split(" - ");
Date sDate = AppTools.timeToDate(dates[0].split(" ")[0], dates[0].split(" ")[1]);
Date endDate = AppTools.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));
CalendarTools.addTask(task);
json.put("code",0);
json.put("msg","add task success!");
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;
}
}

View File

@ -1,51 +0,0 @@
package com.yutou.qqbot.data.calendar;
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 outQQ;
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;
}
}

View File

@ -1,115 +0,0 @@
package com.yutou.qqbot.utlis;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.data.calendar.CalendarTask;
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) {
CalendarTask task = new CalendarTask();
task.setTitle("myTitle");
task.setContent("game");
task.setStartTime(AppTools.timeToDate("2022-9-3",null));
//task.setEndTime(new Date(1669996799999L));
task.setEndTime(AppTools.timeToDate("2032-9-3",null));
task.setType(CalendarTask.TYPE_WEEK);
task.setModel(CalendarTask.MODEL_LOOP);
task.setTime(2);
List<String> list = getMouthData(task);
for (String s : list) {
System.out.println("data = " + s);
}
}
}

View File

@ -1,205 +0,0 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Calendar</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
</head>
<body>
<div class="layui-layout layui-layout-admin myDiy">
<blockquote class="layui-elem-quote">日历管理
</blockquote>
<br/><br/><br/>
<div class="layui-bg-gray layui-row layui-col-space15" id="card">
<form class="layui-form" lay-filter="calendarForm">
<div class="layui-form-item">
<table id="demo" lay-filter="test"></table>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日历</label>
<div class="layui-input-block">
<div id="calendarShow" name="calendar" style="width: 45%"/>
</div>
</div>
<br/>
<br/>
<br/>
<div class="layui-form-item">
<div class="layui-form-item">
<label class="layui-form-label">addTask</label>
<div class="layui-input-block">
<input type="text" class="layui-input" id="calendar">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">标题</label>
<div class="layui-input-block">
<input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">content</label>
<div class="layui-input-block">
<input type="text" name="content" required lay-verify="required" placeholder="请输入content"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">type</label>
<div class="layui-input-block">
<input type="radio" name="model" value="0" title="ONE" checked>
<input type="radio" name="model" value="1" title="LOOP">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">model</label>
<div class="layui-input-block">
<input type="radio" name="type" value="5" title="DAY" checked>
<input type="radio" name="type" value="4" title="WEEK">
<input type="radio" name="type" value="2" title="MONTH">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">间隔日期</label>
<div class="layui-input-block">
<input type="text" name="day" required lay-verify="required" placeholder="天数"
autocomplete="off" class="layui-input">
</div>
</div>
<blockquote class="layui-elem-quote"><span id="dateText">日期选择</span>
</blockquote>
<div class="layui-form-item">
<div class="layui-input-block">
<a class="layui-btn" id="setCalendar">新增规则</a>
</div>
</div>
</div>
</form>
</div>
</div>
</body>
<script src="layui/layui.js"></script>
<script src="layui/jquery-3.2.1.js"></script>
<script>
layui.use(['laydate', 'form','table'], function () {
let dayDateObj
let marks = {}
let holiday = []
let laydate = layui.laydate;
let form = layui.form;
let table=layui.table;
$.get("/calendar/all.do", function (json) {
//执行一个laydate实例
marks = json.data.date;
holiday = json.data.holiday;
showData()
})
table.render({
elem: '#demo'
,url: '/calendar/list.do' //数据接口
,page: true //开启分页
,cols: [[ //表头
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
,{field: 'title', title: '标题', width:100}
,{field: 'content', title: 'content', width:200, sort: true}
,{field: 'startTime', title: 'startTime', width:180}
,{field: 'endTime', title: 'endTime', width: 180}
,{field: 'time', title: 'time', width: 80, sort: true}
,{field: 'type', title: 'type', width: 80, sort: true}
,{field: 'model', title: 'model', width: 80}
,{field: 'words', title: '字数', width: 135, sort: true}
]]
});
function showData() {
laydate.render({
elem: '#calendar' //指定元素
, type: 'datetime'
, show:true
, range: true
, holidays: holiday
, done: function (value, date, endDate) {
console.log(date)
console.log(endDate)
dayDateObj = date;
dayDateObj.time = value
$('#dateText')[0].innerHTML = "从" + date.date + "号开始计算"
}, change: function (value, date, endDate) {
}
});
laydate.render({
elem: '#calendarShow' //指定元素
, position: 'static'
, holidays: holiday
,theme: 'molv'
, done: function (value, date, endDate) {
}, change: function (value, date, endDate) {
console.log(marks[value]+" > "+value)
if (marks[value] !== undefined) {
// datatmp.hint(marks[value])
layer.tips(marks[value], '#calendarShow')
}
}
});
}
$('#setCalendar').click(function () {
form.submit('calendarForm', function (obj) {
console.log(obj)
let field = obj.field;
layer.open({
title: '确认'
, content: '确认从' + dayDateObj.date + '号开始,开始提醒?'
, yes: function (index, layero) {
$.post("/calendar/set.do", {
startDate: dayDateObj.time
, title: field.title
, content: field.content
, type: field.type
, model: field.model
, day: field.day
},function (json) {
layer.msg(json.msg)
})
}
});
})
})
});
</script>
<style>
.myDiy {
/*width: 80%;*/
margin-top: 10%;
margin-left: 15%;
margin-right: 15%;
}
.button {
width: 100px;
height: 100px;
font-size: 1em;
}
</style>
</html>