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

    <resultMap type="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject" id="BizSubsidyProjectResult">
        <id     property="id"                 column="id"/>
        <result property="projectName"        column="project_name"/>
        <result property="introduction"     column="introduction"/>
        <result property="investmentAmount" column="investment_amount"/>
        <result property="projectStartDate" column="project_start_date"/>
        <result property="plannedEndDate"   column="planned_end_date"/>
        <result property="coverFileUrl"     column="cover_file_url"/>
        <result property="coverFilePath"    column="cover_file_path"/>
        <result property="execStatus"       column="exec_status"/>
        <result property="actualEndDate"    column="actual_end_date"/>
        <result property="manualCompleteFlag" column="manual_complete_flag"/>
        <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, project_name, introduction, investment_amount, project_start_date, planned_end_date,
               cover_file_url, cover_file_path, exec_status, actual_end_date, manual_complete_flag,
               publish_status, publish_time, offline_time,
               create_by, create_time, update_by, update_time, remark
        from biz_subsidy_project
    </sql>

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

    <select id="selectBizSubsidyProjectList" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject" resultMap="BizSubsidyProjectResult">
        <include refid="selectVo"/>
        <where>
            <if test="keyword != null and keyword != ''">
                and (project_name like concat('%', #{keyword}, '%')
                or introduction like concat('%', #{keyword}, '%'))
            </if>
            <if test="execStatus != null">
                and exec_status = #{execStatus}
            </if>
            <if test="publishStatus != null">
                and publish_status = #{publishStatus}
            </if>
            <if test="startDate != null and startDate != ''">
                and project_start_date &gt;= #{startDate}
            </if>
            <if test="endDate != null and endDate != ''">
                and project_start_date &lt;= #{endDate}
            </if>
        </where>
        order by project_start_date desc, create_time desc, id desc
    </select>

    <insert id="insertBizSubsidyProject" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject" useGeneratedKeys="true" keyProperty="id">
        insert into biz_subsidy_project (
            project_name, introduction, investment_amount, project_start_date, planned_end_date,
            cover_file_url, cover_file_path, exec_status, actual_end_date, manual_complete_flag,
            publish_status, publish_time, offline_time,
            create_by, create_time, remark
        ) values (
            #{projectName}, #{introduction}, #{investmentAmount}, #{projectStartDate}, #{plannedEndDate},
            #{coverFileUrl}, #{coverFilePath}, #{execStatus}, #{actualEndDate}, #{manualCompleteFlag},
            #{publishStatus}, #{publishTime}, #{offlineTime},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizSubsidyProject" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject">
        update biz_subsidy_project set
            project_name = #{projectName},
            introduction = #{introduction},
            investment_amount = #{investmentAmount},
            project_start_date = #{projectStartDate},
            planned_end_date = #{plannedEndDate},
            cover_file_url = #{coverFileUrl},
            cover_file_path = #{coverFilePath},
            exec_status = #{execStatus},
            actual_end_date = #{actualEndDate},
            manual_complete_flag = #{manualCompleteFlag},
            publish_status = #{publishStatus},
            publish_time = #{publishTime},
            offline_time = #{offlineTime},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <update id="updateBizSubsidyProjectExecStatus" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyProject">
        update biz_subsidy_project set
            exec_status = #{execStatus},
            actual_end_date = #{actualEndDate},
            update_time = sysdate()
        where id = #{id}
    </update>

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