|
@@ -1,33 +1,19 @@
|
|
package com.qmth.distributed.print.api;
|
|
package com.qmth.distributed.print.api;
|
|
|
|
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
-import com.qmth.boot.api.exception.ApiException;
|
|
|
|
import com.qmth.distributed.print.business.bean.excel.ExcelField;
|
|
import com.qmth.distributed.print.business.bean.excel.ExcelField;
|
|
import com.qmth.distributed.print.business.bean.result.EditResult;
|
|
import com.qmth.distributed.print.business.bean.result.EditResult;
|
|
import com.qmth.distributed.print.business.bean.result.ScoreResult;
|
|
import com.qmth.distributed.print.business.bean.result.ScoreResult;
|
|
-import com.qmth.distributed.print.business.entity.TCUsualScore;
|
|
|
|
|
|
+import com.qmth.distributed.print.business.service.PrintCommonService;
|
|
import com.qmth.distributed.print.business.service.TCUsualScoreService;
|
|
import com.qmth.distributed.print.business.service.TCUsualScoreService;
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
-import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
|
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
|
-import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
|
|
|
|
import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
|
|
import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
|
|
-import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
-import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
|
-import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
-import org.springframework.dao.DuplicateKeyException;
|
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -38,7 +24,8 @@ import javax.annotation.Resource;
|
|
import javax.validation.constraints.Max;
|
|
import javax.validation.constraints.Max;
|
|
import javax.validation.constraints.Min;
|
|
import javax.validation.constraints.Min;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -57,6 +44,9 @@ public class TCUsualScoreController {
|
|
@Resource
|
|
@Resource
|
|
TCUsualScoreService tcUsualScoreService;
|
|
TCUsualScoreService tcUsualScoreService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ PrintCommonService printCommonService;
|
|
|
|
+
|
|
@ApiOperation(value = "成绩管理列表")
|
|
@ApiOperation(value = "成绩管理列表")
|
|
@RequestMapping(value = "/score/list", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/score/list", method = RequestMethod.POST)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
|
|
@@ -65,7 +55,7 @@ public class TCUsualScoreController {
|
|
@ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
|
|
@ApiParam(value = "课程编码") @RequestParam(required = false) String courseCode,
|
|
@ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
|
|
@ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
|
|
@ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
|
|
@ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
|
|
- return ResultUtil.ok(tcUsualScoreService.scoreList(new Page<>(pageNumber, pageSize), examId, courseCode));
|
|
|
|
|
|
+ return ResultUtil.ok(printCommonService.scoreList(new Page<>(pageNumber, pageSize), examId, courseCode));
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "导入平时成绩-模板下载")
|
|
@ApiOperation(value = "导入平时成绩-模板下载")
|
|
@@ -73,15 +63,16 @@ public class TCUsualScoreController {
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EXPORT)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.EXPORT)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "下载成功", response = Object.class)})
|
|
public void usualScoreTemplateDownload(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
public void usualScoreTemplateDownload(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
- @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
- @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
|
|
|
|
|
|
+ @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
+ @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
|
|
|
|
+ //TODO 待曹子轩补充接口
|
|
List<ExcelField> excelFieldList = new ArrayList<>();
|
|
List<ExcelField> excelFieldList = new ArrayList<>();
|
|
excelFieldList.add(new ExcelField("studentCode", "学号", true));
|
|
excelFieldList.add(new ExcelField("studentCode", "学号", true));
|
|
excelFieldList.add(new ExcelField("name", "姓名", true));
|
|
excelFieldList.add(new ExcelField("name", "姓名", true));
|
|
excelFieldList.add(new ExcelField("score1", "作业1", true));
|
|
excelFieldList.add(new ExcelField("score1", "作业1", true));
|
|
excelFieldList.add(new ExcelField("score2", "作业2", true));
|
|
excelFieldList.add(new ExcelField("score2", "作业2", true));
|
|
excelFieldList.add(new ExcelField("score3", "作业3", false));
|
|
excelFieldList.add(new ExcelField("score3", "作业3", false));
|
|
- tcUsualScoreService.downLoadExaminationTemplate("1、所有字段均为必填字段;\n" +
|
|
|
|
|
|
+ printCommonService.scoreDownLoadExaminationTemplate("1、所有字段均为必填字段;\n" +
|
|
"2、平时成绩各项数据均需要填写;\n" +
|
|
"2、平时成绩各项数据均需要填写;\n" +
|
|
"3、请不要删除此行,也不要删除模板中的任何列。\n" +
|
|
"3、请不要删除此行,也不要删除模板中的任何列。\n" +
|
|
"4、使用前请先删除样例数据。", "sheet1", "平时成绩导入模版", excelFieldList);
|
|
"4、使用前请先删除样例数据。", "sheet1", "平时成绩导入模版", excelFieldList);
|
|
@@ -91,95 +82,11 @@ public class TCUsualScoreController {
|
|
@RequestMapping(value = "/usual_score/import", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/usual_score/import", method = RequestMethod.POST)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
|
|
- @Transactional
|
|
|
|
public Object usualScoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
|
|
public Object usualScoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
|
|
- @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
|
|
- @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
- @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
|
|
|
|
- log.debug("导入Excel开始...");
|
|
|
|
- long start = System.currentTimeMillis();
|
|
|
|
- MarkPaper markPaper = tcUsualScoreService.importExcelVaild(file, examId, paperNumber);
|
|
|
|
-
|
|
|
|
- Map<String, String> messageMap = new LinkedHashMap<>();
|
|
|
|
- try {
|
|
|
|
- StringJoiner errorData = new StringJoiner("");
|
|
|
|
- StringJoiner successData = new StringJoiner("");
|
|
|
|
- List<Map<String, String>> list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0).doReadSync();
|
|
|
|
- log.info("list:{}", JacksonUtil.parseJson(list));
|
|
|
|
-
|
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
- List<TCUsualScore> tcUsualScoreList = new ArrayList<>(list.size());
|
|
|
|
- Map<String, String> headMap = list.get(0);
|
|
|
|
- for (Map.Entry<String, String> entry : headMap.entrySet()) {
|
|
|
|
- if (Objects.equals(entry.getKey(), 0) && Objects.nonNull(entry.getValue()) &&
|
|
|
|
- !Objects.equals(entry.getValue().trim(), "学号")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("excel表头第一行为学号");
|
|
|
|
- } else if (Objects.equals(entry.getKey(), 1) && Objects.nonNull(entry.getValue()) &&
|
|
|
|
- !Objects.equals(entry.getValue().trim(), "姓名")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("excel表头第二行为姓名");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (int i = 1; i < list.size(); i++) {
|
|
|
|
- Map<String, String> objectMap = list.get(i);
|
|
|
|
- boolean error = false;
|
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
|
- TCUsualScore tcUsualScore = new TCUsualScore(examId, courseCode, markPaper.getCourseName(), paperNumber, sysUser.getId());
|
|
|
|
- for (Map.Entry<String, String> entry : objectMap.entrySet()) {
|
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
|
- if (Objects.isNull(entry.getValue()) || Objects.equals(entry.getValue().trim(), "")) {
|
|
|
|
- errorData.add("excel第" + i + "行[").add(headMap.get(entry.getKey()) + "]为空;").add("\r\n");
|
|
|
|
- error = true;
|
|
|
|
- } else {
|
|
|
|
- String head = headMap.get(entry.getKey());
|
|
|
|
- Objects.requireNonNull(head, "表头信息异常");
|
|
|
|
- if (Objects.equals(head.trim(), "学号")) {
|
|
|
|
- tcUsualScore.setStudentCode(entry.getValue());
|
|
|
|
- } else if (Objects.equals(head.trim(), "姓名")) {
|
|
|
|
- tcUsualScore.setName(entry.getValue());
|
|
|
|
- } else {
|
|
|
|
- jsonObject.put("name", headMap.get(entry.getKey()));
|
|
|
|
- jsonObject.put("score", entry.getValue());
|
|
|
|
- jsonArray.add(jsonObject);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (jsonArray.size() > 0) {
|
|
|
|
- tcUsualScore.setScore(jsonArray.toJSONString());
|
|
|
|
- }
|
|
|
|
- if (!error) {
|
|
|
|
- tcUsualScoreList.add(tcUsualScore);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (!CollectionUtils.isEmpty(tcUsualScoreList)) {
|
|
|
|
- successData.add("共导入" + tcUsualScoreList.size() + "条数据");
|
|
|
|
-
|
|
|
|
- QueryWrapper<TCUsualScore> tcScoreNormalQueryWrapper = new QueryWrapper<>();
|
|
|
|
- tcScoreNormalQueryWrapper.lambda().eq(TCUsualScore::getExamId, examId)
|
|
|
|
- .eq(TCUsualScore::getCourseCode, courseCode)
|
|
|
|
- .eq(TCUsualScore::getCourseName, markPaper.getCourseName())
|
|
|
|
- .eq(TCUsualScore::getPaperNumber, paperNumber);
|
|
|
|
- tcUsualScoreService.remove(tcScoreNormalQueryWrapper);
|
|
|
|
- tcUsualScoreService.saveBatch(tcUsualScoreList);
|
|
|
|
- }
|
|
|
|
- messageMap.put("正确信息", successData.length() > 0 ? successData.toString() : "无");
|
|
|
|
- messageMap.put("错误信息", errorData.length() > 0 ? errorData.toString() : "无");
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- if (e instanceof DuplicateKeyException) {
|
|
|
|
- String errorColumn = e.getCause().toString();
|
|
|
|
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
|
- throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
|
- } else if (e instanceof ApiException) {
|
|
|
|
- ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
|
|
- } else {
|
|
|
|
- ResultUtil.error(e.getMessage());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- log.debug("导入Excel结束...");
|
|
|
|
- long end = System.currentTimeMillis();
|
|
|
|
- log.info("============耗时{}秒============:", (end - start) / 1000);
|
|
|
|
- return ResultUtil.ok(messageMap);
|
|
|
|
|
|
+ @ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
|
|
+ @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
+ @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) throws IOException {
|
|
|
|
+ return ResultUtil.ok(tcUsualScoreService.usualScoreExcelImport(file, examId, courseCode, paperNumber));
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "平时成绩列表")
|
|
@ApiOperation(value = "平时成绩列表")
|
|
@@ -187,10 +94,10 @@ public class TCUsualScoreController {
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = EditResult.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "分页查询", response = EditResult.class)})
|
|
public Object usualScoreList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
public Object usualScoreList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
|
|
- @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
- @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
|
|
|
|
- @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
|
|
|
|
- @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) throws IOException {
|
|
|
|
|
|
+ @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode,
|
|
|
|
+ @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
|
|
|
|
+ @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
|
|
|
|
+ @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) throws IOException {
|
|
return ResultUtil.ok(true);
|
|
return ResultUtil.ok(true);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -207,7 +114,7 @@ public class TCUsualScoreController {
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "保存", response = EditResult.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "保存", response = EditResult.class)})
|
|
public Object usualScoreSave(@ApiParam(value = "主键", required = true) @RequestParam Long id,
|
|
public Object usualScoreSave(@ApiParam(value = "主键", required = true) @RequestParam Long id,
|
|
- @ApiParam(value = "平时成绩json", required = true) @RequestParam String socreNormal) throws IOException {
|
|
|
|
|
|
+ @ApiParam(value = "平时成绩json", required = true) @RequestParam String socreNormal) throws IOException {
|
|
return ResultUtil.ok(true);
|
|
return ResultUtil.ok(true);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -216,7 +123,7 @@ public class TCUsualScoreController {
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.UPDATE)
|
|
@ApiResponses({@ApiResponse(code = 200, message = "编辑", response = EditResult.class)})
|
|
@ApiResponses({@ApiResponse(code = 200, message = "编辑", response = EditResult.class)})
|
|
public Object usualScoreEnable(@ApiParam(value = "主键", required = true) @RequestParam Long id,
|
|
public Object usualScoreEnable(@ApiParam(value = "主键", required = true) @RequestParam Long id,
|
|
- @ApiParam(value = "启用/禁用", required = true) @RequestParam Boolean enable) throws IOException {
|
|
|
|
|
|
+ @ApiParam(value = "启用/禁用", required = true) @RequestParam Boolean enable) throws IOException {
|
|
return ResultUtil.ok(true);
|
|
return ResultUtil.ok(true);
|
|
}
|
|
}
|
|
}
|
|
}
|