<?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.ygtx.worklog.mapper.ProjectMapper">

    <resultMap type="Project" id="ProjectResult">
        <result property="id"    column="id"    />
        <result property="projectCode"    column="project_code"    />
        <result property="projectName"    column="project_name"    />
        <result property="projectDesc"    column="project_desc"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="status"    column="status"    />
        <result property="leaderId"    column="leader_id"    />
        <result property="leaderName"    column="leader_name"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProjectVo">
        select id, project_code, project_name, project_desc, start_date, end_date,
               status, leader_id, leader_name, create_by, create_time, update_by, update_time, remark
        from wl_project
    </sql>

    <select id="selectProjectList" parameterType="Project" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        <where>
            <if test="projectCode != null  and projectCode != ''"> and project_code = #{projectCode}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="leaderId != null "> and leader_id = #{leaderId}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectProjectById" parameterType="Long" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        where id = #{id}
    </select>

    <select id="selectProjectByCode" parameterType="String" resultMap="ProjectResult">
        <include refid="selectProjectVo"/>
        where project_code = #{projectCode}
        limit 1
    </select>

    <insert id="insertProject" parameterType="Project" useGeneratedKeys="true" keyProperty="id">
        insert into wl_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectCode != null and projectCode != ''">project_code,</if>
            <if test="projectName != null and projectName != ''">project_name,</if>
            <if test="projectDesc != null">project_desc,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="status != null">status,</if>
            <if test="leaderId != null">leader_id,</if>
            <if test="leaderName != null">leader_name,</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="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectCode != null and projectCode != ''">#{projectCode},</if>
            <if test="projectName != null and projectName != ''">#{projectName},</if>
            <if test="projectDesc != null">#{projectDesc},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="status != null">#{status},</if>
            <if test="leaderId != null">#{leaderId},</if>
            <if test="leaderName != null">#{leaderName},</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="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProject" parameterType="Project">
        update wl_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectCode != null and projectCode != ''">project_code = #{projectCode},</if>
            <if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
            <if test="projectDesc != null">project_desc = #{projectDesc},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="leaderId != null">leader_id = #{leaderId},</if>
            <if test="leaderName != null">leader_name = #{leaderName},</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="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProjectById" parameterType="Long">
        delete from wl_project where id = #{id}
    </delete>

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