<?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.TaskLogMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TaskLog">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="task_id" jdbcType="INTEGER" property="taskId" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="stop_id" jdbcType="INTEGER" property="stopId" />
  </resultMap>
  <sql id="Base_Column_List">
    id, content, create_time, task_id, aid, stop_id
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from task_log
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from task_log
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TaskLog" useGeneratedKeys="true">
    insert into task_log (content, create_time, task_id,
      aid, stop_id)
    values (#{content,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{taskId,jdbcType=INTEGER},
      #{aid,jdbcType=VARCHAR}, #{stopId,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TaskLog" useGeneratedKeys="true">
    insert into task_log
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="content != null">
        content,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="taskId != null">
        task_id,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="stopId != null">
        stop_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskId != null">
        #{taskId,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="stopId != null">
        #{stopId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TaskLog">
    update task_log
    <set>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="taskId != null">
        task_id = #{taskId,jdbcType=INTEGER},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="stopId != null">
        stop_id = #{stopId,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TaskLog">
    update task_log
    set content = #{content,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      task_id = #{taskId,jdbcType=INTEGER},
      aid = #{aid,jdbcType=VARCHAR},
      stop_id = #{stopId,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectTaskLogList" resultType="com.goafanti.order.bo.TaskLogBo">
    select a.id,a.task_id taskId,a.content,date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createTimes,b.name as aName,
           a.stop_id stopId ,c.reason
    from task_log a left join admin b on a.aid=b.id left join task_stop c on a.stop_id =c.id
    where a.task_id= #{id,jdbcType=INTEGER} order by a.create_time
  </select>
</mapper>
