Browse Source

增加导出程序配置时appCode的强制填充

luoshi 1 year ago
parent
commit
b004082e39

+ 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, module.getId(), env.getId());
+        List<PropertyItem> list = propertyService.mergePropertyList(appCode, version, module.getId(), env.getId());
         response.reset();
         response.setContentType("application/octet-stream");
         response.setHeader("Content-Disposition", "attachment; filename=application.properties");

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

@@ -29,6 +29,8 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
 
     private static final String APP_VERSION_KEY = "com.qmth.solar.app-version";
 
+    private static final String APP_CODE_KEY = "com.qmth.solar.app-code";
+
     @Resource
     private EnvService envService;
 
@@ -215,7 +217,7 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
                         .eq(PropertyItem::getKey, key));
     }
 
-    public List<PropertyItem> mergePropertyList(Version version, Long moduleId, Long envId) {
+    public List<PropertyItem> mergePropertyList(String appCode, Version version, Long moduleId, Long envId) {
         List<PropertyItem> list = listBaseline(version.getId(), moduleId);
         //获取环境定义配置项
         Map<String, PropertyItem> itemMap = listPropertyItem(version.getId(), moduleId, envId).stream()
@@ -237,15 +239,24 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
         if (!itemMap.isEmpty()) {
             list.addAll(itemMap.values());
         }
-        //强制增加版本配置项,自动根据当前version填充
+        //强制增加appCode与appVersion配置项,自动根据当前app和version填充
+        boolean hasCode = false;
         boolean hasVersion = false;
         for (PropertyItem item : list) {
-            if (item.getKey().equals(APP_VERSION_KEY)) {
+            if (item.getKey().equals(APP_CODE_KEY)) {
+                item.setValue(appCode);
+                hasCode = true;
+            } else if (item.getKey().equals(APP_VERSION_KEY)) {
                 item.setValue(version.getName());
                 hasVersion = true;
-                break;
             }
         }
+        if (!hasCode) {
+            PropertyItem item = new PropertyItem();
+            item.setKey(APP_CODE_KEY);
+            item.setValue(appCode);
+            list.add(item);
+        }
         if (!hasVersion) {
             PropertyItem item = new PropertyItem();
             item.setKey(APP_VERSION_KEY);