فهرست منبع

修改头条定时任务

syh 4 سال پیش
والد
کامیت
783b4981ba
15فایلهای تغییر یافته به همراه117 افزوده شده و 170 حذف شده
  1. 0 4
      jeecg-boot-module-system/src/main/java/org/jeecg/config/RedisConfig.java
  2. 0 3
      jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java
  3. 2 1
      jeecg-boot-module-system/src/main/resources/application.yml
  4. 9 157
      jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java
  5. 2 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/StatusCode.java
  6. 54 0
      module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceMaterialsLoadJob.java
  7. 6 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeController.java
  8. 2 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceVideoInfoMapper.java
  9. 3 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceVideoInfoMapper.xml
  10. 2 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceVideoInfoService.java
  11. 0 1
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IBytedanceImageInfoService.java
  12. 1 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java
  13. 1 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCampaignServiceImpl.java
  14. 30 4
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCreativeServiceImpl.java
  15. 5 0
      module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceVideoInfoServiceImpl.java

+ 0 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/config/RedisConfig.java

@@ -42,7 +42,6 @@ public class RedisConfig extends CachingConfigurerSupport {
 		return new KeyGenerator() {
 			@Override
 			public Object generate(Object target, Method method, Object... params) {
-
 				StringBuilder sb = new StringBuilder();
 				sb.append(target.getClass().getName());
 				sb.append(method.getDeclaringClass().getName());
@@ -97,11 +96,8 @@ public class RedisConfig extends CachingConfigurerSupport {
 		// RedisCacheConfiguration config =
 		// RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
 		// 创建默认缓存配置对象
-
-		// 创建默认缓存配置对象
         //设置缓存默认有效期3小时;
         RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(3));
-
 		RedisCacheManager cacheManager = new RedisCacheManager(writer, config);
 		return cacheManager;
 	}

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

@@ -32,9 +32,6 @@ import java.util.Map;
 
 @Configuration
 public class ShiroConfig {
-//    @Value("${jeecg.shiro.excludeUrls}")
-//    private String excludeUrls;
-
     @Value("${spring.redis.port}")
     private String port;
 

+ 2 - 1
jeecg-boot-module-system/src/main/resources/application.yml

@@ -1,6 +1,7 @@
 spring:
   profiles:
-    active: @activatedProperties@
+#    active: @activatedProperties@
+    active: wps
 swagger:
   production: false
   basic:

+ 9 - 157
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,187 +1,39 @@
 package org.jeecg;
 
-import cn.com.ctop.common.module.entity.BindAccountLogin;
 import cn.com.ctop.common.module.entity.CtopOauthToken;
-import cn.com.ctop.common.module.service.IBindAccountLoginService;
 import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
-import cn.com.ctop.common.module.utils.CtopAdConstant;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.crawler.modules.pangolin.entity.PangolinApp;
-import cn.com.ctop.crawler.modules.pangolin.service.PangolinAppService;
-import cn.com.ctop.crawler.modules.pangolin.service.PangolinCrawlerService;
-import cn.com.ctop.crawler.modules.pangolin.service.PangolinLoginService;
-import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
-import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceCampaignService;
-import cn.com.ctop.toutiao.modules.report.service.IReportService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import lombok.extern.slf4j.Slf4j;
-import org.jeecg.common.util.DateUtils;
-import org.jeecg.modules.ctop.entity.KuaishouEffectVideoInfo;
-import org.jeecg.modules.ctop.service.IKuaishouEffectVideoInfoService;
-import org.jeecg.modules.demo.mock.MockController;
-import org.jeecg.modules.demo.test.entity.JeecgDemo;
-import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
-import org.jeecg.modules.demo.test.service.IJeecgDemoService;
-import org.jeecg.modules.system.service.ISysDataLogService;
-import org.junit.Assert;
-import org.jeecg.modules.ctop.service.IRuleEngineService;
-import org.jeecg.modules.ctop.vo.QueryParam;
-import org.jeecg.modules.ctop.vo.RuleResult;
+import cn.com.ctop.toutiao.modules.report.service.IReportService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.kie.api.runtime.KieSession;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import javax.annotation.Resource;
-import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
 @RunWith(SpringRunner.class)
 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("wps")
 public class SampleTest {
     @Autowired
     private ICtopOauthTokenService oauthTokenService;
     @Autowired
-    private IByteDanceAdvertiserDataService advertiserDataService;
-    @Autowired
     private IReportService reportService;
-    @Autowired
-    private IKuaishouInterfaceService interfaceService;
-	@Resource
-	private JeecgDemoMapper jeecgDemoMapper;
-	@Resource
-	private IJeecgDemoService jeecgDemoService;
-	@Resource
-	private ISysDataLogService sysDataLogService;
-	@Resource
-	private MockController mock;
+	@Autowired
     private IByteDanceCreativeService creativeService;
+	@Autowired
+    private IByteDanceCampaignService campaignService;
 
     @Test
     public void loadBytedanceCreativeData() {
-        /**
-         *
-         */
         CtopOauthToken token = oauthTokenService.getTokenByAccountId(1649600126891015L);
         creativeService.getAdvertiserCreative(token,null,null);
-//        advertiserDataService.getMaterialList(token);
     }
 
-    @Autowired
-    private IBindAccountLoginService bindAccountLoginService;
-    @Autowired
-    private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
-
-	@Test
-	public void testSelect() {
-		System.out.println(("----- selectAll method test ------"));
-		List<JeecgDemo> userList = jeecgDemoMapper.selectList(null);
-		Assert.assertEquals(5, userList.size());
-		userList.forEach(System.out::println);
-	}
-
-	@Test
-	public void testXmlSql() {
-		System.out.println(("----- selectAll method test ------"));
-		List<JeecgDemo> userList = jeecgDemoMapper.getDemoByName("Sandy12");
-		userList.forEach(System.out::println);
-	}
-
-	/**
-	 * 测试事务
-	 */
-	@Test
-	public void testTran() {
-		jeecgDemoService.testTran();
-	}
-
-	//author:lvdandan-----date:20190315---for:添加数据日志测试----
-	/**
-	 * 测试数据日志添加
-	 */
-	@Test
-	public void testDataLogSave() {
-		System.out.println(("----- datalog test ------"));
-		String tableName = "jeecg_demo";
-		String dataId = "4028ef81550c1a7901550c1cd6e70001";
-		String dataContent = mock.sysDataLogJson();
-		sysDataLogService.addDataLog(tableName, dataId, dataContent);
-	}
-	//author:lvdandan-----date:20190315---for:添加数据日志测试----
-
-
-    @Autowired
-    private IByteDanceCampaignService campaignService;
-    @Test
-    public void testGetCampaign(){
-        CtopOauthToken token = oauthTokenService.getOauthTokenByAccountId("1649600126891015");
-        campaignService.getAdvertiserCampaign(token,"1672261893872756",null);
-    }
-
-    @Autowired
-    private IKuaishouEffectVideoInfoService effectVideoInfoService;
-    @Test
-    public void loadKuaishouEffectVideoInfo(){
-        List<KuaishouEffectVideoInfo>videoInfos = effectVideoInfoService.list();
-        for (KuaishouEffectVideoInfo video:videoInfos) {
-            if(null!=video.getSignature()&&!"".equals(video.getSignature())){
-                effectVideoInfoService.updateFinalCostDateBySignature(video.getSignature());
-                effectVideoInfoService.updateInitialCostDateBySignature(video.getSignature());
-                effectVideoInfoService.updateTotalCostBySignature(video.getSignature());
-//                effectVideoInfoService.updateTowWeekCostBySignature(video.getSignature());
-            }
-        }
-    }
-
-    @Test
-    public void getIndustryInfo(){
-        String access_token = "cbdf6502c04978ae401cb92a64530fb73a8c7dbe";
-        // 请求地址
-        String url = "https://ad.oceanengine.com/open_api/2/tools/industry/get/";
-        JSONObject jsonObject = HttpUtils.bytedanceGetRequest(access_token, url, new JSONObject());
-        System.out.println(jsonObject.toJSONString());
-    }
-
-    @Test
-    public void loadImageInfo()throws Exception{
-        List<CtopOauthToken>tokens = oauthTokenService.selectToutiaoToken();
-        for (CtopOauthToken token:tokens) {
-            advertiserDataService.getImageByPage(token,null,1);
-            Thread.sleep(1000L);
-        }
-    }
-
-    @Resource
-    private KieSession kieSession;
-    @Autowired
-    private IRuleEngineService ruleEngineService ;
-
     @Test
-    public void testEngine(){
-        QueryParam queryParam1 = new QueryParam() ;
-        queryParam1.setParamId("1");
-        queryParam1.setParamSign("+");
-        QueryParam queryParam2 = new QueryParam() ;
-        queryParam2.setParamId("2");
-        queryParam2.setParamSign("-");
-        // 入参
-        kieSession.insert(queryParam1);
-        kieSession.insert(queryParam2);
-        kieSession.insert(this.ruleEngineService);
-        // 返参
-        RuleResult resultParam = new RuleResult();
-        kieSession.insert(resultParam);
-        kieSession.fireAllRules();
-        System.out.println(resultParam.isPostCodeResult());
+    public void testLoadBytedanceData(){
+        CtopOauthToken token = oauthTokenService.getTokenByAccountId(1673731621920840L);
+       campaignService.getAdvertiserCampaign(token,null,null);
     }
 }

+ 2 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/StatusCode.java

@@ -22,6 +22,8 @@ public enum StatusCode {
     COMMON_PARAM_ERROR("参数异常", -1, false),
     COMMON_ACCOUNT_ERROR("参数异常", -2, false),
     COMMON_DATA_NOT_EXIST("数据不存在或者已经被删除", -101, false),
+    BYTEDANCE_PLAN_DATA_NOT_EXIST("此计划不存在或者已经被删除", -101, false),
+    BYTEDANCE_ACCOUNT_DATA_NOT_EXIST("此账户尚未绑定或已停投", -101, false),
     COMMON_VERSION_NOT_EXIST("版本号不存在", -102, false),
     BYTEDANCE_VIDEO_UPLOAD_FAIL("今日头条视频文件上传失败", -201, false),
     MATERIAL_UPLOAD_FAIL("素材文件上传失败", -201, false),

+ 54 - 0
module-job-bytedance/src/main/java/cn/com/ctop/job/bytedance/handler/BytedanceMaterialsLoadJob.java

@@ -0,0 +1,54 @@
+package cn.com.ctop.job.bytedance.handler;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.xxl.job.core.log.XxlJobLogger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+@Component
+public class BytedanceMaterialsLoadJob {
+    @Autowired
+    private ICtopOauthTokenService tokenService;
+    static ExecutorService executorService = Executors.newFixedThreadPool(4);
+    //线程计数器
+    static CountDownLatch countDownLatch = null;
+    @Autowired
+    private IByteDanceAdvertiserDataService advertiserDataService;
+
+    @XxlJob("bytedanceMaterialsLoadJob")
+    public ReturnT<String> execute(String param) throws Exception{
+        List<CtopOauthToken> tokens = tokenService.selectToutiaoToken();
+        countDownLatch = new CountDownLatch(tokens.size());
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //获取全量视频素材数据
+                        advertiserDataService.getMaterialList(token);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                        countDownLatch.countDown();
+                    }
+                }
+            });
+        });
+        try {
+            countDownLatch.await();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+        XxlJobLogger.log("物料数据同步完成");
+        return ReturnT.SUCCESS;
+    }
+}

+ 6 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/controller/ByteDanceCreativeController.java

@@ -151,6 +151,12 @@ public class ByteDanceCreativeController {
         return result;
     }
 
+    @PostMapping("/detail")
+    public Map<String,Object>creativeDetail(@RequestParam(name = "adId",required = true,defaultValue = "0") Long adId,
+                                            @RequestParam(name = "accountId",required = true,defaultValue = "0") Long accountId){
+        return byteDanceCreativeService.getCreativeDetail(accountId,adId);
+    }
+
     /**
      * 通过id删除
      *

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/ByteDanceVideoInfoMapper.java

@@ -15,4 +15,6 @@ import java.util.List;
 public interface ByteDanceVideoInfoMapper extends BaseMapper<ByteDanceVideoInfo> {
 
     void replaceBatch(@Param(value = "videoList") List<ByteDanceVideoInfo> videoInfoList);
+
+    void updateVideoType();
 }

+ 3 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/mapper/xml/ByteDanceVideoInfoMapper.xml

@@ -51,4 +51,7 @@
             )
         </foreach>
     </insert>
+    <update id="updateVideoType">
+        update ctop_bytedance_video_info set type = 2 where height&gt;width
+    </update>
 </mapper>

+ 2 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IByteDanceVideoInfoService.java

@@ -16,4 +16,6 @@ public interface IByteDanceVideoInfoService extends IService<ByteDanceVideoInfo>
     void replaceBatch(List<ByteDanceVideoInfo> videoInfoList);
 
     ByteDanceVideoInfo getOneByParams(Long materialId);
+
+    void updateVideoType();
 }

+ 0 - 1
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/IBytedanceImageInfoService.java

@@ -12,6 +12,5 @@ import java.util.List;
  * @version V1.0
  */
 public interface IBytedanceImageInfoService extends IService<BytedanceImageInfo> {
-
     void replaceBatch(List<BytedanceImageInfo> videoInfoList);
 }

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -577,6 +577,7 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
     public void getMaterialList(CtopOauthToken token) {
         getVideoByPage(token, "", 1);
         getImageByPage(token, "", 1);
+        videoInfoService.updateVideoType();
     }
 
     @Autowired

+ 1 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCampaignServiceImpl.java

@@ -178,6 +178,7 @@ public class ByteDanceCampaignServiceImpl extends ServiceImpl<ByteDanceCampaignM
         params.put("page", pageNumber + "");
         params.put("page_size", 100);
         String result = HttpUtils.httpGetRequest(url, headers, params);
+        System.out.println(result);
         JSONObject jsonObject = JSONObject.parseObject(result);
         Integer code = jsonObject.getInteger("code");
         if (null == code || !code.equals(0)) {

+ 30 - 4
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceCreativeServiceImpl.java

@@ -1,10 +1,14 @@
 package cn.com.ctop.toutiao.modules.material.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.*;
+import cn.com.ctop.toutiao.modules.material.entity.ByteDanceAdvertisePlan;
 import cn.com.ctop.toutiao.modules.material.entity.ByteDanceCreative;
 import cn.com.ctop.toutiao.modules.material.mapper.ByteDanceCreativeMapper;
+import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertisePlanService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -12,7 +16,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;
@@ -28,12 +31,15 @@ import java.util.TreeMap;
  */
 @Slf4j
 @Service
-@Primary
 public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeMapper, ByteDanceCreative> implements IByteDanceCreativeService {
     @Autowired
     private ICtopOauthTokenService tokenService;
     @Autowired
     private ByteDanceCreativeMapper creativeMapper;
+    @Autowired
+    private IUserAllocationService userAllocationService;
+    @Autowired
+    private IByteDanceAdvertisePlanService byteDanceAdvertisePlanService;
 
     /**
      * 更改创意状态
@@ -189,7 +195,6 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
         resultMap.put("message", "广告计划("+adId+"):"+"创意创建成功");
         return resultMap;
     }
-
     /**
      * 获取创意详细信息
      * @return
@@ -197,6 +202,20 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
     @Override
     public Map<String, Object> getCreativeDetail(Long accountId, Long adId){
         Map<String,Object>resultMap = new HashMap<>();
+        if(null == adId||adId == 0||null == accountId||accountId == 0){
+            ResultMapUtils.setResultMap(resultMap,StatusCode.COMMON_PARAM_ERROR);
+            return resultMap;
+        }
+        UserAllocation allocation = userAllocationService.getByAccountId(accountId);
+        if(null == allocation||allocation.getAccountStatus()!=0){
+            ResultMapUtils.setResultMap(resultMap,StatusCode.BYTEDANCE_PLAN_DATA_NOT_EXIST);
+            return resultMap;
+        }
+        ByteDanceAdvertisePlan plan = byteDanceAdvertisePlanService.getById(adId);
+        if(null == plan||plan.getOptStatus().equals("AD_STATUS_DELETE")){
+            ResultMapUtils.setResultMap(resultMap,StatusCode.BYTEDANCE_ACCOUNT_DATA_NOT_EXIST);
+            return resultMap;
+        }
         CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
         // 请求地址
         String url = PropertiesUtils.getValue("bytedance_config", "bytedance_api_url") + PropertiesUtils.getValue("bytedance_config", "bytedance_v2_creative_read");
@@ -214,11 +233,17 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
             resultMap.put("message", message);
             return resultMap;
         }
-        resultMap.put("data",result.getJSONObject("data"));
+        JSONObject getData = result.getJSONObject("data");
+        resultMap.put("data",formatData(getData));
         ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS);
         return resultMap;
     }
 
+    private JSONObject formatData(JSONObject getData) {
+        JSONObject data = new JSONObject();
+        return data;
+    }
+
     /**
      * TODO 后续需要拼接参数
      * @param accountId
@@ -301,6 +326,7 @@ public class ByteDanceCreativeServiceImpl extends ServiceImpl<ByteDanceCreativeM
         return result;
     }
 
+
     private JSONObject initParams(JSONObject data) {
         JSONObject params = new JSONObject();
         String creativeWay = data.getString("creativeWay");

+ 5 - 0
module-toutiao/src/main/java/cn/com/ctop/toutiao/modules/material/service/impl/ByteDanceVideoInfoServiceImpl.java

@@ -35,4 +35,9 @@ public class ByteDanceVideoInfoServiceImpl extends ServiceImpl<ByteDanceVideoInf
         queryWrapper.last("limit 1");
         return this.getOne(queryWrapper);
     }
+
+    @Override
+    public void updateVideoType() {
+        videoInfoMapper.updateVideoType();
+    }
 }