<?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.gic.haoban.manage.service.dao.mapper.fee.TabHaobanQywxFeeOrderAccountMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.fee.TabHaobanQywxFeeOrderAccount" id="TabHaobanQywxFeeOrderAccountMap">
        <result property="feeAccountId" column="fee_account_id" jdbcType="INTEGER"/>
        <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
        <result property="corpId" column="corp_id" jdbcType="VARCHAR"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="wxUserId" column="wx_user_id" jdbcType="VARCHAR"/>
        <result property="activeCode" column="active_code" jdbcType="VARCHAR"/>
        <result property="accountType" column="account_type" jdbcType="INTEGER"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
        <result property="activeTime" column="active_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        fee_account_id
        , order_id, corp_id, wx_enterprise_id, wx_user_id, active_code, account_type, status, expire_time, active_time
    </sql>

    <!--查询单个-->
    <select id="selectByOrderIdAndCode" resultMap="TabHaobanQywxFeeOrderAccountMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_qywx_fee_order_account
        where  wx_enterprise_id = #{wxEnterpriseId} and order_id = #{orderId} and active_code = #{activeCode}
    </select>

    <!--新增所有列-->
    <insert id="insert">
        insert into tab_haoban_qywx_fee_order_account(fee_account_id, order_id, corp_id, wx_enterprise_id, wx_user_id,
                                                      active_code, account_type, status, expire_time, active_time)
        values (#{feeAccountId}, #{orderId}, #{corpId}, #{wxEnterpriseId}, #{wxUserId}, #{activeCode}, #{accountType},
                #{status}, #{expireTime}, #{activeTime})
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_qywx_fee_order_account
        <set>
            <if test="orderId != null and orderId != ''">
                order_id = #{orderId},
            </if>
            <if test="corpId != null and corpId != ''">
                corp_id = #{corpId},
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="wxUserId != null and wxUserId != ''">
                wx_user_id = #{wxUserId},
            </if>
            <if test="activeCode != null and activeCode != ''">
                active_code = #{activeCode},
            </if>
            <if test="accountType != null">
                account_type = #{accountType},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="expireTime != null">
                expire_time = #{expireTime},
            </if>
            <if test="activeTime != null">
                active_time = #{activeTime},
            </if>
        </set>
        where fee_account_id = #{feeAccountId}
    </update>

    <select id="countOrderAccountStatus" resultType="java.lang.Integer">
        select
        count(*)
        from tab_haoban_qywx_fee_order_account
        where wx_enterprise_id = #{wxEnterpriseId} and status = #{status}
    </select>


    <select id="countStatusByWxEnterpriseId" resultType="java.util.HashMap">
        select
            status,
            count(*) as num
        from tab_haoban_qywx_fee_order_account
        where wx_enterprise_id = #{wxEnterpriseId} GROUP BY STATUS
    </select>

    <select id="selectByWxEnterpriseId" resultMap="TabHaobanQywxFeeOrderAccountMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_qywx_fee_order_account
        where  wx_enterprise_id = #{wxEnterpriseId}
        and status in (1,4)
    </select>

    <update id="updateByActiveCode">
        update tab_haoban_qywx_fee_order_account
        set status = 2,update_time = NOW()
        where wx_enterprise_id = #{wxEnterpriseId} and  active_code = #{activeCode}
    </update>

</mapper>

