<?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.ExpenseAccountPrivateMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ExpenseAccountPrivate">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="bank" jdbcType="VARCHAR" property="bank" />
    <result column="accounts" jdbcType="VARCHAR" property="accounts" />
    <result column="open_bank" jdbcType="VARCHAR" property="openBank" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, aid, `name`, bank, accounts, open_bank, `status`, create_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from expense_account_private
    where id = #{id,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from expense_account_private
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountPrivate" useGeneratedKeys="true">
    insert into expense_account_private (aid, `name`, bank,
      accounts, open_bank, `status`,
      create_time)
    values (#{aid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{bank,jdbcType=VARCHAR},
      #{accounts,jdbcType=VARCHAR}, #{openBank,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
      #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountPrivate" useGeneratedKeys="true">
    insert into expense_account_private
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="aid != null">
        aid,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="bank != null">
        bank,
      </if>
      <if test="accounts != null">
        accounts,
      </if>
      <if test="openBank != null">
        open_bank,
      </if>
      <if test="status != null">
        `status`,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="bank != null">
        #{bank,jdbcType=VARCHAR},
      </if>
      <if test="accounts != null">
        #{accounts,jdbcType=VARCHAR},
      </if>
      <if test="openBank != null">
        #{openBank,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ExpenseAccountPrivate">
    update expense_account_private
    <set>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="bank != null">
        bank = #{bank,jdbcType=VARCHAR},
      </if>
      <if test="accounts != null">
        accounts = #{accounts,jdbcType=VARCHAR},
      </if>
      <if test="openBank != null">
        open_bank = #{openBank,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        `status` = #{status,jdbcType=INTEGER},
      </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.ExpenseAccountPrivate">
    update expense_account_private
    set aid = #{aid,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      bank = #{bank,jdbcType=VARCHAR},
      accounts = #{accounts,jdbcType=VARCHAR},
      open_bank = #{openBank,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="checkParam" resultType="java.lang.Integer">
    select count(*) from expense_account_private
    where 1=1
    <if test="status !=null">
      and status= #{status}
    </if>
     <if test="aid !=null">
       and aid =#{aid}
     </if>
    <if test="accounts !=null">
      and accounts =#{accounts}
    </if>
  </select>
  <sql id="selectDetails">
    id ,aid,name ,bank ,accounts ,open_bank openBank ,status ,
    date_format(create_time,'%Y-%m-%d %H:%i:%S') createTimeStr
  </sql>
  <select id="selectExpenseAccountPrivateList" resultType="com.goafanti.expenseAccount.bo.OutExpenseAccountPrivate">
    select
    <include refid="selectDetails" />
    from expense_account_private
    where aid = #{aid}
    <if test="status != null">
     and status= #{status}
    </if>
    order by create_time desc
    <if test="page_sql !=null">
      ${page_sql}
    </if>
  </select>
  <select id="selectExpenseAccountPrivateCount" resultType="java.lang.Integer">
    select count(*)
    from expense_account_private
    where aid = #{aid}
    <if test="status != null">
      and status= #{status}
    </if>
  </select>
    <select id="selectByAccount" resultType="com.goafanti.common.model.ExpenseAccountPrivate">
      select
      <include refid="Base_Column_List" />
      from expense_account_private
      where accounts = #{accounts}
    </select>

    <update id="updateStatusByAid">
    update expense_account_private
    set status=0
    where aid =#{aid}
  </update>
  <select id="selectById" resultType="com.goafanti.expenseAccount.bo.OutExpenseAccountPrivate">
    select
    <include refid="selectDetails" />
    from expense_account_private
    where id= #{id}
  </select>
    <select id="selectByaidDefault" resultType="java.lang.Integer">
      select id
      from expense_account_private
        where aid=#{aid} and status=1
    </select>


</mapper>
