<?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.goafanti.common.dao.TOrderChangeMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderChange">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="creater_id" jdbcType="VARCHAR" property="createrId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="change_comment" jdbcType="VARCHAR" property="changeComment" />
    <result column="change_status" jdbcType="INTEGER" property="changeStatus" />
    <result column="delete_sign" jdbcType="INTEGER" property="deleteSign" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <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 close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    id, order_no, creater_id, create_time, change_comment, change_status, delete_sign
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.TOrderChangeExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_order_change
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from t_order_change
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    delete from t_order_change
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.TOrderChangeExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    delete from t_order_change
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TOrderChange">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    insert into t_order_change (id, order_no, creater_id, 
      create_time, change_comment, change_status, 
      delete_sign)
    values (#{id,jdbcType=VARCHAR}, #{orderNo,jdbcType=VARCHAR}, #{createrId,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{changeComment,jdbcType=VARCHAR}, #{changeStatus,jdbcType=INTEGER}, 
      #{deleteSign,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TOrderChange">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    insert into t_order_change
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="createrId != null">
        creater_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="changeComment != null">
        change_comment,
      </if>
      <if test="changeStatus != null">
        change_status,
      </if>
      <if test="deleteSign != null">
        delete_sign,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="createrId != null">
        #{createrId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="changeComment != null">
        #{changeComment,jdbcType=VARCHAR},
      </if>
      <if test="changeStatus != null">
        #{changeStatus,jdbcType=INTEGER},
      </if>
      <if test="deleteSign != null">
        #{deleteSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.TOrderChangeExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    select count(*) from t_order_change
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    update t_order_change
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.createrId != null">
        creater_id = #{record.createrId,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.changeComment != null">
        change_comment = #{record.changeComment,jdbcType=VARCHAR},
      </if>
      <if test="record.changeStatus != null">
        change_status = #{record.changeStatus,jdbcType=INTEGER},
      </if>
      <if test="record.deleteSign != null">
        delete_sign = #{record.deleteSign,jdbcType=INTEGER},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    update t_order_change
    set id = #{record.id,jdbcType=VARCHAR},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      creater_id = #{record.createrId,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      change_comment = #{record.changeComment,jdbcType=VARCHAR},
      change_status = #{record.changeStatus,jdbcType=INTEGER},
      delete_sign = #{record.deleteSign,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderChange">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    update t_order_change
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="createrId != null">
        creater_id = #{createrId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="changeComment != null">
        change_comment = #{changeComment,jdbcType=VARCHAR},
      </if>
      <if test="changeStatus != null">
        change_status = #{changeStatus,jdbcType=INTEGER},
      </if>
      <if test="deleteSign != null">
        delete_sign = #{deleteSign,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderChange">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Aug 16 09:06:39 CST 2019.
    -->
    update t_order_change
    set order_no = #{orderNo,jdbcType=VARCHAR},
      creater_id = #{createrId,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      change_comment = #{changeComment,jdbcType=VARCHAR},
      change_status = #{changeStatus,jdbcType=INTEGER},
      delete_sign = #{deleteSign,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="selectOrderChange" parameterType="java.lang.String" resultType="com.goafanti.order.bo.OrderChangeBo">
	 select
		a.id as changeId,
		a.order_no as orderNo,
		date_format( a.create_time, '%Y-%m-%d %H:%i:%S' ) as createTime,
		a.change_comment as changeComment,
		a.change_status as changeStatus,
		b.name as creater
	from
		t_order_change a left join admin b on
		a.creater_id = b.id
	where 
		a.order_no = #{orderNo,jdbcType=VARCHAR} and a.delete_sign = 0
  </select>
  
  <select id="selectCountByStatus" resultType="java.lang.Integer">
	select
		count( 0 )
	from
		t_order_change
	where
	order_no = #{orderNo,jdbcType=VARCHAR}
	and delete_sign = 0
	and change_status = #{changeStatus,jdbcType=INTEGER}
  </select>
</mapper>