<?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.sf.deployment.mapper.DeploymentApplyEnvironmentMapper">
    
    <resultMap type="DeploymentApplyEnvironment" id="DeploymentApplyEnvironmentResult">
        <result property="id"    column="id"    />
        <result property="appId"    column="app_id"    />
        <result property="appCode"    column="app_code"    />
        <result property="name"    column="name"    />
        <result property="serverAddress"    column="server_address"    />
        <result property="remark"    column="remark"    />
        <result property="isDelete"    column="is_delete"    />
        <result property="createDept"    column="create_dept"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDeploymentApplyEnvironmentVo">
        select id, app_id, app_code, name, server_address, remark, is_delete, create_dept, create_time, create_by, update_time, update_by from DEPLOYMENT_APPLY_ENVIRONMENT
    </sql>

    <select id="selectDeploymentApplyEnvironmentList" parameterType="DeploymentApplyEnvironment" resultMap="DeploymentApplyEnvironmentResult">
        <include refid="selectDeploymentApplyEnvironmentVo"/>
        <where>
            <if test="appCode != null  and appCode != ''">and app_code = #{appCode}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
        </where>
    </select>
    
    <select id="selectDeploymentApplyEnvironmentById" parameterType="Long" resultMap="DeploymentApplyEnvironmentResult">
        <include refid="selectDeploymentApplyEnvironmentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDeploymentApplyEnvironment" parameterType="DeploymentApplyEnvironment" useGeneratedKeys="true" keyProperty="id">
        insert into DEPLOYMENT_APPLY_ENVIRONMENT
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appId != null">app_id,</if>
            <if test="appCode != null">app_code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="serverAddress != null and serverAddress != ''">server_address,</if>
            <if test="remark != null">remark,</if>
            <if test="isDelete != null">is_delete,</if>
            <if test="createDept != null">create_dept,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appId != null">#{appId},</if>
            <if test="appCode != null">#{appCode},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="serverAddress != null and serverAddress != ''">#{serverAddress},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isDelete != null">#{isDelete},</if>
            <if test="createDept != null">#{createDept},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateDeploymentApplyEnvironment" parameterType="DeploymentApplyEnvironment">
        update DEPLOYMENT_APPLY_ENVIRONMENT
        <trim prefix="SET" suffixOverrides=",">
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appCode != null">apply_code = #{appCode},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="serverAddress != null and serverAddress != ''">server_address = #{serverAddress},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createDept != null">create_dept = #{createDept},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDeploymentApplyEnvironmentById" parameterType="Long">
        delete from DEPLOYMENT_APPLY_ENVIRONMENT where id = #{id}
    </delete>

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