@Override public void initAccount(String userName, Long accountId) { logger.info("开始导入数据: 用户名=" + userName + ", 账号= " + accountId); SystemUserDTO systemUserDTO = getSystemUser(userName); if (systemUserDTO == null) { logger.warn("没有此账号: " + userName); return; } logger.info("清理已有数据..."); clearAccountData(accountId); logger.info("清理数据完成!"); for (BaiduAccountInfoDTO baiduAccountInfoDTO : systemUserDTO.getBaiduAccounts()) { Long aid = baiduAccountInfoDTO.getId(); if (!Objects.equals(aid, accountId)) continue; CommonService commonService = BaiduServiceSupport.getCommonService( baiduAccountInfoDTO.getBaiduUserName(), baiduAccountInfoDTO.getBaiduPassword(), baiduAccountInfoDTO.getToken()); BaiduApiService apiService = new BaiduApiService(commonService); logger.info("查询账户信息..."); // 初始化账户数据 AccountInfoType accountInfoType = apiService.getAccountInfo(); if (accountInfoType == null) { logger.error("获取账户信息错误: " + ResHeaderUtil.getJsonResHeader(false).toString()); continue; } boolean isDefault = baiduAccountInfoDTO.isDfault(); baiduAccountInfoDTO = ObjectUtils.convert(accountInfoType, BaiduAccountInfoDTO.class); baiduAccountInfoDTO.setId(accountInfoType.getUserid()); baiduAccountInfoDTO.setBaiduUserName(baiduAccountInfoDTO.getBaiduUserName()); baiduAccountInfoDTO.setBaiduPassword(baiduAccountInfoDTO.getBaiduPassword()); baiduAccountInfoDTO.setToken(baiduAccountInfoDTO.getToken()); baiduAccountInfoDTO.setDfault(isDefault); // 新增百度账户 systemUserDAO.insertAccountInfo(userName, baiduAccountInfoDTO); logger.info("查询账户推广计划..."); List<CampaignType> campaignTypes = apiService.getAllCampaign(); logger.info("查询结束: 计划数=" + campaignTypes.size()); List<CampaignDTO> campaignEntities = EntityConvertUtils.convertToCamEntity(campaignTypes); // 查询推广单元 List<Long> ids = new ArrayList<>(campaignEntities.size()); for (CampaignDTO campaignEntity : campaignEntities) { campaignEntity.setAccountId(aid); ids.add(campaignEntity.getCampaignId()); } logger.info("查询账户推广单元..."); List<AdgroupType> adgroupTypeList = apiService.getAllAdGroup(ids); logger.info("查询结束: 单元数=" + adgroupTypeList.size()); List<AdgroupDTO> adgroupEntities = EntityConvertUtils.convertToAdEntity(adgroupTypeList); ids.clear(); for (AdgroupDTO adgroupEntity : adgroupEntities) { adgroupEntity.setAccountId(aid); ids.add(adgroupEntity.getAdgroupId()); } logger.info("查询账户推广关键词..."); // List<KeywordType> keywordTypes = apiService.getAllKeyword(ids); // logger.info("查询结束: 关键词数=" + keywordTypes.size()); // // List<KeywordDTO> keywordEntities = // EntityConvertUtils.convertToKwEntity(keywordTypes); // // for (KeywordDTO keywordEntity : keywordEntities) { // keywordEntity.setAccountId(aid); // } // 分批次请求关键词数据 List<Long> subList = new ArrayList<>(4); for (int i = 1; i <= ids.size(); i++) { Long adgroupId = ids.get(i - 1); subList.add(adgroupId); if (i % 4 == 0) { List<KeywordType> keywordTypes = apiService.getAllKeyword(subList); List<KeywordDTO> keywordEntities = EntityConvertUtils.convertToKwEntity(keywordTypes); for (KeywordDTO keywordEntity : keywordEntities) { keywordEntity.setAccountId(aid); } keywordDAO.save(keywordEntities); subList.clear(); } } if (!subList.isEmpty()) { List<KeywordType> keywordTypes = apiService.getAllKeyword(subList); List<KeywordDTO> keywordEntities = EntityConvertUtils.convertToKwEntity(keywordTypes); for (KeywordDTO keywordEntity : keywordEntities) { keywordEntity.setAccountId(aid); } keywordDAO.save(keywordEntities); subList.clear(); } logger.info("查询账户推广创意..."); List<CreativeType> creativeTypes = apiService.getAllCreative(ids); logger.info("查询结束: 普通创意数=" + creativeTypes.size()); List<CreativeDTO> creativeEntityList = EntityConvertUtils.convertToCrEntity(creativeTypes); for (CreativeDTO creativeEntity : creativeEntityList) { creativeEntity.setAccountId(aid); } // 开始保存数据 campaignDAO.save(campaignEntities); adgroupDAO.save(adgroupEntities); creativeDAO.save(creativeEntityList); } }
@Override public void addAccount(String user, BaiduAccountInfoDTO baiduAccountInfoDTO) { systemUserDAO.insertAccountInfo(user, baiduAccountInfoDTO); }