update:更新Layui版本

add:新增日历功能
add:预埋日历提醒到QQ功能
This commit is contained in:
Yutousama 2022-09-04 12:47:26 +08:00
parent 4cb79b83cd
commit abb67eaf9c
14 changed files with 531 additions and 13 deletions

View File

@ -47,7 +47,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<version>2.7.1</version> <version>2.7.3</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
@ -82,7 +82,7 @@
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId> <artifactId>fastjson2</artifactId>
<version>2.0.8</version> <version>2.0.12</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.jcraft/jsch --> <!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
<dependency> <dependency>
@ -93,13 +93,13 @@
<dependency> <dependency>
<groupId>com.aliyun.oss</groupId> <groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId> <artifactId>aliyun-sdk-oss</artifactId>
<version>3.15.0</version> <version>3.15.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.36.0.3</version> <version>3.39.2.1</version>
</dependency> </dependency>
<dependency> <dependency>

View 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;
}
}

View 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;
}

View 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;
}
}

View 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) {
}
}

View 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;
}
}

View File

@ -34,6 +34,7 @@ import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -473,4 +474,17 @@ public class Tools {
calendar.setTime(new Date()); calendar.setTime(new Date());
return calendar.get(Calendar.DAY_OF_WEEK) - 1; 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;
}
}
} }

View File

@ -0,0 +1,232 @@
<!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">
<div id="header"></div>
<div class="layui-body" style="left: 200px;overflow:auto;">
<div id="side"></div>
<blockquote class="layui-elem-quote">日历管理
</blockquote>
<br/><br/><br/>
<div class="layui-bg-gray layui-row layui-col-space15" id="card">
<div class="layui-form-item">
<table id="demo" lay-filter="test"></table>
</div>
<form class="layui-form" lay-filter="calendarForm">
<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">新增任务</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">内容</label>
<div class="layui-input-block">
<input type="text" name="content" required lay-verify="required" placeholder="请输入内容"
autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">类型</label>
<div class="layui-input-block">
<input type="radio" name="model" value="0" title="单次提醒" checked>
<input type="radio" name="model" value="1" title="循环提醒">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">模式</label>
<div class="layui-input-block">
<input type="radio" name="type" value="5" title="日" checked>
<input type="radio" name="type" value="4" title="周">
<input type="radio" name="type" value="2" title="月">
</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>
<div class="layui-form-item">
<label class="layui-form-label">QQ通知</label>
<div class="layui-input-block">
<input type="checkbox" name="qqbot" title="发送到QQ">
</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 id="footer"></div>
</div>
</div>
</body>
<script src="/layui/layui.js"></script>
<script src="/js/jquery-3.2.1.js"></script>
<script type="text/html" id="calendarToolBar">
<button class="layui-btn layui-btn-sm" lay-event="delete">删除</button>
</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'
, toolbar: '#toolbar'
, 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: '内容', width: 200, sort: true}
, {field: 'startTime', title: '开始时间', width: 180}
, {field: 'endTime', title: '结束时间', width: 180}
, {field: 'time', title: '间隔', width: 80, sort: true}
, {field: 'type', title: '类型', width: 80, sort: true}
, {field: 'model', title: '模式', width: 80}
, {field: 'words', title: '', toolbar: '#calendarToolBar'}
]]
});
table.on('tool(test)', function (obj) {
console.log(obj)
if (obj.event === 'delete') {
$.post('/calendar/del.do', {id: obj.data.id}, function (json) {
layer.msg(json.msg)
})
}
})
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
, qqbot: field.qqbot
}, function (json) {
layer.msg(json.msg)
})
}
});
})
})
});
$('#header').load("/html/header.html");
$('#footer').load("/html/footer.html");
</script>
<style>
.myDiy {
/*width: 80%;*/
margin-top: 10%;
margin-left: 15%;
margin-right: 15%;
}
.button {
width: 100px;
height: 100px;
font-size: 1em;
}
</style>
</html>

View File

@ -40,6 +40,7 @@
<dd><a href="http://bt.yutou233.cn" target="_blank">BT下载</a></dd> <dd><a href="http://bt.yutou233.cn" target="_blank">BT下载</a></dd>
<dd><a href="http://jellyfin.yutou233.cn:7800/" target="_blank">jellyfin</a></dd> <dd><a href="http://jellyfin.yutou233.cn:7800/" target="_blank">jellyfin</a></dd>
<dd><a href="/html/body/nas/music.html">NAS音乐播放器</a></dd> <dd><a href="/html/body/nas/music.html">NAS音乐播放器</a></dd>
<dd><a href="/html/body/tools/calendar.html">日历</a></dd>
</dl> </dl>
</li> </li>
<li class="layui-nav-item" id='icon'> <li class="layui-nav-item" id='icon'>

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #eee;border-left-width:6px;background-color:#FAFAFA;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:40px;line-height:40px;border-bottom:1px solid #eee}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 10px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view .layui-code-ol li:first-child{padding-top:10px}.layui-code-view .layui-code-ol li:last-child{padding-bottom:10px}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}.layui-code-demo .layui-code{visibility:visible!important;margin:-15px;border-top:none;border-right:none;border-bottom:none}.layui-code-demo .layui-tab-content{padding:15px;border-top:none} html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-view{display:block;position:relative;margin:10px 0;padding:0;border:1px solid #eee;border-left-width:6px;background-color:#fafafa;color:#333;font-family:Courier New;font-size:13px}.layui-code-title{position:relative;padding:0 10px;height:40px;line-height:40px;border-bottom:1px solid #eee;font-size:12px}.layui-code-title>.layui-code-about{position:absolute;right:10px;top:0;color:#b7b7b7}.layui-code-about>a{padding-left:10px}.layui-code-view>.layui-code-ol,.layui-code-view>.layui-code-ul{position:relative;overflow:auto}.layui-code-view>.layui-code-ol>li{position:relative;margin-left:45px;line-height:20px;padding:0 10px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view>.layui-code-ol>li:first-child,.layui-code-view>.layui-code-ul>li:first-child{padding-top:10px}.layui-code-view>.layui-code-ol>li:last-child,.layui-code-view>.layui-code-ul>li:last-child{padding-bottom:10px}.layui-code-view>.layui-code-ul>li{position:relative;line-height:20px;padding:0 10px;list-style-type:none;*list-style-type:none;background-color:#fff}.layui-code-view pre{margin:0}.layui-code-dark{border:1px solid #0c0c0c;border-left-color:#3f3f3f;background-color:#0c0c0c;color:#c2be9e}.layui-code-dark>.layui-code-title{border-bottom:none}.layui-code-dark>.layui-code-ol>li,.layui-code-dark>.layui-code-ul>li{background-color:#3f3f3f;border-left:none}.layui-code-dark>.layui-code-ul>li{margin-left:6px}.layui-code-demo .layui-code{visibility:visible!important;margin:-15px;border-top:none;border-right:none;border-bottom:none}.layui-code-demo .layui-tab-content{padding:15px;border-top:none}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long