智慧保安后台管理-外网
Administrator
2021-08-04 60d7651a892baf03bf1bd6541cd4b1809a87d81e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
package org.springblade.modules.exam.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.arg;
import org.springblade.modules.exam.entity.ExamSubjectChoices;
import org.springblade.modules.exam.entity.ExamSubjectOption;
import org.springblade.modules.exam.mapper.ExamSubjectChoicesMapper;
import org.springblade.modules.exam.service.ExamSubjectChoicesService;
import org.springblade.modules.exam.service.ExamSubjectOptionService;
import org.springblade.modules.exam.vo.ExamSubjectChoicesVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
import java.util.List;
 
/**
 * 选择题服务实现类
 * @author zhongrj
 */
@Service
@AllArgsConstructor
public class ExamSubjectChoicesServiceImpl extends ServiceImpl<ExamSubjectChoicesMapper, ExamSubjectChoices> implements ExamSubjectChoicesService {
 
    private final ExamSubjectOptionService examSubjectOptionService;
 
    @Override
    public IPage<ExamSubjectChoicesVO> selectExamSubjectChoicesPage(IPage<ExamSubjectChoicesVO> page, ExamSubjectChoicesVO examSubjectChoices) {
        return page.setRecords(baseMapper.selectExamSubjectChoicesPage(page, examSubjectChoices));
    }
 
    @Override
    public IPage<ExamSubjectChoicesVO> getEexPaperChoices(IPage<ExamSubjectChoicesVO> page, ExamSubjectChoicesVO examSubjectChoices) {
        return page.setRecords(baseMapper.getEexPaperChoices(page, examSubjectChoices));
    }
 
    /**
     * 详情
     * @param examSubjectChoices 选择题信息对象
     */
    @Override
    public ExamSubjectChoicesVO selectExamSubjectChoicesInfo(ExamSubjectChoices examSubjectChoices) {
        return baseMapper.selectExamSubjectChoicesInfo(examSubjectChoices);
    }
 
    @Override
    public boolean updateChoicesValue(String id, String value) {
        return baseMapper.updateChoicesValue(id,value);
    }
 
    /**
     * 新增题目及选项信息
     * @param examSubjectChoices 题目信息对象
     * @return
     */
    @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 {
//                arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return status;
    }
}