<?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.younike.system.mapper.UjdChangeRecordMapper">
  <resultMap id="UjdChangeRecordResult" type="UjdChangeRecord">
    <id column="ujd_change_record_id" property="ujdChangeRecordId" />
    <result column="change_qty" property="changeQty" />
    <result column="change_type" property="changeType" />
    <result column="change_property" property="changeProperty" />
    <result column="merchant_id" property="merchantId" />
    <result column="merchant_index" property="merchantIndex" />
    <result column="merchant_name" property="merchantName" />
    <result column="goods_id" property="goodsId" />
    <result column="goods_index" property="goodsIndex" />
    <result column="goods_name" property="goodsName" />
    <result column="trade_no" property="tradeNo" />
    <result column="change_time" property="changeTime" />
    <result column="del_flag" property="delFlag" />
    <result column="create_by" property="createBy" />
    <result column="create_time" property="createTime" />
    <result column="update_by" property="updateBy" />
    <result column="update_time" property="updateTime" />
    <result column="remark" property="remark" />
  </resultMap>

  <sql id="Base_Column_List">
    select ujd_change_record_id, change_qty, change_type, change_property, merchant_id, merchant_index, merchant_name, goods_id, goods_index, goods_name, trade_no, change_time, del_flag, create_by, create_time, update_by, update_time, remark from ujd_change_record
  </sql>

  <delete id="deleteByUjdChangeRecordId" parameterType="java.lang.Long">
    delete from ujd_change_record where ujd_change_record_id = #{ujdChangeRecordId}
  </delete>

  <insert id="insertUjdChangeRecord" parameterType="UjdChangeRecord" useGeneratedKeys="true" keyProperty="ujdChangeRecordId">
    insert into ujd_change_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="changeQty != null">change_qty,</if>
      <if test="changeType != null and changeType != ''">change_type,</if>
      <if test="changeProperty != null and changeProperty != ''">change_property,</if>
      <if test="merchantId != null">merchant_id,</if>
      <if test="merchantIndex != null and merchantIndex != ''">merchant_index,</if>
      <if test="merchantName != null and merchantName != ''">merchant_name,</if>
      <if test="goodsId != null">goods_id,</if>
      <if test="goodsIndex != null and goodsIndex != ''">goods_index,</if>
      <if test="goodsName != null and goodsName != ''">goods_name,</if>
      <if test="tradeNo != null and tradeNo != ''">trade_no,</if>
      <if test="changeTime != null">change_time,</if>
      <if test="delFlag != null">del_flag,</if>
      <if test="createBy != null">create_by,</if>
      <if test="createTime != null">create_time,</if>
      <if test="updateBy != null">update_by,</if>
      <if test="updateTime != null">update_time,</if>
      <if test="remark != null and remark != ''">remark,</if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="changeQty != null">#{changeQty},</if>
      <if test="changeType != null and changeType != ''">#{changeType},</if>
      <if test="changeProperty != null and changeProperty != ''">#{changeProperty},</if>
      <if test="merchantId != null">#{merchantId},</if>
      <if test="merchantIndex != null and merchantIndex != ''">#{merchantIndex},</if>
      <if test="merchantName != null and merchantName != ''">#{merchantName},</if>
      <if test="goodsId != null">#{goodsId},</if>
      <if test="goodsIndex != null and goodsIndex != ''">#{goodsIndex},</if>
      <if test="goodsName != null and goodsName != ''">#{goodsName},</if>
      <if test="tradeNo != null and tradeNo != ''">#{tradeNo},</if>
      <if test="changeTime != null">#{changeTime},</if>
      <if test="delFlag != null">#{delFlag},</if>
      <if test="createBy != null">#{createBy},</if>
      <if test="createTime != null">#{createTime},</if>
      <if test="updateBy != null">#{updateBy},</if>
      <if test="updateTime != null">#{updateTime},</if>
      <if test="remark != null and remark != ''">#{remark},</if>
    </trim>
  </insert>

  <update id="updateUjdChangeRecord" parameterType="com.younike.system.domain.UjdChangeRecord">
    update ujd_change_record
    <trim prefix="SET" suffixOverrides=",">
      <if test="changeQty != null">change_qty = #{changeQty},</if>
      <if test="changeType != null and changeType != ''">change_type = #{changeType},</if>
      <if test="changeProperty != null and changeProperty != ''">change_property = #{changeProperty},</if>
      <if test="merchantId != null">merchant_id = #{merchantId},</if>
      <if test="merchantIndex != null and merchantIndex != ''">merchant_index = #{merchantIndex},</if>
      <if test="merchantName != null and merchantName != ''">merchant_name = #{merchantName},</if>
      <if test="goodsId != null">goods_id = #{goodsId},</if>
      <if test="goodsIndex != null and goodsIndex != ''">goods_index = #{goodsIndex},</if>
      <if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
      <if test="tradeNo != null and tradeNo != ''">trade_no = #{tradeNo},</if>
      <if test="changeTime != null">change_time = #{changeTime},</if>
      <if test="delFlag != null">del_flag = #{delFlag},</if>
      <if test="createBy != null">create_by = #{createBy},</if>
      <if test="createTime != null">create_time = #{createTime},</if>
      <if test="updateBy != null">update_by = #{updateBy},</if>
      <if test="updateTime != null">update_time = #{updateTime},</if>
      <if test="remark != null and remark != ''">remark = #{remark},</if>
    </trim>
    where ujd_change_record_id = #{ujdChangeRecordId}
  </update>

  <select id="selectUjdChangeRecordList" parameterType="UjdChangeRecord" resultMap="UjdChangeRecordResult">
    <include refid="Base_Column_List"/>
    <where>
      del_flag = '0'
      <if test="merchantId != null"> and merchant_id = #{merchantId}</if>
      <if test="merchantIndex != null  and merchantIndex != ''"> and merchant_index like concat('%', #{merchantIndex}, '%')</if>
      <if test="merchantName != null  and merchantName != ''"> and merchant_name like concat('%', #{merchantName}, '%')</if>
      <if test="goodsId != null"> and goods_id = #{goodsId}</if>
      <if test="goodsIndex != null  and goodsIndex != ''"> and goods_index = #{goodsIndex}</if>
      <if test="goodsName != null  and goodsName != ''"> and goods_name = #{goodsName}</if>
      <if test="changeType != null  and changeType != ''"> and change_type = #{changeType}</if>
      <if test="changeTimeStart != null  and changeTimeStart != ''"> and change_time >= #{changeTimeStart}</if>
      <if test="changeTimeEnd != null  and changeTimeEnd != ''"> and change_time &lt;= #{changeTimeEnd}</if>
    </where>
  </select>

  <select id="pageList" parameterType="UjdChangeRecord" resultMap="UjdChangeRecordResult">
    <include refid="Base_Column_List"/>
    <where>
      del_flag = '0'
      <if test="merchantId != null"> and merchant_id = #{merchantId}</if>
      <if test="merchantIndex != null  and merchantIndex != ''"> and merchant_index like concat('%', #{merchantIndex}, '%')</if>
      <if test="merchantName != null  and merchantName != ''"> and merchant_name like concat('%', #{merchantName}, '%')</if>
      <if test="goodsId != null"> and goods_id = #{goodsId}</if>
      <if test="goodsIndex != null  and goodsIndex != ''"> and goods_index = #{goodsIndex}</if>
      <if test="goodsName != null  and goodsName != ''"> and goods_name = #{goodsName}</if>
      <if test="changeType != null  and changeType != ''"> and change_type = #{changeType}</if>
      <if test="changeTimeStart != null  and changeTimeStart != ''"> and change_time >= #{changeTimeStart}</if>
      <if test="changeTimeEnd != null  and changeTimeEnd != ''"> and change_time &lt;= #{changeTimeEnd}</if>
    </where>
    ORDER BY create_time DESC
  </select>

  <select id="ujdlist" parameterType="UjdChangeRecord" resultMap="UjdChangeRecordResult">
    select u.ujd_change_record_id, u.change_qty, u.change_type, u.change_property, u.merchant_id, u.merchant_index, u.merchant_name, u.goods_id, u.goods_index, u.goods_name, u.trade_no, u.change_time, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time, u.remark from ujd_change_record u
    <where> del_flag=0
      <if test="merchantId != null and merchantId != ''">and merchant_id = #{merchantId}</if>
      <if test="merchantIndex != null and merchantIndex != ''">and merchant_index like concat('%',#{merchantIndex},'%')</if>
      <if test="merchantName != null and merchantName != ''">and merchant_name like concat('%',#{merchantName},'%')</if>
      <if test="goodsId != null and goodsId != ''">and goods_id = #{goodsId}</if>
    <if test="goodsIndex != null and goodsIndex !='' ">and goods_index like concat('%',#{goodsIndex},'%') </if>
    <if test="goodsName != null and goodsName != ''">and goods_name like concat('%',#{goodsName},'%')</if>
    <if test="changeType != null and changeType != ''">and change_type like concat('%',#{changeType},'%')</if>
      <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
        and date_format(u.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
      </if>
      <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
        and date_format(u.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
      </if>
    </where>

  </select>

</mapper>
