Pārlūkot izejas kodu

投放数据-时间阶段数据没有则补0

yangzian 4 gadi atpakaļ
vecāks
revīzija
5fb516911b

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

@@ -119,9 +119,9 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
           lastCostList = bytedanceAdvertiserHourlyReportMapper.getReportCostInfoStage(accountId,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"));
         }
         //当前阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
-        nowMap.put("costList", getCostList(nowCostList,lastTimeMap.get("daysBetween")));
+        nowMap.put("costList", getCostList(nowCostList,startTime,endTime,lastTimeMap.get("daysBetween")));
         //上个阶段 每个时间 的 转化成本;转化数;转化率;平均千次展现费用。数据展示
-        lastMap.put("costList", getCostList(lastCostList,lastTimeMap.get("daysBetween")));
+        lastMap.put("costList", getCostList(lastCostList,lastTimeMap.get("lastTimeStart"),lastTimeMap.get("lastTimeEnd"),lastTimeMap.get("daysBetween")));
 
         resultMap.put("nowMap", nowMap);
         resultMap.put("lastMap", lastMap);
@@ -140,7 +140,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
         double cost = list.stream().mapToDouble(ReportCostVo::getCost).sum();
         //转化成本 = 总花费 / 转化数
         int converNum = list.stream().mapToInt(ReportCostVo::getConvertNum).sum();
-        double conver = cost / converNum;
+        double conver = cost / new Double(converNum);
         map.put("conver",Double.isNaN(conver) ? "0" : String.format("%.2f", conver));
         map.put("converNum", converNum);
         //转化率 = 转化数 / 点击数 * 100
@@ -155,7 +155,7 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
     }
 
     //获取 数据 (时间段)
-    public List<ReportCostVo> getCostList(List<ReportCostVo> list,String daysBetween){
+    public List<ReportCostVo> getCostList(List<ReportCostVo> list,String startTime,String endTime,String daysBetween){
         list.forEach(reportCostVo -> {
             //花费
             double cost = reportCostVo.getCost();
@@ -178,21 +178,35 @@ public class BytedanceAdvertiserHourlyReportServiceImpl extends ServiceImpl<Byte
 
         /**
          * 时间间隔为0 则表示获取当天数据 0-23时段
+         * 不为0 则表示 获取 开始-截至 时间 阶段数据
          */
-        if (daysBetween.equals("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)
-            List<String> reduceList = TIMES.stream().filter(item -> !voTimes.contains(item)).collect(Collectors.toList());
-            //补充差集时段数据
-            if (!Check.isNull(reduceList)){
-                reduceList.forEach(reduce ->{
-                    ReportCostVo vo = new ReportCostVo();
-                    vo.setTime(reduce);
-                    list.add(vo);
-                });
-            }
+            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;
     }
 

+ 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.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Administrator
@@ -56,11 +53,39 @@ public class TimeStartAndEndUtil {
         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 {
-        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="投放数据-更新计划定向包")
 	@GetMapping(value = "/updateADAudiencePackage")
 	public Result updateADAudiencePackage(@RequestParam("accountId") String accountId,