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

程序配置去掉appId字段

luoshi 2 éve
szülő
commit
91377fa866

+ 10 - 11
src/main/java/com/qmth/ops/api/controller/admin/PropertyController.java

@@ -60,18 +60,17 @@ public class PropertyController {
     }
 
     @PostMapping("/baseline")
-    public List<PropertyItem> listBaseline(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
-            @RequestParam Long versionId, @RequestParam Long moduleId) {
-        return propertyService.listBaseline(appId, versionId, moduleId);
+    public List<PropertyItem> listBaseline(@RequestAttribute AdminSession adminSession, @RequestParam Long versionId,
+            @RequestParam Long moduleId) {
+        return propertyService.listBaseline(versionId, moduleId);
     }
 
     @PostMapping("/baseline/update")
-    public Object updateBaseline(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
-            @RequestParam Long versionId, @RequestParam Long moduleId, @RequestParam MultipartFile file,
-            @RequestParam FileFormat extension, @RequestParam(required = false) Long inheritVersionId)
-            throws IOException {
-        return propertyService.updateBaseline(appService.getById(appId), versionService.getById(versionId),
-                moduleService.getById(moduleId), file.getInputStream(), extension,
+    public Object updateBaseline(@RequestAttribute AdminSession adminSession, @RequestParam Long versionId,
+            @RequestParam Long moduleId, @RequestParam MultipartFile file, @RequestParam FileFormat extension,
+            @RequestParam(required = false) Long inheritVersionId) throws IOException {
+        return propertyService.updateBaseline(versionService.getById(versionId), moduleService.getById(moduleId),
+                file.getInputStream(), extension,
                 inheritVersionId != null ? versionService.getById(inheritVersionId) : null);
     }
 
@@ -81,10 +80,10 @@ public class PropertyController {
     }
 
     @PostMapping("/list")
-    public List<PropertyItem> listPropertyItem(@RequestAttribute AdminSession adminSession, @RequestParam Long appId,
+    public List<PropertyItem> listPropertyItem(@RequestAttribute AdminSession adminSession,
             @RequestParam Long versionId, @RequestParam Long moduleId, @RequestParam Long envId) {
         Env env = envService.getById(envId);
-        List<PropertyItem> list = propertyService.listPropertyItem(appId, versionId, moduleId, env.getId());
+        List<PropertyItem> list = propertyService.listPropertyItem(versionId, moduleId, env.getId());
         //非管理员/运维角色,且非环境维护用户,需要隐藏机密信息
         if (!adminSession.getUser().hasRole(Role.ADMIN, Role.OPS)) {
             for (PropertyItem item : list) {

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

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

+ 0 - 10
src/main/java/com/qmth/ops/biz/domain/PropertyItem.java

@@ -10,8 +10,6 @@ public class PropertyItem implements Serializable {
 
     private static final long serialVersionUID = 1390416370953446620L;
 
-    private Long appId;
-
     private Long versionId;
 
     private Long moduleId;
@@ -31,14 +29,6 @@ public class PropertyItem implements Serializable {
 
     private Long updateTime;
 
-    public Long getAppId() {
-        return appId;
-    }
-
-    public void setAppId(Long appId) {
-        this.appId = appId;
-    }
-
     public Long getVersionId() {
         return versionId;
     }

+ 45 - 57
src/main/java/com/qmth/ops/biz/service/PropertyService.java

@@ -36,42 +36,36 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
     @Resource
     private PropertyItemDao propertyItemDao;
 
-    public List<PropertyItem> listBaseline(Long appId, Long versionId, Long moduleId) {
-        return propertyItemDao.selectList(new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getAppId, appId)
-                .eq(PropertyItem::getVersionId, versionId).eq(PropertyItem::getModuleId, moduleId)
-                .eq(PropertyItem::getEnvId, BASELINE_ENV_ID).orderByAsc(PropertyItem::getKey));
+    public List<PropertyItem> listBaseline(Long versionId, Long moduleId) {
+        return propertyItemDao.selectList(
+                new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getVersionId, versionId)
+                        .eq(PropertyItem::getModuleId, moduleId).eq(PropertyItem::getEnvId, BASELINE_ENV_ID)
+                        .orderByAsc(PropertyItem::getKey));
     }
 
     @Transactional
-    public List<PropertyItem> updateBaseline(@NotNull App app, @NotNull Version version, @NotNull Module module,
+    public List<PropertyItem> updateBaseline(@NotNull Version version, @NotNull Module module,
             @NotNull InputStream file, @NotNull FileFormat format, Version inheritVersion) throws IOException {
-        if (!version.getAppId().equals(app.getId())) {
-            throw new ParameterException("指定版本不属于该应用");
+        if (!version.getAppId().equals(module.getAppId())) {
+            throw new ParameterException("指定版本与模块不匹配");
         }
         if (version.getArchived()) {
             throw new ParameterException("指定版本已归档不能操作");
         }
-        if (!module.getAppId().equals(app.getId())) {
-            throw new ParameterException("指定模块不属于该应用");
-        }
         if (format != FileFormat.PROPERTY) {
             throw new ParameterException("暂不支持非properties类型文件");
         }
         long time = System.currentTimeMillis();
         final Map<String, PropertyItem> baseMap = new HashMap<>();
         if (inheritVersion != null) {
-            listBaseline(app.getId(), inheritVersion.getId(), module.getId())
-                    .forEach(item -> baseMap.put(item.getKey(), item));
+            listBaseline(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));
+            listBaseline(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));
+        propertyItemDao.delete(new LambdaUpdateWrapper<PropertyItem>().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());
             item.setVersionId(version.getId());
             item.setModuleId(module.getId());
             item.setEnvId(BASELINE_ENV_ID);
@@ -86,12 +80,12 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
             }
         }
         saveBatch(list);
-        List<PropertyItem> baseline = listBaseline(app.getId(), version.getId(), module.getId());
+        List<PropertyItem> baseline = listBaseline(version.getId(), module.getId());
         baseMap.clear();
         baseline.forEach(item -> baseMap.put(item.getKey(), item));
-        List<Env> envList = envService.list(app.getId());
+        List<Env> envList = envService.list(version.getAppId());
         for (Env env : envList) {
-            resetEnvProperty(app, version, module, env, inheritVersion, baseMap);
+            resetEnvProperty(version, module, env, inheritVersion, baseMap);
         }
         return baseline;
     }
@@ -99,19 +93,17 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
     /**
      * 根据指定版本和最新基线,继承环境自定义配置
      *
-     * @param app
      * @param version
      * @param module
      * @param env
      * @param inheritVersion
      * @param baseMap
      */
-    private void resetEnvProperty(App app, Version version, Module module, Env env, Version inheritVersion,
+    private void resetEnvProperty(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()));
+        List<PropertyItem> currentList = listPropertyItem(version.getId(), module.getId(), env.getId());
+        propertyItemDao.delete(new LambdaUpdateWrapper<PropertyItem>().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) {
@@ -120,8 +112,7 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
             }
         }
         if (inheritVersion != null) {
-            List<PropertyItem> inheritList = listPropertyItem(app.getId(), inheritVersion.getId(), module.getId(),
-                    env.getId());
+            List<PropertyItem> inheritList = listPropertyItem(inheritVersion.getId(), module.getId(), env.getId());
             for (PropertyItem item : inheritList) {
                 if (!saveMap.containsKey(item.getKey()) && accept(item, baseMap)) {
                     item.setVersionId(version.getId());
@@ -159,24 +150,22 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
         propertyItemDao.update(item, new LambdaUpdateWrapper<PropertyItem>()
                 .set(item.getMode() != null, PropertyItem::getMode, item.getMode())
                 .set(item.getComment() != null, PropertyItem::getComment, item.getComment())
-                .eq(PropertyItem::getAppId, item.getAppId()).eq(PropertyItem::getVersionId, item.getVersionId())
-                .eq(PropertyItem::getModuleId, item.getModuleId()).eq(PropertyItem::getEnvId, BASELINE_ENV_ID)
-                .eq(PropertyItem::getKey, item.getKey()));
-        return findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), BASELINE_ENV_ID, item.getKey());
+                .eq(PropertyItem::getVersionId, item.getVersionId()).eq(PropertyItem::getModuleId, item.getModuleId())
+                .eq(PropertyItem::getEnvId, BASELINE_ENV_ID).eq(PropertyItem::getKey, item.getKey()));
+        return findOne(item.getVersionId(), item.getModuleId(), BASELINE_ENV_ID, item.getKey());
     }
 
-    public List<PropertyItem> listPropertyItem(Long appId, Long versionId, Long moduleId, Long envId) {
-        return propertyItemDao.selectList(new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getAppId, appId)
-                .eq(PropertyItem::getVersionId, versionId).eq(PropertyItem::getModuleId, moduleId)
-                .eq(PropertyItem::getEnvId, envId).orderByAsc(PropertyItem::getKey));
+    public List<PropertyItem> listPropertyItem(Long versionId, Long moduleId, Long envId) {
+        return propertyItemDao.selectList(
+                new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getVersionId, versionId)
+                        .eq(PropertyItem::getModuleId, moduleId).eq(PropertyItem::getEnvId, envId)
+                        .orderByAsc(PropertyItem::getKey));
     }
 
     @Transactional
     public PropertyItem updatePropertyItem(PropertyItem item) {
-        PropertyItem base = findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), BASELINE_ENV_ID,
-                item.getKey());
-        PropertyItem previous = findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), item.getEnvId(),
-                item.getKey());
+        PropertyItem base = findOne(item.getVersionId(), item.getModuleId(), BASELINE_ENV_ID, item.getKey());
+        PropertyItem previous = findOne(item.getVersionId(), item.getModuleId(), item.getEnvId(), item.getKey());
         if (base != null && base.getMode() == PropertyMode.READONLY) {
             throw new ParameterException("配置项只读");
         }
@@ -188,11 +177,10 @@ public class PropertyService extends ServiceImpl<PropertyItemDao, PropertyItem>
                     new LambdaUpdateWrapper<PropertyItem>().set(PropertyItem::getValue, item.getValue())
                             .set(item.getComment() != null, PropertyItem::getComment, item.getComment())
                             .set(PropertyItem::getUpdateTime, System.currentTimeMillis())
-                            .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()));
-            return findOne(item.getAppId(), item.getVersionId(), item.getModuleId(), item.getEnvId(), item.getKey());
+            return findOne(item.getVersionId(), item.getModuleId(), item.getEnvId(), item.getKey());
         } else {
             item.setMode(PropertyMode.MUTABLE);
             item.setCreateTime(System.currentTimeMillis());
@@ -204,31 +192,31 @@ 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());
+        PropertyItem base = findOne(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());
+        PropertyItem current = findOne(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()));
+        propertyItemDao
+                .delete(new LambdaQueryWrapper<PropertyItem>().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)
-                .eq(PropertyItem::getEnvId, envId).eq(PropertyItem::getKey, key));
+    public PropertyItem findOne(Long versionId, Long moduleId, Long envId, String key) {
+        return propertyItemDao.selectOne(
+                new LambdaQueryWrapper<PropertyItem>().eq(PropertyItem::getVersionId, versionId)
+                        .eq(PropertyItem::getModuleId, moduleId).eq(PropertyItem::getEnvId, envId)
+                        .eq(PropertyItem::getKey, key));
     }
 
-    public List<PropertyItem> mergePropertyList(Long appId, Long versionId, Long moduleId, Long envId) {
-        List<PropertyItem> list = listBaseline(appId, versionId, moduleId);
+    public List<PropertyItem> mergePropertyList(Long versionId, Long moduleId, Long envId) {
+        List<PropertyItem> list = listBaseline(versionId, moduleId);
         //获取环境定义配置项
-        Map<String, PropertyItem> itemMap = listPropertyItem(appId, versionId, moduleId, envId).stream()
+        Map<String, PropertyItem> itemMap = listPropertyItem(versionId, moduleId, envId).stream()
                 .collect(Collectors.toMap(PropertyItem::getKey, Function.identity()));
         //遍历基线
         for (PropertyItem item : list) {

+ 1 - 2
src/main/resources/script/init.sql

@@ -14,7 +14,6 @@ CREATE TABLE IF NOT EXISTS `app`
 -- Create syntax for TABLE 'property_item'
 CREATE TABLE IF NOT EXISTS `property_item`
 (
-    `app_id`      bigint(20) unsigned NOT NULL,
     `version_id`  bigint(20) unsigned NOT NULL,
     `module_id`   bigint(20) unsigned NOT NULL,
     `env_id`      bigint(20)          NOT NULL,
@@ -24,7 +23,7 @@ CREATE TABLE IF NOT EXISTS `property_item`
     `mode`        varchar(16)         NOT NULL,
     `create_time` bigint(20)          NOT NULL,
     `update_time` bigint(20)          NOT NULL,
-    PRIMARY KEY (`app_id`, `version_id`, `module_id`, `env_id`, `key`)
+    PRIMARY KEY (`version_id`, `module_id`, `env_id`, `key`)
 ) ENGINE = InnoDB
   DEFAULT CHARSET = utf8mb4;