Browse Source

1.打卡优化

main
wangqiang 2 weeks ago
parent
commit
70ac5f0a00

+ 18
- 18
zs-manager/src/main/java/com/ruoyi/zhushi/service/impl/DkAppServiceImpl.java View File



import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException; import java.time.format.DateTimeParseException;


// 初始化打卡记录对象 // 初始化打卡记录对象
DkCheckInRecord dkCheckInRecord = new DkCheckInRecord(); DkCheckInRecord dkCheckInRecord = new DkCheckInRecord();

LocalDate today = LocalDate.now();
LocalDateTime startOfDay = today.atStartOfDay();
LocalDateTime endOfDay = today.plusDays(1).atStartOfDay();
// 构造查询条件 // 构造查询条件
LambdaQueryWrapper<DkCheckInRecord> queryWrapper1 = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DkCheckInRecord> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); queryWrapper1.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
queryWrapper1.between(DkCheckInRecord::getCheckInTime,startOfDay,endOfDay);
List<DkCheckInRecord> dkCheckInRecords1 = dkRecordMapper.selectList(queryWrapper1); List<DkCheckInRecord> dkCheckInRecords1 = dkRecordMapper.selectList(queryWrapper1);


// 判断是否已经存在打卡数据 // 判断是否已经存在打卡数据
if(dkCheckInRecords1.size() > 0){ if(dkCheckInRecords1.size() > 0){
System.out.println("已存在打卡数据"+ LocalDate.now() );
dkCheckInRecord = dkCheckInRecords1.stream().filter(dkCheckInRecord1 -> dkCheckInRecord1.getCheckInTime().toLocalDate().equals(LocalDate.now())).findFirst().orElse(null);
dkCheckInRecord = dkCheckInRecords1.get(0);
} }


// true的时候表示当前时间在给定时间以前,属于正常打卡;false表示当前时间在给定时间以后,属于迟到打卡 // true的时候表示当前时间在给定时间以前,属于正常打卡;false表示当前时间在给定时间以后,属于迟到打卡
if(workEndTime == null){ if(workEndTime == null){
return "系统设置错误"; return "系统设置错误";
} }
LocalDate today = LocalDate.now();
LocalDateTime startOfDay = today.atStartOfDay();
LocalDateTime endOfDay = today.plusDays(1).atStartOfDay();
// 获取当前天的下班打卡记录 // 获取当前天的下班打卡记录
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId()); queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
queryWrapper.apply("DATE(check_in_time) = DATE(NOW())");
queryWrapper.between(DkCheckInRecord::getCheckInTime,startOfDay,endOfDay);
queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime); queryWrapper.orderByDesc(DkCheckInRecord::getCheckInTime);


// 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录 // 如果存在下班打卡记录,则更新打卡记录,否则插入打卡记录


@Override @Override
public List<DkCheckInRecord> getCurrentDayRecord(AppDTO appDTO) { public List<DkCheckInRecord> getCurrentDayRecord(AppDTO appDTO) {
LocalDate currentDate = LocalDate.now();
// List<DkCheckInRecord> currentDayRecords = dkRecordMapper.getCurrentDayRecord(appDTO.getUserId(), currentDate);
LambdaQueryWrapper<DkCheckInRecord> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
List<DkCheckInRecord> dkCheckInRecords1 = dkRecordMapper.selectList(queryWrapper1);
LocalDate today = LocalDate.now();
LocalDateTime startOfDay = today.atStartOfDay();
LocalDateTime endOfDay = today.plusDays(1).atStartOfDay();


// 判断是否已经存在打卡数据
List<DkCheckInRecord> results = new ArrayList<>();
DkCheckInRecord dkCheckInRecord;
if(dkCheckInRecords1.size() > 0){
System.out.println("已存在打卡数据"+ LocalDate.now() );
dkCheckInRecord = dkCheckInRecords1.stream().filter(dkCheckInRecord1 -> dkCheckInRecord1.getCheckInTime().toLocalDate().equals(LocalDate.now())).findFirst().orElse(null);
results.add(dkCheckInRecord);
}
return results;
LambdaQueryWrapper<DkCheckInRecord> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(DkCheckInRecord::getSysUserId, appDTO.getUserId());
queryWrapper.between(DkCheckInRecord::getCheckInTime,startOfDay,endOfDay);
List<DkCheckInRecord> dkCheckInRecords = dkRecordMapper.selectList(queryWrapper);
return dkCheckInRecords;
} }


@Override @Override

Loading…
Cancel
Save