Helius
2021-02-26 de04085526eda992155716eda98af621ad681e4e
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package com.matrix.codeGeneration.ext;
 
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.apache.poi.ss.usermodel.DataFormatter;
 
import com.matrix.codeGeneration.model.CodeFile;
import com.matrix.codeGeneration.model.CodeModel;
import com.matrix.codeGeneration.model.CommonData;
import com.matrix.codeGeneration.model.Constant;
import com.matrix.codeGeneration.model.OutDataSource;
import com.matrix.codeGeneration.model.TableClassModel;
import com.matrix.codeGeneration.plugin.DateUtils;
 
/**
 * 平安意健险代码文件模型
 */
public class AhcsModels implements CodeModel {
 
    /**
     * 模型名称用来标识这个模型
     */
    String modelName="";
 
    /**
     * 包名
     */
    private String packageName="";
 
    /**
     * 名称后缀
     */
    private String suffixName="";
 
    /**
     * 名称前缀
     */
    private String prefixName="";
 
    /**
     * 文件扩展名称
     */
    private String fileExtName="";
 
    /**
     * 模板名称
     */
    private String templateName="";
 
    /**
     * 导入类列表
     */
    private Map<String, String> importList = new HashMap<>();
 
    /**
     * 类的变量名称
     */
    private String classVariableName="";
 
       
 
    @Override
    public List<CodeFile> buildCodeFile(OutDataSource dataSource) {
        List<CodeFile> codeFileList = new ArrayList<>();
        for (TableClassModel tableClassModel : dataSource.getTableClassModels()) {
            Map<String, Object> fileData = new HashMap<>();
            System.out.println(tableClassModel.getClassName());
            System.out.println(this.modelName);
            System.out.println("--------------");
 
            if (Constant.JAVA_BEAN.equals(this.modelName)) {
 
                this.getImportList().put("Extend", "com.zkingsoft.anotations.Extend");
 
            } else if (Constant.MYBATIS_DAO.equals(this.modelName)) {
                this.setImportList(new HashMap<String, String>());
                this.getImportList().put("bean",
                        getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource));
 
                this.getImportList().put("List", "java.util.List");
                this.getImportList().put("Param", "org.apache.ibatis.annotations.Param");
                this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO");
                this.getImportList().put("Map", "java.util.Map");
 
            } else if (Constant.MYBATIS_DAO_IMPL.equals(this.modelName)) {
 
            } else if (Constant.SERVICE.equals(this.modelName)) {
 
                this.setImportList(new HashMap<String, String>());
                this.getImportList().put("bean",
                        getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource));
                this.getImportList().put("List", "java.util.List");
                this.getImportList().put("BaseServices", "com.zkingsoft.constraint.BaseServices");
                this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO");
 
            } else if (Constant.SERVICE_IMPL.equals(this.modelName)) {
                this.setImportList(new HashMap<String, String>());
                this.getImportList().put("bean",
                        getModelQualifiedClassName(Constant.JAVA_BEAN, tableClassModel, dataSource));
 
                this.getImportList().put("services",
                        getModelQualifiedClassName(Constant.SERVICE, tableClassModel, dataSource));
                this.getImportList().put("dao",
                        getModelQualifiedClassName(Constant.MYBATIS_DAO, tableClassModel, dataSource));
                this.getImportList().put("springframework.Service", "org.springframework.stereotype.Service");
                this.getImportList().put("Autowired", "org.springframework.beans.factory.annotation.Autowired");
                this.getImportList().put("List", "java.util.List");
                this.getImportList().put("Map", "java.util.Map");
 
            } else if (Constant.ACTION.equals(this.modelName)) {
 
                this.getImportList().put("Controller", "org.springframework.stereotype.Controller");
                this.getImportList().put("Resource", "javax.annotation.Resource");
                this.getImportList().put("AjaxResult", "com.zkingsoft.pojo.AjaxResult");
                this.getImportList().put("PaginationVO", "com.zkingsoft.pojo.PaginationVO");
                this.getImportList().put("WebUtil", "com.zkingsoft.util.WebUtil");
                this.getImportList().put("SaveRequestToken", "com.zkingsoft.anotations.SaveRequestToken");
                this.getImportList().put("RemoveRequestToken", "com.zkingsoft.anotations.RemoveRequestToken");
                this.getImportList().put("BaseController", "com.zkingsoft.constraint.BaseController");
                this.getImportList().put("RequestMapping", "org.springframework.web.bind.annotation.RequestMapping");
                this.getImportList().put("ResponseBody", "org.springframework.web.bind.annotation.ResponseBody");
            }
            fileData.put("importList", this.getImportList());
            CodeFile codeFile = new CodeFile();
            // 计算文件的名称
            codeFile.setFileName(getFileName(tableClassModel, this));
            codeFile.setSavePath(File.separator + getPackageName().replace(".", File.separator) + File.separator);
            fileData.put("codeModel", this);
            fileData.put("dataSource", dataSource);
            fileData.put("tableClassModel", tableClassModel);
            fileData.put("commonData", new CommonData());
            fileData.put("time", DateUtils.dateFormatStr(new Date(), "yyyy-MM-dd HH:mm"));
 
            fileData.put("ClassName", getModelClassName(this.getModelName(), tableClassModel, dataSource));
            codeFile.setData(fileData);
            codeFile.setTemplateName(this.templateName);
            codeFileList.add(codeFile);
        }
        return codeFileList;
 
    }
 
    /**
     * 计算文件名称
     * 
     * @param tableClassModel
     * @return
     */
    public String getFileName(TableClassModel tableClassModel, AhcsModels ahcsModels) {
        StringBuffer name = new StringBuffer();
        String prefix = ahcsModels.getPrefixName();
        String suffix = ahcsModels.getSuffixName();
        String extensionName = ahcsModels.getFileExtName();
        if (prefix != null) {
            name.append(prefix);
        }
        name.append(tableClassModel.getClassName());
        if (suffix != null) {
            name.append(suffix);
        }
        name.append(extensionName);
        return name.toString();
    }
 
    /**
     * 获取一个模型的变量名
     * 
     * @param modelName
     * @param dataSource
     * @return
     */
    public String getModelVariablesName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) {
        return dataSource.getNameConvert()
                .classNameToTableName(getModelClassName(modelName, tableClassModel, dataSource));
    }
 
    /**
     * 获取一个模型的全类名
     * 
     * @param modelName
     * @param dataSource
     * @return
     */
    public String getModelQualifiedClassName(String modelName, TableClassModel tableClassModel,
            OutDataSource dataSource) {
        AhcsModels ahcsMOdels = ((AhcsModels) dataSource.getCodeModels().get(modelName));
        String className = ahcsMOdels.getPackageName() + "." + ahcsMOdels.getPrefixName()
                + tableClassModel.getClassName() + ahcsMOdels.getSuffixName();
        return className;
    }
 
    /**
     * 获取一个模型的类名
     * 
     * @param modelName
     * @param dataSource
     * @return
     */
    public String getModelClassName(String modelName, TableClassModel tableClassModel, OutDataSource dataSource) {
        AhcsModels ahcsMOdels = ((AhcsModels) dataSource.getCodeModels().get(modelName));
        String className = ahcsMOdels.getPrefixName() + tableClassModel.getClassName() + ahcsMOdels.getSuffixName();
        return className;
    }
 
    public String getModelName() {
        return modelName;
    }
 
    public void setModelName(String modelName) {
        this.modelName = modelName;
    }
 
    public String getPackageName() {
        return packageName;
    }
 
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }
 
    public String getSuffixName() {
        return suffixName;
    }
 
    public void setSuffixName(String suffixName) {
        this.suffixName = suffixName;
    }
 
    public String getPrefixName() {
        return prefixName;
    }
 
    public void setPrefixName(String prefixName) {
        this.prefixName = prefixName;
    }
 
    public String getFileExtName() {
        return fileExtName;
    }
 
    public void setFileExtName(String fileExtName) {
        this.fileExtName = fileExtName;
    }
 
    public String getTemplateName() {
        return templateName;
    }
 
    public void setTemplateName(String templateName) {
        this.templateName = templateName;
    }
 
    public Map<String, String> getImportList() {
        return importList;
    }
 
    public void setImportList(Map<String, String> importList) {
        this.importList = importList;
    }
 
    public String getClassVariableName() {
        return classVariableName;
    }
 
    public void setClassVariableName(String classVariableName) {
        this.classVariableName = classVariableName;
    }
 
 
 
}