List tDiets =dietApiService.getDietsByDate(userId, startDate, endDate);
List> list = newArrayList();
List> newList = newArrayList();int talls=0;if(tDiets.size()>0){int a=0;for(TDiet td:tDiets){
talls+=Integer.parseInt(td.getFoodIntakeMeasure());//摄入总量
a++;
String foodIntakeType=td.getFoodIntakeType();
org.json.JSONArray jsonArray= neworg.json.JSONArray(foodIntakeType);int iSize =jsonArray.length();for (int i = 0; i < iSize; i++) {
org.json.JSONObject jsonObj=jsonArray.getJSONObject(i);
String bigtypes= jsonObj.get("bigtypes").toString();
String num= jsonObj.get("num").toString();
Map maMap = new HashMap();
maMap.put("bigtypes", bigtypes);
maMap.put("num", num);if(a>1){//多组数据
newList=list;
Map newMap =new HashMap();int b=0;for (int j = 0; j < list.size(); j++) {
newMap=list.get(j);if(bigtypes.equals(newMap.get("bigtypes").toString())){//key值相等的:value相加
b++;
newList.remove(j);
Map maMap2 = new HashMap();
maMap2.put("bigtypes", bigtypes);int xx= Integer.parseInt(newMap.get("num"))+Integer.parseInt(num);
maMap2.put("num",xx+"");
newList.add(maMap2);break;
}
}if(b==0){//key值与list的map无共同key的:list新增
newList.add(maMap);
}
list=newList;
}else{//只有一组数据
list.add(maMap);
}
}
}//取百分比
newList=newArrayList();for (int c = 0; c < list.size(); c++) {
Map newMap2 =new HashMap();
Map oldmap=new HashMap();
oldmap=list.get(c);
newMap2.put("bigtypes", oldmap.get("bigtypes"));int aa= Integer.parseInt(oldmap.get("num"));
newMap2.put("num",towNumDivide(aa,talls)+"%");
newList.add(newMap2);
}
list=newList;
}