获取数组中的时间,根据相同月份时间计算总价格


//返回一个list

List<CustcollectFees> custcollectFeesList = custcollectFeesDao.getCustcollectFeesPageNo(pageNo, userId,
customerId);


//定义一个箱子
List<List<CustcollectFees>> box = new ArrayList<List<CustcollectFees>>();

SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
/**
* 便利获取每一条数据,截取年、月 ,进行比较
*/

for (CustcollectFees c : custcollectFeesList) {

Calendar ca = Calendar.getInstance();
ca.setTime(new Date(c.getCreateTime().getTime()));
int cmonth = ca.get(Calendar.MONTH);
int cyear = ca.get(Calendar.YEAR);
/**
* 1.默认为数组时间相同,false;
* 2.外for第二次循环时间与第一次放进box盒子的数组时间进行对比
* 3.如果相同flag==true,内for循环继续循环判断
*/

boolean flag = false;
for (List<CustcollectFees> l : box) {
Calendar cl = Calendar.getInstance();
cl.setTime(new Date(l.get(0).getCreateTime().getTime()));
int lmonth = cl.get(Calendar.MONTH);
int lyear = cl.get(Calendar.YEAR);
if (c.getCreateTime()!=null && cmonth == lmonth && cyear == lyear) {
l.add(c);
flag = true;//不存在就跳出储存,新建数组
continue;
}
}
/**
* 当第一次存储的时候box为空跳出for循环,新建一个数组,将循环的实体类放进数组
* 并将数组放在盒子中,便于后期内for循环进行对比判断
*/

if(!flag) {
List<CustcollectFees> list = new LinkedList<CustcollectFees>();
list.add(c);
box.add(list);
}
}


List<CustcollectFeesVo> resultList = new LinkedList<CustcollectFeesVo>();
/**
* 1.循环遍历box数组盒子
* 2.遍历每个月的数组,获取数量价格算出总价
*/

for (List<CustcollectFees> l : box) {
CustcollectFeesVo cv = new CustcollectFeesVo();
cv.setTime(sf.format(new Date(l.get(0).getCreateTime().getTime())));
cv.setCustcollectFeesList(l);
//计算总价
double totle = 0.0;
for(CustcollectFees c : l) {
totle += c.getCount() * collectFeesDao.getById(c.getCfId()).getPrice();
}
cv.setPrice(totle);
resultList.add(cv);
}

return PageNoUtil.getListMap(resultList);


//修改

@Override
public Map<String, Object> getCustcollectFeesPageNo(Integer pageNo, Integer customerId,
Integer status,Integer type) {


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()));
/**
* 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;
}
}


// 计算总数
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())){

Double price = cu.getCollectfeesprice();
Double count0 = c.getCount();//当月数量
Double count1 = cu.getCount();//上月数量
totle += ( count0 - count1 ) * price;
}
}
}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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值