|
|
|
@ -7,6 +7,7 @@ import com.htfp.weather.griddata.operation.GfsDataImport;
|
|
|
|
|
import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo;
|
|
|
|
|
import com.htfp.weather.info.Constant;
|
|
|
|
|
import com.htfp.weather.utils.DateTimeUtils;
|
|
|
|
|
import com.htfp.weather.web.config.Config;
|
|
|
|
|
import com.htfp.weather.web.config.aspect.ControllerLog;
|
|
|
|
|
import com.htfp.weather.web.exception.AppException;
|
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
@ -52,14 +53,18 @@ public class ConfigController {
|
|
|
|
|
FileService fileService;
|
|
|
|
|
@Resource
|
|
|
|
|
GfsDataServiceImpl gfsDataService;
|
|
|
|
|
private final String SECRET = "htfpweather";
|
|
|
|
|
|
|
|
|
|
private void validSecret(String secret) {
|
|
|
|
|
if (StringUtils.isEmpty(secret) || !SECRET.equals(secret)) {
|
|
|
|
|
throw new AppException(ErrorCode.SECRET_ERROR);
|
|
|
|
|
@Resource
|
|
|
|
|
SurfaceWeatherController surfaceWeatherController;
|
|
|
|
|
@PostMapping("/switchSurfaceDataSource")
|
|
|
|
|
public Result switchService(@RequestBody Map<String, String> params) {
|
|
|
|
|
Config.validSecret(params.get("secret"));
|
|
|
|
|
String dataSource = params.get("dataSource");
|
|
|
|
|
if (StringUtils.isEmpty(dataSource)) {
|
|
|
|
|
return Result.error(ErrorCode.VALIDATE_ERROR, "dataSource不能为空");
|
|
|
|
|
}
|
|
|
|
|
return surfaceWeatherController.switchSurfaceDataSource(dataSource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询tablestore数据库配置
|
|
|
|
|
*/
|
|
|
|
@ -77,7 +82,7 @@ public class ConfigController {
|
|
|
|
|
public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) {
|
|
|
|
|
String secret = request.getSecret();
|
|
|
|
|
TableConfig updateConfig = request.getConfig();
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
if (updateConfig == null) {
|
|
|
|
|
throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空");
|
|
|
|
|
}
|
|
|
|
@ -107,7 +112,7 @@ public class ConfigController {
|
|
|
|
|
public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) {
|
|
|
|
|
String secret = request.getSecret();
|
|
|
|
|
GfsDataConfig updateConfig = request.getConfig();
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
if (updateConfig == null) {
|
|
|
|
|
throw new AppException(ErrorCode.CONFIG_ERROR, "配置文件不能为空");
|
|
|
|
|
}
|
|
|
|
@ -127,7 +132,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "下载当前时刻未来24小时的数据文件")
|
|
|
|
|
public Result downloadAllFiles(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
// List<FileInfo> allCompleted = false;
|
|
|
|
|
try {
|
|
|
|
|
DownloadResult data = gfsDataService.downloadNowAllFile();
|
|
|
|
@ -149,7 +154,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "下载指定时刻文件")
|
|
|
|
|
public Result downloadSingleFile(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
OffsetDateTime offsetDateTime = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
|
|
|
|
|
DownLoadFileInfo downLoadFileInfo = gfsDataService.downloadSingleFile(offsetDateTime);
|
|
|
|
|
return Result.success(downLoadFileInfo);
|
|
|
|
@ -162,7 +167,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "根据起报时间将数据导入数据库")
|
|
|
|
|
public Result importData(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
|
|
|
|
|
return getImportResponse(time);
|
|
|
|
|
}
|
|
|
|
@ -205,7 +210,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "查询所有数据文件夹")
|
|
|
|
|
public Result queryAllDataDir(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
File dataRoot = new File(gfsDataConfig.getSaveRoot());
|
|
|
|
|
List<String> subDirList = fileService.getSubDirList(dataRoot);
|
|
|
|
|
return Result.success(subDirList);
|
|
|
|
@ -218,7 +223,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "查询指定起报时间文件夹中的所有文件名")
|
|
|
|
|
public Result queryAllFileByReferenceTime(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
|
|
|
|
|
String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING));
|
|
|
|
|
File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr);
|
|
|
|
@ -235,7 +240,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "删除指定起报时间对应的文件夹")
|
|
|
|
|
public Result deleteDirByReferenceTime(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
OffsetDateTime time = OffsetDateTime.parse(params.get("time"), Constant.API_TIME_FORMATTER);
|
|
|
|
|
String timeStr = DateTimeUtils.getUTCDateTime(time).format(DateTimeFormatter.ofPattern(Constant.DATA_FOLDER_STRING));
|
|
|
|
|
File dataDir = new File(gfsDataConfig.getSaveRoot(), timeStr);
|
|
|
|
@ -257,7 +262,7 @@ public class ConfigController {
|
|
|
|
|
@ControllerLog(info = "删除指定文件")
|
|
|
|
|
public Result deleteTargetFile(@RequestBody Map<String, String> params) {
|
|
|
|
|
String secret = params.get("secret");
|
|
|
|
|
validSecret(secret);
|
|
|
|
|
Config.validSecret(secret);
|
|
|
|
|
String filePath = params.get("filePath");
|
|
|
|
|
File file = new File(filePath);
|
|
|
|
|
if (gfsDataImport.isImporting()) {
|
|
|
|
|