<?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.ruoyi.zdsz.mapper.ZMaterialStatisticsMapper">

    <resultMap type="com.ruoyi.zdsz.domain.ZMaterialStatistics" id="ZMaterialStatisticsResult">
        <result property="id" column="id"/>
        <result property="areaId" column="area_id"/>
        <result property="buildingId" column="building_id"/>
        <result property="unitId" column="unit_id"/>
        <result property="houseId" column="house_id"/>
        <result property="realityQuality" column="reality_quality"/>
        <result property="realitySpecifications" column="reality_specifications"/>
        <result property="realitySize" column="reality_size"/>
        <result property="enginCycle" column="engin_cycle"/>
        <result property="remark" column="remark"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
<select id="getZMaterialStatisticsList" resultType="com.ruoyi.zdsz.domain.vo.ZMaterialStatisticsVo" >
    SELECT
        *
    FROM
        z_material_statistics
    WHERE
        del_flag = '0'
        <if test="p.unitId != null  and p.unitId != ''">
            and unit_id LIKE CONCAT('%',#{p.unitId},'%')
        </if>
        <if test="p.areaId != null  and p.areaId != ''">
            and area_id = #{p.areaId}
        </if>
        <if test="p.realityQuality != null  and p.realityQuality != ''">
            and reality_quality = #{p.realityQuality}
        </if>
        <if test="p.realitySpecifications != null  and p.realitySpecifications != ''">
            and reality_specifications = #{p.realitySpecifications}
        </if>
    GROUP BY
    unit_id,
    area_id,
    reality_quality,
    reality_specifications
</select>
    <select id="getZMaterialStatistics" resultType="com.ruoyi.zdsz.domain.vo.MaterialStatisticsListVo" >
        SELECT
        a.area_id,
        c.name AS reality_specifications,
        d.name AS  reality_quality,
        a.reality_size,
        a.engin_cycle,
        d.name AS material_quality,
        c.name as estimated_specifications,
        b.estimated_size
        FROM
        z_material_statistics a
        LEFT JOIN z_engineering_materials_resets b ON a.reality_specifications = b.estimated_specifications
        AND b.area_id LIKE CONCAT( "%", a.area_id, "%" )
        AND a.engin_cycle = b.engin_cycle
        AND a.del_flag = b.del_flag
        LEFT JOIN z_engin_specifications c ON b.estimated_specifications=c.id
        LEFT JOIN z_engin_material_quality d ON d.id= b.material_quality
        WHERE
        1=1
        <if test="areaId != null  and areaId != ''">
            and a.area_id = #{areaId}
        </if>
        <if test="realityQuality != null  and realityQuality != ''">
            and b.material_quality = #{realityQuality}
        </if>
        <if test="realitySpecifications != null  and realitySpecifications != ''">
            and b.estimated_specifications = #{realitySpecifications}
        </if>
        <if test="enginCycle != null  and enginCycle != ''">
            and a.engin_cycle = #{enginCycle}
        </if>

    </select>

</mapper>
