<?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.TFaReviewerCommentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TFaReviewerComment">
        <id column="id" property="id"/>
        <result column="project_name" property="projectName"/>
        <result column="project_code" property="projectCode"/>
        <result column="construction_unit" property="constructionUnit"/>
        <result column="industry_code" property="industryCode"/>
        <result column="industry_name" property="industryName"/>
        <result column="starting_time" property="startingTime"/>
        <result column="organ" property="organ"/>
        <result column="ending_time" property="endingTime"/>
        <result column="reference_number" property="referenceNumber"/>
        <result column="equivalent_value" property="equivalentValue"/>
        <result column="indifference_value" property="indifferenceValue"/>
        <result column="incre_equivalent_value" property="increEquivalentValue"/>
        <result column="incre_indifference_value" property="increIndifferenceValue"/>
        <result column="energy_result" property="energyResult"/>
        <result column="electric_expend" property="electricExpend"/>
        <result column="coal_expend" property="coalExpend"/>
        <result column="rest" property="rest"/>
        <result column="user_id" property="userId" />
        <result column="dept_id" property="deptId" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
    </resultMap>

    <sql id="Base_Column_List">
        id,project_name,project_code,construction_unit,industry_code,industry_name,starting_time,organ,ending_time,
        reference_number,equivalent_value,indifference_value,incre_equivalent_value,incre_indifference_value,energy_result,electric_expend,coal_expend,rest,user_id,dept_id,update_time,del_flag,authorized_unit,user_real_name,year,quarter
    </sql>

    <select id="getPage" resultType="com.nantian.cloud.jljc.entity.TFaReviewerComment">
        select <include refid="Base_Column_List"></include>
        from t_fa_reviewer_comment
        where del_flag = "1"
        <if test="query.projectName!=null and query.projectName!=''">
            and project_name like concat("%",#{query.projectName},"%")
        </if>
        <if test="query.constructionUnit !=null and query.constructionUnit!=''">
            and construction_unit like concat("%",#{query.constructionUnit},"%")
        </if>
        <if test="query.year !=null and query.year!=''">
            and year like concat("%",#{query.year},"%")
        </if>
        <if test="query.quarter !=null and query.quarter!=''">
            and quarter like concat("%",#{query.quarter},"%")
        </if>
    </select>
    <select id="getExcelData" resultType="com.nantian.cloud.jljc.entity.TFaReviewerComment">
        select <include refid="Base_Column_List"></include>
        from t_fa_reviewer_comment
        where del_flag = "1"
        <if test="query.projectName!=null and query.projectName!=''">
            and project_name like concat("%",#{query.projectName},"%")
        </if>
        <if test="query.constructionUnit !=null and query.constructionUnit!=''">
            and construction_unit like concat("%",#{query.constructionUnit},"%")
        </if>
        <if test="query.year !=null and query.year!=''">
            and year like concat("%",#{query.year},"%")
        </if>
        <if test="query.quarter !=null and query.quarter!=''">
            and quarter like concat("%",#{query.quarter},"%")
        </if>
        union
        select null id, concat((select meaning2 from dict_region where id = concat(left(t.dept_id,4),'00')),'合计审查合计(',count(t.id),')') project_name, null project_code, null construction_unit, null industry_code, null industry_name, null starting_time, null organ, null ending_time,
        null reference_number,round(sum(equivalent_value),4) equivalent_value, round(sum(indifference_value),4) indifference_value, round(sum(incre_equivalent_value),4) as incre_equivalent_value, round(sum(incre_indifference_value),4) incre_indifference_value,
        round(sum(energy_result),4) energy_result, round(sum(electric_expend),4) electric_expend, round(sum(coal_expend),4) coal_expend, null rest, null user_id, concat(left(dept_id,4),'00') dept_id, null update_time, null del_flag, null authorized_unit, null user_real_name, null year, null quarter
        from t_fa_reviewer_comment t
        where del_flag = "1"
        <if test="query.projectName!=null and query.projectName!=''">
            and project_name like concat("%",#{query.projectName},"%")
        </if>
        <if test="query.constructionUnit !=null and query.constructionUnit!=''">
            and construction_unit like concat("%",#{query.constructionUnit},"%")
        </if>
        <if test="query.year !=null and query.year!=''">
            and year like concat("%",#{query.year},"%")
        </if>
        <if test="query.quarter !=null and query.quarter!=''">
            and quarter like concat("%",#{query.quarter},"%")
        </if>
        group by concat(left(dept_id,4),'00')
        order by concat(left(dept_id,4),'00'), id asc
    </select>

</mapper>
