<?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.xhpc.activity.mapper.XhpcWorkOrderImageMapper">
  <resultMap id="BaseResultMap" type="com.xhpc.activity.domain.XhpcWorkOrderImageDomain">
    <id column="order_image_id" jdbcType="BIGINT" property="orderImageId" />
    <result column="order_id" jdbcType="BIGINT" property="orderId"/>
    <result column="file_name" jdbcType="VARCHAR" property="fileName" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="SMALLINT" property="type" />
    <result column="del_flag" jdbcType="SMALLINT" property="delFlag" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
  </resultMap>
  <sql id="Base_Column_List">
    order_image_id, order_id, file_name, url, `type`, del_flag, create_time, create_by
  </sql>

  <select id="selectImageIdByOrderIdAndType" resultType="java.lang.Long">
    select
      order_image_id
    from xhpc_work_order_image
    where order_id = #{orderId,jdbcType=BIGINT} and type = #{type}
  </select>

  <delete id="deleteByImageIds">
    delete from xhpc_work_order_image
    where order_image_id in
    <foreach collection="imageIds" item="imageId" separator="," open="(" close=")">
      #{imageId}
    </foreach>
  </delete>

  <select id="selectByOrderIdAndType" resultType="com.xhpc.activity.domain.XhpcWorkOrderImageDomain">
    select
    <include refid="Base_Column_List" />
    from xhpc_work_order_image
    where order_id = #{orderId} and type = #{type}
  </select>

  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from xhpc_work_order_image
    where order_image_id = #{orderImageId,jdbcType=BIGINT}
  </select>
  <update id="deleteByPrimaryKey" parameterType="java.lang.Long">
    update xhpc_work_order_image set del_flag=2
    where order_image_id = #{orderImageId,jdbcType=BIGINT}
  </update>
  <insert id="insert" keyColumn="order_image_id" keyProperty="orderImageId" parameterType="com.xhpc.activity.domain.XhpcWorkOrderImageDomain" useGeneratedKeys="true">
    insert into xhpc_work_order_image (file_name, url, `type`, 
      del_flag, create_time, create_by
      )
    values (#{fileName,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{type,jdbcType=SMALLINT}, 
      0, SYSDATE(), #{createBy,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" keyColumn="order_image_id" keyProperty="orderImageId" parameterType="com.xhpc.activity.domain.XhpcWorkOrderImageDomain" useGeneratedKeys="true">
    insert into xhpc_work_order_image
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        order_id,
      </if>
      <if test="fileName != null">
        file_name,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="type != null">
        `type`,
      </if>
        del_flag,
        create_time,
      <if test="createBy != null">
        create_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderId != null">
        #{orderId},
      </if>
      <if test="fileName != null">
        #{fileName,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=SMALLINT},
      </if>
        0,
        SYSDATE(),
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.xhpc.activity.domain.XhpcWorkOrderImageDomain">
    update xhpc_work_order_image
    <set>
        <if test="orderId !=null">
          order_id=#{orderId},
        </if>
      <if test="fileName != null">
        file_name = #{fileName,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=SMALLINT},
      </if>
        create_time = SYSDATE(),
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
    </set>
    where order_image_id = #{orderImageId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.xhpc.activity.domain.XhpcWorkOrderImageDomain">
    update xhpc_work_order_image
    set order_id=#{orderId},
        file_name = #{fileName,jdbcType=VARCHAR},
      url = #{url,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=SMALLINT},
    where order_image_id = #{orderImageId,jdbcType=BIGINT}
  </update>
</mapper>