Sfoglia il codice sorgente

修改考勤打卡方法

main
1341924763@qq.com 1 settimana fa
parent
commit
417ebe5aec

BIN
template-riben.xls Vedi File


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

@@ -82,4 +82,5 @@ public class AppDTO extends BaseEntity {

private String areaName;

private String checkInStatus;
}

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

@@ -5,7 +5,7 @@ import lombok.Data;
@Data
public class DayRecord {

private int day;
private String day;
private String weekday;
private String startTime;
private String endTime;
@@ -15,6 +15,8 @@ public class DayRecord {
private String yichang;
// 休息
private String xiuxi;
// 串休
private String chuanxiu;
// 调休
private String tiaoxiu;
// 值班

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

@@ -40,6 +40,14 @@ public class DkCheckInRecord extends BaseEntity {
@TableField(value = "`clock_in`")
private LocalDateTime clockIn;

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

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

// 下班打卡时间
@TableField(value = "`clock_out`")
private LocalDateTime clockOut;
@@ -50,4 +58,7 @@ public class DkCheckInRecord extends BaseEntity {
private String week;
@TableField(value = "`day`")
private int day;
// 描述
@TableField(value = "`description`")
private String description;
}

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

@@ -49,6 +49,10 @@ public class DkCheckInRecordDTO extends BaseEntity {

private LocalDateTime clockOut;

private String clockInStatus;

private String clockOutStatus;

private String description;

private int month;

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

@@ -17,4 +17,6 @@ public interface DkRecordMapper extends BaseMapperPlus<DkRecordMapper, DkCheckIn
public List<DkCheckInRecord> queryCurrentDayOutRecord(@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 Vedi File

@@ -29,6 +29,14 @@ public class DkAppServiceImpl implements DkAppService {
@Override
public String checkIn(AppDTO appDTO) {
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();
if(workStartTime == null){
@@ -42,10 +50,11 @@ public class DkAppServiceImpl implements DkAppService {
// }

// 解析给定的时分秒(格式:HH:mm:ss 或 HH:mm)
// true的时候表示当前时间在给定时间以前,属于正常打卡;false表示当前时间在给定时间以后,属于迟到打卡
boolean result = canSignIn(workStartTime);
// 初始化打卡记录对象
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
// true的时候可以签到,false的时候进行是否可以迟到签到
if(!result){
// 允许迟到打卡
if(appDTO1.getAllowLate()){
@@ -56,36 +65,60 @@ public class DkAppServiceImpl implements DkAppService {
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord);
return "迟到打卡";
}
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord);
return "打卡成功";
}else{
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insert(dkCheckInRecord);
return "迟到打卡";
}
@@ -95,13 +128,20 @@ public class DkAppServiceImpl implements DkAppService {
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setCheckInTime(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
dkCheckInRecord.setClockIn(TimeUtils.parseStr2LocalDateTime(appDTO.getClockIn()));
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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkRecordMapper.insert(dkCheckInRecord);
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功";
}

@@ -116,8 +156,8 @@ public class DkAppServiceImpl implements DkAppService {
LocalTime givenTime = LocalTime.parse(timeStr, formatter);
LocalTime currentTime = LocalTime.now();

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

public static boolean allowCheckIn(String timeStr, long maxDifferenceMinutes) {
@@ -145,6 +185,7 @@ public class DkAppServiceImpl implements DkAppService {

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

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

// 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录
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.setClockOut(TimeUtils.parseStr2LocalDateTime(appDTO.getClockOut()));
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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "提前打卡";
}
// 签到成功
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId());
dkCheckInRecord.setSysUserName(appDTO.getUserName());

dkCheckInRecord.setCheckInTime(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.setWeek(appDTO.getWeek());
dkCheckInRecord.setDay(appDTO.getDay());
dkCheckInRecord.setDescription(appDTO.getDescription());
dkRecordMapper.insertOrUpdate(dkCheckInRecord);
return "打卡成功";
}
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();

}else{
dkCheckInRecord = new DkCheckInRecord();
dkCheckInRecord.setSysUserId(appDTO.getUserId());
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.setWeek(appDTO.getWeek());
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()));
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.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);
return "打卡成功";
}

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

@@ -23,10 +23,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
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.util.ArrayList;
import java.util.Date;
@@ -117,10 +114,15 @@ public class DkRecordServiceImpl implements DkRecordService {
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = buildQueryWrapper(dkCheckInRecordDTO, "export");
List<DkCheckInRecordDTO> dkCheckInRecordDTOS = dkMapper.selectVoList(queryWrapper);
try {
FileInputStream templateFile;
FileInputStream templateFile = null;
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);
Sheet templateSheet = workbook.getSheetAt(0);
for (int i = 0; i < dkCheckInRecordDTOS.size(); i++){
@@ -146,9 +148,16 @@ public class DkRecordServiceImpl implements DkRecordService {
// 准备数据
dkCheckInRecordDTO.setSysUserId(dk.getSysUserId());
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);
}

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

// 构造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.setEndTime(null != dk.getClockOut() ? dk.getClockOut().format(DateTimeFormatter.ofPattern("HH:mm")) : "");
// 打卡异常判断
@@ -343,9 +355,9 @@ public class DkRecordServiceImpl implements DkRecordService {
// 填充数据表格
int rowIndex = 10; // 数据起始行(根据模板调整)
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, 5, record.getChidao());
// setCellValue(sheet, rowIndex, 6, record.getEndTime());
@@ -382,4 +394,139 @@ public class DkRecordServiceImpl implements DkRecordService {
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 Vedi File

@@ -12,4 +12,8 @@ public class Constans {
public static final String ZHOULIU = "周六";

public static final String ZHOURI = "周日";

public static final String GUONEI = "guonei";

public static final String RIBEN = "riben";
}

Loading…
Annulla
Salva