TbCourseSchedulingController.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.template.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.template.model.pojo.ClassSchedule;
  5. import com.template.model.pojo.TbCourseScheduling;
  6. import com.template.model.result.CommonResult;
  7. import com.template.services.ClassScheduleService;
  8. import com.template.services.TbCourseSchedulingService;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.scheduling.annotation.Scheduled;
  13. import org.springframework.web.bind.annotation.GetMapping;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import java.util.List;
  17. import java.util.Map;
  18. /**
  19. * <p>
  20. * 课程安排 前端控制器
  21. * </p>
  22. *
  23. * @author ceshi
  24. * @since 2024-07-09
  25. */
  26. @RestController
  27. @RequestMapping("/auto/tb-course-scheduling")
  28. public class TbCourseSchedulingController {
  29. private static final Logger log = LoggerFactory.getLogger(TbCourseSchedulingController.class);
  30. @Autowired
  31. private TbCourseSchedulingService tbCourseSchedulingService;
  32. @Autowired
  33. private ClassScheduleService classScheduleService;
  34. @GetMapping("/queryGridPreDetail")
  35. @Scheduled(cron="0 30 0/2 * * ?")
  36. // @Scheduled(cron="0/20 * * * * ?")
  37. public void energyConsumption() {
  38. String xuenian="2024-2025";
  39. String xueqi="1";
  40. String deleteFlag="自动导入";
  41. List<Map<String,Object>> tbList=tbCourseSchedulingService.listAll(xuenian,xueqi);
  42. log.info("查询条数"+tbList.size());
  43. if (tbList.isEmpty()){
  44. log.info("课表导入失败,获取课表为空");
  45. return;
  46. }
  47. int a=classScheduleService.removeByRemark(deleteFlag);
  48. log.info("彻底删除条数"+a);
  49. JSONArray jsonArray = new JSONArray();
  50. jsonArray.addAll(tbList);
  51. List<ClassSchedule> list = jsonArray.toJavaList(ClassSchedule.class);
  52. log.info("导入条数"+list.size());
  53. boolean b=classScheduleService.saveBatch(list);
  54. log.info("课表导入执行结果"+b);
  55. }
  56. }