<?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.DHwxxsjyDao" >
	
	<resultMap id="BaseResultMap" type="com.unis.base.server.entity.DHwxxsjyDO" >
        <result column="hwbh" property="hwbh" jdbcType="VARCHAR" />
        <result column="hwmc" property="hwmc" jdbcType="VARCHAR" />
        <result column="cfbh" property="cfbh" jdbcType="VARCHAR" />
        <result column="cfmc" property="cfmc" jdbcType="VARCHAR" />
        <result column="qyrq" property="qyrq" jdbcType="VARCHAR" />
        <result column="hwzt" property="hwzt" jdbcType="VARCHAR" />
        <result column="hwcr" property="hwcr" jdbcType="VARCHAR" />
        
        <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" />
    </resultMap>
    
    <sql id="Base_Column_List_common">
    	hw.hwbh,hw.hwmc, hw.cfbh, hw.qyrq, hw.hwzt, hw.hwcr, hw.refresh_time, hw.remark
    </sql>
    
    <!-- 根据条件查询廒间信息 -->
    <select id="getDHwxxsjyList" parameterType="com.unis.base.server.entity.DHwxxsjyDO" resultMap="BaseResultMap">
        SELECT 
		<include refid="Base_Column_List_common"></include>, cf.cfmc
 		from
			D_HWXXSJY hw , D_CFXXSJY cf
		<where>
			hw.cfbh = cf.cfbh
			and hw.status = 1
			<!-- 仓房编号 -->
	    	<if test="cfbh != null and cfbh != ''" >
	         	and	cf.cfbh LIKE concat(CONCAT('%',#{cfbh,jdbcType=VARCHAR}) ,'%')
	      	</if>
	      	<!-- 仓房名称 -->
	    	<if test="cfmc != null and cfmc != ''" >
	         	and	cf.cfmc LIKE concat(CONCAT('%',#{cfmc,jdbcType=VARCHAR}) ,'%')
	      	</if>
	      	<!-- 货位编号 -->
	    	<if test="hwbh != null and hwbh != ''" >
	         	and	hw.hwbh LIKE concat(CONCAT('%',#{hwbh,jdbcType=VARCHAR}) ,'%') 
	      	</if>
	      	<!-- 货位名称 -->
	    	<if test="hwmc != null and hwmc != ''" >
	         	and	hw.hwmc LIKE concat(CONCAT('%',#{hwmc,jdbcType=VARCHAR}) ,'%') 
	      	</if>
	      	<!-- 货位状态 -->
	    	<if test="hwzt != null and hwzt != ''" >
	         	and	hw.hwzt LIKE concat(CONCAT('%',#{hwzt,jdbcType=VARCHAR}) ,'%') 
	      	</if>
		</where>
		ORDER BY hw.hwbh,cf.cfbh asc
    </select>
    <!-- 添加廒间信息 -->
    <insert id="insert" parameterType="com.unis.base.server.entity.DHwxxsjyDO">
    	insert into D_HWXXSJY
	    <trim prefix="(" suffix=")" suffixOverrides="," >
	      <if test="hwbh != null" >
	        hwbh,
	      </if>
	      <if test="hwmc != null" >
	        hwmc,
	      </if>
	      <if test="cfbh != null" >
			  cfbh,
	      </if>
	      <if test="qyrq != null" >
	        qyrq,
	      </if>
	      <if test="hwzt != null" >
	        hwzt,
	      </if>
	      <if test="hwcr != null" >
	        hwcr,
	      </if>
	      <if test="creator != null" >
	        creator,
	      </if>
	      <if test="creatorCode != null" >
	        creator_code,
	      </if>
	    </trim>
	    <trim prefix="values (" suffix=")" suffixOverrides="," >
	      <if test="hwbh != null" >
	        #{hwbh,jdbcType=VARCHAR},
	      </if>
	      <if test="hwmc != null" >
	        #{hwmc,jdbcType=VARCHAR},
	      </if>
	      <if test="cfbh != null" >
	        #{cfbh,jdbcType=VARCHAR},
	      </if>
	      <if test="qyrq != null" >
	        #{qyrq,jdbcType=VARCHAR},
	      </if>
	      <if test="hwzt != null" >
	        #{hwzt,jdbcType=VARCHAR},
	      </if>
	      <if test="hwcr != null" >
	        #{hwcr,jdbcType=VARCHAR},
	      </if>
	      <if test="creator != null" >
	        #{creator,jdbcType=VARCHAR},
	      </if>
	      <if test="creatorCode != null" >
	        #{creatorCode,jdbcType=VARCHAR},
	      </if>
	    </trim>
    </insert>
    
    <update id="update" parameterType="com.unis.base.server.entity.DHwxxsjyDO">
    	update D_HWXXSJY
	  	<set>
	  		<if test="hwbh != null">
	  			hwbh = #{hwbh,jdbcType=VARCHAR},
	  		</if>
	  		<if test="hwmc != null">
	  			hwmc = #{hwmc,jdbcType=VARCHAR},
	  		</if>
	  		<if test="cfbh != null">
				cfbh = #{cfbh,jdbcType=VARCHAR},
	  		</if>
	  		<if test="qyrq != null">
	  			qyrq = #{qyrq,jdbcType=VARCHAR},
	  		</if>
	  		<if test="hwzt != null">
	  			hwzt = #{hwzt,jdbcType=VARCHAR},
	  		</if>
	  		<if test="hwcr != null">
	  			hwcr = #{hwcr,jdbcType=VARCHAR},
	  		</if>
	  		<if test="status != null">
	  			status = #{status,jdbcType=VARCHAR},
	  		</if>
	  		<if test="refresher != null">
	  			refresher = #{refresher,jdbcType=VARCHAR},
	  		</if>
	  		<if test="refresherCode != null">
	  			refresher_code = #{refresherCode,jdbcType=VARCHAR},
	  		</if>
	  		refresh_time = NOW()
	  	</set>
	  	<where>
	  		hwbh = #{hwbh,jdbcType=VARCHAR}
	  	</where>
    </update>
    
    <select id="getDHwxxsjyInfo" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT 
		<include refid="Base_Column_List_common"></include>,cf.cfmc
 		from
			D_HWXXSJY hw , D_CFXXSJY cf
		<where>
			hw.status = 1
			and hw.cfbh = cf.cfbh
			and hw.hwbh = #{hwbh,jdbcType=VARCHAR}
		</where>
    </select>
    
    <select id="getMaxCodeById" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT 
        	max(hw.hwbh) 
        from 
			D_HWXXSJY hw
    </select>
</mapper>
