Jelajahi Sumber

修改url和部分接口参数

luoshi 2 tahun lalu
induk
melakukan
d0435e63e5

+ 13 - 8
src/main/java/com/qmth/ops/api/controller/admin/ConfigController.java

@@ -1,15 +1,15 @@
 package com.qmth.ops.api.controller.admin;
 
 import com.qmth.ops.api.constants.OpsApiConstants;
+import com.qmth.ops.api.controller.binder.FileFormatBinder;
 import com.qmth.ops.biz.domain.ConfigItem;
+import com.qmth.ops.biz.domain.FileFormat;
 import com.qmth.ops.biz.service.AppService;
 import com.qmth.ops.biz.service.ConfigService;
 import com.qmth.ops.biz.service.ModuleService;
 import com.qmth.ops.biz.service.VersionService;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.WebDataBinder;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -17,7 +17,7 @@ import java.io.IOException;
 import java.util.List;
 
 @RestController
-@RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/app")
+@RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/config")
 public class ConfigController {
 
     @Resource
@@ -32,6 +32,11 @@ public class ConfigController {
     @Resource
     private VersionService versionService;
 
+    @InitBinder
+    public void initBinder(WebDataBinder dataBinder) {
+        dataBinder.addCustomFormatter(new FileFormatBinder());
+    }
+
     @PostMapping("/baseline")
     public List<ConfigItem> listBaseline(@RequestParam Long appId, @RequestParam Long versionId,
             @RequestParam Long moduleId) {
@@ -40,10 +45,10 @@ public class ConfigController {
 
     @PostMapping("/baseline/update")
     public Object updateBaseline(@RequestParam Long appId, @RequestParam Long versionId, @RequestParam Long moduleId,
-            @RequestParam MultipartFile file, @RequestParam(required = false) Long inheritVersionId)
-            throws IOException {
+            @RequestParam MultipartFile file, @RequestParam FileFormat extension,
+            @RequestParam(required = false) Long inheritVersionId) throws IOException {
         return configService.updateBaseline(appService.findById(appId), versionService.findByid(versionId),
-                moduleService.findById(moduleId), file.getInputStream(),
+                moduleService.findById(moduleId), file.getInputStream(), extension,
                 inheritVersionId != null ? versionService.findByid(inheritVersionId) : null);
     }
 

+ 1 - 1
src/main/java/com/qmth/ops/api/controller/admin/VersionController.java

@@ -32,7 +32,7 @@ public class VersionController {
         return versionService.insert(appService.findById(appId), name);
     }
 
-    @PostMapping("/list")
+    @PostMapping("/query")
     public VersionQuery list(VersionQuery query) {
         return versionService.query(query);
     }

+ 0 - 20
src/main/java/com/qmth/ops/api/controller/binder/ConfigFormatBinder.java

@@ -1,20 +0,0 @@
-package com.qmth.ops.api.controller.binder;
-
-import com.qmth.ops.biz.domain.ConfigFormat;
-import org.springframework.format.Formatter;
-
-import java.text.ParseException;
-import java.util.Locale;
-
-public class ConfigFormatBinder implements Formatter<ConfigFormat> {
-
-    @Override
-    public ConfigFormat parse(String s, Locale locale) throws ParseException {
-        return ConfigFormat.findByExtension(s);
-    }
-
-    @Override
-    public String print(ConfigFormat format, Locale locale) {
-        return format.getExtension();
-    }
-}

+ 20 - 0
src/main/java/com/qmth/ops/api/controller/binder/FileFormatBinder.java

@@ -0,0 +1,20 @@
+package com.qmth.ops.api.controller.binder;
+
+import com.qmth.ops.biz.domain.FileFormat;
+import org.springframework.format.Formatter;
+
+import java.text.ParseException;
+import java.util.Locale;
+
+public class FileFormatBinder implements Formatter<FileFormat> {
+
+    @Override
+    public FileFormat parse(String s, Locale locale) throws ParseException {
+        return FileFormat.findByExtension(s);
+    }
+
+    @Override
+    public String print(FileFormat format, Locale locale) {
+        return format.getExtension();
+    }
+}

+ 7 - 7
src/main/java/com/qmth/ops/api/controller/export/ConfigExportController.java

@@ -6,7 +6,7 @@ import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.core.exception.ParameterException;
 import com.qmth.boot.core.exception.UnauthorizedException;
 import com.qmth.ops.api.constants.OpsApiConstants;
-import com.qmth.ops.api.controller.binder.ConfigFormatBinder;
+import com.qmth.ops.api.controller.binder.FileFormatBinder;
 import com.qmth.ops.biz.domain.*;
 import com.qmth.ops.biz.service.*;
 import com.qmth.ops.biz.utils.PropertyFileUtil;
@@ -45,25 +45,25 @@ public class ConfigExportController {
 
     @InitBinder
     public void initBinder(WebDataBinder dataBinder) {
-        dataBinder.addCustomFormatter(new ConfigFormatBinder());
+        dataBinder.addCustomFormatter(new FileFormatBinder());
     }
 
     @GetMapping("/{appCode}/{moduleCode}/{envCode}/{version}.{format}")
     public void exportVersionConfigFile(@PathVariable String appCode, @PathVariable String moduleCode,
-            @PathVariable String envCode, @PathVariable String version, @PathVariable ConfigFormat format,
+            @PathVariable String envCode, @PathVariable String version, @PathVariable FileFormat format,
             @RequestParam String secret, HttpServletResponse response) throws IOException {
         exportConfigFile(appCode, moduleCode, envCode, version, secret, format, response);
     }
 
     @GetMapping("/{appCode}/{moduleCode}/{envCode}.{format}")
     public void exportMasterVersionConfigFile(@PathVariable String appCode, @PathVariable String moduleCode,
-            @PathVariable String envCode, @PathVariable ConfigFormat format, @RequestParam String secret,
+            @PathVariable String envCode, @PathVariable FileFormat format, @RequestParam String secret,
             HttpServletResponse response) throws IOException {
         exportConfigFile(appCode, moduleCode, envCode, null, secret, format, response);
     }
 
     private void exportConfigFile(String appCode, String moduleCode, String envCode, String versionNumber,
-            String exportSecret, ConfigFormat format, HttpServletResponse response) throws IOException {
+            String exportSecret, FileFormat format, HttpServletResponse response) throws IOException {
         User user = userService.findByExportSecret(exportSecret);
         if (user == null || user.getRole() != Role.OPS) {
             throw new UnauthorizedException("鉴权失败");
@@ -89,12 +89,12 @@ public class ConfigExportController {
         }
         List<ConfigItem> list = configService
                 .mergeConfigList(app.getId(), version.getId(), module.getId(), env.getId());
-        if (format == ConfigFormat.PROPERTY) {
+        if (format == FileFormat.PROPERTY) {
             response.reset();
             response.setContentType("application/octet-stream; charset=unicode");
             response.setHeader("Content-Disposition", "attachment; filename=application." + format.getExtension());
             PropertyFileUtil.write(list, response.getOutputStream());
-        } else if (format == ConfigFormat.JSON) {
+        } else if (format == FileFormat.JSON) {
             response.reset();
             response.setContentType("application/octet-stream; charset=utf-8");
             response.setHeader("Content-Disposition", "attachment; filename=application." + format.getExtension());

+ 4 - 4
src/main/java/com/qmth/ops/biz/domain/ConfigFormat.java → src/main/java/com/qmth/ops/biz/domain/FileFormat.java

@@ -1,12 +1,12 @@
 package com.qmth.ops.biz.domain;
 
-public enum ConfigFormat {
+public enum FileFormat {
 
     PROPERTY("properties"), JSON("json");
 
     private String extension;
 
-    private ConfigFormat(String extension) {
+    private FileFormat(String extension) {
         this.extension = extension;
     }
 
@@ -14,8 +14,8 @@ public enum ConfigFormat {
         return extension;
     }
 
-    public static ConfigFormat findByExtension(String extension) {
-        for (ConfigFormat format : values()) {
+    public static FileFormat findByExtension(String extension) {
+        for (FileFormat format : values()) {
             if (format.getExtension().equalsIgnoreCase(extension)) {
                 return format;
             }

+ 4 - 1
src/main/java/com/qmth/ops/biz/service/ConfigService.java

@@ -37,7 +37,7 @@ public class ConfigService {
 
     @Transactional
     public List<ConfigItem> updateBaseline(@NotNull App app, @NotNull Version version, @NotNull Module module,
-            @NotNull InputStream file, Version inheritVersion) throws IOException {
+            @NotNull InputStream file, @NotNull FileFormat format, Version inheritVersion) throws IOException {
         if (!version.getAppId().equals(app.getId())) {
             throw new ParameterException("指定版本不属于该应用");
         }
@@ -47,6 +47,9 @@ public class ConfigService {
         if (!module.getAppId().equals(app.getId())) {
             throw new ParameterException("指定模块不属于该应用");
         }
+        if (format != FileFormat.PROPERTY) {
+            throw new ParameterException("暂不支持非properties类型文件");
+        }
         long time = System.currentTimeMillis();
         configItemDao.delete(new LambdaUpdateWrapper<ConfigItem>().eq(ConfigItem::getAppId, app.getId())
                 .eq(ConfigItem::getVersionId, version.getId()).eq(ConfigItem::getModuleId, module.getId())