| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | 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;
|
| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.money.UserMoneyDetailMapper;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.service.inter.user.UserMoneyDetailService;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.vo.money.UserMoneyDetailHistoryVO;
|
| | |
| | |
|
| | | @Resource
|
| | | private UserMoneyDetailMapper userMoneyDetailMapper;
|
| | |
|
| | | @Override
|
| | | public void addUserMoneyDetail(UserMoneyDetail detail) throws UserMoneyDetailException {
|
| | | if (detail == null || detail.getMoney() == null || detail.getType() == null || detail.getUserInfo() == null)
|
| | | throw new UserMoneyDetailException(1, "信息不完整");
|
| | | userMoneyDetailMapper.insertSelective(detail);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<UserMoneyDetailHistoryVO> listUserMoneyDetailForClient(Long uid, Long userMoneyDetailId, Date maxTime) {
|
| | |
| | | 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) {
|
| | |
| | | list = tempList;
|
| | | }
|
| | |
|
| | | if (list != null)
|
| | | if (list != null) {
|
| | | if (userMoneyDetailId != null && list.size() > 0) {
|
| | | UserMoneyDetail umd = userMoneyDetailMapper.selectByPrimaryKey(userMoneyDetailId);
|
| | | if (!TimeUtil.getGernalTime(umd.getCreateTime().getTime(), "yyyy-MM")
|
| | | .equalsIgnoreCase(TimeUtil.getGernalTime(list.get(0).getCreateTime().getTime(), "yyyy-MM"))) {
|
| | | 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);
|
| | | }
|
| | |
|
| | | }
|
| | | 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)));
|
| | | 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<>();
|
| | | 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().replace("-", ""));
|
| | | finalList.get(key).getMonth().setIncome(voList.get(p).getIncome());
|
| | | p++;
|
| | | }
|
| | | }
|
| | | return finalList;
|
| | | }
|
| | |
| | | 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);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal statisticUserTypeMoneyWithDate(Long uid, List<UserMoneyDetailTypeEnum> typeList, Date minDate,
|
| | | Date maxDate) {
|
| | | List<String> list = new ArrayList<>();
|
| | | if (typeList != null)
|
| | | for (UserMoneyDetailTypeEnum type : typeList) {
|
| | | list.add(type.name());
|
| | | }
|
| | | BigDecimal money = userMoneyDetailMapper.getTotalMoneyByTypeAndUidWithDate(uid, list, minDate, maxDate);
|
| | | return money == null ? new BigDecimal(0) : money;
|
| | | }
|
| | |
|
| | | }
|