<?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.ruoyi.baseinfo.mapper.BasePlandetailInfoMapper">

    <resultMap type="BasePlandetailInfo" id="BasePlandetailInfoResult">
        <result property="objid"    column="objid"    />
        <result property="planid"    column="planid"    />
        <result property="materialId"    column="material_id"    />
        <result property="planAmount"    column="plan_amount"    />
        <result property="realAmount"    column="real_amount"    />
        <result property="unitId"    column="unit_id"    />
        <result property="groupId"    column="group_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="overTime"    column="over_time"    />
        <result property="remark"    column="remark"    />
        <result property="status"    column="status"    />
        <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="delFlag"    column="del_flag"    />
        <result property="groupname"    column="groupname"    />
    </resultMap>

    <sql id="selectBasePlandetailInfoVo">
        select objid, planid, material_id, plan_amount, real_amount, unit_id, group_id, start_time, over_time,remark, status, create_by, create_time, update_by, update_time, del_flag from base_plandetail_info
    </sql>

    <select id="selectBasePlandetailInfoList" parameterType="BasePlandetailInfo" resultMap="BasePlandetailInfoResult">
        select t1.objid, t1.planid, t1.material_id, t1.plan_amount, t1.real_amount, t1.unit_id, t1.group_id,t2.groupname, t1.start_time, t1.over_time, t1.remark, t1.status, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.del_flag
        from base_plandetail_info t1 left join base_group_info t2 on t1.group_id = t2.groupid
        <where>
            <if test="planid != null  and planid != ''"> and planid = #{planid}</if>
            <if test="materialId != null  and materialId != ''"> and material_id = #{materialId}</if>
            <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
            <if test="realAmount != null "> and real_amount = #{realAmount}</if>
            <if test="unitId != null  and unitId != ''"> and unit_id = #{unitId}</if>
            <if test="groupId != null  and groupId != ''"> and group_id = #{groupId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectBasePlandetailInfoById" parameterType="Long" resultMap="BasePlandetailInfoResult">
        <include refid="selectBasePlandetailInfoVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBasePlandetailInfo" parameterType="BasePlandetailInfo">
        insert into base_plandetail_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objid != null">objid,</if>
            <if test="planid != null">planid,</if>
            <if test="materialId != null">material_id,</if>
            <if test="planAmount != null">plan_amount,</if>
            <if test="realAmount != null">real_amount,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="overTime != null">over_time,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</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="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objid != null">#{objid},</if>
            <if test="planid != null">#{planid},</if>
            <if test="materialId != null">#{materialId},</if>
            <if test="planAmount != null">#{planAmount},</if>
            <if test="realAmount != null">#{realAmount},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="overTime != null">#{overTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</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="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateBasePlandetailInfo" parameterType="BasePlandetailInfo">
        update base_plandetail_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="planid != null">planid = #{planid},</if>
            <if test="materialId != null">material_id = #{materialId},</if>
            <if test="planAmount != null">plan_amount = #{planAmount},</if>
            <if test="realAmount != null">real_amount = #{realAmount},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="groupId != null">group_id = #{groupId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="overTime != null">over_time = #{overTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</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="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBasePlandetailInfoById" parameterType="Long">
        delete from base_plandetail_info where objid = #{objid}
    </delete>

    <delete id="deleteBasePlandetailInfoByIds" parameterType="String">
        delete from base_plandetail_info where objid in
        <foreach item="objid" collection="array" open="(" separator="," close=")">
            #{objid}
        </foreach>
    </delete>

    <delete id="deleteBasePlandetailInfoByPlanIds" parameterType="String">
        delete from base_plandetail_info where planid in
        <foreach item="objid" collection="array" open="(" separator="," close=")">
            #{objid}
        </foreach>
    </delete>

    <select id="selectBasePlandetailInfoByPlanID" parameterType="String" resultMap="BasePlandetailInfoResult">
        <include refid="selectBasePlandetailInfoVo"/>
        where planid = #{planid}
    </select>

</mapper>
