PC
2024-03-30 e46f64d9f9f26531af2104afd2c46ec6b05c430c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.qianwen.core.scanner.modular.service;
 
import cn.hutool.core.util.StrUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.qianwen.core.scanner.config.properties.ScannerProperties;
import com.qianwen.core.scanner.modular.factory.ApiResourceFactory;
import com.qianwen.core.scanner.modular.model.ResourceDefinition;
import com.qianwen.core.scanner.modular.model.ResourceTreeNode;
 
/* loaded from: blade-starter-scanner-9.3.0.0-SNAPSHOT.jar:org/springblade/core/scanner/modular/service/ResourceCollectService.class */
public class ResourceCollectService {
    public static final String APP_CODE_PREFIX = "appType-";
    public static final String CONTROLLER_CODE_PREFIX = "conType-";
    public static final String RESOURCE_CODE_PREFIX = "resType-";
    private ApiResourceFactory apiResourceFactory;
    private ScannerProperties scannerProperties;
 
    public ResourceCollectService(ApiResourceFactory apiResourceFactory, ScannerProperties scannerProperties) {
        this.apiResourceFactory = apiResourceFactory;
        this.scannerProperties = scannerProperties;
    }
 
    public List<ResourceDefinition> getAllAppResourceList(String code, String resourceName) {
        if (StrUtil.isBlank(code)) {
            List<ResourceDefinition> result = this.apiResourceFactory.getAllResources();
            return findResource(resourceName, result);
        }
        List<ResourceDefinition> result2 = null;
        if (code.startsWith(APP_CODE_PREFIX)) {
            result2 = this.apiResourceFactory.getAllResources();
        } else if (code.startsWith(CONTROLLER_CODE_PREFIX)) {
            result2 = this.apiResourceFactory.getResourcesByModularCode(code.replace(CONTROLLER_CODE_PREFIX, ""));
        } else if (code.startsWith(RESOURCE_CODE_PREFIX)) {
            ResourceDefinition resourceDefinitions = this.apiResourceFactory.getResource(code.replace(CONTROLLER_CODE_PREFIX, ""));
            result2 = Arrays.asList(resourceDefinitions);
        }
        return findResource(resourceName, result2);
    }
 
    public List<ResourceTreeNode> getResourceTree() {
        ArrayList<ResourceTreeNode> resourceTreeNodes = new ArrayList<>();
        ResourceTreeNode appResources = new ResourceTreeNode();
        appResources.setName(this.scannerProperties.getAppName());
        appResources.setCode(APP_CODE_PREFIX + this.scannerProperties.getAppCode());
        appResources.setChildren(new ArrayList());
        Map<String, Map<String, ResourceDefinition>> modularResources = this.apiResourceFactory.getModularResources();
        for (String modularCode : modularResources.keySet()) {
            ArrayList<ResourceTreeNode> modularResourceTreeNode = new ArrayList<>();
            Map<String, ResourceDefinition> stringResourceDefinitionMap = modularResources.get(modularCode);
            for (Map.Entry<String, ResourceDefinition> entry : stringResourceDefinitionMap.entrySet()) {
                ResourceDefinition value = entry.getValue();
                modularResourceTreeNode.add(new ResourceTreeNode(value.getName(), RESOURCE_CODE_PREFIX + value.getCode()));
            }
            appResources.getChildren().add(new ResourceTreeNode(this.apiResourceFactory.getResourceName(modularCode), CONTROLLER_CODE_PREFIX + modularCode, modularResourceTreeNode));
        }
        resourceTreeNodes.add(appResources);
        return resourceTreeNodes;
    }
 
    private List<ResourceDefinition> findResource(String resourceName, List<ResourceDefinition> resourceDefinitions) {
        if (StrUtil.isBlank(resourceName)) {
            return resourceDefinitions;
        }
        for (ResourceDefinition resourceDefinition : resourceDefinitions) {
            if (resourceDefinition.getName().equals(resourceName)) {
                return Arrays.asList(resourceDefinition);
            }
        }
        return null;
    }
}