<?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.ActivityUserMapperAdjustLogDao">
	
	<resultMap type="com.ym.mec.biz.dal.entity.ActivityUserMapperAdjustLog" id="ActivityUserMapperAdjustLog">
		<result column="id_" property="id" />
		<result column="operator_id_" property="operatorId" />
		<result column="operator_name_" property="operatorName" />
		<result column="activity_id_" property="activityId" />
		<result column="course_num_" property="courseNum" />
		<result column="give_course_num_" property="giveCourseNum" />
		<result column="memo_" property="memo" />
		<result column="user_id_" property="userId" />
		<result column="type_" property="type" />
		<result column="activity_user_mapper_id_" property="activityUserMapperId" />
		<result column="create_time_" property="createTime" />
		<result column="update_time_" property="updateTime" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>
	
	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="ActivityUserMapperAdjustLog" >
		SELECT * FROM activity_user_mapper_adjust_log WHERE id_ = #{id} 
	</select>
	
	<!-- 全查询 -->
	<select id="findAll" resultMap="ActivityUserMapperAdjustLog">
		SELECT * FROM activity_user_mapper_adjust_log where tenant_id_ = #{tenantId} ORDER BY id_
	</select>
	
	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapperAdjustLog" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO activity_user_mapper_adjust_log (operator_id_,operator_name_,activity_id_,
		                                             course_num_,give_course_num_,memo_,user_id_,create_time_,update_time_,type_,activity_user_mapper_id_,tenant_id_)
		VALUES(#{operatorId},#{operatorName},#{activityId},#{courseNum},#{giveCourseNum},#{memo},#{userId},NOW(),NOW(),#{type},#{activityUserMapperId},#{tenantId})
	</insert>
	<insert id="batchInsert">
		INSERT INTO activity_user_mapper_adjust_log (operator_id_,operator_name_,activity_id_,course_num_,
		                                             give_course_num_,memo_,user_id_,create_time_,update_time_,type_,activity_user_mapper_id_,tenant_id_)
		VALUES
		<foreach collection="logs" separator="," item="bean">
			(#{bean.operatorId},#{bean.operatorName},#{bean.activityId},#{bean.courseNum},#{bean.giveCourseNum},#{bean.memo},#{bean.userId},NOW(),NOW(),#{bean.type},#{bean.activityUserMapperId},#{bean.tenantId})
		</foreach>
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.ym.mec.biz.dal.entity.ActivityUserMapperAdjustLog">
		UPDATE activity_user_mapper_adjust_log <set>
		<if test="operatorId != null">
		operator_id_ = #{operatorId},
		</if>
		<if test="userId != null">
		user_id_ = #{userId},
		</if>
		<if test="courseNum != null">
		course_num_ = #{courseNum},
		</if>
		<if test="memo != null">
		memo_ = #{memo},
		</if>
		<if test="operatorName != null">
		operator_name_ = #{operatorName},
		</if>
		<if test="giveCourseNum != null">
		give_course_num_ = #{giveCourseNum},
		</if>
		<if test="activityId != null">
		activity_id_ = #{activityId},
		</if>
		update_time_ = NOW()
		</set> WHERE id_ = #{id} and tenant_id_ = #{tenantId}
	</update>
	
	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM activity_user_mapper_adjust_log WHERE id_ = #{id} 
	</delete>
	
	<!-- 分页查询 -->
	<select id="queryPage" resultMap="ActivityUserMapperAdjustLog" parameterType="map">
		SELECT * FROM activity_user_mapper_adjust_log where tenant_id_ = #{tenantId}
		<if test="userId != null">
			AND user_id_ = #{userId}
		</if>
		<if test="activityId != null">
			AND activity_id_ = #{activityId}
		</if>
		ORDER BY id_ DESC
		<include refid="global.limit"/>
	</select>
	
	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM activity_user_mapper_adjust_log where tenant_id_ = #{tenantId}
		<if test="userId != null">
			AND user_id_ = #{userId}
		</if>
		<if test="activityId != null">
			AND activity_id_ = #{activityId}
		</if>
	</select>
</mapper>
