@Override public Double getYesterdayCost(Long accountId) { MongoTemplate mongoTemplate = BaseMongoTemplate.getUserReportMongo(); Date date = DateUtils.getYesterday(); Aggregation aggregation = newAggregation( match(Criteria.where(ACCOUNT_ID).is(accountId).and("date").is(date)), project("pccost")); AggregationResults<AccountReportEntity> results = mongoTemplate.aggregate(aggregation, TBL_ACCOUNT_REPORT, AccountReportEntity.class); if (results == null) return 0d; AccountReportEntity reportEntity = results.getUniqueMappedResult(); if (reportEntity != null) return reportEntity.getPcCost().doubleValue(); else return 0d; }
@Override public Double getCostRate() { Long accountId = AppContext.getAccountId(); Double cost1 = getYesterdayCost(accountId); Double cost2 = 0d; Double costRate; MongoTemplate mongoTemplate = BaseMongoTemplate.getUserReportMongo(); Long baiduAccountId = AppContext.get().getAccountId(); Date date = ((List<Date>) DateUtils.getsLatestAnyDays("MM-dd", 2).get(DateUtils.KEY_DATE)).get(1); AccountReportEntity reportEntity = mongoTemplate.findOne( Query.query(Criteria.where("date").is(date).and(ACCOUNT_ID).is(baiduAccountId)), AccountReportEntity.class); if (reportEntity != null) cost2 = reportEntity.getPcCost().doubleValue(); if (cost2 == 0d) return 0d; costRate = (cost1 - cost2) / cost2; costRate = new BigDecimal(costRate * 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); return costRate; }