<?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.pcloud.book.book.dao.impl.BookAssistTempletDaoImpl">

	<!-- 运营方案类型DTO -->
	<resultMap id="BaseResultMap" type="bookAssistTemplet">
		<id column="ASSIST_TEMPLET_ID" property="assistTempletId" jdbcType="BIGINT" />
		<result column="TYPE_CODE" property="typeCode" jdbcType="VARCHAR" />
		<result column="TEMPLET_NAME" property="templetName" jdbcType="VARCHAR" />
		<result column="COVER_IMG" property="coverImg" jdbcType="VARCHAR" />
		<result column="REMARK" property="remark" jdbcType="VARCHAR" />
		<result column="QRCODE_URL" property="qrcodeUrl" jdbcType="VARCHAR" />
		<result column="EFFECT_URL" property="effectUrl" jdbcType="VARCHAR" />
		<result column="TEMPLET_URL" property="templetUrl" jdbcType="VARCHAR" />
		<result column="TEMPLET_FILE_NAME" property="templetFileName" jdbcType="VARCHAR" />
		<result column="TEMPLET_FILE_SIZE" property="templetFileSize" jdbcType="BIGINT" />
		<result column="SAMPLE" property="sample" jdbcType="VARCHAR" />
		<result column="DESCRIPTION" property="description" jdbcType="VARCHAR" />
		<result column="CREATED_USER" property="createdUser" jdbcType="BIGINT" />
		<result column="CREATED_DATE" property="createdDate" jdbcType="TIMESTAMP" />
		<result column="LAST_MODIFIED_USER" property="lastModifiedUser" jdbcType="BIGINT" />
		<result column="LAST_MODIFIED_DATE" property="lastModifiedDate" jdbcType="TIMESTAMP" />
		<result column="VERSION" property="version" jdbcType="BIGINT" />
	</resultMap>
	
	<!-- 新增 -->
	<insert id="insert" parameterType="bookAssistTemplet" useGeneratedKeys="true" keyProperty="assistTempletId" flushCache="true">
		INSERT INTO BOOK_ASSIST_TEMPLET (
			TEMPLET_NAME, COVER_IMG, QRCODE_URL, DESCRIPTION, EFFECT_URL, TEMPLET_URL, TEMPLET_FILE_NAME, 
			TEMPLET_FILE_SIZE, SAMPLE, CREATED_USER, CREATED_DATE, LAST_MODIFIED_USER
		) VALUES (
			#{templetName}, #{coverImg}, #{qrcodeUrl}, #{description}, #{effectUrl}, #{templetUrl}, 
			#{templetFileName}, #{templetFileSize}, #{sample}, #{createdUser}, NOW(), #{createdUser}
		)
	</insert>
	
	<!-- 删除 -->
	<delete id="deleteById" parameterType="long" flushCache="true">
		DELETE FROM  BOOK_ASSIST_TEMPLET WHERE ASSIST_TEMPLET_ID = #{assistTempletId}
	</delete>
	
	<!-- 修改 -->
	<update id="update" parameterType="bookAssistTemplet" flushCache="true">
		UPDATE  BOOK_ASSIST_TEMPLET
		<set>
			COVER_IMG = #{coverImg},
			TEMPLET_NAME = #{templetName},
			QRCODE_URL = #{qrcodeUrl},
			DESCRIPTION = #{description},
			EFFECT_URL = #{effectUrl},
			TEMPLET_URL = #{templetUrl},
			TEMPLET_FILE_NAME = #{templetFileName}, 
			TEMPLET_FILE_SIZE = #{templetFileSize},
			SAMPLE = #{sample},
			LAST_MODIFIED_USER = #{lastModifiedUser},
			VERSION = VERSION+1
		</set>
		WHERE 
			ASSIST_TEMPLET_ID = #{assistTempletId}
		AND 
			VERSION = #{version}
	</update>
		
	<!-- 获取单个 -->
	<select id="getById" resultMap="BaseResultMap" parameterType="long">
		SELECT 
			ASSIST_TEMPLET_ID, TYPE_CODE, TEMPLET_NAME, COVER_IMG, REMARK, QRCODE_URL, EFFECT_URL, TEMPLET_URL, TEMPLET_FILE_NAME, 
			TEMPLET_FILE_SIZE, SAMPLE, DESCRIPTION, VERSION
		FROM 
			BOOK_ASSIST_TEMPLET
		WHERE
			ASSIST_TEMPLET_ID = #{assistTempletId}
		ORDER BY 
			CREATED_DATE DESC
	</select>
	
	<!-- 获取列表 -->
	<select id="listBy" resultMap="BaseResultMap" parameterType="map">
		SELECT 
			ASSIST_TEMPLET_ID, TYPE_CODE, TEMPLET_NAME, COVER_IMG, QRCODE_URL, REMARK, TEMPLET_URL, TEMPLET_FILE_NAME, 
			TEMPLET_FILE_SIZE, SAMPLE, DESCRIPTION, VERSION
		FROM 
			BOOK_ASSIST_TEMPLET
		<where>
			<if test="templetName!=null">
				AND TEMPLET_NAME LIKE CONCAT('%', #{templetName}, '%')
		</if>
		<if test="assistTempletIds!=null">
				AND	ASSIST_TEMPLET_ID IN
				<foreach collection="assistTempletIds" item="item" index="index" open="(" separator="," close=")">
					#{item}
				</foreach>
		</if>
		</where>
		ORDER BY 
			CREATED_DATE DESC
	</select>
	
</mapper>