<?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.unis.base.server.dao.DYpxxDao">

    <resultMap id="BaseResultMap" type="com.unis.base.server.entity.DYpxxDO">
        <result column="YPID" property="ypid" jdbcType="VARCHAR"/>
        <result column="YPDM" property="ypdm" jdbcType="VARCHAR"/>
        <result column="YPMC" property="ypmc" jdbcType="VARCHAR"/>
        <result column="YPGGXH" property="ypggxh" jdbcType="VARCHAR"/>
        <result column="BZZ" property="bzz" jdbcType="VARCHAR"/>
        <result column="KCSL" property="kcsl" jdbcType="VARCHAR"/>
        <result column="YPDJ" property="ypdj" jdbcType="VARCHAR"/>
        <result column="ZHYSSJ" property="zhyssj" jdbcType="DATE"/>
        <result column="STATUS" property="status" jdbcType="VARCHAR"/>
        <result column="CREATOR" property="creator" jdbcType="VARCHAR"/>
        <result column="CREATOR_CODE" property="creatorCode" jdbcType="VARCHAR"/>
        <result column="CREATE_DATE" property="createDate" jdbcType="VARCHAR"/>
        <result column="REFRESHER" property="refresher" jdbcType="VARCHAR"/>
        <result column="REFRESHER_CODE" property="refresherCode" jdbcType="VARCHAR"/>
        <result column="REFRESH_TIME" property="refreshTime" jdbcType="VARCHAR"/>
        <result column="REMARK" property="remark" jdbcType="VARCHAR"/>
        <result column="RQ" property="rq" jdbcType="DATE"/>
        <result column="YJZL" property="yjzl" jdbcType="VARCHAR"/>
        <result column="YJXT" property="yjxt" jdbcType="VARCHAR"/>
        <result column="YJBZ" property="yjbz" jdbcType="VARCHAR"/>
        <result column="ZCSL" property="zcsl" jdbcType="VARCHAR"/>
        <result column="JYSL" property="jysl" jdbcType="VARCHAR"/>
        <result column="PDGQSL" property="pdgqsl" jdbcType="VARCHAR"/>
        <result column="PDSYSL" property="pdsysl" jdbcType="VARCHAR"/>
        <result column="SSKM" property="sskm" jdbcType="VARCHAR"/>
        <result column="SSKMBH" property="sskmbh" jdbcType="VARCHAR"/>
   		 <result column="SFBA" property="sfba" jdbcType="DECIMAL" />
        <result column="SCCJ" property="sccj" jdbcType="VARCHAR"/>
        <result column="DJR_CODE" property="djrCode" jdbcType="VARCHAR"/>
        <result column="HDR_CODE" property="hdrCode" jdbcType="VARCHAR"/>
 	    <result column="DJR_NAME" property="djrName" jdbcType="VARCHAR"/>
 	     <result column="HDR_NAME" property="hdrName" jdbcType="VARCHAR"/>
 	     <result column="QYMC" property="qymc" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Medicine_List">
        YPID, RQ, YPMC, YJZL, YJXT, YJBZ, KCSL, ZCSL, JYSL, PDGQSL, PDSYSL,SSKM, SSKMBH,
        YPDM, YPGGXH, BZZ, YPDJ, ZHYSSJ,STATUS, CREATOR, CREATOR_CODE, CREATE_DATE, 
        REFRESHER, REFRESHER_CODE, REFRESH_TIME, REMARK,SFBA,
        SCCJ,DJR_CODE,HDR_CODE,DJR_NAME,HDR_NAME,QYMC
    </sql>

    <!-- 根据条件查询药剂信息 -->
    <select id="findYpxxList" parameterType="com.unis.base.server.entity.DYpxxDO" resultMap="BaseResultMap">
        select
        <include refid="Medicine_List" />
        FROM
        D_YPXX
        <where>
            STATUS=1
            <!-- 药品名称 -->
            <if test="ypmc != null and ypmc != ''">
                AND YPMC like concat(CONCAT('%',#{ypmc,jdbcType=VARCHAR}) ,'%')
            </if>
            <!-- 日期 -->
            <if test="month != null and month != ''">
                AND date_format(rq,'%d') like concat(CONCAT('%',#{month,jdbcType=VARCHAR}) ,'%')
            </if>
            <!-- 库点名称 -->
            <if test="sskm != null and sskm != ''">
                AND sskm like concat(CONCAT('%',#{sskm,jdbcType=VARCHAR}) ,'%')
            </if>
            <if test="yjzl != null and yjzl != ''">
                AND YJZL = #{yjzl,jdbcType=VARCHAR}
            </if>
             <if test="creatorCode">
             
             and CREATOR_CODE=#{creatorCode}
             
             </if>
        </where>
        order by rq desc
    </select>
    <!-- 根据ID查询药剂信息 -->
    <select id="selectById" parameterType="com.unis.base.server.entity.DYpxxDO" resultMap="BaseResultMap">
        select
        <include refid="Medicine_List" />
        FROM
        D_YPXX where STATUS=1  AND 	 YPID = #{ypid,jdbcType=VARCHAR}
    </select>
  	<!--	更改备案状态-->
	<update id="updateMedicineinfoStatus"  parameterType="java.util.Map">
		UPDATE D_YPXX
		SET SFBA = #{sfba}
		where YPID = #{ypid}
	</update>
</mapper>