|
@@ -1,15 +1,24 @@
|
|
|
package com.zhongzheng.modules.goods.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.course.domain.CourseTopic;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsQuestionRelExamAddBo;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsQuestionRelExamEditBo;
|
|
|
import com.zhongzheng.modules.goods.bo.GoodsQuestionRelExamQueryBo;
|
|
|
+import com.zhongzheng.modules.goods.domain.GoodsQuestionRel;
|
|
|
import com.zhongzheng.modules.goods.domain.GoodsQuestionRelExam;
|
|
|
import com.zhongzheng.modules.goods.mapper.GoodsQuestionRelExamMapper;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsCourseService;
|
|
|
import com.zhongzheng.modules.goods.service.IGoodsQuestionRelExamService;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsQuestionRelService;
|
|
|
import com.zhongzheng.modules.goods.vo.GoodsQuestionRelExamVo;
|
|
|
+import com.zhongzheng.modules.order.domain.OrderGoods;
|
|
|
+import com.zhongzheng.modules.order.service.IOrderGoodsService;
|
|
|
+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;
|
|
@@ -31,6 +40,12 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class GoodsQuestionRelExamServiceImpl extends ServiceImpl<GoodsQuestionRelExamMapper, GoodsQuestionRelExam> implements IGoodsQuestionRelExamService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsQuestionRelService iGoodsQuestionRelService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOrderGoodsService iOrderGoodsService;
|
|
|
+
|
|
|
@Override
|
|
|
public GoodsQuestionRelExamVo queryById(Long id){
|
|
|
GoodsQuestionRelExam db = this.baseMapper.selectById(id);
|
|
@@ -78,6 +93,40 @@ public class GoodsQuestionRelExamServiceImpl extends ServiceImpl<GoodsQuestionRe
|
|
|
return this.save(add);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public GoodsQuestionRelExamVo makeExam(GoodsQuestionRelExamAddBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getRelId())){
|
|
|
+ throw new CustomException("参数缺失");
|
|
|
+ }
|
|
|
+ GoodsQuestionRelExam detail = getOne(new LambdaQueryWrapper<GoodsQuestionRelExam>()
|
|
|
+ .eq(GoodsQuestionRelExam::getRelId, bo.getRelId()).eq(GoodsQuestionRelExam::getStatus, 1)
|
|
|
+ .ge(GoodsQuestionRelExam::getExpTime, DateUtils.getNowTime()).last("limit 1"));
|
|
|
+ if(Validator.isNotEmpty(detail)){
|
|
|
+ return BeanUtil.toBean(detail,GoodsQuestionRelExamVo.class);
|
|
|
+ }
|
|
|
+ GoodsQuestionRelExam add = BeanUtil.toBean(bo, GoodsQuestionRelExam.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setExpTime(DateUtils.getNowTime()+7*24*3600);
|
|
|
+ GoodsQuestionRel questionRel = iGoodsQuestionRelService.getOne(new LambdaQueryWrapper<GoodsQuestionRel>()
|
|
|
+ .eq(GoodsQuestionRel::getId, bo.getRelId()).eq(GoodsQuestionRel::getStatus, 1));
|
|
|
+ if(Validator.isEmpty(questionRel)){
|
|
|
+ throw new CustomException("该题库商品无法访问");
|
|
|
+ }
|
|
|
+ OrderGoods orderGoods = iOrderGoodsService.getOne(new LambdaQueryWrapper<OrderGoods>()
|
|
|
+ .eq(OrderGoods::getOrderGoodsId, questionRel.getQsOrderGoodsId()));
|
|
|
+ if(Validator.isEmpty(orderGoods)||orderGoods.getServiceEndTime()<DateUtils.getNowTime()||orderGoods.getServiceStartTime()>DateUtils.getNowTime()){
|
|
|
+ throw new CustomException("未在服务期内无法访问");
|
|
|
+
|
|
|
+ }
|
|
|
+ if(questionRel.getQuestionDoNum()<1){
|
|
|
+ throw new CustomException("该题库商品试卷可用次数不足");
|
|
|
+ }
|
|
|
+ this.save(add);
|
|
|
+ return BeanUtil.toBean(add,GoodsQuestionRelExamVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean updateByEditBo(GoodsQuestionRelExamEditBo bo) {
|
|
|
GoodsQuestionRelExam update = BeanUtil.toBean(bo, GoodsQuestionRelExam.class);
|