コード例 #1
0
  @Override
  public SupplierUpdatedInfoDto<ContactInfo> getNewContactInfo(
      Long userId, ContactInfo oldContactInfo) {

    SupplierUpdatedInfoDto<ContactInfo> supplierUpdatedInfoDto =
        new SupplierUpdatedInfoDto<ContactInfo>();
    Map<String, Object> oldValues = Maps.newHashMap();

    boolean contactInfoChanged =
        supplierChangedInfoRedisDao.tabInfoChanged(userId, ChangedInfoKeys.contactInfoTab());
    if (!contactInfoChanged) {
      supplierUpdatedInfoDto.setSupplierInfo(oldContactInfo);
      supplierUpdatedInfoDto.setOldValues(oldValues);
      return supplierUpdatedInfoDto;
    }

    Map<String, String> changedInfo = supplierChangedInfoRedisDao.getChangedInfos(userId);

    ContactInfo newContactInfo = new ContactInfo();
    BeanMapper.copy(oldContactInfo, newContactInfo);

    if (changedInfo.containsKey(ChangedInfoKeys.contactInfoName())) {
      newContactInfo.setName(changedInfo.get(ChangedInfoKeys.contactInfoName()));
      oldValues.put(ChangedInfoKeys.contactInfoName(), oldContactInfo.getName());
    }

    if (changedInfo.containsKey(ChangedInfoKeys.contactInfoEmail())) {
      newContactInfo.setEmail(changedInfo.get(ChangedInfoKeys.contactInfoEmail()));
      oldValues.put(ChangedInfoKeys.contactInfoEmail(), oldContactInfo.getEmail());
    }

    if (changedInfo.containsKey(ChangedInfoKeys.contactInfoMobile())) {
      newContactInfo.setMobile(changedInfo.get(ChangedInfoKeys.contactInfoMobile()));
      oldValues.put(ChangedInfoKeys.contactInfoMobile(), oldContactInfo.getMobile());
    }

    if (changedInfo.containsKey(ChangedInfoKeys.contactInfoPhone())) {
      newContactInfo.setOfficePhone(changedInfo.get(ChangedInfoKeys.contactInfoPhone()));
      oldValues.put(ChangedInfoKeys.contactInfoPhone(), oldContactInfo.getOfficePhone());
    }

    supplierUpdatedInfoDto.setSupplierInfo(newContactInfo);
    supplierUpdatedInfoDto.setOldValues(oldValues);
    return supplierUpdatedInfoDto;
  }
コード例 #2
0
  public SupplierInfoChangedDto contactInfoChanged(
      Long userId, ContactInfo updatedContactInfo, ContactInfo oldContactInfo) {
    SupplierInfoChangedDto supplierInfoChangedDto = new SupplierInfoChangedDto();

    ContactInfo newContactInfo = getNewContactInfo(userId, oldContactInfo).getSupplierInfo();

    Map<String, String> changedInfo = Maps.newHashMap();

    if (!Objects.equal(updatedContactInfo.getName(), newContactInfo.getName())) {
      changedInfo.put(ChangedInfoKeys.contactInfoName(), updatedContactInfo.getName());
      updatedContactInfo.setName(null);
    }

    if (!Objects.equal(updatedContactInfo.getEmail(), newContactInfo.getEmail())) {
      changedInfo.put(ChangedInfoKeys.contactInfoEmail(), updatedContactInfo.getEmail());
      updatedContactInfo.setEmail(null);
    }

    if (!Objects.equal(updatedContactInfo.getMobile(), newContactInfo.getMobile())) {
      changedInfo.put(ChangedInfoKeys.contactInfoMobile(), updatedContactInfo.getMobile());
      updatedContactInfo.setMobile(null);
    }

    Company company = companyDao.findByUserId(userId);
    if (!Strings.isNullOrEmpty(company.getSupplierCode())) {
      if (!Objects.equal(updatedContactInfo.getOfficePhone(), newContactInfo.getOfficePhone())) {
        changedInfo.put(ChangedInfoKeys.contactInfoPhone(), updatedContactInfo.getOfficePhone());
        updatedContactInfo.setOfficePhone(null);
      }
    }

    if (!changedInfo.isEmpty()) {
      supplierInfoChangedDto.setChanged(true);
      supplierInfoChangedDto.setChangedInfo(changedInfo);
    }
    return supplierInfoChangedDto;
  }