活动介绍

String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate(); if (ObjectUtil.isEmpty(maxInflowRate1)) { maxOutflowRate1 = "0.0"; } BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate()))); 这些代码报空指针咋回事

时间: 2024-01-25 13:02:47 浏览: 115
根据你提供的代码,可能是`relayLinkReport`或`object`中的`getMaxOutflowRate()`方法返回了`null`,导致在调用`isEmpty()`方法时出现了`NullPointerException`异常。你可以在调用`getMaxOutflowRate()`方法之前,先做一个非空判断,例如: ``` String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate(); if (maxOutflowRate1 == null) { maxOutflowRate1 = "0.0"; } BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate()))); ``` 或者你也可以在方法中添加一个断言,检查`relayLinkReport`和`object`是否为空: ``` assert relayLinkReport != null && object != null; String maxOutflowRate1 = relayLinkReport.getMaxOutflowRate(); if (ObjectUtil.isEmpty(maxInflowRate1)) { maxOutflowRate1 = "0.0"; } BigDecimal maxOutflowRate = new BigDecimal(maxOutflowRate1).add(new BigDecimal(setRelayLinkValue(object.getMaxOutflowRate()))); ``` 这样,如果`relayLinkReport`或`object`为空,就会抛出`AssertionError`,帮助你更快地定位问题。
阅读全文

相关推荐

protected McTaskMsgContentEntity getTaskMsgContent( String templateId, String channelType, McTaskMsgEntity taskMsg, McMsgTemplateEntity msgTemplate, McMsgAccountEntity account ) { String taskMsgId = taskMsg.getId(); // 消息场景 McBusinessInfoVO businessInfoVO = mcBusinessService.getInfoByEnCode(msgTemplate.getMessageSource()); // 业务消息关键词 String businessKey = taskMsg.getBusinessKey(); Map<String, Object> businessKeyMap = JsonUtil.stringToMap(businessKey); // 标题(带有占位符的) String title = msgTemplate.getTitle(); // 内容(带有占位符的) String content = msgTemplate.getContent(); // 摘要 String description = null; // 消息链接 String linkUrl = null; // 图片链接 String picUrl = null; // 替换参数 if (StringUtils.isNotEmpty(businessKeyMap)) { // 标题 if (StringUtils.isNotEmpty(title)) { StringSubstitutor strSubstitutor = new StringSubstitutor(businessKeyMap, "{", "}"); title = strSubstitutor.replace(title); } else { title = String.valueOf(businessKeyMap.get("title")); } // 内容 if (StringUtils.isNotEmpty(content)) { StringSubstitutor strSubstitutor = new StringSubstitutor(businessKeyMap, "{", "}"); content = strSubstitutor.replace(content); } else { content = String.valueOf(businessKeyMap.get("content")); } // 摘要 if (businessKeyMap.containsKey("desc") && StringUtils.isNotEmpty(businessKeyMap.get("desc").toString())) { description = businessKeyMap.get("desc").toString(); } else { description = StringUtils.isEmpty(content) ? null : StringUtils.substring(content, 0, 200); } // 消息链接 linkUrl = this.packLinkUrl(channelType, businessKeyMap, account, taskMsgId); // 图片链接 if (businessKeyMap.containsKey("picUrl") && ObjectUtil.isNotEmpty(businessKeyMap.get("picUrl"))) { picUrl = String.valueOf(businessKeyMap.get("picUrl")); } } // 封装业务消息内容实体 McTaskMsgContentEntity taskMsgContentEntity = new McTaskMsgContentEntity(); // 标题 if (StringUtils.isNotEmpty(title)) { // title = StringUtils.stringFilter(title); title = SensitiveWordUtil.sensitiveFilter(title, true); title = StringUtils.substring(title, 0, 50); taskMsgContentEntity.setTitle(title); } // 内容 if (StringUtils.isNotEmpty(content)) { content = SensitiveWordUtil.sensitiveFilter(content, true); taskMsgContentEntity.setContent(content); } // 摘要 if (StringUtils.isNotEmpty(description)) { description = SensitiveWordUtil.sensitiveFilter(description, true); taskMsgContentEntity.setDescription(description); } // 消息链接 taskMsgContentEntity.setLinkUrl(linkUrl); // 图片链接 if (StringUtils.isNotEmpty(picUrl)) { taskMsgContentEntity.setPicUrl(picUrl); } taskMsgContentEntity.setMsgAccountId(ObjectUtil.isEmpty(account) ? null : account.getId()); return taskMsgContentEntity; }Refactor this method to reduce its Cognitive Complexity from 22 to the 15 allowed.

private Wrapper<SysUser> buildQueryWrapper(SysUserBo user) { Map<String, Object> params = user.getParams(); QueryWrapper<SysUser> wrapper = Wrappers.query(); wrapper.eq("u.del_flag", SystemConstants.NORMAL) .eq(ObjectUtil.isNotNull(user.getUserId()), "u.user_id", user.getUserId()) .like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName()) .eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus()) .like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber()) .between(params.get("beginTime") != null && params.get("endTime") != null, "u.create_time", params.get("beginTime"), params.get("endTime")) .and(ObjectUtil.isNotNull(user.getDeptId()), w -> { List<SysDept> deptList = deptMapper.selectListByParentId(user.getDeptId()); List<Long> ids = StreamUtils.toList(deptList, SysDept::getDeptId); ids.add(user.getDeptId()); w.in("u.dept_id", ids); }).eq(ObjectUtil.isNotNull(user.getGrade()),"eu.grade",user.getGrade()) .eq(ObjectUtil.isNotNull(user.getMajor()),"eu.major",user.getMajor()) .eq(ObjectUtil.isNotNull(user.getWestchinaExperience()),"eu.westchinaExperience",user.getWestchinaExperience()) .eq(ObjectUtil.isNotNull(user.getConfirmStatus()),"eu.confirmStatus",user.getConfirmStatus()) .eq(ObjectUtil.isNotNull(user.getSource()),"eu.source",user.getSource()) .and(ObjectUtil.isNotNull(user.getKeyWord()),k->{ }) .orderByDesc("u.create_time"); if (StringUtils.isNotBlank(user.getExcludeUserIds())) { wrapper.notIn("u.user_id", StringUtils.splitTo(user.getExcludeUserIds(), Convert::toLong)); } return wrapper; } 这是我的sql,我想判断当keyWord不为空的时候,模糊查询姓名,手机号,年级,专业这几个字段

public Map<String,Set<String>> getDepGroupList(List<String> orgIdList) { Map<String,Set<String>> resMap = new HashMap<>(2); Set<String> depcodes = new HashSet<>(); Set<String> groupcodes = new HashSet<>(); List<SmsOrgEntity> orgList = smsOrgService.list(new LambdaQueryWrapper<SmsOrgEntity>().in(SmsOrgEntity::getId, orgIdList)); orgList.forEach(org -> { String depcode = ""; String groupcode = ""; if ("5".equals(org.getLevelcode())) { groupcode = org.getOrgcode(); } if ("4".equals(org.getLevelcode())) { depcode = org.getOrgcode(); } if (StrUtil.isEmpty(depcode) || StrUtil.isEmpty(groupcode)) { String[] orgArr = forGetDepGroupCode(depcode, groupcode, org.getSupercode()); depcode = orgArr[0]; groupcode = orgArr[1]; } if (!StrUtil.isBlank(depcode)) { depcodes.add(depcode); } if (!StrUtil.isBlank(groupcode)) { groupcodes.add(groupcode); } }); resMap.put("depcodes", depcodes); resMap.put("groupcodes", groupcodes); return resMap; } /** * 递归获取部门code和小组code * @param depcode 部门code * @param groupcode 小组code * @param parentCode 父组织code */ public String[] forGetDepGroupCode(String depcode, String groupcode, String parentCode) { if (StrUtil.isEmpty(parentCode)) { return new String[]{depcode, groupcode}; } SmsOrgEntity org = smsOrgService.getOne(new LambdaQueryWrapper<SmsOrgEntity>().eq(SmsOrgEntity::getOrgcode, parentCode)); if (ObjectUtil.isEmpty(org)) { return new String[]{depcode, groupcode}; } if ("5".equals(org.getLevelcode())) { groupcode = org.getOrgcode(); } if ("4".equals(org.getLevelcode())) { depcode = org.getOrgcode(); } if (StrUtil.isEmpty(depcode) || StrUtil.isEmpty(groupcode)) { String[] orgArr = forGetDepGroupCode(depcode, groupcode, org.getSupercode()); depcode = orgArr[0]; groupcode = orgArr[1]; } return new String[]{depcode, groupcode}; }