|
@@ -1,8 +1,15 @@
|
|
|
package org.jeecg.modules.bytedance.common.utils;
|
|
|
|
|
|
+import org.checkerframework.checker.units.qual.min;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.NumberFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -171,4 +178,65 @@ public class StringUtils {
|
|
|
}
|
|
|
return dest;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @description: 获取目标转化出价
|
|
|
+ *
|
|
|
+ * @param type 智能投放计划创建出价方式
|
|
|
+ * 固定出价 FIX ;
|
|
|
+ * 随机出价 RAND;
|
|
|
+ * 阶梯出价 STEP
|
|
|
+ * @param maxBigDecimal 转化出价最da值
|
|
|
+ * @param minBigDecimal 转化出价最小值
|
|
|
+ * @param stepBigDecimal 浮动间隔
|
|
|
+ * @return: java.lang.Double
|
|
|
+ * @author: zianY
|
|
|
+ */
|
|
|
+ public static Double getRandomAdCpaBid(String type,BigDecimal maxBigDecimal,BigDecimal minBigDecimal,BigDecimal stepBigDecimal){
|
|
|
+ double max = maxBigDecimal.doubleValue();
|
|
|
+ double min = minBigDecimal.doubleValue();
|
|
|
+ double step = stepBigDecimal.doubleValue();
|
|
|
+ double result = 0d;
|
|
|
+ //当出价为随机出价时,可以随机选择出价范围内的一个值当作出价
|
|
|
+ if ("RAND".equalsIgnoreCase(type)){
|
|
|
+ result = min + (Math.random() * (max - min));
|
|
|
+ result = (double) Math.round(result * 100) / 100;
|
|
|
+ }
|
|
|
+ //当出价为阶梯出价时,创建的出价为 最低出价 + N * 浮动间隔 < 最高出价
|
|
|
+ if ("STEP".equalsIgnoreCase(type)){
|
|
|
+ int r = (int) (Math.random()*(max-min)+min);
|
|
|
+ result = min + r * step;
|
|
|
+ if (result > max){
|
|
|
+ return getRandomAdCpaBid(type,maxBigDecimal,minBigDecimal,stepBigDecimal);
|
|
|
+ }
|
|
|
+ //System.out.println("随机数-----"+r+"结果====="+min+"+"+r+"x"+step+"="+result);
|
|
|
+ }
|
|
|
+ BigDecimal bg = new BigDecimal(result).setScale(2, RoundingMode.DOWN);
|
|
|
+ return bg.doubleValue();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ BigDecimal max = new BigDecimal(6.89);
|
|
|
+ BigDecimal min = new BigDecimal(0.12);
|
|
|
+ BigDecimal step = new BigDecimal(1.2);
|
|
|
+
|
|
|
+ for (int i = 0 ;i< 100 ;i++){
|
|
|
+ System.out.println(getRandomAdCpaBid("RAND",max,min,step));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|