<?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.platform.yijia.dao.IntegralOrderMapper">
  <!--返回结果-->
  <resultMap id="BaseResultMap" type="com.platform.yijia.pojo.IntegralOrder">
    <id     column="id"                 jdbcType="INTEGER"      property="id" />
    <result column="integral_order_no"  jdbcType="VARCHAR"      property="integralOrderNo" />
    <result column="wares_type"         jdbcType="VARCHAR"      property="waresType" />
    <result column="wares_name"         jdbcType="VARCHAR"      property="waresName" />
    <result column="wares_id"           jdbcType="INTEGER"      property="waresId" />
    <result column="wares_pic"          jdbcType="VARCHAR"      property="waresPic" />
    <result column="wares_detail"       jdbcType="VARCHAR"      property="waresDetail" />
    <result column="union_id"           jdbcType="VARCHAR"      property="unionId" />
    <result column="customer_name"      jdbcType="VARCHAR"      property="customerName" />
    <result column="exchange_num"       jdbcType="INTEGER"      property="exchangeNum" />
    <result column="exchange_time"      jdbcType="TIMESTAMP"    property="exchangeTime" />
    <result column="status"             jdbcType="VARCHAR"      property="status" />
    <result column="integral"           jdbcType="INTEGER"      property="integral" />
    <result column="station_id"         jdbcType="INTEGER"      property="stationId" />
    <result column="printer_status"     jdbcType="VARCHAR"      property="printerStatus" />
    <result column="mobile_phone"       jdbcType="VARCHAR"      property="mobilePhone" />
  </resultMap>

  <!--查询列-->
  <sql id="Base_Column_List">
    id, integral_order_no, wares_type, wares_name, wares_name, wares_id, wares_pic, wares_detail, union_id, customer_name, exchange_num, exchange_time,
    status, integral, station_id, printer_status, mobile_phone
  </sql>

  <!--查询个人积分订单信息-->
  <select id="getUserIntegralOrderList" resultMap="BaseResultMap" parameterType="com.platform.yijia.pojo.IntegralOrder">
    SELECT
        <include refid="Base_Column_List" />
    FROM integral_order
    <where>
      <if test="unionId !=null and unionId !=''">
        union_id = #{unionId}
      </if>
      <if test="stationId !=null and stationId !=''">
        AND station_id = #{stationId}
      </if>
    </where>
    ORDER BY exchange_time DESC
  </select>

  <!-- 更新积分订单-->
  <update id="updateIntegralOrder" parameterType="com.platform.yijia.pojo.IntegralOrder">
    UPDATE
        integral_order
    <set>
      <if test="printerStatus !=null">
        printer_status = #{printerStatus},
      </if>
    </set>
    <where>
      <if test="integralOrderNo !=null and integralOrderNo != ''">
        integral_order_no = #{integralOrderNo}
      </if>
    </where>
  </update>


  <!--新增积分订单-->
  <insert id="insertIntegralOrder" parameterType="com.platform.yijia.pojo.IntegralOrder">
    INSERT INTO integral_order
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="integralOrderNo !=null">
        integral_order_no,
      </if>
      <if test="waresType !=null">
        wares_type,
      </if>
      <if test="waresName !=null">
        wares_name,
      </if>
      <if test="waresId !=null">
        wares_id,
      </if>
      <if test="waresPic !=null">
        wares_pic,
      </if>
      <if test="waresDetail !=null">
        wares_detail,
      </if>
      <if test="unionId !=null">
        union_id,
      </if>
      <if test="customerName !=null">
        customer_name,
      </if>
      <if test="exchangeNum !=null">
        exchange_num,
      </if>
      <if test="exchangeTime !=null">
        exchange_time,
      </if>
      <if test="status !=null">
        status,
      </if>
      <if test="integral !=null">
        integral,
      </if>
      <if test="stationId !=null">
        station_id,
      </if>
      <if test="stationName !=null">
        station_name,
      </if>
      <if test="printerStatus !=null">
        printer_status,
      </if>
      <if test="mobilePhone !=null">
        mobile_phone,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="integralOrderNo !=null">
        #{integralOrderNo},
      </if>
      <if test="waresType !=null">
        #{waresType},
      </if>
      <if test="waresName !=null">
        #{waresName},
      </if>
      <if test="waresId !=null">
        #{waresId},
      </if>
      <if test="waresPic !=null">
        #{waresPic},
      </if>
      <if test="waresDetail !=null">
        #{waresDetail},
      </if>
      <if test="unionId !=null">
        #{unionId},
      </if>
      <if test="customerName !=null">
        #{customerName},
      </if>
      <if test="exchangeNum !=null">
        #{exchangeNum},
      </if>
      <if test="exchangeTime !=null">
        #{exchangeTime},
      </if>
      <if test="status !=null">
        #{status},
      </if>
      <if test="integral !=null">
        #{integral},
      </if>
      <if test="stationId !=null">
        #{stationId},
      </if>
      <if test="stationName !=null">
        #{stationName},
      </if>
      <if test="printerStatus !=null">
        #{printerStatus},
      </if>
      <if test="mobilePhone !=null">
        #{mobilePhone},
      </if>
    </trim>
  </insert>

</mapper>
