<?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.yanzhu.jh.project.mapper.SurProjectBuildDesignDataMapper">
    
    <resultMap type="SurProjectBuildDesignData" id="SurProjectBuildDesignDataResult">
        <result property="id"    column="id"    />
        <result property="nodeId"    column="node_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="ownerPhone"    column="owner_phone"    />
        <result property="dataDate"    column="data_date"    />
        <result property="startDate"    column="start_date"    />
        <result property="planStartDate"    column="plan_start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="planEndDate"    column="plan_end_date"    />
        <result property="duration"    column="duration"    />
        <result property="remainingDays"    column="remaining_days"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="files"    column="files"    />
        <result property="work"    column="work"    />
        <result property="nextWeekWork"    column="next_week_work"    />
        <result property="problem"    column="problem"    />
        <result property="isDel"    column="is_del"    />
        <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="updateInfo"    column="update_info"    />
    </resultMap>

    <resultMap type="SurProjectBuildDesignData" id="SurProjectBuildDesignDataResultNode">
        <result property="id"    column="id"    />
        <result property="nodeId"    column="node_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="ownerName"    column="owner_name"    />
        <result property="ownerPhone"    column="owner_phone"    />
        <result property="dataDate"    column="data_date"    />
        <result property="startDate"    column="start_date"    />
        <result property="planStartDate"    column="plan_start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="planEndDate"    column="plan_end_date"    />
        <result property="duration"    column="duration"    />
        <result property="remainingDays"    column="remaining_days"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <result property="files"    column="files"    />
        <result property="work"    column="work"    />
        <result property="nextWeekWork"    column="next_week_work"    />
        <result property="problem"    column="problem"    />
        <result property="isDel"    column="is_del"    />
        <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="updateInfo"    column="update_info"    />
        <association property="baseBuildNode" javaType="baseBuildNode">
            <result property="id"    column="node_id"    />
            <result property="nodeText"    column="node_text"    />
            <result property="nodeLvl"    column="node_lvl"    />
            <result property="nodeType"    column="node_type"    />
        </association>
        <association property="project" javaType="SurProject">
            <result property="id"    column="project_id"    />
            <result property="projectName" column="projectName"/>
        </association>
    </resultMap>

    <sql id="selectSurProjectBuildDesignDataVo">
        select id, node_id, project_id, owner_name, owner_phone, data_date, start_date, plan_start_date, end_date, plan_end_date, duration, remaining_days, status, remark, files, work, next_week_work, problem, is_del, create_by, create_time, update_by, update_time, update_info from sur_project_build_design_data
    </sql>
    <sql id="selectSurProjectBuildDesignDataVoView">
        select a.*,b.node_text,b.node_lvl,b.node_type,p.projectName
        from sur_project_build_design_data a,base_build_node b,sur_project p
        where a.node_id=b.id and a.project_id=p.id and a.is_del!=1 and b.is_del!=1 and p.isdel!=1
    </sql>
    <select id="selectSurProjectBuildDesignDataList" parameterType="SurProjectBuildDesignData" resultMap="SurProjectBuildDesignDataResultNode">
        <include refid="selectSurProjectBuildDesignDataVoView"/>

            <if test="projectId != null "> and a.project_id = #{projectId}</if>
            <if test="startDate != null "> and a.data_date &gt;= #{startDate}</if>
            <if test="endDate != null "> and a.data_date &lt;= #{endDate}</if>

    </select>
    
    <select id="selectSurProjectBuildDesignDataById" parameterType="Long" resultMap="SurProjectBuildDesignDataResult">
        <include refid="selectSurProjectBuildDesignDataVo"/>
        where id = #{id}
    </select>

    <select id="selectWeekData" parameterType="SurProjectBuildDesignData" resultMap="SurProjectBuildDesignDataResultNode">
        <include refid="selectSurProjectBuildDesignDataVoView"/>
        <if test="projectId != null "> and a.project_id = #{projectId}</if>
        <if test="startDate != null "> and a.data_date &gt;= #{startDate}</if>
        <if test="endDate != null "> and a.data_date &lt;= #{endDate}</if>
    </select>
    <insert id="insertSurProjectBuildDesignData" parameterType="SurProjectBuildDesignData" useGeneratedKeys="true" keyProperty="id">
        insert into sur_project_build_design_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nodeId != null">node_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="ownerName != null">owner_name,</if>
            <if test="ownerPhone != null">owner_phone,</if>
            <if test="dataDate != null">data_date,</if>
            <if test="startDate != null">start_date,</if>
            <if test="planStartDate != null">plan_start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="planEndDate != null">plan_end_date,</if>
            <if test="duration != null">duration,</if>
            <if test="remainingDays != null">remaining_days,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
            <if test="files != null">files,</if>
            <if test="work != null">work,</if>
            <if test="nextWeekWork != null">next_week_work,</if>
            <if test="problem != null">problem,</if>
            <if test="isDel != null">is_del,</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="updateInfo != null">update_info,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nodeId != null">#{nodeId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="ownerName != null">#{ownerName},</if>
            <if test="ownerPhone != null">#{ownerPhone},</if>
            <if test="dataDate != null">#{dataDate},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="planStartDate != null">#{planStartDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="planEndDate != null">#{planEndDate},</if>
            <if test="duration != null">#{duration},</if>
            <if test="remainingDays != null">#{remainingDays},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="files != null">#{files},</if>
            <if test="work != null">#{work},</if>
            <if test="nextWeekWork != null">#{nextWeekWork},</if>
            <if test="problem != null">#{problem},</if>
            <if test="isDel != null">#{isDel},</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="updateInfo != null">#{updateInfo},</if>
         </trim>
    </insert>

    <update id="updateSurProjectBuildDesignData" parameterType="SurProjectBuildDesignData">
        update sur_project_build_design_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeId != null">node_id = #{nodeId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="ownerName != null">owner_name = #{ownerName},</if>
            <if test="ownerPhone != null">owner_phone = #{ownerPhone},</if>
            <if test="dataDate != null">data_date = #{dataDate},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="planStartDate != null">plan_start_date = #{planStartDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="planEndDate != null">plan_end_date = #{planEndDate},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="remainingDays != null">remaining_days = #{remainingDays},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="files != null">files = #{files},</if>
            <if test="work != null">work = #{work},</if>
            <if test="nextWeekWork != null">next_week_work = #{nextWeekWork},</if>
            <if test="problem != null">problem = #{problem},</if>
            <if test="isDel != null">is_del = #{isDel},</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="updateInfo != null">update_info = #{updateInfo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSurProjectBuildDesignDataById" parameterType="Long">
        delete from sur_project_build_design_data where id = #{id}
    </delete>

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