|
@@ -1,11 +1,17 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.UserDataRule;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.jpa.SpecUtils;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.enums.CourseLevel;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.dao.enums.SelectType;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordIllegallyService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.UserDataRules;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.examaudit.ExamAuditInfo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.examaudit.ExamAuditQuery;
|
|
|
+import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExamSettingsCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -18,7 +24,6 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
@@ -30,31 +35,65 @@ public class ExamRecordIllegallyServiceImpl implements ExamRecordIllegallyServic
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Override
|
|
|
- public Page<ExamAuditInfo> getExamRecordIllegallyList(UserDataRules rules, ExamAuditQuery query) {
|
|
|
+ public Page<ExamAuditInfo> getExamRecordIllegallyList(ExamAuditQuery query, UserDataRule courseRule,
|
|
|
+ UserDataRule orgRule) {
|
|
|
Check.isNull(query, "请求参数不能为空!");
|
|
|
Check.isNull(query.getExamId(), "请先选择考试!");
|
|
|
|
|
|
Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize());
|
|
|
- int offset = (query.getPageNo() - 1) * query.getPageSize();
|
|
|
+ if (courseRule.assertEmptyQueryResult() || orgRule.assertEmptyQueryResult()) {
|
|
|
+ return Page.empty(pageable);
|
|
|
+ }
|
|
|
|
|
|
- String countSql = this.queryExamRecordIllegallyListSql(query, true);
|
|
|
- String querySql = this.queryExamRecordIllegallyListSql(query, false);
|
|
|
+ int offset = (query.getPageNo() - 1) * query.getPageSize();
|
|
|
+ String countSql = this.queryExamRecordIllegallyListSql(query, true, courseRule, orgRule);
|
|
|
+ String querySql = this.queryExamRecordIllegallyListSql(query, false, courseRule, orgRule);
|
|
|
String pageSql = querySql + " limit " + offset + "," + query.getPageSize();
|
|
|
|
|
|
+ if (SelectType.EXPORT == query.getSelectType()) {
|
|
|
+ // 仅导出结果
|
|
|
+ List<ExamAuditInfo> list = jdbcTemplate.query(querySql, new BeanPropertyRowMapper(ExamAuditInfo.class));
|
|
|
+ // 填充其它信息
|
|
|
+ this.fillOtherInfo(list, query.getExamId());
|
|
|
+ return new PageImpl<>(list, pageable, list.size());
|
|
|
+ }
|
|
|
+
|
|
|
Long totalElements = jdbcTemplate.queryForObject(countSql, Long.class);
|
|
|
if (totalElements == null || totalElements == 0) {
|
|
|
- return new PageImpl<>(new ArrayList<>(), pageable, 0);
|
|
|
+ return Page.empty(pageable);
|
|
|
}
|
|
|
|
|
|
List<ExamAuditInfo> list = jdbcTemplate.query(pageSql, new BeanPropertyRowMapper(ExamAuditInfo.class));
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
- return new PageImpl<>(new ArrayList<>(), pageable, 0);
|
|
|
+ return Page.empty(pageable);
|
|
|
}
|
|
|
|
|
|
+ // 填充其它信息
|
|
|
+ this.fillOtherInfo(list, query.getExamId());
|
|
|
+
|
|
|
return new PageImpl<>(list, pageable, totalElements);
|
|
|
}
|
|
|
|
|
|
- private String queryExamRecordIllegallyListSql(ExamAuditQuery query, boolean isCount) {
|
|
|
+ private void fillOtherInfo(List<ExamAuditInfo> list, Long examId) {
|
|
|
+ ExamSettingsCacheBean exam = CacheHelper.getExamSettings(examId);
|
|
|
+ for (ExamAuditInfo info : list) {
|
|
|
+ // 考试名称
|
|
|
+ info.setExamName(exam.getName());
|
|
|
+
|
|
|
+ // 学习中心名称
|
|
|
+ OrgCacheBean org = CacheHelper.getOrg(info.getOrgId());
|
|
|
+ info.setOrgName(org.getName());
|
|
|
+
|
|
|
+ // 课程信息
|
|
|
+ CourseCacheBean course = CacheHelper.getCourse(info.getCourseId());
|
|
|
+ info.setCourseCode(course.getCode());
|
|
|
+ info.setCourseName(course.getName());
|
|
|
+ info.setCourseLevel(CourseLevel.getCourseLevel(course.getLevel()).getTitle());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String queryExamRecordIllegallyListSql(ExamAuditQuery query, boolean isCount, UserDataRule courseRule,
|
|
|
+ UserDataRule orgRule) {
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
if (isCount) {
|
|
|
sql.append(" select count(1)");
|
|
@@ -87,12 +126,44 @@ public class ExamRecordIllegallyServiceImpl implements ExamRecordIllegallyServic
|
|
|
}
|
|
|
sql.append(" )");
|
|
|
|
|
|
- if (query.getCourseId() != null) {
|
|
|
- sql.append(" and rd.course_id = ").append(query.getCourseId());
|
|
|
+ if (courseRule.assertNeedQueryRefIds()) {
|
|
|
+ // 限定课程数据权限范围
|
|
|
+ if (query.getCourseId() != null) {
|
|
|
+ if (courseRule.getRefIds().contains(query.getCourseId())) {
|
|
|
+ sql.append(" and rd.course_id = ").append(query.getCourseId());
|
|
|
+ } else {
|
|
|
+ // 不在数据权限范围内,无效查询
|
|
|
+ sql.append(" and rd.course_id = -1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sql.append(" and rd.course_id in (").append(StringUtils.join(courseRule.getRefIds(), ",")).append(")");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 未限定数据权限
|
|
|
+ if (query.getCourseId() != null) {
|
|
|
+ sql.append(" and rd.course_id = ").append(query.getCourseId());
|
|
|
+ }
|
|
|
}
|
|
|
- if (query.getOrgId() != null) {
|
|
|
- sql.append(" and rd.org_id = ").append(query.getOrgId());
|
|
|
+
|
|
|
+ if (orgRule.assertNeedQueryRefIds()) {
|
|
|
+ // 限定机构数据权限范围
|
|
|
+ if (query.getOrgId() != null) {
|
|
|
+ if (orgRule.getRefIds().contains(query.getOrgId())) {
|
|
|
+ sql.append(" and rd.org_id = ").append(query.getOrgId());
|
|
|
+ } else {
|
|
|
+ // 不在数据权限范围内,无效查询
|
|
|
+ sql.append(" and rd.org_id = -1");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ sql.append(" and rd.org_id in (").append(StringUtils.join(orgRule.getRefIds(), ",")).append(")");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 未限定数据权限
|
|
|
+ if (query.getOrgId() != null) {
|
|
|
+ sql.append(" and rd.org_id = ").append(query.getOrgId());
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (query.getExamStageId() != null) {
|
|
|
sql.append(" and rd.exam_stage_id = ").append(query.getExamStageId());
|
|
|
}
|