简化

一开始code

columnList.forEach(column -> {
    if (map.containsKey(column) && map.get(column) != null) {
        Object obj = map.get(column);
        if (obj instanceof ArrayList) {
            JSONArray jsonArray = new JSONArray((ArrayList) obj);
            List<Integer> list = new ArrayList<>();
            for (Object o : jsonArray) {
                if (!(o instanceof CmdbUserResp)) {
                    break;
                }
                JSONObject jsonObject = (JSONObject) JSON.toJSON(o);
                list.add(jsonObject.getInteger("id"));
            }
            if (CollUtil.isNotEmpty(list)) {
                obj = list;
            }
        }
        String value = JSON.toJSONString(obj);
        map.put(column, value);
    }
});

 

修改后

columnList.forEach(column -> {
    if (map.containsKey(column) && map.get(column) != null) {
        Object obj = map.get(column);
        if (obj instanceof ArrayList) {
            List<CmdbUserResp> cmdbUserResps = (List<CmdbUserResp>) obj;
            obj = cmdbUserResps.stream().map(e -> e.getId()).collect(Collectors.toList());
        }
        String value = JSON.toJSONString(obj);
        map.put(column, value);
    }
});

 

posted @ 2021-03-11 18:17  edda_huang  阅读(74)  评论(0编辑  收藏  举报