9836

多条sql返回的数据List进行数据拼装成一条数据返回

  List<Map> list = attendanceDataMapper.getZCDK(map); List<Map> list1 = attendanceDataMapper.getCD(map); List<Map> list2 = attendanceDataMapper.getZT(map); List<Map> mapList; if ("user".equals(map.get("type").toString()) || "campus".equals(map.get("type").toString())){ mapList = getSingeData(map, list, list1, list2); } else { mapList = getData(map, list, list1, list2); } return SimpleMessage.info(mapList);}public List<Map> getData(Map map,List<Map> list,List<Map> list1,List<Map> list2) { List<Map> mapList = new ArrayList<>(); for (Map map1 : list) { mapList.add(map1); } if (list1.size() !=0) { if (mapList.size() ==0) { for (Map map1 : list1) { map1.put("zcnum",0); mapList.add(map1); } } else { for (Map map1 : list1) { for (Map map2 : mapList) { if ("class".equals(map.get("type").toString())) { if (map1.get("cid").toString().equals(map2.get("cid").toString())) { map2.put("cdcount",map1.get("cdcount").toString()); } } else if ("grade".equals(map.get("type").toString())) { if (map1.get("gid").toString().equals(map2.get("gid").toString())) { map2.put("cdcount",map1.get("cdcount").toString()); } } } } List<String> list3 = new ArrayList<>(); List<String> list4 = new ArrayList<>(); for (Map map1 : list1) { if ("class".equals(map.get("type").toString())) { list3.add(map1.get("cid").toString()); } else if ("grade".equals(map.get("type").toString())) { list3.add(map1.get("gid").toString()); } } for (Map map1 : mapList) { if ("class".equals(map.get("type").toString())) { list4.add(map1.get("cid").toString()); } else if ("grade".equals(map.get("type").toString())) { list4.add(map1.get("gid").toString()); } } for (String s : list3) { if (!list4.contains(s)) { for (Map map1 : list1) { if ("class".equals(map.get("type").toString())) { if (s.equals(map1.get("cid").toString())) { map1.put("zcnum",0); mapList.add(map1); } } else if ("grade".equals(map.get("type").toString())) { if (s.equals(map1.get("gid").toString())) { map1.put("zcnum",0); mapList.add(map1); } } } } } } } else { if (mapList.size() !=0) { for (Map map1 : mapList) { map1.put("cdcount",0); } } } if (list2.size() !=0) { if (mapList.size() == 0) { for (Map map1 : list2) { map1.put("zcnum",0); map1.put("cdcount",0); mapList.add(map1); } } else { for (Map map1 : list2) { for (Map map2 : mapList) { if ("class".equals(map.get("type").toString())) { if (map1.get("cid").toString().equals(map2.get("cid").toString())) { map2.put("ztcount", map1.get("ztcount").toString()); } } else if ("grade".equals(map.get("type").toString())) { if (map1.get("gid").toString().equals(map2.get("gid").toString())) { map2.put("ztcount", map1.get("ztcount").toString()); } } } } List<String> list5 = new ArrayList<>(); List<String> list6 = new ArrayList<>(); for (Map map1 : list2) { if ("class".equals(map.get("type").toString())) { list5.add(map1.get("cid").toString()); } else if ("grade".equals(map.get("type").toString())) { list5.add(map1.get("gid").toString()); } } for (Map map1 : mapList) { if ("class".equals(map.get("type").toString())) { list6.add(map1.get("cid").toString()); } else if ("grade".equals(map.get("type").toString())) { list6.add(map1.get("gid").toString()); } } for (String s : list5) { if (!list6.contains(s)) { for (Map map1 : list1) { if ("class".equals(map.get("type").toString())) { if (s.equals(map1.get("cid").toString())) { map1.put("zcnum",0); map1.put("cdcount",0); mapList.add(map1); } } else if ("grade".equals(map.get("type").toString())) { if (s.equals(map1.get("gid").toString())) { map1.put("zcnum",0); map1.put("cdcount",0); mapList.add(map1); } } } } } } } else { if (mapList.size() !=0) { for (Map map1 : mapList) { map1.put("ztcount", 0); } } else { Map hashMap = new HashMap(); hashMap.put("zcnum",0); hashMap.put("cdcount",0); hashMap.put("ztcount",0); mapList.add(hashMap); } } return mapList;}public List<Map> getSingeData(Map map,List<Map> list,List<Map> list1,List<Map> list2) { List<Map> mapList = new ArrayList<>(); if (list.size() !=0) { for (Map map1 : list) { if (null!= map1) { mapList.add(map1); } else { Map hashMap = new HashMap(); hashMap.put("zcnum",0); mapList.add(hashMap); } } } else { Map hashMap = new HashMap(); hashMap.put("zcnum",0); mapList.add(hashMap); } for (Map map1 : mapList) { if (list2.size() !=0) { for (Map map2 : list2) { if (null != map2) { map1.put("ztcount",map2.get("ztcount").toString()); } else { map1.put("ztcount",0); } } } else { map1.put("ztcount",0); } } for (Map map1 : mapList) { if (list1.size() !=0) { for (Map map2 : list1) { if (null != map2) { map1.put("cdcount",map2.get("cdcount").toString()); } else { map1.put("cdcount",0); } } } else { map1.put("cdcount",0); } } return mapList;}

来源:博客园

作者:写尽千帆

链接:https://www.cnblogs.com/bt2882/p/11424599.html

Recommend