package cn.com.qmth.stmms.biz.exam.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.qmth.stmms.biz.campus.model.Campus;
import cn.com.qmth.stmms.biz.campus.service.CampusService;
import cn.com.qmth.stmms.biz.common.BaseQueryService;
import cn.com.qmth.stmms.biz.exam.dao.ExamStudentDao;
import cn.com.qmth.stmms.biz.exam.model.Exam;
import cn.com.qmth.stmms.biz.exam.model.ExamPackage;
import cn.com.qmth.stmms.biz.exam.model.ExamStudent;
import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
import cn.com.qmth.stmms.biz.exam.query.ExamStudentSearchQuery;
import cn.com.qmth.stmms.biz.exam.service.ExamPackageService;
import cn.com.qmth.stmms.biz.exam.service.ExamService;
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
import cn.com.qmth.stmms.biz.user.model.User;
import cn.com.qmth.stmms.biz.user.service.UserService;
import cn.com.qmth.stmms.common.enums.ExamSubjectStatus;
import cn.com.qmth.stmms.common.enums.Role;
import cn.com.qmth.stmms.common.enums.UserType;
import cn.com.qmth.stmms.common.utils.Md5EncryptUtils;

@Service
public class ExamStudentServiceImpl extends BaseQueryService<ExamStudent> implements ExamStudentService {

    @Autowired
    private ExamStudentDao studentDao;

    @Autowired
    private CampusService campusService;

    @Autowired
    private ExamPackageService packageService;

    @Autowired
    private ExamSubjectService subjectService;

    @Autowired
    private ExamService examService;

    @Autowired
    private UserService userService;

    public static final String LOGINNAME_SPLITE = "-";

    public static final String USER_PASSWORD = "123456";

    @Value("${subject.name.bracket.replace}")
    private boolean replaceBracket;

    public ExamStudent findById(int id) {
        return studentDao.findOne(id);
    }

    /**
     * 批量添加考生
     * 
     * @param list
     * @return
     */
    @Transactional
    public int batchSave(List<ExamStudent> list) {
        if (list == null || list.isEmpty()) {
            return 0;
        }
        int success = 0;
        int examId = list.get(0).getExamId();
        int schoolId = list.get(0).getSchoolId();
        Map<String, ExamSubject> subjectMap = new HashMap<String, ExamSubject>();
        Set<String> campusSet = new HashSet<String>();
        Set<String> packageSet = new HashSet<String>();

        for (ExamStudent student : list) {
            if (replaceBracket) {
                String subjectName = student.getSubjectName().replaceAll("\\(", "（").replaceAll("\\)", "）");
                student.setSubjectName(subjectName);
            }
            if (!subjectMap.containsKey(student.getSubjectCode())) {
                ExamSubject subject = new ExamSubject();
                subject.setCode(student.getSubjectCode());
                subject.setName(student.getSubjectName());
                subject.setRemark(StringUtils.trimToNull(student.getSubjectRemark()));
                subject.setLevel(StringUtils.trimToNull(student.getSubjectLevel()));
                subject.setCategory(StringUtils.trimToNull(student.getSubjectCategory()));
                subjectMap.put(subject.getCode(), subject);
            }
            campusSet.add(student.getCampusName());
            if (StringUtils.isNotBlank(student.getPackageCode())) {
                packageSet.add(student.getPackageCode());
            }
            success++;
        }

        for (ExamSubject es : subjectMap.values()) {
            ExamSubject subject = subjectService.find(examId, es.getCode());
            if (subject == null) {
                subject = new ExamSubject();
                subject.setExamId(examId);
                subject.setCode(es.getCode());
                subject.setName(es.getName());
                subject.setLevel(es.getLevel());
                subject.setCategory(es.getCategory());
                subject.setStatus(ExamSubjectStatus.MARKING);
                subject.setObjectiveScore(0d);
                subject.setSubjectiveScore(0d);
                subject.setTotalScore(0d);
                subject.setLibraryCount(0);
                subject.setMarkedCount(0);
                subject.setLeftCount(0);
                subject.setHasAnswer(false);
                subject.setHasPaper(false);
                subject.setRemark(es.getRemark());

                subjectService.save(subject);
                // 增加科组长
                User user = new User();
                StringBuilder name = new StringBuilder();
                name.append(examId).append(LOGINNAME_SPLITE).append(es.getCode());
                user.setSchoolId(schoolId);
                user.setLoginName(name.toString());
                user.setName(name.toString());
                user.setStatus(1);
                user.setType(UserType.VIEWER);
                user.setRoleNames(Role.SUBJECT_VIEWER.getName());
                user.setPassword(Md5EncryptUtils.md5(USER_PASSWORD));
                user.setCreatedTime(new Date());
                userService.save(user);
            }
        }

        for (String name : campusSet) {
            Campus campus = campusService.findBySchoolAndName(schoolId, name);
            if (campus == null) {
                campus = new Campus();
                campus.setSchoolId(schoolId);
                campus.setName(name);
                campusService.save(campus);
            }
        }

        for (String code : packageSet) {
            ExamPackage examPackage = packageService.find(examId, code);
            if (examPackage == null) {
                examPackage = new ExamPackage();
                examPackage.setExamId(examId);
                examPackage.setCode(code);
                examPackage.setPicCount(0);
                packageService.save(examPackage);
            }
        }

        studentDao.save(list);
        return success;
    }

    @Transactional
    public ExamStudent save(ExamStudent student) {
        ExamSubject subject = subjectService.find(student.getExamId(), student.getSubjectCode());
        if (subject == null) {
            subject = new ExamSubject();
            subject.setExamId(student.getExamId());
            subject.setCode(student.getSubjectCode());
            subject.setName(student.getSubjectName());
            subject.setLevel(StringUtils.trimToNull(student.getSubjectLevel()));
            subject.setCategory(StringUtils.trimToNull(student.getSubjectCategory()));
            subject.setStatus(ExamSubjectStatus.MARKING);
            subject.setObjectiveScore(0d);
            subject.setSubjectiveScore(0d);
            subject.setTotalScore(0d);
            subject.setLibraryCount(0);
            subject.setMarkedCount(0);
            subject.setLeftCount(0);
            subject.setHasAnswer(false);
            subject.setHasPaper(false);
            subject.setRemark(StringUtils.trimToNull(student.getSubjectRemark()));
            subjectService.save(subject);
        }

        Campus campus = campusService.findBySchoolAndName(student.getSchoolId(), student.getCampusName());
        if (campus == null) {
            campus = new Campus();
            campus.setSchoolId(student.getSchoolId());
            campus.setName(student.getCampusName());
            campusService.save(campus);
        }

        if (StringUtils.isNotBlank(student.getPackageCode())) {
            ExamPackage examPackage = packageService.find(student.getExamId(), student.getPackageCode());
            if (examPackage == null) {
                examPackage = new ExamPackage();
                examPackage.setExamId(student.getExamId());
                examPackage.setCode(student.getPackageCode());
                examPackage.setPicCount(0);
                packageService.save(examPackage);
            }
        }
        if (replaceBracket) {
            student.setSubjectName(subject.getName());
        }
        return studentDao.save(student);
    }

    @Transactional
    public void deleteById(int id) {
        ExamStudent student = findById(id);
        if (student != null) {
            delete(student);
        }
    }

    @Transactional
    public void delete(ExamStudent student) {
        studentDao.delete(student);
    }

    @Transactional
    public void deleteByExamId(int examId) {
        studentDao.deleteByExamId(examId);
    }

    public ExamStudentSearchQuery findByQuery(final ExamStudentSearchQuery query) {
        checkQuery(query);
        Page<ExamStudent> result = studentDao.findAll(buildSpecification(query), query);
        fillResult(result, query);
        return query;
    }

    public long countByQuery(final ExamStudentSearchQuery query) {
        return studentDao.count(buildSpecification(query));
    }

    @Override
    public List<ExamStudent> findByExamId(int examId) {
        return studentDao.findByExamId(examId, null);
    }

    @Override
    public List<ExamStudent> findByExamId(int examId, int pageNumber, int pageSize) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setPageNumber(pageNumber);
        query.setPageSize(pageSize);
        return studentDao.findByExamId(examId, query);
    }

    @Override
    public List<ExamStudent> findByExamIdAndUploadAndAbsent(int examId, boolean upload, boolean absent, int pageNumber,
            int pageSize) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setPageNumber(pageNumber);
        query.setPageSize(pageSize);
        return studentDao.findByExamIdAndUploadAndAbsent(examId, upload, absent, query);
    }

    @Override
    public List<ExamStudent> findByExamIdAndUpload(int examId, boolean upload, int pageNumber, int pageSize) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setPageNumber(pageNumber);
        query.setPageSize(pageSize);
        return studentDao.findByExamIdAndUpload(examId, upload, query);
    }

    @Override
    public List<ExamStudent> findByExamIdAndCampusName(int examId, String campusName, int pageNumber, int pageSize) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setPageNumber(pageNumber);
        query.setPageSize(pageSize);
        return studentDao.findByExamIdAndCampusName(examId, campusName, query);
    }

    @Override
    public ExamStudent findByExamIdAndExamNumber(int examId, String examNumber) {
        List<ExamStudent> list = studentDao.findByExamIdAndExamNumber(examId, examNumber);
        return list != null && list.size() > 0 ? list.get(0) : null;
    }

    public long countByExamId(int examId) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        return countByQuery(query);
    }

    @Override
    public long countByExamIdAndUpload(int examId, boolean upload) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setUpload(upload);
        return countByQuery(query);
    }

    public long countByExamIdAndSubjectCode(int examId, String subjectCode) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        return countByQuery(query);
    }

    public long countByExamIdAndSubjectCode(int examId, String subjectCode, boolean upload) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        query.setUpload(upload);
        return countByQuery(query);
    }

    public long countByExamIdAndSubjectCode(int examId, String subjectCode, boolean upload, boolean absent) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        query.setUpload(upload);
        query.setAbsent(absent);
        return countByQuery(query);
    }

    public long countByNoAbsentAndBreach(int examId, String subjectCode, boolean upload, boolean absent,
            boolean breach) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        query.setUpload(upload);
        query.setAbsent(absent);
        query.setBreach(breach);
        return countByQuery(query);
    }

    public long countByAbsentAndBreach(int examId, String subjectCode, Boolean absent, Boolean breach) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        if (breach != null) {
            query.setBreach(breach);
        }
        if (absent != null) {
            query.setAbsent(absent);
        }
        return countByQuery(query);
    }

    @Override
    public long countByExamIdAndCampusName(int examId, String campusName) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setCampusName(campusName);
        return countByQuery(query);
    }

    @Override
    public long countByExamIdAndCampusName(int examId, String campusName, boolean upload) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setCampusName(campusName);
        query.setUpload(upload);
        return countByQuery(query);
    }

    @Override
    public long countCampusByExam(int examId) {
        return studentDao.countCampusNameByExamId(examId);
    }

    @Override
    public List<String> findDistinctCampusName(int examId) {
        return studentDao.findDistinctCampusName(examId);
    }

    @Override
    public ExamStudentSearchQuery findDistinctCampusName(ExamStudentSearchQuery query) {
        checkQuery(query);
        Page<ExamStudent> result = studentDao.findDistinctCampusName(query.getExamId(), query);
        fillResult(result, query);
        return query;
    }

    @Override
    public List<String> findDistinctPackageCode(int examId) {
        return studentDao.findDistinctPackageCode(examId);
    }

    @Override
    @Transactional
    public void updateSubjectiveScore(int id, double score, String scoreList) {
        studentDao.updateSubjectiveScore(id, score, scoreList);
    }

    @Override
    @Transactional
    public void updateManualAbsent(int id, boolean manualAbsent) {
        studentDao.updateManualAbsent(id, manualAbsent);
    }

    @Override
    @Transactional
    public void updateManualAbsent(int examId, String examNumber, boolean manualAbsent) {
        studentDao.updateManualAbsent(examId, examNumber, manualAbsent);
    }

    @Override
    @Transactional
    public void clearManualAbsent(int examId) {
        studentDao.clearManualAbsent(examId);
    }

    @Override
    @Transactional
    public void updateException(int id, boolean exception) {
        studentDao.updateException(id, exception);
    }

    private Specification<ExamStudent> buildSpecification(final ExamStudentSearchQuery query) {
        return new Specification<ExamStudent>() {

            @Override
            public Predicate toPredicate(Root<ExamStudent> root, CriteriaQuery<?> cQuery, CriteriaBuilder cb) {
                List<Predicate> predicates = new LinkedList<Predicate>();
                Expression<Double> evaluationItemSum = cb.sum(root.get("objectiveScore").as(Double.class),
                        root.get("subjectiveScore").as(Double.class));
                if (query.getStartScroe() != null) {
                    Predicate predicate1 = cb.ge(evaluationItemSum, query.getStartScroe());
                    Predicate predicate2 = cb.le(evaluationItemSum, query.getEndScroe());
                    if (query.getStartScroe() == 0) {
                        Predicate predicate = cb.or(cb.equal(root.get("absent"), true),
                                cb.equal(root.get("breach"), true));
                        Predicate predicate3 = cb.and(predicate1, predicate2);
                        predicates.add(cb.or(predicate, predicate3));
                    } else {
                        predicates.add(cb.equal(root.get("absent"), false));
                        predicates.add(cb.equal(root.get("breach"), false));
                        predicates.add(cb.and(predicate1, predicate2));
                    }
                }
                // if (query.getStartScroe()!=null && query.getEndScroe()!=null
                // ) {
                // predicates.add(cb.between(evaluationItemSum,
                // query.getStartScroe(), query.getEndScroe()));
                // }
                if (query.getExamId() > 0) {
                    predicates.add(cb.equal(root.get("examId"), query.getExamId()));
                }
                if (StringUtils.isNotBlank(query.getIds())) {
                    String[] ids = query.getIds().split(",");
                    List<String> list = new ArrayList<String>();
                    for (String str : ids) {
                        list.add(str);
                    }
                    predicates.add(root.get("id").in(list));
                }
                if (StringUtils.isNotBlank(query.getExamNumber())) {
                    predicates.add(cb.equal(root.get("examNumber"), query.getExamNumber()));
                } else if (StringUtils.isNotBlank(query.getExamNumberIn())) {
                    String[] list = query.getExamNumberIn().split(",");
                    if (list.length > 0) {
                        Predicate[] sub = new Predicate[list.length];
                        for (int i = 0; i < list.length; i++) {
                            sub[i] = cb.equal(root.get("examNumber"), list[i]);
                        }
                        predicates.add(cb.or(sub));
                    }
                }
                if (StringUtils.isNotBlank(query.getStudentCode())) {
                    predicates.add(cb.equal(root.get("studentCode"), query.getStudentCode()));
                }
                if (StringUtils.isNotBlank(query.getSubjectCode())) {
                    predicates.add(cb.equal(root.get("subjectCode"), query.getSubjectCode()));
                }
                if (StringUtils.isNotBlank(query.getCampusName())) {
                    predicates.add(cb.equal(root.get("campusName"), query.getCampusName()));
                }
                if (StringUtils.isNotBlank(query.getName())) {
                    predicates.add(cb.like(root.get("name").as(String.class), query.getName() + "%"));
                }
                if (StringUtils.isNotBlank(query.getBatchCode())) {
                    predicates.add(cb.equal(root.get("batchCode"), query.getBatchCode()));
                }
                if (StringUtils.isNotBlank(query.getPackageCode())) {
                    predicates.add(cb.equal(root.get("packageCode"), query.getPackageCode()));
                }
                if (StringUtils.isNotBlank(query.getSubjectLevel())) {
                    predicates.add(cb.equal(root.get("subjectLevel"), query.getSubjectLevel()));
                }
                if (StringUtils.isNotBlank(query.getSubjectCategory())) {
                    predicates.add(cb.equal(root.get("subjectCategory"), query.getSubjectCategory()));
                }
                if (query.getObjectiveScore() != null) {
                    predicates.add(cb.equal(root.get("objectiveScore"), query.getObjectiveScore()));
                } else if (query.getObjectiveScoreGt() != null) {
                    predicates.add(
                            cb.greaterThan(root.get("objectiveScore").as(Double.class), query.getObjectiveScoreGt()));
                } else if (query.getObjectiveScoreLt() != null) {
                    predicates
                            .add(cb.lessThan(root.get("objectiveScore").as(Double.class), query.getObjectiveScoreLt()));
                }
                if (query.getSubjectiveScore() != null) {
                    predicates.add(cb.equal(root.get("subjectiveScore"), query.getSubjectiveScore()));
                } else if (query.getSubjectiveScoreGt() != null) {
                    predicates.add(
                            cb.greaterThan(root.get("subjectiveScore").as(Double.class), query.getSubjectiveScoreGt()));
                } else if (query.getSubjectiveScoreLt() != null) {
                    predicates.add(
                            cb.lessThan(root.get("subjectiveScore").as(Double.class), query.getSubjectiveScoreLt()));
                }
                if (query.getUpload() != null) {
                    predicates.add(cb.equal(root.get("upload"), query.getUpload()));
                }
                if (query.getAbsent() != null) {
                    if (query.getAbsent()) {// 缺考=缺考+ 未上传
                        predicates.add(cb.or(cb.equal(root.get("absent"), true), cb.equal(root.get("upload"), false)));
                    } else {
                        predicates.add(cb.equal(root.get("absent"), query.getAbsent()));
                        predicates.add(cb.equal(root.get("upload"), true));
                    }
                }
                if (query.getManualAbsent() != null) {
                    predicates.add(cb.equal(root.get("manualAbsent"), query.getManualAbsent()));
                }
                if (query.getBreach() != null) {
                    predicates.add(cb.equal(root.get("breach"), query.getBreach()));
                }
                if (query.getException() != null) {
                    predicates.add(cb.equal(root.get("exception"), query.getException()));
                }
                if (StringUtils.isNotBlank(query.getSubjectCodeIn())) {
                    String[] list = query.getSubjectCodeIn().split(",");
                    if (list.length > 0) {
                        Predicate[] sub = new Predicate[list.length];
                        for (int i = 0; i < list.length; i++) {
                            sub[i] = cb.equal(root.get("subjectCode"), list[i]);
                        }
                        predicates.add(cb.or(sub));
                    }
                }
                if (StringUtils.isNotBlank(query.getCampusNameIn())) {
                    String[] list = query.getCampusNameIn().split(",");
                    if (list.length > 0) {
                        Predicate[] sub = new Predicate[list.length];
                        for (int i = 0; i < list.length; i++) {
                            sub[i] = cb.equal(root.get("campusName"), list[i]);
                        }
                        predicates.add(cb.or(sub));
                    }
                }
                if (StringUtils.isNotBlank(query.getSubjectCodeNotIn())) {
                    String[] list = query.getSubjectCodeNotIn().split(",");
                    if (list.length > 0) {
                        Predicate[] sub = new Predicate[list.length];
                        for (int i = 0; i < list.length; i++) {
                            sub[i] = cb.notEqual(root.get("subjectCode"), list[i]);
                        }
                        predicates.add(cb.and(sub));
                    }
                }
                if (StringUtils.isNotBlank(query.getCampusNameNotIn())) {
                    String[] list = query.getCampusNameNotIn().split(",");
                    if (list.length > 0) {
                        Predicate[] sub = new Predicate[list.length];
                        for (int i = 0; i < list.length; i++) {
                            sub[i] = cb.notEqual(root.get("campusName"), list[i]);
                        }
                        predicates.add(cb.and(sub));
                    }
                }
                return predicates.isEmpty() ? cb.conjunction()
                        : cb.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        };

    }

    @Override
    public ExamStudent findBySchoolIdAndSubjectCodeAndStudentCode(Integer schoolId, String subjectCode,
            String studentCode) {
        List<Exam> exams = examService.findBySchoolId(schoolId);
        if (exams != null && exams.size() > 0) {
            return studentDao.findByExamIdAndSubjectCodeAndStudentCode(exams.get(0).getId(), subjectCode, studentCode);
        } else {
            return null;
        }
    }

    @Override
    public ExamStudent findBySchoolIdAndSubjectCodeAndStudentCodeAndRemark(Integer schoolId, String subjectCode,
            String studentCode, String examSeqCode) {
        return studentDao.findBySchoolIdAndSubjectCodeAndStudentCodeAndRemark(schoolId, subjectCode, studentCode,
                examSeqCode);
    }

    @Override
    public ExamStudent findByExamIdAndSubjectCodeAndStudentCode(Integer examId, String subjectCode,
            String studentCode) {
        return studentDao.findByExamIdAndSubjectCodeAndStudentCode(examId, subjectCode, studentCode);
    }

    @Override
    public ExamStudent findByExamIdAndSchoolIdAndSubjectCodeAndStudentCode(Integer examId, Integer schoolId,
            String subjectCode, String studentCode) {
        return studentDao.findByExamIdAndSchoolIdAndSubjectCodeAndStudentCode(examId, schoolId, subjectCode,
                studentCode);
    }

    @Override
    public List<Object[]> statisticsByExamIdAndSubjectCode(Integer examId, String code, Boolean upload,
            boolean absent) {
        return studentDao.statisticsByExamIdAndSubjectCode(examId, code, upload, absent);
    }

    @Override
    public List<Object[]> statisticsByExamIdAndSubjectCode(Integer examId, String code) {
        return studentDao.statisticsByExamIdAndSubjectCode(examId, code);
    }

    @Override
    public Long countByExamIdAndSubjectCodeAndCampus(Integer examId, String subjectCode, String campusName,
            boolean upload, boolean absent) {
        ExamStudentSearchQuery query = new ExamStudentSearchQuery();
        query.setExamId(examId);
        query.setSubjectCode(subjectCode);
        query.setCampusName(campusName);
        query.setUpload(upload);
        query.setAbsent(absent);
        return countByQuery(query);
    }

    @Override
    public ExamStudent findBySchoolIdAndSubjectCodeStartingWithAndStudentCode(Integer schoolId, String subjectCode,
            String studentCode) {
        List<Exam> exams = examService.findBySchoolId(schoolId);
        if (exams != null && exams.size() > 0) {
            return studentDao.findByExamIdAndSubjectCodeStartingWithAndStudentCode(exams.get(0).getId(), subjectCode,
                    studentCode);
        } else {
            return null;
        }
    }

    @Override
    public String findIdsByMarkLogin(String markLogin) {
        List<String[]> o = studentDao.findIdsByMarkLogin(markLogin);
        return StringUtils.join(o, ",");
    }

    @Override
    public String findIdsByMarkName(String MarkName) {
        List<String[]> o = studentDao.findIdsByMarkName(MarkName);
        return StringUtils.join(o, ",");
    }

    @Override
    /**
     * 根据缺考和违纪字段联合查询
     */
    public List<Object[]> statisticsByAbsentAndBreach(Integer examId, String code, Boolean upload, boolean absent,
            boolean breach) {
        return studentDao.statisticsByAbsentAndBreach(examId, code, upload, absent, breach);
    }
}
