New file |
| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.TreeMap;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyDetailService;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.vo.money.UserMoneyDetailHistoryVO;
|
| | | import com.yeshi.fanli.vo.money.UserMonthMoneyVO;
|
| | |
|
| | | @Service
|
| | | public class UserMoneyDetailServiceImpl implements UserMoneyDetailService {
|
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailMapper userMoneyDetailMapper;
|
| | |
|
| | | @Override
|
| | | public List<UserMoneyDetailHistoryVO> listUserMoneyDetailForClient(Long uid, Long userMoneyDetailId, Date maxTime) {
|
| | | List<UserMoneyDetailHistoryVO> finalList = new ArrayList<>();
|
| | | List<UserMoneyDetail> list = null;
|
| | | if (userMoneyDetailId == null) {// 首次请求
|
| | | if (maxTime == null)// 没有筛选时间
|
| | | {
|
| | | list = userMoneyDetailMapper.selectByMaxCreateTime(uid,
|
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20);
|
| | | } else {// 筛选了时间
|
| | | list = userMoneyDetailMapper.selectByMaxCreateTime(uid, maxTime, 20);
|
| | | }
|
| | | if (list != null && list.size() > 0) {
|
| | | 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)+1));
|
| | | finalList.add(vo);
|
| | | }
|
| | | } else {// 二次请求
|
| | |
|
| | | int size = 21;
|
| | | List<UserMoneyDetail> tempList = userMoneyDetailMapper.selectByUidWithIndexId(uid, userMoneyDetailId, size);
|
| | | Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒)
|
| | | if (tempList.size() > 0) {
|
| | | for (UserMoneyDetail umd : tempList) {
|
| | | dateSet.add(umd.getCreateTime());
|
| | | }
|
| | |
|
| | | List<UserMoneyDetail> tempList2 = new ArrayList<>();
|
| | | while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据
|
| | | tempList = tempList2;
|
| | | size += 10;
|
| | | tempList2 = userMoneyDetailMapper.selectByUidWithIndexId(uid, userMoneyDetailId, size);
|
| | | dateSet.clear();
|
| | | for (UserMoneyDetail umd : tempList2) {
|
| | | dateSet.add(umd.getCreateTime());
|
| | | }
|
| | | }
|
| | | if (tempList2.size() > 0)
|
| | | tempList = tempList2;
|
| | | }
|
| | |
|
| | | for (int i = 0; i < tempList.size(); i++) {
|
| | | if (tempList.get(i).getId().longValue() == userMoneyDetailId) {
|
| | | tempList.remove(i);
|
| | | break;
|
| | | } else {
|
| | | tempList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | list = tempList;
|
| | | }
|
| | |
|
| | | if (list != null)
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (i > 0 && !TimeUtil.getGernalTime(list.get(i - 1).getCreateTime().getTime(), "yyyy-MM")
|
| | | .equalsIgnoreCase(TimeUtil.getGernalTime(list.get(i).getCreateTime().getTime(), "yyyy-MM"))) {// 本条数据与上条数据不是同一月则插入月份
|
| | | 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)+1));
|
| | | finalList.add(vo);
|
| | | }
|
| | | UserMoneyDetailHistoryVO vo = new UserMoneyDetailHistoryVO();
|
| | | vo.setDetail(list.get(i));
|
| | | finalList.add(vo);
|
| | | }
|
| | |
|
| | | // 统计月资金
|
| | |
|
| | | Map<Integer, UserMoneyDetailHistoryVO> monthMap = new TreeMap<>();
|
| | | if(finalList.size()>1)
|
| | | for (int i = 0; i < finalList.size(); i++) {
|
| | | if (finalList.get(i).getMonth() != null)
|
| | | monthMap.put(i, finalList.get(i));
|
| | | }
|
| | |
|
| | | 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++;
|
| | | }
|
| | | }
|
| | | return finalList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countUserMoneyDetailForClient(Long uid, Long userMoneyDetailId, Date maxTime) {
|
| | | long monthCount = 0L;
|
| | | long detailCount = 0L;
|
| | | // 未通过时间筛选,查询所有
|
| | | if (maxTime == null) {
|
| | | detailCount = userMoneyDetailMapper.selectCountByUid(uid);
|
| | | // 用于表示当前所有
|
| | | monthCount = userMoneyDetailMapper.selectMonthCountByUid(uid,
|
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L));
|
| | | } else {// 通过时间筛选了的,需要查询所有
|
| | | detailCount = userMoneyDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime);
|
| | | monthCount = userMoneyDetailMapper.selectMonthCountByUid(uid, maxTime);
|
| | | }
|
| | |
|
| | | return monthCount + detailCount;
|
| | | }
|
| | |
|
| | | }
|