wanxl пре 1 година
родитељ
комит
7a315652ae

+ 8 - 0
pom.xml

@@ -236,6 +236,14 @@
         <version>4.5.7</version>
         </dependency>
 
+        <!--多数据源-->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
+            <version>3.0.0</version>
+            <scope>compile</scope>
+        </dependency>
+
     </dependencies>
 
     <build>

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

@@ -1,10 +1,25 @@
 package com.template.controller;
 
 
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.template.model.pojo.ClassSchedule;
+import com.template.model.pojo.TbCourseScheduling;
+import com.template.model.result.CommonResult;
+import com.template.services.ClassScheduleService;
+import com.template.services.TbCourseSchedulingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 课程安排 前端控制器
@@ -17,5 +32,36 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/auto/tb-course-scheduling")
 public class TbCourseSchedulingController {
 
+    private static final Logger log = LoggerFactory.getLogger(TbCourseSchedulingController.class);
+    @Autowired
+    private TbCourseSchedulingService tbCourseSchedulingService;
+
+    @Autowired
+    private ClassScheduleService classScheduleService;
+
+
+
+    @GetMapping("/queryGridPreDetail")
+    @Scheduled(cron="0 30 0/2 * * ?")
+//    @Scheduled(cron="0/20 * * * * ?")
+    public void energyConsumption() {
+        String xuenian="2024-2025";
+        String xueqi="1";
+        String deleteFlag="自动导入";
+        List<Map<String,Object>> tbList=tbCourseSchedulingService.listAll(xuenian,xueqi);
+        log.info("查询条数"+tbList.size());
+        if (tbList.isEmpty()){
+            log.info("课表导入失败,获取课表为空");
+            return;
+        }
+        int a=classScheduleService.removeByRemark(deleteFlag);
+        log.info("彻底删除条数"+a);
+        JSONArray jsonArray = new JSONArray();
+        jsonArray.addAll(tbList);
+        List<ClassSchedule> list = jsonArray.toJavaList(ClassSchedule.class);
+        log.info("导入条数"+list.size());
+        boolean b=classScheduleService.saveBatch(list);
+        log.info("课表导入执行结果"+b);
+    }
 }
 

+ 6 - 0
src/main/java/com/template/mapper/ClassScheduleMapper.java

@@ -2,8 +2,10 @@ package com.template.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.template.model.pojo.ClassSchedule;
+import org.apache.ibatis.annotations.Delete;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Component;
 
 import java.time.LocalDate;
 import java.util.List;
@@ -17,7 +19,11 @@ import java.util.List;
  * @since 2023-11-06
  */
 @Mapper
+@Component
 public interface ClassScheduleMapper extends BaseMapper<ClassSchedule> {
 
     String remarks(@Param("localDate") LocalDate localDate,@Param("teacherName") String teacherName);
+
+    @Delete("delete from class_schedule where  remark =#{remark} ")
+    int removeByRemark(String remark);
 }

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

@@ -1,7 +1,15 @@
 package com.template.mapper;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.template.model.pojo.TbCourseScheduling;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -11,6 +19,14 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  * @author ceshi
  * @since 2024-07-09
  */
+@Mapper
+@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" +
+            "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)>=9 and OPERATION_TYPE !='deleted'")
+    @DS("readOnly")
+    List<Map<String,Object>> listAll(String xuenian, String xueqi);
 }

+ 1 - 0
src/main/java/com/template/services/ClassScheduleService.java

@@ -19,4 +19,5 @@ public interface ClassScheduleService extends IService<ClassSchedule> {
 
     ClassListVo  classList(LocalDate localDate, String teacherName);
 
+    int removeByRemark(String remark);
 }

+ 5 - 0
src/main/java/com/template/services/TbCourseSchedulingService.java

@@ -1,8 +1,12 @@
 package com.template.services;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.template.model.pojo.TbCourseScheduling;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 课程安排 服务类
@@ -13,4 +17,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface TbCourseSchedulingService extends IService<TbCourseScheduling> {
 
+    List<Map<String,Object>>listAll(String xuenian, String xueqi);
 }

+ 6 - 0
src/main/java/com/template/services/impl/ClassScheduleServiceImpl.java

@@ -43,4 +43,10 @@ public class ClassScheduleServiceImpl extends ServiceImpl<ClassScheduleMapper, C
         classListVo.setRemarks(remarks);
         return classListVo;
     }
+
+    @Override
+    public int removeByRemark(String remark) {
+
+        return classScheduleMapper.removeByRemark(remark);
+    }
 }

+ 13 - 0
src/main/java/com/template/services/impl/TbCourseSchedulingServiceImpl.java

@@ -1,11 +1,17 @@
 package com.template.services.impl;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.template.model.pojo.TbCourseScheduling;
 import com.template.mapper.TbCourseSchedulingMapper;
 import com.template.services.TbCourseSchedulingService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 课程安排 服务实现类
@@ -17,4 +23,11 @@ import org.springframework.stereotype.Service;
 @Service
 public class TbCourseSchedulingServiceImpl extends ServiceImpl<TbCourseSchedulingMapper, TbCourseScheduling> implements TbCourseSchedulingService {
 
+    @Autowired
+    private TbCourseSchedulingMapper tbCourseSchedulingMapper;
+
+    @DS("readOnly")
+    public List<Map<String,Object>> listAll(String xuenian, String xueqi){
+        return  tbCourseSchedulingMapper.listAll(xuenian,xueqi);
+    }
 }

+ 13 - 4
src/main/resources/application-dev.yml

@@ -15,10 +15,19 @@ spring:
       max-request-size: 10MB
 
   datasource:
-    username: root
-    password: Chuanghai_test
-    url: jdbc:mysql://172.16.20.80:3306/ihotel_test?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
-    driver-class-name: com.mysql.cj.jdbc.Driver
+    dynamic:
+      datasource:
+        master:
+          username: root
+          password: Chuanghai_test
+          url: jdbc:mysql://172.16.20.80:3306/ihotel_test?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+          driver-class-name: com.mysql.cj.jdbc.Driver
+        readOnly:
+          username: queryUser
+          password: fcBtkT2EwCjiTdc4
+          url: jdbc:mysql://172.16.20.77:3306/memdb?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+          driver-class-name: com.mysql.cj.jdbc.Driver
+      enabled: true
     cache:
       type: redis
       redis:

+ 13 - 4
src/main/resources/application.yml

@@ -16,10 +16,19 @@ spring:
       max-request-size: 10MB
 
   datasource:
-    username: root
-    password: Chuanghai_test
-    url: jdbc:mysql://172.16.20.80:3306/ihotel_test?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
-    driver-class-name: com.mysql.cj.jdbc.Driver
+    dynamic:
+      datasource:
+        master:
+          username: root
+          password: Chuanghai_test
+          url: jdbc:mysql://172.16.20.80:3306/ihotel_test?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+          driver-class-name: com.mysql.cj.jdbc.Driver
+        readOnly:
+          username: queryUser
+          password: fcBtkT2EwCjiTdc4
+          url: jdbc:mysql://172.16.20.77:3306/memdb?useUnicode=tru&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true&allowPublicKeyRetrieval=true&allowMultiQueries=true&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
+          driver-class-name: com.mysql.cj.jdbc.Driver
+      enabled: true
     cache:
       type: redis
       redis: