<?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="com.njzscloud.supervisory.biz.mapper.BizCompanyMapper">
    <select id="paging" resultType="com.njzscloud.supervisory.biz.pojo.entity.BizCompanyEntity">
        select a.*, b.biz_obj from biz_company a
        left join sys_user b on b.id = a.user_id
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>
    
    <select id="selectDetailWithBizObj" resultType="com.njzscloud.supervisory.biz.pojo.entity.BizCompanyEntity">
        select a.*, b.biz_obj 
        from biz_company a
        left join sys_user b on b.id = a.user_id
        where a.id = #{id} and a.deleted = 0
    </select>
    <select id="station" resultType="com.njzscloud.supervisory.biz.pojo.result.StationResult">
        SELECT id,
        user_id,
        station,
        uscc,
        company_name,
        station_name,
        business_license,
        license_start_time,
        license_end_time,
        legal_representative,
        province,
        city,
        area,
        town,
        province_name,
        city_name,
        area_name,
        town_name,
        address,
        lng,
        lat,
        contacts,
        phone,
        audit_status,
        audit_memo,
        creator_id,
        modifier_id,
        create_time,
        modify_time,
        deleted,
        `open`,
        <if test="lng != null and lat != null">
            (6371 *
            ACOS(COS(RADIANS(lat)) * COS(RADIANS(#{lat})) *
            COS(RADIANS(#{lng}) - RADIANS(lng)) +
            SIN(RADIANS(lat)) * SIN(RADIANS(#{lat}))))
            AS distance
        </if>
        <if test="lng == null or lat == null">
            NULL distance
        </if>
        FROM biz_company
        WHERE deleted = 0
        AND `open` = 1
        AND station = 1
    </select>
</mapper>
