Bladeren bron

fix 新增随机试卷

he2802 2 jaren geleden
bovenliggende
commit
d6b24ad5fe
19 gewijzigde bestanden met toevoegingen van 1010 en 0 verwijderingen
  1. 79 0
      zhongzheng-api/src/main/java/com/zhongzheng/controller/bank/ExamTempController.java
  2. 44 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempAddBo.java
  3. 48 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempEditBo.java
  4. 56 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQueryBo.java
  5. 30 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionAddBo.java
  6. 37 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionEditBo.java
  7. 48 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionQueryBo.java
  8. 45 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/domain/ExamTemp.java
  9. 35 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/domain/ExamTempQuestion.java
  10. 20 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/ExamTempMapper.java
  11. 14 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/ExamTempQuestionMapper.java
  12. 52 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IExamTempQuestionService.java
  13. 57 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IExamTempService.java
  14. 98 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/ExamTempQuestionServiceImpl.java
  15. 157 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/ExamTempServiceImpl.java
  16. 39 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/ExamTempQuestionVo.java
  17. 50 0
      zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/ExamTempVo.java
  18. 86 0
      zhongzheng-system/src/main/resources/mapper/modules/bank/ExamTempMapper.xml
  19. 15 0
      zhongzheng-system/src/main/resources/mapper/modules/bank/ExamTempQuestionMapper.xml

+ 79 - 0
zhongzheng-api/src/main/java/com/zhongzheng/controller/bank/ExamTempController.java

@@ -0,0 +1,79 @@
+package com.zhongzheng.controller.bank;
+
+import com.zhongzheng.common.annotation.Log;
+import com.zhongzheng.common.core.controller.BaseController;
+import com.zhongzheng.common.core.domain.AjaxResult;
+import com.zhongzheng.common.core.page.TableDataInfo;
+import com.zhongzheng.common.enums.BusinessType;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.framework.web.service.WxTokenService;
+import com.zhongzheng.modules.bank.bo.ExamTempAddBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQueryBo;
+import com.zhongzheng.modules.bank.service.IExamTempService;
+import com.zhongzheng.modules.bank.vo.ExamTempVo;
+import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * 随机生成试卷Controller
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Api(value = "随机生成试卷控制器", tags = {"随机生成试卷管理"})
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/bank/exam/temp")
+public class ExamTempController extends BaseController {
+
+    private final IExamTempService iExamTempService;
+
+    private final WxTokenService wxTokenService;
+
+    /**
+     * 查询随机生成试卷列表
+     */
+    @ApiOperation("查询随机生成试卷列表")
+    @PreAuthorize("@ss.hasPermi('system:temp:list')")
+    @GetMapping("/list")
+    public TableDataInfo<ExamTempVo> list(ExamTempQueryBo bo) {
+        startPage();
+        List<ExamTempVo> list = iExamTempService.queryList(bo);
+        return getDataTable(list);
+    }
+
+
+
+    /**
+     * 获取随机生成试卷详细信息
+     */
+    @ApiOperation("获取随机生成试卷详细信息")
+    @PreAuthorize("@ss.hasPermi('system:temp:query')")
+    @GetMapping("/{examId}")
+    public AjaxResult<ExamTempVo> getInfo(@PathVariable("examId" ) Long examId) {
+        return AjaxResult.success(iExamTempService.queryById(examId));
+    }
+
+    /**
+     * 新增随机生成试卷
+     */
+    @ApiOperation("新增随机生成试卷")
+    @PreAuthorize("@ss.hasPermi('system:temp:add')")
+    @Log(title = "随机生成试卷", businessType = BusinessType.INSERT)
+    @PostMapping()
+    public AjaxResult<ExamTempVo> add(@RequestBody ExamTempAddBo bo) {
+        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        bo.setUserId(loginUser.getUser().getUserId());
+        return AjaxResult.success(iExamTempService.insertByAddBo(bo));
+    }
+
+
+
+}

+ 44 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempAddBo.java

@@ -0,0 +1,44 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+
+/**
+ * 随机生成试卷添加对象 exam_temp
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机生成试卷添加对象")
+public class ExamTempAddBo {
+
+    /**  状态 1正常 0关闭 */
+    @ApiModelProperty(" 状态 1正常 0关闭")
+    private Integer status;
+    /** 更新时间 */
+    @ApiModelProperty("更新时间")
+    private Long updateTime;
+    /** 试卷名 */
+    @ApiModelProperty("试卷名")
+    private String examName;
+    /** 创建时间 */
+    @ApiModelProperty("创建时间")
+    private Long createTime;
+    /** 商品ID */
+    @ApiModelProperty("商品ID")
+    private Long goodsId;
+    /** 用户ID */
+    @ApiModelProperty("用户ID")
+    private Long userId;
+    /** 订单商品ID */
+    @ApiModelProperty("订单商品ID")
+    private Long orderGoodsId;
+    @ApiModelProperty("生成题目数量")
+    private Integer number;
+}

+ 48 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempEditBo.java

@@ -0,0 +1,48 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+/**
+ * 随机生成试卷编辑对象 exam_temp
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机生成试卷编辑对象")
+public class ExamTempEditBo {
+
+    /** $column.columnComment */
+    @ApiModelProperty("$column.columnComment")
+    private Long examId;
+
+    /**  状态 1正常 0关闭 */
+    @ApiModelProperty(" 状态 1正常 0关闭")
+    private Integer status;
+
+    /** 更新时间 */
+    @ApiModelProperty("更新时间")
+    private Long updateTime;
+
+    /** 试卷名 */
+    @ApiModelProperty("试卷名")
+    private String examName;
+
+    /** 商品ID */
+    @ApiModelProperty("商品ID")
+    private Long goodsId;
+
+    /** 用户ID */
+    @ApiModelProperty("用户ID")
+    private Long userId;
+
+    /** 订单商品ID */
+    @ApiModelProperty("订单商品ID")
+    private Long orderGoodsId;
+
+}

+ 56 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQueryBo.java

@@ -0,0 +1,56 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
+
+import com.zhongzheng.common.core.domain.BaseEntity;
+
+/**
+ * 随机生成试卷分页查询对象 exam_temp
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("随机生成试卷分页查询对象")
+public class ExamTempQueryBo extends BaseEntity {
+
+	/** 分页大小 */
+	@ApiModelProperty("分页大小")
+	private Integer pageSize;
+	/** 当前页数 */
+	@ApiModelProperty("当前页数")
+	private Integer pageNum;
+	/** 排序列 */
+	@ApiModelProperty("排序列")
+	private String orderByColumn;
+	/** 排序的方向desc或者asc */
+	@ApiModelProperty(value = "排序的方向", example = "asc,desc")
+	private String isAsc;
+
+
+	/**  状态 1正常 0关闭 */
+	@ApiModelProperty(" 状态 1正常 0关闭")
+	private Integer status;
+	/** 试卷名 */
+	@ApiModelProperty("试卷名")
+	private String examName;
+	/** 商品ID */
+	@ApiModelProperty("商品ID")
+	private Long goodsId;
+	/** 用户ID */
+	@ApiModelProperty("用户ID")
+	private Long userId;
+	/** 订单商品ID */
+	@ApiModelProperty("订单商品ID")
+	private Long orderGoodsId;
+	@ApiModelProperty("生成题目数量")
+	private Integer number;
+}

+ 30 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionAddBo.java

@@ -0,0 +1,30 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+
+/**
+ * 随机试卷题目关系添加对象 exam_temp_question
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机试卷题目关系添加对象")
+public class ExamTempQuestionAddBo {
+
+    /** 试卷ID */
+    @ApiModelProperty("试卷ID")
+    private Long examId;
+    /** 题目ID */
+    @ApiModelProperty("题目ID")
+    private Long questionId;
+    /** 排序 */
+    @ApiModelProperty("排序")
+    private Long sort;
+}

+ 37 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionEditBo.java

@@ -0,0 +1,37 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import java.util.Date;
+
+
+/**
+ * 随机试卷题目关系编辑对象 exam_temp_question
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机试卷题目关系编辑对象")
+public class ExamTempQuestionEditBo {
+
+    /** $column.columnComment */
+    @ApiModelProperty("$column.columnComment")
+    private Long id;
+
+    /** 试卷ID */
+    @ApiModelProperty("试卷ID")
+    private Long examId;
+
+    /** 题目ID */
+    @ApiModelProperty("题目ID")
+    private Long questionId;
+
+    /** 排序 */
+    @ApiModelProperty("排序")
+    private Long sort;
+
+
+}

+ 48 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/bo/ExamTempQuestionQueryBo.java

@@ -0,0 +1,48 @@
+package com.zhongzheng.modules.bank.bo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
+
+import com.zhongzheng.common.core.domain.BaseEntity;
+
+/**
+ * 随机试卷题目关系分页查询对象 exam_temp_question
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ApiModel("随机试卷题目关系分页查询对象")
+public class ExamTempQuestionQueryBo extends BaseEntity {
+
+	/** 分页大小 */
+	@ApiModelProperty("分页大小")
+	private Integer pageSize;
+	/** 当前页数 */
+	@ApiModelProperty("当前页数")
+	private Integer pageNum;
+	/** 排序列 */
+	@ApiModelProperty("排序列")
+	private String orderByColumn;
+	/** 排序的方向desc或者asc */
+	@ApiModelProperty(value = "排序的方向", example = "asc,desc")
+	private String isAsc;
+
+
+	/** 试卷ID */
+	@ApiModelProperty("试卷ID")
+	private Long examId;
+	/** 题目ID */
+	@ApiModelProperty("题目ID")
+	private Long questionId;
+	/** 排序 */
+	@ApiModelProperty("排序")
+	private Long sort;
+}

+ 45 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/domain/ExamTemp.java

@@ -0,0 +1,45 @@
+package com.zhongzheng.modules.bank.domain;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import java.io.Serializable;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.zhongzheng.common.annotation.Excel;
+
+/**
+ * 随机生成试卷对象 exam_temp
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("exam_temp")
+public class ExamTemp implements Serializable {
+
+private static final long serialVersionUID=1L;
+
+    /** $column.columnComment */
+    @TableId(value = "exam_id")
+    private Long examId;
+    /**  状态 1正常 0关闭 */
+    private Integer status;
+    /** 更新时间 */
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    private Long updateTime;
+    /** 试卷名 */
+    private String examName;
+    /** 创建时间 */
+    @TableField(fill = FieldFill.INSERT)
+    private Long createTime;
+    /** 商品ID */
+    private Long goodsId;
+    /** 用户ID */
+    private Long userId;
+    /** 订单商品ID */
+    private Long orderGoodsId;
+}

+ 35 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/domain/ExamTempQuestion.java

@@ -0,0 +1,35 @@
+package com.zhongzheng.modules.bank.domain;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.experimental.Accessors;
+import java.io.Serializable;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.zhongzheng.common.annotation.Excel;
+
+/**
+ * 随机试卷题目关系对象 exam_temp_question
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("exam_temp_question")
+public class ExamTempQuestion implements Serializable {
+
+private static final long serialVersionUID=1L;
+
+    /** $column.columnComment */
+    @TableId(value = "id")
+    private Long id;
+    /** 试卷ID */
+    private Long examId;
+    /** 题目ID */
+    private Long questionId;
+    /** 排序 */
+    private Long sort;
+}

+ 20 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/ExamTempMapper.java

@@ -0,0 +1,20 @@
+package com.zhongzheng.modules.bank.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zhongzheng.modules.bank.bo.ExamQueryBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQueryBo;
+import com.zhongzheng.modules.bank.domain.ExamTemp;
+import com.zhongzheng.modules.bank.vo.ExamVo;
+import com.zhongzheng.modules.bank.vo.QuestionVo;
+
+import java.util.List;
+
+/**
+ * 随机生成试卷Mapper接口
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+public interface ExamTempMapper extends BaseMapper<ExamTemp> {
+    List<QuestionVo> getQuestionList(ExamTempQueryBo bo);
+}

+ 14 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/mapper/ExamTempQuestionMapper.java

@@ -0,0 +1,14 @@
+package com.zhongzheng.modules.bank.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zhongzheng.modules.bank.domain.ExamTempQuestion;
+
+/**
+ * 随机试卷题目关系Mapper接口
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+public interface ExamTempQuestionMapper extends BaseMapper<ExamTempQuestion> {
+
+}

+ 52 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IExamTempQuestionService.java

@@ -0,0 +1,52 @@
+package com.zhongzheng.modules.bank.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionAddBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionEditBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionQueryBo;
+import com.zhongzheng.modules.bank.domain.ExamTempQuestion;
+import com.zhongzheng.modules.bank.vo.ExamTempQuestionVo;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 随机试卷题目关系Service接口
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+public interface IExamTempQuestionService extends IService<ExamTempQuestion> {
+	/**
+	 * 查询单个
+	 * @return
+	 */
+	ExamTempQuestionVo queryById(Long id);
+
+	/**
+	 * 查询列表
+	 */
+	List<ExamTempQuestionVo> queryList(ExamTempQuestionQueryBo bo);
+
+	/**
+	 * 根据新增业务对象插入随机试卷题目关系
+	 * @param bo 随机试卷题目关系新增业务对象
+	 * @return
+	 */
+	Boolean insertByAddBo(ExamTempQuestionAddBo bo);
+
+	/**
+	 * 根据编辑业务对象修改随机试卷题目关系
+	 * @param bo 随机试卷题目关系编辑业务对象
+	 * @return
+	 */
+	Boolean updateByEditBo(ExamTempQuestionEditBo bo);
+
+	/**
+	 * 校验并删除数据
+	 * @param ids 主键集合
+	 * @param isValid 是否校验,true-删除前校验,false-不校验
+	 * @return
+	 */
+	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+}

+ 57 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/IExamTempService.java

@@ -0,0 +1,57 @@
+package com.zhongzheng.modules.bank.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zhongzheng.modules.bank.bo.ExamTempAddBo;
+import com.zhongzheng.modules.bank.bo.ExamTempEditBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQueryBo;
+import com.zhongzheng.modules.bank.domain.ExamTemp;
+import com.zhongzheng.modules.bank.vo.ExamTempVo;
+import com.zhongzheng.modules.bank.vo.QuestionVo;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 随机生成试卷Service接口
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+public interface IExamTempService extends IService<ExamTemp> {
+	/**
+	 * 查询单个
+	 * @return
+	 */
+	ExamTempVo queryById(Long examId);
+
+	/**
+	 * 查询列表
+	 */
+	List<ExamTempVo> queryList(ExamTempQueryBo bo);
+
+	List<QuestionVo> getQuestionList(ExamTempQueryBo bo);
+
+	/**
+	 * 根据新增业务对象插入随机生成试卷
+	 * @param bo 随机生成试卷新增业务对象
+	 * @return
+	 */
+	ExamTempVo insertByAddBo(ExamTempAddBo bo);
+
+
+
+	/**
+	 * 根据编辑业务对象修改随机生成试卷
+	 * @param bo 随机生成试卷编辑业务对象
+	 * @return
+	 */
+	Boolean updateByEditBo(ExamTempEditBo bo);
+
+	/**
+	 * 校验并删除数据
+	 * @param ids 主键集合
+	 * @param isValid 是否校验,true-删除前校验,false-不校验
+	 * @return
+	 */
+	Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+}

+ 98 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/ExamTempQuestionServiceImpl.java

@@ -0,0 +1,98 @@
+package com.zhongzheng.modules.bank.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionAddBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionEditBo;
+import com.zhongzheng.modules.bank.bo.ExamTempQuestionQueryBo;
+import com.zhongzheng.modules.bank.domain.ExamTempQuestion;
+import com.zhongzheng.modules.bank.mapper.ExamTempQuestionMapper;
+import com.zhongzheng.modules.bank.service.IExamTempQuestionService;
+import com.zhongzheng.modules.bank.vo.ExamTempQuestionVo;
+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 hjl
+ * @date 2022-11-14
+ */
+@Service
+public class ExamTempQuestionServiceImpl extends ServiceImpl<ExamTempQuestionMapper, ExamTempQuestion> implements IExamTempQuestionService {
+
+    @Override
+    public ExamTempQuestionVo queryById(Long id){
+        ExamTempQuestion db = this.baseMapper.selectById(id);
+        return BeanUtil.toBean(db, ExamTempQuestionVo.class);
+    }
+
+    @Override
+    public List<ExamTempQuestionVo> queryList(ExamTempQuestionQueryBo bo) {
+        LambdaQueryWrapper<ExamTempQuestion> lqw = Wrappers.lambdaQuery();
+        lqw.eq(bo.getExamId() != null, ExamTempQuestion::getExamId, bo.getExamId());
+        lqw.eq(bo.getQuestionId() != null, ExamTempQuestion::getQuestionId, bo.getQuestionId());
+        lqw.eq(bo.getSort() != null, ExamTempQuestion::getSort, bo.getSort());
+        return entity2Vo(this.list(lqw));
+    }
+
+    /**
+    * 实体类转化成视图对象
+    *
+    * @param collection 实体类集合
+    * @return
+    */
+    private List<ExamTempQuestionVo> entity2Vo(Collection<ExamTempQuestion> collection) {
+        List<ExamTempQuestionVo> voList = collection.stream()
+                .map(any -> BeanUtil.toBean(any, ExamTempQuestionVo.class))
+                .collect(Collectors.toList());
+        if (collection instanceof Page) {
+            Page<ExamTempQuestion> page = (Page<ExamTempQuestion>)collection;
+            Page<ExamTempQuestionVo> pageVo = new Page<>();
+            BeanUtil.copyProperties(page,pageVo);
+            pageVo.addAll(voList);
+            voList = pageVo;
+        }
+        return voList;
+    }
+
+    @Override
+    public Boolean insertByAddBo(ExamTempQuestionAddBo bo) {
+        ExamTempQuestion add = BeanUtil.toBean(bo, ExamTempQuestion.class);
+        validEntityBeforeSave(add);
+        return this.save(add);
+    }
+
+    @Override
+    public Boolean updateByEditBo(ExamTempQuestionEditBo bo) {
+        ExamTempQuestion update = BeanUtil.toBean(bo, ExamTempQuestion.class);
+        validEntityBeforeSave(update);
+        return this.updateById(update);
+    }
+
+    /**
+     * 保存前的数据校验
+     *
+     * @param entity 实体类数据
+     */
+    private void validEntityBeforeSave(ExamTempQuestion entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return this.removeByIds(ids);
+    }
+}

+ 157 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/service/impl/ExamTempServiceImpl.java

@@ -0,0 +1,157 @@
+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.zhongzheng.common.exception.CustomException;
+import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.ServletUtils;
+import com.zhongzheng.modules.bank.bo.*;
+import com.zhongzheng.modules.bank.domain.ExamQuestion;
+import com.zhongzheng.modules.bank.domain.ExamTemp;
+import com.zhongzheng.modules.bank.domain.ExamTempQuestion;
+import com.zhongzheng.modules.bank.mapper.ExamTempMapper;
+import com.zhongzheng.modules.bank.service.IExamTempQuestionService;
+import com.zhongzheng.modules.bank.service.IExamTempService;
+import com.zhongzheng.modules.bank.vo.ExamTempVo;
+import com.zhongzheng.modules.bank.vo.QuestionVo;
+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;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.Page;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 随机生成试卷Service业务层处理
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Service
+public class ExamTempServiceImpl extends ServiceImpl<ExamTempMapper, ExamTemp> implements IExamTempService {
+
+    @Autowired
+    private IOrderGoodsService iOrderGoodsService;
+
+    @Autowired
+    private IExamTempQuestionService iExamTempQuestionService;
+
+    @Override
+    public ExamTempVo queryById(Long examId){
+        ExamTemp db = this.baseMapper.selectById(examId);
+        return BeanUtil.toBean(db, ExamTempVo.class);
+    }
+
+    @Override
+    public List<ExamTempVo> queryList(ExamTempQueryBo bo) {
+        LambdaQueryWrapper<ExamTemp> lqw = Wrappers.lambdaQuery();
+        lqw.eq(bo.getStatus() != null, ExamTemp::getStatus, bo.getStatus());
+        lqw.like(StrUtil.isNotBlank(bo.getExamName()), ExamTemp::getExamName, bo.getExamName());
+        lqw.eq(bo.getGoodsId() != null, ExamTemp::getGoodsId, bo.getGoodsId());
+        lqw.eq(bo.getUserId() != null, ExamTemp::getUserId, bo.getUserId());
+        return entity2Vo(this.list(lqw));
+    }
+
+    @Override
+    public List<QuestionVo> getQuestionList(ExamTempQueryBo bo) {
+        return this.baseMapper.getQuestionList(bo);
+    }
+
+    /**
+    * 实体类转化成视图对象
+    *
+    * @param collection 实体类集合
+    * @return
+    */
+    private List<ExamTempVo> entity2Vo(Collection<ExamTemp> collection) {
+        List<ExamTempVo> voList = collection.stream()
+                .map(any -> BeanUtil.toBean(any, ExamTempVo.class))
+                .collect(Collectors.toList());
+        if (collection instanceof Page) {
+            Page<ExamTemp> page = (Page<ExamTemp>)collection;
+            Page<ExamTempVo> pageVo = new Page<>();
+            BeanUtil.copyProperties(page,pageVo);
+            pageVo.addAll(voList);
+            voList = pageVo;
+        }
+        return voList;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public ExamTempVo insertByAddBo(ExamTempAddBo bo) {
+        ExamTemp add = BeanUtil.toBean(bo, ExamTemp.class);
+        validEntityBeforeSave(add);
+        OrderGoods orderGoods = iOrderGoodsService.getOne(new LambdaQueryWrapper<OrderGoods>()
+                .eq(OrderGoods::getOrderGoodsId, bo.getOrderGoodsId()));
+        if(Validator.isEmpty(orderGoods)||!orderGoods.getGoodsId().equals(bo.getGoodsId())){
+            throw new CustomException("订单商品ID错误");
+        }
+        if(Validator.isEmpty(bo.getNumber())){
+            throw new CustomException("题目数量错误");
+        }
+        ExamTempQueryBo queryBo = new ExamTempQueryBo();
+        queryBo.setGoodsId(bo.getGoodsId());
+        queryBo.setOrderGoodsId(bo.getOrderGoodsId());
+        queryBo.setNumber(bo.getNumber());
+        List<QuestionVo> questionlist = getQuestionList(queryBo);
+
+        add.setExamName(ServletUtils.getEncoded("RD")+bo.getOrderGoodsId());
+
+        add.setCreateTime(DateUtils.getNowTime());
+        add.setUpdateTime(DateUtils.getNowTime());
+        boolean result = this.save(add);
+        if(questionlist!=null){
+            Collection<ExamTempQuestion> coll = new HashSet<>();
+            for(int i=0;i<questionlist.size();i++){
+                QuestionVo questionVo = questionlist.get(i);
+                ExamTempQuestion addItem = new ExamTempQuestion();
+                addItem.setExamId(add.getExamId());
+                addItem.setQuestionId(questionVo.getQuestionId());
+                addItem.setSort(new Long(i));
+                coll.add(addItem);
+            }
+            if(!iExamTempQuestionService.saveBatch(coll)){
+                throw new CustomException("试卷绑定错误");
+            }
+        }
+        ExamTempVo examTempVo = BeanUtil.toBean(add, ExamTempVo.class);
+        examTempVo.setQuestionList(questionlist);
+        return examTempVo;
+    }
+
+    @Override
+    public Boolean updateByEditBo(ExamTempEditBo bo) {
+        ExamTemp update = BeanUtil.toBean(bo, ExamTemp.class);
+        validEntityBeforeSave(update);
+        update.setUpdateTime(DateUtils.getNowTime());
+        return this.updateById(update);
+    }
+
+    /**
+     * 保存前的数据校验
+     *
+     * @param entity 实体类数据
+     */
+    private void validEntityBeforeSave(ExamTemp entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return this.removeByIds(ids);
+    }
+}

+ 39 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/ExamTempQuestionVo.java

@@ -0,0 +1,39 @@
+package com.zhongzheng.modules.bank.vo;
+
+import com.zhongzheng.common.annotation.Excel;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+
+
+
+/**
+ * 随机试卷题目关系视图对象 mall_package
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机试卷题目关系视图对象")
+public class ExamTempQuestionVo {
+	private static final long serialVersionUID = 1L;
+
+	/** $pkColumn.columnComment */
+	@ApiModelProperty("$pkColumn.columnComment")
+	private Long id;
+
+	/** 试卷ID */
+	@Excel(name = "试卷ID")
+	@ApiModelProperty("试卷ID")
+	private Long examId;
+	/** 题目ID */
+	@Excel(name = "题目ID")
+	@ApiModelProperty("题目ID")
+	private Long questionId;
+	/** 排序 */
+	@Excel(name = "排序")
+	@ApiModelProperty("排序")
+	private Long sort;
+}

+ 50 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/bank/vo/ExamTempVo.java

@@ -0,0 +1,50 @@
+package com.zhongzheng.modules.bank.vo;
+
+import com.zhongzheng.common.annotation.Excel;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * 随机生成试卷视图对象 mall_package
+ *
+ * @author hjl
+ * @date 2022-11-14
+ */
+@Data
+@ApiModel("随机生成试卷视图对象")
+public class ExamTempVo {
+	private static final long serialVersionUID = 1L;
+
+	/** $pkColumn.columnComment */
+	@ApiModelProperty("$pkColumn.columnComment")
+	private Long examId;
+
+	/**  状态 1正常 0关闭 */
+	@Excel(name = " 状态 1正常 0关闭")
+	@ApiModelProperty(" 状态 1正常 0关闭")
+	private Integer status;
+	/** 试卷名 */
+	@Excel(name = "试卷名")
+	@ApiModelProperty("试卷名")
+	private String examName;
+	/** 商品ID */
+	@Excel(name = "商品ID")
+	@ApiModelProperty("商品ID")
+	private Long goodsId;
+	/** 用户ID */
+	@Excel(name = "用户ID")
+	@ApiModelProperty("用户ID")
+	private Long userId;
+	/** 订单商品ID */
+	@Excel(name = "订单商品ID")
+	@ApiModelProperty("订单商品ID")
+	private Long orderGoodsId;
+
+	@ApiModelProperty("题目列表")
+	private List<QuestionVo> questionList;
+}

+ 86 - 0
zhongzheng-system/src/main/resources/mapper/modules/bank/ExamTempMapper.xml

@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhongzheng.modules.bank.mapper.ExamTempMapper">
+
+    <resultMap type="com.zhongzheng.modules.bank.domain.ExamTemp" id="ExamTempResult">
+        <result property="examId" column="exam_id"/>
+        <result property="status" column="status"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="examName" column="exam_name"/>
+        <result property="createTime" column="create_time"/>
+        <result property="goodsId" column="goods_id"/>
+        <result property="userId" column="user_id"/>
+        <result property="orderGoodsId" column="order_goods_id"/>
+    </resultMap>
+
+    <resultMap type="com.zhongzheng.modules.bank.vo.QuestionVo" id="QuestionResultVo">
+        <result property="questionId" column="question_id"/>
+        <result property="content" column="content"/>
+        <result property="type" column="type"/>
+        <result property="answerQuestion" column="answer_question"/>
+        <result property="status" column="status"/>
+        <result property="analysisContent" column="analysis_content"/>
+        <result property="imgUrl" column="img_url"/>
+        <result property="jsonStr" column="json_str"/>
+        <result property="prefixName" column="prefix_name"/>
+        <result property="knowledgeIds" column="knowledge_ids"/>
+        <result property="publishStatus" column="publish_status"/>
+        <result property="code" column="code"/>
+    </resultMap>
+
+    <select id="getQuestionList" parameterType="com.zhongzheng.modules.bank.bo.ExamTempQueryBo" resultType="QuestionResultVo">
+        SELECT
+            *
+        FROM
+            question
+        WHERE
+                question_id IN (
+                SELECT
+                    question_id
+                FROM
+                    exam_question
+                WHERE
+                    find_in_set(
+                            exam_id,(
+                        SELECT
+                            concat(
+                                    IFNULL((
+                                               SELECT
+                                                   GROUP_CONCAT( exam_id )
+                                               FROM
+                                                   question_chapter_exam
+                                               WHERE
+                                                   FIND_IN_SET(
+                                                           chapter_exam_id,
+                                                           (
+                                                               SELECT
+                                                                   concat(
+                                                                           IFNULL(( SELECT GROUP_CONCAT( major_id ) eids FROM goods_attached WHERE goods_id = #{goodsId} AND type = 2 ), '' ),
+                                                                           ',',
+                                                                           IFNULL(
+                                                                                   (
+                                                                                       SELECT
+                                                                                           GROUP_CONCAT( chapter_exam_id ) eids2
+                                                                                       FROM
+                                                                                           question_module_chapter
+                                                                                       WHERE
+                                                                                               module_exam_id IN ( SELECT major_id FROM goods_attached WHERE goods_id = #{goodsId} AND type = 1 )),
+                                                                                   ''
+                                                                               ))))),
+                                           ''
+                                        ),
+                                    ',',
+                                    IFNULL(( SELECT GROUP_CONCAT( major_id ) FROM goods_attached WHERE goods_id = #{goodsId} AND type = 3 ), '' ))))
+                  AND NOT FIND_IN_SET(
+                        question_id,(
+                            SELECT
+                                IFNULL(GROUP_CONCAT( do_question_ids ),'')
+                            FROM
+                                user_exam_record uer
+                            WHERE
+                                order_goods_id = #{orderGoodsId} and `type` = 2
+                        ))  GROUP BY question_id ) ORDER BY RAND() LIMIT  #{number}
+    </select>
+</mapper>

+ 15 - 0
zhongzheng-system/src/main/resources/mapper/modules/bank/ExamTempQuestionMapper.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhongzheng.modules.bank.mapper.ExamTempQuestionMapper">
+
+    <resultMap type="com.zhongzheng.modules.bank.domain.ExamTempQuestion" id="ExamTempQuestionResult">
+        <result property="id" column="id"/>
+        <result property="examId" column="exam_id"/>
+        <result property="questionId" column="question_id"/>
+        <result property="sort" column="sort"/>
+    </resultMap>
+
+
+</mapper>