Browse Source

Merge remote-tracking branch 'origin/test' into test

huangxuechao 4 năm trước cách đây
mục cha
commit
2c3a574073

+ 6 - 3
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/ByteDanceGeneralCopywriterMapper.java

@@ -1,12 +1,13 @@
 package org.jeecg.modules.bytedance.advertise.mapper;
 
-import java.util.List;
-import java.util.Map;
-
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.jeecg.modules.bytedance.advertise.entity.ByteDanceCreativeWordPackage;
 import org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 通用文案库
  * @author jeecg-boot
@@ -17,4 +18,6 @@ public interface ByteDanceGeneralCopywriterMapper extends BaseMapper<ByteDanceGe
     List<Map<String,Object>> selectGeneralCopywriterReport(List<String> accountIds, String keyWord, String startTime, String endTime);
 
     ByteDanceCreativeWordPackage selectCreativeWordPackageByName(String name);
+
+    ByteDanceGeneralCopywriter getRandOne(@Param(value = "accountId") Long accountId);
 }

+ 4 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/ByteDanceGeneralCopywriterMapper.xml

@@ -39,4 +39,8 @@
     <select id="selectCreativeWordPackageByName" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceCreativeWordPackage">
         select * from ctop_bytedance_creative_word_package where name = #{name}
     </select>
+    <select id="getRandOne"
+            resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceGeneralCopywriter">
+        select * from ctop_bytedance_general_copywriter where account_id = #{accountId} order by rand() limit 1
+    </select>
 </mapper>

+ 11 - 6
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/AiBytedanceAdvertiserStrategyServiceImpl.java

@@ -152,13 +152,13 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 adDplinkInfoService.save(adDplinkInfo);
                 //3:创建创意
                 JSONObject creativeParams = getCreativeParams(strategy,adId,video,token);
-                log.info("创意创建参数:{}",creativeParams);
+                log.info("账户id:{};创意创建参数:{}",strategy.getAccountId(),creativeParams);
                 JSONObject creativeObject =  marketingService.creativeCreate(token,adId,creativeParams);
                 if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
                     String message = creativeObject.getString("message");
                     Integer code = creativeObject.getInteger("code");
                     //创建创意失败
-                    log.info("创意创建失败:code==>{};message==>{}",code,message);
+                    log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
                     continue;
                 }
                 BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
@@ -220,6 +220,8 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 if(null!=creativeObject.getInteger("code")&&creativeObject.getInteger("code")!=0){
                     String message = creativeObject.getString("message");
                     Integer code = creativeObject.getInteger("code");
+                    //创建创意失败
+                    log.info("账户id:{};创意创建失败:code==>{};message==>{}",strategy.getAccountId(),code,message);
                     continue;
                 }
                 BytedanceAiVideoCreativeLog creativeLog = new BytedanceAiVideoCreativeLog(strategy,adId,campaignId,video);
@@ -319,9 +321,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                 if(titleArray.size() >= 10){
                     break;
                 }
-                QueryWrapper<ByteDanceGeneralCopywriter> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("account_id",strategy.getAccountId());
-                ByteDanceGeneralCopywriter byteDanceGeneralCopywriter = byteDanceGeneralCopywriterMapper.selectOne(queryWrapper);
+                ByteDanceGeneralCopywriter byteDanceGeneralCopywriter = byteDanceGeneralCopywriterMapper.getRandOne(strategy.getAccountId());
                 if(!Check.isNull(byteDanceGeneralCopywriter)){
                     JSONObject titleObject = new JSONObject();
                     titleObject.put("title",byteDanceGeneralCopywriter.getTextCopywriter());
@@ -506,6 +506,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
 
     private Long createAdInfo(CtopOauthToken token, AiBytedanceAdvertiserStrategy strategy, JSONObject adParams) {
         Result result = marketingService.createAdvertiserPlan(token,adParams,strategy);
+        System.out.println(result);
         if(result.getCode()!=0){
             //TODO 计划创建异常 后续需要加日志
             return null;
@@ -837,6 +838,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
         if(!Check.isNull(strategy.getAdAutoExtendEnabled())){
             params.put("auto_extend_enabled",strategy.getAdAutoExtendEnabled());
         }
+        //可放开定向
         if(!Check.isNull(strategy.getAdAutoExtendTargets())){
             String[] autoExtendTargets = strategy.getAdAutoExtendTargets().split(",");
             if(autoExtendTargets.length>0){
@@ -908,6 +910,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
             String date = DateUtils.formatDate(new Date(),"yyyyMMdd");
             adName = adName.replace("{{日期}}",date);
         }
+        if(adName.contains("{{创意方式}}")){
+            adName = adName.replace("{{创意方式}}","程序化");
+        }
         if(adName.contains("{{dp链接标识}}")&&null!=dplinkCode){
             adName = adName.replace("{{dp链接标识}}",dplinkCode);
         }
@@ -1386,7 +1391,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
     @Override
     public void customCreativeSupplement(AiBytedanceAdvertiserStrategy strategy, Integer hour,String openUrl) {
         Long customUnitCnt = strategy.getCampaignAdCnt()*strategy.getCampaignCnt();
-        Long unitNum = customUnitCnt * hour / 15;
+        Long unitNum = customUnitCnt * hour / 19;
         log.info("{}当前时间内需要创建计划总数:{}", strategy.getAccountId(), unitNum);
         //查询当前账户创建自定义类型计划数量
         int unitCreateCnt = planService.queryToDayBuiltCount(strategy.getAccountId());

+ 0 - 1
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/mapper/xml/UserAllocationMapper.xml

@@ -87,7 +87,6 @@
         SELECT
             allocation.account_id
         FROM
-
             ctop_user_allocation allocation
             where 1 =1 and allocation.project_id in (select DISTINCT project_id from ctop_project_member where user_id = #{userId})
     </select>

+ 24 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/common/utils/StringUtils.java

@@ -4,6 +4,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -174,6 +175,29 @@ public class StringUtils {
         return dest;
     }
 
+    /**
+     * 使用正则表达式提取中括号中的内容
+     * @param msg
+     * @return
+     */
+    public static List<String> extractMessageByRegular(String msg){
+
+        List<String> list=new ArrayList<String>();
+        Pattern p = Pattern.compile("\\{([^}]*)\\}");
+        Matcher m = p.matcher(msg);
+        while(m.find()){
+            list.add(m.group().substring(1, m.group().length()-1));
+        }
+        return list;
+    }
+
+    public static void main(String[] args) {
+        String msg = "PerformanceManager{第1个中括号}Product{第2个中括号}<{第3个中括号}79~";
+        List<String> list = extractMessageByRegular(msg);
+        for (int i = 0; i < list.size(); i++) {
+            System.out.println(i+"-->"+list.get(i));
+        }
+    }
 
 
     /**

+ 30 - 17
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/service/impl/BytedanceAdvertiserHourlyReportServiceImpl.java

@@ -73,6 +73,8 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         DecimalFormat df = new DecimalFormat("0.00%");
         Map<String,Object> resultMap = new HashMap<>();
         double compare = 0;
+        double lastCost = 0;
+        double nowCost = 0;
         List<ReportCostVo> nowCostList = new ArrayList<>();
         List<ReportCostVo> lastCostList = new ArrayList<>();
 
@@ -88,34 +90,46 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
             // 账户 日报 阶段 数据
             nowCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,startTime,endTime);
             lastCostList = bytedanceAdvertiserHourlyReportMapper.selectPlanCostInfoCount(accountId,null,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
+            //当前阶段 总花费
+            nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
+            resultMap.put("nowCost", String.format("%.2f", nowCost));
+            //上阶段花费
+            lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
+            resultMap.put("lastCost", String.format("%.2f", lastCost));
+            //环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
+            compare = (nowCost - lastCost) / lastCost;
+            //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
+            resultMap.put("compare", new Double(lastCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
+
         }else{
             // 账户 当前时间段数据
             nowCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,startTime,endTime);
+            //上阶段数据
+            lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),null);
+            //计算环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
+            //获取 同时段 的花费
             ReportCostVo statHourVo = new ReportCostVo();
             if (nowCostList.size() > 0){
                 statHourVo = nowCostList.get(nowCostList.size()-1);
             }
-            //上阶段数据
-            lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),statHourVo.getTime());
+            List<ReportCostVo> compareCost = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStageLast(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),statHourVo.getTime());
+            double lastCompareCost = compareCost.stream().mapToDouble(ReportCostVo::getCost).sum();
+            //当前阶段 总花费
+            nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
+            resultMap.put("nowCost", String.format("%.2f", nowCost));
+            //上阶段花费
+            lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
+            resultMap.put("lastCost", String.format("%.2f", lastCost));
+            //环比 =(当前花费 - 上阶段 同时段 花费 )/ 上阶段花费
+            compare = (nowCost - lastCompareCost) / lastCompareCost;
+            //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
+            resultMap.put("compare", new Double(lastCompareCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
         }
 
         //更新时间
         List<ReportCostVo> updTimeList = nowCostList.stream().sorted(Comparator.comparing(ReportCostVo::getCreateTime)).collect(Collectors.toList());
         resultMap.put("updTime",Check.isNull(updTimeList) ? new Date() : updTimeList.get(0).getCreateTime());
 
-        //当前阶段 总花费
-        double nowCost = nowCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
-        resultMap.put("nowCost", String.format("%.2f", nowCost));
-
-        //上阶段花费
-        double lastCost = lastCostList.stream().mapToDouble(ReportCostVo::getCost).sum();
-        resultMap.put("lastCost", String.format("%.2f", lastCost));
-
-        //环比 =(当前花费 - 上阶段花费 )/ 上阶段花费
-        compare = (nowCost - lastCost) / lastCost;
-        //resultMap.put("compare", Double.isNaN(compare) ? "0" : df.format(compare));
-        resultMap.put("compare", new Double(lastCost).intValue() == 0 ? "0" : String.format("%.2f", compare*100));
-
         //花费占比 = 花费 / 账户预算
         //获取账户预算
         QueryWrapper<AiBytedanceAdvertiserStrategy> strategyQueryWrapper = new QueryWrapper<>();
@@ -148,10 +162,8 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
             lastMap.put("costList",Arrays.asList());
         }
 
-
         resultMap.put("nowMap", nowMap);
         resultMap.put("lastMap", lastMap);
-
         return Result.successMsg("成功。",resultMap);
     }
 
@@ -225,6 +237,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         if (!Check.isNull(reduceList)){
             reduceList.forEach(reduce ->{
                 ReportCostVo vo = new ReportCostVo();
+                vo.setStatDatetime(startTime);
                 vo.setTime(reduce);
                 vo.setConver("0");//转化成本
                 vo.setConvertNum(0);//转化数