<?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.ValueMapper">
    
    <resultMap type="Value" id="ValueResult">
        <result property="valueId"       column="value_id"       />
        <result property="title"         column="title"          />
        <result property="image"         column="image"          />
        <result property="summary"       column="summary"        />
        <result property="content"       column="content"        />
        <result property="publishTime"   column="publish_time"  />
        <result property="publishBy"     column="publish_by"    />
        <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="selectValueVo">
        select value_id, title, image, summary, cast(content as char) as content, publish_time, publish_by, status, create_by, create_time, update_by, update_time, remark 
		from value
    </sql>
    
    <select id="selectValueById" parameterType="Long" resultMap="ValueResult">
        <include refid="selectValueVo"/>
        where value_id = #{valueId}
    </select>
    
    <select id="selectValueList" parameterType="Value" resultMap="ValueResult">
        <include refid="selectValueVo"/>
        <where>
			<if test="title != null and title != ''">
				AND title like concat('%', #{title}, '%')
			</if>
			<if test="publishBy != null and publishBy != ''">
				AND publish_by like concat('%', #{publishBy}, '%')
			</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>
		</where>
    </select>
    
    <insert id="insertValue" parameterType="Value">
        insert into value (
			<if test="title != null and title != '' ">title, </if>
			<if test="image != null and image != '' ">image, </if>
			<if test="summary != null and summary != '' ">summary, </if>
			<if test="content != null and content != '' ">content, </if>
			<if test="publishTime != null ">publish_time, </if>
			<if test="publishBy != null and publishBy != '' ">publish_by, </if>
			<if test="status != null and status != '' ">status, </if>
			<if test="remark != null and remark != ''">remark,</if>
 			<if test="createBy != null and createBy != ''">create_by,</if>
 			create_time
 		)values(
			<if test="title != null and title != ''">#{title}, </if>
			<if test="image != null and image != ''">#{image}, </if>
			<if test="summary != null and summary != ''">#{summary}, </if>
			<if test="content != null and content != ''">#{content}, </if>
			<if test="publishTime != null">#{publishTime}, </if>
			<if test="publishBy != null and publishBy != ''">#{publishBy}, </if>
			<if test="status != null and status != ''">#{status}, </if>
			<if test="remark != null and remark != ''">#{remark},</if>
 			<if test="createBy != null and createBy != ''">#{createBy},</if>
 			sysdate()
		)
    </insert>
	 
    <update id="updateValue" parameterType="Value">
        update value 
        <set>
            <if test="title != null and title != ''">title = #{title}, </if>
            <if test="image != null">image = #{image}, </if>
            <if test="summary != null">summary = #{summary}, </if>
            <if test="content != null">content = #{content}, </if>
            <if test="publishTime != null">publish_time = #{publishTime}, </if>
            <if test="publishBy != null">publish_by = #{publishBy}, </if>
            <if test="status != null and status != ''">status = #{status}, </if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
 			update_time = sysdate()
        </set>
        where value_id = #{valueId}
    </update>
	
    <delete id="deleteValueById" parameterType="Long">
        delete from value where value_id = #{valueId}
    </delete>
    
    <delete id="deleteValueByIds" parameterType="Long">
        delete from value where value_id in 
        <foreach item="valueId" collection="array" open="(" separator="," close=")">
            #{valueId}
        </foreach>
    </delete>
    
</mapper>
