@Override
  public SupplierInfoChangedDto baseCompanyChanged(
      Long userId,
      CompanyDto updatedCompanyDto,
      Company oldCompany,
      List<CompanyMainBusiness> oldMainBusinesses,
      List<CompanySupplyPark> oldSupplyParks) {
    SupplierInfoChangedDto supplierInfoChangedDto = new SupplierInfoChangedDto();

    Company updatedCompany = updatedCompanyDto.getCompany();
    List<CompanyMainBusiness> updatedMainBusinesses = updatedCompanyDto.getCompanyMainBusinesses();
    List<CompanySupplyPark> updatedSupplyParks = updatedCompanyDto.getCompanySupplyParks();

    // 取出新的信息
    CompanyDto newCompanyDto =
        getNewBaseCompany(userId, oldCompany, oldMainBusinesses, oldSupplyParks).getSupplierInfo();
    Company newCompany = newCompanyDto.getCompany();
    List<CompanyMainBusiness> newMainBusinesses = newCompanyDto.getCompanyMainBusinesses();
    List<CompanySupplyPark> newSupplyParks = newCompanyDto.getCompanySupplyParks();

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

    if (!Objects.equal(updatedCompany.getCorporation(), newCompany.getCorporation())) {
      changedInfo.put(ChangedInfoKeys.companyCorporation(), updatedCompany.getCorporation());
      updatedCompany.setCorporation(null);
    }

    if (!Objects.equal(updatedCompany.getInitAgent(), newCompany.getInitAgent())) {
      changedInfo.put(ChangedInfoKeys.companyInitAgent(), updatedCompany.getInitAgent());
      updatedCompany.setInitAgent(null);
    }

    if (!Objects.equal(updatedCompany.getDesc(), newCompany.getDesc())) {
      changedInfo.put(ChangedInfoKeys.companyDesc(), updatedCompany.getDesc());
      updatedCompany.setDesc(null);
    }

    if (!Objects.equal(updatedCompany.getRegCountry(), newCompany.getRegCountry())) {
      changedInfo.put(
          ChangedInfoKeys.companyRegCountry(), String.valueOf(updatedCompany.getRegCountry()));
      updatedCompany.setRegCountry(null);
    }

    //        if (!Objects.equal(company.getCustomers(), newCompany.getCustomers())) {
    //            changedInfo.put("", newCompany.getCustomers());
    //        }
    //
    if (!Objects.equal(updatedCompany.getProductLine(), newCompany.getProductLine())) {
      changedInfo.put(ChangedInfoKeys.companyProductLine(), updatedCompany.getProductLine());
    }

    if (mainBusinessChanged(updatedMainBusinesses, newMainBusinesses)) {
      changedInfo.put(
          ChangedInfoKeys.companyMainBusiness(),
          JsonMapper.nonEmptyMapper().toJson(updatedMainBusinesses));
    }

    if (supplyParkChanged(updatedSupplyParks, newSupplyParks)) {
      changedInfo.put(
          ChangedInfoKeys.companySupplyPark(),
          JsonMapper.nonEmptyMapper().toJson(updatedSupplyParks));
    }

    // 如果有V码,则继续检查合同信息
    if (!Strings.isNullOrEmpty(newCompany.getSupplierCode())) {

      if (!Objects.equal(updatedCompany.getGroupName(), newCompany.getGroupName())) {
        changedInfo.put(ChangedInfoKeys.companyGroupName(), updatedCompany.getGroupName());
        updatedCompany.setGroupName(null);
      }
      if (!Objects.equal(updatedCompany.getGroupAddr(), newCompany.getGroupAddr())) {
        changedInfo.put(ChangedInfoKeys.companyGroupAddr(), updatedCompany.getGroupAddr());
        updatedCompany.setGroupAddr(null);
      }
      if (!Objects.equal(updatedCompany.getRegCapital(), newCompany.getRegCapital())) {
        changedInfo.put(
            ChangedInfoKeys.companyRegCapical(), String.valueOf(updatedCompany.getRegCapital()));
        updatedCompany.setRegCapital(null);
      }
      if (!Objects.equal(updatedCompany.getRcCoinType(), newCompany.getRcCoinType())) {
        changedInfo.put(
            ChangedInfoKeys.companyRcCoinType(), String.valueOf(updatedCompany.getRcCoinType()));
        updatedCompany.setRcCoinType(null);
      }
      if (!Objects.equal(updatedCompany.getPersonScale(), newCompany.getPersonScale())) {
        changedInfo.put(ChangedInfoKeys.companyPersonScale(), updatedCompany.getPersonScale());
        updatedCompany.setPersonScale(null);
      }
      if (!Objects.equal(updatedCompany.getRegProvince(), newCompany.getRegProvince())) {
        changedInfo.put(
            ChangedInfoKeys.companyRegProvince(), String.valueOf(updatedCompany.getRegProvince()));
        updatedCompany.setRegProvince(null);
      }
      if (!Objects.equal(updatedCompany.getRegCity(), newCompany.getRegCity())) {
        changedInfo.put(
            ChangedInfoKeys.companyRegCity(), String.valueOf(updatedCompany.getRegCity()));
        updatedCompany.setRegCity(null);
      }
      if (!Objects.equal(updatedCompany.getFixedAssets(), newCompany.getFixedAssets())) {
        changedInfo.put(
            ChangedInfoKeys.companyFixedAssets(), String.valueOf(updatedCompany.getFixedAssets()));
        updatedCompany.setFixedAssets(null);
      }
      if (!Objects.equal(updatedCompany.getFaCoinType(), newCompany.getFaCoinType())) {
        changedInfo.put(
            ChangedInfoKeys.companyFaCoinType(), String.valueOf(updatedCompany.getFaCoinType()));
        updatedCompany.setFaCoinType(null);
      }

      Date updatedFoundAt = updatedCompany.getFoundAt();
      Date oldFoundAt = newCompany.getFoundAt();
      if (updatedFoundAt != null) {
        DateTime updated = new DateTime(updatedFoundAt);
        if (oldFoundAt == null) {
          changedInfo.put(ChangedInfoKeys.companyFoundAt(), updated.toString(FORMATTER));
          updatedCompany.setFoundAt(null);
        } else {
          DateTime old = new DateTime(oldFoundAt);
          if (!updated.equals(old)) {
            changedInfo.put(ChangedInfoKeys.companyFoundAt(), updated.toString(FORMATTER));
            updatedCompany.setFoundAt(null);
          }
        }
      }

      if (!Objects.equal(updatedCompany.getOfficialWebsite(), newCompany.getOfficialWebsite())) {
        changedInfo.put(
            ChangedInfoKeys.companyOfficialWebSite(), updatedCompany.getOfficialWebsite());
        updatedCompany.setOfficialWebsite(null);
      }
      if (!Objects.equal(updatedCompany.getNature(), newCompany.getNature())) {
        changedInfo.put(
            ChangedInfoKeys.companyNature(), String.valueOf(updatedCompany.getNature()));
        updatedCompany.setNature(null);
      }
      if (!Objects.equal(updatedCompany.getWorldTop(), newCompany.getWorldTop())) {
        changedInfo.put(
            ChangedInfoKeys.companyWorldTop(), String.valueOf(updatedCompany.getWorldTop()));
        updatedCompany.setWorldTop(null);
      }
      if (!Objects.equal(updatedCompany.getListedStatus(), newCompany.getListedStatus())) {
        changedInfo.put(
            ChangedInfoKeys.companyListedStatus(),
            String.valueOf(updatedCompany.getListedStatus()));
        updatedCompany.setListedStatus(null);
      }
      if (!Objects.equal(updatedCompany.getListedRegion(), newCompany.getListedRegion())) {
        changedInfo.put(ChangedInfoKeys.companyListedRegion(), updatedCompany.getListedRegion());
        updatedCompany.setListedRegion(null);
      }
      if (!Objects.equal(updatedCompany.getTicker(), newCompany.getTicker())) {
        changedInfo.put(ChangedInfoKeys.companyTicker(), updatedCompany.getTicker());
        updatedCompany.setTicker(null);
      }
    }

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

    return supplierInfoChangedDto;
  }
  @Override
  public SupplierUpdatedInfoDto<CompanyDto> getNewBaseCompany(
      Long userId,
      Company oldCompany,
      List<CompanyMainBusiness> oldMainBusinesses,
      List<CompanySupplyPark> oldSupplyParks) {
    SupplierUpdatedInfoDto<CompanyDto> supplierUpdatedInfoDto =
        new SupplierUpdatedInfoDto<CompanyDto>();
    CompanyDto companyDto = new CompanyDto();
    Map<String, Object> oldValues = Maps.newHashMap();

    boolean baseCompanyInfoChanged =
        supplierChangedInfoRedisDao.tabInfoChanged(userId, ChangedInfoKeys.companyTab());
    if (!baseCompanyInfoChanged) {
      companyDto.setCompany(oldCompany);
      companyDto.setCompanyMainBusinesses(oldMainBusinesses);
      companyDto.setCompanySupplyParks(oldSupplyParks);

      supplierUpdatedInfoDto.setSupplierInfo(companyDto);
      supplierUpdatedInfoDto.setOldValues(oldValues);
      return supplierUpdatedInfoDto;
    }

    Map<String, String> changedInfo = supplierChangedInfoRedisDao.getChangedInfos(userId);
    Company newCompany = new Company();
    BeanMapper.copy(oldCompany, newCompany);

    if (changedInfo.containsKey(ChangedInfoKeys.companyCorporation())) {
      newCompany.setCorporation(changedInfo.get(ChangedInfoKeys.companyCorporation()));
      oldValues.put(ChangedInfoKeys.companyCorporation(), oldCompany.getCorporation());
    }
    if (changedInfo.containsKey(ChangedInfoKeys.companyInitAgent())) {
      newCompany.setInitAgent(changedInfo.get(ChangedInfoKeys.companyInitAgent()));
      oldValues.put(ChangedInfoKeys.companyInitAgent(), oldCompany.getInitAgent());
    }
    if (changedInfo.containsKey(ChangedInfoKeys.companyRegCountry())) {
      String regCountry = changedInfo.get(ChangedInfoKeys.companyRegCountry());
      newCompany.setRegCountry("null".equals(regCountry) ? null : Integer.parseInt(regCountry));
      oldValues.put(ChangedInfoKeys.companyRegCountry(), oldCompany.getRegCountry());
    }
    if (changedInfo.containsKey(ChangedInfoKeys.companyDesc())) {
      newCompany.setDesc(changedInfo.get(ChangedInfoKeys.companyDesc()));
      oldValues.put(ChangedInfoKeys.companyDesc(), oldCompany.getDesc());
    }

    // 如果有V码,则检查是否有待更新的合同信息
    if (!Strings.isNullOrEmpty(oldCompany.getSupplierCode())) {

      if (changedInfo.containsKey(ChangedInfoKeys.companyGroupName())) {
        newCompany.setGroupName(changedInfo.get(ChangedInfoKeys.companyGroupName()));
        oldValues.put(ChangedInfoKeys.companyGroupName(), oldCompany.getGroupName());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyGroupAddr())) {
        newCompany.setGroupAddr(changedInfo.get(ChangedInfoKeys.companyGroupAddr()));
        oldValues.put(ChangedInfoKeys.companyGroupAddr(), oldCompany.getGroupAddr());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyRegCapical())) {
        String regCapital = changedInfo.get(ChangedInfoKeys.companyRegCapical());
        newCompany.setRegCapital("null".equals(regCapital) ? null : Long.parseLong(regCapital));
        oldValues.put(ChangedInfoKeys.companyRegCapical(), oldCompany.getRegCapital());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyRcCoinType())) {
        String reCoinType = changedInfo.get(ChangedInfoKeys.companyRcCoinType());
        newCompany.setRcCoinType("null".equals(reCoinType) ? null : Integer.parseInt(reCoinType));
        oldValues.put(ChangedInfoKeys.companyRcCoinType(), oldCompany.getRcCoinType());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyPersonScale())) {
        newCompany.setPersonScale(changedInfo.get(ChangedInfoKeys.companyPersonScale()));
        oldValues.put(ChangedInfoKeys.companyPersonScale(), oldCompany.getPersonScale());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyRegProvince())) {
        String regProvince = changedInfo.get(ChangedInfoKeys.companyRegProvince());
        newCompany.setRegProvince(
            "null".equals(regProvince) ? null : Integer.parseInt(regProvince));
        oldValues.put(ChangedInfoKeys.companyRegProvince(), oldCompany.getRegProvince());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyRegCity())) {
        String regCity = changedInfo.get(ChangedInfoKeys.companyRegCity());
        newCompany.setRegCity("null".equals(regCity) ? null : Integer.parseInt(regCity));
        oldValues.put(ChangedInfoKeys.companyRegCity(), oldCompany.getRegCity());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyFixedAssets())) {
        String fixedAssets = changedInfo.get(ChangedInfoKeys.companyFixedAssets());
        newCompany.setFixedAssets("null".equals(fixedAssets) ? null : Long.parseLong(fixedAssets));
        oldValues.put(ChangedInfoKeys.companyFixedAssets(), oldCompany.getFixedAssets());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyFaCoinType())) {
        String faCoinType = changedInfo.get(ChangedInfoKeys.companyFaCoinType());
        newCompany.setFaCoinType("null".equals(faCoinType) ? null : Integer.parseInt(faCoinType));
        oldValues.put(ChangedInfoKeys.companyFaCoinType(), oldCompany.getFaCoinType());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyFoundAt())) {
        String foundAt = changedInfo.get(ChangedInfoKeys.companyFoundAt());
        newCompany.setFoundAt(DateTime.parse(foundAt, FORMATTER).toDate());
        oldValues.put(ChangedInfoKeys.companyFoundAt(), oldCompany.getFoundAt());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyOfficialWebSite())) {
        newCompany.setOfficialWebsite(changedInfo.get(ChangedInfoKeys.companyOfficialWebSite()));
        oldValues.put(ChangedInfoKeys.companyOfficialWebSite(), oldCompany.getOfficialWebsite());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyNature())) {
        String nature = changedInfo.get(ChangedInfoKeys.companyNature());
        newCompany.setNature("null".equals(nature) ? null : Integer.parseInt(nature));
        oldValues.put(ChangedInfoKeys.companyNature(), oldCompany.getNature());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyWorldTop())) {
        String worldTop = changedInfo.get(ChangedInfoKeys.companyWorldTop());
        newCompany.setWorldTop("null".equals(worldTop) ? null : Integer.parseInt(worldTop));
        oldValues.put(ChangedInfoKeys.companyWorldTop(), oldCompany.getWorldTop());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyListedStatus())) {
        String listedStatus = changedInfo.get(ChangedInfoKeys.companyListedStatus());
        newCompany.setListedStatus(
            "null".equals(listedStatus) ? null : Integer.parseInt(listedStatus));
        oldValues.put(ChangedInfoKeys.companyListedStatus(), oldCompany.getListedStatus());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyListedRegion())) {
        newCompany.setListedRegion(changedInfo.get(ChangedInfoKeys.companyListedRegion()));
        oldValues.put(ChangedInfoKeys.companyListedRegion(), oldCompany.getListedRegion());
      }

      if (changedInfo.containsKey(ChangedInfoKeys.companyTicker())) {
        newCompany.setTicker(changedInfo.get(ChangedInfoKeys.companyTicker()));
        oldValues.put(ChangedInfoKeys.companyTicker(), oldCompany.getTicker());
      }
    }

    companyDto.setCompany(newCompany);

    if (changedInfo.containsKey(ChangedInfoKeys.companyMainBusiness())) {
      String mainBusinessesJson = changedInfo.get(ChangedInfoKeys.companyMainBusiness());
      JavaType javaType =
          JsonMapper.JSON_NON_EMPTY_MAPPER.createCollectionType(
              List.class, CompanyMainBusiness.class);
      List<CompanyMainBusiness> updatedMainBusinesses =
          JsonMapper.JSON_NON_EMPTY_MAPPER.fromJson(mainBusinessesJson, javaType);
      companyDto.setCompanyMainBusinesses(updatedMainBusinesses);

      oldValues.put(ChangedInfoKeys.companyMainBusiness(), oldMainBusinesses);
    } else {
      companyDto.setCompanyMainBusinesses(oldMainBusinesses);
    }

    if (changedInfo.containsKey(ChangedInfoKeys.companySupplyPark())) {
      String supplyParkJson = changedInfo.get(ChangedInfoKeys.companySupplyPark());
      JavaType javaType =
          JsonMapper.JSON_NON_EMPTY_MAPPER.createCollectionType(
              List.class, CompanySupplyPark.class);
      List<CompanySupplyPark> updatedSupplyParks =
          JsonMapper.JSON_NON_EMPTY_MAPPER.fromJson(supplyParkJson, javaType);
      companyDto.setCompanySupplyParks(updatedSupplyParks);

      oldValues.put(ChangedInfoKeys.companySupplyPark(), oldSupplyParks);
    } else {
      companyDto.setCompanySupplyParks(oldSupplyParks);
    }

    supplierUpdatedInfoDto.setSupplierInfo(companyDto);
    supplierUpdatedInfoDto.setOldValues(oldValues);
    return supplierUpdatedInfoDto;
  }