<?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.xmomen.module.stockdaily.entity.mapper.StockDailyMapper" >
  <!-- 定义结果映射 -->
  <resultMap id="BaseResultMap" type="com.xmomen.module.stockdaily.entity.StockDaily" >
    <!-- 定义主键 -->
    <id column="id" property="id" jdbcType="VARCHAR" />
    <!-- 定义其他字段 -->
    <result column="stock_id" property="stockId" jdbcType="VARCHAR" />
    <result column="item_id" property="itemId" jdbcType="VARCHAR" />
    <result column="old_stock_num" property="oldStockNum" jdbcType="INTEGER" />
    <result column="in_num" property="inNum" jdbcType="INTEGER" />
    <result column="return_in_num" property="returnInNum" jdbcType="INTEGER" />
    <result column="out_num" property="outNum" jdbcType="INTEGER" />
    <result column="damaged_num" property="damagedNum" jdbcType="INTEGER" />
    <result column="verification_num" property="verificationNum" jdbcType="INTEGER" />
    <result column="new_stock_num" property="newStockNum" jdbcType="INTEGER" />
    <result column="daily_date" property="dailyDate" jdbcType="DATE" />
    <result column="insert_date" propeVrty="insertDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <!-- 定义查询条件 -->
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <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.valid" >
          <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" >
    id, stock_id, item_id, old_stock_num, in_num, return_in_num, out_num, damaged_num, 
    verification_num, new_stock_num, daily_date, insert_date
  </sql>
  <!-- 根据条件查询 -->
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.xmomen.module.stockdaily.entity.StockDailyExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cd_stock_daily
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <!-- 根据条件删除 -->
  <delete id="deleteByExample" parameterType="com.xmomen.module.stockdaily.entity.StockDailyExample" >
    delete from cd_stock_daily
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <!-- 插入数据 -->
  <insert id="insertSelective" parameterType="com.xmomen.module.stockdaily.entity.StockDaily" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
    <selectKey resultType="java.lang.String" keyProperty="id" order="BEFORE" >
      SELECT replace(UUID(),'-','')
    </selectKey>
    insert into cd_stock_daily
    <trim prefix="(" suffix=")" suffixOverrides="," >
      id,
      <if test="stockId != null" >
        stock_id,
      </if>
      <if test="itemId != null" >
        item_id,
      </if>
      <if test="oldStockNum != null" >
        old_stock_num,
      </if>
      <if test="inNum != null" >
        in_num,
      </if>
      <if test="returnInNum != null" >
        return_in_num,
      </if>
      <if test="outNum != null" >
        out_num,
      </if>
      <if test="damagedNum != null" >
        damaged_num,
      </if>
      <if test="verificationNum != null" >
        verification_num,
      </if>
      <if test="newStockNum != null" >
        new_stock_num,
      </if>
      <if test="dailyDate != null" >
        daily_date,
      </if>
      <if test="insertDate != null" >
        insert_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      #{id,jdbcType=VARCHAR},
      <if test="stockId != null" >
        #{stockId,jdbcType=VARCHAR},
      </if>
      <if test="itemId != null" >
        #{itemId,jdbcType=VARCHAR},
      </if>
      <if test="oldStockNum != null" >
        #{oldStockNum,jdbcType=INTEGER},
      </if>
      <if test="inNum != null" >
        #{inNum,jdbcType=INTEGER},
      </if>
      <if test="returnInNum != null" >
        #{returnInNum,jdbcType=INTEGER},
      </if>
      <if test="outNum != null" >
        #{outNum,jdbcType=INTEGER},
      </if>
      <if test="damagedNum != null" >
        #{damagedNum,jdbcType=INTEGER},
      </if>
      <if test="verificationNum != null" >
        #{verificationNum,jdbcType=INTEGER},
      </if>
      <if test="newStockNum != null" >
        #{newStockNum,jdbcType=INTEGER},
      </if>
      <if test="dailyDate != null" >
        #{dailyDate,jdbcType=DATE},
      </if>
      <if test="insertDate != null" >
        #{insertDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <!-- 根据条件统计 -->
  <select id="countByExample" parameterType="com.xmomen.module.stockdaily.entity.StockDailyExample" resultType="java.lang.Integer" >
    select count(*) from cd_stock_daily
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <!-- 根据条件更新 -->
  <update id="updateByExampleSelective" parameterType="map" >
    update cd_stock_daily
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.stockId != null" >
        stock_id = #{record.stockId,jdbcType=VARCHAR},
      </if>
      <if test="record.itemId != null" >
        item_id = #{record.itemId,jdbcType=VARCHAR},
      </if>
      <if test="record.oldStockNum != null" >
        old_stock_num = #{record.oldStockNum,jdbcType=INTEGER},
      </if>
      <if test="record.inNum != null" >
        in_num = #{record.inNum,jdbcType=INTEGER},
      </if>
      <if test="record.returnInNum != null" >
        return_in_num = #{record.returnInNum,jdbcType=INTEGER},
      </if>
      <if test="record.outNum != null" >
        out_num = #{record.outNum,jdbcType=INTEGER},
      </if>
      <if test="record.damagedNum != null" >
        damaged_num = #{record.damagedNum,jdbcType=INTEGER},
      </if>
      <if test="record.verificationNum != null" >
        verification_num = #{record.verificationNum,jdbcType=INTEGER},
      </if>
      <if test="record.newStockNum != null" >
        new_stock_num = #{record.newStockNum,jdbcType=INTEGER},
      </if>
      <if test="record.dailyDate != null" >
        daily_date = #{record.dailyDate,jdbcType=DATE},
      </if>
      <if test="record.insertDate != null" >
        insert_date = #{record.insertDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
</mapper>