yangzian 3 лет назад
Родитель
Сommit
04d674c4f1

+ 432 - 2
jeecg-boot-bytedance/src/test/java/cn/com/ctop/AppTest.java

@@ -1,8 +1,25 @@
 package cn.com.ctop;
 
-import static org.junit.Assert.assertTrue;
-
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.bytedance.advertise.enums.BytedanceCreativeMatTypeEnum;
+import org.jeecg.modules.bytedance.advertise.vo.IndustryVo;
+import org.jeecg.modules.bytedance.common.service.IMaterialInfoService;
+import org.jeecg.modules.bytedance.common.utils.Check;
+import org.jeecg.modules.bytedance.common.utils.GetCampaignNum;
+import org.jeecg.modules.bytedance.common.utils.StringUtils;
 import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import static org.junit.Assert.assertTrue;
 
 /**
  * Unit test for simple App.
@@ -17,4 +34,417 @@ public class AppTest
     {
         assertTrue( true );
     }
+
+
+    @Test
+    public void str(){
+        String adName = "测试-123-{{出价方式}}";
+        String a = "PRICING_OCPM";
+        String pricing = a.replace("PRICING_","");
+        adName = adName.replace("{{出价方式}}",pricing).toLowerCase(Locale.ROOT);
+        System.out.println(adName);
+    }
+
+
+    @Test
+    public void ANDROID(){
+        // String[] platformStr = platform.toArray(new String[]{});
+       // String platStr = "ANDROID,IOS";
+       /* String platStr = "PC,IOS";
+        String a = platStr.replace("ANDROID","Android");
+        System.out.println(a.split(","));*/
+
+
+        DecimalFormat df = new DecimalFormat("0.00%");
+
+//        double a = 188.0;
+        double a = 112375.22;
+        double b = 5385;
+        double c = b / a ;
+        System.out.println(c+"===");
+        System.out.println(df.format(c+"=1=="));
+
+
+        List<IndustryVo> list = new ArrayList<>();
+
+        IndustryVo vo1 = new IndustryVo();
+        vo1.setLevel("1");
+        vo1.setIndustry_name("aaa");
+        IndustryVo vo2 = new IndustryVo();
+        vo2.setLevel("2");
+        vo2.setIndustry_name("bbb");
+        IndustryVo vo3 = new IndustryVo();
+        vo3.setLevel("3");
+        vo3.setIndustry_name("aaa");
+        IndustryVo vo4 = new IndustryVo();
+        vo4.setLevel("4");
+        vo4.setIndustry_name("aaa");
+        IndustryVo vo5 = new IndustryVo();
+        vo5.setLevel("5");
+        vo5.setIndustry_name("bbb");
+        IndustryVo vo6 = new IndustryVo();
+        vo6.setLevel("6");
+        vo6.setIndustry_name("bbb");
+        IndustryVo vo7 = new IndustryVo();
+        vo7.setLevel("7");
+        vo7.setIndustry_name("bbb");
+
+        IndustryVo vo8 = new IndustryVo();
+        vo8.setLevel("8");
+        vo8.setIndustry_name("bbb");
+
+        IndustryVo vo9 = new IndustryVo();
+        vo9.setLevel("6");
+        vo9.setIndustry_name("bbb");
+
+        IndustryVo vo10 = new IndustryVo();
+        vo10.setLevel("10");
+        vo10.setIndustry_name("bbb");
+
+        IndustryVo vo11 = new IndustryVo();
+        vo11.setLevel("11");
+        vo11.setIndustry_name("bbb");
+
+        IndustryVo vo12 = new IndustryVo();
+        vo12.setLevel("12");
+        vo12.setIndustry_name("bbb");
+
+        IndustryVo vo13 = new IndustryVo();
+        vo13.setLevel("13");
+        vo13.setIndustry_name("bbb");
+
+        IndustryVo vo14 = new IndustryVo();
+        vo14.setLevel("14");
+        vo14.setIndustry_name("bbb");
+
+        IndustryVo vo15 = new IndustryVo();
+        vo15.setLevel("15");
+        vo15.setIndustry_name("bbb");
+
+        IndustryVo vo16 = new IndustryVo();
+        vo16.setLevel("16");
+        vo16.setIndustry_name("bbb");
+
+        IndustryVo vo17 = new IndustryVo();
+        vo17.setLevel("17");
+        vo17.setIndustry_name("bbb");
+
+        IndustryVo vo18 = new IndustryVo();
+        vo18.setLevel("18");
+        vo18.setIndustry_name("bbb");
+
+        IndustryVo vo19 = new IndustryVo();
+        vo19.setLevel("19");
+        vo19.setIndustry_name("bbb");
+
+        IndustryVo vo20 = new IndustryVo();
+        vo20.setLevel("20");
+        vo20.setIndustry_name("bbb");
+
+        IndustryVo vo21 = new IndustryVo();
+        vo21.setLevel("21");
+        vo21.setIndustry_name("bbb");
+
+        IndustryVo vo22 = new IndustryVo();
+        vo22.setLevel("22");
+        vo22.setIndustry_name("bbb");
+
+        IndustryVo vo23 = new IndustryVo();
+        vo23.setLevel("0");
+        vo23.setIndustry_name("bbb");
+
+
+
+        list.add(vo1);
+        list.add(vo2);
+        list.add(vo3);
+        list.add(vo4);
+        list.add(vo5);
+        list.add(vo6);
+        list.add(vo20);
+        list.add(vo21);
+        list.add(vo22);
+        list.add(vo7);
+        list.add(vo8);
+        list.add(vo9);
+        list.add(vo10);
+        list.add(vo23);
+        list.add(vo11);
+        list.add(vo12);
+        list.add(vo18);
+        list.add(vo13);
+        list.add(vo14);
+        list.add(vo15);
+        list.add(vo16);
+        list.add(vo17);
+
+        list.add(vo19);
+
+        System.out.println("原始---->"+list);
+
+       // Collections.sort(list,Comparator.comparing(IndustryVo::getLevel));
+        list.sort((IndustryVo v1,IndustryVo v2) -> Integer.valueOf(v1.getLevel()).compareTo(Integer.valueOf(v2.getLevel())));
+        System.out.println("排序------>>>>"+list);
+/*
+
+        Map<String, Map<String, List<IndustryVo>>> studentMap = list.stream().collect(
+                Collectors.groupingBy(IndustryVo::getLevel,Collectors.groupingBy(IndustryVo::getIndustry_name)));
+
+        System.out.println("--->>>"+studentMap);
+        System.out.println("--->>>"+studentMap.values());
+        System.out.println("--->>>"+studentMap.values());
+
+*/
+
+
+
+
+
+    }
+
+
+
+    @Test
+    public void getName(){
+        int i = 4;
+        Long dplinkIndex = 4L;
+        Long startIndex = 1L;
+        Long endIndex = 100L;
+        Long adCount = 3L;
+        String name = "测试测试";
+        if(null != dplinkIndex && dplinkIndex !=0){
+            String campaignSufix = getRangeIndex(startIndex,endIndex,adCount,dplinkIndex);
+            name = name + campaignSufix;
+        }
+        System.out.println(name);
+
+        Long num = GetCampaignNum.getCampaignNameNum(2,adCount, i+1);
+        System.out.println(num);
+
+    }
+    private String getRangeIndex(Long dpLinkStartIndex,Long dpLinkEndIndex, Long campaignAdCnt, Long dpIndex) {
+        // 已创建 < 开始下标 || 已创建 > 结束下标
+        if(dpIndex<dpLinkStartIndex||dpIndex>dpLinkEndIndex){
+            //超出下标范围
+            return null;
+        }
+        Long startIndex ;
+        Long endIndex ;
+        //计算当前下标值和范围区段的余数
+        Long yzIndex = (dpIndex-dpLinkStartIndex+1)%campaignAdCnt;
+        if(yzIndex == 0){
+            startIndex = dpIndex-campaignAdCnt+1;
+            endIndex = dpIndex;
+        }else{
+            startIndex = dpIndex-yzIndex+1;
+            endIndex = dpIndex-yzIndex+campaignAdCnt;
+        }
+
+        //dp 链接使用完
+        if (endIndex > dpLinkEndIndex ){
+            endIndex = dpLinkEndIndex;
+        }
+
+        return "-("+startIndex+"/"+endIndex+")";
+    }
+
+
+    @Test
+    public void getComName(){
+        int i = 6;
+        int j = i == 0 ? i+1 : i;
+        //int j = 0;
+        //当天已创建条数
+        Long index = new Long(j);
+        // 每个组最大创建计划数
+        Long adCount = 5L;
+        //组数量
+        Long zucou = 1L;
+
+        Long zu = index / adCount;
+        Long yu = index % adCount;
+        System.out.println("商---"+zu);
+        System.out.println("余---"+yu);
+        Long count = yu != 0 ? zu.intValue()+1 : zu;
+        if (count <= zucou){
+            System.out.println("----组序号为---"+count);
+        }else {
+            System.out.println("----设置的组序号最大是+"+zucou+"-------["+count+"]"+"已经超过了最大值,不可用。");
+            System.out.println("======="+count);
+        }
+
+
+
+    }
+
+
+    @Test
+    public void getNum(){
+        DecimalFormat df1 = new DecimalFormat("0.00");
+        double d = 12;
+        BigDecimal b = new BigDecimal(d);
+        System.out.println(df1.format(b));
+
+        System.out.println(String.format("%.2f", d));
+    }
+
+
+    @Test
+    public void getTime(){
+        Long timeStart = BytedanceCreativeMatTypeEnum.getStartTimeByType("4");
+        Long timeEnd = BytedanceCreativeMatTypeEnum.getEndTimeByType("4");
+        Long now = System.currentTimeMillis();
+        String startTime = DateUtils.formatDate()+" 00:00:00";
+        String endTime = DateUtils.formatDate()+" 23:59:59";
+        if(timeStart != 0){
+            startTime = DateUtils.formatDateTime(now + timeStart * 60 * 1000L);
+        }
+        if(timeEnd != 0){
+            endTime = DateUtils.formatDateTime(now + timeEnd * 60 * 1000L);
+        }
+
+        //1-当天
+        //2-前3天
+        // 3- 上一周
+        //4-
+        System.out.println(startTime);
+        System.out.println(endTime);
+    }
+
+
+    @Test
+    public void creativeWord(){
+        String creativeWordsIds = "[]";
+        JSONArray creativeWordsArray = JSON.parseArray(creativeWordsIds);
+        if(null!=creativeWordsArray&&!creativeWordsArray.isEmpty()){
+            System.out.println(creativeWordsArray);
+        }
+
+        String a = "";
+        if(!Check.isNull(a)){
+            System.out.println("f");
+        }else {
+            System.out.println("b");
+        }
+
+/*
+        String choice = "add";
+
+        if(!Check.isNull(choice) && "choice".equalsIgnoreCase(choice)){
+            System.out.println("定向包");
+        }
+*/
+    }
+
+
+    @Test
+    public void getGroup(){
+
+        Long dplinkIndex = 4L;
+        Long startIndex = 1L;
+        Long endIndex = 2L;
+        Long adCount = 3L;
+        String name = "测试测试";
+
+
+
+    }
+
+
+    @Test
+    public void PerformOp(){
+        boolean a = true;
+    if (!!a){
+        System.out.println(a);
+    }else {
+        System.out.println(a);
+    }
+
+    }
+
+
+
+    @Test
+    public void getString() throws Exception{
+        String a = "20210814-促活-站内-RTA-sf_jrtt_huichuangch_ptb_297571-ocpm-[这是这是这是这这是这是这是这是这是这是这是这是这这是这是这是这是这是]-0728";
+        //获取[] 中的内容 --素材名称
+        String rep = a.substring(a.indexOf("["),a.indexOf("]")+1);
+        //String c = "这是这是这是这这是这是这是这是这是这是这是这是这这是这是这是这是这是";
+        int astr = StringUtils.length(a.replaceAll("[\\[\\]]", ""));
+
+        int cstr = StringUtils.length(rep.replaceAll("[\\[\\]]", ""));
+
+        System.out.println(cstr);
+
+        int shang = astr / 2;
+        int yu = astr % 2;
+
+        int totalLength = shang + yu;
+        System.out.println(totalLength);
+
+        if (totalLength > 47){
+            int substrlength = (totalLength - 47) * 2 ;
+            String subc = StringUtils.subStr50(rep,cstr - substrlength);
+
+
+            String sub = a.replace(rep, subc);
+            System.out.println(sub);
+            System.out.println(StringUtils.length(sub));
+
+        }else {
+           String name =  a.replaceAll("[\\[\\]]", "");
+            System.out.println(name);
+        }
+
+    }
+
+
+    @Test
+    public void getAdName(){
+        //String a = "20210814-促活-站内-RTA-sf_jrtt_huichuangch_ptb_297571-ocpm-{{素材名称}}-0728";
+        //String a = "20210814-促活-站内-RTA-sf_jrtt_huichuangch_ptb_297571-ocpm--0728";
+        String a = "xxxxxcccccxxxxxcccccxxxxx我cccccxxxxxccccc-{{素材名}}-";
+        a = a.replace("{{素材名称}}","["+"我是我是我是我是我是我是我是我是我是"+"]");
+
+        //System.out.println(StringUtils.length(a));
+        System.out.println(StringUtils.length(a.replaceAll("[\\[\\]]", "")));
+        System.out.println(a);
+        String name = StringUtils.adNameSubMaterial(a);
+        System.out.println(name);
+        System.out.println(StringUtils.length(name));
+    }
+
+
+    @Autowired
+    private IMaterialInfoService materialInfoService;
+
+
+
+
+    @Test
+    public void getCreativeTimeTest() {
+        Long timeStart = BytedanceCreativeMatTypeEnum.getStartTimeByType("4");
+        Long timeEnd = BytedanceCreativeMatTypeEnum.getEndTimeByType("4");
+        Long now = System.currentTimeMillis();
+
+        long zero = now/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();//今天零点零分零秒的毫秒数
+        long twelve = zero+24*60*60*1000-1;//今天23点59分59秒的毫秒数
+        String startTime = DateUtils.formatDateTime(zero);
+        String endTime = DateUtils.formatDateTime(twelve);
+        if(timeStart != 0){
+            startTime = DateUtils.formatDateTime(zero + timeStart * 60 * 1000L);
+        }
+        if(timeEnd != 0){
+            endTime = DateUtils.formatDateTime(twelve + timeEnd * 60 * 1000L);
+        }
+        System.out.println(startTime);
+        System.out.println(endTime);
+
+
+
+    }
+
+
 }
+
+

+ 6 - 2
jeecg-boot-module-system/src/main/resources/application-test.yml

@@ -134,6 +134,10 @@ spring:
           url: jdbc:mysql://139.186.165.84:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: hcst
           password: hcst@2020
+#          url: jdbc:mysql://139.186.27.96:3390/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+#          username: data
+#          password: hcst@2021
+
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:
@@ -152,8 +156,8 @@ spring:
          max-wait: -1ms  #最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
          min-idle: 0     #最小等待连接中的数量,设 0 为没有限制
        shutdown-timeout: 100ms
-     password: hcst@2020
-     #password: ''
+     #password: hcst@2020
+     password: ''
      port: 6379
 #mybatis plus 设置
 mybatis-plus: