<?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.hc.business.mapper.ZccmUserInvoicesMapper">

    <resultMap type="zccmuserInvoices" id="UserInvoicesMap">
        <result property="userInvoicesId" column="user_invoices_id" jdbcType="INTEGER"/>
        <result property="invoicesHead" column="invoices_head" jdbcType="VARCHAR"/>
        <result property="invoicesType" column="invoices_type" jdbcType="INTEGER"/>
        <result property="invoicesCode" column="invoices_code" jdbcType="VARCHAR"/>
        <result property="invoicesBank" column="invoices_bank" jdbcType="VARCHAR"/>
        <result property="invoicesUser" column="invoices_user" jdbcType="VARCHAR"/>
        <result property="invoicesNo" column="invoices_no" jdbcType="VARCHAR"/>
        <result property="invoicesPrice" column="invoices_price" jdbcType="NUMERIC"/>
        <result property="createTime" column="create_time" jdbcType="INTEGER"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="time" column="time" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="classId" column="class_id" jdbcType="INTEGER"/>
        <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
        <result property="remarksSign" column="remarks_sign" jdbcType="VARCHAR"/>
        <result property="taxCode" column="tax_code" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        user_invoices_id,
           invoices_head,
           invoices_type,
           invoices_code,
           invoices_bank,
           invoices_user,
           invoices_no,
           invoices_price,
           create_time,
           `status`,
           `time`,
           user_id,
           class_id,
           remarks,
           remarks_sign,
           tax_code
    </sql>

    <select id="queryDetailByUserId" resultMap="UserInvoicesMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zccm_user_invoices
        WHERE user_id = #{userId}
    </select>

    <select id="queryAll" resultMap="UserInvoicesMap">
        SELECT zccm_user_invoices.*
        FROM zccm_user_invoices
                 INNER JOIN zccm_orders o on zccm_user_invoices.user_invoices_id = o.user_invoices_id
        WHERE order_status = 1
    </select>

    <select id="queryByClassId" resultMap="UserInvoicesMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zccm_user_invoices
        WHERE class_id = #{classId}
    </select>

    <select id="queryByStatus" resultMap="UserInvoicesMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM zccm_user_invoices
        WHERE status = #{status}
    </select>

</mapper>