package org.jeecg; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.service.ICtopOauthTokenService; import cn.com.ctop.common.module.service.IFileInfoService; import cn.com.ctop.common.module.utils.OSSUtils; import cn.com.ctop.common.module.utils.StringUtils; import cn.com.ctop.toutiao.entity.ByteDanceUserOrientationTemplate; import cn.com.ctop.toutiao.entity.BytedanceInterestCategory; import cn.com.ctop.toutiao.mapper.ByteDanceUserOrientationTemplateMapper; import cn.com.ctop.toutiao.mapper.BytedanceAreaInfoMapper; import cn.com.ctop.toutiao.mapper.BytedanceInterestCategoryMapper; import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import org.jeecg.common.util.jsonschema.JsonschemaUtil; import org.jeecg.modules.ctop.service.ICreateInternalService; import org.jeecg.modules.demo.mock.MockController; 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.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.annotation.Resource; import java.io.File; import java.util.ArrayList; import java.util.Date; import java.util.Map; @RunWith(SpringRunner.class) @SpringBootTest public class SampleTest { @Resource private JeecgDemoMapper jeecgDemoMapper; @Resource private IJeecgDemoService jeecgDemoService; @Resource private ISysDataLogService sysDataLogService; @Resource private MockController mock; @Autowired private ICreateInternalService createInternalService; @Test public void testLogin() { Map map = createInternalService.checkAccountPassword("dcd_ad@bytedance.com", "typdDCD@2018"); System.out.println(map.toString()); } @Test public void testFileType() { File file = new File("D:\\工作文件\\360借条\\快手后台数据-户1.csv"); System.out.println(file); } @Test public void testFileUpload() { OSSUtils.uploadObject2Oss(new File("D:\\upload\\excel\\template.xlsx")); } @Test public void testNg() { JSONObject json = new JSONObject(); System.err.println(json); createInternalService.createInternal(json); } @Autowired private BytedanceAreaInfoMapper areaInfoMapper; @Autowired private BytedanceInterestCategoryMapper interestCategoryMapper; @Test public void setCategoryData() { String path = "D:\\工作文件\\头条批量\\data_20190222\\ad_tag.json"; String jsonString = JsonschemaUtil.readJsonFile(path); JSONObject data = JSONObject.parseObject(jsonString); JSONArray tagArray = data.getJSONArray("adtags"); tagArray.forEach(tag -> { JSONObject getTag = (JSONObject) tag; String pcode = getTag.getString("value"); String plabel = getTag.getString("label"); BytedanceInterestCategory category = new BytedanceInterestCategory(); category.setCode(pcode); category.setName(plabel); category.setParentCode("0"); category.setLevel(1); category.setCreateTime(new Date()); category.setUpdateTime(new Date()); interestCategoryMapper.insert(category); JSONArray children = getTag.getJSONArray("subTags"); children.forEach(child -> { JSONObject getchild = (JSONObject) child; String code = getchild.getString("value"); String label = getchild.getString("label"); BytedanceInterestCategory childCategory = new BytedanceInterestCategory(); childCategory.setCode(code); childCategory.setName(label); childCategory.setParentCode(pcode); childCategory.setLevel(2); childCategory.setCreateTime(new Date()); childCategory.setUpdateTime(new Date()); interestCategoryMapper.insert(childCategory); }); }); } @Autowired private ICtopOauthTokenService tokenService; @Autowired private ByteDanceUserOrientationTemplateMapper userOrientationTemplateMapper; @Autowired private IByteDanceAdvertiserDataService advertiserDataService; @Test public void testEditPlan() throws Exception { String accountId = "74099510334"; Long userOrientationId = 5L; Long adId = 1643004580559934L; //修改用户定向 ByteDanceUserOrientationTemplate template = userOrientationTemplateMapper.selectById(userOrientationId); if (null != template) { CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId); if (null != token) { //获取modify_time Thread.sleep(5000L); advertiserDataService.getAdvertiserPlan(accountId, adId + ""); advertiserDataService.updateAd(token, adId, template); } } } @Autowired private IFileInfoService fileInfoService; @Test public void setJSONFile() { CtopOauthToken token = tokenService.getOauthTokenByAccountId("93289889842"); JSONObject wordsObject = fileInfoService.getCreativeWord(token, token.getAccountId()); String getTitle = "哈哈{日期}{男人女人}"; JSONArray ids = getCreativeWordIds(getTitle, wordsObject); System.out.println(ids); } public JSONArray getCreativeWordIds(String getTitle, JSONObject wordsObject) { ArrayList wordsString = StringUtils.stringCutFromBrace(getTitle); JSONArray creativeWords = wordsObject.getJSONArray("creative_word"); JSONArray ids = new JSONArray(); wordsString.forEach(v -> { creativeWords.forEach(word -> { JSONObject wordObject = (JSONObject) word; String name = wordObject.getString("name"); Integer id = wordObject.getInteger("creative_word_id"); if (v.equals(name)) { ids.add(id); } }); }); return ids; } }