|
|
@@ -0,0 +1,114 @@
|
|
|
+package com.zhongzheng.modules.bank.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.modules.bank.bo.QuestionBankAddBo;
|
|
|
+import com.zhongzheng.modules.bank.bo.QuestionBankEditBo;
|
|
|
+import com.zhongzheng.modules.bank.bo.QuestionBankQueryBo;
|
|
|
+import com.zhongzheng.modules.bank.domain.QuestionBank;
|
|
|
+import com.zhongzheng.modules.bank.mapper.QuestionBankMapper;
|
|
|
+import com.zhongzheng.modules.bank.service.IQuestionBankService;
|
|
|
+import com.zhongzheng.modules.bank.vo.QuestionBankVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 题库Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2021-05-20
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QuestionBankServiceImpl extends ServiceImpl<QuestionBankMapper, QuestionBank> implements IQuestionBankService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public QuestionBankVo queryById(Long bankId){
|
|
|
+ QuestionBank db = this.baseMapper.selectById(bankId);
|
|
|
+ return BeanUtil.toBean(db, QuestionBankVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<QuestionBankVo> queryList(QuestionBankQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<QuestionBank> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getCategoryId() != null, QuestionBank::getCategoryId, bo.getCategoryId());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getBankName()), QuestionBank::getBankName, bo.getBankName());
|
|
|
+ lqw.eq(bo.getPrice() != null, QuestionBank::getPrice, bo.getPrice());
|
|
|
+ lqw.eq(bo.getStartTime() != null, QuestionBank::getStartTime, bo.getStartTime());
|
|
|
+ lqw.eq(bo.getEndTime() != null, QuestionBank::getEndTime, bo.getEndTime());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCoverUrl()), QuestionBank::getCoverUrl, bo.getCoverUrl());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getIntroduction()), QuestionBank::getIntroduction, bo.getIntroduction());
|
|
|
+ lqw.eq(bo.getPassingScore() != null, QuestionBank::getPassingScore, bo.getPassingScore());
|
|
|
+ lqw.eq(bo.getExamTime() != null, QuestionBank::getExamTime, bo.getExamTime());
|
|
|
+ lqw.eq(bo.getSingleChoiceNum() != null, QuestionBank::getSingleChoiceNum, bo.getSingleChoiceNum());
|
|
|
+ lqw.eq(bo.getSingleChoiceScore() != null, QuestionBank::getSingleChoiceScore, bo.getSingleChoiceScore());
|
|
|
+ lqw.eq(bo.getMultipleChoiceNum() != null, QuestionBank::getMultipleChoiceNum, bo.getMultipleChoiceNum());
|
|
|
+ lqw.eq(bo.getMultipleChoiceScore() != null, QuestionBank::getMultipleChoiceScore, bo.getMultipleChoiceScore());
|
|
|
+ lqw.eq(bo.getJudgmentNum() != null, QuestionBank::getJudgmentNum, bo.getJudgmentNum());
|
|
|
+ lqw.eq(bo.getJudgmentScore() != null, QuestionBank::getJudgmentScore, bo.getJudgmentScore());
|
|
|
+ lqw.eq(bo.getCaseNum() != null, QuestionBank::getCaseNum, bo.getCaseNum());
|
|
|
+ lqw.eq(bo.getCaseScore() != null, QuestionBank::getCaseScore, bo.getCaseScore());
|
|
|
+ lqw.eq(bo.getTotalScore() != null, QuestionBank::getTotalScore, bo.getTotalScore());
|
|
|
+ lqw.eq(bo.getStatus() != null, QuestionBank::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getTypeId() != null, QuestionBank::getTypeId, bo.getTypeId());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getTeacherIds()), QuestionBank::getTeacherIds, bo.getTeacherIds());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<QuestionBankVo> entity2Vo(Collection<QuestionBank> collection) {
|
|
|
+ List<QuestionBankVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, QuestionBankVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<QuestionBank> page = (Page<QuestionBank>)collection;
|
|
|
+ Page<QuestionBankVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(QuestionBankAddBo bo) {
|
|
|
+ QuestionBank add = BeanUtil.toBean(bo, QuestionBank.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(QuestionBankEditBo bo) {
|
|
|
+ QuestionBank update = BeanUtil.toBean(bo, QuestionBank.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(QuestionBank entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|