<?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.datai.setting.mapper.DataiConfigEnvironmentMapper">
    
    <resultMap type="DataiConfigEnvironment" id="DataiConfigEnvironmentResult">
        <result property="id" column="id" />
        <result property="deptId" column="dept_id" />
        <result property="environmentName" column="environment_name" />
        <result property="environmentCode" column="environment_code" />
        <result property="description" column="description" />
        <result property="isActive" column="is_active" />
        <result property="remark" column="remark" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="selectDataiConfigEnvironmentVo">
        select 
            dce.id,
            dce.dept_id,
            dce.environment_name,
            dce.environment_code,
            dce.description,
            dce.is_active,
            dce.remark,
            dce.create_by,
            dce.create_time,
            dce.update_by,
            dce.update_time
        from datai_config_environment dce
    </sql>

    <select id="selectDataiConfigEnvironmentList" parameterType="DataiConfigEnvironment" resultMap="DataiConfigEnvironmentResult">
        <include refid="selectDataiConfigEnvironmentVo"/>
        <where>
            <if test="deptId != null "> and dce.dept_id = #{deptId}</if>
            <if test="environmentName != null  and environmentName != ''"> and dce.environment_name like concat('%', #{environmentName}, '%')</if>
            <if test="environmentCode != null  and environmentCode != ''"> and dce.environment_code = #{environmentCode}</if>
            <if test="description != null  and description != ''"> and dce.description = #{description}</if>
            <if test="isActive != null "> and dce.is_active = #{isActive}</if>
        </where>
    </select>
    
    <select id="selectDataiConfigEnvironmentById" parameterType="Long" resultMap="DataiConfigEnvironmentResult">
        <include refid="selectDataiConfigEnvironmentVo"/>
        where dce.id = #{id}
    </select>
        
    <insert id="insertDataiConfigEnvironment" parameterType="DataiConfigEnvironment" useGeneratedKeys="true" keyProperty="id">
        insert into datai_config_environment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="environmentName != null and environmentName != ''">environment_name,</if>
            <if test="environmentCode != null and environmentCode != ''">environment_code,</if>
            <if test="description != null">description,</if>
            <if test="isActive != null">is_active,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deptId != null">#{deptId},</if>
            <if test="environmentName != null and environmentName != ''">#{environmentName},</if>
            <if test="environmentCode != null and environmentCode != ''">#{environmentCode},</if>
            <if test="description != null">#{description},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDataiConfigEnvironment" parameterType="DataiConfigEnvironment">
        update datai_config_environment
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="environmentName != null and environmentName != ''">environment_name = #{environmentName},</if>
            <if test="environmentCode != null and environmentCode != ''">environment_code = #{environmentCode},</if>
            <if test="description != null">description = #{description},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where datai_config_environment.id = #{id}
    </update>

    <delete id="deleteDataiConfigEnvironmentById" parameterType="Long">
        delete from datai_config_environment where id = #{id}
    </delete>

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