Prechádzať zdrojové kódy

定向包~创建、推送、查询功能

zhaoxian 4 rokov pred
rodič
commit
c4dda06ab1
14 zmenil súbory, kde vykonal 480 pridanie a 223 odobranie
  1. 9 4
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  2. 32 45
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouDirectionalPackageController.java
  3. 1 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouDirectionalPackage.java
  4. 81 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouDirectionalTemplateRel.java
  5. 8 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouDirectionalPackageMapper.java
  6. 17 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouDirectionalTemplateRelMapper.java
  7. 51 16
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouDirectionalPackageMapper.xml
  8. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouDirectionalTemplateRelMapper.xml
  9. 4 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouDirectionalPackageService.java
  10. 14 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouDirectionalTemplateRelService.java
  11. 201 148
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouDirectionalPackageServiceImpl.java
  12. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouDirectionalTemplateRelServiceImpl.java
  13. 2 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateService.java
  14. 36 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java

+ 9 - 4
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -85,6 +85,11 @@ public class KuaishouInterfaceConstant {
     public static final String TEMPLATE_CREATE = "/rest/openapi/v1/target/template/create";
 
     public static final String TEMPLATE_UPDATE = "/rest/openapi/v1/target/template/update";
+
+    /**
+     * 删除定向模板
+     */
+    public static final String TEMPLATE_DELETE = "/rest/openapi/v1/target/template/delete";
     /**
      * 获取行为与兴趣"类目"
      */
@@ -333,19 +338,19 @@ public class KuaishouInterfaceConstant {
      * 频库-视频关联创意数查询
      */
     public static final String VIDEO_RELATE_CREATIVES = "/rest/openapi/v1/file/ad/video/relate/creatives";
-/**
+    /**
      * 查询加速探索信息接口
      */
     public static final String UNIT_EXPLORE_INFO_GET = "/rest/openapi/v1/ad_unit/explore/info/get";
-/**
+    /**
      * 广告组的加速探索预算设置
      */
     public static final String UNIT_EXPLORE_BUDGET_UPDATE = "/rest/openapi/v1/ad_unit/explore/budget/update";
-/**
+    /**
      * 暂停广告组的加速探索预算
      */
     public static final String UNIT_EXPLORE_STATUS_PAUSE = "/rest/openapi/v1/ad_unit/explore/status/pause";
-/**
+    /**
      * 查询广告组的加速探索报表接口
      */
     public static final String QUERY_SPEED_EXPLORE_REPORT = "/rest/openapi/v1/report/speed_explore";

+ 32 - 45
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaishouDirectionalPackageController.java

@@ -104,10 +104,10 @@ public class KuaishouDirectionalPackageController {
         try {
             return kuaishouDirectionalPackageService.queryList(directionalPackage, pageNo, pageSize);
         } catch (Exception e) {
-            log.error("查询异常,", e.getMessage());
-            e.printStackTrace();
+            log.error("查询异常,", e);
+            return Result.error("查询失败," + e.getMessage());
         }
-        return Result.error("查询失败");
+
     }
 
     /**
@@ -120,25 +120,20 @@ public class KuaishouDirectionalPackageController {
      * @author ZHAOXA
      */
     @GetMapping(value = "/getRelatedAccountGroup")
-    public Result<Object> getRelatedAccountGroup(Long projectId, Long templateId, Integer type,
-                                                 @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
-                                                 @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+    public Result<Object> getRelatedAccountGroup(String id, Integer type, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
         try {
-            if (Check.isNull(templateId)) {
+            if (Check.isNull(id)) {
                 return Result.error("请选择人群包");
             }
-            if (Check.isNull(projectId)) {
-                return Result.error("请选择项目");
-            }
             if (Check.isNull(type)) {
                 return Result.error("请选择查询类型");
             }
-            return kuaishouDirectionalPackageService.getRelatedAccountGroup(projectId, templateId, type, pageNo, pageSize);
+            return kuaishouDirectionalPackageService.getRelatedAccountGroup(id, type, pageNo, pageSize);
         } catch (Exception e) {
-            log.error("查询异常,", e.getMessage());
-            e.printStackTrace();
+            log.error("查询异常,", e);
+            return Result.error("查询失败");
         }
-        return Result.error("查询失败");
+
     }
 
     /**
@@ -216,10 +211,9 @@ public class KuaishouDirectionalPackageController {
             }
             return kuaishouDirectionalPackageService.createDirectionalPackage(oauthToken.getAccessToken(), requestJson);
         } catch (Exception e) {
-            result.setSuccess(false);
-            result.setMessage(e.getMessage());
+            log.error("创建定向包失败", e);
+            return Result.error("创建失败" + e.getMessage());
         }
-        return Result.error("上传失败");
     }
 
     /**
@@ -264,19 +258,15 @@ public class KuaishouDirectionalPackageController {
     public Result<Object> pushDirectionalPackage(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
         try {
-            Long accountId = requestJson.getLong("accountId");
-            Long templateId = requestJson.getLong("templateId");
-            JSONArray ids = requestJson.getJSONArray("ids");
-            if (Check.isNull(templateId)) {
+            String id = requestJson.getString("id");
+            JSONArray accountIds = requestJson.getJSONArray("accountIds");
+            if (Check.isNull(id)) {
                 return Result.error("请选择人群包");
             }
-            if (Check.isNull(accountId)) {
-                return Result.error("请选择目标账户");
-            }
-            if (Check.isNull(ids)) {
+            if (Check.isNull(accountIds)) {
                 return Result.error("请选择推送账户");
             }
-            return kuaishouDirectionalPackageService.pushDirectionalPackage(accountId, templateId, ids);
+            return kuaishouDirectionalPackageService.pushDirectionalPackage(id, accountIds);
         } catch (Exception e) {
             result.setSuccess(false);
             result.setMessage(e.getMessage());
@@ -284,6 +274,22 @@ public class KuaishouDirectionalPackageController {
         return Result.error("上传失败");
     }
 
+    /**
+     * 删除定向模板
+     *
+     * @param
+     * @return org.jeecg.common.api.vo.Result<?>
+     * @throws
+     * @author ZHAOXA
+     */
+    @GetMapping(value = "/delete")
+    public Result<Object> delete(Long accountId, Long templateId) {
+        try {
+            return kuaishouDirectionalPackageService.delete(accountId, templateId);
+        } catch (Exception e) {
+            return Result.error("删除失败!");
+        }
+    }
 
     /**
      * 添加
@@ -331,25 +337,6 @@ public class KuaishouDirectionalPackageController {
     }
 
     /**
-     * 通过id删除
-     *
-     * @param id
-     * @return
-     */
-    @AutoLog(value = "自动投放-定向包详情-通过id删除")
-    @ApiOperation(value = "自动投放-定向包详情-通过id删除", notes = "自动投放-定向包详情-通过id删除")
-    @DeleteMapping(value = "/delete")
-    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
-        try {
-            kuaishouDirectionalPackageService.removeById(id);
-        } catch (Exception e) {
-            log.error("删除失败", e.getMessage());
-            return Result.error("删除失败!");
-        }
-        return Result.ok("删除成功!");
-    }
-
-    /**
      * 批量删除
      *
      * @param ids

+ 1 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/entity/KuaishouDirectionalPackage.java

@@ -32,11 +32,7 @@ public class KuaishouDirectionalPackage {
     /**
      * 定向模板id
      */
-    @Excel(name = "定向模板id", width = 15)
-    @ApiModelProperty(value = "定向模板id")
-    private Long templateId;
-
-    private Long accountId;
+    private Long projectId;
     /**
      * 0无效,1有效
      */
@@ -252,7 +248,4 @@ public class KuaishouDirectionalPackage {
      */
     @ApiModelProperty(value = "定向模板修改时间")
     private Date updateTime;
-
-    @TableField(exist = false)
-    private Long projectId;
 }

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

@@ -0,0 +1,81 @@
+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
+ * @date   2021-04-25
+ * @version V1.0
+ */
+@Data
+@TableName("ctop_kuaishou_directional_template_rel")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="ctop_kuaishou_directional_template_rel对象", description="自动投放-定向包详情关系表")
+public class KuaishouDirectionalTemplateRel {
+    
+	/**id*/
+	@TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+	private Long id;
+	/**本地定向模板ID*/
+	@Excel(name = "本地定向模板ID", width = 15)
+    @ApiModelProperty(value = "本地定向模板ID")
+	private String dirId;
+	/**项目ID*/
+	@Excel(name = "项目ID", width = 15)
+    @ApiModelProperty(value = "项目ID")
+	private Long projectId;
+	/**定向模板id*/
+	@Excel(name = "定向模板id", width = 15)
+    @ApiModelProperty(value = "定向模板id")
+	private Long templateId;
+	/**人群包名*/
+	@Excel(name = "人群包名", width = 15)
+    @ApiModelProperty(value = "人群包名")
+	private String templateName;
+	/**账户ID*/
+	@Excel(name = "账户ID", width = 15)
+    @ApiModelProperty(value = "账户ID")
+	private Long relId;
+	/**绑定类型,account 账户,unit 组*/
+	@Excel(name = "绑定类型,account 账户,unit 组", width = 15)
+    @ApiModelProperty(value = "绑定类型,account 账户,unit 组")
+	private String relType;
+	/**排除人群包*/
+	@Excel(name = "排除人群包", width = 15)
+    @ApiModelProperty(value = "排除人群包")
+	private String excludePopulation;
+	/**付费人群包*/
+	@Excel(name = "付费人群包", width = 15)
+    @ApiModelProperty(value = "付费人群包")
+	private String paidAudience;
+	/**定向人群包*/
+	@Excel(name = "定向人群包", width = 15)
+    @ApiModelProperty(value = "定向人群包")
+	private String population;
+	/**结果说明*/
+	@Excel(name = "结果说明", width = 15)
+    @ApiModelProperty(value = "结果说明")
+	private String message;
+	/**定向模板创建时间*/
+    @ApiModelProperty(value = "定向模板创建时间")
+	private Date createTime;
+	/**定向模板修改时间*/
+    @ApiModelProperty(value = "定向模板修改时间")
+	private Date updateTime;
+}

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

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.ai.mapper;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalPackage;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -15,7 +16,14 @@ import java.util.List;
  */
 public interface KuaishouDirectionalPackageMapper extends BaseMapper<KuaishouDirectionalPackage> {
 
+    KuaishouDirectionalPackage queryEntity(JSONObject requestJson);
+
     List<JSONObject> queryList(KuaishouDirectionalPackage directionalPackage);
 
     Long queryListTotal(KuaishouDirectionalPackage directionalPackage);
+
+    List<JSONObject> getRelatedAccountGroup(@Param("id") String id,@Param("type") Integer type);
+
+    int delete(@Param("accountId") Long accountId, @Param("templateId") Long templateId);
+
 }

+ 17 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouDirectionalTemplateRelMapper.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.KuaishouDirectionalTemplateRel;
+import org.apache.ibatis.annotations.Param;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 自动投放-定向包详情关系表
+ * @author: jeecg-boot
+ * @date:   2021-04-25
+ * @cersion: V1.0
+ */
+public interface KuaishouDirectionalTemplateRelMapper extends BaseMapper<KuaishouDirectionalTemplateRel> {
+
+}

+ 51 - 16
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouDirectionalPackageMapper.xml

@@ -2,22 +2,41 @@
 <!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.KuaishouDirectionalPackageMapper">
 
+    <select id="queryEntity" resultType="cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalPackage">
+        SELECT project_id,template_name from ctop_kuaishou_directional_package
+        WHERE  data_status = 1
+        <if test="projectId != null">
+            and  project_id = #{projectId}
+        </if>
+        <if test="templateName != null">
+            and  template_name = #{templateName}
+        </if>
+        limit 1
+    </select>
     <select id="queryList" resultType="com.alibaba.fastjson.JSONObject">
         SELECT
+        t1.id,
         t1.template_id 'templateId',
         t1.template_name 'templateName',
-        t3.project_name 'projectName',
+        t2.project_name 'projectName',
         CASE WHEN t1.platform_os =1 THEN 'Android' WHEN t1.platform_os =2 THEN 'iOS' ELSE '-' END 'platformOs',
         t1.update_time 'updateTime',
         IFNULL(t4.count,0) as 'accountCount',
-        '-' as 'unitCount'
+        IFNULL(t5.count,0) as 'unitCount'
         FROM ctop_kuaishou_directional_package t1
-        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
-        LEFT JOIN ctop_project t3 ON t3.id = t2.project_id
+        LEFT JOIN ctop_project t2 ON t2.id = t1.project_id
         LEFT JOIN (
-        SELECT template_id,COUNT(1) 'count' FROM
-        ctop_kuaishou_template GROUP BY template_id
-        ) t4 ON t4.template_id = t1.template_id
+        SELECT dir_id,COUNT(1) 'count' FROM
+        ctop_kuaishou_directional_template_rel
+        WHERE rel_type = 'account'
+        GROUP BY dir_id
+        ) t4 ON t4.dir_id = t1.id
+        LEFT JOIN (
+        SELECT dir_id,COUNT(1) 'count' FROM
+        ctop_kuaishou_directional_template_rel
+        WHERE rel_type = 'unit'
+        GROUP BY dir_id
+        ) t5 ON t5.dir_id = t1.id
         where t1.data_status = 1
         <if test="templateName !=null">
             AND t1.template_name like concat('%',#{templateName},'%')
@@ -26,18 +45,15 @@
             AND t1.platform_os = #{platformOs}
         </if>
         <if test="projectId !=null">
-            AND t3.project_id = #{projectId}
+            AND t2.project_id = #{projectId}
         </if>
-        GROUP BY t1.template_id
+        order by t1.update_time desc
     </select>
     <select id="queryListTotal" resultType="java.lang.Long">
         SELECT
         IFNULL(count(1),0)
-        from(
-        select t1.template_id
         FROM ctop_kuaishou_directional_package t1
-        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
-        LEFT JOIN ctop_project t3 ON t3.id = t2.project_id
+        LEFT JOIN ctop_project t2 ON t2.id = t1.project_id
         where t1.data_status = 1
         <if test="templateName !=null">
             AND t1.template_name like concat('%',#{templateName},'%')
@@ -46,9 +62,28 @@
             AND t1.platform_os = #{platformOs}
         </if>
         <if test="projectId !=null">
-            AND t3.project_id = #{projectId}
+            AND t2.project_id = #{projectId}
+        </if>
+    </select>
+
+
+    <select id="getRelatedAccountGroup" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            IFNULL(t2.auth_name,'') as 'authName',
+            IFNULL(t2.account_id,'') as 'accountId',
+            IFNULL(t1.template_id,'') as 'templateId'
+        FROM ctop_kuaishou_directional_template_rel t1
+            <if test=" type ==1 ">
+        INNER JOIN ctop_user_allocation t2 ON t1.rel_id = t2.account_id
+            </if>
+        <if test=" type ==2 ">
+            INNER  JOIN ctop_kuaishou_group_template t2 ON t1.rel_id = t2.unit_id
+            INNER JOIN ctop_user_allocation t3 ON t3.account_id = t3.account_id
         </if>
-        GROUP BY t1.template_id
-        ) t
+        WHERE t1.dir_id =#{id}
     </select>
+
+    <delete id="delete">
+        DELETE FROM ctop_kuaishou_directional_package where template_id= #{templateId} and account_id = #{accountId}
+    </delete>
 </mapper>

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaishouDirectionalTemplateRelMapper.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.KuaishouDirectionalTemplateRelMapper">
+
+</mapper>

+ 4 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaishouDirectionalPackageService.java

@@ -20,11 +20,13 @@ public interface IKuaishouDirectionalPackageService extends IService<KuaishouDir
 
     Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize);
 
-    Result<Object> getRelatedAccountGroup(Long projectId,Long templateId, Integer type, Integer pageNo, Integer pageSize);
+    Result<Object> getRelatedAccountGroup(String id, Integer type, Integer pageNo, Integer pageSize);
 
-    Result<Object> pushDirectionalPackage(Long accountId, Long templateId, JSONArray ids);
+    Result<Object> pushDirectionalPackage(String id, JSONArray accountIds);
 
     Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize);
 
     Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize);
+
+    Result<Object> delete(Long accountId, Long templateId);
 }

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

@@ -0,0 +1,14 @@
+package cn.com.ctop.kuaishou.modules.ai.service;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalTemplateRel;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @Description: 自动投放-定向包详情关系表
+ * @Author: jeecg-boot
+ * @Date:   2021-04-25
+ * @Version: V1.0
+ */
+public interface IKuaishouDirectionalTemplateRelService extends IService<KuaishouDirectionalTemplateRel> {
+
+}

+ 201 - 148
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaishouDirectionalPackageServiceImpl.java

@@ -1,12 +1,16 @@
 package cn.com.ctop.kuaishou.modules.ai.service.impl;
 
+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.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalPackage;
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalTemplateRel;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalPackageMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalPackageService;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalTemplateRelService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -21,6 +25,8 @@ import org.springframework.stereotype.Service;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 自动投放-定向包详情
@@ -37,16 +43,40 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
     private IKuaishouTemplateService kuaishouTemplateService;
     @Autowired
     private KuaishouDirectionalPackageMapper packageMapper;
+    @Autowired
+    private IKuaishouDirectionalTemplateRelService relService;
+    @Autowired
+    private ICtopOauthTokenService oauthTokenService;
+    static ExecutorService executorService = null;
 
     @Override
     public Result<Object> createDirectionalPackage(String accessToken, JSONObject requestJson) {
+        KuaishouDirectionalPackage entity = packageMapper.queryEntity(requestJson);
+        if (!Check.isNull(entity)) {
+            return Result.error("该账户下人群包名已存在");
+        }
+        KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
+        kuaishouDirectionalPackage.setDataStatus(1);
+        boolean save = this.save(kuaishouDirectionalPackage);
+        if (save) {
+            return Result.ok("创建成功");
+        }
+        return Result.error("创建失败,定向包存储失败");
+    }
+
+
+    @Override
+    public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
         JSONObject returnJson = new JSONObject();
         String message = "";
         int flag = -1;
         try {
             JSONObject param = new JSONObject();
+            param.put("template_id", requestJson.getLong("templateId"));
             param.put("advertiser_id", requestJson.getLong("accountId"));
-            param.put("template_name", requestJson.getString("templateName"));
+            if (!Check.isNull(requestJson.getString("templateName"))) {
+                param.put("template_name", requestJson.getString("templateName"));
+            }
             JSONObject targetJson = new JSONObject();
             if (!Check.isNull(requestJson.getJSONArray("region"))) {
                 targetJson.put("region", requestJson.getJSONArray("region"));
@@ -61,14 +91,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
                 targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
             }
 
-            JSONObject ageJson = new JSONObject();
-            if (!Check.isNull(requestJson.getInteger("min"))) {
+            if (!Check.isNull(requestJson.getInteger("min")) && !Check.isNull(requestJson.getInteger("max"))) {
+                JSONObject ageJson = new JSONObject();
                 ageJson.put("min", requestJson.getInteger("min"));
-            }
-            if (!Check.isNull(requestJson.getInteger("max"))) {
                 ageJson.put("max", requestJson.getInteger("max"));
-            }
-            if (!Check.isNull(ageJson)) {
                 targetJson.put("age", ageJson);
             }
 
@@ -123,22 +149,24 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
             if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
                 targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
             }
-            JSONObject intelliExtendJson = new JSONObject();
+
 
             if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                JSONObject intelliExtendJson = new JSONObject();
                 intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
-            }
-            if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
-                intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
-            }
-            if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
-                intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
-            }
-            if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
-                intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
-            }
-            if (!Check.isNull(intelliExtendJson)) {
-                targetJson.put("intelli_extend", intelliExtendJson);
+
+                if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
+                    intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
+                }
+                if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
+                    intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
+                }
+                if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
+                    intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
+                }
+                if (!Check.isNull(intelliExtendJson)) {
+                    targetJson.put("intelli_extend", intelliExtendJson);
+                }
             }
             if (!Check.isNull(targetJson)) {
                 param.put("target", targetJson);
@@ -176,7 +204,8 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
             Map<String, String> headers = new HashMap<String, String>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", " application/json");
-            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
+            log.info("入参:" + param);
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
@@ -186,18 +215,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
                     kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), accessToken, 1);
                     flag = code;
                     JSONObject data = resultJson.getJSONObject("data");
-                    requestJson.put("templateId", data.getLong("template_id"));
-                    requestJson.put("dataStatus", 1);
-                } else {
-                    requestJson.put("dataStatus", 0);
                 }
-            } else {
-                requestJson.put("dataStatus", 0);
-                message = "返回结果为空";
             }
-            requestJson.put("message", message);
             KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
-            this.save(kuaishouDirectionalPackage);
+            this.saveOrUpdate(kuaishouDirectionalPackage);
         } catch (Exception e) {
             e.printStackTrace();
             returnJson.put("code", -1);
@@ -211,107 +232,148 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
     }
 
     @Override
-    public Result<Object> updateDirectionalPackage(String accessToken, JSONObject requestJson) {
-        JSONObject returnJson = new JSONObject();
+    public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
+        Long total = packageMapper.queryListTotal(directionalPackage);
+        PageHelper.startPage(pageNo, pageSize, false);
+        List<JSONObject> list = packageMapper.queryList(directionalPackage);
+        PageInfo pageInfo = new PageInfo(list);
+        pageInfo.setTotal(total);
+        return Result.ok(pageInfo);
+    }
+
+    @Override
+    public Result<Object> getRelatedAccountGroup(String id, Integer type, Integer pageNo, Integer pageSize) {
+        PageHelper.startPage(pageNo, pageSize);
+        return Result.ok(new PageInfo(packageMapper.getRelatedAccountGroup(id, type)));
+    }
+
+    @Override
+    public Result<Object> pushDirectionalPackage(String id, JSONArray accountIds) {
+        KuaishouDirectionalPackage directionalPackage = packageMapper.selectById(id);
+        if (Check.isNull(directionalPackage)) {
+            return Result.error("未找到定向包");
+        }
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                try {
+                    executorService = Executors.newFixedThreadPool(3);
+                    for (int i = 0; i < accountIds.size(); i++) {
+                        Long accountId = accountIds.getLong(i);
+                        executorService.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                createDirectionalPackage(directionalPackage, accountId);
+                            }
+                        });
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        };
+        thread.start();
+        return Result.ok("推送成功");
+    }
+
+    private void createDirectionalPackage(KuaishouDirectionalPackage directionalPackage, Long accountId) {
+        CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
         String message = "";
-        int flag = -1;
         try {
             JSONObject param = new JSONObject();
-            param.put("template_id", requestJson.getLong("templateId"));
-            param.put("advertiser_id", requestJson.getLong("accountId"));
-            if (!Check.isNull(requestJson.getString("templateName"))) {
-                param.put("template_name", requestJson.getString("templateName"));
-            }
+            param.put("advertiser_id", accountId);
+            param.put("template_name", directionalPackage.getTemplateName());
             JSONObject targetJson = new JSONObject();
-            if (!Check.isNull(requestJson.getJSONArray("region"))) {
-                targetJson.put("region", requestJson.getJSONArray("region"));
+            if (!Check.isNull(directionalPackage.getRegion())) {
+                targetJson.put("region", directionalPackage.getRegion());
             }
-            if (!Check.isNull(requestJson.getJSONArray("districtIds"))) {
-                targetJson.put("district_ids", requestJson.getJSONArray("districtIds"));
+            if (!Check.isNull(directionalPackage.getDistrictIds())) {
+                targetJson.put("district_ids", directionalPackage.getDistrictIds());
             }
-            if (!Check.isNull(requestJson.getInteger("userType"))) {
-                targetJson.put("user_type", requestJson.getInteger("userType"));
+            if (!Check.isNull(directionalPackage.getUserType())) {
+                targetJson.put("user_type", directionalPackage.getUserType());
             }
-            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
-                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            if (!Check.isNull(directionalPackage.getAgesRange())) {
+                targetJson.put("ages_range", directionalPackage.getAgesRange());
             }
 
-            if (!Check.isNull(requestJson.getInteger("min")) && !Check.isNull(requestJson.getInteger("max"))) {
-                JSONObject ageJson = new JSONObject();
-                ageJson.put("min", requestJson.getInteger("min"));
-                ageJson.put("max", requestJson.getInteger("max"));
+            JSONObject ageJson = new JSONObject();
+            if (!Check.isNull(directionalPackage.getMin())) {
+                ageJson.put("min", directionalPackage.getMin());
+            }
+            if (!Check.isNull(directionalPackage.getMax())) {
+                ageJson.put("max", directionalPackage.getMax());
+            }
+            if (!Check.isNull(ageJson)) {
                 targetJson.put("age", ageJson);
             }
-
-            if (!Check.isNull(requestJson.getInteger("gender"))) {
-                targetJson.put("gender", requestJson.getInteger("gender"));
+            if (!Check.isNull(directionalPackage.getGender())) {
+                targetJson.put("gender", directionalPackage.getGender());
             }
-            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
-                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            if (!Check.isNull(directionalPackage.getPlatformOs())) {
+                targetJson.put("platform_os", directionalPackage.getPlatformOs());
             }
-            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
-                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            if (!Check.isNull(directionalPackage.getAndroidOsv())) {
+                targetJson.put("android_osv", directionalPackage.getAndroidOsv());
             }
-            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
-                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            if (!Check.isNull(directionalPackage.getIosOsv())) {
+                targetJson.put("ios_osv", directionalPackage.getIosOsv());
             }
-            if (!Check.isNull(requestJson.getInteger("network"))) {
-                targetJson.put("network", requestJson.getInteger("network"));
+            if (!Check.isNull(directionalPackage.getNetwork())) {
+                targetJson.put("network", directionalPackage.getNetwork());
             }
-            if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
-                targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
+            if (!Check.isNull(directionalPackage.getFilterConvertedLevel())) {
+                targetJson.put("filter_converted_level", directionalPackage.getFilterConvertedLevel());
             }
-            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
-                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            if (!Check.isNull(directionalPackage.getDeviceBrand())) {
+                targetJson.put("device_brand", directionalPackage.getDeviceBrand());
             }
-            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
-                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            if (!Check.isNull(directionalPackage.getDevicePrice())) {
+                targetJson.put("device_price", directionalPackage.getDevicePrice());
             }
-            if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
-                targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+            if (!Check.isNull(directionalPackage.getBusinessInterestType())) {
+                targetJson.put("business_interest_type", directionalPackage.getBusinessInterestType());
             }
-            if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
-                targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+            if (!Check.isNull(directionalPackage.getBusinessInterest())) {
+                targetJson.put("business_interest", directionalPackage.getBusinessInterest());
             }
-            if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
-                targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+            if (!Check.isNull(directionalPackage.getFansStar())) {
+                targetJson.put("fans_star", directionalPackage.getFansStar());
             }
-            if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
-                targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+            if (!Check.isNull(directionalPackage.getInterestVideo())) {
+                targetJson.put("interest_video", directionalPackage.getInterestVideo());
             }
-            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
-                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            if (!Check.isNull(directionalPackage.getAppInterest())) {
+                targetJson.put("app_interest", directionalPackage.getAppInterest());
             }
-            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
-                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            if (!Check.isNull(directionalPackage.getAppIds())) {
+                targetJson.put("app_ids", directionalPackage.getAppIds());
             }
-            if (!Check.isNull(requestJson.getJSONArray("population"))) {
-                targetJson.put("population", requestJson.getJSONArray("population"));
+            if (!Check.isNull(directionalPackage.getPopulation())) {
+                targetJson.put("population", directionalPackage.getPopulation());
             }
-            if (!Check.isNull(requestJson.getJSONArray("paidAudience"))) {
-                targetJson.put("paid_audience", requestJson.getJSONArray("paidAudience"));
+            if (!Check.isNull(directionalPackage.getPaidAudience())) {
+                targetJson.put("paid_audience", directionalPackage.getPaidAudience());
             }
-            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
-                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            if (!Check.isNull(directionalPackage.getExcludePopulation())) {
+                targetJson.put("exclude_population", directionalPackage.getExcludePopulation());
             }
+            JSONObject intelliExtendJson = new JSONObject();
 
-
-            if (!Check.isNull(requestJson.getInteger("isOpen"))) {
-                JSONObject intelliExtendJson = new JSONObject();
-                intelliExtendJson.put("is_open", requestJson.getInteger("isOpen"));
-
-                if (!Check.isNull(requestJson.getInteger("noAgeBreak"))) {
-                    intelliExtendJson.put("no_age_break", requestJson.getInteger("noAgeBreak"));
-                }
-                if (!Check.isNull(requestJson.getInteger("noGenderBreak"))) {
-                    intelliExtendJson.put("no_gender_break", requestJson.getInteger("noGenderBreak"));
-                }
-                if (!Check.isNull(requestJson.getInteger("noAreaBreak"))) {
-                    intelliExtendJson.put("no_area_break", requestJson.getInteger("noAreaBreak"));
-                }
-                if (!Check.isNull(intelliExtendJson)) {
-                    targetJson.put("intelli_extend", intelliExtendJson);
-                }
+            if (!Check.isNull(directionalPackage.getIsOpen())) {
+                intelliExtendJson.put("is_open", directionalPackage.getIsOpen());
+            }
+            if (!Check.isNull(directionalPackage.getNoAgeBreak())) {
+                intelliExtendJson.put("no_age_break", directionalPackage.getNoAgeBreak());
+            }
+            if (!Check.isNull(directionalPackage.getNoGenderBreak())) {
+                intelliExtendJson.put("no_gender_break", directionalPackage.getNoGenderBreak());
+            }
+            if (!Check.isNull(directionalPackage.getNoAreaBreak())) {
+                intelliExtendJson.put("no_area_break", directionalPackage.getNoAreaBreak());
+            }
+            if (!Check.isNull(intelliExtendJson)) {
+                targetJson.put("intelli_extend", intelliExtendJson);
             }
             if (!Check.isNull(targetJson)) {
                 param.put("target", targetJson);
@@ -319,23 +381,23 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
             JSONObject behaviorInterest = new JSONObject();
             JSONObject behavior = new JSONObject();
             JSONObject interest = new JSONObject();
-            if (!Check.isNull(requestJson.getJSONArray("keyword"))) {
-                behavior.put("keyword", requestJson.getJSONArray("keyword"));
+            if (!Check.isNull(directionalPackage.getKeyword())) {
+                behavior.put("keyword", directionalPackage.getKeyword());
             }
-            if (!Check.isNull(requestJson.getJSONArray("label"))) {
-                behavior.put("label", requestJson.getJSONArray("label"));
+            if (!Check.isNull(directionalPackage.getLabel())) {
+                behavior.put("label", directionalPackage.getLabel());
             }
-            if (!Check.isNull(requestJson.getInteger("strengthType"))) {
-                behavior.put("strength_type", requestJson.getInteger("strengthType"));
+            if (!Check.isNull(directionalPackage.getStrengthType())) {
+                behavior.put("strength_type", directionalPackage.getStrengthType());
             }
-            if (!Check.isNull(requestJson.getInteger("timeType"))) {
-                behavior.put("time_type", requestJson.getInteger("timeType"));
+            if (!Check.isNull(directionalPackage.getTimeType())) {
+                behavior.put("time_type", directionalPackage.getTimeType());
             }
-            if (!Check.isNull(requestJson.getJSONArray("sceneType"))) {
-                behavior.put("scene_type", requestJson.getJSONArray("sceneType"));
+            if (!Check.isNull(directionalPackage.getSceneType())) {
+                behavior.put("scene_type", directionalPackage.getSceneType());
             }
-            if (!Check.isNull(requestJson.getJSONArray("interestLabel"))) {
-                interest.put("label", requestJson.getJSONArray("interestLabel"));
+            if (!Check.isNull(directionalPackage.getInterestLabel())) {
+                interest.put("label", directionalPackage.getInterestLabel());
             }
             if (!Check.isNull(behavior)) {
                 behaviorInterest.put("behavior", behavior);
@@ -347,62 +409,53 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
                 param.put("behavior_interest", behaviorInterest);
             }
             Map<String, String> headers = new HashMap<String, String>();
-            headers.put("Access-Token", accessToken);
+            headers.put("Access-Token", oauthToken.getAccessToken());
             headers.put("Content-Type", " application/json");
-            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_UPDATE;
-            log.info("入参:" + param);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_CREATE;
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
                 message = resultJson.getString("message");
                 if (code == 0) {
-                    kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), accessToken, 1);
-                    flag = code;
+                    kuaishouTemplateService.getTemplateByAccountId(accountId, oauthToken.getAccessToken(), 1);
                     JSONObject data = resultJson.getJSONObject("data");
+                    KuaishouDirectionalTemplateRel rel = new KuaishouDirectionalTemplateRel();
+                    rel.setDirId(directionalPackage.getId());
+                    rel.setRelId(accountId);
+                    rel.setRelType("account");
+                    rel.setProjectId(directionalPackage.getProjectId());
+                    rel.setTemplateId(data.getLong("template_id"));
+                    rel.setTemplateName(directionalPackage.getTemplateName());
+                    rel.setMessage(message);
+                    relService.save(rel);
+                } else {
+                    log.error("创建定向包失败," + message);
                 }
+            } else {
+                message = "创建定向包失败,返回结果为空";
             }
-            KuaishouDirectionalPackage kuaishouDirectionalPackage = JSONObject.toJavaObject(requestJson, KuaishouDirectionalPackage.class);
-            this.saveOrUpdate(kuaishouDirectionalPackage);
         } catch (Exception e) {
-            e.printStackTrace();
-            returnJson.put("code", -1);
-            returnJson.put("message", e.getMessage());
+            log.error("创建定向包出现异常", e);
         }
-        if (flag == 0) {
-            return Result.ok(message);
-        } else {
-            return Result.error(message);
-        }
-    }
-
-    @Override
-    public Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize) {
-        Long total = packageMapper.queryListTotal(directionalPackage);
-        PageHelper.startPage(pageNo, pageSize, false);
-        List<JSONObject> list = packageMapper.queryList(directionalPackage);
-        PageInfo pageInfo = new PageInfo(list);
-        pageInfo.setTotal(total);
-        return Result.ok(pageInfo);
-    }
-
-    @Override
-    public Result<Object> getRelatedAccountGroup(Long projectId, Long templateId, Integer type, Integer pageNo, Integer pageSize) {
-        return null;
     }
 
     @Override
-    public Result<Object> pushDirectionalPackage(Long accountId, Long templateId, JSONArray ids) {
+    public Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize) {
         return null;
     }
 
     @Override
-    public Result<Object> getHistory(Long projectId, Long templateId, Integer pageNo, Integer pageSize) {
+    public Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize) {
         return null;
     }
 
     @Override
-    public Result<Object> getAccountByProjectId(Long projectId, Integer pageNo, Integer pageSize) {
-        return null;
+    public Result<Object> delete(Long accountId, Long templateId) {
+        int delete = packageMapper.delete(accountId, templateId);
+        if (delete > 0) {
+            return Result.ok("删除成功");
+        }
+        return Result.error("删除失败");
     }
 }

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

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
+
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalTemplateRel;
+import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalTemplateRelMapper;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouDirectionalTemplateRelService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 自动投放-定向包详情关系表
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-04-25
+ */
+@Service
+public class KuaishouDirectionalTemplateRelServiceImpl extends ServiceImpl<KuaishouDirectionalTemplateRelMapper, KuaishouDirectionalTemplateRel> implements IKuaishouDirectionalTemplateRelService {
+
+}

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouTemplateService.java

@@ -26,4 +26,6 @@ public interface IKuaishouTemplateService extends IService<KuaishouTemplate> {
     Result<Object> getBehaviorInterest(Long accountId);
 
     Result<Object> getKeywordQuery(JSONObject data);
+
+    Result<Object> templateDelete(Long accountId, Long templateId);
 }

+ 36 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouTemplateServiceImpl.java

@@ -628,4 +628,40 @@ public class KuaishouTemplateServiceImpl extends ServiceImpl<KuaishouTemplateMap
         }
         return Result.error("获取行为兴趣关键词失败");
     }
+
+    /**
+     * 删除定向模板
+     *
+     * @param
+     * @throws
+     * @author ZHAOXA
+     */
+    @Override
+    public Result<Object> templateDelete(Long accountId, Long templateId) {
+        try {
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TEMPLATE_DELETE;
+            Map<String, String> header = new HashMap<>();
+            header.put("Access-Token", token.getAccessToken());
+            header.put("Content-Type", "application/json");
+            JSONObject params = new JSONObject();
+            params.put("advertiser_id", accountId);
+            params.put("template_id", templateId);
+            String result = HttpUtils.httpPostRequest(url, params, header);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    return Result.ok("删除成功");
+                } else {
+                    log.info("删除定向模板失败,accountId:{},返回信息:{}", accountId, resultJson);
+                    return Result.error("删除定向模板失败," + resultJson.getString("message"));
+                }
+            }
+        } catch (Exception e) {
+            log.error("删除定向模板失败", e);
+        }
+        return Result.error("删除定向模板失败");
+    }
+
 }