<?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.system.mapper.SysProjectMapper">

    <resultMap type="SysProject" id="SysProjectResult">
        <result property="id"    column="id"    />
        <result property="projectName"    column="project_name"    />
        <result property="projectStatus"    column="project_status"    />
        <result property="leadUnit"    column="lead_unit"    />
        <result property="coreUnits"    column="core_units"    />
        <result property="projectLeader"    column="project_leader"    />
        <result property="contactPhone"    column="contact_phone"    />
        <result property="projectBackground"    column="project_background"    />
        <result property="overallGoal"    column="overall_goal"    />
        <result property="implementationPeriod"    column="implementation_period"    />
        <result property="projectDetail"    column="project_detail"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysProjectVo">
        select id, project_name, project_status, lead_unit, core_units, project_leader, contact_phone, project_background, overall_goal, implementation_period, project_detail, create_time, update_time, create_by, update_by, remark from sys_project
    </sql>

    <select id="selectSysProjectList" parameterType="SysProject" resultMap="SysProjectResult">
        <include refid="selectSysProjectVo"/>
        <where>
            <if test="projectName != null and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="projectStatus != null and projectStatus != ''"> and project_status = #{projectStatus}</if>
            <if test="leadUnit != null and leadUnit != ''"> and lead_unit like concat('%', #{leadUnit}, '%')</if>
            <if test="params.beginTime != null and params.beginTime != ''">
                and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="selectSysProjectById" parameterType="Long" resultMap="SysProjectResult">
        <include refid="selectSysProjectVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysProject" parameterType="SysProject" useGeneratedKeys="true" keyProperty="id">
        insert into sys_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">project_name,</if>
            <if test="projectStatus != null">project_status,</if>
            <if test="leadUnit != null">lead_unit,</if>
            <if test="coreUnits != null">core_units,</if>
            <if test="projectLeader != null">project_leader,</if>
            <if test="contactPhone != null">contact_phone,</if>
            <if test="projectBackground != null">project_background,</if>
            <if test="overallGoal != null">overall_goal,</if>
            <if test="implementationPeriod != null">implementation_period,</if>
            <if test="projectDetail != null">project_detail,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">#{projectName},</if>
            <if test="projectStatus != null">#{projectStatus},</if>
            <if test="leadUnit != null">#{leadUnit},</if>
            <if test="coreUnits != null">#{coreUnits},</if>
            <if test="projectLeader != null">#{projectLeader},</if>
            <if test="contactPhone != null">#{contactPhone},</if>
            <if test="projectBackground != null">#{projectBackground},</if>
            <if test="overallGoal != null">#{overallGoal},</if>
            <if test="implementationPeriod != null">#{implementationPeriod},</if>
            <if test="projectDetail != null">#{projectDetail},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysProject" parameterType="SysProject">
        update sys_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
            <if test="projectStatus != null">project_status = #{projectStatus},</if>
            <if test="leadUnit != null">lead_unit = #{leadUnit},</if>
            <if test="coreUnits != null">core_units = #{coreUnits},</if>
            <if test="projectLeader != null">project_leader = #{projectLeader},</if>
            <if test="contactPhone != null">contact_phone = #{contactPhone},</if>
            <if test="projectBackground != null">project_background = #{projectBackground},</if>
            <if test="overallGoal != null">overall_goal = #{overallGoal},</if>
            <if test="implementationPeriod != null">implementation_period = #{implementationPeriod},</if>
            <if test="projectDetail != null">project_detail = #{projectDetail},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysProjectById" parameterType="Long">
        delete from sys_project where id = #{id}
    </delete>

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

</mapper>
