|
@ -1,5 +1,8 @@
|
1
|
1
|
package com.css.oa.exam.assign.service;
|
2
|
2
|
|
|
3
|
import com.css.oa.exam.admin.bean.Admin;
|
|
4
|
import com.css.oa.exam.assign.bean.AssignQueryReq;
|
|
5
|
import com.css.oa.exam.assign.bean.Condition;
|
3
|
6
|
import com.css.oa.exam.assign.bean.MyAdmWrap;
|
4
|
7
|
import com.css.oa.exam.assign.repository.Assign;
|
5
|
8
|
import com.css.oa.exam.assign.repository.IAssignRepository;
|
|
@ -8,17 +11,241 @@ import com.css.oa.exam.exam.repository.Exam;
|
8
|
11
|
import com.css.oa.exam.exam.repository.IExamRepository;
|
9
|
12
|
import com.css.oa.exam.room.repository.IRoomRepository;
|
10
|
13
|
import com.css.oa.exam.room.repository.Room;
|
|
14
|
import com.css.oa.exam.student.repository.Student;
|
11
|
15
|
import com.css.oa.exam.util.CopyObjTool;
|
12
|
16
|
import lombok.extern.slf4j.Slf4j;
|
|
17
|
import org.apache.http.util.TextUtils;
|
13
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
19
|
import org.springframework.data.domain.Page;
|
|
20
|
import org.springframework.data.domain.PageRequest;
|
|
21
|
import org.springframework.data.jpa.domain.Specification;
|
14
|
22
|
import org.springframework.stereotype.Service;
|
15
|
23
|
|
|
24
|
import javax.persistence.criteria.*;
|
16
|
25
|
import java.util.*;
|
17
|
26
|
|
18
|
27
|
@Slf4j
|
19
|
28
|
@Service
|
20
|
29
|
public class AdmService extends BaseAssignService {
|
21
|
30
|
|
|
31
|
private Specification<Assign> getSpec(Condition condition) {
|
|
32
|
Specification<Assign> spec = new Specification<Assign>() {
|
|
33
|
@Override
|
|
34
|
public Predicate toPredicate(Root<Assign> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
35
|
List<Predicate> predicateList = new ArrayList<>();
|
|
36
|
|
|
37
|
//0.所属考试
|
|
38
|
String exam_id = condition.exam_id;
|
|
39
|
if (!TextUtils.isEmpty(exam_id)) {
|
|
40
|
predicateList.add(criteriaBuilder.equal(root.get("exam_id").as(String.class), exam_id));
|
|
41
|
}
|
|
42
|
//学生名、身份证号查询学生信息
|
|
43
|
if (condition.studentIds.size() > 0) {
|
|
44
|
Path<String> path = root.get("student_id");//定义查询的字段
|
|
45
|
CriteriaBuilder.In<String> in = criteriaBuilder.in(path);
|
|
46
|
for (String studentId : condition.studentIds) {
|
|
47
|
in.value(studentId);//存入值
|
|
48
|
}
|
|
49
|
predicateList.add(in);
|
|
50
|
}
|
|
51
|
|
|
52
|
//我能看到的所有审核
|
|
53
|
Admin admin = Admin.getAdminByToken(token);
|
|
54
|
if (!TextUtils.isEmpty(admin.my_unit_id)) {
|
|
55
|
//1,如果是我创建的审核
|
|
56
|
Predicate p1 = criteriaBuilder.equal(root.get("create_unit_id").as(String.class), admin.my_unit_id);
|
|
57
|
//2,审核权到了我手里边
|
|
58
|
Predicate p2 = criteriaBuilder.equal(root.get("curr_unit_id").as(String.class), admin.my_unit_id);
|
|
59
|
//3,如果不是我创建的审核,要求审核不是驳回状态
|
|
60
|
Predicate or;
|
|
61
|
//获取room_ids
|
|
62
|
List<String> ids = assignRecord.queryByUnitId(admin.my_unit_id);
|
|
63
|
if (ids.size() > 0) {
|
|
64
|
Path<String> path = root.get("uuid");//定义查询的字段
|
|
65
|
CriteriaBuilder.In<String> in = criteriaBuilder.in(path);
|
|
66
|
for (int i = 0; i < ids.size(); i++) {
|
|
67
|
in.value(ids.get(i));//存入值
|
|
68
|
}
|
|
69
|
Predicate is_reject = criteriaBuilder.notEqual(root.get("is_reject").as(Integer.class), BoolState.YES);
|
|
70
|
Predicate p3 = criteriaBuilder.and(in, is_reject);
|
|
71
|
or = criteriaBuilder.or(p1, p2, p3);
|
|
72
|
} else {
|
|
73
|
or = criteriaBuilder.or(p1, p2);
|
|
74
|
}
|
|
75
|
predicateList.add(or);
|
|
76
|
}
|
|
77
|
String series_name = condition.series_name;
|
|
78
|
if (!TextUtils.isEmpty(series_name)) {
|
|
79
|
|
|
80
|
}
|
|
81
|
String room_name = condition.room_name;
|
|
82
|
if (!TextUtils.isEmpty(room_name)) {
|
|
83
|
String pattern = "%" + room_name + "%";
|
|
84
|
predicateList.add(criteriaBuilder.like(root.get("room_name").as(String.class), pattern));
|
|
85
|
}
|
|
86
|
int isAssign = condition.is_assign;
|
|
87
|
if (isAssign != BoolState.DEFULT) {
|
|
88
|
Path<String> path = root.get("room_id");//定义查询的字段
|
|
89
|
if (condition.is_assign == BoolState.YES) {
|
|
90
|
predicateList.add(criteriaBuilder.isNotNull(path));
|
|
91
|
} else {
|
|
92
|
predicateList.add(criteriaBuilder.isNull(path));
|
|
93
|
}
|
|
94
|
}
|
|
95
|
String room_id = condition.room_id;
|
|
96
|
if (!TextUtils.isEmpty(room_id)) {
|
|
97
|
predicateList.add(criteriaBuilder.equal(root.get("room_id").as(String.class), room_id));
|
|
98
|
}
|
|
99
|
String place_id = condition.place_id;
|
|
100
|
if (!TextUtils.isEmpty(place_id)) {
|
|
101
|
predicateList.add(criteriaBuilder.equal(root.get("place_id").as(String.class), place_id));
|
|
102
|
}
|
|
103
|
String area = condition.area;
|
|
104
|
if (!TextUtils.isEmpty(area)) {
|
|
105
|
predicateList.add(criteriaBuilder.equal(root.get("area").as(String.class), area));
|
|
106
|
}
|
|
107
|
//4.审核状态
|
|
108
|
// String verify_state = condition.verify_state;
|
|
109
|
// if (!TextUtils.isEmpty(verify_state)) {
|
|
110
|
// if (verify_state.equalsIgnoreCase(DropdownVerifyState.WAIT_COMMIT)) {
|
|
111
|
// //待提交
|
|
112
|
// Predicate isInMine = criteriaBuilder.equal(root.get("curr_unit_id").as(String.class), admin.my_unit_id);
|
|
113
|
// Predicate isMeCreate = criteriaBuilder.equal(root.get("create_unit_id").as(String.class), admin.my_unit_id);
|
|
114
|
// Predicate and = criteriaBuilder.and(isInMine, isMeCreate);
|
|
115
|
// predicateList.add(and);
|
|
116
|
// } else if (verify_state.equalsIgnoreCase(DropdownVerifyState.WAIT_VERIFY)) {
|
|
117
|
// //待我审核
|
|
118
|
// Predicate isInMine = criteriaBuilder.equal(root.get("curr_unit_id").as(String.class), admin.my_unit_id);
|
|
119
|
// Predicate isNotMeCreate = criteriaBuilder.notEqual(root.get("create_unit_id").as(String.class), admin.my_unit_id);
|
|
120
|
// Predicate and = criteriaBuilder.and(isInMine, isNotMeCreate);
|
|
121
|
// predicateList.add(and);
|
|
122
|
// } else if (verify_state.equalsIgnoreCase(DropdownVerifyState.ING)) {
|
|
123
|
// //上级审核中
|
|
124
|
// Predicate noInMine = criteriaBuilder.notEqual(root.get("curr_unit_id").as(String.class), admin.my_unit_id);
|
|
125
|
// Predicate isNotGree = criteriaBuilder.notEqual(root.get("curr_unit_id").as(String.class), getTopCode());
|
|
126
|
// Predicate and = criteriaBuilder.and(noInMine, isNotGree);
|
|
127
|
// predicateList.add(and);
|
|
128
|
// } else if (verify_state.equalsIgnoreCase(DropdownVerifyState.ED)) {
|
|
129
|
// //审核通过
|
|
130
|
// predicateList.add(criteriaBuilder.equal(root.get("curr_unit_id").as(String.class), getTopCode()));
|
|
131
|
// }
|
|
132
|
// }
|
|
133
|
// - - - - - - - - - - - - 下边是准考证查询页面所使用的 - - - - - - - - - - - - -
|
|
134
|
String adm_num = condition.adm_num;
|
|
135
|
if (!TextUtils.isEmpty(adm_num)) {
|
|
136
|
String pattern = "%" + adm_num + "%";
|
|
137
|
predicateList.add(criteriaBuilder.like(root.get("adm_num").as(String.class), pattern));
|
|
138
|
}
|
|
139
|
String place_name = condition.place_name;
|
|
140
|
if (!TextUtils.isEmpty(place_name)) {
|
|
141
|
String pattern = "%" + place_name + "%";
|
|
142
|
predicateList.add(criteriaBuilder.like(root.get("place_name").as(String.class), pattern));
|
|
143
|
}
|
|
144
|
int isGenerate = condition.is_generate;
|
|
145
|
if (isGenerate == BoolState.NO) {
|
|
146
|
predicateList.add(criteriaBuilder.isNull(root.get("adm_num").as(String.class)));
|
|
147
|
} else if (isGenerate == BoolState.YES) {
|
|
148
|
predicateList.add(criteriaBuilder.isNotNull(root.get("adm_num").as(String.class)));
|
|
149
|
}
|
|
150
|
int is_sended = condition.is_sended;
|
|
151
|
if (is_sended != BoolState.DEFULT) {
|
|
152
|
predicateList.add(criteriaBuilder.equal(root.get("is_sended").as(Integer.class), is_sended));
|
|
153
|
}
|
|
154
|
//分配完毕考场,并一级审核通过,才能查询到准考证
|
|
155
|
int isGree = condition.is_gree;
|
|
156
|
if (isGree != BoolState.DEFULT) {
|
|
157
|
predicateList.add(criteriaBuilder.equal(root.get("curr_unit_id").as(String.class), getTopCode()));
|
|
158
|
}
|
|
159
|
|
|
160
|
Predicate[] pre = new Predicate[predicateList.size()];
|
|
161
|
pre = predicateList.toArray(pre);
|
|
162
|
return criteriaQuery.where(pre).getRestriction();
|
|
163
|
}
|
|
164
|
};
|
|
165
|
return spec;
|
|
166
|
}
|
|
167
|
|
|
168
|
private Specification<Student> getStudentSpec(Condition condition) {
|
|
169
|
Specification<Student> spec = new Specification<Student>() {
|
|
170
|
@Override
|
|
171
|
public Predicate toPredicate(Root<Student> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
172
|
List<Predicate> predicateList = new ArrayList<>();
|
|
173
|
//考生名、身份证号、单位名
|
|
174
|
String student_name = condition.student_name;
|
|
175
|
if (!TextUtils.isEmpty(student_name)) {
|
|
176
|
String pattern = "%" + student_name + "%";
|
|
177
|
predicateList.add(criteriaBuilder.like(root.get("name").as(String.class), pattern));
|
|
178
|
}
|
|
179
|
String card_num = condition.card_num;
|
|
180
|
if (!TextUtils.isEmpty(card_num)) {
|
|
181
|
String pattern = "%" + card_num + "%";
|
|
182
|
predicateList.add(criteriaBuilder.like(root.get("card_num").as(String.class), pattern));
|
|
183
|
}
|
|
184
|
String unit_name = condition.unit_name;
|
|
185
|
if (!TextUtils.isEmpty(unit_name)) {
|
|
186
|
String pattern = "%" + unit_name + "%";
|
|
187
|
predicateList.add(criteriaBuilder.like(root.get("unit_name").as(String.class), pattern));
|
|
188
|
}
|
|
189
|
|
|
190
|
Predicate[] pre = new Predicate[predicateList.size()];
|
|
191
|
pre = predicateList.toArray(pre);
|
|
192
|
return criteriaQuery.where(pre).getRestriction();
|
|
193
|
}
|
|
194
|
};
|
|
195
|
return spec;
|
|
196
|
}
|
|
197
|
|
|
198
|
public Map queryPage(AssignQueryReq req) {
|
|
199
|
if (req.pageSize == 0) {
|
|
200
|
req.pageSize = 20;
|
|
201
|
}
|
|
202
|
Specification<Assign> spec = getSpec(req.condition);
|
|
203
|
PageRequest pageReques = PageRequest.of(req.curPage, req.pageSize);
|
|
204
|
Long count = repository.count(spec);
|
|
205
|
Page<Assign> pages = repository.findAll(spec, pageReques);
|
|
206
|
List<Assign> list = pages.getContent();
|
|
207
|
setProperties(list);
|
|
208
|
List<MyAdmWrap> wraps = getWraps(list);
|
|
209
|
|
|
210
|
Map map = new LinkedHashMap();
|
|
211
|
map.put("total", count);
|
|
212
|
map.put("assigns", list);
|
|
213
|
map.put("adms", wraps);
|
|
214
|
return map;
|
|
215
|
}
|
|
216
|
|
|
217
|
public Map queryCondition(AssignQueryReq req) {
|
|
218
|
if (req.pageSize == 0) {
|
|
219
|
req.pageSize = 20;
|
|
220
|
}
|
|
221
|
//考生名、身份证号查询考生
|
|
222
|
List<Student> students = studentRepository.findAll(getStudentSpec(req.condition));
|
|
223
|
if (students.size() == 0) {
|
|
224
|
Map map = new LinkedHashMap();
|
|
225
|
map.put("total", 0);
|
|
226
|
map.put("list", null);
|
|
227
|
return map;
|
|
228
|
}
|
|
229
|
List<String> studentIds = new ArrayList<>();
|
|
230
|
for (Student stu : students) {
|
|
231
|
studentIds.add(stu.getUuid());
|
|
232
|
}
|
|
233
|
req.condition.studentIds = studentIds;
|
|
234
|
Specification<Assign> spec = getSpec(req.condition);
|
|
235
|
PageRequest pageReques = PageRequest.of(req.curPage, req.pageSize);
|
|
236
|
Long count = repository.count(spec);
|
|
237
|
Page<Assign> pages = repository.findAll(spec, pageReques);
|
|
238
|
List<Assign> list = pages.getContent();
|
|
239
|
setProperties(list);
|
|
240
|
List<MyAdmWrap> wraps = getWraps(list);
|
|
241
|
|
|
242
|
Map map = new LinkedHashMap();
|
|
243
|
map.put("total", count);
|
|
244
|
map.put("assigns", list);
|
|
245
|
map.put("adms", wraps);
|
|
246
|
return map;
|
|
247
|
}
|
|
248
|
|
22
|
249
|
@Autowired
|
23
|
250
|
IAssignRepository repository;
|
24
|
251
|
|
|
@ -85,19 +312,26 @@ public class AdmService extends BaseAssignService {
|
85
|
312
|
List<Assign> assigns = repository.myAdm(student_id);
|
86
|
313
|
setProperties(assigns);
|
87
|
314
|
|
|
315
|
List<MyAdmWrap> wraps = getWraps(assigns);
|
|
316
|
Map map = new LinkedHashMap();
|
|
317
|
map.put("total", wraps.size());
|
|
318
|
map.put("list", wraps);
|
|
319
|
return map;
|
|
320
|
}
|
|
321
|
|
|
322
|
private List<MyAdmWrap> getWraps(List<Assign> assigns) {
|
88
|
323
|
List<MyAdmWrap> wraps = new ArrayList<>();
|
89
|
324
|
for (Assign assign : assigns) {
|
90
|
325
|
MyAdmWrap wrap = new MyAdmWrap();
|
91
|
326
|
CopyObjTool.copyProperties(assign, wrap);
|
92
|
327
|
Exam exam = examRepository.findById(assign.getExam_id()).get();
|
|
328
|
wrap.setExam_name("" + exam.getYear() + exam.getExam_name());
|
93
|
329
|
CopyObjTool.copyProperties(exam, wrap);
|
94
|
|
wrap.setXilie_jibie(exam.getExam_name() +" "+ exam.getLevel_name());
|
95
|
|
|
|
330
|
wrap.setXilie_jibie(exam.getExam_name() + " " + exam.getLevel_name());
|
|
331
|
|
96
|
332
|
wraps.add(wrap);
|
97
|
333
|
}
|
98
|
|
Map map = new LinkedHashMap();
|
99
|
|
map.put("total", wraps.size());
|
100
|
|
map.put("list", wraps);
|
101
|
|
return map;
|
|
334
|
return wraps;
|
102
|
335
|
}
|
|
336
|
|
103
|
337
|
}
|