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

    <resultMap type="com.bonus.sharedstation.app.domain.MlMedicalInformation" id="MlMedicalInformationMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="userId" column="user_id" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="unit" column="unit" jdbcType="VARCHAR"/>
        <result property="appointmentTime" column="appointment_time" jdbcType="TIMESTAMP"/>
        <result property="hospitalName" column="hospital_name" jdbcType="VARCHAR"/>
        <result property="officesName" column="offices_name" jdbcType="VARCHAR"/>
        <result property="doctorName" column="doctor_name" jdbcType="VARCHAR"/>
        <result property="surgicalType" column="surgical_type" jdbcType="VARCHAR"/>
        <result property="type" column="type" jdbcType="VARCHAR"/>
        <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
        <result property="orderId" column="order_id" 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="status" column="status" jdbcType="VARCHAR"/>
        <result property="tenantId" column="tenant_id" jdbcType="INTEGER"/>
        <result property="custId" column="cust_id" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="MlMedicalInformationMap">
        select
          id, name, user_id, phone, unit, appointment_time, hospital_name, offices_name,
               doctor_name, surgical_type, type, remarks, created_by, created_time,
               updated_time, updated_by, is_deleted, tenant_id,order_id,status,cust_id
        from yz_ml_medical_information
        where id = #{id}
    </select>

    <insert id="insert"  useGeneratedKeys="true" keyProperty="id">
        INSERT INTO yz_ml_medical_information
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="userId != null">user_id,</if>
            <if test="phone != null and phone != ''">phone,</if>
            <if test="unit != null and unit != ''">unit,</if>
            <if test="appointmentTime != null">appointment_time,</if>
            <if test="hospitalName != null and hospitalName != ''">hospital_name,</if>
            <if test="officesName != null and officesName != ''">offices_name,</if>
            <if test="doctorName != null and doctorName != ''">doctor_name,</if>
            <if test="surgicalType != null and surgicalType != ''">surgical_type,</if>
            <if test="type != null and type != ''">type,</if>
            <if test="remarks != null and remarks != ''">remarks,</if>
            <if test="orderId != null and orderId != ''">order_id,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="isDeleted != null">is_deleted,</if>
            <if test="status != null">status,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="custId != null">cust_id,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="userId != null">#{userId},</if>
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="unit != null and unit != ''">#{unit},</if>
            <if test="appointmentTime != null">#{appointmentTime},</if>
            <if test="hospitalName != null and hospitalName != ''">#{hospitalName},</if>
            <if test="officesName != null and officesName != ''">#{officesName},</if>
            <if test="doctorName != null and doctorName != ''">#{doctorName},</if>
            <if test="surgicalType != null and surgicalType != ''">#{surgicalType},</if>
            <if test="type != null and type != ''">#{type},</if>
            <if test="remarks != null and remarks != ''">#{remarks},</if>
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="isDeleted != null">#{isDeleted},</if>
            <if test="status != null">#{status},</if>
            <if test="tenantId != null">#{tenantId}</if> <!-- 最后一个字段不需要逗号 -->
            <if test="custId != null">#{custId}</if> <!-- 最后一个字段不需要逗号 -->
        </trim>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update yz_ml_medical_information
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="userId != null and userId != ''">
                user_id = #{userId},
            </if>
            <if test="phone != null and phone != ''">
                phone = #{phone},
            </if>
            <if test="unit != null and unit != ''">
                unit = #{unit},
            </if>
            <if test="appointmentTime != null">
                appointment_time = #{appointmentTime},
            </if>
            <if test="hospitalName != null and hospitalName != ''">
                hospital_name = #{hospitalName},
            </if>
            <if test="officesName != null and officesName != ''">
                offices_name = #{officesName},
            </if>
            <if test="doctorName != null and doctorName != ''">
                doctor_name = #{doctorName},
            </if>
            <if test="surgicalType != null and surgicalType != ''">
                surgical_type = #{surgicalType},
            </if>
            <if test="type != null and type != ''">
                type = #{type},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks},
            </if>

            <if test="remarks != null and remarks != ''">
                order_id = #{orderId},
            </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="status != null and status != ''">
                status = #{status},
            </if>
            <if test="tenantId != null">
                tenant_id = #{tenantId},
            </if>
            <if test="custId != null">
                cust_id = #{custId},
            </if>
        </set>
        where id = #{id}
    </update>

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

