<?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.ximai.mes.pro.mapper.ProArrangeMapper">

    <resultMap type="ProArrange" id="ProArrangeResult">
        <result property="arrangeId" column="arrange_id"/>
        <result property="arrangeCode" column="arrange_code"/>
        <result property="arrangeSort" column="arrange_sort"/>
        <result property="workorderId" column="workorder_id"/>
        <result property="workorderCode" column="workorder_code"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="workorderIds" column="workorder_ids"/>
        <result property="groupCode" column="group_code"/>
    </resultMap>

    <sql id="selectProArrangeVo">
        select arrange_id,
               arrange_code,
               arrange_sort,
               workorder_id,
               workorder_code,
               group_code,
               create_by,
               create_time,
               update_by,
               update_time
        from pro_arrange
    </sql>


    <select id="selectProArrangeList" parameterType="ProArrange" resultMap="ProArrangeResult">
        <include refid="selectProArrangeVo"/>
        <where>
            <if test="arrangeCode != null  and arrangeCode != ''">and arrange_code = #{arrangeCode}</if>
            <if test="arrangeSort != null ">and arrange_sort = #{arrangeSort}</if>
            <if test="workorderId != null ">and workorder_id = #{workorderId}</if>
            <if test="workorderCode != null  and workorderCode != ''">and workorder_code = #{workorderCode}</if>
            <if test="groupCode != null  and groupCode != ''">and group_code = #{groupCode}</if>
        </where>
    </select>

    <select id="selectProArrangeByArrangeId" parameterType="Long" resultMap="ProArrangeResult">
        <include refid="selectProArrangeVo"/>
        where arrange_id = #{arrangeId}
    </select>


    <select id="selectProArrangeByWorkorderId" parameterType="Long" resultMap="ProArrangeResult">
        <include refid="selectProArrangeVo"/>
        where workorder_Id = #{workorderId}
    </select>

    <insert id="insertProArrange" parameterType="ProArrange" useGeneratedKeys="true" keyProperty="arrangeId">
        insert into pro_arrange
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="arrangeCode != null and arrangeCode != ''">arrange_code,</if>
            <if test="arrangeSort != null">arrange_sort,</if>
            <if test="workorderId != null">workorder_id,</if>
            <if test="workorderCode != null">workorder_code,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="groupCode != null">group_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="arrangeCode != null and arrangeCode != ''">#{arrangeCode},</if>
            <if test="arrangeSort != null">#{arrangeSort},</if>
            <if test="workorderId != null">#{workorderId},</if>
            <if test="workorderCode != null">#{workorderCode},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="groupCode != null">#{groupCode},</if>
        </trim>
    </insert>

    <update id="updateProArrange" parameterType="ProArrange">
        update pro_arrange
        <trim prefix="SET" suffixOverrides=",">
            <if test="arrangeCode != null and arrangeCode != ''">arrange_code = #{arrangeCode},</if>
            <if test="arrangeSort != null">arrange_sort = #{arrangeSort},</if>
            <if test="workorderId != null">workorder_id = #{workorderId},</if>
            <if test="workorderCode != null">workorder_code = #{workorderCode},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="groupCode != null">group_code = #{groupCode},</if>
        </trim>
        where arrange_id = #{arrangeId}
    </update>

    <delete id="deleteProArrangeByArrangeId" parameterType="Long">
        delete
        from pro_arrange
        where arrange_id = #{arrangeId}
    </delete>

    <delete id="deleteProArrangeByArrangeIds" parameterType="String">
        delete from pro_arrange where arrange_id in
        <foreach item="arrangeId" collection="array" open="(" separator="," close=")">
            #{arrangeId}
        </foreach>
    </delete>

</mapper>
