智慧保安后台管理-外网-验收版本
Administrator
2021-07-16 269031cf8e6d1e4643e1be2b822bbfebcf87ea4b
考试成绩计算接口新增
12 files modified
2 files added
245 ■■■■■ changed files
src/main/java/org/springblade/modules/exam/controller/ExamPaperController.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java 27 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/entity/ExamExaminationSubject.java 75 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/entity/ExamScore.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.java 3 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.xml 13 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/ExamPaperService.java 3 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/ExamScoreService.java 8 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/impl/ExamPaperServiceImpl.java 5 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/vo/ExamPaperSubjectVO.java 9 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/vo/ExamResultVO.java 23 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java 9 ●●●●● patch | view | raw | blame | history
src/main/resources/application.yml 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/controller/ExamPaperController.java
@@ -28,6 +28,7 @@
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamPaperVO;
import org.springblade.modules.exam.wrapper.ExamPaperWrapper;
import org.springframework.web.bind.annotation.*;
@@ -46,6 +47,7 @@
public class ExamPaperController extends BladeController {
    private final ExamPaperService examPaperService;
    /**
     * 详情
@@ -128,8 +130,8 @@
    @GetMapping("/queryPagerSubject")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "考试题目绑定", notes = "传入exam")
    public R<ExamPaperVO> queryPagerSubject(@ApiParam(value = "主键集合") ExamPaper exam) {
        ExamPaperVO subject = examPaperService.queryPagerSubject(exam);
    public R<ExamPaperSubjectVO> queryPagerSubject(@ApiParam(value = "主键集合") ExamPaper exam) {
        ExamPaperSubjectVO subject = examPaperService.queryPagerSubject(exam);
        return R.data(subject);
    }
src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
@@ -14,6 +14,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
/**
 * @author zhongrj
@@ -57,6 +58,17 @@
        return R.status(examScoreService.save(examScore));
    }
    /**
     * 保存考试成绩
     * @param examScore 考试成绩信息对象
     */
    @PostMapping("/saveExamScore")
    public R saveExamScore(@RequestBody ExamScoreVO examScore) {
        return R.status(examScoreService.saveExamScore(examScore));
    }
    /**
     * 修改
     * @param examScore 考试成绩信息对象
@@ -67,14 +79,23 @@
    }
    /**
     * 修改总成绩
     * @param examScore 考试成绩信息对象
     */
    @PostMapping("/updateExamScore")
    public R updateExamScore(@RequestBody ExamScore examScore) {
        if (null!=examScore.getLearnGrade() && null!=examScore.getTheoryGrade()){
            examScore.setAllGrade(examScore.getLearnGrade()+examScore.getTheoryGrade());
        }
        return R.status(examScoreService.updateById(examScore));
    }
    /**
     * 新增或修改
     * @param examScore 考试成绩信息对象
     */
    @PostMapping("/submit")
    public R submit(@RequestBody ExamScore examScore) {
//        if (null!=examScore.getId()){
//            examScore.setExamTime(new Date());
//        }
        return R.status(examScoreService.saveOrUpdate(examScore));
    }
src/main/java/org/springblade/modules/exam/entity/ExamExaminationSubject.java
New file
@@ -0,0 +1,75 @@
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.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 io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 *  试卷分类实体类
 *
 * @author Chill
 */
@Data
@TableName("exam_examination_subject")
public class ExamExaminationSubject implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * ID
     */
    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    /**
     * 试卷id
     */
    @TableField("examination_id")
    private String examinationId;
    /**
     * 分类
     */
    @TableField("category_id")
    private Integer categoryId;
    /**
     * 题目id
     */
    @TableField("subject_id")
    private String subjectId;
    /**
     * 题目对象
     */
    private ExamSubjectChoices examSubjectChoices;
}
src/main/java/org/springblade/modules/exam/entity/ExamScore.java
@@ -67,7 +67,7 @@
    private String company;
    /**
     * 考试时间
     * 考试开始时间
     */
    @TableField("exam_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@@ -75,6 +75,14 @@
    private Date examTime;
    /**
     * 考试结束时间
     */
    @TableField("exam_end_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date examEndTime;
    /**
     * 考试名称
     */
    @TableField("exam_name")
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.java
@@ -22,6 +22,7 @@
import org.springblade.modules.desk.entity.Notice;
import org.springblade.modules.desk.vo.NoticeVO;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamPaperVO;
import java.util.List;
@@ -33,5 +34,5 @@
 */
public interface ExamPaperMapper extends BaseMapper<ExamPaper> {
    ExamPaperVO queryPagerSubject(@Param("paper") ExamPaper paper);
    ExamPaperSubjectVO queryPagerSubject(@Param("paper") ExamPaper paper);
}
src/main/java/org/springblade/modules/exam/mapper/ExamPaperMapper.xml
@@ -5,15 +5,19 @@
    <resultMap id="PagerSubject" type="org.springblade.modules.exam.vo.ExamPaperSubjectVO"
               autoMapping="true">
        <id property="id" column="id"/>
        <collection property="subjectList" javaType="java.util.List"
                    ofType="org.springblade.modules.exam.entity.ExamSubjectChoices" autoMapping="true">
            <id property="id" column="tmxq.id"/>
        <collection property="examExaminationSubjects" javaType="java.util.List" ofType="org.springblade.modules.exam.entity.ExamExaminationSubject" autoMapping="true">
            <id property="id" column="tid"/>
            <association property="examSubjectChoices" javaType="org.springblade.modules.exam.entity.ExamSubjectChoices" autoMapping="true">
                <id property="id" column="sid"/>
            </association>
        </collection>
    </resultMap>
    <select id="queryPagerSubject" resultMap="PagerSubject">
        SELECT
        sj.exam_name,sj.exam_type,sj.exam_attention,sj.total_score,sj.exam_status,tmxq.id,tmxq.subject_name,tmxq.answer,tmxq.analysis
        sj.*,
        tm.id tid,
        tmxq.id as sid,tmxq.subject_name,tmxq.answer,tmxq.analysis
        FROM
        ksxt_exam sj
        LEFT JOIN exam_examination_subject tm ON sj.id = tm.examination_id
@@ -23,7 +27,6 @@
        <if test="paper.id !=null">
        and sj.id = #{paper.id}
        </if>
    </select>
</mapper>
src/main/java/org/springblade/modules/exam/service/ExamPaperService.java
@@ -18,6 +18,7 @@
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamPaperVO;
/**
@@ -27,6 +28,6 @@
 */
public interface ExamPaperService extends IService<ExamPaper> {
    ExamPaperVO queryPagerSubject(ExamPaper paper);
    ExamPaperSubjectVO queryPagerSubject(ExamPaper paper);
}
src/main/java/org/springblade/modules/exam/service/ExamScoreService.java
@@ -22,6 +22,14 @@
    /**
     * 详情
     * @param examScore 考试成绩信息对象
     * @return
     */
    ExamScoreVO selectExamScoreInfo(ExamScore examScore);
    /**
     * 保存考试成绩
     * @param examScore 考试成绩信息对象
     * @return
     */
    Boolean saveExamScore(ExamScoreVO examScore);
}
src/main/java/org/springblade/modules/exam/service/impl/ExamPaperServiceImpl.java
@@ -20,6 +20,7 @@
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.mapper.ExamPaperMapper;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamPaperVO;
import org.springframework.stereotype.Service;
@@ -33,7 +34,9 @@
    @Override
    public ExamPaperVO queryPagerSubject(ExamPaper paper) {
    public ExamPaperSubjectVO queryPagerSubject(ExamPaper paper) {
        //查询试卷分类信息
        return baseMapper.queryPagerSubject(paper);
    }
}
src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -3,18 +3,32 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.modules.exam.entity.ExamExaminationSubject;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.entity.ExamScore;
import org.springblade.modules.exam.mapper.ExamScoreMapper;
import org.springblade.modules.exam.service.ExamPaperService;
import org.springblade.modules.exam.service.ExamScoreService;
import org.springblade.modules.exam.vo.ExamPaperSubjectVO;
import org.springblade.modules.exam.vo.ExamResultVO;
import org.springblade.modules.exam.vo.ExamScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
 * 考试成绩服务实现类
 * @author zhongrj
 */
@Service
@AllArgsConstructor
public class ExamScoreServiceImpl extends ServiceImpl<ExamScoreMapper, ExamScore> implements ExamScoreService {
    private final ExamPaperService examPaperService;
    /**
     * 自定义分页数据
@@ -35,4 +49,43 @@
    public ExamScoreVO selectExamScoreInfo(ExamScore examScore) {
        return baseMapper.selectExamScoreInfo(examScore);
    }
    /**
     * 保存考试成绩
     * @param examScore 考试成绩信息对象
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveExamScore(ExamScoreVO examScore) {
        //取出考试结果
        if (examScore.getExamResultVOS().size()>0){
            List<ExamResultVO> examResultVOS = examScore.getExamResultVOS();
            //获取试卷的内容(题号,答案)
            ExamPaper examPaper = new ExamPaper();
            examPaper.setId(examScore.getPapersId());
            List<ExamExaminationSubject> examExaminationSubjects
                = examPaperService.queryPagerSubject(examPaper).getExamExaminationSubjects();
            //比对考试结果
            //声明理论得分
            int theoryGrade = 0;
            for (int i = 0; i < examResultVOS.size(); i++) {
                if (examResultVOS.get(i).getValue().equals(examExaminationSubjects.get(i).getExamSubjectChoices().getAnswer())){
                    theoryGrade += examResultVOS.get(i).getGrade();
                }
            }
            //设置理论得分
            examScore.setTheoryGrade(theoryGrade);
            //计算总成绩
            examScore.setAllGrade(theoryGrade + examScore.getLearnGrade());
            //保存成绩数据
            int i = baseMapper.insert(examScore);
            if (i>0){
                //返回结果
                return true;
            }
        }
        //返回结果
        return false;
    }
}
src/main/java/org/springblade/modules/exam/vo/ExamPaperSubjectVO.java
@@ -2,18 +2,23 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.exam.entity.ExamExaminationSubject;
import org.springblade.modules.exam.entity.ExamPaper;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import java.util.List;
/**
 * 通知公告视图类
 * 考试类目视图类
 *
 * @author Chill
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ExamPaperSubjectVO extends ExamPaper {
    private List<ExamSubjectChoices> subjectList;
    /**
     * 考试类目
     */
    private List<ExamExaminationSubject> examExaminationSubjects;
}
src/main/java/org/springblade/modules/exam/vo/ExamResultVO.java
New file
@@ -0,0 +1,23 @@
package org.springblade.modules.exam.vo;
import lombok.Data;
import java.io.Serializable;
/**
 * @author zhongrj
 */
@Data
public class ExamResultVO implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 提交的答案
     */
    private String value;
    /**
     * 每道题的分数
     */
    private Integer grade;
}
src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java
@@ -5,6 +5,7 @@
import org.springblade.modules.exam.entity.ExamSubjectOption;
import java.io.Serializable;
import java.util.List;
/**
 * 选择题选项实体类vo
@@ -15,5 +16,13 @@
public class ExamScoreVO extends ExamScore implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 试卷id
     */
    private Long papersId;
    /**
     * 考勤提交的结果
     */
    private List<ExamResultVO> examResultVOS;
}
src/main/resources/application.yml
@@ -204,6 +204,7 @@
      - /examSubjectChoices/**
      - /exampaper/**
      - /examScore/**
      - /exampaper/**
    #授权认证配置
    auth:
      - method: ALL