/** * 单元下创意数不超过50个 * * @param adgroupIds * @return */ public List<CreativeType> getAllCreative(List<Long> adgroupIds) { List<CreativeType> creativeTypes = new ArrayList<>(); if (logger.isDebugEnabled()) { logger.debug("推广单元总数: " + adgroupIds.size()); } try { CreativeService creativeService = commonService.getService(CreativeService.class); GetCreativeByAdgroupIdRequest getCreativeByAdgroupIdRequest = new GetCreativeByAdgroupIdRequest(); List<Long> subList = new ArrayList<>(2 << 5); for (int i = 1; i <= adgroupIds.size(); i++) { Long agid = adgroupIds.get(i - 1); subList.add(agid); if (i % 200 == 0) { getCreativeByAdgroupIdRequest.setAdgroupIds(subList); GetCreativeByAdgroupIdResponse response = creativeService.getCreativeByAdgroupId(getCreativeByAdgroupIdRequest); if (response != null) { List<GroupCreative> creatives = response.getGroupCreatives(); for (GroupCreative groupCreative : creatives) { creativeTypes.addAll(groupCreative.getCreativeTypes()); } } subList.clear(); } } if (subList.size() > 0) { getCreativeByAdgroupIdRequest.setAdgroupIds(subList); GetCreativeByAdgroupIdResponse response = creativeService.getCreativeByAdgroupId(getCreativeByAdgroupIdRequest); if (response != null) { List<GroupCreative> creatives = response.getGroupCreatives(); for (GroupCreative groupCreative : creatives) { List<CreativeType> types = groupCreative.getCreativeTypes(); creativeTypes.addAll(types); } } subList.clear(); } } catch (ApiException e) { e.printStackTrace(); } return creativeTypes; }
/** * 创意更新 * * @param list 创意列表 * @return * @throws ApiException */ public List<CreativeType> updateCreative(List<CreativeType> list) throws ApiException { if (list == null || list.isEmpty()) { return Collections.emptyList(); } UpdateCreativeRequest request = new UpdateCreativeRequest(); request.setCreativeTypes(list); CreativeService creativeService = commonService.getService(CreativeService.class); UpdateCreativeResponse response = creativeService.updateCreative(request); if (response == null) return Collections.emptyList(); return response.getCreativeTypes(); }
public Integer deleteCreative(List<Long> creativeIds) throws ApiException { DeleteCreativeRequest request = new DeleteCreativeRequest(); request.setCreativeIds(creativeIds); CreativeService creativeService = commonService.getService(CreativeService.class); DeleteCreativeResponse response = creativeService.deleteCreative(request); if (response == null) { try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } if (response != null) return response.getResult(); } return -1; }
public List<CreativeType> addCreative(List<CreativeType> list) throws ApiException { AddCreativeRequest request = new AddCreativeRequest(); request.setCreativeTypes(list); CreativeService creativeService = commonService.getService(CreativeService.class); AddCreativeResponse response = creativeService.addCreative(request); if (response == null) { try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); } if (response != null) return response.getCreativeTypes(); } return Collections.emptyList(); }