<?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="cn.com.tenlion.configcolumn.dao.configcolumnset.IConfigColumnSetDao">

    <resultMap id="configColumnSetDTO" type="cn.com.tenlion.configcolumn.pojo.dtos.configcolumnset.ConfigColumnSetDTO">
        <result column="config_column_set_id" property="configColumnSetId"/>
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_order" property="configColumnOrder"/>
        <result column="config_column_icon" property="configColumnIcon"/>
        <result column="config_column_set_mode" property="configColumnSetMode"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="configColumnSetBO" type="cn.com.tenlion.configcolumn.pojo.bos.configcolumnset.ConfigColumnSetBO">
        <result column="config_column_set_id" property="configColumnSetId"/>
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_set_mode" property="configColumnSetMode"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="configColumnSetPO" type="cn.com.tenlion.configcolumn.pojo.pos.configcolumnset.ConfigColumnSetPO">
        <result column="config_column_set_id" property="configColumnSetId"/>
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_set_mode" property="configColumnSetMode"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_config_column_set(
            config_column_set_id,
            config_column_id,
            config_column_name,
            config_column_set_mode,
            config_column_order,
            config_column_icon,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{configColumnSetId},
            #{configColumnId},
            #{configColumnName},
            #{configColumnSetMode},
            #{configColumnOrder},
            #{configColumnIcon},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除 -->
    <update id="remove" parameterType="map">
        UPDATE
            m_config_column_set
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            config_column_set_id IN
        <foreach collection="configColumnSetIds" index="index" open="(" separator="," close=")">
            #{configColumnSetIds[${index}]}
        </foreach>
    </update>

    <!-- 删除（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            m_config_column_set
        WHERE
            config_column_set_id IN
        <foreach collection="configColumnSetIds" index="index" open="(" separator="," close=")">
            #{configColumnSetIds[${index}]}
        </foreach>
    </update>

    <!-- 修改 -->
    <update id="update" parameterType="map">
        UPDATE
            m_config_column_set
        SET
        <if test="configColumnId != null and configColumnId != ''">
            config_column_id = #{configColumnId},
        </if>
        <if test="configColumnName != null and configColumnName != ''">
            config_column_name = #{configColumnName},
        </if>
        <if test="configColumnOrder != null and configColumnOrder != ''">
            config_column_order = #{configColumnOrder},
        </if>
        <if test="configColumnIcon != null and configColumnIcon != ''">
            config_column_icon = #{configColumnIcon},
        </if>
        <if test="configColumnSetMode != null and configColumnSetMode != ''">
            config_column_set_mode = #{configColumnSetMode},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            config_column_set_id = config_column_set_id
        WHERE
            config_column_set_id = #{configColumnSetId}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="configColumnSetDTO">
        SELECT
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.config_column_set_id,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnSetId != null and configColumnSetId != ''">
                AND
                t1.config_column_set_id = #{configColumnSetId}
            </if>
            <if test="configColumnId != null and configColumnId != ''">
                AND
                t1.config_column_id = #{configColumnId}
            </if>
            <if test="configColumnSetMode != null and configColumnSetMode != ''">
                AND
                t1.config_column_set_mode = #{configColumnSetMode}
            </if>
            <if test="userId != null and userId != ''">
                AND
                t1.creator = #{userId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getBO" parameterType="map" resultMap="configColumnSetBO">
        SELECT
            t1.config_column_set_id,
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnSetId != null and configColumnSetId != ''">
        AND
            t1.config_column_set_id = #{configColumnSetId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getPO" parameterType="map" resultMap="configColumnSetPO">
        SELECT
            t1.config_column_set_id,
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnSetId != null and configColumnSetId != ''">
        AND
            t1.config_column_set_id = #{configColumnSetId}
            </if>
    </select>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="configColumnSetDTO">
        SELECT
            t1.config_column_set_id,
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configColumnSetIds != null and configColumnSetIds.size > 0">
        AND
            t1.config_column_set_id IN
            <foreach collection="configColumnSetIds" index="index" open="(" separator="," close=")">
                #{configColumnSetIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listBO" parameterType="map" resultMap="configColumnSetBO">
        SELECT
            t1.config_column_set_id,
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configColumnSetIds != null and configColumnSetIds.size > 0">
        AND
            t1.config_column_set_id IN
            <foreach collection="configColumnSetIds" index="index" open="(" separator="," close=")">
                #{configColumnSetIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="configColumnSetPO">
        SELECT
            t1.config_column_set_id,
            t1.config_column_id,
            t1.config_column_name,
            t1.config_column_set_mode,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_order,
            t1.config_column_icon
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configColumnSetIds != null and configColumnSetIds.size > 0">
        AND
            t1.config_column_set_id IN
            <foreach collection="configColumnSetIds" index="index" open="(" separator="," close=")">
                #{configColumnSetIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_config_column_set t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>