瀏覽代碼

Merge branch 'release_1.0.0' into release_1.0.1

luoshi 2 年之前
父節點
當前提交
d33ff8077f
共有 1 個文件被更改,包括 21 次插入9 次删除
  1. 21 9
      src/main/java/com/qmth/ops/biz/service/PropertyService.java

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

@@ -15,7 +15,10 @@ import javax.annotation.Resource;
 import javax.validation.constraints.NotNull;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.*;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -55,14 +58,17 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
             throw new ParameterException("暂不支持非properties类型文件");
         }
         long time = System.currentTimeMillis();
-        propertyItemDao.delete(new LambdaUpdateWrapper<PropertyItem>().eq(PropertyItem::getAppId, app.getId())
-                .eq(PropertyItem::getVersionId, version.getId()).eq(PropertyItem::getModuleId, module.getId())
-                .eq(PropertyItem::getEnvId, BASELINE_ENV_ID));
         final Map<String, PropertyItem> baseMap = new HashMap<>();
         if (inheritVersion != null) {
             listBaseline(app.getId(), inheritVersion.getId(), module.getId())
                     .forEach(item -> baseMap.put(item.getKey(), item));
+        } else {
+            listBaseline(app.getId(), version.getId(), module.getId())
+                    .forEach(item -> baseMap.put(item.getKey(), item));
         }
+        propertyItemDao.delete(new LambdaUpdateWrapper<PropertyItem>().eq(PropertyItem::getAppId, app.getId())
+                .eq(PropertyItem::getVersionId, version.getId()).eq(PropertyItem::getModuleId, module.getId())
+                .eq(PropertyItem::getEnvId, BASELINE_ENV_ID));
         List<PropertyItem> list = PropertyFileUtil.read(file);
         for (PropertyItem item : list) {
             item.setAppId(app.getId());
@@ -102,24 +108,30 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
      */
     private void resetEnvProperty(App app, Version version, Module module, Env env, Version inheritVersion,
             Map<String, PropertyItem> baseMap) {
+        List<PropertyItem> currentList = listPropertyItem(app.getId(), version.getId(), module.getId(), env.getId());
         propertyItemDao.delete(new LambdaUpdateWrapper<PropertyItem>().eq(PropertyItem::getAppId, app.getId())
                 .eq(PropertyItem::getVersionId, version.getId()).eq(PropertyItem::getModuleId, module.getId())
                 .eq(PropertyItem::getEnvId, env.getId()));
+        long time = System.currentTimeMillis();
+        Map<String, PropertyItem> saveMap = new HashMap<>();
+        for (PropertyItem item : currentList) {
+            if (accept(item, baseMap)) {
+                saveMap.put(item.getKey(), item);
+            }
+        }
         if (inheritVersion != null) {
-            long time = System.currentTimeMillis();
             List<PropertyItem> inheritList = listPropertyItem(app.getId(), inheritVersion.getId(), module.getId(),
                     env.getId());
-            List<PropertyItem> saveList = new LinkedList<>();
             for (PropertyItem item : inheritList) {
-                if (accept(item, baseMap)) {
+                if (!saveMap.containsKey(item.getKey()) && accept(item, baseMap)) {
                     item.setVersionId(version.getId());
                     item.setCreateTime(time);
                     item.setUpdateTime(time);
-                    saveList.add(item);
+                    saveMap.put(item.getKey(), item);
                 }
             }
-            saveBatch(saveList);
         }
+        saveBatch(saveMap.values());
     }
 
     /**