Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.ibeetl.admin.core.gen;
 
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
 
import com.ibeetl.admin.core.gen.model.Entity;
 
public class MavenProjectTarget extends BaseTarget {
    Entity entity;
    String basePackage;
    String basePackagePath = null;
    String targetPath = null;
    
    public MavenProjectTarget(Entity entity,String basePackage) {
        this.entity = entity;
        this.basePackage = basePackage;
        this.basePackagePath = basePackage.replace('.', '/');
    }
 
    @Override
    public void flush(AutoGen gen, String content) {
        String name = gen.getName();
        String target  = null;
        if (gen instanceof JSDelGen) {
             target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof JSEditGen) {
             target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof JSAddGen) {
             target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof JSApiGen) {
             target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof JSIndexGen) {
             target = getResourcePath()+"/static/js/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof HtmlIndexGen) {
             target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof HtmlEditGen) {
             target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof HtmlAddGen) {
             target = getResourcePath()+"/templates/"+this.urlBase+"/"+entity.getCode()+"/"+name;
        }else if (gen instanceof MdGen) {
             target = getResourcePath()+"/sql/"+entity.getSystem()+"/"+name;
        }else if (gen instanceof JavaEntityGen) {
             target = getSrcPath()+"/"+basePackagePath+"/entity/"+name;
        }else if (gen instanceof JavaDaoGen) {
             target = getSrcPath()+"/"+basePackagePath+"/dao/"+name;
        }else if (gen instanceof JavaQueryGen) {
             target = getSrcPath()+"/"+basePackagePath+"/web/query/"+name;
        }else if (gen instanceof JavaServiceGen) {
             target = getSrcPath()+"/"+basePackagePath+"/service/"+name;
        }else if (gen instanceof JavaControllerGen) {
             target = getSrcPath()+"/"+basePackagePath+"/web/"+name;
        }
        
        if(target==null) {
            return ;
        }
        flush(target,content);
 
    }
 
    protected void flush(String path, String content) {
        
        FileWriter fw;
        try {
            File file = new File(path);
            if(!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            fw = new FileWriter(new File(path));
            fw.write(content);
            fw.close();
            System.out.println(path);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        
    }
 
    
    public String getTargetPath() {
        return targetPath;
    }
 
    public void setTargetPath(String targetPath) {
        this.targetPath = targetPath;
    }
 
    private  String getSrcPath() {
       
        return getRootPath() + File.separator + "src/main/java";
    }
 
    private  String getResourcePath() {
 
        return getRootPath() + File.separator + "src/main/resources";
    }
 
    public  String getRootPath() {
        if(targetPath!=null) {
            return targetPath;
        }else {
            return detectRootPath();
        }
        
    }
    
    public static String detectRootPath() {
        String srcPath;
        String userDir = System.getProperty("user.dir");
        if (userDir == null) {
            throw new NullPointerException("用户目录未找到");
        }
 
        return userDir;
    }
 
}