<?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.sooka.mainpage.mapper.MainPageMapper">
    <resultMap id="rm_InterfaceCallCount_Bean" type="com.sooka.mainpage.domain.InterfaceCallCount_Bean"></resultMap>
    <select id="interfaceCallCount" resultMap="rm_InterfaceCallCount_Bean">
     select dept_id,dept_name, IFNULL(info.cou,0) cou,  IFNULL(info_gx.cou,0) cou_gx,IFNULL(info_gj.cou,0) cou_gj from sys_dept dept
		LEFT OUTER JOIN
    (select c.apply_oid org_id, count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c,t_u_log d
    where a.id = b.int_id and b.record_id=c.id and d.interfaceinfo_id=a.id
    group by c.apply_oid) info
    on (dept.dept_id=info.org_id)
		LEFT OUTER JOIN
		(select c.apply_oid org_id, count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c,t_u_log d
    where a.id = b.int_id and b.record_id=c.id and d.interfaceinfo_id=a.id and a.share_type='share_type_1'
    group by c.apply_oid) info_gx
    on (dept.dept_id=info_gx.org_id)

LEFT OUTER JOIN
		(select c.apply_oid org_id, count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c,t_u_log d
    where a.id = b.int_id and b.record_id=c.id and d.interfaceinfo_id=a.id and a.share_type='share_type_2'
    group by c.apply_oid) info_gj
    on (dept.dept_id=info_gj.org_id)

where dept.del_flag=0 and dept.dept_id >200
    order by  info.cou desc
    </select>


    <!--select dept_id,dept_name, IFNULL(info.cou,0) cou,  IFNULL(info_gx.cou,0) cou_gx,IFNULL(info_gj.cou,0) cou_gj from sys_dept dept-->
    <!--LEFT OUTER JOIN-->
    <!--(select c.apply_oid org_id, sum(a.callsuccnum) cou from t_u_interfaceinfo a,int_detailed b,int_record c-->
    <!--where a.id = b.int_id and b.record_id=c.id-->
    <!--group by c.apply_oid) info-->
    <!--on (dept.dept_id=info.org_id)-->
    <!--LEFT OUTER JOIN-->
    <!--(select c.apply_oid org_id, sum(a.callsuccnum) cou from t_u_interfaceinfo a,int_detailed b,int_record c-->
    <!--where a.id = b.int_id and b.record_id=c.id and a.share_type='share_type_1'-->
    <!--group by c.apply_oid) info_gx-->
    <!--on (dept.dept_id=info_gx.org_id)-->

    <!--LEFT OUTER JOIN-->
    <!--(select c.apply_oid org_id, sum(a.callsuccnum) cou from t_u_interfaceinfo a,int_detailed b,int_record c-->
    <!--where a.id = b.int_id and b.record_id=c.id and a.share_type='share_type_2'-->
    <!--group by c.apply_oid) info_gj-->
    <!--on (dept.dept_id=info_gj.org_id)-->

    <!--where dept.del_flag=0 and dept.dept_id >200-->
    <!--order by  info.cou desc-->





    <resultMap id="rm_qssjgxqk" type="com.sooka.mainpage.domain.Qssjgxqk_Bean"></resultMap>
    <select id="qssjgxqk" resultMap="rm_qssjgxqk">
        select dept.dept_id dept_id,dept.dept_name dept_name,IFNULL(gx.cou,0) gx_cou,IFNULL(gj.cou,0) gj_cou,
        IFNULL(gx.cou,0)+IFNULL(gj.cou,0) total_cou
        from sys_dept dept
        LEFT OUTER JOIN
        (select c.apply_oid dept_id,count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c
        where a.share_type='share_type_1' and a.id=b.int_id and b.record_id=c.id
        group by c.apply_oid) gx on (dept.dept_id=gx.dept_id)
        LEFT OUTER JOIN
        (select c.apply_oid dept_id,count(*) cou from t_u_interfaceinfo a,int_detailed b,int_record c
        where a.share_type='share_type_2' and a.id=b.int_id and b.record_id=c.id
        group by c.apply_oid) gj on (gj.dept_id=dept.dept_id)

        where dept.del_flag =0  and dept.dept_id>200
    </select>

    <resultMap id="rm_interfacepinci" type="com.sooka.mainpage.domain.InterfacePinci_Day_Bean"></resultMap>
    <select id="getInterfacePinci_day" resultMap="rm_interfacepinci">
        select DATE_FORMAT(create_time,'%Y/%m/%d') day,count(*) cou from t_u_log
        group by DATE_FORMAT(create_time,'%Y/%m/%d')
        order by create_time asc
    </select>

    <select id="countNumFromDept" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(*) from ${table_name}
    </select>

    <resultMap id="rm_tj_dept_table" type="com.business.domain.TJ_dept_table"></resultMap>
    <select id="getTableNamesBydeptId" parameterType="java.lang.Integer" resultMap="rm_tj_dept_table">
        select id,dept_id,table_name,user_name from tj_dept_table where dept_id=#{dept_id}
    </select>

    <select id="getTableNamesBydeptId_gjj" parameterType="java.lang.Integer" resultMap="rm_tj_dept_table">
        select id,dept_id,table_name,user_name from tj_dept_table_gjj where dept_id=#{dept_id}
    </select>



    <select id="getInterfaceStatusCount" parameterType="java.lang.String" resultType="java.lang.Integer">
        select count(*) from t_u_interfaceinfo where status=#{status}
    </select>


    <select id="getGXPT_jkzs" resultType="java.lang.Integer">
        select count(*) from t_u_interfaceinfo where share_type='share_type_3'
    </select>
</mapper>
