<?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.logisticssafe.ILogisticsSafeDao">

    <resultMap id="logisticsSafeDTO" type="cn.com.tenlion.systembase.pojo.dtos.logisticssafe.LogisticsSafeDTO">
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <result column="license_num" property="licenseNum"/>
        <result column="logistics_enterprise_name" property="logisticsEnterpriseName"/>
        <result column="enterprise_location" property="enterpriseLocation"/>
        <result column="enterprise_location_name" property="enterpriseLocationName"/>
        <result column="enterprise_location_code" property="enterpriseLocationCode"/>
        <result column="enterprise_address" property="enterpriseAddress"/>
        <result column="enterprise_phone" property="enterprisePhone"/>
        <result column="enterprise_link_man" property="enterpriseLinkMan"/>
        <result column="enterprise_link_phone" property="enterpriseLinkPhone"/>
        <result column="registration_type" property="registrationType"/>
        <result column="registration_type_name" property="registrationTypeName"/>
        <result column="registration_type_code" property="registrationTypeCode"/>
        <result column="holding_situation" property="holdingSituation"/>
        <result column="holding_situation_name" property="holdingSituationName"/>
        <result column="holding_situation_code" property="holdingSituationCode"/>
        <result column="business_nature" property="businessNature"/>
        <result column="business_nature_name" property="businessNatureName"/>
        <result column="business_nature_code" property="businessNatureCode"/>
        <result column="enterprise_type" property="enterpriseType"/>
        <result column="enterprise_type_name" property="enterpriseTypeName"/>
        <result column="enterprise_type_code" property="enterpriseTypeCode"/>
        <result column="service_brand" property="serviceBrand"/>
        <result column="employees_count" property="employeesCount"/>
        <result column="video_count" property="videoCount"/>
        <result column="x_machine_count" property="xMachineCount"/>
        <result column="is_sealing" property="isSealing"/>
        <result column="is_real_name" property="isRealName"/>
        <result column="is_x_check" property="isXCheck"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="grid" property="grid"/>
    </resultMap>

    <resultMap id="logisticsSafeBO" type="cn.com.tenlion.systembase.pojo.bos.logisticssafe.LogisticsSafeBO">
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <result column="license_num" property="licenseNum"/>
        <result column="logistics_enterprise_name" property="logisticsEnterpriseName"/>
        <result column="enterprise_location" property="enterpriseLocation"/>
        <result column="enterprise_location_name" property="enterpriseLocationName"/>
        <result column="enterprise_location_code" property="enterpriseLocationCode"/>
        <result column="enterprise_address" property="enterpriseAddress"/>
        <result column="enterprise_phone" property="enterprisePhone"/>
        <result column="enterprise_link_man" property="enterpriseLinkMan"/>
        <result column="enterprise_link_phone" property="enterpriseLinkPhone"/>
        <result column="registration_type" property="registrationType"/>
        <result column="registration_type_name" property="registrationTypeName"/>
        <result column="registration_type_code" property="registrationTypeCode"/>
        <result column="holding_situation" property="holdingSituation"/>
        <result column="holding_situation_name" property="holdingSituationName"/>
        <result column="holding_situation_code" property="holdingSituationCode"/>
        <result column="business_nature" property="businessNature"/>
        <result column="business_nature_name" property="businessNatureName"/>
        <result column="business_nature_code" property="businessNatureCode"/>
        <result column="enterprise_type" property="enterpriseType"/>
        <result column="enterprise_type_name" property="enterpriseTypeName"/>
        <result column="enterprise_type_code" property="enterpriseTypeCode"/>
        <result column="service_brand" property="serviceBrand"/>
        <result column="employees_count" property="employeesCount"/>
        <result column="video_count" property="videoCount"/>
        <result column="x_machine_count" property="xMachineCount"/>
        <result column="is_sealing" property="isSealing"/>
        <result column="is_real_name" property="isRealName"/>
        <result column="is_x_check" property="isXCheck"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <resultMap id="logisticsSafePO" type="cn.com.tenlion.systembase.pojo.pos.logisticssafe.LogisticsSafePO">
        <result column="logistics_safe_id" property="logisticsSafeId"/>
        <result column="license_num" property="licenseNum"/>
        <result column="logistics_enterprise_name" property="logisticsEnterpriseName"/>
        <result column="enterprise_location" property="enterpriseLocation"/>
        <result column="enterprise_location_name" property="enterpriseLocationName"/>
        <result column="enterprise_location_code" property="enterpriseLocationCode"/>
        <result column="enterprise_address" property="enterpriseAddress"/>
        <result column="enterprise_phone" property="enterprisePhone"/>
        <result column="enterprise_link_man" property="enterpriseLinkMan"/>
        <result column="enterprise_link_phone" property="enterpriseLinkPhone"/>
        <result column="registration_type" property="registrationType"/>
        <result column="registration_type_name" property="registrationTypeName"/>
        <result column="registration_type_code" property="registrationTypeCode"/>
        <result column="holding_situation" property="holdingSituation"/>
        <result column="holding_situation_name" property="holdingSituationName"/>
        <result column="holding_situation_code" property="holdingSituationCode"/>
        <result column="business_nature" property="businessNature"/>
        <result column="business_nature_name" property="businessNatureName"/>
        <result column="business_nature_code" property="businessNatureCode"/>
        <result column="enterprise_type" property="enterpriseType"/>
        <result column="enterprise_type_name" property="enterpriseTypeName"/>
        <result column="enterprise_type_code" property="enterpriseTypeCode"/>
        <result column="service_brand" property="serviceBrand"/>
        <result column="employees_count" property="employeesCount"/>
        <result column="video_count" property="videoCount"/>
        <result column="x_machine_count" property="xMachineCount"/>
        <result column="is_sealing" property="isSealing"/>
        <result column="is_real_name" property="isRealName"/>
        <result column="is_x_check" property="isXCheck"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <!-- 新增寄递物流安全管理 -->
    <insert id="save" parameterType="map">
        INSERT INTO data_logistics_safe(
            logistics_safe_id,
            license_num,
            logistics_enterprise_name,
            enterprise_location,
            enterprise_location_name,
            enterprise_location_code,
            enterprise_address,
            enterprise_phone,
            enterprise_link_man,
            enterprise_link_phone,
            registration_type,
            registration_type_name,
            registration_type_code,
            holding_situation,
            holding_situation_name,
            holding_situation_code,
            business_nature,
            business_nature_name,
            business_nature_code,
            enterprise_type,
            enterprise_type_name,
            enterprise_type_code,
            service_brand,
            employees_count,
            video_count,
            x_machine_count,
            is_sealing,
            is_real_name,
            is_x_check,
            longitude,
            latitude,
            grid,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{logisticsSafeId},
            #{licenseNum},
            #{logisticsEnterpriseName},
            #{enterpriseLocation},
            #{enterpriseLocationName},
            #{enterpriseLocationCode},
            #{enterpriseAddress},
            #{enterprisePhone},
            #{enterpriseLinkMan},
            #{enterpriseLinkPhone},
            #{registrationType},
            #{registrationTypeName},
            #{registrationTypeCode},
            #{holdingSituation},
            #{holdingSituationName},
            #{holdingSituationCode},
            #{businessNature},
            #{businessNatureName},
            #{businessNatureCode},
            #{enterpriseType},
            #{enterpriseTypeName},
            #{enterpriseTypeCode},
            #{serviceBrand},
            #{employeesCount},
            #{videoCount},
            #{xMachineCount},
            #{isSealing},
            #{isRealName},
            #{isXCheck},
            #{longitude},
            #{latitude},
            #{grid},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除寄递物流安全管理 -->
    <update id="remove" parameterType="map">
        UPDATE
            data_logistics_safe
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            logistics_safe_id IN
        <foreach collection="logisticsSafeIds" index="index" open="(" separator="," close=")">
            #{logisticsSafeIds[${index}]}
        </foreach>
    </update>

    <!-- 删除寄递物流安全管理（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            data_logistics_safe
        WHERE
            logistics_safe_id IN
        <foreach collection="logisticsSafeIds" index="index" open="(" separator="," close=")">
            #{logisticsSafeIds[${index}]}
        </foreach>
    </update>

    <!-- 修改寄递物流安全管理 -->
    <update id="update" parameterType="map">
        UPDATE
            data_logistics_safe
        SET
        <if test="licenseNum != null and licenseNum != ''">
            license_num = #{licenseNum},
        </if>
        <if test="logisticsEnterpriseName != null and logisticsEnterpriseName != ''">
            logistics_enterprise_name = #{logisticsEnterpriseName},
        </if>
        <if test="enterpriseLocation != null and enterpriseLocation != ''">
            enterprise_location = #{enterpriseLocation},
        </if>
        <if test="enterpriseLocationName != null and enterpriseLocationName != ''">
            enterprise_location_name = #{enterpriseLocationName},
        </if>
        <if test="enterpriseLocationCode != null and enterpriseLocationCode != ''">
            enterprise_location_code = #{enterpriseLocationCode},
        </if>
        <if test="enterpriseAddress != null and enterpriseAddress != ''">
            enterprise_address = #{enterpriseAddress},
        </if>
        <if test="enterprisePhone != null and enterprisePhone != ''">
            enterprise_phone = #{enterprisePhone},
        </if>
        <if test="enterpriseLinkMan != null and enterpriseLinkMan != ''">
            enterprise_link_man = #{enterpriseLinkMan},
        </if>
        <if test="enterpriseLinkPhone != null and enterpriseLinkPhone != ''">
            enterprise_link_phone = #{enterpriseLinkPhone},
        </if>
        <if test="registrationType != null">
            registration_type = #{registrationType},
        </if>
        <if test="registrationTypeName != null and registrationTypeName != ''">
            registration_type_name = #{registrationTypeName},
        </if>
        <if test="registrationTypeCode != null and registrationTypeCode != ''">
            registration_type_code = #{registrationTypeCode},
        </if>
        <if test="holdingSituation != null">
            holding_situation = #{holdingSituation},
        </if>
        <if test="holdingSituationName != null and holdingSituationName != ''">
            holding_situation_name = #{holdingSituationName},
        </if>
        <if test="holdingSituationCode != null and holdingSituationCode != ''">
            holding_situation_code = #{holdingSituationCode},
        </if>
        <if test="businessNature != null and businessNature != ''">
            business_nature = #{businessNature},
        </if>
        <if test="businessNatureName != null and businessNatureName != ''">
            business_nature_name = #{businessNatureName},
        </if>
        <if test="businessNatureCode != null and businessNatureCode != ''">
            business_nature_code = #{businessNatureCode},
        </if>
        <if test="enterpriseType != null">
            enterprise_type = #{enterpriseType},
        </if>
        <if test="enterpriseTypeName != null and enterpriseTypeName != ''">
            enterprise_type_name = #{enterpriseTypeName},
        </if>
        <if test="enterpriseTypeCode != null and enterpriseTypeCode != ''">
            enterprise_type_code = #{enterpriseTypeCode},
        </if>
        <if test="serviceBrand != null and serviceBrand != ''">
            service_brand = #{serviceBrand},
        </if>
        <if test="employeesCount != null">
            employees_count = #{employeesCount},
        </if>
        <if test="videoCount != null">
            video_count = #{videoCount},
        </if>
        <if test="xMachineCount != null">
            x_machine_count = #{xMachineCount},
        </if>
        <if test="isSealing != null">
            is_sealing = #{isSealing},
        </if>
        <if test="isRealName != null">
            is_real_name = #{isRealName},
        </if>
        <if test="isXCheck != null">
            is_x_check = #{isXCheck},
        </if>
        <if test="longitude != null">
            longitude = #{longitude},
        </if>
        <if test="latitude != null">
            latitude = #{latitude},
        </if>
        <if test="grid != null and grid != ''">
            grid = #{grid},
        </if>
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            logistics_safe_id = logistics_safe_id
        WHERE
            logistics_safe_id = #{logisticsSafeId}
    </update>

    <!-- 寄递物流安全管理详情 -->
    <select id="get" parameterType="map" resultMap="logisticsSafeDTO">
        SELECT
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude,
            t1.grid,
            t1.logistics_safe_id
        FROM
            data_logistics_safe t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafeId != null and logisticsSafeId != ''">
        AND
            t1.logistics_safe_id = #{logisticsSafeId}
            </if>
    </select>

    <!-- 寄递物流安全管理详情 -->
    <select id="getBO" parameterType="map" resultMap="logisticsSafeBO">
        SELECT
            t1.logistics_safe_id,
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude
        FROM
            data_logistics_safe t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafeId != null and logisticsSafeId != ''">
        AND
            t1.logistics_safe_id = #{logisticsSafeId}
            </if>
    </select>

    <!-- 寄递物流安全管理详情 -->
    <select id="getPO" parameterType="map" resultMap="logisticsSafePO">
        SELECT
            t1.logistics_safe_id,
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude
        FROM
            data_logistics_safe t1
        WHERE
            t1.is_delete = 0
            <if test="logisticsSafeId != null and logisticsSafeId != ''">
        AND
            t1.logistics_safe_id = #{logisticsSafeId}
            </if>
    </select>

    <!-- 寄递物流安全管理列表 -->
    <select id="list" parameterType="map" resultMap="logisticsSafeDTO">
        SELECT
            t1.logistics_safe_id,
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude,
            t1.grid,
            1
        FROM
            data_logistics_safe t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.license_num LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.logistics_enterprise_name LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="areaCode != null and areaCode != ''">
            AND t1.enterprise_location_code = #{areaCode}
        </if>
        <if test="areaCodeLike != null and areaCodeLike != ''">
            AND t1.enterprise_location_code LIKE CONCAT(#{areaCodeLike}, '%')
        </if>
        <if test="grid != null and grid != ''">
            AND t1.grid = #{grid}
        </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="logisticsSafeIds != null and logisticsSafeIds.size > 0">
        AND
            t1.logistics_safe_id IN
            <foreach collection="logisticsSafeIds" index="index" open="(" separator="," close=")">
                #{logisticsSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全管理列表 -->
    <select id="listBO" parameterType="map" resultMap="logisticsSafeBO">
        SELECT
            t1.logistics_safe_id,
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude
        FROM
            data_logistics_safe 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="logisticsSafeIds != null and logisticsSafeIds.size > 0">
        AND
            t1.logistics_safe_id IN
            <foreach collection="logisticsSafeIds" index="index" open="(" separator="," close=")">
                #{logisticsSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全管理列表 -->
    <select id="listPO" parameterType="map" resultMap="logisticsSafePO">
        SELECT
            t1.logistics_safe_id,
            t1.license_num,
            t1.logistics_enterprise_name,
            t1.enterprise_location,
            t1.enterprise_location_name,
            t1.enterprise_location_code,
            t1.enterprise_address,
            t1.enterprise_phone,
            t1.enterprise_link_man,
            t1.enterprise_link_phone,
            t1.registration_type,
            t1.registration_type_name,
            t1.registration_type_code,
            t1.holding_situation,
            t1.holding_situation_name,
            t1.holding_situation_code,
            t1.business_nature,
            t1.business_nature_name,
            t1.business_nature_code,
            t1.enterprise_type,
            t1.enterprise_type_name,
            t1.enterprise_type_code,
            t1.service_brand,
            t1.employees_count,
            t1.video_count,
            t1.x_machine_count,
            t1.is_sealing,
            t1.is_real_name,
            t1.is_x_check,
            t1.longitude,
            t1.latitude
        FROM
            data_logistics_safe 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="logisticsSafeIds != null and logisticsSafeIds.size > 0">
        AND
            t1.logistics_safe_id IN
            <foreach collection="logisticsSafeIds" index="index" open="(" separator="," close=")">
                #{logisticsSafeIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 寄递物流安全管理统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            data_logistics_safe t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>