<commit_before>package cn.momia.service.user.teacher.impl;

import cn.momia.api.user.dto.Teacher;
import cn.momia.api.user.dto.TeacherEducation;
import cn.momia.api.user.dto.TeacherExperience;
import cn.momia.api.user.dto.TeacherStatus;
import cn.momia.common.service.AbstractService;
import cn.momia.service.user.teacher.TeacherService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.KeyHolder;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TeacherServiceImpl extends AbstractService implements TeacherService {
    @Override
    public TeacherStatus status(long userId) {
        String sql = "SELECT Status, Msg FROM SG_Teacher WHERE UserId=? AND Status<>0";
        return queryObject(sql, new Object[] { userId }, TeacherStatus.class, TeacherStatus.NOT_EXIST_TEACHER_STATUS);
    }

    @Override
    public Teacher getByUser(long userId) {
        String sql = "SELECT Id FROM SG_Teacher WHERE UserId=? AND Status<>0";
        List<Integer> teacherIds = queryIntList(sql, new Object[] { userId });
        List<Teacher> teachers = listTeachers(teacherIds);

        return teachers.isEmpty() ? Teacher.NOT_EXIST_TEACHER : teachers.get(0);
    }

    private List<Teacher> listTeachers(Collection<Integer> teacherIds) {
        if (teacherIds.isEmpty()) return new ArrayList<Teacher>();

        String sql = "SELECT Id, UserId, Pic, Name, IdNo, Gender AS Sex, Birthday, Address FROM SG_Teacher WHERE Id IN (" + StringUtils.join(teacherIds, ",") + ") AND Status<>0";
        List<Teacher> teachers = queryObjectList(sql, Teacher.class);

        Map<Integer, Teacher> teachersMap = new HashMap<Integer, Teacher>();
        Set<Long> userIds = new HashSet<Long>();
        for (Teacher teacher : teachers) {
            teachersMap.put(teacher.getId(), teacher);
            userIds.add(teacher.getUserId());
        }

        Map<Long, List<TeacherExperience>> experiencesMap = queryExperiences(userIds);
        Map<Long, List<TeacherEducation>> educationsMap = queryEducations(userIds);

        List<Teacher> result = new ArrayList<Teacher>();
        for (int teacherId : teacherIds) {
            Teacher teacher = teachersMap.get(teacherId);
            if (teacher == null) teacher = new Teacher();

            teacher.setExperiences(experiencesMap.get(teacher.getUserId()));<commit_msg>未申请返回工作经历和教育背景<commit_after>package cn.momia.service.user.teacher.impl;

import cn.momia.api.user.dto.Teacher;
import cn.momia.api.user.dto.TeacherEducation;
import cn.momia.api.user.dto.TeacherExperience;
import cn.momia.api.user.dto.TeacherStatus;
import cn.momia.common.service.AbstractService;
import cn.momia.service.user.teacher.TeacherService;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.KeyHolder;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TeacherServiceImpl extends AbstractService implements TeacherService {
    @Override
    public TeacherStatus status(long userId) {
        String sql = "SELECT Status, Msg FROM SG_Teacher WHERE UserId=? AND Status<>0";
        return queryObject(sql, new Object[] { userId }, TeacherStatus.class, TeacherStatus.NOT_EXIST_TEACHER_STATUS);
    }

    @Override
    public Teacher getByUser(long userId) {
        String sql = "SELECT Id FROM SG_Teacher WHERE UserId=? AND Status<>0";
        List<Integer> teacherIds = queryIntList(sql, new Object[] { userId });
        List<Teacher> teachers = listTeachers(teacherIds);

        if (!teachers.isEmpty()) return teachers.get(0);

        Teacher teacher = new Teacher();
        teacher.setExperiences(queryExperiences(Sets.newHashSet(userId)).get(userId));
        teacher.setEducations(queryEducations(Sets.newHashSet(userId)).get(userId));

        return teacher;
    }

    private List<Teacher> listTeachers(Collection<Integer> teacherIds) {
        if (teacherIds.isEmpty()) return new ArrayList<Teacher>();

        String sql = "SELECT Id, UserId, Pic, Name, IdNo, Gender AS Sex, Birthday, Address FROM SG_Teacher WHERE Id IN (" + StringUtils.join(teacherIds, ",") + ") AND Status<>0";
        List<Teacher> teachers = queryObjectList(sql, Teacher.class);

        Map<Integer, Teacher> teachersMap = new HashMap<Integer, Teacher>();
        Set<Long> userIds = new HashSet<Long>();
        for (Teacher teacher : teachers) {
            teachersMap.put(teacher.getId(), teacher);
            userIds.add(teacher.getUserId());
        }

        Map<Long, List<TeacherExperience>> experiencesMap = queryExperiences(userIds);
        Map<Long, List<TeacherEducation>> educationsMap = queryEducations(userIds);

        List<Teacher> result = new ArrayList<Teacher>();
        for (int teacherId : teacherIds) {
            Teacher teacher = teachersMap.get(teacherId);
            if (teacher == null) continue;

            teacher.setExperiences(experiencesMap.get(teacher.getUserId()));
{'fraction_non_alphanumeric': 0.11370106761565836, 'fraction_numerical': 0.0017793594306049821, 'mean_word_length': 4.01875, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409700', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1671, 'n_words': 365}