3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cn.iocoder.yudao.module.hrm.api.workhour;
 
import cn.iocoder.yudao.module.hrm.api.workhour.dto.HrmWorkHourSummaryRespDTO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.workhour.HrmWorkHourSummaryDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.workhour.HrmWorkHourSummaryMapper;
import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
/**
 * 月度工时汇总 API 实现
 *
 * @author 超级管理员
 */
@Service
public class HrmWorkHourSummaryApiImpl implements HrmWorkHourSummaryApi {
 
    @Resource
    private HrmWorkHourSummaryMapper workHourSummaryMapper;
    @Resource
    private HrmEmployeeService employeeService;
    @Resource
    private DeptApi deptApi;
 
    @Override
    public List<HrmWorkHourSummaryRespDTO> getSummaryByPeriod(String period) {
        return workHourSummaryMapper.selectListByPeriod(period).stream()
                .map(this::convert)
                .toList();
    }
 
    @Override
    public HrmWorkHourSummaryRespDTO getSummaryByEmployeeAndPeriod(Long employeeId, String period) {
        HrmWorkHourSummaryDO summary = workHourSummaryMapper.selectByEmployeeIdAndPeriod(employeeId, period);
        return summary == null ? null : convert(summary);
    }
 
    private HrmWorkHourSummaryRespDTO convert(HrmWorkHourSummaryDO summary) {
        HrmWorkHourSummaryRespDTO dto = new HrmWorkHourSummaryRespDTO();
        dto.setEmployeeId(summary.getEmployeeId());
        dto.setDeptId(summary.getDeptId());
        dto.setPeriod(summary.getPeriod());
        dto.setWorkDays(summary.getWorkDays());
        dto.setWorkHours(summary.getWorkHours());
        dto.setOvertimeHours(summary.getOvertimeHours());
        HrmEmployeeDO employee = employeeService.getEmployee(summary.getEmployeeId());
        if (employee != null) {
            dto.setEmployeeNo(employee.getEmployeeNo());
            dto.setEmployeeName(employee.getName());
        }
        if (summary.getDeptId() != null) {
            DeptRespDTO dept = deptApi.getDept(summary.getDeptId());
            if (dept != null) {
                dto.setDeptName(dept.getName());
            }
        }
        return dto;
    }
 
}