Prechádzať zdrojové kódy

getReexamineLogList

deason 11 mesiacov pred
rodič
commit
5c2dc313dc

+ 4 - 1
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ReexamineLogController.java

@@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.List;
 
 @RestController
 @Api(tags = "重考设置记录相关接口")
@@ -50,7 +52,8 @@ public class ReexamineLogController extends ControllerSupport {
         query.setByExport(true);
 
         Page<ReexamineLogInfo> page = reexamineLogService.getReexamineLogList(query, courseRule, orgRule);
-        ExportUtils.exportEXCEL("重考设置记录", ReexamineLogInfo.class, page.getContent(), response);
+        List<ReexamineLogInfo> list = new ArrayList<>(page.getContent());
+        ExportUtils.exportEXCEL("重考设置记录", ReexamineLogInfo.class, list, response);
     }
 
 }

+ 124 - 2
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ReexamineLogServiceImpl.java

@@ -8,13 +8,23 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ReexamineLogEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.ReexamineLogService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.reexaminelog.ReexamineLogInfo;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.reexaminelog.ReexamineLogQuery;
+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.OrgCacheBean;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
 public class ReexamineLogServiceImpl implements ReexamineLogService {
 
@@ -23,6 +33,9 @@ public class ReexamineLogServiceImpl implements ReexamineLogService {
     @Autowired
     private ReexamineLogRepo reexamineLogRepo;
 
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
     @Override
     public void addReexamineLog(ReexamineLogEntity reexamineLog) {
         if (reexamineLog == null) {
@@ -40,9 +53,118 @@ public class ReexamineLogServiceImpl implements ReexamineLogService {
         Check.isNull(query.getExamId(), "请先选择考试!");
 
         Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize());
-        //todo
+        if (courseRule.assertEmptyQueryResult() || orgRule.assertEmptyQueryResult()) {
+            return Page.empty(pageable);
+        }
+
+        int offset = (query.getPageNo() - 1) * query.getPageSize();
+        String countSql = this.queryReexamineLogListSql(query, true, courseRule, orgRule);
+        String querySql = this.queryReexamineLogListSql(query, false, courseRule, orgRule);
+        String pageSql = querySql + " limit " + offset + "," + query.getPageSize();
+
+        if (query.getByExport() != null && query.getByExport()) {
+            // 仅导出结果
+            List<ReexamineLogInfo> list = jdbcTemplate.query(querySql, new BeanPropertyRowMapper(ReexamineLogInfo.class));
+
+            // 填充其它信息
+            this.fillOtherInfo(list);
+            return new PageImpl<>(list, pageable, list.size());
+        }
+
+        Long totalElements = jdbcTemplate.queryForObject(countSql, Long.class);
+        if (totalElements == null || totalElements == 0) {
+            return Page.empty(pageable);
+        }
+
+        List<ReexamineLogInfo> list = jdbcTemplate.query(pageSql, new BeanPropertyRowMapper(ReexamineLogInfo.class));
+        if (CollectionUtils.isEmpty(list)) {
+            return Page.empty(pageable);
+        }
+
+        // 填充其它信息
+        this.fillOtherInfo(list);
+        return new PageImpl<>(list, pageable, totalElements);
+    }
+
+    private void fillOtherInfo(List<ReexamineLogInfo> list) {
+        for (ReexamineLogInfo info : list) {
+            // 学习中心名称
+            OrgCacheBean org = CacheHelper.getOrg(info.getOrgId());
+            info.setOrgName(org.getName());
+
+            // 课程信息
+            CourseCacheBean course = CacheHelper.getCourse(info.getCourseId());
+            info.setCourseCode(course.getCode());
+            info.setCourseName(course.getName());
+        }
+    }
+
+    private String queryReexamineLogListSql(ReexamineLogQuery query, boolean isCount, UserDataRule courseRule, UserDataRule orgRule) {
+        StringBuilder sql = new StringBuilder();
+        if (isCount) {
+            sql.append(" select count(1)");
+        } else {
+            sql.append(" select r.exam_id,r.exam_student_id,stu.student_name,stu.student_code,stu.identity_number,");
+            sql.append(" stu.org_id,stu.course_id,r.operate_user_id,r.operate_user_name,r.creation_time");
+        }
+
+        sql.append(" from ec_oe_reexamine_log r");
+        sql.append(" inner join ec_oe_exam_student stu on stu.exam_student_id = r.exam_student_id");
+        sql.append(" where r.exam_id = ").append(query.getExamId());
+
+        if (courseRule.assertNeedQueryRefIds()) {
+            // 限定课程数据权限范围
+            if (query.getCourseId() != null) {
+                if (courseRule.getRefIds().contains(query.getCourseId())) {
+                    sql.append(" and stu.course_id = ").append(query.getCourseId());
+                } else {
+                    // 不在数据权限范围内,无效查询
+                    sql.append(" and stu.course_id = -1");
+                }
+            } else {
+                sql.append(" and stu.course_id in (").append(StringUtils.join(courseRule.getRefIds(), ",")).append(")");
+            }
+        } else {
+            // 未限定数据权限
+            if (query.getCourseId() != null) {
+                sql.append(" and stu.course_id = ").append(query.getCourseId());
+            }
+        }
+
+        if (orgRule.assertNeedQueryRefIds()) {
+            // 限定机构数据权限范围
+            if (query.getOrgId() != null) {
+                if (orgRule.getRefIds().contains(query.getOrgId())) {
+                    sql.append(" and stu.org_id = ").append(query.getOrgId());
+                } else {
+                    // 不在数据权限范围内,无效查询
+                    sql.append(" and stu.org_id = -1");
+                }
+            } else {
+                sql.append(" and stu.org_id in (").append(StringUtils.join(orgRule.getRefIds(), ",")).append(")");
+            }
+        } else {
+            // 未限定数据权限
+            if (query.getOrgId() != null) {
+                sql.append(" and stu.org_id = ").append(query.getOrgId());
+            }
+        }
+
+        if (StringUtils.isNotBlank(query.getIdentityNumber())) {
+            sql.append(" and stu.identity_number like '").append(query.getIdentityNumber()).append("%'");
+        }
+        if (StringUtils.isNotBlank(query.getStudentCode())) {
+            sql.append(" and stu.student_code like '").append(query.getStudentCode()).append("%'");
+        }
+        if (StringUtils.isNotBlank(query.getStudentName())) {
+            sql.append(" and stu.student_name like '").append(query.getStudentName()).append("%'");
+        }
+
+        if (!isCount) {
+            sql.append(" order by r.id desc");
+        }
 
-        return Page.empty(pageable);
+        return sql.toString();
     }
 
 }