| | |
| | | package cc.mrbird.febs.dapp.utils; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.SpringContextUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Slf4j |
| | | public class BoxUtil { |
| | | |
| | | public static volatile List<Box> boxList = Collections.synchronizedList(new ArrayList<>()); |
| | | // public static volatile List<Box> boxList = Collections.synchronizedList(new ArrayList<>()); |
| | | |
| | | private static final RedisUtils redisUtils = SpringContextUtil.getBean(RedisUtils.class); |
| | | public synchronized static Box openBox() { |
| | | String redisStr = redisUtils.getString(AppContants.IDO_BOX_PRIZE); |
| | | List<Box> boxList = JSONObject.parseArray(redisStr, Box.class); |
| | | if (CollUtil.isEmpty(boxList)) { |
| | | Box box1 = new Box(1, 6); |
| | | Box box2 = new Box(2, 1); |
| | | Box box3 = new Box(3, 1); |
| | | boxList = Collections.synchronizedList(new ArrayList<>()); |
| | | Box box1 = new Box(1, 91); |
| | | Box box2 = new Box(2, 4); |
| | | Box box3 = new Box(3, 3); |
| | | Box box4 = new Box(4, 1); |
| | | Box box5 = new Box(5, 1); |
| | | boxList.add(box1); |
| | |
| | | for (int i = 0; i < boxList.size(); i++) { |
| | | Box box = boxList.get(i); |
| | | if (i != 0) { |
| | | minIndex += boxList.get(i - 1).getCount(); |
| | | Box lastBox = (Box) boxList.get(i - 1); |
| | | minIndex += lastBox.getCount(); |
| | | } |
| | | max += box.getCount(); |
| | | box.setMin(minIndex); |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | redisUtils.set(AppContants.IDO_BOX_PRIZE, JSONObject.toJSONString(boxList)); |
| | | return result; |
| | | } |
| | | |