<?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.aucma.report.mapper.RealTaskInfoMapper">

    <resultMap type="RealTaskInfo" id="RealTaskInfoResult">
            <result property="objid"    column="objid"    />
            <result property="taskCode"    column="task_code"    />
            <result property="taskType"    column="task_type"    />
            <result property="taskStatus"    column="task_status"    />
            <result property="planCode"    column="plan_code"    />
            <result property="materialCode"    column="material_code"    />
            <result property="materialType"    column="material_type"    />
            <result property="spaceCode"    column="space_code"    />
            <result property="planAmount"    column="plan_amount"    />
            <result property="completeAmount"    column="complete_amount"    />
            <result property="beginTime"    column="begin_time"    />
            <result property="endTime"    column="end_time"    />
            <result property="isFlag"    column="is_flag"    />
            <result property="createdBy"    column="created_by"    />
            <result property="createdTime"    column="created_time"    />
            <result property="updatedBy"    column="updated_by"    />
            <result property="updatedTime"    column="updated_time"    />
            <result property="storeCode"    column="store_code"    />
            <result property="spaceName"    column="space_name"    />
            <result property="taskModel"    column="task_model"    />
    </resultMap>

    <sql id="selectRealTaskInfoVo">
        select objid, task_code, task_type, task_status, plan_code, material_code, material_type, space_code, plan_amount, complete_amount, begin_time, end_time, is_flag, created_by, created_time, updated_by, updated_time, store_code, space_name, task_model from real_taskinfo
    </sql>

    <select id="selectRealTaskInfoList" parameterType="RealTaskInfo" resultMap="RealTaskInfoResult">
        <include refid="selectRealTaskInfoVo"/>
        <where>
                        <if test="taskCode != null  and taskCode != ''"> and task_code = #{taskCode}</if>
                        <if test="taskType != null "> and task_type = #{taskType}</if>
                        <if test="taskStatus != null "> and task_status = #{taskStatus}</if>
                        <if test="planCode != null  and planCode != ''"> and plan_code = #{planCode}</if>
                        <if test="materialCode != null  and materialCode != ''"> and material_code = #{materialCode}</if>
                        <if test="materialType != null  and materialType != ''"> and material_type = #{materialType}</if>
                        <if test="spaceCode != null  and spaceCode != ''"> and space_code = #{spaceCode}</if>
                        <if test="planAmount != null "> and plan_amount = #{planAmount}</if>
                        <if test="completeAmount != null "> and complete_amount = #{completeAmount}</if>
                        <if test="params.beginBeginTime != null and params.beginBeginTime != '' and params.endBeginTime != null and params.endBeginTime != ''"> and begin_time between to_date(#{params.beginBeginTime}, 'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endBeginTime}, 'yyyy-mm-dd hh24:mi:ss')</if>
                        <if test="params.beginEndTime != null and params.beginEndTime != '' and params.endEndTime != null and params.endEndTime != ''"> and end_time between to_date(#{params.beginEndTime}, 'yyyy-mm-dd hh24:mi:ss') and to_date(#{params.endEndTime}, 'yyyy-mm-dd hh24:mi:ss')</if>
                        <if test="isFlag != null "> and is_flag = #{isFlag}</if>
                        <if test="createdBy != null  and createdBy != ''"> and created_by = #{createdBy}</if>
                        <if test="createdTime != null "> and created_time = #{createdTime}</if>
                        <if test="updatedBy != null  and updatedBy != ''"> and updated_by = #{updatedBy}</if>
                        <if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
                        <if test="storeCode != null  and storeCode != ''"> and store_code = #{storeCode}</if>
                        <if test="spaceName != null  and spaceName != ''"> and space_name like concat(concat('%', #{spaceName}), '%')</if>
                        <if test="taskModel != null "> and task_model = #{taskModel}</if>
        </where>
    </select>

    <select id="selectRealTaskInfoByObjid" parameterType="Long" resultMap="RealTaskInfoResult">
            <include refid="selectRealTaskInfoVo"/>
            where objid = #{objid}
    </select>

    <insert id="insertRealTaskInfo" parameterType="RealTaskInfo">
            <selectKey keyProperty="objid" resultType="long" order="BEFORE">
                SELECT SEQ_REAL_TASK_INFO.NEXTVAL as objid FROM DUAL
            </selectKey>
        insert into real_taskinfo
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="objid != null">objid,</if>
                <if test="taskCode != null">task_code,</if>
                <if test="taskType != null">task_type,</if>
                <if test="taskStatus != null">task_status,</if>
                <if test="planCode != null">plan_code,</if>
                <if test="materialCode != null">material_code,</if>
                <if test="materialType != null">material_type,</if>
                <if test="spaceCode != null">space_code,</if>
                <if test="planAmount != null">plan_amount,</if>
                <if test="completeAmount != null">complete_amount,</if>
                <if test="beginTime != null">begin_time,</if>
                <if test="endTime != null">end_time,</if>
                <if test="isFlag != null">is_flag,</if>
                <if test="createdBy != null">created_by,</if>
                <if test="createdTime != null">created_time,</if>
                <if test="updatedBy != null">updated_by,</if>
                <if test="updatedTime != null">updated_time,</if>
                <if test="storeCode != null">store_code,</if>
                <if test="spaceName != null">space_name,</if>
                <if test="taskModel != null">task_model,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="objid != null">#{objid},</if>
                <if test="taskCode != null">#{taskCode},</if>
                <if test="taskType != null">#{taskType},</if>
                <if test="taskStatus != null">#{taskStatus},</if>
                <if test="planCode != null">#{planCode},</if>
                <if test="materialCode != null">#{materialCode},</if>
                <if test="materialType != null">#{materialType},</if>
                <if test="spaceCode != null">#{spaceCode},</if>
                <if test="planAmount != null">#{planAmount},</if>
                <if test="completeAmount != null">#{completeAmount},</if>
                <if test="beginTime != null">#{beginTime},</if>
                <if test="endTime != null">#{endTime},</if>
                <if test="isFlag != null">#{isFlag},</if>
                <if test="createdBy != null">#{createdBy},</if>
                <if test="createdTime != null">#{createdTime},</if>
                <if test="updatedBy != null">#{updatedBy},</if>
                <if test="updatedTime != null">#{updatedTime},</if>
                <if test="storeCode != null">#{storeCode},</if>
                <if test="spaceName != null">#{spaceName},</if>
                <if test="taskModel != null">#{taskModel},</if>
        </trim>
    </insert>

    <update id="updateRealTaskInfo" parameterType="RealTaskInfo">
        update real_taskinfo
        <trim prefix="SET" suffixOverrides=",">
                    <if test="taskCode != null">task_code = #{taskCode},</if>
                    <if test="taskType != null">task_type = #{taskType},</if>
                    <if test="taskStatus != null">task_status = #{taskStatus},</if>
                    <if test="planCode != null">plan_code = #{planCode},</if>
                    <if test="materialCode != null">material_code = #{materialCode},</if>
                    <if test="materialType != null">material_type = #{materialType},</if>
                    <if test="spaceCode != null">space_code = #{spaceCode},</if>
                    <if test="planAmount != null">plan_amount = #{planAmount},</if>
                    <if test="completeAmount != null">complete_amount = #{completeAmount},</if>
                    <if test="beginTime != null">begin_time = #{beginTime},</if>
                    <if test="endTime != null">end_time = #{endTime},</if>
                    <if test="isFlag != null">is_flag = #{isFlag},</if>
                    <if test="createdBy != null">created_by = #{createdBy},</if>
                    <if test="createdTime != null">created_time = #{createdTime},</if>
                    <if test="updatedBy != null">updated_by = #{updatedBy},</if>
                    <if test="updatedTime != null">updated_time = #{updatedTime},</if>
                    <if test="storeCode != null">store_code = #{storeCode},</if>
                    <if test="spaceName != null">space_name = #{spaceName},</if>
                    <if test="taskModel != null">task_model = #{taskModel},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteRealTaskInfoByObjid" parameterType="Long">
        delete from real_taskinfo where objid = #{objid}
    </delete>

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