Kaynağa Gözat

Merge branch 'kuaishou-ai-advertising' of http://git.tjyourong.com.cn/ctop/adsp-boot into kuaishou-ai-advertising

jiequan.bi 4 yıl önce
ebeveyn
işleme
8cb2a7e1f4
20 değiştirilmiş dosya ile 576 ekleme ve 266 silme
  1. 9 2
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetUnion.java
  2. 178 215
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java
  3. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouImageGetService.java
  4. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouImageGetServiceImpl.java
  5. 20 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouAudienceReportDailyController.java
  6. 13 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAudienceReportDaily.java
  7. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyAgeMapper.java
  8. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyBusinessMapper.java
  9. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyCityMapper.java
  10. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyClientMapper.java
  11. 4 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyGenderMapper.java
  12. 3 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyProvinceMapper.java
  13. 46 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyAgeMapper.xml
  14. 46 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyBusinessMapper.xml
  15. 45 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyCityMapper.xml
  16. 45 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyClientMapper.xml
  17. 45 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyGenderMapper.xml
  18. 45 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyProvinceMapper.xml
  19. 13 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouAudienceReportDailyService.java
  20. 43 3
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyServiceImpl.java

+ 9 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/entity/AiKuaishouStrategyTargetUnion.java

@@ -14,8 +14,6 @@ import lombok.Data;
 @Data
 @TableName("ctop_ai_kuaishou_strategy_target_union")
 public class AiKuaishouStrategyTargetUnion {
-
-	/**strategy_target_union_id*/
 	@TableId(type = IdType.AUTO)
 	private Long id;
 	/**middle_id*/
@@ -30,4 +28,13 @@ public class AiKuaishouStrategyTargetUnion {
 	/**updateTime*/
     @ApiModelProperty(value = "updateTime")
 	private Date updateTime;
+
+	public AiKuaishouStrategyTargetUnion() {
+	}
+
+	public AiKuaishouStrategyTargetUnion(Long strategyMiddleId, Long strategyTargetId, String targetContent) {
+		this.strategyMiddleId = strategyMiddleId;
+		this.strategyTargetId = strategyTargetId;
+		this.actualTargetContent = targetContent;
+	}
 }

+ 178 - 215
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ads/service/impl/AiStrategyServiceImpl.java

@@ -6,7 +6,6 @@ import cn.com.ctop.common.module.entity.MaterialImageInfo;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
 import cn.com.ctop.common.module.service.IMaterialImageInfoService;
-import cn.com.ctop.common.module.service.IOauthAgentTokenService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouStrategy;
@@ -14,29 +13,26 @@ import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouImageGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouMaterialUploadService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.sun.mail.imap.protocol.INTERNALDATE;
-import groovy.util.logging.Slf4j;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ads.entity.*;
 import org.jeecg.modules.ads.service.*;
-import org.openqa.selenium.json.Json;
+import org.jeecg.modules.ngalain.aop.LogRecordAspect;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
-import java.util.Date;
-
-import static com.bstek.ureport.definition.datasource.DataType.Date;
 
-@Slf4j
 @Service
 public class AiStrategyServiceImpl implements IAiStrategyService {
+    private static final Logger log = LoggerFactory.getLogger(AiStrategyServiceImpl.class);
     @Autowired
     private IKuaiShouVideoGetService videoGetService;
     @Autowired
@@ -57,11 +53,9 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
     private IMaterialCutFrameService materialCutFrameService;
     @Autowired
     private IMaterialImageInfoService materialImageInfoService;
-
     @Autowired
     private IKuaiShouImageGetService imageGetService;
-
-
+    @Autowired
     private IKuaiShouMaterialUploadService materialUploadService;
     /**
      *
@@ -84,7 +78,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             log.info("策略模板信息获取失败=>testDirection:{}",scenes);
             return;
         }
-        //1:获取相应账户下的最新的5条素材信息 TODO
+        //1:获取相应账户下的最新的5条素材信息
         List<KuaiShouVideoGet> videoGets = videoGetService.getNewVideoByAccountId(accountId,5);
         if(null == videoGets){
             log.info("素材获取失败=>accountId:{}",accountId);
@@ -97,21 +91,7 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             return;
         }
         //3:获取相应字段相应的用户定义域
-        String definitionDomain = null;
-
-        if (strategyTemplate.getTestDirection().equals("age")){
-            definitionDomain = strategy.getAgesRange();
-        }
-        if (strategyTemplate.getTestDirection().equals("gender")){
-            definitionDomain = strategy.getGender().toString();
-        }
-        if (strategyTemplate.getTestDirection().equals("region")){
-            definitionDomain = strategy.getRegion();
-        }
-        if (strategyTemplate.getTestDirection().equals("operation_system")){
-            definitionDomain = strategy.getPlatformOs().toString();
-        }
-
+        String definitionDomain = getStragyDefDomain(strategyTemplate,strategy);
         //4:计算定向拆分逻辑
         List<AiKuaishouStrategyTargetBase>getBases = splitBasesByDomain(definitionDomain,targetBases);
         if(null == getBases){
@@ -138,186 +118,50 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
             return;
         }
         Long campaignId = (Long) campaignCreateResult.get("campaignId");
-        // 8、根据定向和素材,两层循环 创建组和创意
         int unitCnt = 0;
+        // 8、根据定向和素材,两层循环 创建组和创意
         for (AiKuaishouStrategyTargetBase item:getBases) {
             unitCnt++;
             // 策略定向拆分数据,写入数据库
-            AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion();
-            targetUnion.setStrategyMiddleId(strategyMiddle.getId());
-            targetUnion.setStrategyTargetId(item.getId());
-            targetUnion.setActualTargetContent(item.getTargetContent());
+            AiKuaishouStrategyTargetUnion targetUnion = new AiKuaishouStrategyTargetUnion(strategyMiddle.getId(),item.getId(),item.getTargetContent());
             targetUnionService.save(targetUnion);
-
-            // 拼装创建组的入参 json
-            JSONObject unitParams = new JSONObject();
-            unitParams.put("advertiser_id",token.getAccountId());
-            unitParams.put("campaign_id",campaignId);
-            unitParams.put("unit_name", strategy.getStrategyName() + item.getTargetType() +
-                                        item.getTargetContent() + timestamp + unitCnt);
-
-            //TODO
-//            unitParams.put("template_id",strategy.getTemplateId());
-            unitParams.put("bid_type",10);
-
-            //TODO 前端添加对应设置项
-            if(null!=strategy.getUseAppMarket()&&!"".equals(strategy.getUseAppMarket())){
-                unitParams.put("use_app_market",Integer.parseInt(strategy.getUseAppMarket()));
-            }else{
-                unitParams.put("use_app_market",0);
-            }
-            if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
-                unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
-            }
-
-            // 非 OCPM 出价方式,是手动通过AD后台,走通几个成功下载APP的案例
-            // 在本策略中,都是 OCPM 的出价方式
-            unitParams.put("cpa_bid",strategy.getCpaBid());
-//            unitParams.put("smart_bid","");  //当 speed 等于 3 时可用
-            unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
-            unitParams.put("deep_conversion_typ",strategy.getDeepConversionType());
-//            unitParams.put("roi_ratio",""); 付费ROI系数 优化目标为「首日ROI」时必填
-            unitParams.put("deep_conversion_bid",strategy.getDeepConversionBid());
-            unitParams.put("scene_id",JSONArray.parseArray(strategy.getSceneId()));
-            unitParams.put("unit_type",4);
-
-            Date putDate = new Date();
-            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
-            String putDateString = formatter.format(putDate);
-            unitParams.put("begin_time",putDateString); // 格式为yyyy-MM-dd,需大于等于当前时间
-//            unitParams.put("end_time",""); 不传值表示从今天开始长期投放
-//            unitParams.put("schedule_time","");
-//            unitParams.put("day_budget","");
-//            unitParams.put("day_budget_schedule","");
-            unitParams.put("convert_id",strategy.getConvertId()); // ?
-//            unitParams.put("url_type",""); 当计划类型为3(获取电商下单)时必填
-            unitParams.put("url_type",strategy.getUrlType()); // 当计划类型为3(获取电商下单)
-//            unitParams.put("web_uri_type",""); // 当计划类型为5(收集销售线索)&使用建站时必填:需使用魔力建站
-            unitParams.put("url",strategy.getUrl()); // 当计划类型是3/4/5时必填
-            unitParams.put("schema_uri",""); // 可选
-            unitParams.put("app_id",""); // long 当计划类型为2时必填,可通过应用列表接口获取应用ID  但是前端为app_ids,是集合?
-            unitParams.put("show_mode",2);
-            unitParams.put("speed",1); // 前端没有设置,暂时默认为加速投放
-//            unitParams.put("site_type",""); // 预约广告,1:IOS预约 缺省为不传或传0
-//            unitParams.put("gift_data",""); // 游戏礼包码 "gift_data": {},仅支持计划类型为 2
-//            unitParams.put("video_landing_page","");
-//            unitParams.put("auto_target","");   智能定向
-//            unitParams.put("smart_cover","");   是否开启智能抽帧
-//            unitParams.put("asset_mining","");  是否开启历史素材挖掘
-
-            // 设置定向内容
-            JSONObject targetJsonObject = new JSONObject();
-            if (strategyTemplate.getTestDirection().equals("region"))
-                targetJsonObject.put("region",item.getTargetContent());
-            else
-                targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
-
-//            targetJsonObject.put("district_ids",""); 商圈定向 与region字段不能同时传
-//            targetJsonObject.put("user_type",""); 用户类型
-//            targetJsonObject.put("age","");
-
-            if (strategyTemplate.getTestDirection().equals("age"))
-                targetJsonObject.put("ages_range",item.getTargetContent());
-            else
-                targetJsonObject.put("ages_range",JSONArray.parseArray(strategy.getAgesRange()));
-
-            if (strategyTemplate.getTestDirection().equals("gender"))
-                targetJsonObject.put("gender",item.getTargetContent());
-            else
-                targetJsonObject.put("gender",strategy.getGender());
-
-            if (strategyTemplate.getTestDirection().equals("operation_system"))
-                targetJsonObject.put("platform_os",item.getTargetContent());
-            else
-                targetJsonObject.put("platform_os",strategy.getPlatformOs());
-//            targetJsonObject.put("android_osv","");
-//            targetJsonObject.put("ios_osv","");
-//            targetJsonObject.put("network","");
-//            targetJsonObject.put("device_brand","");
-//            targetJsonObject.put("device_price","");
-//            targetJsonObject.put("business_interest_type","");
-//            targetJsonObject.put("business_interest","");
-//            targetJsonObject.put("fans_star","");
-//            targetJsonObject.put("interest_video","");
-//            targetJsonObject.put("app_interest","");
-//            targetJsonObject.put("app_ids",""); // APP行为-按APP名称
-//            targetJsonObject.put("filter_converted_level","");
-            targetJsonObject.put("population",JSONArray.parseArray(strategy.getPopulation()));
-//            targetJsonObject.put("exclude_population","");
-//            targetJsonObject.put("paid_audience","");
-//            targetJsonObject.put("intelli_extend","");
-//            targetJsonObject.put("behavior_interest","");
-            unitParams.put("target",targetJsonObject);
-
-
-            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(),
-                    token.getAccountId(), unitParams,1);
+            //拼装广告组参数
+            JSONObject unitParams = createUnitParams(token,campaignId,strategy,strategyTemplate, item,timestamp,unitCnt);
+            Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams,1);
             Integer unitCode = (Integer) unitCreateResult.get("code");
+            String unitMessage = (String) unitCreateResult.get("message");
             if(unitCode != 0 ){
-                return;
+                log.info("组创建失败=>accountId:{};message:{}",accountId,unitMessage);
+                continue;
             }
             Long unitId = (Long) unitCreateResult.get("unitId");
-
             // 选择素材,创建创意
             for(KuaiShouVideoGet videoItem: videoGets){
-                // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
-                // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
-                List<MaterialCutFrame> cutFrameList =
-                        materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
-                List<MaterialImageInfo> orgFrameList =
-                        materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
-
+                //
+                JSONObject creativeParams = creativeParams(token,unitId,videoItem,timestamp,unitCnt,strategy);
                 JSONArray sceneIdJsonArray = JSONArray.parseArray(strategy.getSceneId());
-                JSONObject creativeParams = new JSONObject();
-                Integer creativeCnt = 1;
+                // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
                 if (sceneIdJsonArray.contains(6) && sceneIdJsonArray.size() == 1){
-                    // 如果广告位只包含 上下滑大屏广告(6),则一个素材搭配1张封面,生成1个创意
-                    String imageCode;
-                    String imageUrl;
-                    if (cutFrameList.size() == 0 && orgFrameList.size()==0){
-                        return;
-                    }
-                    if (orgFrameList.size()!=0){
-                        imageCode = orgFrameList.get(0).getCode();
-                        imageUrl = orgFrameList.get(0).getUrl();
-                    }
-                    else{
-                        imageCode = cutFrameList.get(0).getSignature();
-                        imageUrl = cutFrameList.get(0).getUrl();
-                    }
-                    String imageToken = getImageToken(imageUrl,
-                            imageCode,
-                            token.getAccountId(),
-                            token.getAccessToken());
-
-                    creativeParams.put("advertiser_id",token.getAccountId());
-                    creativeParams.put("unit_id",unitId);
-                    Date creativeDate = new Date();
-                    creativeParams.put("creative_name",creativeDate.toString() + creativeCnt.toString());
-                    creativeParams.put("photo_id",videoItem.getPhotoId());
-                    creativeParams.put("image_token",imageToken);
-                    creativeParams.put("creative_material_type",1); // 1:竖版视频  2:横版视频 4:便利贴单图图片创意 5:竖版图片 6:横版图片
-//                    creativeParams.put("image_tokens",""); 便利贴单图图片创意token
-                    creativeParams.put("action_bar_text","立即下载");
-                    creativeParams.put("description",""); // 广告语 -- 看小说太累?不妨试一试听书,解放双手,缓解压力!
-                    creativeParams.put("site_id",strategy.getSiteId()); // 安卓下载中间页ID
-                    creativeParams.put("click_track_url",strategy.getClickTrackUrl());
-                    creativeParams.put("impression_url",strategy.getImpressionUrl());
-//                    creativeParams.put("ad_photo_played_t3s_url","?");
-                    creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
-//                    creativeParams.put("creative_category","");// 创意分类
-//                    creativeParams.put("creative_tag",""); //创意标签
-                }
-                else
-                {
+                    //直接创建创意
+                    createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,1);
+                } else {
+                    // 素材自带的封面 ctop_material_image_info 内部素材的自带封面,素造的没有
+                    // 素材的智能抽帧封面 ctop_material_cut_frame 其中素造的为8张封面,内部的为15张封面
+                    List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
+                    List<MaterialImageInfo> orgFrameList = materialImageInfoService.getListByVideoSignature(videoItem.getSignature());
                     // 其他情况下,一个素材搭配15张封面,生成15个创意
-                    if (cutFrameList.size() == 0 && orgFrameList.size()==0){
-                        return;
+                    if ((null == cutFrameList||cutFrameList.isEmpty())&&(null == orgFrameList|| orgFrameList.isEmpty())){
+                        log.info("未获取到视频封面=>videoSignature:{}",videoItem.getSignature());
+                        continue;
                     }
-                    if (orgFrameList.size() !=0) {
+                    int creativeCnt = 1;
+                    if (null!=orgFrameList&&!orgFrameList.isEmpty()) {
                         for (int i = 0; i < orgFrameList.size(); i++) {
                             String imageCode = orgFrameList.get(i).getCode();
                             String imageUrl = orgFrameList.get(i).getUrl();
+                            String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
+                            creativeParams.put("image_token",imageToken);
+                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
                             creativeCnt++;
                             if (creativeCnt > 15) {
                                 break;
@@ -325,56 +169,175 @@ public class AiStrategyServiceImpl implements IAiStrategyService {
                         }
                     }
 
-                    if ((cutFrameList.size() !=0) && (creativeCnt<=15)){
+                    if ((null!=cutFrameList&&!cutFrameList.isEmpty()) && (creativeCnt<=15)){
                         for (int i = 0; i < cutFrameList.size(); i++) {
                             String imageCode = cutFrameList.get(i).getSignature();
                             String imageUrl = cutFrameList.get(i).getUrl();
+                            String imageToken = getImageToken(imageUrl,imageCode,accountId,token.getAccessToken());
+                            creativeParams.put("image_token",imageToken);
+                            createCreative(token,creativeParams,campaignId,unitId,strategy,targetUnion,creativeCnt);
                             creativeCnt ++;
                             if (creativeCnt > 15) {
                                 break;
                             }
                         }
                     }
-
-                }
-
-
-
-                Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
-                        (token.getAccessToken(), token.getAccountId(), creativeParams,1);
-                Integer creativeCode = (Integer) creativeCreateResult.get("code");
-                if(creativeCode != 0 ){
-                    return;
                 }
-                Long creativeId = (Long) creativeCreateResult.get("creativeId");
-                AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
-                mapCreative.setAccountId(token.getAccountId());
-                mapCreative.setCampaignId(campaignId);
-                mapCreative.setUnitId(unitId);
-                mapCreative.setCreativeId(creativeId);
-                mapCreative.setStrategyId(strategy.getId());
-                mapCreative.setStrategyTargetUnionId(targetUnion.getId());
-                mapCreativeService.save(mapCreative);
+            }
+        }
+    }
 
+    private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,String timestamp,int unitCnt,KuaishouStrategy strategy){
+        JSONObject creativeParams = new JSONObject();
+        creativeParams.put("advertiser_id",token.getAccountId());
+
+        creativeParams.put("unit_id",unitId);
+        creativeParams.put("photo_id",videoItem.getPhotoId());
+        creativeParams.put("creative_name","智能创意-"+timestamp+unitCnt+"-"+1);
+        creativeParams.put("creative_material_type",videoItem.getMaterialType());
+        creativeParams.put("action_bar_text","立即下载");
+        //TODO 广告语
+        creativeParams.put("description","测试广告语");
+        // 安卓下载中间页ID
+        if(null == strategy.getSiteId()||!"".equals(strategy.getSiteId())){
+            creativeParams.put("site_id",strategy.getSiteId());
+        }
+        if(null == strategy.getClickTrackUrl()||!"".equals(strategy.getClickTrackUrl())){
+            creativeParams.put("click_track_url",strategy.getClickTrackUrl());
+        }
+        if(null == strategy.getImpressionUrl()||!"".equals(strategy.getImpressionUrl())){
+            creativeParams.put("impression_url",strategy.getImpressionUrl());
+        }
+        if(null == strategy.getActionbarClickUrl()||!"".equals(strategy.getActionbarClickUrl())){
+            creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
+        }
+        return creativeParams;
+    }
 
-            }
+    private String getStragyDefDomain(AiKuaishouStrategyTemplate strategyTemplate,KuaishouStrategy strategy){
+        String definitionDomain = null;
+        if (strategyTemplate.getTestDirection().equals("age")){
+            definitionDomain = strategy.getAgesRange();
+        }
+        if (strategyTemplate.getTestDirection().equals("gender")){
+            definitionDomain = strategy.getGender().toString();
+        }
+        if (strategyTemplate.getTestDirection().equals("region")){
+            definitionDomain = strategy.getRegion();
+        }
+        if (strategyTemplate.getTestDirection().equals("operation_system")){
+            definitionDomain = strategy.getPlatformOs().toString();
+        }
+        return definitionDomain;
+    }
 
+    private JSONObject createUnitParams(CtopOauthToken token,Long campaignId,KuaishouStrategy strategy,AiKuaishouStrategyTemplate strategyTemplate,
+                                        AiKuaishouStrategyTargetBase item,String timestamp,int unitCnt){
+        // 拼装创建组的入参 json
+        JSONObject unitParams = new JSONObject();
+        unitParams.put("advertiser_id",token.getAccountId());
+        unitParams.put("campaign_id",campaignId);
+        unitParams.put("unit_name", strategy.getStrategyName() + item.getTargetType() +
+                item.getTargetContent() + timestamp + unitCnt);
+        unitParams.put("bid_type",10);
+
+        if(null!=strategy.getUseAppMarket()&&!"".equals(strategy.getUseAppMarket())){
+            unitParams.put("use_app_market",Integer.parseInt(strategy.getUseAppMarket()));
+        }
+        if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
+            unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
+        }
 
+        // 在本策略中,都是 OCPM 的出价方式
+        unitParams.put("cpa_bid",strategy.getCpaBid());
+        unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
+        unitParams.put("deep_conversion_type",strategy.getDeepConversionType());
+        unitParams.put("deep_conversion_bid",strategy.getDeepConversionBid());
+        unitParams.put("scene_id",JSONArray.parseArray(strategy.getSceneId()));
+        unitParams.put("unit_type",4);
+
+        // 格式为yyyy-MM-dd,需大于等于当前时间
+        unitParams.put("begin_time",DateUtils.formatDate(new Date()));
+        if(null!=strategy.getConvertId()){
+            unitParams.put("convert_id",strategy.getConvertId());
+        }
+        // 当计划类型是3/4/5时必填
+        if(null!=strategy.getUrl()&&!"".equals(strategy.getUrl())){
+            unitParams.put("url",strategy.getUrl());
+        }
+        JSONArray appIds = JSONArray.parseArray(strategy.getAppIds());
+        //TODO 先只做单appId的逻辑
+        if(null!=appIds&&!appIds.isEmpty()){
+            unitParams.put("app_id",appIds.getLong(0));
+        }
+        unitParams.put("show_mode",2);
+        unitParams.put("speed",1);
+        // 设置定向内容
+        JSONObject targetJsonObject = new JSONObject();
+        if (strategyTemplate.getTestDirection().equals("region")){
+            targetJsonObject.put("region",JSONArray.parseArray(item.getTargetContent()));
+        } else {
+            targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
+        }
 
+        if (strategyTemplate.getTestDirection().equals("age")){
+            targetJsonObject.put("ages_range",JSONArray.parseArray(item.getTargetContent()));
+        } else{
+            targetJsonObject.put("ages_range",JSONArray.parseArray(strategy.getAgesRange()));
+        }
 
+        if (strategyTemplate.getTestDirection().equals("gender")){
+            targetJsonObject.put("gender",item.getTargetContent());
+        } else {
+            targetJsonObject.put("gender",strategy.getGender());
         }
 
+        if (strategyTemplate.getTestDirection().equals("operation_system")){
+            targetJsonObject.put("platform_os",item.getTargetContent());
+        } else {
+            targetJsonObject.put("platform_os",strategy.getPlatformOs());
+        }
+        JSONArray population = JSONArray.parseArray(strategy.getPopulation());
+        if(null!=population&&!population.isEmpty()){
+            targetJsonObject.put("population",population);
+        }
+        JSONArray excludePopulation = JSONArray.parseArray(strategy.getExcludePopulation());
+        if(null!=excludePopulation&&!excludePopulation.isEmpty()){
+            targetJsonObject.put("paid_audience",excludePopulation);
+        }
 
+        unitParams.put("target",targetJsonObject);
+        return unitParams;
+    }
+    private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
+                                KuaishouStrategy strategy,AiKuaishouStrategyTargetUnion targetUnion,int creativeCnt){
+        creativeParams.put("creative_name",creativeParams.getString("creative_name")+creativeCnt);
+        Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
+                (token.getAccessToken(), token.getAccountId(), creativeParams,1);
+        Integer creativeCode = (Integer) creativeCreateResult.get("code");
+        String creativeMessage = (String) creativeCreateResult.get("message");
+        if(creativeCode != 0 ){
+            log.info("创意创建失败=>message:{}",creativeMessage);
+            return;
+        }
+        Long creativeId = (Long) creativeCreateResult.get("creativeId");
+        AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
+        mapCreative.setAccountId(token.getAccountId());
+        mapCreative.setCampaignId(campaignId);
+        mapCreative.setUnitId(unitId);
+        mapCreative.setCreativeId(creativeId);
+        mapCreative.setStrategyId(strategy.getId());
+        mapCreative.setStrategyTargetUnionId(targetUnion.getId());
+        mapCreativeService.save(mapCreative);
     }
 
     private String getImageToken(String imageUrl, String imageCode, Long accountId,String token){
         // 根据imageUrl 和 imageCode,获取 imageToken (创建创意用)
-        KuaiShouImageGet imageGet = imageGetService.getOneByParams(imageUrl);
+        KuaiShouImageGet imageGet = imageGetService.getOneByParams(null,imageCode);
         if ((null == imageGet) || ("".equals(imageGet.getImageToken()))){
             // 如果取不到image_token
             // 则调用上传url的方法 kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
-            String imageToken = materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
-            return imageToken;
+            return materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
         }
 
         return imageGet.getImageToken();

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouImageGetService.java

@@ -16,5 +16,5 @@ public interface IKuaiShouImageGetService extends IService<KuaiShouImageGet> {
 
     String getUrlByCode(String signature);
 
-    KuaiShouImageGet getOneByParams(String url);
+    KuaiShouImageGet getOneByParams(String url,String code);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouImageGetServiceImpl.java

@@ -41,11 +41,14 @@ public class KuaiShouImageGetServiceImpl extends ServiceImpl<KuaiShouImageGetMap
 
 
     @Override
-    public KuaiShouImageGet getOneByParams(String url) {
+    public KuaiShouImageGet getOneByParams(String url,String code) {
         QueryWrapper<KuaiShouImageGet> queryWrapper= new QueryWrapper<>();
         if(null!=url&&!"".equals(url.trim())){
             queryWrapper.eq("url",url);
         }
+        if(null!=code&&!"".equals(code.trim())){
+            queryWrapper.eq("signature",code);
+        }
         queryWrapper.orderByDesc("create_time");
         queryWrapper.last("limit 1");
         return this.getOne(queryWrapper);

+ 20 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/controller/KuaishouAudienceReportDailyController.java

@@ -4,7 +4,6 @@ import cn.com.ctop.common.module.annotation.AutoLog;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.service.IKuaishouAudienceReportDailyService;
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -104,6 +103,26 @@ public class KuaishouAudienceReportDailyController {
     }
 
     /**
+     * 首页报表数据接口
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @AutoLog(value = "首页报表数据接口")
+    @ApiOperation(value = "首页报表数据接口", notes = "首页报表数据接口")
+    @GetMapping(value = "/queryAllReportForm")
+    public Result<Object> queryAllReportForm(KuaishouAudienceReportDaily audienceReport) {
+        try {
+            return kuaishouAudienceReportDailyService.queryAllReportForm(audienceReport);
+        } catch (Exception e) {
+            log.error("首页报表数据接口", e);
+        }
+        return Result.error("首页报表数据接口失败");
+    }
+
+    /**
      * 添加
      *
      * @param kuaishouAudienceReportDaily

+ 13 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouAudienceReportDaily.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.report.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
@@ -724,6 +725,18 @@ public class KuaishouAudienceReportDaily {
     @Excel(name = "eventAdWatchTimes", width = 15)
     @ApiModelProperty(value = "eventAdWatchTimes")
     private java.lang.String eventAdWatchTimes;
+
+    @TableField(exist = false)
+    private java.lang.String startTime;
+
+    @TableField(exist = false)
+    private java.lang.String endTime;
+
+    @TableField(exist = false)
+    private java.lang.String orderType;
+
+    @TableField(exist = false)
+    private java.lang.String upOrDown;
     /**
      * 评论数
      */

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyAgeMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyAge;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import java.util.List;
@@ -15,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyAgeMapper extends BaseMapper<KuaishouAudienceReportDailyAge> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyBusinessMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyBussiness;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import java.util.List;
@@ -15,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyBusinessMapper extends BaseMapper<KuaishouAudienceReportDailyBussiness> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyCityMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyCity;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import java.util.List;
@@ -15,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyCityMapper extends BaseMapper<KuaishouAudienceReportDailyCity> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyClientMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyClient;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import java.util.List;
@@ -15,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyClientMapper extends BaseMapper<KuaishouAudienceReportDailyClient> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 4 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyGenderMapper.java

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDailyGender;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 
 import java.util.List;
@@ -15,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyGenderMapper extends BaseMapper<KuaishouAudienceReportDailyGender> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 3 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouAudienceReportDailyProvinceMapper.java

@@ -16,5 +16,7 @@ import java.util.List;
  */
 public interface KuaishouAudienceReportDailyProvinceMapper extends BaseMapper<KuaishouAudienceReportDailyProvince> {
 
-    List<KuaishouAudienceReportDaily> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+    List<JSONObject> queryPageLists(KuaishouAudienceReportDaily audienceReport);
+
+    List<JSONObject> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 46 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouAudienceReportDailyAgeMapper.xml

@@ -1,11 +1,52 @@
 <?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.report.mapper.KuaishouAudienceReportDailyAgeMapper">
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
         select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+        SELECT
+        account_id,
+        age_segment,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_age t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY age_segment
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        age_segment,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_age t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY age_segment
+    </select>
 </mapper>

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

@@ -1,11 +1,51 @@
 <?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.report.mapper.KuaishouAudienceReportDailyBusinessMapper">
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
-        select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        account_id,
+        business_interest_tags,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_business t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY business_interest_tags
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        business_interest_tags,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_business t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY business_interest_tags
+    </select>
 </mapper>

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

@@ -1,11 +1,50 @@
 <?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.report.mapper.KuaishouAudienceReportDailyCityMapper">
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
-        select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        account_id,
+        city,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_city t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY city
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        city,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_city t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY city
+    </select>
 </mapper>

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

@@ -1,11 +1,50 @@
 <?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.report.mapper.KuaishouAudienceReportDailyClientMapper">
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
-        select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        account_id,
+        client,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_client t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY client
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        client,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_client t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY client
+    </select>
 </mapper>

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

@@ -1,11 +1,50 @@
 <?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.report.mapper.KuaishouAudienceReportDailyGenderMapper">
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
-        select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        account_id,
+        gender,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_gender t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY gender
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        gender,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_gender t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY gender
+    </select>
 </mapper>

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

@@ -2,11 +2,50 @@
 <!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.report.mapper.KuaishouAudienceReportDailyProvinceMapper">
 
-    <select id="queryPageLists" resultType="cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily">
-        select
-        *
-       from
-        ctop_kuaishou_audience_report_daily_province
+    <select id="queryPageLists" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        account_id,
+        province,
+        SUM(charge) as charge,
+        SUM(activation) as activation,
+        SUM(event_next_day_stay) as eventNextDayStay,
+        ROUND(SUM(event_next_day_stay)/SUM(activation)*100,2)as eventNextDayStayRatio
+        FROM ctop_kuaishou_audience_report_daily_province t1
         where account_id = #{accountId}
-      </select>
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY province
+        <if test="orderType!= null">
+            ORDER BY #{orderType}
+        </if>
+        <if test="upOrDown == 'desc' || upOrDown == 'DESC'">
+            DESC
+        </if>
+    </select>
+
+    <select id="queryAllReportForm" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        stat_date,
+        account_id,
+        province,
+        SUM(photo_show) as photoShow,
+        SUM(photo_click) as photoClick,
+        SUM(aclick) as aclick,
+        SUM(bclick) as bclick,
+        ROUND(SUM(photo_click)/SUM(photo_show)*100,2) as photoClickRatio,
+        ROUND(SUM(bclick)/SUM(aclick)*100,2) as actionRatio
+        FROM ctop_kuaishou_audience_report_daily_province t1
+        where account_id = #{accountId}
+        <if test="startTime != null">
+            AND stat_date &gt;= #{startTime}
+        </if>
+        <if test="endTime != null">
+            AND stat_date &lt;= #{endTime}
+        </if>
+        GROUP BY province
+    </select>
 </mapper>

+ 13 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/IKuaishouAudienceReportDailyService.java

@@ -2,7 +2,6 @@ package cn.com.ctop.kuaishou.modules.report.service;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouAudienceReportDaily;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
 
@@ -24,12 +23,24 @@ public interface IKuaishouAudienceReportDailyService extends IService<KuaishouAu
     void crowdAnalysisReport(CtopOauthToken token, String date, String type, Long plan, Long unit, Integer page, Integer pageSize);
 
     /**
-     * 人群分析报表
+     * 查询人群分析报表
      *
      * @param
+     * @param no
+     * @param type
      * @return java.lang.Long
      * @throws
      * @author ZHAOXA
      */
     Result<Object> queryPageLists(KuaishouAudienceReportDaily audienceReport, Integer pageNo, Integer pageSize, String type);
+
+    /**
+     * 首页报表数据
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    Result<Object> queryAllReportForm(KuaishouAudienceReportDaily audienceReport);
 }

+ 43 - 3
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/service/impl/KuaishouAudienceReportDailyServiceImpl.java

@@ -65,7 +65,7 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
     private String urlPath = PropertiesUtils.getConfig("kuaishou_api_url");
 
     /**
-     * 报表分页查询
+     * 报表分页分页查询
      *
      * @param type province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布
      * @return org.jeecg.common.api.vo.Result<java.lang.Object>
@@ -80,7 +80,7 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
         if (null == pageSize || pageSize == 0) {
             pageSize = 10;
         }
-        List<KuaishouAudienceReportDaily> list = null;
+        List<JSONObject> list = null;
         PageHelper.startPage(pageNo, pageSize);
         if ("province".equals(type)) {
             list = provinceMapper.queryPageLists(audienceReport);
@@ -97,11 +97,51 @@ public class KuaishouAudienceReportDailyServiceImpl extends ServiceImpl<Kuaishou
         } else {
             return Result.error("请选择人群报表类型");
         }
-        PageInfo<KuaishouAudienceReportDaily> pageInfo = new PageInfo<>(list);
+        if (Check.isNull(list)) {
+            return Result.error("只能获取到两天前的数据,请正确选择时间");
+        }
+        PageInfo<JSONObject> pageInfo = new PageInfo<>(list);
         return Result.ok(pageInfo);
     }
 
     /**
+     * 首页报表数据
+     *
+     * @param type province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布
+     * @return org.jeecg.common.api.vo.Result<java.lang.Object>
+     * @throws
+     * @author ZHAOXA
+     */
+    @Override
+    public Result<Object> queryAllReportForm(KuaishouAudienceReportDaily audienceReport) {
+        JSONObject data = new JSONObject();
+        List<JSONObject> provinces = provinceMapper.queryAllReportForm(audienceReport);
+        if (!Check.isNull(provinces)) {
+            data.put("province", provinces);
+        }
+        List<JSONObject> genders = genderMapper.queryAllReportForm(audienceReport);
+        if (!Check.isNull(genders)) {
+            data.put("gender", genders);
+        }
+        List<JSONObject> ages = ageMapper.queryAllReportForm(audienceReport);
+        if (!Check.isNull(ages)) {
+            data.put("ageSegment", ages);
+        }
+        List<JSONObject> clients = clientMapper.queryAllReportForm(audienceReport);
+        if (!Check.isNull(clients)) {
+            data.put("client", clients);
+        }
+        List<JSONObject> bussiness = bussinessMapper.queryAllReportForm(audienceReport);
+        if (!Check.isNull(bussiness)) {
+            data.put("businessInterestTags", bussiness);
+        }
+        if (data.size() == 0) {
+            return Result.error("只能获取到两天前的数据,请正确选择时间");
+        }
+        return Result.ok(data);
+    }
+
+    /**
      * 人群分析报表入库
      *
      * @param type      province: 省级地域分布, city: 地级地域分布,gender: 性别分布,ageSegment: 年龄分布clientId: 系统分布 businessInterestTags: 商业兴趣分布