<?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.configcolumn.IConfigColumnDao">

    <resultMap id="configColumnDTO" type="cn.com.tenlion.configcolumn.pojo.dtos.configcolumn.ConfigColumnDTO">
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_code" property="configColumnCode"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_sub_name" property="configColumnSubName"/>
        <result column="config_column_target_mode" property="configColumnTargetMode"/>
        <result column="config_column_target_url" property="configColumnTargetUrl"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="config_column_status" property="configColumnStatus"/>
        <result column="config_column_order" property="configColumnOrder"/>
        <result column="config_column_default" property="configColumnDefault"/>
        <result column="config_column_type" property="configColumnType"/>
        <result column="config_column_photo" property="configColumnPhoto"/>
        <result column="config_column_remark" property="configColumnRemark"/>
        <result column="config_column_max_count" property="configColumnMaxCount"/>
        <result column="config_column_row_count" property="configColumnRowCount"/>
        <result column="config_column_row_target_mode" property="configColumnRowTargetMode"/>
        <result column="config_column_row_target_url" property="configColumnRowTargetUrl"/>
        <result column="config_column_comment" property="configColumnComment"/>
        <result column="config_column_dispatch" property="configColumnDispatch"/>
        <result column="config_column_like" property="configColumnLike"/>
        <result column="config_column_collect" property="configColumnCollect"/>
        <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="configColumnBO" type="cn.com.tenlion.configcolumn.pojo.bos.configcolumn.ConfigColumnBO">
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_code" property="configColumnCode"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_sub_name" property="configColumnSubName"/>
        <result column="config_column_target_mode" property="configColumnTargetMode"/>
        <result column="config_column_target_url" property="configColumnTargetUrl"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="config_column_status" property="configColumnStatus"/>
        <result column="config_column_order" property="configColumnOrder"/>
        <result column="config_column_default" property="configColumnDefault"/>
        <result column="config_column_type" property="configColumnType"/>
        <result column="config_column_photo" property="configColumnPhoto"/>
        <result column="config_column_remark" property="configColumnRemark"/>
        <result column="config_column_max_count" property="configColumnMaxCount"/>
        <result column="config_column_row_count" property="configColumnRowCount"/>
        <result column="config_column_row_target_mode" property="configColumnRowTargetMode"/>
        <result column="config_column_row_target_url" property="configColumnRowTargetUrl"/>
        <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="configColumnPO" type="cn.com.tenlion.configcolumn.pojo.pos.configcolumn.ConfigColumnPO">
        <result column="config_column_id" property="configColumnId"/>
        <result column="config_column_group_id" property="configColumnGroupId"/>
        <result column="config_column_code" property="configColumnCode"/>
        <result column="config_column_name" property="configColumnName"/>
        <result column="config_column_sub_name" property="configColumnSubName"/>
        <result column="config_column_target_mode" property="configColumnTargetMode"/>
        <result column="config_column_target_url" property="configColumnTargetUrl"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="config_column_status" property="configColumnStatus"/>
        <result column="config_column_order" property="configColumnOrder"/>
        <result column="config_column_default" property="configColumnDefault"/>
        <result column="config_column_type" property="configColumnType"/>
        <result column="config_column_photo" property="configColumnPhoto"/>
        <result column="config_column_remark" property="configColumnRemark"/>
        <result column="config_column_max_count" property="configColumnMaxCount"/>
        <result column="config_column_row_count" property="configColumnRowCount"/>
        <result column="config_column_row_target_mode" property="configColumnRowTargetMode"/>
        <result column="config_column_row_target_url" property="configColumnRowTargetUrl"/>
        <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="map" resultMap="configColumnDTO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.config_column_id,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0 AND t1.config_column_code = #{configColumnCode}
    </select>

    <!-- 详情 -->
    <select id="getByGroupId" parameterType="map" resultMap="configColumnDTO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.config_column_id,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0 AND t1.config_column_group_id = #{configColumnGroupId}
        ORDER BY
            t1.config_column_order
    </select>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_config_column(
            config_column_id,
            config_column_group_id,
            config_column_code,
            config_column_name,
            config_column_sub_name,
            config_column_target_mode,
            config_column_target_url,
            config_table_id,
            config_column_status,
            config_column_order,
            config_column_default,
            config_column_type,
            config_column_photo,
            config_column_remark,
            config_column_max_count,
            config_column_row_count,
            config_column_row_target_mode,
            config_column_row_target_url,
            config_column_comment,
            config_column_dispatch,
            config_column_like,
            config_column_collect,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{configColumnId},
            #{configColumnGroupId},
            #{configColumnCode},
            #{configColumnName},
            #{configColumnSubName},
            #{configColumnTargetMode},
            #{configColumnTargetUrl},
            #{configTableId},
            #{configColumnStatus},
            #{configColumnOrder},
            #{configColumnDefault},
            #{configColumnType},
            #{configColumnPhoto},
            #{configColumnRemark},
            #{configColumnMaxCount},
            #{configColumnRowCount},
            #{configColumnRowTargetMode},
            #{configColumnRowTargetUrl},
            #{configColumnComment},
            #{configColumnDispatch},
            #{configColumnLike},
            #{configColumnCollect},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

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

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

    <!-- 修改 -->
    <update id="update" parameterType="map">
        UPDATE
            m_config_column
        SET
        <if test="configColumnGroupId != null and configColumnGroupId != ''">
            config_column_group_id = #{configColumnGroupId},
        </if>
        <if test="configColumnName != null and configColumnName != ''">
            config_column_name = #{configColumnName},
        </if>
        <if test="configColumnSubName != null and configColumnSubName != ''">
            config_column_sub_name = #{configColumnSubName},
        </if>
        <if test="configColumnTargetMode != null">
            config_column_target_mode = #{configColumnTargetMode},
        </if>
        <if test="configColumnTargetUrl != null and configColumnTargetUrl != ''">
            config_column_target_url = #{configColumnTargetUrl},
        </if>
        <if test="configTableId != null">
            config_table_id = #{configTableId},
        </if>
        <if test="configColumnStatus != null">
            config_column_status = #{configColumnStatus},
        </if>
        <if test="configColumnOrder != null">
            config_column_order = #{configColumnOrder},
        </if>
        <if test="configColumnDefault != null">
            config_column_default = #{configColumnDefault},
        </if>
        <if test="configColumnType != null">
            config_column_type = #{configColumnType},
        </if>
        <if test="configColumnPhoto != null and configColumnPhoto != ''">
            config_column_photo = #{configColumnPhoto},
        </if>
        <if test="configColumnRemark != null and configColumnRemark != ''">
            config_column_remark = #{configColumnRemark},
        </if>
        <if test="configColumnMaxCount != null">
            config_column_max_count = #{configColumnMaxCount},
        </if>
        <if test="configColumnRowCount != null">
            config_column_row_count = #{configColumnRowCount},
        </if>
        <if test="configColumnRowTargetMode != null">
            config_column_row_target_mode = #{configColumnRowTargetMode},
        </if>
        <if test="configColumnRowTargetUrl != null and configColumnRowTargetUrl != ''">
            config_column_row_target_url = #{configColumnRowTargetUrl},
        </if>
            config_column_comment = #{configColumnComment},
            config_column_dispatch = #{configColumnDispatch},
            config_column_like = #{configColumnLike},
            config_column_collect = #{configColumnCollect},
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            config_column_id = config_column_id
        WHERE
            config_column_id = #{configColumnId}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="configColumnDTO">
        SELECT
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.config_column_id,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnId != null and configColumnId != ''">
        AND
            t1.config_column_id = #{configColumnId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getBO" parameterType="map" resultMap="configColumnBO">
        SELECT
            t1.config_column_id,
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnId != null and configColumnId != ''">
        AND
            t1.config_column_id = #{configColumnId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getPO" parameterType="map" resultMap="configColumnPO">
        SELECT
            t1.config_column_id,
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0
            <if test="configColumnId != null and configColumnId != ''">
        AND
            t1.config_column_id = #{configColumnId}
            </if>
    </select>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="configColumnDTO">
        SELECT
            t1.config_column_id,
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column t1
        WHERE
            t1.is_delete = 0
        <if test="configTableId != null and configTableId != ''">
            AND t1.config_table_id = #{configTableId}
        </if>
        <if test="configColumnDefault != null and configColumnDefault != ''">
            AND t1.config_column_default = #{configColumnDefault}
        </if>
        <if test="configColumnGroupId != null and configColumnGroupId != ''">
            AND t1.config_column_group_id = #{configColumnGroupId}
        </if>
        <if test="configColumnStatus != null and configColumnStatus != ''">
            AND t1.config_column_status = #{configColumnStatus}
        </if>
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.config_column_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.config_column_sub_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.config_column_code 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="configColumnIds != null and configColumnIds.size > 0">
        AND
            t1.config_column_id IN
            <foreach collection="configColumnIds" index="index" open="(" separator="," close=")">
                #{configColumnIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.config_column_order
    </select>

    <!-- 列表 -->
    <select id="listBO" parameterType="map" resultMap="configColumnBO">
        SELECT
            t1.config_column_id,
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column 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="configColumnIds != null and configColumnIds.size > 0">
        AND
            t1.config_column_id IN
            <foreach collection="configColumnIds" index="index" open="(" separator="," close=")">
                #{configColumnIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="configColumnPO">
        SELECT
            t1.config_column_id,
            t1.config_column_group_id,
            t1.config_column_code,
            t1.config_column_name,
            t1.config_column_sub_name,
            t1.config_column_target_mode,
            t1.config_column_target_url,
            t1.config_table_id,
            t1.config_column_status,
            t1.config_column_order,
            t1.config_column_default,
            t1.config_column_type,
            t1.config_column_photo,
            t1.config_column_remark,
            t1.config_column_max_count,
            t1.config_column_row_count,
            t1.config_column_row_target_mode,
            t1.config_column_row_target_url,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            t1.config_column_comment,
            t1.config_column_dispatch,
            t1.config_column_like,
            t1.config_column_collect
        FROM
            m_config_column 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="configColumnIds != null and configColumnIds.size > 0">
        AND
            t1.config_column_id IN
            <foreach collection="configColumnIds" index="index" open="(" separator="," close=")">
                #{configColumnIds[${index}]}
            </foreach>
        </if>
    </select>

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

</mapper>