<?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.workattendance.dao.WorkAttendancePlaceDao">
    
	<sql id="workAttendancePlaceColumns">
		a.id AS "id",
		a.area_id AS "area.id",
		a.place_name AS "placeName",
		a.place_scope AS "placeScope",
		a.wifi AS "wifi",
		a.wifi_name AS "wifiName",
		a.longitude AS "longitude",
		a.latitude AS "latitude",
		a.attendance_rule_id AS "workAttendanceRule.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",
		area.name AS "area.name"
	</sql>
	
	<sql id="workAttendancePlaceJoins">
		LEFT JOIN sys_area area ON area.id = a.area_id
	</sql>
	
    
	<select id="get" resultType="WorkAttendancePlace" >
		SELECT 
			<include refid="workAttendancePlaceColumns"/>
		FROM work_attendance_place a
		<include refid="workAttendancePlaceJoins"/>
		WHERE a.id = #{id}
	</select>
	<select id="getByRuleId" resultType="WorkAttendancePlace" >
		SELECT
			<include refid="workAttendancePlaceColumns"/>
		FROM work_attendance_place a
		<include refid="workAttendancePlaceJoins"/>
		WHERE a.attendance_rule_id = #{workAttendanceRule.id}
	</select>

	<select id="findList" resultType="WorkAttendancePlace" >
		SELECT 
			<include refid="workAttendancePlaceColumns"/>
		FROM work_attendance_place a
		<include refid="workAttendancePlaceJoins"/>
		<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="WorkAttendancePlace" >
		SELECT 
			<include refid="workAttendancePlaceColumns"/>
		FROM work_attendance_place a
		<include refid="workAttendancePlaceJoins"/>
		<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_attendance_place(
			id,
			area_id,
			place_name,
			place_scope,
			wifi,
			wifi_name,
			longitude,
			latitude,
			attendance_rule_id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{area.id},
			#{placeName},
			#{placeScope},
			#{wifi},
			#{wifiName},
			#{longitude},
			#{latitude},
			#{workAttendanceRule.id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>
	
	<update id="update">
		UPDATE work_attendance_place SET 	
			area_id = #{area.id},
			place_name = #{placeName},
			place_scope = #{placeScope},
			wifi = #{wifi},
			wifi_name = #{wifiName},
			longitude = #{longitude},
			latitude = #{latitude},
			attendance_rule_id = #{workAttendanceRule.id},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_attendance_place
		WHERE id = #{id}
	</update>
	<!--物理删除-->
	<update id="deleteByRuleId">
		DELETE FROM work_attendance_place
		WHERE attendance_rule_id = #{workAttendanceRule.id}
	</update>

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