| | |
| | | import org.springframework.web.bind.annotation.ControllerAdvice; |
| | | import org.springframework.web.bind.annotation.ExceptionHandler; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.List; |
| | |
| | | * Copyright (C), 2020-2024, 武汉思维跳跃科技有限公司 |
| | | * @date 2021/12/25 9:45 |
| | | */ |
| | | @ControllerAdvice |
| | | @RestControllerAdvice |
| | | public class ExceptionHandle { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class); |
| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | //@RestController |
| | | public class ErrorController extends BasicErrorController { |
| | | |
| | | private static final String PATH = "/error"; |
| | |
| | | package com.ycl.jxkg.controller.admin; |
| | | |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.group.Update; |
| | | import com.ycl.jxkg.group.Add; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import javax.validation.constraints.NotEmpty; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import com.ycl.jxkg.service.ExamTemplateService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.form.ExamTemplateForm; |
| | | import com.ycl.jxkg.domain.query.ExamTemplateQuery; |
| | | import com.ycl.jxkg.group.Add; |
| | | import com.ycl.jxkg.group.Update; |
| | | import com.ycl.jxkg.service.ExamTemplateService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.util.List; |
| | | import static com.ycl.jxkg.enums.DeductTypeEnum.EachCorrect; |
| | | import static com.ycl.jxkg.enums.DeductTypeEnum.PartCorrect; |
| | | |
| | | /** |
| | | * 随机试卷模板 前端控制器 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Validated |
| | | @RequiredArgsConstructor |
| | | @Api(value = "随机试卷模板", tags = "随机试卷模板管理") |
| | | @RestController |
| | | @RequestMapping("/exam-template") |
| | | @RequestMapping("/api/admin/exam-template") |
| | | public class ExamTemplateController { |
| | | |
| | | private final ExamTemplateService examTemplateService; |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加", notes = "添加") |
| | | @PreAuthorize("hasAuthority('examTemplate:add')") |
| | | public Result add(@RequestBody @Validated(Add.class) ExamTemplateForm form) { |
| | | //参数校验 |
| | | if(form.getDeductType()!=null && (form.getDeductType() ==PartCorrect.getCode() || form.getDeductType() == EachCorrect.getCode()) && (form.getDeductTypeScore() ==null || form.getDeductTypeScore().compareTo(BigDecimal.ZERO) <= 0)){ |
| | | return Result.fail(SystemCode.ParameterValidError.getCode(),"多选评分不能为0或空"); |
| | | } |
| | | return examTemplateService.add(form); |
| | | } |
| | | |
| | | @PutMapping |
| | | @ApiOperation(value = "修改", notes = "修改") |
| | | @PreAuthorize("hasAuthority('examTemplate:edit')") |
| | | public Result update(@RequestBody @Validated(Update.class) ExamTemplateForm form) { |
| | | return examTemplateService.update(form); |
| | | } |
| | | |
| | | @DeleteMapping("/{id}") |
| | | @ApiOperation(value = "ID删除", notes = "ID删除") |
| | | @PreAuthorize("hasAuthority('examTemplate:del')") |
| | | public Result removeById(@PathVariable("id") String id) { |
| | | return examTemplateService.removeById(id); |
| | | } |
| | | |
| | | @DeleteMapping("/batch") |
| | | @ApiOperation(value = "批量删除", notes = "批量删除") |
| | | @PreAuthorize("hasAuthority('examTemplate:del:batch')") |
| | | public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List<String> ids) { |
| | | return examTemplateService.remove(ids); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "分页", notes = "分页") |
| | | @PreAuthorize("hasAuthority('examTemplate:page')") |
| | | public Result page(ExamTemplateQuery query) { |
| | | return examTemplateService.page(query); |
| | | } |
| | | |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "详情", notes = "详情") |
| | | @PreAuthorize("hasAuthority('examTemplate:detail')") |
| | | public Result detail(@PathVariable("id") Integer id) { |
| | | return examTemplateService.detail(id); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @PreAuthorize("hasAuthority('examTemplate:list')") |
| | | @ApiOperation(value = "列表", notes = "列表") |
| | | public Result list() { |
| | | return examTemplateService.all(); |
| | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.ycl.jxkg.domain.base.AbsEntity; |
| | | import io.swagger.models.auth.In; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 随机试卷模板表 |
| | | * */ |
| | | * 随机试卷模板 |
| | | * |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Data |
| | | @TableName("t_exam_template") |
| | | public class ExamTemplate extends AbsEntity { |
| | | /** |
| | | * 试卷id |
| | | * */ |
| | | @TableField("exam_paper_id") |
| | | private Integer examPaperId; |
| | | |
| | | /** |
| | | * 单选题数量 |
| | | * */ |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @TableField("name") |
| | | /** 模板名 */ |
| | | private String name; |
| | | |
| | | @TableField("subject_id") |
| | | /** 学科id */ |
| | | private Integer subjectId; |
| | | |
| | | @TableField("score") |
| | | /** 总分 */ |
| | | private BigDecimal score; |
| | | |
| | | @TableField("visibility") |
| | | /** 是否私有 */ |
| | | private String visibility; |
| | | |
| | | @TableField("suggest_time") |
| | | /** 建议时间 */ |
| | | private Integer suggestTime; |
| | | |
| | | @TableField("deduct_type") |
| | | /** 多选扣分类型 */ |
| | | private Integer deductType; |
| | | |
| | | @TableField("deduct_type_score") |
| | | private BigDecimal deductTypeScore; |
| | | |
| | | @TableField("single_choice") |
| | | /** 单选题数量 */ |
| | | private Integer singleChoice; |
| | | |
| | | /** |
| | | * 多选题数量 |
| | | * */ |
| | | @TableField("multiple_choice") |
| | | /** 多选题数量 */ |
| | | private Integer multipleChoice; |
| | | |
| | | /** |
| | | * 填空题数量 |
| | | * */ |
| | | @TableField("gap_filling") |
| | | /** 填空题数量 */ |
| | | private Integer gapFilling; |
| | | |
| | | /** |
| | | * 判断题数量 |
| | | * */ |
| | | @TableField("true_false") |
| | | /** 判断数量 */ |
| | | private Integer trueFalse; |
| | | |
| | | /** |
| | | * 简答题数量 |
| | | * */ |
| | | @TableField("short_answer") |
| | | /** 简答题数量 */ |
| | | private Integer shortAnswer; |
| | | |
| | | /** |
| | | * 计算题数量 |
| | | * */ |
| | | @TableField("calculation") |
| | | /** 计算题数量 */ |
| | | private Integer calculation; |
| | | |
| | | /** 单选每题分数 */ |
| | | @TableField("single_score") |
| | | /** 单选每题分数 */ |
| | | private BigDecimal singleScore; |
| | | |
| | | /** 多选每题分数 */ |
| | | @TableField("multiple_score") |
| | | /** 多选每题分数 */ |
| | | private BigDecimal multipleScore; |
| | | |
| | | /** 填空每题分数 */ |
| | | @TableField("gap_score") |
| | | /** 填空每题分数 */ |
| | | private BigDecimal gapScore; |
| | | |
| | | @TableField("true_false_score") |
| | | /** 判断每题分数 */ |
| | | @TableField("trueFalse_score") |
| | | private BigDecimal trueFalseScore; |
| | | |
| | | @TableField("short_answer_score") |
| | | /** 简答每题分数 */ |
| | | @TableField("shortAnswer_score") |
| | | private BigDecimal shortAnswerScore; |
| | | |
| | | @TableField("calculation__score") |
| | | /** 计算每题分数 */ |
| | | @TableField("calculation_score") |
| | | private BigDecimal calculationScore; |
| | | |
| | | @TableField("create_user") |
| | | /** */ |
| | | private Integer createUser; |
| | | |
| | | @TableField("create_time") |
| | | /** */ |
| | | private Date createTime; |
| | | } |
| | |
| | | |
| | | import com.ycl.jxkg.domain.base.AbsForm; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.ycl.jxkg.domain.question.TemplateQuestionDTO; |
| | | import com.ycl.jxkg.group.Add; |
| | | import com.ycl.jxkg.group.Update; |
| | | import io.swagger.annotations.ApiModel; |
| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.lang.NonNull; |
| | | |
| | | import javax.validation.constraints.Min; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 随机试卷模板表单 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "ExamTemplate表单", description = "随机试卷模板表单") |
| | | public class ExamTemplateForm extends AbsForm { |
| | | |
| | | @NotBlank(message = "模板名称不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("模板名称") |
| | | @NotBlank(message = "模板名不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("模板名") |
| | | private String name; |
| | | |
| | | @NotNull(message = "试卷科目不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("试卷科目") |
| | | @NotNull(message = "学科id不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("学科id") |
| | | private Integer subjectId; |
| | | |
| | | @NotNull(message = "考试时长(分钟)不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("考试时长(分钟)") |
| | | @ApiModelProperty("总分") |
| | | private BigDecimal score; |
| | | |
| | | @ApiModelProperty("是否私有") |
| | | private String visibility; |
| | | |
| | | @Min(value = 1,message = "建议时间必须大于0",groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("建议时间") |
| | | private Integer suggestTime; |
| | | |
| | | @NotNull(message = "单选题数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("单选题数量") |
| | | private Integer singleChoice; |
| | | @ApiModelProperty("多选扣分类型") |
| | | private Integer deductType; |
| | | |
| | | @NotNull(message = "多选题数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("多选题数量") |
| | | private Integer multipleChoice; |
| | | @ApiModelProperty("多选扣分") |
| | | private BigDecimal deductTypeScore; |
| | | |
| | | @NotNull(message = "填空题数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("填空题数量") |
| | | private Integer gapFilling; |
| | | |
| | | @NotNull(message = "判断数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("判断数量") |
| | | private Integer trueFalse; |
| | | |
| | | @NotNull(message = "简答题数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("简答题数量") |
| | | private Integer shortAnswer; |
| | | |
| | | @NotNull(message = "计算题数量不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("计算题数量") |
| | | private Integer calculation; |
| | | |
| | | @NotNull(message = "试卷总分不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("试卷总分") |
| | | private Integer score; |
| | | |
| | | @NotBlank(message = "多选题扣分方式不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("多选题扣分方式") |
| | | private String deductType; |
| | | |
| | | @NotNull(message = "创建人不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("创建人") |
| | | private Integer createUser; |
| | | |
| | | @NotNull(message = "创建时间不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("创建时间") |
| | | private LocalDateTime createTime; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal singleScore; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal multipleScore; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal gapScore; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal trueFalseScore; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal shortAnswerScore; |
| | | |
| | | @NotNull(message = "不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("") |
| | | private BigDecimal calculationScore; |
| | | @ApiModelProperty("题目模板") |
| | | private List<TemplateQuestionDTO> questionList; |
| | | |
| | | public static ExamTemplate getEntityByForm(@NonNull ExamTemplateForm form, ExamTemplate entity) { |
| | | if(entity == null) { |
| | |
| | | package com.ycl.jxkg.domain.query; |
| | | |
| | | import com.ycl.jxkg.domain.base.AbsQuery; |
| | | import java.util.List; |
| | | import org.springframework.lang.NonNull; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 随机试卷模板查询 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "ExamTemplate查询", description = "随机试卷模板查询") |
| | | public class ExamTemplateQuery extends AbsQuery { |
| | | private String name; |
| | | private Integer subjectId; |
| | | } |
| | | |
New file |
| | |
| | | package com.ycl.jxkg.domain.question; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | @Data |
| | | public class TemplateQuestionDTO { |
| | | private Integer questionType; |
| | | private Integer num; |
| | | private BigDecimal score; |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.domain.vo; |
| | | |
| | | import com.ycl.jxkg.domain.base.AbsVo; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import org.springframework.lang.NonNull; |
| | | import org.springframework.beans.BeanUtils; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 随机试卷模板展示 |
| | | * |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Data |
| | | public class ExamTemplateVO extends AbsVo { |
| | | |
| | | /** 模板名 */ |
| | | private String name; |
| | | |
| | | /** 学科id */ |
| | | private Integer subjectId; |
| | | |
| | | /** 总分 */ |
| | | private Integer score; |
| | | |
| | | /** 是否私有 */ |
| | | private String visibility; |
| | | |
| | | /** 建议时间 */ |
| | | private Integer suggestTime; |
| | | |
| | | /** 多选扣分类型 */ |
| | | private Integer deductType; |
| | | |
| | | /** 多选评分 */ |
| | | private BigDecimal deductTypeScore; |
| | | |
| | | /** 单选题数量 */ |
| | | private Integer singleChoice; |
| | | |
| | | /** 多选题数量 */ |
| | | private Integer multipleChoice; |
| | | |
| | | /** 填空题数量 */ |
| | | private Integer gapFilling; |
| | | |
| | | /** 判断数量 */ |
| | | private Integer trueFalse; |
| | | |
| | | /** 简答题数量 */ |
| | | private Integer shortAnswer; |
| | | |
| | | /** 计算题数量 */ |
| | | private Integer calculation; |
| | | |
| | | /** 单选每题分数 */ |
| | | private BigDecimal singleScore; |
| | | |
| | | /** 多选每题分数 */ |
| | | private BigDecimal multipleScore; |
| | | |
| | | /** 填空每题分数 */ |
| | | private BigDecimal gapScore; |
| | | |
| | | /** 判断每题分数 */ |
| | | private BigDecimal trueFalseScore; |
| | | |
| | | /** 简答每题分数 */ |
| | | private BigDecimal shortAnswerScore; |
| | | |
| | | /** 计算每题分数 */ |
| | | private BigDecimal calculationScore; |
| | | |
| | | /** */ |
| | | private Integer createUser; |
| | | |
| | | /** */ |
| | | private Date createTime; |
| | | |
| | | public static ExamTemplateVO getVoByEntity(@NonNull ExamTemplate entity, ExamTemplateVO vo) { |
| | | if(vo == null) { |
| | | vo = new ExamTemplateVO(); |
| | | } |
| | | BeanUtils.copyProperties(entity, vo); |
| | | return vo; |
| | | } |
| | | |
| | | } |
| | |
| | | public enum DeductTypeEnum { |
| | | |
| | | AllCorrect(1, "答错不得分"), |
| | | PartCorrect(2, "漏选得固定分值,包含错误选项不得分"), |
| | | EachCorrect(3, "每对一题得相应分值,包含错误选项不得分"); |
| | | PartCorrect(2, "漏选得固定分值,包含错误选项不得分"), |
| | | EachCorrect(3, "每对一题得相应分值,包含错误选项不得分"); |
| | | |
| | | int code; |
| | | String name; |
| | |
| | | import java.util.Map; |
| | | |
| | | public enum VisibilityEnum { |
| | | Private("私有", "只有老师自己能看"), |
| | | Public("公开", "所有人能看"); |
| | | |
| | | Private(1,"PRIVATE", "只有老师自己能看"), |
| | | Public(2,"PUBLIC", "所有人能看"); |
| | | Integer code; |
| | | String name; |
| | | String description; |
| | | |
| | | VisibilityEnum(String name, String description) { |
| | | VisibilityEnum(Integer code,String name, String description) { |
| | | this.code = code; |
| | | this.name = name; |
| | | this.description = description; |
| | | } |
| | |
| | | this.name = name; |
| | | } |
| | | |
| | | public Integer getCode() { |
| | | return code; |
| | | } |
| | | |
| | | private static Map<String, VisibilityEnum> keyMap = new HashMap<>(); |
| | | public void setCode(Integer code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | private static final Map<Integer, VisibilityEnum> keyMap = new HashMap<>(); |
| | | |
| | | static { |
| | | for (VisibilityEnum item : VisibilityEnum.values()) { |
| | | keyMap.put(item.getName(), item); |
| | | keyMap.put(item.getCode(), item); |
| | | } |
| | | } |
| | | |
| | | public static VisibilityEnum fromCode(String name) { |
| | | return keyMap.get(name); |
| | | public static VisibilityEnum fromCode(Integer code) { |
| | | return keyMap.get(code); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ycl.jxkg.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ycl.jxkg.domain.query.ExamTemplateQuery; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamTemplateVO; |
| | | import com.ycl.jxkg.domain.vo.ExamTemplateVO; |
| | | import com.ycl.jxkg.domain.form.ExamTemplateForm; |
| | | import java.util.List; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | /** |
| | | * 随机试卷模板 Mapper 接口 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Mapper |
| | | public interface ExamTemplateMapper extends BaseMapper<ExamTemplate> { |
| | |
| | | package com.ycl.jxkg.service; |
| | | |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.ycl.jxkg.domain.form.ExamTemplateForm; |
| | | import com.ycl.jxkg.domain.query.ExamTemplateQuery; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 随机试卷模板 服务类 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | public interface ExamTemplateService extends IService<ExamTemplate> { |
| | | |
| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Assert; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.ycl.jxkg.domain.form.ExamTemplateForm; |
| | | import com.ycl.jxkg.domain.query.ExamTemplateQuery; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamTemplateVO; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.domain.question.TemplateQuestionDTO; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.enums.VisibilityEnum; |
| | | import com.ycl.jxkg.mapper.ExamTemplateMapper; |
| | | import com.ycl.jxkg.service.ExamTemplateService; |
| | | import com.ycl.jxkg.utils.PageUtil; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.form.ExamTemplateForm; |
| | | import com.ycl.jxkg.domain.vo.ExamTemplateVO; |
| | | import com.ycl.jxkg.domain.query.ExamTemplateQuery; |
| | | import io.swagger.models.auth.In; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.context.SecurityContext; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.core.userdetails.UserDetails; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.ycl.jxkg.utils.PageUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.security.Security; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 随机试卷模板 服务实现类 |
| | | * |
| | | * @author 开发人员名字 |
| | | * @since 2024-06-03 |
| | | * @author flq |
| | | * @since 2024-06-05 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class ExamTemplateServiceImpl extends ServiceImpl<ExamTemplateMapper, ExamTemplate> implements ExamTemplateService { |
| | | |
| | | @Autowired |
| | | protected WebContext webContext; |
| | | |
| | | private final ExamTemplateMapper examTemplateMapper; |
| | | |
| | |
| | | @Override |
| | | public Result add(ExamTemplateForm form) { |
| | | ExamTemplate entity = ExamTemplateForm.getEntityByForm(form, null); |
| | | User currentUser = webContext.getCurrentUser(); |
| | | entity.setCreateUser(currentUser.getId()); |
| | | entity.setCreateTime(new Date()); |
| | | if(!StringUtils.isEmpty(entity.getVisibility())) { |
| | | entity.setVisibility(VisibilityEnum.fromCode(Integer.parseInt(entity.getVisibility())).getName()); |
| | | } |
| | | List<TemplateQuestionDTO> questionList = form.getQuestionList(); |
| | | BigDecimal score = BigDecimal.ZERO; |
| | | //设置题目信息 |
| | | for (TemplateQuestionDTO dto : questionList) { |
| | | score = score.add(dto.getScore().multiply(BigDecimal.valueOf(dto.getNum()))); |
| | | Integer questionType = dto.getQuestionType(); |
| | | switch (QuestionTypeEnum.fromCode(questionType)){ |
| | | //单选 |
| | | case SingleChoice: |
| | | entity.setSingleChoice(dto.getNum()); |
| | | entity.setSingleScore(dto.getScore()); |
| | | break; |
| | | //多选 |
| | | case MultipleChoice: |
| | | entity.setMultipleChoice(dto.getNum()); |
| | | entity.setMultipleScore(dto.getScore()); |
| | | break; |
| | | //判断 |
| | | case TrueFalse: |
| | | entity.setTrueFalse(dto.getNum()); |
| | | entity.setTrueFalseScore(dto.getScore()); |
| | | break; |
| | | //填空 |
| | | case GapFilling: |
| | | entity.setGapFilling(dto.getNum()); |
| | | entity.setGapScore(dto.getScore()); |
| | | break; |
| | | //简答 |
| | | case ShortAnswer: |
| | | entity.setShortAnswer(dto.getNum()); |
| | | entity.setShortAnswerScore(dto.getScore()); |
| | | break; |
| | | //计算 |
| | | case Calculation: |
| | | entity.setCalculation(dto.getNum()); |
| | | entity.setCalculationScore(dto.getScore()); |
| | | break; |
| | | } |
| | | } |
| | | entity.setScore(score); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | public Result page(ExamTemplateQuery query) { |
| | | IPage<ExamTemplateVO> page = PageUtil.getPage(query, ExamTemplateVO.class); |
| | | baseMapper.getPage(page, query); |
| | | PageInfo<ExamTemplateVO> pageInfo = new PageInfo<>(); |
| | | pageInfo.setList(page.getRecords()); |
| | | pageInfo.setTotal(page.getTotal()); |
| | | return Result.ok(pageInfo); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | |
| | | public Result detail(Integer id) { |
| | | ExamTemplateVO vo = baseMapper.getById(id); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | return Result.ok(vo); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | |
| | | List<ExamTemplateVO> vos = entities.stream() |
| | | .map(entity -> ExamTemplateVO.getVoByEntity(entity, null)) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok(vos); |
| | | return Result.ok().data(vos); |
| | | } |
| | | } |
| | |
| | | server: |
| | | servlet: |
| | | session: |
| | | timeout: 7200 |
| | | port: 8000 |
| | | undertow: |
| | | io-threads: 16 |
| | |
| | | logging: |
| | | config: classpath:logback-spring.xml |
| | | file: xzs |
| | | level: |
| | | com.lucifer.springboot.cache.mapper: debug |
| | | |
| | | |
| | | #mybatis plus |
| | | mybatis-plus: |
| | |
| | | logic-not-delete-value: 0 # 没有删除的值 |
| | | configuration: |
| | | default-enum-type-handler: org.apache.ibatis.type.EnumOrdinalTypeHandler # 通用枚举处理器 |
| | | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志打印 |
| | | type-enums-package: com.ycl.jxkg.enums.general # 通用枚举所在包路径 |
| | | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 日志打印 |
| | | type-enums-package: com.ycl.jxkg.domain.enums.general # 通用枚举所在包路径 |
| | | mapper-locations: classpath*:mapper/*.xml # mapper.xml位置 |
| | | |
| | | system: |
| | |
| | | <appender-ref ref="CONSOLE"/> |
| | | <appender-ref ref="FILE"/> |
| | | </root> |
| | | <logger name="repository" level="DEBUG" additivity="false"> |
| | | <logger name="mapper" level="DEBUG" additivity="false"> |
| | | <appender-ref ref="CONSOLE"/> |
| | | <appender-ref ref="FILE"/> |
| | | </logger> |
| | |
| | | <?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.monkeylessey.mapper.ExamTemplateMapper"> |
| | | <mapper namespace="com.ycl.jxkg.mapper.ExamTemplateMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.vo.admin.exam.ExamTemplateVO"> |
| | | <result column="exam_paper_id" property="examPaperId" /> |
| | | <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.vo.ExamTemplateVO"> |
| | | <result column="name" property="name" /> |
| | | <result column="subject_id" property="subjectId" /> |
| | | <result column="score" property="score" /> |
| | | <result column="visibility" property="visibility" /> |
| | | <result column="suggest_time" property="suggestTime" /> |
| | | <result column="deduct_type" property="deductType" /> |
| | | <result column="deduct_type_score" property="deductTypeScore" /> |
| | | <result column="single_choice" property="singleChoice" /> |
| | | <result column="multiple_choice" property="multipleChoice" /> |
| | | <result column="gap_filling" property="gapFilling" /> |
| | |
| | | <result column="gap_score" property="gapScore" /> |
| | | <result column="true_false_score" property="trueFalseScore" /> |
| | | <result column="short_answer_score" property="shortAnswerScore" /> |
| | | <result column="calculation_score" property="calculationScore" /> |
| | | <result column="calculation__score" property="calculationScore" /> |
| | | <result column="create_user" property="createUser" /> |
| | | <result column="create_time" property="createTime" /> |
| | | </resultMap> |
| | | |
| | | |
| | |
| | | |
| | | <select id="getById" resultMap="BaseResultMap"> |
| | | SELECT |
| | | TET.exam_paper_id, |
| | | TET.name, |
| | | TET.subject_id, |
| | | TET.score, |
| | | TET.visibility, |
| | | TET.suggest_time, |
| | | TET.deduct_type, |
| | | TET.deduct_type_score, |
| | | TET.single_choice, |
| | | TET.multiple_choice, |
| | | TET.gap_filling, |
| | |
| | | TET.true_false_score, |
| | | TET.short_answer_score, |
| | | TET.calculation__score, |
| | | TET.create_user, |
| | | TET.create_time, |
| | | TET.id |
| | | FROM |
| | | t_exam_template TET |
| | |
| | | |
| | | <select id="getPage" resultMap="BaseResultMap"> |
| | | SELECT |
| | | TET.exam_paper_id, |
| | | TET.name, |
| | | TET.subject_id, |
| | | TET.score, |
| | | TET.visibility, |
| | | TET.suggest_time, |
| | | TET.deduct_type, |
| | | TET.deduct_type_score, |
| | | TET.single_choice, |
| | | TET.multiple_choice, |
| | | TET.gap_filling, |
| | |
| | | TET.true_false_score, |
| | | TET.short_answer_score, |
| | | TET.calculation__score, |
| | | TET.create_user, |
| | | TET.create_time, |
| | | TET.id |
| | | FROM |
| | | t_exam_template TET |
| | | WHERE |
| | | <where> |
| | | TET.deleted = 0 |
| | | <if test="query.name!=null and query.name !=''"> |
| | | and name like concat ('%',#{query.name},'%') |
| | | </if> |
| | | <if test="query.subjectId!=null "> |
| | | and subject_id = #{query.subjectId} |
| | | </if> |
| | | </where> |
| | | </select> |
| | | |
| | | </mapper> |