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

    <select id="queryPageList" resultType="com.ruoyi.zdsz.domain.vo.ZEngineeringGasOpeningVo">
        SELECT
            z.id as id,
            z.district,
            z.area_id,
            z.building_id,
            z.unit_id,
            z.house_id,
            e.dict_label AS districtName,
            z.state,
            z.create_time as createTime,
            if(a.name is null , '未知' ,a.NAME) AS areaName,
            if(b.name is null , '未知' ,b.NAME) AS buildingName,
            if(c.name is null , '未知' ,c.NAME) AS unitName,
            if(d.name is null , '未知' ,d.NAME) AS houseName
        FROM
            z_engineering_gas_opening z
            LEFT JOIN z_area a ON z.area_id = a.id
            LEFT JOIN z_building b ON z.building_id = b.id
            LEFT JOIN z_unit c ON z.unit_id = c.id
            LEFT JOIN z_house d ON z.house_id = d.id
            LEFT JOIN sys_dict_data e ON e.dict_value = z.district
        where z.del_flag = 0
        <if test="p.district != null and p.district != ''">
            and z.district = #{p.district}
        </if>
        <if test="p.areaId != null and p.areaId != ''">
            and z.area_id = #{p.areaId}
        </if>
        <if test="p.buildingId != null and p.buildingId != ''">
            and z.building_id = #{p.buildingId}
        </if>
        <if test="p.unitId != null and p.unitId != ''">
            and z.unit_id = #{p.unitId}
        </if>
        <if test="p.houseId != null and p.houseId != ''">
            and z.house_id = #{p.houseId}
        </if>
        <if test="p.createBy != null and p.createBy != ''">
            and z.create_by = #{p.createBy}
        </if>
        <if test="p.completionStatus != null and p.completionStatus != ''">
            and z.state = #{p.completionStatus}
        </if>
        order by z.update_info_time desc
    </select>
    <select id="queryVoById" parameterType="java.lang.String" resultType="com.ruoyi.zdsz.domain.vo.ZEngineeringGasOpeningVo">
        SELECT
            z.id,
            z.state,
            z.engin_type AS engintype,
            z.district,
            z.area_id AS areaId,
            z.building_id AS buildingId,
            z.unit_id AS unitId,
            z.house_id AS houseId,
            z.is_anti_corrosion_paint AS isAntiCorrosionPaint,
            z.is_vertical_bar_clamp AS isVerticalBarClamp,
            z.vertical_bar_test AS verticalBarTest,
            z.household_test AS householdTest,
            z.gas_meter_number AS gasMeterNumber,
            z.gas_meter_count AS gasMeterCount,
            z.gas_meter_brand AS gasMeterBrand,
            z.gas_meter_direction AS gasMeterDirection,
            e1.dict_label AS gasMeterDirectionName,
            z.gas_meter_type AS gasMeterType,
            z.is_rear_pipe_clamp AS isRearPipeClamp,
            z.is_gas_change_type AS isGasChangeType,
            z.gas_change_type AS gasChangeType,
            e2.dict_label AS gasChangeTypeName,
            z.is_windproof_circle AS isWindproofCircle,
            z.engin_name AS enginName,
            z.version,
            z.remark,
            z.del_flag AS delFlag,
            z.create_by AS createBy,
            z.create_time AS createTime,
            z.update_by AS updateBy,
            z.update_time AS updateTime,
            z.update_info_time AS updateInfoTime,
            e.dict_label AS districtName,
            if(a.name is null , '未知' ,a.NAME) AS areaName,
            if(b.name is null , '未知' ,b.NAME) AS buildingName,
            if(c.name is null , '未知' ,c.NAME) AS unitName,
            if(d.name is null , '未知' ,d.NAME) AS houseName
        FROM
            z_engineering_gas_opening z
                LEFT JOIN z_area a ON z.area_id = a.id
                LEFT JOIN z_building b ON z.building_id = b.id
                LEFT JOIN z_unit c ON z.unit_id = c.id
                LEFT JOIN z_house d ON z.house_id = d.id
                LEFT JOIN sys_dict_data e ON e.dict_value = z.district
                LEFT JOIN sys_dict_data e1 ON e1.dict_value = z.gas_meter_direction
                LEFT JOIN sys_dict_data e2 ON e2.dict_value = z.gas_change_type
        where z.del_flag = 0 and z.id = #{id}
    </select>
</mapper>
