Browse Source

批量2.0支持商品库

yumeng 2 năm trước cách đây
mục cha
commit
01de793870

+ 67 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouGroupTemplateController.java

@@ -1,5 +1,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.KuaiShouGroupTemplate;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouGroupTemplateService;
@@ -52,8 +54,73 @@ import java.util.concurrent.Executors;
 public class KuaiShouGroupTemplateController {
     @Autowired
     private IKuaiShouGroupTemplateService kuaiShouGroupTemplateService;
+    @Autowired
+    private ICtopOauthTokenService tokenService;
     static ExecutorService executorService = Executors.newFixedThreadPool(10);
 
+
+    @PostMapping(value = "/getLibraryConfig")
+    public Result<JSONObject> getLibraryConfig(@RequestBody JSONObject requestJson) {
+        Result<JSONObject> result = new Result<>();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("参数不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请传如账户ID");
+            }
+            JSONObject returnJson = kuaiShouGroupTemplateService.getLibraryConfig(accountId);
+            result.setSuccess(true);
+            result.setResult(returnJson);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+
+    }
+
+    @PostMapping(value = "/productList")
+    public JSONObject productList(@RequestBody JSONObject requestJson) {
+        JSONObject returnJson = new JSONObject();
+        try {
+            if (Check.isNull(requestJson)) {
+                throw new Exception("参数不能为空");
+            }
+            Long accountId = requestJson.getLong("accountId");
+            if (Check.isNull(accountId)) {
+                throw new Exception("请传如账户ID");
+            }
+            CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(token)) {
+                throw new Exception("未获取到授权信息");
+            }
+
+            Long libraryId = requestJson.getLong("libraryId");
+            if (Check.isNull(libraryId)) {
+                throw new Exception("请传入商品ID");
+            }
+            Integer page = requestJson.getInteger("page");
+            if (Check.isNull(page)) {
+                throw new Exception("请传入商品请求页数");
+            }
+            Integer pageSize = requestJson.getInteger("pageSize");
+            if (Check.isNull(pageSize)) {
+                throw new Exception("请传入商品请求条数");
+            }
+            String libraryName = requestJson.getString("libraryName");
+            returnJson = kuaiShouGroupTemplateService.productList(accountId, token.getAccessToken(), libraryId, page, pageSize, libraryName);
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnJson.put("code", -1);
+            returnJson.put("message", e.getMessage());
+        }
+        return returnJson;
+    }
+
+
     /**
      * 批量创建广告组
      *

+ 4 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/entity/KuaiShouGroupTemplate.java

@@ -218,6 +218,10 @@ public class KuaiShouGroupTemplate {
     private String photoIds;
     private String schemaUri;
     private Integer imageCount;
+    private String productId; // 快手商品id
+    private String outerId; // 外部商品id
+    private Integer detailUnitType; // 商品链接类型
+    private Long libraryId; // 商品库 ID
 
     /**
      * 创建时间

+ 7 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouGroupTemplateMapper.java

@@ -27,4 +27,11 @@ public interface KuaiShouGroupTemplateMapper extends BaseMapper<KuaiShouGroupTem
     JSONObject getImageJsonByMd5(String md5);
 
     List<Long> getIdList();
+
+    /**
+     * @param projectId
+     * @return
+     */
+    JSONObject getConfig(@Param("projectId") Long projectId);
+
 }

+ 8 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouGroupTemplateMapper.xml

@@ -57,4 +57,12 @@
     limit 70
     </select>
 
+
+
+    <select id="getConfig" resultType="com.alibaba.fastjson.JSONObject">
+      select
+      library_id as 'libraryId'
+      from ctop_kuaishou_library_config
+      where project_id = #{projectId}
+    </select>
 </mapper>

+ 20 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouGroupTemplateService.java

@@ -45,4 +45,24 @@ public interface IKuaiShouGroupTemplateService extends IService<KuaiShouGroupTem
      * @return
      */
     List<Long> getIdList();
+
+    /**
+     * 商品信息
+     *
+     * @param accountId
+     * @param accessToken
+     * @param libraryId
+     * @param page
+     * @param pageSize
+     * @param libraryName
+     * @return
+     */
+    JSONObject productList(Long accountId, String accessToken, Long libraryId, Integer page, Integer pageSize, String libraryName);
+
+    /**
+     * 获取商品库配置
+     * @param accountId
+     * @return
+     */
+    JSONObject getLibraryConfig(Long accountId);
 }

+ 95 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouGroupTemplateServiceImpl.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.kuaishou.modules.batch.service.impl;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
@@ -147,6 +149,10 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
         String description = requestJson.getString("description");
         String site_id = requestJson.getString("siteId");
         String schema_uri = requestJson.getString("schemaUri");
+        String product_id = requestJson.getString("productId");
+        String outer_id = requestJson.getString("outerId");
+        Integer detail_unit_type = requestJson.getInteger("detailUnitType");
+        Long library_id = requestJson.getLong("libraryId");
         Integer startNumber = 0;
         if (unitName.contains("{{序号}}")) {
             if (!Check.isNull(requestJson.getInteger("startNumber"))) {
@@ -280,6 +286,18 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             if (!Check.isNull(site_id)) {
                 template.setSiteId(site_id);
             }
+            if (!Check.isNull(product_id)) {
+                template.setProductId(product_id);
+            }
+            if (!Check.isNull(outer_id)) {
+                template.setOuterId(outer_id);
+            }
+            if (!Check.isNull(detail_unit_type)) {
+                template.setDetailUnitType(detail_unit_type);
+            }
+            if (!Check.isNull(library_id)) {
+                template.setLibraryId(library_id);
+            }
             template.setImageCount(imageCount);
             template.setTaskStatus(0);
             template.setCreativeReviewDetail("创意待创建");
@@ -432,6 +450,25 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
             createUnitJson.put("unit_type", template.getUnitType()); //创意制作方式
         }
 
+        Long libraryId = template.getLibraryId();
+        if (!Check.isNull(libraryId)) {
+            JSONObject dpa_unit_param = new JSONObject();
+            dpa_unit_param.put("library_id", libraryId);
+            String productId = template.getProductId();
+            if (!Check.isNull(productId)) {
+                dpa_unit_param.put("product_id", productId);
+            }
+            String outerId = template.getOuterId();
+            if (!Check.isNull(outerId)) {
+                dpa_unit_param.put("outer_id", outerId);
+            }
+            Integer detailUnitType = template.getDetailUnitType();
+            if (!Check.isNull(detailUnitType)) {
+                dpa_unit_param.put("detail_unit_type", detailUnitType);
+            }
+            dpa_unit_param.put("dpa_unit_sub_type", 2);
+            createUnitJson.put("dpa_unit_param", dpa_unit_param);
+        }
         Map<String, Object> groupMap = iKuaishouInterfaceService.adUnitCreate(token.getAccessToken(), accountId, createUnitJson, 1);
         updateTemplate = new KuaiShouGroupTemplate();
         updateTemplate.setId(template.getId());
@@ -597,6 +634,64 @@ public class KuaiShouGroupTemplateServiceImpl extends ServiceImpl<KuaiShouGroupT
     }
 
     /**
+     * 获取商品信息
+     *
+     * @param accountId
+     * @param accessToken
+     * @param libraryId
+     * @param page
+     * @param pageSize
+     * @param libraryName
+     * @return
+     */
+    @Override
+    public JSONObject productList(Long accountId, String accessToken, Long libraryId, Integer page, Integer pageSize, String libraryName) {
+        String url = "https://ad.e.kuaishou.com/rest/openapi/gw/dsp/v1/dpa/product/list";
+        Map<String, String> headers = new HashMap<>();
+        headers.put("Access-Token", accessToken);
+        Map<String, Object> param = new HashMap<>();
+        param.put("advertiser_id", accountId);
+        param.put("library_id", libraryId);
+        if (!Check.isNull(libraryName)) {
+            param.put("id_or_name", libraryName);
+        }
+        param.put("page_size", pageSize);
+        param.put("page", page);
+
+        String result = HttpUtils.httpPostRequest(url, param, headers);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if (!Check.isNull(resultJson)) {
+            JSONObject data = resultJson.getJSONObject("data");
+            if (!Check.isNull(data)) {
+                data.put("page_size", pageSize);
+                data.put("page", page);
+            }
+
+        }
+        System.err.println(resultJson);
+        return resultJson;
+    }
+
+    @Autowired
+    private IUserAllocationService userAllocationService;
+
+    @Override
+    public JSONObject getLibraryConfig(Long accountId) {
+        JSONObject returnJson = new JSONObject();
+        UserAllocation userAllocation = userAllocationService.getByAccountId(accountId);
+        Long projectId = userAllocation.getProjectId();
+        JSONObject configJson = groupTemplateMapper.getConfig(projectId);
+        if (Check.isNull(configJson)) {
+            returnJson.put("isLibrary", false);
+        } else {
+            Long libraryId = configJson.getLong("libraryId");
+            returnJson.put("isLibrary", true);
+            returnJson.put("libraryId", libraryId);
+        }
+        return returnJson;
+    }
+
+    /**
      * 获取当天api创建创意数
      *
      * @param accountId