浏览代码

快手批量调整

yumeng 5 年之前
父节点
当前提交
116c74c874
共有 21 个文件被更改,包括 922 次插入100 次删除
  1. 63 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouAppListJob.java
  2. 11 12
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  3. 0 7
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java
  4. 12 1
      module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java
  5. 208 7
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  6. 248 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouTargetingTagsController.java
  7. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouCampaignDayBudget.java
  8. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouCampaignStatus.java
  9. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupBid.java
  10. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupDayBudget.java
  11. 71 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouTargetingTags.java
  12. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouTargetingTagsMapper.java
  13. 5 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouTargetingTagsMapper.xml
  14. 11 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IBatchService.java
  15. 15 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouTargetingTagsService.java
  16. 20 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  17. 24 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  18. 19 17
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCreateAppTemplateServiceImpl.java
  19. 19 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouTargetingTagsServiceImpl.java
  20. 8 8
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java
  21. 169 44
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 63 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/KuaishouAppListJob.java

@@ -0,0 +1,63 @@
+package org.jeecg.modules.ctop.job;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.utils.CtopAdConstant;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import lombok.extern.slf4j.Slf4j;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * 获取广告计划分时报表
+ *
+ * @author syh
+ */
+@Slf4j
+public class KuaishouAppListJob implements Job {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+
+    static ExecutorService executorService = null;
+
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+
+        Thread thread = new Thread() {
+            @Override
+            public void run() {
+                List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+                executorService = Executors.newFixedThreadPool(3);
+                tokens.forEach(token -> {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                kuaishouInterfaceService.getAppList(token.getAccountId(), token.getAccessToken());
+                                log.info("快手应用信息获取完成完成");
+
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            } finally {
+                            }
+                        }
+                    });
+                });
+
+            }
+
+        };
+        thread.start();
+
+
+    }
+}

+ 11 - 12
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -2,6 +2,7 @@ package org.jeecg;
 
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.HttpUtils2;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
@@ -146,7 +147,7 @@ public class SampleTest {
     @Test
     public void testMail() throws Exception {
         // String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page
-        kuaishouInterfaceService.getGroupList("adf659b9b43e8952f9a3f0c5269505ca", 35675L, null, null, 1);
+        kuaishouInterfaceService.getTargetingTags(23212L, "c1c5f8c03bd6981e85b677bb6cdc8beb");
     }
 
 
@@ -155,17 +156,15 @@ public class SampleTest {
 
     @Test
     public void testMa() throws Exception {
-        //String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_advertiser_info");
-        String url = "https://ad.oceanengine.com/open_api/2/advertiser/public_info/";
-        Map<String, String> headers = new HashMap<>();
-        headers.put("Content-Type", "application/json");
-        headers.put("Access-Token", "7827db33fe53348e935706250a991461e7cffda2");
-        TreeMap<String, Object> params = new TreeMap<>();
-        //TODO jsonArray
-        params.put("advertiser_ids", "[" + 111463131228L+ "]");
-        String result = HttpUtils.httpGetRequest(url, headers, params);
-        JSONObject jsonObject = JSONObject.parseObject(result);
-        System.err.println(jsonObject);
+        String url = "https://ad.e.kuaishou.com/rest/openapi/v1/dmp/population/list";
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Access-Token", "4e0c7411f78d47cce7a77b2d40b283f2");
+        headers.put("Content-Type", " application/json");
+        JSONObject requestJson = new JSONObject();
+        requestJson.put("advertiser_id", 23212L);
+        String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        System.err.println(resultJson);
     }
 
 

+ 0 - 7
module-common/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java

@@ -71,17 +71,10 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
     @Override
     public String getByteDanceCodeUrl(String state) throws UnsupportedEncodingException {
         StringBuffer sb = new StringBuffer();
-        JSONArray jsonArray = new JSONArray();
-        jsonArray.add("100");
-        jsonArray.add("2");
-        jsonArray.add("3");
-        jsonArray.add("4");
-        jsonArray.add("5");
         sb.append(PropertiesUtils.getValue("bytedance_config", "bytedance_auth_url"))
                 .append(BytedanceInterfaceConstant.AUTH_PATH)
                 .append("?app_id=" + PropertiesUtils.getValue("bytedance_config", "bytedance_appid"))
                 .append("&state=" + URLEncoder.encode(state))
-              //  .append("&scope=" + jsonArray)
                 .append("&redirect_uri=" + URLEncoder.encode(PropertiesUtils.getValue("bytedance_config", "bytedance_callback_url"), "UTF-8"));
         return sb.toString();
     }

+ 12 - 1
module-common/src/main/java/cn/com/ctop/common/module/utils/KuaishouInterfaceConstant.java

@@ -4,7 +4,7 @@ package cn.com.ctop.common.module.utils;
  * 2019年9月9日13:21:39
  */
 public class KuaishouInterfaceConstant {
-    public static final String AUTH_PATH = "/#/openapi/oauth";
+    public static final String AUTH_PATH = "/openapi/oauth";
     public static final String AUTH_TOKEN = "/rest/openapi/oauth2/authorize/access_token";
     public static final String REFRESH_TOKEN = "/rest/openapi/oauth2/authorize/refresh_token";
     /**
@@ -94,6 +94,17 @@ public class KuaishouInterfaceConstant {
      */
     public static final String DAILY_FLOWS = "/rest/openapi/v1/advertiser/fund/daily_flows";
 
+    /**
+     * 获取人群包接口
+     */
+    public static final String POPULATION_LIST = "/rest/openapi/v1/dmp/population/list";
+
+
+    /**
+     * 获取定向标签
+     */
+    public static final String TARGETING_TAGS = "/rest/openapi/v1/tool/targeting_tags/list";
+
 
     /**
      * 修改广告计划预算

+ 208 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java

@@ -4,6 +4,7 @@ package cn.com.ctop.kuaishou.modules.batch.controller;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouRegionListParent;
@@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 @Slf4j
 @Api(tags = "快手-批量工具")
@@ -48,6 +50,8 @@ public class BatchController {
     private IKuaiShouGroupService kuaiShouGroupService;
     @Autowired
     private KuaiShouRegionListParentMapper regionListParentMapper;
+    @Autowired
+    private IKuaiShouAppListService kuaiShouAppListService;
 
 
     /**
@@ -114,6 +118,65 @@ public class BatchController {
 
 
     /**
+     * 批量修改广告计划状态
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/batchUpdateStatus")
+    public Result<JSONObject> batchUpdateStatus(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+
+
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("账号信息为空");
+            }
+            Integer putStatus = requestJson.getInteger("putStatus");
+            if (putStatus == null) {
+                throw new Exception("请选择状态");
+            }
+            String userId = requestJson.getString("userId");
+            JSONArray campaignIds = requestJson.getJSONArray("campaignIds");
+            JSONArray failArr = new JSONArray();
+            if (!Check.isNull(campaignIds)) {
+                for (int i = 0; i < campaignIds.size(); i++) {
+                    Long campaignId = campaignIds.getLong(i);
+                    if (!Check.isNull(campaignId)) {
+                        Map<String, Object> updateMap = updateService.updateCampaignStatus(token.getAccessToken(), accountId, campaignId, putStatus, userId);
+                        if (!Check.isNull(updateMap)) {
+                            Integer code = (Integer) updateMap.get("code");
+                            if (code != 0) {
+                                JSONObject failJson = new JSONObject();
+                                failJson.put("message", updateMap.get("message"));
+                                KuaiShouCampaign campaign = batchService.getCampaignInfo(accountId, campaignId);
+                                if (!Check.isNull(campaign)) {
+                                    failJson.put("campaignName", campaign.getCampaignName());
+                                }
+                                failArr.add(failJson);
+                            }
+                        }
+                    }
+                }
+            }
+            JSONObject json = new JSONObject();
+            json.put("totalCount", campaignIds.size());
+            json.put("failCount", failArr.size());
+            json.put("failInfo", failArr);
+            result.setResult(json);
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+
+    /**
      * 批量修改广告计划预算
      *
      * @param requestJson
@@ -123,6 +186,7 @@ public class BatchController {
     public Result<JSONObject> batchUpdateDayBudget(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
 
+
         try {
             Long accountId = requestJson.getLong("accountId");
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
@@ -135,14 +199,32 @@ public class BatchController {
             }
             String userId = requestJson.getString("userId");
             JSONArray campaignIds = requestJson.getJSONArray("campaignIds");
+            JSONArray failArr = new JSONArray();
             if (!Check.isNull(campaignIds)) {
                 for (int i = 0; i < campaignIds.size(); i++) {
                     Long campaignId = campaignIds.getLong(i);
                     if (!Check.isNull(campaignId)) {
-                        updateService.updateCampaign(token.getAccessToken(), accountId, campaignId, dayBudget, userId);
+                        Map<String, Object> updateMap = updateService.updateCampaign(token.getAccessToken(), accountId, campaignId, dayBudget, userId);
+                        if (!Check.isNull(updateMap)) {
+                            Integer code = (Integer) updateMap.get("code");
+                            if (code != 0) {
+                                JSONObject failJson = new JSONObject();
+                                failJson.put("message", updateMap.get("message"));
+                                KuaiShouCampaign campaign = batchService.getCampaignInfo(accountId, campaignId);
+                                if (!Check.isNull(campaign)) {
+                                    failJson.put("campaignName", campaign.getCampaignName());
+                                }
+                                failArr.add(failJson);
+                            }
+                        }
                     }
                 }
             }
+            JSONObject json = new JSONObject();
+            json.put("totalCount", campaignIds.size());
+            json.put("failCount", failArr.size());
+            json.put("failInfo", failArr);
+            result.setResult(json);
             result.setSuccess(true);
         } catch (Exception e) {
             e.printStackTrace();
@@ -180,19 +262,52 @@ public class BatchController {
     /**
      * 获取区域列表
      *
-     * @param kuaiShouRegionListParent
+     * @param
      * @return
      */
     @GetMapping(value = "/getRegion")
-    public Result<List<KuaiShouRegionListParent>> getRegion(KuaiShouRegionListParent kuaiShouRegionListParent, HttpServletRequest req) {
-        Result<List<KuaiShouRegionListParent>> result = new Result<>();
+    public Result<JSONArray> getRegion() {
+        Result<JSONArray> result = new Result<>();
 
         try {
-            QueryWrapper<KuaiShouRegionListParent> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouRegionListParent, req.getParameterMap());
-
+            JSONArray regionArr = new JSONArray();
+            QueryWrapper<KuaiShouRegionListParent> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("level", 1);
             List<KuaiShouRegionListParent> regionListParents = regionListParentMapper.selectList(queryWrapper);
+            if (!Check.isNull(regionListParents)) {
+
+                for (KuaiShouRegionListParent regionListParent : regionListParents) {
+                    if (Check.isNull(regionListParent)) {
+                        continue;
+                    }
+                    JSONObject parentJson = new JSONObject();
+                    Long regionId = regionListParent.getRegionId();
+                    parentJson.put("regionId", regionId);
+                    parentJson.put("name", regionListParent.getName());
+                    QueryWrapper<KuaiShouRegionListParent> childrenQueryWrapper = new QueryWrapper<>();
+                    childrenQueryWrapper.eq("parent", regionId);
+                    List<KuaiShouRegionListParent> childrenRegions = regionListParentMapper.selectList(childrenQueryWrapper);
+
+                    JSONArray childrenArr = new JSONArray();
+                    if (!Check.isNull(childrenRegions)) {
+                        for (KuaiShouRegionListParent childrenRegion : childrenRegions) {
+                            if (!Check.isNull(childrenRegion)) {
+                                JSONObject childrenJson = new JSONObject();
+                                childrenJson.put("regionId", childrenRegion.getRegionId());
+                                childrenJson.put("name", childrenRegion.getName());
+                                childrenArr.add(childrenJson);
+                            }
+                        }
+                        parentJson.put("children", childrenArr);
+
+                    }
+
+                    regionArr.add(parentJson);
+                }
+            }
+
             result.setSuccess(true);
-            result.setResult(regionListParents);
+            result.setResult(regionArr);
         } catch (Exception e) {
             e.printStackTrace();
             result.setSuccess(false);
@@ -201,4 +316,90 @@ public class BatchController {
         return result;
     }
 
+
+    /**
+     * 创建广告计划
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/campaignCreate")
+    public Result<Object> campaignCreate(@RequestBody JSONObject requestJson) {
+        Result<Object> result = new Result<>();
+        try {
+            Long accountId = requestJson.getLong("accountId");
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONObject campaignJson = new JSONObject();
+            campaignJson.put("campaign_name", requestJson.getString("campaignName"));
+            campaignJson.put("type", requestJson.getInteger("type"));
+            campaignJson.put("day_budget", requestJson.getLong("day_budget"));
+            Map<String, Object> campaignMap = iKuaishouInterfaceService.campaignCreate(oauthToken.getAccessToken(), accountId, campaignJson);
+            Integer code = (Integer) campaignMap.get("code");
+            if (code != 0) {
+                throw new Exception((String) campaignMap.get("message"));
+            }
+            result.setSuccess(true);
+            result.setResult(campaignMap.get("campaignId"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+
+        }
+        return result;
+
+    }
+
+
+    /**
+     * 获取应用列表
+     */
+
+    @GetMapping(value = "/getAppList")
+    public Result<List<KuaiShouAppList>> getAppList(KuaiShouAppList kuaiShouAppList, HttpServletRequest req) {
+        Result<List<KuaiShouAppList>> result = new Result<>();
+        try {
+            QueryWrapper<KuaiShouAppList> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouAppList, req.getParameterMap());
+            queryWrapper.orderByDesc("return_time");
+
+            List<KuaiShouAppList> appList = kuaiShouAppListService.list(queryWrapper);
+            result.setSuccess(true);
+            result.setResult(appList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+
+        return result;
+    }
+
+
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @return
+     */
+    @GetMapping(value = "/getPopulationList")
+    public Result<JSONArray> getAppList(Long accountId) {
+        Result<JSONArray> result = new Result<>();
+        try {
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            JSONArray jsonArray = iKuaishouInterfaceService.getPopulationList(accountId, oauthToken.getAccessToken());
+            result.setSuccess(true);
+            result.setResult(jsonArray);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+
 }

+ 248 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouTargetingTagsController.java

@@ -0,0 +1,248 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTargetingTags;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouTargetingTagsService;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 快手-定向标签
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-19
+ */
+@Slf4j
+@Api(tags = "快手-定向标签")
+@RestController
+@RequestMapping("/kuaishou/kuaiShouTargetingTags")
+public class KuaiShouTargetingTagsController {
+    @Autowired
+    private IKuaiShouTargetingTagsService kuaiShouTargetingTagsService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaiShouTargetingTags
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "快手-定向标签-分页列表查询")
+    @ApiOperation(value = "快手-定向标签-分页列表查询", notes = "快手-定向标签-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaiShouTargetingTags>> queryPageList(KuaiShouTargetingTags kuaiShouTargetingTags,
+                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                              HttpServletRequest req) {
+        Result<IPage<KuaiShouTargetingTags>> result = new Result<IPage<KuaiShouTargetingTags>>();
+        QueryWrapper<KuaiShouTargetingTags> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouTargetingTags, req.getParameterMap());
+        Page<KuaiShouTargetingTags> page = new Page<KuaiShouTargetingTags>(pageNo, pageSize);
+        IPage<KuaiShouTargetingTags> pageList = kuaiShouTargetingTagsService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaiShouTargetingTags
+     * @return
+     */
+    @AutoLog(value = "快手-定向标签-添加")
+    @ApiOperation(value = "快手-定向标签-添加", notes = "快手-定向标签-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaiShouTargetingTags> add(@RequestBody KuaiShouTargetingTags kuaiShouTargetingTags) {
+        Result<KuaiShouTargetingTags> result = new Result<KuaiShouTargetingTags>();
+        try {
+            kuaiShouTargetingTagsService.save(kuaiShouTargetingTags);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaiShouTargetingTags
+     * @return
+     */
+    @AutoLog(value = "快手-定向标签-编辑")
+    @ApiOperation(value = "快手-定向标签-编辑", notes = "快手-定向标签-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaiShouTargetingTags> edit(@RequestBody KuaiShouTargetingTags kuaiShouTargetingTags) {
+        Result<KuaiShouTargetingTags> result = new Result<KuaiShouTargetingTags>();
+        KuaiShouTargetingTags kuaiShouTargetingTagsEntity = kuaiShouTargetingTagsService.getById(kuaiShouTargetingTags.getId());
+        if (kuaiShouTargetingTagsEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaiShouTargetingTagsService.updateById(kuaiShouTargetingTags);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过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 {
+            kuaiShouTargetingTagsService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "快手-定向标签-批量删除")
+    @ApiOperation(value = "快手-定向标签-批量删除", notes = "快手-定向标签-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<KuaiShouTargetingTags> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaiShouTargetingTags> result = new Result<KuaiShouTargetingTags>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaiShouTargetingTagsService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "快手-定向标签-通过id查询")
+    @ApiOperation(value = "快手-定向标签-通过id查询", notes = "快手-定向标签-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<KuaiShouTargetingTags> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaiShouTargetingTags> result = new Result<KuaiShouTargetingTags>();
+        KuaiShouTargetingTags kuaiShouTargetingTags = kuaiShouTargetingTagsService.getById(id);
+        if (kuaiShouTargetingTags == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaiShouTargetingTags);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaiShouTargetingTags> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaiShouTargetingTags kuaiShouTargetingTags = JSON.parseObject(deString, KuaiShouTargetingTags.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouTargetingTags, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaiShouTargetingTags> pageList = kuaiShouTargetingTagsService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "快手-定向标签列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaiShouTargetingTags.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手-定向标签列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<KuaiShouTargetingTags> listKuaiShouTargetingTagss = ExcelImportUtil.importExcel(file.getInputStream(), KuaiShouTargetingTags.class, params);
+                kuaiShouTargetingTagsService.saveBatch(listKuaiShouTargetingTagss);
+                return Result.ok("文件导入成功!数据行数:" + listKuaiShouTargetingTagss.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouCampaignDayBudget.java

@@ -62,7 +62,7 @@ public class KuaiShouCampaignDayBudget {
      */
     @Excel(name = "操作人id", width = 15)
     @ApiModelProperty(value = "操作人id")
-    private String loginId;
+    private String userId;
     /**
      * 创建时间
      */

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouCampaignStatus.java

@@ -62,7 +62,7 @@ public class KuaiShouCampaignStatus {
      */
     @Excel(name = "操作人id", width = 15)
     @ApiModelProperty(value = "操作人id")
-    private String loginId;
+    private String userId;
     /**
      * 创建时间
      */

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupBid.java

@@ -62,7 +62,7 @@ public class KuaiShouGroupBid {
      */
     @Excel(name = "操作人id", width = 15)
     @ApiModelProperty(value = "操作人id")
-    private String loginId;
+    private String userId;
     /**
      * 创建时间
      */

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupDayBudget.java

@@ -62,7 +62,7 @@ public class KuaiShouGroupDayBudget {
      */
     @Excel(name = "操作人id", width = 15)
     @ApiModelProperty(value = "操作人id")
-    private String loginId;
+    private String userId;
     /**
      * 创建时间
      */

+ 71 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouTargetingTags.java

@@ -0,0 +1,71 @@
+package cn.com.ctop.kuaishou.modules.batch.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 快手-定向标签
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-19
+ */
+@Data
+@TableName("ctop_kuaishou_targeting_tags")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_targeting_tags对象", description = "快手-定向标签")
+public class KuaiShouTargetingTags {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Long id;
+    /**
+     * 标签ID
+     */
+    @Excel(name = "标签ID", width = 15)
+    @ApiModelProperty(value = "标签ID")
+    private Long tagId;
+    /**
+     * 标签名称
+     */
+    @Excel(name = "标签名称", width = 15)
+    @ApiModelProperty(value = "标签名称")
+    private String tagName;
+    /**
+     * 投放结束时间
+     */
+    @Excel(name = "投放结束时间", width = 15)
+    @ApiModelProperty(value = "投放结束时间")
+    private String tagType;
+    /**
+     * 创建时间
+     */
+    @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;
+}

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

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.mapper;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTargetingTags;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 快手-定向标签
+ *
+ * @author: jeecg-boot
+ * @date: 2019-12-19
+ * @cersion: V1.0
+ */
+public interface KuaiShouTargetingTagsMapper extends BaseMapper<KuaiShouTargetingTags> {
+
+}

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

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

@@ -1,5 +1,7 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+
 import java.math.BigDecimal;
 
 public interface IBatchService {
@@ -18,4 +20,13 @@ public interface IBatchService {
      * @return
      */
     BigDecimal getBudget(Long accountId);
+
+    /**
+     * 获取计划信息
+     *
+     * @param accountId
+     * @param campaignId
+     * @return
+     */
+    KuaiShouCampaign getCampaignInfo(Long accountId, Long campaignId);
 }

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

@@ -0,0 +1,15 @@
+package cn.com.ctop.kuaishou.modules.batch.service;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTargetingTags;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 快手-定向标签
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-19
+ */
+public interface IKuaiShouTargetingTagsService extends IService<KuaiShouTargetingTags> {
+
+}

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

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.entity.CtopOauthToken;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
 import cn.com.ctop.kuaishou.modules.report.entity.*;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -304,4 +305,23 @@ public interface IKuaishouInterfaceService {
      * @param token
      */
     void getDailyFlows(CtopOauthToken token);
+
+
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param accessToken
+     * @return
+     */
+    JSONArray getPopulationList(Long accountId, String accessToken);
+
+
+    /**
+     * 获取定向标签
+     *
+     * @param accountId
+     * @param accessToken
+     */
+    void getTargetingTags(Long accountId, String accessToken);
 }

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

@@ -1,7 +1,10 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
 import cn.com.ctop.kuaishou.modules.batch.mapper.BatchMapper;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCampaignMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +18,8 @@ import java.util.Date;
 public class BatchServiceImpl implements IBatchService {
     @Autowired
     private BatchMapper batchMapper;
+    @Autowired
+    private KuaiShouCampaignMapper campaignMapper;
 
 
     /**
@@ -43,6 +48,25 @@ public class BatchServiceImpl implements IBatchService {
     }
 
 
+    /**
+     * 获取计划信息
+     *
+     * @param accountId
+     * @param campaignId
+     * @return
+     */
+    @Override
+    public KuaiShouCampaign getCampaignInfo(Long accountId, Long campaignId) {
+        QueryWrapper<KuaiShouCampaign> campaignQueryWrapper = new QueryWrapper<>();
+        campaignQueryWrapper.eq("account_id", accountId);
+        campaignQueryWrapper.eq("campaign_id", campaignId);
+        campaignQueryWrapper.orderByDesc("create_time");
+        campaignQueryWrapper.last("limit 1");
+        KuaiShouCampaign campaign = campaignMapper.selectOne(campaignQueryWrapper);
+        return campaign;
+    }
+
+
 }
 
 

+ 19 - 17
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouCreateAppTemplateServiceImpl.java

@@ -1,13 +1,15 @@
 package cn.com.ctop.kuaishou.modules.batch.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.KuaishouInterfaceConstant;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouAppList;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreateAppTemplate;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouAppListMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouCreateAppTemplateMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreateAppTemplateService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -25,13 +27,15 @@ import java.util.Map;
  */
 @Service
 public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCreateAppTemplateMapper, KuaiShouCreateAppTemplate> implements IKuaiShouCreateAppTemplateService {
-    @Autowired
-    private KuaiShouCreateAppTemplateMapper appTemplateMapper;
+
     @Autowired
     private ICtopOauthTokenService oauthTokenService;
     @Autowired
     private IKuaishouInterfaceService interfaceService;
 
+    @Autowired
+    private KuaiShouAppListMapper appListMapper;
+
     @Override
     public Map<String, Object> insert(KuaiShouCreateAppTemplate appTemplate) {
         Map<String, Object> resultMap = new HashMap<>();
@@ -42,15 +46,14 @@ public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCr
                 throw new Exception("未获取到token信息");
             }
             String accessToken = cTopOauthToken.getAccessToken();
-            String loginId = appTemplate.getLoginId();
             String appVersion = appTemplate.getAppVersion();
-            QueryWrapper<KuaiShouCreateAppTemplate> queryWrapper = new QueryWrapper<>();
+            QueryWrapper<KuaiShouAppList> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("app_version", appVersion);
-            queryWrapper.eq("login_id", loginId);
+            queryWrapper.eq("account_id", accountId);
             queryWrapper.orderByDesc("create_time");
             queryWrapper.last("limit 1");
-            KuaiShouCreateAppTemplate kuaiShouCreateAppTemplate = appTemplateMapper.selectOne(queryWrapper);
-            if (!Check.isNull(kuaiShouCreateAppTemplate)) {
+            KuaiShouAppList kuaiShouAppList = appListMapper.selectOne(queryWrapper);
+            if (!Check.isNull(kuaiShouAppList)) {
                 resultMap.put("success", false);
                 resultMap.put("message", "应用标记重复");
                 resultMap.put("code", -1);
@@ -80,13 +83,13 @@ public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCr
                 }
                 if ("1".equals(platform) && appTemplate.getUploadType() == 1) {
                     apkJson.put("file", appTemplate.getFile());
-                    Thread thread = new Thread() {
-                        @Override
-                        public void run() {
-                            interfaceService.appCreate(accountId, accessToken, apkJson);
-                        }
-                    };
-                    thread.start();
+
+                    Map<String, Object> appMap = interfaceService.appCreate(accountId, accessToken, apkJson);
+                    if ((Integer) appMap.get("code") != 0) {
+                        return appMap;
+
+                    }
+
                 } else {
                     apkJson.put("url", appTemplate.getUrl());
                     Map<String, Object> appMap = interfaceService.urlAppCreate(accountId, accessToken, apkJson);
@@ -94,7 +97,6 @@ public class KuaiShouCreateAppTemplateServiceImpl extends ServiceImpl<KuaiShouCr
                         return appMap;
                     }
                 }
-                appTemplateMapper.insert(appTemplate);
                 resultMap.put("success", true);
                 resultMap.put("message", "创建应用成功");
                 resultMap.put("code", 0);

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

@@ -0,0 +1,19 @@
+package cn.com.ctop.kuaishou.modules.batch.service.impl;
+
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouTargetingTags;
+import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouTargetingTagsMapper;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouTargetingTagsService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 快手-定向标签
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2019-12-19
+ */
+@Service
+public class KuaiShouTargetingTagsServiceImpl extends ServiceImpl<KuaiShouTargetingTagsMapper, KuaiShouTargetingTags> implements IKuaiShouTargetingTagsService {
+
+}

+ 8 - 8
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java

@@ -57,7 +57,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
                     QueryWrapper<KuaiShouCampaign> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("accountId", advertiserId);
+                    queryWrapper.eq("account_id", advertiserId);
                     queryWrapper.eq("campaign_id", campaignId);
                     queryWrapper.orderByDesc("create_time");
                     queryWrapper.last("limit 1");
@@ -66,7 +66,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     KuaiShouCampaignDayBudget campaignDayBudget = new KuaiShouCampaignDayBudget();
                     campaignDayBudget.setAccountId(advertiserId);
                     campaignDayBudget.setCampaignId(campaignId);
-                    campaignDayBudget.setLoginId(loginId);
+                    campaignDayBudget.setUserId(loginId);
                     campaignDayBudget.setDayBudget(campaign.getDayBudget());
                     campaignDayBudget.setUpdateDayBudget(dayBudget);
                     int i = campaignDayBudgetMapper.insert(campaignDayBudget);
@@ -131,7 +131,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
                     QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("accountId", advertiserId);
+                    queryWrapper.eq("account_id", advertiserId);
                     queryWrapper.eq("unit_id", unitId);
                     queryWrapper.orderByDesc("create_time");
                     queryWrapper.last("limit 1");
@@ -142,7 +142,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     groupDayBudget.setUnitId(unitId);
                     groupDayBudget.setDayBudget(group.getDayBudget());
                     groupDayBudget.setUpdateDayBudget(dayBudget);
-                    groupDayBudget.setLoginId(loginId);
+                    groupDayBudget.setUserId(loginId);
                     int i = groupDayBudgetMapper.insert(groupDayBudget);
                     if (i > 0) {
                         log.info("修改广告组预算本地记录添加成功,unitId:{}", unitId);
@@ -205,7 +205,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                 if (code == 0) {
                     QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("unit_id", unitId);
-                    queryWrapper.eq("accountId", advertiserId);
+                    queryWrapper.eq("account_id", advertiserId);
                     queryWrapper.orderByDesc("create_time");
                     queryWrapper.last("limit 1");
                     KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
@@ -215,7 +215,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     groupBid.setUnitId(unitId);
                     groupBid.setBid(group.getBid());
                     groupBid.setUpdateBid(bid);
-                    groupBid.setLoginId(loginId);
+                    groupBid.setUserId(loginId);
                     int i = groupBidMapper.insert(groupBid);
                     if (i > 0) {
                         log.info("修改广告组出价本地记录添加成功,unitId:{}", unitId);
@@ -277,7 +277,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
 
                     QueryWrapper<KuaiShouCampaign> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("campaign_id", campaignId);
-                    queryWrapper.eq("accountId", advertiserId);
+                    queryWrapper.eq("account_id", advertiserId);
                     queryWrapper.orderByDesc("create_time");
                     queryWrapper.last("limit 1");
                     // 查询本地记录信息
@@ -288,7 +288,7 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     campaignStatus.setCampaignId(campaignId);
                     campaignStatus.setPutStatus(campaign.getStatus());
                     campaignStatus.setUpdatePutStatus(putStatus);
-                    campaignStatus.setLoginId(loginId);
+                    campaignStatus.setUserId(loginId);
                     int i = campaignStatusMapper.insert(campaignStatus);
                     if (i > 0) {
                         log.info("修改广告计划状态本地记录添加成功,campaignId:{}", campaignId);

+ 169 - 44
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -975,6 +975,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
             getImageList(token, null, null);
         }
 
+
+        getAppList(token.getAccountId(), token.getAccessToken());
     }
 
 
@@ -990,31 +992,37 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         Map<String, Object> returnMap = new HashMap<>();
         try {
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
-            Map<String, String> headers = new HashMap<String, String>();
+            Map<String, String> headers = new HashMap<>();
             headers.put("Access-Token", accessToken);
             headers.put("Content-Type", " application/json");
             requestJson.put("advertiser_id", advertiserId);
             String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
             if (!Check.isNull(resultJson)) {
+                System.err.println(requestJson);
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
-                    KuaiShouCampaignCreate campaignCreate = new KuaiShouCampaignCreate();
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     Long campaignId = dataJson.getLong("campaign_id");
-                    campaignCreate.setCampaignId(campaignId);
-                    campaignCreate.setAccountId(advertiserId);
-                    campaignCreate.setCampaignName(requestJson.getString("campaign_name"));
-                    campaignCreate.setDayBudget(requestJson.getInteger("day_budget"));
-                    campaignCreate.setType(requestJson.getInteger("type"));
-                    int i = kuaiShouCampaignCreateMapper.insert(campaignCreate);
-                    if (i > 0) {
-                        log.info("创建广告信息入库完成,advertiser_id:{}", advertiserId);
-                    }
                     returnMap.put("code", 0);
                     returnMap.put("message", "success");
-                    returnMap.put("campaign_id", campaignId);
+                    returnMap.put("campaignId", campaignId);
                     returnMap.put("success", true);
+                    // 创建成功 拉取广告组信息
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                Thread.sleep(2 * 1000);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                            getCampaign(accessToken, advertiserId, campaignId);
+
+                        }
+
+                    };
+                    thread.start();
                 } else {
                     log.error("创建广告计划失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
                     returnMap.put("code", -1);
@@ -2163,6 +2171,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
+                        String signature = dataJson.getString("signature");
                         KuaiShouImageGet imageGet = new KuaiShouImageGet();
                         imageGet.setAccountId(advertiserId);
                         imageGet.setUrl(dataJson.getString("url"));
@@ -2170,7 +2179,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                         imageGet.setHeight(dataJson.getLong("height"));
                         imageGet.setSize(dataJson.getLong("size"));
                         imageGet.setFormat(dataJson.getString("format"));
-                        String signature = dataJson.getString("signature");
+
                         imageGet.setSignature(signature);
                         imageGet.setImageToken(dataJson.getString("image_token"));
                         Map<String, Object> deleteMap = new HashMap<>();
@@ -2387,23 +2396,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
-                        KuaiShouAppCreate appCreate = new KuaiShouAppCreate();
-                        appCreate.setAccountId(advertiserId);
-                        appCreate.setSavaPath(filePath);
-                        // 上传应用地址
-                        appCreate.setUrl(requestJson.getString("url"));
-                        appCreate.setAppVersion(requestJson.getString("app_version"));
-                        appCreate.setAppName(requestJson.getString("app_name"));
-                        appCreate.setImageToken(requestJson.getString("image_token"));
-                        appCreate.setPackageName(requestJson.getString("package_name"));
-                        appCreate.setPlatform(requestJson.getInteger("platform"));
-                        appCreate.setReturnUrl(dataJson.getString("url"));
-                        appCreate.setAppId(dataJson.getLong("app_id"));
-                        appCreate.setUploadTime(new Date().toString());
-                        int i = appCreateMapper.insert(appCreate);
-                        if (i > 0) {
-                            log.info("快手创建应用成功,共耗时:{} ms", System.currentTimeMillis() - startTime);
-                        }
+                        requestJson.put("url", dataJson.getString("url"));
+                        requestJson.put("app_id", dataJson.getLong("app_id"));
+                        this.insertAppList(advertiserId, requestJson);
+                        log.info("应用创建成功,耗时:{} s", (System.currentTimeMillis() - startTime) / 1000);
                         returnMap.put("appId", dataJson.getLong("app_id"));
                         returnMap.put("success", true);
                         returnMap.put("code", 0);
@@ -2471,20 +2467,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 if (code == 0) {
                     JSONObject dataJson = resultJson.getJSONObject("data");
                     if (!Check.isNull(dataJson)) {
-                        KuaiShouAppCreate appCreate = new KuaiShouAppCreate();
-                        appCreate.setAccountId(accountId);
-                        appCreate.setUrl(apkJson.getString("url"));
-                        appCreate.setPackageName(apkJson.getString("package_name"));
-                        appCreate.setPlatform(apkJson.getInteger("platform"));
-                        appCreate.setReturnUrl(dataJson.getString("url"));
-                        appCreate.setAppId(dataJson.getLong("app_id"));
-                        appCreate.setAppVersion(apkJson.getString("app_version"));
-                        appCreate.setImageToken(apkJson.getString("image_token"));
-                        appCreate.setAppName(apkJson.getString("app_name"));
-                        int i = appCreateMapper.insert(appCreate);
-                        if (i > 0) {
-                            log.info("快手创建应用成功");
-                        }
+                        apkJson.put("url", dataJson.getString("url"));
+                        apkJson.put("app_id", dataJson.getLong("app_id"));
+                        this.insertAppList(accountId, apkJson);
+
                         returnMap.put("code", 0);
                         returnMap.put("message", "success");
                         returnMap.put("appId", dataJson.getLong("app_id"));
@@ -2513,6 +2499,34 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
 
     /**
+     * 添加 应用信息
+     */
+    private void insertAppList(Long accountId, JSONObject dataJson) {
+
+        Map<String, Object> deleteMap = new HashMap<>();
+        deleteMap.put("account_id", accountId);
+        deleteMap.put("app_version", dataJson.getString("app_version"));
+        appListMapper.deleteByMap(deleteMap);
+        KuaiShouAppList appList = new KuaiShouAppList();
+        appList.setAccountId(accountId);
+        appList.setUrl(dataJson.getString("url"));
+        appList.setPlatform(dataJson.getInteger("platform"));
+        appList.setAppVersion(dataJson.getString("app_version"));
+        appList.setAppName(dataJson.getString("app_name"));
+        appList.setImageToken(dataJson.getString("image_token"));
+        appList.setPackageName(dataJson.getString("package_name"));
+        appList.setAppId(dataJson.getLong("app_id"));
+        appList.setAppIconUrl(dataJson.getString("app_icon_url"));
+        appList.setReturnTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm"));
+        int i = appListMapper.insert(appList);
+        if (i > 0) {
+            log.info("同步应用成功");
+        }
+
+    }
+
+
+    /**
      * 获取快手广告租信息
      *
      * @param accountId
@@ -2992,4 +3006,115 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
     }
 
 
+    /**
+     * 获取人群包接口
+     *
+     * @param accountId
+     * @param accessToken
+     * @return
+     */
+    @Override
+    public JSONArray getPopulationList(Long accountId, String accessToken) {
+        try {
+            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", 4);
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    JSONArray data = resultJson.getJSONArray("data");
+                    return data;
+                } else {
+
+
+                    log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
+                    return null;
+                }
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+
+    /**
+     * 获取定向标签
+     *
+     * @param accountId
+     * @param accessToken
+     */
+    @Autowired
+    private KuaiShouTargetingTagsMapper targetingTagsMapper;
+
+    @Override
+    public void getTargetingTags(Long accountId, String accessToken) {
+        try {
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TARGETING_TAGS;
+            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);
+
+
+            JSONArray typeArr = new JSONArray();
+            typeArr.add("BUSINESS_INTEREST");
+            typeArr.add("APP_INTEREST");
+            typeArr.add("FANS_STAR");
+            typeArr.add("INTEREST_VIDEO");
+
+
+            for (int i = 0; i < typeArr.size(); i++) {
+                String type = typeArr.get(i).toString();
+                requestJson.put("type", type);
+                String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
+                JSONObject resultJson = JSONObject.parseObject(result);
+                System.err.println(resultJson);
+                if (!Check.isNull(resultJson)) {
+                    Integer code = resultJson.getInteger("code");
+                    if (code == 0) {
+                        JSONArray dataArr = resultJson.getJSONArray("data");
+                        if (!Check.isNull(dataArr)) {
+                            Map<String, Object> deleteMap = new HashMap<>();
+                            deleteMap.put("tag_type", type);
+                            targetingTagsMapper.deleteByMap(deleteMap);
+                            for (int j = 0; j < dataArr.size(); j++) {
+                                JSONObject dataJson = dataArr.getJSONObject(j);
+                                if (!Check.isNull(dataJson)) {
+                                    KuaiShouTargetingTags targetingTags = new KuaiShouTargetingTags();
+                                    targetingTags.setTagId(dataJson.getLong("id"));
+                                    targetingTags.setTagName(dataJson.getString("name"));
+                                    targetingTags.setTagType(type);
+                                    targetingTagsMapper.insert(targetingTags);
+                                }
+                            }
+                        }
+
+                    } else {
+                        log.error("获取定向标签返回数据为空,accountId:{}", accountId);
+
+                    }
+
+                }
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
 }