xiaoyong931011
2022-11-16 8dd33964afa3e8a4b1540e857f0270f25994598d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package cc.mrbird.febs.dapp.enumerate;
 
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.dapp.service.MemberOnHookPlan;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
 
public enum MemberOnHookPlanEnum implements MemberOnHookPlan {
 
        //会员游客等身份
        LEVEL_MB{
            @Override
            public Map<String, LinkedList<String>> getMemberOnHook(Double hours, BigDecimal hangingRevenue,List<Map<String,String>> plan) {
                Map objectObjectHashMap = new HashMap<String, List<String>>();
                LinkedList linkedList = new LinkedList<>();
                //最小挂机金额
                //最大挂机次数,五分钟开奖一次,一个小时固定次数12次
                int maxTimes = new Double(hours * 12).intValue();
                //预期最大收益
                BigDecimal profitTotal = AppContants.ONHOOK_BASIC_AMOUNT.multiply(hangingRevenue).setScale(4, BigDecimal.ROUND_DOWN);
                BigDecimal profitTotalNow = BigDecimal.ZERO;
                for(int i=1;i<=maxTimes;){
 
                    //当实际的收益小于预期的收益时,按照随机,否则只中奖第一方案
                    int randomInt = 1;
                    if(profitTotalNow.compareTo(profitTotal)>0){
                        randomInt = RandomUtil.randomInt(1, 3);
                    }
                    if(1 == randomInt){
                        String planKey = Integer.toString(randomInt);
                        for(Map<String,String> planMap : plan){
                            if(ObjectUtil.isNotEmpty(planMap.get(planKey))){
                                String planMapValue = planMap.get(planKey);
                                JSONObject jsonObject = JSONUtil.parseObj(planMapValue);
                                jsonObject.set("isGoal","2");
                                BigDecimal amount = new BigDecimal(jsonObject.get("amount").toString());
                                BigDecimal profit = amount.multiply(hangingRevenue).setScale(4, BigDecimal.ROUND_DOWN);
                                profitTotalNow = profitTotalNow.add(profit).setScale(4, BigDecimal.ROUND_DOWN);
                                jsonObject.set("profit",profit);
                                linkedList.add(JSONUtil.toJsonStr(jsonObject));
                                maxTimes --;
                            }
                        }
                    }else{
                        for(int j = 1;j<=randomInt;j++){
                            String planKey = Integer.toString(j);
                            for(Map<String,String> planMap : plan){
                                if(ObjectUtil.isNotEmpty(planMap.get(planKey))){
                                    String planMapValue = planMap.get(planKey);
                                    JSONObject jsonObject = JSONUtil.parseObj(planMapValue);
                                    if(j == randomInt){
                                        jsonObject.set("isGoal","2");
                                    }else{
                                        jsonObject.set("isGoal","1");
                                    }
                                    BigDecimal amount = new BigDecimal(jsonObject.get("amount").toString());
                                    BigDecimal profit = amount.multiply(hangingRevenue).setScale(4, BigDecimal.ROUND_DOWN);
                                    if(j != randomInt){
                                        profitTotalNow = profitTotalNow.add(profit).subtract(amount).setScale(4, BigDecimal.ROUND_DOWN);
                                    }else{
                                        profitTotalNow = profitTotalNow.add(profit).setScale(4, BigDecimal.ROUND_DOWN);
                                    }
                                    jsonObject.set("profit",profit);
                                    linkedList.add(JSONUtil.toJsonStr(jsonObject));
                                    maxTimes --;
                                }
                            }
                        }
                    }
 
                }
                objectObjectHashMap.put("LEVEL_MB",linkedList);
                return objectObjectHashMap;
            }
        },
        //系统设置亏损时,不管用户的身份等级
        IS_PROFIT_NO{
            @Override
            public Map<String, LinkedList<String>> getMemberOnHook(Double hours, BigDecimal hangingRevenue,List<Map<String,String>> plan) {
                Map objectObjectHashMap = new HashMap<String, LinkedList<String>>();
                LinkedList linkedList = new LinkedList<>();
                for(int i = 1;i <= plan.size();i++){
                    String planKey = Integer.toString(i);
                    for(Map<String,String> planMap : plan){
                        if(ObjectUtil.isNotEmpty(planMap.get(planKey))){
                            String planMapValue = planMap.get(planKey);
                            JSONObject jsonObject = JSONUtil.parseObj(planMapValue);
                            jsonObject.set("isGoal","1");
                            BigDecimal amount = new BigDecimal(jsonObject.get("amount").toString());
                            BigDecimal profit = amount.multiply(hangingRevenue).setScale(4, BigDecimal.ROUND_DOWN);
                            jsonObject.set("profit",profit);
                            linkedList.add(JSONUtil.toJsonStr(jsonObject));
                        }
                    }
                }
                objectObjectHashMap.put("IS_PROFIT_NO",linkedList);
                return objectObjectHashMap;
            }
        }
 
}