| | |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | 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 cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceRecordPageReqVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceRecordRespVO; |
| | | import cn.iocoder.yudao.module.hrm.controller.admin.attendance.vo.HrmAttendanceMyStatusRespVO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.attendance.HrmAttendanceRecordDO; |
| | | import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO; |
| | | import cn.iocoder.yudao.module.hrm.service.attendance.HrmAttendanceClockResult; |
| | | import cn.iocoder.yudao.module.hrm.service.attendance.HrmAttendanceRecordService; |
| | | import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService; |
| | | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| | |
| | | @PostMapping("/clock-in") |
| | | @Operation(summary = "上班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockIn(@RequestParam("location") String location) { |
| | | @ApiAccessLog(requestEnable = false) |
| | | public CommonResult<HrmAttendanceClockRespVO> 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 new ServiceException(EMPLOYEE_NOT_EXISTS.getCode(), |
| | | "当前登录账号未关联员工信息,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | } |
| | | HrmAttendanceRecordDO record = attendanceRecordService.clockIn(employee.getId(), LocalDateTime.now(), location); |
| | | HrmAttendanceRecordRespVO respVO = BeanUtils.toBean(record, HrmAttendanceRecordRespVO.class); |
| | | respVO.setUserName(employee.getName()); |
| | | if (record.getDeptId() != null) { |
| | | DeptRespDTO dept = deptApi.getDept(record.getDeptId()); |
| | | if (dept != null) { |
| | | respVO.setDeptName(dept.getName()); |
| | | } |
| | | } |
| | | return success(respVO); |
| | | HrmAttendanceClockResult result = attendanceRecordService.clockIn( |
| | | employee.getId(), LocalDateTime.now(), reqVO, legacyLocation); |
| | | return success(buildClockResultVO(result, employee)); |
| | | } |
| | | |
| | | @PostMapping("/clock-out") |
| | | @Operation(summary = "下班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockOut(@RequestParam("location") String location) { |
| | | @ApiAccessLog(requestEnable = false) |
| | | public CommonResult<HrmAttendanceClockRespVO> 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 new ServiceException(EMPLOYEE_NOT_EXISTS.getCode(), |
| | | "当前登录账号未关联员工信息,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | } |
| | | HrmAttendanceRecordDO record = attendanceRecordService.clockOut(employee.getId(), LocalDateTime.now(), location); |
| | | HrmAttendanceClockResult result = attendanceRecordService.clockOut( |
| | | employee.getId(), LocalDateTime.now(), reqVO, legacyLocation); |
| | | return success(buildClockResultVO(result, employee)); |
| | | } |
| | | |
| | | private HrmAttendanceRecordRespVO buildClockRespVO(HrmAttendanceRecordDO record, HrmEmployeeDO employee) { |
| | | HrmAttendanceRecordRespVO respVO = BeanUtils.toBean(record, HrmAttendanceRecordRespVO.class); |
| | | respVO.setUserName(employee.getName()); |
| | | if (record.getDeptId() != null) { |
| | |
| | | respVO.setDeptName(dept.getName()); |
| | | } |
| | | } |
| | | return success(respVO); |
| | | 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; |
| | | } |
| | | |
| | | @GetMapping("/my-status") |