<?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.jeeplus.modules.workmeeting.dao.WorkmeetinguserDao">
    
	<sql id="workmeetinguserColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.type AS "type",
		a.user_id AS "user.id",
		a.meeting_id AS "meetingId",
		a.status AS "status",
		u.name AS "user.name",
		u.photo AS "user.photo"
	</sql>
	
	<sql id="workmeetinguserJoins">
		LEFT JOIN sys_user u ON u.id = a.user_id
	</sql>
	
    
	<select id="get" resultType="Workmeetinguser" >
		SELECT 
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByMeetingId" resultType="Workmeetinguser" >
		SELECT
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="user != null and user.id != null and user.id != ''">
				AND a.user_id = #{user.id}
			</if>
			<if test="meetingId != null and meetingId != ''">
				AND a.meeting_id = #{meetingId}
			</if>

		</where>
	</select>

	<select id="getByMeetingIdAndUser" resultType="Workmeetinguser" >
		SELECT
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="user != null and user.id != null and user.id != ''">
				AND a.user_id = #{user.id}
			</if>
			<if test="meetingId != null and meetingId != ''">
				AND a.meeting_id = #{meetingId}
			</if>

		</where>
	</select>

	<select id="getByUserId" resultType="Workmeetinguser" >
		SELECT
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="user != null and user.id != null and user.id != ''">
				AND a.user_id = #{user.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>

		</where>
	</select>

	<select id="findList" resultType="Workmeetinguser" >
		SELECT 
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="Workmeetinguser" >
		SELECT 
			<include refid="workmeetinguserColumns"/>
		FROM work_meeting_user a
		<include refid="workmeetinguserJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO work_meeting_user(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			type,
			user_id,
			meeting_id,
			status
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{type},
			#{user.id},
			#{meetingId},
			#{status}
		)
	</insert>
	
	<update id="update">
		UPDATE work_meeting_user SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			type = #{type},
			user_id = #{user.id},
			meeting_id = #{meetingId},
			status = #{status}
		WHERE id = #{id}
	</update>
	<update id="updateByRoomName">
		UPDATE work_meeting_user SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			status = #{status}
		WHERE meeting_id = #{meetingId} AND status &lt; 2
	</update>
	<update id="updateByUser">
		UPDATE work_meeting_user SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			status = #{status}
		WHERE user_id = #{user.id}
	</update>

	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_meeting_user
		WHERE id = #{id}
	</update>

	<!--物理删除-->
	<update id="deleteByRoomName">
		DELETE FROM work_meeting_user
		WHERE meeting_id = #{meetingId}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_meeting_user SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="Workmeetinguser" statementType="STATEMENT">
		select * FROM work_meeting_user  where ${propertyName} = '${value}'
	</select>
	
</mapper>