<?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.system.mapper.house.HouseResourceMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.house.HouseResource">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="relationId" column="relation_id" jdbcType="VARCHAR"/>
        <result property="two" column="two" jdbcType="VARCHAR"/>
        <result property="three" column="three" jdbcType="VARCHAR"/>
        <result property="four" column="four" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="projectId" column="project_id" jdbcType="VARCHAR"/>
        <result property="houseResourceUrl" column="house_resource_url" jdbcType="VARCHAR"/>
        <result property="houseNumber" column="house_number" jdbcType="VARCHAR"/>
        <result property="houseArea" column="house_area" jdbcType="INTEGER"/>
        <result property="houseResourceAttribute" column="house_resource_attribute" jdbcType="INTEGER"/>
        <result property="houseResourceType" column="house_resource_type" jdbcType="INTEGER"/>
        <result property="houseResourceUse" column="house_resource_use" jdbcType="VARCHAR"/>
        <result property="houseResourceEquity" column="house_resource_equity" jdbcType="VARCHAR"/>
        <result property="houseResourceEquityTel" column="house_resource_equity_tel" jdbcType="VARCHAR"/>
        <result property="ownership" column="ownership" jdbcType="VARCHAR" />
        <result property="decorationCondition" column="decoration_condition" jdbcType="INTEGER"/>
        <result property="orientation" column="orientation" jdbcType="INTEGER"/>
        <result property="landingHeadFlag" column="landing_head_flag" jdbcType="BIT"/>
        <result property="commonAreaNumber" column="common_area_number" jdbcType="INTEGER"/>
        <result property="officeNumber" column="office_number" jdbcType="INTEGER"/>
        <result property="meetingNumber" column="meeting_number" jdbcType="INTEGER"/>
        <result property="stationNumber" column="station_number" jdbcType="INTEGER"/>
        <result property="setUp" column="set_up" jdbcType="VARCHAR"/>
        <result property="labelId" column="label_id" jdbcType="VARCHAR"/>
        <result property="unitPrice" column="unit_price" jdbcType="DECIMAL"/>
        <result property="rentalUnit" column="rental_unit" jdbcType="INTEGER"/>
        <result property="planeGraphUrl" column="plane_graph_url" jdbcType="VARCHAR"/>
        <result property="hireStatus" column="hire_status" jdbcType="INTEGER"/>
    </resultMap>

    <insert id="insertHouseResource" parameterType="com.ruoyi.system.domain.house.HouseResource">
        INSERT INTO house_resource
        (id, relation_id, two, three, four, type, project_id, house_resource_url, house_number, house_area,
         house_resource_attribute, house_resource_type, house_resource_use, house_resource_equity, house_resource_equity_tel, ownership,
         decoration_condition, orientation, landing_head_flag, common_area_number, office_number,
         meeting_number, station_number, set_up, label_id, unit_price, rental_unit, plane_graph_url, hire_status)
        VALUES
            (#{id}, #{relationId}, #{two}, #{three}, #{four}, #{type}, #{projectId}, #{houseResourceUrl}, #{houseNumber}, #{houseArea},
             #{houseResourceAttribute}, #{houseResourceType}, #{houseResourceUse}, #{houseResourceEquity}, #{houseResourceEquityTel}, #{ownership},
             #{decorationCondition}, #{orientation}, #{landingHeadFlag}, #{commonAreaNumber}, #{officeNumber},
             #{meetingNumber}, #{stationNumber}, #{setUp}, #{labelId}, #{unitPrice}, #{rentalUnit}, #{planeGraphUrl}, #{hireStatus})
    </insert>

    <select id="selectHouseResourceById" resultType="com.ruoyi.system.domain.house.HouseResource" parameterType="string">
        SELECT * FROM house_resource WHERE id = #{id}
    </select>

    <update id="updateHouseResource" parameterType="com.ruoyi.system.domain.house.HouseResource">
        UPDATE house_resource
        SET relation_id = #{relationId},
            two = #{two},
            three = #{three},
            four = #{four},
            type = #{type},
            project_id = #{projectId},
            house_resource_url = #{houseResourceUrl},
            house_number = #{houseNumber},
            house_area = #{houseArea},
            house_resource_attribute = #{houseResourceAttribute},
            house_resource_type = #{houseResourceType},
            house_resource_use = #{houseResourceUse},
            house_resource_equity = #{houseResourceEquity},
            house_resource_equity_tel = #{houseResourceEquityTel},
            ownership = #{ownership},
            decoration_condition = #{decorationCondition},
            orientation = #{orientation},
            landing_head_flag = #{landingHeadFlag},
            common_area_number = #{commonAreaNumber},
            office_number = #{officeNumber},
            meeting_number = #{meetingNumber},
            station_number = #{stationNumber},
            set_up = #{setUp},
            label_id = #{labelId},
            unit_price = #{unitPrice},
            rentalUnit = #{rental_unit},
            plane_graph_url = #{planeGraphUrl},
            hire_status = #{hire_status}
        WHERE id = #{id}
    </update>

    <delete id="deleteHouseResourceById" parameterType="string">
        DELETE FROM house_resource WHERE id = #{id}
    </delete>

    <insert id="batchInsertHouseResources" parameterType="java.util.List">
        INSERT INTO house_resource
        (id, relation_id, two, three, four, type, project_id, house_resource_url, house_number, house_area,
        house_resource_attribute, house_resource_type, house_resource_use, house_resource_equity, house_resource_equity_tel, ownership,
        decoration_condition, orientation, landing_head_flag, common_area_number, office_number,
        meeting_number, station_number, set_up, label_id, unit_price, rental_unit, plane_graph_url, hire_status)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.id}, #{item.relationId},  #{two}, #{three}, #{four}, #{item.type}, #{item.projectId}, #{item.houseResourceUrl},
            #{item.houseNumber}, #{item.houseArea}, #{item.houseResourceAttribute}, #{item.houseResourceType},
            #{item.houseResourceUse}, #{item.houseResourceEquity}, #{item.houseResourceEquityTel}, #{ownership}, #{item.decorationCondition},
            #{item.orientation}, #{item.landingHeadFlag}, #{item.commonAreaNumber}, #{item.officeNumber},
            #{item.meetingNumber}, #{item.stationNumber}, #{item.setUp}, #{item.labelId}, #{item.unitPrice}, #{item.rentalUnit},
            #{item.planeGraphUrl}, #{item.hireStatus})
        </foreach>
    </insert>

    <select id="selectPage" resultType="com.ruoyi.system.domain.house.vo.HouseResourcePage">
        SELECT t1.*, t2.wg_name AS wgName FROM house_resource t1 LEFT JOIN grid_region t2 ON t1.four = t2.id
        <where>
            <if test="query.two != null and query.two != ''">
                and two like concat('%', #{query.two}, '%')
            </if>
            <if test="query.three != null and query.three != ''">
                and three like concat('%', #{query.three}, '%')
            </if>
            <if test="query.four != null and query.four != ''">
                and four like concat('%', #{query.four}, '%')
            </if>
            <if test="query.houseResourceAttribute != null and query.houseResourceAttribute != ''">
                and house_resource_attribute = #{query.houseResourceAttribute}
            </if>
            <if test="query.sortWay != null and query.sortWay != ''">
                order by houseArea ${query.sortWay}
            </if>
        </where>
    </select>
</mapper>