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

    <resultMap type="com.ruoyi.web.modules.industrypolicy.domain.BizIndustryPolicyPublicity" id="BizIndustryPolicyPublicityResult">
        <id     property="id"              column="id"/>
        <result property="policyName"      column="policy_name"/>
        <result property="policyLevel"     column="policy_level"/>
        <result property="introduction"    column="introduction"/>
        <result property="issueDate"       column="issue_date"/>
        <result property="policyDesc"      column="policy_desc"/>
        <result property="policyFileUrl"   column="policy_file_url"/>
        <result property="policyFilePath"  column="policy_file_path"/>
        <result property="policyFileName"  column="policy_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, policy_name, policy_level, introduction, issue_date, policy_desc,
               policy_file_url, policy_file_path, policy_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_industry_policy_publicity
    </sql>

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

    <select id="selectBizIndustryPolicyPublicityList" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizIndustryPolicyPublicity" resultMap="BizIndustryPolicyPublicityResult">
        <include refid="selectVo"/>
        <where>
            <if test="keyword != null and keyword != ''">
                and (policy_name like concat('%', #{keyword}, '%')
                or introduction like concat('%', #{keyword}, '%'))
            </if>
            <if test="policyLevel != null">
                and policy_level = #{policyLevel}
            </if>
            <if test="publishStatus != null">
                and publish_status = #{publishStatus}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizIndustryPolicyPublicity" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizIndustryPolicyPublicity" useGeneratedKeys="true" keyProperty="id">
        insert into biz_industry_policy_publicity (
            policy_name, policy_level, introduction, issue_date, policy_desc,
            policy_file_url, policy_file_path, policy_file_name,
            cover_file_url, cover_file_path,
            publish_status, publish_time, offline_time,
            create_by, create_time, remark
        ) values (
            #{policyName}, #{policyLevel}, #{introduction}, #{issueDate}, #{policyDesc},
            #{policyFileUrl}, #{policyFilePath}, #{policyFileName},
            #{coverFileUrl}, #{coverFilePath},
            #{publishStatus}, #{publishTime}, #{offlineTime},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizIndustryPolicyPublicity" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizIndustryPolicyPublicity">
        update biz_industry_policy_publicity set
            policy_name = #{policyName},
            policy_level = #{policyLevel},
            introduction = #{introduction},
            issue_date = #{issueDate},
            policy_desc = #{policyDesc},
            policy_file_url = #{policyFileUrl},
            policy_file_path = #{policyFilePath},
            policy_file_name = #{policyFileName},
            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="deleteBizIndustryPolicyPublicityByIds" parameterType="long">
        delete from biz_industry_policy_publicity where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
