<?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.pz.system.mapper.DbghOrderMapper">

    <resultMap type="com.pz.system.domain.DbghOrder" id="DbghOrderResult">
        <result property="id" column="id"/>
        <result property="orderId" column="order_id"/>
        <result property="hid" column="hid"/>
        <result property="visitor" column="visitor"/>
        <result property="visitTime" column="visit_time"/>
        <result property="did" column="did"/>
        <result property="status" column="status"/>
        <result property="overTime" column="over_time"/>
        <result property="voucher" column="voucher"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <select id="findDbghOrderVoPage" resultType="com.pz.system.domain.vo.DbghOrderVo">
        SELECT
        tlo.order_sn AS orderSn,
        tlo.pay_money AS PayMoney,
        s.`name` AS serviceName,
        c.`name` AS cityName,
        h.`name` AS hName,
        d.title AS title,
        e.`name` AS eName,
        tlo.remark AS remark,
        yyod.visit_time AS visitTime,
        yyod.`status` AS yStatus,
        tlo.`status` AS tStatus,
        tlo.is_satisfaction AS isSatisfaction,
        tlo.evaluation_content AS evaluationContent,
        yyod.over_time AS overtime,
        yyod.voucher AS voucher,
        yyod.create_time as createTime
        FROM dbgh_order AS yyod
        LEFT JOIN total_order AS tlo ON yyod.order_id = tlo.id
        LEFT JOIN city AS c ON c.id = tlo.city_id
        LEFT JOIN hospital AS h ON h.id = yyod.hid
        LEFT JOIN department AS d ON d.id = yyod.did
        LEFT JOIN services AS s ON s.id = tlo.service_id
        LEFT JOIN employees AS e ON e.id = tlo.em_id
        <if test="bo.orderSn != null and bo.orderSn != ''">
            where tlo.order_sn LIKE CONCAT('%', #{bo.orderSn}, '%')
        </if>
    </select>

    <select id="selectSonOrderInfoByTotalId" resultType="com.pz.merchant.domain.vo.SonOrderVo">
        select vsitor.name       as userName,
               dbgh_order.status as orderStatus,
               sys_user.avatar,
               hospital.name     as hospital,
               dbgh_order.visit_time
        from dbgh_order
                 left join user_vsitor as vsitor on vsitor.id = dbgh_order.visitor
                 left join sys_user on sys_user.user_id = vsitor.uid
                 left join hospital on hospital.id = dbgh_order.hid
        where dbgh_order.order_id = #{id}
    </select>

    <select id="selectDbghOrderDetailDateByTotalId" resultType="com.pz.system.domain.vo.DbghOrderItemVo">
        select total_order.id                          as orderId,
               dbgh_order.id                           as serviceOrderId,
               total_order.business_id,
               total_order.status                      as orderStatus,
               dbgh_order.status                       as serviceStatus,
               services.name                           as project,
               business.name                           as businessName,
               CONVERT((1 - services.fenmo / 100), decimal(10, 2)) *
               CONVERT(services.price, decimal(10, 2)) as commission,
               user_vsitor.name                        as userName,
               hospital.name                           as hospital,
               department.title                        as department,
               dbgh_order.visit_time,
               total_order.remark                      as description,
               dbgh_order.remark,
               total_order.evaluation_content,
               total_order.is_satisfaction             as evaluation_flag,
               dbgh_order.voucher,
               total_order.uid                         as userId,
               employees.uid                           as euserId
        from total_order
                 left join business on total_order.business_id = business.id
                 left join employees on employees.id = total_order.em_id
                 left join dbgh_order on dbgh_order.order_id = total_order.id
                 left join services on total_order.service_id = services.id
                 left join user_vsitor on user_vsitor.id = dbgh_order.visitor
                 left join hospital on dbgh_order.hid = hospital.id
                 left join department on department.id = dbgh_order.did
        where total_order.id = #{id}
    </select>
    <select id="selectFinishTime" resultType="java.lang.String">
        select visit_time
            from total_order t left join dbgh_order d on d.order_id = t.id
        where  t.id = #{id}
    </select>


</mapper>