<?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.WorkAttendanceAuditDao">
    
	<sql id="workAttendanceAuditColumns">
		a.id AS "id",
		a.company_id AS "companyId",
		a.office_id AS "office.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.staff_id AS "staffId",
		a.attendance_date AS "attendanceDate",
		a.attendance_type AS "attendanceType",
		a.type AS "type",
		a.is_overtime AS "isOvertime",
		a.date_type AS "dateType",
		a.overtime_time AS "overtimeTime",
		a.holiday_type AS "holidayType",
		a.is_calculate_attendance AS "isCalculateAttendance",
		a.is_calculate_subsidies AS "isCalculateSubsidies",
		a.attendance_place AS "attendancePlace",
		a.attendance_time AS "attendanceTime",
		a.photo AS "photo",
		a.late_early AS "lateEarly",
		a.late_early_time AS "lateEarlyTime",
		a.is_valid AS "isValid",
		a.morning_afternoon AS "morningAfternoon",
		a.is_holidays AS "isHolidays",
		a.user_id AS "userId",
		a.lnt AS "lnt",
		a.lat AS "lat",
		a.wifi AS "wifi",
		a.status AS "status",
		a.wid AS "wid",
		a.rule_id AS "workAttendanceRule.id",
		office.name AS "office.name"
	</sql>
	
	<sql id="workAttendanceAuditJoins">
		LEFT JOIN sys_office office ON office.id = a.office_id
	</sql>
	
    
	<select id="get" resultType="WorkAttendanceInfo" >
		SELECT 
			<include refid="workAttendanceAuditColumns"/>
		FROM work_attendance_audit a
		<include refid="workAttendanceAuditJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkAttendanceInfo" >
		SELECT 
			<include refid="workAttendanceAuditColumns"/>
		FROM work_attendance_audit a
		<include refid="workAttendanceAuditJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="companyId != null and companyId != ''">
				AND a.company_id = #{companyId}
			</if>
			<if test="staffId != null and staffId != ''">
				AND a.staff_id = #{staffId}
			</if>
			<if test="attendanceDate != null and attendanceDate != ''">
				AND a.attendance_date = #{attendanceDate}
			</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="WorkAttendanceInfo" >
		SELECT 
			<include refid="workAttendanceAuditColumns"/>
		FROM work_attendance_audit a
		<include refid="workAttendanceAuditJoins"/>
		<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_audit(
			id,
			company_id,
			office_id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			staff_id,
			attendance_date,
			attendance_type,
			type,
			is_overtime,
			date_type,
			overtime_time,
			holiday_type,
			is_calculate_attendance,
			is_calculate_subsidies,
			attendance_place,
			attendance_time,
			photo,
			late_early,
			late_early_time,
			morning_afternoon,
			is_holidays,
			user_id,
			rule_id,
			lnt,
			lat,
			wifi,
			status,
			wid,
			is_valid
		) VALUES (
			#{id},
			#{companyId},
			#{office.id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{staffId},
			#{attendanceDate},
			#{attendanceType},
			#{type},
			#{isOvertime},
			#{dateType},
			#{overtimeTime},
			#{holidayType},
			#{isCalculateAttendance},
			#{isCalculateSubsidies},
			#{attendancePlace},
			#{attendanceTime},
			#{photo},
			#{lateEarly},
			#{lateEarlyTime},
			#{morningAfternoon},
			#{isHolidays},
			#{userId},
			#{workAttendanceRule.id},
			#{lnt},
			#{lat},
			#{wifi},
			#{status},
			#{wid},
			#{isValid}
		)
	</insert>
	
	<update id="update">
		UPDATE work_attendance_audit SET 	
			company_id = #{companyId},
			office_id = #{office.id},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			staff_id = #{staffId},
			attendance_date = #{attendanceDate},
			attendance_type = #{attendanceType},
			type = #{type},
			is_overtime = #{isOvertime},
			date_type = #{dateType},
			overtime_time = #{overtimeTime},
			holiday_type = #{holidayType},
			is_calculate_attendance = #{isCalculateAttendance},
			is_calculate_subsidies = #{isCalculateSubsidies},
			attendance_place = #{attendancePlace},
			attendance_time = #{attendanceTime},
			photo = #{photo},
			late_early = #{lateEarly},
			late_early_time = #{lateEarlyTime},
			morning_afternoon = #{morningAfternoon},
			is_holidays = #{isHolidays},
			is_valid = #{isValid},
			lnt = #{lnt},
			lat = #{lat},
			wifi = #{wifi},
			status = #{status},
			wid = #{wid},
			rule_id = #{workAttendanceRule.id},
			user_id = #{userId}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_attendance_audit
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_attendance_audit SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkAttendanceInfo" statementType="STATEMENT">
		select * FROM work_attendance_audit  where ${propertyName} = '${value}'
	</select>
	
</mapper>