@Override public void getAdgroupReportData( List<AdgroupReportDTO> adgroupReportDTOs, SystemUserDTO systemUser, String dateStr, int i) { MongoTemplate mongoTemplate; mongoTemplate = BaseMongoTemplate.getMongoTemplate(DBNameUtils.getReportDBName(systemUser.getUserName())); List<AdgroupReportEntity> adgroupReportEntities = new ArrayList<>(ObjectUtils.convert(adgroupReportDTOs, AdgroupReportEntity.class)); List<AdgroupReportEntity> adgroupReportEntities1; if (mongoTemplate.collectionExists(dateStr + "-adgroup")) { if (i > 1) { adgroupReportEntities1 = new ArrayList<>( mongoTemplate.find(new Query(), AdgroupReportEntity.class, dateStr + "-adgroup")); adgroupReportEntities.addAll(adgroupReportEntities1); } mongoTemplate.dropCollection(dateStr + "-adgroup"); } mongoTemplate.insert(adgroupReportEntities, dateStr + "-adgroup"); }
@Override public void getAccountReportData( List<AccountReportDTO> accountReportDTOs, SystemUserDTO systemUser, String dateStr, String baiduUserName) { MongoTemplate mongoTemplate; mongoTemplate = BaseMongoTemplate.getMongoTemplate(DBNameUtils.getReportDBName(systemUser.getUserName())); List<AccountReportEntity> accountReportEntities = ObjectUtils.convert(accountReportDTOs, AccountReportEntity.class); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String dateString = df.format(date); List<AccountReportEntity> entities = null; if (!dateStr.equals(dateString)) { try { entities = mongoTemplate.find( Query.query( Criteria.where("date") .is(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr)) .and("acna") .is(baiduUserName)), AccountReportEntity.class); } catch (ParseException e) { e.printStackTrace(); } if (entities == null || entities.size() == 0) { mongoTemplate.insert(accountReportEntities, TBL_ACCOUNT_REPORT); } } }