<?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.sharedstation.app.mapper.TherapyAppointmentsMapper">

    <resultMap type="com.bonus.sharedstation.app.domain.TherapyAppointments" id="TherapyAppointmentsMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="therapyProject" column="therapy_project" jdbcType="VARCHAR"/>
        <result property="projectPrice" column="project_price" jdbcType="NUMERIC"/>
        <result property="projectUnit" column="project_unit" jdbcType="VARCHAR"/>
        <result property="appointmentTime" column="appointment_time" jdbcType="VARCHAR"/>
        <result property="appointmentDate" column="appointment_date" jdbcType="TIMESTAMP"/>
        <result property="parkLocation" column="park_location" jdbcType="VARCHAR"/>
        <result property="patientName" column="patient_name" jdbcType="VARCHAR"/>
        <result property="phoneNumber" column="phone_number" jdbcType="VARCHAR"/>
        <result property="appointmentStatus" column="appointment_status" jdbcType="VARCHAR"/>
        <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
        <result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
        <result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
        <result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
        <result property="updatedBy" column="updated_by" jdbcType="VARCHAR"/>
        <result property="isDeleted" column="is_deleted" jdbcType="VARCHAR"/>
        <result property="tenantId" column="tenant_id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="VARCHAR"/>
        <result property="timeSlot" column="time_slot" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="VARCHAR"/>
        <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="TherapyAppointmentsMap">
        select id,
               therapy_project,
               project_price,
               project_unit,
               appointment_time,
               appointment_date,
               park_location,
               patient_name,
               phone_number,
               appointment_status,
               remarks,
               created_by,
               created_time,
               updated_time,
               updated_by,
               is_deleted,
               tenant_id,
               user_id,
               time_slot,order_id,status
        from therapy_appointments
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="TherapyAppointmentsMap">
        select
        id, therapy_project, project_price, project_unit, appointment_time, appointment_date, park_location,
        patient_name, phone_number, appointment_status, remarks, created_by, created_time, updated_time, updated_by,
        is_deleted, tenant_id,user_id,time_slot,order_id,status
        from therapy_appointments
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="therapyProject != null and therapyProject != ''">
                and therapy_project = #{therapyProject}
            </if>
            <if test="projectPrice != null">
                and project_price = #{projectPrice}
            </if>
            <if test="projectUnit != null and projectUnit != ''">
                and project_unit = #{projectUnit}
            </if>
            <if test="appointmentTime != null and appointmentTime != ''">
                and appointment_time = #{appointmentTime}
            </if>
            <if test="appointmentDate != null">
                and appointment_date = #{appointmentDate}
            </if>
            <if test="parkLocation != null and parkLocation != ''">
                and park_location = #{parkLocation}
            </if>
            <if test="patientName != null and patientName != ''">
                and patient_name = #{patientName}
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                and phone_number = #{phoneNumber}
            </if>
            <if test="appointmentStatus != null and appointmentStatus != ''">
                and appointment_status = #{appointmentStatus}
            </if>
            <if test="remarks != null and remarks != ''">
                and remarks = #{remarks}
            </if>
            <if test="createdBy != null and createdBy != ''">
                and created_by = #{createdBy}
            </if>
            <if test="createdTime != null">
                and created_time = #{createdTime}
            </if>
            <if test="updatedTime != null">
                and updated_time = #{updatedTime}
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                and updated_by = #{updatedBy}
            </if>
            <if test="isDeleted != null and isDeleted != ''">
                and is_deleted = #{isDeleted}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="tenantId != null">
                and tenant_id = #{tenantId}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from therapy_appointments
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="therapyProject != null and therapyProject != ''">
                and therapy_project = #{therapyProject}
            </if>
            <if test="projectPrice != null">
                and project_price = #{projectPrice}
            </if>
            <if test="projectUnit != null and projectUnit != ''">
                and project_unit = #{projectUnit}
            </if>
            <if test="appointmentTime != null and appointmentStatus != ''">
                and appointment_time = #{appointmentTime}
            </if>
            <if test="appointmentDate != null">
                and appointment_date = #{appointmentDate}
            </if>
            <if test="parkLocation != null and parkLocation != ''">
                and park_location = #{parkLocation}
            </if>
            <if test="patientName != null and patientName != ''">
                and patient_name = #{patientName}
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                and phone_number = #{phoneNumber}
            </if>
            <if test="appointmentStatus != null and appointmentStatus != ''">
                and appointment_status = #{appointmentStatus}
            </if>
            <if test="remarks != null and remarks != ''">
                and remarks = #{remarks}
            </if>
            <if test="createdBy != null and createdBy != ''">
                and created_by = #{createdBy}
            </if>
            <if test="createdTime != null">
                and created_time = #{createdTime}
            </if>
            <if test="updatedTime != null">
                and updated_time = #{updatedTime}
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                and updated_by = #{updatedBy}
            </if>
            <if test="isDeleted != null and isDeleted != ''">
                and is_deleted = #{isDeleted}
            </if>
            <if test="tenantId != null">
                and tenant_id = #{tenantId}
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into therapy_appointments(therapy_project, project_price, project_unit, appointment_time,
                                         appointment_date, park_location, patient_name, phone_number,
                                         appointment_status, remarks, created_by, created_time, updated_time,
                                         updated_by, is_deleted, tenant_id,user_id,time_slot,status,order_id)
        values (#{therapyProject}, #{projectPrice}, #{projectUnit}, #{appointmentTime}, #{appointmentDate},
                #{parkLocation}, #{patientName}, #{phoneNumber}, #{appointmentStatus}, #{remarks}, #{createdBy},
                #{createdTime}, #{updatedTime}, #{updatedBy}, #{isDeleted}, #{tenantId},#{userId},#{timeSlot},#{status},#{orderId})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into therapy_appointments(therapy_project, project_price, project_unit, appointment_time,
        appointment_date, park_location, patient_name, phone_number, appointment_status, remarks, created_by,
        created_time, updated_time, updated_by, is_deleted, tenant_id,user_id,time_slot,status,order_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.therapyProject}, #{entity.projectPrice}, #{entity.projectUnit}, #{entity.appointmentTime},
            #{entity.appointmentDate}, #{entity.parkLocation}, #{entity.patientName}, #{entity.phoneNumber},
            #{entity.appointmentStatus}, #{entity.remarks}, #{entity.createdBy}, #{entity.createdTime},
            #{entity.updatedTime}, #{entity.updatedBy}, #{entity.isDeleted}, #{entity.tenantId},#{entities.userId},#{entities.status},#{entities.orderId})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into therapy_appointments(therapy_project, project_price, project_unit, appointment_time,
        appointment_date, park_location, patient_name, phone_number, appointment_status, remarks, created_by,
        created_time, updated_time, updated_by, is_deleted, tenant_id,user_id,time_slot,status,order_id)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.therapyProject}, #{entity.projectPrice}, #{entity.projectUnit}, #{entity.appointmentTime},
            #{entity.appointmentDate}, #{entity.parkLocation}, #{entity.patientName}, #{entity.phoneNumber},
            #{entity.appointmentStatus}, #{entity.remarks}, #{entity.createdBy}, #{entity.createdTime},
            #{entity.updatedTime}, #{entity.updatedBy}, #{entity.isDeleted}, #{entity.tenantId},#{entity.userId},#{entity.timeSlot},#{entity.status},#{entity.orderId})
        </foreach>
        on duplicate key update
        therapy_project = values(therapy_project),
        project_price = values(project_price),
        project_unit = values(project_unit),
        appointment_time = values(appointment_time),
        appointment_date = values(appointment_date),
        park_location = values(park_location),
        patient_name = values(patient_name),
        phone_number = values(phone_number),
        appointment_status = values(appointment_status),
        remarks = values(remarks),
        created_by = values(created_by),
        created_time = values(created_time),
        updated_time = values(updated_time),
        updated_by = values(updated_by),
        is_deleted = values(is_deleted),
        tenant_id = values(tenant_id),
        user_id = values(user_id)
        time_slot = values(time_slot)
        status = values(status)
        order_id = values(order_id)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update therapy_appointments
        <set>
            <if test="therapyProject != null and therapyProject != ''">
                therapy_project = #{therapyProject},
            </if>
            <if test="projectPrice != null">
                project_price = #{projectPrice},
            </if>
            <if test="projectUnit != null and projectUnit != ''">
                project_unit = #{projectUnit},
            </if>
            <if test="appointmentTime != null and appointmentStatus != ''">
                appointment_time = #{appointmentTime},
            </if>
            <if test="appointmentDate != null">
                appointment_date = #{appointmentDate},
            </if>
            <if test="parkLocation != null and parkLocation != ''">
                park_location = #{parkLocation},
            </if>
            <if test="patientName != null and patientName != ''">
                patient_name = #{patientName},
            </if>
            <if test="phoneNumber != null and phoneNumber != ''">
                phone_number = #{phoneNumber},
            </if>
            <if test="appointmentStatus != null and appointmentStatus != ''">
                appointment_status = #{appointmentStatus},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks},
            </if>
            <if test="createdBy != null and createdBy != ''">
                created_by = #{createdBy},
            </if>
            <if test="createdTime != null">
                created_time = #{createdTime},
            </if>
            <if test="updatedTime != null">
                updated_time = #{updatedTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updated_by = #{updatedBy},
            </if>
            <if test="isDeleted != null and isDeleted != ''">
                is_deleted = #{isDeleted},
            </if>
            <if test="tenantId != null">
                tenant_id = #{tenantId},
            </if>
            <if test="userId != null and userId != ''">
                and user_id = #{userId}
            </if>
            <if test="timeSlot != null and timeSlot != ''">
                and time_slot = #{timeSlot}
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
            <if test="orderId != null and orderId != ''">
                and order_id = #{orderId}
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete
        from therapy_appointments
        where id = #{id}
    </delete>

</mapper>

