|
@@ -1,113 +0,0 @@
|
|
|
-package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.bean.ExamCourseCriteria;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.bean.ExamCourseDTO;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
-import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by songyue on 18/4/2.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class ExamCourseService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
|
|
-
|
|
|
- public Page<ExamCourseDTO> findAllPage(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuilder sql = new StringBuilder();
|
|
|
- sql.append(buildBaseSql());
|
|
|
- sql.append(buildCriteriaSql(examCourseCriteria));
|
|
|
- sql.append(buildGroupSql());
|
|
|
- sql.append(buildPageSql(examCourseCriteria));
|
|
|
- BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(ExamCourseDTO.class);
|
|
|
- List<ExamCourseDTO> projectStatDTOs = this.namedParameterJdbcTemplate.query(sql.toString(), mapper);
|
|
|
- long total = countAll(examCourseCriteria);
|
|
|
- return new PageImpl<ExamCourseDTO>(projectStatDTOs,examCourseCriteria.getPageable(),total);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public List<ExamCourseDTO> findAll(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuilder sql = new StringBuilder();
|
|
|
- sql.append(buildBaseSql());
|
|
|
- sql.append(buildCriteriaSql(examCourseCriteria));
|
|
|
- sql.append(buildGroupSql());
|
|
|
- BeanPropertyRowMapper mapper = new BeanPropertyRowMapper<>(ExamCourseDTO.class);
|
|
|
- List<ExamCourseDTO> projectStatDTOs = this.namedParameterJdbcTemplate.query(sql.toString(), mapper);
|
|
|
- return projectStatDTOs;
|
|
|
- }
|
|
|
-
|
|
|
- private long countAll(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuffer sql = new StringBuffer();
|
|
|
- sql.append(buildCountSql(examCourseCriteria));
|
|
|
- return this.jdbcTemplate.queryForObject(sql.toString(),Long.class);
|
|
|
- }
|
|
|
-
|
|
|
- private String buildPageSql(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuilder pageSql = new StringBuilder();
|
|
|
- int currentNum = examCourseCriteria.getCurPage() * examCourseCriteria.getPageSize();
|
|
|
- pageSql.append(" limit "+currentNum+","+examCourseCriteria.getPageSize());
|
|
|
- return pageSql.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private String buildCriteriaSql(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuilder criteriaSql = new StringBuilder();
|
|
|
- if(examCourseCriteria.getExamId() != null){
|
|
|
- criteriaSql.append(" and exam_id ="+examCourseCriteria.getExamId());
|
|
|
- }
|
|
|
- if(!StringUtils.isEmpty(examCourseCriteria.getCourseCode())){
|
|
|
- criteriaSql.append(" and course_code ='"+examCourseCriteria.getCourseCode()+"'");
|
|
|
- }
|
|
|
- if(!StringUtils.isEmpty(examCourseCriteria.getCourseLevel())){
|
|
|
- criteriaSql.append(" and course_level ='"+examCourseCriteria.getCourseLevel()+"'");
|
|
|
- }
|
|
|
- criteriaSql.append(" and exists (select 1 from ecs_core_course tc where tc.org_id = ts.root_org_id" +
|
|
|
- " and tc.code = ts.course_code" +
|
|
|
- " and tc.enable = 1)");
|
|
|
- return criteriaSql.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private String buildGroupSql(){
|
|
|
- return " group by ts.course_code order by ts.course_code";
|
|
|
- }
|
|
|
-
|
|
|
- private String buildBaseSql(){
|
|
|
- StringBuilder baseSql = new StringBuilder();
|
|
|
- baseSql.append("select" +
|
|
|
- " ts.exam_id as exam_id," +
|
|
|
- " te.name as exam_name," +
|
|
|
- " te.exam_type as exam_type," +
|
|
|
- " ts.course_code as course_code," +
|
|
|
- " ts.course_name as course_name," +
|
|
|
- " ts.root_org_id as org_id" +
|
|
|
- " from" +
|
|
|
- " ecs_exam_student ts," +
|
|
|
- " ecs_exam te" +
|
|
|
- " where ts.exam_id = te.id");
|
|
|
- return baseSql.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private String buildCountSql(ExamCourseCriteria examCourseCriteria){
|
|
|
- StringBuilder countSql = new StringBuilder();
|
|
|
- countSql.append("select count(*) from (");
|
|
|
- countSql.append(buildBaseSql());
|
|
|
- countSql.append(buildCriteriaSql(examCourseCriteria));
|
|
|
- countSql.append(buildGroupSql());
|
|
|
- countSql.append(")as tt");
|
|
|
- return countSql.toString();
|
|
|
- }
|
|
|
-
|
|
|
-}
|