diff --git a/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseScoreDashboardDao.java b/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseScoreDashboardDao.java index 82b4b707..0395b5f1 100644 --- a/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseScoreDashboardDao.java +++ b/web/src/main/java/com/ibeetl/jlw/dao/TeacherOpenCourseScoreDashboardDao.java @@ -29,4 +29,6 @@ public interface TeacherOpenCourseScoreDashboardDao extends BaseMapper>getExcelValues(TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery); @Update int deleteByTeacherOpenCourseId(Long teacherOpenCourseId); + + List queryByConditionQueryNotPage(TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery); } diff --git a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseQuestionSetting.java b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseQuestionSetting.java index 65c50384..6296dc4e 100644 --- a/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseQuestionSetting.java +++ b/web/src/main/java/com/ibeetl/jlw/entity/TeacherOpenCourseQuestionSetting.java @@ -175,7 +175,7 @@ public class TeacherOpenCourseQuestionSetting extends BaseEntity { @UpdateIgnore @InsertIgnore - @FetchSql("select count(1) " + + @FetchSql("select count(*) " + "from resources_question_snapshot t where t.teacher_open_course_question_setting_id = #teacherOpenCourseQuestionSettingId# \n" + "and t.question_status = 1 \n" ) diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeResourcesQuestionService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeResourcesQuestionService.java index 0af4cdd9..bb50dc40 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeResourcesQuestionService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseMergeResourcesQuestionService.java @@ -210,7 +210,7 @@ public class TeacherOpenCourseMergeResourcesQuestionService extends CoreBaseServ //查询章节题目配置信息 TeacherOpenCourseQuestionSettingQuery questionSettingQuery = new TeacherOpenCourseQuestionSettingQuery(); - questionSettingQuery.setTeacherOpenCourseQuestionSettingName(courseInfo.getCourseInfoName()); + questionSettingQuery.setTeacherOpenCourseMergeCourseInfoId(mergeCourseInfoId); questionSettingQuery.setTeacherOpenCourseQuestionSettingStatus(1); TeacherOpenCourseQuestionSetting questionSetting = teacherOpenCourseQuestionSettingService.getInfo(questionSettingQuery); diff --git a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScoreDashboardService.java b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScoreDashboardService.java index 8b338dff..69acf894 100644 --- a/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScoreDashboardService.java +++ b/web/src/main/java/com/ibeetl/jlw/service/TeacherOpenCourseScoreDashboardService.java @@ -3,11 +3,13 @@ package com.ibeetl.jlw.service; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; import cn.jlw.util.ToolUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ibeetl.admin.core.entity.CoreUser; import com.ibeetl.admin.core.service.CoreBaseService; +import com.ibeetl.admin.core.util.BeanCopyUtil; import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.TimeTool; import com.ibeetl.admin.core.web.JsonResult; @@ -34,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletResponse; import javax.validation.constraints.NotNull; import java.io.*; import java.math.BigDecimal; @@ -43,6 +46,9 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; +import static com.ibeetl.admin.core.util.ExcelUtil.convertData; +import static com.ibeetl.admin.core.util.ExcelUtil.write; + /** * 成绩 Service * 当分布式ID开启后请勿使用insert(*,true) @@ -82,8 +88,12 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService queryByCondition(PageQuery query) { PageQuery ret = teacherOpenCourseScoreDashboardDao.queryByCondition(query); @@ -498,7 +508,7 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService v.getChatLogSendType().equals(ChatLogSendTypeEnum.normal) - && v.getStudentScore() != null + && v.getStudentScore() != null ).count(); BigDecimal chatScore = BigDecimal.ZERO; if (weight != null && StringUtils.isNotEmpty(weight.getInteractionResultSetting())) { @@ -645,13 +655,13 @@ public class TeacherOpenCourseScoreDashboardService extends CoreBaseService queryByConditionQueryNotPage(TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery) { + return teacherOpenCourseScoreDashboardDao.queryByConditionQueryNotPage(teacherOpenCourseScoreDashboardQuery); + } + + public void export(HttpServletResponse response, TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, CoreUser coreUser) throws IOException { + if (coreUser.isStudent()) { + Student student = studentService.getByUserId(coreUser.getId()); + if (student != null) { + teacherOpenCourseScoreDashboardQuery.setStudentId(student.getStudentId()); + } + } + /** 构建表头 */ + Map header = new LinkedHashMap<>(13); + header.put("studentSn", "学号"); + header.put("studentName", "姓名"); + header.put("className", "班级"); + header.put("signinScore", "签到成绩"); + header.put("courseScore", "章节练习成绩"); + header.put("realOperationScore", "课程实操成绩"); + header.put("questionHomeworkScore", "作业成绩"); + header.put("examScore", "考试成绩"); + header.put("chatScore", "互动成绩"); + header.put("totalScore", "总成绩"); + header.put("manualScore", "手动调整的分数"); + header.put("lastScore", "最终成绩"); + header.put("lastStatus", "成绩状态"); + + List teacherOpenCourseScoreDashboardList = this.queryByConditionQueryNotPage(teacherOpenCourseScoreDashboardQuery); + + + List> maps = BeanCopyUtil.baseEntity2MapWithParallel(teacherOpenCourseScoreDashboardList); + + String filename = StrUtil.format("成绩-导出 {}.xlsx", System.currentTimeMillis()); + write(response, filename, "Sheet1", header.values(), convertData(header.keySet(), maps)); + } } diff --git a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseScoreDashboardController.java b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseScoreDashboardController.java index 839f354a..3148b913 100644 --- a/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseScoreDashboardController.java +++ b/web/src/main/java/com/ibeetl/jlw/web/TeacherOpenCourseScoreDashboardController.java @@ -7,21 +7,20 @@ import cn.jlw.validate.ValidateConfig; import com.ibeetl.admin.core.annotation.Function; import com.ibeetl.admin.core.entity.CoreUser; import com.ibeetl.admin.core.file.FileService; +import com.ibeetl.admin.core.util.PlatformException; import com.ibeetl.admin.core.util.TimeTool; import com.ibeetl.admin.core.web.JsonResult; import com.ibeetl.jlw.dao.StudentDao; import com.ibeetl.jlw.entity.FileEntity; import com.ibeetl.jlw.entity.Student; import com.ibeetl.jlw.entity.TeacherOpenCourseScoreDashboard; +import com.ibeetl.jlw.job.TeacherOpenCourseScoreDashboardJob; import com.ibeetl.jlw.service.TeacherOpenCourseScoreDashboardService; import com.ibeetl.jlw.web.query.TeacherOpenCourseScoreDashboardQuery; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.poi.hssf.usermodel.*; -import org.apache.poi.ss.usermodel.HorizontalAlignment; -import org.apache.poi.ss.usermodel.VerticalAlignment; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.beetl.sql.core.engine.PageQuery; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +33,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Date; @@ -283,149 +283,19 @@ public class TeacherOpenCourseScoreDashboardController { //导出信息 @RequestMapping(MODEL + "/excel/export.json") - public void export(HttpServletRequest request, HttpServletResponse response, TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, @SCoreUser CoreUser coreUser) { + public void export( HttpServletResponse response, TeacherOpenCourseScoreDashboardQuery teacherOpenCourseScoreDashboardQuery, @SCoreUser CoreUser coreUser) throws IOException { if (null == coreUser) { - return; + throw new PlatformException("请登录后再操作"); } - HSSFWorkbook workbook = null; - try { - //表头数据 - String[] header = { - "学生", - "签到成绩", - "章节练习成绩", - "课程实操成绩", - "作业成绩", - "考试成绩", - "互动成绩", - "总成绩", - "手动调整的分数", - "最终成绩", - "成绩状态", - "创建时间" - }; - String[] headerCode = { - "studentId", - "signinScore", - "courseScore", - "realOperationScore", - "questionHomeworkScore", - "examScore", - "chatScore", - "totalScore", - "manualScore", - "lastScore", - "lastStatus", - "createTime" - }; - - //数据内容 - List> mapList = teacherOpenCourseScoreDashboardService.getExcelValues(teacherOpenCourseScoreDashboardQuery); - - //内容宽度 - Map widthMap = mapList.get(0); - mapList.remove(0); - - //声明一个工作簿 - workbook = new HSSFWorkbook(); - - //生成一个表格,设置表格名称为"Sheet1" - HSSFSheet sheet = workbook.createSheet("Sheet1"); - - //冻结表头 - sheet.createFreezePane(0, 1, 0, 1); - - //设置默认列宽度为5个字节 - sheet.setDefaultColumnWidth(5); - - //创建第一行表头 - HSSFRow headRow = sheet.createRow(0); - - //头部样式 - HSSFCellStyle headerStyle = workbook.createCellStyle(); - //垂直居中 - headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); - //水平居中 - headerStyle.setAlignment(HorizontalAlignment.CENTER); - - //单元格样式 - HSSFCellStyle cellStyle = workbook.createCellStyle(); - //垂直居中 - cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); - //水平居左 - cellStyle.setAlignment(HorizontalAlignment.CENTER); - //自动换行 - cellStyle.setWrapText(true); - - //遍历添加表头 - for (int i = 0; i < header.length; i++) { - - //设置表格特定的列宽度 - if (null != widthMap.get(headerCode[i])) { - String width = widthMap.get(headerCode[i]).toString().split("\\.")[0]; - Integer w = Integer.parseInt(width) > header[i].length() * 3 ? Integer.parseInt(width) : header[i].length() * 3; - sheet.setColumnWidth(i, w * 190); - } - - //创建一个单元格 - HSSFCell cell = headRow.createCell(i); - - //创建一个内容对象 - HSSFRichTextString text = new HSSFRichTextString(header[i]); - - //将内容对象的文字内容写入到单元格中 - cell.setCellValue(text); - - //设置样式 - cell.setCellStyle(headerStyle); - } - - //遍历结果集,把内容加入表格 - for (int i = 0; i < mapList.size(); i++) { - HSSFRow row = sheet.createRow(i + 1); - - row.setHeight((short) (50 * 10)); - Map map = mapList.get(i); - for (int j = 0; j < headerCode.length; j++) { - HSSFCell cell = row.createCell(j); - cell.setCellStyle(cellStyle); - HSSFRichTextString text = new HSSFRichTextString(null != map.get(headerCode[j]) ? map.get(headerCode[j]).toString() : " "); - cell.setCellValue(text); - } - } - - - //准备将Excel的输出流通过response输出到页面下载 - //八进制输出流 - response.setContentType("application/octet-stream"); - - //这后面可以设置导出Excel的名称,此例中名为student.xls - response.setHeader("Content-disposition", "attachment;filename=competitionTeacher(" + TimeTool.getNowTime("YMD") + ").xls"); + teacherOpenCourseScoreDashboardService.export( response, teacherOpenCourseScoreDashboardQuery, coreUser); - //刷新缓冲 - response.flushBuffer(); - - //workbook将Excel写入到response的输出流中,供页面下载 - workbook.write(response.getOutputStream()); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (null != workbook) { - workbook.close(); - } - if (null != response && null != response.getOutputStream()) { - response.getOutputStream().close(); - } - } catch (Exception e) { - } - } } /** * 更新成绩 + * * @param map teacherOpenCourseId 课程开课ID * @return */ diff --git a/web/src/main/resources/sql/jlw/teacherOpenCourseScoreDashboard.md b/web/src/main/resources/sql/jlw/teacherOpenCourseScoreDashboard.md index f760fcfd..6f4ede4b 100644 --- a/web/src/main/resources/sql/jlw/teacherOpenCourseScoreDashboard.md +++ b/web/src/main/resources/sql/jlw/teacherOpenCourseScoreDashboard.md @@ -598,3 +598,86 @@ deleteByTeacherOpenCourseId delete from teacher_open_course_score_dashboard where teacher_open_course_id = #teacherOpenCourseId# + +queryByConditionQueryNotPage +=== +* 根据不为空的参数进行查询 + + select + @pageTag(){ + t.*, + s1.student_sn studentSn, + s1.student_name studentName, + s2.class_name className + @} + from teacher_open_course_score_dashboard t + left join student s1 on s1.student_id = t.student_id + left join school_class s2 on s2.class_id = s1.class_id + where 1=1 + and #function("teacherOpenCourseScoreDashboard.query")# + @if(!isEmpty(teacherOpenCourseScoreDashboardId)){ + and t.teacher_open_course_score_dashboard_id =#teacherOpenCourseScoreDashboardId# + @} + @if(!isEmpty(teacherOpenCourseScoreDashboardIdPlural)){ + and find_in_set(t.teacher_open_course_score_dashboard_id,#teacherOpenCourseScoreDashboardIdPlural#) + @} + @if(!isEmpty(studentId)){ + and t.student_id =#studentId# + @} + @if(!isEmpty(studentIdPlural)){ + and find_in_set(t.student_id,#studentIdPlural#) + @} + @if(!isEmpty(signinScore)){ + and t.signin_score =#signinScore# + @} + @if(!isEmpty(courseScore)){ + and t.course_score =#courseScore# + @} + @if(!isEmpty(realOperationScore)){ + and t.real_operation_score =#realOperationScore# + @} + @if(!isEmpty(questionHomeworkScore)){ + and t.question_homework_score =#questionHomeworkScore# + @} + @if(!isEmpty(examScore)){ + and t.exam_score =#examScore# + @} + @if(!isEmpty(chatScore)){ + and t.chat_score =#chatScore# + @} + @if(!isEmpty(totalScore)){ + and t.total_score =#totalScore# + @} + @if(!isEmpty(manualScore)){ + and t.manual_score =#manualScore# + @} + @if(!isEmpty(lastScore)){ + and t.last_score =#lastScore# + @} + @if(!isEmpty(lastStatus)){ + and t.last_status =#lastStatus# + @} + @if(!isEmpty(orgId)){ + and t.org_id =#orgId# + @} + @if(!isEmpty(orgIdPlural)){ + and find_in_set(t.org_id,#orgIdPlural#) + @} + @if(!isEmpty(userId)){ + and t.user_id =#userId# + @} + @if(!isEmpty(userIdPlural)){ + and find_in_set(t.user_id,#userIdPlural#) + @} + @if(!isEmpty(createTime)){ + and t.create_time =#createTime# + @} + @if(!isEmpty(teacherOpenCourseId)){ + and t.teacher_open_course_id =#teacherOpenCourseId# + @} + @if(!isEmpty(studentOrName)){ + and (s1.student_name like #'%'+studentOrName+'%'# or s1.student_sn like #'%'+studentOrName+'%'#) + @} + @if(!isEmpty(classId)){ + and s2.class_id =#classId# + @} \ No newline at end of file