Quellcode durchsuchen

优化课表导入自动判断学年和学期,课表增加连续两天上课的前一天可免费入住

wanxl vor 1 Jahr
Ursprung
Commit
c9175e242f

+ 16 - 0
src/main/java/com/template/controller/TbCourseSchedulingController.java

@@ -3,6 +3,7 @@ package com.template.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.template.common.utils.TimeExchange;
 import com.template.model.pojo.ClassSchedule;
 import com.template.model.pojo.TbCourseScheduling;
 import com.template.model.result.CommonResult;
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Calendar;
 import java.util.List;
 import java.util.Map;
 
@@ -45,8 +47,22 @@ public class TbCourseSchedulingController {
     @Scheduled(cron="0 30 4 * * ?")
 //    @Scheduled(cron="0/20 * * * * ?")
     public void energyConsumption() {
+        Calendar calendar = Calendar.getInstance();
+        // 获取当前年
+        int year = calendar.get(Calendar.YEAR);
+        // 获取当前月
+        int month = calendar.get(Calendar.MONTH) + 1;
         String xuenian="2024-2025";
         String xueqi="1";
+        //上半年月份第二学期 2-7月 下半年月份8-1月
+        if(month<8&&month>=2){
+            xueqi="2";
+            xuenian=(year-1)+"-"+year;
+        }else if(month<2){
+            xuenian=(year-1)+"-"+year;
+        }else{
+            xuenian=year+"-"+(year+1);
+        }
         String deleteFlag="自动导入";
         List<Map<String,Object>> tbList=tbCourseSchedulingService.listAll(xuenian,xueqi);
         log.info("查询条数"+tbList.size());

+ 16 - 3
src/main/java/com/template/mapper/TbCourseSchedulingMapper.java

@@ -23,10 +23,23 @@ import java.util.Map;
 @Component
 public interface TbCourseSchedulingMapper extends BaseMapper<TbCourseScheduling> {
 
-    @Select("select  push_jc jc,push_zj zj,push_djz djz,push_xq xq,push_xn xn,push_jsxm jsxm,push_jsgh jsgh,\n" +
+    @Select("select * from(\n" +
+            "select a.push_jc jc,a.push_zj zj,a.push_djz djz,a.push_xq xq,a.push_xn xn,a.push_jsxm jsxm,a.push_jsgh jsgh,\n" +
+            "a.dt `dateTime`,'自动导入' remark,now() createTime,now() updateTime,'0' createUser,'0' updateUser, 0 deleted  from \n" +
+            "(select \n" +
+            "date_add((select cfg_value from tb_config tc where cfg_key='termBeginsTime' ),interval (push_djz -1)*7+push_zj-1 day)  `dt`,a.*\n" +
+            "from tb_course_scheduling a where  push_xq =#{xueqi} AND push_xn = #{xuenian} and OPERATION_TYPE !='deleted' ) a,\n" +
+            "(select \n" +
+            "date_add((select cfg_value from tb_config tc where cfg_key='termBeginsTime' ),interval (push_djz -1)*7+push_zj-1 day)  `dt`,a.*\n" +
+            "from tb_course_scheduling a where  push_xq =#{xueqi} AND push_xn = #{xuenian} and OPERATION_TYPE !='deleted' ) b\n" +
+            "where  TIMESTAMPDIFF(DAY,a.dt,b.dt)=1 and a.push_jsgh=b.push_jsgh\n" +
+            "union all\n" +
+            "select \n" +
+            "push_jc jc,push_zj zj,push_djz djz,push_xq xq,push_xn xn,push_jsxm jsxm,push_jsgh jsgh,\n" +
             "date_add((select cfg_value from tb_config tc where cfg_key='termBeginsTime' ),interval (push_djz -1)*7+push_zj-1 day)  `dateTime`,\n" +
-            "'自动导入' remark,now() createTime,now() updateTime,'0' createUser,'0' updateUser,0\n" +
-            " from  tb_course_scheduling where  push_xq = #{xueqi} AND push_xn = #{xuenian} and SUBSTRING_INDEX(push_jc,\"-\", -1)>=8 and OPERATION_TYPE !='deleted'")
+            "'自动导入' remark,now() createTime,now() updateTime,'0' createUser,'0' updateUser,0 deleted\n" +
+            "from  tb_course_scheduling where push_xq =#{xueqi} AND push_xn = #{xuenian} and OPERATION_TYPE !='deleted' and SUBSTRING_INDEX(push_jc,\"-\", -1)>=8 \n" +
+            ") c group by jsgh,dateTime")
     @DS("readOnly")
     List<Map<String,Object>> listAll(String xuenian, String xueqi);
 }