@Transactional
  public ServerConfig createOrUpdateConfig(ServerConfig serverConfig) {

    ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());

    if (Objects.isNull(storedConfig)) {//create
      serverConfig.setId(0L);//为空，设置ID 为0，jpa执行新增操作
      if(Objects.isNull(serverConfig.getCluster())){
        serverConfig.setCluster("default");
      }
      return serverConfigRepository.save(serverConfig);
    }

    //update
    storedConfig.setComment(serverConfig.getComment());
    storedConfig.setDataChangeLastModifiedBy(serverConfig.getDataChangeLastModifiedBy());
    storedConfig.setValue(serverConfig.getValue());

    return serverConfigRepository.save(storedConfig);
  }
@Test
  public void createOrUpdateConfig() {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.setKey("name");
    serverConfig.setValue("kl");
    serverConfigService.createOrUpdateConfig(serverConfig);

    List<ServerConfig> serverConfigs = serverConfigService.findAll();
    assertThat(serverConfigs).isNotNull();
    assertThat(serverConfigs.get(0).getValue()).isEqualTo("kl");
    assertThat(serverConfigs.get(0).getCluster()).isEqualTo("default");
    assertThat(serverConfigs.get(0).getKey()).isEqualTo("name");


    serverConfig.setValue("kl2");
    serverConfigService.createOrUpdateConfig(serverConfig);

    serverConfigs = serverConfigService.findAll();
    assertThat(serverConfigs).isNotNull();
    assertThat(serverConfigs.size()).isEqualTo(1);
    assertThat(serverConfigs.get(0).getValue()).isEqualTo("kl2");
    assertThat(serverConfigs.get(0).getKey()).isEqualTo("name");

    serverConfig = new ServerConfig();
    serverConfig.setKey("name2");
    serverConfig.setValue("kl2");
    serverConfigService.createOrUpdateConfig(serverConfig);

    serverConfigs = serverConfigService.findAll();
    assertThat(serverConfigs).isNotNull();
    assertThat(serverConfigs.size()).isEqualTo(2);
  }