|
@@ -2,6 +2,7 @@ package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.qunzhixinxi.hnqz.admin.api.dto.WmQuizDTO;
|
|
@@ -11,6 +12,7 @@ import com.qunzhixinxi.hnqz.admin.mapper.WmQuizMapper;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.WmQuizItemService;
|
|
|
import com.qunzhixinxi.hnqz.admin.service.WmQuizService;
|
|
|
import com.qunzhixinxi.hnqz.common.core.constant.enums.UpmsState;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.exception.BizException;
|
|
|
import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -124,4 +126,54 @@ public class WmQuizServiceImpl extends ServiceImpl<WmQuizMapper, WmQuiz> impleme
|
|
|
|
|
|
return this.save(quiz) ? sn : "";
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新试卷
|
|
|
+ *
|
|
|
+ * @param resource 试卷信息
|
|
|
+ * @param user 操作人
|
|
|
+ * @return 更新结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateQuiz(WmQuizDTO.OnQuizUpdate resource, HnqzUser user) {
|
|
|
+
|
|
|
+ return this.update(Wrappers.<WmQuiz>lambdaUpdate()
|
|
|
+ .set(StrUtil.isNotBlank(resource.getTitle()), WmQuiz::getTitle, resource.getTitle())
|
|
|
+ .set(StrUtil.isNotBlank(resource.getIntroduction()), WmQuiz::getIntroduction, resource.getIntroduction())
|
|
|
+ .set(resource.getExpand() != null, WmQuiz::getExpand, resource.getExpand())
|
|
|
+ .set(WmQuiz::getUpdateBy, user.getUsername())
|
|
|
+ .set(WmQuiz::getUpdateTime, LocalDateTime.now())
|
|
|
+ .eq(WmQuiz::getSerialNumber, resource.getSn())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验试卷信息
|
|
|
+ *
|
|
|
+ * @param serialNum 序列号
|
|
|
+ * @param expand 试卷统计信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void checkQuizExpand(WmQuiz.Expand expand, String serialNum) {
|
|
|
+ if (expand.getPassingMark() > expand.getTotalMark()) {
|
|
|
+ log.error("通过分数不能大于总分");
|
|
|
+ throw new BizException("通过分数不能大于总分");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WmQuizItem> items = quizItemService.listItems(serialNum);
|
|
|
+
|
|
|
+ if (expand.getItemQty() != items.size()) {
|
|
|
+ log.error("试卷项和参数值不符");
|
|
|
+ throw new BizException("试卷项和参数值不符");
|
|
|
+ }
|
|
|
+
|
|
|
+ int sum = items.stream().mapToInt(WmQuizItem::getMark).sum();
|
|
|
+
|
|
|
+ if (expand.getTotalMark() != sum) {
|
|
|
+ log.error("总分和参数值不符");
|
|
|
+ throw new BizException("总分和参数值不符");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|