Selaa lähdekoodia

导出程序配置时自动加入com.qmth.solar.app-version配置值,与当前选择版本相同

luoshi 2 vuotta sitten
vanhempi
commit
199b09c06e

+ 1 - 1
src/main/java/com/qmth/ops/api/controller/export/PropertyExportController.java

@@ -77,7 +77,7 @@ public class PropertyExportController {
         if (version == null) {
             throw new ParameterException("version不存在");
         }
-        List<PropertyItem> list = propertyService.mergePropertyList(version.getId(), module.getId(), env.getId());
+        List<PropertyItem> list = propertyService.mergePropertyList(version, module.getId(), env.getId());
         response.reset();
         response.setContentType("application/octet-stream");
         response.setHeader("Content-Disposition", "attachment; filename=application.properties");

+ 21 - 4
src/main/java/com/qmth/ops/biz/service/PropertyService.java

@@ -27,6 +27,8 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
 
     private static final long BASELINE_ENV_ID = 0L;
 
+    private static final String APP_VERSION_KEY = "com.qmth.solar.app-version";
+
     @Resource
     private EnvService envService;
 
@@ -213,10 +215,10 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
                         .eq(PropertyItem::getKey, key));
     }
 
-    public List<PropertyItem> mergePropertyList(Long versionId, Long moduleId, Long envId) {
-        List<PropertyItem> list = listBaseline(versionId, moduleId);
+    public List<PropertyItem> mergePropertyList(Version version, Long moduleId, Long envId) {
+        List<PropertyItem> list = listBaseline(version.getId(), moduleId);
         //获取环境定义配置项
-        Map<String, PropertyItem> itemMap = listPropertyItem(versionId, moduleId, envId).stream()
+        Map<String, PropertyItem> itemMap = listPropertyItem(version.getId(), moduleId, envId).stream()
                 .collect(Collectors.toMap(PropertyItem::getKey, Function.identity()));
         //遍历基线
         for (PropertyItem item : list) {
@@ -234,8 +236,23 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
         //合并新增配置项
         if (!itemMap.isEmpty()) {
             list.addAll(itemMap.values());
-            list.sort(Comparator.comparing(PropertyItem::getKey));
         }
+        //强制增加版本配置项,自动根据当前version填充
+        boolean hasVersion = false;
+        for (PropertyItem item : list) {
+            if (item.getKey().equals(APP_VERSION_KEY)) {
+                item.setValue(version.getName());
+                hasVersion = true;
+                break;
+            }
+        }
+        if (!hasVersion) {
+            PropertyItem item = new PropertyItem();
+            item.setKey(APP_VERSION_KEY);
+            item.setValue(version.getName());
+            list.add(item);
+        }
+        list.sort(Comparator.comparing(PropertyItem::getKey));
         return list;
     }
 }