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

    <resultMap type="com.ruoyi.web.modules.industryservice.domain.BizGrassLivestockImbalanceWarning"
               id="BizGrassLivestockImbalanceWarningResult">
        <id     property="id"                         column="id"/>
        <result property="sourceKey"                  column="source_key"/>
        <result property="dataSource"                 column="data_source"/>
        <result property="sourceRecordId"             column="source_record_id"/>
        <result property="statYear"                   column="stat_year"/>
        <result property="statMonth"                  column="stat_month"/>
        <result property="townDeptId"                 column="town_dept_id"/>
        <result property="townName"                   column="town_name"/>
        <result property="villageDeptId"              column="village_dept_id"/>
        <result property="villageName"                column="village_name"/>
        <result property="subjectName"                column="subject_name"/>
        <result property="approvedCarryingCapacity"   column="approved_carrying_capacity"/>
        <result property="yearEndStockSheepUnit"      column="year_end_stock_sheep_unit"/>
        <result property="alertTime"                  column="alert_time"/>
        <result property="alertMessage"               column="alert_message"/>
        <result property="createTime"                 column="create_time"/>
        <result property="updateTime"                 column="update_time"/>
    </resultMap>

    <sql id="selectVo">
        select id, source_key, data_source, source_record_id, stat_year, stat_month,
               town_dept_id, town_name, village_dept_id, village_name, subject_name,
               approved_carrying_capacity, year_end_stock_sheep_unit,
               alert_time, alert_message, create_time, update_time
        from biz_grass_livestock_imbalance_warning
    </sql>

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

    <select id="selectBySourceKey" resultMap="BizGrassLivestockImbalanceWarningResult">
        <include refid="selectVo"/>
        where source_key = #{sourceKey}
        limit 1
    </select>

    <select id="selectList" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassLivestockImbalanceWarning"
            resultMap="BizGrassLivestockImbalanceWarningResult">
        <include refid="selectVo"/>
        <where>
            <if test="dataSource != null and dataSource != ''">
                and data_source = #{dataSource}
            </if>
            <if test="statYear != null">
                and stat_year = #{statYear}
            </if>
            <if test="statMonth != null">
                and stat_month = #{statMonth}
            </if>
            <if test="townDeptId != null">
                and town_dept_id = #{townDeptId}
            </if>
            <if test="villageDeptId != null">
                and village_dept_id = #{villageDeptId}
            </if>
            <if test="subjectName != null and subjectName != ''">
                and subject_name like concat('%', #{subjectName}, '%')
            </if>
            <if test="alertTimeBegin != null">
                and alert_time &gt;= #{alertTimeBegin}
            </if>
            <if test="alertTimeEnd != null">
                and alert_time &lt;= #{alertTimeEnd}
            </if>
        </where>
        order by alert_time desc, id desc
    </select>

    <insert id="insert" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassLivestockImbalanceWarning"
            useGeneratedKeys="true" keyProperty="id">
        insert into biz_grass_livestock_imbalance_warning (
            source_key, data_source, source_record_id, stat_year, stat_month,
            town_dept_id, town_name, village_dept_id, village_name, subject_name,
            approved_carrying_capacity, year_end_stock_sheep_unit,
            alert_time, alert_message, create_time, update_time
        ) values (
            #{sourceKey}, #{dataSource}, #{sourceRecordId}, #{statYear}, #{statMonth},
            #{townDeptId}, #{townName}, #{villageDeptId}, #{villageName}, #{subjectName},
            #{approvedCarryingCapacity}, #{yearEndStockSheepUnit},
            #{alertTime}, #{alertMessage}, #{createTime}, #{updateTime}
        )
    </insert>

    <update id="updateContent" parameterType="com.ruoyi.web.modules.industryservice.domain.BizGrassLivestockImbalanceWarning">
        update biz_grass_livestock_imbalance_warning
        set stat_year = #{statYear},
            stat_month = #{statMonth},
            town_dept_id = #{townDeptId},
            town_name = #{townName},
            village_dept_id = #{villageDeptId},
            village_name = #{villageName},
            subject_name = #{subjectName},
            approved_carrying_capacity = #{approvedCarryingCapacity},
            year_end_stock_sheep_unit = #{yearEndStockSheepUnit},
            alert_time = #{alertTime},
            alert_message = #{alertMessage},
            update_time = #{updateTime}
        where id = #{id}
    </update>

    <delete id="deleteBySourceKey">
        delete from biz_grass_livestock_imbalance_warning
        where source_key = #{sourceKey}
    </delete>

    <delete id="deleteBySourceKeys">
        delete from biz_grass_livestock_imbalance_warning
        where source_key in
        <foreach collection="sourceKeys" item="key" open="(" separator="," close=")">#{key}</foreach>
    </delete>
</mapper>
