gaoluyang
5 天以前 eee03bbfea8b15d1a56ab63bd09a35c6c861c4cb
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
66
67
68
69
package cn.iocoder.yudao.module.hrm.api.employee;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.hrm.api.employee.dto.HrmEmployeeSimpleRespDTO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.service.employee.HrmEmployeeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
 
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * 员工信息 API 实现
 *
 * @author 超级管理员
 */
@Service
public class HrmEmployeeApiImpl implements HrmEmployeeApi {
 
    @Resource
    private HrmEmployeeService employeeService;
 
    @Override
    public List<HrmEmployeeSimpleRespDTO> getEmployeeListByPostIds(Collection<Long> postIds) {
        return convertList(employeeService.getEmployeeListByPostIds(postIds));
    }
 
    @Override
    public Map<Long, HrmEmployeeSimpleRespDTO> getEmployeeMap(Collection<Long> ids) {
        return CollectionUtils.convertMap(convertList(employeeService.getEmployeeList(ids)),
                HrmEmployeeSimpleRespDTO::getId);
    }
 
    @Override
    public HrmEmployeeSimpleRespDTO getEmployeeByUserId(Long userId) {
        if (userId == null) {
            return null;
        }
        HrmEmployeeDO employee = employeeService.getEmployeeByUserId(userId);
        return employee == null ? null : buildDTO(employee);
    }
 
    private List<HrmEmployeeSimpleRespDTO> convertList(List<HrmEmployeeDO> list) {
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        return CollectionUtils.convertList(list, this::buildDTO);
    }
 
    private HrmEmployeeSimpleRespDTO buildDTO(HrmEmployeeDO employee) {
        HrmEmployeeSimpleRespDTO dto = BeanUtils.toBean(employee, HrmEmployeeSimpleRespDTO.class);
        if (StrUtil.isNotBlank(employee.getPostIds())) {
            try {
                dto.setPostIds(JSONUtil.toList(employee.getPostIds(), Long.class));
            } catch (Exception ignored) {
                // 历史脏数据:岗位 JSON 解析失败时忽略,不影响员工本身返回
            }
        }
        return dto;
    }
 
}