|
@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.boot.tools.excel.ExcelReader;
|
|
|
import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
-import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
import com.qmth.distributed.print.business.bean.dto.FinalScoreDto;
|
|
|
import com.qmth.distributed.print.business.bean.result.FinalScoreResult;
|
|
|
import com.qmth.distributed.print.business.entity.TCFinalScore;
|
|
@@ -86,62 +85,67 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
|
|
|
StringJoiner successData = new StringJoiner("");
|
|
|
|
|
|
ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, file.getInputStream(), 1);
|
|
|
- List<DataMap> list = excelReader.getDataMapList();
|
|
|
- log.info("list:{}", JacksonUtil.parseJson(list));
|
|
|
+ List<String[]> arrayList = excelReader.getDataArrayList();
|
|
|
+ log.info("arrayList:{}", JacksonUtil.parseJson(arrayList));
|
|
|
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- List<TCFinalScore> tcFinalScoreList = new ArrayList<>(list.size());
|
|
|
- String[] columnNames = excelReader.getColumnNames();
|
|
|
- for (int i = 0; i < columnNames.length; i++) {
|
|
|
- if (i == 0 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "学号")) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("excel表头第一行为学号");
|
|
|
- } else if (i == 1 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "姓名")) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("excel表头第二行为姓名");
|
|
|
- } else if (i == 2 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "成绩")) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("excel表头第三行为成绩");
|
|
|
+ if (!CollectionUtils.isEmpty(arrayList)) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ List<TCFinalScore> tcFinalScoreList = new ArrayList<>(arrayList.size());
|
|
|
+ String[] columnNames = excelReader.getColumnNames();
|
|
|
+ for (int i = 0; i < columnNames.length; i++) {
|
|
|
+ if (i == 0 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "学号")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel表头第一行为学号");
|
|
|
+ } else if (i == 1 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "姓名")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel表头第二行为姓名");
|
|
|
+ } else if (i == 2 && Objects.nonNull(columnNames[i]) && !Objects.equals(columnNames[i].trim(), "成绩")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel表头第三行为成绩");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
- Map<String, String> objectMap = list.get(i);
|
|
|
- if (!CollectionUtils.isEmpty(objectMap)) {
|
|
|
- boolean error = false;
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
- TCFinalScore tcFinalScore = new TCFinalScore(examId, courseCode, markPaper.getCourseName(), paperNumber, SourceEnum.EXCEL_IMPORT, 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 + 1) + "行[").add(entry.getKey() + "]为空;").add("\r\n");
|
|
|
- error = true;
|
|
|
- } else {
|
|
|
- if (Objects.equals(entry.getKey().trim(), "学号")) {
|
|
|
- tcFinalScore.setStudentCode(entry.getValue());
|
|
|
- } else if (Objects.equals(entry.getKey().trim(), "姓名")) {
|
|
|
- tcFinalScore.setName(entry.getValue());
|
|
|
- } else if (Objects.equals(entry.getKey().trim(), "成绩")) {
|
|
|
- tcFinalScore.setScore(Double.valueOf(entry.getValue()));
|
|
|
+ for (int i = 0; i < arrayList.size(); i++) {
|
|
|
+ String[] strs = arrayList.get(i);
|
|
|
+ if (Objects.nonNull(strs) && strs.length > 0) {
|
|
|
+ if (strs.length != columnNames.length) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel列和数据不匹配");
|
|
|
+ }
|
|
|
+ boolean error = false;
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ TCFinalScore tcFinalScore = new TCFinalScore(examId, courseCode, markPaper.getCourseName(), paperNumber, SourceEnum.EXCEL_IMPORT, sysUser.getId());
|
|
|
+ for (int j = 0; j < strs.length; j++) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (Objects.isNull(strs[j]) || Objects.equals(strs[j].trim(), "")) {
|
|
|
+ errorData.add("excel第" + (i + 1) + "行[").add(columnNames[j] + "]为空;").add("\r\n");
|
|
|
+ error = true;
|
|
|
} else {
|
|
|
- jsonObject.put("name", entry.getKey());
|
|
|
- jsonObject.put("score", entry.getValue());
|
|
|
- jsonArray.add(jsonObject);
|
|
|
+ if (Objects.equals(columnNames[j].trim(), "学号")) {
|
|
|
+ tcFinalScore.setStudentCode(strs[j]);
|
|
|
+ } else if (Objects.equals(columnNames[j].trim(), "姓名")) {
|
|
|
+ tcFinalScore.setName(strs[j]);
|
|
|
+ } else if (Objects.equals(columnNames[j].trim(), "成绩")) {
|
|
|
+ tcFinalScore.setScore(Double.valueOf(strs[j]));
|
|
|
+ } else {
|
|
|
+ jsonObject.put("name", columnNames[j]);
|
|
|
+ jsonObject.put("score", strs[j]);
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (jsonArray.size() > 0) {
|
|
|
- tcFinalScore.setScoreDetail(jsonArray.toJSONString());
|
|
|
- }
|
|
|
- if (!error) {
|
|
|
- tcFinalScoreList.add(tcFinalScore);
|
|
|
+ if (jsonArray.size() > 0) {
|
|
|
+ tcFinalScore.setScoreDetail(jsonArray.toJSONString());
|
|
|
+ }
|
|
|
+ if (!error) {
|
|
|
+ tcFinalScoreList.add(tcFinalScore);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
|
|
|
- successData.add("共导入" + tcFinalScoreList.size() + "条数据");
|
|
|
- tcFinalScoreService.remove(new QueryWrapper<TCFinalScore>().lambda().eq(TCFinalScore::getExamId, examId)
|
|
|
- .eq(TCFinalScore::getCourseCode, courseCode)
|
|
|
- .eq(TCFinalScore::getCourseName, markPaper.getCourseName())
|
|
|
- .eq(TCFinalScore::getPaperNumber, paperNumber));
|
|
|
- tcFinalScoreService.saveBatch(tcFinalScoreList);
|
|
|
+ if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
|
|
|
+ successData.add("共导入" + tcFinalScoreList.size() + "条数据");
|
|
|
+ tcFinalScoreService.remove(new QueryWrapper<TCFinalScore>().lambda().eq(TCFinalScore::getExamId, examId)
|
|
|
+ .eq(TCFinalScore::getCourseCode, courseCode)
|
|
|
+ .eq(TCFinalScore::getCourseName, markPaper.getCourseName())
|
|
|
+ .eq(TCFinalScore::getPaperNumber, paperNumber));
|
|
|
+ tcFinalScoreService.saveBatch(tcFinalScoreList);
|
|
|
+ }
|
|
|
}
|
|
|
messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
|
|
|
messageMap.put(SystemConstant.EXCEL_ERROR, errorData.length() > 0 ? errorData.toString() : "无");
|