<?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.TOrderExamineMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.TOrderExamine">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="aname" jdbcType="VARCHAR" property="aname" />
  </resultMap>
  <sql id="Base_Column_List">
    id, order_no, aid, `status`, create_time, aname
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_order_examine
    where id = #{id,jdbcType=INTEGER}
  </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_order_examine
    where id = #{id,jdbcType=INTEGER}
  </delete>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderExamine" useGeneratedKeys="true">
    insert into t_order_examine (order_no, aid, `status`,
      create_time, aname)
    values (#{orderNo,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
      #{createTime,jdbcType=TIMESTAMP}, #{aname,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.TOrderExamine" useGeneratedKeys="true">
    insert into t_order_examine
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="aname != null">
        aname,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aname != null">
        #{aname,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TOrderExamine">
    update t_order_examine
    <set>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="aname != null">
        aname = #{aname,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TOrderExamine">
    update t_order_examine
    set order_no = #{orderNo,jdbcType=VARCHAR},
      aid = #{aid,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      aname = #{aname,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="selectByOrderNo" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_order_examine
    where order_no = #{orderNo,jdbcType=VARCHAR}
  </select>


  <update id="updateStatusByOrderNo">
    update t_order_examine
    set status= #{status}
    where order_no = #{orderNo,jdbcType=VARCHAR}
    <if test="aid!=null">
      and aid = #{aid}
    </if>
  </update>

  <insert id="insertBatch">
    insert into t_order_examine (order_no, aid, `status`, aname)
    values
    <foreach item="item" index="index" collection="list" separator=",">
      (#{item.orderNo,jdbcType=VARCHAR}, #{item.aid,jdbcType=VARCHAR}, #{item.status,jdbcType=INTEGER},
       #{item.aname,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <select id="selectByOrderNoAndAid" resultType="java.lang.Integer">
    select count(*)
    from t_order_examine where status=0
    and order_no = #{orderNo} and aid= #{aid}
  </select>
  <delete id="deleteByOrderNo">
    delete from t_order_examine
    where order_no = #{orderNo}
  </delete>

</mapper>
