<?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.oa.dao.OaAttendanceRuleDao">
    
	<sql id="oaAttendanceRuleColumns">
		a.id AS "id",
		a.company_id AS "company.id",
		a.start_time AS "startTime",
		a.end_time AS "endTime",
		a.workdays AS "workdays",
		a.wifi AS "wifi",
		a.wifi_name AS "wifiName",
		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.name AS "name",
		a.place_id AS "placeId",
		company.name AS "company.name"
	</sql>
	
	<sql id="oaAttendanceRuleJoins">
		LEFT JOIN sys_office company ON company.id = a.company_id
	</sql>
	
    
	<select id="get" resultType="OaAttendanceRule" >
		SELECT 
			<include refid="oaAttendanceRuleColumns"/>
		FROM oa_attendance_rule a
		<include refid="oaAttendanceRuleJoins"/>
		WHERE a.id = #{id} 
		GROUP BY a.id
	</select>
	
	<select id="findList" resultType="OaAttendanceRule" >
		SELECT 
			<include refid="oaAttendanceRuleColumns"/>
		FROM oa_attendance_rule a
		<include refid="oaAttendanceRuleJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="company != null and company.id != null and company.id != ''">
				AND a.company_id = #{company.id}
			</if>
			<if test="name != null and name != ''">
				AND a.name = #{name}
			</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="OaAttendanceRule" >
		SELECT 
			<include refid="oaAttendanceRuleColumns"/>
		FROM oa_attendance_rule a
		<include refid="oaAttendanceRuleJoins"/>
		<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 oa_attendance_rule(
			id,
			company_id,
			start_time,
			end_time,
			workdays,
			place_id,
			wifi,
			wifi_name,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			name
		) VALUES (
			#{id},
			#{company.id},
			#{startTime},
			#{endTime},
			#{workdays},
			#{placeId},
			#{wifi},
			#{wifiName},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{name}
		)
	</insert>
	
	<update id="update">
		UPDATE oa_attendance_rule SET 	
			company_id = #{company.id},
			start_time = #{startTime},
			end_time = #{endTime},
			workdays = #{workdays},
			place_id = #{placeId},
			wifi = #{wifi},
			wifi_name = #{wifiName},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			name = #{name}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM oa_attendance_rule
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE oa_attendance_rule SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="OaAttendanceRule" statementType="STATEMENT">
		select * FROM oa_attendance_rule  where ${propertyName} = '${value}'
	</select>
	
	
		<select id="findListByComapny" resultType="OaAttendanceRule">
		SELECT 
			*
		FROM oa_attendance_rule a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="company.id != null and company.id != ''">
				AND a.company_id = #{company.id}
			</if>
		</where>
	</select>

	<!-- 查询规则 -->
	<select id="queryRuleByCompanyIdAndRuleId" parameterType="java.util.HashMap" resultType="OaAttendanceRule">
		select * from oa_attendance_rule where id = #{ruleId} and company_id = #{companyId}
	</select>
</mapper>