| | |
| | | package com.yeshi.fanli.service.impl.user.integral;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | 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.integral.IntegralDetailMapper;
|
| | | import com.yeshi.fanli.entity.integral.IntegralDetail;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.vo.integral.IntegralDetailVO;
|
| | | import com.yeshi.fanli.vo.integral.IntegralMonthVO;
|
| | |
|
| | | @Service
|
| | | public class IntegralDetailServiceImpl implements IntegralDetailService {
|
| | |
|
| | | @Resource
|
| | | private IntegralDetailMapper integralDetailMapper;
|
| | | |
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | | |
| | | @Override
|
| | | public void insertSelective(IntegralDetail record) {
|
| | | integralDetailMapper.insertSelective(record);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public IntegralDetail getDetailByUniqueKey(String uniqueKey) {
|
| | | return integralDetailMapper.getDetailByUniqueKey(uniqueKey);
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) {
|
| | | List<IntegralDetailVO> finalList = new ArrayList<>();
|
| | | List<IntegralDetail> list = null;
|
| | | if (detailId == null) {// 首次请求
|
| | | if (maxTime == null)// 没有筛选时间
|
| | | {
|
| | | list = integralDetailMapper.selectByMaxCreateTime(uid,
|
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20, type);
|
| | | } else {// 筛选了时间
|
| | | list = integralDetailMapper.selectByMaxCreateTime(uid, maxTime, 20, type);
|
| | | }
|
| | | if (list != null && list.size() > 0) {
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTimeInMillis(list.get(0).getCreateTime().getTime());
|
| | | IntegralDetailVO vo = new IntegralDetailVO();
|
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
|
| | | finalList.add(vo);
|
| | | } else {
|
| | | if (maxTime != null) {//
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTimeInMillis(maxTime.getTime());
|
| | | IntegralDetailVO vo = new IntegralDetailVO();
|
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
|
| | | vo.getMonth().setExpend("0");
|
| | | vo.getMonth().setIncome("0");
|
| | | finalList.add(vo);
|
| | | }
|
| | | }
|
| | |
|
| | | } else {// 二次请求
|
| | |
|
| | | int size = 21;
|
| | | List<IntegralDetail> tempList = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type);
|
| | | Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒)
|
| | | if (tempList.size() > 0) {
|
| | | for (IntegralDetail umd : tempList) {
|
| | | dateSet.add(umd.getCreateTime());
|
| | | }
|
| | |
|
| | | List<IntegralDetail> tempList2 = new ArrayList<>();
|
| | | while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据
|
| | | tempList = tempList2;
|
| | | size += 10;
|
| | | tempList2 = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type);
|
| | | dateSet.clear();
|
| | | for (IntegralDetail 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() == detailId) {
|
| | | tempList.remove(i);
|
| | | break;
|
| | | } else {
|
| | | tempList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | list = tempList;
|
| | | }
|
| | |
|
| | | if (list != null) {
|
| | | if (detailId != null && list.size() > 0) {
|
| | | IntegralDetail umd = integralDetailMapper.selectByPrimaryKey(detailId);
|
| | | 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());
|
| | | IntegralDetailVO vo = new IntegralDetailVO();
|
| | | vo.setMonth(new IntegralMonthVO(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());
|
| | | IntegralDetailVO vo = new IntegralDetailVO();
|
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
|
| | | finalList.add(vo);
|
| | | }
|
| | | IntegralDetailVO vo = new IntegralDetailVO();
|
| | | vo.setDetail(list.get(i));
|
| | | finalList.add(vo);
|
| | | }
|
| | | }
|
| | |
|
| | | // 统计月资金
|
| | |
|
| | | Map<Integer, IntegralDetailVO> 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<IntegralMonthVO> voList = integralDetailMapper.selectMonthMoneyByUid(uid, dateFormat);
|
| | |
|
| | | int p = 0;
|
| | | keys = monthMap.keySet().iterator();
|
| | | while (keys.hasNext()) {
|
| | | Integer key = keys.next();
|
| | | |
| | | BigDecimal expend = new BigDecimal(voList.get(p).getExpend());
|
| | | BigDecimal income = new BigDecimal(voList.get(p).getIncome());
|
| | | |
| | | // 去除支出负号
|
| | | finalList.get(key).getMonth().setExpend(expend.setScale(0).toString().replace("-", ""));
|
| | | finalList.get(key).getMonth().setIncome(income.setScale(0).toString());
|
| | | p++;
|
| | | }
|
| | | }
|
| | | return finalList;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public long countDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) {
|
| | | long monthCount = 0L;
|
| | | long detailCount = 0L;
|
| | | // 未通过时间筛选,查询所有
|
| | | if (maxTime == null) {
|
| | | detailCount = integralDetailMapper.selectCountByUid(uid, type);
|
| | | // 用于表示当前所有
|
| | | monthCount = integralDetailMapper.selectMonthCountByUid(uid, new Date(System.currentTimeMillis() + 1000 * 60 * 60L), type);
|
| | | } else {// 通过时间筛选了的,需要查询所有
|
| | | detailCount = integralDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime, type);
|
| | | monthCount = integralDetailMapper.selectMonthCountByUid(uid, maxTime, type);
|
| | | }
|
| | |
|
| | | return monthCount + detailCount;
|
| | | }
|
| | | |
| | | @Override
|
| | | public BigDecimal getCumulativeMoney(Long uid) {
|
| | | return integralDetailMapper.getCumulativeMoney(uid);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public Long countNewAddByDate(String preDay) {
|
| | | return integralDetailMapper.countNewAddByDate(preDay);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<IntegralDetail> listQuery(long start, int count, String key) {
|
| | | return integralDetailMapper.listQuery(start, count, key);
|
| | | }
|
| | | |
| | | @Override
|
| | | public long countQuery(String key) {
|
| | | Long count = integralDetailMapper.countQuery(key);
|
| | | if (count == null) {
|
| | | count = 0L;
|
| | | }
|
| | | return count;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public long sumUseGoldCoin(Long uid) {
|
| | | Long count = integralDetailMapper.sumUseGoldCoin(uid);
|
| | | if (count == null) {
|
| | | count = 0L;
|
| | | }
|
| | | return count;
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | package com.yeshi.fanli.service.impl.user.integral; |
| | | |
| | | import java.math.BigDecimal; |
| | | 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.integral.IntegralDetailMapper; |
| | | import com.yeshi.fanli.entity.integral.IntegralDetail; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.vo.integral.IntegralDetailVO; |
| | | import com.yeshi.fanli.vo.integral.IntegralMonthVO; |
| | | |
| | | @Service |
| | | public class IntegralDetailServiceImpl implements IntegralDetailService { |
| | | |
| | | @Resource |
| | | private IntegralDetailMapper integralDetailMapper; |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | @Override |
| | | public void insertSelective(IntegralDetail record) { |
| | | integralDetailMapper.insertSelective(record); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IntegralDetail getDetailByUniqueKey(String uniqueKey) { |
| | | return integralDetailMapper.getDetailByUniqueKey(uniqueKey); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<IntegralDetailVO> listDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) { |
| | | List<IntegralDetailVO> finalList = new ArrayList<>(); |
| | | List<IntegralDetail> list = null; |
| | | if (detailId == null) {// 首次请求 |
| | | if (maxTime == null)// 没有筛选时间 |
| | | { |
| | | list = integralDetailMapper.selectByMaxCreateTime(uid, |
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20, type); |
| | | } else {// 筛选了时间 |
| | | list = integralDetailMapper.selectByMaxCreateTime(uid, maxTime, 20, type); |
| | | } |
| | | if (list != null && list.size() > 0) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(list.get(0).getCreateTime().getTime()); |
| | | IntegralDetailVO vo = new IntegralDetailVO(); |
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); |
| | | finalList.add(vo); |
| | | } else { |
| | | if (maxTime != null) {// |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(maxTime.getTime()); |
| | | IntegralDetailVO vo = new IntegralDetailVO(); |
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); |
| | | vo.getMonth().setExpend("0"); |
| | | vo.getMonth().setIncome("0"); |
| | | finalList.add(vo); |
| | | } |
| | | } |
| | | |
| | | } else {// 二次请求 |
| | | |
| | | int size = 21; |
| | | List<IntegralDetail> tempList = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type); |
| | | Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒) |
| | | if (tempList.size() > 0) { |
| | | for (IntegralDetail umd : tempList) { |
| | | dateSet.add(umd.getCreateTime()); |
| | | } |
| | | |
| | | List<IntegralDetail> tempList2 = new ArrayList<>(); |
| | | while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据 |
| | | tempList = tempList2; |
| | | size += 10; |
| | | tempList2 = integralDetailMapper.selectByUidWithIndexId(uid, detailId, size, type); |
| | | dateSet.clear(); |
| | | for (IntegralDetail 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() == detailId) { |
| | | tempList.remove(i); |
| | | break; |
| | | } else { |
| | | tempList.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | list = tempList; |
| | | } |
| | | |
| | | if (list != null) { |
| | | if (detailId != null && list.size() > 0) { |
| | | IntegralDetail umd = integralDetailMapper.selectByPrimaryKey(detailId); |
| | | 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()); |
| | | IntegralDetailVO vo = new IntegralDetailVO(); |
| | | vo.setMonth(new IntegralMonthVO(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()); |
| | | IntegralDetailVO vo = new IntegralDetailVO(); |
| | | vo.setMonth(new IntegralMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); |
| | | finalList.add(vo); |
| | | } |
| | | IntegralDetailVO vo = new IntegralDetailVO(); |
| | | vo.setDetail(list.get(i)); |
| | | finalList.add(vo); |
| | | } |
| | | } |
| | | |
| | | // 统计月资金 |
| | | |
| | | Map<Integer, IntegralDetailVO> 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<IntegralMonthVO> voList = integralDetailMapper.selectMonthMoneyByUid(uid, dateFormat); |
| | | |
| | | int p = 0; |
| | | keys = monthMap.keySet().iterator(); |
| | | while (keys.hasNext()) { |
| | | Integer key = keys.next(); |
| | | |
| | | BigDecimal expend = new BigDecimal(voList.get(p).getExpend()); |
| | | BigDecimal income = new BigDecimal(voList.get(p).getIncome()); |
| | | |
| | | // 去除支出负号 |
| | | finalList.get(key).getMonth().setExpend(expend.setScale(0).toString().replace("-", "")); |
| | | finalList.get(key).getMonth().setIncome(income.setScale(0).toString()); |
| | | p++; |
| | | } |
| | | } |
| | | return finalList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public long countDetailForClient(Long uid, Long detailId, Date maxTime, Integer type) { |
| | | long monthCount = 0L; |
| | | long detailCount = 0L; |
| | | // 未通过时间筛选,查询所有 |
| | | if (maxTime == null) { |
| | | detailCount = integralDetailMapper.selectCountByUid(uid, type); |
| | | // 用于表示当前所有 |
| | | monthCount = integralDetailMapper.selectMonthCountByUid(uid, new Date(System.currentTimeMillis() + 1000 * 60 * 60L), type); |
| | | } else {// 通过时间筛选了的,需要查询所有 |
| | | detailCount = integralDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime, type); |
| | | monthCount = integralDetailMapper.selectMonthCountByUid(uid, maxTime, type); |
| | | } |
| | | |
| | | return monthCount + detailCount; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getCumulativeMoney(Long uid) { |
| | | return integralDetailMapper.getCumulativeMoney(uid); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Long countNewAddByDate(String preDay) { |
| | | return integralDetailMapper.countNewAddByDate(preDay); |
| | | } |
| | | |
| | | @Override |
| | | public List<IntegralDetail> listQuery(long start, int count, String key) { |
| | | return integralDetailMapper.listQuery(start, count, key); |
| | | } |
| | | |
| | | @Override |
| | | public long countQuery(String key) { |
| | | Long count = integralDetailMapper.countQuery(key); |
| | | if (count == null) { |
| | | count = 0L; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public long sumUseGoldCoin(Long uid) { |
| | | Long count = integralDetailMapper.sumUseGoldCoin(uid); |
| | | if (count == null) { |
| | | count = 0L; |
| | | } |
| | | return count; |
| | | } |
| | | |
| | | } |
| | | |