<?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.bonus.canteen.core.nutrition.mapper.HealthCustMedicalReportMapper">

    <delete id="deleteCustReport">
        DELETE
        t1.*,
            t2.*
        FROM
            health_cust_medical_report_project t1,
            health_cust_medical_report_detail t2
        WHERE
            t1.medical_id = t2.medical_id
        AND t1.medical_id = #{medicalId}
    </delete>

    <select id="pageMedicalReportInfo" resultType="com.bonus.canteen.core.nutrition.common.vo.HealthCustMedicalReportVO">
        SELECT medical_id,
        user_id,
        medical_date,
        medical_mechanism,
        medical_template_id
        FROM health_cust_medical_report
        WHERE user_id = #{param.userId}
        <if test="param.medicalDate != null">
            AND medical_date = #{param.medicalDate}
        </if>
        ORDER BY medical_date DESC
    </select>

    <select id="listCustReport" resultType="com.bonus.canteen.core.nutrition.common.vo.HealthCustMedicalReportProjectVO">
        SELECT medical_project_id,
               medical_project_name
        FROM health_cust_medical_report_project
        WHERE medical_id = #{medicalId}
        ORDER BY
            medical_project_id
    </select>

    <select id="listMedicalReport" resultType="com.bonus.canteen.core.nutrition.common.vo.HealthCustMedicalReportVO">
        SELECT medical_id,
               user_id,
               medical_date,
               medical_mechanism,
               medical_template_id
        FROM health_cust_medical_report
        WHERE user_id = #{userId}
        ORDER BY medical_date DESC
    </select>

</mapper>
