| | |
| | | package com.xiaopeng.maintenance.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Boolean checkWorkStatus(Long appUserId) { |
| | | public Integer checkWorkStatus(Long appUserId) { |
| | | if (appUserId == null) { |
| | | log.warn("检查上班状态失败: appUserId 为空"); |
| | | return false; |
| | | return 1; |
| | | } |
| | | |
| | | try { |
| | |
| | | LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX); // 23:59:59 |
| | | |
| | | // 2. 查询当天打卡记录 |
| | | List<XpClockIn> records = baseMapper.selectTodayClockInRecords( |
| | | appUserId, startTime, endTime |
| | | ); |
| | | |
| | | XpClockIn xpClockIn = baseMapper.selectOne(new LambdaQueryWrapper<XpClockIn>() |
| | | .eq(XpClockIn::getAppUserId, appUserId) |
| | | .between(XpClockIn::getClockInTime, startTime, endTime) |
| | | .last("limit 1")); |
| | | // 3. 判断上班状态 |
| | | if (records == null || records.isEmpty()) { |
| | | // 无打卡记录 = 未上班 |
| | | log.debug("用户 {} 今日无打卡记录, workFlag=false", appUserId); |
| | | return false; |
| | | } else if (records.size() == 1) { |
| | | // 1条记录 = 已上班未下班 |
| | | log.debug("用户 {} 今日打卡1次, workFlag=true", appUserId); |
| | | return true; |
| | | // 有上班打卡状态,无下班打卡状态 |
| | | if (Objects.isNull(xpClockIn)) { |
| | | return 1; |
| | | } else if (Objects.nonNull(xpClockIn.getClockInResult()) && Objects.isNull(xpClockIn.getClockOutResult())) { |
| | | return 2; |
| | | } else { |
| | | // 2条及以上记录 = 已下班 |
| | | log.debug("用户 {} 今日打卡{}次, workFlag=false", appUserId, records.size()); |
| | | return false; |
| | | return 3; |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("检查用户上班状态异常, appUserId={}", appUserId, e); |
| | | // 异常情况返回 false |
| | | return false; |
| | | return 1; |
| | | } |
| | | } |
| | | |