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

	<resultMap type="com.ym.mec.biz.dal.entity.TenantEntryActivities"
		id="TenantEntryActivities">
		<result column="id_" property="id" />
		<result column="name_" property="name" />
		<result column="cover_img_" property="coverImg" />
		<result column="detail_" property="detail" />
		<result column="suitable_user_" property="suitableUser" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
		<result column="tag_" property="tag" />
		<result column="total_price_" property="totalPrice" />
		<result column="discount_price_" property="discountPrice" />
		<result column="purchase_minutes_" property="purchaseMinutes" />
		<result column="give_minutes_" property="giveMinutes" />
		<result column="start_date_" property="startDate" />
		<result column="end_date_" property="endDate" />
		<result column="condition_" property="condition" />
		<result column="del_flag_" property="delFlag" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>
	
	<sql id="queryCondition">
		<where>
			tenant_id_ = #{tenantId}
			<if test="startDate != null">
				and (start_date_ &lt;= #{startDate} and end_date_ &gt;= #{startDate})
			</if>
			<if test="delFlag != null">
				and del_flag_ = #{delFlag}
			</if>
			<if test="suitableUser != null">
				and suitable_user_ = #{suitableUser, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
			</if>
		</where>
	</sql>

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

	<!-- 全查询 -->
	<select id="findAll" resultMap="TenantEntryActivities">
		SELECT * FROM
		tenant_entry_activities where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.TenantEntryActivities"
		useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
			AS ID FROM DUAL </selectKey> -->
		INSERT INTO tenant_entry_activities
		(id_,name_,cover_img_,detail_,suitable_user_,tag_,total_price_,discount_price_,purchase_minutes_,give_minutes_,start_date_,end_date_,condition_,del_flag_,create_time_,update_time_,tenant_id_)
		VALUES(#{id},#{name},#{coverImg},#{detail},#{suitableUser, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{tag},#{totalPrice},#{discountPrice},#{purchaseMinutes},#{giveMinutes},#{startDate},#{endDate},#{condition},#{delFlag},#{createTime},#{updateTime},#{tenantId})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.TenantEntryActivities">
		UPDATE tenant_entry_activities
		<set>
			<if test="condition != null">
				condition_ = #{condition},
			</if>
			<if test="delFlag != null">
				del_flag_ = #{delFlag},
			</if>
			<if test="startDate != null">
				start_date_ = #{startDate},
			</if>
			<if test="coverImg != null">
				cover_img_ = #{coverImg},
			</if>
			<if test="id != null">
				id_ = #{id},
			</if>
			<if test="suitableUser != null">
				suitable_user_ = #{suitableUser, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
			</if>
			<if test="tag != null">
				tag_ = #{tag},
			</if>
			<if test="purchaseMinutes != null">
				purchase_minutes_ = #{purchaseMinutes},
			</if>
			<if test="giveMinutes != null">
				give_minutes_ = #{giveMinutes},
			</if>
			<if test="name != null">
				name_ = #{name},
			</if>
			<if test="createTime != null">
				create_time_ = #{createTime},
			</if>
			<if test="totalPrice != null">
				total_price_ = #{totalPrice},
			</if>
			<if test="detail != null">
				detail_ = #{detail},
			</if>
			<if test="endDate != null">
				end_date_ = #{endDate},
			</if>
			<if test="updateTime != null">
				update_time_ = #{updateTime},
			</if>
			<if test="discountPrice != null">
				discount_price_ = #{discountPrice},
			</if>
		</set>
		WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>

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

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="TenantEntryActivities"
		parameterType="map">
		SELECT * FROM tenant_entry_activities
		<include refid="queryCondition" />
		order by id_ desc
		<include refid="global.limit" />
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM tenant_entry_activities
		<include refid="queryCondition" />
		order by id_ desc
	</select>
</mapper>
