private void judgmentHospital(newList, oldList, arrayList){
/*新老学生list->map*/
Map<Long, Student> newCodeMap = newList.stream().collect(Collectors.toMap(Student::getId, Function.identity()));
Map<Long, Student> oldCodeMap = oldList.stream().collect(Collectors.toMap(Student::getId, Function.identity()));
List<Long> codeString = Lists.newArrayList();
codeString.addAll(newCodeMap.keySet());
codeString.addAll(oldCodeMap.keySet());
Map<Long, Long> counts =
codeString.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting()));
counts.forEach((code, count) -> {
Student newItem = newCodeMap.get(code);
Student oldItem = oldCodeMap.get(code);
if (count == 1) {
/*新版本新增的*/
if (newItem != null) {
arrayList.add("新增学生"+newItem.getId()+newItem.getName());
}
/*新版本删除的*/
if (oldItem != null) {
arrayList.add("删除学生"+newItem.getId()+newItem.getName());
}
} else {
if (!newItem.equals(oldItem)) {
arrayList.add("修改学生"+newItem.getId()+newItem.getName());
}
}
});
}
————————————————
版权声明:本文为CSDN博主「qiuqiucatcat」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_32896095/article/details/114300216
public static void main(String[] args){
JSONArray messages=new JSONArray();//新数据
JSONObject j1=new JSONObject();
j1.put("rcsId","111");
JSONObject j2=new JSONObject();
j2.put("rcsId","222");
JSONObject j3=new JSONObject();
j3.put("rcsId","333");
JSONObject j4=new JSONObject();
j4.put("rcsId","444");
messages.add(j1);
messages.add(j2);
messages.add(j3);
messages.add(j4);
List<RcsTopoMessage> beforeMessageList=new ArrayList<>();//原数据
beforeMessageList.add(new RcsTopoMessage("1","111"));
beforeMessageList.add(new RcsTopoMessage("2","222"));
beforeMessageList.add(new RcsTopoMessage("5","555"));
/* JSONArray updateArray=new JSONArray();
JSONArray insertArray=new JSONArray();
int msgCount=0;
if(messages!=null&&messages.size()>0){
msgCount=messages.size();
for(int i=0;i<messages.size();i++){
JSONObject msg=messages.getJSONObject(i);
String rcsId=msg.getString("rcsId");
if(beforeMessageList.parallelStream().anyMatch(item ->item.getRcsId().equals(rcsId))){//存在 为修改数据
updateArray.add(msg);
}else {//不存在说明是新增的
insertArray.add(msg);
}
}
}*/
//那些是删除的msg?
List<RcsTopoMessage> delete = beforeMessageList.stream().filter(item ->(messages.parallelStream().noneMatch(tm->item.getRcsId().equals(((JSONObject)tm).getString("rcsId"))))).collect(toList());
delete.forEach(e->System.out.println("需要删除的"+e.getRcsId()));
//那些是修改的
JSONArray update = messages.stream().filter(tm ->(beforeMessageList.parallelStream().anyMatch(item->item.getRcsId().equals(((JSONObject)tm).getString("rcsId"))))).collect(Collectors.toCollection(JSONArray::new));
update.forEach(e->System.out.println("需要修改的"+((JSONObject)e).getString("rcsId")));
//那些是新增的
JSONArray insert = messages.stream().filter(tm ->(beforeMessageList.parallelStream().noneMatch(item->item.getRcsId().equals(((JSONObject)tm).getString("rcsId"))))).collect(Collectors.toCollection(JSONArray::new));
insert.forEach(e->System.out.println("需要新增的"+((JSONObject)e).getString("rcsId")));
System.out.println("===========");
}
————————————————
版权声明:本文为CSDN博主「码java的秃头少女」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39477018/article/details/106673205