From f46c09c6edc59cd45ff3097b260b16cce66f39cf Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 4 Sep 2022 11:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A5=E5=8E=86=E6=8F=90?= =?UTF-8?q?=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/Controllers/CalendarController.java | 62 ------ .../qqbot/data/calendar/CalendarTask.java | 51 ----- .../com/yutou/qqbot/utlis/CalendarTools.java | 115 ---------- web/calendar.html | 205 ------------------ 4 files changed, 433 deletions(-) delete mode 100644 src/main/java/com/yutou/qqbot/Controllers/CalendarController.java delete mode 100644 src/main/java/com/yutou/qqbot/data/calendar/CalendarTask.java delete mode 100644 src/main/java/com/yutou/qqbot/utlis/CalendarTools.java delete mode 100644 web/calendar.html diff --git a/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java b/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java deleted file mode 100644 index 0bd3c94..0000000 --- a/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java +++ /dev/null @@ -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 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; - } -} diff --git a/src/main/java/com/yutou/qqbot/data/calendar/CalendarTask.java b/src/main/java/com/yutou/qqbot/data/calendar/CalendarTask.java deleted file mode 100644 index fa7b900..0000000 --- a/src/main/java/com/yutou/qqbot/data/calendar/CalendarTask.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java b/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java deleted file mode 100644 index fc6a370..0000000 --- a/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java +++ /dev/null @@ -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 getTasks(){ - List list=new ArrayList<>(); - Set 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 getMouthData(CalendarTask task) { - List 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 list = getMouthData(task); - for (String s : list) { - System.out.println("data = " + s); - } - } -} diff --git a/web/calendar.html b/web/calendar.html deleted file mode 100644 index a542b9b..0000000 --- a/web/calendar.html +++ /dev/null @@ -1,205 +0,0 @@ - - - - - - Calendar - - - - - - - -
-
日历管理 -
- -


- -
- -
-
-
-
-
- -
-
-
-
- -
-
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- - -
-
-
- -
- - - -
-
-
- -
- -
-
-
日期选择 -
- -
- -
-
- - -
-
- - - - - - - - \ No newline at end of file