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

    <select id="selectDValueConfig" parameterType="pd" resultType="pd">
        select * from s_gxhpz_dvalueconfig where 1=1
        <if test="d_value_code != null and d_value_code != ''">
            and d_value_code = #{d_value_code}
        </if>
        <if test="mdmCode != null and mdmCode != ''">
            and mdmCode = #{mdmCode}
        </if>
        <if test="dValueName != null and dValueName != ''">
            and dValueName = #{dValueName}
        </if>
        <if test="specification != null and specification != ''">
            and specification = #{specification}
        </if>
        <if test="genericName != null and genericName != ''">
            and genericName = #{genericName}
        </if>
        <if test="productName != null and productName != ''">
            and productName = #{productName}
        </if>
        <if test="icdIndication != null and icdIndication != ''">
            and icdIndication = #{icdIndication}
        </if>
        <if test="indicationCode != null and indicationCode != ''">
            and indicationCode = #{indicationCode}
        </if>
        <if test="administrationMethod != null and administrationMethod != ''">
            and administrationMethod = #{administrationMethod}
        </if>
        <if test="dosage != null and dosage != ''">
            and dosage = #{dosage}
        </if>
        <if test="unit != null and unit != ''">
            and unit = #{unit}
        </if>
        <if test="frequency != null and frequency != ''">
            and frequency = #{frequency}
        </if>
        <if test="createdBy != null and createdBy != ''">
            and createdBy = #{createdBy}
        </if>
        <if test="createdTime != null">
            and createdTime = #{createdTime}
        </if>
        <if test="updatedBy != null and updatedBy != ''">
            and updatedBy = #{updatedBy}
        </if>
        <if test="updatedTime != null">
            and updatedTime = #{updatedTime}
        </if>
        <if test="status != null and status != ''">
            and status = #{status}
        </if>
        <if test="remarks != null and remarks != ''">
            and remarks = #{remarks}
        </if>
        <if test="id != null and id != ''">
            and id = #{id}
        </if>
    </select>

    <select id="selectOne" parameterType="pd" resultType="pd">
        select v.* ,d.packaging,d.manufacturerShortName,d.isFollowUpManaged,
               d.isColdChainManaged,d.isRegisteredManaged,d.isCharityAidManaged,
               d.enterpriseFlowManagement,
               d.indicationDescription,d.dosageAndAdministration
        from s_gxhpz_dvalueconfig  v
        left join s_gxhpz_drugconfig d on d.mdmCode = v.mdmCode
        where 1=1
        <if test="query != null and query != ''">
            AND (v.dValueName LIKE CONCAT('%', #{query}, '%')
            OR v.d_value_code = #{query})
        </if>

        LIMIT 1
    </select>
    <update id="updateDValueConfig" parameterType="pd">
        update s_gxhpz_dvalueconfig
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                d_value_code = #{d_value_code},
            </if>
            <if test="mdmCode != null and mdmCode != ''">
                mdmCode = #{mdmCode},
            </if>
            <if test="dValueName != null and dValueName != ''">
                dValueName = #{dValueName},
            </if>
            <if test="specification != null and specification != ''">
                specification = #{specification},
            </if>
            <if test="genericName != null and genericName != ''">
                genericName = #{genericName},
            </if>
            <if test="productName != null and productName != ''">
                productName = #{productName},
            </if>
            <if test="icdIndication != null and icdIndication != ''">
                icdIndication = #{icdIndication},
            </if>
            <if test="indicationCode != null and indicationCode != ''">
                indicationCode = #{indicationCode},
            </if>
            <if test="administrationMethod != null and administrationMethod != ''">
                administrationMethod = #{administrationMethod},
            </if>
            <if test="dosage != null and dosage != ''">
                dosage = #{dosage},
            </if>
            <if test="unit != null and unit != ''">
                unit = #{unit},
            </if>
            <if test="frequency != null and frequency != ''">
                frequency = #{frequency},
            </if>
            <if test="createdBy != null and createdBy != ''">
                createdBy = #{createdBy},
            </if>
            <if test="createdTime != null">
                createdTime = #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
            <if test="status != null and status != ''">
                status = #{status},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks},
            </if>
        </trim>
        <if test="id != null">
            where id = #{id}
        </if>
    </update>
    <update id="updateDValue" parameterType="pd">
        update s_gxhpz_dvalueconfig
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="mdmCode != null and mdmCode != ''">
                mdmCode = #{mdmCode},
            </if>
            <if test="dValueName != null and dValueName != ''">
                dValueName = #{dValueName},
            </if>
            <if test="specification != null and specification != ''">
                specification = #{specification},
            </if>
            <if test="genericName != null and genericName != ''">
                genericName = #{genericName},
            </if>
            <if test="productName != null and productName != ''">
                productName = #{productName},
            </if>
            <if test="icdIndication != null and icdIndication != ''">
                icdIndication = #{icdIndication},
            </if>
            <if test="indicationCode != null and indicationCode != ''">
                indicationCode = #{indicationCode},
            </if>
            <if test="administrationMethod != null and administrationMethod != ''">
                administrationMethod = #{administrationMethod},
            </if>
            <if test="dosage != null and dosage != ''">
                dosage = #{dosage},
            </if>
            <if test="unit != null and unit != ''">
                unit = #{unit},
            </if>
            <if test="frequency != null and frequency != ''">
                frequency = #{frequency},
            </if>

            <if test="updatedBy != null and updatedBy != ''">
                updatedBy = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
            <if test="status != null and status != ''">
                status = #{status},
            </if>

        </trim>
        <if test="d_value_code != null and d_value_code != ''">
            where d_value_code = #{d_value_code}
        </if>
    </update>
    <delete id="deleteDvalueConfigByIds" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_gxhpz_dvalueconfig
            where id in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>
<!--    <delete id="deleteDvalueConfigByIds" parameterType="pd">-->
<!--        delete from s_gxhpz_dvalueconfig-->
<!--        <if test="ids != null">-->
<!--            where id in (${ids})-->
<!--        </if>-->
<!--    </delete>-->

    <insert id="insertDValueConfig" parameterType="pd">
        insert into s_gxhpz_dvalueconfig
        <trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                d_value_code,
            </if>
            <if test="mdmCode != null and mdmCode != ''">
                mdmCode,
            </if>
            <if test="dValueName != null and dValueName != ''">
                dValueName,
            </if>
            <if test="specification != null and specification != ''">
                specification,
            </if>
            <if test="genericName != null and genericName != ''">
                genericName,
            </if>
            <if test="productName != null and productName != ''">
                productName,
            </if>
            <if test="icdIndication != null and icdIndication != ''">
                icdIndication,
            </if>
            <if test="indicationCode != null and indicationCode != ''">
                indicationCode,
            </if>
            <if test="administrationMethod != null and administrationMethod != ''">
                administrationMethod,
            </if>
            <if test="dosage != null and dosage != ''">
                dosage,
            </if>
            <if test="unit != null and unit != ''">
                unit,
            </if>
            <if test="frequency != null and frequency != ''">
                frequency,
            </if>
            <if test="createdBy != null and createdBy != ''">
                createdBy,
            </if>
            <if test="createdTime != null">
                createdTime,
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy,
            </if>
            <if test="updatedTime != null">
                updatedTime,
            </if>
            <if test="status != null and status !=''">
                status,
            </if>
            <if test="remarks != null and remarks != ''">
                remarks,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
            <if test="d_value_code != null and d_value_code != ''">
                #{d_value_code},
            </if>
            <if test="mdmCode != null and mdmCode != ''">
                #{mdmCode},
            </if>
            <if test="dValueName != null and dValueName != ''">
                #{dValueName},
            </if>
            <if test="specification != null and specification != ''">
                #{specification},
            </if>
            <if test="genericName != null and genericName != ''">
                #{genericName},
            </if>
            <if test="productName != null and productName != ''">
                #{productName},
            </if>
            <if test="icdIndication != null and icdIndication != ''">
                #{icdIndication},
            </if>
            <if test="indicationCode != null and indicationCode != ''">
                #{indicationCode},
            </if>
            <if test="administrationMethod != null and administrationMethod != ''">
                #{administrationMethod},
            </if>
            <if test="dosage != null and dosage != ''">
                #{dosage},
            </if>
            <if test="unit != null and unit != ''">
                #{unit},
            </if>
            <if test="frequency != null and frequency != ''">
                #{frequency},
            </if>
            <if test="createdBy != null and createdBy != ''">
                #{createdBy},
            </if>
            <if test="createdTime != null">
                #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                #{updatedBy},
            </if>
            <if test="updatedTime != null">
                #{updatedTime},
            </if>
            <if test="status != null and status !=''">
                #{status},
            </if>
            <if test="remarks != null and remarks != ''">
                #{remarks},
            </if>
        </trim>
    </insert>

    <update id="changeStatus" parameterType="pd">
        update s_gxhpz_dvalueconfig set  status = #{status}, updatedBy = #{updatedBy},updatedTime = #{updatedTime} where   id = #{id}
    </update>
</mapper>
