| | |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceClockReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceClockRespVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceMyStatusRespVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceRecordImportExcelVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceRecordImportReqVO; |
| | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.EMPLOYEE_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.hrm.enums.ErrorCodeConstants.ATTENDANCE_EMPLOYEE_NOT_BOUND; |
| | | import static cn.iocoder.yudao.module.hrm.enums.LogRecordConstants.*; |
| | | |
| | | @Tag(name = "管理后台 - HRM 考勤记录") |
| | |
| | | |
| | | @PostMapping("/clock-in") |
| | | @Operation(summary = "上班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | @ApiAccessLog(requestEnable = false) |
| | | public CommonResult<HrmAttendanceClockRespVO> clockIn( |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockIn( |
| | | @Valid @RequestBody(required = false) HrmAttendanceClockReqVO reqVO, |
| | | @RequestParam(value = "location", required = false) String legacyLocation) { |
| | | Long loginUserId = getLoginUserId(); |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(loginUserId); |
| | | if (employee == null) { |
| | | throw exception(EMPLOYEE_NOT_EXISTS, |
| | | "当前登录账号未关联员工档案,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | throw exception(ATTENDANCE_EMPLOYEE_NOT_BOUND); |
| | | } |
| | | HrmAttendanceClockResult result = attendanceRecordService.clockIn( |
| | | employee.getId(), LocalDateTime.now(), reqVO, legacyLocation); |
| | | return success(buildClockResultVO(result, employee)); |
| | | return success(buildClockRespVO(result.record(), employee)); |
| | | } |
| | | |
| | | @PostMapping("/clock-out") |
| | | @Operation(summary = "下班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | @ApiAccessLog(requestEnable = false) |
| | | public CommonResult<HrmAttendanceClockRespVO> clockOut( |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockOut( |
| | | @Valid @RequestBody(required = false) HrmAttendanceClockReqVO reqVO, |
| | | @RequestParam(value = "location", required = false) String legacyLocation) { |
| | | Long loginUserId = getLoginUserId(); |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(loginUserId); |
| | | if (employee == null) { |
| | | throw exception(EMPLOYEE_NOT_EXISTS, |
| | | "当前登录账号未关联员工档案,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | throw exception(ATTENDANCE_EMPLOYEE_NOT_BOUND); |
| | | } |
| | | HrmAttendanceClockResult result = attendanceRecordService.clockOut( |
| | | employee.getId(), LocalDateTime.now(), reqVO, legacyLocation); |
| | | return success(buildClockResultVO(result, employee)); |
| | | return success(buildClockRespVO(result.record(), employee)); |
| | | } |
| | | |
| | | @GetMapping("/my-status") |
| | | @Operation(summary = "获得当前登录人的考勤状态") |
| | | @Parameter(name = "date", description = "考勤日期,格式 yyyy-MM-dd,默认服务器当天", example = "2026-10-17") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | public CommonResult<HrmAttendanceMyStatusRespVO> getMyStatus( |
| | | @RequestParam(value = "date", required = false) |
| | | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) LocalDate date) { |
| | |
| | | if (dept != null) { |
| | | respVO.setDeptName(dept.getName()); |
| | | } |
| | | } |
| | | return respVO; |
| | | } |
| | | |
| | | private HrmAttendanceClockRespVO buildClockResultVO(HrmAttendanceClockResult result, |
| | | HrmEmployeeDO employee) { |
| | | HrmAttendanceClockRespVO respVO = new HrmAttendanceClockRespVO(); |
| | | respVO.setRecord(buildClockRespVO(result.record(), employee)); |
| | | respVO.setLocationName(result.rule().getLocationName()); |
| | | if (Boolean.TRUE.equals(result.rule().getLocationRequired())) { |
| | | respVO.setDistanceMeters(result.distanceMeters()); |
| | | respVO.setRadiusMeters(result.rule().getRadiusMeters()); |
| | | respVO.setWithinRange(true); |
| | | } |
| | | return respVO; |
| | | } |