-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add the defaultconfig for the query of compareconfig from s…
…chedule-api (#304)
- Loading branch information
Showing
14 changed files
with
672 additions
and
529 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 37 additions & 18 deletions
55
.../src/main/java/com/arextest/web/api/service/controller/config/SystemConfigController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,57 @@ | ||
package com.arextest.web.api.service.controller.config; | ||
|
||
import com.arextest.common.model.response.Response; | ||
import com.arextest.common.utils.ResponseUtils; | ||
import com.arextest.web.core.business.ConfigLoadService; | ||
import com.arextest.web.core.repository.SystemConfigRepository; | ||
import com.arextest.web.model.contract.contracts.config.SaveSystemConfigRequestType; | ||
import com.arextest.web.model.contract.contracts.config.SystemConfig; | ||
import javax.annotation.Resource; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import com.arextest.common.model.response.Response; | ||
import com.arextest.common.utils.ResponseUtils; | ||
import com.arextest.web.core.repository.SystemConfigRepository; | ||
import com.arextest.web.model.contract.contracts.config.SaveSystemConfigRequestType; | ||
|
||
/** | ||
* @author wildeslam. | ||
* @create 2023/9/26 11:25 | ||
*/ | ||
@Controller | ||
@RequestMapping("/api/system/config") | ||
@Slf4j | ||
public class SystemConfigController { | ||
@Resource | ||
private SystemConfigRepository systemConfigRepository; | ||
|
||
@PostMapping("/save") | ||
@ResponseBody | ||
public Response saveSystemConfig(@RequestBody SaveSystemConfigRequestType request) { | ||
return ResponseUtils.successResponse(systemConfigRepository.saveConfig(request.getSystemConfig())); | ||
} | ||
@Resource | ||
private SystemConfigRepository systemConfigRepository; | ||
|
||
@Resource | ||
private ConfigLoadService configLoadService; | ||
|
||
@PostMapping("/save") | ||
@ResponseBody | ||
public Response saveSystemConfig(@RequestBody SaveSystemConfigRequestType request) { | ||
return ResponseUtils.successResponse( | ||
systemConfigRepository.saveConfig(request.getSystemConfig())); | ||
} | ||
|
||
@GetMapping("/list") | ||
@ResponseBody | ||
public Response listSystemConfig() { | ||
return ResponseUtils.successResponse(systemConfigRepository.getLatestSystemConfig()); | ||
@GetMapping("/list") | ||
@ResponseBody | ||
public Response listSystemConfig() { | ||
SystemConfig latestSystemConfig = systemConfigRepository.getLatestSystemConfig(); | ||
latestSystemConfig.setCompareNameToLower( | ||
Boolean.valueOf(configLoadService.getCompareNameToLower("true"))); | ||
latestSystemConfig.setCompareNullEqualsEmpty( | ||
Boolean.valueOf(configLoadService.getCompareNullEqualsEmpty("true"))); | ||
try { | ||
Long ignoredTimePrecisionMillis = Long.valueOf( | ||
configLoadService.getCompareIgnoredTimePrecisionMillis("2000")); | ||
latestSystemConfig.setCompareIgnoreTimePrecisionMillis(ignoredTimePrecisionMillis); | ||
} catch (RuntimeException e) { | ||
LOGGER.error("getCompareIgnoredTimePrecisionMillis error", e); | ||
} | ||
} | ||
return ResponseUtils.successResponse(latestSystemConfig); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
arex-web-core/src/main/java/com/arextest/web/core/business/ConfigLoadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.arextest.web.core.business; | ||
|
||
public interface ConfigLoadService { | ||
|
||
String compareIgnoredTimePrecisionMillis = "arex.compare.ignoredTimePrecisionMillis"; | ||
|
||
String compareNameToLower = "arex.compare.nameToLower"; | ||
|
||
String compareNullEqualsEmpty = "arex.compare.nullEqualsEmpty"; | ||
|
||
Object getProperty(String key, Object defaultValue); | ||
|
||
default String getCompareIgnoredTimePrecisionMillis(String defaultValue) { | ||
return (String) getProperty(compareIgnoredTimePrecisionMillis, defaultValue); | ||
} | ||
|
||
default String getCompareNameToLower(String defaultValue) { | ||
return (String) getProperty(compareNameToLower, defaultValue); | ||
} | ||
|
||
default String getCompareNullEqualsEmpty(String defaultValue) { | ||
return (String) getProperty(compareNullEqualsEmpty, defaultValue); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...web-core/src/main/java/com/arextest/web/core/business/beans/DefaultConfigLoadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.arextest.web.core.business.beans; | ||
|
||
import com.arextest.web.core.business.ConfigLoadService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
|
||
public class DefaultConfigLoadService implements ConfigLoadService { | ||
|
||
private Environment environment; | ||
|
||
public DefaultConfigLoadService(@Autowired Environment environment) { | ||
this.environment = environment; | ||
|
||
} | ||
|
||
@Override | ||
public Object getProperty(String key, Object defaultValue) { | ||
if (environment.getProperty(key) == null) { | ||
return defaultValue; | ||
} | ||
return environment.getProperty(key); | ||
} | ||
} |
Oops, something went wrong.