Merge remote-tracking branch 'origin/lyf' into lyf
# Conflicts: # src/main/java/com/chaozhanggui/system/cashierservice/entity/TbShopInfo.java # src/main/java/com/chaozhanggui/system/cashierservice/util/RandomUtil.java
This commit is contained in:
commit
60fc45a65e
|
|
@ -105,4 +105,6 @@ public class TbShopInfo implements Serializable {
|
|||
*/
|
||||
private String tag;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
|
@ -6,10 +7,31 @@ import java.math.RoundingMode;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
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); // 返回对应索引的用户
|
||||
}
|
||||
|
||||
public static BigDecimal randomDecimalGenerator(){
|
||||
|
||||
double number = generateRandomInt(2, 40);
|
||||
|
|
@ -37,24 +59,4 @@ public class RandomUtil {
|
|||
|
||||
return random.nextInt(46) + 1;
|
||||
}
|
||||
|
||||
//获取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); // 返回对应索引的用户
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue