举例:
间隔三天,更换展示顺序
用户9.1日 看到顺序为A,B,C
9.4日,看到顺序为B,C,A
9.7日,看到顺序为C,A,B
private List<String> couponOrderList(String userId){
//缓存用户第一次看到的时间
String redisKey = RedisKey.xx+ userId;
String stTimeStr = userCache.getValue(redisKey);
Date stDay = new Date();
if(StringUtils.isNotEmpty(stTimeStr)){
stDay = DateUtil.parseDate(stTimeStr,"yyyyMMdd");
}
//顺序1,2,3 对应不同的内容
String orderStr = "1,2,3";
//间隔天数
String intervalStr = "3";
List<String> orderList = Splitter.on(",").omitEmptyStrings().splitToList(orderStr);
int orderSize = orderList.size();
int interval = Integer.parseInt(intervalStr);
int intervalBig = interval * orderSize;
int intervalDays = DateUtil.getBetweenDays(stDay,new Date());
int idx = 0;
intervalDays = intervalDays % intervalBig;
idx = intervalDays / orderSize;
if(0== idx) {
return orderList;
} else {
List<String> list = new LinkedList<>();
list.addAll(orderList.subList(idx,orderSize));
list.addAll(orderList.subList(0,idx));
return list;
}
}