SampleTest.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package org.jeecg;
  2. import cn.com.ctop.bytedance.entity.BytedancePlanDailyReport;
  3. import cn.com.ctop.bytedance.service.IBytedancePlanDailyReportService;
  4. import cn.com.ctop.bytedance.service.IReportService;
  5. import cn.com.ctop.common.module.entity.CtopOauthToken;
  6. import cn.com.ctop.common.module.entity.UserAllocation;
  7. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  8. import cn.com.ctop.common.module.service.IUserAllocationService;
  9. import cn.com.ctop.common.module.utils.CtopAdConstant;
  10. import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
  11. import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
  12. import cn.com.ctop.toutiao.service.IByteDanceCreativeService;
  13. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.jeecg.common.util.DateUtils;
  16. import org.jeecg.modules.mq.Sender;
  17. import org.junit.Test;
  18. import org.junit.runner.RunWith;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.boot.test.context.SpringBootTest;
  22. import org.springframework.test.context.junit4.SpringRunner;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. import java.util.List;
  26. @RunWith(SpringRunner.class)
  27. @SpringBootTest
  28. @Slf4j
  29. public class SampleTest {
  30. @Value("${jeecg.path.chrome-driver}")
  31. private String chromeDriver;
  32. @Autowired
  33. private IAppiumJobService jobService;
  34. @Test
  35. public void testMq() {
  36. Sender sender = new Sender();
  37. sender.send();
  38. }
  39. @Autowired
  40. private ICtopOauthTokenService tokenService;
  41. @Autowired
  42. private IReportService reportService;
  43. @Test
  44. public void getYddData()throws Exception{
  45. String dateString = "2020-01-06";
  46. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  47. Date getDate = dateFormat.parse(dateString);
  48. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  49. if (null == tokens || tokens.size() <= 0) {
  50. log.info("定时获取头条数据异常:为获取到可用的token");
  51. return;
  52. }
  53. tokens.forEach(token -> {
  54. reportService.getAdvertiserPlanReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  55. });
  56. //清洗关于缘多多数据
  57. //1:查询缘多多相关的用户数据
  58. QueryWrapper<UserAllocation> yddWrapper = new QueryWrapper<>();
  59. yddWrapper.eq("project_id",113);
  60. List<UserAllocation> yddallocations = userAllocationService.list(yddWrapper);
  61. if(null!=yddallocations&&yddallocations.size()>0){
  62. yddallocations.forEach(allocation->{
  63. //根据accountId和时间,查询相关的日报表信息
  64. QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
  65. queryWrapper.eq("advertiser_id",allocation.getAccountId())
  66. //.eq("stat_datetime",dateString)
  67. ;
  68. List<BytedancePlanDailyReport>bytedancePlanDailyReports = planDailyReportService.list(queryWrapper);
  69. if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){
  70. bytedancePlanDailyReports.forEach(report->{
  71. String adName = report.getAdName();
  72. String[] tags = adName.split("-");
  73. report.setChannelCode(tags[0]);
  74. planDailyReportService.updateById(report);
  75. });
  76. }
  77. });
  78. }
  79. //清洗关于缘多多数据
  80. //1:查询缘多多相关的用户数据
  81. QueryWrapper<UserAllocation> dsjyWrapper = new QueryWrapper<>();
  82. yddWrapper.eq("project_id",112);
  83. List<UserAllocation> dsjyAllocations = userAllocationService.list(dsjyWrapper);
  84. if(null!=dsjyAllocations&&dsjyAllocations.size()>0){
  85. dsjyAllocations.forEach(allocation->{
  86. //根据accountId和时间,查询相关的日报表信息
  87. QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
  88. queryWrapper.eq("advertiser_id",allocation.getAccountId())
  89. //.eq("stat_datetime",dateString)
  90. ;
  91. List<BytedancePlanDailyReport>bytedancePlanDailyReports = planDailyReportService.list(queryWrapper);
  92. if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){
  93. bytedancePlanDailyReports.forEach(report->{
  94. String adName = report.getAdName();
  95. String[] tags = adName.split("-");
  96. report.setChannelCode(tags[0]);
  97. planDailyReportService.updateById(report);
  98. });
  99. }
  100. });
  101. }
  102. //清洗关于缘多多数据
  103. //1:查询缘多多相关的用户数据
  104. QueryWrapper<UserAllocation> fjyhWrapper = new QueryWrapper<>();
  105. yddWrapper.eq("project_id",222);
  106. List<UserAllocation> fjyhAllocations = userAllocationService.list(fjyhWrapper);
  107. if(null!=fjyhAllocations&&fjyhAllocations.size()>0){
  108. fjyhAllocations.forEach(allocation->{
  109. //根据accountId和时间,查询相关的日报表信息
  110. QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
  111. queryWrapper.eq("advertiser_id",allocation.getAccountId())
  112. //.eq("stat_datetime",dateString)
  113. ;
  114. List<BytedancePlanDailyReport>bytedancePlanDailyReports = planDailyReportService.list(queryWrapper);
  115. if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){
  116. bytedancePlanDailyReports.forEach(report->{
  117. String adName = report.getAdName();
  118. String[] tags = adName.split("-");
  119. report.setChannelCode(tags[0]);
  120. planDailyReportService.updateById(report);
  121. });
  122. }
  123. });
  124. }
  125. }
  126. @Test
  127. public void getZybBytedancePlanReport(){
  128. // Date getDate = DateUtils.addDay(new Date(), -1);
  129. Date getDate = new Date();
  130. //1:查询作业帮相关的用户数据
  131. QueryWrapper<UserAllocation> wrapper = new QueryWrapper<>();
  132. wrapper.eq("project_id",215);
  133. List<UserAllocation> allocations = userAllocationService.list(wrapper);
  134. if(null!=allocations){
  135. allocations.forEach(allocation->{
  136. CtopOauthToken token = tokenService.getOauthTokenByAccountId(allocation.getAccountId()+"");
  137. //3:获取广告计划信息数据
  138. reportService.getAdvertiserReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  139. });
  140. }
  141. //清洗关于作业帮数据
  142. if(null!=allocations&&allocations.size()>0){
  143. allocations.forEach(allocation->{
  144. //根据accountId和时间,查询相关的日报表信息
  145. QueryWrapper<BytedancePlanDailyReport> queryWrapper = new QueryWrapper<>();
  146. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  147. String dateString = dateFormat.format(getDate)+" 00:00:00";
  148. System.out.println(dateString);
  149. queryWrapper.eq("advertiser_id",allocation.getAccountId())
  150. // .eq("stat_datetime",dateString)
  151. ;
  152. List<BytedancePlanDailyReport>bytedancePlanDailyReports = planDailyReportService.list(queryWrapper);
  153. if(null!=bytedancePlanDailyReports&&bytedancePlanDailyReports.size()>0){
  154. bytedancePlanDailyReports.forEach(report->{
  155. String adName = report.getAdName();
  156. System.out.println(adName);
  157. String[] tags = adName.split("-");
  158. report.setAdsense(tags[1]);
  159. report.setPlanCode(tags[2]);
  160. String tag = tags[3];
  161. if(tag.contains("其他")){
  162. report.setMaterialType("其他");
  163. }else if (tag.contains("图片轮播")){
  164. report.setMaterialType("图片轮播");
  165. }else if(tag.contains("大字报")){
  166. report.setMaterialType("大字报");
  167. }else if(tag.contains("文字动画")){
  168. report.setMaterialType("文字动画");
  169. }else if(tag.contains("采访形式")){
  170. report.setMaterialType("采访形式");
  171. }else if(tag.contains("剧情")){
  172. report.setMaterialType("剧情");
  173. }else if(tag.contains("口播")){
  174. report.setMaterialType("口播");
  175. }else{
  176. report.setMaterialType("其他");
  177. }
  178. planDailyReportService.updateById(report);
  179. });
  180. }
  181. });
  182. }
  183. }
  184. @Test
  185. public void getByteDanceCreativeDate()throws Exception{
  186. String dateString = "2020-01-06";
  187. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  188. Date getDate = dateFormat.parse(dateString);
  189. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  190. if (null == tokens || tokens.size() <= 0) {
  191. log.info("定时获取头条数据异常:为获取到可用的token");
  192. return;
  193. }
  194. tokens.forEach(token -> {
  195. //3:获取广告计划信息数据
  196. // creativeService.getAdvertiserCreative(token.getAccountId() + "", "", null);
  197. //2:获取全量素材数据
  198. // advertiserDataService.getMaterialList(token);
  199. reportService.getAdvertiserPlanReport(token,getDate,getDate,CtopAdConstant.BYTEDANCE_REPORT_TYPE_DAILY);
  200. });
  201. }
  202. @Autowired
  203. private IByteDanceAdvertiserDataService advertiserDataService;
  204. @Autowired
  205. private IByteDanceCreativeService creativeService;
  206. @Test
  207. public void getBytedancePlanHourReport(){
  208. Date getDate = DateUtils.addDay(new Date(), -1);
  209. //1:查询当日数据
  210. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  211. if (null == tokens || tokens.size() <= 0) {
  212. log.info("定时获取头条数据异常:为获取到可用的token");
  213. return;
  214. }
  215. tokens.forEach(token -> {
  216. //3:获取广告计划信息数据
  217. advertiserDataService.getAdvertiserPlan(token, "", null, null);
  218. });
  219. }
  220. @Test
  221. public void loadRegistOrderData(){
  222. }
  223. @Autowired
  224. private IUserAllocationService userAllocationService;
  225. @Autowired
  226. private IBytedancePlanDailyReportService planDailyReportService;
  227. }