fix: [临时提交]
This commit is contained in:
parent
e01fe45e8b
commit
a3decaedb4
|
@ -0,0 +1,68 @@
|
|||
package com.guwan.backend.model.exam.controller;
|
||||
|
||||
|
||||
import com.guwan.backend.core.api.ApiRest;
|
||||
import com.guwan.backend.core.api.controller.BaseController;
|
||||
import com.guwan.backend.core.api.dto.BaseIdReqDTO;
|
||||
import com.guwan.backend.core.api.dto.BaseIdRespDTO;
|
||||
|
||||
import com.guwan.backend.model.exam.dto.PaperCreateReqDTO;
|
||||
import com.guwan.backend.model.exam.service.PaperService;
|
||||
import com.guwan.backend.security.CustomUserDetails;
|
||||
import com.guwan.backend.util.JwtUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 试卷控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 聪明笨狗
|
||||
* @since 2020-05-25 16:33
|
||||
*/
|
||||
@Api(tags={"试卷"})
|
||||
@RestController
|
||||
@RequestMapping("/exam/api/paper/paper")
|
||||
public class PaperController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private PaperService baseService;
|
||||
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建试卷
|
||||
* @param reqDTO
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "创建试卷")
|
||||
@PostMapping(value = "/create-paper")
|
||||
public ApiRest<BaseIdRespDTO> save(@RequestBody PaperCreateReqDTO reqDTO) {
|
||||
|
||||
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails userDetails) {
|
||||
// sysLog.setUserId(userDetails.getUserId());
|
||||
// sysLog.setUsername(userDetails.getUsername());
|
||||
}
|
||||
|
||||
|
||||
//复制参数
|
||||
// String paperId = baseService.createPaper(UserUtils.getUserId(), reqDTO.getExamId());
|
||||
String paperId = baseService.createPaper("111",
|
||||
reqDTO.getExamId());
|
||||
|
||||
return super.success(new BaseIdRespDTO(paperId));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.guwan.backend.model.exam.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author bool
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value="试卷创建请求类", description="试卷创建请求类")
|
||||
public class PaperCreateReqDTO {
|
||||
|
||||
@JsonIgnore
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty(value = "考试ID", required=true)
|
||||
private String examId;
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package com.guwan.backend.model.exam.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 17:31
|
||||
*/
|
||||
@Data
|
||||
@TableName("el_paper")
|
||||
public class Paper extends Model<Paper> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 试卷ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
@TableField("depart_id")
|
||||
private String departId;
|
||||
|
||||
/**
|
||||
* 规则ID
|
||||
*/
|
||||
@TableField("exam_id")
|
||||
private String examId;
|
||||
|
||||
/**
|
||||
* 考试标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 考试时长
|
||||
*/
|
||||
@TableField("total_time")
|
||||
private Integer totalTime;
|
||||
|
||||
/**
|
||||
* 用户时长
|
||||
*/
|
||||
@TableField("user_time")
|
||||
private Integer userTime;
|
||||
|
||||
/**
|
||||
* 试卷总分
|
||||
*/
|
||||
@TableField("total_score")
|
||||
private Integer totalScore;
|
||||
|
||||
/**
|
||||
* 及格分
|
||||
*/
|
||||
@TableField("qualify_score")
|
||||
private Integer qualifyScore;
|
||||
|
||||
/**
|
||||
* 客观分
|
||||
*/
|
||||
@TableField("obj_score")
|
||||
private Integer objScore;
|
||||
|
||||
/**
|
||||
* 主观分
|
||||
*/
|
||||
@TableField("subj_score")
|
||||
private Integer subjScore;
|
||||
|
||||
/**
|
||||
* 用户得分
|
||||
*/
|
||||
@TableField("user_score")
|
||||
private Integer userScore;
|
||||
|
||||
/**
|
||||
* 是否包含简答题
|
||||
*/
|
||||
@TableField("has_saq")
|
||||
private Boolean hasSaq;
|
||||
|
||||
/**
|
||||
* 试卷状态
|
||||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 截止时间
|
||||
*/
|
||||
@TableField("limit_time")
|
||||
private Date limitTime;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.guwan.backend.model.exam.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import com.guwan.backend.model.exam.entity.Paper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 试卷Mapper
|
||||
* </p>
|
||||
*
|
||||
* @author 聪明笨狗
|
||||
* @since 2020-05-25 16:33
|
||||
*/
|
||||
public interface PaperMapper extends BaseMapper<Paper> {
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.guwan.backend.model.exam.service;
|
||||
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import com.guwan.backend.model.exam.entity.Paper;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 试卷业务类
|
||||
* </p>
|
||||
*
|
||||
* @author 聪明笨狗
|
||||
* @since 2020-05-25 16:33
|
||||
*/
|
||||
public interface PaperService extends IService<Paper> {
|
||||
|
||||
/**
|
||||
* 创建试卷
|
||||
* @param userId
|
||||
* @param examId
|
||||
* @return
|
||||
*/
|
||||
String createPaper(String userId, String examId);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.guwan.backend.model.exam.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.core.BeanMapper;
|
||||
import com.guwan.backend.core.api.ApiError;
|
||||
import com.guwan.backend.core.api.dto.PagingReqDTO;
|
||||
import com.guwan.backend.core.exception.ServiceException;
|
||||
import com.guwan.backend.model.exam.dto.ExamDTO;
|
||||
import com.guwan.backend.model.exam.entity.Paper;
|
||||
import com.guwan.backend.model.exam.enums.ExamState;
|
||||
import com.guwan.backend.model.exam.mapper.PaperMapper;
|
||||
import com.guwan.backend.model.exam.service.ExamRepoService;
|
||||
import com.guwan.backend.model.exam.service.ExamService;
|
||||
import com.guwan.backend.model.exam.service.PaperService;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 语言设置 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 聪明笨狗
|
||||
* @since 2020-05-25 16:33
|
||||
*/
|
||||
@Service
|
||||
public class PaperServiceImpl extends ServiceImpl<PaperMapper, Paper> implements PaperService {
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private ExamService examService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 展示的选项,ABC这样
|
||||
*/
|
||||
private static List<String> ABC = Arrays.asList(new String[]{
|
||||
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K","L","M","N","O","P","Q","R","S","T","U","V","W","X"
|
||||
,"Y","Z"
|
||||
});
|
||||
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public String createPaper(String userId, String examId) {
|
||||
|
||||
// 校验是否有正在考试的试卷
|
||||
/* QueryWrapper<Paper> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.eq(Paper::getUserId, userId)
|
||||
.eq(Paper::getState, PaperState.ING);
|
||||
|
||||
long exists = this.count(wrapper);
|
||||
|
||||
|
||||
if (exists > 0) {
|
||||
throw new ServiceException(ApiError.ERROR_20010002);
|
||||
}*/
|
||||
|
||||
// 查找考试
|
||||
ExamDTO exam = examService.findById(examId);
|
||||
|
||||
if(exam == null){
|
||||
throw new ServiceException(1, "考试不存在!");
|
||||
}
|
||||
|
||||
if(!ExamState.ENABLE.equals(exam.getState())){
|
||||
throw new ServiceException(1, "考试状态不正确!");
|
||||
}
|
||||
|
||||
// 考试题目列表
|
||||
/* List<PaperQu> quList = this.generateByRepo(examId);
|
||||
|
||||
if(CollectionUtils.isEmpty(quList)){
|
||||
throw new ServiceException(1, "规则不正确,无对应的考题!");
|
||||
}
|
||||
|
||||
//保存试卷内容
|
||||
Paper paper = this.savePaper(userId, exam, quList);*/
|
||||
|
||||
|
||||
|
||||
// return paper.getId();
|
||||
|
||||
return "1";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue