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