|
@@ -1,15 +1,26 @@
|
|
|
package com.qmth.distributed.print.api;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
import com.qmth.distributed.print.business.bean.excel.ExcelField;
|
|
|
import com.qmth.distributed.print.business.bean.result.EditResult;
|
|
|
+import com.qmth.distributed.print.business.entity.TCScoreNormal;
|
|
|
import com.qmth.distributed.print.business.service.TCScoreNormalService;
|
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
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.ServletUtil;
|
|
|
+import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
+import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
import io.swagger.annotations.*;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -20,8 +31,7 @@ import javax.annotation.Resource;
|
|
|
import javax.validation.constraints.Max;
|
|
|
import javax.validation.constraints.Min;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -35,10 +45,14 @@ import java.util.List;
|
|
|
@RestController
|
|
|
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COURSE_DEGREE)
|
|
|
public class TCScoreNormalController {
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TCScoreNormalController.class);
|
|
|
|
|
|
@Resource
|
|
|
TCScoreNormalService tcScoreNormalService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ MarkPaperService markPaperService;
|
|
|
+
|
|
|
@ApiOperation(value = "成绩管理列表")
|
|
|
@RequestMapping(value = "/score/list", method = RequestMethod.POST)
|
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.SEARCH)
|
|
@@ -75,8 +89,46 @@ public class TCScoreNormalController {
|
|
|
@RequestMapping(value = "/score/import", method = RequestMethod.POST)
|
|
|
@OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.IMPORT)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "导入成功", response = EditResult.class)})
|
|
|
- public Object scoreImport(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) throws IOException {
|
|
|
- return ResultUtil.ok(true);
|
|
|
+ @Transactional
|
|
|
+ public Object scoreImport(@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,
|
|
|
+ @ApiParam(value = "试卷类型", required = true) @RequestParam String paperType) throws IOException {
|
|
|
+ log.debug("导入Excel开始...");
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ String reqFileMd5 = ServletUtil.getRequestMd5();
|
|
|
+ String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
+ if (!Objects.equals(fileMd5, reqFileMd5)) {
|
|
|
+ throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
+ }
|
|
|
+ MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumberAndPaperType(examId, paperNumber, paperType);
|
|
|
+ Objects.requireNonNull(markPaper, "未找到科目信息");
|
|
|
+
|
|
|
+ List<Map<String, String>> list = null;
|
|
|
+ try {
|
|
|
+ StringJoiner errorData = new StringJoiner("");
|
|
|
+ list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0).doReadSync();
|
|
|
+ List<TCScoreNormal> tcScoreNormalList = new ArrayList<>(list.size());
|
|
|
+ log.info("list:{}", JacksonUtil.parseJson(list));
|
|
|
+ Map<String, String> headMap = list.get(0);
|
|
|
+ log.info("headMap:{}", JacksonUtil.parseJson(headMap));
|
|
|
+ for (int i = 1; i < list.size(); i++) {
|
|
|
+ Map<String, String> objectMap = list.get(i);
|
|
|
+ for (Map.Entry<String, String> entry : objectMap.entrySet()) {
|
|
|
+ if (Objects.isNull(entry) || Objects.equals(entry, "")) {
|
|
|
+ errorData.add("第" + i + "行").add(headMap.get(entry.getKey()) + "为空\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("objectMap:{}", JacksonUtil.parseJson(objectMap));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ log.debug("导入Excel结束...");
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ log.info("============耗时{}秒============:", (end - start) / 1000);
|
|
|
+ return ResultUtil.ok(list);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "平时成绩列表")
|