<?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.yanzhu.jh.base.mapper.BasePeriodicalMapper">
    
    <resultMap type="BasePeriodical" id="BasePeriodicalResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="ord"    column="ord"    />
        <result property="state"    column="state"    />
        <result property="remark"    column="remark"    />
        <result property="isDel"    column="is_del"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBasePeriodicalVo">
        select id, name, image_url, file_url, ord, state, remark, is_del, create_by, create_time, update_by, update_time from base_periodical
    </sql>

    <select id="selectBasePeriodicalList" parameterType="BasePeriodical" resultMap="BasePeriodicalResult">
        <include refid="selectBasePeriodicalVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="ord != null "> and ord = #{ord}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
        order by ord
    </select>
    
    <select id="selectBasePeriodicalById" parameterType="Long" resultMap="BasePeriodicalResult">
        <include refid="selectBasePeriodicalVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBasePeriodical" parameterType="BasePeriodical" useGeneratedKeys="true" keyProperty="id">
        insert into base_periodical
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="imageUrl != null">image_url,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="ord != null">ord,</if>
            <if test="state != null">state,</if>
            <if test="remark != null">remark,</if>
            <if test="isDel != null">is_del,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="imageUrl != null">#{imageUrl},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="ord != null">#{ord},</if>
            <if test="state != null">#{state},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isDel != null">#{isDel},</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>
         </trim>
    </insert>

    <update id="updateBasePeriodical" parameterType="BasePeriodical">
        update base_periodical
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="ord != null">ord = #{ord},</if>
            <if test="state != null">state = #{state},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBasePeriodicalById" parameterType="Long">
        delete from base_periodical where id = #{id}
    </delete>

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