Browse Source

Merge remote-tracking branch 'origin/V1.1.5' into V1.1.5

syh 4 năm trước cách đây
mục cha
commit
d7efb01d85

+ 6 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/EtlKuaishouAudienceAccountDailyMapper.java

@@ -20,9 +20,13 @@ public interface EtlKuaishouAudienceAccountDailyMapper extends BaseMapper<EtlKua
 
     List<JSONObject> queryAudienceTypeInfo(@Param("value") String value, @Param("type") String type, @Param("accountId") Long accountId, @Param("audienceType") String audienceType, @Param("parType") String parType);
 
-    List<JSONObject> queryEveryDayInfo(@Param("value") String value, @Param("type") String type, @Param("accountId") Long accountId, @Param("audienceType") String audienceType, @Param("parType") String parType);
+    List<JSONObject> queryEveryDayInfo(@Param("value") String value, @Param("type") String type, @Param("accountId") Long accountId, @Param("audienceType") String audienceType, @Param("parType") String parType,@Param("day") String day);
 
     List<JSONObject> getSceneInfo(@Param("value") String value, @Param("accountId") Long accountId, @Param("parType") String parType);
 
-    List<JSONObject> getSceneEveryDayInfo(@Param("value") String value, @Param("accountId") Long accountId, @Param("parType") String parType);
+    List<JSONObject> getSceneEveryDayInfo(@Param("value") String value, @Param("accountId") Long accountId, @Param("parType") String parType,@Param("day") String day);
+
+    List<String> getTypeList(@Param("type") String type,@Param("audienceType") String audienceType);
+
+    List<String> getSceneTypeList();
 }

+ 20 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/EtlKuaishouAudienceAccountDailyMapper.xml

@@ -92,12 +92,11 @@
         </if>
         ${type} as 'type'
         FROM ctop_etl_kuaishou_audience_account_daily
-        where stat_date &gt;= DATE_FORMAT(date_sub(now(), interval 8 day), '%Y-%m-%d')
-        AND stat_date &lt;= DATE_FORMAT(date_sub(now(), interval 2 day), '%Y-%m-%d')
+        where stat_date = #{day}
         AND audience_type = #{audienceType}
         AND account_id = #{accountId}
         group by stat_date,${type}
-        order by stat_date
+        order by stat_date,${type}
     </select>
 
     <select id="getSceneEveryDayInfo" resultType="com.alibaba.fastjson.JSONObject">
@@ -126,11 +125,25 @@
         WHEN ad_scene = '' THEN '全部'
         ELSE ad_scene END as 'type'
         FROM ctop_kuaishou_report_daily_account
-        where stat_date &gt;= DATE_FORMAT(date_sub(now(), interval 8 day), '%Y-%m-%d')
-        AND stat_date &lt;= DATE_FORMAT(date_sub(now(), interval 2 day), '%Y-%m-%d')
+        where stat_date = #{day}
         AND account_id = #{accountId}
         group by stat_date,ad_scene
-        order by stat_date
+        order by stat_date,ad_scene
+    </select>
+
+    <select id="getSceneTypeList" resultType="java.lang.String">
+        SELECT DISTINCT IFNULL(ad_scene, '全部')
+        FROM ctop_kuaishou_report_daily_account
+        WHERE LENGTH(trim(ad_scene))>0
+        ORDER BY ad_scene
+    </select>
+
+    <select id="getTypeList" resultType="java.lang.String">
+        SELECT ${type} as 'type'
+        FROM ctop_etl_kuaishou_audience_account_daily
+        where audience_type = #{audienceType}
+        group by ${type}
+        order by ${type}
     </select>
 
     <select id="getSceneInfo" resultType="com.alibaba.fastjson.JSONObject">
@@ -162,5 +175,6 @@
         AND stat_date &lt;= DATE_FORMAT(date_sub(now(), interval 2 day), '%Y-%m-%d')
         AND account_id = #{accountId}
         group by ad_scene
+        order by ad_scene
     </select>
 </mapper>

+ 66 - 12
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/EtlKuaishouAudienceAccountDailyServiceImpl.java

@@ -9,9 +9,12 @@ import cn.com.ctop.kuaishou.modules.report.service.IEtlKuaishouAudienceAccountDa
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -52,13 +55,24 @@ public class EtlKuaishouAudienceAccountDailyServiceImpl extends ServiceImpl<EtlK
         String audienceType = "gender";
         String type = "gender";
         List<JSONObject> list = null;
+        List<String> typeList = accountDailyMapper.getTypeList(type, audienceType);
         if ("pie".equals(dataType)) {
             list = accountDailyMapper.queryAudienceTypeInfo(value, type, accountId, audienceType, parType);
+            if (Check.isNull(list)) {
+                return Result.ok("未查询到数据");
+            }
+            completeData(list, typeList);
         } else if ("line".equals(dataType)) {
-            list = accountDailyMapper.queryEveryDayInfo(value, type, accountId, audienceType, parType);
-        }
-        if (Check.isNull(list)) {
-            return Result.ok("未查询到数据");
+            String startTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 8);
+            String endTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 2);
+            List<String> dayList = DateUtils.getDays(startTime, endTime);
+            JSONObject data = new JSONObject();
+            for (String day : dayList) {
+                list = accountDailyMapper.queryEveryDayInfo(value, type, accountId, audienceType, parType, day);
+                completeData(list, typeList);
+                data.put(day, list);
+            }
+            return Result.ok(data);
         }
         return Result.ok(list);
     }
@@ -79,13 +93,24 @@ public class EtlKuaishouAudienceAccountDailyServiceImpl extends ServiceImpl<EtlK
         String audienceType = "ageSegment";
         String type = "age_segment";
         List<JSONObject> list = null;
+        List<String> typeList = accountDailyMapper.getTypeList(type, audienceType);
         if ("pie".equals(dataType)) {
             list = accountDailyMapper.queryAudienceTypeInfo(value, type, accountId, audienceType, parType);
+            if (Check.isNull(list)) {
+                return Result.ok("未查询到数据");
+            }
+            completeData(list, typeList);
         } else if ("line".equals(dataType)) {
-            list = accountDailyMapper.queryEveryDayInfo(value, type, accountId, audienceType, parType);
-        }
-        if (Check.isNull(list)) {
-            return Result.ok("未查询到数据");
+            String startTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 8);
+            String endTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 2);
+            List<String> dayList = DateUtils.getDays(startTime, endTime);
+            JSONObject data = new JSONObject();
+            for (String day : dayList) {
+                list = accountDailyMapper.queryEveryDayInfo(value, type, accountId, audienceType, parType, day);
+                completeData(list, typeList);
+                data.put(day, list);
+            }
+            return Result.ok(data);
         }
         return Result.ok(list);
     }
@@ -104,15 +129,44 @@ public class EtlKuaishouAudienceAccountDailyServiceImpl extends ServiceImpl<EtlK
             parType = "alone";
         }
         List<JSONObject> list = null;
+        List<String> typeList = accountDailyMapper.getSceneTypeList();
         if ("pie".equals(dataType)) {
             list = accountDailyMapper.getSceneInfo(value, accountId, parType);
+            if (Check.isNull(list)) {
+                return Result.ok("未查询到数据");
+            }
+            completeData(list, typeList);
         } else if ("line".equals(dataType)) {
-            list = accountDailyMapper.getSceneEveryDayInfo(value, accountId, parType);
-        }
-        if (Check.isNull(list)) {
-            return Result.ok("未查询到数据");
+            String startTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 8);
+            String endTime = DateUtils.getLastDay(DateUtils.formatDate(new Date()), 2);
+            List<String> dayList = DateUtils.getDays(startTime, endTime);
+            JSONObject data = new JSONObject();
+            for (String day : dayList) {
+                list = accountDailyMapper.getSceneEveryDayInfo(value, accountId, parType, day);
+                completeData(list, typeList);
+                data.put(day, list);
+            }
+            return Result.ok(data);
         }
         return Result.ok(list);
     }
 
+    /**
+     * 补全数据
+     */
+    private void completeData(List<JSONObject> list, List<String> typeList) {
+        List<String> newDayList = new ArrayList<>();
+        for (JSONObject data : list) {
+            newDayList.add(data.getString("type"));
+        }
+        for (String type : typeList) {
+            if (!newDayList.contains(type)) {
+                JSONObject obj = new JSONObject();
+                obj.put("type", type);
+                obj.put("value", 0);
+                list.add(obj);
+            }
+        }
+    }
+
 }