SampleTest.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package org.jeecg;
  2. import cn.com.ctop.common.module.entity.CtopOauthToken;
  3. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  4. import cn.com.ctop.common.module.service.IFileInfoService;
  5. import cn.com.ctop.common.module.utils.OSSUtils;
  6. import cn.com.ctop.common.module.utils.StringUtils;
  7. import cn.com.ctop.toutiao.entity.ByteDanceUserOrientationTemplate;
  8. import cn.com.ctop.toutiao.entity.BytedanceInterestCategory;
  9. import cn.com.ctop.toutiao.mapper.ByteDanceUserOrientationTemplateMapper;
  10. import cn.com.ctop.toutiao.mapper.BytedanceAreaInfoMapper;
  11. import cn.com.ctop.toutiao.mapper.BytedanceInterestCategoryMapper;
  12. import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
  13. import com.alibaba.fastjson.JSONArray;
  14. import com.alibaba.fastjson.JSONObject;
  15. import org.jeecg.common.util.jsonschema.JsonschemaUtil;
  16. import org.jeecg.modules.ctop.service.ICreateInternalService;
  17. import org.jeecg.modules.demo.mock.MockController;
  18. import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
  19. import org.jeecg.modules.demo.test.service.IJeecgDemoService;
  20. import org.jeecg.modules.system.service.ISysDataLogService;
  21. import org.junit.Test;
  22. import org.junit.runner.RunWith;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.boot.test.context.SpringBootTest;
  25. import org.springframework.test.context.junit4.SpringRunner;
  26. import javax.annotation.Resource;
  27. import java.io.File;
  28. import java.util.ArrayList;
  29. import java.util.Date;
  30. import java.util.Map;
  31. @RunWith(SpringRunner.class)
  32. @SpringBootTest
  33. public class SampleTest {
  34. @Resource
  35. private JeecgDemoMapper jeecgDemoMapper;
  36. @Resource
  37. private IJeecgDemoService jeecgDemoService;
  38. @Resource
  39. private ISysDataLogService sysDataLogService;
  40. @Resource
  41. private MockController mock;
  42. @Autowired
  43. private ICreateInternalService createInternalService;
  44. @Test
  45. public void testLogin() {
  46. Map<String, Object> map = createInternalService.checkAccountPassword("dcd_ad@bytedance.com", "typdDCD@2018");
  47. System.out.println(map.toString());
  48. }
  49. @Test
  50. public void testFileType() {
  51. File file = new File("D:\\工作文件\\360借条\\快手后台数据-户1.csv");
  52. System.out.println(file);
  53. }
  54. @Test
  55. public void testFileUpload() {
  56. OSSUtils.uploadObject2Oss(new File("D:\\upload\\excel\\template.xlsx"));
  57. }
  58. @Test
  59. public void testNg() {
  60. JSONObject json = new JSONObject();
  61. System.err.println(json);
  62. createInternalService.createInternal(json);
  63. }
  64. @Autowired
  65. private BytedanceAreaInfoMapper areaInfoMapper;
  66. @Autowired
  67. private BytedanceInterestCategoryMapper interestCategoryMapper;
  68. @Test
  69. public void setCategoryData() {
  70. String path = "D:\\工作文件\\头条批量\\data_20190222\\ad_tag.json";
  71. String jsonString = JsonschemaUtil.readJsonFile(path);
  72. JSONObject data = JSONObject.parseObject(jsonString);
  73. JSONArray tagArray = data.getJSONArray("adtags");
  74. tagArray.forEach(tag -> {
  75. JSONObject getTag = (JSONObject) tag;
  76. String pcode = getTag.getString("value");
  77. String plabel = getTag.getString("label");
  78. BytedanceInterestCategory category = new BytedanceInterestCategory();
  79. category.setCode(pcode);
  80. category.setName(plabel);
  81. category.setParentCode("0");
  82. category.setLevel(1);
  83. category.setCreateTime(new Date());
  84. category.setUpdateTime(new Date());
  85. interestCategoryMapper.insert(category);
  86. JSONArray children = getTag.getJSONArray("subTags");
  87. children.forEach(child -> {
  88. JSONObject getchild = (JSONObject) child;
  89. String code = getchild.getString("value");
  90. String label = getchild.getString("label");
  91. BytedanceInterestCategory childCategory = new BytedanceInterestCategory();
  92. childCategory.setCode(code);
  93. childCategory.setName(label);
  94. childCategory.setParentCode(pcode);
  95. childCategory.setLevel(2);
  96. childCategory.setCreateTime(new Date());
  97. childCategory.setUpdateTime(new Date());
  98. interestCategoryMapper.insert(childCategory);
  99. });
  100. });
  101. }
  102. @Autowired
  103. private ICtopOauthTokenService tokenService;
  104. @Autowired
  105. private ByteDanceUserOrientationTemplateMapper userOrientationTemplateMapper;
  106. @Autowired
  107. private IByteDanceAdvertiserDataService advertiserDataService;
  108. @Test
  109. public void testEditPlan() throws Exception {
  110. String accountId = "74099510334";
  111. Long userOrientationId = 5L;
  112. Long adId = 1643004580559934L;
  113. //修改用户定向
  114. ByteDanceUserOrientationTemplate template = userOrientationTemplateMapper.selectById(userOrientationId);
  115. if (null != template) {
  116. CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId);
  117. if (null != token) {
  118. //获取modify_time
  119. Thread.sleep(5000L);
  120. advertiserDataService.getAdvertiserPlan(accountId, adId + "");
  121. advertiserDataService.updateAd(token, adId, template);
  122. }
  123. }
  124. }
  125. @Autowired
  126. private IFileInfoService fileInfoService;
  127. @Test
  128. public void setJSONFile() {
  129. CtopOauthToken token = tokenService.getOauthTokenByAccountId("93289889842");
  130. JSONObject wordsObject = fileInfoService.getCreativeWord(token, token.getAccountId());
  131. String getTitle = "哈哈{日期}{男人女人}";
  132. JSONArray ids = getCreativeWordIds(getTitle, wordsObject);
  133. System.out.println(ids);
  134. }
  135. public JSONArray getCreativeWordIds(String getTitle, JSONObject wordsObject) {
  136. ArrayList<String> wordsString = StringUtils.stringCutFromBrace(getTitle);
  137. JSONArray creativeWords = wordsObject.getJSONArray("creative_word");
  138. JSONArray ids = new JSONArray();
  139. wordsString.forEach(v -> {
  140. creativeWords.forEach(word -> {
  141. JSONObject wordObject = (JSONObject) word;
  142. String name = wordObject.getString("name");
  143. Integer id = wordObject.getInteger("creative_word_id");
  144. if (v.equals(name)) {
  145. ids.add(id);
  146. }
  147. });
  148. });
  149. return ids;
  150. }
  151. }