<?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.TabHaobanQywxFeeOrderMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.fee.TabHaobanQywxFeeOrder" id="TabHaobanQywxFeeOrderMap">
        <result property="feeOrderId" column="fee_order_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="orderType" column="order_type" jdbcType="INTEGER"/>
        <result property="orderStatus" column="order_status" jdbcType="INTEGER"/>
        <result property="price" column="price" jdbcType="VARCHAR"/>
        <result property="baseCount" column="base_count" jdbcType="INTEGER"/>
        <result property="externalContactCount" column="external_contact_count" jdbcType="INTEGER"/>
        <result property="months" column="months" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="payTime" column="pay_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        fee_order_id
        , order_id, corp_id, wx_enterprise_id, order_type, order_status, price, base_count, external_contact_count, months, create_time, pay_time
    </sql>

    <!--查询单个-->
    <select id="selectByOrderId" resultMap="TabHaobanQywxFeeOrderMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_qywx_fee_order
        where wx_enterprise_id = #{wxEnterpriseId} and order_id = #{orderId}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="feeOrderId" useGeneratedKeys="true">
        insert into tab_haoban_qywx_fee_order(fee_order_id, order_id, corp_id, wx_enterprise_id, order_type,
                                              order_status, price, base_count, external_contact_count, months,
                                              create_time, pay_time)
        values (#{feeOrderId}, #{orderId}, #{corpId}, #{wxEnterpriseId}, #{orderType}, #{orderStatus}, #{price},
                #{baseCount}, #{externalContactCount}, #{months}, #{createTime}, #{payTime})
    </insert>

    <select id="countExternalContactCount" resultType="java.lang.Integer">
        select sum(external_contact_count)
        from tab_haoban_qywx_fee_order
        where wx_enterprise_id = #{wxEnterpriseId}
    </select>

	
	
	<select id="listOrder" resultMap="TabHaobanQywxFeeOrderMap">
		  select
        <include refid="Base_Column_List"/>
        from tab_haoban_qywx_fee_order
        where wx_enterprise_id = #{wxEnterpriseId}
	</select>
</mapper>

