| | |
| | | package com.yeshi.fanli.service.impl.redpack;
|
| | |
|
| | | 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.redpack.RedPackDetailMapper;
|
| | | import com.yeshi.fanli.entity.redpack.RedPackDetail;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import org.yeshi.utils.TimeUtil;
|
| | | import com.yeshi.fanli.vo.redpack.RedPackDetailVO;
|
| | | import com.yeshi.fanli.vo.redpack.RedPackMonthVO;
|
| | |
|
| | | @Service
|
| | | public class RedPackDetailServiceImpl implements RedPackDetailService {
|
| | |
|
| | | @Resource
|
| | | private RedPackDetailMapper redPackDetailMapper;
|
| | |
|
| | | @Override
|
| | | public void insertSelective(RedPackDetail record) {
|
| | | redPackDetailMapper.insertSelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateByPrimaryKeySelective(RedPackDetail record) {
|
| | | redPackDetailMapper.updateByPrimaryKeySelective(record);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public RedPackDetail getByIdentifyCode(String identifyCode) {
|
| | | return redPackDetailMapper.getByIdentifyCode(identifyCode);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal countAddMoneyByDate(long uid, int dateType) {
|
| | | return redPackDetailMapper.countAddMoneyByDate(uid, dateType);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal countUseMoneyByDate(long uid, int dateType) {
|
| | | return redPackDetailMapper.countUseMoneyByDate(uid, dateType);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<RedPackDetailVO> listUserMoneyDetailForClient(Long uid, Long detailId, Date maxTime) {
|
| | | List<RedPackDetailVO> finalList = new ArrayList<>();
|
| | | List<RedPackDetail> list = null;
|
| | | if (detailId == null) {// 首次请求
|
| | | if (maxTime == null)// 没有筛选时间
|
| | | {
|
| | | list = redPackDetailMapper.selectByMaxCreateTime(uid,
|
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20);
|
| | | } else {// 筛选了时间
|
| | | list = redPackDetailMapper.selectByMaxCreateTime(uid, maxTime, 20);
|
| | | }
|
| | | if (list != null && list.size() > 0) {
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTimeInMillis(list.get(0).getCreateTime().getTime());
|
| | | RedPackDetailVO vo = new RedPackDetailVO();
|
| | | vo.setMonth(new RedPackMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
|
| | | finalList.add(vo);
|
| | | } else {
|
| | | if (maxTime != null) {//
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTimeInMillis(maxTime.getTime());
|
| | | RedPackDetailVO vo = new RedPackDetailVO();
|
| | | vo.setMonth(new RedPackMonthVO(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<RedPackDetail> tempList = redPackDetailMapper.selectByUidWithIndexId(uid, detailId, size);
|
| | | Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒)
|
| | | if (tempList.size() > 0) {
|
| | | for (RedPackDetail umd : tempList) {
|
| | | dateSet.add(umd.getCreateTime());
|
| | | }
|
| | |
|
| | | List<RedPackDetail> tempList2 = new ArrayList<>();
|
| | | while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据
|
| | | tempList = tempList2;
|
| | | size += 10;
|
| | | tempList2 = redPackDetailMapper.selectByUidWithIndexId(uid, detailId, size);
|
| | | dateSet.clear();
|
| | | for (RedPackDetail 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) {
|
| | | RedPackDetail umd = redPackDetailMapper.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());
|
| | | RedPackDetailVO vo = new RedPackDetailVO();
|
| | | vo.setMonth(new RedPackMonthVO(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());
|
| | | RedPackDetailVO vo = new RedPackDetailVO();
|
| | | vo.setMonth(new RedPackMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1));
|
| | | finalList.add(vo);
|
| | | }
|
| | | RedPackDetailVO vo = new RedPackDetailVO();
|
| | | vo.setDetail(list.get(i));
|
| | | finalList.add(vo);
|
| | | }
|
| | | }
|
| | |
|
| | | // 统计月资金
|
| | |
|
| | | Map<Integer, RedPackDetailVO> 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<RedPackMonthVO> voList = redPackDetailMapper.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(2).toString().replace("-", ""));
|
| | | finalList.get(key).getMonth().setIncome(income.setScale(2).toString());
|
| | | p++;
|
| | | }
|
| | | }
|
| | | return finalList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countUserMoneyDetailForClient(Long uid, Long detailId, Date maxTime) {
|
| | | long monthCount = 0L;
|
| | | long detailCount = 0L;
|
| | | // 未通过时间筛选,查询所有
|
| | | if (maxTime == null) {
|
| | | detailCount = redPackDetailMapper.selectCountByUid(uid);
|
| | | // 用于表示当前所有
|
| | | monthCount = redPackDetailMapper.selectMonthCountByUid(uid,
|
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L));
|
| | | } else {// 通过时间筛选了的,需要查询所有
|
| | | detailCount = redPackDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime);
|
| | | monthCount = redPackDetailMapper.selectMonthCountByUid(uid, maxTime);
|
| | | }
|
| | |
|
| | | return monthCount + detailCount;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void changeDisplayByIdentifyCode(String code, boolean disPlay) {
|
| | | if (StringUtil.isNullOrEmpty(code))
|
| | | return;
|
| | | RedPackDetail oldDetail = getByIdentifyCode(code);
|
| | | if (oldDetail != null) {// 外显红包详情
|
| | | RedPackDetail update = new RedPackDetail();
|
| | | update.setId(oldDetail.getId());
|
| | | update.setDisplay(true);
|
| | | redPackDetailMapper.updateByPrimaryKeySelective(update);
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public BigDecimal countWinMoneyByDate(long uid, int dateType) {
|
| | | return redPackDetailMapper.countWinMoneyByDate(uid, dateType);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public BigDecimal countReduceMoneyByDate(long uid, int dateType) {
|
| | | return redPackDetailMapper.countReduceMoneyByDate(uid, dateType);
|
| | | }
|
| | | |
| | | @Override
|
| | | public List<RedPackDetail> query(Integer start, Integer count, String key, Long uid, Integer type){
|
| | | return redPackDetailMapper.query(start, count, key, uid, type);
|
| | | }
|
| | | |
| | | @Override
|
| | | public long count(String key,Long uid, Integer type){
|
| | | return redPackDetailMapper.count(key, uid, type);
|
| | | }
|
| | | |
| | | @Override
|
| | | public Long countNumByDay(String preDay) {
|
| | | return redPackDetailMapper.countNumByDay(preDay);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public BigDecimal countMoneyByDay(String preDay) {
|
| | | return redPackDetailMapper.countMoneyByDay(preDay);
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.redpack; |
| | | |
| | | 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.redpack.RedPackDetailMapper; |
| | | import com.yeshi.fanli.entity.redpack.RedPackDetail; |
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.fanli.vo.redpack.RedPackDetailVO; |
| | | import com.yeshi.fanli.vo.redpack.RedPackMonthVO; |
| | | |
| | | @Service |
| | | public class RedPackDetailServiceImpl implements RedPackDetailService { |
| | | |
| | | @Resource |
| | | private RedPackDetailMapper redPackDetailMapper; |
| | | |
| | | @Override |
| | | public void insertSelective(RedPackDetail record) { |
| | | redPackDetailMapper.insertSelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public void updateByPrimaryKeySelective(RedPackDetail record) { |
| | | redPackDetailMapper.updateByPrimaryKeySelective(record); |
| | | } |
| | | |
| | | @Override |
| | | public RedPackDetail getByIdentifyCode(String identifyCode) { |
| | | return redPackDetailMapper.getByIdentifyCode(identifyCode); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal countAddMoneyByDate(long uid, int dateType) { |
| | | return redPackDetailMapper.countAddMoneyByDate(uid, dateType); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal countUseMoneyByDate(long uid, int dateType) { |
| | | return redPackDetailMapper.countUseMoneyByDate(uid, dateType); |
| | | } |
| | | |
| | | @Override |
| | | public List<RedPackDetailVO> listUserMoneyDetailForClient(Long uid, Long detailId, Date maxTime) { |
| | | List<RedPackDetailVO> finalList = new ArrayList<>(); |
| | | List<RedPackDetail> list = null; |
| | | if (detailId == null) {// 首次请求 |
| | | if (maxTime == null)// 没有筛选时间 |
| | | { |
| | | list = redPackDetailMapper.selectByMaxCreateTime(uid, |
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L), 20); |
| | | } else {// 筛选了时间 |
| | | list = redPackDetailMapper.selectByMaxCreateTime(uid, maxTime, 20); |
| | | } |
| | | if (list != null && list.size() > 0) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(list.get(0).getCreateTime().getTime()); |
| | | RedPackDetailVO vo = new RedPackDetailVO(); |
| | | vo.setMonth(new RedPackMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); |
| | | finalList.add(vo); |
| | | } else { |
| | | if (maxTime != null) {// |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(maxTime.getTime()); |
| | | RedPackDetailVO vo = new RedPackDetailVO(); |
| | | vo.setMonth(new RedPackMonthVO(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<RedPackDetail> tempList = redPackDetailMapper.selectByUidWithIndexId(uid, detailId, size); |
| | | Set<Date> dateSet = new HashSet<>();// 用于储存是否在同一时间上面(精确到秒) |
| | | if (tempList.size() > 0) { |
| | | for (RedPackDetail umd : tempList) { |
| | | dateSet.add(umd.getCreateTime()); |
| | | } |
| | | |
| | | List<RedPackDetail> tempList2 = new ArrayList<>(); |
| | | while (dateSet.size() == 1 && tempList2.size() != tempList.size() && size < 40) {// 只有一个时间点的数据 |
| | | tempList = tempList2; |
| | | size += 10; |
| | | tempList2 = redPackDetailMapper.selectByUidWithIndexId(uid, detailId, size); |
| | | dateSet.clear(); |
| | | for (RedPackDetail 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) { |
| | | RedPackDetail umd = redPackDetailMapper.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()); |
| | | RedPackDetailVO vo = new RedPackDetailVO(); |
| | | vo.setMonth(new RedPackMonthVO(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()); |
| | | RedPackDetailVO vo = new RedPackDetailVO(); |
| | | vo.setMonth(new RedPackMonthVO(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1)); |
| | | finalList.add(vo); |
| | | } |
| | | RedPackDetailVO vo = new RedPackDetailVO(); |
| | | vo.setDetail(list.get(i)); |
| | | finalList.add(vo); |
| | | } |
| | | } |
| | | |
| | | // 统计月资金 |
| | | |
| | | Map<Integer, RedPackDetailVO> 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<RedPackMonthVO> voList = redPackDetailMapper.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(2).toString().replace("-", "")); |
| | | finalList.get(key).getMonth().setIncome(income.setScale(2).toString()); |
| | | p++; |
| | | } |
| | | } |
| | | return finalList; |
| | | } |
| | | |
| | | @Override |
| | | public long countUserMoneyDetailForClient(Long uid, Long detailId, Date maxTime) { |
| | | long monthCount = 0L; |
| | | long detailCount = 0L; |
| | | // 未通过时间筛选,查询所有 |
| | | if (maxTime == null) { |
| | | detailCount = redPackDetailMapper.selectCountByUid(uid); |
| | | // 用于表示当前所有 |
| | | monthCount = redPackDetailMapper.selectMonthCountByUid(uid, |
| | | new Date(System.currentTimeMillis() + 1000 * 60 * 60L)); |
| | | } else {// 通过时间筛选了的,需要查询所有 |
| | | detailCount = redPackDetailMapper.selectCountByUidAndMaxCreateTime(uid, maxTime); |
| | | monthCount = redPackDetailMapper.selectMonthCountByUid(uid, maxTime); |
| | | } |
| | | |
| | | return monthCount + detailCount; |
| | | } |
| | | |
| | | @Override |
| | | public void changeDisplayByIdentifyCode(String code, boolean disPlay) { |
| | | if (StringUtil.isNullOrEmpty(code)) |
| | | return; |
| | | RedPackDetail oldDetail = getByIdentifyCode(code); |
| | | if (oldDetail != null) {// 外显红包详情 |
| | | RedPackDetail update = new RedPackDetail(); |
| | | update.setId(oldDetail.getId()); |
| | | update.setDisplay(true); |
| | | redPackDetailMapper.updateByPrimaryKeySelective(update); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal countWinMoneyByDate(long uid, int dateType) { |
| | | return redPackDetailMapper.countWinMoneyByDate(uid, dateType); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal countReduceMoneyByDate(long uid, int dateType) { |
| | | return redPackDetailMapper.countReduceMoneyByDate(uid, dateType); |
| | | } |
| | | |
| | | @Override |
| | | public List<RedPackDetail> query(Integer start, Integer count, String key, Long uid, Integer type){ |
| | | return redPackDetailMapper.query(start, count, key, uid, type); |
| | | } |
| | | |
| | | @Override |
| | | public long count(String key,Long uid, Integer type){ |
| | | return redPackDetailMapper.count(key, uid, type); |
| | | } |
| | | |
| | | @Override |
| | | public Long countNumByDay(String preDay) { |
| | | return redPackDetailMapper.countNumByDay(preDay); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal countMoneyByDay(String preDay) { |
| | | return redPackDetailMapper.countMoneyByDay(preDay); |
| | | } |
| | | } |