<?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.ty.lift.system.homepage.dao.mapper.HomeLiftDataMapper">

    <!-- 获取平台电梯数据 - 统计电梯台量 -->
    <select id="getLiftUnitsData" resultType="cn.com.ty.lift.system.homepage.dao.model.LiftUnitsDataModel">
        select
            pclr.mt_company_id as mtCompanyId,
            pclr.lift_id as liftId,
            pclr.lift_company_status as liftCompanyStatus,
            mc.province_code as provinceCode
        from
            platform_company_lift_relevance pclr
        left join
            maintenance_company mc
        on
            pclr.mt_company_id = mc.id
    </select>

    <!-- 获取电梯地图中的电梯数据 -->
    <select id="getLiftMapData" parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.LiftDataRequest"
            resultType="cn.com.ty.lift.system.homepage.dao.model.LiftMapDataModel">
        select
            plr.lift_id as liftId,
            pclr.lift_company_status as liftCompanyStatus,
            l.registration_code as registrationCode,
            l.lift_type as liftType,
            l.lift_code as liftCode,
            l.lift_brand as liftBrand,
            l.coordinate as coordinate,
            l.device_position as devicePosition,
            p.project_name as projectName,
            ui.name as workerName
        from
            platform_company_lift_relevance pclr
        left join
            lift l
        on
            pclr.lift_id = l.id
        left join
            project_lift_relevance plr
        on
            pclr.lift_id = plr.lift_id
        left join
            project p
        on
            plr.project_id = p.id
        left join
            user_info ui
        on
            plr.worker_id = ui.user_id
        where
            pclr.mt_company_id = #{mtCompanyId}
    </select>

    <!-- 获取公司电梯信息 -->
    <select id="getCompanyLiftData" parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.LiftDataRequest"
            resultType="cn.com.ty.lift.system.homepage.dao.model.LiftMapDataModel">
        select
            lift_company_status as liftCompanyStatus,
            mt_company_id as mtCompanyId
        from
            platform_company_lift_relevance
        where
            1=1
        <!-- 判断公司id是否在集合中 -->
        <if test="companyIdList != null">
            and mt_company_id in
            <foreach item="item" index="index" collection="companyIdList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
    </select>

    <!-- 获取总电梯数量-->
    <select id="getTotalLiftNum" parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.LiftDataRequest"
            resultType="java.lang.Long">
        select
            count(1)
        from
            lift
    </select>

    <!-- 获取平台电梯数量 -->
    <select id="getPlatformLiftList" parameterType="cn.com.ty.lift.system.homepage.dao.dto.request.LiftDataRequest"
            resultType="cn.com.ty.lift.system.homepage.dao.dto.response.PlatformLiftData">
        select
            id as liftId,
            registration_code as registrationCode,
            lift_code as liftCode,
            lift_type as liftType,
            coordinate
        from
            lift
        limit  0, 1000
    </select>
</mapper>