fix(smartfactory): 修复用户数据权限导致的工厂列表获取问题

- 优化了工厂列表获取逻辑,确保用户可以正确获取其有权限访问的工厂信息
- 新增对自己所在工厂的判断和添加逻辑
- 修复了原代码中可能存在的空指针异常问题
This commit is contained in:
furongxin 2024-12-23 10:23:22 +08:00
parent a25bd59e00
commit 2462b89750

View File

@ -233,20 +233,23 @@ public class FactoryInfoServiceImpl implements FactoryInfoService {
@Override
public List<FactoryInfoDO> getFactoryListByAuthority() {
List<Long> factoryIds = null;
List<Long> factoryIds = new ArrayList<>();
DeptDataPermissionRespDTO deptDataPermission = permissionApi.getDeptDataPermission(getLoginUserId()).getCheckedData();
// 如果当前登录用户数据权限 不是查看全部数据
if (!deptDataPermission.getAll()) {
// 获取自己所在工厂
DeptRespDTO respDTO = deptApi.getDept(userApi.getUser(getLoginUserId()).getCheckedData().getDeptId()).getCheckedData();
if (respDTO != null && respDTO.getFactoryId() != null) {
factoryIds.add(respDTO.getFactoryId());
}
// 查找担任负责人的工厂信息
List<DeptRespDTO> deptRespDTO = deptApi.getDeptByLeaderId(getLoginUserId()).getCheckedData();
if (deptRespDTO != null) {
factoryIds = convertList(deptRespDTO, DeptRespDTO::getFactoryId);
} else {
DeptRespDTO respDTO = deptApi.getDept(userApi.getUser(getLoginUserId()).getCheckedData().getDeptId()).getCheckedData();
factoryIds = Collections.singletonList(respDTO.getFactoryId());
factoryIds.addAll(convertList(deptRespDTO, DeptRespDTO::getFactoryId));
}
}