fix: 修复部门错误数据导致的异常

This commit is contained in:
liangcheng 2025-08-28 14:10:33 +08:00
parent 3d104ac67a
commit 4ee7f30197
1 changed files with 18 additions and 6 deletions

View File

@ -19,8 +19,10 @@ import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
/** /**
* @Author liang.cheng * @Author liang.cheng
@ -29,6 +31,7 @@ import java.util.stream.Collectors;
* @Version 1.0 * @Version 1.0
*/ */
@Component @Component
@Slf4j
public class EbTableMonitorBO { public class EbTableMonitorBO {
@Autowired @Autowired
@ -45,19 +48,28 @@ public class EbTableMonitorBO {
EmployeePO employeePO = selectEmployee(); EmployeePO employeePO = selectEmployee();
return hrKpiFlows.stream() return hrKpiFlows.stream()
.filter(Objects::nonNull)
.map(hrKpiFlow -> { .map(hrKpiFlow -> {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
String formattedDate = hrKpiFlow.getRealPeriod() != null String formattedDate = hrKpiFlow.getRealPeriod() != null
? sdf.format(hrKpiFlow.getRealPeriod()) ? sdf.format(hrKpiFlow.getRealPeriod())
: null; : null;
WeaDepartMent weaDepartMent = departMentService.getDepartMentById(hrKpiFlow.getDepartmentId()); Long departmentId = hrKpiFlow.getDepartmentId();
String deptPath = departMentService.getDeptPath(hrKpiFlow.getDepartmentId(), WeaDeptPathLevel.DEPT_ALL_LEVEL, ">", employeePO.getTenantKey()); WeaDepartMent weaDepartMent = departMentService.getDepartMentById(departmentId);
String deptPath = "";
try {
deptPath = departMentService.getDeptPath(departmentId, WeaDeptPathLevel.DEPT_ALL_LEVEL, ">", employeePO.getTenantKey());
if (StringUtils.isNotBlank(deptPath)) { if (StringUtils.isNotBlank(deptPath)) {
deptPath = deptPath + ">" + weaDepartMent.getDepartMentName(); deptPath = deptPath + ">" + weaDepartMent.getDepartMentName();
} else { } else {
deptPath = weaDepartMent.getDepartMentName(); deptPath = weaDepartMent.getDepartMentName();
} }
}catch (Exception e) {
log.error("处理 hrKpiFlow ID: {} 时发生异常: {}",
hrKpiFlow.getId(), e.getMessage(), e);
return null;
}
return EbTableMonitorPO.builder() return EbTableMonitorPO.builder()
// 基础字段 // 基础字段