<?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.ltgk.port.mapper.DsPortMapper">
    <resultMap type="com.ltgk.port.domain.entity.DsPort" id="DsPortResult">
        <result property="id" column="id"/>
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="portName" column="port_name"/>
        <result property="portLevel" column="port_level"/>
        <result property="berthNum" column="berth_num"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="finishTime" column="finish_time"/>
        <result property="typeId" column="type_id"/>
        <result property="typeName" column="type_name"/>
        <result property="landingsYear" column="landings_year"/>
        <result property="portShorelineLength" column="port_shoreline_length"/>
        <result property="portBreakwaterLength" column="port_breakwater_length"/>
        <result property="portBerthLength" column="port_berth_length"/>
        <result property="portJobAreaWidth" column="port_job_area_width"/>
        <result property="portWaterDepth" column="port_water_depth"/>
        <result property="serviceFacility" column="service_facility"/>
        <result property="portBusinessEntityName" column="port_business_entity_name"/>
        <result property="portBusinessEntityAddr" column="port_business_entity_addr"/>
        <result property="portBusinessEntityPeople" column="port_business_entity_people"/>
        <result property="portBusinessEntityTel" column="port_business_entity_tel"/>
        <result property="portRegulatoryBodiesName" column="port_regulatory_bodies_name"/>
        <result property="portRegulatoryBodiesAddr" column="port_regulatory_bodies_addr"/>
        <result property="portRegulatoryBodiesPeople" column="port_regulatory_bodies_people"/>
        <result property="portRegulatoryBodiesTel" column="port_regulatory_bodies_tel"/>
        <result property="areaType" column="area_type"/>
        <result property="boatWharf" column="boat_wharf"/>
        <result property="leisureWharf" column="leisure_wharf"/>
        <result property="waterArea" column="water_area"/>
        <result property="landArea" column="land_area"/>
        <result property="totalArea" column="total_area"/>
        <result property="portAddrDetail" column="port_addr_detail"/>
        <result property="positionInfo" column="position_info"/>
        <result property="nameDisplayState" column="name_display_state"/>
        <result property="fillColor" column="fill_color"/>
        <result property="diaphaneity" column="diaphaneity"/>
        <result property="lineColor" column="line_color"/>
        <result property="lineWidth" column="line_width"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="delFlag" column="del_flag"/>
        <result property="sort" column="sort"/>
        <result property="createBy" column="create_by"/>
        <result property="createAt" column="create_at"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateAt" column="update_at"/>
        <result property="remarks" column="remarks"/>
    </resultMap>

    <select id="getBoatCount" resultType="java.lang.Long">
        select count(boat_id)
        from ds_boat_data
    </select>

    <select id="getEnterOrOutPortCount" resultType="java.lang.Long">
        select count(*) from ds_enter_out_port where entry_dir = #{enterOrOut}
        <if test="startTime != null and endTime != null">
            and enter_out_time between #{startTime} and #{endTime}
        </if>
        <if test="portId != null and portId != ''">
            and port_id = #{portId}
        </if>
    </select>

    <select id="getEnterOutPortGroupBYPortId" resultType="com.ltgk.port.domain.vo.EnterOutVo">
        select port_id            as portId,
               port_name          as portName,
               sum(entry_dir = 0) as enterPortCount,
               sum(entry_dir = 1) as outPortCount,
               sum(id)            as allCount
        from ds_enter_out_port
        where enter_out_time between #{startTime} and #{endTime}
        group by port_id
        order by allCount desc
    </select>

    <select id="getBerthCount" resultType="java.lang.Long">
        select sum(berth_num) from ds_port where del_flag = 0
        <if test="portId != null">
            and id = #{portId}
        </if>
    </select>

    <select id="getEnterOrOutPortList" resultType="com.ltgk.port.domain.vo.BoatEnterOutVo">
        select dop.boat_id as boatId,dop.boat_name as boatName,dop.enter_out_time as enterOutTime,dop.port_name as
        portName,
        dop.device_type as deviceType,dop.device_code as deviceCode,dop.is_local as isLocal,
        dop.port_id as portId, dbd.boat_type as boatType,
        dbd.length, dbd.width, dbd.height, dbd.tonnage, dbd.net_tonnage as netTonnage,
        dbd.main_power as mainPower, dbd.holder_name as holderName, dbd.holder_address as holderAddress,
        dbd.holder_phone as holderPhone, dbd.boat_type as boatType,dop.entry_dir as enterOrOut
        from ds_enter_out_port as dop
        left join ds_boat_data as dbd on dop.boat_id = dbd.boat_id
        where entry_dir = #{enterOrOut}
        <if test="startTime != null and endTime != null">
            and enter_out_time between #{startTime} and #{endTime}
        </if>
        <if test="req.boatName != null and req.boatName != ''">
            and dop.boat_name like concat('%',#{req.boatName},'%')
        </if>
        <if test="req.deviceCode != null and req.deviceCode != ''">
            and dop.device_code like concat('%',#{req.deviceCode},'%')
        </if>
        <if test="req.portName != null and req.portName != ''">
            and dop.port_name like concat('%',#{req.portName},'%')
        </if>
        <if test="req.portId != null and req.portId != ''">
            and dop.port_id = #{req.portId}
        </if>
    </select>
    <select id="getBusinessIndexPortStatistics" resultType="com.ltgk.port.domain.entity.DsPort">
        SELECT dp.id, dp.dept_id, dp.dept_name, dp.port_name, dp.port_level, dp.berth_num, dp.longitude,
        dp.latitude, dp.finish_time, dp.type_id, dp.type_name, dp.landings_year, dp.port_shoreline_length,
        dp.port_breakwater_length, dp.port_berth_length, dp.port_job_area_width, dp.port_water_depth,
        dp.service_facility,
        dp.port_business_entity_name, dp.port_business_entity_addr, dp.port_business_entity_people,
        dp.port_business_entity_tel,
        dp.port_regulatory_bodies_name, dp.port_regulatory_bodies_addr, dp.port_regulatory_bodies_people,
        dp.port_regulatory_bodies_tel,
        dp.area_type, dp.boat_wharf, dp.leisure_wharf, dp.water_area, dp.land_area, dp.total_area, dp.port_addr_detail,
        dp.position_info, dp.name_display_state, dp.fill_color, dp.diaphaneity, dp.line_color, dp.line_width,
        dp.area_code,
        dp.area_name, dp.del_flag, dp.sort, dp.create_by, dp.create_at, dp.update_by, dp.update_at, dp.remarks
        FROM ds_port AS dp
        LEFT JOIN sys_dept d on dp.dept_id = d.dept_id
        where
        dp.del_flag = 0
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        ORDER BY dp.sort ASC
    </select>
</mapper>