Explorar el Código

Merge branch 'test'

songyh hace 4 años
padre
commit
b6b12c4eed

+ 2 - 2
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/dockapi/MarketingServiceImpl.java

@@ -320,12 +320,12 @@ public class MarketingServiceImpl implements MarketingService{
     public  Result createAdvertiserPlan(CtopOauthToken token, JSONObject params, AiBytedanceAdvertiserStrategy strategy) {
     public  Result createAdvertiserPlan(CtopOauthToken token, JSONObject params, AiBytedanceAdvertiserStrategy strategy) {
         JSONObject jsonObject = HttpUtils.bytedancePostRequest(token.getAccessToken(),
         JSONObject jsonObject = HttpUtils.bytedancePostRequest(token.getAccessToken(),
                 urlPath + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_create"), params);
                 urlPath + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_ad_create"), params);
+        log.info("广告计划输出返回信息---->>>>>",jsonObject);
         Integer code = jsonObject.getInteger("code");
         Integer code = jsonObject.getInteger("code");
         if (null ==  code || !code.equals(0)) {
         if (null ==  code || !code.equals(0)) {
             log.error("广告计划创建失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
             log.error("广告计划创建失败==》accountId:{},message:{}", token.getAccountId(), jsonObject.getString("message"));
-            Result.error(jsonObject.getString("message"));
+            return Result.error(jsonObject.getString("message"));
         }
         }
-        System.out.println(jsonObject);
         //strategy.setId(jsonObject.getJSONObject("data").getLong("ad_id"));
         //strategy.setId(jsonObject.getJSONObject("data").getLong("ad_id"));
         return Result.successMsg("广告计划创建成功",jsonObject.getJSONObject("data").getLong("ad_id"));
         return Result.successMsg("广告计划创建成功",jsonObject.getJSONObject("data").getLong("ad_id"));
     }
     }

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

@@ -26,6 +26,7 @@ import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * @Description: 广告主小时级别报表信息
  * @Description: 广告主小时级别报表信息
@@ -39,6 +40,10 @@ import java.util.*;
 public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<BytedanceAdvertiserHourlyReportMapper, BytedanceAdvertiserHourlyReport> implements IBytedanceAdvertiserHourlyReportService {
 public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<BytedanceAdvertiserHourlyReportMapper, BytedanceAdvertiserHourlyReport> implements IBytedanceAdvertiserHourlyReportService {
 
 
 
 
+    //时段数组
+    private final static List<String> TIMES = Arrays.asList("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23");
+
+
     @Resource
     @Resource
     private BytedanceAdvertiserHourlyReportMapper bytedanceAdvertiserHourlyReportMapper;
     private BytedanceAdvertiserHourlyReportMapper bytedanceAdvertiserHourlyReportMapper;
 
 
@@ -114,9 +119,9 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
           lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
           lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
         }
         }
         //当前阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
         //当前阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
-        nowMap.put("costList", getCostList(nowCostList));
+        nowMap.put("costList", getCostList(nowCostList,startTime,endTime,lastTimeMap.get("daysBetween")));
         //上个阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
         //上个阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
-        lastMap.put("costList", getCostList(lastCostList));
+        lastMap.put("costList", getCostList(lastCostList,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),lastTimeMap.get("daysBetween")));
 
 
         resultMap.put("nowMap", nowMap);
         resultMap.put("nowMap", nowMap);
         resultMap.put("lastMap", lastMap);
         resultMap.put("lastMap", lastMap);
@@ -135,41 +140,73 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         double cost = list.stream().mapToDouble(ReportCostVo::getCost).sum();
         double cost = list.stream().mapToDouble(ReportCostVo::getCost).sum();
         //转化成本 = 总花费 / 转化数
         //转化成本 = 总花费 / 转化数
         int converNum = list.stream().mapToInt(ReportCostVo::getConvertNum).sum();
         int converNum = list.stream().mapToInt(ReportCostVo::getConvertNum).sum();
-        double conver = cost / converNum;
-        map.put("conver", String.format("%.2f", conver));
+        double conver = cost / new Double(converNum);
+        map.put("conver",Double.isNaN(conver) ? "0" : String.format("%.2f", conver));
         map.put("converNum", converNum);
         map.put("converNum", converNum);
         //转化率 = 转化数 / 点击数 * 100
         //转化率 = 转化数 / 点击数 * 100
         int clickNum = list.stream().mapToInt(ReportCostVo::getClick).sum();
         int clickNum = list.stream().mapToInt(ReportCostVo::getClick).sum();
         double click = Double.valueOf(converNum) /  Double.valueOf(clickNum) * 100;
         double click = Double.valueOf(converNum) /  Double.valueOf(clickNum) * 100;
-        map.put("converRate", String.format("%.2f", click));
+        map.put("converRate", Double.isNaN(click) ? "0" : String.format("%.2f", click));
         // 平均千次展显费用 = 总花费/展示数 * 1000
         // 平均千次展显费用 = 总花费/展示数 * 1000
         int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
         int showNum = list.stream().mapToInt(ReportCostVo::getShowNum).sum();
         double show = (cost / showNum) * 1000 ;
         double show = (cost / showNum) * 1000 ;
-        map.put("averageShow", String.format("%.2f", show));
+        map.put("averageShow", Double.isNaN(show) ? "0" : String.format("%.2f", show));
         return map;
         return map;
     }
     }
 
 
     //获取 数据 (时间段)
     //获取 数据 (时间段)
-    public List<ReportCostVo> getCostList(List<ReportCostVo> list){
+    public List<ReportCostVo> getCostList(List<ReportCostVo> list,String startTime,String endTime,String daysBetween){
         list.forEach(reportCostVo -> {
         list.forEach(reportCostVo -> {
             //花费
             //花费
             double cost = reportCostVo.getCost();
             double cost = reportCostVo.getCost();
             //转化成本 = 总花费 / 转化数
             //转化成本 = 总花费 / 转化数
             int converNum = reportCostVo.getConvertNum();
             int converNum = reportCostVo.getConvertNum();
             double conver = cost / converNum;
             double conver = cost / converNum;
-            reportCostVo.setConver(String.format("%.2f", conver));
+            reportCostVo.setConver(converNum == 0 ? "0" : String.format("%.2f", conver));
             reportCostVo.setConvertNum(converNum);
             reportCostVo.setConvertNum(converNum);
 
 
             //转化率 = 转化数 / 点击数 * 100
             //转化率 = 转化数 / 点击数 * 100
             int clickNum = reportCostVo.getClick();
             int clickNum = reportCostVo.getClick();
             double click = Double.valueOf(converNum) /  Double.valueOf(clickNum) * 100;
             double click = Double.valueOf(converNum) /  Double.valueOf(clickNum) * 100;
-            reportCostVo.setConverRate(String.format("%.2f", click));
+            reportCostVo.setConverRate(clickNum == 0 ? "0" : String.format("%.2f", click));
 
 
             // 平均千次展显费用 = 总花费/展示数 * 1000
             // 平均千次展显费用 = 总花费/展示数 * 1000
             int showNum = reportCostVo.getShowNum();
             int showNum = reportCostVo.getShowNum();
             double show = (cost / showNum) * 1000 ;
             double show = (cost / showNum) * 1000 ;
-            reportCostVo.setAverageShow(String.format("%.2f", show));
+            reportCostVo.setAverageShow( showNum == 0 ? "0" : String.format("%.2f", show));
         });
         });
+
+        /**
+         * 时间间隔为0 则表示获取当天数据 0-23时段
+         * 不为0 则表示 获取 开始-截至 时间 阶段数据
+         */
+        List<String> reduceList = new ArrayList<>();
+        if ("0".equals(daysBetween)){
+            //返回数据中 time 的集合
+            List<String> voTimes = list.stream().map(ReportCostVo::getTime).collect(Collectors.toList());
+            // 获取0-23时段 和 已有时段的 差集 (times - voTimes)
+            reduceList = TIMES.stream().filter(item -> !voTimes.contains(item)).collect(Collectors.toList());
+        }else {
+            // 获取两个日期之间 所有的 时间 年-月-日
+            List<String> betweenDaysList = TimeStartAndEndUtil.getAllDatesOfTwoTimes(startTime,endTime);
+            ////返回数据中 time 的集合
+            List<String> dayTimes = list.stream().map(ReportCostVo::getTime).collect(Collectors.toList());
+            //差集
+            reduceList = betweenDaysList.stream().filter(item -> !dayTimes.contains(item)).collect(Collectors.toList());
+        }
+        //补充差集时段数据
+        if (!Check.isNull(reduceList)){
+            reduceList.forEach(reduce ->{
+                ReportCostVo vo = new ReportCostVo();
+                vo.setTime(reduce);
+                vo.setConver("0");//转化成本
+                vo.setConvertNum(0);//转化数
+                vo.setConverRate("0");//转化率
+                vo.setAverageShow("0");//平均前次展现费用
+                list.add(vo);
+            });
+        }
+         Collections.sort(list,Comparator.comparing(ReportCostVo::getTime));
         return list;
         return list;
     }
     }
 
 

+ 31 - 6
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/utils/TimeStartAndEndUtil.java

@@ -2,10 +2,7 @@ package org.jeecg.modules.bytedance.report.utils;
 
 
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 
 /**
 /**
  * Administrator
  * Administrator
@@ -56,11 +53,39 @@ public class TimeStartAndEndUtil {
         return nowTime;
         return nowTime;
     }
     }
 
 
+    /**
+     * 获取 两个日期之间的所有 日期
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<String> getAllDatesOfTwoTimes(String startDate, String endDate) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        List<String> dateList = new ArrayList<String>();
+        try{
+            Date dateOne = sdf.parse(startDate);
+            Date dateTwo = sdf.parse(endDate);
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(dateOne);
+
+            dateList.add(startDate);
+            while(calendar.getTime().before(dateTwo)){ //倒序时间,顺序after改before其他相应的改动。
+                calendar.add(Calendar.DAY_OF_MONTH, 1);
+                dateList.add(sdf.format(calendar.getTime()));
+            }
+        } catch(Exception e){
+            e.printStackTrace();
+        }
+        return dateList;
+    }
+
 
 
 
 
     public static void main(String[] args) throws Exception {
     public static void main(String[] args) throws Exception {
-        Map<String,String> map = TimeStartAndEndUtil.getStartEndTime("2020-05-15","2020-05-18");
-        System.out.println(map);
+//        Map<String,String> map = TimeStartAndEndUtil.getStartEndTime("2020-05-15","2020-05-18");
+        List<String> list = TimeStartAndEndUtil.getAllDatesOfTwoTimes("2021-05-19","2021-05-27");
+        System.out.println(list);
     }
     }
 
 
 
 

+ 34 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/bytedance/advertise/controller/BytedanceReportController.java

@@ -164,6 +164,40 @@ public class BytedanceReportController {
 	}
 	}
 
 
 
 
+	@ApiOperation(value="投放数据-获取计划已有定向包", notes="投放数据-获取计划已有定向包")
+	@GetMapping(value = "/getADAudiencePackageId")
+	public Result getADAudiencePackageId(@RequestParam("accountId") String accountId,
+										  @RequestParam("adId") String adId) {
+		try {
+			//1 获取token
+			CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
+			PlanSearchVo planSearchVo = new PlanSearchVo();
+			String[] ids = adId.split(",");
+			planSearchVo.setIds(ids);
+			//2 获取广告计划
+			Result result = marketingService.getPlanList(token,planSearchVo,1,1000);
+			if (!result.isSuccess()){
+				return Result.errorMsg(result.getMessage());
+			}
+			JSONObject jsonObject =JSONObject.parseObject(result.getResult().toString());
+			JSONArray array = jsonObject.getJSONArray("list");
+			List<Map<String,Object>> dataList = JSONArray.parseObject(array.toJSONString(),List.class);
+			Map<String,String> resultMap = new HashMap<>();
+			for (Map<String, Object> map : dataList) {
+				String packageId = Check.isNull(map.get("audience_package_id")) ? "" : map.get("audience_package_id") .toString();
+				resultMap.put("packageId",packageId);
+			}
+			return Result.successMsg("获取计划定向包id", resultMap);
+		}catch (Exception e){
+			log.error("投放数据-获取计划已有定向包异常",e);
+			return Result.error("请求失败,请联系开发人员!");
+		}
+	}
+
+
+
+
+
 	@ApiOperation(value="投放数据-更新计划定向包", notes="投放数据-更新计划定向包")
 	@ApiOperation(value="投放数据-更新计划定向包", notes="投放数据-更新计划定向包")
 	@GetMapping(value = "/updateADAudiencePackage")
 	@GetMapping(value = "/updateADAudiencePackage")
 	public Result updateADAudiencePackage(@RequestParam("accountId") String accountId,
 	public Result updateADAudiencePackage(@RequestParam("accountId") String accountId,