<?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.TyYpxxbDao" >

  <resultMap id="BaseResultMap" type="com.unis.base.server.entity.TyYpxxbDO" >
    <id column="YPID" property="ypid" jdbcType="VARCHAR" />
    <result column="YPBH" property="ypbh" jdbcType="VARCHAR" />
    <result column="QYDBH" property="qydbh" jdbcType="VARCHAR" />
    <result column="GGXH" property="ggxh" jdbcType="VARCHAR" />
    <result column="SCRQPC" property="scrqpc" jdbcType="VARCHAR" />
    <result column="LYFS" property="lyfs" jdbcType="VARCHAR" />
    <result column="YPSLDW" property="ypsldw" jdbcType="DECIMAL" />
    <result column="DBSLDW" property="dbsldw" jdbcType="DECIMAL" />
    <result column="LSYPBM" property="lsypbm" jdbcType="VARCHAR" />
    <result column="LSYPMC" property="lsypmc" jdbcType="VARCHAR" />
    <result column="LSDJBM" property="lsdjbm" jdbcType="VARCHAR" />
    <result column="LSDJMC" property="lsdjmc" jdbcType="VARCHAR" />
    <result column="LSXZBM" property="lsxzbm" jdbcType="VARCHAR" />
    <result column="LSXZMC" property="lsxzmc" jdbcType="VARCHAR" />
    <result column="YPZTBS" property="ypztbs" jdbcType="VARCHAR" />
    <result column="YPSSKDDM" property="ypsskddm" jdbcType="VARCHAR" />
    <result column="YPSSKDMC" property="ypsskdmc" jdbcType="VARCHAR" />
    <result column="QYDD" property="qydd" jdbcType="VARCHAR" />
    <result column="QYRBM" property="qyrbm" jdbcType="VARCHAR" />
    <result column="QYRMC" property="qyrmc" jdbcType="VARCHAR" />
    <result column="LSCD" property="lscd" jdbcType="VARCHAR" />
    <result column="SHND" property="shnd" jdbcType="VARCHAR" />
    <result column="RKSJ" property="rksj" jdbcType="TIMESTAMP" />
    <result column="BZFS" property="bzfs" jdbcType="VARCHAR" />
    <result column="JYLX" property="jylx" jdbcType="VARCHAR" />
    <result column="WTDWBM" property="wtdwbm" jdbcType="VARCHAR" />
    <result column="WTDWMC" property="wtdwmc" jdbcType="VARCHAR" />
    <result column="JCSJ" property="jcsj" jdbcType="TIMESTAMP" />
    <result column="ORG_CODE" property="orgCode" jdbcType="VARCHAR" />
    <result column="CFLXBH" property="cflxbh" jdbcType="VARCHAR" />
    <result column="CFLXMC" property="cflxmc" jdbcType="VARCHAR" />
    
    
    
    <result column="TYSJ" property="tysj" jdbcType="TIMESTAMP" />
    <result column="TYJG" property="tyjg" jdbcType="VARCHAR" />
    <result column="TYRQ" property="tyrq" jdbcType="TIMESTAMP" />
    <result column="SFCXGQHYX" property="sfcxgqhyx" jdbcType="INTEGER" />
    <result column="SFCXGYZCH" property="sfcxgyzch" jdbcType="INTEGER" />
    <result column="SM" property="sm" jdbcType="VARCHAR" />
    <result column="SYQK" property="syqk" jdbcType="VARCHAR" />
    <result column="SYSJ" property="sysj" jdbcType="TIMESTAMP" />
    <result column="SYMC" property="symc" jdbcType="VARCHAR" />
    <result column="NHQZ" property="nhqz" jdbcType="VARCHAR" />
    <result column="NHLXFS" property="nhlxfs" jdbcType="VARCHAR" />
    <result column="TYXXFJ" property="tyxxfj" jdbcType="VARCHAR" />
    
    
    
    <result column="SPAQXM" property="spaqxm" jdbcType="VARCHAR" />
    <result column="ZJSYSJ" property="zjsysj" jdbcType="TIMESTAMP" />
    <result column="SYYJMC" property="syyjmc" jdbcType="VARCHAR" />
    <result column="CLJS" property="cljs" jdbcType="VARCHAR" />
    <result column="CHFSQK" property="chfsqk" jdbcType="VARCHAR" />
    <result column="LCSYMC" property="lcsymc" jdbcType="VARCHAR" />
    <result column="BZ" property="bz" jdbcType="VARCHAR" />
    <result column="TYFZRQZ" property="tyfzrqz" jdbcType="VARCHAR" />
    <result column="CCQYFZR" property="ccqyfzr" jdbcType="VARCHAR" />
    <result column="CCQYLXDH" property="ccqylxdh" jdbcType="VARCHAR" />
    <result column="QHSM" property="qhsm" jdbcType="VARCHAR" />
    
    
    <result column="CYDW" property="cydw" jdbcType="VARCHAR" />
    <result column="CYRQ" property="cyrq" jdbcType="TIMESTAMP" />
    <result column="SCCJ" property="sccj" jdbcType="VARCHAR" />
    <result column="SB" property="sb" jdbcType="VARCHAR" />
    <result column="ZXBZ" property="zxbz" jdbcType="VARCHAR" />
    <result column="BZQ" property="bzq" jdbcType="VARCHAR" />
    <result column="CYF" property="cyf" jdbcType="VARCHAR" />
    
    
    
    
  </resultMap>


  <!--
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.ypid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
          
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.ypid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  -->


  <sql id="Base_Column_List_common" >
    yp.ypid, yp.ypbh, yp.qydbh, yp.ggxh, yp.scrqpc, yp.lyfs, yp.ypsldw, yp.dbsldw, yp.lsypbm,
    yp.lsypmc, yp.lsdjbm, yp.lsdjmc,yp.lsxzbm, yp.lsxzmc, yp.ypztbs, yp.ypsskddm, yp.ypsskdmc,
    yp.qydd, yp.qyrbm, yp.qyrmc, yp.lscd, yp.shnd, yp.rksj,yp.bzfs, yp.jylx, yp.wtdwbm,
    yp.wtdwmc, yp.jcsj, yp.org_code, yp.cflxbh, yp.cflxmc, yp.tysj, yp.tyjg, yp.tyrq,
    yp.sfcxgqhyx, yp.sfcxgyzch, yp.sm, yp.syqk, yp.sysj, yp.symc, yp.nhqz,
    yp.nhlxfs, yp.tyxxfj, yp.spaqxm, yp.zjsysj, yp.syyjmc, yp.cljs, yp.chfsqk,
    yp.lcsymc, yp.bz, yp.tyfzrqz, yp.ccqyfzr, yp.ccqylxdh, yp.qhsm,
    yp.cydw, yp.cyrq, yp.sccj, yp.sb, yp.zxbz, yp.bzq,
    yp.cyf,
    yp.remark
  </sql>


  <!-- 根据条件查询样品信息 -->
  <select id="getSampleList" parameterType="com.unis.base.common.vo.SampleQueryVO" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List_common"></include>
    FROM
        TY_YPXXB yp
    <where>
      yp.status = 1
      <!-- 样品ID -->
      <if test="ypid != null and ypid != ''">
        and yp.ypid LIKE concat(CONCAT('%',#{ypid,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 样品编号 -->
      <if test="ypbh != null and ypbh != ''">
        and yp.ypbh LIKE concat(CONCAT('%',#{ypbh,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 样品单编号 -->
      <if test="qydbh != null and qydbh != ''">
        and yp.qydbh LIKE concat(CONCAT('%',#{qydbh,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 规格型号 -->
      <if test="ggxh != null and ggxh != ''">
        and yp.ggxh LIKE concat(CONCAT('%',#{ggxh,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 来样方式 -->
      <if test="lyfs != null and lyfs != ''">
        and yp.lyfs LIKE concat(CONCAT('%',#{lyfs,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 粮食等级编码 -->
      <if test="lsdjbm != null and lsdjbm != ''">
        and yp.lsdjbm LIKE concat(CONCAT('%',#{lsdjbm,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 粮食等级名称 -->
      <if test="lsdjmc != null and lsdjmc != ''">
        and yp.lsdjmc LIKE concat(CONCAT('%',#{lsdjmc,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 粮食性质编码 -->
      <if test="lsxzbm != null and lsxzbm != ''">
        and yp.lsxzbm LIKE concat(CONCAT('%',#{lsxzbm,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 粮食性质名称 -->
      <if test="lsxzmc != null and lsxzmc != ''">
        and yp.lsxzmc LIKE concat(CONCAT('%',#{lsxzmc,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 样品状态标识 -->
      <if test="ypztbs != null and ypztbs != ''">
        and yp.ypztbs LIKE concat(CONCAT('%',#{ypztbs,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 样品所属库点编码 -->
      <if test="ypsskddm != null and ypsskddm != ''">
        and yp.ypsskddm LIKE concat(CONCAT('%',#{ypsskddm,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 样品所属库点名称 -->
      <if test="ypsskdmc != null and ypsskdmc != ''">
        and yp.ypsskdmc LIKE concat(CONCAT('%',#{ypsskdmc,jdbcType=VARCHAR}) , '%')
      </if>
      <!-- 检测开始时间 -->
      <if test="jckssj != null and jckssj != ''">
        and date_format(yp.jcsj,'%Y-%d-%m') &gt;= #{jckssj}
      </if>
      <!-- 检测结束时间 -->
      <if test="jcjssj != null and jcjssj != ''">
        and date_format(yp.jcsj,'%Y-%d-%m') &lt;= #{jcjssj}
      </if>
    </where>
    ORDER BY yp.ypid asc
  </select>
  
  <!-- 根据样品ID获取样品信息 -->
  <select id="getSampleInfo" parameterType="java.lang.String" resultMap="BaseResultMap">
    SELECT 
    <include refid="Base_Column_List_common"></include>
    from
        TY_YPXXB yp
    <where>
      yp.ypid = #{ypid,jdbcType=VARCHAR}
      and yp.status = 1
    </where>
  </select>

  <!-- 更新样品信息 -->
  <update id="update" parameterType="com.unis.base.server.entity.TyYpxxbDO">
    update TY_YPXXB
    <set>
      <if test="ypbh != null">
        ypbh = #{ypbh,jdbcType=VARCHAR},
      </if>
      <if test="qydbh != null">
        qydbh = #{qydbh,jdbcType=VARCHAR},
      </if>
      <if test="ggxh != null">
        ggxh = #{ggxh,jdbcType=VARCHAR},
      </if>
      <if test="scrqpc != null">
        scrqpc = #{scrqpc,jdbcType=VARCHAR},
      </if>
      <if test="lyfs != null">
        lyfs = #{lyfs,jdbcType=VARCHAR},
      </if>
      <if test="ypsldw != null">
        ypsldw = #{ypsldw,jdbcType=VARCHAR},
      </if>
      <if test="dbsldw != null">
        dbsldw = #{dbsldw,jdbcType=VARCHAR},
      </if>
      <if test="lsypbm != null">
        lsypbm = #{lsypbm,jdbcType=VARCHAR},
      </if>
      <if test="lsypmc != null">
        lsypmc = #{lsypmc,jdbcType=VARCHAR},
      </if>
      <if test="lsdjbm != null">
        lsdjbm = #{lsdjbm,jdbcType=VARCHAR},
      </if>
      <if test="lsdjmc != null">
        lsdjmc = #{lsdjmc,jdbcType=VARCHAR},
      </if>
      <if test="lsxzbm != null">
        lsxzbm = #{lsxzbm,jdbcType=VARCHAR},
      </if>
      <if test="lsxzmc != null">
        lsxzmc = #{lsxzmc,jdbcType=VARCHAR},
      </if>
      <if test="ypztbs != null">
        ypztbs = #{ypztbs,jdbcType=VARCHAR},
      </if>
      <if test="ypsskddm != null">
        ypsskddm = #{ypsskddm,jdbcType=VARCHAR},
      </if>
      <if test="ypsskdmc != null">
        ypsskdmc = #{ypsskdmc,jdbcType=VARCHAR},
      </if>
      <if test="qydd != null">
        qydd = #{qydd,jdbcType=VARCHAR},
      </if>
      <if test="qyrbm != null">
        qyrbm = #{qyrbm,jdbcType=VARCHAR},
      </if>
      <if test="qyrmc != null">
        qyrmc = #{qyrmc,jdbcType=VARCHAR},
      </if>
      <if test="lscd != null">
        lscd = #{lscd,jdbcType=VARCHAR},
      </if>
      <if test="shnd != null">
        shnd = #{shnd,jdbcType=VARCHAR},
      </if>
      <if test="rksj != null">
        rksj = #{rksj,jdbcType=VARCHAR},
      </if>
      <if test="bzfs != null">
        bzfs = #{bzfs,jdbcType=VARCHAR},
      </if>
      <if test="jylx != null">
        jylx = #{jylx,jdbcType=VARCHAR},
      </if>
      <if test="wtdwbm != null">
        wtdwbm = #{wtdwbm,jdbcType=VARCHAR},
      </if>
      <if test="wtdwmc != null">
        wtdwmc = #{wtdwmc,jdbcType=VARCHAR},
      </if>
      <if test="jcsj != null">
        jcsj = #{jcsj,jdbcType=VARCHAR},
      </if>
      <if test="orgCode != null">
        org_code = #{orgCode,jdbcType=VARCHAR},
      </if>
      <if test="cflxbh != null">
        cflxbh = #{cflxbh,jdbcType=VARCHAR},
      </if>
      <if test="cflxmc != null">
        cflxmc = #{cflxmc,jdbcType=VARCHAR},
      </if>
      <if test="refresher != null">
        refresher = #{refresher,jdbcType=VARCHAR},
      </if>
      <if test="refresherCode != null">
        refresher_code = #{refresherCode,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=VARCHAR},
      </if>
      refresh_time = NOW()
    </set>
    <where>
      ypid = #{ypid,jdbcType=VARCHAR}
    </where>
  </update>

  <!-- 新增样品信息 -->
  <insert id="insert" parameterType="com.unis.base.server.entity.TyYpxxbDO">
    insert into TY_YPXXB
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="ypid != null">
        ypid,
      </if>
      <if test="ypbh != null">
        ypbh,
      </if>
      <if test="qydbh != null">
        qydbh,
      </if>
      <if test="ggxh != null">
        ggxh,
      </if>
      <if test="scrqpc != null">
        scrqpc,
      </if>
      <if test="lyfs != null">
        lyfs,
      </if>
      <if test="ypsldw != null">
        ypsldw,
      </if>
      <if test="dbsldw != null">
        dbsldw,
      </if>
      <if test="lsypbm != null">
        lsypbm,
      </if>
      <if test="lsypmc != null">
        lsypmc,
      </if>
      <if test="lsdjbm != null">
        lsdjbm,
      </if>
      <if test="lsdjmc != null">
        lsdjmc,
      </if>
      <if test="lsxzbm != null">
        lsxzbm,
      </if>
      <if test="lsxzmc != null">
        lsxzmc,
      </if>
      <if test="ypztbs != null">
        ypztbs,
      </if>
      <if test="ypsskddm != null">
        ypsskddm,
      </if>
      <if test="ypsskdmc != null">
        ypsskdmc,
      </if>
      <if test="qydd != null">
        qydd,
      </if>
      <if test="qyrbm != null">
        qyrbm,
      </if>
      <if test="qyrmc != null">
        qyrmc,
      </if>
      <if test="lscd != null">
        lscd,
      </if>
      <if test="shnd != null">
        shnd,
      </if>
      <if test="rksj != null">
        rksj,
      </if>
      <if test="bzfs != null">
        bzfs,
      </if>
      <if test="jylx != null">
        jylx,
      </if>
      <if test="wtdwbm != null">
        wtdwbm,
      </if>
      <if test="wtdwmc != null">
        wtdwmc,
      </if>
      <if test="jcsj != null">
        jcsj,
      </if>
      <if test="orgCode != null">
        org_code,
      </if>
      <if test="cflxbh != null">
        cflxbh,
      </if>
      <if test="cflxmc != null">
        cflxmc,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="creator != null" >
        creator,
      </if>
      <if test="creatorCode != null" >
        creator_code,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
      <if test="remark != null" >
        remark,
      </if>
    </trim>
    <trim prefix="values （" suffix=")" suffixOverrides=",">
      <if test="ypid != null">
        #{ypid,jdbcType=VARCHAR},
      </if>
      <if test="ypbh != null">
        #{ypbh,jdbcType=VARCHAR},
      </if>
      <if test="qydbh != null">
        #{qydbh,jdbcType=VARCHAR},
      </if>
      <if test="ggxh != null">
        #{ggxh,jdbcType=VARCHAR},
      </if>
      <if test="scrqpc != null">
        #{scrqpc,jdbcType=VARCHAR},
      </if>
      <if test="lyfs != null">
        #{lyfs,jdbcType=VARCHAR},
      </if>
      <if test="ypsldw != null">
        #{ypsldw,jdbcType=VARCHAR},
      </if>
      <if test="dbsldw != null">
        #{dbsldw,jdbcType=VARCHAR},
      </if>
      <if test="lsypbm != null">
        #{lsypbm,jdbcType=VARCHAR},
      </if>
      <if test="lsypmc != null">
        #{lsypmc,jdbcType=VARCHAR},
      </if>
      <if test="lsdjbm != null">
        #{lsdjbm,jdbcType=VARCHAR},
      </if>
      <if test="lsdjmc != null">
        #{lsdjmc,jdbcType=VARCHAR},
      </if>
      <if test="lsxzbm != null">
        #{lsxzbm,jdbcType=VARCHAR},
      </if>
      <if test="lsxzmc != null">
        #{lsxzmc,jdbcType=VARCHAR},
      </if>
      <if test="ypztbs != null">
        #{ypztbs,jdbcType=VARCHAR},
      </if>
      <if test="ypsskddm != null">
        #{ypsskddm,jdbcType=VARCHAR},
      </if>
      <if test="ypsskdmc != null">
        #{ypsskdmc,jdbcType=VARCHAR},
      </if>
      <if test="qydd != null">
        #{qydd,jdbcType=VARCHAR},
      </if>
      <if test="qyrbm != null">
        #{qyrbm,jdbcType=VARCHAR},
      </if>
      <if test="qyrmc != null">
        #{qyrmc,jdbcType=VARCHAR},
      </if>
      <if test="lscd != null">
        #{lscd,jdbcType=VARCHAR},
      </if>
      <if test="shnd != null">
        #{shnd,jdbcType=VARCHAR},
      </if>
      <if test="rksj != null">
        #{rksj,jdbcType=VARCHAR},
      </if>
      <if test="bzfs != null">
        #{bzfs,jdbcType=VARCHAR},
      </if>
      <if test="jylx != null">
        #{jylx,jdbcType=VARCHAR},
      </if>
      <if test="wtdwbm != null">
        #{wtdwbm,jdbcType=VARCHAR},
      </if>
      <if test="wtdwmc != null">
        #{wtdwmc,jdbcType=VARCHAR},
      </if>
      <if test="jcsj != null">
        #{jcsj,jdbcType=VARCHAR},
      </if>
      <if test="orgCode != null">
        #{orgCode,jdbcType=VARCHAR},
      </if>
      <if test="cflxbh != null">
        #{cflxbh,jdbcType=VARCHAR},
      </if>
      <if test="cflxmc != null">
        #{cflxmc,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="creator != null" >
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="creatorCode != null" >
        #{creatorCode,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=VARCHAR},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <select id="getMaxCodeById" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT
        	max(yp.YPID)
        from
			TY_YPXXB yp
		<where>
          substr(ypid,0,6)=concat('YP',date_format(NOW(), '%Y'))
        </where>
    </select>



<!-- 用样品单编号获取样品信息 -->
	<select id="getSampleInfoByypdid" resultMap="BaseResultMap" parameterType="java.lang.String">
	
	 SELECT 
    <include refid="Base_Column_List_common"></include>
    from
        TY_YPXXB yp
    <where>
      yp.qydbh = #{qydbh,jdbcType=VARCHAR}
      and yp.status = 1
	</where>
	</select>

</mapper>
