<?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.web.modules.industryservice.mapper.BizDisposableIncomeMapper">

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizDisposableIncome" id="BizDisposableIncomeResult">
        <id property="id" column="id"/>
        <result property="statYear" column="stat_year"/>
        <result property="ruralDisposableIncome" column="rural_disposable_income"/>
        <result property="incomeIncrease" column="income_increase"/>
        <result property="incomeGrowthRate" column="income_growth_rate"/>
        <result property="povertyNetIncome" column="poverty_net_income"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select r.id, r.stat_year, r.rural_disposable_income, r.income_increase, r.income_growth_rate,
               r.poverty_net_income,
               r.create_by, r.create_time, r.update_by, r.update_time, r.remark
        from biz_disposable_income r
    </sql>

    <select id="selectBizDisposableIncomeById" parameterType="long" resultMap="BizDisposableIncomeResult">
        <include refid="selectVo"/>
        where r.id = #{id}
    </select>

    <select id="selectByStatYear" resultMap="BizDisposableIncomeResult">
        <include refid="selectVo"/>
        where r.stat_year = #{statYear}
        limit 1
    </select>

    <select id="countByStatYearExcludeId" resultType="int">
        select count(1) from biz_disposable_income
        where stat_year = #{statYear}
        <if test="excludeId != null">and id != #{excludeId}</if>
    </select>

    <select id="selectBizDisposableIncomeList" parameterType="com.ruoyi.web.modules.industryservice.domain.BizDisposableIncome"
            resultMap="BizDisposableIncomeResult">
        <include refid="selectVo"/>
        <where>
            <if test="statYear != null">and r.stat_year = #{statYear}</if>
        </where>
        order by r.stat_year desc, r.id desc
    </select>

    <insert id="insertBizDisposableIncome" parameterType="com.ruoyi.web.modules.industryservice.domain.BizDisposableIncome"
            useGeneratedKeys="true" keyProperty="id">
        insert into biz_disposable_income (
            stat_year, rural_disposable_income, income_increase, income_growth_rate, poverty_net_income,
            create_by, create_time, remark
        ) values (
            #{statYear}, #{ruralDisposableIncome}, #{incomeIncrease}, #{incomeGrowthRate}, #{povertyNetIncome},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizDisposableIncome" parameterType="com.ruoyi.web.modules.industryservice.domain.BizDisposableIncome">
        update biz_disposable_income set
            stat_year = #{statYear},
            rural_disposable_income = #{ruralDisposableIncome},
            income_increase = #{incomeIncrease},
            income_growth_rate = #{incomeGrowthRate},
            poverty_net_income = #{povertyNetIncome},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizDisposableIncomeByIds">
        delete from biz_disposable_income where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
    </delete>
</mapper>
