<?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.xinelu.applet.mapper.apporderevaluate.AppOrderEvaluateMapper">

    <!--评价-->
    <resultMap type="com.xinelu.applet.dto.apporderevaluate.OrderEvaluateAndPictureDTO"
               id="OrderEvaluateAndPictureDTOResult">
        <result property="orderEvaluateInfoId" column="orderEvaluateInfoId"/>
        <result property="patientId" column="patient_id"/>
        <result property="openid" column="openid"/>
        <result property="unionid" column="unionid"/>
        <result property="orderNo" column="order_no"/>
        <result property="evaluateContent" column="evaluate_content"/>
        <result property="evaluateChannel" column="evaluate_channel"/>
        <result property="evaluateSatisfaction" column="evaluate_satisfaction"/>
        <result property="compositeScore" column="composite_score"/>
        <result property="orderSource" column="order_source"/>
        <result property="createTime" column="create_time"/>
        <result property="patientName" column="patient_name"/>
        <collection property="orderEvaluatePictureInfoList" javaType="java.util.List"
                    resultMap="OrderEvaluatePictureInfoResult"/>
    </resultMap>

    <!--评价图片-->
    <resultMap type="OrderEvaluatePictureInfo" id="OrderEvaluatePictureInfoResult">
        <result property="id" column="id"/>
        <result property="orderEvaluateId" column="order_evaluate_id"/>
        <result property="evaluatePictureUrl" column="evaluate_picture_url"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <insert id="insertOrderEvaluatePictureList">
        insert into order_evaluate_picture_info(
        order_evaluate_id,
        evaluate_picture_url,
        create_time
        ) values
        <foreach item="orderEvaluatePictureList" index="index" collection="orderEvaluatePictureList" separator=",">
            (
            #{orderEvaluatePictureList.orderEvaluateId},
            #{orderEvaluatePictureList.evaluatePictureUrl},
            #{orderEvaluatePictureList.createTime}
            )
        </foreach>
    </insert>

    <select id="selectOrderEvaluateAndPictureByOrderNo" resultMap="OrderEvaluateAndPictureDTOResult">
        SELECT oei.id orderEvaluateInfoId,
               oei.patient_id,
               oei.order_no,
               oei.evaluate_content,
               oei.evaluate_channel,
               oei.evaluate_satisfaction,
               oei.composite_score,
               oei.order_source,
               oei.create_time,
               oepi.evaluate_picture_url,
               oepi.create_time,
               pi.patient_name
        FROM order_evaluate_info oei
                 LEFT JOIN order_evaluate_picture_info oepi ON oepi.order_evaluate_id = oei.id
                 LEFT JOIN patient_info pi ON pi.id = oei.patient_id
        where oei.order_no = #{orderNo}
    </select>

    <select id="selectGoodsOrderByOrderNo" resultType="com.xinelu.manage.domain.goodsOrder.GoodsOrder">
        select order_status,
               order_type
        from goods_order
        where order_no = #{orderNo}
    </select>
</mapper>
