<?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.system.mapper.SysAchievementMapper">
    <resultMap type="SysAchievement" id="SysAchievementResult">
        <id property="id" column="id" />
        <result property="achievementName" column="achievement_name" />
        <result property="thumbnail" column="thumbnail" />
        <result property="achievementCategory" column="achievement_category" />
        <result property="researchField" column="research_field" />
        <result property="researchUnit" column="research_unit" />
        <result property="researchers" column="researchers" />
        <result property="introduction" column="introduction" />
        <result property="details" column="details" />
        <result property="publishTime" column="publish_time" />
        <result property="publisher" column="publisher" />
        <result property="sort" column="sort" />
        <result property="status" column="status" />
        <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="selectSysAchievementVo">
        select id, achievement_name, thumbnail, achievement_category, research_field, research_unit, researchers, introduction, details, publish_time, publisher, sort, status, create_by, create_time, update_by, update_time, remark
        from sys_achievement
    </sql>

    <select id="selectSysAchievementList" parameterType="SysAchievement" resultMap="SysAchievementResult">
        select id, achievement_name, thumbnail, achievement_category, research_field, research_unit, researchers, publish_time, publisher, sort, status, create_by, create_time, update_by, update_time, remark
        from sys_achievement
        <where>
            <if test="achievementName != null and achievementName != ''">
                AND achievement_name like concat('%', #{achievementName}, '%')
            </if>
            <if test="achievementCategory != null and achievementCategory != ''">
                AND achievement_category = #{achievementCategory}
            </if>
            <if test="researchField != null and researchField != ''">
                AND research_field = #{researchField}
            </if>
            <if test="publisher != null and publisher != ''">
                AND publisher = #{publisher}
            </if>
            <if test="params.beginTime != null and params.beginTime != ''">
                AND date_format(publish_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                AND date_format(publish_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
        </where>
        order by sort asc, create_time desc
    </select>

    <select id="selectSysAchievementById" parameterType="Long" resultMap="SysAchievementResult">
        select id, achievement_name, thumbnail, achievement_category, research_field, research_unit, researchers, publish_time, publisher, sort, status, create_by, create_time, update_by, update_time, remark
        from sys_achievement
        where id = #{id}
    </select>

    <insert id="insertSysAchievement" parameterType="SysAchievement" useGeneratedKeys="true" keyProperty="id">
        insert into sys_achievement
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="achievementName != null and achievementName != ''">achievement_name,</if>
            <if test="thumbnail != null">thumbnail,</if>
            <if test="achievementCategory != null">achievement_category,</if>
            <if test="researchField != null">research_field,</if>
            <if test="researchUnit != null">research_unit,</if>
            <if test="researchers != null">researchers,</if>
            <if test="introduction != null">introduction,</if>
            <if test="details != null">details,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="publisher != null">publisher,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="achievementName != null and achievementName != ''">#{achievementName},</if>
            <if test="thumbnail != null">#{thumbnail},</if>
            <if test="achievementCategory != null">#{achievementCategory},</if>
            <if test="researchField != null">#{researchField},</if>
            <if test="researchUnit != null">#{researchUnit},</if>
            <if test="researchers != null">#{researchers},</if>
            <if test="introduction != null">#{introduction},</if>
            <if test="details != null">#{details},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="publisher != null">#{publisher},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateSysAchievement" parameterType="SysAchievement">
        update sys_achievement
        <trim prefix="set" suffixOverrides=",">
            <if test="achievementName != null and achievementName != ''">achievement_name = #{achievementName},</if>
            <if test="thumbnail != null">thumbnail = #{thumbnail},</if>
            <if test="achievementCategory != null">achievement_category = #{achievementCategory},</if>
            <if test="researchField != null">research_field = #{researchField},</if>
            <if test="researchUnit != null">research_unit = #{researchUnit},</if>
            <if test="researchers != null">researchers = #{researchers},</if>
            <if test="introduction != null">introduction = #{introduction},</if>
            <if test="details != null">details = #{details},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
            <if test="publisher != null">publisher = #{publisher},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysAchievementById" parameterType="Long">
        delete from sys_achievement where id = #{id}
    </delete>

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