From a3decaedb46fc6cf97843606df8a067331dc179d Mon Sep 17 00:00:00 2001 From: ovo Date: Tue, 15 Apr 2025 23:50:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exam/controller/PaperController.java | 68 ++++++++++ .../model/exam/dto/PaperCreateReqDTO.java | 21 +++ .../backend/model/exam/entity/Paper.java | 125 ++++++++++++++++++ .../model/exam/mapper/PaperMapper.java | 23 ++++ .../model/exam/service/PaperService.java | 33 +++++ .../exam/service/impl/PaperServiceImpl.java | 104 +++++++++++++++ 6 files changed, 374 insertions(+) create mode 100644 src/main/java/com/guwan/backend/model/exam/controller/PaperController.java create mode 100644 src/main/java/com/guwan/backend/model/exam/dto/PaperCreateReqDTO.java create mode 100644 src/main/java/com/guwan/backend/model/exam/entity/Paper.java create mode 100644 src/main/java/com/guwan/backend/model/exam/mapper/PaperMapper.java create mode 100644 src/main/java/com/guwan/backend/model/exam/service/PaperService.java create mode 100644 src/main/java/com/guwan/backend/model/exam/service/impl/PaperServiceImpl.java diff --git a/src/main/java/com/guwan/backend/model/exam/controller/PaperController.java b/src/main/java/com/guwan/backend/model/exam/controller/PaperController.java new file mode 100644 index 0000000..e6b56e3 --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/controller/PaperController.java @@ -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.*; + +/** +*

+* 试卷控制器 +*

+* +* @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 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)); + } + + +} diff --git a/src/main/java/com/guwan/backend/model/exam/dto/PaperCreateReqDTO.java b/src/main/java/com/guwan/backend/model/exam/dto/PaperCreateReqDTO.java new file mode 100644 index 0000000..6982cb5 --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/dto/PaperCreateReqDTO.java @@ -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; + +} diff --git a/src/main/java/com/guwan/backend/model/exam/entity/Paper.java b/src/main/java/com/guwan/backend/model/exam/entity/Paper.java new file mode 100644 index 0000000..bf2d7f9 --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/entity/Paper.java @@ -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; + +/** +*

+* 试卷实体类 +*

+* +* @author 聪明笨狗 +* @since 2020-05-25 17:31 +*/ +@Data +@TableName("el_paper") +public class Paper extends Model { + + 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; +} diff --git a/src/main/java/com/guwan/backend/model/exam/mapper/PaperMapper.java b/src/main/java/com/guwan/backend/model/exam/mapper/PaperMapper.java new file mode 100644 index 0000000..449a7ea --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/mapper/PaperMapper.java @@ -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; + +/** +*

+* 试卷Mapper +*

+* +* @author 聪明笨狗 +* @since 2020-05-25 16:33 +*/ +public interface PaperMapper extends BaseMapper { + + +} diff --git a/src/main/java/com/guwan/backend/model/exam/service/PaperService.java b/src/main/java/com/guwan/backend/model/exam/service/PaperService.java new file mode 100644 index 0000000..3ab28c9 --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/service/PaperService.java @@ -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; + + +/** +*

+* 试卷业务类 +*

+* +* @author 聪明笨狗 +* @since 2020-05-25 16:33 +*/ +public interface PaperService extends IService { + + /** + * 创建试卷 + * @param userId + * @param examId + * @return + */ + String createPaper(String userId, String examId); + + + + + + +} diff --git a/src/main/java/com/guwan/backend/model/exam/service/impl/PaperServiceImpl.java b/src/main/java/com/guwan/backend/model/exam/service/impl/PaperServiceImpl.java new file mode 100644 index 0000000..fa25a55 --- /dev/null +++ b/src/main/java/com/guwan/backend/model/exam/service/impl/PaperServiceImpl.java @@ -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; + +/** +*

+* 语言设置 服务实现类 +*

+* +* @author 聪明笨狗 +* @since 2020-05-25 16:33 +*/ +@Service +public class PaperServiceImpl extends ServiceImpl implements PaperService { + + + + @Autowired + private ExamService examService; + + + + + + /** + * 展示的选项,ABC这样 + */ + private static List 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 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 quList = this.generateByRepo(examId); + + if(CollectionUtils.isEmpty(quList)){ + throw new ServiceException(1, "规则不正确,无对应的考题!"); + } + + //保存试卷内容 + Paper paper = this.savePaper(userId, exam, quList);*/ + + + + // return paper.getId(); + + return "1"; + } + + + + +}