<?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.artfess.mail.persistence.dao.MailAttachmentDao">
	<resultMap id="MailAttachment" type="com.artfess.mail.model.MailAttachment">
		<id property="id" column="FILEID" jdbcType="VARCHAR"/>
		<result property="fileName" column="FILENAME" jdbcType="VARCHAR"/>
		<result property="filePath" column="FILEPATH" jdbcType="VARCHAR"/>
		<result property="mailId" column="MAILID" jdbcType="VARCHAR"/>
	</resultMap>
	
	<sql id="columns">
		FILEID,FILENAME,FILEPATH,MAILID
	</sql>
	
	<sql id="dynamicWhere">
		<where>
			<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(id)"> AND FILEID  =#{id} </if>
			<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(fileName)"> AND FILENAME  LIKE #{fileName}  </if>
			<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(filePath)"> AND FILEPATH  LIKE #{filePath}  </if>
			<if test="@com.artfess.base.ognl.Ognl@isNotEmpty(mailId)"> AND MAILID  =#{mailId} </if>
		</where>
	</sql>
	
	<select id="getByMailId" parameterType="java.lang.String" resultMap="MailAttachment">
		SELECT <include refid="columns"/>
		FROM portal_sys_mail_attachement
		WHERE
		MAILID=#{mailId}
	</select>
	
	<update id="updateFilePath" parameterType="java.lang.String">
		UPDATE portal_sys_mail_attachement SET
		FILEPATH=#{filePath}
		WHERE
		FILENAME=#{fileName}
		AND 
		MAILID =#{mailId}
	</update>
	
	<delete id="delByMailId" parameterType="java.lang.String">
		DELETE FROM portal_sys_mail_attachement 
		WHERE
		MAILID=#{mailId}
	</delete>
	
</mapper>