From 7a95cae8276abbd619c5c14762585aadeecbcd6b Mon Sep 17 00:00:00 2001
From: Mlxa0324 <mlx950324@163.com>
Date: Sun, 11 Sep 2022 23:31:49 +0800
Subject: [PATCH] =?UTF-8?q?1.=20=E8=8E=B7=E5=8F=96=E5=AE=9E=E6=97=B6?=
 =?UTF-8?q?=E7=9A=84=E8=8A=82=E5=81=87=E6=97=A5=E6=8E=A5=E5=8F=A3=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 admin-core/pom.xml                            |  9 +--
 .../ibeetl/admin/core/util/holidays/Day.java  | 42 ++++++++++++++
 .../admin/core/util/holidays/Holidays.java    | 53 ++++++++++++++++++
 .../core/util/holidays/HolidaysUtils.java     | 56 +++++++++++++++++++
 .../TeacherOpenCourseScheduleSessionHttp.http |  2 +-
 web/pom.xml                                   |  6 --
 ...acherOpenCourseScheduleSessionOptions.java | 21 ++++---
 ...acherOpenCourseScheduleSessionService.java | 25 ++++++---
 .../teacherOpenCourseScheduleSession/index.js | 28 +++++-----
 .../teacherOpenCourseScheduleSessionApi.js    |  3 +-
 10 files changed, 202 insertions(+), 43 deletions(-)
 create mode 100644 admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Day.java
 create mode 100644 admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Holidays.java
 create mode 100644 admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/HolidaysUtils.java

diff --git a/admin-core/pom.xml b/admin-core/pom.xml
index 5b245600..8f5a2712 100644
--- a/admin-core/pom.xml
+++ b/admin-core/pom.xml
@@ -166,9 +166,10 @@
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-api</artifactId>
 		</dependency>
-
+		<dependency>
+			<groupId>cn.hutool</groupId>
+			<artifactId>hutool-all</artifactId>
+			<version>5.7.22</version>
+		</dependency>
 	</dependencies>
-
-
-
 </project>
diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Day.java b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Day.java
new file mode 100644
index 00000000..efd5ed8f
--- /dev/null
+++ b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Day.java
@@ -0,0 +1,42 @@
+
+package com.ibeetl.admin.core.util.holidays;
+
+@SuppressWarnings("unused")
+public class Day {
+    /**
+     * 时间
+     */
+    private String date;
+    /**
+     * 是否休息日
+     */
+    private Boolean isOffDay;
+    /**
+     * 中文名称
+     */
+    private String name;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public Boolean getOffDay() {
+        return isOffDay;
+    }
+
+    public void setOffDay(Boolean offDay) {
+        isOffDay = offDay;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}
diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Holidays.java b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Holidays.java
new file mode 100644
index 00000000..cb65e9e9
--- /dev/null
+++ b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/Holidays.java
@@ -0,0 +1,53 @@
+
+package com.ibeetl.admin.core.util.holidays;
+
+import java.util.List;
+
+public class Holidays {
+
+    private String $id;
+    private String $schema;
+    private List<Day> days;
+    private List<String> papers;
+    private Long year;
+
+    public String get$id() {
+        return $id;
+    }
+
+    public void set$id(String $id) {
+        this.$id = $id;
+    }
+
+    public String get$schema() {
+        return $schema;
+    }
+
+    public void set$schema(String $schema) {
+        this.$schema = $schema;
+    }
+
+    public List<Day> getDays() {
+        return days;
+    }
+
+    public void setDays(List<Day> days) {
+        this.days = days;
+    }
+
+    public List<String> getPapers() {
+        return papers;
+    }
+
+    public void setPapers(List<String> papers) {
+        this.papers = papers;
+    }
+
+    public Long getYear() {
+        return year;
+    }
+
+    public void setYear(Long year) {
+        this.year = year;
+    }
+}
diff --git a/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/HolidaysUtils.java b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/HolidaysUtils.java
new file mode 100644
index 00000000..b6dc1723
--- /dev/null
+++ b/admin-core/src/main/java/com/ibeetl/admin/core/util/holidays/HolidaysUtils.java
@@ -0,0 +1,56 @@
+package com.ibeetl.admin.core.util.holidays;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.logging.log4j.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * <p>
+ * 节假日查询工具
+ * </p>
+ *
+ * @author mlx
+ * @date 2022/9/11
+ * @modified
+ */
+public abstract class HolidaysUtils {
+
+    private static final Logger log = LoggerFactory.getLogger(HolidaysUtils.class);
+
+    private volatile static Map<Integer, Holidays> cache = new ConcurrentHashMap<>();
+    /**
+     * 线路一
+     * https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/{年份}.json
+     */
+    private static final String githubHolidaysURL1 = "https://raw.githubusercontent.com/NateScarlet/holiday-cn/master/%s.json";
+
+    /**
+     * 线路二
+     * https://cdn.jsdelivr.net/gh/NateScarlet/holiday-cn@master/{年份}.json
+     */
+    private static final String githubHolidaysURL2 = "https://cdn.jsdelivr.net/gh/NateScarlet/holiday-cn@master/%s.json";
+
+    public static Holidays get() {
+        int year = DateUtil.thisYear();
+        if (cache.containsKey(year)) {
+            return cache.get(year);
+        }
+        String URL1 = String.format(githubHolidaysURL2, year);
+        String URL2 = String.format(githubHolidaysURL2, year);
+        String defaultResponseStr = HttpUtil.get(URL1);
+        String secondResponseStr = HttpUtil.get(URL2);
+        String responseStr = ObjectUtil.defaultIfBlank(defaultResponseStr, secondResponseStr);
+        Holidays holidays = JSONObject.parseObject(responseStr, Holidays.class);
+        log.info("正在从{} 获取节假日列表信息。", Strings.isNotBlank(defaultResponseStr) ? URL1 : URL2);
+        cache.put(year, holidays);
+        return holidays;
+    }
+
+}
diff --git a/http/TeacherOpenCourseScheduleSessionHttp.http b/http/TeacherOpenCourseScheduleSessionHttp.http
index 8c5ebe34..05776e3a 100644
--- a/http/TeacherOpenCourseScheduleSessionHttp.http
+++ b/http/TeacherOpenCourseScheduleSessionHttp.http
@@ -1,6 +1,6 @@
 POST http://localhost:9090/server/jlw/teacherOpenCourseScheduleSession/addSession.json
 Content-Type: application/json
-Cookie: JSESSIONID=F74A384F5C293F55D26E00CF608C358C
+Cookie: JSESSIONID=C6B69E52BCBD67B087124FF688F1A55D
 
 {
   "startTime": "2022-09-11 00:00:00",
diff --git a/web/pom.xml b/web/pom.xml
index cfbcdb4f..f4a142f1 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -231,12 +231,6 @@
 				</exclusion>
 			</exclusions>
 		</dependency>
-		<dependency>
-			<groupId>cn.hutool</groupId>
-			<artifactId>hutool-all</artifactId>
-			<version>4.0.12</version>
-		</dependency>
-
 	</dependencies>
 	<build>
 		<plugins>
diff --git a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseScheduleSessionOptions.java b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseScheduleSessionOptions.java
index 5d2fe615..12d1a44c 100644
--- a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseScheduleSessionOptions.java
+++ b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseScheduleSessionOptions.java
@@ -11,10 +11,10 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-/* 
-* 课程开课-新增排课页面的设置
-* gen by Spring Boot2 Admin 2022-09-10
-*/
+/*
+ * 课程开课-新增排课页面的设置
+ * gen by Spring Boot2 Admin 2022-09-10
+ */
 @Data
 @Accessors(chain = true)
 public class TeacherOpenCourseScheduleSessionOptions {
@@ -36,8 +36,8 @@ public class TeacherOpenCourseScheduleSessionOptions {
     /**
      * 上课教室类型
      */
-    @NotNull(message = "上课教室类型不能为空", groups =ValidateConfig.ADD.class)
-    private ClassRoomType classRoomType;
+//    @NotNull(message = "上课教室类型不能为空", groups =ValidateConfig.ADD.class)
+//    private ClassRoomType classRoomType;
     /**
      * 开课节次List
      */
@@ -90,11 +90,14 @@ public class TeacherOpenCourseScheduleSessionOptions {
         T6(7),
         T7(1);
 
+        /**
+         * 星期转为数字
+         */
         @Getter
-        private Integer i;
+        private Integer weekNumber;
 
-        WeekDetailType(int i) {
-            this.i = i;
+        WeekDetailType(int weekNumber) {
+            this.weekNumber = weekNumber;
         }
     }
 
diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScheduleSessionService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScheduleSessionService.java
index 8453ffc7..81b480e5 100644
--- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScheduleSessionService.java
+++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScheduleSessionService.java
@@ -11,6 +11,9 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ibeetl.admin.core.service.CoreBaseService;
 import com.ibeetl.admin.core.util.PlatformException;
+import com.ibeetl.admin.core.util.holidays.Day;
+import com.ibeetl.admin.core.util.holidays.Holidays;
+import com.ibeetl.admin.core.util.holidays.HolidaysUtils;
 import com.ibeetl.admin.core.web.JsonResult;
 import com.ibeetl.admin.core.web.JsonReturnCode;
 import com.ibeetl.jlw.dao.TeacherOpenCourseScheduleSessionDao;
@@ -25,11 +28,12 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import static cn.hutool.core.date.DatePattern.NORM_DATE_PATTERN;
+
 
 /**
  * 新增排课 Service
@@ -165,23 +169,28 @@ public class TeacherOpenCourseScheduleSessionService extends CoreBaseService<Tea
         // 偏移周
         Date endTime = DateUtil.offsetWeek(options.getStartTime(), options.getWeekNum());
         List<DateTime> dateTimes = DateUtil.rangeToList(options.getStartTime(), endTime, DateField.DAY_OF_YEAR);
+
         // 断言,确保开课节次不为空
         Assert.notEmpty(options.getSessionClassList(), "开课节次不能为空!");
 
-        String[] lFtv = new String[]{
-                "0101 春节", "0102 大年初二", "0103 大年初三", "0104 大年初四",
-                "0105 大年初五", "0106 大年初六", "0107 大年初七",
-                "0505 端午节", "1223 过小年", "1230 除夕"};
-
         // 节假日处理
         if (!options.getOpenOnHolidays()) {
-            dateTimes = dateTimes.stream().filter(dt -> !Arrays.stream(lFtv).anyMatch(e -> e.split(" ")[0].equals(DateUtil.format(dt, "MMdd"))))
+
+            // 获取github上的节假日列表
+            Holidays holidays = HolidaysUtils.get();
+            Assert.notNull(holidays, "获取节假日列表失败!");
+
+            // 获取节假日列表,只获取节假日中的休息日,非休息日则是需要补班的日期。
+            List<String> collect = holidays.getDays().stream().filter(Day::getOffDay).map(Day::getDate).collect(Collectors.toList());
+            dateTimes = dateTimes.stream().filter(dt -> !collect.stream().anyMatch(e -> e.equals(DateUtil.format(dt, NORM_DATE_PATTERN))))
                     .collect(Collectors.toList());
         }
 
         // 开课星期处理
         if (ObjectUtil.isNotEmpty(options.getWeekDetail())) {
-            dateTimes = dateTimes.stream().filter(dt -> options.getWeekDetail().stream().anyMatch(e -> e.getI().equals(DateUtil.dayOfWeek(dt))))
+
+            // 指定星期的日期时间
+            dateTimes = dateTimes.stream().filter(dt -> options.getWeekDetail().stream().anyMatch(e -> e.getWeekNumber().equals(DateUtil.dayOfWeek(dt))))
                     .collect(Collectors.toList());
         }
 
diff --git a/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/index.js b/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/index.js
index c8a61a36..cbb657bc 100644
--- a/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/index.js
+++ b/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/index.js
@@ -83,20 +83,20 @@ layui.define([ 'form', 'laydate', 'table' ], function(exports) {
                     hideField :false,
                     hide:$.isEmpty(sx_['schoolClassIds'])?false:sx_['schoolClassIds'],
                 },
-                {
-                    field : 'orgId', 
-                    title : '组织ID',
-                    align:"center",
-                    hideField :false,
-                    hide:$.isEmpty(sx_['orgId'])?false:sx_['orgId'],
-                },
-                {
-                    field : 'userId', 
-                    title : '用户ID',
-                    align:"center",
-                    hideField :false,
-                    hide:$.isEmpty(sx_['userId'])?false:sx_['userId'],
-                },
+                // {
+                //     field : 'orgId',
+                //     title : '组织ID',
+                //     align:"center",
+                //     hideField :false,
+                //     hide:$.isEmpty(sx_['orgId'])?false:sx_['orgId'],
+                // },
+                // {
+                //     field : 'userId',
+                //     title : '用户ID',
+                //     align:"center",
+                //     hideField :false,
+                //     hide:$.isEmpty(sx_['userId'])?false:sx_['userId'],
+                // },
                 {
                     field : 'teacherOpenCourseScheduleSessionTagName', 
                     title : '课次名称',
diff --git a/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/teacherOpenCourseScheduleSessionApi.js b/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/teacherOpenCourseScheduleSessionApi.js
index 15e71d6a..9c386f80 100644
--- a/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/teacherOpenCourseScheduleSessionApi.js
+++ b/web/src/main/resources/static/js/jlw/teacherOpenCourseScheduleSession/teacherOpenCourseScheduleSessionApi.js
@@ -5,7 +5,8 @@ layui.define([], function(exports) {
                 Lib.submitForm("/jlw/teacherOpenCourseScheduleSession/edit.json",form,{},callback)
             },
             addTeacherOpenCourseScheduleSession:function(form,callback){
-                Lib.submitForm("/jlw/teacherOpenCourseScheduleSession/add.json",form,{},callback)
+                // Lib.submitForm("/jlw/teacherOpenCourseScheduleSession/add.json",form,{},callback)
+                Lib.submitForm("/jlw/teacherOpenCourseScheduleSession/addSession.json",form,{},callback)
             },
             del:function(ids,callback){
                 Common.post("/jlw/teacherOpenCourseScheduleSession/delete.json",{"ids":ids},function(){