浏览代码

修改获取人群报表组数据

zhaoxian 3 年之前
父节点
当前提交
2c6ff239d7

+ 1 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -229,6 +229,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/material/bytedance/report/**", "anon");
         filterChainDefinitionMap.put("/cwjsSaleAssistantInfo/**", "anon");
         filterChainDefinitionMap.put("/task/kuaishouHostingTask/**", "anon");
+        filterChainDefinitionMap.put("/audienceReport/**", "anon");
 
         // 添加自己的过滤器并且取名为jwt
         Map<String, Filter> filterMap = new HashMap<>(1);

+ 2 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/AiKuaishouUnitLevelOperationRecordMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.ai.mapper;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.Date;
 import java.util.List;
@@ -15,5 +16,5 @@ import java.util.List;
 public interface AiKuaishouUnitLevelOperationRecordMapper extends BaseMapper<AiKuaishouUnitLevelOperationRecord> {
     List<AiKuaishouUnitLevelOperationRecord> selectAllByAccountId(Date startDate, Date endDate);
     List<Long> selectAllAccountIds(Date startDate, Date endDate);
-    List<AiKuaishouUnitLevelOperationRecord> selectAllByAccountIdAndDate(Long accountId, Date startDate, Date endDate);
+    List<AiKuaishouUnitLevelOperationRecord> selectAllByAccountIdAndDate(@Param("accountId") Long accountId, @Param("startDate") Date startDate,@Param("endDate") Date endDate);
 }

+ 26 - 5
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/AiKuaishouUnitLevelOperationRecordMapper.xml

@@ -1,14 +1,35 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouUnitLevelOperationRecordMapper">
-    <select id="selectAllByAccountId" resultType="cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord">
-        select distinct account_id,campaign_id,unit_id from ctop_ai_kuaishou_unit_level_operation_record where unit_id is not null and  create_time &gt;= #{startDate} and create_time &lt;= #{endDate} and account_id in (select account_id from ctop_user_allocation where project_id = 458) group by account_id,campaign_id,unit_id
+    <select id="selectAllByAccountId"
+            resultType="cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord">
+        select distinct account_id, campaign_id, unit_id
+        from ctop_ai_kuaishou_unit_level_operation_record
+        where unit_id is not null
+          and create_time &gt;= #{startDate}
+          and create_time &lt;= #{endDate}
+          and account_id in (select account_id from ctop_user_allocation where project_id = 458)
+        group by account_id, campaign_id, unit_id
     </select>
-    <select id="selectAllByAccountIdAndDate" resultType="cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord">
-        select distinct account_id,campaign_id,unit_id from ctop_ai_kuaishou_unit_level_operation_record where unit_id is not null and unit_type = 4 and create_time &gt;= #{startDate} and create_time &lt;= #{endDate} and account_id = #{accountId} group by account_id,campaign_id,unit_id
+    <select id="selectAllByAccountIdAndDate"
+            resultType="cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord">
+        select distinct account_id, campaign_id, unit_id
+        from ctop_ai_kuaishou_unit_level_operation_record
+        where unit_id is not null
+          and unit_type = 4
+          and create_time &gt;= #{startDate}
+          and create_time &lt;= #{endDate}
+          and account_id = #{accountId}
+        group by unit_id
     </select>
 
     <select id="selectAllAccountIds" resultType="long">
-        select distinct account_id from ctop_ai_kuaishou_unit_level_operation_record where unit_id is not null and  create_time &gt;= #{startDate} and create_time &lt;= #{endDate} and account_id in (select account_id from ctop_user_allocation where project_id = 458) group by account_id
+        select distinct account_id
+        from ctop_ai_kuaishou_unit_level_operation_record
+        where unit_id is not null
+          and create_time &gt;= #{startDate}
+          and create_time &lt;= #{endDate}
+          and account_id in (select account_id from ctop_user_allocation where project_id = 458)
+        group by account_id
     </select>
 </mapper>

+ 95 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouAudienceReportDailyController.java

@@ -1,5 +1,10 @@
 package cn.com.ctop.kuaishou.modules.report.controller;
 
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouUnitLevelOperationRecord;
+import cn.com.ctop.kuaishou.modules.ai.mapper.AiKuaishouUnitLevelOperationRecordMapper;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyAccount;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAudienceReportDailyAccountService;
@@ -16,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
 import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -28,14 +34,20 @@ import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 人群分析报表
@@ -287,4 +299,87 @@ public class KuaishouAudienceReportDailyController {
         return Result.ok("文件导入失败!");
     }
 
+    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    static CountDownLatch countDownLatch = null;
+    @Resource
+    AiKuaishouUnitLevelOperationRecordMapper kuaishouUnitLevelOperationRecordMapper;
+
+    @GetMapping(value = "/getAudienceDataNew")
+    public void getAudienceData(@RequestParam(required = false, defaultValue = "2019-01-01") String date) throws Exception {
+        int page = 1;
+        int pageSize = 2000;
+        if (date.equals("2019-01-01")) {
+            date = DateUtils.formatDate(DateUtils.addDay(DateUtils.getNowDate(), -1), "yyyy-MM-dd");
+        }
+        int count = 0;
+        List<CtopOauthToken> tokens = tokenService.getByProjectId(458L);    //淘特项目
+        SimpleDateFormat dsdf = new SimpleDateFormat("yyyy-MM-dd");
+        for (CtopOauthToken token : tokens) {
+            Date enDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
+            if (enDate.after(token.getAccessTokenExpiresIn())) {   //过期跳过
+                continue;
+            }
+            Date startDate = DateUtils.addDay(enDate, -30);
+            log.info("accountId=" + token.getAccountId() + "开始:" + DateUtils.getLastDay(date, 30) + "结束:" + DateUtils.getLastDay(date, 1));
+            List<AiKuaishouUnitLevelOperationRecord> planIdsAndUnitIds = kuaishouUnitLevelOperationRecordMapper.selectAllByAccountIdAndDate(token.getAccountId(), startDate, enDate);
+            if (Check.isNull(planIdsAndUnitIds)) {
+                continue;
+            }
+            log.info("账户总数:" + tokens.size() + "当前:" + ++count);
+            countDownLatch = new CountDownLatch(planIdsAndUnitIds.size());
+            String finalDate = date;
+            planIdsAndUnitIds.forEach(planIdAndUnitId -> executorService.submit(() -> {
+                try {
+                    // province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "province", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "city", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "gender", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "clientId", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "ageSegment", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                    kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "businessInterestTags", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                } catch (Exception e) {
+                } finally {
+                    countDownLatch.countDown();
+                }
+            }));
+            countDownLatch.await();
+        }
+    }
+
+
+    @GetMapping(value = "/getOneAudienceDataNew")
+    public void getOneAudienceDataNew(Long accountId) throws Exception {
+        int page = 1;
+        int pageSize = 2000;
+        int count = 0;
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        Date enDate = DateUtils.addDay(DateUtils.getNowDate(), -1);
+        if (enDate.after(token.getAccessTokenExpiresIn())) {   //过期跳过
+            return;
+        }
+        Date startDate = DateUtils.addDay(enDate, -30);
+        List<AiKuaishouUnitLevelOperationRecord> planIdsAndUnitIds = kuaishouUnitLevelOperationRecordMapper.selectAllByAccountIdAndDate(token.getAccountId(), startDate, enDate);
+        if (Check.isNull(planIdsAndUnitIds)) {
+            return;
+        }
+        countDownLatch = new CountDownLatch(planIdsAndUnitIds.size());
+        String finalDate = DateUtils.formatDate(enDate, "yyyy-MM-dd");;
+        planIdsAndUnitIds.forEach(planIdAndUnitId -> executorService.submit(() -> {
+            try {
+                // province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "province", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "city", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "gender", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "clientId", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "ageSegment", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+                kuaishouAudienceReportDailyService.crowdAnalysisReport2(token, finalDate, "businessInterestTags", planIdAndUnitId.getCampaignId(), planIdAndUnitId.getUnitId(), page, pageSize);
+            } catch (Exception e) {
+            } finally {
+                countDownLatch.countDown();
+            }
+        }));
+    }
+
 }