|
@@ -23,7 +23,11 @@ import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
|
|
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;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
|
+import com.qmth.teachcloud.mark.bean.archivescore.MarkStudentScoreVo;
|
|
|
|
+import com.qmth.teachcloud.mark.dto.mark.ScoreItem;
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
|
|
+import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
|
+import com.qmth.teachcloud.mark.service.MarkStudentService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
@@ -54,6 +58,12 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
|
|
@Resource
|
|
@Resource
|
|
TCFinalScoreService tcFinalScoreService;
|
|
TCFinalScoreService tcFinalScoreService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ MarkPaperService markPaperService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ MarkStudentService markStudentService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 导入期末成绩excel
|
|
* 导入期末成绩excel
|
|
*
|
|
*
|
|
@@ -69,10 +79,9 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
|
|
public Map<String, String> finalScoreExcelImport(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException {
|
|
public Map<String, String> finalScoreExcelImport(MultipartFile file, Long examId, String courseCode, String paperNumber) throws IOException {
|
|
log.debug("导入Excel开始...");
|
|
log.debug("导入Excel开始...");
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
- MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
|
|
|
|
-
|
|
|
|
Map<String, String> messageMap = new LinkedHashMap<>();
|
|
Map<String, String> messageMap = new LinkedHashMap<>();
|
|
try {
|
|
try {
|
|
|
|
+ MarkPaper markPaper = printCommonService.scoreImportExcelVaild(file, examId, paperNumber);
|
|
StringJoiner errorData = new StringJoiner("");
|
|
StringJoiner errorData = new StringJoiner("");
|
|
StringJoiner successData = new StringJoiner("");
|
|
StringJoiner successData = new StringJoiner("");
|
|
|
|
|
|
@@ -126,13 +135,10 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
|
|
}
|
|
}
|
|
if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
|
|
if (!CollectionUtils.isEmpty(tcFinalScoreList)) {
|
|
successData.add("共导入" + tcFinalScoreList.size() + "条数据");
|
|
successData.add("共导入" + tcFinalScoreList.size() + "条数据");
|
|
-
|
|
|
|
- QueryWrapper<TCFinalScore> tcScoreEndExamQueryWrapper = new QueryWrapper<>();
|
|
|
|
- tcScoreEndExamQueryWrapper.lambda().eq(TCFinalScore::getExamId, examId)
|
|
|
|
|
|
+ tcFinalScoreService.remove(new QueryWrapper<TCFinalScore>().lambda().eq(TCFinalScore::getExamId, examId)
|
|
.eq(TCFinalScore::getCourseCode, courseCode)
|
|
.eq(TCFinalScore::getCourseCode, courseCode)
|
|
.eq(TCFinalScore::getCourseName, markPaper.getCourseName())
|
|
.eq(TCFinalScore::getCourseName, markPaper.getCourseName())
|
|
- .eq(TCFinalScore::getPaperNumber, paperNumber);
|
|
|
|
- tcFinalScoreService.remove(tcScoreEndExamQueryWrapper);
|
|
|
|
|
|
+ .eq(TCFinalScore::getPaperNumber, paperNumber));
|
|
tcFinalScoreService.saveBatch(tcFinalScoreList);
|
|
tcFinalScoreService.saveBatch(tcFinalScoreList);
|
|
}
|
|
}
|
|
messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
|
|
messageMap.put(SystemConstant.SUCCESS, successData.length() > 0 ? successData.toString() : "无");
|
|
@@ -209,4 +215,66 @@ public class TCFinalScoreServiceImpl extends ServiceImpl<TCFinalScoreMapper, TCF
|
|
public List<FinalScoreResult> examStudentOverview(Long examId, String courseCode, String paperNumber) {
|
|
public List<FinalScoreResult> examStudentOverview(Long examId, String courseCode, String paperNumber) {
|
|
return this.baseMapper.examStudentOverview(examId, courseCode, paperNumber);
|
|
return this.baseMapper.examStudentOverview(examId, courseCode, paperNumber);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 同步期末成绩
|
|
|
|
+ *
|
|
|
|
+ * @param examId
|
|
|
|
+ * @param courseCode
|
|
|
|
+ * @param paperNumber
|
|
|
|
+ * @return
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public Map<String, String> finalScoreExcelSync(Long examId, String courseCode, String paperNumber) throws IOException {
|
|
|
|
+ Map<String, String> messageMap = new LinkedHashMap<>();
|
|
|
|
+ try {
|
|
|
|
+ MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
|
|
|
|
+ Objects.requireNonNull(markPaper, "未找到科目信息");
|
|
|
|
+
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+ StringJoiner errorData = new StringJoiner("");
|
|
|
|
+ StringJoiner successData = new StringJoiner("");
|
|
|
|
+ List<MarkStudentScoreVo> markStudentScoreVoList = markStudentService.listMarkStudentScoreList(examId, paperNumber);
|
|
|
|
+ if (!CollectionUtils.isEmpty(markStudentScoreVoList)) {
|
|
|
|
+ List<TCFinalScore> tcFinalScoreList = new ArrayList<>(markStudentScoreVoList.size());
|
|
|
|
+ for (MarkStudentScoreVo markStudentScoreVo : markStudentScoreVoList) {
|
|
|
|
+ if (!CollectionUtils.isEmpty(markStudentScoreVo.getTotalScoreList())) {
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ for (ScoreItem scoreItem : markStudentScoreVo.getTotalScoreList()) {
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ String name = scoreItem.getMainNumber() + "-" + scoreItem.getSubNumber();
|
|
|
|
+ jsonObject.put("name", name);
|
|
|
|
+ jsonObject.put("score", scoreItem.getScore());
|
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
|
+ }
|
|
|
|
+ tcFinalScoreList.add(new TCFinalScore(markStudentScoreVo, jsonArray.toJSONString(), SourceEnum.SYNC, sysUser.getId()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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() : "无");
|
|
|
|
+ } 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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return messageMap;
|
|
|
|
+ }
|
|
}
|
|
}
|