智慧保安后台管理-外网
Administrator
2021-08-10 c8ebf3038d2a7f69d9eb40f5a276dc3fa826fa9b
报名接口修改,考试计算成绩接口修改,对比答案修改为对比所有题目
10 files modified
253 ■■■■ changed files
src/main/java/org/springblade/modules/apply/controller/ApplyController.java 17 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/excel/ApplyExcel.java 10 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/excel/ApplyImporter.java 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/excel/ApplyInfoExcel.java 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/mapper/ApplyMapper.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/mapper/ApplyMapper.xml 47 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/service/ApplyService.java 11 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java 105 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/vo/ApplyVO.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java 36 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/apply/controller/ApplyController.java
@@ -166,7 +166,7 @@
    @ApiOperation(value = "导入报名考试数据", notes = "传入excel")
    public R importUser(MultipartFile file, Integer isCovered) {
        ApplyImporter applyImporter = new ApplyImporter(applyService, false);
        ExcelUtil.save(file, applyImporter, ApplyInfoExcel.class);
        ExcelUtil.save(file, applyImporter, ApplyExcel.class);
        return R.success("操作成功");
    }
@@ -176,8 +176,8 @@
    @GetMapping("export-template")
    @ApiOperation(value = "导出模板")
    public void exportUser(HttpServletResponse response) {
        List<ApplyInfoExcel> list = new ArrayList<>();
        ExcelUtil.export(response, "考试报名数据模板", "考试报名数据表", list, ApplyInfoExcel.class);
        List<ApplyExcel> list = new ArrayList<>();
        ExcelUtil.export(response, "考试报名数据模板", "考试报名数据表", list, ApplyExcel.class);
    }
@@ -527,4 +527,15 @@
        return null;
    }
    /**
     * 查询报名清册信息
     * @param apply 报名信息
     * @return
     */
    @GetMapping("/getApplyDetailList")
    public Map<String,Object> getApplyDetailList(ApplyVO apply){
        return applyService.getApplyDetailList(apply);
    }
}
src/main/java/org/springblade/modules/apply/excel/ApplyExcel.java
@@ -38,13 +38,13 @@
    @ColumnWidth(15)
    @ExcelProperty("保安ID")
    private Long userId;
    @ExcelProperty("保安姓名")
    private String realName;
    @ColumnWidth(15)
    @ExcelProperty("考试ID")
    private Long examId;
    @ColumnWidth(25)
    @ExcelProperty("身份证号")
    private String idCardNo;
}
src/main/java/org/springblade/modules/apply/excel/ApplyImporter.java
@@ -29,13 +29,13 @@
 * @since 2021-07-22
 */
@RequiredArgsConstructor
public class ApplyImporter implements ExcelImporter<ApplyInfoExcel> {
public class ApplyImporter implements ExcelImporter<ApplyExcel> {
    private final ApplyService service;
    private final Boolean isCovered;
    @Override
    public void save(List<ApplyInfoExcel> data) {
    public void save(List<ApplyExcel> data) {
        service.importApply(data, isCovered);
    }
}
src/main/java/org/springblade/modules/apply/excel/ApplyInfoExcel.java
@@ -68,8 +68,4 @@
    @ExcelProperty("报名时间")
    private Date applyTime;
    @ColumnWidth(20)
    @ExcelProperty("考试时间")
    private Date examTime;
}
src/main/java/org/springblade/modules/apply/mapper/ApplyMapper.java
@@ -88,4 +88,18 @@
     * @return
     */
    List<Long> getApplyIds();
    /**
     * 查询考试人数
     * @param id 考试id
     * @return
     */
    int getApplyDeatailNum(Long id);
    /**
     * 查询已报名的的人信息集合
     * @param id 考试id
     * @return
     */
    List<ApplyVO> getApplyDetailList(Long id);
}
src/main/java/org/springblade/modules/apply/mapper/ApplyMapper.xml
@@ -227,4 +227,51 @@
        and sa.exam_id is null
    </select>
    <!--查询考试人数-->
    <select id="getApplyDeatailNum" resultType="java.lang.Integer">
        SELECT
        count(*)
        FROM
        sys_apply sa
        left join
        blade_user bu
        on
        sa.user_id = bu.id
        WHERE
        1=1
        and is_exam = 1
        and sa.apply_status = 2
        and bu.is_apply = 1
        and sa.exam_id is not null
    </select>
    <!--查询已报名的的人信息集合-->
    <select id="getApplyDetailList" resultType="org.springblade.modules.apply.vo.ApplyVO">
        SELECT
            sa.candidate_no candidateNo,sa.apply_time applyTime,
            ke.exam_name examName,
            bu.real_name realName,bu.cardid idCardNo,bu.sex,
            bd.dept_name deptName,"保安证" applyCard
        FROM
        sys_apply sa
        left join
        blade_user bu
        on
        sa.user_id = bu.id
        left join
        ksxt_exam ke
        on
        ke.id = sa.exam_id
        left join
        blade_dept bd
        on
        bd.id = bu.dept_id
        WHERE
        1=1
        and is_exam = 1
        and sa.apply_status = 2
        and bu.is_apply = 1
        and sa.exam_id is not null
    </select>
</mapper>
src/main/java/org/springblade/modules/apply/service/ApplyService.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.core.tool.api.R;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.apply.excel.ApplyExcel;
import org.springblade.modules.apply.excel.ApplyInfoExcel;
@@ -9,6 +10,7 @@
import org.springblade.modules.apply.vo.ApplyVO;
import java.util.List;
import java.util.Map;
/**
 * 考试报名服务类
@@ -52,7 +54,7 @@
     * @param isCovered
     * @return
     */
    void importApply(List<ApplyInfoExcel> data, Boolean isCovered);
    void importApply(List<ApplyExcel> data, Boolean isCovered);
    /**
     * 获取准考证信息
@@ -86,4 +88,11 @@
     * @return
     */
    List<Long> getApplyIds();
    /**
     * 查询报名清册信息
     * @param apply 报名信息
     * @return
     */
    Map<String,Object> getApplyDetailList(ApplyVO apply);
}
src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
@@ -11,6 +11,7 @@
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springblade.common.utils.arg;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.modules.apply.entity.Apply;
import org.springblade.modules.apply.excel.ApplyExcel;
import org.springblade.modules.apply.excel.ApplyInfoExcel;
@@ -27,9 +28,7 @@
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
 * 考试报名服务实现类
@@ -85,26 +84,47 @@
    }
    /**
     * 导入报名信息
     * @param data
     * @param isCovered
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importApply(List<ApplyInfoExcel> data, Boolean isCovered) {
        data.forEach(applyInfoExcel -> {
            //通过准考证号
            if (null!=applyInfoExcel.getCandidateNo() && applyInfoExcel.getIdCardNo()!=""){
                Apply apply = new Apply();
                apply.setCandidateNo(applyInfoExcel.getCandidateNo());
                //查询报名信息
                Apply apply1 = baseMapper.selectOne(Condition.getQueryWrapper(apply));
                apply1.setIsExam(2);
                baseMapper.updateById(apply1);
                //内网新增
                try {
//                    arg.test01(arg.url+"/apply/update",apply1);
                } catch (Exception e) {
                    e.printStackTrace();
    public void importApply(List<ApplyExcel> data, Boolean isCovered) {
        data.forEach(applyExcel -> {
            //查询用户信息
            User user = new User();
            user.setCardid(applyExcel.getIdCardNo());
            User user1 = userService.getOne(Condition.getQueryWrapper(user));
            if (null!=user1){
                //未报名的新增,已报名的不做处理
                if (null==user1.getIsApply()) {
                    Apply apply1 = new Apply();
                    apply1.setApplyStatus(2);
                    //默认为未考试状态
                    apply1.setIsExam(1);
                    apply1.setApplyTime(new Date());
                    apply1.setUserId(user1.getId());
                    this.save(apply1);
                    //修改保安报名状态
                    user1.setIsApply(1);
                    userService.updateById(user1);
                }else {
                    if (user1.getIsApply()==2) {
                        Apply apply1 = new Apply();
                        apply1.setApplyStatus(2);
                        //默认为未考试状态
                        apply1.setIsExam(1);
                        apply1.setApplyTime(new Date());
                        apply1.setUserId(user1.getId());
                        this.save(apply1);
                        //修改保安报名状态
                        user1.setIsApply(1);
                        userService.updateById(user1);
                    }
                }
            }
        });
    }
@@ -121,9 +141,9 @@
            String year = format.substring(2,4);
            String quarter  = null;
            String months = null;
            String days = null;
            int month = Integer.parseInt(format.substring(5,7));
            int day = Integer.parseInt(format.substring(8,10));
            String days = null;
            if (month>0 && month<=3){
                quarter = "C";
            }
@@ -141,19 +161,34 @@
            }
            if (day<=9){
                days = "0" + day;
            }else {
                days = ""+day;
            }
            String type = null;
            if (examPaper.getExamType()==1){
                type = "z";
            }
            if (examPaper.getExamType()==2){
                type = "m";
            }
            //获取考试名称前缀,去除数字,字母
            String examName
                = examPaper.getExamName().replaceAll("\\s*", "").replaceAll("[^(\\u4e00-\\u9fa5)]", "").substring(0,1);
            //前缀 = 年的最后两位  + 月份(两位) + 考试名称(中文拼音)首字母(去除数字,字母) + 考试类型 + 季度拼音首字母大写(春季就是 C)
//            String result = year
//                            + months
//                            + toFirstChar(examName).toUpperCase()
//                            + examPaper.getExamType()
//                            + quarter;
            //前缀 = 年的最后两位  + 月份(两位) + 日 (两位) + 考试类型 正式考试  z   模拟考试   m
            String result = year
                + months
                + toFirstChar(examName).toUpperCase()
                + examPaper.getExamType()
                + quarter;
                + days
                + type;
            //查询是当前前缀已生成的数量
            int count = getCandidateNoCount(result);
            int count = this.getCandidateNoCount(result);
            if (count==0){
                return result + "0000";
            }
@@ -313,4 +348,26 @@
    public List<Long> getApplyIds() {
        return baseMapper.getApplyIds();
    }
    /**
     * 查询报名清册信息
     * @param apply 报名信息
     * @return
     */
    @Override
    public Map<String,Object> getApplyDetailList(ApplyVO apply) {
        //创建  map 对象
        Map<String, Object> map = new HashMap<>(3);
        //查询考试信息
        ExamPaper paper = examPaperService.getById(apply.getExamId());
        map.put("examName",paper.getExamName());
        //查询已报名的总人数
        int num = baseMapper.getApplyDeatailNum(paper.getId());
        map.put("num",num);
        //查询已报名的的人信息集合
        List<ApplyVO> applyVOList = baseMapper.getApplyDetailList(paper.getId());
        map.put("applyList",applyVOList);
        //返回数据
        return map;
    }
}
src/main/java/org/springblade/modules/apply/vo/ApplyVO.java
@@ -83,4 +83,9 @@
     */
    private String realName;
    /**
     * 性别 1:男  2:女
     */
    private Integer sex;
}
src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -8,10 +8,12 @@
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.entity.ExamSubjectChoices;
import org.springblade.modules.exam.excel.ExamScoreExcel;
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.service.ExamSubjectChoicesService;
import org.springblade.modules.exam.vo.ExamResultVO;
import org.springblade.modules.exam.vo.ExamScoreVO;
import org.springframework.stereotype.Service;
@@ -32,6 +34,8 @@
public class ExamScoreServiceImpl extends ServiceImpl<ExamScoreMapper, ExamScore> implements ExamScoreService {
    private final ExamPaperService examPaperService;
    private final ExamSubjectChoicesService examSubjectChoicesService;
    /**
     * 自定义分页数据
@@ -65,25 +69,25 @@
        if (examScore.getExamResultVOS().size()>0){
            List<ExamResultVO> examResultVOS = examScore.getExamResultVOS();
            //获取试卷的内容(题号,答案)
            ExamPaper examPaper = new ExamPaper();
            examPaper.setId(examScore.getPapersId());
            List<ExamExaminationSubject> examExaminationSubjects
                = examPaperService.PagerSubject(examPaper).getExamExaminationSubjects();
//            ExamPaper examPaper = new ExamPaper();
//            examPaper.setId(examScore.getPapersId());
//            List<ExamExaminationSubject> examExaminationSubjects
//                = examPaperService.PagerSubject(examPaper).getExamExaminationSubjects();
            List<ExamSubjectChoices> list = examSubjectChoicesService.list();
            //比对考试结果
            //声明理论得分
            int theoryGrade = 0;
            for (ExamResultVO examResultVO : examResultVOS) {
                for (ExamExaminationSubject examExaminationSubject : examExaminationSubjects) {
                for (ExamSubjectChoices es: list) {
                    //对比题目id
                    if (examResultVO.getSubjectChoicesId().equals(examExaminationSubject.getExamSubjectChoices().getId())) {
                    if (examResultVO.getSubjectChoicesId().equals(es.getId())) {
                        //对比答案
                        if (examExaminationSubject.getExamSubjectChoices().getChoicesType() == 2 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 3){
                        if (es.getChoicesType() == 2 || es.getChoicesType() == 3){
                            //判断题逻辑
                            if (examResultVO.getValue().equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) {
                            if (examResultVO.getValue().equals(es.getAnswer())) {
                                theoryGrade += examResultVO.getGrade();
                            }
                        }else if(examExaminationSubject.getExamSubjectChoices().getChoicesType() == 0 || examExaminationSubject.getExamSubjectChoices().getChoicesType() == 1){
                        }else if(es.getChoicesType() == 0 || es.getChoicesType() == 1){
                            //处理多选题的答案排序
                            String[] split = examResultVO.getValue().split(",");
                            StringBuilder builder = new StringBuilder();
@@ -95,12 +99,12 @@
                            Arrays.sort(arrayCh);
                            String sub0 = Arrays.toString(arrayCh);
                            String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ","");
                            if (sub.equals(examExaminationSubject.getExamSubjectChoices().getAnswer())) {
                            if (sub.equals(es.getAnswer())) {
                                theoryGrade += examResultVO.getGrade();
                            }
                        }
                        //移除当前试卷题目答案对象
                        examExaminationSubjects.remove(examExaminationSubject);
                        list.remove(es);
                        break;
                    }
                }
@@ -117,12 +121,8 @@
            }
            //保存成绩数据
            int i = baseMapper.insert(examScore);
            //内网新增
            try {
                //arg.test01(arg.url+"/examScore/save",examScore);
            } catch (Exception e) {
                e.printStackTrace();
            }
            //修改考试状态
            if (i>0){
                //返回结果
                return true;