<?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.ExpenseAccountDetailsMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.ExpenseAccountDetails">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="eaid" jdbcType="INTEGER" property="eaid" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
    <result column="start_district" jdbcType="VARCHAR" property="startDistrict" />
    <result column="end_district" jdbcType="VARCHAR" property="endDistrict" />
    <result column="amount" jdbcType="DECIMAL" property="amount" />
    <result column="vehicle" jdbcType="INTEGER" property="vehicle" />
    <result column="vehicle_other" jdbcType="VARCHAR" property="vehicleOther" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="agree_time" jdbcType="TIMESTAMP" property="agreeTime" />
    <result column="pay_type" jdbcType="INTEGER" property="payType" />
    <result column="invoice_type" jdbcType="INTEGER" property="invoiceType" />
    <result column="invoice_no" jdbcType="VARCHAR" property="invoiceNo" />
    <result column="payer_name" jdbcType="VARCHAR" property="payerName" />
    <result column="open_bank" jdbcType="VARCHAR" property="openBank" />
    <result column="bank_accounts" jdbcType="VARCHAR" property="bankAccounts" />
    <result column="open_bank_address" jdbcType="VARCHAR" property="openBankAddress" />
    <result column="lend_id" jdbcType="INTEGER" property="lendId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, eaid, `type`, start_time, end_time, start_district, end_district, amount, vehicle,
    vehicle_other, remarks, agree_time, pay_type, invoice_type, invoice_no, payer_name,
    open_bank, bank_accounts, open_bank_address, lend_id, create_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from expense_account_details
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from expense_account_details
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountDetails" useGeneratedKeys="true">
    insert into expense_account_details (eaid, `type`, start_time,
      end_time, start_district, end_district,
      amount, vehicle, vehicle_other,
      remarks, agree_time, pay_type,
      invoice_type, invoice_no, payer_name,
      open_bank, bank_accounts, open_bank_address,
      lend_id, create_time)
    values (#{eaid,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{startTime,jdbcType=TIMESTAMP},
      #{endTime,jdbcType=TIMESTAMP}, #{startDistrict,jdbcType=VARCHAR}, #{endDistrict,jdbcType=VARCHAR},
      #{amount,jdbcType=DECIMAL}, #{vehicle,jdbcType=INTEGER}, #{vehicleOther,jdbcType=VARCHAR},
      #{remarks,jdbcType=VARCHAR}, #{agreeTime,jdbcType=TIMESTAMP}, #{payType,jdbcType=INTEGER},
      #{invoiceType,jdbcType=INTEGER}, #{invoiceNo,jdbcType=VARCHAR}, #{payerName,jdbcType=VARCHAR},
      #{openBank,jdbcType=VARCHAR}, #{bankAccounts,jdbcType=VARCHAR}, #{openBankAddress,jdbcType=VARCHAR},
      #{lendId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.ExpenseAccountDetails" useGeneratedKeys="true">
    insert into expense_account_details
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="eaid != null">
        eaid,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="startTime != null">
        start_time,
      </if>
      <if test="endTime != null">
        end_time,
      </if>
      <if test="startDistrict != null">
        start_district,
      </if>
      <if test="endDistrict != null">
        end_district,
      </if>
      <if test="amount != null">
        amount,
      </if>
      <if test="vehicle != null">
        vehicle,
      </if>
      <if test="vehicleOther != null">
        vehicle_other,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="agreeTime != null">
        agree_time,
      </if>
      <if test="payType != null">
        pay_type,
      </if>
      <if test="invoiceType != null">
        invoice_type,
      </if>
      <if test="invoiceNo != null">
        invoice_no,
      </if>
      <if test="payerName != null">
        payer_name,
      </if>
      <if test="openBank != null">
        open_bank,
      </if>
      <if test="bankAccounts != null">
        bank_accounts,
      </if>
      <if test="openBankAddress != null">
        open_bank_address,
      </if>
      <if test="lendId != null">
        lend_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="eaid != null">
        #{eaid,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="startTime != null">
        #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
        #{endTime,jdbcType=TIMESTAMP},
      </if>
      <if test="startDistrict != null">
        #{startDistrict,jdbcType=VARCHAR},
      </if>
      <if test="endDistrict != null">
        #{endDistrict,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        #{amount,jdbcType=DECIMAL},
      </if>
      <if test="vehicle != null">
        #{vehicle,jdbcType=INTEGER},
      </if>
      <if test="vehicleOther != null">
        #{vehicleOther,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="agreeTime != null">
        #{agreeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="payType != null">
        #{payType,jdbcType=INTEGER},
      </if>
      <if test="invoiceType != null">
        #{invoiceType,jdbcType=INTEGER},
      </if>
      <if test="invoiceNo != null">
        #{invoiceNo,jdbcType=VARCHAR},
      </if>
      <if test="payerName != null">
        #{payerName,jdbcType=VARCHAR},
      </if>
      <if test="openBank != null">
        #{openBank,jdbcType=VARCHAR},
      </if>
      <if test="bankAccounts != null">
        #{bankAccounts,jdbcType=VARCHAR},
      </if>
      <if test="openBankAddress != null">
        #{openBankAddress,jdbcType=VARCHAR},
      </if>
      <if test="lendId != null">
        #{lendId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.ExpenseAccountDetails">
    update expense_account_details
    <set>
      <if test="eaid != null">
        eaid = #{eaid,jdbcType=INTEGER},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="startTime != null">
        start_time = #{startTime,jdbcType=TIMESTAMP},
      </if>
      <if test="endTime != null">
        end_time = #{endTime,jdbcType=TIMESTAMP},
      </if>
      <if test="startDistrict != null">
        start_district = #{startDistrict,jdbcType=VARCHAR},
      </if>
      <if test="endDistrict != null">
        end_district = #{endDistrict,jdbcType=VARCHAR},
      </if>
      <if test="amount != null">
        amount = #{amount,jdbcType=DECIMAL},
      </if>
      <if test="vehicle != null">
        vehicle = #{vehicle,jdbcType=INTEGER},
      </if>
      <if test="vehicleOther != null">
        vehicle_other = #{vehicleOther,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="agreeTime != null">
        agree_time = #{agreeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="payType != null">
        pay_type = #{payType,jdbcType=INTEGER},
      </if>
      <if test="invoiceType != null">
        invoice_type = #{invoiceType,jdbcType=INTEGER},
      </if>
      <if test="invoiceNo != null">
        invoice_no = #{invoiceNo,jdbcType=VARCHAR},
      </if>
      <if test="payerName != null">
        payer_name = #{payerName,jdbcType=VARCHAR},
      </if>
      <if test="openBank != null">
        open_bank = #{openBank,jdbcType=VARCHAR},
      </if>
      <if test="bankAccounts != null">
        bank_accounts = #{bankAccounts,jdbcType=VARCHAR},
      </if>
      <if test="openBankAddress != null">
        open_bank_address = #{openBankAddress,jdbcType=VARCHAR},
      </if>
      <if test="lendId != null">
        lend_id = #{lendId,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.ExpenseAccountDetails">
    update expense_account_details
    set eaid = #{eaid,jdbcType=INTEGER},
      `type` = #{type,jdbcType=INTEGER},
      start_time = #{startTime,jdbcType=TIMESTAMP},
      end_time = #{endTime,jdbcType=TIMESTAMP},
      start_district = #{startDistrict,jdbcType=VARCHAR},
      end_district = #{endDistrict,jdbcType=VARCHAR},
      amount = #{amount,jdbcType=DECIMAL},
      vehicle = #{vehicle,jdbcType=INTEGER},
      vehicle_other = #{vehicleOther,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      agree_time = #{agreeTime,jdbcType=TIMESTAMP},
      pay_type = #{payType,jdbcType=INTEGER},
      invoice_type = #{invoiceType,jdbcType=INTEGER},
      invoice_no = #{invoiceNo,jdbcType=VARCHAR},
      payer_name = #{payerName,jdbcType=VARCHAR},
      open_bank = #{openBank,jdbcType=VARCHAR},
      bank_accounts = #{bankAccounts,jdbcType=VARCHAR},
      open_bank_address = #{openBankAddress,jdbcType=VARCHAR},
      lend_id = #{lendId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="selectAmountCountByEAid" resultType="java.math.BigDecimal">
    select ifnull(sum(amount),0)amount  from expense_account_details
    where eaid = #{id}
  </select>
  <select id="selectByEAid" resultType="com.goafanti.expenseAccount.bo.OutExpenseAccountDetails">
    SELECT id, eaid, `type`, date_format(a.start_time,'%Y-%m-%d %H:%i:%S')startTimeStr, date_format(a.end_time,'%Y-%m-%d %H:%i:%S')endTimeStr,
           start_district startDistrict, end_district endDistrict, amount, vehicle, vehicle_other vehicleOther, remarks,
           date_format(a.agree_time,'%Y-%m-%d %H:%i:%S')agreeTimeStr, pay_type payType,invoice_type invoiceType, invoice_no invoiceNo,
           payer_name payerName, open_bank openBank, bank_accounts bankAccounts, open_bank_address openBankAddress, lend_id lendId,
           date_format(a.create_time,'%Y-%m-%d %H:%i:%S')createTimeStr
    FROM expense_account_details a WHERE eaid= #{eaid}
  </select>
  <delete id="deleteByeaid">
    delete from expense_account_details
    where eaid = #{id}
  </delete>
</mapper>
