<?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.testor.module.partner.dao.TJobAccountingDao">
    <!-- 开启二级缓存 -->
    <!-- <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/> -->
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.testor.module.partner.model.domain.TJobAccounting">
        <id column="id" property="id"/>
        <id column="ref_id" property="refId"/>
        <id column="parent_id" property="parentId"/>
        <id column="tenant_id" property="tenantId"/>
        <id column="process_id" property="processId"/>
        <id column="process_status" property="processStatus"/>
        <id column="org_id" property="orgId"/>
        <id column="acc_start_date" property="accStartDate"/>
        <id column="partner_population" property="partnerPopulation"/>
        <id column="acc_type" property="accType"/>
        <id column="lease_name" property="leaseName"/>
        <id column="lease" property="lease"/>
    </resultMap>

    <select id="dangerousTimes" resultType="com.testor.module.partner.model.vo.TJobAccountingStatisticsVO">
        SELECT org_name as name,COUNT(acc_type) num
        FROM t_job_accounting
        GROUP BY org_name;
    </select>

    <select id="dangerousDistributed" resultType="com.testor.module.partner.model.vo.TJobAccountingStatisticsVO">
        SELECT acc_type as name,COUNT(acc_type) num
        FROM t_job_accounting
        GROUP BY acc_type
    </select>

    <select id="partnerPeopleNum" resultType="com.testor.module.partner.model.vo.TJobAccountingStatisticsVO">
        SELECT org_name as name,SUM(partner_population) num
        FROM t_job_accounting
        GROUP BY org_name
    </select>

    <select id="sum" resultType="com.testor.module.partner.model.vo.TJobAccountingSumVO">
        SELECT
            b.org_name as name,
            c.count AS acc_type_count,
            b.count AS partner_population_count
        FROM
            ( SELECT org_name, SUM( partner_population ) count FROM t_job_accounting GROUP BY org_name ) AS b
                LEFT JOIN ( SELECT org_name, COUNT( acc_type ) count FROM t_job_accounting GROUP BY org_name ) AS c ON b.org_name = c.org_name
    </select>
</mapper>