<?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.hm.TabHaobanHmGroupSettingMapper">
    <resultMap id="BaseResultMap" type="com.gic.haoban.manage.service.entity.hm.TabHaobanHmGroupSetting">
        <id column="group_id" property="groupId" jdbcType="BIGINT"/>
        <result column="group_name" property="groupName" jdbcType="VARCHAR"/>
        <result column="enterprise_id" property="enterpriseId" jdbcType="VARCHAR"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="sort" property="sort" jdbcType="INTEGER"/>
        <result column="creator_id" property="creatorId" jdbcType="VARCHAR"/>
        <result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
        <result column="modifier_id" property="modifierId" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="modifier_name" property="modifierName" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        group_id
        , group_name, enterprise_id, wx_enterprise_id, status, sort, creator_id,
    creator_name, modifier_id, create_time, update_time, modifier_name
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_hm_group_setting
        where group_id = #{groupId,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from tab_haoban_hm_group_setting
        where group_id = #{groupId,jdbcType=BIGINT}
    </delete>
    <insert id="insert" useGeneratedKeys="true" keyProperty="groupId"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanHmGroupSetting">
        insert into tab_haoban_hm_group_setting (group_id, group_name, enterprise_id,
                                                 wx_enterprise_id, status,
                                                 sort, creator_id, creator_name,
                                                 modifier_id, create_time, update_time,
                                                 modifier_name)
        values (#{groupId,jdbcType=BIGINT}, #{groupName,jdbcType=VARCHAR}, #{enterpriseId,jdbcType=VARCHAR},
                #{wxEnterpriseId,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
                #{sort,jdbcType=INTEGER}, #{creatorId,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR},
                #{modifierId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
                #{modifierName,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" useGeneratedKeys="true" keyProperty="groupId"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanHmGroupSetting">
        insert into tab_haoban_hm_group_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupId != null">
                group_id,
            </if>
            <if test="groupName != null">
                group_name,
            </if>
            <if test="enterpriseId != null">
                enterprise_id,
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="sort != null">
                sort,
            </if>
            <if test="creatorId != null">
                creator_id,
            </if>
            <if test="creatorName != null">
                creator_name,
            </if>
            <if test="modifierId != null">
                modifier_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="modifierName != null">
                modifier_name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupId != null">
                #{groupId,jdbcType=BIGINT},
            </if>
            <if test="groupName != null">
                #{groupName,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="sort != null">
                #{sort,jdbcType=INTEGER},
            </if>
            <if test="creatorId != null">
                #{creatorId,jdbcType=VARCHAR},
            </if>
            <if test="creatorName != null">
                #{creatorName,jdbcType=VARCHAR},
            </if>
            <if test="modifierId != null">
                #{modifierId,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="modifierName != null">
                #{modifierName,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanHmGroupSetting">
        update tab_haoban_hm_group_setting
        <set>
            <if test="groupName != null">
                group_name = #{groupName,jdbcType=VARCHAR},
            </if>
            <if test="enterpriseId != null">
                enterprise_id = #{enterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="wxEnterpriseId != null">
                wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="sort != null">
                sort = #{sort,jdbcType=INTEGER},
            </if>
            <if test="creatorId != null">
                creator_id = #{creatorId,jdbcType=VARCHAR},
            </if>
            <if test="creatorName != null">
                creator_name = #{creatorName,jdbcType=VARCHAR},
            </if>
            <if test="modifierId != null">
                modifier_id = #{modifierId,jdbcType=VARCHAR},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="modifierName != null">
                modifier_name = #{modifierName,jdbcType=VARCHAR},
            </if>
        </set>
        where group_id = #{groupId,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.hm.TabHaobanHmGroupSetting">
        update tab_haoban_hm_group_setting
        set group_name       = #{groupName,jdbcType=VARCHAR},
            enterprise_id    = #{enterpriseId,jdbcType=VARCHAR},
            wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
            status           = #{status,jdbcType=INTEGER},
            sort             = #{sort,jdbcType=INTEGER},
            creator_id       = #{creatorId,jdbcType=VARCHAR},
            creator_name     = #{creatorName,jdbcType=VARCHAR},
            modifier_id      = #{modifierId,jdbcType=VARCHAR},
            create_time      = #{createTime,jdbcType=TIMESTAMP},
            update_time      = #{updateTime,jdbcType=TIMESTAMP},
            modifier_name    = #{modifierName,jdbcType=VARCHAR}
        where group_id = #{groupId,jdbcType=BIGINT}
    </update>

    <select id="queryHmGroupSettingList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tab_haoban_hm_group_setting
        <where>
            <if test="groupName != null and groupName != ''">
                group_name like concat('%', #{groupName}, '%')
            </if>
            <if test="status != null">
                and `status` = #{status}
            </if>
            <if test="enterpriseId != null and enterpriseId != ''">
                and enterprise_id = #{enterpriseId}
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                and wx_enterprise_id = #{wxEnterpriseId}
            </if>
        </where>
    </select>

    <update id="updateGroupSettingCount">
        update tab_haoban_hm_group_setting
        set refer_num = if(refer_num + #{changeCount} >= 0, refer_num + #{changeCount}, 0)
        where group_id = #{groupId,jdbcType=BIGINT}
    </update>

    <select id="queryHmGroupSettingByName" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tab_haoban_hm_group_setting
        where group_name = #{groupName}
        and enterprise_id = #{enterpriseId}
        and wx_enterprise_id = #{wxEnterpriseId}
        and `status` = 1
    </select>
</mapper>