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

    <resultMap type="com.ruoyi.zdsz.domain.ZEngineeringCivil" id="ZEngineeringCivilResult">
        <result property="id" column="id"/>
        <result property="district" column="district"/>
        <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="enginType" column="engin_type"/>
        <result property="enginClassification" column="engin_classification"/>
        <result property="enginCycle" column="engin_cycle"/>
        <result property="completionStatus" column="completion_status"/>
        <result property="version" column="version"/>
        <result property="imgUrl" column="img_url"/>
        <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="queryPageList" resultType="com.ruoyi.zdsz.domain.vo.ZEngineeringCivilVo">
        select a.*,
               b.name AS areaName,
               c.name AS buildingName,
               d.name AS unitName,
               e.name AS houseName,
               f.dict_label AS enginClassificationName
        from z_engineering_civil a
                 left join z_area b on b.id = a.area_id
                 left join z_building c on c.id = a.building_id
                 left join z_unit d on d.id = a.unit_id
                 left join z_house e on e.id = a.house_id
                    left join  sys_dict_data f on f.dict_type = a.engin_type and f.dict_value = a.engin_classification
        where a.del_flag = 0
        <if test="p.district != null and p.district != ''">
            and a.district = #{p.district}
        </if>
        <if test="p.areaId != null and p.areaId != ''">
            and a.area_id = #{p.areaId}
        </if>
        <if test="p.buildingId != null and p.buildingId != ''">
            and a.building_id = #{p.buildingId}
        </if>
        <if test="p.unitId != null and p.unitId != ''">
            and a.unit_id = #{p.unitId}
        </if>
    </select>
<select id="getObtainRoomcCompletionInformationList" resultType="com.ruoyi.zdsz.domain.vo.roomStatusVo">
    select
    a.area_id,
    a.building_id,
    a.unit_id ,
    c.name AS unitName,
    a.NAME AS roomName,
    a.id AS roomId,
    IFNULL( b.completion_status, '未开工' ) AS roomStatus,
    b.create_time
    FROM
    z_house a
    LEFT JOIN z_engineering_civil b ON a.id = b.house_id
    LEFT JOIN z_unit c ON c.id=a.unit_id
    WHERE
         a.del_flag=0
    <if test="areaId != null and areaId != ''">
        and a.area_id = #{areaId}
    </if>
    <if test="buildingId != null and buildingId != ''">
        and a.building_id = #{buildingId}
    </if>
    <if test="unitId != null and unitId != ''">
        and a.unit_id = #{unitId}
    </if>
    ORDER BY  unitName,a.`name` ASC
</select>
    <select id="getAreaCompletionInformationList"  resultType="com.ruoyi.zdsz.domain.vo.areaWillDoneVo">
        SELECT
            a.area_id,
            d.`name`,
            a.building_id,
            a.unit_id,
            c.NAME AS unitName,
            a.NAME AS roomName,
            a.id AS roomId,
            IFNULL( b.completion_status, '未开工' ) AS roomStatus,
            b.create_time
        FROM
            z_house a
                LEFT JOIN z_engineering_civil b ON a.id = b.house_id and b.engin_cycle=#{enginCycle}
                LEFT JOIN z_unit c ON c.id = a.unit_id
                LEFT JOIN z_area d ON d.id = c.area_id
        WHERE
            a.del_flag = 0
          AND a.area_id in
        <foreach collection="list" item="name" open="(" separator="," close=")">
            #{name}
        </foreach>
        ORDER BY a.area_id ASC

    </select>
    <select id="getsumStatus" resultType="com.ruoyi.zdsz.domain.vo.areaStatusVo">
        SELECT
            COUNT( DISTINCT a.house_id ) AS 'willDone' ,
            ( SELECT COUNT( DISTINCT a.house_id ) FROM z_engineering_civil a WHERE a.completion_status = '完工' AND a.engin_cycle=a.engin_cycle=#{enginCycle}) AS 'done',
            ( SELECT COUNT( a.id ) FROM z_house a )  AS 'notstart'
        FROM
            z_engineering_civil a
        WHERE
            a.completion_status = '未完工'AND a.engin_cycle=#{enginCycle}
    </select>
</mapper>
