<?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.BizWarnMapper">

    <resultMap id="BizWarnDetailVOResultMap" type="com.njzscloud.supervisory.biz.pojo.result.BizWarnDetailVO">
        <id property="id" column="id"/>
        <result property="warnCategory" column="warn_category"/>
        <result property="warnContent" column="warn_content"/>
        <result property="processResult" column="process_result"/>
        <result property="processStatus" column="process_status"/>
        <result property="orderId" column="order_id"/>
        <result property="picture" column="picture"/>
        <result property="creatorId" column="creator_id"/>
        <result property="modifierId" column="modifier_id"/>
        <result property="createTime" column="create_time"/>
        <result property="modifyTime" column="modify_time"/>
        <result property="deleted" column="deleted"/>
        <result property="sn" column="sn"/>
        <result property="contacts" column="contacts"/>
        <result property="phone" column="phone"/>
        <result property="cargoPlace" column="cargo_place"/>
        <result property="goodsName" column="goods_name"/>
        <result property="projectName" column="project_name"/>
        <result property="transCompanyName" column="trans_company_name"/>
        <result property="cfCompanyName" column="cf_company_name"/>
        <result property="licensePlate" column="license_plate"/>
        <result property="truckPicture" column="truck_picture"/>
        <result property="carryingCapacity" column="carrying_capacity"/>
        <result property="gps" column="gps"/>
        <result property="driverName" column="driver_name"/>
        <result property="driverPhone" column="driver_phone"/>
    </resultMap>

    <select id="selectWarnDetailPage" resultMap="BizWarnDetailVOResultMap">
        SELECT 
            bw.id,
            bw.warn_category,
            bw.warn_content,
            bw.process_result,
            bw.process_status,
            bw.order_id,
            bw.picture,
            bw.creator_id,
            bw.modifier_id,
            bw.create_time,
            bw.modify_time,
            bw.deleted,
            oi.sn,
            oi.contacts,
            oi.phone,
            CONCAT_WS('', ocp.province_name, ocp.city_name, ocp.area_name, ocp.town_name, ocp.address) AS cargo_place,
            og.goods_name,
            bp.project_name,
            bc1.company_name AS trans_company_name,
            bc2.company_name AS cf_company_name,
            bt.license_plate,
            bt.picture truck_picture,
            bt.carrying_capacity,
            bt.gps,
            bd.driver_name,
            bd.phone driver_phone
        FROM biz_warn bw
        LEFT JOIN order_info oi ON bw.order_id = oi.id AND oi.deleted = 0
        LEFT JOIN order_cargo_place ocp ON oi.cargo_place_id = ocp.id
        LEFT JOIN order_goods og ON oi.goods_id = og.id
        LEFT JOIN biz_project bp ON oi.project_id = bp.id AND bp.deleted = 0
        LEFT JOIN biz_company bc1 ON oi.trans_company_id = bc1.id AND bc1.deleted = 0
        LEFT JOIN biz_company bc2 ON oi.user_id = bc2.user_id AND bc2.deleted = 0
        LEFT JOIN biz_truck bt ON oi.truck_id = bt.id AND bt.deleted = 0
        LEFT JOIN biz_driver bd ON oi.driver_id = bd.id AND bd.deleted = 0
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
        ORDER BY bw.modify_time DESC
    </select>

    <select id="selectWarnDetailById" resultMap="BizWarnDetailVOResultMap">
        SELECT 
            bw.id,
            bw.warn_category,
            bw.warn_content,
            bw.process_result,
            bw.process_status,
            bw.order_id,
            bw.picture,
            bw.creator_id,
            bw.modifier_id,
            bw.create_time,
            bw.modify_time,
            bw.deleted,
            oi.sn,
            oi.contacts,
            oi.phone,
            CONCAT_WS('', ocp.province_name, ocp.city_name, ocp.area_name, ocp.town_name, ocp.address) AS cargo_place,
            og.goods_name,
            bp.project_name,
            bc1.company_name AS trans_company_name,
            bc2.company_name AS cf_company_name,
            bt.license_plate,
            bt.picture,
            bt.carrying_capacity,
            bt.gps,
            bd.driver_name,
            bd.phone driver_phone
        FROM biz_warn bw
        LEFT JOIN order_info oi ON bw.order_id = oi.id AND oi.deleted = 0
        LEFT JOIN order_cargo_place ocp ON oi.cargo_place_id = ocp.id
        LEFT JOIN order_goods og ON oi.goods_id = og.id
        LEFT JOIN biz_project bp ON oi.project_id = bp.id AND bp.deleted = 0
        LEFT JOIN biz_company bc1 ON oi.trans_company_id = bc1.id AND bc1.deleted = 0
        LEFT JOIN biz_company bc2 ON oi.user_id = bc2.user_id AND bc2.deleted = 0
        LEFT JOIN biz_truck bt ON oi.truck_id = bt.id AND bt.deleted = 0
        LEFT JOIN biz_driver bd ON oi.driver_id = bd.id AND bd.deleted = 0
        WHERE bw.id = #{id} AND bw.deleted = 0
    </select>

</mapper>