<?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.DAjxxsjyDao" >
	
	<resultMap id="BaseResultMap" type="com.unis.base.server.entity.DAjxxsjyDO" >
        <result column="ajbh" property="ajbh" jdbcType="VARCHAR" />
        <result column="ajmc" property="ajmc" jdbcType="VARCHAR" />
        <result column="cfbh" property="cfbh" jdbcType="VARCHAR" />
        <result column="cfmc" property="cfmc" jdbcType="VARCHAR" />
        <result column="ajcd" property="ajcd" jdbcType="VARCHAR" />
        <result column="ajkd" property="ajkd" jdbcType="VARCHAR" />
        <result column="ajgd" property="ajgd" jdbcType="VARCHAR" />
        <result column="ajsjcr" property="ajsjcr" jdbcType="VARCHAR" />
        <result column="ajsjcr01" property="ajsjcr01" jdbcType="VARCHAR" />
        <result column="qyrq" property="qyrq" jdbcType="VARCHAR" />
        <result column="ajzt" property="ajzt" jdbcType="VARCHAR" />
        <result column="ajsyzt" property="ajsyzt" 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" />
        
        <result column="kdmc" property="kdmc" jdbcType="VARCHAR" />
    </resultMap>
    
    <sql id="Base_Column_List_common">
    	aj.ajbh, aj.ajmc, aj.cfbh, aj.ajcd, aj.ajkd, aj.ajgd, aj.ajsjcr,
    	aj.ajsjcr01, aj.lxdh, aj.qyrq, aj.ajzt, aj.ajsyzt, aj.refresh_time, aj.remark
    </sql>
    
    <!-- 根据条件查询廒间信息 -->
    <select id="getDAjxxsjyList" parameterType="com.unis.base.server.entity.DAjxxsjyDO" resultMap="BaseResultMap">
        SELECT 
		<include refid="Base_Column_List_common"></include>, cf.cfmc
 		from
			D_AJXXSJY aj, D_CFXXSJY cf
		<where>
			aj.cfbh = cf.cfbh
			and aj.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="ajbh != null and ajbh != ''" >
	         	and	aj.ajbh LIKE concat(CONCAT('%',#{ajbh,jdbcType=VARCHAR}) ,'%') 
	      	</if>
	      	<!-- 廒间名称 -->
	    	<if test="ajmc != null and ajmc != ''" >
	         	and	aj.ajmc LIKE concat(CONCAT('%',#{ajmc,jdbcType=VARCHAR}) ,'%') 
	      	</if>
	      	<!-- 廒间状态 -->
	    	<if test="ajzt != null and ajzt != ''" >
	         	and	aj.ajzt LIKE concat(CONCAT('%',#{ajzt,jdbcType=VARCHAR}) ,'%') 
	      	</if>
		</where>
		ORDER BY cf.CFBH,aj.ajbh asc
    </select>
    <!-- 添加廒间信息 -->
    <insert id="insert" parameterType="com.unis.base.server.entity.DAjxxsjyDO">
    	insert into D_AJXXSJY
	    <trim prefix="(" suffix=")" suffixOverrides="," >
	      <if test="ajbh != null" >
	        ajbh,
	      </if>
	      <if test="ajmc != null" >
	        ajmc,
	      </if>
	      <if test="cfbh != null" >
	        cfbh,
	      </if>
	      <if test="ajcd != null" >
	        ajcd,
	      </if>
	      <if test="ajkd != null" >
	        ajkd,
	      </if>
	      <if test="ajgd != null" >
	        ajgd,
	      </if>
	      <if test="ajsjcr != null" >
	        ajsjcr,
	      </if>
	      <if test="ajsjcr01 != null" >
	        ajsjcr01,
	      </if>
	      <if test="lxdh != null" >
	        lxdh,
	      </if>
	      <if test="qyrq != null" >
	        qyrq,
	      </if>
	      <if test="ajzt != null" >
	        ajzt,
	      </if>
	      <if test="ajsyzt != null" >
	        ajsyzt,
	      </if>
	      <if test="creator != null" >
	        creator,
	      </if>
	      <if test="creatorCode != null" >
	        creator_code,
	      </if>
	    </trim>
	    <trim prefix="values (" suffix=")" suffixOverrides="," >
	      <if test="ajbh != null" >
	        #{ajbh,jdbcType=VARCHAR},
	      </if>
	      <if test="ajmc != null" >
	        #{ajmc,jdbcType=VARCHAR},
	      </if>
	      <if test="cfbh != null" >
	        #{cfbh,jdbcType=VARCHAR},
	      </if>
	      <if test="ajcd != null" >
	        #{ajcd,jdbcType=VARCHAR},
	      </if>
	      <if test="ajkd != null" >
	        #{ajkd,jdbcType=VARCHAR},
	      </if>
	      <if test="ajgd != null" >
	        #{ajgd,jdbcType=VARCHAR},
	      </if>
	      <if test="ajsjcr != null" >
	        #{ajsjcr,jdbcType=VARCHAR},
	      </if>
	      <if test="ajsjcr01 != null" >
	        #{ajsjcr01,jdbcType=VARCHAR},
	      </if>
	      <if test="lxdh != null" >
	        #{lxdh,jdbcType=VARCHAR},
	      </if>
	      <if test="qyrq != null" >
	        #{qyrq,jdbcType=VARCHAR},
	      </if>
	      <if test="ajzt != null" >
	        #{ajzt,jdbcType=VARCHAR},
	      </if>
	      <if test="ajsyzt != null" >
	        #{ajsyzt,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.DAjxxsjyDO">
    	update D_AJXXSJY
	  	<set>
	  		<if test="ajbh != null">
	  			ajbh = #{ajbh,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajmc != null">
	  			ajmc = #{ajmc,jdbcType=VARCHAR},
	  		</if>
	  		<if test="cfbh != null">
	  			cfbh = #{cfbh,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajcd != null">
	  			ajcd = #{ajcd,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajkd != null">
	  			ajkd = #{ajkd,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajgd != null">
	  			ajgd = #{ajgd,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajsjcr != null">
	  			ajsjcr = #{ajsjcr,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajsjcr01 != null">
	  			ajsjcr01 = #{ajsjcr01,jdbcType=VARCHAR},
	  		</if>
	  		<if test="lxdh != null">
	  			lxdh = #{lxdh,jdbcType=VARCHAR},
	  		</if>
	  		<if test="qyrq != null">
	  			qyrq = #{qyrq,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajzt != null">
	  			ajzt = #{ajzt,jdbcType=VARCHAR},
	  		</if>
	  		<if test="ajsyzt != null">
	  			ajsyzt = #{ajsyzt,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>
	  		ajbh = #{ajbh,jdbcType=VARCHAR}
	  	</where>
    </update>
    
    <select id="getDAjxxsjyInfo" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT 
		<include refid="Base_Column_List_common"></include>
 		from
			D_AJXXSJY aj
		<where>
			aj.status = 1
			and aj.ajbh = #{ajbh,jdbcType=VARCHAR}
		</where>
    </select>
    
    <select id="getMaxCodeById" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT 
        	max(aj.AJBH) 
        from 
			D_AJXXSJY aj
    </select>

	<select id="getGranaryByajbh" parameterType="String" resultMap="BaseResultMap">
		select * from D_AJXXSJY WHERE AJBH = #{ajbh}
	</select>
</mapper>
