<?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.VipGroupCategoryDao">

	<resultMap type="com.ym.mec.biz.dal.entity.VipGroupCategory"
		id="VipGroupCategory">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="del_flag_" property="delFlag" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="single_class_minutes_" property="singleClassMinutes" />
		<result column="student_num_" property="studentNum" />
		<result column="music_theory_" property="musicTheory" />
		<result column="online_classes_unit_price_" property="onlineClassesUnitPrice" />
		<result column="offline_classes_unit_price_" property="offlineClassesUnitPrice" />
        <result column="tenant_id_" property="tenantId"/>
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="VipGroupCategory">
		SELECT * FROM
		vip_group_category WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="VipGroupCategory">
		SELECT vgc.* FROM vip_group_category vgc
		WHERE vgc.del_flag_!= 1 and tenant_id_ = #{tenantId}
		ORDER BY id_
	</select>

	<select id="findAllByOrgan" resultMap="VipGroupCategory">
		SELECT vgc.*,vgdcup.online_classes_unit_price_,vgdcup.offline_classes_unit_price_ FROM vip_group_category vgc
		LEFT JOIN vip_group_default_classes_unit_price_ vgdcup ON vgc.id_=vgdcup.vip_group_category_id_ AND FIND_IN_SET(vgdcup.organ_id_,#{organId})
		WHERE vgc.del_flag_ != 1
		ORDER BY id_
	</select>

	<select id="findTeacherDefaultSalary" resultMap="VipGroupCategory">
		SELECT
			vgc.*,
			tdvgs.offline_classes_salary_ online_classes_unit_price_,
			tdvgs.offline_classes_salary_ offline_classes_unit_price_
		FROM
			vip_group_category vgc
			LEFT JOIN teacher_default_vip_group_salary tdvgs ON vgc.id_ = tdvgs.vip_group_category_id_ AND tdvgs.user_id_=#{userId}
		WHERE
			vgc.del_flag_ = 0
		ORDER BY
			id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.VipGroupCategory"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO vip_group_category
		(id_,name_,del_flag_,create_time_,update_time_,single_class_minutes_,student_num_,music_theory_,tenant_id_)
		VALUES(#{id},#{name},#{delFlag},#{createTime},NOW(),#{singleClassMinutes},#{studentNum},#{musicTheory},#{tenantId})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.VipGroupCategory">
		UPDATE vip_group_category
		<set>
			<if test="delFlag != null">
				del_flag_ = #{delFlag},
			</if>
			<if test="studentNum != null">
				student_num_ = #{studentNum},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="singleClassMinutes != null">
				single_class_minutes_ = #{singleClassMinutes},
			</if>
			<if test="name != null">
				name_ = #{name},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
			<if test="musicTheory != null">
				music_theory_ = #{musicTheory},
			</if>
				update_time_ = NOW(),
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete">
		DELETE FROM vip_group_category WHERE id_ =
		#{id}
	</delete>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="VipGroupCategory"
		parameterType="map">
		SELECT * FROM vip_group_category where del_flag_ != 1 and tenant_id_ = #{tenantId} ORDER BY id_
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM vip_group_category where del_flag_ != 1 and tenant_id_ = #{tenantId}
	</select>
	<select id="findConditionCategorys" resultType="com.ym.mec.biz.dal.dto.ConditionDto">
      	select id_ id,name_ `name` from vip_group_category where del_flag_ != 1
    </select>
	<select id="findByIds" resultType="com.ym.mec.biz.dal.entity.VipGroupCategory">
		SELECT * FROM vip_group_category WHERE del_flag_ = 0 AND id_ IN
		<foreach collection="categoryIds" open="(" close=")" item="id" separator=",">
			#{id}
		</foreach>
	</select>
	<select id="getTheory" resultMap="VipGroupCategory">
		SELECT * FROM vip_group_category WHERE del_flag_ = 0 AND music_theory_ = 1 LIMIT 1
	</select>
</mapper>
