|
@@ -1,15 +1,21 @@
|
|
package com.qmth.distributed.print.api;
|
|
package com.qmth.distributed.print.api;
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
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.entity.TCScoreNormal;
|
|
import com.qmth.distributed.print.business.entity.TCScoreNormal;
|
|
import com.qmth.distributed.print.business.service.TCScoreNormalService;
|
|
import com.qmth.distributed.print.business.service.TCScoreNormalService;
|
|
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.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.JacksonUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
@@ -20,7 +26,9 @@ import io.swagger.annotations.*;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
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.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;
|
|
@@ -105,30 +113,90 @@ public class TCScoreNormalController {
|
|
MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumberAndPaperType(examId, paperNumber, paperType);
|
|
MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumberAndPaperType(examId, paperNumber, paperType);
|
|
Objects.requireNonNull(markPaper, "未找到科目信息");
|
|
Objects.requireNonNull(markPaper, "未找到科目信息");
|
|
|
|
|
|
- List<Map<String, String>> list = null;
|
|
|
|
|
|
+ Map<String, String> messageMap = new LinkedHashMap<>();
|
|
try {
|
|
try {
|
|
StringJoiner errorData = new StringJoiner("");
|
|
StringJoiner errorData = new StringJoiner("");
|
|
- list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0).doReadSync();
|
|
|
|
|
|
+ StringJoiner successData = new StringJoiner("");
|
|
|
|
+ List<Map<String, String>> list = EasyExcel.read(file.getInputStream()).headRowNumber(1).sheet(0).doReadSync();
|
|
|
|
+
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
List<TCScoreNormal> tcScoreNormalList = new ArrayList<>(list.size());
|
|
List<TCScoreNormal> tcScoreNormalList = new ArrayList<>(list.size());
|
|
log.info("list:{}", JacksonUtil.parseJson(list));
|
|
log.info("list:{}", JacksonUtil.parseJson(list));
|
|
Map<String, String> headMap = list.get(0);
|
|
Map<String, String> headMap = list.get(0);
|
|
log.info("headMap:{}", JacksonUtil.parseJson(headMap));
|
|
log.info("headMap:{}", JacksonUtil.parseJson(headMap));
|
|
|
|
+ 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++) {
|
|
for (int i = 1; i < list.size(); i++) {
|
|
Map<String, String> objectMap = list.get(i);
|
|
Map<String, String> objectMap = list.get(i);
|
|
|
|
+ boolean error = false;
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ TCScoreNormal tcScoreNormal = new TCScoreNormal(examId, courseCode, markPaper.getCourseName(), paperNumber, paperType, sysUser.getId());
|
|
for (Map.Entry<String, String> entry : objectMap.entrySet()) {
|
|
for (Map.Entry<String, String> entry : objectMap.entrySet()) {
|
|
- if (Objects.isNull(entry) || Objects.equals(entry, "")) {
|
|
|
|
- errorData.add("第" + i + "行").add(headMap.get(entry.getKey()) + "为空\n");
|
|
|
|
|
|
+ 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(), "学号")) {
|
|
|
|
+ tcScoreNormal.setExamNumber(entry.getValue());
|
|
|
|
+ } else if (Objects.equals(head.trim(), "姓名")) {
|
|
|
|
+ tcScoreNormal.setName(entry.getValue());
|
|
|
|
+ } else {
|
|
|
|
+ jsonObject.put("name", headMap.get(entry.getKey()));
|
|
|
|
+ jsonObject.put("score", entry.getValue());
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
|
+ tcScoreNormal.setScoreNormal(jsonArray.toJSONString());
|
|
|
|
+ }
|
|
|
|
+ if (!error) {
|
|
|
|
+ tcScoreNormalList.add(tcScoreNormal);
|
|
|
|
+ }
|
|
log.info("objectMap:{}", JacksonUtil.parseJson(objectMap));
|
|
log.info("objectMap:{}", JacksonUtil.parseJson(objectMap));
|
|
|
|
+ log.info("jsonArray:{}", JacksonUtil.parseJson(jsonArray));
|
|
|
|
+ }
|
|
|
|
+ if (!CollectionUtils.isEmpty(tcScoreNormalList)) {
|
|
|
|
+ successData.add("共导入" + tcScoreNormalList.size() + "条数据");
|
|
|
|
+
|
|
|
|
+ QueryWrapper<TCScoreNormal> tcScoreNormalQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ tcScoreNormalQueryWrapper.lambda().eq(TCScoreNormal::getExamId, examId)
|
|
|
|
+ .eq(TCScoreNormal::getCourseCode, courseCode)
|
|
|
|
+ .eq(TCScoreNormal::getCourseName, markPaper.getCourseName())
|
|
|
|
+ .eq(TCScoreNormal::getPaperNumber, paperNumber)
|
|
|
|
+ .eq(TCScoreNormal::getPaperType, paperType);
|
|
|
|
+ tcScoreNormalService.remove(tcScoreNormalQueryWrapper);
|
|
|
|
+ tcScoreNormalService.saveBatch(tcScoreNormalList);
|
|
}
|
|
}
|
|
|
|
+ messageMap.put("正确信息", successData.length() > 0 ? successData.toString() : "无");
|
|
|
|
+ messageMap.put("错误信息", errorData.length() > 0 ? errorData.toString() : "无");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ 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结束...");
|
|
log.debug("导入Excel结束...");
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
log.info("============耗时{}秒============:", (end - start) / 1000);
|
|
log.info("============耗时{}秒============:", (end - start) / 1000);
|
|
- return ResultUtil.ok(list);
|
|
|
|
|
|
+ return ResultUtil.ok(messageMap);
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "平时成绩列表")
|
|
@ApiOperation(value = "平时成绩列表")
|