@Override public List<SystemUserDTO> getAccount() { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); return ObjectUtils.convert( mongoTemplate.find(Query.query(Criteria.where("state").is(0)), getEntityClass()), getDTOClass()); }
@Override public void uploadImg(byte[] bytes) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); mongoTemplate.updateFirst( Query.query(Criteria.where("userName").is(AppContext.getUser())), Update.update("img", bytes), getEntityClass()); }
@Override public SystemUserDTO getCurrUserInfo() { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); SystemUserEntity entity = mongoTemplate.findOne( Query.query(Criteria.where("userName").is(AppContext.getUser())), getEntityClass()); return ObjectUtils.convert(entity, getDTOClass()); }
@Override public List<SystemUserDTO> getAllSysUserAccount() { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); List<SystemUserEntity> userEntityList = mongoTemplate.find( Query.query(Criteria.where("access").is(2).and("acstate").is(1).and("state").is(1)), getEntityClass()); return ObjectUtils.convertToList(userEntityList, getDTOClass()); }
/** * @param dates * @return */ @Override public List<AccountReportDTO> getAccountReports(List<Date> dates) { MongoTemplate mongoTemplate = BaseMongoTemplate.getUserReportMongo(); Long baiduAccountId = AppContext.getAccountId(); return ObjectUtils.convert( mongoTemplate.find( Query.query(Criteria.where(ACCOUNT_ID).is(baiduAccountId).and("date").in(dates)), AccountReportEntity.class), AccountReportDTO.class); }
@Override public boolean updateSysAccount(String userName, Long state) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); Update update = new Update(); update.set("acstate", state); WriteResult writeResult = mongoTemplate.updateFirst( Query.query(Criteria.where("userName").is(userName)), update, "sys_user"); return writeResult.isUpdateOfExisting(); }
@Override public boolean updateBaiDuName(String name, Long baiduId) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); Update update = new Update(); update.set("bdAccounts.$.baiduRemarkName", name); WriteResult writeResult = mongoTemplate.updateFirst( Query.query(Criteria.where("bdAccounts._id").is(baiduId)), update, "sys_user"); return writeResult.isUpdateOfExisting(); }
@Override public boolean updatePwd(String account, String pwd) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); WriteResult writeResult = mongoTemplate.updateFirst( Query.query(Criteria.where("userName").is(account)), Update.update("password", pwd), "sys_user"); return writeResult.isUpdateOfExisting(); }
@Override public int updateAccountStruts(String userName) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); WriteResult writeResult = mongoTemplate.updateFirst( Query.query(Criteria.where("userName").is(userName)), Update.update("state", 1), "sys_user"); int i = 0; if (writeResult.isUpdateOfExisting()) i = 1; return i; }
@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 void updateBaiduAccountInfo(BaiduAccountInfoDTO dto) { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); String currUser = AppContext.getUser(); Update update = new Update(); if (dto.getBudget() != null) update.set("bdAccounts.$.bgt", dto.getBudget()); if (dto.getIsDynamicCreative() != null) update.set("bdAccounts.$.dc", dto.getIsDynamicCreative()); if (dto.getExcludeIp() != null) update.set("bdAccounts.$.exIp", dto.getExcludeIp()); mongoTemplate.updateFirst( Query.query(Criteria.where("userName").is(currUser).and("bdAccounts._id").is(dto.getId())), update, getEntityClass()); }
@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; }
@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); } } }
/** * 百度账户树 * * @return */ @Override public ArrayNode getAccountTree() { ObjectMapper mapper = new ObjectMapper(); ArrayNode arrayNode = mapper.createArrayNode(); ObjectNode objectNode; Long accountId = AppContext.getAccountId(); MongoTemplate mongoTemplate = BaseMongoTemplate.getUserMongo(); Aggregation aggregation1 = Aggregation.newAggregation( match(Criteria.where(ACCOUNT_ID).is(accountId)), project(CAMPAIGN_ID, NAME, SYSTEM_ID), sort(Sort.Direction.ASC, CAMPAIGN_ID)); // 推广计划树 AggregationResults<CampaignVO> results1 = mongoTemplate.aggregate(aggregation1, TBL_CAMPAIGN, CampaignVO.class); for (CampaignVO vo : results1) { objectNode = mapper.createObjectNode(); if (vo.getCampaignId() == null) { objectNode.put("id", vo.getId()); } else { objectNode.put("id", vo.getCampaignId()); } objectNode.put("pId", 0); objectNode.put("name", vo.getCampaignName()); arrayNode.add(objectNode); } Aggregation aggregation2 = Aggregation.newAggregation( match(Criteria.where(ACCOUNT_ID).is(accountId)), project(CAMPAIGN_ID, OBJ_CAMPAIGN_ID, ADGROUP_ID, SYSTEM_ID, NAME), sort(Sort.Direction.ASC, ADGROUP_ID)); AggregationResults<AdgroupVO> results2 = mongoTemplate.aggregate(aggregation2, TBL_ADGROUP, AdgroupVO.class); for (AdgroupVO vo : results2) { objectNode = mapper.createObjectNode(); objectNode.put("name", vo.getAdgroupName()); if (vo.getCampaignId() == null) { objectNode.put("id", vo.getId()); objectNode.put("pId", vo.getCampaignObjId()); arrayNode.add(objectNode); continue; } if (vo.getAdgroupId() == null) { objectNode.put("id", vo.getId()); objectNode.put("pId", vo.getCampaignId()); arrayNode.add(objectNode); continue; } objectNode.put("id", vo.getAdgroupId()); objectNode.put("pId", vo.getCampaignId()); arrayNode.add(objectNode); } return arrayNode; }
@Override public List<SystemUserDTO> getAccountAll() { MongoTemplate mongoTemplate = BaseMongoTemplate.getSysMongo(); return ObjectUtils.convert(mongoTemplate.find(new Query(), getEntityClass()), getDTOClass()); }