|
@@ -0,0 +1,164 @@
|
|
|
+package com.zhongzheng.modules.exam.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.exam.bo.ExamNumberGoodsAddBo;
|
|
|
+import com.zhongzheng.modules.exam.domain.ExamNumberGoods;
|
|
|
+import com.zhongzheng.modules.exam.service.IExamNumberGoodsService;
|
|
|
+import com.zhongzheng.modules.exam.vo.ExamNumberGoodsVo;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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 com.zhongzheng.modules.exam.bo.ExamNumberAddBo;
|
|
|
+import com.zhongzheng.modules.exam.bo.ExamNumberQueryBo;
|
|
|
+import com.zhongzheng.modules.exam.bo.ExamNumberEditBo;
|
|
|
+import com.zhongzheng.modules.exam.domain.ExamNumber;
|
|
|
+import com.zhongzheng.modules.exam.mapper.ExamNumberMapper;
|
|
|
+import com.zhongzheng.modules.exam.vo.ExamNumberVo;
|
|
|
+import com.zhongzheng.modules.exam.service.IExamNumberService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考试次数配置Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2021-12-06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExamNumberServiceImpl extends ServiceImpl<ExamNumberMapper, ExamNumber> implements IExamNumberService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IExamNumberGoodsService examNumberGoodsService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ExamNumberVo queryById(Long examNumberId){
|
|
|
+ ExamNumber db = this.baseMapper.selectById(examNumberId);
|
|
|
+ return BeanUtil.toBean(db, ExamNumberVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamNumberVo> queryList(ExamNumberQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<ExamNumber> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getCode()), ExamNumber::getCode, bo.getCode());
|
|
|
+ lqw.eq(bo.getExamNumber() != null, ExamNumber::getExamNumber, bo.getExamNumber());
|
|
|
+ lqw.eq(bo.getDoNumber() != null, ExamNumber::getDoNumber, bo.getDoNumber());
|
|
|
+ lqw.eq(bo.getStatus() != null, ExamNumber::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getGoodsType() != null, ExamNumber::getGoodsType, bo.getGoodsType());
|
|
|
+ lqw.eq(bo.getEducationTypeId() != null, ExamNumber::getEducationTypeId, bo.getEducationTypeId());
|
|
|
+ lqw.eq(bo.getBusinessId() != null, ExamNumber::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.eq(bo.getProjectId() != null, ExamNumber::getProjectId, bo.getProjectId());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<ExamNumberVo> entity2Vo(Collection<ExamNumber> collection) {
|
|
|
+ List<ExamNumberVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, ExamNumberVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<ExamNumber> page = (Page<ExamNumber>)collection;
|
|
|
+ Page<ExamNumberVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByAddBo(ExamNumberAddBo bo) {
|
|
|
+ ExamNumber add = BeanUtil.toBean(bo, ExamNumber.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCode(ServletUtils.getEncoded("KC"));
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ boolean save = this.save(add);
|
|
|
+ for (Long goodsId : bo.getGoodsId()) {
|
|
|
+ ExamNumberGoodsAddBo examNumberGoodsAddBo = new ExamNumberGoodsAddBo();
|
|
|
+ examNumberGoodsAddBo.setGoodsId(goodsId);
|
|
|
+ examNumberGoodsAddBo.setExamNumberId(add.getExamNumberId());
|
|
|
+ examNumberGoodsAddBo.setCreateTime(DateUtils.getNowTime());
|
|
|
+ examNumberGoodsAddBo.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ examNumberGoodsService.insertByAddBo(examNumberGoodsAddBo);
|
|
|
+ }
|
|
|
+ return save;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(ExamNumberEditBo bo) {
|
|
|
+ ExamNumber update = BeanUtil.toBean(bo, ExamNumber.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ if (bo.getGoodsId() != null){
|
|
|
+ LambdaQueryWrapper<ExamNumberGoods> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(ExamNumberGoods::getExamNumberId, bo.getExamNumberId());
|
|
|
+ examNumberGoodsService.remove(lqw);
|
|
|
+ for (Long goodsId : bo.getGoodsId()) {
|
|
|
+ if (bo.getStatus() == 1) {
|
|
|
+ ExamNumberQueryBo examNumberQueryBo = new ExamNumberQueryBo();
|
|
|
+ List<Integer> status = new ArrayList<>();
|
|
|
+ status.add(1);
|
|
|
+ examNumberQueryBo.setStatus(status);
|
|
|
+ examNumberQueryBo.setGoodsId(goodsId);
|
|
|
+ List<ExamNumberVo> examNumberVos = baseMapper.ListExamNumber(examNumberQueryBo);
|
|
|
+ if (CollectionUtils.isNotEmpty(examNumberVos)) {
|
|
|
+ throw new IllegalArgumentException("考次存在商品已启用考次配置,不可开启,请重新创建新的考次配置商品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ExamNumberGoodsAddBo examNumberGoodsAddBo = new ExamNumberGoodsAddBo();
|
|
|
+ examNumberGoodsAddBo.setGoodsId(goodsId);
|
|
|
+ examNumberGoodsAddBo.setExamNumberId(update.getExamNumberId());
|
|
|
+ examNumberGoodsAddBo.setCreateTime(DateUtils.getNowTime());
|
|
|
+ examNumberGoodsAddBo.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ examNumberGoodsService.insertByAddBo(examNumberGoodsAddBo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(ExamNumber entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamNumberVo> ListExamNumber(ExamNumberQueryBo bo) {
|
|
|
+ List<ExamNumberVo> examNumberVos = baseMapper.ListExamNumber(bo);
|
|
|
+ for (ExamNumberVo examNumberVo : examNumberVos) {
|
|
|
+ List<ExamNumberGoodsVo> examNumberGoodsVos = examNumberGoodsService.ListExamNumber(examNumberVo.getExamNumberId());
|
|
|
+ examNumberVo.setExamNumberGoodsVos(examNumberGoodsVos);
|
|
|
+ }
|
|
|
+ return examNumberVos;
|
|
|
+ }
|
|
|
+}
|