<?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.oa.mapper.CmcProjectMapper">

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
        <result property="projectLeader"    column="project_leader"    />
        <result property="isFinished"    column="is_finished"    />
        <result property="projectSource"    column="project_source"    />
        <result property="partyA"    column="party_a"    />
        <result property="contactPerson"    column="contact_person"    />
        <result property="telephone"    column="telephone"    />
        <result property="contractId"    column="contract_id"    />
        <result property="projectType"    column="project_type"    />
        <result property="projectLevel"    column="project_level"    />
        <result property="projectRegistrant"    column="project_registrant"    />
        <result property="undertakingDept"    column="undertaking_dept"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCmcProjectVo">
        select project_id, project_number, project_name, project_leader, is_finished, project_source, party_a, contact_person, telephone, contract_id, project_type, project_level, project_registrant, undertaking_dept, create_time, remark from cmc_project
    </sql>

    <select id="selectCmcProjectList" parameterType="CmcProject" resultMap="CmcProjectResult">
        <include refid="selectCmcProjectVo"/>
        <where>
            <if test="projectNumber != null  and projectNumber != ''"> and project_number like concat('%', #{projectNumber}, '%')</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="isFinished != null  and isFinished != ''"> and is_finished = #{isFinished}</if>
            <if test="projectSource != null  and projectSource != ''"> and project_source = #{projectSource}</if>
            <if test="partyA != null  and partyA != ''"> and party_a like concat('%', #{partyA}, '%')</if>
            <if test="contactPerson != null  and contactPerson != ''"> and contact_person like concat('%', #{contactPerson}, '%')</if>
            <if test="telephone != null  and telephone != ''"> and telephone like concat('%', #{telephone}, '%')</if>
            <if test="contractId != null  and contractId != ''"> and contract_id like concat('%', #{contractId}, '%')</if>
            <if test="projectType != null  and projectType != ''"> and project_type like concat('%', #{projectType}, '%')</if>
            <if test="projectLevel != null  and projectLevel != ''"> and project_level = #{projectLevel}</if>
        </where>
    </select>

    <select id="selectCmcProjectByProjectId" parameterType="Integer" resultMap="CmcProjectResult">
        <include refid="selectCmcProjectVo"/>
        where project_id = #{projectId}
    </select>

    <insert id="insertCmcProject" parameterType="CmcProject">
        insert into cmc_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="projectNumber != null">project_number,</if>
            <if test="projectName != null">project_name,</if>
            <if test="projectLeader != null">project_leader,</if>
            <if test="isFinished != null">is_finished,</if>
            <if test="projectSource != null">project_source,</if>
            <if test="partyA != null">party_a,</if>
            <if test="contactPerson != null">contact_person,</if>
            <if test="telephone != null">telephone,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="projectType != null">project_type,</if>
            <if test="projectLevel != null">project_level,</if>
            <if test="projectRegistrant != null">project_registrant,</if>
            <if test="undertakingDept != null">undertaking_dept,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectId != null">#{projectId},</if>
            <if test="projectNumber != null">#{projectNumber},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="projectLeader != null">#{projectLeader},</if>
            <if test="isFinished != null">#{isFinished},</if>
            <if test="projectSource != null">#{projectSource},</if>
            <if test="partyA != null">#{partyA},</if>
            <if test="contactPerson != null">#{contactPerson},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="projectType != null">#{projectType},</if>
            <if test="projectLevel != null">#{projectLevel},</if>
            <if test="projectRegistrant != null">#{projectRegistrant},</if>
            <if test="undertakingDept != null">#{undertakingDept},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateCmcProject" parameterType="CmcProject">
        update cmc_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectNumber != null">project_number = #{projectNumber},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="projectLeader != null">project_leader = #{projectLeader},</if>
            <if test="isFinished != null">is_finished = #{isFinished},</if>
            <if test="projectSource != null">project_source = #{projectSource},</if>
            <if test="partyA != null">party_a = #{partyA},</if>
            <if test="contactPerson != null">contact_person = #{contactPerson},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="projectType != null">project_type = #{projectType},</if>
            <if test="projectLevel != null">project_level = #{projectLevel},</if>
            <if test="projectRegistrant != null">project_registrant = #{projectRegistrant},</if>
            <if test="undertakingDept != null">undertaking_dept = #{undertakingDept},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where project_id = #{projectId}
    </update>

    <delete id="deleteCmcProjectByProjectId" parameterType="Integer">
        delete from cmc_project where project_id = #{projectId}
    </delete>

    <delete id="deleteCmcProjectByProjectIds" parameterType="Integer">
        delete from cmc_project where project_id in
        <foreach item="projectId" collection="array" open="(" separator="," close=")">
            #{projectId}
        </foreach>
    </delete>
</mapper>