|
|
|
|
@ -70,9 +70,17 @@ public class ExamService {
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> teacherClasses(JwtUser teacher) {
|
|
|
|
|
requireTeacher(teacher);
|
|
|
|
|
return jdbc.query("select school_class_id as id, class_name as name from school_class " +
|
|
|
|
|
"where created_by=? and (status is null or status=1) and (class_type is null or class_type='TEACHING') order by create_time desc",
|
|
|
|
|
(rs, n) -> map("id", rs.getString("id"), "name", rs.getString("name")), teacher.getUserId());
|
|
|
|
|
StringBuilder sql = new StringBuilder("select school_class_id as id, class_name as name from school_class " +
|
|
|
|
|
"where school_id=? and (status is null or status=1) and (class_type is null or class_type='TEACHING')");
|
|
|
|
|
List<Object> args = new ArrayList<>();
|
|
|
|
|
args.add(teacher.getSchoolId());
|
|
|
|
|
if (!isTeacherAdmin(teacher)) {
|
|
|
|
|
sql.append(" and created_by=?");
|
|
|
|
|
args.add(teacher.getUserId());
|
|
|
|
|
}
|
|
|
|
|
sql.append(" order by create_time desc");
|
|
|
|
|
return jdbc.query(sql.toString(),
|
|
|
|
|
(rs, n) -> map("id", rs.getString("id"), "name", rs.getString("name")), args.toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> questions(JwtUser teacher, String type, String taskKey, String keyword) {
|
|
|
|
|
@ -820,7 +828,15 @@ public class ExamService {
|
|
|
|
|
|
|
|
|
|
private void validateOwnedClasses(JwtUser teacher, List<String> classIds) {
|
|
|
|
|
Set<String> owned = teacherClasses(teacher).stream().map(c -> text(c.get("id"))).collect(Collectors.toSet());
|
|
|
|
|
if (!owned.containsAll(classIds)) throw new AccessDeniedException("只能选择自己名下的教学班");
|
|
|
|
|
if (!owned.containsAll(classIds)) throw new AccessDeniedException(isTeacherAdmin(teacher)
|
|
|
|
|
? "只能选择本校教学班" : "只能选择自己名下的教学班");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isTeacherAdmin(JwtUser teacher) {
|
|
|
|
|
if (teacher == null || teacher.getUserId() == null || teacher.getSchoolId() == null) return false;
|
|
|
|
|
Integer count = jdbc.queryForObject("select count(*) from userinfo where user_id=? and school_id=? and role=3 and teacher_admin=1",
|
|
|
|
|
Integer.class, teacher.getUserId(), teacher.getSchoolId());
|
|
|
|
|
return count != null && count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> parseQuestionDocument(MultipartFile file) {
|
|
|
|
|
|