mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
bugfix: 资源初始化
This commit is contained in:
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RequestMapping("/Script")
|
||||
@RequestMapping("/script")
|
||||
@RestController
|
||||
@SysLog(module = "")
|
||||
public class ScriptController {
|
||||
|
||||
@@ -38,35 +38,35 @@ public class ResourceEntity extends CommonEntity {
|
||||
|
||||
|
||||
@Comment("需要机构管理员权限")
|
||||
private Boolean orgAdmin;
|
||||
private Boolean orgAdmin = false;
|
||||
|
||||
|
||||
@Comment("需要系统管理员权限")
|
||||
private Boolean sysAdmin;
|
||||
private Boolean sysAdmin = false;
|
||||
|
||||
|
||||
@Comment("匿名用户可以访问")
|
||||
private Boolean anonymous;
|
||||
private Boolean anonymous = false;
|
||||
|
||||
|
||||
public void addChildren(ResourceEntity entity) {
|
||||
public void addChildren(ResourceEntity newRs) {
|
||||
|
||||
log.info("addChildren {} {}", this.getUrl(), entity.getUrl());
|
||||
log.info("addChildren1 {} {}", this.getUrl(), newRs.getUrl());
|
||||
if (this.children == null) {
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
if (entity.getUrl().equals(this.getUrl())) {
|
||||
if (newRs.getUrl().equals(this.getUrl())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (ResourceEntity child : this.children) {
|
||||
|
||||
if (this.getUrl().startsWith(child.getUrl())) {
|
||||
if (newRs.getUrl().startsWith(child.getUrl())) {
|
||||
|
||||
|
||||
child.addChildren(entity);
|
||||
child.addChildren(newRs);
|
||||
|
||||
return;
|
||||
|
||||
@@ -75,40 +75,30 @@ public class ResourceEntity extends CommonEntity {
|
||||
}
|
||||
|
||||
|
||||
String parent = getParent(entity.url);
|
||||
ResourceEntity r = new ResourceEntity();
|
||||
|
||||
if (isSamePath(parent, this.getUrl())) {
|
||||
String tmp = newRs.getUrl();
|
||||
|
||||
this.children.add(entity);
|
||||
entity.setParent(this);
|
||||
|
||||
} else {
|
||||
|
||||
ResourceEntity r = new ResourceEntity();
|
||||
|
||||
String tmp = entity.getUrl();
|
||||
|
||||
while (!isSamePath(this.getUrl(), getParent(tmp))) {
|
||||
tmp = getParent(tmp);
|
||||
}
|
||||
|
||||
|
||||
r.setUrl(tmp);
|
||||
|
||||
r.setName(r.getUrl());
|
||||
r.setType("3");
|
||||
r.setParent(this);
|
||||
r.setChildren(new ArrayList<>());
|
||||
r.setCode(r.getUrl());
|
||||
|
||||
|
||||
this.children.add(r);
|
||||
|
||||
|
||||
r.addChildren(entity);
|
||||
while (!isSamePath(this.getUrl(), getParent(tmp))) {
|
||||
tmp = getParent(tmp);
|
||||
}
|
||||
|
||||
|
||||
r.setUrl(tmp);
|
||||
|
||||
r.setName(r.getUrl());
|
||||
r.setType("3");
|
||||
r.setParent(this);
|
||||
r.setChildren(new ArrayList<>());
|
||||
r.setCode(r.getUrl());
|
||||
|
||||
|
||||
this.children.add(r);
|
||||
log.info("addChildren2 {} {}", r.getUrl(), this.getUrl());
|
||||
|
||||
r.addChildren(newRs);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private boolean isSamePath(String a, String b) {
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ResourceService extends BaseService<ResourceEntity, ResourceRepository>{
|
||||
public class ResourceService extends BaseService<ResourceEntity, ResourceRepository> {
|
||||
|
||||
@Autowired
|
||||
ResourceRepository repository;
|
||||
@@ -99,12 +99,12 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
public Optional<ResourceEntity> findByCode(String requestURL) {
|
||||
|
||||
return
|
||||
findAll(new Specification<ResourceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<ResourceEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.equal(root.get("code"), requestURL);
|
||||
}
|
||||
}).stream().findFirst();
|
||||
findAll(new Specification<ResourceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(Root<ResourceEntity> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.equal(root.get("code"), requestURL);
|
||||
}
|
||||
}).stream().findFirst();
|
||||
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
EntityManager entityManager;
|
||||
|
||||
@Transactional
|
||||
public void initUrlResource(){
|
||||
public void initUrlResource() {
|
||||
|
||||
List<ResourceEntity> all = findAll(new Specification<ResourceEntity>() {
|
||||
@Override
|
||||
@@ -135,14 +135,13 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
entity.setUrl("/");
|
||||
this.save(entity);
|
||||
root = entity;
|
||||
}else {
|
||||
} else {
|
||||
|
||||
root = all.get(0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<String> allUrls = getAllUrls();
|
||||
|
||||
|
||||
@@ -176,7 +175,7 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
|
||||
for (PathPattern pattern : info.getPathPatternsCondition().getPatterns()) {
|
||||
String ps = pattern.getPatternString();
|
||||
|
||||
urls.add(ps);
|
||||
urls.add(ps);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user