<?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.MemberRankSettingDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.MemberRankSetting" id="MemberRankSetting">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="intro_" property="intro" />
		<result column="icon_" property="icon" />
		<result column="experience_icon_" property="experienceIcon" />
		<result column="is_default_" property="isDefault" javaType="java.lang.Boolean" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="operator_" property="operator" />
		<result column="operator_name_" property="operatorName" />
	</resultMap>

	<select id="get" resultMap="MemberRankSetting" >
		SELECT * FROM member_rank_setting WHERE id_ = #{id}
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="MemberRankSetting">
		SELECT * FROM member_rank_setting
		<where>
			<if test="isDefault != null">
				is_default_ = #{isDefault}
			</if>
		</where>
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MemberRankSetting" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO member_rank_setting (name_,intro_,icon_,is_default_,create_time_,update_time_,operator_,experience_icon_)
		VALUES(#{name},#{intro},#{icon},#{isDefault},NOW(),NOW(),#{operator},#{experienceIcon})
	</insert>

	<update id="update" parameterType="com.ym.mec.biz.dal.entity.MemberRankSetting">
		UPDATE member_rank_setting
		<set>
		<if test="experienceIcon != null">
			experience_icon_ = #{experienceIcon},
		</if>
		<if test="operator != null">
			operator_ = #{operator},
		</if>
		<if test="name != null">
			name_ = #{name},
		</if>
		<if test="intro != null">
			intro_ = #{intro},
		</if>
		<if test="isDefault != null">
			is_default_ = #{isDefault},
		</if>
		<if test="icon != null">
			icon_ = #{icon},
		</if>
		update_time_ = NOW()
	</set>WHERE id_ = #{id}
	</update>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="MemberRankSetting" parameterType="map">
		SELECT mrs.*,su.real_name_ operator_name_ FROM member_rank_setting mrs
		LEFT JOIN sys_user su ON su.id_ = mrs.operator_
		<include refid="queryPageSql"/>
		<include refid="global.limit"/>
	</select>

	<sql id="queryPageSql">
		<where>
			<if test="search != null and search != ''">
				AND (mrs.name_ LIKE CONCAT('%',#{search},'%') OR mrs.id_ = #{search})
			</if>
		</where>
	</sql>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(mrs.id_) FROM member_rank_setting mrs
		<include refid="queryPageSql"/>
	</select>
	
	<select id="queryListByIsDefault" resultMap="MemberRankSetting" parameterType="map">
		SELECT * FROM member_rank_setting 
		<where>
			<if test="isDefault != null">
				AND is_default_ = #{isDefault}
			</if>
		</where>
	</select>
</mapper>
