展示要求:
客户/日期 | 2017-10-16 | 1017-10-17 | 2017-10-18 |
客户1 | |||
客户2 |
数据库中数据:
解决办法:
1.新建一个实体类:客户名称、客户数据(ArrayList)
2.组建数据:(1)遍历客户;
(2)遍历日期;
(3)遍历数据库中的数据,添加客户数据;
代码:
@Override
public List<CustomerCountVo> getCustomerCount10(){
List<TransCount> transCountList=transMapper.getTransCountList10();
List<Integer> customerIdList=transMapper.getCustomerIdList(); List<CustomerCountVo> customerCountVoList=new LinkedList<CustomerCountVo>();
for (Integer cid:customerIdList){//遍历客户
String date=DateUtil.getPreNDay(DateUtil.getDate(),10);
CustomerCountVo ccv=new CustomerCountVo();
ccv.setCustomerId(cid);
ArrayList<Double> incomeList=new ArrayList<Double>();
for (int i=1;i<11;i++){//遍历日期
for (TransCount tc:transCountList){//遍历数据库中的数据
if (tc.getCustomerId()==cid&&date.equals(DateUtil.getSomeDate(tc.getTransDate(),"yyyy-MM-dd"))){//该客户、该日期
ccv.setCustomerName(tc.getCustomerName());
incomeList.add(tc.getIncome());//添加客户数据(ArrayList)
}
}
if (null==incomeList||incomeList.size()<i){//该日期下没有数据,数据为0
incomeList.add(0.00);
}
date=DateUtil.getNextDay(date);
ccv.setIncomeList(incomeList);
}
customerCountVoList.add(ccv);
}
return customerCountVoList;
}