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

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizGrassland" id="BizGrasslandResult">
        <id     property="id"                    column="id"/>
        <result property="grasslandName"         column="grassland_name"/>
        <result property="areaMu"                column="area_mu"/>
        <result property="degradationLevel"      column="degradation_level"/>
        <result property="utilizationType"       column="utilization_type"/>
        <result property="grassYieldPerMu"       column="grass_yield_per_mu"/>
        <result property="utilizationRate"       column="utilization_rate"/>
        <result property="grazingBanStartDate"   column="grazing_ban_start_date"/>
        <result property="grazingBanEndDate"     column="grazing_ban_end_date"/>
        <result property="rotationPlotCount"     column="rotation_plot_count"/>
        <result property="rotationGrazingDays"   column="rotation_grazing_days"/>
        <result property="rotationCycleDays"     column="rotation_cycle_days"/>
        <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"/>
        <result property="remark"                column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, grassland_name, area_mu, degradation_level, utilization_type,
               grass_yield_per_mu, utilization_rate,
               grazing_ban_start_date, grazing_ban_end_date,
               rotation_plot_count, rotation_grazing_days, rotation_cycle_days,
               del_flag, create_by, create_time, update_by, update_time, remark
        from biz_grassland
    </sql>

    <select id="selectBizGrasslandById" parameterType="long" resultMap="BizGrasslandResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectBizGrasslandByIdAny" parameterType="long" resultMap="BizGrasslandResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizGrasslandList" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassland" resultMap="BizGrasslandResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="keyword != null and keyword != ''">
                and grassland_name like concat('%', #{keyword}, '%')
            </if>
            <if test="utilizationType != null">
                and utilization_type = #{utilizationType}
            </if>
            <if test="degradationLevel != null">
                and degradation_level = #{degradationLevel}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizGrassland" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassland" useGeneratedKeys="true" keyProperty="id">
        insert into biz_grassland (
            grassland_name, area_mu, degradation_level, utilization_type,
            grass_yield_per_mu, utilization_rate,
            grazing_ban_start_date, grazing_ban_end_date,
            rotation_plot_count, rotation_grazing_days, rotation_cycle_days,
            del_flag, create_by, create_time, remark
        ) values (
            #{grasslandName}, #{areaMu}, #{degradationLevel}, #{utilizationType},
            #{grassYieldPerMu}, #{utilizationRate},
            #{grazingBanStartDate}, #{grazingBanEndDate},
            #{rotationPlotCount}, #{rotationGrazingDays}, #{rotationCycleDays},
            #{delFlag}, #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizGrassland" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassland">
        update biz_grassland set
            grassland_name = #{grasslandName},
            area_mu = #{areaMu},
            degradation_level = #{degradationLevel},
            utilization_type = #{utilizationType},
            grass_yield_per_mu = #{grassYieldPerMu},
            utilization_rate = #{utilizationRate},
            grazing_ban_start_date = #{grazingBanStartDate},
            grazing_ban_end_date = #{grazingBanEndDate},
            rotation_plot_count = #{rotationPlotCount},
            rotation_grazing_days = #{rotationGrazingDays},
            rotation_cycle_days = #{rotationCycleDays},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizGrasslandByIds">
        update biz_grassland set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where del_flag = '0' and id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
