在同一张数据库表中使用Map统计数据

在同一张数据库表中使用Map统计数据
1、主要方法:
               String startDate = req.getParameter("startDate"); 
String endDate = req.getParameter("endDate");
UserVO users = (UserVO) req.getSession().getAttribute("users");
List<ReportBaseVO> titleList = MessageCountService.titleList();  //表列
List<ReportBaseVO> mentList=MessageCountService.findMentList(users,messType); //表行
                List<ReportDataVO> dataList=MessageCountService.findData(users,messType,startDate,endDate); //数据集
Map<String,String> dataMap = ReportService.getReport(dataList); //装入Map
2、方法实现:
//0:满意 1:非常满意2:不满意 
public static List<ReportBaseVO> titleList(){
List<ReportBaseVO> list = new ArrayList<ReportBaseVO>();
ReportBaseVO vo1 = new ReportBaseVO();
vo1.setCode("0");
vo1.setName("满意");
list.add(vo1);
ReportBaseVO vo2 = new ReportBaseVO();
vo2.setCode("1");
vo2.setName("基本满意");
list.add(vo2);
ReportBaseVO vo3 = new ReportBaseVO();
vo3.setCode("2");
vo3.setName("不满意");
list.add(vo3);
return list;
}

public static List<ReportBaseVO> findMentList(UserVO users,String type){
List<ReportBaseVO> list = new ArrayList<ReportBaseVO>();
         
if((users.isHave("0") && ("1".equals(type)||type==null||"".equals(type)))||users.isHave("1") && ("1".equals(type)||type==null||"".equals(type))){
ReportBaseVO vo1 = new ReportBaseVO();
vo1.setCode("1");
vo1.setName("局长信箱");
list.add(vo1);
}
}

public static List<ReportDataVO> findData(UserVO users, String messType,String startDate,String endDate){
               List<ReportDataVO> list = new ArrayList<ReportDataVO>();
String sql="select APPRAISAL as titleId,MESS_TYPE as mentId,count(ID) as count from act_message where DELETE_FLAG='0' and APPRAISAL<>'' and MESS_TYPE='1' group by MESS_TYPE,APPRAISAL";
List<ReportDataVO> reportDataList = DBBeanUtil.execute(conn, new ReportDataVO(),sql);
list.addAll(reportDataList);
return list;
}

public static Map<String,String> getReport(List<ReportDataVO> paraList){
Map<String, String> reportMap = new HashMap<String, String>();
for(int i=0;i<paraList.size();i++){
ReportDataVO p = paraList.get(i);
reportMap.put(p.getMentId()+"_"+p.getTitleId(), String.valueOf(p.getCount()));
}
return reportMap;
}

3、遍历数据:
Map<String,String> dataMap = ReportService.getReport(dataList);
String[][] data = new String[mentList.size()][titleList.size()];
for (int i = 0; i < mentList.size(); i++) {
mentList.get(i).getName();  
int typeAll=0;
for (int j = 0; j < titleList.size(); j++) {
String dateMa=mentList.get(i).getCode()+ "_" + titleList.get(j).getCode();
//             out.print("titleList.get(j).getCode():"+titleList.get(j).getCode());
String content = dataMap.get(dateMa);//IsTurn0
if (content == null || "".equals(content)) {
content = "0";
}
data[i][j] = content;
typeAll=Integer.parseInt(content)+typeAll;
}
BigDecimal point = new BigDecimal(0);
BigDecimal mcount=new BigDecimal(data[i][0]).add(new BigDecimal(data[i][1]));//满意发布件数
BigDecimal atotal=mcount.add(new BigDecimal(data[i][2]));//共发布件数
if(atotal.compareTo(new BigDecimal(0))!=0){
point = new BigDecimal(100).multiply(mcount.divide(atotal,2, RoundingMode.HALF_UP));
}
}

你可能感兴趣的:(在同一张数据库表中使用Map统计数据)