<?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.ruoyi.web.modules.architecture.mapper.BizWithdrawalPeriodStandardMapper">

    <resultMap type="com.ruoyi.web.modules.architecture.domain.BizWithdrawalPeriodStandard" id="BizWithdrawalPeriodStandardResult">
        <id     property="id"                column="id"/>
        <result property="drugName"          column="drug_name"/>
        <result property="drugType"          column="drug_type"/>
        <result property="withdrawalDays"    column="withdrawal_days"/>
        <result property="usageGuide"        column="usage_guide"/>
        <result property="drugEffect"        column="drug_effect"/>
        <result property="kbSyncStatus"     column="kb_sync_status"/>
        <result property="kbDocId"           column="kb_doc_id"/>
        <result property="createBy"          column="create_by"/>
        <result property="createTime"        column="create_time"/>
        <result property="updateBy"          column="update_by"/>
        <result property="updateTime"        column="update_time"/>
        <result property="remark"            column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, drug_name, drug_type, withdrawal_days, usage_guide, drug_effect,
               kb_sync_status, kb_doc_id,
               create_by, create_time, update_by, update_time, remark
        from biz_withdrawal_period_standard
    </sql>

    <select id="selectBizWithdrawalPeriodStandardById" parameterType="long" resultMap="BizWithdrawalPeriodStandardResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="countByDrugNameExcludeId" resultType="int">
        select count(1)
        from biz_withdrawal_period_standard
        where drug_name = #{drugName}
        <if test="excludeId != null">
            and id != #{excludeId}
        </if>
    </select>

    <select id="selectBizWithdrawalPeriodStandardList" parameterType="com.ruoyi.web.modules.architecture.domain.BizWithdrawalPeriodStandard" resultMap="BizWithdrawalPeriodStandardResult">
        <include refid="selectVo"/>
        <where>
            <if test="keyword != null and keyword != ''">
                and drug_name like concat('%', #{keyword}, '%')
            </if>
            <if test="drugType != null">
                and drug_type = #{drugType}
            </if>
        </where>
        order by create_time desc, id desc
    </select>

    <insert id="insertBizWithdrawalPeriodStandard" parameterType="com.ruoyi.web.modules.architecture.domain.BizWithdrawalPeriodStandard" useGeneratedKeys="true" keyProperty="id">
        insert into biz_withdrawal_period_standard (
            drug_name, drug_type, withdrawal_days, usage_guide, drug_effect,
            kb_sync_status, kb_doc_id,
            create_by, create_time, remark
        ) values (
            #{drugName}, #{drugType}, #{withdrawalDays}, #{usageGuide}, #{drugEffect},
            #{kbSyncStatus}, #{kbDocId},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizWithdrawalPeriodStandard" parameterType="com.ruoyi.web.modules.architecture.domain.BizWithdrawalPeriodStandard">
        update biz_withdrawal_period_standard set
            drug_name = #{drugName},
            drug_type = #{drugType},
            withdrawal_days = #{withdrawalDays},
            usage_guide = #{usageGuide},
            drug_effect = #{drugEffect},
            kb_sync_status = #{kbSyncStatus},
            kb_doc_id = #{kbDocId},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizWithdrawalPeriodStandardById" parameterType="long">
        delete from biz_withdrawal_period_standard where id = #{id}
    </delete>

    <delete id="deleteBizWithdrawalPeriodStandardByIds" parameterType="Long">
        delete from biz_withdrawal_period_standard where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
