Ejemplo n.º 1
0
  @Override
  public Response<Boolean> addTQRDCTag(Long userId, Integer score) {

    Response<Boolean> result = new Response<Boolean>();

    if (userId == null) {
      log.error("user id can not be null");
      result.setError("user.id.not.null.fail");
      return result;
    }

    if (score == null) {
      log.error("score can not be null");
      result.setError("score.not.null.fail");
      return result;
    }

    try {

      User user = userDao.findById(userId);
      if (user == null) {
        log.error("user(user id={}) not found", userId);
        result.setError("user.not.found");
        return result;
      }

      List<String> tags = user.buildTags();

      // 找出已有的tqrdc tag
      String old = null;
      for (String tag : tags) {
        if (tag.startsWith(User.SupplierTag.PERFORMANCE.toString())) {
          old = tag;
        }
      }

      // 删除已有的tqrdc tag
      if (old != null) {
        tags.remove(old);
      }

      tags.add(User.SupplierTag.PERFORMANCE.toString().concat(String.valueOf(score)));
      user.setTagsFromList(tags);
      userDao.update(user);

      result.setResult(Boolean.TRUE);

    } catch (Exception e) {
      log.error(
          "fail to add tqrdc tag where user id={},score={},cause:{}",
          userId,
          score,
          Throwables.getStackTraceAsString(e));
      result.setError("add.tag.fail");
    }

    return result;
  }
Ejemplo n.º 2
0
  @Override
  public Response<Boolean> addTag(Long userId, User.SupplierTag tag) {

    Response<Boolean> result = new Response<Boolean>();

    if (userId == null) {
      log.error("user id can not be null");
      result.setError("user.id.not.null.fail");
      return result;
    }

    if (tag == null) {
      log.error("tag can not be null");
      result.setError("tag.not.null.fail");
      return result;
    }

    try {

      User user = userDao.findById(userId);
      if (user == null) {
        log.error("user(user id={}) not found", userId);
        result.setError("user.not.found");
        return result;
      }

      List<String> tags = user.buildTags();

      add(tags, tag.toString());
      user.setTagsFromList(tags);

      // 如果是状态标签,则更新所处阶段
      if (isStatusTag(tag)) {
        User.Step step = convertToStep(tag);
        if (step != null) {
          user.setStep(step.value());
        }
      }

      userDao.update(user);

      result.setResult(Boolean.TRUE);

    } catch (Exception e) {
      log.error(
          "fail to add tag where user id={},tag={},cause:{}",
          userId,
          tag,
          Throwables.getStackTraceAsString(e));
      result.setError("add.tag.fail");
    }

    return result;
  }
Ejemplo n.º 3
0
  @Override
  public Response<Boolean> updateTagsByCompany(Long userId, Company company) {

    Response<Boolean> result = new Response<Boolean>();

    if (userId == null) {
      log.error("user id can not be null");
      result.setError("user.id.not.null.fail");
      return result;
    }

    if (company == null) {
      log.error("company can not be null");
      result.setError("company.not.null.fail");
      return result;
    }

    try {

      User user = userDao.findById(userId);
      if (user == null) {
        log.error("user(user id={}) not found", userId);
        result.setError("user.not.found");
        return result;
      }

      List<String> tags = user.buildTags();

      if (Objects.equal(company.getWorldTop(), Company.WorldTop.IS_WORLD_TOP_500.value())) {
        add(tags, User.SupplierTag.WORLD_TOP_SUPPLIER.toString());
      } else if (Objects.equal(company.getWorldTop(), Company.WorldTop.NO_WORLD_TOP_500.value())) {
        remove(tags, User.SupplierTag.WORLD_TOP_SUPPLIER.toString());
      }

      if (!Strings.isNullOrEmpty(company.getSupplierCode())) {
        add(tags, User.SupplierTag.IN_SUPPLIER.toString());
      }

      user.setTagsFromList(tags);
      userDao.update(user);

      result.setResult(Boolean.TRUE);

    } catch (Exception e) {
      log.error(
          "fail to update tag where user id={},company={},cause:{}",
          userId,
          company,
          Throwables.getStackTraceAsString(e));
      result.setError("add.tag.fail");
    }

    return result;
  }
Ejemplo n.º 4
0
 @Override
 public Response<Boolean> addSupplierStatusTag(Long userId, User.SupplierTag tag) {
   Response<Boolean> result = new Response<Boolean>();
   try {
     List<String> tags = checkNotNull(userDao.findById(userId)).buildRoles();
     User.SupplierTag curStat = getCurrentStat(tags);
     if (canMove(curStat, tag)) {
       delTag(userId, curStat);
       addTag(userId, tag);
       result.setResult(Boolean.TRUE);
     } else {
       result.setResult(Boolean.FALSE);
     }
   } catch (Exception e) {
     log.error(
         "addSupplierStatusTag(userId={}, tag={}) failed, cause:{}",
         userId,
         tag,
         Throwables.getStackTraceAsString(e));
     result.setError("add.tag.fail");
   }
   return result;
 }