Administrator
2021-08-05 61db25e82f9f6d635883cf55dbbe2dd39d692ff0
考试题目新增接口修改
3 files modified
129 ■■■■ changed files
src/main/java/org/springblade/modules/exam/mapper/ExamSubjectChoicesMapper.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamSubjectChoicesMapper.xml 7 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java 116 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/exam/mapper/ExamSubjectChoicesMapper.java
@@ -41,4 +41,10 @@
    boolean updateChoicesValue(String id,String value);
    /**
     * 根据 题目id 删除选项
     * @param id 题目id
     * @return
     */
    int removeBySubjectId(@Param("id")Long id);
}
src/main/java/org/springblade/modules/exam/mapper/ExamSubjectChoicesMapper.xml
@@ -47,6 +47,7 @@
        <id property="choicesType" column="choices_type"/>
        <id property="score" column="score"/>
        <id property="analysis" column="analysis"/>
        <id property="answer" column="answer"/>
        <id property="level" column="level"/>
        <id property="creator" column="creator"/>
        <id property="createDate" column="create_date"/>
@@ -55,6 +56,7 @@
        <id property="delFlag" column="del_flag"/>
        <id property="applicationCode" column="application_code"/>
        <id property="tenantCode" column="tenant_code"/>
        <id property="tktype" column="tktype"/>
        <result column="id" property="id"/>
        <collection property="examSubjectOptions" javaType="java.util.List" ofType="org.springblade.modules.exam.entity.ExamSubjectOption" autoMapping="true">
            <id property="id" column="eso_id"/>
@@ -84,4 +86,9 @@
    <update id="updateChoicesValue">
        update exam_subject_choices set score = #{value} where id = #{id}
    </update>
    <!--根据 题目id 删除选项-->
    <delete id="removeBySubjectId">
        delete from exam_subject_option where subject_choices_id = #{id}
    </delete>
</mapper>
src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
@@ -59,38 +59,92 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveSubjectChoicesAndOption(ExamSubjectChoicesVO examSubjectChoices) {
        ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
        subjectChoices.setCreateDate(new Date());
        subjectChoices.setDelFlag(0);
        subjectChoices.setAnswer(examSubjectChoices.getAnswer());
        if (null!=examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis()!=""){
            subjectChoices.setAnalysis(examSubjectChoices.getAnalysis());
        }
        subjectChoices.setCreator(examSubjectChoices.getCreator());
        subjectChoices.setChoicesType(examSubjectChoices.getChoicesType());
        subjectChoices.setSubjectName(examSubjectChoices.getSubjectName());
        subjectChoices.setScore(examSubjectChoices.getScore());
        subjectChoices.setTktype(examSubjectChoices.getTktype());
        //题目新增
        boolean status = this.save(subjectChoices);
        //判断类型,单选,多选
        if (examSubjectChoices.getChoicesType()==0 || examSubjectChoices.getChoicesType()==1 || examSubjectChoices.getChoicesType()==3){
            //选项新增
            List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions();
            examSubjectOptions.forEach(examSubjectOption -> {
                examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
                examSubjectOption.setCreateDate(new Date());
                examSubjectOption.setDelFlag(0);
                //新增
                examSubjectOptionService.save(examSubjectOption);
            });
            return true;
        }
        //内网数据同步
        try {
        boolean status = false;
        //新增
        if (null == examSubjectChoices.getId()) {
            ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
            subjectChoices.setCreateDate(new Date());
            subjectChoices.setDelFlag(0);
            subjectChoices.setAnswer(examSubjectChoices.getAnswer());
            if (null != examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis() != "") {
                subjectChoices.setAnalysis(examSubjectChoices.getAnalysis());
            }
            subjectChoices.setCreator(examSubjectChoices.getCreator());
            subjectChoices.setChoicesType(examSubjectChoices.getChoicesType());
            subjectChoices.setSubjectName(examSubjectChoices.getSubjectName());
            subjectChoices.setScore(examSubjectChoices.getScore());
            subjectChoices.setTktype(examSubjectChoices.getTktype());
            //题目新增
            status = this.save(subjectChoices);
            //判断类型,单选,多选,实操
            if (examSubjectChoices.getChoicesType() == 0 || examSubjectChoices.getChoicesType() == 1 || examSubjectChoices.getChoicesType() == 3) {
                //选项新增
                List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions();
                examSubjectOptions.forEach(examSubjectOption -> {
                    examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
                    examSubjectOption.setCreateDate(new Date());
                    examSubjectOption.setDelFlag(0);
                    //新增
                    examSubjectOptionService.save(examSubjectOption);
                });
                return true;
            }
            //内网数据同步
            try {
//                arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
        } catch (Exception e) {
            e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else {
            //修改
            ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
            subjectChoices.setId(examSubjectChoices.getId());
            subjectChoices.setModifyDate(new Date());
            subjectChoices.setAnswer(examSubjectChoices.getAnswer());
            if (null != examSubjectChoices.getAnalysis() && examSubjectChoices.getAnalysis() != "") {
                subjectChoices.setAnalysis(examSubjectChoices.getAnalysis());
            }
            subjectChoices.setModifier(examSubjectChoices.getCreator());
            subjectChoices.setChoicesType(examSubjectChoices.getChoicesType());
            subjectChoices.setSubjectName(examSubjectChoices.getSubjectName());
            subjectChoices.setScore(examSubjectChoices.getScore());
            subjectChoices.setTktype(examSubjectChoices.getTktype());
            //题目修改
            status = this.updateById(subjectChoices);
            //判断类型,单选,多选
            if (examSubjectChoices.getChoicesType() == 0 || examSubjectChoices.getChoicesType() == 1) {
                //选项修改
                List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions();
                examSubjectOptions.forEach(examSubjectOption -> {
                    examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
                    examSubjectOption.setModifyDate(new Date());
                    examSubjectOption.setModifier(examSubjectChoices.getCreator());
                    //修改
                    examSubjectOptionService.updateById(examSubjectOption);
                });
                return true;
            }
            //实操
            if (examSubjectChoices.getChoicesType() == 3) {
                //先将选项删除
                baseMapper.removeBySubjectId(examSubjectChoices.getId());
                //选项新增
                List<ExamSubjectOption> examSubjectOptions = examSubjectChoices.getExamSubjectOptions();
                examSubjectOptions.forEach(examSubjectOption -> {
                    examSubjectOption.setSubjectChoicesId(subjectChoices.getId());
                    examSubjectOption.setCreateDate(new Date());
                    examSubjectOption.setDelFlag(0);
                    //新增
                    examSubjectOptionService.save(examSubjectOption);
                });
                return true;
            }
            //内网数据同步
            try {
//                arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return status;
    }