<?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.ghy.order.mapper.OrderBehaviorMapper">

    <resultMap id="ColumnMap" type="com.ghy.order.domain.OrderBehavior">
        <id     property="id"                   column="id"/>
        <result property="workerId"             column="worker_id"/>
        <result property="workerName"           column="worker_name"/>
        <result property="orderMasterId"        column="order_master_id"/>
        <result property="orderMasterCode"      column="order_master_code"/>
        <result property="orderDetailId"        column="order_detail_id"/>
        <result property="orderDetailCode"      column="order_detail_code"/>
        <result property="behavior"             column="behavior"/>
        <result property="behaviorTime"         column="behavior_time"/>
    </resultMap>

    <sql id="selectColumns">
        SELECT id,
               worker_id,
               worker_name,
               order_master_id,
               order_master_code,
               order_detail_id,
               order_detail_code,
               behavior,
               behavior_time
        FROM order_behavior
    </sql>

    <insert id="insert" parameterType="com.ghy.order.domain.OrderBehavior" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO order_behavior(
        worker_id, worker_name, order_master_id, order_master_code,
        order_detail_id, order_detail_code, behavior, behavior_time
        )VALUES(
        #{workerId}, #{workerName}, #{orderMasterId}, #{orderMasterCode},
        #{orderDetailId}, #{orderDetailCode}, #{behavior}, NOW())
    </insert>

    <select id="select" parameterType="com.ghy.order.domain.OrderBehavior" resultMap="ColumnMap">
        <include refid="selectColumns"/>
        <where>
            <if test="workerId != null and workerId != 0">
                AND worker_id = #{workerId}
            </if>
            <if test="orderMasterId != null and orderMasterId != 0">
                AND order_master_id = #{orderMasterId}
            </if>
            <if test="orderMasterCode != null and orderMasterCode != ''">
                AND order_master_code = #{orderMasterCode}
            </if>
            <if test="orderDetailId != null and orderDetailId != 0">
                AND order_detail_id = #{orderDetailId}
            </if>
            <if test="orderDetailCode != null and orderDetailCode != ''">
                AND order_detail_code = #{orderDetailCode}
            </if>
        </where>
    </select>

    <select id="selectById" parameterType="long" resultMap="ColumnMap">
        <include refid="selectColumns"/> WHERE id = #{id}
    </select>

    <select id="selectByIds" resultMap="ColumnMap">
        <include refid="selectColumns"/> WHERE id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <delete id="delete" parameterType="Long">
        DELETE FROM order_behavior WHERE id = #{id}
    </delete>

    <delete id="batchDelete">
        DELETE FROM order_behavior WHERE id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
