出现一个问题:
private List<Map<String, Object>> getBuIdByTask(Long userId, Integer clientShow) throws Exception { int complete_status = TaskCenterDefinedCode.OPERATION_STATUS.COMPLETE.getNumberCode().intValue(); // 默认手机端 0,1 List<Long> cardTypeUkids = getActionUkidsForTaskTags(clientShow, null); TsOperationDOExample tsOperationDOExample = new TsOperationDOExample(); List<String> fields = new ArrayList<>(1); fields.add("owner_id"); // fields.add("operation_ukid"); //新加入 ① tsOperationDOExample.setCustomFields(fields); tsOperationDOExample.createCriteria().andStatusLessThan(complete_status) .andOpUserIdEqualTo(userId) .andOperationUnitUkidIn(cardTypeUkids); List<TsOperation> tsOperations = tsOperationManager.selectByExample(tsOperationDOExample); List<Map<String, Object>> buMaps = new ArrayList<>(); Set<Long> buIdSets = tsOperations.stream().map(TsOperation::getOwnerId).filter(ObjectUtil::isNotEmpty).collect(Collectors.toSet()); //这里报错② List<CmBusinessUnitInfo> businessUnits = cmBusinessUnitsService.getBusinessUnitInfoByBuIds(buIdSets); for (CmBusinessUnitInfo cmBusinessUnitInfo : businessUnits) { if (cmBusinessUnitInfo == null) { continue; } Map<String, Object> bu = new HashMap<>(2); bu.put("buId", cmBusinessUnitInfo.getBusinessUnitId()); bu.put("buName", cmBusinessUnitInfo.getBusinessUnitName()); buMaps.add(bu); } return buMaps; }
如果不新加入 ① fields.add("operation_ukid");
Set<Long> buIdSets = tsOperations.stream().map(TsOperation::getOwnerId).filter(ObjectUtil::isNotEmpty).collect(Collectors.toSet()); //这里报错②
经过查找,
tsOperationManager.selectByExample(tsOperationDOExample); 只会返回owner_id这个字段,并且使用
TsOperation返回。当owner_id为null时,TsOperation会为null。
所以这里把主键也返回,就不会返回null对象了。