admin
2018-12-25 4cb15e222cd7d099d533ccbeb7f9a8cd99bf180c
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserMoneyDetailServiceImpl.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -44,12 +43,23 @@
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(list.get(0).getCreateTime().getTime());
            UserMoneyDetailHistoryVO vo = new UserMoneyDetailHistoryVO();
            vo.setMonth(new UserMonthMoneyVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)));
            vo.setMonth(new UserMonthMoneyVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
            finalList.add(vo);
         } else {
            if (maxTime != null) {//
               Calendar calendar = Calendar.getInstance();
               calendar.setTimeInMillis(maxTime.getTime());
               UserMoneyDetailHistoryVO vo = new UserMoneyDetailHistoryVO();
               vo.setMonth(new UserMonthMoneyVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
               vo.getMonth().setExpend("0");
               vo.getMonth().setIncome("0");
               finalList.add(vo);
            }
         }
      } else {// 二次请求
         int size = 20;
         int size = 21;
         List<UserMoneyDetail> tempList = userMoneyDetailMapper.selectByUidWithIndexId(uid, userMoneyDetailId, size);
         Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒)
         if (tempList.size() > 0) {
@@ -90,7 +100,7 @@
               Calendar calendar = Calendar.getInstance();
               calendar.setTimeInMillis(list.get(i).getCreateTime().getTime());
               UserMoneyDetailHistoryVO vo = new UserMoneyDetailHistoryVO();
               vo.setMonth(new UserMonthMoneyVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)));
               vo.setMonth(new UserMonthMoneyVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
               finalList.add(vo);
            }
            UserMoneyDetailHistoryVO vo = new UserMoneyDetailHistoryVO();
@@ -101,31 +111,34 @@
      // 统计月资金
      Map<Integer, UserMoneyDetailHistoryVO> monthMap = new TreeMap<>();
      for (int i = 0; i < finalList.size(); i++) {
         if (finalList.get(i).getMonth() != null)
            monthMap.put(i, finalList.get(i));
      }
      if (finalList.size() > 1)
         for (int i = 0; i < finalList.size(); i++) {
            if (finalList.get(i).getMonth() != null)
               monthMap.put(i, finalList.get(i));
         }
      List<String> dateFormat = new ArrayList<>();
      Iterator<Integer> keys = monthMap.keySet().iterator();
      while (keys.hasNext()) {
         Integer key = keys.next();
         String date = "";
         date += monthMap.get(key).getMonth().getYear();
         date += "-";
         date += (monthMap.get(key).getMonth().getMonth() + "").length() < 2
               ? "0" + monthMap.get(key).getMonth().getMonth() : monthMap.get(key).getMonth().getMonth();
         dateFormat.add(date);
      }
      List<UserMonthMoneyVO> voList = userMoneyDetailMapper.selectMonthMoneyByUid(uid, dateFormat);
      if (!monthMap.isEmpty()) {
         List<String> dateFormat = new ArrayList<>();
         Iterator<Integer> keys = monthMap.keySet().iterator();
         while (keys.hasNext()) {
            Integer key = keys.next();
            String date = "";
            date += monthMap.get(key).getMonth().getYear();
            date += "-";
            date += (monthMap.get(key).getMonth().getMonth() + "").length() < 2
                  ? "0" + monthMap.get(key).getMonth().getMonth() : monthMap.get(key).getMonth().getMonth();
            dateFormat.add(date);
         }
         List<UserMonthMoneyVO> voList = userMoneyDetailMapper.selectMonthMoneyByUid(uid, dateFormat);
      int p = 0;
      keys = monthMap.keySet().iterator();
      while (keys.hasNext()) {
         Integer key = keys.next();
         finalList.get(key).getMonth().setExpend(voList.get(p).getExpend());
         finalList.get(key).getMonth().setIncome(voList.get(p).getIncome());
         p++;
         int p = 0;
         keys = monthMap.keySet().iterator();
         while (keys.hasNext()) {
            Integer key = keys.next();
            finalList.get(key).getMonth().setExpend(voList.get(p).getExpend());
            finalList.get(key).getMonth().setIncome(voList.get(p).getIncome());
            p++;
         }
      }
      return finalList;
   }
@@ -148,4 +161,14 @@
      return monthCount + detailCount;
   }
   @Override
   public List<UserMoneyDetail> listByUidWithState(Long uid, int page, int pageSize) {
      return userMoneyDetailMapper.selectByUidWithState(uid, (page - 1) * pageSize, pageSize);
   }
   @Override
   public long countByUidWithState(Long uid) {
      return userMoneyDetailMapper.selectCountByUidWithState(uid);
   }
}