<?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="closePlanReasonMapper">

    <!-- 插入关闭计划原因 -->
    <insert id="insertCloseplanReason" parameterType="pd">
        insert into s_gxhpz_closeplan_reason
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="reason != null and reason != ''">reason,</if>
            <if test="drugsStatus != null and drugsStatus != ''">drugsStatus,</if>
            <if test="flowNo != null and flowNo != ''">flowNo,</if>
            <if test="otherReason != null and otherReason != ''">otherReason,</if>
            <if test="closePlanScope != null and closePlanScope != ''">closePlanScope,</if>
            <if test="drugsStop != null and drugsStop != ''">drugsStop,</if>
            <if test="specifiedType != null and specifiedType != ''">specifiedType,</if>
            <if test="disableProduct != null and disableProduct != ''">disableProduct,</if>
            <if test="closeType != null and closeType != ''">closeType,</if>
            <if test="planId != null and planId != ''">planId,</if>
            <if test="taskId != null and taskId != ''">taskId,</if>
            <if test="patientId != null and patientId != ''">patientId,</if>
            <if test="closePlanTime != null">closePlanTime,</if>
            <if test="storeId != null and storeId != ''">storeId,</if>
            <if test="operator != null and operator != ''">operator,</if>
            <if test="createdAt != null">created_at,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="reason != null and reason != ''">#{reason},</if>
            <if test="drugsStatus != null and drugsStatus != ''">#{drugsStatus},</if>
            <if test="flowNo != null and flowNo != ''">#{flowNo},</if>
            <if test="otherReason != null and otherReason != ''">#{otherReason},</if>
            <if test="closePlanScope != null and closePlanScope != ''">#{closePlanScope},</if>
            <if test="drugsStop != null and drugsStop != ''">#{drugsStop},</if>
            <if test="specifiedType != null and specifiedType != ''">#{specifiedType},</if>
            <if test="disableProduct != null and disableProduct != ''">#{disableProduct},</if>
            <if test="closeType != null and closeType != ''">#{closeType},</if>
            <if test="planId != null and planId != ''">#{planId},</if>
            <if test="taskId != null and taskId != ''">#{taskId},</if>
            <if test="patientId != null and patientId != ''">#{patientId},</if>
            <if test="closePlanTime != null">#{closePlanTime},</if>
            <if test="storeId != null and storeId != ''">#{storeId},</if>
            <if test="operator != null and operator != ''">#{operator},</if>
            <if test="createdAt != null">#{createdAt},</if>
        </trim>
    </insert>

    <!-- 更新关闭计划原因 -->
    <update id="updateCloseplanReason" parameterType="pd">
        update s_gxhpz_closeplan_reason
        <set>
            <if test="reason != null and reason != ''">reason = #{reason},</if>
            <if test="drugsStatus != null and drugsStatus != ''">drugsStatus = #{drugsStatus},</if>
            <if test="flowNo != null and flowNo != ''">flowNo = #{flowNo},</if>
            <if test="otherReason != null and otherReason != ''">otherReason = #{otherReason},</if>
            <if test="closePlanScope != null and closePlanScope != ''">closePlanScope = #{closePlanScope},</if>
            <if test="drugsStop != null and drugsStop != ''">drugsStop = #{drugsStop},</if>
            <if test="specifiedType != null and specifiedType != ''">specifiedType = #{specifiedType},</if>
            <if test="disableProduct != null and disableProduct != ''">disableProduct = #{disableProduct},</if>
            <if test="closeType != null and closeType != ''">closeType = #{closeType},</if>
            <if test="planId != null and planId != ''">planId = #{planId},</if>
            <if test="taskId != null and taskId != ''">taskId = #{taskId},</if>
            <if test="patientId != null and patientId != ''">patientId = #{patientId},</if>
            <if test="closePlanTime != null">closePlanTime = #{closePlanTime},</if>
            <if test="storeId != null and storeId != ''">storeId = #{storeId},</if>
            <if test="operator != null and operator != ''">operator = #{operator},</if>
        </set>
        where id = #{id}
    </update>

    <!-- 根据ID删除 -->
    <delete id="deleteCloseplanReasonById" parameterType="pd">
        delete from s_gxhpz_closeplan_reason
        where id = #{id}
    </delete>

    <!-- 根据ID查询 -->
    <select id="selectCloseplanReasonById" parameterType="pd" resultType="pd">
        select
            id, reason, drugsStatus, flowNo, otherReason,
            closePlanScope, drugsStop, specifiedType,disableProduct, closeType,
            planId, taskId, patientId, closePlanTime, storeId,
            operator, created_at as createdAt, updated_at as updatedAt
        from s_gxhpz_closeplan_reason
        where id = #{id}
    </select>
</mapper>
