@Override
  public boolean removeAccount(Long id, String account) {

    SystemUserDTO byUserName = systemUserDAO.findByUserName(account);
    boolean Master = false;
    if (byUserName != null && byUserName.getBaiduAccounts().size() > 0) {
      for (int i = 0; i < byUserName.getBaiduAccounts().size(); i++) {
        if (byUserName.getBaiduAccounts().get(i).getId().compareTo(id) == 0) {
          if (byUserName.getBaiduAccounts().get(i).isDfault()) {}

          byUserName.getBaiduAccounts().remove(i);
          --i;
        }
      }
      List<BaiduAccountInfoDTO> baiduAccountInfoDTOs = byUserName.getBaiduAccounts();
      if (baiduAccountInfoDTOs.size() > 0 && Master) {
        baiduAccountInfoDTOs.get(0).setDfault(true);
      }
      int falg = systemUserDAO.removeAccountInfo(baiduAccountInfoDTOs, account);
      if (falg > 0) {
        return true;
      }
    }
    return false;
  }
Exemplo n.º 2
0
 /**
  * 获取当前登录用户的所有百度账户信息
  *
  * @param currUserName
  * @return
  */
 @Override
 public List<BaiduAccountInfoDTO> getBaiduAccountItems(String currUserName) {
   SystemUserDTO systemUserDTO = systemUserDAO.findByUserName(currUserName);
   if (systemUserDTO != null) {
     return systemUserDTO.getBaiduAccounts();
   }
   return Collections.emptyList();
 }
 @Override
 public Iterable<SystemUserDTO> findAll() {
   return systemUserDAO.findAll();
 }
 @Override
 public SystemUserDTO findByUserName(String userName) {
   return systemUserDAO.findByUserName(userName);
 }
 @Override
 public List<Long> getLocalCreativeIds(Long accountId, List<Long> adgroupIds) {
   return systemUserDAO.getLocalCreativeIds(accountId, adgroupIds);
 }
 @Override
 public List<Long> getLocalAdgroupIds(Long accountId, List<Long> campaignIds) {
   return systemUserDAO.getLocalAdgroupIds(accountId, campaignIds);
 }
 @Override
 public void clearCreativeData(Long accountId, List<Long> creativeIds) {
   systemUserDAO.clearCreativeData(accountId, creativeIds);
 }
 @Override
 public void clearKeywordData(Long accountId, List<Long> keywordIds) {
   systemUserDAO.clearKeywordData(accountId, keywordIds);
 }
 @Override
 public void clearAdgroupData(Long accountId, List<Long> adgroupIds) {
   systemUserDAO.clearAdgroupData(accountId, adgroupIds);
 }
Exemplo n.º 10
0
 @Override
 public void clearCampaignData(Long accountId, List<Long> campaignIds) {
   systemUserDAO.clearCampaignData(accountId, campaignIds);
 }
Exemplo n.º 11
0
 @Override
 public void clearAccountData(Long accountId) {
   systemUserDAO.clearAccountData(accountId);
 }
Exemplo n.º 12
0
 @Override
 public SystemUserDTO findByAid(long aid) {
   return systemUserDAO.findByAid(aid);
 }
Exemplo n.º 13
0
  @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);
    }
  }
Exemplo n.º 14
0
 @Override
 public void addAccount(String user, BaiduAccountInfoDTO baiduAccountInfoDTO) {
   systemUserDAO.insertAccountInfo(user, baiduAccountInfoDTO);
 }
Exemplo n.º 15
0
 @Override
 public void save(SystemUserDTO systemUserDTO) {
   systemUserDAO.save(systemUserDTO);
 }
Exemplo n.º 16
0
 @Override
 public List<SystemUserDTO> getAllValidUser() {
   return Lists.newArrayList(systemUserDAO.getAllValidUser());
 }