<?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.workevaluationroom.dao.WorkEvaluationRoomDao">
    
	<sql id="workEvaluationRoomColumns">
		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.del_flag AS "delFlag",
		a.remarks AS "remarks",
		a.address AS "address",
		a.floor AS "floor",
		a.house_number AS "houseNumber",
		a.company_id AS "companyId",
		a.office_id AS "office.id",
		office.name AS "office.name"
	</sql>
	
	<sql id="workEvaluationRoomJoins">
		LEFT JOIN sys_office office ON office.id = a.office_id
	</sql>
	
    
	<select id="get" resultType="WorkEvaluationRoom" >
		SELECT 
			<include refid="workEvaluationRoomColumns"/>
		FROM work_evaluation_room a
		<include refid="workEvaluationRoomJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkEvaluationRoom" >
		SELECT 
			<include refid="workEvaluationRoomColumns"/>
		FROM work_evaluation_room a
		<include refid="workEvaluationRoomJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="address != null and address != ''">
				AND a.address LIKE 
					<if test="dbName == 'oracle'">'%'||#{address}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{address}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{address},'%')</if>
			</if>
			<if test="floor != null and floor != ''">
				AND a.floor LIKE 
					<if test="dbName == 'oracle'">'%'||#{floor}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{floor}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{floor},'%')</if>
			</if>
			<if test="houseNumber != null and houseNumber != ''">
				AND a.house_number LIKE 
					<if test="dbName == 'oracle'">'%'||#{houseNumber}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{houseNumber}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{houseNumber},'%')</if>
			</if>
		</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="WorkEvaluationRoom" >
		SELECT 
			<include refid="workEvaluationRoomColumns"/>
		FROM work_evaluation_room a
		<include refid="workEvaluationRoomJoins"/>
		<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_evaluation_room(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			del_flag,
			remarks,
			address,
			floor,
			house_number,
			company_id,
			office_id
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{delFlag},
			#{remarks},
			#{address},
			#{floor},
			#{houseNumber},
			#{companyId},
			#{office.id}
		)
	</insert>
	
	<update id="update">
		UPDATE work_evaluation_room SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			address = #{address},
			floor = #{floor},
			house_number = #{houseNumber},
			company_id = #{companyId},
			office_id = #{office.id}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_evaluation_room
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_evaluation_room SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkEvaluationRoom" statementType="STATEMENT">
		select * FROM work_evaluation_room  where ${propertyName} = '${value}'
	</select>
	
</mapper>