| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- package com.xjrsoft.module.schedule.controller;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.util.ObjectUtil;
- import cn.hutool.core.util.StrUtil;
- import cn.hutool.db.Db;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.google.gson.JsonArray;
- import com.google.gson.JsonObject;
- import com.google.gson.JsonParser;
- import com.xjrsoft.common.constant.GlobalConstant;
- import com.xjrsoft.common.enums.DeleteMark;
- import com.xjrsoft.common.enums.EnabledMark;
- import com.xjrsoft.common.model.result.RT;
- import com.xjrsoft.common.utils.DatasourceUtil;
- import com.xjrsoft.module.base.entity.BaseSemester;
- import com.xjrsoft.module.courseTable.entity.CourseTable;
- import com.xjrsoft.module.courseTable.service.ICourseTableService;
- import com.xjrsoft.module.schedule.dto.CourseTableAdjustDto;
- import com.xjrsoft.module.schedule.dto.CourseTableDto;
- import com.xjrsoft.module.schedule.dto.CourseTablePreCheckDto;
- import com.xjrsoft.module.schedule.entity.CourseReceiveMsg;
- import com.xjrsoft.module.schedule.entity.JianyueData;
- import com.xjrsoft.module.schedule.service.ICourseReceiveMsgService;
- import com.xjrsoft.module.schedule.service.IJianyueDataService;
- import com.xjrsoft.module.schedule.util.DataUtil;
- import com.xjrsoft.module.schedule.util.ScheduleUtil;
- import com.xjrsoft.module.schedule.vo.CourseListVo;
- import com.xjrsoft.module.schedule.vo.CourseTableVo;
- import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
- import com.xjrsoft.module.student.service.impl.IBaseStudentSchoolRollService;
- import com.xjrsoft.module.teacher.entity.BaseTeacher;
- import com.xjrsoft.module.teacher.service.IBaseTeacherService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.RestController;
- import javax.sql.DataSource;
- import java.time.DayOfWeek;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- /**
- * @title: 寝室
- * @Author dzx
- * @Date: 2023-12-27
- * @Version 1.0i see you monster歌曲
- */
- @RestController
- @RequestMapping("/schedule" + "/schedule")
- @Api(value = "/schedule" + "/schedule",tags = "课表代码")
- @AllArgsConstructor
- public class ScheduleController {
- private final ICourseReceiveMsgService courseReceiveMsgService;
- private final IJianyueDataService jianyueDataService;
- private final ICourseTableService courseTableService;
- private final IBaseStudentSchoolRollService baseStudentSchoolRollService;
- private final IBaseTeacherService baseTeacherService;
- @GetMapping(value = "/receive-msg")
- @ApiOperation(value="接收消息")
- @SaCheckPermission("room:detail")
- public RT<CourseReceiveMsg> receiveMsg(@RequestParam String schoolId, @RequestParam String eduYearSerialNo, @RequestParam String startDate, @RequestParam String endDate) throws Exception {
- CourseReceiveMsg courseReceiveMsg = new CourseReceiveMsg();
- courseReceiveMsg.setCreateDate(new Date());
- courseReceiveMsg.setSchoolId(schoolId);
- courseReceiveMsg.setEduYearSerialNo(eduYearSerialNo);
- courseReceiveMsg.setStartDate(startDate);
- courseReceiveMsg.setEndDate(endDate);
- courseReceiveMsg.setDeleteMark(DeleteMark.NODELETE.getCode());
- courseReceiveMsg.setEnabledMark(EnabledMark.ENABLED.getCode());
- courseReceiveMsgService.save(courseReceiveMsg);
- DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
- Db use = Db.use(datasource);
- DataUtil dataUtil = new DataUtil();
- JsonArray scheduleInfo = dataUtil.getScheduleInfoByGrade(eduYearSerialNo, startDate, endDate);
- String sql = "SELECT distinct table_name FROM jianyue_data WHERE 1 = 1";
- List<JianyueData> query = use.query(sql, JianyueData.class);
- Set<String> tables = new HashSet<>();
- for (JianyueData jianyueData : query) {
- tables.add(jianyueData.getTableName());
- }
- sql = "SELECT * FROM jianyue_data WHERE 0 = 0";
- List<JianyueData> list = use.query(sql, JianyueData.class);
- Map<String, Map<String, Long>> dataMap = new HashMap<>();
- for (String table : tables) {
- Map<String, Long> tableData = new HashMap<>();
- for (JianyueData jianyueData : list) {
- if(!table.equals(jianyueData.getTableName())){
- continue;
- }
- tableData.put(jianyueData.getJianyueId(), jianyueData.getSourceId());
- }
- dataMap.put(table, tableData);
- }
- //获取学期
- String tableName = "base_semester";
- Map<String, Long> semesterMap = dataMap.get(tableName);
- //获取课程
- tableName = "base_course_subject";
- Map<String, Long> courseMap = dataMap.get(tableName);
- //获取教职工
- tableName = "base_teacher";
- Map<String, Long> teacherMap = dataMap.get(tableName);
- //获取行政班
- tableName = "base_class";
- Map<String, Long> classMap = dataMap.get(tableName);
- tableName = "base_classroom";
- Map<String, Long> classroomMap = dataMap.get(tableName);
- dataUtil.insertCourseTable(use, scheduleInfo, classroomMap, courseMap, semesterMap, teacherMap, classMap);
- //查询当前学期id
- String currenSemeter = dataUtil.getCurrenSemeter();
- if(StrUtil.isEmpty(currenSemeter)){
- return RT.ok(courseReceiveMsg);
- }
- sql = "SELECT * FROM base_semester WHERE id = (select source_id from jianyue_data where jianyue_id = '" + currenSemeter + "')";
- List<BaseSemester> semesters = use.query(sql, BaseSemester.class);
- if(semesters.isEmpty()){
- return RT.ok(courseReceiveMsg);
- }
- BaseSemester baseSemester = semesters.get(0);
- dataUtil.insertClassTime(use, scheduleInfo, baseSemester);
- return RT.ok(courseReceiveMsg);
- }
- @GetMapping(value = "/course-table")
- @ApiOperation(value="课表接口(PC端)")
- @SaCheckPermission("room:detail")
- public RT<CourseTableVo> courseInfo(CourseTableDto dto){
- CourseTableVo list = courseTableService.getList(dto);
- return RT.ok(list);
- }
- @GetMapping(value = "/course-table-day")
- @ApiOperation(value="今日课表接口(手机端)")
- @SaCheckPermission("room:detail")
- public RT<CourseTableVo> courseInfoDay(CourseTableDto dto){
- DayOfWeek dayOfWeek = LocalDateTime.now().getDayOfWeek();
- dto.setWeekDay(dayOfWeek.getValue());
- if(ObjectUtil.isNotNull(dto.getStudentId())){
- List<BaseStudentSchoolRoll> schoolRolls = baseStudentSchoolRollService.list(
- new QueryWrapper<BaseStudentSchoolRoll>().lambda().eq(BaseStudentSchoolRoll::getUserId, dto.getStudentId())
- );
- if(schoolRolls != null && !schoolRolls.isEmpty()){
- dto.setCourseType("class");
- dto.setClassId(schoolRolls.get(0).getClassId());
- }
- }else{
- // 查询登录者身份
- long loginIdAsLong = StpUtil.getLoginIdAsLong();
- List<BaseStudentSchoolRoll> schoolRolls = baseStudentSchoolRollService.list(
- new QueryWrapper<BaseStudentSchoolRoll>().lambda().eq(BaseStudentSchoolRoll::getUserId, loginIdAsLong)
- );
- if(schoolRolls != null && !schoolRolls.isEmpty()){
- dto.setCourseType("class");
- dto.setClassId(schoolRolls.get(0).getClassId());
- }
- List<BaseTeacher> teachers = baseTeacherService.list(new QueryWrapper<BaseTeacher>().lambda().eq(BaseTeacher::getUserId, loginIdAsLong));
- if(teachers != null && !teachers.isEmpty()){
- dto.setCourseType("teacher");
- dto.setTeacherId(loginIdAsLong);
- }
- }
- CourseTableVo list = courseTableService.getList(dto);
- return RT.ok(list);
- }
- @GetMapping(value = "/adjust-list")
- @ApiOperation(value = "可以调课的课程")
- @SaCheckPermission("evaluateobject:detail")
- public RT<List<CourseListVo>> adjustList(CourseTableAdjustDto dto){
- // if(dto.getAdjustDate() == null || dto.getTeacherId() == null){
- // return RT.error("请传入调整日期和教师id");
- // }
- // List<CourseListVo> list = courseTableService.getAdjustList(dto);
- // if(list.isEmpty()){
- // return RT.error("暂无可调课程");
- // }
- return RT.ok();
- }
- @GetMapping(value = "/pre-check")
- @ApiOperation(value = "预检查")
- @SaCheckPermission("evaluateobject:detail")
- public RT<String> preCheck(CourseTablePreCheckDto dto) throws Exception {
- if(dto.getPreCheckType() != null){
- if(dto.getPreCheckType() == 1){
- CourseTable courseTable = courseTableService.getById(dto.getCourseId());
- CourseTable swapCourseTable = courseTableService.getById(dto.getSwapCourseId());
- JsonObject preCheck = getExtendPreCheck(dto, courseTable, swapCourseTable);
- if(!preCheck.get("data").getAsBoolean()){
- return RT.error(preCheck.get("msg").getAsString());
- }
- }else if(dto.getPreCheckType() == 2){
- CourseTable courseTable = courseTableService.getById(dto.getCourseId());
- JsonObject jsonObject = substitutePreTestin(dto, courseTable);
- if(!jsonObject.get("data").getAsBoolean()){
- return RT.error(jsonObject.get("msg").getAsString());
- }
- }
- }
- return RT.ok("ok");
- }
- /**
- * 顶课预检查
- * @param dto
- * @param courseTable
- * @return 检查结果
- */
- JsonObject substitutePreTestin(CourseTablePreCheckDto dto, CourseTable courseTable) throws Exception {
- JsonParser jsonParser = new JsonParser();
- String url = ScheduleUtil.apiUrl + "RescheduleApply/Extend/Substitute/PreTesting";
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("timetableId", courseTable.getJianyueId());
- jsonObject.addProperty("isCycles", Boolean.FALSE);
- JsonArray extendIds = new JsonArray();
- extendIds.add(dto.getSubTeacherId());
- jsonObject.add("extendIds", extendIds);
- //获取时间戳
- long timestamp = System.currentTimeMillis();
- //生成签名
- String sign = ScheduleUtil.createSign(timestamp);
- String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
- if(StrUtil.isEmpty(result)){
- return null;
- }
- return jsonParser.parse(result).getAsJsonObject();
- }
- /**
- * 调课预检查
- * @param courseTable 需要调整的课程
- * @param swapCourseTable 对调的课程
- * @return 检查结果
- */
- JsonObject getExtendPreCheck(CourseTablePreCheckDto dto, CourseTable courseTable, CourseTable swapCourseTable) throws Exception {
- JsonParser jsonParser = new JsonParser();
- String url = ScheduleUtil.apiUrl + "RescheduleApply/Extend/PreTesting";
- JsonObject jsonObject = new JsonObject();
- jsonObject.addProperty("timetableId", courseTable.getJianyueId());
- jsonObject.addProperty("isCycles", Boolean.FALSE);
- // jsonObject.addProperty("startDate", "2024-01-01");
- // jsonObject.addProperty("endDate", "2024-01-31");
- // jsonObject.addProperty("dayOfweek", 5);
- jsonObject.addProperty("numberOfday", swapCourseTable.getTimeNumber());
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- jsonObject.addProperty("date", dto.getSwapDate().format(formatter));
- jsonObject.addProperty("reschduleId", courseTable.getJianyueId());
- //获取时间戳
- long timestamp = System.currentTimeMillis();
- //生成签名
- String sign = ScheduleUtil.createSign(timestamp);
- String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
- if(StrUtil.isEmpty(result)){
- return null;
- }
- return jsonParser.parse(result).getAsJsonObject();
- }
- }
|