<?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.innovation.mapper.BizTechProjectGuideMapper">

    <resultMap type="com.ruoyi.web.modules.innovation.domain.BizTechProjectGuide" id="BizTechProjectGuideResult">
        <id     property="id"                     column="id"/>
        <result property="projectName"            column="project_name"/>
        <result property="projectType"            column="project_type"/>
        <result property="projectIntro"           column="project_intro"/>
        <result property="applicationTarget"      column="application_target"/>
        <result property="applicationStartDate"   column="application_start_date"/>
        <result property="applicationEndDate"     column="application_end_date"/>
        <result property="projectPeriod"          column="project_period"/>
        <result property="applicationConditions"  column="application_conditions"/>
        <result property="applicationProcess"     column="application_process"/>
        <result property="personInCharge"         column="person_in_charge"/>
        <result property="contactPhone"           column="contact_phone"/>
        <result property="attachmentFileUrl"      column="attachment_file_url"/>
        <result property="attachmentFilePath"   column="attachment_file_path"/>
        <result property="attachmentFileName"     column="attachment_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, project_name, project_type, project_intro, application_target,
               application_start_date, application_end_date, project_period,
               application_conditions, application_process, person_in_charge, contact_phone,
               attachment_file_url, attachment_file_path, attachment_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_tech_project_guide
    </sql>

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

    <select id="selectBizTechProjectGuideList" parameterType="com.ruoyi.web.modules.innovation.domain.BizTechProjectGuide" resultMap="BizTechProjectGuideResult">
        <include refid="selectVo"/>
        <where>
            <if test="projectName != null and projectName != ''">
                and project_name like concat('%', #{projectName}, '%')
            </if>
            <if test="projectType != null">
                and project_type = #{projectType}
            </if>
            <if test="publishStatus != null">
                and publish_status = #{publishStatus}
            </if>
        </where>
        order by (case when publish_time is null then 1 else 0 end), publish_time desc, create_time desc, id desc
    </select>

    <insert id="insertBizTechProjectGuide" parameterType="com.ruoyi.web.modules.innovation.domain.BizTechProjectGuide" useGeneratedKeys="true" keyProperty="id">
        insert into biz_tech_project_guide (
            project_name, project_type, project_intro, application_target,
            application_start_date, application_end_date, project_period,
            application_conditions, application_process, person_in_charge, contact_phone,
            attachment_file_url, attachment_file_path, attachment_file_name,
            cover_file_url, cover_file_path,
            publish_status, publish_time, offline_time,
            create_by, create_time, remark
        ) values (
            #{projectName}, #{projectType}, #{projectIntro}, #{applicationTarget},
            #{applicationStartDate}, #{applicationEndDate}, #{projectPeriod},
            #{applicationConditions}, #{applicationProcess}, #{personInCharge}, #{contactPhone},
            #{attachmentFileUrl}, #{attachmentFilePath}, #{attachmentFileName},
            #{coverFileUrl}, #{coverFilePath},
            #{publishStatus}, #{publishTime}, #{offlineTime},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizTechProjectGuide" parameterType="com.ruoyi.web.modules.innovation.domain.BizTechProjectGuide">
        update biz_tech_project_guide set
            project_name = #{projectName},
            project_type = #{projectType},
            project_intro = #{projectIntro},
            application_target = #{applicationTarget},
            application_start_date = #{applicationStartDate},
            application_end_date = #{applicationEndDate},
            project_period = #{projectPeriod},
            application_conditions = #{applicationConditions},
            application_process = #{applicationProcess},
            person_in_charge = #{personInCharge},
            contact_phone = #{contactPhone},
            attachment_file_url = #{attachmentFileUrl},
            attachment_file_path = #{attachmentFilePath},
            attachment_file_name = #{attachmentFileName},
            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="deleteBizTechProjectGuideByIds" parameterType="long">
        delete from biz_tech_project_guide where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
