<?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.gic.haoban.manage.service.dao.mapper.TabKeyDataMapper">
	<resultMap type="com.gic.haoban.manage.service.entity.TabKeyData"
		id="result-map-tabHaobanKeyData">
		<result column="id" property="id" />
		<result column="enterprise_id" property="enterpriseId" />
		<result column="relation_id" property="relationId" />
		<result column="data_key" property="dataKey" />
		<result column="data" property="data" />
		<result column="type" property="type" />
		<result column="create_time" property="createTime" />
	</resultMap>
	<sql id="Base_Column_List">
		data_key,
		data,
		type,
		create_time , enterpriseId , relation_id
	</sql>
	<!-- ===================== 新增 ======================== -->
	<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabKeyData">
	  <![CDATA[
	  INSERT INTO tab_haoban_key_data(
	  	  id,
	  	  enterprise_id,
	  	  relation_id ,
		  data_key,
		  data,
		  type,
		  create_time
	  )VALUES(
	  	  #{id},
	  	  #{enterpriseId} ,
	  	  #{relationId} ,
		  #{dataKey,jdbcType=VARCHAR},
		  #{data,jdbcType=VARCHAR},
		  #{type,jdbcType=INTEGER},
		  #{createTime,jdbcType=TIMESTAMP}
	  )
	  ]]>
	</insert>

	<!-- ============ 查询============= -->
	<select id="selectByKey" resultMap="result-map-tabHaobanKeyData">
		SELECT * FROM tab_haoban_key_data WHERE data_key = #{key} and type=#{type} 
		<if test="null != relationId">
			and relation_id = #{relationId}
		</if>
		order
		by create_time desc limit 1
	</select>

</mapper> 