Commit a7d940ff authored by 王琮's avatar 王琮

考勤定时修改

parent 3ce8d6f2
package org.rcisoft.sys.attendance.schedule;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.rcisoft.sys.attendance.dao.AttendanceSyncRepository;
import org.rcisoft.sys.attendance.entity.Attendance;
import org.rcisoft.sys.attendance.entity.AttendanceSync;
import org.rcisoft.sys.attendance.service.AttendanceService;
import org.rcisoft.sys.sysuser.dao.SysUserRepositorys;
import org.rcisoft.sys.sysuser.entity.SysUser;
import org.rcisoft.sys.visit.entity.VisitInfoMation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
......@@ -31,10 +32,10 @@ public class AttendanceSyncSchedule {
// @Scheduled(cron = "0 0 0,15,16,17 * * ?")
// 每隔5秒执行一次
@Scheduled(cron = "0 */10 * * * ?")
@Scheduled(cron = "0 */1 * * * ?")
public void execute() {
Attendance attendance = new Attendance();
//查询考勤
// 查询昨日所有考勤
List<Attendance> all = attendanceService.findAll(attendance);
AttendanceSync attendanceSync = new AttendanceSync();
for (int i = 0; i < all.size(); i++) {
......@@ -60,7 +61,10 @@ public class AttendanceSyncSchedule {
}
attendanceSync.setCreateDate(new Date());
attendanceSync.setPassageTime(all.get(i).getCrossTime());
attendanceSyncRepository.addAttendanceSync(attendanceSync);
// 判断考勤是否已经存在,已经存在不会添加
//查询条件 查询比当前时间大的第一条记录
if (attendanceSyncRepository.queryAttendanceSyncs(attendanceSync).size() == 0)
attendanceSyncRepository.addAttendanceSync(attendanceSync);
}
}
}
......@@ -45,51 +45,37 @@ public class AttendanceServiceImpl implements AttendanceService {
@Override
public List<Attendance> findAll(Attendance attendance) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date1 = "2022-01-01 00:00:01";
String date2 = "2023-12-31 11:59:59";
try {
attendance.setBeginTime(simpleDateFormat.parse(date1));
attendance.setEndTime(simpleDateFormat.parse(date2));
} catch (ParseException e) {
e.printStackTrace();
}
List<Attendance> attendanceList = new ArrayList<>();
// 根据时间范围筛选所有打卡成功的记录
attendance.setBeginTime(TimeUtils.getDateNotTime(attendance.getBeginTime()));
attendance.setEndTime(TimeUtils.getDateEndDay(attendance.getEndTime()));
// 获取前一天的时间
Date update = TimeUtils.getUpdate();
attendance.setBeginTime(TimeUtils.getDateNotTime(update));
attendance.setEndTime(TimeUtils.getDateEndDay(update));
// 查询时间范围内员工的正常记录集合
List<DoorRecord> doorRecordList = doorRecordRepository.queryAttendance(attendance);
/*if (attendanceList.size() == 0)*/
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//这里可以指定日期的格式
// 根据用户分组(每个员工时间范围内的所有打卡记录)
Map<Integer, List<DoorRecord>> listMap = doorRecordList.stream()
.collect(Collectors.groupingBy(DoorRecord::getUserId));
for (Integer key : listMap.keySet()) {
// 根据考勤日期分组
Map<String, List<DoorRecord>> list = listMap.get(key).stream()
.collect(Collectors.groupingBy(f -> sdf.format(f.getCrossTime())));
for (String l : list.keySet()) {
List<DoorRecord> records = list.get(l);
// 某个员工某日所有通行记录
Attendance att = new Attendance();
att.setPeopleName(records.get(0).getName());
att.setPhoneNumber(records.get(0).getMobile());
att.setDeptName(records.get(0).getDeptName());
att.setPositionName(records.get(0).getPositionName());
att.setNltBz(records.get(0).getNltBz());
att.setKqDate(l);
att.setUserId(records.get(0).getUserId());
att = setValue(records, att);
if (att != null)
attendanceList.add(att);
}
List<DoorRecord> records = listMap.get(key);
// 某个员工某日所有通行记录
Attendance att = new Attendance();
att.setPeopleName(records.get(0).getName());
att.setPhoneNumber(records.get(0).getMobile());
att.setDeptName(records.get(0).getDeptName());
att.setPositionName(records.get(0).getPositionName());
att.setNltBz(records.get(0).getNltBz());
att.setKqDate(sdf.format(update));
att.setUserId(records.get(0).getUserId());
att = setValue(records, att);
if (att != null)
attendanceList.add(att);
}
return attendanceList;
}
// 整合考勤信息
Attendance setValue(List<DoorRecord> records, Attendance attendance) {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
......@@ -106,7 +92,7 @@ public class AttendanceServiceImpl implements AttendanceService {
if (work != null && out != null) {
String begin = time.format(work.getCrossTime());
String end = time.format(out.getCrossTime());
if ((begin.compareTo(end) > 0))
if (begin.compareTo(end) > 0)
return null;
attendance.setWorkShift(sdf.format(work.getCrossTime()));
attendance.setClosingTime(sdf.format(out.getCrossTime()));
......@@ -120,7 +106,7 @@ public class AttendanceServiceImpl implements AttendanceService {
beginTime = records.get(i).getCrossTime();
if (records.get(i).getDeviceType().equals("2"))
endTime = records.get(i).getCrossTime();
if (beginTime != null && endTime != null) {
if (beginTime != null && endTime != null && beginTime.compareTo(endTime) < 0) {
sumTime += TimeUtils.getDatePoor(beginTime, endTime);
beginTime = null;
endTime = null;
......
package org.rcisoft.sys.attendance.util;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class TimeUtils {
//验证日期格式是否正确
......@@ -50,4 +48,13 @@ public class TimeUtils {
}
public static Date getUpdate() {
Calendar calendar = new GregorianCalendar();
calendar.setTime(new Date());
int i = -1;
calendar.add(Calendar.DATE,i);
return calendar.getTime();
}
}
......@@ -21,7 +21,7 @@
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="abnormal" jdbcType="VARCHAR" property="abnormal" />
<result column="abnormal" jdbcType="VARCHAR" property="abnormal"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
......@@ -34,6 +34,14 @@
<if test="entity.flag !=null and entity.flag != '' ">
and flag = #{entity.flag}
</if>
// todo
<if test="entity.delFlag !=null and entity.delFlag != '' ">
and del_flag = #{entity.delFlag}
</if>
<if test="entity.delFlag !=null and entity.delFlag != '' ">
and del_flag = #{entity.delFlag}
</if>
</select>
<select id="queryAttendanceSyncsPaged" resultMap="BaseResultMap">
......@@ -45,24 +53,24 @@
<if test="entity.flag !=null and entity.flag != '' ">
and flag = #{entity.flag}
</if>
<if test="entity.beginDate != null and entity.beginDate != ''">
and date_of_attendance &gt;= #{entity.beginDate}
</if>
<if test="entity.endDate != null and entity.endDate != ''">
and date_of_attendance &lt;= #{entity.endDate}
</if>
<if test="entity.nltBz != null and entity.nltBz != ''">
and nlt_bz = #{entity.nltBz}
</if>
<if test="entity.sort == '0'.toString()">
order by work_hours
</if>
<if test="entity.sort == '1'.toString()">
order by off_hours
</if>
<if test="entity.sort == '2'.toString()">
order by time_on_job + 0
</if>
<if test="entity.beginDate != null and entity.beginDate != ''">
and date_of_attendance &gt;= #{entity.beginDate}
</if>
<if test="entity.endDate != null and entity.endDate != ''">
and date_of_attendance &lt;= #{entity.endDate}
</if>
<if test="entity.nltBz != null and entity.nltBz != ''">
and nlt_bz = #{entity.nltBz}
</if>
<if test="entity.sort == '0'.toString()">
order by work_hours
</if>
<if test="entity.sort == '1'.toString()">
order by off_hours
</if>
<if test="entity.sort == '2'.toString()">
order by time_on_job + 0
</if>
</select>
<insert id="addAttendanceSync" parameterType="org.rcisoft.sys.attendance.entity.AttendanceSync"
......
......@@ -114,8 +114,6 @@
where dr.del_flag = '0'
and dr.tenement_type = '0'
and dr.record_type = '1'
and dr.cross_time &gt; date_format(date_sub(now(), interval 1 DAY),'%Y-%m-%d')
AND dr.cross_time &lt; date_format(now(),'%Y-%m-%d')
<if test="attendance.beginTime !=null and attendance.endTime != null ">
and dr.cross_time between #{attendance.beginTime} and #{attendance.endTime}
</if>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment