|
|
@@ -22,6 +22,7 @@ import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.common.enums.CourseAdjustTypeEnum;
|
|
|
+import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.enums.TimeNumberEnum;
|
|
|
import com.xjrsoft.common.enums.TimePeriodEnum;
|
|
|
import com.xjrsoft.common.enums.WeekEnum;
|
|
|
@@ -31,7 +32,11 @@ import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
|
|
|
import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
|
|
|
import com.xjrsoft.config.TimetableConfig;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClassroom;
|
|
|
+import com.xjrsoft.module.base.entity.BaseOfficeBuild;
|
|
|
import com.xjrsoft.module.base.entity.BaseSemester;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseClassroomMapper;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseOfficeBuildMapper;
|
|
|
import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
|
|
|
import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
import com.xjrsoft.module.base.service.IBaseSemesterService;
|
|
|
@@ -49,10 +54,12 @@ import com.xjrsoft.module.organization.service.IUserService;
|
|
|
import com.xjrsoft.module.schedule.dto.ClassOptionDto;
|
|
|
import com.xjrsoft.module.schedule.dto.CourseTableAdjustDto;
|
|
|
import com.xjrsoft.module.schedule.dto.CourseTableDto;
|
|
|
+import com.xjrsoft.module.schedule.dto.CourseTableExportQueryDto;
|
|
|
import com.xjrsoft.module.schedule.dto.ScheduleWeekExportQueryDto;
|
|
|
import com.xjrsoft.module.schedule.entity.CourseTableBak;
|
|
|
import com.xjrsoft.module.schedule.entity.WfCourseAdjust;
|
|
|
import com.xjrsoft.module.schedule.mapper.CourseTableBakMapper;
|
|
|
+import com.xjrsoft.module.schedule.util.CourseTableExportQueryUtil;
|
|
|
import com.xjrsoft.module.schedule.util.ScheduleUtil;
|
|
|
import com.xjrsoft.module.schedule.vo.*;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
@@ -60,6 +67,7 @@ import com.xjrsoft.module.student.service.IBaseStudentSchoolRollService;
|
|
|
import com.xjrsoft.module.teacher.entity.BaseTeacher;
|
|
|
import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import com.xjrsoft.module.teacher.service.ITeacherbaseManagerService;
|
|
|
+import com.xjrsoft.module.veb.util.ImportExcelUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import me.zhyd.oauth.log.Log;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
@@ -105,6 +113,8 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
private final IBaseStudentSchoolRollService baseStudentSchoolRollService;
|
|
|
private final CourseTableBakMapper courseTableBakMapper;
|
|
|
private final IUserService userService;
|
|
|
+ private final BaseClassroomMapper classroomMapper;
|
|
|
+ private final BaseOfficeBuildMapper officeBuildMapper;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -249,7 +259,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
tableVo.setTeacherName(xjrUser.getName());
|
|
|
}
|
|
|
}
|
|
|
- if (dto.getStartDate() != null && dto.getEndDate() != null) {
|
|
|
+ if (dto.getStartDate() != null && dto.getEndDate() != null && dto.getIsCustom() == null) {
|
|
|
if (dto.getStudentId() == null && dto.getTeacherId() == null && dto.getClassId() == null) {
|
|
|
dto.setTeacherId(StpUtil.getLoginIdAsLong());
|
|
|
} else {
|
|
|
@@ -383,6 +393,9 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
for (int i = 0; i < courseIds.length; i++) {
|
|
|
String courseId = courseIds[i];
|
|
|
String exchangeCourseId = exchangeCourseIds[i];
|
|
|
+ if (StrUtil.isEmpty(exchangeCourseId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
//调课,将双方课程的日期(schedule_date)、时段(time_period)、节次(time_number)、周(week)、星期几(1-7)(weeks)、星期中文(weeks_cn)对调
|
|
|
CourseTable courseTable = courseMap.get(bakKeyInfoMap.get(Long.parseLong(courseId)));
|
|
|
@@ -995,7 +1008,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
|
|
|
createFirstTitle(workbook, sheet, data, dto);
|
|
|
|
|
|
- createSecondTitle(workbook, sheet);
|
|
|
+ createSecondTitle(workbook, sheet, 1);
|
|
|
|
|
|
Map<Integer, ClassTime> timeNumberMap = data.getClassTimeList().stream().collect(Collectors.toMap(ClassTime::getNumber, x -> x));
|
|
|
Map<String, List<CourseDetailVo>> timeNumberDataMap = data.getCourseList().stream().collect(Collectors.groupingBy(CourseDetailVo::getTimeNumber));
|
|
|
@@ -1122,7 +1135,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void createSecondTitle(Workbook workbook, Sheet sheet) {
|
|
|
+ void createSecondTitle(Workbook workbook, Sheet sheet, int rowNumber) {
|
|
|
// 创建一个字体对象
|
|
|
Font font = workbook.createFont();
|
|
|
font.setBold(true);// 设置为粗体
|
|
|
@@ -1140,7 +1153,6 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
|
|
|
- int rowNumber = 1;
|
|
|
Row row = sheet.createRow(rowNumber);
|
|
|
|
|
|
int cellNumber = 0;
|
|
|
@@ -1249,4 +1261,262 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
|
|
|
return this.baseMapper.getSubstituteTeacherCourseCountByParams(dto);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 课表导出
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ByteArrayOutputStream exportQuery(CourseTableExportQueryDto dto) throws IOException {
|
|
|
+ BaseSemester baseSemester = baseSemesterMapper.selectById(dto.getSemesterId());
|
|
|
+ CourseTableExportQueryUtil exportQueryUtil = new CourseTableExportQueryUtil();
|
|
|
+ String schoolName = "重庆市铜梁职业教育中心";
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ //查询数据
|
|
|
+ CourseTableDto dataDto = new CourseTableDto();
|
|
|
+ dataDto.setSemesterId(dto.getSemesterId());
|
|
|
+ dataDto.setWeek(dto.getWeek());
|
|
|
+ dataDto.setIsCustom(1);
|
|
|
+ CourseTableVo tableVo = this.getList(dataDto);
|
|
|
+
|
|
|
+ if("class".equals(dto.getCourseType())){//班级课表
|
|
|
+ //根据年级、专业部,查询需要导出的班级
|
|
|
+ List<BaseClass> classList = baseClassService.list(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ .in(BaseClass::getGradeId, dto.getGradeIds())
|
|
|
+ .in(BaseClass::getOrgId, dto.getDeptIds())
|
|
|
+ );
|
|
|
+ if(classList.isEmpty()){
|
|
|
+ throw new MyException("未查询到班级,无法导出");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, List<CourseDetailVo>> classDataMap = tableVo.getCourseList().stream().filter(x -> x.getClassName() != null).collect(Collectors.groupingBy(CourseDetailVo::getClassName));
|
|
|
+
|
|
|
+ List<Long> teacherIds = classList.stream().map(BaseClass::getTeacherId).collect(Collectors.toList());
|
|
|
+ List<User> userList = userService.listByIds(teacherIds);
|
|
|
+ Map<Long, String> teacherMap = userList.stream().collect(Collectors.toMap(User::getId, User::getName));
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ String sheetName = "班级课表";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+ String bigHead = "课程表";
|
|
|
+
|
|
|
+ int classTableRowCount = 16;//每个班的课表占用的总行数
|
|
|
+ int i = 0;
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ CourseTableVo classData = new CourseTableVo();
|
|
|
+ classData.setClassTimeList(tableVo.getClassTimeList());
|
|
|
+ if(!classDataMap.containsKey(baseClass.getName())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ classData.setCourseList(classDataMap.get(baseClass.getName()));
|
|
|
+
|
|
|
+ String rightName = "班主任:" + teacherMap.get(baseClass.getTeacherId()) + " 行政班:" + baseClass.getName();
|
|
|
+ int bigHeadRow = (classTableRowCount + 3) * i;
|
|
|
+ //生成第一行title
|
|
|
+ ImportExcelUtil.createBigHead(workbook, sheet, bigHead, bigHeadRow, 8);
|
|
|
+ //生成副标题,展示所属学期
|
|
|
+ ImportExcelUtil.createSubtitle(workbook, sheet, baseSemester.getName(), bigHeadRow + 1, 8);
|
|
|
+ //生成第三行,显示学校名字、班主任和班级名字
|
|
|
+ exportQueryUtil.createThirdTitle(workbook, sheet, bigHeadRow + 2, schoolName, rightName);
|
|
|
+ //生成表头
|
|
|
+ createSecondTitle(workbook, sheet, bigHeadRow + 3);
|
|
|
+ //生成内容
|
|
|
+ exportQueryUtil.createContent(workbook, sheet, bigHeadRow + 4, classData, dto.getCourseType());
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+ workbook.write(bot);
|
|
|
+ }else if("teacher".equals(dto.getCourseType())){//教师课表
|
|
|
+ //根据学期和周次,查询当前所有有课表的教师id
|
|
|
+ LocalDateTime startDateTime = LocalDateTime.ofInstant(baseSemester.getTeachingStart().toInstant(), ZoneId.systemDefault());
|
|
|
+
|
|
|
+ LocalDate startDate = startDateTime.plusDays((dto.getWeek() - 1) * 7L).toLocalDate();
|
|
|
+ LocalDate endDate = startDate.plusDays(6);
|
|
|
+
|
|
|
+ List<CourseTable> list = this.list(
|
|
|
+ new QueryWrapper<CourseTable>().lambda()
|
|
|
+ .eq(CourseTable::getBaseSemesterId, dto.getSemesterId())
|
|
|
+ .ge(CourseTable::getScheduleDate, startDate)
|
|
|
+ .le(CourseTable::getScheduleDate, endDate)
|
|
|
+ );
|
|
|
+ Set<String> teacherIds = list.stream().map(CourseTable::getTeacherId).collect(Collectors.toSet());
|
|
|
+ Set<Long> teacherIdList = new HashSet<>();
|
|
|
+ for (String teacherId : teacherIds) {
|
|
|
+ String[] split = teacherId.split(", ");
|
|
|
+ for (String s : split) {
|
|
|
+ teacherIdList.add(Long.parseLong(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<User> userList = userService.listByIds(teacherIdList);
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ String sheetName = "教师课表";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+ String bigHead = "课程表";
|
|
|
+ int classTableRowCount = 16;//每个班的课表占用的总行数
|
|
|
+
|
|
|
+ for(int i = 0; i < userList.size(); i ++){
|
|
|
+ User user = userList.get(i);
|
|
|
+ List<CourseDetailVo> courseList = tableVo.getCourseList().stream().filter(x -> x.getTeacherName().contains(user.getName())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ CourseTableVo classData = new CourseTableVo();
|
|
|
+ classData.setClassTimeList(tableVo.getClassTimeList());
|
|
|
+ classData.setCourseList(courseList);
|
|
|
+
|
|
|
+ String rightName = "教师:" + user.getName();
|
|
|
+ int bigHeadRow = (classTableRowCount + 3) * i;
|
|
|
+ //生成第一行title
|
|
|
+ ImportExcelUtil.createBigHead(workbook, sheet, bigHead, bigHeadRow, 8);
|
|
|
+ //生成副标题,展示所属学期
|
|
|
+ ImportExcelUtil.createSubtitle(workbook, sheet, baseSemester.getName(), bigHeadRow + 1, 8);
|
|
|
+ //生成第三行,显示学校名字、班主任和班级名字
|
|
|
+ exportQueryUtil.createThirdTitle(workbook, sheet, bigHeadRow + 2, schoolName, rightName);
|
|
|
+ //生成表头
|
|
|
+ createSecondTitle(workbook, sheet, bigHeadRow + 3);
|
|
|
+ //生成内容
|
|
|
+ exportQueryUtil.createContent(workbook, sheet, bigHeadRow + 4, classData, dto.getCourseType());
|
|
|
+ }
|
|
|
+ workbook.write(bot);
|
|
|
+ }else if("classroom".equals(dto.getCourseType())){//教室课表
|
|
|
+ Map<String, List<CourseDetailVo>> classroomDataMap = tableVo.getCourseList().stream().filter(x -> x.getClassroomName() != null).collect(Collectors.groupingBy(CourseDetailVo::getClassroomName));
|
|
|
+ List<BaseClassroom> classroomList = classroomMapper.selectList(
|
|
|
+ new QueryWrapper<BaseClassroom>().lambda()
|
|
|
+ .eq(BaseClassroom::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ List<BaseOfficeBuild> buildList = officeBuildMapper.selectList(
|
|
|
+ new QueryWrapper<BaseOfficeBuild>().lambda()
|
|
|
+ .eq(BaseOfficeBuild::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ );
|
|
|
+ Map<Long, String> buildMap = buildList.stream().collect(Collectors.toMap(BaseOfficeBuild::getId, BaseOfficeBuild::getName));
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ String sheetName = "教室课表";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+ String bigHead = "课程表";
|
|
|
+ int classTableRowCount = 16;//每个班的课表占用的总行数
|
|
|
+ int i = 0;
|
|
|
+ for (BaseClassroom baseClassroom : classroomList) {
|
|
|
+ String classroomName = buildMap.get(baseClassroom.getOfficeBuildId()) + baseClassroom.getName();
|
|
|
+ if(!classroomDataMap.containsKey(classroomName)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CourseDetailVo> courseList = classroomDataMap.get(classroomName);
|
|
|
+
|
|
|
+ CourseTableVo classData = new CourseTableVo();
|
|
|
+ classData.setClassTimeList(tableVo.getClassTimeList());
|
|
|
+ classData.setCourseList(courseList);
|
|
|
+
|
|
|
+ int bigHeadRow = (classTableRowCount + 3) * i;
|
|
|
+ //生成第一行title
|
|
|
+ ImportExcelUtil.createBigHead(workbook, sheet, bigHead, bigHeadRow, 8);
|
|
|
+ //生成副标题,展示所属学期
|
|
|
+ ImportExcelUtil.createSubtitle(workbook, sheet, baseSemester.getName(), bigHeadRow + 1, 8);
|
|
|
+ //生成第三行,显示学校名字、班主任和班级名字
|
|
|
+ exportQueryUtil.createThirdTitle(workbook, sheet, bigHeadRow + 2, schoolName, classroomName);
|
|
|
+ //生成表头
|
|
|
+ createSecondTitle(workbook, sheet, bigHeadRow + 3);
|
|
|
+ //生成内容
|
|
|
+ exportQueryUtil.createContent(workbook, sheet, bigHeadRow + 4, classData, dto.getCourseType());
|
|
|
+
|
|
|
+ i ++;
|
|
|
+ }
|
|
|
+ workbook.write(bot);
|
|
|
+ }else if("all".equals(dto.getCourseType())){//总课表
|
|
|
+ //根据年级、专业部,查询需要导出的班级
|
|
|
+ List<BaseClass> classList = baseClassService.list(
|
|
|
+ new QueryWrapper<BaseClass>().lambda()
|
|
|
+ .eq(BaseClass::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
+ .eq(BaseClass::getIsGraduate, 1)
|
|
|
+ .in(BaseClass::getGradeId, dto.getGradeIds())
|
|
|
+ .in(BaseClass::getOrgId, dto.getDeptIds())
|
|
|
+ .orderByAsc(BaseClass::getName)
|
|
|
+ );
|
|
|
+ if(classList.isEmpty()){
|
|
|
+ throw new MyException("未查询到班级,无法导出");
|
|
|
+ }
|
|
|
+ Map<String, List<CourseDetailVo>> classDataMap = tableVo.getCourseList().stream().filter(x -> x.getClassName() != null).collect(Collectors.groupingBy(CourseDetailVo::getClassName));
|
|
|
+ ArrayList<ArrayList<String>> dataList = new ArrayList<>();
|
|
|
+ for (BaseClass baseClass : classList) {
|
|
|
+ List<CourseDetailVo> detailVoList = classDataMap.get(baseClass.getName());
|
|
|
+ if(detailVoList == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<Integer, List<CourseDetailVo>> weeksMap = detailVoList.stream().collect(Collectors.groupingBy(CourseDetailVo::getWeeks));
|
|
|
+
|
|
|
+ List<Integer> weekList = new ArrayList<>();
|
|
|
+ weekList.add(1);
|
|
|
+ weekList.add(2);
|
|
|
+ weekList.add(3);
|
|
|
+ weekList.add(4);
|
|
|
+ weekList.add(5);
|
|
|
+ weekList.add(6);
|
|
|
+ weekList.add(7);
|
|
|
+
|
|
|
+ ArrayList<String> classData = new ArrayList<>();
|
|
|
+ classData.add(baseClass.getName());
|
|
|
+ for (Integer weeks : weekList) {
|
|
|
+ if(!weeksMap.containsKey(weeks)){
|
|
|
+ for (ClassTime classTime : tableVo.getClassTimeList()) {
|
|
|
+ classData.add("");
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<String, CourseDetailVo> timeNumberMap = weeksMap.get(weeks).stream().filter(x -> x.getTimeNumber() != null).collect(Collectors.toMap(CourseDetailVo::getTimeNumber, x -> x));
|
|
|
+ for (ClassTime classTime : tableVo.getClassTimeList()) {
|
|
|
+ CourseDetailVo courseDetailVo = timeNumberMap.get(classTime.getNumber().toString());
|
|
|
+ if(courseDetailVo == null){
|
|
|
+ classData.add("");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String content = courseDetailVo.getCourseName() + "\r\n" + courseDetailVo.getTeacherName();
|
|
|
+ if(courseDetailVo.getClassroomName() != null){
|
|
|
+ content += "\r\n" + courseDetailVo.getClassroomName();
|
|
|
+ }
|
|
|
+ classData.add(content);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataList.add(classData);
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ String sheetName = "总课表";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ exportQueryUtil.createAllCourseTableTitle(workbook, sheet, tableVo.getClassTimeList());
|
|
|
+
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short) 12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ cellStyle.setBorderTop(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderBottom(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderLeft(BorderStyle.THIN);
|
|
|
+ cellStyle.setBorderRight(BorderStyle.THIN);
|
|
|
+ cellStyle.setWrapText(true);
|
|
|
+ int rowNumber = 2;
|
|
|
+ for (ArrayList<String> rowData : dataList) {
|
|
|
+ Row row = sheet.createRow(rowNumber);
|
|
|
+ for (int i = 0; i < rowData.size(); i++) {
|
|
|
+ Cell cell = row.createCell(i);
|
|
|
+ cell.setCellValue(rowData.get(i));
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+ rowNumber++;
|
|
|
+ row.setHeightInPoints(48);
|
|
|
+ }
|
|
|
+
|
|
|
+ workbook.write(bot);
|
|
|
+ }
|
|
|
+ return bot;
|
|
|
+ }
|
|
|
+
|
|
|
}
|