Ver código fonte

修改考勤打卡方法

main
1341924763@qq.com 1 semana atrás
pai
commit
417ebe5aec

BIN
template-riben.xls Ver arquivo


+ 1
- 0
zs-manager/src/main/java/com/ruoyi/zhushi/entity/AppDTO.java Ver arquivo



private String areaName; private String areaName;


private String checkInStatus;
} }

+ 3
- 1
zs-manager/src/main/java/com/ruoyi/zhushi/entity/DayRecord.java Ver arquivo

@Data @Data
public class DayRecord { public class DayRecord {


private int day;
private String day;
private String weekday; private String weekday;
private String startTime; private String startTime;
private String endTime; private String endTime;
private String yichang; private String yichang;
// 休息 // 休息
private String xiuxi; private String xiuxi;
// 串休
private String chuanxiu;
// 调休 // 调休
private String tiaoxiu; private String tiaoxiu;
// 值班 // 值班

+ 11
- 0
zs-manager/src/main/java/com/ruoyi/zhushi/entity/DkCheckInRecord.java Ver arquivo

@TableField(value = "`clock_in`") @TableField(value = "`clock_in`")
private LocalDateTime clockIn; private LocalDateTime clockIn;


// 上班打卡状态
@TableField(value = "`clock_in_status`")
private String clockInStatus;

// 下班打卡状态
@TableField(value = "`clock_out_status`")
private String clockOutStatus;

// 下班打卡时间 // 下班打卡时间
@TableField(value = "`clock_out`") @TableField(value = "`clock_out`")
private LocalDateTime clockOut; private LocalDateTime clockOut;
private String week; private String week;
@TableField(value = "`day`") @TableField(value = "`day`")
private int day; private int day;
// 描述
@TableField(value = "`description`")
private String description;
} }

+ 4
- 0
zs-manager/src/main/java/com/ruoyi/zhushi/entity/DkCheckInRecordDTO.java Ver arquivo



private LocalDateTime clockOut; private LocalDateTime clockOut;


private String clockInStatus;

private String clockOutStatus;

private String description; private String description;


private int month; private int month;

+ 2
- 0
zs-manager/src/main/java/com/ruoyi/zhushi/mapper/DkRecordMapper.java Ver arquivo

public List<DkCheckInRecord> queryCurrentDayOutRecord(@Param("userId") long userId); public List<DkCheckInRecord> queryCurrentDayOutRecord(@Param("userId") long userId);


DkAttendanceGroup queryConfigByUserId(@Param("userId") long userId); DkAttendanceGroup queryConfigByUserId(@Param("userId") long userId);

DkCheckInRecord getRecordHistory(@Param("userId") long userId);
} }

+ 149
- 61
zs-manager/src/main/java/com/ruoyi/zhushi/service/impl/DkAppServiceImpl.java Ver arquivo

@Override @Override
public String checkIn(AppDTO appDTO) { public String checkIn(AppDTO appDTO) {
AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId()); AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId());

// 判断是否已经打卡,如果已经打卡,则不允许再次打卡
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper);
if (dkCheckInRecords.size() > 0){
return "已经打卡,不允许重复打卡!";
}
// 打卡开始时间 // 打卡开始时间
String workStartTime = appDTO1.getWorkStartTime(); String workStartTime = appDTO1.getWorkStartTime();
if(workStartTime == null){ if(workStartTime == null){
// } // }


// 解析给定的时分秒(格式:HH:mm:ss 或 HH:mm) // 解析给定的时分秒(格式:HH:mm:ss 或 HH:mm)
// true的时候表示当前时间在给定时间以前,属于正常打卡;false表示当前时间在给定时间以后,属于迟到打卡
boolean result = canSignIn(workStartTime); boolean result = canSignIn(workStartTime);
// 初始化打卡记录对象
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
// true的时候可以签到,false的时候进行是否可以迟到签到
if(!result){ if(!result){
// 允许迟到打卡 // 允许迟到打卡
if(appDTO1.getAllowLate()){ if(appDTO1.getAllowLate()){
dkCheckInRecord.setSysUserId(appDTO.getUserId()); dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName()); dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("3");
if (null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockInStatus(appDTO.getCheckInStatus());
} else {
dkCheckInRecord.setCheckInStatus("3");
dkCheckInRecord.setClockInStatus("3");
}
dkCheckInRecord.setClockInStatus(appDTO.getCheckInStatus());
// dkCheckInRecord.setCheckInStatus("3");
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord); dkRecordMapper.insert(dkCheckInRecord);
return "迟到打卡"; return "迟到打卡";
} }
dkCheckInRecord.setSysUserId(appDTO.getUserId()); dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName()); dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("1");
if (null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockInStatus(appDTO.getCheckInStatus());
} else {
dkCheckInRecord.setCheckInStatus("1");
dkCheckInRecord.setClockInStatus("1");
}
// dkCheckInRecord.setCheckInStatus("1");
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord); dkRecordMapper.insert(dkCheckInRecord);
return "打卡成功"; return "打卡成功";
}else{ }else{
dkCheckInRecord.setSysUserId(appDTO.getUserId()); dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName()); dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("3");
if (null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockInStatus(appDTO.getCheckInStatus());
} else {
dkCheckInRecord.setCheckInStatus("3");
dkCheckInRecord.setClockInStatus("3");
}
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord); dkRecordMapper.insert(dkCheckInRecord);
return "迟到打卡"; return "迟到打卡";
} }
dkCheckInRecord.setSysUserId(appDTO.getUserId()); dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName()); dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("1");
if (null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockInStatus(appDTO.getCheckInStatus());
}else {
dkCheckInRecord.setCheckInStatus("1");
dkCheckInRecord.setClockInStatus("1");
}
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkRecordMapper.insert(dkCheckInRecord);
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功"; return "打卡成功";
} }


LocalTime givenTime = LocalTime.parse(timeStr, formatter); LocalTime givenTime = LocalTime.parse(timeStr, formatter);
LocalTime currentTime = LocalTime.now(); LocalTime currentTime = LocalTime.now();


// 如果给定时间在当前时间之前,则可以签到
return givenTime.isBefore(currentTime);
// 如果当前时间再给定时间之前,则可以签到
return currentTime.isBefore(givenTime);
} }


public static boolean allowCheckIn(String timeStr, long maxDifferenceMinutes) { public static boolean allowCheckIn(String timeStr, long maxDifferenceMinutes) {


@Override @Override
public String checkOut(AppDTO appDTO) { public String checkOut(AppDTO appDTO) {
// 查询打卡配置信息
AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId()); AppDTO appDTO1 = dkAttendanceGroupMapper.queryAttendanceGroupBYUserId(appDTO.getUserId());
// 根据经纬度计算两点之间的距离 // 根据经纬度计算两点之间的距离
// double distanceKm = GeoDistanceUtil.getDistanceKm(appDTO.getLat(), appDTO.getLng(), appDTO1.getLat(), appDTO1.getLng()); // double distanceKm = GeoDistanceUtil.getDistanceKm(appDTO.getLat(), appDTO.getLng(), appDTO1.getLat(), appDTO1.getLng());
// return "超出范围"; // return "超出范围";
// } // }


// 打卡开始时间
// 打卡结束时间
String workEndTime = appDTO1.getWorkEndTime(); String workEndTime = appDTO1.getWorkEndTime();
if(workEndTime == null){ if(workEndTime == null){
return "系统设置错误"; return "系统设置错误";
// 获取当前天的下班打卡记录 // 获取当前天的下班打卡记录
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
queryWrapper.eq(DkCheckInRecord::getCheckInType, "clockOut");
// queryWrapper.eq(DkCheckInRecord::getCheckInType, "clockOut");
// queryWrapper.isNotNull(DkCheckInRecord::getClockOut);
queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime); queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime);

// 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录
List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper); List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper);
if(dkCheckInRecords.size() > 0){
DkCheckInRecord dkCheckInRecord = dkCheckInRecords.get(0);
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("5");
dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "更新打卡成功";
}
DkCheckInRecord dkCheckInRecord;


if(dkCheckInRecords.size() > 0){
dkCheckInRecord = dkCheckInRecords.get(0);
if(dkCheckInRecord.getClockOut() != null){
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else {
dkCheckInRecord.setCheckInStatus("5");
dkCheckInRecord.setClockOutStatus("5");
}
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "更新打卡成功";
}else{
// true的时候表示当前时间在给定时间以前,为提前打卡,false的时候正常打卡
boolean result = canSignIn(workEndTime);
if(result){
// 判断是否允许提前打卡
if(appDTO1.getAllowEarly()){
// 根据允许的范围进行是否可以打卡判断 true 在允许的范围内, false 不在允许的范围内
boolean b = allowCheckIn(workEndTime, appDTO.getEarlyRange());
if(!b){
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else{
dkCheckInRecord.setCheckInStatus("4");
dkCheckInRecord.setClockOutStatus("4");
}
dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
dkCheckInRecord.setDescription(appDTO.getDescription());
return "提前打卡";
}
// 签到成功
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else{
dkCheckInRecord.setCheckInStatus("2");
dkCheckInRecord.setClockOutStatus("2");
}
dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功";
}


// 解析给定的时分秒(格式:HH:mm:ss 或 HH:mm)
boolean result = canSignIn(workEndTime);
// true的时候为提前打卡,false的时候正常打卡
if(result){
// 判断是否允许提前打卡
if(appDTO1.getAllowEarly()){
// 根据允许的范围进行是否可以打卡判断 true 在允许的范围内, false 不在允许的范围内
boolean b = allowCheckIn(workEndTime, appDTO.getEarlyRange());
if(!b){
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("4");
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else{
dkCheckInRecord.setCheckInStatus("4");
dkCheckInRecord.setClockOutStatus("4");
}
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord); dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "提前打卡"; return "提前打卡";
} }
// 签到成功
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());

dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("2");
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else{
dkCheckInRecord.setCheckInStatus("2");
dkCheckInRecord.setClockOutStatus("2");
}
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord); dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功"; return "打卡成功";
} }
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();

}else{
dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId()); dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName()); dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("4");
dkCheckInRecord.setMonth(appDTO.getMonth()); dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek()); dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay()); dkCheckInRecord.setDay(appDTO.getDay());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "提前打卡";
}else{
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
if(null != appDTO.getCheckInStatus()){
dkCheckInRecord.setCheckInStatus(appDTO.getCheckInStatus());
dkCheckInRecord.setClockOutStatus(appDTO.getCheckInStatus());
}else{
dkCheckInRecord.setCheckInStatus("4");
dkCheckInRecord.setClockOutStatus("4");
}
dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut())); dkCheckInRecord.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
dkCheckInRecord.setCheckInType(appDTO.getCheckInType()); dkCheckInRecord.setCheckInType(appDTO.getCheckInType());
dkCheckInRecord.setCheckInStatus("2");
dkCheckInRecord.setMonth(appDTO.getMonth());
dkCheckInRecord.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());

dkRecordMapper.insertOrUpdate(dkCheckInRecord); dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功"; return "打卡成功";
} }

+ 163
- 16
zs-manager/src/main/java/com/ruoyi/zhushi/service/impl/DkRecordServiceImpl.java Ver arquivo

import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.*;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, "export"); LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, "export");
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper); List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
try { try {
FileInputStream templateFile;
FileInputStream templateFile = null;
Workbook workbook; Workbook workbook;
// 加载模板文件 // 加载模板文件
templateFile = new FileInputStream("template-guonei.xlsx");
if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){
templateFile = new FileInputStream("template-guonei.xlsx");
}
if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){
templateFile = new FileInputStream("template-riben.xlsx");
}
workbook = WorkbookFactory.create(templateFile); workbook = WorkbookFactory.create(templateFile);
Sheet templateSheet = workbook.getSheetAt(0); Sheet templateSheet = workbook.getSheetAt(0);
for (int i = 0; i < dkCheckInRecordDTOS.size(); i++){ for (int i = 0; i < dkCheckInRecordDTOS.size(); i++){
// 准备数据 // 准备数据
dkCheckInRecordDTO.setSysUserId(dk.getSysUserId()); dkCheckInRecordDTO.setSysUserId(dk.getSysUserId());
dkCheckInRecordDTO.setSysUserName(dk.getSysUserName()); dkCheckInRecordDTO.setSysUserName(dk.getSysUserName());
EmployeeAttendance attendanceData = prepareSampleData(dkCheckInRecordDTO);
// 填充数据到模板
fillTemplate(newSheet, attendanceData);
if(Constans.GUONEI.equals(dkCheckInRecordDTO.getModelType())){
EmployeeAttendance attendanceData = prepareSampleData(dkCheckInRecordDTO);
// 填充数据到模板
fillTemplate(newSheet, attendanceData);
}
if(Constans.RIBEN.equals(dkCheckInRecordDTO.getModelType())){
EmployeeAttendance attendanceData = prepareSampleDataRiBen(dkCheckInRecordDTO);
// 填充数据到模板
fillTemplateRiBen(newSheet, attendanceData);
}


} }
// 保存为新文件 // 保存为新文件
// 是否允许迟到 // 是否允许迟到
Boolean allowLate = dkAttendanceGroup.getAllowLate(); Boolean allowLate = dkAttendanceGroup.getAllowLate();
// 允许迟到的时长 // 允许迟到的时长
dkAttendanceGroup.getAllowLate();
Integer lateRange = dkAttendanceGroup.getLateRange();
// 是否允许早退 // 是否允许早退
Boolean allowEarly = dkAttendanceGroup.getAllowEarly(); Boolean allowEarly = dkAttendanceGroup.getAllowEarly();
// 允许早退的时长 // 允许早退的时长
// 构造excel数据 // 构造excel数据
for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){ for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){
// 根据打卡时间获取日期 // 根据打卡时间获取日期
LocalDate localDate = dk.getCheckInTime().toLocalDate();
LocalDate localDate = dk.getCheckInTime() != null ? dk.getCheckInTime().toLocalDate() : LocalDate.now();
// 构造当天开始打卡时间 // 构造当天开始打卡时间
String workStartTime = dkAttendanceGroup.getWorkStartTime(); String workStartTime = dkAttendanceGroup.getWorkStartTime();
LocalDateTime workStartTime1 = LocalDateTime.of(localDate, LocalTime.parse(workStartTime)); LocalDateTime workStartTime1 = LocalDateTime.of(localDate, LocalTime.parse(workStartTime));


// 构造DayRecord // 构造DayRecord
DayRecord dayRecord = new DayRecord(); DayRecord dayRecord = new DayRecord();
dayRecord.setDay(dk.getDay());
dayRecord.setWeekday(dk.getWeek());
dayRecord.setDay(localDate.toString());
// 获取星期几(返回 DayOfWeek 枚举)
DayOfWeek dayOfWeek = localDate.getDayOfWeek();
int week = dayOfWeek.getValue();
dayRecord.setWeekday(String.valueOf(week));
dayRecord.setStartTime(null != dk.getClockIn() ? dk.getClockIn().format(DateTimeFormatter.ofPattern("HH:mm")) : ""); dayRecord.setStartTime(null != dk.getClockIn() ? dk.getClockIn().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
dayRecord.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : ""); dayRecord.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
// 打卡异常判断 // 打卡异常判断
// 填充数据表格 // 填充数据表格
int rowIndex = 10; // 数据起始行(根据模板调整) int rowIndex = 10; // 数据起始行(根据模板调整)
for (DayRecord record : data.getDayRecords()) { for (DayRecord record : data.getDayRecords()) {
// setCellValue(sheet, rowIndex, 1, record.getDay());
// setCellValue(sheet, rowIndex, 2, record.getWeekday());
// setCellValue(sheet, rowIndex, 3, data.getDateTime());
setCellValue(sheet, rowIndex, 1, record.getDay());
setCellValue(sheet, rowIndex, 2, record.getWeekday());
setCellValue(sheet, rowIndex, 3, record.getStartTime());
setCellValue(sheet, rowIndex, 4, record.getEndTime()); setCellValue(sheet, rowIndex, 4, record.getEndTime());
setCellValue(sheet, rowIndex, 5, record.getChidao()); setCellValue(sheet, rowIndex, 5, record.getChidao());
// setCellValue(sheet, rowIndex, 6, record.getEndTime()); // setCellValue(sheet, rowIndex, 6, record.getEndTime());
cell.setCellValue(value.toString()); cell.setCellValue(value.toString());
} }
} }

private EmployeeAttendance prepareSampleDataRiBen(DkCheckInRecordDTO dkCheckInRecordDTO) {

// 定义员工类对象
EmployeeAttendance data = new EmployeeAttendance();
// 设置员工的名字
data.setEmployeeName(dkCheckInRecordDTO.getSysUserName());

// 判断月日是否为空
if(dkCheckInRecordDTO.getStrMonth() != null){
data.setDateTime(dkCheckInRecordDTO.getStrMonth());
}
if(dkCheckInRecordDTO.getStrDay() != null){
data.setDateTime(dkCheckInRecordDTO.getStrDay());
}

//根据userId获取打卡配置信息
DkAttendanceGroup dkAttendanceGroup = dkMapper.queryConfigByUserId(dkCheckInRecordDTO.getSysUserId());


// 是否允许迟到
Boolean allowLate = dkAttendanceGroup.getAllowLate();
// 允许迟到的时长
Integer lateRange = dkAttendanceGroup.getLateRange();
// 是否允许早退
Boolean allowEarly = dkAttendanceGroup.getAllowEarly();
// 允许早退的时长
Integer earlyRange = dkAttendanceGroup.getEarlyRange();

// 定义集合,用于存储每天打卡记录
List<DayRecord> dayRecords = new ArrayList<>();
// 根据用户的ID查询该用户所有的打卡记录
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, null);
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
// 构造excel数据
for(DkCheckInRecordDTO dk : dkCheckInRecordDTOS){
// 根据打卡时间获取日期
LocalDate localDate = dk.getCheckInTime().toLocalDate();
// 构造当天开始打卡时间
String workStartTime = dkAttendanceGroup.getWorkStartTime();
LocalDateTime workStartTime1 = LocalDateTime.of(localDate, LocalTime.parse(workStartTime));
// 构造当天结束打卡时间
String workEndTime = dkAttendanceGroup.getWorkEndTime();
LocalDateTime workEndTime1 = LocalDateTime.of(localDate, LocalTime.parse(workEndTime));

// 构造DayRecord
DayRecord dayRecord = new DayRecord();
dayRecord.setDay(localDate.toString());
dayRecord.setWeekday(dk.getWeek());
dayRecord.setStartTime(null != dk.getClockIn() ? dk.getClockIn().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
dayRecord.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
// 打卡异常判断
if(dk.getClockIn() != null && dk.getClockOut() != null){
if(dk.getClockIn().isAfter(workStartTime1)){
dayRecord.setChidao("*");
dayRecord.setRemark("迟到1次");
}
}

if(dk.getClockIn() != null && dk.getClockOut() == null){
dayRecord.setYichang("*");
dayRecord.setRemark("异常打卡");
}

// 判断是否为工作日加班
if(dk.getClockOut() != null){
if(dk.getClockOut().isAfter(workEndTime1)){
// 计算时间差
Duration duration = Duration.between(workEndTime1, dk.getClockOut());
// 获取小时差(注意:此方法会舍去分钟和秒部分)
long hours1 = duration.toMinutes(); // 结果:6 小时(15:45 - 09:30 = 6小时15分钟)

if(hours1 >= 30){
BigDecimal a = new BigDecimal(hours1);
BigDecimal b = new BigDecimal("60");
// 执行除法,指定精度和舍入模式
BigDecimal result = a.divide(b, 1, BigDecimal.ROUND_HALF_UP);
dayRecord.setGongzuori("*");
dayRecord.setRemark("加班1次:" + result + "小时");
}
}
}
// 判断是否为休假日加班
if(Constans.ZHOULIU.equals(dk.getWeek()) || Constans.ZHOURI.equals(dk.getWeek())){
dayRecord.setXiuxiri("*");
dayRecord.setRemark("加班1次");
}
// 判断是否为法定节假日加班
// // 获取法定节假日时间
// List<LocalDate> holidays = getHolidays(LocalDate.now().getYear());
// // 获取打卡日期
// int day = dk.getDay();



dayRecords.add(dayRecord);
}

// dayRecords.add(new DayRecord(1, "金", "09:05", "18:23", "迟到", "", 0.5, "会议"));
// dayRecords.add(new DayRecord(2, "土", "08:55", "18:30", "正常", "", 1.0, ""));
// dayRecords.add(new DayRecord(3, "日", "", "", "休息", "年假", 0, ""));
// 添加更多日期记录...

data.setDayRecords(dayRecords);
return data;
}

private void fillTemplateRiBen(Sheet sheet, EmployeeAttendance data) {
// 填充标题区域
setCellValue(sheet, 5, 13, data.getEmployeeName());
setCellValue(sheet, 2, 1, data.getDateTime());
// setCellValue(sheet, 2, 0, data.getYear() + "年" + data.getMonth() + "月考勤记录");

// 填充数据表格
int rowIndex = 9; // 数据起始行(根据模板调整)
for (DayRecord record : data.getDayRecords()) {
setCellValue(sheet, rowIndex, 0, record.getDay());
setCellValue(sheet, rowIndex, 1, record.getWeekday());
// setCellValue(sheet, rowIndex, 3, data.getDateTime());
setCellValue(sheet, rowIndex, 2, record.getStartTime());
setCellValue(sheet, rowIndex, 3, record.getEndTime());
// setCellValue(sheet, rowIndex, 6, record.getEndTime());
setCellValue(sheet, rowIndex, 4, record.getChidao());
setCellValue(sheet, rowIndex, 5, record.getYichang());
setCellValue(sheet, rowIndex, 6, record.getXiuxi());
setCellValue(sheet, rowIndex, 7, record.getChuanxiu());
setCellValue(sheet, rowIndex, 8, record.getZhiban());
setCellValue(sheet, rowIndex, 9, record.getQingjia());
setCellValue(sheet, rowIndex, 10, record.getNianjia());
setCellValue(sheet, rowIndex, 11, record.getJiaban());
setCellValue(sheet, rowIndex, 12, record.getHeji());
setCellValue(sheet, rowIndex, 13, record.getRemark());
rowIndex++;
}
}
} }

+ 4
- 0
zs-manager/src/main/java/com/ruoyi/zhushi/util/Constans.java Ver arquivo

public static final String ZHOULIU = "周六"; public static final String ZHOULIU = "周六";


public static final String ZHOURI = "周日"; public static final String ZHOURI = "周日";

public static final String GUONEI = "guonei";

public static final String RIBEN = "riben";
} }

Carregando…
Cancelar
Salvar