parent
aa4270e61b
commit
811ea95957
@ -0,0 +1,56 @@
|
||||
package com.yf.exam.modules.qu.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
///**
|
||||
// * <p>
|
||||
// * 候选答案请求类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author 聪明笨狗
|
||||
// * @since 2020-05-25 13:23
|
||||
// */
|
||||
@Data
|
||||
@ApiModel(value="候选答案", description="候选答案")
|
||||
public class QuAnswerDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 答案的唯一标识ID
|
||||
// */
|
||||
@ApiModelProperty(value = "答案ID", required=true)
|
||||
private String id;
|
||||
|
||||
// /**
|
||||
// * 所属问题的唯一标识ID
|
||||
// */
|
||||
@ApiModelProperty(value = "问题ID", required=true)
|
||||
private String quId;
|
||||
|
||||
// /**
|
||||
// * 表示该答案是否正确
|
||||
// */
|
||||
@ApiModelProperty(value = "是否正确", required=true)
|
||||
private Boolean isRight;
|
||||
|
||||
// /**
|
||||
// * 选项的图片URL
|
||||
// */
|
||||
@ApiModelProperty(value = "选项图片", required=true)
|
||||
private String image;
|
||||
|
||||
// /**
|
||||
// * 答案的具体内容
|
||||
// */
|
||||
@ApiModelProperty(value = "答案内容", required=true)
|
||||
private String content;
|
||||
|
||||
// /**
|
||||
// * 对该答案的分析说明
|
||||
// */
|
||||
@ApiModelProperty(value = "答案分析", required=true)
|
||||
private String analysis;
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package com.yf.exam.modules.qu.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
|
||||
///**
|
||||
// * <p>
|
||||
// * 试题题库请求类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author 聪明笨狗
|
||||
// * @since 2020-05-25 13:23
|
||||
// */
|
||||
@Data
|
||||
@ApiModel(value="试题题库", description="试题题库")
|
||||
public class QuRepoDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 题库记录的唯一标识ID
|
||||
// */
|
||||
private String id;
|
||||
|
||||
// /**
|
||||
// * 关联试题的唯一标识ID
|
||||
// */
|
||||
@ApiModelProperty(value = "试题", required=true)
|
||||
private String quId;
|
||||
|
||||
// /**
|
||||
// * 归属题库的唯一标识ID
|
||||
// */
|
||||
@ApiModelProperty(value = "归属题库", required=true)
|
||||
private String repoId;
|
||||
|
||||
// /**
|
||||
// * 试题的类型
|
||||
// */
|
||||
@ApiModelProperty(value = "题目类型", required=true)
|
||||
private Integer quType;
|
||||
|
||||
// /**
|
||||
// * 试题在题库中的排序顺序
|
||||
// */
|
||||
@ApiModelProperty(value = "排序", required=true)
|
||||
private Integer sort;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.yf.exam.modules.qu.dto.ext;
|
||||
|
||||
import com.yf.exam.modules.qu.dto.QuAnswerDTO;
|
||||
import com.yf.exam.modules.qu.dto.QuDTO;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
// * <p>
|
||||
// * 问题题目请求类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author 聪明笨狗
|
||||
// * @since 2020-05-25 13:23
|
||||
// */
|
||||
@Data
|
||||
@ApiModel(value="问题题目详情", description="问题题目详情")
|
||||
public class QuDetailDTO extends QuDTO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 备选项列表
|
||||
// */
|
||||
@ApiModelProperty(value = "备选项列表", required=true)
|
||||
private List<QuAnswerDTO> answerList;
|
||||
|
||||
// /**
|
||||
// * 题库ID列表
|
||||
// */
|
||||
@ApiModelProperty(value = "题库列表", required=true)
|
||||
private List<String> repoIds;
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.yf.exam.modules.qu.dto.request;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
// * <p>
|
||||
// * 题目查询请求类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author 聪明笨狗
|
||||
// * @since 2020-05-25 13:23
|
||||
// */
|
||||
@Data
|
||||
@ApiModel(value="题目查询请求类", description="题目查询请求类")
|
||||
public class QuQueryReqDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 题目类型
|
||||
// */
|
||||
@ApiModelProperty(value = "题目类型")
|
||||
private Integer quType;
|
||||
|
||||
// /**
|
||||
// * 归属题库ID列表
|
||||
// */
|
||||
@ApiModelProperty(value = "归属题库")
|
||||
private List<String> repoIds;
|
||||
|
||||
// /**
|
||||
// * 题目内容的关键字
|
||||
// */
|
||||
@ApiModelProperty(value = "题目内容")
|
||||
private String content;
|
||||
|
||||
// /**
|
||||
// * 需要排除的题目ID列表
|
||||
// */
|
||||
@ApiModelProperty(value = "排除ID列表")
|
||||
private List<String> excludes;
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
package com.yf.exam.modules.qu.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 问题题目实体类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
@Data
|
||||
@TableName("el_qu")
|
||||
public class Qu extends Model<Qu> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 题目ID
|
||||
// */
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
// /**
|
||||
// * 题目类型
|
||||
// */
|
||||
@TableField("qu_type")
|
||||
private Integer quType;
|
||||
|
||||
// /**
|
||||
// * 1普通,2较难
|
||||
// */
|
||||
private Integer level;
|
||||
|
||||
// /**
|
||||
// * 题目图片
|
||||
// */
|
||||
private String image;
|
||||
|
||||
// /**
|
||||
// * 题目内容
|
||||
// */
|
||||
private String content;
|
||||
|
||||
// /**
|
||||
// * 创建时间
|
||||
// */
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
// /**
|
||||
// * 更新时间
|
||||
// */
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
// /**
|
||||
// * 题目备注
|
||||
// */
|
||||
private String remark;
|
||||
|
||||
// /**
|
||||
// * 整题解析
|
||||
// */
|
||||
private String analysis;
|
||||
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package com.yf.exam.modules.qu.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 候选答案实体类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
@Data
|
||||
@TableName("el_qu_answer")
|
||||
public class QuAnswer extends Model<QuAnswer> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// /**
|
||||
// * 答案ID
|
||||
// */
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
// /**
|
||||
// * 问题ID
|
||||
// */
|
||||
@TableField("qu_id")
|
||||
private String quId;
|
||||
|
||||
// /**
|
||||
// * 是否正确
|
||||
// */
|
||||
@TableField("is_right")
|
||||
private Boolean isRight;
|
||||
|
||||
// /**
|
||||
// * 选项图片
|
||||
// */
|
||||
private String image;
|
||||
|
||||
// /**
|
||||
// * 答案内容
|
||||
// */
|
||||
private String content;
|
||||
|
||||
|
||||
/**
|
||||
* 答案分析
|
||||
*/
|
||||
private String analysis;
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.yf.exam.modules.qu.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 试题题库实体类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
@Data
|
||||
@TableName("el_qu_repo")
|
||||
public class QuRepo extends Model<QuRepo> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
// /**
|
||||
// * 试题
|
||||
// */
|
||||
@TableField("qu_id")
|
||||
private String quId;
|
||||
|
||||
// /**
|
||||
// * 归属题库
|
||||
// */
|
||||
@TableField("repo_id")
|
||||
private String repoId;
|
||||
|
||||
// /**
|
||||
// * 题目类型
|
||||
// */
|
||||
@TableField("qu_type")
|
||||
private Integer quType;
|
||||
|
||||
// /**
|
||||
// * 排序
|
||||
// */
|
||||
private Integer sort;
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.yf.exam.modules.qu.enums;
|
||||
|
||||
|
||||
///**
|
||||
// * 题目类型
|
||||
// * @author bool
|
||||
// * @date 2019-10-30 13:11
|
||||
// */
|
||||
public interface QuType {
|
||||
|
||||
// /**
|
||||
// * 单选题
|
||||
// */
|
||||
Integer RADIO = 1;
|
||||
|
||||
// /**
|
||||
// * 多选题
|
||||
// */
|
||||
Integer MULTI = 2;
|
||||
|
||||
// /**
|
||||
// * 判断题
|
||||
// */
|
||||
Integer JUDGE = 3;
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.yf.exam.modules.qu.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yf.exam.modules.qu.entity.QuAnswer;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 候选答案Mapper
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuAnswerMapper extends BaseMapper<QuAnswer> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package com.yf.exam.modules.qu.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yf.exam.modules.qu.dto.QuDTO;
|
||||
import com.yf.exam.modules.qu.dto.export.QuExportDTO;
|
||||
import com.yf.exam.modules.qu.dto.request.QuQueryReqDTO;
|
||||
import com.yf.exam.modules.qu.entity.Qu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 问题题目Mapper
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuMapper extends BaseMapper<Qu> {
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 随机抽取题库的数据
|
||||
// * @param repoId
|
||||
// * @param quType
|
||||
// * @param level
|
||||
// * @param excludes 要排除的ID列表
|
||||
// * @param size
|
||||
// * @return
|
||||
// */
|
||||
List<Qu> listByRandom(@Param("repoId") String repoId,
|
||||
@Param("quType") Integer quType,
|
||||
@Param("excludes") List<String> excludes,
|
||||
@Param("size") Integer size);
|
||||
|
||||
// /**
|
||||
// * 查找导出列表
|
||||
// * @param query
|
||||
// * @return
|
||||
// */
|
||||
List<QuExportDTO> listForExport(@Param("query") QuQueryReqDTO query);
|
||||
|
||||
// /**
|
||||
// * 分页查找
|
||||
// * @param page
|
||||
// * @param query
|
||||
// * @return
|
||||
// */
|
||||
IPage<QuDTO> paging(Page page, @Param("query") QuQueryReqDTO query);
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.yf.exam.modules.qu.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yf.exam.modules.qu.entity.QuRepo;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 试题题库Mapper
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuRepoMapper extends BaseMapper<QuRepo> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.yf.exam.modules.qu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yf.exam.core.api.dto.PagingReqDTO;
|
||||
import com.yf.exam.modules.qu.dto.QuAnswerDTO;
|
||||
import com.yf.exam.modules.qu.entity.QuAnswer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 候选答案业务类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuAnswerService extends IService<QuAnswer> {
|
||||
|
||||
// /**
|
||||
// * 分页查询数据
|
||||
// * @param reqDTO
|
||||
// * @return
|
||||
// */
|
||||
IPage<QuAnswerDTO> paging(PagingReqDTO<QuAnswerDTO> reqDTO);
|
||||
//
|
||||
// /**
|
||||
// * 根据题目ID查询答案并随机
|
||||
// * @param quId
|
||||
// * @return
|
||||
// */
|
||||
List<QuAnswer> listAnswerByRandom(String quId);
|
||||
|
||||
// /**
|
||||
// * 根据问题查找答案
|
||||
// * @param quId
|
||||
// * @return
|
||||
// */
|
||||
List<QuAnswerDTO> listByQu(String quId);
|
||||
|
||||
// /**
|
||||
// * 保存试题
|
||||
// * @param quId
|
||||
// * @param list
|
||||
// */
|
||||
void saveAll(String quId, List<QuAnswerDTO> list);
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package com.yf.exam.modules.qu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yf.exam.core.api.dto.PagingReqDTO;
|
||||
import com.yf.exam.modules.qu.dto.QuRepoDTO;
|
||||
import com.yf.exam.modules.qu.dto.request.QuRepoBatchReqDTO;
|
||||
import com.yf.exam.modules.qu.entity.QuRepo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 试题题库业务类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuRepoService extends IService<QuRepo> {
|
||||
|
||||
// /**
|
||||
// * 分页查询数据
|
||||
// * @param reqDTO
|
||||
// * @return
|
||||
// */
|
||||
IPage<QuRepoDTO> paging(PagingReqDTO<QuRepoDTO> reqDTO);
|
||||
|
||||
// /**
|
||||
// * 保存全部列表
|
||||
// * @param quId
|
||||
// * @param quType
|
||||
// * @param ids
|
||||
// */
|
||||
void saveAll(String quId, Integer quType, List<String> ids);
|
||||
|
||||
// /**
|
||||
// * 根据问题查找题库
|
||||
// * @param quId
|
||||
// * @return
|
||||
// */
|
||||
List<String> listByQu(String quId);
|
||||
|
||||
// /**
|
||||
// * 根据题库查找题目ID列表
|
||||
// * @param repoId
|
||||
// * @param quType
|
||||
// * @param rand
|
||||
// * @return
|
||||
// */
|
||||
List<String> listByRepo(String repoId, Integer quType, boolean rand);
|
||||
|
||||
// /**
|
||||
// * 批量操作
|
||||
// * @param reqDTO
|
||||
// */
|
||||
void batchAction(QuRepoBatchReqDTO reqDTO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
package com.yf.exam.modules.qu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.yf.exam.core.api.dto.PagingReqDTO;
|
||||
import com.yf.exam.modules.qu.dto.QuDTO;
|
||||
import com.yf.exam.modules.qu.dto.export.QuExportDTO;
|
||||
import com.yf.exam.modules.qu.dto.ext.QuDetailDTO;
|
||||
import com.yf.exam.modules.qu.dto.request.QuQueryReqDTO;
|
||||
import com.yf.exam.modules.qu.entity.Qu;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 问题题目业务类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
public interface QuService extends IService<Qu> {
|
||||
|
||||
// /**
|
||||
// * 分页查询数据
|
||||
// * @param reqDTO
|
||||
// * @return
|
||||
// */
|
||||
IPage<QuDTO> paging(PagingReqDTO<QuQueryReqDTO> reqDTO);
|
||||
|
||||
// /**
|
||||
// * 删除试题
|
||||
// * @param ids
|
||||
// */
|
||||
void delete(List<String> ids);
|
||||
|
||||
// /**
|
||||
// * 随机抽取题库的数据
|
||||
// * @param repoId
|
||||
// * @param quType
|
||||
// * @param excludes 要排除的ID列表
|
||||
// * @param size
|
||||
// * @return
|
||||
// */
|
||||
List<Qu> listByRandom(String repoId,
|
||||
Integer quType,
|
||||
List<String> excludes,
|
||||
Integer size);
|
||||
|
||||
// /**
|
||||
// * 问题详情
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
QuDetailDTO detail(String id);
|
||||
|
||||
// /**
|
||||
// * 保存试题
|
||||
// * @param reqDTO
|
||||
// */
|
||||
void save(QuDetailDTO reqDTO);
|
||||
|
||||
// /**
|
||||
// * 查找导出列表
|
||||
// * @param query
|
||||
// * @return
|
||||
// */
|
||||
List<QuExportDTO> listForExport(QuQueryReqDTO query);
|
||||
|
||||
// /**
|
||||
// * 导入Excel
|
||||
// * @param dtoList
|
||||
// * @return
|
||||
// */
|
||||
int importExcel(List<QuExportDTO> dtoList);
|
||||
}
|
||||
@ -0,0 +1,144 @@
|
||||
package com.yf.exam.modules.qu.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yf.exam.core.api.dto.PagingReqDTO;
|
||||
import com.yf.exam.core.utils.BeanMapper;
|
||||
import com.yf.exam.modules.qu.dto.QuAnswerDTO;
|
||||
import com.yf.exam.modules.qu.entity.QuAnswer;
|
||||
import com.yf.exam.modules.qu.mapper.QuAnswerMapper;
|
||||
import com.yf.exam.modules.qu.service.QuAnswerService;
|
||||
import com.yf.exam.modules.qu.utils.ImageCheckUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 语言设置 服务实现类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
@Service
|
||||
public class QuAnswerServiceImpl extends ServiceImpl<QuAnswerMapper, QuAnswer> implements QuAnswerService {
|
||||
|
||||
@Autowired
|
||||
private ImageCheckUtils imageCheckUtils;
|
||||
|
||||
@Override
|
||||
public IPage<QuAnswerDTO> paging(PagingReqDTO<QuAnswerDTO> reqDTO) {
|
||||
|
||||
//创建分页对象
|
||||
IPage<QuAnswer> query = new Page<>(reqDTO.getCurrent(), reqDTO.getSize());
|
||||
|
||||
//查询条件
|
||||
QueryWrapper<QuAnswer> wrapper = new QueryWrapper<>();
|
||||
|
||||
//获得数据
|
||||
IPage<QuAnswer> page = this.page(query, wrapper);
|
||||
//转换结果
|
||||
IPage<QuAnswerDTO> pageData = JSON.parseObject(JSON.toJSONString(page), new TypeReference<Page<QuAnswerDTO>>(){});
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuAnswer> listAnswerByRandom(String quId) {
|
||||
QueryWrapper<QuAnswer> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuAnswer::getQuId, quId);
|
||||
wrapper.last(" ORDER BY RAND() ");
|
||||
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuAnswerDTO> listByQu(String quId) {
|
||||
QueryWrapper<QuAnswer> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuAnswer::getQuId, quId);
|
||||
|
||||
List<QuAnswer> list = this.list(wrapper);
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
return BeanMapper.mapList(list, QuAnswerDTO.class);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 查找已存在的列表
|
||||
// * @param quId
|
||||
// * @return
|
||||
// */
|
||||
public List<String> findExistsList(String quId) {
|
||||
//返回结果
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
QueryWrapper<QuAnswer> wrapper = new QueryWrapper();
|
||||
wrapper.lambda().eq(QuAnswer::getQuId, quId);
|
||||
List<QuAnswer> list = this.list(wrapper);
|
||||
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
for (QuAnswer item : list) {
|
||||
ids.add(item.getId());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAll(String quId, List<QuAnswerDTO> list) {
|
||||
|
||||
//最终要保存的列表
|
||||
List<QuAnswer> saveList = new ArrayList<>();
|
||||
|
||||
//已存在的标签列表
|
||||
List<String> ids = this.findExistsList(quId);
|
||||
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
for(QuAnswerDTO item: list){
|
||||
|
||||
// 校验图片地址
|
||||
imageCheckUtils.checkImage(item.getImage(), "选项图片地址错误!");
|
||||
|
||||
//标签ID
|
||||
String id = item.getId();
|
||||
QuAnswer answer = new QuAnswer();
|
||||
BeanMapper.copy(item, answer);
|
||||
answer.setQuId(quId);
|
||||
|
||||
//补全ID避免新增
|
||||
if(ids.contains(id)){
|
||||
ids.remove(id);
|
||||
}
|
||||
|
||||
saveList.add(answer);
|
||||
}
|
||||
|
||||
//保存标签列表
|
||||
if(!CollectionUtils.isEmpty(saveList)) {
|
||||
this.saveOrUpdateBatch(saveList);
|
||||
}
|
||||
|
||||
//删除已移除
|
||||
if(!ids.isEmpty()){
|
||||
this.removeByIds(ids);
|
||||
}
|
||||
}else{
|
||||
|
||||
QueryWrapper<QuAnswer> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuAnswer::getQuId, quId);
|
||||
this.remove(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,175 @@
|
||||
package com.yf.exam.modules.qu.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yf.exam.core.api.dto.PagingReqDTO;
|
||||
import com.yf.exam.modules.qu.dto.QuRepoDTO;
|
||||
import com.yf.exam.modules.qu.dto.request.QuRepoBatchReqDTO;
|
||||
import com.yf.exam.modules.qu.entity.Qu;
|
||||
import com.yf.exam.modules.qu.entity.QuRepo;
|
||||
import com.yf.exam.modules.qu.mapper.QuMapper;
|
||||
import com.yf.exam.modules.qu.mapper.QuRepoMapper;
|
||||
import com.yf.exam.modules.qu.service.QuRepoService;
|
||||
import com.yf.exam.modules.repo.service.RepoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
///**
|
||||
//* <p>
|
||||
//* 语言设置 服务实现类
|
||||
//* </p>
|
||||
//*
|
||||
//* @author 聪明笨狗
|
||||
//* @since 2020-05-25 13:23
|
||||
//*/
|
||||
@Service
|
||||
public class QuRepoServiceImpl extends ServiceImpl<QuRepoMapper, QuRepo> implements QuRepoService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private QuMapper quMapper;
|
||||
|
||||
@Autowired
|
||||
private RepoService repoService;
|
||||
|
||||
@Override
|
||||
public IPage<QuRepoDTO> paging(PagingReqDTO<QuRepoDTO> reqDTO) {
|
||||
|
||||
//创建分页对象
|
||||
IPage<QuRepo> query = new Page<>(reqDTO.getCurrent(), reqDTO.getSize());
|
||||
|
||||
//查询条件
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
|
||||
//获得数据
|
||||
IPage<QuRepo> page = this.page(query, wrapper);
|
||||
//转换结果
|
||||
IPage<QuRepoDTO> pageData = JSON.parseObject(JSON.toJSONString(page), new TypeReference<Page<QuRepoDTO>>(){});
|
||||
return pageData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAll(String quId, Integer quType, List<String> ids) {
|
||||
// 先删除
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuRepo::getQuId, quId);
|
||||
this.remove(wrapper);
|
||||
|
||||
// 保存全部
|
||||
if(!CollectionUtils.isEmpty(ids)){
|
||||
List<QuRepo> list = new ArrayList<>();
|
||||
for(String id: ids){
|
||||
QuRepo ref = new QuRepo();
|
||||
ref.setQuId(quId);
|
||||
ref.setRepoId(id);
|
||||
ref.setQuType(quType);
|
||||
list.add(ref);
|
||||
}
|
||||
this.saveBatch(list);
|
||||
|
||||
|
||||
for(String id: ids){
|
||||
this.sortRepo(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listByQu(String quId) {
|
||||
// 先删除
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuRepo::getQuId, quId);
|
||||
List<QuRepo> list = this.list(wrapper);
|
||||
List<String> ids = new ArrayList<>();
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
for(QuRepo item: list){
|
||||
ids.add(item.getRepoId());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listByRepo(String repoId, Integer quType, boolean rand) {
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.eq(QuRepo::getRepoId, repoId);
|
||||
|
||||
if(quType!=null){
|
||||
wrapper.lambda().eq(QuRepo::getQuType, quType);
|
||||
}
|
||||
|
||||
if(rand){
|
||||
wrapper.orderByAsc(" RAND() ");
|
||||
}else{
|
||||
wrapper.lambda().orderByAsc(QuRepo::getSort);
|
||||
}
|
||||
|
||||
List<QuRepo> list = this.list(wrapper);
|
||||
List<String> ids = new ArrayList<>();
|
||||
if(!CollectionUtils.isEmpty(list)){
|
||||
for(QuRepo item: list){
|
||||
ids.add(item.getQuId());
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchAction(QuRepoBatchReqDTO reqDTO) {
|
||||
|
||||
// 移除的
|
||||
if(reqDTO.getRemove()!=null && reqDTO.getRemove()){
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.in(QuRepo::getRepoId, reqDTO.getRepoIds())
|
||||
.in(QuRepo::getQuId, reqDTO.getQuIds());
|
||||
this.remove(wrapper);
|
||||
}else{
|
||||
|
||||
// 新增的
|
||||
for(String quId : reqDTO.getQuIds()){
|
||||
Qu q = quMapper.selectById(quId);
|
||||
this.saveAll(quId, q.getQuType(), reqDTO.getRepoIds());
|
||||
}
|
||||
}
|
||||
|
||||
for(String id: reqDTO.getRepoIds()){
|
||||
this.sortRepo(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 单个题库进行排序
|
||||
// * @param repoId
|
||||
// */
|
||||
private void sortRepo(String repoId){
|
||||
|
||||
QueryWrapper<QuRepo> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda().eq(QuRepo::getRepoId, repoId);
|
||||
|
||||
List<QuRepo> list = this.list(wrapper);
|
||||
if(CollectionUtils.isEmpty(list)){
|
||||
return;
|
||||
}
|
||||
|
||||
int sort = 1;
|
||||
for(QuRepo item: list){
|
||||
item.setSort(sort);
|
||||
sort++;
|
||||
}
|
||||
this.updateBatchById(list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
package com.yf.exam.modules.qu.utils;
|
||||
|
||||
import com.yf.exam.ability.upload.config.UploadConfig;
|
||||
import com.yf.exam.core.exception.ServiceException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ImageCheckUtils {
|
||||
|
||||
@Autowired
|
||||
private UploadConfig conf;
|
||||
|
||||
// /**
|
||||
// * 进行图片校验!
|
||||
// * @param image
|
||||
// * @param throwMsg
|
||||
// */
|
||||
public void checkImage(String image, String throwMsg) {
|
||||
|
||||
if(StringUtils.isBlank(image)){
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验图片地址
|
||||
if(!image.startsWith(conf.getUrl())){
|
||||
throw new ServiceException(throwMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue