<?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.TabMaterialContentMapper">
  <resultMap type="com.gic.haoban.manage.service.entity.TabMaterialContent" id="result-map-tabHaobanMaterialContent">
      <result column="material_id"  property="materialId"/>
      <result column="material_type"  property="materialType"/>
      <result column="wx_last_upload_time"  property="wxLastUploadTime"/>
      <result column="media_id"  property="mediaId"/>
      <result column="wx_enterprise_id"  property="wxEnterpriseId"/>
      <result column="img_url"  property="imgUrl"/>
      <result column="url_md5"  property="urlMd5"/>
      <result column="status_flag"  property="statusFlag"/>
      <result column="create_time"  property="createTime"/>
      <result column="update_time"  property="updateTime"/>
      <result column="media_type" property="mediaType" />
      <result column="video_img_url" property="videoImgUrl" />
  </resultMap>
  <sql id="Base_Column_List">
	  material_id,
	  material_type,
	  wx_last_upload_time,
	  media_id,
	  wx_enterprise_id,
	  img_url,
	  url_md5,
	  status_flag,
	  create_time,
	  update_time , media_type,
      video_img_url
  </sql>
  <!-- ===================== 新增 ======================== -->
  <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabMaterialContent" useGeneratedKeys="true" keyProperty="id">
  <![CDATA[
  INSERT INTO tab_haoban_material_content(
	  material_id,
	  material_type,
	  wx_last_upload_time,
	  media_id,
	  wx_enterprise_id,
	  img_url,
	  url_md5,
	  status_flag,
	  create_time,
	  update_time , 
	  media_type,
      video_img_url
  )VALUES(
	  #{materialId,jdbcType=VARCHAR},
	  #{materialType,jdbcType=INTEGER},
	  #{wxLastUploadTime,jdbcType=TIMESTAMP},
	  #{mediaId,jdbcType=VARCHAR},
	  #{wxEnterpriseId,jdbcType=VARCHAR},
	  #{imgUrl,jdbcType=VARCHAR},
	  #{urlMd5,jdbcType=VARCHAR},
	  1,
	  now(),
	  now() , #{mediaType},#{videoImgUrl}
  )
  ]]>
  </insert>
  
   <!-- ==================更新 ========== -->
  <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabMaterialContent">
	  <![CDATA[
	  UPDATE tab_haoban_material_content SET
		  wx_last_upload_time=#{wxLastUploadTime,jdbcType=TIMESTAMP},
		  media_id=#{mediaId,jdbcType=VARCHAR},
		  wx_enterprise_id=#{wxEnterpriseId,jdbcType=VARCHAR},
		  status_flag=#{statusFlag,jdbcType=INTEGER},
		  update_time= now()
	  where material_id = #{materialId}
	  ]]>
  </update>

    <update id="updateVideoImgUrl" >
        <![CDATA[
        UPDATE tab_haoban_material_content SET
        video_img_url=#{videoImgUrl,jdbcType=VARCHAR},
        update_time= now()
        where material_id = #{id}
        ]]>
    </update>
  
  <!-- ============ 查询=============-->
  
  <select id="selectById" parameterType="String" resultMap="result-map-tabHaobanMaterialContent">
  	SELECT 
  		 <include refid="Base_Column_List"/>
  	 FROM tab_haoban_material_content WHERE material_id=#{id} and status_flag = 1
  </select>
  
  <select id="selectByUrl" resultMap="result-map-tabHaobanMaterialContent">
  	SELECT 
  		 <include refid="Base_Column_List"/>
  	 FROM tab_haoban_material_content WHERE wx_enterprise_id=#{wxEnterpriseId} and url_md5=#{urlMd5} and media_type = #{mediaType} and status_flag = 1
  </select>
    <select id="listByIds" resultMap="result-map-tabHaobanMaterialContent">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_material_content
        where media_type = #{mediaType} and material_id in
        <foreach collection="materialIds" item="item" open="(" close=")" separator=",">
            #{item,jdbcType=VARCHAR}
        </foreach>
    </select>
</mapper> 