<?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.nantian.cloud.jljc.mapper.TFaCheckAcceptMapper">

    <resultMap id="tFaCheckAcceptMap" type="com.nantian.cloud.jljc.entity.TFaCheckAccept">
        <result property="id" column="id"/>
        <result property="oldFileName" column="old_file_name"/>
        <result property="newFileName" column="new_file_name"/>
        <result property="extension" column="extension"/>
        <result property="fileSize" column="file_size"/>
        <result property="fileType" column="file_type"/>
        <result property="filePath" column="file_path"/>
        <result property="uploadName" column="upload_name"/>
        <result property="uploadTime" column="upload_time"/>
        <result property="projectId" column="project_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="userId" column="user_id"/>
        <result property="deptId" column="dept_id"/>
        <result property="updateTime" column="update_time"/>
        <result property="indifference" column="indifference"/>
        <result property="energySaving" column="energy_saving"/>
        <result property="electricity" column="electricity"/>
        <result property="coal" column="coal"/>
        <result property="reset" column="reset"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,old_file_name,new_file_name,extension,file_size,file_type,file_path,upload_name
        ,user_id,dept_id,update_time,upload_time,project_id,del_flag,indifference，energy_saving
        ,electricity,coal,reset
    </sql>


    <select id="getTotal" resultType="com.nantian.cloud.jljc.vo.TFaTotalDataVo">
        <choose>
            <when test="deptId != null and deptId != ''">
                SELECT t.dept_id AS dept_id, d.meaning2 AS real_name,
                SUM( equivalent ) AS equi_sum,
                SUM( electricity ) AS elec_sum,
                SUM( energy_saving ) AS ener_sum,
                SUM( indifference ) AS indi_sum,
                COUNT(1) AS count
                FROM t_fa_check_accept t,(
                select id,meaning2 from dict_region where pid =
                (select id from dict_region where meaning2 = #{deptId})) d
                where t.dept_id = d.id
                group by t.dept_id
            </when>
            <otherwise>
                SELECT left(t.dept_id,4) AS dept_id, d.meaning2 AS real_name,
                SUM( equivalent ) AS equi_sum,
                SUM( electricity ) AS elec_sum,
                SUM( energy_saving ) AS ener_sum,
                SUM( indifference ) AS indi_sum,
                COUNT(1) AS count
                FROM
                t_fa_check_accept t
                left join dict_region d on concat(left(t.dept_id,4),'00') = d.id
                WHERE t.del_flag = 1
                group by left(t.dept_id,4)
            </otherwise>
        </choose>
    </select>

</mapper>
