zhuhaiwen 3 years ago
parent
commit
53533fcd60

+ 6 - 6
oa-app/src/main/java/com/css/oa/exam/exam/controller/ExamController.java

14
import java.util.List;
14
import java.util.List;
15
import java.util.Map;
15
import java.util.Map;
16
16
17
/**
18
 * @author :朱海文
19
 * @version : 1.0
20
 * @description :考场控制器
21
 * @date :2021/3/5
22
 */
23
@Api(tags = {"考试管理"})
17
@Api(tags = {"考试管理"})
24
@RestController
18
@RestController
25
@RequestMapping("/exam")
19
@RequestMapping("/exam")
114
    public Result add(@RequestBody Exam exam) {
108
    public Result add(@RequestBody Exam exam) {
115
        Result<Map> result;
109
        Result<Map> result;
116
        try {
110
        try {
111
            String token = getToken();
112
            mService.setToken(token);
117
            String msg = mService.add(exam);
113
            String msg = mService.add(exam);
118
            result = setResult(msg);
114
            result = setResult(msg);
119
        } catch (Exception e) {
115
        } catch (Exception e) {
128
    public Result update(@RequestBody Exam obj) {
124
    public Result update(@RequestBody Exam obj) {
129
        Result<Map> result;
125
        Result<Map> result;
130
        try {
126
        try {
127
            String token = getToken();
128
            mService.setToken(token);
131
            if (TextUtils.isEmpty(obj.getUuid())) {
129
            if (TextUtils.isEmpty(obj.getUuid())) {
132
                return setErr("uuid参数不能为空");
130
                return setErr("uuid参数不能为空");
133
            }
131
            }
145
    public Result delete(@RequestBody List<String> ids) {
143
    public Result delete(@RequestBody List<String> ids) {
146
        Result<Map> result;
144
        Result<Map> result;
147
        try {
145
        try {
146
            String token = getToken();
147
            mService.setToken(token);
148
            mService.delete(ids);
148
            mService.delete(ids);
149
            result = setResult();
149
            result = setResult();
150
        } catch (Exception e) {
150
        } catch (Exception e) {

+ 0 - 6
oa-app/src/main/java/com/css/oa/exam/exam/repository/Exam.java

45
    @Column(name = "SUBJECT_NAME")
45
    @Column(name = "SUBJECT_NAME")
46
    private String subject_name;
46
    private String subject_name;
47
47
48
    @Column(name = "SERIES_ID")
49
    private String series_id;
50
51
    @Column(name = "SERIES_NAME")
48
    @Column(name = "SERIES_NAME")
52
    private String series_name;
49
    private String series_name;
53
50
54
    @Column(name = "LEVEL_ID")
55
    private String level_id;
56
57
    @Column(name = "LEVEL_NAME")
51
    @Column(name = "LEVEL_NAME")
58
    private String level_name;
52
    private String level_name;
59
53

+ 34 - 23
oa-app/src/main/java/com/css/oa/exam/exam/service/ExamService.java

1
package com.css.oa.exam.exam.service;
1
package com.css.oa.exam.exam.service;
2
2
3
import com.css.oa.exam.admin.bean.Admin;
4
import com.css.oa.exam.admin.repository.IUnitRepository;
5
import com.css.oa.exam.admin.repository.Unit;
3
import com.css.oa.exam.base.BaseService;
6
import com.css.oa.exam.base.BaseService;
4
import com.css.oa.exam.exam.repository.IExamRepository;
7
import com.css.oa.exam.exam.repository.IExamRepository;
5
import com.css.oa.exam.exam.repository.Exam;
8
import com.css.oa.exam.exam.repository.Exam;
6
import com.css.oa.exam.subject.repository.ISubjectRepository;
7
import com.css.oa.exam.subject.repository.Subject;
8
import com.css.oa.exam.util.UpdateObjectTool;
9
import com.css.oa.exam.util.UpdateObjectTool;
9
import com.css.oa.utils.UUIDGenerator;
10
import com.css.oa.utils.UUIDGenerator;
10
import lombok.extern.slf4j.Slf4j;
11
import lombok.extern.slf4j.Slf4j;
27
28
28
    @Autowired
29
    @Autowired
29
    IExamRepository repository;
30
    IExamRepository repository;
31
30
    @Autowired
32
    @Autowired
31
    ISubjectRepository subjectRepository;
33
    IUnitRepository unitRepository;
34
35
    private void checkPermission(String msg) throws Exception {
36
        String adminUnitId = Admin.getAdminUnitId(token);
37
        List<Unit> unitList = unitRepository.getUnitBy(adminUnitId);
38
        if (unitList.size() > 0) {
39
            Unit unit = unitList.get(0);
40
            String parent_unit_id = unit.getParent_unit_id();
41
            if (!TextUtils.isEmpty(parent_unit_id)) {
42
                throw new Exception(msg);
43
            }
44
        }
45
    }
32
46
33
    private String addSubject(Exam obj){
47
    private String saveExam(Exam obj){
34
        if(TextUtils.isEmpty(obj.getSubject_code())){
48
        if(TextUtils.isEmpty(obj.getSubject_code())){
35
            return "subject_code不能为空";
49
            return "subject_code不能为空";
36
        }
50
        }
37
        List<Subject> subjects = subjectRepository.queryById(obj.getSubject_code());
38
        if(subjects.size() == 0){
39
            return "您查找的subject_code不存在";
51
        if(TextUtils.isEmpty(obj.getSubject_name())){
52
            return "subject_name不能为空";
53
        }
54
        if(TextUtils.isEmpty(obj.getSeries_name())){
55
            return "series_name不能为空";
56
        }
57
        if(TextUtils.isEmpty(obj.getSeries_name())){
58
            return "level_name不能为空";
40
        }
59
        }
41
        Subject subject = subjects.get(0);
42
        obj.setSubject_name(subject.getSubject_name());
43
//
44
//        int a = subject.getSeries();
45
//        String seriesName = SubjectMapping.getSeriesName(a);
46
//        obj.setSeries_name(seriesName);
47
//
48
//        int b = subject.getLevel();
49
//        String levelName = SubjectMapping.getLevelName(b);
50
//        obj.setLevel_name(levelName);
51
52
        repository.save(obj);
60
        repository.save(obj);
53
        return "保存成功";
61
        return "保存成功";
54
    }
62
    }
55
63
56
    @Override
64
    @Override
57
    public String add(Exam obj) {
65
    public String add(Exam obj) throws Exception {
58
        System.out.println("传入的obj => " + obj.toString());
66
        System.out.println("传入的obj => " + obj.toString());
67
        checkPermission("管理员所在的单位没有创建考试的权限");
59
        if (obj.getUuid() == null) {
68
        if (obj.getUuid() == null) {
60
            String id = UUIDGenerator.getUUID();
69
            String id = UUIDGenerator.getUUID();
61
            obj.setUuid(id);
70
            obj.setUuid(id);
73
        if (TextUtils.isEmpty(obj.getUpdate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
82
        if (TextUtils.isEmpty(obj.getUpdate_user()) || obj.getCreate_user().equalsIgnoreCase("null")) {
74
            obj.setUpdate_user("系统");
83
            obj.setUpdate_user("系统");
75
        }
84
        }
76
        return addSubject(obj);
85
        return saveExam(obj);
77
    }
86
    }
78
87
79
    @Override
88
    @Override
80
    public String update(Exam newObj) {
89
    public String update(Exam newObj) throws Exception {
90
        checkPermission("管理员所在的单位没有编辑考试的权限");
81
        Optional<Exam> byId = repository.findById(newObj.getUuid());
91
        Optional<Exam> byId = repository.findById(newObj.getUuid());
82
        Exam old = byId.get();
92
        Exam old = byId.get();
83
        UpdateObjectTool.copyNullProperties(old, newObj);
93
        UpdateObjectTool.copyNullProperties(old, newObj);
84
        return addSubject(newObj);
94
        return saveExam(newObj);
85
    }
95
    }
86
96
87
    @Override
97
    @Override
150
    }
160
    }
151
161
152
    @Override
162
    @Override
153
    public void delete(List<String> ids) {
163
    public void delete(List<String> ids) throws Exception {
164
        checkPermission("管理员所在的单位没有删除考试的权限");
154
        //ids = ["0","2","3"]
165
        //ids = ["0","2","3"]
155
        repository.deleteRealByIds(ids);
166
        repository.deleteRealByIds(ids);
156
    }
167
    }

+ 3 - 3
oa-app/src/main/java/com/css/oa/exam/exam/service/IExamService.java

7
7
8
public interface IExamService {
8
public interface IExamService {
9
9
10
    String add(Exam exam);
10
    String add(Exam exam) throws Exception;
11
11
12
    Map queryPage(Map map, int curPage, int pageSize);
12
    Map queryPage(Map map, int curPage, int pageSize);
13
13
14
    List queryToYear();
14
    List queryToYear();
15
15
16
    String update(Exam newExam);
16
    String update(Exam newExam) throws Exception;
17
17
18
    void delete(List<String> ids);
18
    void delete(List<String> ids) throws Exception;
19
19
20
    List queryAll(String exam_name);
20
    List queryAll(String exam_name);
21
21