<?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.ExpenseAccountExamineMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ExpenseAccountExamine">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="eaid" jdbcType="INTEGER" property="eaid" />
    <result column="process_status" jdbcType="INTEGER" property="processStatus" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="auditor" jdbcType="VARCHAR" property="auditor" />
    <result column="auditorName" jdbcType="VARCHAR" property="auditorname" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, eaid, process_status, `status`, auditor, auditorName, create_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from expense_account_examine
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from expense_account_examine
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountExamine" useGeneratedKeys="true">
    insert into expense_account_examine (eaid, process_status, `status`,
      auditor, auditorName, create_time
      )
    values (#{eaid,jdbcType=INTEGER}, #{processStatus,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
      #{auditor,jdbcType=VARCHAR}, #{auditorname,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountExamine" useGeneratedKeys="true">
    insert into expense_account_examine
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="eaid != null">
        eaid,
      </if>
      <if test="processStatus != null">
        process_status,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="auditor != null">
        auditor,
      </if>
      <if test="auditorname != null">
        auditorName,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="eaid != null">
        #{eaid,jdbcType=INTEGER},
      </if>
      <if test="processStatus != null">
        #{processStatus,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="auditor != null">
        #{auditor,jdbcType=VARCHAR},
      </if>
      <if test="auditorname != null">
        #{auditorname,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ExpenseAccountExamine">
    update expense_account_examine
    <set>
      <if test="eaid != null">
        eaid = #{eaid,jdbcType=INTEGER},
      </if>
      <if test="processStatus != null">
        process_status = #{processStatus,jdbcType=INTEGER},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=INTEGER},
      </if>
      <if test="auditor != null">
        auditor = #{auditor,jdbcType=VARCHAR},
      </if>
      <if test="auditorname != null">
        auditorName = #{auditorname,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.ExpenseAccountExamine">
    update expense_account_examine
    set eaid = #{eaid,jdbcType=INTEGER},
      process_status = #{processStatus,jdbcType=INTEGER},
      `status` = #{status,jdbcType=INTEGER},
      auditor = #{auditor,jdbcType=VARCHAR},
      auditorName = #{auditorname,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>



  <insert id="insertBatch">
    insert into expense_account_examine (eaid,process_status, `status`, auditor, auditorName)
    values
    <foreach  collection="list" item="e" separator=",">
      (#{e.eaid,jdbcType=INTEGER},#{e.processStatus}, #{e.status,jdbcType=INTEGER}, #{e.auditor,jdbcType=VARCHAR},
      #{e.auditorname,jdbcType=VARCHAR})
    </foreach>
  </insert>
  <update id="updateStatusByEaidAndAid">
    update expense_account_examine
    set status= #{status}
    where eaid =#{id}
      <if test="aid != null">
        and auditor= #{aid}
      </if>
  </update>

  <select id="selectByEaidAndProcessStatus" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from expense_account_examine
    where eaid = #{id}
    <if test="processStatus !=null">
    and process_status= #{processStatus}
    </if>
  </select>
  <select id="selectNotExamineByEaidAndProcessStatus" resultType="com.goafanti.expenseAccount.bo.OutExpenseAccountLog">
    select  process_status processStatus,group_concat(auditorName) auditorName
    from expense_account_examine
    where eaid = #{id} and process_status> #{processStatus}
    group by process_status
  </select>

</mapper>
