通过考勤组id获得考勤组人员Ids

This commit is contained in:
aikai 2024-05-27 14:26:11 +08:00
parent 7c07b3ec50
commit 7664d59676
6 changed files with 79 additions and 13 deletions

View File

@ -71,6 +71,15 @@ public class AttendanceGroupUserController {
return success(BeanUtils.toBean(groupUser, AttendanceGroupUserRespVO.class));
}
@GetMapping("/getUserIdsByGroupId")
@Operation(summary = "通过考勤组id获得考勤组人员Ids")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('attendance:group-user:query')")
public CommonResult<List<Long>> getUserIdsByGroupId(@RequestParam("id") Long id) {
List<Long> userIds = groupUserService.getUserIdsByGroupId(id);
return success(userIds);
}
@GetMapping("/page")
@Operation(summary = "获得考勤组人员分页")
@PreAuthorize("@ss.hasPermission('attendance:group-user:query')")

View File

@ -107,12 +107,12 @@ public class AttendancePunchRecordDO extends BaseDO {
private String punchAddress;
/**
* 迟到时长
* 迟到时长时间戳
*/
private String lateTime;
private Long lateTime;
/**
* 早退时长
* 迟到时长时间戳
*/
private String leaveEarlyTime;
private Long leaveEarlyTime;
}

View File

@ -50,6 +50,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static cn.hutool.core.date.DateUtil.dayOfWeekEnum;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
@ -420,6 +421,7 @@ public class AttendanceServiceImpl implements AttendanceService {
List<AttendancePunchRecordDO> list = attendancePunchRecordMapper.selectList(new LambdaQueryWrapper<AttendancePunchRecordDO>()
.eq(AttendancePunchRecordDO::getUserId, dto.getUserId())
.in(AttendancePunchRecordDO::getDayTime, dateList)
.eq(AttendancePunchRecordDO::getNextDayFlag, Constants.FALSE)
.orderByAsc(AttendancePunchRecordDO::getWorkType)
.orderByAsc(AttendancePunchRecordDO::getLevel));
// ---
@ -427,23 +429,63 @@ public class AttendanceServiceImpl implements AttendanceService {
List<AttendancePunchStatisticsVO> averageWorkingHours = new ArrayList<>();
List<AttendancePunchStatisticsVO> attendanceDays = new ArrayList<>();
List<AttendancePunchStatisticsVO> RestDays = new ArrayList<>();
// 总考勤时间
long totalWorkingHours = 0L;
// 总出勤天数
int totalAttendanceDays = 0;
// 总休息天数
int totalRestDays = 0;
// 迟到总次数
int totalBeLateFrequencys = 0;
// 迟到总时间
long totalBeLateTime = 0L;
for (Map.Entry<String, List<AttendancePunchRecordDO>> entry : map.entrySet()) {
//计算平均工时
AttendancePunchStatisticsVO averageWorkingHourVO = new AttendancePunchStatisticsVO();
averageWorkingHourVO.setDay(entry.getKey());
averageWorkingHourVO.setWeek(DateUtil.dayOfWeekEnum(DateUtil.parse(entry.getKey())).toChinese());
long totalWorkingHours = 0L;
String weekChinese = dayOfWeekEnum(DateUtil.parse(entry.getKey())).toChinese();
averageWorkingHourVO.setWeek(weekChinese);
// -- 按照班次子表分组
Map<Long, List<AttendancePunchRecordDO>> workMap = entry.getValue().stream().collect(Collectors.groupingBy(AttendancePunchRecordDO::getAttendanceGroupShiftItemId));
for (Map.Entry<Long, List<AttendancePunchRecordDO>> workEntry : workMap.entrySet()) {
if (CollectionUtil.isNotEmpty(workEntry.getValue()) && workEntry.getValue().size() >= 2) {
AttendancePunchRecordDO first = CollectionUtil.getFirst(workEntry.getValue());
AttendancePunchRecordDO last = CollectionUtil.getLast(workEntry.getValue());
if (ObjectUtil.isNotEmpty(first.getPunchTime()) && ObjectUtil.isNotEmpty(last.getPunchTime())) {
long time = Math.abs(LocalDateTimeUtil.between(first.getPunchTime(), last.getPunchTime(), ChronoUnit.MILLIS));
totalWorkingHours += time;
averageWorkingHourVO.setTime(DateUtil.formatBetween(time, BetweenFormatter.Level.HOUR));
if (CollectionUtil.isNotEmpty(workEntry.getValue())) {
// -- 出勤天数计算 -- 有打卡记录就算出勤了
List<AttendancePunchRecordDO> attendanceList = workEntry.getValue().stream().filter(a -> ObjectUtil.isNotEmpty(a.getPunchTime())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(attendanceList)) {
AttendancePunchStatisticsVO attendanceDayVO = new AttendancePunchStatisticsVO();
averageWorkingHourVO.setDay(entry.getKey());
averageWorkingHourVO.setWeek(weekChinese);
attendanceDays.add(attendanceDayVO);
totalAttendanceDays += 1;
}
// -- 工时计算 - 有上班和下班两个卡 才计算到工时里面
if (workEntry.getValue().size() >= 2) {
AttendancePunchRecordDO first = CollectionUtil.getFirst(workEntry.getValue());
AttendancePunchRecordDO last = CollectionUtil.getLast(workEntry.getValue());
if (ObjectUtil.isNotEmpty(first.getPunchTime()) && ObjectUtil.isNotEmpty(last.getPunchTime())) {
long time = Math.abs(LocalDateTimeUtil.between(first.getPunchTime(), last.getPunchTime(), ChronoUnit.MILLIS));
totalWorkingHours += time;
averageWorkingHourVO.setTime(DateUtil.formatBetween(time, BetweenFormatter.Level.HOUR));
}
}
// -- 迟到计算
List<AttendancePunchRecordDO> beLateList = workEntry.getValue().stream().filter(a -> AttendanceOnTheDayDTO.PUNCH_STATUS_LATE.equals(a.getStatus())).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(beLateList)) {
totalBeLateFrequencys += beLateList.size();
totalBeLateTime += beLateList.stream().mapToLong(AttendancePunchRecordDO::getLateTime).sum();
}
} else {
// -- 当天不需要考勤 则记录为休息
AttendancePunchStatisticsVO restDay = new AttendancePunchStatisticsVO();
restDay.setDay(entry.getKey());
restDay.setWeek(weekChinese);
RestDays.add(restDay);
totalRestDays += 1;
}
}
averageWorkingHours.add(averageWorkingHourVO);

View File

@ -53,4 +53,11 @@ public interface AttendanceGroupUserService {
*/
PageResult<AttendanceGroupUserDO> getGroupUserPage(AttendanceGroupUserPageReqVO pageReqVO);
/**
* 根据考勤组id获取考勤人员ids
*
* @param id
* @return
*/
List<Long> getUserIdsByGroupId(Long id);
}

View File

@ -98,4 +98,11 @@ public class AttendanceGroupUserServiceImpl implements AttendanceGroupUserServic
return groupUserMapper.selectPage(pageReqVO);
}
@Override
public List<Long> getUserIdsByGroupId(Long id) {
List<AttendanceGroupUserDO> list = groupUserMapper.selectList(new LambdaQueryWrapper<AttendanceGroupUserDO>()
.eq(AttendanceGroupUserDO::getAttendanceGroupId, id));
return list.stream().map(AttendanceGroupUserDO::getUserId).collect(Collectors.toList());
}
}

View File

@ -158,6 +158,7 @@ public class AttendanceSchedulingServiceImpl implements AttendanceSchedulingServ
return map;
}
@Override
public List<AttendanceSchedulingRespVO> getListByGroupId(Long attendanceGroupId) {
List<AttendanceSchedulingRespVO> respVOS = new ArrayList<>();