优惠券+异常全局处理
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class NicknameGenerator {
|
||||
private static final String[] FIRST_NAMES = {
|
||||
"晓", "小", "云", "飞", "宝", "琳", "静", "翔", "晨", "昊", "若", "萌", "悦", "舒", "婷", "紫", "凡", "佳", "雨", "阳"
|
||||
};
|
||||
|
||||
private static final String[] LAST_NAMES = {
|
||||
"天", "星", "月", "琪", "雪", "梦", "婷", "晨", "宇", "瑞", "颖", "欣", "莹", "妍", "娜", "辰", "楠", "妮", "欢", "瑶"
|
||||
};
|
||||
|
||||
private static final String[] WORDS = {
|
||||
"烟火", "夜景", "小巷", "阳光", "雨滴", "星空", "花海", "梦境", "魔法", "飞翔", "童话", "温柔", "快乐", "微笑", "甜蜜", "浪漫", "幸福"
|
||||
};
|
||||
|
||||
private static final String[] EMOJIS = {
|
||||
"(^-^)", "( ̄▽ ̄)~■干杯□~( ̄▽ ̄)", "(*^▽^*)", "≧◡≦", "ヾ(≧▽≦*)o",
|
||||
"(*^3^)/~☆", "(*^▽^*)", "╰( ̄▽ ̄)╮", "(o^^)o", "(づ ̄ 3 ̄)づ"
|
||||
};
|
||||
|
||||
public static String generateRandomWeChatNickname() {
|
||||
Random random = new Random();
|
||||
String firstName = FIRST_NAMES[random.nextInt(FIRST_NAMES.length)];
|
||||
String lastName = LAST_NAMES[random.nextInt(LAST_NAMES.length)];
|
||||
String word = WORDS[random.nextInt(WORDS.length)];
|
||||
String emoji = EMOJIS[random.nextInt(EMOJIS.length)];
|
||||
return firstName + lastName + word + emoji;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomUtil {
|
||||
//获取BigDeciaml随机数
|
||||
public static BigDecimal getRandomBigDecimal(BigDecimal minAmount, BigDecimal maxAmount) {
|
||||
BigDecimal randomBigDecimal = maxAmount.subtract(minAmount).multiply(new BigDecimal(Math.random())).add(minAmount);
|
||||
return randomBigDecimal.setScale(2, RoundingMode.HALF_UP); // 设置保留两位小数并四舍五入
|
||||
}
|
||||
//获取中奖随机数
|
||||
public static TbOrderInfo selectWinner(List<TbOrderInfo> list, Map<Integer,Integer> map) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return null; // 如果用户列表为空,则返回null
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
int randomIndex = random.nextInt(list.size()); // 生成一个随机的索引值
|
||||
TbOrderInfo orderInfo = list.get(randomIndex);
|
||||
if (map.containsKey(orderInfo.getId())){
|
||||
return selectWinner(list,map);
|
||||
}
|
||||
return list.get(randomIndex); // 返回对应索引的用户
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class WiningUtil {
|
||||
private List<String> participants;
|
||||
private Random random;
|
||||
|
||||
public WiningUtil(List<String> participants) {
|
||||
this.participants = participants;
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public String drawWinner() {
|
||||
if (participants.isEmpty()) {
|
||||
return "No participants to draw from";
|
||||
}
|
||||
|
||||
int index = random.nextInt(participants.size());
|
||||
return participants.get(index);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 参与抽奖的人员名单
|
||||
List<String> participants = new ArrayList<>();
|
||||
participants.add("Alice");
|
||||
participants.add("Bob");
|
||||
participants.add("Charlie");
|
||||
participants.add("David");
|
||||
participants.add("Eve");
|
||||
|
||||
// 创建抽奖对象
|
||||
WiningUtil winingUtil = new WiningUtil(participants);
|
||||
|
||||
// 进行抽奖
|
||||
String winner = winingUtil.drawWinner();
|
||||
System.out.println("Winner: " + winner);
|
||||
}
|
||||
public static boolean winingresult(){
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user