<?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.ho.flow.mapper.WorkOrderPictureMapper">

    <resultMap id="BaseResultMap" type="com.ho.common.tools.entity.WorkOrderPicture">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="workOrderId" column="work_order_id" jdbcType="INTEGER"/>
        <result property="fileName" column="file_name" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,work_order_id,file_name,
        url,type,create_time
    </sql>

    <select id="selectByPrimaryKey" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from work_order_picture
        where id = #{id,jdbcType=INTEGER}
    </select>

    <select id="selectByWorkOrderIdAndType" resultType="com.ho.common.tools.entity.WorkOrderPicture">
        select
        <include refid="Base_Column_List"/>
        from work_order_picture
        where work_order_id = #{workOrderId}
        and type = #{type}
    </select>
    <select id="selectAll" resultType="com.ho.common.tools.entity.WorkOrderPicture">
        select
        <include refid="Base_Column_List"/>
        from work_order_picture
    </select>

    <delete id="deleteByPrimaryKey">
        delete
        from work_order_picture
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <delete id="deletedBySrcIdsAndType">
        delete from work_order_picture
        <where>
            <if test="ids != null and ids.size() != 0">
                and id in
                <foreach collection="ids" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
            <if test="type != null">
                and type = #{type}
            </if>
        </where>
    </delete>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.common.tools.entity.WorkOrderPicture"
            useGeneratedKeys="true">
        insert into work_order_picture
        ( id, work_order_id, file_name
        , url, type, create_time)
        values ( #{id,jdbcType=INTEGER}, #{workOrderId,jdbcType=INTEGER}, #{fileName,jdbcType=VARCHAR}
               , #{url,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id"
            parameterType="com.ho.common.tools.entity.WorkOrderPicture" useGeneratedKeys="true">
        insert into work_order_picture
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="workOrderId != null">work_order_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="url != null">url,</if>
            <if test="type != null">type,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=INTEGER},</if>
            <if test="workOrderId != null">#{workOrderId,jdbcType=INTEGER},</if>
            <if test="fileName != null">#{fileName,jdbcType=VARCHAR},</if>
            <if test="url != null">#{url,jdbcType=VARCHAR},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="createTime != null">now(),</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.ho.common.tools.entity.WorkOrderPicture">
        update work_order_picture
        <set>
            <if test="workOrderId != null">
                work_order_id = #{workOrderId,jdbcType=INTEGER},
            </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=INTEGER},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.common.tools.entity.WorkOrderPicture">
        update work_order_picture
        set work_order_id = #{workOrderId,jdbcType=INTEGER},
            file_name     = #{fileName,jdbcType=VARCHAR},
            url           = #{url,jdbcType=VARCHAR},
            type          = #{type,jdbcType=INTEGER},
            create_time   = #{createTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="setUpWorkOrderIdIdNUll">
        update work_order_picture
        set work_order_id = null
        <where>
            <if test="pictureIds != null and pictureIds.size() != 0">
                and id in
                <foreach collection="pictureIds" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </update>
</mapper>
