<?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.AchievementOrderLogMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.AchievementOrderLog" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="achievement_order_id" property="achievementOrderId" jdbcType="VARCHAR" />
    <result column="record_time" property="recordTime" jdbcType="TIMESTAMP" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="operator" property="operator" jdbcType="VARCHAR" />
    <result column="comment" property="comment" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, achievement_order_id, record_time, status, operator, comment
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from achievement_order_log
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from achievement_order_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.AchievementOrderLog" >
    insert into achievement_order_log (id, achievement_order_id, record_time, 
      status, operator, comment
      )
    values (#{id,jdbcType=VARCHAR}, #{achievementOrderId,jdbcType=VARCHAR}, #{recordTime,jdbcType=TIMESTAMP}, 
      #{status,jdbcType=INTEGER}, #{operator,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.AchievementOrderLog" >
    insert into achievement_order_log
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="achievementOrderId != null" >
        achievement_order_id,
      </if>
      <if test="recordTime != null" >
        record_time,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="operator != null" >
        operator,
      </if>
      <if test="comment != null" >
        comment,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="achievementOrderId != null" >
        #{achievementOrderId,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        #{status,jdbcType=INTEGER},
      </if>
      <if test="operator != null" >
        #{operator,jdbcType=VARCHAR},
      </if>
      <if test="comment != null" >
        #{comment,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.AchievementOrderLog" >
    update achievement_order_log
    <set >
      <if test="achievementOrderId != null" >
        achievement_order_id = #{achievementOrderId,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null" >
        record_time = #{recordTime,jdbcType=TIMESTAMP},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="operator != null" >
        operator = #{operator,jdbcType=VARCHAR},
      </if>
      <if test="comment != null" >
        comment = #{comment,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.AchievementOrderLog" >
    update achievement_order_log
    set achievement_order_id = #{achievementOrderId,jdbcType=VARCHAR},
      record_time = #{recordTime,jdbcType=TIMESTAMP},
      status = #{status,jdbcType=INTEGER},
      operator = #{operator,jdbcType=VARCHAR},
      comment = #{comment,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
   <select id="selectAchievementOrderLogByAchievementOrderId" parameterType="java.lang.String" resultType="com.goafanti.achievement.bo.AchievementOrderLogUserBo">
  	select 
  		record_time as recordTime, status, comment
  	from achievement_order_log
  	where achievement_order_id = #{achievementOrderId,jdbcType=VARCHAR}
  	order by record_time 
  </select>
  
  <select id="selectAdminAchievementOrderLogByAchievementOrderId" parameterType="java.lang.String" resultType="com.goafanti.achievement.bo.AchievementOrderLogAdminBo">
  	select 
  		aol.record_time as recordTime, aol.status, aol.comment,
  		a.name as operator
  	from achievement_order_log aol
  	left join admin a on a.id = aol.operator
  	where aol.achievement_order_id = #{achievementOrderId,jdbcType=VARCHAR}
  	order by aol.record_time 
  </select>
</mapper>