<?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.TDunLogMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TDunLog">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="dun_id" jdbcType="VARCHAR" property="dunId" />
    <result column="dum_by" jdbcType="VARCHAR" property="dumBy" />
    <result column="dum_time" jdbcType="DATE" property="dumTime" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="attachment_url" jdbcType="VARCHAR" property="attachmentUrl" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, dun_id, dum_by, dum_time, remarks, attachment_url, `type`, order_no, create_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_dun_log
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from t_dun_log
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.TDunLog">
    insert into t_dun_log (id, dun_id, dum_by, 
      dum_time, remarks, attachment_url, 
      `type`, order_no, create_time
      )
    values (#{id,jdbcType=VARCHAR}, #{dunId,jdbcType=VARCHAR}, #{dumBy,jdbcType=VARCHAR}, 
      #{dumTime,jdbcType=DATE}, #{remarks,jdbcType=VARCHAR}, #{attachmentUrl,jdbcType=VARCHAR}, 
      #{type,jdbcType=INTEGER}, #{orderNo,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.TDunLog">
    insert into t_dun_log
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="dunId != null">
        dun_id,
      </if>
      <if test="dumBy != null">
        dum_by,
      </if>
      <if test="dumTime != null">
        dum_time,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="attachmentUrl != null">
        attachment_url,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="dunId != null">
        #{dunId,jdbcType=VARCHAR},
      </if>
      <if test="dumBy != null">
        #{dumBy,jdbcType=VARCHAR},
      </if>
      <if test="dumTime != null">
        #{dumTime,jdbcType=DATE},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="attachmentUrl != null">
        #{attachmentUrl,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TDunLog">
    update t_dun_log
    <set>
      <if test="dunId != null">
        dun_id = #{dunId,jdbcType=VARCHAR},
      </if>
      <if test="dumBy != null">
        dum_by = #{dumBy,jdbcType=VARCHAR},
      </if>
      <if test="dumTime != null">
        dum_time = #{dumTime,jdbcType=DATE},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="attachmentUrl != null">
        attachment_url = #{attachmentUrl,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TDunLog">
    update t_dun_log
    set dun_id = #{dunId,jdbcType=VARCHAR},
      dum_by = #{dumBy,jdbcType=VARCHAR},
      dum_time = #{dumTime,jdbcType=DATE},
      remarks = #{remarks,jdbcType=VARCHAR},
      attachment_url = #{attachmentUrl,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=INTEGER},
      order_no = #{orderNo,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <select id="selectByDunId" parameterType="java.lang.String" resultType="com.goafanti.order.bo.TDunLogListBo">
   select
    a.id, a.dun_id as dunId, b.name as dumBy, a.dum_time as dumTime, a.remarks
    from t_dun_log a left join admin b on a.dum_by=b.id
    where dun_id = #{dunId,jdbcType=VARCHAR}
  </select>
  <select id="selectByOrderNo" resultType="com.goafanti.order.bo.TDunLogListBo">
    select a.id, a.dun_id as dunId, b.name as dumBy, a.dum_time as dumTime, a.remarks,a.type,
           a.attachment_url attachmentUrl, c.order_no orderNo,c.buyer_name userName,a.create_time createTime
    from t_dun_log a left join admin b on a.dum_by=b.id left join t_order_mid c on a.order_no =c.order_no
    where c.order_no = #{orderNo} order by a.create_time desc
  </select>
</mapper>