浏览代码

定向包~修改定向,人群包接口开发

zhaoxian 4 年之前
父节点
当前提交
fb6dc45419

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

@@ -120,7 +120,7 @@ public class KuaishouDirectionalPackageController {
      * @author ZHAOXA
      */
     @GetMapping(value = "/getRelatedAccountGroup")
-    public Result<Object> getRelatedAccountGroup(String id, Integer type, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
+    public Result<Object> getRelatedAccountGroup(String id, Integer type, Long accountId, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
         try {
             if (Check.isNull(id)) {
                 return Result.error("请选择人群包");
@@ -128,7 +128,7 @@ public class KuaishouDirectionalPackageController {
             if (Check.isNull(type)) {
                 return Result.error("请选择查询类型");
             }
-            return kuaishouDirectionalPackageService.getRelatedAccountGroup(id, type, pageNo, pageSize);
+            return kuaishouDirectionalPackageService.getRelatedAccountGroup(id, type, accountId, pageNo, pageSize);
         } catch (Exception e) {
             log.error("查询异常,", e);
             return Result.error("查询失败");
@@ -144,8 +144,8 @@ public class KuaishouDirectionalPackageController {
      * @throws
      * @author ZHAOXA
      */
-    @PostMapping(value = "/updatePopulation")
-    public Result<Object> updatePopulation(@RequestBody JSONObject requestJson) {
+    @PostMapping(value = "/editPopulation")
+    public Result<Object> editPopulation(@RequestBody JSONObject requestJson) {
         try {
             if (Check.isNull(requestJson.getString("id"))) {
                 return Result.error("请选择人群包");
@@ -159,7 +159,7 @@ public class KuaishouDirectionalPackageController {
             if (Check.isNull(requestJson.getString("templateName"))) {
                 return Result.error("未获取到定向包名称");
             }
-            return kuaishouDirectionalPackageService.updatePopulation(requestJson);
+            return kuaishouDirectionalPackageService.editPopulation(requestJson);
         } catch (Exception e) {
             log.error("查询异常,", e.getMessage());
             e.printStackTrace();

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

@@ -22,6 +22,7 @@ public interface KuaishouDirectionalPackageMapper extends BaseMapper<KuaishouDir
 
     Long queryListTotal(KuaishouDirectionalPackage directionalPackage);
 
-    List<JSONObject> getRelatedAccountGroup(@Param("id") String id,@Param("type") Integer type);
+    List<JSONObject> getRelatedAccount(@Param("id") String id);
 
+    List getRelatedGroup(@Param("id") String id, @Param("accountId") Long accountId);
 }

+ 10 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaishouDirectionalTemplateRelMapper.java

@@ -1,26 +1,29 @@
 package cn.com.ctop.kuaishou.modules.ai.mapper;
 
-import java.util.List;
-
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouDirectionalTemplateRel;
 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-04-25
+ * @date: 2021-04-25
  * @cersion: V1.0
  */
 public interface KuaishouDirectionalTemplateRelMapper extends BaseMapper<KuaishouDirectionalTemplateRel> {
 
     void replace(KuaishouDirectionalTemplateRel rel);
 
-    List<JSONObject> queryPushResults(@Param("id")String id, @Param("accountIds")JSONArray accountIds);
+    List<JSONObject> queryPushResults(@Param("id") String id, @Param("accountIds") JSONArray accountIds);
+
+    List<JSONObject> getAccountByProjectId(@Param("projectId") Long projectId, @Param("id") String id);
 
-    List<JSONObject> getAccountByProjectId(@Param("projectId") Long projectId,@Param("id") String id);
+    List<JSONObject> queryRelId(@Param("projectId") Long projectId, @Param("id") String id, @Param("type") String type);
 
-    List<JSONObject> queryRelId(@Param("projectId") Long projectId,@Param("id") String id,@Param("type") String type);
+    List<JSONObject> queryUnitIdByAccountId(@Param("id") String id,@Param("accountId")  Long accountId);
 }

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

@@ -65,22 +65,29 @@
     </select>
 
 
-    <select id="getRelatedAccountGroup" resultType="com.alibaba.fastjson.JSONObject">
-        SELECT
-        t1.dir_id as 'id',
-        IFNULL(t2.auth_name,'') as 'authName',
-        IFNULL(t2.account_id,'') as 'accountId',
-        IFNULL(t1.template_id,'') as 'templateId',
-        IFNULL(t1.template_name,'') as 'templateName'
+    <select id="getRelatedAccount" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.dir_id as 'id', IFNULL(t2.auth_name, '') as 'authName', IFNULL(t2.account_id, '') as 'accountId', IFNULL(t1.template_id, '') as 'templateId', IFNULL(t1.template_name, '') as 'templateName'
         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 t3 ON t1.rel_id = t3.unit_id
-            INNER JOIN ctop_user_allocation t2 ON t2.account_id = t3.account_id
-        </if>
+                 INNER JOIN ctop_user_allocation t2 ON t1.rel_id = t2.account_id
         WHERE t1.data_status = 1
-        AND t1.dir_id =#{id}
+          AND t1.dir_id = #{id}
+    </select>
+
+    <select id="getRelatedGroup" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+        t2.dir_id as 'id',
+        IFNULL(t3.auth_name,'') as 'authName',
+        IFNULL(t1.account_id,'') as 'accountId',
+        IFNULL(t2.template_id,'') as 'templateId',
+        t1.unit_name
+        FROM ctop_kuaishou_directional_template_rel t2
+        LEFT JOIN ( SELECT account_id,unit_id,unit_name FROM ctop_kuaishou_group
+        where 1=1
+        <if test="accountId!=null">
+            account_id = #{accountId}
+        </if>
+        ) t1 ON t1.unit_id = t2.rel_id
+        LEFT JOIN ctop_user_allocation t3 ON t1.account_id = t3.account_id
+        WHERE t2.rel_type = 'unit' AND t2.dir_id =#{id}
     </select>
 </mapper>

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

@@ -83,4 +83,13 @@
           AND rel_type = #{type}
           AND dir_id = #{id}
     </select>
+
+    <select id="queryUnitIdByAccountId" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT rel_id,template_id FROM(
+       SELECT DISTINCT unit_id FROM ctop_kuaishou_group
+       where account_id = #{accountId} ) t1
+       INNER JOIN ctop_kuaishou_directional_template_rel t2 ON t1.unit_id = t2.rel_id
+        WHERE t2.rel_type = 'unit' AND t2.dir_id = #{id}
+    </select>
+
 </mapper>

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

@@ -16,18 +16,32 @@ public interface IKuaishouDirectionalPackageService extends IService<KuaishouDir
 
     Result<Object> createDirectionalPackage(JSONObject requestJson);
 
-    Result<Object> updateDirectionalPackage(JSONObject requestJson);
+    Result<Object> updateDirectionalPackage(JSONObject requestJson) throws InterruptedException;
 
     Result<Object> queryList(KuaishouDirectionalPackage directionalPackage, Integer pageNo, Integer pageSize);
 
-    Result<Object> getRelatedAccountGroup(String id, Integer type, Integer pageNo, Integer pageSize);
+    Result<Object> getRelatedAccountGroup(String id, Integer type,Long accountId, Integer pageNo, Integer pageSize);
 
     Result<Object> pushDirectionalPackage(String id, JSONArray datas);
 
     Result<Object> queryPushResults(String id, JSONArray accountIds);
 
-    Result<Object> updatePopulation(JSONObject requestJson);
+    Result<Object> editPopulation(JSONObject requestJson);
 
     Result<Object> getAccountByProjectId(Long projectId, String id);
 
+    /**
+     * 添加广告组和定向模板绑定关系
+     *
+     * @param unitId            广告组Id
+     * @param templateId        模板Id
+     * @param population        定向人群包
+     * @param paidAudience      付费人群包
+     * @param excludePopulation 排除人群包
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
+    void createUnitAndTemplate(JSONObject request) throws Exception;
+
 }

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

@@ -12,6 +12,10 @@ import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalPackageMapper;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouDirectionalTemplateRelMapper;
 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.entity.KuaiShouGroup;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaishouTemplateMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouTemplateService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -21,6 +25,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -51,6 +56,12 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
     private IKuaishouDirectionalTemplateRelService relService;
     @Autowired
     private ICtopOauthTokenService oauthTokenService;
+    @Autowired
+    private KuaishouTemplateMapper templateMapper;
+    @Autowired
+    private IKuaiShouUpdateService updateService;
+    @Autowired
+    private KuaiShouGroupMapper groupMapper;
 
     static ExecutorService executorService = null;
 
@@ -74,7 +85,7 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
 
 
     @Override
-    public Result<Object> updateDirectionalPackage(JSONObject requestJson) {
+    public Result<Object> updateDirectionalPackage(JSONObject requestJson) throws InterruptedException {
         KuaishouDirectionalPackage entity = packageMapper.selectById(requestJson.getString("id"));
         if (Check.isNull(entity)) {
             return Result.error("未获取到定向包");
@@ -87,49 +98,31 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
         //获取本项目绑定该定向的账户
         List<JSONObject> accounts = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "account");
         if (!Check.isNull(accounts)) {
-            Thread thread = new Thread() {
-                @Override
-                public void run() {
-                    executorService = Executors.newFixedThreadPool(3);
-                    accounts.forEach(accountEntity -> {
-                        executorService.submit(new Runnable() {
-                            @Override
-                            public void run() {
-                                try {
-                                    updateAccountsDirectionalPackage(requestJson, accountEntity);
-                                } catch (Exception e) {
-                                    e.printStackTrace();
-                                }
-                            }
-                        });
-                    });
-                    log.info("快手物料数据同步完成");
-                }
-            };
-            thread.start();
+            for (JSONObject account : accounts) {
+                updateAccountsDirectionalPackage(requestJson, account);
+            }
         }
+        Thread.sleep(300);
         //获取本项目绑定该定向的广告组
-        List<JSONObject> unitIds = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "unit");
-        if (!Check.isNull(unitIds)) {
+        List<JSONObject> units = relMapper.queryRelId(requestJson.getLong("projectId"), requestJson.getString("id"), "unit");
+        if (!Check.isNull(units)) {
             Thread thread = new Thread() {
                 @Override
                 public void run() {
                     executorService = Executors.newFixedThreadPool(3);
-                    unitIds.forEach(unitId -> {
+                    units.forEach(unit -> {
                         executorService.submit(new Runnable() {
                             @Override
                             public void run() {
                                 try {
-                                    //TODO
-                                    System.out.println("修改广告组定向");
-    //                                    updateAccountsDirectionalPackage(requestJson, accountId);
+                                    updateUnitsDirectionalPackage(requestJson, unit);
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }
                             }
                         });
                     });
-                    log.info("快手物料数据同步完成");
+                    log.info("修改广告组定向完成");
                 }
             };
             thread.start();
@@ -137,6 +130,218 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
         return Result.ok("该项目下定向包已做同步修改");
     }
 
+    private void updateUnitsDirectionalPackage(JSONObject requestJson, JSONObject unit) {
+        try {
+            Long unitId = unit.getLong("rel_id");
+            QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper();
+            queryWrapper.eq("unit_id", unitId);
+            queryWrapper.last("limit 1");
+            KuaiShouGroup kuaiShouGroup = groupMapper.selectOne(queryWrapper);
+            if (Check.isNull(kuaiShouGroup)) {
+                throw new Exception("未获取到组信息");
+            }
+            CtopOauthToken token = oauthTokenService.getTokenByAccountId(kuaiShouGroup.getAccountId());
+            String sceneId = kuaiShouGroup.getSceneId();
+            if (Check.isNull(sceneId)) {
+                throw new Exception("未获取资源位置");
+            }
+            Integer scene = (Integer) JSONArray.parseArray(sceneId).get(0);
+            JSONObject unitJson = new JSONObject();
+            unitJson.put("advertiser_id", token.getAccountId());
+            unitJson.put("unit_id", unitId);
+            // 广告组名称
+            unitJson.put("unit_name", kuaiShouGroup.getUnitName());
+            // 资源位置
+            unitJson.put("scene_id", JSONArray.parseArray(sceneId));
+            //投放开始时间
+            String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+            boolean beginTimeBoolean = DateUtils.compare(kuaiShouGroup.getBeginTime(), nowDate);
+            if (beginTimeBoolean) {
+                unitJson.put("begin_time", nowDate);
+            } else {
+                unitJson.put("begin_time", kuaiShouGroup.getBeginTime());
+            }
+            // 创意展现方式
+            unitJson.put("show_mode", kuaiShouGroup.getShowMode());
+            //投放方式
+            unitJson.put("speed", kuaiShouGroup.getSpeed());
+
+            // -----------------修改组非必填参数-----------
+            // 出价
+            if (!Check.isNull(kuaiShouGroup.getBid())) {
+                unitJson.put("bid", kuaiShouGroup.getBid());
+            }
+            // 深度转化出价
+            if (!Check.isNull(kuaiShouGroup.getCpaBid())) {
+                unitJson.put("cpa_bid", kuaiShouGroup.getCpaBid());
+            }
+            // 深度转化目标出价
+            if (!Check.isNull(kuaiShouGroup.getDeepConversionBid())) {
+                unitJson.put("deep_conversion_bid", kuaiShouGroup.getDeepConversionBid());
+            }
+            // 投放结束时间
+            if (!Check.isNull(kuaiShouGroup.getEndTime())) {
+                unitJson.put("end_time", kuaiShouGroup.getEndTime());
+            }
+            // 投放时间段
+            if (!Check.isNull(kuaiShouGroup.getScheduleTime())) {
+                unitJson.put("schedule_time", kuaiShouGroup.getScheduleTime());
+            }
+            // 广告组单日预算
+            if (!Check.isNull(kuaiShouGroup.getDayBudget())) {
+                unitJson.put("day_budget", kuaiShouGroup.getDayBudget());
+            }
+            // url类型
+            if (!Check.isNull(kuaiShouGroup.getUrlType())) {
+                unitJson.put("url_type", kuaiShouGroup.getUrlType());
+            }
+            // url
+            if (!Check.isNull(kuaiShouGroup.getUrl())) {
+                unitJson.put("url", kuaiShouGroup.getUrl());
+            }
+            // appId
+            if (!Check.isNull(kuaiShouGroup.getAppId())) {
+                unitJson.put("app_id", kuaiShouGroup.getAppId());
+            }
+            // 优先从系统应用商店下载
+            if (!Check.isNull(kuaiShouGroup.getUseAppMarket())) {
+                unitJson.put("use_app_market", kuaiShouGroup.getUseAppMarket());
+            }
+            // 应用商店列表
+            if (!Check.isNull(kuaiShouGroup.getAppStore())) {
+                unitJson.put("app_store", JSONArray.parseArray(kuaiShouGroup.getAppStore()));
+            }
+            // 转化目标
+            if (!Check.isNull(kuaiShouGroup.getConvertId())) {
+                unitJson.put("convert_id", kuaiShouGroup.getConvertId());
+            }
+            // -----------------用户定向-----------
+            JSONObject targetJson = new JSONObject();
+
+            // 地域
+            if (!Check.isNull(requestJson.getJSONArray("region"))) {
+                targetJson.put("region", requestJson.getJSONArray("region"));
+            }
+
+            // 自定义年龄段
+
+            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"));
+                targetJson.put("age", ageJson);
+            }
+            // 固定年龄段
+            if (!Check.isNull(requestJson.getJSONArray("agesRange"))) {
+                targetJson.put("ages_range", requestJson.getJSONArray("agesRange"));
+            }
+            // 性别
+            if (!Check.isNull(requestJson.getInteger("gender"))) {
+                targetJson.put("gender", requestJson.getInteger("gender"));
+            }
+            //操作系统
+            if (!Check.isNull(requestJson.getInteger("platformOs"))) {
+                targetJson.put("platform_os", requestJson.getInteger("platformOs"));
+            }
+            //Android版本
+            if (!Check.isNull(requestJson.getInteger("androidOsv"))) {
+                targetJson.put("android_osv", requestJson.getInteger("androidOsv"));
+            }
+            // iOS版本
+            if (!Check.isNull(requestJson.getInteger("iosOsv"))) {
+                targetJson.put("ios_osv", requestJson.getInteger("iosOsv"));
+            }
+            //网络环境
+            if (!Check.isNull(requestJson.getInteger("network"))) {
+                targetJson.put("network", requestJson.getInteger("network"));
+            }
+            // 设备品牌
+            if (!Check.isNull(requestJson.getJSONArray("deviceBrand"))) {
+                targetJson.put("device_brand", requestJson.getJSONArray("deviceBrand"));
+            }
+            // 设备价格
+            if (!Check.isNull(requestJson.getJSONArray("devicePrice"))) {
+                targetJson.put("device_price", requestJson.getJSONArray("devicePrice"));
+            }
+
+            if (!Check.isNull(requestJson.getJSONArray("appInterest"))) {
+                targetJson.put("app_interest", requestJson.getJSONArray("appInterest"));
+            }
+            // APP行为-按APP名称
+            if (!Check.isNull(requestJson.getJSONArray("appIds"))) {
+                targetJson.put("app_ids", requestJson.getJSONArray("appIds"));
+            }
+            // 人群包
+            if (!Check.isNull(requestJson.getJSONArray("population"))) {
+                targetJson.put("population", requestJson.getJSONArray("population"));
+            }
+            // 人群包排除
+            if (!Check.isNull(requestJson.getJSONArray("excludePopulation"))) {
+                targetJson.put("exclude_population", requestJson.getJSONArray("excludePopulation"));
+            }
+            if (!Check.isNull(requestJson.getJSONArray("thirdPlatformCode"))) {
+                targetJson.put("third_platform_code", requestJson.getJSONArray("thirdPlatformCode"));
+            }
+
+            if (scene != 5) {
+                if (!Check.isNull(requestJson.getInteger("filterConvertedLevel"))) {
+                    targetJson.put("filter_converted_level", requestJson.getInteger("filterConvertedLevel"));
+                }
+                //商业兴趣类型
+                if (!Check.isNull(requestJson.getInteger("businessInterestType"))) {
+                    targetJson.put("business_interest_type", requestJson.getInteger("businessInterestType"));
+                }
+                // 商业兴趣
+                if (!Check.isNull(requestJson.getJSONArray("businessInterest"))) {
+                    targetJson.put("business_interest", requestJson.getJSONArray("businessInterest"));
+                }
+                //网红粉丝
+                if (!Check.isNull(requestJson.getJSONArray("fansStar"))) {
+                    targetJson.put("fans_star", requestJson.getJSONArray("fansStar"));
+                }
+                //兴趣视频用户
+                if (!Check.isNull(requestJson.getJSONArray("interestVideo"))) {
+                    targetJson.put("interest_video", requestJson.getJSONArray("interestVideo"));
+                }
+            }
+            if (scene != 5) {
+                JSONObject intelliExtendJson = new JSONObject();
+                // 开启智能扩量
+                if (!Check.isNull(requestJson.getInteger("isOpen"))) {
+                    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);
+                }
+            }
+            unitJson.put("target", targetJson);
+            JSONObject jsonObject = updateService.updateUnit(token.getAccessToken(), unitJson);
+        } catch (Exception e) {
+            log.error("修改广告组定向异常", e);
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 更新帐户定向包
+     *
+     * @param
+     * @return void
+     * @throws
+     * @author ZHAOXA
+     */
     private void updateAccountsDirectionalPackage(JSONObject requestJson, JSONObject accounEntity) {
         Long accountId = accounEntity.getLong("rel_id");
         CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
@@ -298,9 +503,16 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
     }
 
     @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)));
+    public Result<Object> getRelatedAccountGroup(String id, Integer type,Long accountId, Integer pageNo, Integer pageSize) {
+        PageInfo pageInfo = null;
+        if (1 == type) {
+            PageHelper.startPage(pageNo, pageSize);
+            pageInfo = new PageInfo(packageMapper.getRelatedAccount(id));
+        } else {
+            PageHelper.startPage(pageNo, pageSize);
+            pageInfo = new PageInfo(packageMapper.getRelatedGroup(id,accountId));
+        }
+        return Result.ok(pageInfo);
     }
 
     @Override
@@ -494,7 +706,7 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
 
 
     @Override
-    public Result<Object> updatePopulation(JSONObject requestJson) {
+    public Result<Object> editPopulation(JSONObject requestJson) {
         Long accountId = requestJson.getLong("accountId");
         String message = "";
         KuaishouDirectionalTemplateRel rel = new KuaishouDirectionalTemplateRel();
@@ -538,6 +750,10 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
                     kuaishouTemplateService.getTemplateByAccountId(requestJson.getLong("accountId"), oauthToken.getAccessToken(), 1);
                     JSONObject data = resultJson.getJSONObject("data");
                     relService.update(rel, queryWrapper);
+                    List<JSONObject> units = relMapper.queryUnitIdByAccountId(requestJson.getString("id"), requestJson.getLong("accountId"));
+                    for (JSONObject unit : units) {
+                        updateUnitsDirectionalPackage(requestJson, unit);
+                    }
                     return Result.ok("修改成功");
                 } else {
                     return Result.error("修改失败," + message);
@@ -558,4 +774,24 @@ public class KuaishouDirectionalPackageServiceImpl extends ServiceImpl<KuaishouD
         return Result.ok(new PageInfo<>(list));
     }
 
+    @Override
+    public void createUnitAndTemplate(JSONObject request) throws Exception {
+        JSONObject target = templateMapper.queryByTemplateId(request.getLong("templateId"));
+        if (Check.isNull(target)) {
+            throw new Exception("添加广告组和定向模板绑定关系失败");
+        }
+        KuaishouDirectionalTemplateRel relEntity = new KuaishouDirectionalTemplateRel();
+        relEntity.setDirId(target.getString("dir_id"));
+        relEntity.setProjectId(target.getLong("project_id"));
+        relEntity.setTemplateId(request.getLong("templateId"));
+        relEntity.setTemplateName(target.getString("template_name"));
+        relEntity.setDataStatus(1);
+        relEntity.setRelId(request.getLong("unitId"));
+        relEntity.setRelType("unit");
+        relEntity.setExcludePopulation(request.getString("excludePopulation"));
+        relEntity.setPopulation(request.getString("population"));
+        relEntity.setPaidAudience(request.getString("paidAudience"));
+        relService.save(relEntity);
+    }
+
 }

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

@@ -18,4 +18,6 @@ public interface KuaishouTemplateMapper extends BaseMapper<KuaishouTemplate> {
     List<JSONObject> getJsonArrByAccountId(@Param("accountId") Long accountId, @Param("platformOs") Integer platformOs, @Param("autoTarget") Boolean autoTarget);
 
     void replaceBatch(@Param("templateList") List<KuaishouTemplate> templateList);
+
+    JSONObject queryByTemplateId(@Param("templateId") Long templateId);
 }

+ 10 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouTemplateMapper.xml

@@ -48,4 +48,14 @@
         </if>
     </select>
 
+
+    <select id="queryByTemplateId" resultType="com.alibaba.fastjson.JSONObject">
+        select t1.account_id,t1.template_id,t1.template_name,t3.dir_id,t3.project_id
+        from ctop_kuaishou_template t1
+                 INNER JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
+                 left JOIN ctop_kuaishou_directional_template_rel t3 ON t1.template_name = t3.template_name AND t2.project_id = t3.project_id
+        where t1.template_id = #{templateId}
+    </select>
+
+
 </mapper>