<?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.systembase.dao.comprehensivecenter.IComprehensiveCenterDao">

    <resultMap id="comprehensiveCenterDTO" type="cn.com.tenlion.systembase.pojo.dtos.comprehensivecenter.ComprehensiveCenterDTO">
        <result column="comprehensive_center_id" property="comprehensiveCenterId"/>
        <result column="center_name" property="centerName"/>
        <result column="center_phone" property="centerPhone"/>
        <result column="center_level" property="centerLevel"/>
        <result column="center_level_name" property="centerLevelName"/>
        <result column="center_level_code" property="centerLevelCode"/>
        <result column="link_man" property="linkMan"/>
        <result column="link_phone" property="linkPhone"/>
        <result column="component" property="component"/>
        <result column="location" property="location"/>
        <result column="location_name" property="locationName"/>
        <result column="location_code" property="locationCode"/>
        <result column="address" property="address"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="comprehensiveCenterBO" type="cn.com.tenlion.systembase.pojo.bos.comprehensivecenter.ComprehensiveCenterBO">
        <result column="comprehensive_center_id" property="comprehensiveCenterId"/>
        <result column="center_name" property="centerName"/>
        <result column="center_phone" property="centerPhone"/>
        <result column="center_level" property="centerLevel"/>
        <result column="center_level_name" property="centerLevelName"/>
        <result column="center_level_code" property="centerLevelCode"/>
        <result column="link_man" property="linkMan"/>
        <result column="link_phone" property="linkPhone"/>
        <result column="component" property="component"/>
        <result column="location" property="location"/>
        <result column="location_name" property="locationName"/>
        <result column="location_code" property="locationCode"/>
        <result column="address" property="address"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <resultMap id="comprehensiveCenterPO" type="cn.com.tenlion.systembase.pojo.pos.comprehensivecenter.ComprehensiveCenterPO">
        <result column="comprehensive_center_id" property="comprehensiveCenterId"/>
        <result column="center_name" property="centerName"/>
        <result column="center_phone" property="centerPhone"/>
        <result column="center_level" property="centerLevel"/>
        <result column="center_level_name" property="centerLevelName"/>
        <result column="center_level_code" property="centerLevelCode"/>
        <result column="link_man" property="linkMan"/>
        <result column="link_phone" property="linkPhone"/>
        <result column="component" property="component"/>
        <result column="location" property="location"/>
        <result column="location_name" property="locationName"/>
        <result column="location_code" property="locationCode"/>
        <result column="address" property="address"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <!-- 新增综治中心 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_comprehensive_center(
            comprehensive_center_id,
            center_name,
            center_phone,
            center_level,
            center_level_name,
            center_level_code,
            link_man,
            link_phone,
            component,
            location,
            location_name,
            location_code,
            grid,
            address,
            longitude,
            latitude,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{comprehensiveCenterId},
            #{centerName},
            #{centerPhone},
            #{centerLevel},
            #{centerLevelName},
            #{centerLevelCode},
            #{linkMan},
            #{linkPhone},
            #{component},
            #{location},
            #{locationName},
            #{locationCode},
            #{grid},
            #{address},
            #{longitude},
            #{latitude},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除综治中心 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_comprehensive_center
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            comprehensive_center_id IN
        <foreach collection="comprehensiveCenterIds" index="index" open="(" separator="," close=")">
            #{comprehensiveCenterIds[${index}]}
        </foreach>
    </update>

    <!-- 删除综治中心（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_comprehensive_center
        WHERE
            comprehensive_center_id IN
        <foreach collection="comprehensiveCenterIds" index="index" open="(" separator="," close=")">
            #{comprehensiveCenterIds[${index}]}
        </foreach>
    </update>

    <!-- 修改综治中心 -->
    <update id="update" parameterType="map">
        UPDATE
            data_comprehensive_center
        SET
        <if test="centerName != null and centerName != ''">
            center_name = #{centerName},
        </if>
        <if test="centerPhone != null and centerPhone != ''">
            center_phone = #{centerPhone},
        </if>
        <if test="centerLevel != null">
            center_level = #{centerLevel},
        </if>
        <if test="centerLevelName != null and centerLevelName != ''">
            center_level_name = #{centerLevelName},
        </if>
        <if test="centerLevelCode != null and centerLevelCode != ''">
            center_level_code = #{centerLevelCode},
        </if>
        <if test="linkMan != null and linkMan != ''">
            link_man = #{linkMan},
        </if>
        <if test="linkPhone != null and linkPhone != ''">
            link_phone = #{linkPhone},
        </if>
        <if test="component != null and component != ''">
            component = #{component},
        </if>
        <if test="location != null and location != ''">
            location = #{location},
        </if>
        <if test="locationName != null and locationName != ''">
            location_name = #{locationName},
        </if>
        <if test="locationCode != null and locationCode != ''">
            location_code = #{locationCode},
        </if>
        <if test="grid != null and grid != ''">
            grid = #{grid},
        </if>
        <if test="address != null and address != ''">
            address = #{address},
        </if>
        <if test="longitude != null">
            longitude = #{longitude},
        </if>
        <if test="latitude != null">
            latitude = #{latitude},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            comprehensive_center_id = comprehensive_center_id
        WHERE
            comprehensive_center_id = #{comprehensiveCenterId}
    </update>

    <!-- 综治中心详情 -->
    <select id="get" parameterType="map" resultMap="comprehensiveCenterDTO">
        SELECT
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.grid,
            t1.address,
            t1.longitude,
            t1.latitude,
            t1.comprehensive_center_id
        FROM
            data_comprehensive_center t1
        WHERE
            t1.is_delete = 0
            <if test="comprehensiveCenterId != null and comprehensiveCenterId != ''">
        AND
            t1.comprehensive_center_id = #{comprehensiveCenterId}
            </if>
    </select>

    <!-- 综治中心详情 -->
    <select id="getBO" parameterType="map" resultMap="comprehensiveCenterBO">
        SELECT
            t1.comprehensive_center_id,
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.address,
            t1.longitude,
            t1.latitude
        FROM
            data_comprehensive_center t1
        WHERE
            t1.is_delete = 0
            <if test="comprehensiveCenterId != null and comprehensiveCenterId != ''">
        AND
            t1.comprehensive_center_id = #{comprehensiveCenterId}
            </if>
    </select>

    <!-- 综治中心详情 -->
    <select id="getPO" parameterType="map" resultMap="comprehensiveCenterPO">
        SELECT
            t1.comprehensive_center_id,
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.address,
            t1.longitude,
            t1.latitude
        FROM
            data_comprehensive_center t1
        WHERE
            t1.is_delete = 0
            <if test="comprehensiveCenterId != null and comprehensiveCenterId != ''">
        AND
            t1.comprehensive_center_id = #{comprehensiveCenterId}
            </if>
    </select>

    <!-- 综治中心列表 -->
    <select id="list" parameterType="map" resultMap="comprehensiveCenterDTO">
        SELECT
            t1.comprehensive_center_id,
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.grid,
            t1.address,
            t1.longitude,
            t1.latitude,
            1
        FROM
            data_comprehensive_center 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="comprehensiveCenterIds != null and comprehensiveCenterIds.size > 0">
        AND
            t1.comprehensive_center_id IN
            <foreach collection="comprehensiveCenterIds" index="index" open="(" separator="," close=")">
                #{comprehensiveCenterIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 综治中心列表 -->
    <select id="listBO" parameterType="map" resultMap="comprehensiveCenterBO">
        SELECT
            t1.comprehensive_center_id,
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.address,
            t1.longitude,
            t1.latitude
        FROM
            data_comprehensive_center 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="comprehensiveCenterIds != null and comprehensiveCenterIds.size > 0">
        AND
            t1.comprehensive_center_id IN
            <foreach collection="comprehensiveCenterIds" index="index" open="(" separator="," close=")">
                #{comprehensiveCenterIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 综治中心列表 -->
    <select id="listPO" parameterType="map" resultMap="comprehensiveCenterPO">
        SELECT
            t1.comprehensive_center_id,
            t1.center_name,
            t1.center_phone,
            t1.center_level,
            t1.center_level_name,
            t1.center_level_code,
            t1.link_man,
            t1.link_phone,
            t1.component,
            t1.location,
            t1.location_name,
            t1.location_code,
            t1.address,
            t1.longitude,
            t1.latitude
        FROM
            data_comprehensive_center 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="comprehensiveCenterIds != null and comprehensiveCenterIds.size > 0">
        AND
            t1.comprehensive_center_id IN
            <foreach collection="comprehensiveCenterIds" index="index" open="(" separator="," close=")">
                #{comprehensiveCenterIds[${index}]}
            </foreach>
        </if>
    </select>

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

</mapper>