<?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 -->
<mapper namespace="com.xmomen.module.stock.entity.mapper.StockRecordMapper" >
  <!-- 结果映射，将数据库中的字段映射到实体类的属性 -->
  <resultMap id="BaseResultMap" type="com.xmomen.module.stock.entity.StockRecord" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="stock_id" property="stockId" jdbcType="VARCHAR" />
    <result column="change_num" property="changeNum" jdbcType="INTEGER" />
    <result column="chang_type" property="changType" jdbcType="INTEGER" />
    <result column="ref_order_id" property="refOrderId" jdbcType="INTEGER" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />
    <result column="insert_user_id" property="insertUserId" jdbcType="INTEGER" />
    <result column="insert_date" property="insertDate" jdbcType="TIMESTAMP" />
    <result column="update_user_id" property="updateUserId" jdbcType="INTEGER" />
    <result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <!-- SQL片段，用于条件查询 -->
  <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, change_num, chang_type, ref_order_id, remark, insert_user_id, insert_date,
    update_user_id, update_date
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.xmomen.module.stock.entity.StockRecordExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from cd_stock_record
    <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.stock.entity.StockRecordExample" >
    delete from cd_stock_record
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insertSelective" parameterType="com.xmomen.module.stock.entity.StockRecord" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
    <selectKey resultType="java.lang.String" keyProperty="id" order="BEFORE" >
      SELECT replace(UUID(),'-','')
    </selectKey>
    insert into cd_stock_record
    <trim prefix="(" suffix=")" suffixOverrides="," >
      id,
      <if test="stockId != null" >
        stock_id,
      </if>
      <if test="changeNum != null" >
        change_num,
      </if>
      <if test="changType != null" >
        chang_type,
      </if>
      <if test="refOrderId != null" >
        ref_order_id,
      </if>
      <if test="remark != null" >
        remark,
      </if>
      <if test="insertUserId != null" >
        insert_user_id,
      </if>
      <if test="insertDate != null" >
        insert_date,
      </if>
      <if test="updateUserId != null" >
        update_user_id,
      </if>
      <if test="updateDate != null" >
        update_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      #{id,jdbcType=VARCHAR},
      <if test="stockId != null" >
        #{stockId,jdbcType=VARCHAR},
      </if>
      <if test="changeNum != null" >
        #{changeNum,jdbcType=INTEGER},
      </if>
      <if test="changType != null" >
        #{changType,jdbcType=INTEGER},
      </if>
      <if test="refOrderId != null" >
        #{refOrderId,jdbcType=INTEGER},
      </if>
      <if test="remark != null" >
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="insertUserId != null" >
        #{insertUserId,jdbcType=INTEGER},
      </if>
      <if test="insertDate != null" >
        #{insertDate,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUserId != null" >
        #{updateUserId,jdbcType=INTEGER},
      </if>
      <if test="updateDate != null" >
        #{updateDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.xmomen.module.stock.entity.StockRecordExample" resultType="java.lang.Integer" >
    select count(*) from cd_stock_record
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update cd_stock_record
    <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.changeNum != null" >
        change_num = #{record.changeNum,jdbcType=INTEGER},
      </if>
      <if test="record.changType != null" >
        chang_type = #{record.changType,jdbcType=INTEGER},
      </if>
      <if test="record.refOrderId != null" >
        ref_order_id = #{record.refOrderId,jdbcType=INTEGER},
      </if>
      <if test="record.remark != null" >
        remark = #{record.remark,jdbcType=VARCHAR},
      </if>
      <if test="record.insertUserId != null" >
        insert_user_id = #{record.insertUserId,jdbcType=INTEGER},
      </if>
      <if test="record.insertDate != null" >
        insert_date = #{record.insertDate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateUserId != null" >
        update_user_id = #{record.updateUserId,jdbcType=INTEGER},
      </if>
      <if test="record.updateDate != null" >
        update_date = #{record.updateDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
</mapper>