|
@@ -13,6 +13,7 @@ import static cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamS
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -44,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
import org.springframework.jdbc.core.RowMapper;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -582,51 +584,106 @@ public class ExamStudentServiceImpl implements ExamStudentService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ExamStudentFinishedStatistic getExamStudentStatisticByFinished(Long examId) {
|
|
public ExamStudentFinishedStatistic getExamStudentStatisticByFinished(Long examId) {
|
|
- SqlWrapper wrapper = new SqlWrapper()
|
|
|
|
- .select(statisticFinishedColumns())
|
|
|
|
- .from("ec_oe_exam_student").as("student")
|
|
|
|
- .where().eq("student.exam_id", examId);
|
|
|
|
- Query dataQuery = entityManager.createNativeQuery(wrapper.build());
|
|
|
|
-// dataQuery.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(HashMap.class));
|
|
|
|
- dataQuery.unwrap(NativeQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
|
|
|
- Map<String, BigDecimal> map = (HashMap) dataQuery.getSingleResult();
|
|
|
|
- ExamStudentFinishedStatistic statistic = new ExamStudentFinishedStatistic();
|
|
|
|
- if (map != null) {
|
|
|
|
- if (map.get("finished") == null) {
|
|
|
|
- statistic.setFinished(0);
|
|
|
|
- } else {
|
|
|
|
- statistic.setFinished(map.get("finished").intValue());
|
|
|
|
- }
|
|
|
|
- if (map.get("unFinished") == null) {
|
|
|
|
- statistic.setUnFinished(0);
|
|
|
|
- } else {
|
|
|
|
- statistic.setUnFinished(map.get("unFinished").intValue());
|
|
|
|
|
|
+ ExamBean examBean = ExamCacheTransferHelper.getDefaultCachedExam(examId);
|
|
|
|
+ if (ExamType.ONLINE.name().equals(examBean.getExamType()) || ExamType.ONLINE_HOMEWORK.name().equals(examBean.getExamType())) {
|
|
|
|
+ ExamStudentFinishedStatistic statistic = new ExamStudentFinishedStatistic();
|
|
|
|
+ StringBuffer totalsql = new StringBuffer();
|
|
|
|
+ totalsql.append("select count(t1.id) from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ totalsql.append(" and exam_id = " + examId);
|
|
|
|
+ Integer total=jdbcTemplate.queryForObject(totalsql.toString(), Integer.class);
|
|
|
|
+
|
|
|
|
+ StringBuffer finishsql = new StringBuffer();
|
|
|
|
+ finishsql.append("select count(t1.id) from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ finishsql.append(" and exam_id = " + examId);
|
|
|
|
+ finishsql.append(" AND ( finished = 1 OR EXISTS ( SELECT 1 FROM ec_oes_exam_record_data t2 WHERE t2.exam_student_id = t1.exam_student_id ) )");
|
|
|
|
+ Integer finish=jdbcTemplate.queryForObject(finishsql.toString(), Integer.class);
|
|
|
|
+ statistic.setFinished(finish);
|
|
|
|
+ statistic.setUnFinished(total-finish);
|
|
|
|
+ return statistic;
|
|
|
|
+ }else {
|
|
|
|
+ SqlWrapper wrapper = new SqlWrapper()
|
|
|
|
+ .select(statisticFinishedColumns())
|
|
|
|
+ .from("ec_oe_exam_student").as("student")
|
|
|
|
+ .where().eq("student.exam_id", examId);
|
|
|
|
+ Query dataQuery = entityManager.createNativeQuery(wrapper.build());
|
|
|
|
+ dataQuery.unwrap(NativeQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
|
|
|
+ Map<String, BigDecimal> map = (HashMap) dataQuery.getSingleResult();
|
|
|
|
+ ExamStudentFinishedStatistic statistic = new ExamStudentFinishedStatistic();
|
|
|
|
+ if (map != null) {
|
|
|
|
+ if (map.get("finished") == null) {
|
|
|
|
+ statistic.setFinished(0);
|
|
|
|
+ } else {
|
|
|
|
+ statistic.setFinished(map.get("finished").intValue());
|
|
|
|
+ }
|
|
|
|
+ if (map.get("unFinished") == null) {
|
|
|
|
+ statistic.setUnFinished(0);
|
|
|
|
+ } else {
|
|
|
|
+ statistic.setUnFinished(map.get("unFinished").intValue());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ return statistic;
|
|
}
|
|
}
|
|
- return statistic;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<ExamStudentOrgStatistic> getExamStudentStatisticByOrg(Long examId, Long orgId) {
|
|
public List<ExamStudentOrgStatistic> getExamStudentStatisticByOrg(Long examId, Long orgId) {
|
|
- SqlWrapper wrapper = new SqlWrapper()
|
|
|
|
- .select(statisticOrgColumns())
|
|
|
|
- .from("ec_oe_exam_student").as("student")
|
|
|
|
- .where().eq("student.exam_id", examId);
|
|
|
|
- if (orgId != null) {
|
|
|
|
- wrapper.and().eq("student.org_id", orgId);
|
|
|
|
- }
|
|
|
|
- wrapper.groupBy("student.org_id").orderBy("student.org_id", false);
|
|
|
|
- Query dataQuery = entityManager.createNativeQuery(wrapper.build());
|
|
|
|
-// dataQuery.unwrap(SQLQuery.class).setResultTransformer(Transformers.aliasToBean(HashMap.class));
|
|
|
|
- dataQuery.unwrap(NativeQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
|
|
|
- List<ExamStudentOrgStatistic> examStudentOrgStatisticList = ExamStudentEntityConvert.ofList(dataQuery.getResultList());
|
|
|
|
- Map<String, Object> cahcheMap = new HashMap<String, Object>();
|
|
|
|
- for (ExamStudentOrgStatistic statistic : examStudentOrgStatisticList) {
|
|
|
|
- OrgCacheBean orgBean = gainBaseDataService.getOrgBean(statistic.getOrgId());
|
|
|
|
- statistic.setOrgCode(orgBean.getCode());
|
|
|
|
- statistic.setOrgName(orgBean.getName());
|
|
|
|
|
|
+ ExamBean examBean = ExamCacheTransferHelper.getDefaultCachedExam(examId);
|
|
|
|
+ if (ExamType.ONLINE.name().equals(examBean.getExamType()) || ExamType.ONLINE_HOMEWORK.name().equals(examBean.getExamType())) {
|
|
|
|
+ StringBuffer totalsql = new StringBuffer();
|
|
|
|
+ totalsql.append("select t1.org_id orgId,count(t1.id) totalCount from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ totalsql.append(" and exam_id = " + examId);
|
|
|
|
+ if (orgId != null) {
|
|
|
|
+ totalsql.append(" and org_id = " + orgId);
|
|
|
|
+ }
|
|
|
|
+ totalsql.append(" group by t1.org_id ");
|
|
|
|
+ List<ExamStudentOrgStatistic> totalList=jdbcTemplate.query(totalsql.toString(), new BeanPropertyRowMapper<ExamStudentOrgStatistic>(ExamStudentOrgStatistic.class));
|
|
|
|
+
|
|
|
|
+ StringBuffer finishsql = new StringBuffer();
|
|
|
|
+ finishsql.append("select t1.org_id orgId,count(t1.id) finishedCount from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ finishsql.append(" and exam_id = " + examId);
|
|
|
|
+ if (orgId != null) {
|
|
|
|
+ finishsql.append(" and org_id = " + orgId);
|
|
|
|
+ }
|
|
|
|
+ finishsql.append(" AND ( finished = 1 OR EXISTS ( SELECT 1 FROM ec_oes_exam_record_data t2 WHERE t2.exam_student_id = t1.exam_student_id ) )");
|
|
|
|
+ finishsql.append(" group by t1.org_id ");
|
|
|
|
+
|
|
|
|
+ List<ExamStudentOrgStatistic> finishList=jdbcTemplate.query(finishsql.toString(), new BeanPropertyRowMapper<ExamStudentOrgStatistic>(ExamStudentOrgStatistic.class));
|
|
|
|
+
|
|
|
|
+ Map<Long,ExamStudentOrgStatistic> finishMap=finishList.stream().collect(Collectors.toMap(ExamStudentOrgStatistic::getOrgId, account -> account));
|
|
|
|
+
|
|
|
|
+ for(ExamStudentOrgStatistic statistic:totalList) {
|
|
|
|
+ statistic.setFinishedCount(finishMap.get(statistic.getOrgId()).getFinishedCount());
|
|
|
|
+ OrgCacheBean orgBean = gainBaseDataService.getOrgBean(statistic.getOrgId());
|
|
|
|
+ statistic.setOrgCode(orgBean.getCode());
|
|
|
|
+ statistic.setOrgName(orgBean.getName());
|
|
|
|
+ if (statistic.getTotalCount() == 0 || statistic.getFinishedCount() == 0) {
|
|
|
|
+ statistic.setFinishedPercent("0");
|
|
|
|
+ } else {
|
|
|
|
+ double percent = (double) statistic.getFinishedCount() / statistic.getTotalCount();
|
|
|
|
+ statistic.setFinishedPercent(new DecimalFormat("#.00").format(percent * 100));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return totalList;
|
|
|
|
+ }else {
|
|
|
|
+ SqlWrapper wrapper = new SqlWrapper()
|
|
|
|
+ .select(statisticOrgColumns())
|
|
|
|
+ .from("ec_oe_exam_student").as("student")
|
|
|
|
+ .where().eq("student.exam_id", examId);
|
|
|
|
+ if (orgId != null) {
|
|
|
|
+ wrapper.and().eq("student.org_id", orgId);
|
|
|
|
+ }
|
|
|
|
+ wrapper.groupBy("student.org_id").orderBy("student.org_id", false);
|
|
|
|
+ Query dataQuery = entityManager.createNativeQuery(wrapper.build());
|
|
|
|
+ dataQuery.unwrap(NativeQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
|
|
|
|
+ List<ExamStudentOrgStatistic> examStudentOrgStatisticList = ExamStudentEntityConvert.ofList(dataQuery.getResultList());
|
|
|
|
+ Map<String, Object> cahcheMap = new HashMap<String, Object>();
|
|
|
|
+ for (ExamStudentOrgStatistic statistic : examStudentOrgStatisticList) {
|
|
|
|
+ OrgCacheBean orgBean = gainBaseDataService.getOrgBean(statistic.getOrgId());
|
|
|
|
+ statistic.setOrgCode(orgBean.getCode());
|
|
|
|
+ statistic.setOrgName(orgBean.getName());
|
|
|
|
+ }
|
|
|
|
+ return examStudentOrgStatisticList;
|
|
}
|
|
}
|
|
- return examStudentOrgStatisticList;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -685,34 +742,72 @@ public class ExamStudentServiceImpl implements ExamStudentService {
|
|
if (examId == null) {
|
|
if (examId == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- if (StringUtils.isBlank(orderColumn)) {
|
|
|
|
- orderColumn = "all_num";
|
|
|
|
- }
|
|
|
|
- String sql = "select *,ROUND(tb.completed_num/tb.all_num,2)*100 completed_proportion from ( " +
|
|
|
|
- " select " +
|
|
|
|
- " course_id, " +
|
|
|
|
- " sum(case when finished = 1 then 1 else 0 end) completed_num, " +
|
|
|
|
- " sum(case when finished = 0 then 1 else 0 end) no_completed_num, " +
|
|
|
|
- " count(course_id) all_num" +
|
|
|
|
- " from ec_oe_exam_student " +
|
|
|
|
- " where exam_id = " + examId;
|
|
|
|
- if (courseId != null) {
|
|
|
|
- sql += " and course_id = " + courseId;
|
|
|
|
- }
|
|
|
|
- sql += " group by course_id ) tb ORDER BY " + orderColumn + " desc";
|
|
|
|
-
|
|
|
|
- return jdbcTemplate.query(sql, new RowMapper<CourseProgressInfo>() {
|
|
|
|
- @Override
|
|
|
|
- public CourseProgressInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
|
|
- CourseProgressInfo courseProgressInfo = new CourseProgressInfo();
|
|
|
|
- courseProgressInfo.setCourseId(rs.getLong("course_id"));
|
|
|
|
- courseProgressInfo.setCompletedNum(rs.getInt("completed_num"));
|
|
|
|
- courseProgressInfo.setNoCompletedNum(rs.getInt("no_completed_num"));
|
|
|
|
- courseProgressInfo.setAllNum(rs.getInt("all_num"));
|
|
|
|
- courseProgressInfo.setCompletedProportion(rs.getDouble("completed_proportion"));
|
|
|
|
- return courseProgressInfo;
|
|
|
|
|
|
+ ExamBean examBean = ExamCacheTransferHelper.getDefaultCachedExam(examId);
|
|
|
|
+ if (ExamType.ONLINE.name().equals(examBean.getExamType()) || ExamType.ONLINE_HOMEWORK.name().equals(examBean.getExamType())) {
|
|
|
|
+ StringBuffer totalsql = new StringBuffer();
|
|
|
|
+ totalsql.append("select t1.course_id courseId,count(t1.id) allNum from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ totalsql.append(" and exam_id = " + examId);
|
|
|
|
+ if (courseId != null) {
|
|
|
|
+ totalsql.append(" and course_id = " + courseId);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ totalsql.append(" group by t1.course_id ");
|
|
|
|
+ List<CourseProgressInfo> totalList=jdbcTemplate.query(totalsql.toString(), new BeanPropertyRowMapper<CourseProgressInfo>(CourseProgressInfo.class));
|
|
|
|
+
|
|
|
|
+ StringBuffer finishsql = new StringBuffer();
|
|
|
|
+ finishsql.append("select t1.course_id courseId,count(t1.id) completedNum from ec_oe_exam_student t1 where 1=1 ");
|
|
|
|
+ finishsql.append(" and exam_id = " + examId);
|
|
|
|
+ if (courseId != null) {
|
|
|
|
+ finishsql.append(" and course_id = " + courseId);
|
|
|
|
+ }
|
|
|
|
+ finishsql.append(" AND ( finished = 1 OR EXISTS ( SELECT 1 FROM ec_oes_exam_record_data t2 WHERE t2.exam_student_id = t1.exam_student_id ) )");
|
|
|
|
+ finishsql.append(" group by t1.course_id ");
|
|
|
|
+
|
|
|
|
+ List<CourseProgressInfo> finishList=jdbcTemplate.query(finishsql.toString(), new BeanPropertyRowMapper<CourseProgressInfo>(CourseProgressInfo.class));
|
|
|
|
+
|
|
|
|
+ Map<Long,CourseProgressInfo> finishMap=finishList.stream().collect(Collectors.toMap(CourseProgressInfo::getCourseId, account -> account));
|
|
|
|
+
|
|
|
|
+ for(CourseProgressInfo statistic:totalList) {
|
|
|
|
+ statistic.setCompletedNum(finishMap.get(statistic.getCourseId()).getCompletedNum());
|
|
|
|
+ if (statistic.getAllNum() == 0 || statistic.getCompletedNum() == 0) {
|
|
|
|
+ statistic.setCompletedProportion(0.0D);
|
|
|
|
+ statistic.setNoCompletedNum(0);
|
|
|
|
+ } else {
|
|
|
|
+ statistic.setNoCompletedNum(statistic.getAllNum()-statistic.getCompletedNum());
|
|
|
|
+ double percent = (double) statistic.getCompletedNum() / statistic.getAllNum();
|
|
|
|
+ statistic.setCompletedProportion(Double.valueOf(new DecimalFormat("#.00").format(percent * 100)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return totalList;
|
|
|
|
+ }else {
|
|
|
|
+ if (StringUtils.isBlank(orderColumn)) {
|
|
|
|
+ orderColumn = "all_num";
|
|
|
|
+ }
|
|
|
|
+ String sql = "select *,ROUND(tb.completed_num/tb.all_num,2)*100 completed_proportion from ( " +
|
|
|
|
+ " select " +
|
|
|
|
+ " course_id, " +
|
|
|
|
+ " sum(case when finished = 1 then 1 else 0 end) completed_num, " +
|
|
|
|
+ " sum(case when finished = 0 then 1 else 0 end) no_completed_num, " +
|
|
|
|
+ " count(course_id) all_num" +
|
|
|
|
+ " from ec_oe_exam_student " +
|
|
|
|
+ " where exam_id = " + examId;
|
|
|
|
+ if (courseId != null) {
|
|
|
|
+ sql += " and course_id = " + courseId;
|
|
|
|
+ }
|
|
|
|
+ sql += " group by course_id ) tb ORDER BY " + orderColumn + " desc";
|
|
|
|
+
|
|
|
|
+ return jdbcTemplate.query(sql, new RowMapper<CourseProgressInfo>() {
|
|
|
|
+ @Override
|
|
|
|
+ public CourseProgressInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
|
|
|
|
+ CourseProgressInfo courseProgressInfo = new CourseProgressInfo();
|
|
|
|
+ courseProgressInfo.setCourseId(rs.getLong("course_id"));
|
|
|
|
+ courseProgressInfo.setCompletedNum(rs.getInt("completed_num"));
|
|
|
|
+ courseProgressInfo.setNoCompletedNum(rs.getInt("no_completed_num"));
|
|
|
|
+ courseProgressInfo.setAllNum(rs.getInt("all_num"));
|
|
|
|
+ courseProgressInfo.setCompletedProportion(rs.getDouble("completed_proportion"));
|
|
|
|
+ return courseProgressInfo;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|