@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());
 }
Beispiel #2
0
  @Override
  public WriteResult updateRoom(String roomPK, String socketId) {

    Query query = new Query(Criteria.where("roomPK").is(roomPK));
    Update update = new Update();
    update.set("socketId", socketId);

    return mongoTemplate.updateFirst(query, update, COLLECTION_NAME);
  }
 @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();
 }
 public void update(Drug drug) {
   MongoTemplate mongoTemplate = this.getMongoTemplate();
   Query query = new Query(Criteria.where("id").is(drug.getId()));
   Update update = new Update();
   update.set("drugId", drug.getDrugId());
   update.set("drugName", drug.getDrugName());
   update.set("manufacturer", drug.getManufacturer());
   update.set("description", drug.getDescription());
   mongoTemplate.updateFirst(query, update, Drug.class);
 }
 @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;
 }
  public QuestionUI addBookmark(String questionId, Principal principal) {
    QuestionUI result = new QuestionUI();
    User user = userRepo.findByUserName(principal.getName());

    Query q = new Query(Criteria.where("id").is(questionId));
    if (user != null) {
      Bookmark bookmark = new Bookmark();
      bookmark.setId(user.getId());
      bookmark.setUser(user.getUserName());
      bookmark.setQuestionId(questionId);
      bookmark.setCreatedDate(Calendar.getInstance().getTime());

      template.updateFirst(
          new Query(Criteria.where("id").is(user.getId())),
          new Update().set("bookmarks." + questionId, bookmark),
          User.class);

      Update updateQ = new Update().set("bookmarks." + user.getId(), bookmark);
      template.updateFirst(q, updateQ, Question.class);
    }

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
  @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());
  }
  public QuestionUI addQuestionComment(CommentUI comment, Principal principal) {
    QuestionUI result = new QuestionUI();
    Comment newComment = cMapper.toPersistenceBean(comment);
    newComment.setId(UUID.randomUUID().toString());
    newComment.setCreatedDate(Calendar.getInstance().getTime());
    User user = userRepo.findByUserName(principal.getName());
    if (user != null) {
      newComment.setCreatedBy(user);
    }

    Query q = new Query(Criteria.where("id").is(comment.getQuestionId()));
    Update updateQ = new Update().set("comments." + newComment.getId(), newComment);
    template.updateFirst(q, updateQ, Question.class);

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
Beispiel #11
0
 @Override
 public void receive(CbipReport report) {
   logger.debug("cbipMessage:收到report:" + report);
   System.out.println("cbipMessage:收到report:" + report);
   System.out.println(mongoTemplate);
   System.out.println("seq:" + report.getClientSeq());
   if (report.getStatus() == 0
       && ("0".equals(report.getErrorCode()) || "DELIVRD".equals(report.getErrorCode()))) {
     logger.debug("msgId:" + report.getClientSeq() + "发送成功");
     mongoTemplate.updateFirst(
         new Query(Criteria.where("msgId").is(String.valueOf(report.getClientSeq()))),
         new Update().set("status", MessageStatus.发送成功),
         ShortMessage.class);
   }
   report.getStatus(); // 0
   report.getErrorCode(); // 0
 }
  public QuestionUI addVote(String questionId, Principal principal) {
    QuestionUI result = new QuestionUI();
    User user = userRepo.findByUserName(principal.getName());

    Query q = new Query(Criteria.where("id").is(questionId));
    if (user != null) {
      Vote vote = new Vote();
      vote.setId(user.getId());
      vote.setUser(user.getUserName());
      vote.setCreatedDate(Calendar.getInstance().getTime());

      Update updateQ = new Update().set("votes." + user.getId(), vote);
      template.updateFirst(q, updateQ, Question.class);
    }

    result = qMapper.toUIBean(template.findOne(q, Question.class));
    return result;
  }
  private void addTags(Question question) {
    for (String tagName : question.getTags()) {
      Tag existingTag = tagRepo.findByName(tagName);
      if (existingTag != null) {
        Query q = new Query(Criteria.where("id").is(existingTag.getId()));
        template.updateFirst(
            q, new Update().push("questions", question.getId()).inc("questionCount", 1), Tag.class);
      } else {
        Tag newTag = new Tag();
        newTag.setName(tagName);
        newTag.setCreatedBy(question.getCreatedBy());
        newTag.setCreatedDate(Calendar.getInstance().getTime());
        newTag.setQuestionCount(1);

        List<String> questions = new ArrayList<String>();
        questions.add(question.getId());
        newTag.setQuestions(questions);

        template.insert(newTag);
      }
    }
  }
  public QuestionUI findById(String id, Principal principal) {
    template.updateFirst(
        new Query(Criteria.where("id").is(id)), new Update().inc("viewCount", 1), Question.class);

    return qMapper.toUIBean(qaRepo.findById(id));
  }
 /** Updates a {<span class="referer">@link</span> Task} name for a particular id. */
 public WriteResult updateObject(String id, String name) {
   return mongoTemplate.updateFirst(
       new Query(Criteria.where("id").is(id)), Update.update("name", name), Task.class);
 }