java110
2021-09-12 3ed2627f7c05e8eaa4559371f9d6d2cb71aa4275
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
package com.java110.code.newBack;
 
import com.java110.code.util.FileUtilBase;
import com.java110.utils.util.DateUtil;
 
import java.util.Map;
 
/**
 *
 */
public class GeneratorDtoBean extends BaseGenerator {
 
 
    /**
     * 拼装 查询数量
     *
     * @param data        数据
     * @param fileContext 文件内容
     * @return filContext 数据
     */
    private String dealVariableAndGetSet(Data data, String fileContext) {
 
        Map<String, String> params = data.getParams();
 
        String variable = "";
        String variableGetSet = "";
 
        for (String key : params.keySet()) {
            if ("operate".equals(key) || "bId".equals(key) || "statusCd".equals(key)|| "createTime".equals(key)) {
                continue;
            }
            variable += "private String " + key + ";\n";
 
            variableGetSet += "public String get" + toUpperCaseFirstOne(key) + "() {\n"
                    + "        return " + key + ";\n"
                    + "    }\n";
            variableGetSet += "public void set" + toUpperCaseFirstOne(key) + "(String " + key + ") {\n"
                    + "        this." + key + " = " + key + ";\n"
                    + "    }\n";
 
 
        }
 
 
        fileContext = fileContext.replace("$beanVariable$", variable);
        fileContext = fileContext.replace("$beanVariableGetSet$", variableGetSet);
 
        return fileContext;
    }
 
 
    /**
     * 生成代码
     *
     * @param data 数据
     */
    public void generator(Data data) throws Exception {
        StringBuffer sb = readFile(this.getClass().getResource("/template/dto.txt").getFile());
        String fileContext = sb.toString();
        fileContext = fileContext.replace("store", toLowerCaseFirstOne(data.getName()))
                .replace("@@templateCode@@",data.getName())
                .replace("Store", toUpperCaseFirstOne(data.getName()))
                .replace("商户", data.getDesc())
                .replace("@@date@@", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
 
        fileContext = dealVariableAndGetSet(data, fileContext);
        String writePath = this.getClass().getResource("/").getPath()
                + "out/back/dto/" + data.getName() + "/" + toUpperCaseFirstOne(data.getName()) + "Dto.java";
 
        writeFile(writePath,
                fileContext);
        //复制生成的文件到对应分区目录下
        if (data.isAutoMove()) {
            FileUtilBase.copyfile(writePath, "java110-bean\\src\\main\\java\\com\\java110\\dto\\" + data.getName() + "/" + toUpperCaseFirstOne(data.getName()) + "Dto.java");
        }
    }
}