| | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| | | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| | | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| | | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| | |
| | | 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.HrmAttendanceRecordService; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | |
| | | @PostMapping("/clock-in") |
| | | @Operation(summary = "上班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance:clock')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockIn(@RequestParam("location") String location) { |
| | | Long loginUserId = getLoginUserId(); |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(loginUserId); |
| | | if (employee == null) { |
| | | throw exception(EMPLOYEE_NOT_EXISTS, "当前用户未关联员工信息,无法打卡"); |
| | | throw new ServiceException(EMPLOYEE_NOT_EXISTS.getCode(), |
| | | "当前登录账号未关联员工信息,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | } |
| | | HrmAttendanceRecordDO record = attendanceRecordService.clockIn(employee.getId(), LocalDateTime.now(), location); |
| | | HrmAttendanceRecordRespVO respVO = BeanUtils.toBean(record, HrmAttendanceRecordRespVO.class); |
| | |
| | | |
| | | @PostMapping("/clock-out") |
| | | @Operation(summary = "下班打卡") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance:clock')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:clock')") |
| | | public CommonResult<HrmAttendanceRecordRespVO> clockOut(@RequestParam("location") String location) { |
| | | Long loginUserId = getLoginUserId(); |
| | | HrmEmployeeDO employee = employeeService.getEmployeeByUserId(loginUserId); |
| | | if (employee == null) { |
| | | throw exception(EMPLOYEE_NOT_EXISTS, "当前用户未关联员工信息,无法打卡"); |
| | | throw new ServiceException(EMPLOYEE_NOT_EXISTS.getCode(), |
| | | "当前登录账号未关联员工信息,无法打卡。请联系管理员在【员工管理】中将该登录账号绑定到员工。"); |
| | | } |
| | | HrmAttendanceRecordDO record = attendanceRecordService.clockOut(employee.getId(), LocalDateTime.now(), location); |
| | | HrmAttendanceRecordRespVO respVO = BeanUtils.toBean(record, HrmAttendanceRecordRespVO.class); |
| | |
| | | return success(respVO); |
| | | } |
| | | |
| | | private Long getLoginUserId() { |
| | | return cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId(); |
| | | @GetMapping("/my-status") |
| | | @Operation(summary = "获得当前登录人的考勤状态", description = "App 打卡页使用:返回当日考勤规则、打卡记录与可打卡状态") |
| | | @Parameter(name = "date", description = "考勤日期,格式 yyyy-MM-dd,默认服务器当天", example = "2026-10-17") |
| | | public CommonResult<HrmAttendanceMyStatusRespVO> getMyStatus( |
| | | @RequestParam(value = "date", required = false) |
| | | @org.springframework.format.annotation.DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { |
| | | return success(attendanceRecordService.getMyStatus(getLoginUserId(), date)); |
| | | } |
| | | |
| | | private Long getLoginUserId() { |
| | | return cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId(); } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得考勤记录分页") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance:query')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:query')") |
| | | public CommonResult<PageResult<HrmAttendanceRecordRespVO>> getAttendanceRecordPage(@Valid HrmAttendanceRecordPageReqVO pageReqVO) { |
| | | PageResult<HrmAttendanceRecordDO> pageResult = attendanceRecordService.getAttendanceRecordPage(pageReqVO); |
| | | // 转换为 VO |
| | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得考勤记录") |
| | | @Parameter(name = "id", description = "记录ID", required = true) |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance:query')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:query')") |
| | | public CommonResult<HrmAttendanceRecordRespVO> getAttendanceRecord(@RequestParam("id") Long id) { |
| | | HrmAttendanceRecordDO attendanceRecord = attendanceRecordService.getAttendanceRecord(id); |
| | | if (attendanceRecord == null) { |
| | |
| | | |
| | | @GetMapping("/export-excel") |
| | | @Operation(summary = "导出考勤记录 Excel") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance:export')") |
| | | @PreAuthorize("@ss.hasPermission('hrm:attendance-record:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportAttendanceRecordExcel(@Valid HrmAttendanceRecordPageReqVO pageReqVO, |
| | | HttpServletResponse response) throws IOException { |