yumeng hace 5 años
padre
commit
3de2494528

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -134,6 +134,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/qywexin", "anon");
         filterChainDefinitionMap.put("/test/getGroupData/**", "anon");
         filterChainDefinitionMap.put("/test/getVideoAndImage/**", "anon");
+        filterChainDefinitionMap.put("/test/gerCreative/**", "anon");
 
 		filterChainDefinitionMap.put("/report/kuaishouReportDailyAgent/get","anon");
 

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

@@ -2,7 +2,10 @@ package org.jeecg.modules.ctop.controller;
 
 
 import cn.com.ctop.common.module.entity.MaterialInfo;
+import cn.com.ctop.common.module.service.IMaterialAscriptionService;
 import cn.com.ctop.common.module.service.IMaterialInfoService;
+import cn.com.ctop.common.module.service.IMaterialParameterService;
+import cn.com.ctop.common.module.service.IMaterialTagService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import com.alibaba.fastjson.JSON;
@@ -40,8 +43,11 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * 素材信息
@@ -57,6 +63,12 @@ import java.util.Map;
 public class MaterialInfoController {
     @Autowired
     private IMaterialInfoService materialInfoService;
+    @Autowired
+    private IMaterialAscriptionService materialAscriptionService;
+    @Autowired
+    private IMaterialParameterService materialParameterService;
+    @Autowired
+    private IMaterialTagService materialTagService;
 
     @GetMapping(value = "/report")
     public JSONObject report(String userId) {
@@ -247,6 +259,12 @@ public class MaterialInfoController {
     public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
         try {
             materialInfoService.removeById(id);
+            Map<String, Object> deleteMap = new HashMap<>();
+            deleteMap.put("material_id", id);
+
+            materialAscriptionService.removeByMap(deleteMap);
+            materialParameterService.removeByMap(deleteMap);
+            materialTagService.removeByMap(deleteMap);
         } catch (Exception e) {
             log.error("删除失败", e.getMessage());
             return Result.error("删除失败!");
@@ -327,6 +345,7 @@ public class MaterialInfoController {
         return mv;
     }
 
+
     /**
      * 通过excel导入数据
      *

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

@@ -16,6 +16,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * @author jeecg-boot
@@ -114,4 +116,27 @@ public class TestController {
         return "Success";
     }
 
+    @Autowired
+    private CtopOauthTokenMapper oauthTokenMapper;
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
+
+    @GetMapping(value = "/gerCreative")
+    public void gerCreative() {
+        QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
+        oauthTokenQueryWrapper.eq("media_id", 2);
+        List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(oauthTokenQueryWrapper);
+        for (CtopOauthToken token : ctopOauthTokens) {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        kuaishouInterfaceService.getCreativeList(token, null, null);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+
+    }
 }

+ 32 - 7
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,9 +1,7 @@
 package org.jeecg;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
-import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.utils.HttpUtils2;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
 import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
@@ -29,6 +27,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -157,19 +157,44 @@ public class SampleTest {
     private IAccountWarningService accountWarningService;
     @Autowired
     private CtopOauthTokenMapper oauthTokenMapper;
+    static ExecutorService executorService = Executors.newFixedThreadPool(5);
 
     @Test
     public void testMa() throws Exception {
         // accountWarningService.accountWarning(23212L);
         QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
-        oauthTokenQueryWrapper.eq("account_id", 23212L);
-        CtopOauthToken token = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);
-        kuaishouInterfaceService.getVideoList(token, null, null);
-        //3: 获取图片信息数据
-        kuaishouInterfaceService.getImageList(token, null, null);
+        oauthTokenQueryWrapper.eq("media_id", 2);
+        List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(oauthTokenQueryWrapper);
+        for (CtopOauthToken token : ctopOauthTokens) {
+            kuaishouInterfaceService.getCreativeList(token, null, null);
+        }
+
+
     }
 
 
+    @Test
+    public void testMa2() throws Exception {
+
+        QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
+        oauthTokenQueryWrapper.eq("media_id", 2);
+        List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(oauthTokenQueryWrapper);
+        for (CtopOauthToken token : ctopOauthTokens) {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        kuaishouInterfaceService.getCreativeList(token, null, null);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+
+
+    }
+
 }
 
 

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

@@ -197,8 +197,6 @@ public class BatchController {
     @PostMapping(value = "/batchUpdateDayBudget")
     public Result<JSONObject> batchUpdateDayBudget(@RequestBody JSONObject requestJson) {
         Result<JSONObject> result = new Result<>();
-
-
         try {
             Long accountId = requestJson.getLong("accountId");
             CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
@@ -604,7 +602,6 @@ public class BatchController {
     private IKuaiShouCreativeService kuaiShouCreativeService;
 
 
-    @AutoLog(value = "快手-创意信息-分页列表查询")
     @GetMapping(value = "/getCreativeList")
     public Result<IPage<KuaiShouCreative>> getCreativeList(KuaiShouCreative kuaiShouCreative, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
@@ -821,7 +818,6 @@ public class BatchController {
         return result;
 
 
-
     }
 
     /**
@@ -929,4 +925,63 @@ public class BatchController {
         return result;
     }
 
+
+    /**
+     * 批量修改广告组状态
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/batchUpdateCreativeStatus")
+    public Result<JSONObject> batchUpdateCreativeStatus(@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 creativeIds = requestJson.getJSONArray("creativeIds");
+            JSONArray failArr = new JSONArray();
+            if (!Check.isNull(creativeIds)) {
+                for (int i = 0; i < creativeIds.size(); i++) {
+                    Long creativeId = creativeIds.getLong(i);
+                    if (!Check.isNull(creativeId)) {
+                        Map<String, Object> updateMap = updateService.updateCreativeStatus(token.getAccessToken(), accountId, creativeId, 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"));
+                                KuaiShouCreative creative = batchService.getCreativeInfo(accountId, creativeId);
+                                if (!Check.isNull(creative)) {
+                                    failJson.put("campaignName", creative.getCreativeName());
+                                }
+                                failArr.add(failJson);
+                            }
+                        }
+                    }
+                }
+            }
+            JSONObject json = new JSONObject();
+            json.put("totalCount", creativeIds.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;
+    }
+
 }

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

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.batch.service;
 
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 import com.alibaba.fastjson.JSONObject;
 
@@ -75,4 +76,13 @@ public interface IBatchService {
      * @return
      */
     JSONObject createCreative(JSONObject requestJson) throws Exception;
+
+    /**
+     * 获取创意信息
+     *
+     * @param accountId
+     * @param creativeId
+     * @return
+     */
+    KuaiShouCreative getCreativeInfo(Long accountId, Long creativeId);
 }

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

@@ -348,4 +348,6 @@ public interface IKuaishouInterfaceService {
     void getVideoList2(CtopOauthToken token, Date startDate, Date endDate, Integer page);
 
     void getCreativeList2(CtopOauthToken token, Date startDate, Date endDate, Integer page);
+
+    void getCreative(String token, Long advertiserId, Long creativeId);
 }

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

@@ -6,9 +6,11 @@ import cn.com.ctop.common.module.mapper.UserAllocationMapper;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCampaign;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouCreative;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouGroup;
 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.mapper.KuaiShouCreativeMapper;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouGroupMapper;
 import cn.com.ctop.kuaishou.modules.batch.service.IBatchService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
@@ -504,6 +506,28 @@ public class BatchServiceImpl implements IBatchService {
         return returnJson;
     }
 
+    @Autowired
+    private KuaiShouCreativeMapper creativeMapper;
+
+
+    /**
+     * 获取创意信息
+     *
+     * @param accountId
+     * @param creativeId
+     * @return
+     */
+    @Override
+    public KuaiShouCreative getCreativeInfo(Long accountId, Long creativeId) {
+        QueryWrapper<KuaiShouCreative> creativeQueryWrapper = new QueryWrapper<>();
+        creativeQueryWrapper.eq("account_id", accountId);
+        creativeQueryWrapper.eq("creative_id", creativeId);
+        creativeQueryWrapper.orderByDesc("create_time");
+        creativeQueryWrapper.last("limit 1");
+        KuaiShouCreative creative = creativeMapper.selectOne(creativeQueryWrapper);
+        return creative;
+    }
+
 
 }
 

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

@@ -408,6 +408,9 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
      * @param putStatus
      * @return
      */
+    @Autowired
+    private KuaiShouCreativeMapper creativeMapper;
+
     @Override
     public Map<String, Object> updateCreativeStatus(String token, Long advertiserId, Long creativeId, int putStatus, String loginId) {
         Map<String, Object> returnMap = new HashMap<>();
@@ -425,6 +428,17 @@ public class KuaiShouUpdateServiceImpl implements IKuaiShouUpdateService {
             if (!Check.isNull(resultJson)) {
                 Integer code = resultJson.getInteger("code");
                 if (code == 0) {
+
+                    if (putStatus == 3) {
+                        Map<String, Object> deleteMap = new HashMap<>();
+                        deleteMap.put("account_id", advertiserId);
+                        deleteMap.put("creative_id", creativeId);
+                        creativeMapper.deleteByMap(deleteMap);
+                    } else {
+                        interfaceService.getCreative(token, advertiserId, creativeId);
+                    }
+
+
                     returnMap.put("code", 0);
                     returnMap.put("success", true);
                     returnMap.put("message", "修改成功");

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

@@ -1720,6 +1720,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
 
             String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
             JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println(resultJson);
             if (Check.isNull(resultJson)) {
                 log.error("获取广告创意返回结果为空,advertiserId:{}", token.getAccountId());
                 return;
@@ -1788,9 +1789,94 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         }
     }
 
+    @Override
+    public void getCreative(String token, Long advertiserId, Long creativeId) {
+        try {
+            log.info("快手创意数据获取,accountId:{}", advertiserId);
+            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", token);
+            JSONObject param = new JSONObject();
+            param.put("advertiser_id", advertiserId);
+            param.put("creative_id", creativeId);
+            param.put("page_size", 200);
+            param.put("page", 1);
+
+            String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            System.err.println(resultJson);
+            if (Check.isNull(resultJson)) {
+                log.error("获取广告创意返回结果为空,advertiserId:{}", advertiserId);
+                return;
+            }
+            Integer code = resultJson.getInteger("code");
+            String message = resultJson.getString("message");
+            if (null == code || code != 0) {
+                log.error("获取广告创意返回结果异常,advertiserId:{},message:{}", advertiserId, message);
+                return;
+            }
+            JSONArray details = resultJson.getJSONObject("data").getJSONArray("details");
+            if (null == details || details.size() <= 0) {
+//            log.error("获取广告创意返回结果数据为空,advertiserId:{}", advertiserId);
+                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("" + advertiserId + detailJson.getLong("creative_id"));
+                    creative.setAccountId(advertiserId);
+                    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"));
+                    creative.setPhotoId(detailJson.getString("photo_id"));
+                    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"));
+                    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());
+                    creatives.add(creative);
+                }
+            }
+            creativeService.replaceBatch(creatives);
+        } catch (Exception e) {
+            e.printStackTrace();
+
+        }
+    }
+
 
     public void getCreativeListByPage(String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page) {
         try {
+            System.err.println("获取创意accountId:" + advertiserId);
             String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
             Map<String, String> headers = new HashMap<>();
             headers.put("Content-Type", " application/json");