Forráskód Böngészése

增加非基线新增配置项的删除接口

luoshi 2 éve
szülő
commit
7c876936e6

+ 12 - 0
src/main/java/com/qmth/ops/api/controller/admin/PropertyController.java

@@ -15,7 +15,9 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping(OpsApiConstants.ADMIN_URI_PREFIX + "/property")
@@ -126,5 +128,15 @@ public class PropertyController {
         return propertyService.updatePropertyItem(item);
     }
 
+    @PostMapping("/item/delete")
+    public Object deletePropertyItem(@RequestAttribute AdminSession adminSession, PropertyItem item) {
+        adminSession.validateApp(appService.getById(item.getAppId()));
+        adminSession.validateEnv(envService.getById(item.getEnvId()));
+        propertyService.deletePropertyItem(item);
+        Map<String, Object> map = new HashMap<>();
+        map.put("success", true);
+        return map;
+    }
+
 }
 

+ 17 - 0
src/main/java/com/qmth/ops/biz/service/PropertyService.java

@@ -190,6 +190,23 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
         }
     }
 
+    @Transactional
+    public void deletePropertyItem(PropertyItem item) {
+        PropertyItem base = findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), BASELINE_ENV_ID,
+                item.getKey());
+        if (base != null) {
+            throw new ParameterException("存在基线配置项时不能删除");
+        }
+        PropertyItem current = findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), item.getEnvId(),
+                item.getKey());
+        if (current == null) {
+            throw new ParameterException("配置项不存在");
+        }
+        propertyItemDao.delete(new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getAppId, item.getAppId())
+                .eq(PropertyItem::getVersionId, item.getVersionId()).eq(PropertyItem::getModuleId, item.getModuleId())
+                .eq(PropertyItem::getEnvId, item.getEnvId()).eq(PropertyItem::getKey, item.getKey()));
+    }
+
     public PropertyItem findOne(Long appId, Long versionId, Long moduleId, Long envId, String key) {
         return propertyItemDao.selectOne(new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getAppId, appId)
                 .eq(PropertyItem::getVersionId, versionId).eq(PropertyItem::getModuleId, moduleId)

+ 2 - 0
src/main/java/com/qmth/ops/biz/utils/SortedProperties.java

@@ -7,6 +7,8 @@ import java.util.*;
  */
 public class SortedProperties extends Properties {
 
+    private static final long serialVersionUID = -1652301484480055608L;
+
     @Override
     public Set<Map.Entry<Object, Object>> entrySet() {
         /*