<?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.ym.mec.biz.dal.dao.MemberRankPrivilegesDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MemberRankPrivileges" id="MemberRankPrivileges">
		<result column="member_rank_id_" property="memberRankId" />
		<result column="member_privileges_id_" property="memberPrivilegesId" />
	</resultMap>

	<select id="get" resultMap="MemberRankPrivileges" >
		SELECT * FROM member_rank_privileges WHERE id_ = #{id}
	</select>

	<delete id="deleteByRankSettingId">
		DELETE FROM member_rank_privileges WHERE member_rank_id_ = #{memberRankSettingId}
	</delete>

	<!-- 全查询 -->
	<select id="findAll" resultMap="MemberRankPrivileges">
		SELECT * FROM member_rank_privileges
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MemberRankPrivileges" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO member_rank_privileges (member_rank_id_,member_privileges_id_)
		VALUES(#{memberRankId},#{memberPrivilegesId})
	</insert>
	<insert id="batchInsert">
		INSERT INTO member_rank_privileges (member_rank_id_,member_privileges_id_) VALUES
		<foreach collection="memberPrivilegesItemIdList" item="item" separator=",">
			(#{memberRankSettingId}, #{item})
		</foreach>
	</insert>

	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MemberRankPrivileges">
		UPDATE member_rank_privileges <set>
		<if test="memberRankId != null">
			member_rank_id_ = #{memberRankId},
		</if>
		<if test="memberPrivilegesId != null">
			member_privileges_id_ = #{memberPrivilegesId},
		</if>
	</set> WHERE id_ = #{id}
	</update>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MemberRankPrivileges" parameterType="map">
		SELECT * FROM member_rank_privileges
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM member_rank_privileges
	</select>
	<select id="findByRankSettingId" resultMap="MemberRankPrivileges">
		SELECT * FROM member_rank_privileges WHERE member_rank_id_ = #{memberRankSettingId}
	</select>
    <select id="hasPrivileges" resultType="java.lang.Boolean">
		SELECT COUNT(member_privileges_id_) > 0 FROM member_rank_privileges WHERE member_privileges_id_ = #{parentId}
	</select>
</mapper>
