|
@@ -4,14 +4,7 @@ import java.math.BigDecimal; |
|
@@ -4,14 +4,7 @@ import java.math.BigDecimal; |
4
|
import java.text.DecimalFormat;
|
4
|
import java.text.DecimalFormat;
|
5
|
import java.text.ParseException;
|
5
|
import java.text.ParseException;
|
6
|
import java.text.SimpleDateFormat;
|
6
|
import java.text.SimpleDateFormat;
|
7
|
-import java.util.ArrayList;
|
|
|
8
|
-import java.util.Arrays;
|
|
|
9
|
-import java.util.Calendar;
|
|
|
10
|
-import java.util.HashMap;
|
|
|
11
|
-import java.util.HashSet;
|
|
|
12
|
-import java.util.List;
|
|
|
13
|
-import java.util.Map;
|
|
|
14
|
-import java.util.Set;
|
7
|
+import java.util.*;
|
15
|
import java.util.concurrent.TimeUnit;
|
8
|
import java.util.concurrent.TimeUnit;
|
16
|
import java.util.concurrent.atomic.AtomicInteger;
|
9
|
import java.util.concurrent.atomic.AtomicInteger;
|
17
|
import java.util.stream.Collectors;
|
10
|
import java.util.stream.Collectors;
|
|
@@ -172,6 +165,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
@@ -172,6 +165,10 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
172
|
private String UNION_SHAREID = "union.shareId";
|
165
|
private String UNION_SHAREID = "union.shareId";
|
173
|
private String UNION_CPS_IMAGEURL = "union.cps.ImageUrl";
|
166
|
private String UNION_CPS_IMAGEURL = "union.cps.ImageUrl";
|
174
|
private String UNION_CPS_APPLY_IMAGEURL = "union.cps.applyImageUrl";
|
167
|
private String UNION_CPS_APPLY_IMAGEURL = "union.cps.applyImageUrl";
|
|
|
168
|
+ private String UNION_CPS_RANK_LIST_SWITCH = "union.cps.rankList.switch";
|
|
|
169
|
+ private String UNION_CPS_RANK_INFO_SWITCH = "union.cps.rankInfo.switch";
|
|
|
170
|
+ private String UNION_CPS_RANK_MONTHDAY = "union.cps.rank.monthday";
|
|
|
171
|
+ private String UNION_CPS_RANK_HOUR = "union.cps.rank.hour";
|
175
|
|
172
|
|
176
|
//USER_SETTLEMENT下hashkey
|
173
|
//USER_SETTLEMENT下hashkey
|
177
|
private String USER_SETTLEMENT_SETTLEAMOUNT = "settleAmount";
|
174
|
private String USER_SETTLEMENT_SETTLEAMOUNT = "settleAmount";
|
|
@@ -185,6 +182,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
@@ -185,6 +182,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
185
|
|
182
|
|
186
|
private static final byte STATISTICS_QUERY_TIME_LAST_MONTH = 3;
|
183
|
private static final byte STATISTICS_QUERY_TIME_LAST_MONTH = 3;
|
187
|
|
184
|
|
|
|
185
|
+ private static final int RANK_LIST_MAX_NUM = 100;
|
|
|
186
|
+
|
188
|
/**
|
187
|
/**
|
189
|
* 获取用户可提现金额、已提现金额、是否可以提现
|
188
|
* 获取用户可提现金额、已提现金额、是否可以提现
|
190
|
* */
|
189
|
* */
|
|
@@ -1105,39 +1104,130 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
@@ -1105,39 +1104,130 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
1105
|
@Override
|
1104
|
@Override
|
1106
|
public UninoShareIncomeRankBo queryRank(UninoShareIncomeRankReqBo req){
|
1105
|
public UninoShareIncomeRankBo queryRank(UninoShareIncomeRankReqBo req){
|
1107
|
UninoShareIncomeRankBo result = new UninoShareIncomeRankBo();
|
1106
|
UninoShareIncomeRankBo result = new UninoShareIncomeRankBo();
|
1108
|
- //todo 查询排行榜
|
|
|
1109
|
- PageResponseBO<UninoShareIncomeBo> rankList = getRankList(req);
|
|
|
1110
|
- result.setRankList(rankList);
|
1107
|
+ //每月一号0-8点排行榜关闭
|
|
|
1108
|
+ Calendar now = Calendar.getInstance();
|
|
|
1109
|
+// int monthday=configReader.getInt(UNION_CPS_RANK_MONTHDAY,1);
|
|
|
1110
|
+// int hour=configReader.getInt(UNION_CPS_RANK_HOUR,8);
|
|
|
1111
|
+ if (now.get(Calendar.DAY_OF_MONTH) == 1 && now.get(Calendar.HOUR_OF_DAY) < 8) {
|
|
|
1112
|
+ return result;
|
|
|
1113
|
+ }
|
|
|
1114
|
+ //查询排行榜
|
|
|
1115
|
+ int date = Integer.valueOf(DateUtil.getToday("yyyyMMdd"));
|
|
|
1116
|
+
|
1111
|
if (req.getUid() != null) {
|
1117
|
if (req.getUid() != null) {
|
1112
|
- //todo 需要查询用户的数据
|
|
|
1113
|
- if (req.getDate() != null) {
|
|
|
1114
|
- BigDecimal amount = unionShareOrdersMonthMapper.selectAmountByUid(Integer.valueOf(req.getDate()), req.getUid(), 1);
|
|
|
1115
|
- if (amount == null) {
|
|
|
1116
|
- amount = new BigDecimal(0);
|
|
|
1117
|
- }
|
|
|
1118
|
- result.setAmount(amount);
|
|
|
1119
|
- DecimalFormat df = new DecimalFormat("0.00");
|
|
|
1120
|
- result.setAmountStr("¥"+df.format(result.getAmount()));
|
|
|
1121
|
-//todo result.setRankNum();
|
|
|
1122
|
- UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(req.getUid());
|
|
|
1123
|
- if (userInfoRspBO != null) {
|
|
|
1124
|
- result.setImage(userInfoRspBO.getHeadIco());
|
|
|
1125
|
- result.setNickname(userInfoRspBO.getNickname());
|
|
|
1126
|
- }
|
1118
|
+ //查询用户的数据
|
|
|
1119
|
+ UninoShareIncomeBo rankInfo=getRankInfo(req.getUid(), date, req.getType());
|
|
|
1120
|
+ if (rankInfo == null) {
|
|
|
1121
|
+ //可能是zk开关关闭
|
|
|
1122
|
+ return result;
|
1127
|
}
|
1123
|
}
|
|
|
1124
|
+ BeanUtils.copyProperties(rankInfo,result);
|
|
|
1125
|
+ }
|
|
|
1126
|
+ UninoShareIncomeRankBo rankList = queryRankList(date, req.getType(), req.getPage(), req.getSize());
|
|
|
1127
|
+ if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
|
|
|
1128
|
+ result.setRankList(rankList.getRankList());
|
1128
|
}
|
1129
|
}
|
1129
|
return result;
|
1130
|
return result;
|
1130
|
}
|
1131
|
}
|
1131
|
|
1132
|
|
1132
|
- //todo 获取排行榜数据
|
|
|
1133
|
- private PageResponseBO<UninoShareIncomeBo> getRankList(UninoShareIncomeRankReqBo req) {
|
|
|
1134
|
- List<UninoShareIncomeBo> all = new ArrayList<>();
|
|
|
1135
|
- PageResponseBO<UninoShareIncomeBo> result = new PageResponseBO<>();
|
|
|
1136
|
- result.setPage(req.getPage());
|
|
|
1137
|
- result.setTotal(all.size());
|
|
|
1138
|
- result.setSize(req.getSize());
|
|
|
1139
|
- result.setList(result.getPage()>1?all.subList((result.getPage()-1)*result.getSize()+1,result.getPage()*result.getSize()):null);
|
|
|
1140
|
- return result;
|
1133
|
+ // 获取排行榜数据
|
|
|
1134
|
+ private UninoShareIncomeRankBo queryRankList(int date,Integer type,int page,int size){
|
|
|
1135
|
+ //查询zk中cps达人排行开关
|
|
|
1136
|
+ if (!configReader.getBoolean(UNION_CPS_RANK_LIST_SWITCH, true)) {
|
|
|
1137
|
+ return null;
|
|
|
1138
|
+ }
|
|
|
1139
|
+ //date 具体到日:20180814
|
|
|
1140
|
+ int start = page > 1 ? (page - 1) * size : 0;
|
|
|
1141
|
+ UninoShareIncomeRankBo cacheRank=getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, type.toString(), "" + start, "" + size);
|
|
|
1142
|
+ if (cacheRank != null && CollectionUtils.isNotEmpty(cacheRank.getRankList().getList())) {
|
|
|
1143
|
+ return cacheRank;
|
|
|
1144
|
+ }
|
|
|
1145
|
+ PageResponseBO<UninoShareIncomeBo> pagelist = new PageResponseBO<>();
|
|
|
1146
|
+ if(start>0||size<RANK_LIST_MAX_NUM){
|
|
|
1147
|
+ cacheRank = getFromRedis(ShareOrdersKeyEnum.RANK_LIST, date, UninoShareIncomeRankBo.class, "" + type, "" + 0, "" + RANK_LIST_MAX_NUM);
|
|
|
1148
|
+ }
|
|
|
1149
|
+ PageResponseBO<UninoShareIncomeBo> ranklist = new PageResponseBO<>();
|
|
|
1150
|
+ if (cacheRank == null||CollectionUtils.isEmpty(cacheRank.getRankList().getList())) {
|
|
|
1151
|
+ ranklist = queryRankListFromSql(date, type, RANK_LIST_MAX_NUM);
|
|
|
1152
|
+ }
|
|
|
1153
|
+ if (ranklist == null||CollectionUtils.isEmpty(ranklist.getList())) {
|
|
|
1154
|
+ return null;
|
|
|
1155
|
+ }
|
|
|
1156
|
+ pagelist = new PageResponseBO<>();
|
|
|
1157
|
+ int toIndex = start + size - 1;
|
|
|
1158
|
+ if (toIndex > ranklist.getList().size()) {
|
|
|
1159
|
+ toIndex = ranklist.getList().size();
|
|
|
1160
|
+ }
|
|
|
1161
|
+ pagelist.setList(ranklist.getList().subList(start, toIndex));
|
|
|
1162
|
+ pagelist.setPage(page > 1 ?page:1);
|
|
|
1163
|
+ pagelist.setSize(size);
|
|
|
1164
|
+ pagelist.setTotal(pagelist.getList().size());
|
|
|
1165
|
+ UninoShareIncomeRankBo uninoShareIncomeRankBo = new UninoShareIncomeRankBo(pagelist);
|
|
|
1166
|
+ addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,uninoShareIncomeRankBo,""+type,""+start,""+size);
|
|
|
1167
|
+ return uninoShareIncomeRankBo;
|
|
|
1168
|
+ }
|
|
|
1169
|
+
|
|
|
1170
|
+ //获取用户达人排行个人信息
|
|
|
1171
|
+ private UninoShareIncomeBo getRankInfo(Integer uid,int date,Integer type) {
|
|
|
1172
|
+ //查询zk中cps达人排行个人信息开关
|
|
|
1173
|
+ if (!configReader.getBoolean(UNION_CPS_RANK_INFO_SWITCH, true)) {
|
|
|
1174
|
+ return null;
|
|
|
1175
|
+ }
|
|
|
1176
|
+
|
|
|
1177
|
+ UninoShareIncomeBo rankInfo = getFromRedis(ShareOrdersKeyEnum.RANK_INFO,date,UninoShareIncomeBo.class,uid.toString(), type.toString());
|
|
|
1178
|
+ if (rankInfo != null) {
|
|
|
1179
|
+ return rankInfo;
|
|
|
1180
|
+ }
|
|
|
1181
|
+ //
|
|
|
1182
|
+ UninoShareIncomeRankBo rankList=queryRankList(date,type,0, RANK_LIST_MAX_NUM);
|
|
|
1183
|
+ if (rankList != null && rankList.getRankList() != null && CollectionUtils.isNotEmpty(rankList.getRankList().getList())) {
|
|
|
1184
|
+ for (UninoShareIncomeBo bo : rankList.getRankList().getList()) {
|
|
|
1185
|
+ if (bo.getUid() == uid) {
|
|
|
1186
|
+ return bo;
|
|
|
1187
|
+ }
|
|
|
1188
|
+ }
|
|
|
1189
|
+ }
|
|
|
1190
|
+ rankInfo = new UninoShareIncomeBo();
|
|
|
1191
|
+ BigDecimal amount = unionShareOrdersMonthMapper.selectAmountByUid(date/100, uid, 1);//类型:1-联盟用户,2-马甲用户
|
|
|
1192
|
+ if (amount == null) {
|
|
|
1193
|
+ amount = new BigDecimal(0);
|
|
|
1194
|
+ }
|
|
|
1195
|
+ rankInfo.setAmount(amount);
|
|
|
1196
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
1197
|
+ rankInfo.setAmountStr("¥"+df.format(rankInfo.getAmount()));
|
|
|
1198
|
+ UserInfoRspBO userInfoRspBO = userServiceHelper.getUserInfoFromUic(uid);
|
|
|
1199
|
+ if (userInfoRspBO != null) {
|
|
|
1200
|
+ rankInfo.setImage(userInfoRspBO.getHeadIco());
|
|
|
1201
|
+ rankInfo.setNickname(userInfoRspBO.getNickname());
|
|
|
1202
|
+ }
|
|
|
1203
|
+ addToRedis(ShareOrdersKeyEnum.RANK_INFO,date,rankInfo,uid.toString(), type.toString());
|
|
|
1204
|
+ return rankInfo;
|
|
|
1205
|
+ }
|
|
|
1206
|
+
|
|
|
1207
|
+ private PageResponseBO<UninoShareIncomeBo> queryRankListFromSql(int date,int type,int maxSize) {
|
|
|
1208
|
+ List<UninoShareIncomeBo> list;
|
|
|
1209
|
+ int monthDate = date / 100;//date 具体到日:20180814
|
|
|
1210
|
+ if (type==1) {//1-本月,2-全部
|
|
|
1211
|
+ list = unionShareOrdersMonthMapper.selectMonthRankList(monthDate, 0, maxSize);
|
|
|
1212
|
+ }else {
|
|
|
1213
|
+ list = unionShareOrdersMonthMapper.selectTotalRankList(0, maxSize);
|
|
|
1214
|
+ }
|
|
|
1215
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
1216
|
+ return null;
|
|
|
1217
|
+ }
|
|
|
1218
|
+ DecimalFormat df = new DecimalFormat("0.00");
|
|
|
1219
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
1220
|
+ UninoShareIncomeBo uninoShareIncomeBo = list.get(i);
|
|
|
1221
|
+ uninoShareIncomeBo.setRankNum(i+1);
|
|
|
1222
|
+ uninoShareIncomeBo.setAmountStr("¥"+df.format(uninoShareIncomeBo.getAmount()));
|
|
|
1223
|
+ }
|
|
|
1224
|
+ PageResponseBO<UninoShareIncomeBo> pageList = new PageResponseBO<>();
|
|
|
1225
|
+ pageList.setList(list);
|
|
|
1226
|
+ pageList.setPage(0);
|
|
|
1227
|
+ pageList.setSize(list.size());
|
|
|
1228
|
+ pageList.setTotal(list.size());
|
|
|
1229
|
+ addToRedis(ShareOrdersKeyEnum.RANK_LIST,date,new UninoShareIncomeRankBo(pageList),""+type,"0",""+RANK_LIST_MAX_NUM);
|
|
|
1230
|
+ return pageList;
|
1141
|
}
|
1231
|
}
|
1142
|
|
1232
|
|
1143
|
|
1233
|
|
|
@@ -1879,13 +1969,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
@@ -1879,13 +1969,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
1879
|
}
|
1969
|
}
|
1880
|
|
1970
|
|
1881
|
//存入redis,注意param的顺序
|
1971
|
//存入redis,注意param的顺序
|
1882
|
- public void addToRedis(ShareOrdersKeyEnum se, int uid,Object value, String... param) {
|
|
|
1883
|
- redisHashCache.put(se.getPreKey(),uid,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
|
1972
|
+ public void addToRedis(ShareOrdersKeyEnum se, int key,Object value, String... param) {
|
|
|
1973
|
+ redisHashCache.put(se.getPreKey(),key,se.getHashKey(param),value,se.getCacheTime(), TimeUnit.SECONDS);
|
1884
|
}
|
1974
|
}
|
1885
|
|
1975
|
|
1886
|
//从redis取数据
|
1976
|
//从redis取数据
|
1887
|
- public <T> T getFromRedis(ShareOrdersKeyEnum se, int uid,Class<T> clazz, String... param) {
|
|
|
1888
|
- return redisHashCache.get(se.getPreKey(), uid, se.getHashKey(param), clazz);
|
1977
|
+ public <T> T getFromRedis(ShareOrdersKeyEnum se, int key,Class<T> clazz, String... param) {
|
|
|
1978
|
+ return redisHashCache.get(se.getPreKey(), key, se.getHashKey(param), clazz);
|
1889
|
}
|
1979
|
}
|
1890
|
|
1980
|
|
1891
|
public void clearShareOrderRedis(int uid) {
|
1981
|
public void clearShareOrderRedis(int uid) {
|