<?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.projectconfig.dao.projectconfig.IProjectConfigDao">

    <cache/>

    <resultMap id="projectConfigDTO" type="cn.com.tenlion.projectconfig.pojo.dtos.projectconfig.ProjectConfigDTO">
        <result column="project_config_id" property="projectConfigId"/>
        <result column="project_config_key" property="projectConfigKey"/>
        <result column="project_config_mode" property="projectConfigMode"/>
        <result column="project_config_text" property="projectConfigText"/>
        <result column="project_config_switch" property="projectConfigSwitch"/>
        <result column="project_config_image" property="projectConfigImage"/>
        <result column="project_config_html" property="projectConfigHtml"/>
        <result column="project_config_params" property="projectConfigParams"/>
        <result column="project_config_level" property="projectConfigLevel"/>
        <result column="project_config_status" property="projectConfigStatus"/>
        <result column="project_config_remark" property="projectConfigRemark"/>
        <result column="project_config_project" property="projectConfigProject"/>
        <result column="project_config_int" property="projectConfigInt"/>
        <result column="project_config_double" property="projectConfigDouble"/>
        <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="projectConfigBO" type="cn.com.tenlion.projectconfig.pojo.bos.projectconfig.ProjectConfigBO">
        <result column="project_config_id" property="projectConfigId"/>
        <result column="project_config_key" property="projectConfigKey"/>
        <result column="project_config_mode" property="projectConfigMode"/>
        <result column="project_config_text" property="projectConfigText"/>
        <result column="project_config_switch" property="projectConfigSwitch"/>
        <result column="project_config_image" property="projectConfigImage"/>
        <result column="project_config_params" property="projectConfigParams"/>
        <result column="project_config_level" property="projectConfigLevel"/>
        <result column="project_config_status" property="projectConfigStatus"/>
        <result column="project_config_remark" property="projectConfigRemark"/>
        <result column="project_config_project" property="projectConfigProject"/>
        <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="projectConfigPO" type="cn.com.tenlion.projectconfig.pojo.pos.projectconfig.ProjectConfigPO">
        <result column="project_config_id" property="projectConfigId"/>
        <result column="project_config_key" property="projectConfigKey"/>
        <result column="project_config_mode" property="projectConfigMode"/>
        <result column="project_config_text" property="projectConfigText"/>
        <result column="project_config_switch" property="projectConfigSwitch"/>
        <result column="project_config_image" property="projectConfigImage"/>
        <result column="project_config_params" property="projectConfigParams"/>
        <result column="project_config_level" property="projectConfigLevel"/>
        <result column="project_config_status" property="projectConfigStatus"/>
        <result column="project_config_remark" property="projectConfigRemark"/>
        <result column="project_config_project" property="projectConfigProject"/>
        <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>

    <!-- 新增CBC项目配置管理表 -->
    <insert id="save" parameterType="map" flushCache="true">
        INSERT INTO m_project_config(
            project_config_id,
            project_config_key,
            project_config_mode,
            project_config_text,
            project_config_switch,
            project_config_image,
            project_config_params,
            project_config_level,
            project_config_status,
            project_config_remark,
            project_config_project,
            project_config_int,
            project_config_double,
            project_config_html,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{projectConfigId},
            #{projectConfigKey},
            #{projectConfigMode},
            #{projectConfigText},
            #{projectConfigSwitch},
            #{projectConfigImage},
            #{projectConfigParams},
            #{projectConfigLevel},
            #{projectConfigStatus},
            #{projectConfigRemark},
            #{projectConfigProject},
            #{projectConfigInt},
            #{projectConfigDouble},
            #{projectConfigHtml},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除CBC项目配置管理表 -->
    <update id="remove" parameterType="map" flushCache="true">
        UPDATE
            m_project_config
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            project_config_id IN
        <foreach collection="projectConfigIds" index="index" open="(" separator="," close=")">
            #{projectConfigIds[${index}]}
        </foreach>
    </update>

    <!-- 删除CBC项目配置管理表（物理） -->
    <update id="delete" parameterType="map" flushCache="true">
        DELETE FROM
            m_project_config
        WHERE
            project_config_id IN
        <foreach collection="projectConfigIds" index="index" open="(" separator="," close=")">
            #{projectConfigIds[${index}]}
        </foreach>
    </update>

    <update id="updateSwitch" parameterType="map" flushCache="true">
        UPDATE
            m_project_config
        SET
            project_config_switch = #{projectConfigSwitch},
            gmt_modified = #{gmtModified},
            modifier = #{modifier}
        WHERE
            project_config_id = #{projectConfigId}
    </update>

    <!-- 修改CBC项目配置管理表 -->
    <update id="update" parameterType="map" flushCache="true">
        UPDATE
            m_project_config
        SET
        <if test="projectConfigText != null and projectConfigText != ''">
            project_config_text = #{projectConfigText},
        </if>
        <if test="projectConfigSwitch != null and projectConfigSwitch != ''">
            project_config_switch = #{projectConfigSwitch},
        </if>
        <if test="projectConfigImage != null and projectConfigImage != ''">
            project_config_image = #{projectConfigImage},
        </if>
        <if test="projectConfigParams != null and projectConfigParams != ''">
            project_config_params = #{projectConfigParams},
        </if>
        <if test="projectConfigLevel != null and projectConfigLevel != ''">
            project_config_level = #{projectConfigLevel},
        </if>
        <if test="projectConfigRemark != null and projectConfigRemark != ''">
            project_config_remark = #{projectConfigRemark},
        </if>
        <if test="projectConfigProject != null and projectConfigProject != ''">
            project_config_project = #{projectConfigProject},
        </if>
        <if test="projectConfigInt != null  and projectConfigInt != ''">
            project_config_int = #{projectConfigInt},
        </if>
        <if test="projectConfigDouble != null  and projectConfigDouble != ''">
            project_config_double = #{projectConfigDouble},
        </if>
        <if test="projectConfigHtml != null  and projectConfigHtml != ''">
            project_config_html = #{projectConfigHtml},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            project_config_id = project_config_id
        WHERE
            project_config_id = #{projectConfigId}
    </update>

    <!-- CBC项目配置管理表详情 -->
    <select id="get" parameterType="map" resultMap="projectConfigDTO" useCache="true">
        SELECT
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.project_config_id
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
            <if test="projectConfigId != null and projectConfigId != ''">
        AND
            t1.project_config_id = #{projectConfigId}
            </if>
        <if test="projectConfigKey != null and projectConfigKey != ''">
            AND
            t1.project_config_key = #{projectConfigKey}
        </if>
        LIMIT 1
    </select>

    <!-- CBC项目配置管理表详情 -->
    <select id="getBO" parameterType="map" resultMap="projectConfigBO">
        SELECT
            t1.project_config_id,
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
            <if test="projectConfigId != null and projectConfigId != ''">
        AND
            t1.project_config_id = #{projectConfigId}
            </if>
    </select>

    <!-- CBC项目配置管理表详情 -->
    <select id="getPO" parameterType="map" resultMap="projectConfigPO">
        SELECT
            t1.project_config_id,
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
            <if test="projectConfigId != null and projectConfigId != ''">
        AND
            t1.project_config_id = #{projectConfigId}
            </if>
    </select>

    <!-- CBC项目配置管理表列表 -->
    <select id="list" parameterType="map" resultMap="projectConfigDTO" useCache="true">
        SELECT
            t1.project_config_id,
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.project_config_remark LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.project_config_key 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="projectConfigIds != null and projectConfigIds.size > 0">
        AND
            t1.project_config_id IN
            <foreach collection="projectConfigIds" index="index" open="(" separator="," close=")">
                #{projectConfigIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create DESC
    </select>

    <!-- CBC项目配置管理表列表 -->
    <select id="listBO" parameterType="map" resultMap="projectConfigBO">
        SELECT
            t1.project_config_id,
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_project_config 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="projectConfigIds != null and projectConfigIds.size > 0">
        AND
            t1.project_config_id IN
            <foreach collection="projectConfigIds" index="index" open="(" separator="," close=")">
                #{projectConfigIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC项目配置管理表列表 -->
    <select id="listPO" parameterType="map" resultMap="projectConfigPO">
        SELECT
            t1.project_config_id,
            t1.project_config_key,
            t1.project_config_mode,
            t1.project_config_text,
            t1.project_config_switch,
            t1.project_config_image,
            t1.project_config_params,
            t1.project_config_level,
            t1.project_config_status,
            t1.project_config_remark,
            t1.project_config_project,
            t1.project_config_int,
            t1.project_config_double,
            t1.project_config_html,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.project_config_key LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.project_config_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="projectConfigIds != null and projectConfigIds.size > 0">
        AND
            t1.project_config_id IN
            <foreach collection="projectConfigIds" index="index" open="(" separator="," close=")">
                #{projectConfigIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- CBC项目配置管理表统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_project_config t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>