ScheduleController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package com.xjrsoft.module.schedule.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.util.ObjectUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import cn.hutool.db.Db;
  7. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  8. import com.google.gson.JsonArray;
  9. import com.google.gson.JsonObject;
  10. import com.google.gson.JsonParser;
  11. import com.xjrsoft.common.constant.GlobalConstant;
  12. import com.xjrsoft.common.enums.DeleteMark;
  13. import com.xjrsoft.common.enums.EnabledMark;
  14. import com.xjrsoft.common.model.result.RT;
  15. import com.xjrsoft.common.utils.DatasourceUtil;
  16. import com.xjrsoft.module.courseTable.entity.CourseTable;
  17. import com.xjrsoft.module.courseTable.service.ICourseTableService;
  18. import com.xjrsoft.module.schedule.dto.CourseTableAdjustDto;
  19. import com.xjrsoft.module.schedule.dto.CourseTableDto;
  20. import com.xjrsoft.module.schedule.dto.CourseTablePreCheckDto;
  21. import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
  22. import com.xjrsoft.module.schedule.entity.JianyueData;
  23. import com.xjrsoft.module.schedule.service.ICourseReceiveMsgService;
  24. import com.xjrsoft.module.schedule.service.IJianyueDataService;
  25. import com.xjrsoft.module.schedule.util.DataUtil;
  26. import com.xjrsoft.module.schedule.util.ScheduleUtil;
  27. import com.xjrsoft.module.schedule.vo.CourseListVo;
  28. import com.xjrsoft.module.schedule.vo.CourseTableVo;
  29. import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
  30. import com.xjrsoft.module.student.service.impl.IBaseStudentSchoolRollService;
  31. import com.xjrsoft.module.teacher.entity.BaseTeacher;
  32. import com.xjrsoft.module.teacher.service.IBaseTeacherService;
  33. import io.swagger.annotations.Api;
  34. import io.swagger.annotations.ApiOperation;
  35. import lombok.AllArgsConstructor;
  36. import org.apache.commons.lang3.concurrent.BasicThreadFactory;
  37. import org.springframework.web.bind.annotation.GetMapping;
  38. import org.springframework.web.bind.annotation.RequestMapping;
  39. import org.springframework.web.bind.annotation.RequestParam;
  40. import org.springframework.web.bind.annotation.RestController;
  41. import javax.sql.DataSource;
  42. import java.sql.SQLException;
  43. import java.time.DayOfWeek;
  44. import java.time.LocalDateTime;
  45. import java.time.format.DateTimeFormatter;
  46. import java.util.Date;
  47. import java.util.HashMap;
  48. import java.util.HashSet;
  49. import java.util.List;
  50. import java.util.Map;
  51. import java.util.Set;
  52. import java.util.concurrent.CompletableFuture;
  53. /**
  54. * @title: 课表
  55. * @Author dzx
  56. * @Date: 2023-12-27
  57. * @Version 1.0
  58. */
  59. @RestController
  60. @RequestMapping("/schedule" + "/schedule")
  61. @Api(value = "/schedule" + "/schedule",tags = "课表代码")
  62. @AllArgsConstructor
  63. public class ScheduleController {
  64. private final ICourseReceiveMsgService courseReceiveMsgService;
  65. private final IJianyueDataService jianyueDataService;
  66. private final ICourseTableService courseTableService;
  67. private final IBaseStudentSchoolRollService baseStudentSchoolRollService;
  68. private final IBaseTeacherService baseTeacherService;
  69. @GetMapping(value = "/receive-msg")
  70. @ApiOperation(value="接收消息")
  71. @SaCheckPermission("room:detail")
  72. public RT<CourseReceiveMsg> receiveMsg(@RequestParam String schoolId, @RequestParam String eduYearSerialNo, @RequestParam String startDate, @RequestParam String endDate) throws Exception {
  73. CourseReceiveMsg courseReceiveMsg = new CourseReceiveMsg();
  74. courseReceiveMsg.setCreateDate(new Date());
  75. courseReceiveMsg.setSchoolId(schoolId);
  76. courseReceiveMsg.setEduYearSerialNo(eduYearSerialNo);
  77. courseReceiveMsg.setStartDate(startDate);
  78. courseReceiveMsg.setEndDate(endDate);
  79. courseReceiveMsg.setDeleteMark(DeleteMark.NODELETE.getCode());
  80. courseReceiveMsg.setEnabledMark(EnabledMark.ENABLED.getCode());
  81. courseReceiveMsgService.save(courseReceiveMsg);
  82. return RT.ok(courseReceiveMsg);
  83. }
  84. @GetMapping(value = "/course-table")
  85. @ApiOperation(value="课表接口(PC端)")
  86. @SaCheckPermission("room:detail")
  87. public RT<CourseTableVo> courseInfo(CourseTableDto dto){
  88. CourseTableVo list = courseTableService.getList(dto);
  89. return RT.ok(list);
  90. }
  91. @GetMapping(value = "/course-table-day")
  92. @ApiOperation(value="今日课表接口(手机端)")
  93. @SaCheckPermission("room:detail")
  94. public RT<CourseTableVo> courseInfoDay(CourseTableDto dto){
  95. LocalDateTime now = LocalDateTime.now();
  96. DayOfWeek dayOfWeek = now.getDayOfWeek();
  97. dto.setWeekDay(dayOfWeek.getValue());
  98. dto.setToDay(now);
  99. if(ObjectUtil.isNotNull(dto.getStudentId())){
  100. List<BaseStudentSchoolRoll> schoolRolls = baseStudentSchoolRollService.list(
  101. new QueryWrapper<BaseStudentSchoolRoll>().lambda().eq(BaseStudentSchoolRoll::getUserId, dto.getStudentId())
  102. );
  103. if(schoolRolls != null && !schoolRolls.isEmpty()){
  104. dto.setCourseType("class");
  105. dto.setClassId(schoolRolls.get(0).getClassId());
  106. }
  107. }else{
  108. // 查询登录者身份
  109. long loginIdAsLong = StpUtil.getLoginIdAsLong();
  110. List<BaseStudentSchoolRoll> schoolRolls = baseStudentSchoolRollService.list(
  111. new QueryWrapper<BaseStudentSchoolRoll>().lambda().eq(BaseStudentSchoolRoll::getUserId, loginIdAsLong)
  112. );
  113. if(schoolRolls != null && !schoolRolls.isEmpty()){
  114. dto.setCourseType("class");
  115. dto.setClassId(schoolRolls.get(0).getClassId());
  116. }
  117. List<BaseTeacher> teachers = baseTeacherService.list(new QueryWrapper<BaseTeacher>().lambda().eq(BaseTeacher::getUserId, loginIdAsLong));
  118. if(teachers != null && !teachers.isEmpty()){
  119. dto.setCourseType("teacher");
  120. dto.setTeacherId(loginIdAsLong);
  121. }
  122. }
  123. CourseTableVo list = courseTableService.getList(dto);
  124. return RT.ok(list);
  125. }
  126. @GetMapping(value = "/adjust-list")
  127. @ApiOperation(value = "可以调课的课程")
  128. @SaCheckPermission("evaluateobject:detail")
  129. public RT<List<CourseListVo>> adjustList(CourseTableAdjustDto dto){
  130. // if(dto.getAdjustDate() == null || dto.getTeacherId() == null){
  131. // return RT.error("请传入调整日期和教师id");
  132. // }
  133. // List<CourseListVo> list = courseTableService.getAdjustList(dto);
  134. // if(list.isEmpty()){
  135. // return RT.error("暂无可调课程");
  136. // }
  137. return RT.ok();
  138. }
  139. @GetMapping(value = "/pre-check")
  140. @ApiOperation(value = "预检查")
  141. @SaCheckPermission("evaluateobject:detail")
  142. public RT<String> preCheck(CourseTablePreCheckDto dto) throws Exception {
  143. if(dto.getPreCheckType() != null){
  144. if(dto.getPreCheckType() == 1){
  145. CourseTable courseTable = courseTableService.getById(dto.getCourseId());
  146. CourseTable swapCourseTable = courseTableService.getById(dto.getSwapCourseId());
  147. JsonObject preCheck = getExtendPreCheck(dto, courseTable, swapCourseTable);
  148. if(!preCheck.get("data").getAsBoolean()){
  149. return RT.error(preCheck.get("msg").getAsString());
  150. }
  151. }else if(dto.getPreCheckType() == 2){
  152. CourseTable courseTable = courseTableService.getById(dto.getCourseId());
  153. JsonObject jsonObject = substitutePreTestin(dto, courseTable);
  154. if(!jsonObject.get("data").getAsBoolean()){
  155. return RT.error(jsonObject.get("msg").getAsString());
  156. }
  157. }
  158. }
  159. return RT.ok("ok");
  160. }
  161. /**
  162. * 顶课预检查
  163. * @param dto
  164. * @param courseTable
  165. * @return 检查结果
  166. */
  167. JsonObject substitutePreTestin(CourseTablePreCheckDto dto, CourseTable courseTable) throws Exception {
  168. JsonParser jsonParser = new JsonParser();
  169. String url = ScheduleUtil.apiUrl + "RescheduleApply/Extend/Substitute/PreTesting";
  170. JsonObject jsonObject = new JsonObject();
  171. jsonObject.addProperty("timetableId", courseTable.getJianyueId());
  172. jsonObject.addProperty("isCycles", Boolean.FALSE);
  173. JsonArray extendIds = new JsonArray();
  174. extendIds.add(dto.getSubTeacherId());
  175. jsonObject.add("extendIds", extendIds);
  176. //获取时间戳
  177. long timestamp = System.currentTimeMillis();
  178. //生成签名
  179. String sign = ScheduleUtil.createSign(timestamp);
  180. String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
  181. if(StrUtil.isEmpty(result)){
  182. return null;
  183. }
  184. return jsonParser.parse(result).getAsJsonObject();
  185. }
  186. /**
  187. * 调课预检查
  188. * @param courseTable 需要调整的课程
  189. * @param swapCourseTable 对调的课程
  190. * @return 检查结果
  191. */
  192. JsonObject getExtendPreCheck(CourseTablePreCheckDto dto, CourseTable courseTable, CourseTable swapCourseTable) throws Exception {
  193. JsonParser jsonParser = new JsonParser();
  194. String url = ScheduleUtil.apiUrl + "RescheduleApply/Extend/PreTesting";
  195. JsonObject jsonObject = new JsonObject();
  196. jsonObject.addProperty("timetableId", courseTable.getJianyueId());
  197. jsonObject.addProperty("isCycles", Boolean.FALSE);
  198. // jsonObject.addProperty("startDate", "2024-01-01");
  199. // jsonObject.addProperty("endDate", "2024-01-31");
  200. // jsonObject.addProperty("dayOfweek", 5);
  201. jsonObject.addProperty("numberOfday", swapCourseTable.getTimeNumber());
  202. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  203. jsonObject.addProperty("date", dto.getSwapDate().format(formatter));
  204. jsonObject.addProperty("reschduleId", courseTable.getJianyueId());
  205. //获取时间戳
  206. long timestamp = System.currentTimeMillis();
  207. //生成签名
  208. String sign = ScheduleUtil.createSign(timestamp);
  209. String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
  210. if(StrUtil.isEmpty(result)){
  211. return null;
  212. }
  213. return jsonParser.parse(result).getAsJsonObject();
  214. }
  215. }