<?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.srs.stureg.mapper.SrsStuRegCountMapper">

    <resultMap id="ExistKsh" type="SrsStuReg">
        <result property="KSH" column="KSH"/>
    </resultMap>

    <resultMap type="SrsStuReg" id="SrsStuRegResult">
        <result property="id" column="id"/>
        <result property="XSXM" column="XSXM"/>
        <result property="KSH" column="KSH"/>
        <result property="SFZH" column="SFZH"/>
        <result property="SJH" column="SJH"/>
        <result property="XB" column="XB"/>
        <result property="ZZMM" column="ZZMM"/>
        <result property="MZ" column="MZ"/>
        <result property="XH" column="XH"/>
        <result property="XY" column="XY"/>
        <result property="XYDM" column="XYDM"/>
        <result property="ZY" column="ZY"/>
        <result property="ZYDM" column="ZYDM"/>
        <result property="BJ" column="BJ"/>
        <result property="BJDM" column="BJDM"/>
        <result property="lastSchool" column="last_school"/>
        <result property="lastSchoolAddr" column="last_school_addr"/>
        <result property="famName" column="fam_name"/>
        <result property="famRelation" column="fam_relation"/>
        <result property="famPhone" column="fam_phone"/>
        <result property="famNowAddr" column="fam_now_addr"/>
        <result property="sfzAddr" column="sfz_addr"/>
        <result property="regStatus" column="reg_status"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="delFlag" column="del_flag"/>
        <result property="isChangePwd" column="is_change_pwd"/>
        <result property="dorm" column="dorm"/>
        <result property="isLoan" column="is_loan"/>
        <result property="isDirection" column="is_direction"/>
        <result property="loanNo" column="loan_no"/>
        <result property="deptId"    column="dept_id"    />
        <result property="majorId"    column="major_id"    />
        <result property="classId"    column="class_id"    />
    </resultMap>

    <sql id="selectSrsStuRegVo">
        select a.*,
               case c.room_no is NULL
                   when true then "无"
                   else concat(c.park_name,' ',c.building_name,' ',c.room_no) end as dorm
        from srs_stu_reg as a
                 left join dms_new_reg as b on a.KSH = b.ksh
                 left join view_dorm_info as c on b.dormitory_id = c.id
    </sql>

    <!--查询全部-->
    <select id="selectTable" resultType="java.util.HashMap">
        select *
        from ${tableName}
    </select>
    <!--查询条数-->
    <select id="selectTableCount" resultType="int">
        select count(1)
        from ${tableName}
    </select>

    <select id="countDept" resultType="Map">
        select dept_name,
               b.xydm,
               case when total is null then 0 else total end     as total,
               case when xytotal is null then 0 else xytotal end as xytotal,
               case when jftotal is null then 0 else jftotal end as jftotal
        from (select dept_name, dept_code from sys_dept where parent_id = 1014 and dept_name like '%学院%') a
                 left join (select xydm, (select count(1) from srs_stu_reg) as total, count(1) as xytotal
                            from srs_stu_reg
                            group by xydm) b on a.dept_code = b.xydm
                 left join (select xydm, count(1) as jftotal
                            from srs_stu_reg
                            where reg_status = 1
                            group by xydm) c on b.xydm = c.xydm
    </select>

    <select id="countArea" resultType="DataScreen" parameterType="SrsStuReg">
        SELECT
            COUNT(ksh) AS `value`,
            CASE
                WHEN a.sfz_addr LIKE '%北京%' THEN '北京'
                WHEN a.sfz_addr LIKE '%天津%' THEN '天津'
                WHEN a.sfz_addr LIKE '%河北%' THEN '河北'
                WHEN a.sfz_addr LIKE '%山西%' THEN '山西'
                WHEN a.sfz_addr LIKE '%内蒙古%' THEN '内蒙古'
                WHEN a.sfz_addr LIKE '%辽宁%' THEN '辽宁'
                WHEN a.sfz_addr LIKE '%吉林%' THEN '吉林'
                WHEN a.sfz_addr LIKE '%黑龙江%' THEN '黑龙江'
                WHEN a.sfz_addr LIKE '%上海%' THEN '上海'
                WHEN a.sfz_addr LIKE '%江苏%' THEN '江苏'
                WHEN a.sfz_addr LIKE '%浙江%' THEN '浙江'
                WHEN a.sfz_addr LIKE '%安徽%' THEN '安徽'
                WHEN a.sfz_addr LIKE '%福建%' THEN '福建'
                WHEN a.sfz_addr LIKE '%江西%' THEN '江西'
                WHEN a.sfz_addr LIKE '%山东%' THEN '山东'
                WHEN a.sfz_addr LIKE '%河南%' THEN '河南'
                WHEN a.sfz_addr LIKE '%湖北%' THEN '湖北'
                WHEN a.sfz_addr LIKE '%湖南%' THEN '湖南'
                WHEN a.sfz_addr LIKE '%广东%' THEN '广东'
                WHEN a.sfz_addr LIKE '%广西%' THEN '广西'
                WHEN a.sfz_addr LIKE '%海南%' THEN '海南'
                WHEN a.sfz_addr LIKE '%重庆%' THEN '重庆'
                WHEN a.sfz_addr LIKE '%四川%' THEN '四川'
                WHEN a.sfz_addr LIKE '%贵州%' THEN '贵州'
                WHEN a.sfz_addr LIKE '%云南%' THEN '云南'
                WHEN a.sfz_addr LIKE '%西藏%' THEN '西藏'
                WHEN a.sfz_addr LIKE '%陕西%' THEN '陕西'
                WHEN a.sfz_addr LIKE '%甘肃%' THEN '甘肃'
                WHEN a.sfz_addr LIKE '%青海%' THEN '青海'
                WHEN a.sfz_addr LIKE '%宁夏%' THEN '宁夏'
                WHEN a.sfz_addr LIKE '%新疆%' THEN '新疆'
                ELSE '其他'
                END AS `name`
        FROM
            srs_stu_reg AS a
        where reg_status = 1
        GROUP BY
            CASE
                WHEN a.sfz_addr LIKE '%北京%' THEN '北京'
                WHEN a.sfz_addr LIKE '%天津%' THEN '天津'
                WHEN a.sfz_addr LIKE '%河北%' THEN '河北'
                WHEN a.sfz_addr LIKE '%山西%' THEN '山西'
                WHEN a.sfz_addr LIKE '%内蒙古%' THEN '内蒙古'
                WHEN a.sfz_addr LIKE '%辽宁%' THEN '辽宁'
                WHEN a.sfz_addr LIKE '%吉林%' THEN '吉林'
                WHEN a.sfz_addr LIKE '%黑龙江%' THEN '黑龙江'
                WHEN a.sfz_addr LIKE '%上海%' THEN '上海'
                WHEN a.sfz_addr LIKE '%江苏%' THEN '江苏'
                WHEN a.sfz_addr LIKE '%浙江%' THEN '浙江'
                WHEN a.sfz_addr LIKE '%安徽%' THEN '安徽'
                WHEN a.sfz_addr LIKE '%福建%' THEN '福建'
                WHEN a.sfz_addr LIKE '%江西%' THEN '江西'
                WHEN a.sfz_addr LIKE '%山东%' THEN '山东'
                WHEN a.sfz_addr LIKE '%河南%' THEN '河南'
                WHEN a.sfz_addr LIKE '%湖北%' THEN '湖北'
                WHEN a.sfz_addr LIKE '%湖南%' THEN '湖南'
                WHEN a.sfz_addr LIKE '%广东%' THEN '广东'
                WHEN a.sfz_addr LIKE '%广西%' THEN '广西'
                WHEN a.sfz_addr LIKE '%海南%' THEN '海南'
                WHEN a.sfz_addr LIKE '%重庆%' THEN '重庆'
                WHEN a.sfz_addr LIKE '%四川%' THEN '四川'
                WHEN a.sfz_addr LIKE '%贵州%' THEN '贵州'
                WHEN a.sfz_addr LIKE '%云南%' THEN '云南'
                WHEN a.sfz_addr LIKE '%西藏%' THEN '西藏'
                WHEN a.sfz_addr LIKE '%陕西%' THEN '陕西'
                WHEN a.sfz_addr LIKE '%甘肃%' THEN '甘肃'
                WHEN a.sfz_addr LIKE '%青海%' THEN '青海'
                WHEN a.sfz_addr LIKE '%宁夏%' THEN '宁夏'
                WHEN a.sfz_addr LIKE '%新疆%' THEN '新疆'
                ELSE '其他'
                END
    </select>

    <select id="countMajorTop10"  resultType="Map">
        select major_name,
               a.major_code,
               case when total is null then 0 else total end     as total,
               case when zytotal is null then 0 else zytotal end as zytotal,
               case when jftotal is null then 0 else jftotal end as jftotal
        from (select major_name, major_code from srs_majors) a
                 left join (select ZY, (select count(1) from srs_stu_reg) as total, count(1) as zytotal
                            from srs_stu_reg
                            group by ZY) b on a.major_name = b.ZY
                 left join (select ZY, count(1) as jftotal
                            from srs_stu_reg
                            where reg_status = 1
                            group by ZY) c on b.ZY = c.ZY
        ORDER BY jftotal desc
        LIMIT 0,10
    </select>

    <select id="countNowAt" resultType="Map">
        select (select count(ksh)
                from srs_stu_reg)         as need_at,
               (select count(ksh)
                from srs_stu_reg as a
                where a.reg_status = '1') as now_at
    </select>

    <select id="countGender" resultType="DataScreen">
        select count(ksh) as `value`, a.XB as `name`
        from srs_stu_reg as a
        GROUP BY a.XB
    </select>

    <select id="countHour" resultType="Map">
        SELECT HOUR(update_time) AS hours,count(1) as bdtotal
        from srs_stu_todo as a
        WHERE `status` = '1' and DATE(update_time) = CURDATE() and task_code='ZXJF'
        GROUP BY hours
        order by  hours
    </select>
    <select id="countClass" resultType="Map">
        select a.major_code,cl.class_name,b.BJDM,
               case when total is null then 0 else total end as total,
               case when bjtotal is null then 0 else bjtotal end as bjtotal,
               case when jftotal is null then 0 else jftotal end as jftotal
        from (select BJDM,(select count(1) from srs_stu_reg) as total,count(1) as bjtotal
              from srs_stu_reg  group by BJDM ) b
                 left join (select class_name,class_code,major_id from srs_class) as cl on cl.class_code=b.BJDM
                 left join (select major_id,major_name,major_code from srs_majors) a on cl.major_id=a.major_id
                 left join ( select BJDM,count(1) as jftotal from srs_stu_reg where reg_status=1
                             group by BJDM ) c on cl.class_code=c.BJDM
        ORDER BY jftotal desc
    </select>
    <select id="selectCountByRegStatus" resultType="java.lang.Integer">
        select count(*)
        from srs_stu_reg
        where reg_status = #{regStatus}
    </select>

    <select id="atStationCount" resultType="Map">
        select case when tools_type=1 then '飞机'
                    when tools_type=2 then '火车'
                    when tools_type=4 then '自驾'
                    when tools_type=5 then '巴士' else '巴士' end as tooltype,count(1) as totalnum
        from srs_at_station  where create_time>CURDATE()-INTERVAL 90 DAY
        group by tools_type
    </select>


    <select id="atStationByCampusCount" resultType="Map">
        select case when tools_type=1 then '飞机'
                    when tools_type=2 then '火车'
                    when tools_type=4 then '自驾'
                    when tools_type=5 then '巴士' else '巴士' end as tooltype,count(1) as totalnum,xq
        from (
                 select s.tools_type,case  when r.xy='经济管理学院' then '长堽校区'
                                           when  r.xy='信息工程学院' then '长堽校区' else '里建校区' end as xq
                 from srs_at_station s inner  join srs_stu_reg r on s.ksh=r.ksh where s.create_time>CURDATE()-INTERVAL 90 DAY ) t
        group by tools_type,xq order by xq,totalnum desc
    </select>


</mapper>
