From c76bec54f31fc072c1b59735a7e5f04cdaeeed7c Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 15 Jul 2022 17:43:23 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/dapp/utils/BoxUtil.java | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/utils/BoxUtil.java b/src/main/java/cc/mrbird/febs/dapp/utils/BoxUtil.java
index 4055d35..8b76880 100644
--- a/src/main/java/cc/mrbird/febs/dapp/utils/BoxUtil.java
+++ b/src/main/java/cc/mrbird/febs/dapp/utils/BoxUtil.java
@@ -1,12 +1,18 @@
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
@@ -15,13 +21,17 @@
@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);
@@ -38,7 +48,8 @@
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);
@@ -61,7 +72,7 @@
break;
}
}
-
+ redisUtils.set(AppContants.IDO_BOX_PRIZE, JSONObject.toJSONString(boxList));
return result;
}
--
Gitblit v1.9.1