Browse Source

人群包功能开发

zhaoxian 4 years ago
parent
commit
4f58daf008
14 changed files with 475 additions and 50 deletions
  1. 57 0
      module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/CrowdListQueryJob.java
  2. 36 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouCrowdPackController.java
  3. 11 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouCrowdPack.java
  4. 91 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouCrowdPackageRel.java
  5. 13 6
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouCrowdPackMapper.java
  6. 17 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouCrowdPackageRelMapper.java
  7. 74 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouCrowdPackMapper.xml
  8. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouCrowdPackageRelMapper.xml
  9. 5 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouCrowdPackService.java
  10. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouCrowdPackageRelService.java
  11. 99 22
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouCrowdPackServiceImpl.java
  12. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouCrowdPackageRelServiceImpl.java
  13. 3 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouPopulationService.java
  14. 31 11
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouPopulationServiceImpl.java

+ 57 - 0
module-job-kuaishou/src/main/java/cn/com/ctop/job/kuaishou/handler/CrowdListQueryJob.java

@@ -0,0 +1,57 @@
+package cn.com.ctop.job.kuaishou.handler;
+
+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.KuaishouCrowdPack;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class CrowdListQueryJob {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+
+    @Autowired
+    private KuaishouCrowdPackMapper crowdPackMapper;
+    @Autowired
+    private IKuaishouPopulationService iKuaishouPopulationService;
+
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @XxlJob("crowdListQueryJob")
+    public void execute() {
+        List<Integer> list = new ArrayList<>();
+        for (int i = 0; i <= 7; i++) {
+            list.add(i);
+        }
+        list.forEach(status -> executorService.submit(() -> {
+            List<KuaishouCrowdPack> crowdList = crowdPackMapper.queryListByStatus();
+            for (KuaishouCrowdPack crowdPack : crowdList) {
+                CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
+                JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), crowdPack.getStatus());
+                if (jsonObject.getInteger("code") == 0) {
+                    JSONObject data = jsonObject.getJSONObject("data");
+                    if (!Check.isNull(data)) {
+                        JSONArray details = data.getJSONArray("details");
+                        if (details.size() > 0) {
+                            crowdPackMapper.updateBatch(details);
+                        }
+                    }
+                }
+            }
+        }));
+        XxlJobHelper.log("快手人群报表更新成功");
+    }
+}

+ 36 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouCrowdPackController.java

@@ -6,6 +6,7 @@ import cn.com.ctop.common.module.utils.QueryGenerator;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackService;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -84,10 +85,24 @@ public class KuaishouCrowdPackController {
     }
 
     @GetMapping(value = "/queryPageList")
-    @PostMapping(value = "/queryPageList")
-    public Result<Object> queryPageList(@RequestBody JSONObject request) {
+    public Result<Object> queryPageList(KuaishouCrowdPack kuaishouCrowdPack,
+                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
         try {
-            return kuaishouCrowdPackService.queryPageList(request);
+            return kuaishouCrowdPackService.queryPageList(kuaishouCrowdPack, pageNo, pageSize);
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
+    @GetMapping(value = "/queryRel")
+    public Result<Object> queryRel(String type, Long orientationId, Long accountId,
+                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+        try {
+            return kuaishouCrowdPackService.queryRel(type, orientationId, accountId, pageNo, pageSize);
         } catch (Exception e) {
             log.error("查询异常,", e.getMessage());
             e.printStackTrace();
@@ -103,7 +118,11 @@ public class KuaishouCrowdPackController {
      */
 
     @PostMapping(value = "/uploadCrowdPack")
-    public Result<Object> uploadCrowdPack(Integer type, String orientationName, Long accountId, String url) {
+    public Result<Object> uploadCrowdPack(@RequestBody JSONObject request) {
+        Integer type = request.getInteger("type");
+        String orientationName = request.getString("orientationName");
+        Long accountId = request.getLong("accountId");
+        String url = request.getString("url");
         try {
             if (Check.isNull(type) || Check.isNull(orientationName) || Check.isNull(url) || Check.isNull(accountId)) {
                 return Result.error("缺少参数");
@@ -127,7 +146,7 @@ public class KuaishouCrowdPackController {
     @PostMapping(value = "/accountPush")
     public Result<Object> accountPush(@RequestBody JSONObject request) {
         try {
-            Long accountIds = request.getLong("accountIds");
+            JSONArray accountIds = request.getJSONArray("accountIds");
             String orientationId = request.getString("orientationId");
             if (Check.isNull(accountIds) || Check.isNull(orientationId)) {
                 return Result.error("缺少参数");
@@ -140,6 +159,18 @@ public class KuaishouCrowdPackController {
         return Result.error("查询失败");
     }
 
+    @PostMapping(value = "/crowdListQuery")
+    public Result<Object> crowdListQuery() {
+        try {
+            kuaishouCrowdPackService.crowdListQuery();
+            return Result.ok("success");
+        } catch (Exception e) {
+            log.error("查询异常,", e.getMessage());
+            e.printStackTrace();
+        }
+        return Result.error("查询失败");
+    }
+
     /**
      * 添加
      *

+ 11 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouCrowdPack.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.ai.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
@@ -16,7 +17,8 @@ import java.util.Date;
 
 /**
  * 人群报表
- *package
+ * package
+ *
  * @author jeecg-boot
  * @version V1.0
  * @date 2021-03-26
@@ -63,7 +65,11 @@ public class KuaishouCrowdPack {
      */
     private String url;
     /**
-     * 链接
+     * 执行结果反馈
+     */
+    private String message;
+    /**
+     * MD5
      */
     private String signature;
     /**
@@ -118,4 +124,7 @@ public class KuaishouCrowdPack {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "修改时间")
     private Date updateTime;
+
+    @TableField(exist = false)
+    private String accountName;
 }

+ 91 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouCrowdPackageRel.java

@@ -0,0 +1,91 @@
+package cn.com.ctop.kuaishou.modules.ai.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.jeecgframework.poi.excel.annotation.Excel;
+
+/**
+ * 人群推送账户
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-03-30
+ */
+@Data
+@TableName("ctop_kuaishou_crowd_package_rel")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_crowd_package_rel对象", description = "人群推送账户")
+public class KuaishouCrowdPackageRel {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 目标账户ID
+     */
+    @Excel(name = "目标账户ID", width = 15)
+    @ApiModelProperty(value = "目标账户ID")
+    private Long tgtAccountId;
+    /**
+     * 推送账户ID
+     */
+    @Excel(name = "推送账户ID", width = 15)
+    @ApiModelProperty(value = "推送账户ID")
+    private Long accountId;
+    /**
+     * 上传日期
+     */
+    @Excel(name = "上传日期", width = 15)
+    @ApiModelProperty(value = "上传日期")
+    private String statDate;
+    /**
+     * 人群包ID
+     */
+    @Excel(name = "人群包ID", width = 15)
+    @ApiModelProperty(value = "人群包ID")
+    private Long orientationId;
+    /**
+     * 人群包名称
+     */
+    @Excel(name = "人群包名称", width = 15)
+    @ApiModelProperty(value = "人群包名称")
+    private String orientationName;
+    /**
+     * 执行结果反馈
+     */
+    @Excel(name = "执行结果反馈", width = 15)
+    @ApiModelProperty(value = "执行结果反馈")
+    private String message;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 13 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouCrowdPackMapper.java

@@ -1,21 +1,28 @@
 package cn.com.ctop.kuaishou.modules.ai.mapper;
 
-import java.util.List;
-
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import org.apache.ibatis.annotations.Param;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 /**
  * 人群报表
+ *
  * @author: jeecg-boot
- * @date:   2021-03-26
+ * @date: 2021-03-26
  * @cersion: V1.0
  */
 public interface KuaishouCrowdPackMapper extends BaseMapper<KuaishouCrowdPack> {
 
-    Long getTotal(JSONObject request);
+    Long getTotal(@Param(value = "status") Integer status, @Param(value = "accountName") String accountName, @Param(value = "orientationName") String orientationName);
+
+    List<JSONObject> queryPageList(@Param(value = "status") Integer status, @Param(value = "accountName") String accountName, @Param(value = "orientationName") String orientationName);
+
+    List<KuaishouCrowdPack> queryListByStatus();
+
+    void updateBatch(@Param(value = "details") JSONArray details);
 
-    List<KuaishouCrowdPack> queryPageList(JSONObject request);
 }

+ 17 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouCrowdPackageRelMapper.java

@@ -0,0 +1,17 @@
+package cn.com.ctop.kuaishou.modules.ai.mapper;
+
+import java.util.List;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPackageRel;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 人群推送账户
+ * @author: jeecg-boot
+ * @date:   2021-03-30
+ * @cersion: V1.0
+ */
+public interface KuaishouCrowdPackageRelMapper extends BaseMapper<KuaishouCrowdPackageRel> {
+
+}

+ 74 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouCrowdPackMapper.xml

@@ -3,12 +3,84 @@
 <mapper namespace="cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackMapper">
 
     <select id="getTotal" resultType="java.lang.Long">
-
+        SELECT
+        count(1)
+        FROM ctop_kuaishou_crowd_package t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE `status` !='' and `status` is not null
+        <if test="orientationName !=null">
+            AND orientation_name LIKE CONCAT('%',#{orientationName},'%')
+        </if>
+        <if test="accountName !=null">
+            AND t2.auth_name LIKE CONCAT('%',#{accountName},'%')
+        </if>
+        <if test="status !=null">
+            AND t1.`status` =#{status}
+        </if>
     </select>
 
-     <select id="queryPageList" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack">
+    <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.id,
+        t1.account_id as 'accountId',
+        t2.auth_name as 'accountName',
+        stat_date as 'statDate',
+        orientation_id as 'orientationId',
+        orientation_name as 'orientationName',
+        url,
+        population_type as 'populationType',
+        t1.type,
+        CASE t1.type
+        WHEN 1 THEN 'IMEI'
+        WHEN 2 THEN 'IDFA'
+        WHEN 3 THEN 'IMEI_MD5'
+        WHEN 4 THEN 'IDFA_MD5'
+        WHEN 5 THEN '手机号-MD5'
+        WHEN 7 THEN 'OAID'
+        WHEN 8 THEN 'OAID_MD5'
+        END as 'typeStr',
+        t1.`status`,
+        CASE t1.`status`
+        WHEN 0 THEN '计算中'
+        WHEN 1 THEN '已生效'
+        WHEN 2 THEN '已删除'
+        WHEN 3 THEN '推送中'
+        WHEN 4 THEN '已推送'
+        WHEN 5 THEN '计算失败'
+        WHEN 6 THEN '推送失败'
+        WHEN 7 THEN '已失效'
+        END as 'statusStr',
+        IFNULL(signature,null),
+        IFNULL(cover_num,0) as 'coverNum',
+        IFNULL((SELECT COUNT(1) FROM ctop_user_allocation t where t1.account_id = t.account_id),0) as 'projectCount',
+        IFNULL((SELECT COUNT(1) FROM ctop_kuaishou_crowd_package_rel t WHERE t.tgt_account_id = t1.account_id),0) as 'accountCount'
+        FROM ctop_kuaishou_crowd_package t1
+        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+        WHERE `status` !='' and `status` is not null
+        <if test="orientationName !=null">
+            AND orientation_name LIKE CONCAT('%',#{orientationName},'%')
+        </if>
+        <if test="accountName !=null">
+            AND t2.auth_name LIKE CONCAT('%',#{accountName},'%')
+        </if>
+        <if test="status !=null">
+            AND t1.`status` =#{status}
+        </if>
+    </select>
 
+    <select id="queryListByStatus" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack">
+        SELECT account_id
+        FROM ctop_kuaishou_crowd_package
+        WHERE `status` !='' and `status` is not null
+        GROUP BY account_id
     </select>
 
+    <update id="updateBatch">
+        <foreach collection="details" separator=";" item="item">
+            update ctop_kuaishou_crowd_package
+            set status = #{item.status}
+            where account_id = #{item.account_id}
+            and orientation_id = #{item.orientation_id}
+        </foreach>
+    </update>
 
 </mapper>

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouCrowdPackageRelMapper.xml

@@ -0,0 +1,5 @@
+<?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.KuaishouCrowdPackageRelMapper">
+
+</mapper>

+ 5 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouCrowdPackService.java

@@ -13,9 +13,13 @@ import org.jeecg.common.api.vo.Result;
  */
 public interface IKuaishouCrowdPackService extends IService<KuaishouCrowdPack> {
 
-    Result<Object> queryPageList(JSONObject request);
+    Result<Object> queryPageList(KuaishouCrowdPack kuaishouCrowdPack, Integer pageNo, Integer pageSize);
 
     Result<Object> uploadCrowdPack(Integer type, String orientationName, Long accountId, String url);
 
     Result<Object> accountPush(JSONObject request);
+
+    void crowdListQuery();
+
+    Result<Object> queryRel(String type, Long orientationId, Long accountId, Integer pageNo, Integer pageSize);
 }

+ 14 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouCrowdPackageRelService.java

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPackageRel;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 人群推送账户
+ * @Author: jeecg-boot
+ * @Date:   2021-03-30
+ * @Version: V1.0
+ */
+public interface IKuaishouCrowdPackageRelService extends IService<KuaishouCrowdPackageRel> {
+
+}

+ 99 - 22
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouCrowdPackServiceImpl.java

@@ -6,10 +6,15 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPackageRel;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackageRelService;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -20,8 +25,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.UUID;
 
@@ -40,12 +46,18 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
     private KuaishouCrowdPackMapper crowdPackMapper;
 
     @Autowired
+    private IKuaishouCrowdPackageRelService relService;
+
+    @Autowired
     private ICtopOauthTokenService tokenService;
 
     @Autowired
     private IKuaishouPopulationService iKuaishouPopulationService;
 
     @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+
+    @Autowired
     UserAllocationMapper userAllocationMapper;
 
     @Value("${zip.local.download-path}")
@@ -53,18 +65,10 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
 
 
     @Override
-    public Result<Object> queryPageList(JSONObject request) {
-        int pageNo = request.getInteger("pageNo");
-        int pageSize = request.getInteger("pageSize");
-        if (Check.isNull(pageNo)) {
-            pageNo = 1;
-        }
-        if (Check.isNull(pageSize)) {
-            pageSize = 10;
-        }
-        Long total = crowdPackMapper.getTotal(request);
+    public Result<Object> queryPageList(KuaishouCrowdPack kuaishouCrowdPack, Integer pageNo, Integer pageSize) {
+        Long total = crowdPackMapper.getTotal(kuaishouCrowdPack.getStatus(), kuaishouCrowdPack.getAccountName(), kuaishouCrowdPack.getOrientationName());
         PageHelper.startPage(pageNo, pageSize, false);
-        List<KuaishouCrowdPack> list = crowdPackMapper.queryPageList(request);
+        List<JSONObject> list = crowdPackMapper.queryPageList(kuaishouCrowdPack.getStatus(), kuaishouCrowdPack.getAccountName(), kuaishouCrowdPack.getOrientationName());
         PageInfo pageInfo = new PageInfo(list);
         pageInfo.setTotal(total);
         return Result.ok(pageInfo);
@@ -75,10 +79,7 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
         StringBuffer path = new StringBuffer();
         path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
         log.info("-------下载到服务器地址:{}", path.toString());
-        String name = url.substring(url.lastIndexOf("/") + 1);
-//        String newFileUrl = FilesUtil.writeFiles(path.toString(), url, name);
         String newFileUrl = LoadFileUtil.downLoadFromUrl(url, path.toString());
-//        String newFileUrl = url;
         String md5 = null;
         try {
             md5 = LoadFileUtil.getMD5(newFileUrl);
@@ -87,18 +88,94 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
         }
         CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
         JSONObject jsonObject = iKuaishouPopulationService.updatePopulation(token, type, orientationName, newFileUrl);
-        System.out.println("=============返回结果:"+jsonObject);
-        if (jsonObject.getInteger("code") == 0) {
-            KuaishouCrowdPack crowdPack = JSONObject.toJavaObject(jsonObject, KuaishouCrowdPack.class);
-            crowdPack.setSignature(md5);
-            crowdPack.setUrl(url);
-            this.save(crowdPack);
+        LoadFileUtil.delFile(newFileUrl);
+        if (!Check.isNull(jsonObject)) {
+            if (jsonObject.getInteger("code") == 0) {
+                KuaishouCrowdPack crowdPack = JSONObject.toJavaObject(jsonObject.getJSONObject("data"), KuaishouCrowdPack.class);
+                crowdPack.setSignature(md5);
+                crowdPack.setUrl(url);
+                crowdPack.setMessage(jsonObject.getString("message"));
+                crowdPack.setStatDate(DateUtils.formatDate(new Date()));
+                this.save(crowdPack);
+            } else {
+                KuaishouCrowdPack crowdPack = new KuaishouCrowdPack();
+                crowdPack.setSignature(md5);
+                crowdPack.setUrl(url);
+                crowdPack.setMessage(jsonObject.getString("message"));
+                crowdPack.setStatDate(DateUtils.formatDate(new Date()));
+                this.save(crowdPack);
+                return Result.error(jsonObject.getString("message"));
+            }
         }
-        return null;
+        return Result.ok("success");
     }
 
     @Override
     public Result<Object> accountPush(JSONObject request) {
+        JSONArray accountIds = request.getJSONArray("accountIds");
+        List<Long> longs = accountIds.toJavaList(Long.class);
+        Long orientationId = request.getLong("orientationId");
+        Long accountId = request.getLong("accountId");
+        CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+        QueryWrapper<KuaishouCrowdPack> wrapper = new QueryWrapper<>();
+        wrapper.eq("account_id", accountId);
+        wrapper.eq("orientation_id", orientationId);
+        KuaishouCrowdPack kuaishouCrowdPack = crowdPackMapper.selectOne(wrapper);
+        JSONObject jsonObject = iKuaishouPopulationService.pushAccountsPopulation(token, orientationId, accountIds);
+        if (jsonObject.getInteger("code") == 0) {
+            JSONObject data = jsonObject.getJSONObject("data");
+            if (!Check.isNull(data)) {
+                JSONArray success = data.getJSONArray("success");
+                List<KuaishouCrowdPackageRel> relList = new ArrayList<>();
+                for (Object account : success) {
+                    KuaishouCrowdPackageRel rel = new KuaishouCrowdPackageRel();
+                    rel.setAccountId((Long) account);
+                    rel.setTgtAccountId(accountId);
+                    rel.setMessage("OK");
+                    rel.setStatDate(DateUtils.formatDate(new Date()));
+                    rel.setOrientationId(orientationId);
+                    rel.setOrientationName(kuaishouCrowdPack.getOrientationName());
+                    relList.add(rel);
+                }
+                JSONArray fail = data.getJSONArray("fail");
+                for (Object account : fail) {
+                    KuaishouCrowdPackageRel rel = new KuaishouCrowdPackageRel();
+                    rel.setAccountId((Long) account);
+                    rel.setTgtAccountId(accountId);
+                    rel.setMessage(jsonObject.getString("message"));
+                    rel.setStatDate(DateUtils.formatDate(new Date()));
+                    rel.setOrientationId(orientationId);
+                    rel.setOrientationName(kuaishouCrowdPack.getOrientationName());
+                    relList.add(rel);
+                }
+                relService.saveBatch(relList);
+            }
+        }
+        return Result.ok("success");
+    }
+
+    @Override
+    public void crowdListQuery() {
+        List<KuaishouCrowdPack> crowdList = crowdPackMapper.queryListByStatus();
+        for (int i = 0; i <= 7; i++) {
+            for (KuaishouCrowdPack crowdPack : crowdList) {
+                CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
+                JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), i);
+                if (jsonObject.getInteger("code") == 0) {
+                    JSONObject data = jsonObject.getJSONObject("data");
+                    if (!Check.isNull(data)) {
+                        JSONArray details = data.getJSONArray("details");
+                        if (details.size() > 0) {
+                            crowdPackMapper.updateBatch(details);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public Result<Object> queryRel(String type, Long orientationId, Long accountId, Integer pageNo, Integer pageSize) {
         return null;
     }
 }

+ 19 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouCrowdPackageRelServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPackageRel;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackageRelMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackageRelService;
+import org.springframework.stereotype.Service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+
+/**
+ * 人群推送账户
+ * @author jeecg-boot
+ * @date   2021-03-30
+ * @version V1.0
+ */
+@Service
+public class KuaishouCrowdPackageRelServiceImpl extends ServiceImpl<KuaishouCrowdPackageRelMapper, KuaishouCrowdPackageRel> implements IKuaishouCrowdPackageRelService {
+
+}

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

@@ -2,6 +2,7 @@ package cn.com.ctop.kuaishou.modules.batch.service;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.web.multipart.MultipartFile;
@@ -61,7 +62,7 @@ public interface IKuaishouPopulationService extends IService<KuaishouPopulation>
      * @param ids          要推送的账户ids
      * @return
      */
-    boolean pushAccountsPopulation(Long accountId, String populationId, Long[] ids, String accessToken);
+    JSONObject pushAccountsPopulation(CtopOauthToken token, Long orientationId, JSONArray accountIds);
 
     /**
      * 游戏精选标签人群包
@@ -72,6 +73,7 @@ public interface IKuaishouPopulationService extends IService<KuaishouPopulation>
      */
     JSONObject selectGameTags(String accessToken);
 
+    JSONObject getPopulationList(Long accountId, String accessToken,Integer status);
     /**
      * 游戏精选标签人群包
      * 游戏精选标签创建

+ 31 - 11
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouPopulationServiceImpl.java

@@ -9,6 +9,7 @@ import cn.com.ctop.kuaishou.modules.batch.entity.KuaishouPopulation;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouPopulationMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
@@ -38,6 +39,27 @@ public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulatio
     @Autowired
     private IKuaishouInterfaceService kuaishouInterfaceService;
 
+
+    @Override
+    public JSONObject getPopulationList(Long accountId, String accessToken, Integer status) {
+        log.info("获取人群包列表,accountId:{}", accountId);
+        String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.POPULATION_LIST;
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        headers.put("Content-Type", "application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", accountId);
+        requestJson.put("status", status);
+        requestJson.put("page", 1);
+        requestJson.put("page_size", 500);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            return resultJson;
+        }
+        return null;
+    }
+
     /**
      * 获取人群包接口
      *
@@ -83,14 +105,13 @@ public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulatio
         String url = urlPath + KuaishouInterfaceConstant.POPULATION_UPLOAD;
         Map<String, String> headerMap = new HashMap<>();
         headerMap.put("Access-Token", token.getAccessToken());
-        headerMap.put("Content-Type", "application/json");
+        headerMap.put("Content-Type", "multipart/form-data");
         JSONObject requestJson = new JSONObject();
         Map<String, Object> paramMap = new HashMap<>();
         paramMap.put("advertiser_id", token.getAccountId());
         paramMap.put("type", type);
         paramMap.put("orientation_name", populationName);
         String result = kuaishouInterfaceService.exceptInfoForRestTemplate(url, paramMap, headerMap, filePath);
-        System.out.println("------------------返回结果2:"+result);
         if (!Check.isNull(result)) {
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
@@ -138,23 +159,22 @@ public class KuaishouPopulationServiceImpl extends ServiceImpl<KuaishouPopulatio
      * @return
      */
     @Override
-    public boolean pushAccountsPopulation(Long accountId, String populationId, Long[] ids, String accessToken) {
-        log.info("推送人群包,accountId:{}", accountId);
+    public JSONObject pushAccountsPopulation(CtopOauthToken token, Long orientationId, JSONArray accountIds) {
+        log.info("推送人群包,accountId:{}", token.getAccountId());
         String url = urlPath + KuaishouInterfaceConstant.POPULATION_PUSH_ACCOUNTS;
         Map<String, String> headers = new HashMap<>();
-        headers.put("Access-Token", accessToken);
+        headers.put("Access-Token", token.getAccessToken());
         headers.put("Content-Type", "application/json");
         JSONObject requestJson = new JSONObject();
-        requestJson.put("advertiser_id", accountId);
-        requestJson.put("orientation_id", populationId);
-        requestJson.put("dest_account_ids", ids);
+        requestJson.put("advertiser_id", token.getAccountId());
+        requestJson.put("orientation_id", orientationId);
+        requestJson.put("dest_account_ids", accountIds);
         String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
         JSONObject resultJson = JSONObject.parseObject(result);
         if (!Check.isNull(resultJson)) {
-            Integer code = resultJson.getInteger("code");
-            return code == 0;
+            return resultJson;
         }
-        return false;
+        return null;
     }
 
     /**