<?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.industrypolicy.mapper.BizSubsidyMatterMapper">

    <resultMap type="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter" id="BizSubsidyMatterResult">
        <id     property="id"              column="id"/>
        <result property="subsidyName"     column="subsidy_name"/>
        <result property="introduction"  column="introduction"/>
        <result property="grantStatus"   column="grant_status"/>
        <result property="detailFileUrl" column="detail_file_url"/>
        <result property="detailFilePath" column="detail_file_path"/>
        <result property="detailFileName" column="detail_file_name"/>
        <result property="coverFileUrl"  column="cover_file_url"/>
        <result property="coverFilePath" column="cover_file_path"/>
        <result property="publishStatus" column="publish_status"/>
        <result property="publishTime"   column="publish_time"/>
        <result property="offlineTime"   column="offline_time"/>
        <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, subsidy_name, introduction, grant_status,
               detail_file_url, detail_file_path, detail_file_name,
               cover_file_url, cover_file_path,
               publish_status, publish_time, offline_time,
               create_by, create_time, update_by, update_time, remark
        from biz_subsidy_matter
    </sql>

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

    <select id="selectBizSubsidyMatterList" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter" resultMap="BizSubsidyMatterResult">
        <include refid="selectVo"/>
        <where>
            <if test="keyword != null and keyword != ''">
                and (subsidy_name like concat('%', #{keyword}, '%')
                or introduction like concat('%', #{keyword}, '%'))
            </if>
            <if test="grantStatus != null">
                and grant_status = #{grantStatus}
            </if>
            <if test="publishStatus != null">
                and publish_status = #{publishStatus}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizSubsidyMatter" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter" useGeneratedKeys="true" keyProperty="id">
        insert into biz_subsidy_matter (
            subsidy_name, introduction, grant_status,
            detail_file_url, detail_file_path, detail_file_name,
            cover_file_url, cover_file_path,
            publish_status, publish_time, offline_time,
            create_by, create_time, remark
        ) values (
            #{subsidyName}, #{introduction}, #{grantStatus},
            #{detailFileUrl}, #{detailFilePath}, #{detailFileName},
            #{coverFileUrl}, #{coverFilePath},
            #{publishStatus}, #{publishTime}, #{offlineTime},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizSubsidyMatter" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyMatter">
        update biz_subsidy_matter set
            subsidy_name = #{subsidyName},
            introduction = #{introduction},
            grant_status = #{grantStatus},
            detail_file_url = #{detailFileUrl},
            detail_file_path = #{detailFilePath},
            detail_file_name = #{detailFileName},
            cover_file_url = #{coverFileUrl},
            cover_file_path = #{coverFilePath},
            publish_status = #{publishStatus},
            publish_time = #{publishTime},
            offline_time = #{offlineTime},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizSubsidyMatterByIds" parameterType="long">
        delete from biz_subsidy_matter where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
