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

  <resultMap id="BaseResultMap" type="com.unis.base.server.entity.WarehouseDoorDO" >
    <result column="CMBH" property="cmbh" jdbcType="VARCHAR" />
    <result column="CFBH" property="cfbh" jdbcType="VARCHAR" />
    <result column="CMMC" property="cmmc" jdbcType="VARCHAR" />
    <result column="CMSL" property="cmsl" jdbcType="DECIMAL" />
    <result column="CMGD" property="cmgd" jdbcType="DECIMAL" />
    <result column="CMKD" property="cmkd" jdbcType="DECIMAL" />
    <result column="STATUS" property="status" jdbcType="DECIMAL" />
    <result column="CREATOR" property="creator" jdbcType="VARCHAR" />
    <result column="CREATOR_CODE" property="creatorCode" jdbcType="VARCHAR" />
    <result column="CREATE_DATE" property="createDate" jdbcType="TIMESTAMP" />
    <result column="REFRESHER" property="refresher" jdbcType="VARCHAR" />
    <result column="REFRESHER_CODE" property="refresherCode" jdbcType="VARCHAR" />
    <result column="REFRESH_TIME" property="refreshTime" jdbcType="TIMESTAMP" />
    <result column="REMARK" property="remark" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="Base_Column_List_common">
    	cf.CMBH, cf.CFBH, cf.CMMC, cf.CMSL, cf.CMGD, cf.CMKD, cf.creator, cf.creator_code ,
    	 cf.refresher, cf.refresher_code,  cf.remark
    </sql>

  <insert id="insert" parameterType="com.unis.base.server.entity.WarehouseDoorDO" >
    insert into D_CMXXSJY
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="cmbh != null" >
        CMBH,
      </if>
      <if test="cfbh != null" >
        CFBH,
      </if>
      <if test="cmmc != null" >
        CMMC,
      </if>
      <if test="cmsl != null" >
        CMSL,
      </if>
      <if test="cmgd != null" >
        CMGD,
      </if>
      <if test="cmkd != null" >
        CMKD,
      </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="refresher != null" >
        REFRESHER,
      </if>
      <if test="refresherCode != null" >
        REFRESHER_CODE,
      </if>
      <if test="refreshTime != null" >
        REFRESH_TIME,
      </if>
      <if test="remark != null" >
        REMARK,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="cmbh != null" >
        #{cmbh,jdbcType=VARCHAR},
      </if>
      <if test="cfbh != null" >
        #{cfbh,jdbcType=VARCHAR},
      </if>
      <if test="cmmc != null" >
        #{cmmc,jdbcType=VARCHAR},
      </if>
      <if test="cmsl != null" >
        #{cmsl,jdbcType=DECIMAL},
      </if>
      <if test="cmgd != null" >
        #{cmgd,jdbcType=DECIMAL},
      </if>
      <if test="cmkd != null" >
        #{cmkd,jdbcType=DECIMAL},
      </if>
      <if test="status != null" >
        #{status,jdbcType=DECIMAL},
      </if>
      <if test="creator != null" >
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="creatorCode != null" >
        #{creatorCode,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="refresher != null" >
        #{refresher,jdbcType=VARCHAR},
      </if>
      <if test="refresherCode != null" >
        #{refresherCode,jdbcType=VARCHAR},
      </if>
      <if test="refreshTime != null" >
        #{refreshTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <!-- 更新仓门信息 -->
  <update id="update" parameterType="com.unis.base.server.entity.WarehouseDoorDO">
    update D_CMXXSJY
    <set>
      <if test="cfbh != null">
        cfbh = #{cfbh,jdbcType=VARCHAR},
      </if>
      <if test="cmmc != null">
        cmmc = #{cmmc,jdbcType=VARCHAR},
      </if>
      <if test="cmsl != null">
        cmsl = #{cmsl,jdbcType=DECIMAL},
      </if>
      <if test="cmgd != null">
        cmgd = #{cmgd,jdbcType=DECIMAL},
      </if>
      <if test="cmkd != null">
        cmkd = #{cmkd,jdbcType=DECIMAL},
      </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>
      CMBH = #{cmbh,jdbcType=VARCHAR}
    </where>
  </update>

  <!-- 根据ID获取仓门信息 -->
  <select id="getWarehouseDoorInfo" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_common" />
    from D_CMXXSJY cf
    <where>
      cf.CMBH = #{cmbh,jdbcType=DECIMAL}
      and cf.status = 1
    </where>
  </select>

  <!-- 根据数据ID获取仓门列表 -->
  <select id="getWarehouseDoorListByCfbh" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_common" />
    from D_CMXXSJY cf
    <where>
      cf.status = 1
      and cf.CFBH = #{cfbh,jdbcType=VARCHAR}
    </where>
  </select>

  <!-- 获取数据最大ID -->
  <select id="getMaxCodeById" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT
    max(cf.CMBH)
    from
      D_CMXXSJY cf
    <where>
      cf.CMBH like CONCAT(#{prefix,jdbcType=VARCHAR},'%')
    </where>
  </select>

  <!--根据仓房代码删除仓门信息列表-->
  <update id="deleteList" parameterType="java.lang.String">
    UPDATE
      D_CMXXSJY cf
    SET
    cf.status = 0
    <where>
      cf.CFBH like CONCAT(#{cfbh,jdbcType=VARCHAR},'%')
    </where>
  </update>
  
  <insert id="insertSelective" parameterType="com.unis.base.server.entity.WarehouseDoorDO" >
    insert into D_CMXXSJY
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="cmbh != null" >
        CMBH,
      </if>
      <if test="cfbh != null" >
        CFBH,
      </if>
      <if test="cmmc != null" >
        CMMC,
      </if>
      <if test="cmsl != null" >
        CMSL,
      </if>
      <if test="cmgd != null" >
        CMGD,
      </if>
      <if test="cmkd != null" >
        CMKD,
      </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="refresher != null" >
        REFRESHER,
      </if>
      <if test="refresherCode != null" >
        REFRESHER_CODE,
      </if>
      <if test="refreshTime != null" >
        REFRESH_TIME,
      </if>
      <if test="remark != null" >
        REMARK,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="cmbh != null" >
        #{cmbh,jdbcType=VARCHAR},
      </if>
      <if test="cfbh != null" >
        #{cfbh,jdbcType=VARCHAR},
      </if>
      <if test="cmmc != null" >
        #{cmmc,jdbcType=VARCHAR},
      </if>
      <if test="cmsl != null" >
        #{cmsl,jdbcType=DECIMAL},
      </if>
      <if test="cmgd != null" >
        #{cmgd,jdbcType=DECIMAL},
      </if>
      <if test="cmkd != null" >
        #{cmkd,jdbcType=DECIMAL},
      </if>
      <if test="status != null" >
        #{status,jdbcType=DECIMAL},
      </if>
      <if test="creator != null" >
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="creatorCode != null" >
        #{creatorCode,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
      <if test="refresher != null" >
        #{refresher,jdbcType=VARCHAR},
      </if>
      <if test="refresherCode != null" >
        #{refresherCode,jdbcType=VARCHAR},
      </if>
      <if test="refreshTime != null" >
        #{refreshTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
</mapper>