@Override
public Map<String, Object> getCustcollectFeesPageNo(Integer pageNo, Integer customerId,
Integer status,Integer type) {
//1.根据条件查询出来的列表list
List<CustcollectFees> custcollectFeesList = custcollectFeesDao.getCustcollectFeesPageNo(pageNo,customerId, status,type);
// 定义一个箱子二维数组
List<List<CustcollectFees>> box = new LinkedList<List<CustcollectFees>>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
big: for (CustcollectFees c : custcollectFeesList) {
/**
* 便利获取每一条数据,截取年、月 ,进行比较
*/
// 获取年月的时间
String outDate = sdf.format(new Date(c.getCreateTime().getTime()));
//如果时间是String格式 sdf.parse(pr.detailTime)
/**
* 1.第一次box为空,不走内for循环 。第二次循环判断。。第三次。。
* 2.外for第二次循环时间与第一次放进box盒子的数组时间进行对比
* 3.如果时间相同,将一条数据放进box箱子的list数组中,继续外for循环判断
*/
for (List<CustcollectFees> list : box) {
String inDate = sdf.format(new Date(list.get(0).getCreateTime().getTime()));
if ((c.getCreateTime() != null && outDate.equals(inDate)) &&
(c.getCustomerId().intValue() == list.get(0).getCustomerId().intValue())) {
list.add(c);
continue big;
}
}
/**
* 当第一次存储的时候box为空跳出for循环,新建一个数组,将循环的实体类放进数组
* 并将数组放在箱子中,便于后期内for循环进行对比判断
*/
List<CustcollectFees> list = new LinkedList<CustcollectFees>();
list.add(c);
box.add(list);
}
// SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
List<CustcollectFeesVo> resultList = new LinkedList<CustcollectFeesVo>();
/**
* 1.循环遍历box数组盒子 2.遍历每个月的数组,获取数量价格算出总价
*/
for (List<CustcollectFees> l : box) {
CustcollectFeesVo cv = new CustcollectFeesVo();
String monthtime = sdf.format(new Date(l.get(0).getCreateTime().getTime()));//月份
cv.setTime(monthtime);
cv.setCustomerId(l.get(0).getCustomerId());
cv.setCustomerName(l.get(0).getCustomerName());
// cv.setCustcollectFeesList(l);
java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");//余额格式化
//上月月份
String lastmonth = TimeUtils.getMonthBydate(monthtime);
List<CustcollectFees> cuList = null;
// custcollectFeesDao.getCustcollectFeesList(null, lastmonth, null);
for(List<CustcollectFees> li : box ){
String time = sdf.format(new Date(li.get(0).getCreateTime().getTime())).substring(0,7);
if(lastmonth.equals(time) && (li.get(0).getCustomerId().intValue() ==l.get(0).getCustomerId().intValue())){
cuList = li;//上月费用list
}
}
// 计算同一租户这月费用总数,(这月费用总量-上月费用总量)*该费用的单价
Double totle = 0.00;
for (CustcollectFees c : l) {//当月
if(cuList!=null && cuList.size()>0){
for(CustcollectFees cu : cuList){//上月
if((c.getCfId().intValue() == cu.getCfId().intValue() )
&& ( c.getCustomerId().intValue() == cu.getCustomerId().intValue())
&& !("物业费").equals(cu.getCollectfeesname()) ){
Double price = cu.getCollectfeesprice();
Double count0 = c.getCount();//当月数量
Double count1 = cu.getCount();//上月数量
totle += ( count0 - count1 ) * price;
}
}
if(("物业费").equals(c.getCollectfeesname())){
totle += c.getPrice();
}
}else {
Double price = c.getCollectfeesprice();
Double count0 = c.getCount();//当月数量
totle += count0 * price;
}
}
cv.setPrice(df.format(totle));
resultList.add(cv);
}
int queryCount = PageNoUtil.pageSize_15;
Long count = Long.valueOf(resultList.size());
return PageNoUtil.getListMap(resultList,queryCount,count);
}