<?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="DTPMapper">
<!--处方登记信息查询 -->
    <select id="RecipeRegisterList" parameterType="pd" resultType="pd">
        select * from s_dtp_cfdj_prescription
        <where>
            <if test="id != null and id!=''">AND id = #{id}</if>
            <if test="orderId != null and orderId!=''">AND orderId = #{orderId}</if>
            <if test="saleOrderNumber != null and saleOrderNumber!=''">AND saleOrderNumber = #{saleOrderNumber}</if>
            <if test="genericName != null and genericName!=''">AND genericName = #{genericName}</if>
            <if test="productName != null and productName!=''">AND productName = #{productName}</if>
            <if test="specification != null and specification!=''">AND specification = #{specification}</if>
            <if test="quantity != null and quantity!=''">AND quantity = #{quantity}</if>
            <if test="manufacturer != null and manufacturer!=''">AND manufacturer = #{manufacturer}</if>
            <if test="mdmCode != null and mdmCode!=''">AND mdmCode = #{mdmCode}</if>
            <if test="posMemberName != null and posMemberName!=''">AND posMemberName = #{posMemberName}</if>
            <if test="posMemberPhone != null and posMemberPhone!=''">AND posMemberPhone = #{posMemberPhone}</if>
            <if test="prescriptionType != null and prescriptionType!=''">AND prescriptionType=#{prescriptionType}</if>
            <if test="beginTime != null and beginTime!='' and endTime != null and endTime!=''">
                and createTime between #{beginTime} and #{endTime}
            </if>
            <if test="orderTime != null and orderTime!=''">AND orderTime= #{orderTime}</if>
            <if test="saleOrderTime != null and saleOrderTime!=''">AND saleOrderTime= #{saleOrderTime}</if>
            <if test="prescriptionNumber != null and prescriptionNumber!=''">AND prescriptionNumber = #{prescriptionNumber}</if>
            <if test="hospital != null and hospital!=''">AND hospital = #{hospital}</if>
            <if test="department != null and department!=''">AND department = #{department}</if>
            <if test="doctor != null and doctor!=''">AND doctor = #{doctor}</if>
            <if test="query != null and query != ''">
                AND (patientName LIKE CONCAT('%', #{query}, '%')
                OR patientPhone = #{query})
            </if>
            <if test="storeName != null and storeName!=''">AND storeName = #{storeName}</if>
            <if test="registrar != null and registrar!=''">AND registrar = #{registrar}</if>
            <if test="completionTime != null and completionTime != ''">AND completionTime = #{completionTime}</if>
            <if test="deliveryMethod != null and deliveryMethod!=''">AND deliveryMethod=#{deliveryMethod}</if>
            <if test="paymentCode != null and paymentCode!=''">AND paymentCode = #{paymentCode}</if>
            <if test="paymentMethod != null and paymentMethod!=''">AND paymentMethod = #{paymentMethod}</if>
            <if test="status != null  and status!=''">AND status = #{status}</if>
            <if test="isFlipItem != null  and isFlipItem!=''">AND isFlipItem = #{isFlipItem}</if>
            <if test="createTime != null and createTime!=''">AND createTime = #{createTime}</if>

            and del_flag = '0'
        </where>
        order by createTime desc
    </select>

    <insert id="insertRecipe" parameterType="pd">
        insert into s_dtp_cfdj_prescription
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="id != null and id != ''">id,</if>
            <if test="orderId != null and orderId != ''">orderId,</if>
            <if test="prescriptionDate != null and prescriptionDate != ''">prescriptionDate,</if>
            <if test="saleOrderNumber != null and saleOrderNumber != ''">saleOrderNumber,</if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">prescriptionNumber,</if>
            <if test="prescription_drug_id != null and prescription_drug_id != ''">prescription_drug_id,</if>
            <if test="prescriptionDrug != null and prescriptionDrug != ''">prescriptionDrug,</if>
            <if test="dosage != null and dosage != ''">dosage,</if>
            <if test="drugRoute != null and drugRoute != ''">drugRoute,</if>
            <if test="medicationCycle != null and medicationCycle != ''">medicationCycle,</if>
            <if test="singleDose != null and singleDose != ''">singleDose,</if>
            <if test="diseaseType != null and diseaseType != ''">diseaseType,</if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">clinicalDiagnosis,</if>
            <if test="prescriptionImg != null and prescriptionImg != ''">prescriptionImg,</if>
            <if test="prescriptionSource != null and prescriptionSource != ''">prescriptionSource,</if>
            <if test="genericName != null and genericName != ''">genericName,</if>
            <if test="specification != null and specification != ''">specification,</if>
            <if test="quantity != null and quantity != ''">quantity,</if>
            <if test="frequency != null and frequency != ''">frequency,</if>
            <if test="usage != null and usage != ''">usage,</if>
            <if test="wordUsage != null and wordUsage != ''">wordUsage,</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
            <if test="createTime != null and createTime != ''">createTime,</if>
            <if test="saleOrderTime != null and saleOrderTime != ''">saleOrderTime,</if>
            <if test="orderTime != null and orderTime != ''">orderTime,</if>
            <if test="hospital != null and hospital != ''">hospital,</if>
            <if test="department != null and department != ''">department,</if>
            <if test="doctor != null and doctor != ''">doctor,</if>
            <if test="patientName != null and patientName != ''">patientName,</if>
            <if test="patientPhone != null and patientPhone != ''">patientPhone,</if>
            <if test="storeName != null and storeName != ''">storeName,</if>
            <if test="isFlipItem != null and isFlipItem != ''">isFlipItem,</if>
            <if test="noFlipCause != null and noFlipCause !=''">noFlipCause,</if>
            <if test="registrar != null and registrar != ''">registrar,</if>
            <if test="completionTime != null and completionTime != ''">completionTime,</if>
            <if test="lastUpdated != null and lastUpdated != ''">lastUpdated,</if>
            <if test="deliveryMethod != null and deliveryMethod != ''">deliveryMethod,</if>
            <if test="paymentCode != null and paymentCode != ''">paymentCode,</if>
            <if test="paymentMethod != null and paymentMethod != ''">paymentMethod,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="del_flag != null and del_flag != ''">del_flag,</if>
            <if test="posMemberName != null and posMemberName != ''">posMemberName,</if>
            <if test="productName != null and productName != ''">productName,</if>
            <if test="mdmCode != null and mdmCode != ''">mdmCode,</if>
            <if test="posMemberPhone != null and posMemberPhone != ''">posMemberPhone,</if>
            <if test="prescriptionType != null and prescriptionType !=''">prescriptionType,</if>
        </trim>
        <trim prefix=" VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="id != null and id != ''">#{id},</if>
            <if test="orderId != null and orderId != ''">#{orderId},</if>
            <if test="prescriptionDate != null and prescriptionDate != ''">#{prescriptionDate},</if>
            <if test="saleOrderNumber != null and saleOrderNumber != ''">#{saleOrderNumber},</if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">#{prescriptionNumber},</if>
            <if test="prescription_drug_id != null and prescription_drug_id !=''">#{prescription_drug_id},</if>
            <if test="prescriptionDrug != null and prescriptionDrug != ''">#{prescriptionDrug},</if>
            <if test="dosage != null and dosage !=''">#{dosage},</if>
            <if test="drugRoute != null and drugRoute != ''">#{drugRoute},</if>
            <if test="medicationCycle != null and medicationCycle != ''">#{medicationCycle},</if>
            <if test="singleDose != null and singleDose != ''">#{singleDose},</if>
            <if test="diseaseType != null and diseaseType != ''">#{diseaseType},</if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">#{clinicalDiagnosis},</if>
            <if test="prescriptionImg != null and prescriptionImg != ''">#{prescriptionImg},</if>
            <if test="prescriptionSource != null and prescriptionSource != ''">#{prescriptionSource},</if>
            <if test="genericName != null and genericName != ''">#{genericName},</if>
            <if test="specification != null and specification != ''">#{specification},</if>
            <if test="quantity != null and quantity != ''">#{quantity},</if>
            <if test="frequency != null and frequency != ''">#{frequency},</if>
            <if test="usage != null and usage != ''">#{usage},</if>
            <if test="wordUsage != null and wordUsage != ''">#{wordUsage},</if>
            <if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if>
            <if test="createTime != null and createTime != ''">#{createTime},</if>
            <if test="saleOrderTime != null and saleOrderTime != ''">#{saleOrderTime},</if>
            <if test="orderTime != null and orderTime != ''">#{orderTime},</if>
            <if test="hospital != null and hospital != ''">#{hospital},</if>
            <if test="department != null and department != ''">#{department},</if>
            <if test="doctor != null and doctor != ''">#{doctor},</if>
            <if test="patientName != null and patientName != ''">#{patientName},</if>
            <if test="patientPhone != null and patientPhone != ''">#{patientPhone},</if>
            <if test="storeName != null and storeName != ''">#{storeName},</if>
            <if test="isFlipItem != null and isFlipItem != ''">#{isFlipItem},</if>
            <if test="noFlipCause != null and noFlipCause !=''">#{noFlipCause},</if>
            <if test="registrar != null and registrar != ''">#{registrar},</if>
            <if test="completionTime != null and completionTime != ''">#{completionTime},</if>
            <if test="lastUpdated != null and lastUpdated != ''">#{lastUpdated},</if>
            <if test="deliveryMethod != null and deliveryMethod != ''">#{deliveryMethod},</if>
            <if test="paymentCode != null and paymentCode != ''">#{paymentCode},</if>
            <if test="paymentMethod != null and paymentMethod != ''">#{paymentMethod},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="del_flag != null and del_flag != ''">#{del_flag},</if>
            <if test="posMemberName != null and posMemberName != ''">#{posMemberName},</if>
            <if test="productName != null and productName != ''">#{productName},</if>
            <if test="mdmCode != null and mdmCode != ''">#{mdmCode},</if>
            <if test="posMemberPhone != null and posMemberPhone != ''">#{posMemberPhone},</if>
            <if test="prescriptionType != null and prescriptionType != ''">#{prescriptionType}</if>
        </trim>
    </insert>

    <delete id="deleteRecipeReg" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_dtp_prescription_registration
            where id in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>
    <delete id="deleteRecipe" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_dtp_drug_purchase_record
            where prescriptionNumber in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>
    <update id="BangdingRecipe" parameterType="pd">
    update s_dtp_cfdj_prescription
        <set>
            <if test="name != null and name != ''">patientName = #{name},</if>
            <if test="phoneNumber != null and phoneNumber != ''">patientPhone = #{phoneNumber}</if>
        </set>
        where id = #{prescriptionId}
    </update>
    <update id="updateRecipe" parameterType="pd">
        update s_dtp_cfdj_prescription
        <set>
            <if test="orderId != null and orderId != ''">orderId = #{orderId},</if>
            <if test="prescriptionDate != null and prescriptionDate != ''">prescriptionDate = #{prescriptionDate},</if>
            <if test="saleOrderNumber != null and saleOrderNumber != ''">saleOrderNumber = #{saleOrderNumber},</if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">prescriptionNumber = #{prescriptionNumber},</if>
            <if test="prescription_drug_id != null and prescription_drug_id != ''">prescription_drug_id = #{prescription_drug_id},</if>
            <if test="prescriptionDrug != null and prescriptionDrug != ''">prescriptionDrug = #{prescriptionDrug},</if>
            <if test="dosage != null and dosage != ''">dosage = #{dosage},</if>
            <if test="drugRoute != null and drugRoute != ''">drugRoute = #{drugRoute},</if>
            <if test="medicationCycle != null and medicationCycle != ''">medicationCycle = #{medicationCycle},</if>
            <if test="singleDose != null and singleDose != ''">singleDose = #{singleDose},</if>
            <if test="diseaseType != null and diseaseType != ''">diseaseType = #{diseaseType},</if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">clinicalDiagnosis = #{clinicalDiagnosis},</if>
            <if test="prescriptionImg != null and prescriptionImg != ''">prescriptionImg = #{prescriptionImg},</if>
            <if test="prescriptionSource != null and prescriptionSource != ''">prescriptionSource = #{prescriptionSource},</if>
            <if test="genericName != null and genericName != ''">genericName = #{genericName},</if>
            <if test="specification != null and specification != ''">specification = #{specification},</if>
            <if test="quantity != null and quantity != ''">quantity = #{quantity},</if>
            <if test="frequency != null and frequency != ''">frequency = #{frequency},</if>
            <if test="usage != null and usage != ''">usage = #{usage},</if>
            <if test="wordUsage != null and wordUsage != ''">wordUsage = #{wordUsage},</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer = #{manufacturer},</if>
            <if test="createTime != null and createTime != ''">createTime = #{createTime},</if>
            <if test="saleOrderTime != null and saleOrderTime != ''">saleOrderTime = #{saleOrderTime},</if>
            <if test="orderTime != null and orderTime != ''">orderTime = #{orderTime},</if>
            <if test="hospital != null and hospital != ''">hospital = #{hospital},</if>
            <if test="department != null and department != ''">department = #{department},</if>
            <if test="doctor != null and doctor != ''">doctor = #{doctor},</if>
            <if test="patientName != null and patientName != ''">patientName = #{patientName},</if>
            <if test="patientPhone != null and patientPhone != ''">patientPhone = #{patientPhone},</if>
            <if test="storeName != null and storeName != ''">storeName = #{storeName},</if>
            <if test="isFlipItem != null and isFlipItem != ''">isFlipItem = #{isFlipItem},</if>
            <if test="noFlipCause != null and noFlipCause != ''">noFlipCause = #{noFlipCause},</if>
            <if test="registrar != null and registrar != ''">registrar = #{registrar},</if>
            <if test="completionTime != null and completionTime != ''">completionTime = #{completionTime},</if>
            <if test="lastUpdated != null and lastUpdated != ''">lastUpdated = #{lastUpdated},</if>
            <if test="deliveryMethod != null and deliveryMethod != ''">deliveryMethod = #{deliveryMethod},</if>
            <if test="paymentCode != null and paymentCode != ''">paymentCode = #{paymentCode},</if>
            <if test="paymentMethod != null and paymentMethod != ''">paymentMethod = #{paymentMethod},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="del_flag != null and del_flag != ''">del_flag = #{del_flag},</if>
            <if test="posMemberName != null and posMemberName != ''">posMemberName = #{posMemberName},</if>
            <if test="productName != null and productName != ''">productName = #{productName},</if>
            <if test="mdmCode != null and mdmCode != ''">mdmCode = #{mdmCode},</if>
            <if test="posMemberPhone != null and posMemberPhone != ''">posMemberPhone = #{posMemberPhone},</if>
            <if test="prescriptionType != null and prescriptionType != ''">prescriptionType = #{prescriptionType},</if>
            <if test="storeId != null and storeId != ''">storeId = #{storeId},</if>
        </set>
        where id = #{id}
    </update>

    <select id="checkPatientNameAndPhoneUnique" parameterType="pd" resultType="pd">
        select name, phoneNumber from s_dtp_ysfw_archive_management where name=#{name} and phoneNumber=#{phoneNumber} and del_flag = '0' limit 1
    </select>
    <select id="checkPatientNameAndIdCardUnique" parameterType="pd" resultType="pd">
        select documentNumber, name from s_dtp_ysfw_archive_management where documentNumber=#{documentNumber} and name=#{name} and del_flag = '0' limit 1
    </select>
    <select id="selectOne" parameterType="pd" resultType="pd">
        select * from s_dtp_cfdj_prescription where id=#{id}
    </select>


    <!--冷链配送管理 -->
    <select id="DistributionOrderList" parameterType="pd" resultType="pd">
        select *
        from s_dtp_llps_distribution_order
        <where>
            <if test="id != null">AND id = #{id}</if>
            <if test="orderNumber != null and orderNumber!=''">AND orderNumber = #{orderNumber}</if>
            <if test="chainName != null and chainName!=''">AND chainName = #{chainName}</if>
            <if test="storeName != null and storeName!=''">AND storeName = #{storeName}</if>
            <if test="deliveryStatus != null and deliveryStatus!=''">AND deliveryStatus = #{deliveryStatus}</if>
            <if test="recipientName != null and recipientName!=''">AND recipientName = #{recipientName}</if>
            <if test="recipientPhone != null and recipientPhone!=''">AND recipientPhone = #{recipientPhone}</if>
            <if test="recipientAddress != null and recipientAddress!=''">AND recipientAddress = #{recipientAddress}</if>
            <if test="deliveryPerson != null and deliveryPerson!=''">AND deliveryPerson = #{deliveryPerson}</if>
            <if test="expectedDeliveryTime != null and expectedDeliveryTime!=''">AND expectedDeliveryTime = #{expectedDeliveryTime}</if>
            <if test="actualDeliveryTimeStart != null and actualDeliveryTimeStart!='' and actualDeliveryTimeEnd != null and actualDeliveryTimeEnd!=''">
                and actualDeliveryTime between #{actualDeliveryTimeStart} and #{actualDeliveryTimeEnd}
            </if>
            <if test="creationTimeStart != null and creationTimeStart!='' and  creationTimeEnd != null and creationTimeEnd!=''">
                and creationTime between #{creationTimeStart} and #{creationTimeEnd}
            </if>
            <if test="updatedTime != null and updatedTime!=''">AND updatedTime = #{updatedTime}</if>
            <if test="createdBy != null and createdBy!=''">AND createdBy = #{createdBy}</if>
            <if test="createdDate != null and createdDate!=''">AND createdDate = #{createdDate}</if>
            <if test="query != null and query!=''">
                AND recipientName LIKE CONCAT('%', #{query}, '%') or recipientPhone = #{query}
            </if>
             and del_flag= '0'
        </where>
        order by create_time desc
    </select>

    <insert id="insertDistributionOrder" parameterType="pd">
        insert into s_dtp_llps_distribution_order
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="orderNumber != null and orderNumber!=''">orderNumber,</if>
            <if test="chainName != null and chainName!=''">chainName,</if>
            <if test="storeName != null and storeName!=''">storeName,</if>
            <if test="deliveryStatus != null and deliveryStatus!=''">deliveryStatus,</if>
            <if test="recipientName != null and recipientName!=''">recipientName,</if>
            <if test="recipientPhone != null and recipientPhone!=''">recipientPhone,</if>
            <if test="recipientAddress != null and recipientAddress!=''">recipientAddress,</if>
            <if test="deliveryPerson != null and deliveryPerson!=''">deliveryPerson,</if>
            <if test="expectedDeliveryTime != null and expectedDeliveryTime!=''">expectedDeliveryTime,</if>
            <if test="actualDeliveryTime != null and actualDeliveryTime!=''">actualDeliveryTime,</if>
            <if test="createdBy != null and createdBy!=''">createdBy,</if>
            <if test="createdDate != null and createdDate!=''">createdDate,</if>
            <if test="creationTime != null and creationTime!=''">creationTime,</if>
            <if test="updatedTime != null and updatedTime!=''">updatedTime,</if>
            <if test="createTime != null and createTime!=''">create_time,</if>
            <if test="coldChainType != null and coldChainType != ''">coldChainType ,</if>
            <if test="orderSource != null and orderSource != ''">orderSource,</if>
            <if test="departureTemperature != null">departureTemperature,</if>
            <if test="arrivalTemperature != null">arrivalTemperature,</if>
            <if test="signaturePhoto != null and signaturePhoto != ''">signaturePhoto,</if>
            <if test="isOnlineSignature != null">isOnlineSignature ,</if>
            <if test="deliveryBoxNumber != null and deliveryBoxNumber != ''">deliveryBoxNumber ,</if>
            <if test="icePackNumber != null and icePackNumber != ''">icePackNumber,</if>
            <if test="paymentSequence != null">paymentSequence,</if>
        </trim>
        <trim prefix=" VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="orderNumber != null and orderNumber!=''">#{orderNumber},</if>
            <if test="chainName != null and chainName!=''">#{chainName},</if>
            <if test="storeName != null and storeName!=''">#{storeName},</if>
            <if test="deliveryStatus != null and deliveryStatus!=''">#{deliveryStatus},</if>
            <if test="recipientName != null and recipientName!=''">#{recipientName},</if>
            <if test="recipientPhone != null and recipientPhone!=''">#{recipientPhone},</if>
            <if test="recipientAddress != null and recipientAddress!=''">#{recipientAddress},</if>
            <if test="deliveryPerson != null and deliveryPerson!=''">#{deliveryPerson},</if>
            <if test="expectedDeliveryTime != null and expectedDeliveryTime!=''">#{expectedDeliveryTime},</if>
            <if test="actualDeliveryTime != null and actualDeliveryTime!=''">#{actualDeliveryTime},</if>
            <if test="createdBy != null and createdBy!=''">#{createdBy},</if>
            <if test="createdDate != null and createdDate!=''">#{createdDate},</if>
            <if test="creationTime != null and creationTime!=''">#{creationTime},</if>
            <if test="updatedTime != null and updatedTime!=''">#{updatedTime},</if>
            <if test="createTime != null and createTime!=''">#{createTime},</if>
            <if test="coldChainType != null and coldChainType != ''">#{coldChainType} ,</if>
            <if test="orderSource != null and orderSource != ''">#{orderSource},</if>
            <if test="departureTemperature != null">#{departureTemperature},</if>
            <if test="arrivalTemperature != null">#{arrivalTemperature},</if>
            <if test="signaturePhoto != null and signaturePhoto != ''">#{signaturePhoto},</if>
            <if test="isOnlineSignature != null">#{isOnlineSignature} ,</if>
            <if test="deliveryBoxNumber != null and deliveryBoxNumber != ''">#{deliveryBoxNumber} ,</if>
            <if test="icePackNumber != null and icePackNumber != ''">#{icePackNumber},</if>
            <if test="paymentSequence != null">#{paymentSequence},</if>
        </trim>
    </insert>

    <update id="updateDistributionOrder" parameterType="pd">
        update s_dtp_llps_distribution_order
        <set>
            <if test="orderNumber != null and orderNumber != ''">orderNumber = #{orderNumber},</if>
            <if test="chainName != null and chainName != ''">chainName = #{chainName},</if>
            <if test="storeName != null and storeName != ''">storeName = #{storeName},</if>
            <if test="deliveryStatus != null">deliveryStatus = #{deliveryStatus},</if>
            <if test="recipientName != null and recipientName != ''">recipientName = #{recipientName},</if>
            <if test="recipientPhone != null and recipientPhone != ''">recipientPhone = #{recipientPhone},</if>
            <if test="recipientAddress != null and recipientAddress != ''">recipientAddress = #{recipientAddress},</if>
            <if test="deliveryPerson != null and deliveryPerson != ''">deliveryPerson = #{deliveryPerson},</if>
            <if test="expectedDeliveryTime != null">expectedDeliveryTime = #{expectedDeliveryTime},</if>
            <if test="actualDeliveryTime != null">actualDeliveryTime = #{actualDeliveryTime},</if>
            <if test="createdBy != null and createdBy != ''">createdBy = #{createdBy},</if>
            <if test="createdDate != null">createdDate = #{createdDate},</if>
            <if test="creationTime != null">creationTime = #{creationTime},</if>
            <if test="updatedTime != null">updatedTime = #{updatedTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="coldChainType != null and coldChainType != ''">coldChainType = #{coldChainType},</if>
            <if test="orderSource != null and orderSource != ''">orderSource = #{orderSource},</if>
            <if test="departureTemperature != null">departureTemperature = #{departureTemperature},</if>
            <if test="arrivalTemperature != null">arrivalTemperature = #{arrivalTemperature},</if>
            <if test="signaturePhoto != null and signaturePhoto != ''">signaturePhoto = #{signaturePhoto},</if>
            <if test="isOnlineSignature != null">isOnlineSignature = #{isOnlineSignature},</if>
            <if test="deliveryBoxNumber != null and deliveryBoxNumber != ''">deliveryBoxNumber = #{deliveryBoxNumber},</if>
            <if test="icePackNumber != null and icePackNumber != ''">icePackNumber = #{icePackNumber},</if>
            <if test="paymentSequence != null">paymentSequence = #{paymentSequence},</if>
        </set>
        where id = #{id}
    </update>



    <update id="softDeleteColdOrder" parameterType="pd">
            update s_dtp_llps_distribution_order
            set del_flag = 1
            where
            <if test="ids != null and ids!=''">
                id in(${ids})
            </if>
    </update>
<!--配送单据打印模块-->
    <select id="listPrintEntity" parameterType="pd" resultType="com.bzd.common.core.domain.entity.DtpDeliveryPrint">
        select id,
        businessId,
        orderId,
        storeId,
        status,
        deliverer,
        deliveryTime,
        printRequestTime,
        createdBy,
        orderData,
        del_flag as delFlag,
        gmtCreate,
        updateBy updatedTime,
        create_time as createTime
        from s_dtp_llps_distribution_print
        <where>
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="businessId != null and businessId != ''">and businessId = #{businessId}</if>
            <if test="orderId != null and orderId != ''">and orderId = #{orderId}</if>
            <if test="storeId != null and storeId != ''">and storeId = #{storeId}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="deliverer != null and deliverer != ''">and deliverer = #{deliverer}</if>
            <if test="deliveryTimeStart != null and deliveryTimeStart!='' and deliveryTimeEnd != null and deliveryTimeEnd!=''">
                and deliveryTime between #{deliveryTimeStart} and #{deliveryTimeEnd}
            </if>
            <if test="printRequestTimeStart != null and printRequestTimeStart!='' and  printRequestTimeEnd != null and printRequestTimeEnd!=''">
                and printRequestTime between #{printRequestTimeStart} and #{printRequestTimeEnd}
            </if>
            <if test="createdBy != null and createdBy != ''">and createdBy = #{createdBy}</if>
            <if test="createBy != null and createBy != ''">and createBy = #{createBy}</if>
            <if test="updateBy != null and updateBy != ''">and updateBy = #{updateBy}</if>
            and del_flag = '0'
        </where>
        order by create_time desc
    </select>
    <select id="listPrintPd" parameterType="pd" resultType="pd">
        select id,
        businessId,
        orderId,
        storeId,
        status,
        deliverer,
        deliveryTime,
        printRequestTime,
        createdBy,
        orderData,
        del_flag as delFlag,
        gmtCreate,
        updateBy updatedTime,
        create_time as createTime
        from s_dtp_llps_distribution_print
        <where>
            <if test="id != null and id != ''">and id = #{id}</if>
            <if test="businessId != null and businessId != ''">and businessId = #{businessId}</if>
            <if test="orderId != null and orderId != ''">and orderId = #{orderId}</if>
            <if test="storeId != null and storeId != ''">and storeId = #{storeId}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="deliverer != null and deliverer != ''">and deliverer = #{deliverer}</if>
            <if test="deliveryTimeStart != null and deliveryTimeStart!='' and deliveryTimeEnd != null and deliveryTimeEnd!=''">
                and deliveryTime between #{deliveryTimeStart} and #{deliveryTimeEnd}
            </if>
            <if test="printRequestTimeStart != null and printRequestTimeStart!='' and  printRequestTimeEnd != null and printRequestTimeEnd!=''">
                and printRequestTime between #{printRequestTimeStart} and #{printRequestTimeEnd}
            </if>
            <if test="createdBy != null and createdBy != ''">and createdBy = #{createdBy}</if>
            <if test="createBy != null and createBy != ''">and createBy = #{createBy}</if>
            <if test="updateBy != null and updateBy != ''">and updateBy = #{updateBy}</if>
            and del_flag = '0'
        </where>
        order by create_time desc
    </select>

    <insert id="savePrint" parameterType="pd">
        insert into s_dtp_llps_distribution_print
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="createdBy != null and createdBy != ''">createdBy,</if>
            <if test="createTime != null and createTime != ''">create_time,</if>
            <if test="businessId != null and businessId != ''">businessId,</if>
            <if test="deliveryTime != null and deliveryTime != ''">deliveryTime,</if>
            <if test="printRequestTime != null and printRequestTime != ''">printRequestTime,</if>
            <if test="deliverer != null and deliverer != ''">deliverer,</if>
            <if test="createBy != null and createBy != ''">createBy,</if>
            <if test="extend != null and extend != ''">extend,</if>
            <if test="gmtCreate != null and gmtCreate != ''">gmtCreate,</if>
            <if test="gmtUpdate != null and gmtUpdate != ''">gmtUpdate,</if>
            <if test="orderId != null and orderId != ''">orderId,</if>
            <if test="orderData != null and orderData != ''">orderData,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="storeId != null and storeId != ''">storeId,</if>
            <if test="updateBy != null and updateBy != ''">updateBy,</if>
            <if test="version != null and version != ''">version,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="createdBy != null and createdBy != ''">#{createdBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="businessId != null">#{businessId},</if>
            <if test="deliveryTime != null">#{deliveryTime},</if>
            <if test="printRequestTime != null">#{printRequestTime},</if>
            <if test="deliverer != null and deliverer != ''">#{deliverer},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="extend != null">#{extend},</if>
            <if test="gmtCreate != null">#{gmtCreate},</if>
            <if test="gmtUpdate != null">#{gmtUpdate},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="orderData != null">#{orderData},</if>
            <if test="status != null">#{status},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="version != null">#{version},</if>
        </trim>
    </insert>

    <update id="editPrint" parameterType="pd">
        update s_dtp_llps_distribution_print
        <set>
            <if test="createdBy != null and createdBy != ''">createdBy = #{createdBy},</if>
            <if test="createTime != null  and createTime != ''">create_time = #{createTime},</if>
            <if test="businessId != null  and businessId != ''">businessId = #{businessId},</if>
            <if test="deliveryTime != null  and deliveryTime != ''">deliveryTime = #{deliveryTime},</if>
            <if test="printRequestTime != null  and printRequestTime != ''">printRequestTime = #{printRequestTime},</if>
            <if test="deliverer != null and deliverer != ''">deliverer = #{deliverer},</if>
            <if test="createBy != null and createBy != ''">createBy = #{createBy},</if>
            <if test="extend != null  and extend != ''">extend = #{extend},</if>
            <if test="gmtCreate != null  and gmtCreate != ''">gmtCreate = #{gmtCreate},</if>
            <if test="gmtUpdate != null  and gmtUpdate != ''">gmtUpdate = #{gmtUpdate},</if>
            <if test="orderId != null  and orderId != ''">orderId = #{orderId},</if>
            <if test="orderData != null  and orderData != ''">orderData = #{orderData},</if>
            <if test="status != null  and status != ''">status = #{status},</if>
            <if test="storeId != null  and storeId != ''">storeId = #{storeId},</if>
            <if test="updateBy != null and updateBy != ''">updateBy = #{updateBy},</if>
            <if test="version != null  and version != ''">version = #{version},</if>
        </set>
        where id = #{id}
    </update>

    <!--配送单据打印模块 软删除-->
    <update id="DelPrint" parameterType="pd">
            update s_dtp_llps_distribution_print
            set del_flag = 1
            where
            <if test="ids != null and ids!=''">
                id in(${ids})
            </if>
    </update>

    <!--配置信息查询模块一店一目-->
    <select id="StoreProductList" parameterType="pd" resultType="pd">
        select
        *
        from s_dtp_pzxx_store_product_list
        <where>
            <if test="id != null">AND id = #{id}</if>
            <if test="createdBy != null and createdBy != ''">AND createdBy = #{createdBy}</if>
            <if test="createdDate != null and createdDate != ''">AND createdDate = #{createdDate}</if>
            <if test="storeId != null">AND storeId = #{storeId}</if>
            <if test="storeCode != null and storeCode != ''">AND storeCode = #{storeCode}</if>
            <if test="storeName != null and storeName != ''">AND storeName = #{storeName}</if>
            <if test="mdmCode != null and mdmCode != ''">AND mdmCode = #{mdmCode}</if>
            <if test="genericName != null and genericName != ''">AND genericName = #{genericName}</if>
            <if test="productName != null and productName != ''">AND productName = #{productName}</if>
            <if test="manufacturer != null and manufacturer != ''">AND manufacturer = #{manufacturer}</if>
            <if test="specification != null and specification != ''">AND specification = #{specification}</if>
            <if test="isPrescriptionItem != null">AND isPrescriptionItem = #{isPrescriptionItem}</if>
            <if test="isFlipItem != null">AND isFlipItem = #{isFlipItem}</if>
            <if test="isFollowUpItem != null">AND isFollowUpItem = #{isFollowUpItem}</if>
            <if test="isMandatoryRegistration != null">AND isMandatoryRegistration = #{isMandatoryRegistration}</if>
            <if test="isColdChainItem != null">AND isColdChainItem = #{isColdChainItem}</if>
            <if test="create_time_start != null and create_time_start != '' and create_time_end != null and create_time_end != ''">
                AND create_time BETWEEN #{create_time_start} AND #{create_time_end}
            </if>
            <if test="updatedAt_start != null and updatedAt_start != '' and updatedAt_end != null and updatedAt_end != ''">
                AND updatedAt BETWEEN #{updatedAt_start} AND #{updatedAt_end}
            </if>
            <if test="query != null and query != ''">
                AND (genericName LIKE CONCAT('%', #{query}, '%') OR productName LIKE CONCAT('%', #{query}, '%') OR mdmCode LIKE CONCAT('%', #{query}, '%'))
            </if>
            AND del_flag = '0'
        </where>
        order by create_time desc
    </select>
    <!--配置信息删除 一店一目-->
    <delete id="deleteProductList" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_dtp_pzxx_store_product_list
            where id in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>


    <select id="HospitalList" parameterType="pd" resultType="pd">
        select
      *
        from s_dtp_pzxx_hospital_list
        <where>
            <if test="id != null and id != ''">AND id = #{id}</if>
            <if test="createdBy != null and createdBy != ''">AND createdBy = #{createdBy}</if>
            <if test="standardName != null and standardName != ''">
                AND standardName like concat('%', #{standardName}, '%')
            </if>
            <if test="address != null and address != ''">AND address = #{address}</if>
            <if test="storeId != null and storeId != ''">AND storeId = #{storeId}</if>
            <if test="storeName != null and storeName != ''">AND storeName = #{storeName}</if>
            <if test="phone != null and phone != ''">AND phone = #{phone}</if>
            <if test="create_time_start != null and create_time_start != '' and create_time_end != null and create_time_end != ''">
                AND create_time BETWEEN #{create_time_start} AND #{create_time_end}
            </if>
            <if test="updated_time_start != null and updated_time_start != '' and updated_time_end != null and updated_time_end != ''">
                AND updated_time BETWEEN #{updated_time_start} AND #{updated_time_end}
            </if>
            AND del_flag =0
        </where>
        order by create_time desc
    </select>


    <!-- 查询处方药品信息 -->
    <select id="selectPrescriptionDrugs" parameterType="pd" resultType="pd">
        SELECT * FROM s_dtp_cfdj_prescription_drug WHERE 1=1
        <if test="id != null and id != ''">
            AND id = #{id}
        </if>
        <if test="productName != null and productName != ''">
            AND productName =#{productName}
        </if>
        <if test="genericName != null and genericName != ''">
            AND genericName = #{genericName}
        </if>
        <if test="prescriptionNumber != null and prescriptionNumber != ''">
            AND prescriptionNumber = #{prescriptionNumber}
        </if>
        <if test="drugCode != null and drugCode != ''">
            AND drugCode = #{drugCode}
        </if>
        <if test="specification != null and specification != ''">
            AND specification= #{specification}
        </if>
        <if test="usageMethod != null and usageMethod != ''">
            AND usageMethod = #{usageMethod}
        </if>
        <if test="quantity != null">
            AND quantity = #{quantity}
        </if>
        <if test="frequency != null and frequency != ''">
            AND frequency = #{frequency}
        </if>
        <if test="wordUsage != null and wordUsage != ''">
            AND wordUsage = #{wordUsage}
        </if>
        <if test="medicationCycle != null and medicationCycle != ''">
            AND medicationCycle = #{medicationCycle}
        </if>
        <if test="mdmCode != null and mdmCode != ''">
            AND mdmCode = #{mdmCode}
        </if>
        <if test="dosage != null and dosage != ''">
            AND dosage = #{dosage}
        </if>
        <if test="indication != null and indication != ''">
            AND indication= #{indication}
        </if>
        <if test="sideEffects != null and sideEffects != ''">
            AND sideEffects =#{sideEffects}
        </if>
        <if test="drugSource != null and drugSource != ''">
            AND drugSource = #{drugSource}
        </if>
        <if test="creator != null and creator != ''">
            AND creator = #{creator}
        </if>
        <if test="createTime != null">
            AND createTime = #{createTime}
        </if>
        <if test="status != null">
            AND status = #{status}
        </if>

    </select>

    <!-- 插入处方药品信息 -->
    <insert id="insertPrescriptionDrug" parameterType="pd">
        INSERT INTO s_dtp_cfdj_prescription_drug
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="productName != null and productName != ''">productName,</if>
            <if test="genericName != null and genericName != ''">genericName,</if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">prescriptionNumber,</if>
            <if test="drugCode != null and drugCode != ''">drugCode,</if>
            <if test="specification != null and specification != ''">specification,</if>
            <if test="usageMethod != null and usageMethod != ''">usageMethod,</if>
            <if test="quantity != null">quantity,</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
            <if test="frequency != null and frequency != ''">frequency,</if>
            <if test="wordUsage != null and wordUsage != ''">wordUsage,</if>
            <if test="medicationCycle != null and medicationCycle != ''">medicationCycle,</if>
            <if test="mdmCode != null and mdmCode != ''">mdmCode,</if>
            <if test="dosage != null and dosage != ''">dosage,</if>
            <if test="indication != null and indication != ''">indication,</if>
            <if test="sideEffects != null and sideEffects != ''">sideEffects,</if>
            <if test="drugSource != null and drugSource != ''">drugSource,</if>
            <if test="creator != null and creator != ''">creator,</if>
            <if test="createTime != null">createTime,</if>
            <if test="status != null">status,</if>
            <if test="isFlipItem != null and isFlipItem !=''">isFlipItem,</if>
            <if test="patientId != null and patientId !=''">patientId,</if>
            <if test="remarks != null and remarks != ''">remarks</if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="productName != null and productName != ''">#{productName},</if>
            <if test="genericName != null and genericName != ''">#{genericName},</if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">#{prescriptionNumber},</if>
            <if test="drugCode != null and drugCode != ''">#{drugCode},</if>
            <if test="specification != null and specification != ''">#{specification},</if>
            <if test="usageMethod != null and usageMethod != ''">#{usageMethod},</if>
            <if test="quantity != null">#{quantity},</if>
            <if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if>
            <if test="frequency != null and frequency != ''">#{frequency},</if>
            <if test="wordUsage != null and wordUsage != ''">#{wordUsage},</if>
            <if test="medicationCycle != null and medicationCycle != ''">#{medicationCycle},</if>
            <if test="mdmCode != null and mdmCode != ''">#{mdmCode},</if>
            <if test="dosage != null and dosage != ''">#{dosage},</if>
            <if test="indication != null and indication != ''">#{indication},</if>
            <if test="sideEffects != null and sideEffects != ''">#{sideEffects},</if>
            <if test="drugSource != null and drugSource != ''">#{drugSource},</if>
            <if test="creator != null and creator != ''">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="status != null">#{status},</if>
            <if test="isFlipItem != null">#{isFlipItem},</if>
            <if test="patientId != null and patientId !=''">#{patientId},</if>
            <if test="remarks != null and remarks != ''">#{remarks}</if>
        </trim>
    </insert>
    <!-- 批量插入处方药品信息 -->
    <insert id="batchAddPrescriptionDrug" parameterType="java.util.List" useGeneratedKeys="false">
        INSERT INTO s_dtp_cfdj_prescription_drug
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="dataList[0].productName != null and dataList[0].productName != ''">productName,</if>
            <if test="dataList[0].genericName != null and dataList[0].genericName != ''">genericName,</if>
            <if test="dataList[0].prescriptionNumber != null and dataList[0].prescriptionNumber != ''">prescriptionNumber,</if>
            <if test="dataList[0].soptemplateId != null">soptemplateId,</if>
            <if test="dataList[0].drugCode != null and dataList[0].drugCode != ''">drugCode,</if>
            <if test="dataList[0].specification != null and dataList[0].specification != ''">specification,</if>
            <if test="dataList[0].usageMethod != null and dataList[0].usageMethod != ''">usageMethod,</if>
            <if test="dataList[0].quantity != null">quantity,</if>
            <if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
            <if test="dataList[0].frequency != null and dataList[0].frequency != ''">frequency,</if>
            <if test="dataList[0].wordUsage != null and dataList[0].wordUsage != ''">wordUsage,</if>
            <if test="dataList[0].medicationCycle != null and dataList[0].medicationCycle != ''">medicationCycle,</if>
            <if test="dataList[0].mdmCode != null and dataList[0].mdmCode != ''">mdmCode,</if>
            <if test="dataList[0].dosage != null and dataList[0].dosage != ''">dosage,</if>
            <if test="dataList[0].indication != null and dataList[0].indication != ''">indication,</if>
            <if test="dataList[0].sideEffects != null and dataList[0].sideEffects != ''">sideEffects,</if>
            <if test="dataList[0].drugSource != null and dataList[0].drugSource != ''">drugSource,</if>
            <if test="dataList[0].creator != null and dataList[0].creator != ''">creator,</if>
            <if test="dataList[0].createTime != null">createTime,</if>
            <if test="dataList[0].status != null">status,</if>
            <if test="dataList[0].isFlipItem != null and dataList[0].isFlipItem != ''">isFlipItem,</if>
            <if test="dataList[0].patientId != null and dataList[0].patientId != ''">patientId,</if>
            <if test="dataList[0].remarks != null and dataList[0].remarks != ''">remarks</if>
        </trim>
        VALUES
        <foreach item="item" index="index" collection="dataList" separator=",">
            <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
                <if test="item.productName != null and item.productName != ''">#{item.productName},</if>
                <if test="item.genericName != null and item.genericName != ''">#{item.genericName},</if>
                <if test="item.prescriptionNumber != null and item.prescriptionNumber != ''">#{item.prescriptionNumber},</if>
                <if test="item.soptemplateId != null">#{item.soptemplateId},</if>
                <if test="item.drugCode != null and item.drugCode != ''">#{item.drugCode},</if>
                <if test="item.specification != null and item.specification != ''">#{item.specification},</if>
                <if test="item.usageMethod != null and item.usageMethod != ''">#{item.usageMethod},</if>
                <if test="item.quantity != null">#{item.quantity},</if>
                <if test="item.manufacturer != null and item.manufacturer != ''">{item.manufacturer},</if>
                <if test="item.frequency != null and item.frequency != ''">#{item.frequency},</if>
                <if test="item.wordUsage != null and item.wordUsage != ''">#{item.wordUsage},</if>
                <if test="item.medicationCycle != null and item.medicationCycle != ''">#{item.medicationCycle},</if>
                <if test="item.mdmCode != null and item.mdmCode != ''">#{item.mdmCode},</if>
                <if test="item.dosage != null and item.dosage != ''">#{item.dosage},</if>
                <if test="item.indication != null and item.indication != ''">#{item.indication},</if>
                <if test="item.sideEffects != null and item.sideEffects != ''">#{item.sideEffects},</if>
                <if test="item.drugSource != null and item.drugSource != ''">#{item.drugSource},</if>
                <if test="item.creator != null and item.creator != ''">#{item.creator},</if>
                <if test="item.createTime != null">#{item.createTime},</if>
                <if test="item.status != null">#{item.status},</if>
                <if test="item.isFlipItem != null and item.isFlipItem != ''">#{item.isFlipItem},</if>
                <if test="item.patientId != null and item.patientId != ''">#{item.patientId},</if>
                <if test="item.remarks != null and item.remarks != ''">#{item.remarks}</if>
            </trim>
        </foreach>
    </insert>
    <!-- 批量修改处方药品信息 -->
    <update id="batchUpdatePrescriptionDrug" parameterType="java.util.List">
        <foreach item="item" index="index" collection="list" separator=";">
            UPDATE s_dtp_cfdj_prescription_drug
            SET
            <trim prefix="" suffixOverrides=",">
                <if test="item.productName != null and item.productName != ''">
                    productName = #{item.productName},
                </if>
                <if test="item.genericName != null and item.genericName != ''">
                    genericName = #{item.genericName},
                </if>
                <if test="item.drugCode != null and item.drugCode != ''">
                    drugCode = #{item.drugCode},
                </if>
                <if test="item.specification != null and item.specification != ''">
                    specification = #{item.specification},
                </if>
                <if test="item.usageMethod != null and item.usageMethod != ''">
                    usageMethod = #{item.usageMethod},
                </if>
                <if test="item.quantity != null">
                    quantity = #{item.quantity},
                </if>
                <if test="item.manufacturer != null and item.manufacturer != ''">
                    manufacturer = #{item.manufacturer},
                </if>

                <if test="item.frequency != null and item.frequency != ''">
                    frequency = #{item.frequency},
                </if>
                <if test="item.wordUsage != null and item.wordUsage != ''">
                    wordUsage = #{item.wordUsage},
                </if>
                <if test="item.medicationCycle != null and item.medicationCycle != ''">
                    medicationCycle = #{item.medicationCycle},
                </if>
                <if test="item.mdmCode != null and item.mdmCode != ''">
                    mdmCode = #{item.mdmCode},
                </if>
                <if test="item.dosage != null and item.dosage != ''">
                    dosage = #{item.dosage},
                </if>
                <if test="item.indication != null and item.indication != ''">
                    indication = #{item.indication},
                </if>
                <if test="item.sideEffects != null and item.sideEffects != ''">
                    sideEffects = #{item.sideEffects},
                </if>
                    <if test="item.drugSource != null and item.drugSource != ''">
                    drugSource = #{item.drugSource},
                </if>
                <if test="item.creator != null and item.creator != ''">
                    creator = #{item.creator},
                </if>
                <if test="item.createTime != null">
                    createTime = #{item.createTime},
                </if>
                <if test="item.status != null">
                    status = #{item.status},
                </if>
                <if test="item.isFlipItem != null and item.isFlipItem != ''">
                    isFlipItem = #{item.isFlipItem},
                </if>
                <if test="item.patientId != null and item.patientId != ''">
                    item.patientId = #{item.patientId},
                </if>
                <if test="item.remarks != null and item.remarks != ''">
                    remarks = #{item.remarks}
                </if>
            </trim>
            WHERE prescriptionNumber = #{item.prescriptionId}
        </foreach>
    </update>

    <!-- 更新处方药品信息 -->
    <update id="updatePrescriptionDrug" parameterType="pd">
        UPDATE s_dtp_cfdj_prescription_drug SET
        <trim prefix="" suffixOverrides="," prefixOverrides=",">
            <if test="productName != null and productName != ''">
                productName = #{productName},
            </if>
            <if test="genericName != null and genericName != ''">
                genericName = #{genericName},
            </if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">
                prescriptionNumber = #{prescriptionNumber},
            </if>
            <if test="drugCode != null and drugCode != ''">
                drugCode = #{drugCode},
            </if>
            <if test="specification != null and specification != ''">
                specification = #{specification},
            </if>
            <if test="usageMethod != null and usageMethod != ''">
                usageMethod = #{usageMethod},
            </if>
            <if test="quantity != null">
                quantity = #{quantity},
            </if>
            <if test="manufacturer != null and manufacturer != ''">
                manufacturer = #{manufacturer},
            </if>
            <if test="frequency != null and frequency != ''">
                frequency = #{frequency},
            </if>
            <if test="wordUsage != null and wordUsage != ''">
                wordUsage = #{wordUsage},
            </if>
            <if test="medicationCycle != null and medicationCycle != ''">
                medicationCycle = #{medicationCycle},
            </if>
            <if test="mdmCode != null and mdmCode != ''">
                mdmCode = #{mdmCode},
            </if>
            <if test="dosage != null and dosage != ''">
                dosage = #{dosage},
            </if>
            <if test="indication != null and indication != ''">
                indication = #{indication},
            </if>
            <if test="sideEffects != null and sideEffects != ''">
                sideEffects = #{sideEffects},
            </if>
            <if test="drugSource != null and drugSource != ''">
                drugSource = #{drugSource},
            </if>
            <if test="creator != null and creator != ''">
                creator = #{creator},
            </if>
            <if test="createTime != null">
                createTime = #{createTime},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="isFlipItem != null and isFlipItem != ''">
                isFlipItem = #{isFlipItem},
            </if>
            <if test="patientId != null and patientId != ''">
                patientId = #{patientId},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks}
            </if>
        </trim>
        WHERE id = #{id}
    </update>

    <!-- 删除处方药品信息 -->
    <update id="deletePrescriptionDrug" parameterType="pd">
        DELETE FROM s_dtp_cfdj_prescription_drug WHERE id = #{id}
    </update>



</mapper>
