|
@@ -0,0 +1,128 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmPkgQuizRelation;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmQuiz;
|
|
|
+import com.qunzhixinxi.hnqz.admin.api.entity.WmQuizItem;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmPkgQuizRelationMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmPkgQuizRelationService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmQuizService;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 积分包试卷服务实现
|
|
|
+ *
|
|
|
+ * @author jimmy
|
|
|
+ * @version 1.0.0
|
|
|
+ * @date 2023-10-19 13:22
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class WmPkgQuizRelationServiceImpl extends ServiceImpl<WmPkgQuizRelationMapper, WmPkgQuizRelation> implements WmPkgQuizRelationService {
|
|
|
+
|
|
|
+ private final WmQuizService quizService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建积分包关联的试卷
|
|
|
+ *
|
|
|
+ * @param quizIds 试卷ID
|
|
|
+ * @param pkgId 积分包ID
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void createPkgQuizzes(List<Integer> quizIds, Integer pkgId) {
|
|
|
+
|
|
|
+ List<WmPkgQuizRelation> relations = quizIds.stream().distinct().map(quizService::getDetails)
|
|
|
+ .filter(details -> details.get("quiz") != null && CollUtil.isNotEmpty((List<WmQuizItem>) details.get("items"))).map(detailMap -> {
|
|
|
+ WmQuiz quiz = (WmQuiz) detailMap.get("quiz");
|
|
|
+ List<WmQuizItem> quizItems = (List<WmQuizItem>) detailMap.get("items");
|
|
|
+ WmPkgQuizRelation relation = new WmPkgQuizRelation();
|
|
|
+ relation.setQuizId(quiz.getQuizId());
|
|
|
+ relation.setTitle(quiz.getTitle());
|
|
|
+ WmQuiz.Expand expand = quiz.getExpand();
|
|
|
+ relation.setItemQty(expand.getItemQty());
|
|
|
+ relation.setTotalMark(expand.getTotalMark());
|
|
|
+ relation.setPassingMark(expand.getPassingMark());
|
|
|
+ relation.setAvailable(Boolean.TRUE);
|
|
|
+ relation.setPkgId(pkgId);
|
|
|
+ relation.setCreateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ WmPkgQuizRelation.Item[] array = quizItems.stream().map(qi -> {
|
|
|
+ WmPkgQuizRelation.Item item = new WmPkgQuizRelation.Item();
|
|
|
+ item.setLabel(qi.getLabel());
|
|
|
+ item.setOptions(qi.getOptions());
|
|
|
+ item.setAnswer(qi.getAnswer());
|
|
|
+ item.setMark(qi.getMark());
|
|
|
+ return item;
|
|
|
+ }).toArray(WmPkgQuizRelation.Item[]::new);
|
|
|
+
|
|
|
+ relation.setItems(array);
|
|
|
+
|
|
|
+ return relation;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveBatch(relations);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制关联关系
|
|
|
+ *
|
|
|
+ * @param pkgId 积分包ID
|
|
|
+ * @param quizRelationIds 关联关系列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void copyQuizRelations(List<Integer> quizRelationIds, Integer pkgId) {
|
|
|
+ List<WmPkgQuizRelation> quizRelations = this.listByIds(quizRelationIds);
|
|
|
+
|
|
|
+ List<WmPkgQuizRelation> relations = quizRelations.stream().map(qr -> {
|
|
|
+
|
|
|
+ WmPkgQuizRelation relation = new WmPkgQuizRelation();
|
|
|
+ relation.setQuizId(qr.getQuizId());
|
|
|
+ relation.setTitle(qr.getTitle());
|
|
|
+ relation.setItemQty(qr.getItemQty());
|
|
|
+ relation.setTotalMark(qr.getTotalMark());
|
|
|
+ relation.setPassingMark(qr.getPassingMark());
|
|
|
+ relation.setItems(qr.getItems());
|
|
|
+ relation.setPkgId(pkgId);
|
|
|
+ relation.setAvailable(qr.getAvailable());
|
|
|
+ relation.setCreateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ return relation;
|
|
|
+
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.saveBatch(relations);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取积分包的关联试卷
|
|
|
+ *
|
|
|
+ * @param pkgIds 积分包id
|
|
|
+ * @return 关联试卷集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<WmPkgQuizRelation> listQuizRelationsByPkgIds(List<Integer> pkgIds) {
|
|
|
+
|
|
|
+ List<WmPkgQuizRelation> relations = null;
|
|
|
+ if (CollUtil.isNotEmpty(pkgIds)) {
|
|
|
+ relations = this.list(Wrappers.<WmPkgQuizRelation>lambdaQuery().in(WmPkgQuizRelation::getPkgId, pkgIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ return CollUtil.isNotEmpty(relations) ? relations : Collections.emptyList();
|
|
|
+ }
|
|
|
+}
|