<?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.configcolumngroup.IConfigColumnGroupDao">

    <resultMap id="configColumnGroupDTO" type="cn.com.tenlion.configcolumn.pojo.dtos.configcolumngroup.ConfigColumnGroupDTO">
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_group_code" property="configColumnGroupCode"/>
        <result column="config_column_group_name" property="configColumnGroupName"/>
        <result column="config_column_group_photo" property="configColumnGroupPhoto"/>
        <result column="config_column_group_direction" property="configColumnGroupDirection"/>
        <result column="config_column_group_status" property="configColumnGroupStatus"/>
        <result column="config_column_group_remark" property="configColumnGroupRemark"/>
        <result column="config_column_group_order" property="configColumnGroupOrder"/>
        <result column="config_column_group_target_mode" property="configColumnGroupTargetMode"/>
        <result column="config_column_group_target_url" property="configColumnGroupTargetUrl"/>
        <result column="config_column_group_style" property="configColumnGroupStyle"/>
        <result column="config_column_group_role" property="configColumnGroupRole"/>
        <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="configColumnGroupBO" type="cn.com.tenlion.configcolumn.pojo.bos.configcolumngroup.ConfigColumnGroupBO">
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_group_code" property="configColumnGroupCode"/>
        <result column="config_column_group_name" property="configColumnGroupName"/>
        <result column="config_column_group_photo" property="configColumnGroupPhoto"/>
        <result column="config_column_group_direction" property="configColumnGroupDirection"/>
        <result column="config_column_group_status" property="configColumnGroupStatus"/>
        <result column="config_column_group_remark" property="configColumnGroupRemark"/>
        <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="configColumnGroupPO" type="cn.com.tenlion.configcolumn.pojo.pos.configcolumngroup.ConfigColumnGroupPO">
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_group_code" property="configColumnGroupCode"/>
        <result column="config_column_group_name" property="configColumnGroupName"/>
        <result column="config_column_group_photo" property="configColumnGroupPhoto"/>
        <result column="config_column_group_direction" property="configColumnGroupDirection"/>
        <result column="config_column_group_status" property="configColumnGroupStatus"/>
        <result column="config_column_group_remark" property="configColumnGroupRemark"/>
        <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>

    <select id="getByCode" parameterType="java.lang.String" resultMap="configColumnGroupDTO">
        SELECT
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_id,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.config_column_group_role
        FROM
            m_config_column_group t1
        WHERE
            t1.is_delete = 0 AND t1.config_column_group_code = #{configColumnGroupCode}
    </select>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_config_column_group(
            config_column_group_id,
            config_column_group_code,
            config_column_group_name,
            config_column_group_photo,
            config_column_group_direction,
            config_column_group_status,
            config_column_group_remark,
            config_column_group_order,
            config_column_group_target_mode,
            config_column_group_target_url,
            config_column_group_style,
            config_column_group_role,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{configColumnGroupId},
            #{configColumnGroupCode},
            #{configColumnGroupName},
            #{configColumnGroupPhoto},
            #{configColumnGroupDirection},
            #{configColumnGroupStatus},
            #{configColumnGroupRemark},
            #{configColumnGroupOrder},
            #{configColumnGroupTargetMode},
            #{configColumnGroupTargetUrl},
            #{configColumnGroupStyle},
            #{configColumnGroupRole},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

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

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

    <!-- 修改 -->
    <update id="update" parameterType="map">
        UPDATE
            m_config_column_group
        SET
        <if test="configColumnGroupName != null and configColumnGroupName != ''">
            config_column_group_name = #{configColumnGroupName},
        </if>
        <if test="configColumnGroupPhoto != null and configColumnGroupPhoto != ''">
            config_column_group_photo = #{configColumnGroupPhoto},
        </if>
        <if test="configColumnGroupDirection != null">
            config_column_group_direction = #{configColumnGroupDirection},
        </if>
        <if test="configColumnGroupStatus != null">
            config_column_group_status = #{configColumnGroupStatus},
        </if>
        <if test="configColumnGroupRemark != null and configColumnGroupRemark != ''">
            config_column_group_remark = #{configColumnGroupRemark},
        </if>
        <if test="configColumnGroupOrder != null and configColumnGroupOrder != ''">
            config_column_group_order = #{configColumnGroupOrder},
        </if>
        <if test="configColumnGroupTargetMode != null and configColumnGroupTargetMode != ''">
            config_column_group_target_mode = #{configColumnGroupTargetMode},
        </if>
        <if test="configColumnGroupTargetUrl != null and configColumnGroupTargetUrl != ''">
            config_column_group_target_url = #{configColumnGroupTargetUrl},
        </if>
        <if test="configColumnGroupStyle != null and configColumnGroupStyle != ''">
            config_column_group_style = #{configColumnGroupStyle},
        </if>
            config_column_group_role = #{configColumnGroupRole},
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            config_column_group_id = config_column_group_id
        WHERE
            config_column_group_id = #{configColumnGroupId}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="configColumnGroupDTO">
        SELECT
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_id,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.config_column_group_role
        FROM
            m_config_column_group t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnGroupId != null and configColumnGroupId != ''">
        AND
            t1.config_column_group_id = #{configColumnGroupId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getBO" parameterType="map" resultMap="configColumnGroupBO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_column_group t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnGroupId != null and configColumnGroupId != ''">
        AND
            t1.config_column_group_id = #{configColumnGroupId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getPO" parameterType="map" resultMap="configColumnGroupPO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_column_group t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnGroupId != null and configColumnGroupId != ''">
        AND
            t1.config_column_group_id = #{configColumnGroupId}
            </if>
    </select>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="configColumnGroupDTO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_group_role
        FROM
            m_config_column_group t1
        WHERE
            t1.is_delete = 0
        <if test="configColumnGroupRole != null and configColumnGroupRole != ''">
            AND t1.config_column_group_role LIKE CONCAT('%', CONCAT( #{configColumnGroupRole} , '%'))
        </if>
        <if test="configColumnGroupStatus != null and configColumnGroupStatus != ''">
            AND t1.config_column_group_status = #{configColumnGroupStatus}
        </if>
        <if test="configColumnGroupTargetMode != null and configColumnGroupTargetMode != ''">
            AND t1.config_column_group_target_mode = #{configColumnGroupTargetMode}
        </if>
        <if test="notInConfigColumnGroupCode != null and notInConfigColumnGroupCode.size > 0 ">
            AND
            t1.config_column_group_code NOT IN
            <foreach collection="notInConfigColumnGroupCode" index="index" open="(" separator="," close=")">
                #{notInConfigColumnGroupCode[${index}]}
            </foreach>
        </if>
        <if test="inConfigColumnGroupCode != null and inConfigColumnGroupCode.size > 0">
            AND
            t1.config_column_group_code IN
            <foreach collection="inConfigColumnGroupCode" index="index" open="(" separator="," close=")">
                #{inConfigColumnGroupCode[${index}]}
            </foreach>
        </if>
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.config_column_group_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.config_column_group_code LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.config_column_group_remark 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="configColumnGroupIds != null and configColumnGroupIds.size > 0">
        AND
            t1.config_column_group_id IN
            <foreach collection="configColumnGroupIds" index="index" open="(" separator="," close=")">
                #{configColumnGroupIds[${index}]}
            </foreach>
        </if>
        ORDER BY
            t1.config_column_group_order
    </select>

    <!-- 列表 -->
    <select id="listBO" parameterType="map" resultMap="configColumnGroupBO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_column_group 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="configColumnGroupIds != null and configColumnGroupIds.size > 0">
        AND
            t1.config_column_group_id IN
            <foreach collection="configColumnGroupIds" index="index" open="(" separator="," close=")">
                #{configColumnGroupIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="configColumnGroupPO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_group_code,
            t1.config_column_group_name,
            t1.config_column_group_photo,
            t1.config_column_group_direction,
            t1.config_column_group_status,
            t1.config_column_group_remark,
            t1.config_column_group_order,
            t1.config_column_group_target_mode,
            t1.config_column_group_target_url,
            t1.config_column_group_style,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_column_group 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="configColumnGroupIds != null and configColumnGroupIds.size > 0">
        AND
            t1.config_column_group_id IN
            <foreach collection="configColumnGroupIds" index="index" open="(" separator="," close=")">
                #{configColumnGroupIds[${index}]}
            </foreach>
        </if>
    </select>

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

</mapper>