Browse Source

调整批量

yumeng 5 years ago
parent
commit
19d5cb9e61
13 changed files with 523 additions and 20 deletions
  1. 10 8
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialImageInfoController.java
  2. 19 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java
  3. 7 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IKuaiShouUploadService.java
  4. 198 0
      jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java
  5. 1 0
      module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialInfoService.java
  6. 6 1
      module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java
  7. 1 2
      module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java
  8. 64 5
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/BatchController.java
  9. 12 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouUpdateService.java
  10. 9 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaishouInterfaceService.java
  11. 1 1
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/BatchServiceImpl.java
  12. 63 2
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouUpdateServiceImpl.java
  13. 132 0
      module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

+ 10 - 8
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialImageInfoController.java

@@ -40,6 +40,7 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -110,19 +111,20 @@ public class MaterialImageInfoController {
 
     /**
      * 分页列表查询
-     *
-     * @param MaterialImageInfo
-     * @param req
-     * @return
+     * * @return
      */
     @AutoLog(value = "素材-分页列表查询")
     @ApiOperation(value = "素材-分页列表查询", notes = "素材-分页列表查询")
     @GetMapping(value = "/list")
-    public Result<List<MaterialImageInfo>> queryPageList(MaterialImageInfo MaterialImageInfo,
-                                                         HttpServletRequest req) {
+    public Result<List<MaterialImageInfo>> queryPageList(String videoId) {
         Result<List<MaterialImageInfo>> result = new Result<>();
-        QueryWrapper<MaterialImageInfo> queryWrapper = QueryGenerator.initQueryWrapper(MaterialImageInfo, req.getParameterMap());
-        List<MaterialImageInfo> list = MaterialImageInfoService.list(queryWrapper);
+
+        List<MaterialImageInfo> list = new ArrayList<>();
+        if (!Check.isNull(videoId)) {
+            QueryWrapper<MaterialImageInfo> queryWrapper = new QueryWrapper<>();
+            list = MaterialImageInfoService.list(queryWrapper);
+        }
+
         result.setSuccess(true);
         result.setResult(list);
         return result;

+ 19 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialInfoController.java

@@ -27,6 +27,7 @@ import org.jeecg.modules.ctop.entity.ByteDanceCleanMaterialReport;
 import org.jeecg.modules.ctop.entity.KuaiShouCleanMaterialReport;
 import org.jeecg.modules.ctop.service.IByteDanceCleanMaterialReportService;
 import org.jeecg.modules.ctop.service.IKuaiShouCleanMaterialReportService;
+import org.jeecg.modules.ctop.service.IKuaiShouUploadService;
 import org.jeecg.modules.ctop.service.IProjectMemberService;
 import org.jeecgframework.poi.excel.ExcelImportUtil;
 import org.jeecgframework.poi.excel.def.NormalExcelConstants;
@@ -76,6 +77,8 @@ public class MaterialInfoController {
     private IKuaiShouCleanMaterialReportService kuaiShouCleanMaterialReportService;
     @Autowired
     private IVideoWatermarkTaskService watermarkTaskService;
+    @Autowired
+    private IKuaiShouUploadService uploadService;
 
 
     @PostMapping("/correlationUpload")
@@ -348,6 +351,22 @@ public class MaterialInfoController {
                 materialInfo.setUrl(url);
             }
 
+            if (!Check.isNull(materialInfo.getStatus())) {
+                Integer status = materialInfo.getStatus();
+                if (status == 1) {
+                    Thread thread = new Thread() {
+                        @Override
+                        public void run() {
+                            log.info("开始自动同步素材,code:{}", materialInfoEntity.getCode());
+                            uploadService.upload(materialInfoEntity);
+                        }
+                    };
+                    thread.start();
+
+                }
+
+            }
+
             boolean ok = materialInfoService.updateById(materialInfo);
             if (ok) {
                 result.success("修改成功!");

+ 7 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IKuaiShouUploadService.java

@@ -0,0 +1,7 @@
+package org.jeecg.modules.ctop.service;
+
+import cn.com.ctop.common.module.entity.MaterialInfo;
+
+public interface IKuaiShouUploadService {
+    void upload(MaterialInfo materialInfo);
+}

+ 198 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouUploadServiceImpl.java

@@ -0,0 +1,198 @@
+package org.jeecg.modules.ctop.service.impl;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.MaterialInfo;
+import cn.com.ctop.common.module.entity.MaterialParameter;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.enums.MaterialEnum;
+import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.MaterialParameterMapper;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
+import cn.com.ctop.common.module.utils.LoadFileUtil;
+import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.ParseException;
+import org.jeecg.modules.ctop.service.IKuaiShouUploadService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Slf4j
+@Service
+public class KuaiShouUploadServiceImpl implements IKuaiShouUploadService {
+    private static ExecutorService executorService = Executors.newFixedThreadPool(6);
+
+    @Value("${oss.replace.replace-value}")
+    private String replaceValue;
+    @Value("${oss.replace.replace-old-value}")
+    private String replaceOldValue;
+    @Value("${oss.replace.download}")
+    private String downloadUrl;
+
+
+    @Autowired
+    private IUserAllocationService allocationService;
+    @Autowired
+    private CtopOauthTokenMapper oauthTokenMapper;
+    @Autowired
+    private MaterialParameterMapper parameterMapper;
+    @Autowired
+    private IKuaiShouVideoGetService kuaiShouVideoGetService;
+
+    @Override
+    public void upload(MaterialInfo materialInfo) {
+        try {
+            String url = materialInfo.getUrl().replace(replaceOldValue, replaceValue);
+            log.info("replaceUrl:{}", url);
+            String localUrl = LoadFileUtil.downLoadFromUrl(url, downloadUrl);
+            FileSystemResource resource = new FileSystemResource(new File(localUrl));
+            Map<String, String> headerMap = new HashMap<>();
+            headerMap.put("Content-Type", "multipart/form-data");
+            JSONObject requestJson = new JSONObject();
+            requestJson.put("file", resource);
+            requestJson.put("signature", materialInfo.getCode());
+
+            QueryWrapper<MaterialParameter> parameterQueryWrapper = new QueryWrapper<>();
+            parameterQueryWrapper.eq("material_id", materialInfo.getCode());
+            parameterQueryWrapper.last("limit 1");
+            Integer type = null;
+            MaterialParameter materialParameter = parameterMapper.selectOne(parameterQueryWrapper);
+            if (!Check.isNull(materialParameter)) {
+                String width = materialParameter.getWidth();
+                String height = materialParameter.getHeight();
+                type = MaterialEnum.getTypeBySize(Integer.valueOf(width), Integer.valueOf(height));
+                if (!Check.isNull(type)) {
+                    requestJson.put("type", type);
+                }
+            }
+
+            QueryWrapper<UserAllocation> allocationQueryWrapper = new QueryWrapper<>();
+            allocationQueryWrapper.eq("project_id", materialInfo.getProjectId());
+            allocationQueryWrapper.eq("account_status", 0);
+            List<UserAllocation> list = allocationService.list(allocationQueryWrapper);
+            if (!Check.isNull(list)) {
+                for (UserAllocation allocation : list) {
+                    Long accountId = allocation.getAccountId();
+                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
+                    tokenQueryWrapper.eq("account_id", accountId);
+                    tokenQueryWrapper.eq("media_id", 2);
+                    tokenQueryWrapper.orderByDesc("create_time");
+                    tokenQueryWrapper.last("limit 1");
+                    CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(tokenQueryWrapper);
+                    if (Check.isNull(ctopOauthToken)) {
+                        log.error("快手账户信息为空,accountId:{}", accountId);
+                        continue;
+                    }
+
+                    QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
+                    videoGetQueryWrapper.eq("account_id", accountId);
+                    videoGetQueryWrapper.eq("signature", materialInfo.getCode());
+                    videoGetQueryWrapper.last("limit 1");
+                    KuaiShouVideoGet checkVideoGet = kuaiShouVideoGetService.getOne(videoGetQueryWrapper);
+                    if (!Check.isNull(checkVideoGet)) {
+                        log.info("此素材已同步,accountId:{},code:{}", accountId, materialInfo.getCode());
+                        continue;
+                    }
+                    requestJson.put("advertiser_id", accountId);
+                    headerMap.put("Access-Token", ctopOauthToken.getAccessToken());
+                    Integer finalType = type;
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            try {
+                                log.info("快手素材自动同步,accountId:{},code:{}", accountId, materialInfo.getCode());
+                                String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
+                                String result = exceptInfoForRestTemplate(url, requestJson, headerMap);
+                                JSONObject resultJson = JSONObject.parseObject(result);
+                                if (!Check.isNull(resultJson)) {
+                                    if (resultJson.getInteger("code") == 0) {
+                                        JSONObject dataJson = resultJson.getJSONObject("data");
+                                        if (!Check.isNull(dataJson)) {
+                                            String photoId = dataJson.getString("photo_id");
+                                            String signature = dataJson.getString("signature");
+                                            KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
+                                            videoGet.setAccountId(accountId);
+                                            videoGet.setId(accountId + photoId);
+                                            videoGet.setUrl(materialInfo.getUrl());
+
+
+                                            videoGet.setMaterialType(finalType);
+                                            videoGet.setPhotoId(photoId);
+                                            videoGet.setSignature(signature);
+                                            kuaiShouVideoGetService.saveOrUpdate(videoGet);
+                                        }
+                                        log.info("快手素材同步完成,accountId:{},code:{},返回信息:{}", accountId, materialInfo.getCode(), resultJson);
+                                    } else {
+                                        log.error("快手同步素材失败,返回信息:{},请求参数:{}", resultJson, requestJson);
+                                    }
+                                } else {
+                                    log.error("快手自动同步素材返回信息为空,accountId:{}", accountId);
+                                }
+
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }
+                        }
+                    });
+                }
+            }
+
+            /*boolean isTrue = LoadFileUtil.delFile(localUrl);
+            if (isTrue) {
+                log.info("删除本地缓存素材成功,code:{}", materialInfo.getCode());
+            }*/
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Autowired
+    private RestTemplate rest;
+
+    private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
+        try {
+            MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
+            if (!Check.isNullMap(paramMap)) {
+                for (String key : paramMap.keySet()) {
+                    param.add(key, paramMap.get(key));
+                }
+                HttpHeaders headers = new HttpHeaders();
+                if (!Check.isNullMap(headerMap)) {
+                    for (String key : headerMap.keySet()) {
+                        headers.add(key, headerMap.get(key));
+                    }
+                }
+                HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
+                ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
+                return responseEntity.getBody();
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+}

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialInfoService.java

@@ -63,4 +63,5 @@ public interface IMaterialInfoService extends IService<MaterialInfo> {
     List<MaterialInfo> effiMaterialInfo();
 
     List<String> getEffiCode();
+
 }

+ 6 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -40,6 +40,8 @@ import java.util.regex.Pattern;
 @Service
 public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, MaterialInfo> implements IMaterialInfoService {
     private static ExecutorService uploadExecutorService = Executors.newFixedThreadPool(5);
+    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+
     @Autowired
     private IVideoWatermarkTemplateService videoWatermarkTemplateService;
     @Autowired
@@ -545,6 +547,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
         return materialInfoMapper.getEffiSignature();
     }
 
+
     public List<MaterialInfo> effiMaterialInfo() {
         List<MaterialInfo> materialInfoList = new ArrayList<>();
         List<String> effiSignatureList = materialInfoMapper.getEffiSignature();
@@ -575,7 +578,9 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
     }
 
 
+}
+
+
 
 
 
-}

+ 1 - 2
module-ctop/src/main/java/cn/com/ctop/manage/modules/material/service/impl/MaterialUploadServiceImpl.java

@@ -269,8 +269,7 @@ public class MaterialUploadServiceImpl implements IMaterialUploadService {
     @Autowired
     private RestTemplate rest;
 
-    private String exceptInfoForRestTemplate(String
-                                                     url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
+    private String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap) throws ParseException {
         try {
             MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
             if (!Check.isNullMap(paramMap)) {

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

@@ -80,6 +80,8 @@ public class BatchController {
     private IKuaiShouVideoGetService videoGetService;
     @Autowired
     private IKuaishouPopulationService populationService;
+    @Autowired
+    private KuaiShouGroupMapper groupMapper;
 
 
     /**
@@ -950,6 +952,8 @@ public class BatchController {
             if (bid == null) {
                 throw new Exception("请输入出价");
             }
+
+            Long deepConversionBid = requestJson.getLong("deepConversionBid");
             String userId = requestJson.getString("userId");
             JSONArray unitIds = requestJson.getJSONArray("unitIds");
             JSONArray failArr = new JSONArray();
@@ -957,13 +961,21 @@ public class BatchController {
                 for (int i = 0; i < unitIds.size(); i++) {
                     Long unitId = unitIds.getLong(i);
                     if (!Check.isNull(unitId)) {
+                        KuaiShouGroup group = batchService.getUnitInfo(accountId, unitId);
+
                         Map<String, Object> updateMap = updateService.updateUnitBid(token.getAccessToken(), accountId, unitId, bid, userId);
+                        if (!Check.isNull(deepConversionBid) && deepConversionBid != 0) {
+                            Long updateDeepConversionBid = group.getDeepConversionBid();
+                            if (!Check.isNull(updateDeepConversionBid) && updateDeepConversionBid != 0) {
+                                Map<String, Object> updateDeepMap = updateService.updateUnitDeepConversionBid(token.getAccessToken(), accountId, unitId, deepConversionBid, userId);
+                            }
+                            iKuaishouInterfaceService.getGroup(token.getAccessToken(), accountId, unitId);
+                        }
                         if (!Check.isNull(updateMap)) {
                             Integer code = (Integer) updateMap.get("code");
                             if (code != 0) {
                                 JSONObject failJson = new JSONObject();
                                 failJson.put("message", updateMap.get("message"));
-                                KuaiShouGroup group = batchService.getUnitInfo(accountId, unitId);
                                 if (!Check.isNull(group)) {
                                     failJson.put("unitName", group.getUnitName());
                                 }
@@ -1051,7 +1063,6 @@ public class BatchController {
     public Result<MaterialInfo> getVideoList(String code, Long accountId) {
         Result<MaterialInfo> result = new Result<>();
         try {
-
             Long projectId = materialInfoMapper.getProjectIdByAccountId(accountId);
             QueryWrapper<MaterialInfo> materialInfoQueryWrapper = new QueryWrapper<>();
             materialInfoQueryWrapper.eq("code", code);
@@ -1060,8 +1071,8 @@ public class BatchController {
             MaterialInfo materialInfo = materialInfoMapper.selectOne(materialInfoQueryWrapper);
             result.setSuccess(true);
             result.setResult(materialInfo);
-
         } catch (Exception e) {
+
             e.printStackTrace();
             result.setSuccess(false);
         }
@@ -1537,6 +1548,11 @@ public class BatchController {
     }
 
 
+    /**
+     * 批量复制组
+     * @param requestJson
+     * @return
+     */
     @PostMapping(value = "/batchCopyUnit")
     public Result<JSONObject> batchCopyUnit(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
@@ -1603,9 +1619,13 @@ public class BatchController {
     }
 
 
-    @Autowired
-    private KuaiShouGroupMapper groupMapper;
 
+
+    /**
+     * 复制组
+     * @param requestJson
+     * @return
+     */
     @PostMapping(value = "/copyUnit")
     public Result<JSONObject> copyUnit(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
@@ -1696,6 +1716,11 @@ public class BatchController {
         return result;
     }
 
+    /**
+     * 获取人群包
+     * @param accountId
+     * @return
+     */
     @GetMapping(value = "/pullPopulationList")
     public Result pullPopulationList(Long accountId) {
         Result result = new Result<>();
@@ -1722,4 +1747,38 @@ public class BatchController {
     }
 
 
+    /**
+     * 获取创意
+     * @param accountId
+     * @param campaignId
+     * @return
+     */
+    @GetMapping(value = "/getAsyncCreativeList")
+    public Result getAsyncCreativeList(Long accountId, Long campaignId) {
+        Result result = new Result<>();
+        try {
+            if (Check.isNull(campaignId) || Check.isNull(accountId)) {
+                throw new Exception("必填参数不能为空");
+            }
+            CtopOauthToken oauthToken = oauthTokenService.getTokenByAccountId(accountId);
+            if (Check.isNull(oauthToken)) {
+                throw new Exception("未获取到账户信息");
+            }
+            Thread thread = new Thread() {
+                @Override
+                public void run() {
+                    iKuaishouInterfaceService.getAsyncCreativeList(accountId, oauthToken.getAccessToken(), campaignId);
+                }
+            };
+            thread.start();
+
+            result.setSuccess(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+        return result;
+    }
+
+
 }

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

@@ -114,4 +114,16 @@ public interface IKuaiShouUpdateService {
      * @return
      */
     JSONObject updateCreative(String accessToken, JSONObject creativeJson);
+
+    /**
+     * 修改深度转化出价
+     *
+     * @param accessToken
+     * @param accountId
+     * @param unitId
+     * @param deepConversionBid
+     * @param userId
+     * @return
+     */
+    Map<String, Object> updateUnitDeepConversionBid(String accessToken, Long accountId, Long unitId, Long deepConversionBid, String userId);
 }

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

@@ -171,7 +171,7 @@ public interface IKuaishouInterfaceService {
      * @param authCode
      * @return
      */
-    KuaishouResultToken getAccessToken(String authCode,Integer agentType);
+    KuaishouResultToken getAccessToken(String authCode, Integer agentType);
 
 
     /**
@@ -471,7 +471,15 @@ public interface IKuaishouInterfaceService {
      */
     void getSuZaoList(String token, Long accountId, int page);
 
+    /**
+     * 异步获取创意信息
+     *
+     * @param accountId
+     * @param accessToken
+     * @param campaignId
+     */
 
+    void getAsyncCreativeList(Long accountId, String accessToken, Long campaignId);
 }
 
 

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

@@ -764,7 +764,7 @@ public class BatchServiceImpl implements IBatchService {
                 creativeJson.put("action_bar_text", action_bar_text);
                 creativeJson.put("description", description);
                 creativeJson.put("image_token", image);
-                creativeJson.put("creative_name", name + RandomUtil.verifyCode());
+                creativeJson.put("creative_name", name);
                 creativeJson.put("photo_id", photo_id);
                 creativeJson.put("click_track_url", click_track_url);
 

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

@@ -220,8 +220,6 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
                     if (i > 0) {
                         log.info("修改广告组出价本地记录添加成功,unitId:{}", unitId);
                     }
-                    // 重新请求数据
-                    interfaceService.getGroup(token, advertiserId, unitId);
                     returnMap.put("code", 0);
                     returnMap.put("success", true);
                 } else {
@@ -673,4 +671,67 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
         return returnJson;
     }
 
+    @Override
+    public Map<String, Object> updateUnitDeepConversionBid(String accessToken, Long accountId, Long unitId, Long deepConversionBid, String userId) {
+
+        Map<String, Object> returnMap = new HashMap<>();
+        try {
+
+            JSONObject updateJson = new JSONObject();
+            updateJson.put("advertiser_id", accountId);
+            updateJson.put("unit_id", unitId);
+            updateJson.put("deep_conversion_bid", deepConversionBid);
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.UPDATE_UNIT;
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Access-Token", accessToken);
+            headers.put("Content-Type", "application/json");
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, updateJson.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            log.info("修改深度转化出价返回信息,accountId:{},返回信息:{}", accountId, resultJson);
+            if (!Check.isNull(resultJson)) {
+                Integer code = resultJson.getInteger("code");
+                if (code == 0) {
+                    /*QueryWrapper<KuaiShouGroup> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("unit_id", unitId);
+                    queryWrapper.eq("account_id", advertiserId);
+                    queryWrapper.orderByDesc("create_time");
+                    queryWrapper.last("limit 1");
+                    KuaiShouGroup group = groupMapper.selectOne(queryWrapper);
+
+                    KuaiShouGroupBid groupBid = new KuaiShouGroupBid();
+                    groupBid.setAccountId(advertiserId);
+                    groupBid.setUnitId(unitId);
+                    groupBid.setBid(group.getBid());
+                    groupBid.setUpdateBid(bid);
+                    groupBid.setUserId(loginId);
+                    int i = groupBidMapper.insert(groupBid);
+                    if (i > 0) {
+                        log.info("修改广告组深度转化出价本地记录添加成功,unitId:{}", unitId);
+                    }*/
+                    // 重新请求数据
+
+                    returnMap.put("code", 0);
+                    returnMap.put("success", true);
+                } else {
+                    log.error("修改广告组深度转化出价失败,advertiserId:{},unitId:{},返回信息:{}", accountId, unitId, resultJson);
+                    returnMap.put("code", -1);
+                    returnMap.put("success", false);
+                    returnMap.put("message", resultJson.getString("message"));
+                }
+            } else {
+                log.error("修改广告组深度转化出价返回结果为空,advertiserId:{},unitId:{}", returnMap, unitId);
+                returnMap.put("code", -1);
+                returnMap.put("success", false);
+                returnMap.put("message", "修改广告组预算返回结果为空");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            returnMap.put("code", -1);
+            returnMap.put("message", e.getMessage());
+        }
+
+
+        return returnMap;
+    }
+
 }

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

@@ -48,6 +48,8 @@ import java.io.IOException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * @author
@@ -156,6 +158,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
         String result = HttpUtils.httpPostRequest(url, param, headers);
         JSONObject resultJson = JSONObject.parseObject(result);
+        System.err.println(resultJson);
         Integer code = resultJson.getInteger("code");
         String message = resultJson.getString("message");
         if (null == code || code != 0) {
@@ -3039,5 +3042,134 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
     }
 
+    private static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @Override
+    public void getAsyncCreativeList(Long accountId, String accessToken, Long campaignId) {
+
+
+        try {
+            String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
+            Map<String, String> headers = new HashMap<>();
+            headers.put("Content-Type", " application/json");
+            headers.put("Access-Token", accessToken);
+            JSONObject param = new JSONObject();
+            param.put("advertiser_id", accountId);
+            param.put("page_size", 200);
+
+            Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("account_id", accountId);
+            deleteMap.put("campaign_id", campaignId);
+            creativeService.removeByMap(deleteMap);
+            QueryWrapper<KuaiShouGroup> groupQueryWrapper = new QueryWrapper<>();
+            groupQueryWrapper.eq("account_id", accountId);
+            groupQueryWrapper.eq("campaign_id", campaignId);
+            List<KuaiShouGroup> list = kuaiShouGroupService.list(groupQueryWrapper);
+            if (!Check.isNull(list)) {
+                for (KuaiShouGroup group : list) {
+                    executorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            param.put("unit_id", group.getUnitId());
+                            String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+                            JSONObject resultJson = JSONObject.parseObject(result);
+                            if (Check.isNull(resultJson)) {
+                                log.error("获取广告创意返回结果为空,advertiserId:{}", accountId);
+                                return;
+                            }
+                            Integer code = resultJson.getInteger("code");
+                            String message = resultJson.getString("message");
+                            if (null == code || code != 0) {
+                                log.error("获取广告创意返回结果异常,advertiserId:{},message:{}", accountId, message);
+                                return;
+                            }
+                            JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+                            if (null == details || details.size() <= 0) {
+                                return;
+                            }
+                            List<KuaiShouCreative> creatives = new ArrayList<>();
+                            for (int i = 0; i < details.size(); i++) {
+                                JSONObject detailJson = JSONObject.parseObject(details.get(i).toString());
+                                if (!Check.isNull(detailJson)) {
+                                    KuaiShouCreative creative = new KuaiShouCreative();
+                                    creative.setId("" + accountId + detailJson.getLong("creative_id"));
+                                    creative.setAccountId(accountId);
+                                    creative.setCampaignId(detailJson.getLong("campaign_id"));
+                                    creative.setUnitId(detailJson.getLong("unit_id"));
+                                    creative.setCreativeId(detailJson.getLong("creative_id"));
+                                    creative.setCreativeName(detailJson.getString("creative_name"));
+                                    creative.setCreativeMaterialType(detailJson.getInteger("creative_material_type"));
+                                    if (!Check.isNull(detailJson.getJSONArray("material_url"))) {
+                                        creative.setMaterialUrl(detailJson.getJSONArray("material_url").toJSONString());
+                                    }
+
+                                    if (!Check.isNull(detailJson.getJSONArray("image_tokens"))) {
+                                        creative.setImageTokens(detailJson.getJSONArray("image_tokens").toJSONString());
+                                    }
+                                    creative.setStatus(detailJson.getInteger("status"));
+                                    creative.setPutStatus(detailJson.getInteger("put_status"));
+                                    creative.setCreateChannel(detailJson.getInteger("create_channel"));
+                                    creative.setReviewDetail(detailJson.getString("review_detail"));
+                                    creative.setCoverUrl(detailJson.getString("cover_url"));
+                                    creative.setImageToken(detailJson.getString("image_token"));
+                                    creative.setCoverWidth(detailJson.getString("cover_width"));
+                                    creative.setCoverHeight(detailJson.getString("cover_height"));
+                                    creative.setOverlayBgUrl(detailJson.getString("overlay_bg_url"));
+                                    creative.setOverlayBgImageToken(detailJson.getString("overlay_bg_image_token"));
+                                    creative.setStickerTitle(detailJson.getString("sticker_title"));
+                                    creative.setOverlayType(detailJson.getString("overlay_type"));
+                                    creative.setClickTrackUrl(detailJson.getString("click_track_url"));
+                                    creative.setImpressionUrl(detailJson.getString("impression_url"));
+                                    creative.setAdPhotoPlayedT3sUrl(detailJson.getString("ad_photo_played_t3s_url"));
+                                    creative.setCreativeCreateTime(detailJson.getDate("create_time"));
+                                    creative.setCreativeUpdateTime(detailJson.getDate("update_time"));
+                                    creative.setFirstFrameType(detailJson.getInteger("first_frame_type"));
+                                    JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
+                                    if (!Check.isNull(displayInfoJson)) {
+                                        creative.setDescription(displayInfoJson.getString("description"));
+                                        creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
+                                    }
+                                    creative.setCreateTime(new Date());
+                                    creative.setUpdateTime(new Date());
+                                    creative.setSiteId(detailJson.getLong("site_id"));
+                                    creative.setPhotoId(detailJson.getString("photo_id"));
+                                    if (detailJson.getLong("photo_id") == 0) {
+                                        JSONArray photoIds = new JSONArray();
+                                        JSONObject programmed_creative_material = detailJson.getJSONObject("programmed_creative_material");
+                                        if (!Check.isNull(programmed_creative_material)) {
+                                            creative.setProgrammedCreativeMaterial(programmed_creative_material.toJSONString());
+                                            JSONArray materials = programmed_creative_material.getJSONArray("materials");
+                                            if (!Check.isNull(materials)) {
+                                                for (int j = 0; j < materials.size(); j++) {
+                                                    JSONObject materialJson = materials.getJSONObject(j);
+                                                    if (!Check.isNull(materialJson)) {
+                                                        Long photo_id = materialJson.getLong("photo_id");
+                                                        photoIds.add(String.valueOf(photo_id));
+                                                    }
+                                                }
+                                                creative.setPhotoIds(photoIds.toJSONString());
+                                            }
+                                        }
+                                    }
+                                    creatives.add(creative);
+                                }
+
+                            }
+                            creativeService.replaceBatch(creatives);
+                        }
+                    });
+                }
+
+            }
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+
+        }
+
+
+    }
+
 
 }