<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xjrsoft.module.student.mapper.PbVXsxxsfytbMapper">
    <select id="getClassQfCount" resultType="com.xjrsoft.module.student.vo.BaseClassQfCountVo">
        select id, (
            select count(*) from xjr_user t1
                                     inner join base_student_school_roll t2 on t1.id = t2.user_id
                                     inner join pb_v_xsxxsfytb t3 on t1.credential_number = t3.Studentcode
            where t3.qfje > 0 and t2.class_id = base_class.id
        ) as count
        from base_class where delete_mark = 0
    </select>

    <select id="getList" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbDto" resultType="com.xjrsoft.module.student.vo.PbVXsxxsfytbVo">
        SELECT * FROM pb_v_xsxxsfytb WHERE 1 = 1
        <if test="dto.studentCodes != null and dto.studentCodes.size() > 0">
            and Studentcode IN
            <foreach item="studentcode" index="index" collection="dto.studentCodes" open="(" close=")" separator=",">
                #{studentcode}
            </foreach>
        </if>
        AND beltcode = #{dto.beltcode} and feeitemcode in (103042766003001, 999010604, 999010603)
    </select>
    <select id="getSpecnameCount" parameterType="com.xjrsoft.module.student.dto.EnrollmentStatisticsInfoDto" resultType="com.xjrsoft.module.student.vo.PbVXsxxsfytbSpecnameCountVo">
        SELECT specname,COUNT(DISTINCT(Studentcode)) as student_count FROM pb_v_xsxxsfytb WHERE jfzt = '已缴费' AND enteryear = #{dto.year} GROUP BY specname
    </select>
    <select id="getStudentFeeInfo" parameterType="com.xjrsoft.module.student.dto.BaseStudentInfoDetailDto" resultType="com.xjrsoft.module.student.vo.PbVXsxxsfytbFeeitemVo">
        SELECT replace(IFNULL((SELECT jfzt FROM pb_v_xsxxsfytb WHERE Studentcode = #{dto.credentialNumber} AND feeitemcode LIKE '999010604%' AND beltcode = #{dto.beltcode}),'欠费'),'未缴费','欠费') AS jxf,
               replace(IFNULL((SELECT jfzt FROM pb_v_xsxxsfytb WHERE Studentcode = #{dto.credentialNumber} AND feeitemcode LIKE '999010603%' AND beltcode = #{dto.beltcode}),'欠费'),'未缴费','欠费') AS jcf,
               replace(IFNULL((SELECT jfzt FROM pb_v_xsxxsfytb WHERE Studentcode = #{dto.credentialNumber} AND feeitemcode = 103042766003001 AND beltcode = #{dto.beltcode}),'欠费'),'未缴费','欠费') AS ssf
    </select>

    <select id="getFeeDetail" resultType="com.xjrsoft.module.student.vo.FeeDetailListVo">
        SELECT t4.shortname,t3.name AS semester_name,REPLACE(t1.jfzt,'未缴费','欠费') AS jfzt,t1.factrecarmny,t1.factar FROM pb_v_xsxxsfytb t1
        LEFT JOIN pb_semester_config t2 ON t1.beltcode = t2.beltcode
        LEFT JOIN base_semester t3 ON t2.base_semester_id = t3.id
        LEFT JOIN pb_cse_feeitem2 t4 ON t1.feeitemcode = t4.feeitemcode
        WHERE t1.Studentcode = #{studentcode}
        <if test="beltcode != null and beltcode != ''">
            and t1.beltcode = #{beltcode}
        </if>
    </select>


    <select id="studentCategoryStat" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.StringCountVo">
        SELECT t1.resourcename as name,COUNT(t1.studentcode) as count FROM pb_cse_feeobjupdate t1
        INNER JOIN xjr_user t2 ON t1.studentcode = t2.credential_number
        INNER JOIN base_student_school_roll t3 ON t2.id = t3.user_id
        WHERE t2.delete_mark = 0 AND t3.delete_mark = 0
        <if test="dto.gradeId != null">
            and t3.grade_id = #{dto.gradeId}
        </if>
        GROUP BY t1.resourcename
    </select>
    <select id="stduyStatusStat" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.StringCountVo">
        SELECT t1.quartername as name,COUNT(t1.studentcode) as count FROM pb_cse_feeobjupdate t1
        INNER JOIN xjr_user t2 ON t1.studentcode = t2.credential_number
        INNER JOIN base_student_school_roll t3 ON t2.id = t3.user_id
        WHERE t2.delete_mark = 0 AND t3.delete_mark = 0
        <if test="dto.gradeId != null">
            and t3.grade_id = #{dto.gradeId}
        </if>
        GROUP BY t1.quartername
    </select>
    <select id="stduyStatusStat" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.StringCountVo">
        SELECT t1.quartername as name,COUNT(t1.studentcode) as count FROM pb_cse_feeobjupdate t1
        INNER JOIN xjr_user t2 ON t1.studentcode = t2.credential_number
        INNER JOIN base_student_school_roll t3 ON t2.id = t3.user_id
        WHERE t2.delete_mark = 0 AND t3.delete_mark = 0
        <if test="dto.gradeId != null">
            and t3.grade_id = #{dto.gradeId}
        </if>
        GROUP BY t1.quartername
    </select>

    <select id="getClassQfPage" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.ClassQfPageVo">
        SELECT t1.id, t2.name AS grade_name,t2.name AS class_name,t3.name AS teacher_name,
        (
        SELECT SUM(qfje) FROM pb_v_xsxxsfytb a1
        INNER JOIN xjr_user a2 ON a1.studentcode = a2.credential_number
        INNER JOIN base_student_school_roll a3 ON a2.id = a3.user_id
        WHERE a2.delete_mark = 0 AND a3.delete_mark = 0 AND a3.class_id = t1.id
        ) AS qfzje FROM base_class t1
        INNER JOIN base_grade t2 ON t1.grade_id = t2.id
        LEFT JOIN xjr_user t3 ON t1.teacher_id = t3.id
        WHERE t1.delete_mark = 0
        <if test="dto.gradeId != null">
            and t1.grade_id = #{dto.gradeId}
        </if>
        ORDER BY qfzje DESC
    </select>

    <select id="feeitemStat" parameterType="com.xjrsoft.module.student.dto.PbVXsxxsfytbStatDto" resultType="com.xjrsoft.module.student.vo.NameFee2Vo">
        SELECT t4.shortname as fee_name,SUM(factar) as money1,SUM(qfje) as money2 FROM pb_v_xsxxsfytb t1
        INNER JOIN pb_cse_feeitem2 t4 ON t4.feeitemcode = t1.feeitemcode
        INNER JOIN xjr_user t2 ON t1.Studentcode = t2.credential_number
        INNER JOIN base_student_school_roll t3 ON t3.user_id = t2.id
        WHERE t3.delete_mark = 0 AND t2.delete_mark = 0
        AND t1.feeitemcode IN ('999010604','103042766003001','999010603')
        <if test="dto.gradeId != null">
            and t3.grade_id = #{dto.gradeId}
        </if>
        GROUP BY t4.shortname
    </select>
</mapper>