|
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
@ -25,10 +26,8 @@ import com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum;
|
|
|
|
|
import com.ibeetl.jlw.web.query.GeneralQuestionLogQuery;
|
|
|
|
|
import com.ibeetl.jlw.web.query.GeneralQuestionSettingQuery;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.beetl.sql.core.SqlId;
|
|
|
|
|
import org.beetl.sql.core.engine.PageQuery;
|
|
|
|
@ -39,6 +38,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
|
@ -52,6 +53,7 @@ import static cn.hutool.core.date.DateUnit.SECOND;
|
|
|
|
|
import static cn.hutool.core.util.ArrayUtil.join;
|
|
|
|
|
import static cn.jlw.util.CacheUserUtil.getStudent;
|
|
|
|
|
import static com.ibeetl.admin.core.util.ExcelUtil.getCellFormatValue;
|
|
|
|
|
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.FINALLY_SUBMIT;
|
|
|
|
|
import static com.ibeetl.jlw.enums.QuestionLogAddTypeEnum.PRE_SUBMIT;
|
|
|
|
|
import static com.ibeetl.jlw.enums.ResourcesQuestionSnapshotFromTypeEnum.CHAPTER_EXERCISE;
|
|
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
|
@ -464,11 +466,15 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
|
|
|
|
|
List<GeneralQuestionLog> updateList = generalQuestionLogDao.getValuesByQueryNotWithPermission(generalQuestionLogQuery);
|
|
|
|
|
|
|
|
|
|
final Date now = new Date();
|
|
|
|
|
// 批量更新分数
|
|
|
|
|
// 批量更新分数。支持重复设置分数和评语
|
|
|
|
|
updateList.forEach(questionLog -> {
|
|
|
|
|
questionLog.setQuestionScore(score);
|
|
|
|
|
BigDecimal questionScore = questionLog.getQuestionScore();
|
|
|
|
|
questionLog.setStudentScore(score);
|
|
|
|
|
questionLog.setGeneralQuestionLogReply(reply);
|
|
|
|
|
// 这里不是记录用时,只是记录教师批阅的时间
|
|
|
|
|
questionLog.setGeneralQuestionLogUpdateTime(now);
|
|
|
|
|
// 是否错题库,也可以用作标记答案是对的错的
|
|
|
|
|
questionLog.setIsErrorFavorite(NumberUtil.equals(questionScore, score));
|
|
|
|
|
});
|
|
|
|
|
updateBatchTemplate(updateList);
|
|
|
|
|
|
|
|
|
@ -522,7 +528,10 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
|
|
|
|
|
GeneralQuestionLogQuery query = new GeneralQuestionLogQuery();
|
|
|
|
|
query.setGeneralQuestionLogUploadFile(absFilePath);
|
|
|
|
|
query.setGeneralQuestionSettingId(questionSettingId);
|
|
|
|
|
query.setGeneralQuestionLogUpdateTime(new Date());
|
|
|
|
|
query.setGeneralQuestionLogStatus(1);
|
|
|
|
|
// 附件作业,只有一题,所有默认是全部提交的方式
|
|
|
|
|
query.setQuestionLogAddType(FINALLY_SUBMIT);
|
|
|
|
|
query.setOrgId(student.getOrgId());
|
|
|
|
|
query.setUserId(student.getUserId());
|
|
|
|
|
query.setStudentId(student.getStudentId());
|
|
|
|
@ -834,4 +843,136 @@ public class GeneralQuestionLogService extends CoreBaseService<GeneralQuestionLo
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出
|
|
|
|
|
* @param request
|
|
|
|
|
* @param response
|
|
|
|
|
* @param generalQuestionLogQuery
|
|
|
|
|
* @param coreUser
|
|
|
|
|
*/
|
|
|
|
|
public void exportErrorFavorite(HttpServletRequest request, HttpServletResponse response, GeneralQuestionLogQuery generalQuestionLogQuery, CoreUser coreUser) {
|
|
|
|
|
if(null == coreUser){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
HSSFWorkbook workbook = null;
|
|
|
|
|
try {
|
|
|
|
|
//表头数据
|
|
|
|
|
String[] header = {
|
|
|
|
|
"通用题目配置", "题目快照", "学生提交的答案", "附件,学生端上传附件", "创建时间", "状态", "学生",
|
|
|
|
|
"学生得分", "题型", "分值", "题干", "选项A", "选项B", "选项C", "选项D", "选项E", "答案", "解析",
|
|
|
|
|
"是否收藏夹", "是否错题库",
|
|
|
|
|
};
|
|
|
|
|
String[] headerCode = {
|
|
|
|
|
"generalQuestionSettingId", "generalResourcesQuestionSnapshotId", "generalQuestionLogAnswer",
|
|
|
|
|
"generalQuestionLogUploadFile", "generalQuestionLogAddTime", "generalQuestionLogStatus",
|
|
|
|
|
"studentId", "studentScore", "questionType", "questionScore", "questionStem", "questionOptionA",
|
|
|
|
|
"questionOptionB", "questionOptionC", "questionOptionD", "questionOptionE", "questionAnswer",
|
|
|
|
|
"questionAnalysis", "isTuck", "isErrorFavorite",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//数据内容
|
|
|
|
|
List<Map<String, Object>> mapList = getExcelValues(generalQuestionLogQuery);
|
|
|
|
|
|
|
|
|
|
//内容宽度
|
|
|
|
|
Map<String, Object> 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<String, Object> 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
|
|
|
|
|
String fileName = ToolUtils.web2fileName(request,"generalQuestionLog(" + TimeTool.getNowTime("YMD") + ").xls");
|
|
|
|
|
|
|
|
|
|
response.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
|
|
|
|
|
|
|
//刷新缓冲
|
|
|
|
|
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) { }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|