<?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.hw.mes.mapper.MesProductPlanDetailMapper">

    <resultMap type="MesProductPlanDetail" id="MesProductPlanDetailResult">
        <result property="planDetailId"    column="plan_detail_id"    />
        <result property="planDetailCode"    column="plan_detail_code"    />
        <result property="planId"    column="plan_id"    />
        <result property="planCode"    column="plan_code"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="realBeginTime"    column="real_begin_time"    />
        <result property="realEndTime"    column="real_end_time"    />
        <result property="planDetailStatus"    column="plan_detail_status"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectMesProductPlanDetailVo">
        select plan_detail_id, plan_detail_code, plan_id, plan_code, user_id, user_name, real_begin_time, real_end_time, plan_detail_status, is_flag, remark, create_by, create_time, update_by, update_time from mes_product_plan_detail
    </sql>

    <select id="selectMesProductPlanDetailList" parameterType="MesProductPlanDetail" resultMap="MesProductPlanDetailResult">
        <include refid="selectMesProductPlanDetailVo"/>
        <where>
            <if test="planDetailCode != null  and planDetailCode != ''"> and plan_detail_code = #{planDetailCode}</if>
            <if test="planId != null "> and plan_id = #{planId}</if>
            <if test="planCode != null  and planCode != ''"> and plan_code = #{planCode}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="realBeginTime != null "> and real_begin_time = #{realBeginTime}</if>
            <if test="realEndTime != null "> and real_end_time = #{realEndTime}</if>
            <if test="planDetailStatus != null  and planDetailStatus != ''"> and plan_detail_status = #{planDetailStatus}</if>
            <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectMesProductPlanDetailByPlanDetailId" parameterType="Long" resultMap="MesProductPlanDetailResult">
        <include refid="selectMesProductPlanDetailVo"/>
        where plan_detail_id = #{planDetailId}
    </select>

    <insert id="insertMesProductPlanDetail" parameterType="MesProductPlanDetail" useGeneratedKeys="true" keyProperty="planDetailId">
        insert into mes_product_plan_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planDetailCode != null and planDetailCode != ''">plan_detail_code,</if>
            <if test="planId != null">plan_id,</if>
            <if test="planCode != null and planCode != ''">plan_code,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="realBeginTime != null">real_begin_time,</if>
            <if test="realEndTime != null">real_end_time,</if>
            <if test="planDetailStatus != null and planDetailStatus != ''">plan_detail_status,</if>
            <if test="isFlag != null and isFlag != ''">is_flag,</if>
            <if test="remark != null">remark,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planDetailCode != null and planDetailCode != ''">#{planDetailCode},</if>
            <if test="planId != null">#{planId},</if>
            <if test="planCode != null and planCode != ''">#{planCode},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="realBeginTime != null">#{realBeginTime},</if>
            <if test="realEndTime != null">#{realEndTime},</if>
            <if test="planDetailStatus != null and planDetailStatus != ''">#{planDetailStatus},</if>
            <if test="isFlag != null and isFlag != ''">#{isFlag},</if>
            <if test="remark != null">#{remark},</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>
         </trim>
    </insert>

    <update id="updateMesProductPlanDetail" parameterType="MesProductPlanDetail">
        update mes_product_plan_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="planDetailCode != null and planDetailCode != ''">plan_detail_code = #{planDetailCode},</if>
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="planCode != null and planCode != ''">plan_code = #{planCode},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="realBeginTime != null">real_begin_time = #{realBeginTime},</if>
            <if test="realEndTime != null">real_end_time = #{realEndTime},</if>
            <if test="planDetailStatus != null and planDetailStatus != ''">plan_detail_status = #{planDetailStatus},</if>
            <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where plan_detail_id = #{planDetailId}
    </update>

    <delete id="deleteMesProductPlanDetailByPlanDetailId" parameterType="Long">
        delete from mes_product_plan_detail where plan_detail_id = #{planDetailId}
    </delete>

    <delete id="deleteMesProductPlanDetailByPlanDetailIds" parameterType="String">
        delete from mes_product_plan_detail where plan_detail_id in
        <foreach item="planDetailId" collection="array" open="(" separator="," close=")">
            #{planDetailId}
        </foreach>
    </delete>
</mapper>
