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 getEmployeeListByPostIds(Collection postIds) { return convertList(employeeService.getEmployeeListByPostIds(postIds)); } @Override public Map getEmployeeMap(Collection 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 convertList(List 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; } }