...
|
...
|
@@ -4,14 +4,7 @@ import java.math.BigDecimal; |
|
|
import java.text.DecimalFormat;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
...
|
...
|
@@ -172,6 +165,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
private String UNION_SHAREID = "union.shareId";
|
|
|
private String UNION_CPS_IMAGEURL = "union.cps.ImageUrl";
|
|
|
private String UNION_CPS_APPLY_IMAGEURL = "union.cps.applyImageUrl";
|
|
|
private String UNION_CPS_RANK_LIST_SWITCH = "union.cps.rankList.switch";
|
|
|
private String UNION_CPS_RANK_INFO_SWITCH = "union.cps.rankInfo.switch";
|
|
|
private String UNION_CPS_RANK_MONTHDAY = "union.cps.rank.monthday";
|
|
|
private String UNION_CPS_RANK_HOUR = "union.cps.rank.hour";
|
|
|
|
|
|
//USER_SETTLEMENT下hashkey
|
|
|
private String USER_SETTLEMENT_SETTLEAMOUNT = "settleAmount";
|
...
|
...
|
@@ -185,6 +182,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
|
|
|
private static final byte STATISTICS_QUERY_TIME_LAST_MONTH = 3;
|
|
|
|
|
|
private static final int RANK_LIST_MAX_NUM = 100;
|
|
|
|
|
|
/**
|
|
|
* 获取用户可提现金额、已提现金额、是否可以提现
|
|
|
* */
|
...
|
...
|
@@ -1105,39 +1104,130 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
@Override
|
|
|
public UninoShareIncomeRankBo queryRank(UninoShareIncomeRankReqBo req){
|
|
|
UninoShareIncomeRankBo result = new UninoShareIncomeRankBo();
|
|
|
//todo 查询排行榜
|
|
|
PageResponseBO<UninoShareIncomeBo> rankList = getRankList(req);
|
|
|
result.setRankList(rankList);
|
|
|
//每月一号0-8点排行榜关闭
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
// int monthday=configReader.getInt(UNION_CPS_RANK_MONTHDAY,1);
|
|
|
// int hour=configReader.getInt(UNION_CPS_RANK_HOUR,8);
|
|
|
if (now.get(Calendar.DAY_OF_MONTH) == 1 && now.get(Calendar.HOUR_OF_DAY) < 8) {
|
|
|
return result;
|
|
|
}
|
|
|
//查询排行榜
|
|
|
int date = Integer.valueOf(DateUtil.getToday("yyyyMMdd"));
|
|
|
|
|
|
if (req.getUid() != null) {
|
|
|
//todo 需要查询用户的数据
|
|
|
if (req.getDate() != null) {
|
|
|
BigDecimal amount = unionShareOrdersMonthMapper.selectAmountByUid(Integer.valueOf(req.getDate()), req.getUid(), 1);
|
|
|
if (amount == null) {
|
|
|
amount = new BigDecimal(0);
|
|
|
}
|
|
|
result.setAmount(amount);
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
result.setAmountStr("¥"+df.format(result.getAmount()));
|
|
|
//todo result.setRankNum();
|
|
|
UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(req.getUid());
|
|
|
if (userInfoRspBO != null) {
|
|
|
result.setImage(userInfoRspBO.getHeadIco());
|
|
|
result.setNickname(userInfoRspBO.getNickname());
|
|
|
}
|
|
|
//查询用户的数据
|
|
|
UninoShareIncomeBo rankInfo=getRankInfo(req.getUid(), date, req.getType());
|
|
|
if (rankInfo == null) {
|
|
|
//可能是zk开关关闭
|
|
|
return result;
|
|
|
}
|
|
|
BeanUtils.copyProperties(rankInfo,result);
|
|
|
}
|
|
|
UninoShareIncomeRankBo rankList = queryRankList(date, req.getType(), req.getPage(), req.getSize());
|
|
|
if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
|
|
|
result.setRankList(rankList.getRankList());
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//todo 获取排行榜数据
|
|
|
private PageResponseBO<UninoShareIncomeBo> getRankList(UninoShareIncomeRankReqBo req) {
|
|
|
List<UninoShareIncomeBo> all = new ArrayList<>();
|
|
|
PageResponseBO<UninoShareIncomeBo> result = new PageResponseBO<>();
|
|
|
result.setPage(req.getPage());
|
|
|
result.setTotal(all.size());
|
|
|
result.setSize(req.getSize());
|
|
|
result.setList(result.getPage()>1?all.subList((result.getPage()-1)*result.getSize()+1,result.getPage()*result.getSize()):null);
|
|
|
return result;
|
|
|
// 获取排行榜数据
|
|
|
private UninoShareIncomeRankBo queryRankList(int date,Integer type,int page,int size){
|
|
|
//查询zk中cps达人排行开关
|
|
|
if (!configReader.getBoolean(UNION_CPS_RANK_LIST_SWITCH, true)) {
|
|
|
return null;
|
|
|
}
|
|
|
//date 具体到日:20180814
|
|
|
int start = page > 1 ? (page - 1) * size : 0;
|
|
|
UninoShareIncomeRankBo cacheRank=getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, type.toString(), "" + start, "" + size);
|
|
|
if (cacheRank != null && CollectionUtils.isNotEmpty(cacheRank.getRankList().getList())) {
|
|
|
return cacheRank;
|
|
|
}
|
|
|
PageResponseBO<UninoShareIncomeBo> pagelist = new PageResponseBO<>();
|
|
|
if(start>0||size<RANK_LIST_MAX_NUM){
|
|
|
cacheRank = getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, "" + type, "" + 0, "" + RANK_LIST_MAX_NUM);
|
|
|
}
|
|
|
PageResponseBO<UninoShareIncomeBo> ranklist = new PageResponseBO<>();
|
|
|
if (cacheRank == null||CollectionUtils.isEmpty(cacheRank.getRankList().getList())) {
|
|
|
ranklist = queryRankListFromSql(date, type, RANK_LIST_MAX_NUM);
|
|
|
}
|
|
|
if (ranklist == null||CollectionUtils.isEmpty(ranklist.getList())) {
|
|
|
return null;
|
|
|
}
|
|
|
pagelist = new PageResponseBO<>();
|
|
|
int toIndex = start + size - 1;
|
|
|
if (toIndex > ranklist.getList().size()) {
|
|
|
toIndex = ranklist.getList().size();
|
|
|
}
|
|
|
pagelist.setList(ranklist.getList().subList(start, toIndex));
|
|
|
pagelist.setPage(page > 1 ?page:1);
|
|
|
pagelist.setSize(size);
|
|
|
pagelist.setTotal(pagelist.getList().size());
|
|
|
UninoShareIncomeRankBo uninoShareIncomeRankBo = new UninoShareIncomeRankBo(pagelist);
|
|
|
addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,uninoShareIncomeRankBo,""+type,""+start,""+size);
|
|
|
return uninoShareIncomeRankBo;
|
|
|
}
|
|
|
|
|
|
//获取用户达人排行个人信息
|
|
|
private UninoShareIncomeBo getRankInfo(Integer uid,int date,Integer type) {
|
|
|
//查询zk中cps达人排行个人信息开关
|
|
|
if (!configReader.getBoolean(UNION_CPS_RANK_INFO_SWITCH, true)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
UninoShareIncomeBo rankInfo = getFromRedis(ShareOrdersKeyEnum.RANK_INFO,date,UninoShareIncomeBo.class,uid.toString(), type.toString());
|
|
|
if (rankInfo != null) {
|
|
|
return rankInfo;
|
|
|
}
|
|
|
//
|
|
|
UninoShareIncomeRankBo rankList=queryRankList(date,type,0, RANK_LIST_MAX_NUM);
|
|
|
if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
|
|
|
for (UninoShareIncomeBo bo : rankList.getRankList().getList()) {
|
|
|
if (bo.getUid() == uid) {
|
|
|
return bo;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
rankInfo = new UninoShareIncomeBo();
|
|
|
BigDecimal amount = unionShareOrdersMonthMapper.selectAmountByUid(date/100, uid, 1);//类型:1-联盟用户,2-马甲用户
|
|
|
if (amount == null) {
|
|
|
amount = new BigDecimal(0);
|
|
|
}
|
|
|
rankInfo.setAmount(amount);
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
rankInfo.setAmountStr("¥"+df.format(rankInfo.getAmount()));
|
|
|
UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(uid);
|
|
|
if (userInfoRspBO != null) {
|
|
|
rankInfo.setImage(userInfoRspBO.getHeadIco());
|
|
|
rankInfo.setNickname(userInfoRspBO.getNickname());
|
|
|
}
|
|
|
addToRedis(ShareOrdersKeyEnum.RANK_INFO,date,rankInfo,uid.toString(), type.toString());
|
|
|
return rankInfo;
|
|
|
}
|
|
|
|
|
|
private PageResponseBO<UninoShareIncomeBo> queryRankListFromSql(int date,int type,int maxSize) {
|
|
|
List<UninoShareIncomeBo> list;
|
|
|
int monthDate = date / 100;//date 具体到日:20180814
|
|
|
if (type==1) {//1-本月,2-全部
|
|
|
list = unionShareOrdersMonthMapper.selectMonthRankList(monthDate, 0, maxSize);
|
|
|
}else {
|
|
|
list = unionShareOrdersMonthMapper.selectTotalRankList(0, maxSize);
|
|
|
}
|
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
return null;
|
|
|
}
|
|
|
DecimalFormat df = new DecimalFormat("0.00");
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
UninoShareIncomeBo uninoShareIncomeBo = list.get(i);
|
|
|
uninoShareIncomeBo.setRankNum(i+1);
|
|
|
uninoShareIncomeBo.setAmountStr("¥"+df.format(uninoShareIncomeBo.getAmount()));
|
|
|
}
|
|
|
PageResponseBO<UninoShareIncomeBo> pageList = new PageResponseBO<>();
|
|
|
pageList.setList(list);
|
|
|
pageList.setPage(0);
|
|
|
pageList.setSize(list.size());
|
|
|
pageList.setTotal(list.size());
|
|
|
addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,new UninoShareIncomeRankBo(pageList),""+type,"0",""+RANK_LIST_MAX_NUM);
|
|
|
return pageList;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -1879,13 +1969,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
|
|
|
//存入redis,注意param的顺序
|
|
|
public void addToRedis(ShareOrdersKeyEnum se, int uid,Object value, String... param) {
|
|
|
redisHashCache.put(se.getPreKey(),uid,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
|
|
|
public void addToRedis(ShareOrdersKeyEnum se, int key,Object value, String... param) {
|
|
|
redisHashCache.put(se.getPreKey(),key,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
//从redis取数据
|
|
|
public <T> T getFromRedis(ShareOrdersKeyEnum se, int uid,Class<T> clazz, String... param) {
|
|
|
return redisHashCache.get(se.getPreKey(), uid, se.getHashKey(param), clazz);
|
|
|
public <T> T getFromRedis(ShareOrdersKeyEnum se, int key,Class<T> clazz, String... param) {
|
|
|
return redisHashCache.get(se.getPreKey(), key, se.getHashKey(param), clazz);
|
|
|
}
|
|
|
|
|
|
public void clearShareOrderRedis(int uid) {
|
...
|
...
|
|