Merge remote-tracking branch 'origin/master'
# Conflicts:
# src/main/java/com/ycl/jxkg/service/ExamPaperService.java
# src/main/java/com/ycl/jxkg/service/impl/ExamPaperServiceImpl.java
| | |
| | | <mybatisplus.version>3.5.4</mybatisplus.version> |
| | | <lombok.version>1.18.24</lombok.version> |
| | | <knife.version>3.0.3</knife.version> |
| | | <easyexcel.version>3.3.2</easyexcel.version> |
| | | </properties> |
| | | |
| | | |
| | |
| | | <optional>true</optional> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>easyexcel</artifactId> |
| | | <version>${easyexcel.version}</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | |
| | |
| | | public Result list() { |
| | | return classesService.all(); |
| | | } |
| | | |
| | | @GetMapping("/my") |
| | | @PreAuthorize("hasAuthority('classes:my')") |
| | | @ApiOperation(value = "我的班级", notes = "我的班级") |
| | | public Result myClassList() { |
| | | return classesService.myClassList(); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.controller.admin; |
| | | |
| | | 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.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.ExamService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * 考试 前端控制器 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Validated |
| | | @RequiredArgsConstructor |
| | | @Api(value = "考试", tags = "考试管理") |
| | | @RestController |
| | | @RequestMapping("/api/exam") |
| | | public class ExamController { |
| | | |
| | | private final ExamService examService; |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加", notes = "添加") |
| | | @PreAuthorize("hasAuthority('exam:add')") |
| | | public Result add(@RequestBody @Validated(Add.class) ExamForm form) { |
| | | return examService.add(form); |
| | | } |
| | | |
| | | @PutMapping |
| | | @ApiOperation(value = "修改", notes = "修改") |
| | | @PreAuthorize("hasAuthority('exam:edit')") |
| | | public Result update(@RequestBody @Validated(Update.class) ExamForm form) { |
| | | return examService.update(form); |
| | | } |
| | | |
| | | @DeleteMapping("/{id}") |
| | | @ApiOperation(value = "ID删除", notes = "ID删除") |
| | | @PreAuthorize("hasAuthority('exam:del')") |
| | | public Result removeById(@PathVariable("id") String id) { |
| | | return examService.removeById(id); |
| | | } |
| | | |
| | | @DeleteMapping("/batch") |
| | | @ApiOperation(value = "批量删除", notes = "批量删除") |
| | | @PreAuthorize("hasAuthority('exam:del:batch')") |
| | | public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List<String> ids) { |
| | | return examService.remove(ids); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @ApiOperation(value = "分页", notes = "分页") |
| | | @PreAuthorize("hasAuthority('exam:page')") |
| | | public Result page(ExamQuery query) { |
| | | return examService.page(query); |
| | | } |
| | | |
| | | @GetMapping("/{id}") |
| | | @ApiOperation(value = "详情", notes = "详情") |
| | | @PreAuthorize("hasAuthority('exam:detail')") |
| | | public Result detail(@PathVariable("id") Integer id) { |
| | | return examService.detail(id); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @PreAuthorize("hasAuthority('exam:list')") |
| | | @ApiOperation(value = "列表", notes = "列表") |
| | | public Result list() { |
| | | return examService.all(); |
| | | } |
| | | } |
| | |
| | | import com.ycl.jxkg.domain.vo.admin.paper.ExamPaperAnswerPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.student.exam.ExamPaperReadVO; |
| | | import com.ycl.jxkg.domain.vo.student.exam.ExamPaperSubmitVO; |
| | | import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerExportVO; |
| | | import com.ycl.jxkg.domain.vo.student.exampaper.ExamPaperAnswerPageResponseVO; |
| | | import com.ycl.jxkg.service.ExamPaperAnswerService; |
| | | import com.ycl.jxkg.service.ExamPaperService; |
| | | import com.ycl.jxkg.utils.ExcelUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.List; |
| | | |
| | | @RequiredArgsConstructor |
| | | @RestController("AdminExamPaperAnswerController") |
| | |
| | | return Result.ok(examPaperAnswerService.adminPage(model)); |
| | | } |
| | | |
| | | @RequestMapping(value = "/exportExcel", method = RequestMethod.POST) |
| | | @SneakyThrows |
| | | public void exportExcel(ExamPaperAnswerPageRequestVO model, HttpServletResponse response) { |
| | | List<ExamPaperAnswerPageResponseVO> list = examPaperAnswerService.list(model); |
| | | ExcelUtils.exportExcelToTarget(response, "", "成绩列表", list, ExamPaperAnswerExportVO.class); |
| | | } |
| | | |
| | | @PostMapping("/read/{id}") |
| | | public Result<ExamPaperReadVO> read(@PathVariable Integer id) { |
| | | ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(id); |
| | |
| | | baseMapper.deleteById(id); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @GetMapping("/my") |
| | | public Result myExamPaper(Integer paperType) { |
| | | List<ExamPaper> list = examPaperService.myExamPaper(paperType); |
| | | return Result.ok(list); |
| | | } |
| | | } |
| | |
| | | package com.ycl.jxkg.domain.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | |
| | |
| | | /** 备注 */ |
| | | private String remark; |
| | | |
| | | @TableField("create_time") |
| | | @TableField(value = "create_time", fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.domain.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import java.util.Date; |
| | | |
| | | import com.ycl.jxkg.domain.base.AbsEntity; |
| | | import com.ycl.jxkg.enums.general.ExamStatusEnum; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 考试 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Data |
| | | @TableName("t_exam") |
| | | public class Exam extends AbsEntity { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @TableField("exam_name") |
| | | /** 考试名称 */ |
| | | private String examName; |
| | | |
| | | @TableField("exam_paper_id") |
| | | /** 试卷ID */ |
| | | private Integer examPaperId; |
| | | |
| | | @TableField("classes_id") |
| | | /** 班级ID */ |
| | | private Integer classesId; |
| | | |
| | | @TableField("exam_paper_type") |
| | | /** 试卷类型 */ |
| | | private Integer examPaperType; |
| | | |
| | | @TableField("exam_place") |
| | | /** 考试地点 */ |
| | | private String examPlace; |
| | | |
| | | @TableField("status") |
| | | /** 考试状态 */ |
| | | private ExamStatusEnum status; |
| | | |
| | | @TableField("start_time") |
| | | /** 开始时间 */ |
| | | private Date startTime; |
| | | |
| | | @TableField("end_time") |
| | | /** 结束时间 */ |
| | | private Date endTime; |
| | | |
| | | @TableField("teacher_id") |
| | | /** 创建老师 */ |
| | | private Integer teacherId; |
| | | |
| | | @TableField(value = "create_time", fill = FieldFill.INSERT) |
| | | private Date createTime; |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.domain.form; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ycl.jxkg.group.Update; |
| | | import com.ycl.jxkg.group.Add; |
| | | import com.ycl.jxkg.domain.base.AbsForm; |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import org.springframework.beans.BeanUtils; |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | import org.springframework.lang.NonNull; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 考试表单 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "Exam表单", description = "考试表单") |
| | | public class ExamForm extends AbsForm { |
| | | |
| | | @NotBlank(message = "考试名称不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("考试名称") |
| | | private String examName; |
| | | |
| | | @NotNull(message = "考试试卷不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("试卷ID") |
| | | private Integer examPaperId; |
| | | |
| | | @NotNull(message = "参考班级不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("班级ID") |
| | | private Integer classesId; |
| | | |
| | | @NotNull(message = "试卷类型不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("试卷类型") |
| | | private Integer examPaperType; |
| | | |
| | | @NotBlank(message = "考试地点不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("考试地点") |
| | | private String examPlace; |
| | | |
| | | @NotNull(message = "开始时间不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("开始时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date startTime; |
| | | |
| | | @NotNull(message = "结束时间不能为空", groups = {Add.class, Update.class}) |
| | | @ApiModelProperty("结束时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date endTime; |
| | | |
| | | public static Exam getEntityByForm(@NonNull ExamForm form, Exam entity) { |
| | | if(entity == null) { |
| | | entity = new Exam(); |
| | | } |
| | | BeanUtils.copyProperties(form, entity); |
| | | return entity; |
| | | } |
| | | |
| | | } |
| | |
| | | /** 班级状态 */ |
| | | private String status; |
| | | |
| | | private Integer userId; |
| | | |
| | | } |
| | | |
New file |
| | |
| | | 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 xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Data |
| | | @ApiModel(value = "Exam查询", description = "考试查询") |
| | | public class ExamQuery extends AbsQuery { |
| | | |
| | | /** 考试名称 */ |
| | | private String examName; |
| | | |
| | | /** 班级 */ |
| | | private Integer classesId; |
| | | |
| | | } |
| | | |
New file |
| | |
| | | package com.ycl.jxkg.domain.vo; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.ycl.jxkg.domain.base.AbsVo; |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | 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; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 考试展示 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Data |
| | | public class ExamVO extends AbsVo { |
| | | |
| | | /** 考试名称 */ |
| | | private String examName; |
| | | |
| | | /** 试卷ID */ |
| | | private Integer examPaperId; |
| | | private String examPaperName; |
| | | |
| | | /** 班级ID */ |
| | | private Integer classesId; |
| | | private String className; |
| | | |
| | | /** 试卷类型 */ |
| | | private Integer examPaperType; |
| | | |
| | | /** 考试地点 */ |
| | | private String examPlace; |
| | | |
| | | /** 考试状态 */ |
| | | private String status; |
| | | |
| | | /** 开始时间 */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date startTime; |
| | | |
| | | /** 结束时间 */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date endTime; |
| | | |
| | | /** 创建时间 */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | private Date createTime; |
| | | |
| | | /** 创建老师 */ |
| | | private Integer teacherId; |
| | | |
| | | public static ExamVO getVoByEntity(@NonNull Exam entity, ExamVO vo) { |
| | | if(vo == null) { |
| | | vo = new ExamVO(); |
| | | } |
| | | BeanUtils.copyProperties(entity, vo); |
| | | return vo; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.domain.vo.student.exampaper; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import com.alibaba.excel.annotation.write.style.ColumnWidth; |
| | | import com.alibaba.excel.annotation.write.style.ContentStyle; |
| | | import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author gonghl |
| | | * @since 2024/6/7 下午 4:58 |
| | | */ |
| | | |
| | | @Data |
| | | @ColumnWidth(18) |
| | | @ContentStyle(horizontalAlignment= HorizontalAlignmentEnum.CENTER) |
| | | public class ExamPaperAnswerExportVO { |
| | | |
| | | @ExcelProperty("姓名") |
| | | private String userName; |
| | | |
| | | @ExcelProperty("分数") |
| | | private String userScore; |
| | | |
| | | @ExcelProperty("总分") |
| | | private String paperScore; |
| | | |
| | | @ExcelProperty("正确题数") |
| | | private Integer questionCorrect; |
| | | |
| | | @ExcelProperty("题目总数") |
| | | private Integer questionCount; |
| | | |
| | | @ExcelProperty("答题时间") |
| | | private String doTime; |
| | | |
| | | @ExcelProperty("提交时间") |
| | | private String createTime; |
| | | |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.enums.general; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | import com.fasterxml.jackson.annotation.JsonValue; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 考试状态 |
| | | * |
| | | * @author:xp |
| | | * @date:2024/6/4 9:35 |
| | | */ |
| | | @Getter |
| | | public enum ExamStatusEnum { |
| | | |
| | | NOT_START("not_start", "未开始"), |
| | | ING("ing", "进行中"), |
| | | FINISHED("finished", "已结束"), |
| | | ; |
| | | |
| | | @EnumValue |
| | | private final String value; |
| | | |
| | | @JsonValue |
| | | private final String desc; |
| | | |
| | | ExamStatusEnum(String value, String desc) { |
| | | this.value = value; |
| | | this.desc = desc; |
| | | } |
| | | |
| | | /** |
| | | * 判断当前时间对应的考试状态 |
| | | * |
| | | * @param start |
| | | * @param end |
| | | * @param now |
| | | * @return |
| | | */ |
| | | public static ExamStatusEnum getStatusByTime(Date start, Date end, Date now) { |
| | | if (Objects.isNull(now)) { |
| | | now = new Date(); |
| | | } |
| | | if (now.after(end)) { |
| | | return FINISHED; |
| | | } else if (now.before(start)) { |
| | | return NOT_START; |
| | | } else { |
| | | return ING; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.mapper; |
| | | |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import com.ycl.jxkg.domain.vo.ExamVO; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import java.util.List; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | /** |
| | | * 考试 Mapper 接口 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Mapper |
| | | public interface ExamMapper extends BaseMapper<Exam> { |
| | | |
| | | /** |
| | | * id查找考试 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | ExamVO getById(Integer id); |
| | | |
| | | /** |
| | | * 分页 |
| | | */ |
| | | IPage getPage(IPage page, @Param("query") ExamQuery query); |
| | | |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | Result dissolution(Integer id); |
| | | |
| | | /** |
| | | * |
| | | * 我的班级 |
| | | * |
| | | * @return |
| | | */ |
| | | Result myClassList(); |
| | | } |
| | |
| | | PageInfo<ExamPaperAnswerPageResponseVO> adminPage(ExamPaperAnswerPageRequestVO requestVM); |
| | | |
| | | /** |
| | | * 成绩列表 |
| | | * @param requestVM 查询条件 |
| | | * @return 数据 |
| | | */ |
| | | List<ExamPaperAnswerPageResponseVO> list(ExamPaperAnswerPageRequestVO requestVM); |
| | | |
| | | /** |
| | | * 答卷列表 |
| | | * @param model 查询条件 |
| | | * @return 数据 |
| | |
| | | |
| | | List<Integer> selectMothCount(); |
| | | |
| | | /** |
| | | * |
| | | * 我的试卷 |
| | | * |
| | | * @param paperType |
| | | * @return |
| | | */ |
| | | List<ExamPaper> myExamPaper(Integer paperType); |
| | | |
| | | void addPaper(ExamPaperForm form); |
| | | |
| | | void updateExamPaper(ExamPaperForm form); |
New file |
| | |
| | | package com.ycl.jxkg.service; |
| | | |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 考试 服务类 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | public interface ExamService extends IService<Exam> { |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | Result add(ExamForm form); |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | Result update(ExamForm form); |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | Result remove(List<String> ids); |
| | | |
| | | /** |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | Result removeById(String id); |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | Result page(ExamQuery query); |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | Result detail(Integer id); |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | Result all(); |
| | | } |
| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.Classes; |
| | | import com.ycl.jxkg.enums.general.ClassesStatusEnum; |
| | | import com.ycl.jxkg.mapper.ClassesMapper; |
| | |
| | | public class ClassesServiceImpl extends ServiceImpl<ClassesMapper, Classes> implements ClassesService { |
| | | |
| | | private final ClassesMapper classesMapper; |
| | | private final WebContext webContext; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | @Override |
| | | public Result add(ClassesForm form) { |
| | | Classes entity = ClassesForm.getEntityByForm(form, null); |
| | | entity.setStatus(ClassesStatusEnum.NORMAL); |
| | | entity.setCreateUser(webContext.getCurrentUser().getId()); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | @Override |
| | | public Result page(ClassesQuery query) { |
| | | IPage<ClassesVO> page = PageUtil.getPage(query, ClassesVO.class); |
| | | query.setUserId(webContext.getCurrentUser().getId()); |
| | | baseMapper.getPage(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | |
| | | .update(); |
| | | return Result.ok("解散成功"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Result myClassList() { |
| | | Integer userId = webContext.getCurrentUser().getId(); |
| | | List<Classes> list = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .select(Classes::getId, Classes::getClassName) |
| | | .eq(Classes::getCreateUser, userId) |
| | | .list(); |
| | | return Result.ok(list); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<ExamPaperAnswerPageResponseVO> list(ExamPaperAnswerPageRequestVO requestVM) { |
| | | return examPaperAnswerMapper.adminPage(requestVM); |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<ExamPaperAnswerPageResponseVO> pageExamPaper(ExamPaperAnswerPageRequestVO model) { |
| | | return PageHelper.startPage(model.getPageIndex(), model.getPageSize()).doSelectPageInfo(() -> |
| | | examPaperAnswerMapper.pageExamPaper(model)); |
| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.entity.ExamTemplate; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.TextContent; |
| | | import com.ycl.jxkg.domain.exam.ExamPaperTempDTO; |
| | | import com.ycl.jxkg.domain.form.ExamPaperForm; |
| | |
| | | import com.ycl.jxkg.domain.exam.ExamPaperTitleItemObject; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.enums.QuestionTypeEnum; |
| | | import com.ycl.jxkg.enums.VisibilityEnum; |
| | | import com.ycl.jxkg.enums.VisibilityEnum; |
| | | import com.ycl.jxkg.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.mapper.ExamTemplateMapper; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final QuestionService questionService; |
| | | private final SubjectService subjectService; |
| | | private final ExamTemplateMapper examTemplateMapper; |
| | | private final WebContext webContext; |
| | | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<ExamPaper> myExamPaper(Integer paperType) { |
| | | Integer userId = webContext.getCurrentUser().getId(); |
| | | List<ExamPaper> list = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .select(ExamPaper::getId, ExamPaper::getName, ExamPaper::getVisibility) |
| | | .eq(ExamPaper::getCreateUser, userId) |
| | | .eq(Objects.nonNull(paperType), ExamPaper::getPaperType, paperType) |
| | | .or() |
| | | .eq(ExamPaper::getVisibility, VisibilityEnum.Public.getName()) |
| | | .eq(Objects.nonNull(paperType), ExamPaper::getPaperType, paperType) |
| | | .list(); |
| | | list.stream().forEach(item -> { |
| | | if (VisibilityEnum.Public.getName().equals(item.getVisibility())) { |
| | | item.setName(item.getName() + " (公开)"); |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.domain.entity.Exam; |
| | | import com.ycl.jxkg.enums.general.ExamStatusEnum; |
| | | import com.ycl.jxkg.mapper.ExamMapper; |
| | | import com.ycl.jxkg.service.ExamService; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.jxkg.domain.form.ExamForm; |
| | | import com.ycl.jxkg.domain.vo.ExamVO; |
| | | import com.ycl.jxkg.domain.query.ExamQuery; |
| | | 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 java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 考试 服务实现类 |
| | | * |
| | | * @author xp |
| | | * @since 2024-06-11 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements ExamService { |
| | | |
| | | private final ExamMapper examMapper; |
| | | private final WebContext webContext; |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result add(ExamForm form) { |
| | | Exam entity = ExamForm.getEntityByForm(form, null); |
| | | entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null)); |
| | | entity.setTeacherId(webContext.getCurrentUser().getId()); |
| | | baseMapper.insert(entity); |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result update(ExamForm form) { |
| | | Exam entity = baseMapper.selectById(form.getId()); |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | entity.setStatus(ExamStatusEnum.getStatusByTime(form.getStartTime(), form.getEndTime(), null)); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | baseMapper.deleteBatchIds(ids); |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | | /** |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | baseMapper.deleteById(id); |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result page(ExamQuery query) { |
| | | IPage<ExamVO> page = PageUtil.getPage(query, ExamVO.class); |
| | | baseMapper.getPage(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result detail(Integer id) { |
| | | ExamVO vo = baseMapper.getById(id); |
| | | Assert.notNull(vo, "记录不存在"); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<Exam> entities = baseMapper.selectList(null); |
| | | List<ExamVO> vos = entities.stream() |
| | | .map(entity -> ExamVO.getVoByEntity(entity, null)) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.utils; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * excel工具类 |
| | | * |
| | | * @author gonghl |
| | | */ |
| | | public class ExcelUtils { |
| | | |
| | | /** |
| | | * Excel导出 |
| | | * |
| | | * @param response response |
| | | * @param fileName 文件名 |
| | | * @param sheetName sheetName |
| | | * @param list 数据List |
| | | * @param pojoClass 对象Class |
| | | */ |
| | | public static void exportExcel(HttpServletResponse response, String fileName, String sheetName, List<?> list, Class<?> pojoClass) throws IOException { |
| | | if (StringUtils.isBlank(fileName)) { |
| | | fileName = Long.toString(System.currentTimeMillis()); |
| | | } |
| | | |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), pojoClass).sheet(sheetName).doWrite(list); |
| | | } |
| | | |
| | | /** |
| | | * Excel导出,先sourceList转换成List<targetClass>,再导出 |
| | | * |
| | | * @param response response |
| | | * @param fileName 文件名 |
| | | * @param sheetName sheetName |
| | | * @param sourceList 原数据List |
| | | * @param targetClass 目标对象Class |
| | | */ |
| | | public static void exportExcelToTarget(HttpServletResponse response, String fileName, String sheetName, List<?> sourceList, Class<?> targetClass) throws Exception { |
| | | List<Object> targetList = new ArrayList<>(sourceList.size()); |
| | | for (Object source : sourceList) { |
| | | Object target = targetClass.newInstance(); |
| | | BeanUtils.copyProperties(source, target); |
| | | targetList.add(target); |
| | | } |
| | | |
| | | exportExcel(response, fileName, sheetName, targetList, targetClass); |
| | | } |
| | | |
| | | } |
| | |
| | | t_classes TC |
| | | LEFT JOIN t_user TU ON TU.id = TC.create_user AND TU.deleted = 0 |
| | | WHERE |
| | | TC.deleted = 0 |
| | | TC.deleted = 0 AND TC.create_user = #{query.userId} |
| | | <if test="query.className != null and query.className != ''"> |
| | | AND TC.class_name like concat('%', #{query.className}, '%') |
| | | </if> |
New file |
| | |
| | | <?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.ycl.jxkg.mapper.ExamMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.ycl.jxkg.domain.vo.ExamVO"> |
| | | <result column="exam_name" property="examName" /> |
| | | <result column="exam_paper_id" property="examPaperId" /> |
| | | <result column="classes_id" property="classesId" /> |
| | | <result column="exam_paper_type" property="examPaperType" /> |
| | | <result column="exam_place" property="examPlace" /> |
| | | <result column="status" property="status" /> |
| | | <result column="start_time" property="startTime" /> |
| | | <result column="end_time" property="endTime" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="teacher_id" property="teacherId" /> |
| | | <result column="class_name" property="className" /> |
| | | <result column="name" property="examPaperName" /> |
| | | </resultMap> |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | <select id="getById" resultMap="BaseResultMap"> |
| | | SELECT |
| | | TE.exam_name, |
| | | TE.exam_paper_id, |
| | | TE.classes_id, |
| | | TE.exam_paper_type, |
| | | TE.exam_place, |
| | | TE.status, |
| | | TE.start_time, |
| | | TE.end_time, |
| | | TE.create_time, |
| | | TE.teacher_id, |
| | | TE.id |
| | | FROM |
| | | t_exam TE |
| | | WHERE |
| | | TE.id = #{id} AND TE.deleted = 0 |
| | | </select> |
| | | |
| | | |
| | | <select id="getPage" resultMap="BaseResultMap"> |
| | | SELECT |
| | | TE.exam_name, |
| | | TE.exam_paper_id, |
| | | TE.classes_id, |
| | | TE.exam_paper_type, |
| | | TE.exam_place, |
| | | TE.status, |
| | | TE.start_time, |
| | | TE.end_time, |
| | | TE.create_time, |
| | | TE.teacher_id, |
| | | TE.id, |
| | | TC.class_name, |
| | | TEP.name |
| | | FROM |
| | | t_exam TE |
| | | INNER JOIN t_user TU ON TU.id = TE.teacher_id AND TU.deleted = 0 |
| | | INNER JOIN t_classes TC ON TC.id = TE.classes_id AND TC.deleted = 0 |
| | | INNER JOIN t_exam_paper TEP ON TEP.id = TE.exam_paper_id AND TEP.deleted = 0 |
| | | WHERE |
| | | TE.deleted = 0 |
| | | <if test="query.examName != null and query.examName != ''"> |
| | | AND TE.exam_name like concat('%', #{query.examName}, '%') |
| | | </if> |
| | | <if test="query.classesId != null"> |
| | | AND TE.classes_id = #{query.classesId} |
| | | </if> |
| | | </select> |
| | | |
| | | </mapper> |