<?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.BusinessEntitySellMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.house.BusinessEntitySell">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="business_entity_info_id" property="businessEntityInfoId" jdbcType="VARCHAR"/>
        <result column="year" property="year" jdbcType="INTEGER"/>
        <result column="year_sell" property="yearSell" jdbcType="DECIMAL"/>
        <result column="year_tax" property="yearTax" jdbcType="DECIMAL"/>
        <result column="compare" property="compare" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 插入操作 -->
    <insert id="insertBusinessEntitySell" parameterType="com.ruoyi.system.domain.house.BusinessEntitySell">
        INSERT INTO business_entity_sell (
            id, business_entity_info_id, year, year_sell, year_tax, compare
        ) VALUES (
                     #{id}, #{businessEntityInfoId}, #{year}, #{yearSell}, #{yearTax}, #{compare}
                 )
    </insert>

    <!-- 根据ID查询操作 -->
    <select id="selectBusinessEntitySellById" resultMap="BaseResultMap">
        SELECT * FROM business_entity_sell WHERE id = #{id}
    </select>

    <!-- 更新操作 -->
    <update id="updateBusinessEntitySell" parameterType="com.ruoyi.system.domain.house.BusinessEntitySell">
        UPDATE business_entity_sell
        <set>
            <if test="businessEntityInfoId != null">business_entity_info_id=#{businessEntityInfoId},</if>
            <if test="year != null">year=#{year},</if>
            <if test="yearSell != null">year_sell=#{yearSell},</if>
            <if test="yearTax != null">year_tax=#{yearTax},</if>
            <if test="compare != null">compare=#{compare},</if>
        </set>
        WHERE id=#{id}
    </update>

    <!-- 删除操作 -->
    <delete id="deleteBusinessEntitySellById">
        DELETE FROM business_entity_sell WHERE id = #{id}
    </delete>

    <!-- 查询所有记录操作 -->
    <select id="selectAllBusinessEntitySells" resultMap="BaseResultMap">
        SELECT * FROM business_entity_sell
    </select>

    <delete id="deleteBusinessEntitySellByEntityId">
        DELETE FROM business_entity_sell WHERE business_entity_info_id = #{businessEntityId}
    </delete>

    <select id="selectBusinessEntitySellByEntityId"
            resultType="com.ruoyi.system.domain.house.BusinessEntitySell">
        SELECT * FROM business_entity_sell WHERE business_entity_info_id = #{entityId}
    </select>
    <select id="selectBusinessEntitySellByEntityIds"
            resultType="com.ruoyi.system.domain.house.BusinessEntitySell">
        SELECT * FROM business_entity_sell WHERE business_entity_info_id in <foreach collection="entityIds" item="entityId" open="(" close=")" separator=",">#{entityId}</foreach>
    </select>
    <select id="selectBusinessEntitySellByBusinessEntityInfoId"
            resultType="com.ruoyi.system.domain.house.BusinessEntitySell">
        SELECT
            t2.*
        FROM
            business_entity_info t1
                LEFT JOIN business_entity_sell t2 ON t1.id = t2.business_entity_info_id
        WHERE t1.id = #{businessEntityInfoId} AND t2.year = #{year}
        limit 1
    </select>
    <select id="selectBusinessEntityTaxByBusinessEntityInfoId"
            resultType="com.ruoyi.system.domain.house.BusinessEntitySell">
        SELECT
            t2.*
        FROM
            business_entity_info t1
                LEFT JOIN business_entity_sell t2 ON t1.id = t2.business_entity_info_id
        WHERE t1.id = #{businessEntityInfoId} AND t2.year = #{year}
            limit 1
    </select>
</mapper>
