<?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.microservices.zone.specialProject.mapper.ZoneSpecialProjectMapper">

    <resultMap type="ZoneSpecialProject" id="ZoneSpecialProjectResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="projectLeader" column="project_leader"/>
        <result property="description" column="description"/>
        <result property="awards" column="awards"/>
        <result property="typeId" column="type_id"/>
        <result property="zoneId" column="zone_id"/>
        <result property="deptId" column="dept_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="reservedField1" column="reserved_field_1"/>
        <result property="reservedField2" column="reserved_field_2"/>
        <result property="responsibleCompany" column="responsible_company"/>
        <result property="introductionImageIdentifier" column="introduction_image_identifier"/>
        <result property="sort" column="sort"/>
    </resultMap>

    <sql id="selectZoneSpecialProjectVo">
        select id,
               name,
               project_leader,
               description,
               awards,
               type_id,
               zone_id,
               dept_id,
               del_flag,
               update_time,
               update_by,
               create_time,
               create_by,
               reserved_field_1,
               reserved_field_2,
               responsible_company,
               introduction_image_identifier,
               sort
        from zone_special_project
    </sql>

    <select id="selectZoneSpecialProjectList" parameterType="ZoneSpecialProject" resultMap="ZoneSpecialProjectResult">
        <include refid="selectZoneSpecialProjectVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="projectLeader != null ">and project_leader = #{projectLeader}</if>
            <if test="description != null  and description != ''">and description = #{description}</if>
            <if test="awards != null  and awards != ''">and awards = #{awards}</if>
            <if test="typeId != null ">and type_id = #{typeId}</if>
            <if test="zoneId != null ">and zone_id = #{zoneId}</if>
            <if test="deptId != null ">and dept_id = #{deptId}</if>
            <if test="reservedField1 != null  and reservedField1 != ''">and reserved_field_1 = #{reservedField1}</if>
            <if test="reservedField2 != null  and reservedField2 != ''">and reserved_field_2 = #{reservedField2}</if>
            <if test="responsibleCompany != null  and responsibleCompany != ''">and responsible_company =
                #{responsibleCompany}
            </if>
            <if test="introductionImageIdentifier != null  and introductionImageIdentifier != ''">and
                introduction_image_identifier = #{introductionImageIdentifier}
            </if>
            <if test="sort != null ">and sort = #{sort}</if>
        </where>
        ORDER BY sort ASC
    </select>

    <select id="selectZoneSpecialProjectById" parameterType="Long" resultMap="ZoneSpecialProjectResult">
        <include refid="selectZoneSpecialProjectVo"/>
        where id = #{id}
    </select>
    <select id="selectZoneSpecialProjectByNameAndZoneId" resultMap="ZoneSpecialProjectResult">
        <include refid="selectZoneSpecialProjectVo"/>
        where name = #{name}
        and zone_id = #{zoneId}
    </select>

    <insert id="insertZoneSpecialProject" parameterType="ZoneSpecialProject" useGeneratedKeys="true" keyProperty="id">
        insert into zone_special_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="projectLeader != null">project_leader,</if>
            <if test="description != null">description,</if>
            <if test="awards != null">awards,</if>
            <if test="typeId != null">type_id,</if>
            <if test="zoneId != null">zone_id,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="reservedField1 != null">reserved_field_1,</if>
            <if test="reservedField2 != null">reserved_field_2,</if>
            <if test="responsibleCompany != null">responsible_company,</if>
            <if test="introductionImageIdentifier != null">introduction_image_identifier,</if>
            <if test="sort != null">sort,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="projectLeader != null">#{projectLeader},</if>
            <if test="description != null">#{description},</if>
            <if test="awards != null">#{awards},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="zoneId != null">#{zoneId},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="reservedField1 != null">#{reservedField1},</if>
            <if test="reservedField2 != null">#{reservedField2},</if>
            <if test="responsibleCompany != null">#{responsibleCompany},</if>
            <if test="introductionImageIdentifier != null">#{introductionImageIdentifier},</if>
            <if test="sort != null">#{sort},</if>
        </trim>
    </insert>

    <update id="updateZoneSpecialProject" parameterType="ZoneSpecialProject">
        update zone_special_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="projectLeader != null">project_leader = #{projectLeader},</if>
            <if test="description != null">description = #{description},</if>
            <if test="awards != null">awards = #{awards},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="zoneId != null">zone_id = #{zoneId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="reservedField1 != null">reserved_field_1 = #{reservedField1},</if>
            <if test="reservedField2 != null">reserved_field_2 = #{reservedField2},</if>
            <if test="responsibleCompany != null">responsible_company = #{responsibleCompany},</if>
            <if test="introductionImageIdentifier != null">introduction_image_identifier =
                #{introductionImageIdentifier},
            </if>
            <if test="sort != null">sort = #{sort},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZoneSpecialProjectById" parameterType="Long">
        delete
        from zone_special_project
        where id = #{id}
    </delete>

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