mirror of
https://github.com/dataease/dataease.git
synced 2026-06-17 21:08:31 +08:00
refactor(X-Pack): 对权限体系进行重构-17
This commit is contained in:
@@ -29,6 +29,9 @@ public class InitSqlListener implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
List<DeStandaloneVersion> versionRecords = deStandaloneVersionRepository.findRecords();
|
||||
boolean isUpgrade = !CollectionUtils.isEmpty(versionRecords);
|
||||
|
||||
List<SqlBlock> sqlBlocks = new ArrayList<>();
|
||||
Map<String, SqlBlock> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType(SqlBlock.class);
|
||||
sqlBlocks.addAll(beansOfType.entrySet().stream().map(Map.Entry::getValue).toList());
|
||||
@@ -38,11 +41,21 @@ public class InitSqlListener implements ApplicationRunner {
|
||||
String versionGroup = block.getVersionGroup();
|
||||
groupedSqlBlocks.computeIfAbsent(versionGroup, k -> new ArrayList<>()).add(block);
|
||||
}
|
||||
for (String versionGroup : groupedSqlBlocks.keySet()) {
|
||||
List<SqlBlock> toMigrateSqlBlocks = groupedSqlBlocks.get(versionGroup);
|
||||
|
||||
if (isUpgrade) {
|
||||
executeGroups(groupedSqlBlocks, "upgrade");
|
||||
} else {
|
||||
executeGroups(groupedSqlBlocks, "1", "2", "3");
|
||||
}
|
||||
}
|
||||
|
||||
private void executeGroups(Map<String, List<SqlBlock>> groupedSqlBlocks, String... groups) {
|
||||
for (String group : groups) {
|
||||
List<SqlBlock> toMigrateSqlBlocks = groupedSqlBlocks.get(group);
|
||||
if (toMigrateSqlBlocks == null) continue;
|
||||
toMigrateSqlBlocks.sort(versionComparator);
|
||||
int versionRank = findLastRank();
|
||||
DeStandaloneVersion lastVersion = getLastVersion(versionGroup);
|
||||
DeStandaloneVersion lastVersion = getLastVersion(group);
|
||||
if (lastVersion == null) {
|
||||
for (SqlBlock sqlBlock : toMigrateSqlBlocks) {
|
||||
versionRank++;
|
||||
@@ -98,33 +111,6 @@ public class InitSqlListener implements ApplicationRunner {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Comparator<SqlBlock> versionComparator = new Comparator<SqlBlock>() {
|
||||
@Override
|
||||
public int compare(SqlBlock sb1, SqlBlock sb2) {
|
||||
Version v1 = sb1.getVersion();
|
||||
Version v2 = sb2.getVersion();
|
||||
|
||||
int i = 0;
|
||||
while (i < v1.getParts().size() || i < v2.getParts().size()) {
|
||||
if (i < v1.getParts().size() && i < v2.getParts().size()) {
|
||||
int thisPart = Integer.parseInt(v1.getParts().get(i));
|
||||
int otherPart = Integer.parseInt(v2.getParts().get(i));
|
||||
if (thisPart != otherPart) {
|
||||
return thisPart - otherPart;
|
||||
}
|
||||
} else if (i < v1.getParts().size()) {
|
||||
if (Integer.parseInt(v1.getParts().get(i)) != 0) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (Integer.parseInt(v2.getParts().get(i)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
private Comparator<SqlBlock> versionComparator = (sb1, sb2) -> sb1.getVersion().compareTo(sb2.getVersion());
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -42,14 +43,10 @@ public class SysParameterManage {
|
||||
private DatasourceServer datasourceServer;
|
||||
|
||||
public String singleVal(String key) {
|
||||
Specification<CoreSysSetting> spec = (root, query, cb) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
predicates.add(cb.equal(root.get("pkey"), key));
|
||||
return cb.and(predicates.toArray(new Predicate[0]));
|
||||
};
|
||||
CoreSysSetting sysSetting = coreSysSettingRepository.findOne(spec).orElse(null);
|
||||
if (ObjectUtils.isNotEmpty(sysSetting)) {
|
||||
return sysSetting.getPval();
|
||||
Specification<CoreSysSetting> spec = (root, query, cb) -> cb.equal(root.get("pkey"), key);
|
||||
List<CoreSysSetting> list = coreSysSettingRepository.findAll(spec, PageRequest.of(0, 1)).toList();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
return list.getFirst().getPval();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,22 +19,30 @@ public class Version implements Comparable<Version> {
|
||||
return Arrays.asList(version.split("\\."));
|
||||
}
|
||||
|
||||
private static int parsePart(String s) {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version other) {
|
||||
int i = 0;
|
||||
while (i < parts.size() || i < other.parts.size()) {
|
||||
if (i < parts.size() && i < other.parts.size()) {
|
||||
int thisPart = Integer.parseInt(parts.get(i));
|
||||
int otherPart = Integer.parseInt(other.parts.get(i));
|
||||
int thisPart = parsePart(parts.get(i));
|
||||
int otherPart = parsePart(other.parts.get(i));
|
||||
if (thisPart != otherPart) {
|
||||
return thisPart - otherPart;
|
||||
}
|
||||
} else if (i < parts.size()) {
|
||||
if (Integer.parseInt(parts.get(i)) != 0) {
|
||||
if (parsePart(parts.get(i)) != 0) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (Integer.parseInt(other.parts.get(i)) != 0) {
|
||||
if (parsePart(other.parts.get(i)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user