<?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.TabHaobanWxEnterpriseActiveDataMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseActiveData">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="wx_enterprise_id" jdbcType="VARCHAR" property="wxEnterpriseId"/>
        <result column="purchased" jdbcType="INTEGER" property="purchased"/>
        <result column="used" jdbcType="INTEGER" property="used"/>
        <result column="inactive" jdbcType="INTEGER" property="inactive"/>
        <result column="transfer" jdbcType="INTEGER" property="transfer"/>
        <result column="activated" jdbcType="INTEGER" property="activated"/>
        <result column="expired" jdbcType="INTEGER" property="expired"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="delete_flag" jdbcType="INTEGER" property="deleteFlag"/>
    </resultMap>
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseActiveData">
        insert into tab_haoban_wx_enterprise_active_data (id, wx_enterprise_id, purchased,used,
                                                          inactive, transfer, activated,expired,create_time,update_time,delete_flag)
        values (#{id,jdbcType=BIGINT}, #{wxEnterpriseId,jdbcType=VARCHAR}, #{purchased,jdbcType=INTEGER},#{used,jdbcType=INTEGER},#{inactive,jdbcType=INTEGER},
                #{transfer,jdbcType=INTEGER},#{activated,jdbcType=INTEGER},#{expired,jdbcType=INTEGER},now(),now(),0)
	</insert>

    <select id="getWxEnterpriseActiveDataByWxEnterpriseId" resultMap="BaseResultMap">
        select  * from  tab_haoban_wx_enterprise_active_data where wx_enterprise_id=#{wxEnterpriseId} and delete_flag=0
    </select>

    <update id="updateActiveDataByWxEnterpriseId" parameterType="com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseActiveData" >
        update tab_haoban_wx_enterprise_active_data
        <set >
            <if test="purchased != null" >
                purchased = #{purchased,jdbcType=INTEGER},
            </if>
            <if test="used != null" >
                used = #{used,jdbcType=INTEGER},
            </if>
            <if test="inactive != null" >
                inactive = #{inactive,jdbcType=INTEGER},
            </if>
            <if test="transfer != null" >
                transfer = #{transfer,jdbcType=INTEGER},
            </if>
            <if test="activated != null" >
                activated = #{activated,jdbcType=INTEGER},
            </if>
            <if test="expired != null" >
                expired = #{expired,jdbcType=INTEGER},
            </if>
            update_time = now()
        </set>
        where wx_enterprise_id=#{wxEnterpriseId}
    </update>

</mapper>