<?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.WorkOrderCirculationMapper">


    <sql id="Base_Column_List">
        id
        ,order_id,from_id,
        to_id,create_time,work_order_action,`desc`
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long"
            resultType="com.ho.flow.vo.WorkOrderCirculation">
        select
        <include refid="Base_Column_List"/>
        from work_order_circulation
        where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByOrderId" resultType="com.ho.flow.vo.resp.workorder.WorkOrderCirculationRespVO">
        select
        <include refid="Base_Column_List"/>
        from work_order_circulation
        where order_id LIKE concat('%',#{orderId},'%')
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.flow.vo.WorkOrderCirculation"
            useGeneratedKeys="true">
        insert into work_order_circulation
        (id, order_id, from_id,
         to_id, `desc`, work_order_action)
        values ( #{id,jdbcType=BIGINT}, #{orderId,jdbcType=VARCHAR}, #{fromId,jdbcType=VARCHAR}
               , #{toId,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}
               , #{workOrderAction,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id"
            parameterType="com.ho.flow.vo.WorkOrderCirculation" useGeneratedKeys="true">
        insert into work_order_circulation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="orderId != null">order_id,</if>
            <if test="fromId != null">from_id,</if>
            <if test="toId != null">to_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="desc != null">`desc`,</if>
            <if test="workOrderAction">work_order_action,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="orderId != null">#{orderId,jdbcType=VARCHAR},</if>
            <if test="fromId != null">#{fromId,jdbcType=INTEGER},</if>
            <if test="toId != null">#{toId,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="desc != null">#{desc,jdbcType=VARCHAR},</if>
            <if test="workOrderAction">#{workOrderAction,jdbcType=INTEGER}</if>
        </trim>
    </insert>

    <insert id="insertBatch">
        insert into work_order_circulation
        ( id,order_id, from_id,
        to_id, `desc`, work_order_action)
        values
        <foreach item="item" collection="list" index="index" separator=",">
         (
            #{item.id},#{item.orderId},
            #{item.fromId},#{item.toId},#{item.desc},
            #{item.workOrderAction}
            )
        </foreach>
    </insert>
</mapper>
