<?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.role.TabHaobanRoleMapper">

    <resultMap type="com.gic.haoban.manage.service.entity.role.TabHaobanRole" id="TabHaobanRoleMap">
        <result property="roleId" column="role_id" jdbcType="INTEGER"/>
        <result property="roleName" column="role_name" jdbcType="VARCHAR"/>
        <result property="clerkType" column="clerk_type" jdbcType="INTEGER"/>
        <result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
        <result property="creatorId" column="creator_id" jdbcType="VARCHAR"/>
        <result property="creatorName" column="creator_name" jdbcType="VARCHAR"/>
        <result property="modifierId" column="modifier_id" jdbcType="VARCHAR"/>
        <result property="modifierName" column="modifier_name" jdbcType="VARCHAR"/>
        <result property="statusFlag" column="status_flag" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="systemFlag" column="system_flag" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
    role_id, role_name, clerk_type, wx_enterprise_id, creator_id, creator_name, modifier_id, modifier_name, status_flag, create_time, update_time,system_flag
  </sql>

    <!--查询单个-->
    <select id="queryById" resultMap="TabHaobanRoleMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_role
        where role_id = #{roleId}
    </select>

    <insert id="insertBatch" keyProperty="roleId" useGeneratedKeys="true">
        insert into tab_haoban_role(role_id, role_name, clerk_type, wx_enterprise_id,
        creator_id, creator_name, modifier_id, modifier_name, status_flag, create_time, update_time,system_flag)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.roleId}, #{entity.roleName}, #{entity.clerkType},
            #{entity.wxEnterpriseId},  #{entity.creatorId}, #{entity.creatorName},
            #{entity.modifierId}, #{entity.modifierName}, #{entity.statusFlag}, #{entity.createTime},
            #{entity.updateTime},#{entity.systemFlag})
        </foreach>
    </insert>


    <!--通过主键修改数据-->
    <update id="update">
        update tab_haoban_role
        <set>
            <if test="roleName != null and roleName != ''">
                role_name = #{roleName},
            </if>
            <if test="clerkType != null">
                clerk_type = #{clerkType},
            </if>
            <if test="wxEnterpriseId != null and wxEnterpriseId != ''">
                wx_enterprise_id = #{wxEnterpriseId},
            </if>
            <if test="creatorId != null and creatorId != ''">
                creator_id = #{creatorId},
            </if>
            <if test="creatorName != null and creatorName != ''">
                creator_name = #{creatorName},
            </if>
            <if test="modifierId != null and modifierId != ''">
                modifier_id = #{modifierId},
            </if>
            <if test="modifierName != null and modifierName != ''">
                modifier_name = #{modifierName},
            </if>
            <if test="statusFlag != null">
                status_flag = #{statusFlag},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="systemFlag != null">
                system_flag = #{systemFlag},
            </if>
        </set>
        where role_id = #{roleId}
    </update>

    <select id="getByWxEnterpriseIdAndClerkType" resultMap="TabHaobanRoleMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_role
        where wx_enterprise_id = #{wxEnterpriseId}
        <if test="clerkType != null">
            and clerk_type = #{clerkType}
        </if>
        <if test="systemFlag != null">
            and system_flag = #{systemFlag}
        </if>
        limit 1
    </select>

    <select id="getCountByWxEnterpriseId" resultType="java.lang.Integer">
        select
        count(*)
        from tab_haoban_role
        where wx_enterprise_id = #{wxEnterpriseId}
        <if test="systemFlag != null">
            and system_flag = #{systemFlag}
        </if>
    </select>

    <select id="getListByWxEnterpriseId" resultMap="TabHaobanRoleMap">
        select
        <include refid="Base_Column_List"/>
        from tab_haoban_role
        where wx_enterprise_id = #{wxEnterpriseId}
        <if test="systemFlag != null">
            and system_flag = #{systemFlag}
        </if>
    </select>

    <delete id="deleteByWxEnterpriseId">
        delete from tab_haoban_role where wx_enterprise_id = #{wxEnterpriseId}
        <if test="systemFlag != null">
            and system_flag = #{systemFlag}
        </if>
    </delete>

</mapper>

