Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/dev' into dev

yangdamao 2 gadi atpakaļ
vecāks
revīzija
a82e6278ad

+ 10 - 26
zhongzheng-api/src/main/java/com/zhongzheng/controller/goods/GoodsQuestionRelExamController.java

@@ -4,11 +4,14 @@ import java.util.List;
 import java.util.Arrays;
 
 import com.zhongzheng.common.core.page.TableDataInfo;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.WxTokenService;
 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.service.IGoodsQuestionRelExamService;
 import com.zhongzheng.modules.goods.vo.GoodsQuestionRelExamVo;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,39 +44,20 @@ public class GoodsQuestionRelExamController extends BaseController {
 
     private final IGoodsQuestionRelExamService iGoodsQuestionRelExamService;
 
-    /**
-     * 查询三方题库试卷记录列表
-     */
-    @ApiOperation("查询三方题库试卷记录列表")
-    @PreAuthorize("@ss.hasPermi('system:exam:list')")
-    @GetMapping("/list")
-    public TableDataInfo<GoodsQuestionRelExamVo> list(GoodsQuestionRelExamQueryBo bo) {
-        startPage();
-        List<GoodsQuestionRelExamVo> list = iGoodsQuestionRelExamService.queryList(bo);
-        return getDataTable(list);
-    }
-
+    private final WxTokenService wxTokenService;
 
 
-    /**
-     * 获取三方题库试卷记录详细信息
-     */
-    @ApiOperation("获取三方题库试卷记录详细信息")
-    @PreAuthorize("@ss.hasPermi('system:exam:query')")
-    @GetMapping("/{id}")
-    public AjaxResult<GoodsQuestionRelExamVo> getInfo(@PathVariable("id" ) Long id) {
-        return AjaxResult.success(iGoodsQuestionRelExamService.queryById(id));
-    }
-
     /**
      * 新增三方题库试卷记录
      */
-    @ApiOperation("新增三方题库试卷记录")
+    @ApiOperation("获取三方题库试卷ID")
     @PreAuthorize("@ss.hasPermi('system:exam:add')")
-    @Log(title = "三方题库试卷记录", businessType = BusinessType.INSERT)
+    @Log(title = "获取三方题库试卷ID", businessType = BusinessType.INSERT)
     @PostMapping()
-    public AjaxResult<Void> add(@RequestBody GoodsQuestionRelExamAddBo bo) {
-        return toAjax(iGoodsQuestionRelExamService.insertByAddBo(bo) ? 1 : 0);
+    public AjaxResult<GoodsQuestionRelExamVo> add(@RequestBody GoodsQuestionRelExamAddBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        return AjaxResult.success(iGoodsQuestionRelExamService.makeExam(bo));
     }
 
 

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IQuestionOtherService.java

@@ -24,6 +24,8 @@ public interface IQuestionOtherService extends IService<QuestionOther> {
 	 */
 	QuestionOtherVo queryById(Long id);
 
+	Long queryByUserMajor(Long userId,String majorname);
+
 	/**
 	 * 查询列表
 	 */

+ 13 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/QuestionOtherServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zhongzheng.modules.bank.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -19,6 +20,7 @@ import com.zhongzheng.modules.bank.service.IQuestionService;
 import com.zhongzheng.modules.bank.vo.ExamVo;
 import com.zhongzheng.modules.bank.vo.QuestionOtherVo;
 import com.zhongzheng.modules.course.service.ICourseMenuExamService;
+import com.zhongzheng.modules.order.domain.OrderGoods;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -179,6 +181,17 @@ public class QuestionOtherServiceImpl extends ServiceImpl<QuestionOtherMapper, Q
         return BeanUtil.toBean(db, QuestionOtherVo.class);
     }
 
+    @Override
+    public Long queryByUserMajor(Long userId, String majorname) {
+        QuestionOther questionOther = getOne(new LambdaQueryWrapper<QuestionOther>()
+                .eq(QuestionOther::getUserId, userId).eq(QuestionOther::getMajorname, majorname)
+                .eq(QuestionOther::getStatus, 1));
+        if(Validator.isNotEmpty(questionOther.getExamId())){
+            return questionOther.getExamId();
+        }
+        return null;
+    }
+
     private Long dealOptions(String v) {
         if ("A".equals(v)) {
            return 1L;

+ 44 - 4
zhongzheng-system/src/main/java/com/zhongzheng/modules/goods/service/impl/GoodsQuestionRelExamServiceImpl.java

@@ -5,19 +5,26 @@ 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.bank.service.IQuestionOtherService;
 import com.zhongzheng.modules.course.domain.CourseTopic;
+import com.zhongzheng.modules.course.domain.Major;
+import com.zhongzheng.modules.course.service.IMajorService;
 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.Goods;
 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.service.IGoodsService;
 import com.zhongzheng.modules.goods.vo.GoodsQuestionRelExamVo;
 import com.zhongzheng.modules.order.domain.OrderGoods;
 import com.zhongzheng.modules.order.service.IOrderGoodsService;
+import com.zhongzheng.modules.user.domain.UserSubscribe;
+import com.zhongzheng.modules.user.service.IUserSubscribeService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -46,6 +53,18 @@ public class GoodsQuestionRelExamServiceImpl extends ServiceImpl<GoodsQuestionRe
     @Autowired
     private IOrderGoodsService iOrderGoodsService;
 
+    @Autowired
+    private IGoodsService iGoodsService;
+
+    @Autowired
+    private IMajorService iMajorService;
+
+    @Autowired
+    private IQuestionOtherService iQuestionOtherService;
+
+    @Autowired
+    private IUserSubscribeService iUserSubscribeService;
+
     @Override
     public GoodsQuestionRelExamVo queryById(Long id){
         GoodsQuestionRelExam db = this.baseMapper.selectById(id);
@@ -108,21 +127,42 @@ public class GoodsQuestionRelExamServiceImpl extends ServiceImpl<GoodsQuestionRe
         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>()
+        OrderGoods qsOrderGoods = iOrderGoodsService.getOne(new LambdaQueryWrapper<OrderGoods>()
                 .eq(OrderGoods::getOrderGoodsId, questionRel.getQsOrderGoodsId()));
-        if(Validator.isEmpty(orderGoods)||orderGoods.getServiceEndTime()<DateUtils.getNowTime()||orderGoods.getServiceStartTime()>DateUtils.getNowTime()){
+        if(Validator.isEmpty(qsOrderGoods)||qsOrderGoods.getServiceEndTime()<DateUtils.getNowTime()||qsOrderGoods.getServiceStartTime()>DateUtils.getNowTime()){
             throw new CustomException("未在服务期内无法访问");
-
         }
         if(questionRel.getQuestionDoNum()<1){
             throw new CustomException("该题库商品试卷可用次数不足");
         }
+        UserSubscribe userSubscribe = iUserSubscribeService.getOne(new LambdaQueryWrapper<UserSubscribe>()
+                .eq(UserSubscribe::getUserId, bo.getUserId()).eq(UserSubscribe::getOrderGoodsId, questionRel.getOrderGoodsId())
+                .eq(UserSubscribe::getExamStatus, 1).orderByDesc(UserSubscribe::getSubscribeId).last("limit 1"));
+        if(Validator.isEmpty(userSubscribe)){
+            throw new CustomException("预约数据不存在");
+        }
+        OrderGoods orderGoods = iOrderGoodsService.getOne(new LambdaQueryWrapper<OrderGoods>()
+                .eq(OrderGoods::getOrderGoodsId, questionRel.getOrderGoodsId()));
+        Goods goods = iGoodsService.getOne(new LambdaQueryWrapper<Goods>()
+                .eq(Goods::getGoodsId, orderGoods.getGoodsId()));
+        if(Validator.isEmpty(goods.getMajorId())){
+            throw new CustomException("商品专业不存在");
+        }
+        Major major = iMajorService.getOne(new LambdaQueryWrapper<Major>()
+                .eq(Major::getId, goods.getMajorId()));
+        Long examId = iQuestionOtherService.queryByUserMajor(bo.getUserId(),major.getCategoryName());
+        if(Validator.isEmpty(examId)){
+            throw new CustomException("试卷不存在");
+        }
+        add.setExpTime(qsOrderGoods.getServiceEndTime());
+        add.setExamId(examId);
+        add.setUserSubscribeId(userSubscribe.getSubscribeId());
         this.save(add);
         return BeanUtil.toBean(add,GoodsQuestionRelExamVo.class);
     }

+ 1 - 1
zhongzheng-system/src/main/resources/mapper/modules/top/TopInstitutionMapper.xml

@@ -17,7 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="listByCat" parameterType="com.zhongzheng.modules.top.system.bo.TopInstitutionQueryBo"  resultType="com.zhongzheng.modules.top.system.vo.TopInstitutionVo">
         SELECT
-        i.*
+        DISTINCT i.*
         FROM
         top_cost_inst_tp it
         LEFT JOIN top_cost_inst_tp_item iti ON it.tp_id = iti.tp_id