admin
2024-07-25 47e3087067abd35e6337c011f96d2338c0bb1aae
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
package org.yeshi.utils.generater.entity.admin;
 
import org.yeshi.utils.generater.annotation.admin.AdminController;
import org.yeshi.utils.generater.annotation.admin.form.*;
import org.yeshi.utils.generater.entity.KeyValue;
import org.yeshi.utils.generater.util.AnotationUtil;
import org.yeshi.utils.generater.vo.xmlconfig.admin.AdminControllerData;
import org.yeshi.utils.generater.vo.xmlconfig.admin.AdminData;
import org.yeshi.utils.generater.vo.xmlconfig.admin.ColumnData;
import org.yeshi.utils.generater.vo.xmlconfig.admin.SearchFormData;
import org.yeshi.utils.generater.vo.xmlconfig.admin.form.*;
import org.yeshi.utils.generater.vo.xmlconfig.base.FormComponent;
 
import java.lang.annotation.Annotation;
import java.util.*;
 
/**
 * @author Administrator
 * @title: AdminGeneraterInfo
 * @description: TODO
 * @date 2021/9/24 11:03
 */
public class AdminGeneraterInfo {
 
    //entity类
    private Class entity;
    //controller注解对象
    private AdminControllerData controllerData;
    //修改的表单行数据
    private List<FormRowData> updateFormRows;
    //添加的表单行数据
    private List<FormRowData> addFormRows;
    //搜索的表单行数据
    private List<FormRowData> searchFormRows;
 
    private List<Map<String, Object>> showDataList;
 
    private String title;
    private String pageDir;
    private String listFileName;
    private String addFileName;
    private String updateFileName;
 
    private boolean delete;
    private boolean add;
    private boolean edit;
 
 
    public String getPageDir() {
        return pageDir;
    }
 
    public void setPageDir(String pageDir) {
        this.pageDir = pageDir;
    }
 
    public Class getEntity() {
        return entity;
    }
 
    public void setEntity(Class entity) {
        this.entity = entity;
    }
 
    public AdminControllerData getControllerData() {
        return controllerData;
    }
 
    public void setControllerData(AdminControllerData controllerData) {
        this.controllerData = controllerData;
    }
 
    public List<FormRowData> getUpdateFormRows() {
        return updateFormRows;
    }
 
    public void setUpdateFormRows(List<FormRowData> updateFormRows) {
        this.updateFormRows = updateFormRows;
    }
 
    public List<FormRowData> getAddFormRows() {
        return addFormRows;
    }
 
    public void setAddFormRows(List<FormRowData> addFormRows) {
        this.addFormRows = addFormRows;
    }
 
    public List<FormRowData> getSearchFormRows() {
        return searchFormRows;
    }
 
    public void setSearchFormRows(List<FormRowData> searchFormRows) {
        this.searchFormRows = searchFormRows;
    }
 
    public List<Map<String, Object>> getShowDataList() {
        return showDataList;
    }
 
    public void setShowDataList(List<Map<String, Object>> showDataList) {
        this.showDataList = showDataList;
    }
 
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
    public String getListFileName() {
        return listFileName;
    }
 
    public void setListFileName(String listFileName) {
        this.listFileName = listFileName;
    }
 
    public String getAddFileName() {
        return addFileName;
    }
 
    public void setAddFileName(String addFileName) {
        this.addFileName = addFileName;
    }
 
    public String getUpdateFileName() {
        return updateFileName;
    }
 
    public void setUpdateFileName(String updateFileName) {
        this.updateFileName = updateFileName;
    }
 
    public boolean isDelete() {
        return delete;
    }
 
    public void setDelete(boolean delete) {
        this.delete = delete;
    }
 
    public boolean isAdd() {
        return add;
    }
 
    public void setAdd(boolean add) {
        this.add = add;
    }
 
    public boolean isEdit() {
        return edit;
    }
 
    public void setEdit(boolean edit) {
        this.edit = edit;
    }
 
    public static class Builder {
 
        private Class entity;
 
        private AdminData adminData;
 
        public Builder setEntityClass(Class clazz) {
            this.entity = clazz;
            return this;
        }
 
        public Builder setAdminData(AdminData adminData) {
            this.adminData = adminData;
            return this;
        }
 
        public AdminGeneraterInfo build() throws Exception {
            if (entity == null) {
                throw new Exception("尚未设置entity");
            }
 
            if (adminData != null) {
                //xml配置文件方式生成
                AdminGeneraterInfo info = new AdminGeneraterInfo();
                info.setEntity(entity);
                info.setControllerData(adminData.getController());
                info.setTitle(adminData.getPages().getTitle());
                info.setPageDir(adminData.getPages().getPageDir());
                info.setEdit(adminData.getPages().getList().isEdit());
                info.setDelete(adminData.getPages().getList().isDelete());
                info.setAdd(adminData.getPages().getAdd() != null);
 
 
                if (adminData.getPages().getList() != null) {
                    info.setListFileName(adminData.getPages().getList().getFileName());
                    if (adminData.getPages().getList().getSearchForm() != null) {
                        List<FormRowData> searchFormList = new ArrayList<>();
                        for (ColumnData columnData : adminData.getPages().getList().getSearchForm().getColumns()) {
                            FormRowData rowData = getFormRowData(columnData);
                            searchFormList.add(rowData);
                        }
                        info.setSearchFormRows(searchFormList);
                    }
 
                    List<Map<String, Object>> showList = new ArrayList<>();
 
                    for (ColumnData columnData : adminData.getPages().getList().getColumns()) {
                        Map<String, Object> map = new HashMap<>();
                        map.put("identifier", columnData.getProperty());
                        map.put("title", columnData.getTitle());
                        map.put("order", columnData.getOrder());
                        map.put("imgWidth", columnData.getImgWidth());
                        map.put("imgHeight", columnData.getImgHeight());
                        map.put("showType", columnData.getShowType().name());
                        showList.add(map);
                    }
 
                    Comparator<Map<String, Object>> cm = (Map<String, Object> o1, Map<String, Object> o2) -> {
                        return (int) (o1.get("order")) - (int) (o2.get("order"));
                    };
                    Collections.sort(showList, cm);
                    info.setShowDataList(showList);
                }
 
                if (adminData.getPages().getAdd() != null) {
                    info.setAddFileName(adminData.getPages().getAdd().getFileName());
                    List<FormRowData> rowList = new ArrayList<>();
                    for (ColumnData columnData : adminData.getPages().getAdd().getColumns()) {
                        FormRowData rowData = getFormRowData(columnData);
                        rowList.add(rowData);
                    }
                    info.setAddFormRows(rowList);
                }
 
                if (adminData.getPages().getUpdate() != null) {
                    info.setUpdateFileName(adminData.getPages().getUpdate().getFileName());
                    List<FormRowData> rowList = new ArrayList<>();
                    for (ColumnData columnData : adminData.getPages().getUpdate().getColumns()) {
                        FormRowData rowData = getFormRowData(columnData);
                        rowList.add(rowData);
                    }
                    info.setUpdateFormRows(rowList);
                }
 
                return info;
            } else {
                //注解方式生成
                //查询是否需要生成管理界面与controller
                Annotation[] ans = entity.getAnnotations();
                for (Annotation an : ans) {
                    if (an instanceof AdminController) {
                        Class searchFormClass = ((AdminController) an).searchForm();
                        AdminGeneraterInfo info = new AdminGeneraterInfo();
                        info.setEntity(entity);
 
                        AdminControllerData adminControllerData = new AdminControllerData();
                        AdminController adminController = (AdminController) an;
                        adminControllerData.setMapping(adminController.mapping());
                        adminControllerData.setResponseBody(true);
                        adminControllerData.setPkg(null);
                        adminControllerData.setJsonp(false);
 
                        info.setEdit(adminController.edit());
                        info.setDelete(adminController.delete());
                        info.setAdd(true);
 
                        info.setControllerData(adminControllerData);
                        info.setSearchFormRows(AnotationUtil.getFormRowData(searchFormClass));
                        info.setAddFormRows(AnotationUtil.getFormRowData(entity));
                        info.setUpdateFormRows(AnotationUtil.getUpdateFormRowData(entity));
                        info.setShowDataList(AnotationUtil.getShowDataList(entity));
                        return info;
                    }
                }
            }
            return null;
        }
 
        private FormRowData getFormRowData(ColumnData columnData) {
            FormRowData rowData = new FormRowData();
            rowData.setKey(columnData.getProperty());
            FormComponent component = columnData.getComponent();
            Map<String, Object> params = new HashMap<>();
            params.put("desc", component.getDesc());
            params.put("disable", !component.isEnable());
            params.put("title", columnData.getTitle());
            if (component instanceof FormComponentText) {
                rowData.setType(Text.class.getSimpleName());
 
                FormComponentText formComponentText = (FormComponentText) component;
                params.put("dateFormat", formComponentText.getDateFormat());
                params.put("inputType", formComponentText.getInputType().name());
                params.put("maxLength", formComponentText.getMaxLength() == null ? -1 : formComponentText.getMaxLength());
                params.put("minLength", formComponentText.getMinLength() == null ? -1 : formComponentText.getMinLength());
                params.put("placeHolder", formComponentText.getPlaceHolder());
                if (formComponentText.getVerify() != null) {
                    params.put("require", formComponentText.getVerify().isRequire());
                    params.put("verifyType", formComponentText.getVerify().getType());
                    params.put("verifyValue", formComponentText.getVerify().getExpress());
                    params.put("verifyNotifyMsg", formComponentText.getVerify().getNotify());
                }
 
            } else if (component instanceof FormComponentRadioGroup) {
                rowData.setType(RadioGroup.class.getSimpleName());
                FormComponentRadioGroup formComponentRadioGroup = (FormComponentRadioGroup) component;
                Map<String, Object> map = formComponentRadioGroup.getValues();
                List<KeyValue> list = new ArrayList<>();
                for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) {
                    String key = its.next();
                    list.add(new KeyValue(key, map.get(key) + ""));
                }
                params.put("values", list);
            } else if (component instanceof FormComponentImg) {
                rowData.setType(Img.class.getSimpleName());
                FormComponentImg formComponentImg = (FormComponentImg) component;
                params.put("width", formComponentImg.getWidth() == null ? -1 : formComponentImg.getWidth());
                params.put("height", formComponentImg.getHeight() == null ? -1 : formComponentImg.getHeight());
                if( formComponentImg.getApi()!=null) {
                    params.put("uploadApi", formComponentImg.getApi().getPath());
                    if (formComponentImg.getApi().getParams() != null) {
                        List<KeyValue> list = new ArrayList<>();
                        for (Iterator<String> its = formComponentImg.getApi().getParams().keySet().iterator(); its.hasNext(); ) {
                            String key = its.next();
                            list.add(new KeyValue(key, formComponentImg.getApi().getParams().get(key) + ""));
                        }
                        params.put("uploadApiParams", list);
                    }
                }
            } else if (component instanceof FormComponentSwitch) {
                rowData.setType(Switch.class.getSimpleName());
            } else if (component instanceof FormComponentSelect) {
                rowData.setType(Select.class.getSimpleName());
                FormComponentSelect formComponentSelect = (FormComponentSelect) component;
                if (formComponentSelect.getApi() != null) {
                    params.put("apiPath", formComponentSelect.getApi().getPath());
                    if(formComponentSelect.getApi().getParams()!=null) {
                        List<KeyValue> list = new ArrayList<>();
                        for (Iterator<String> its = formComponentSelect.getApi().getParams().keySet().iterator(); its.hasNext(); ) {
                            String key = its.next();
                            list.add(new KeyValue(key, formComponentSelect.getApi().getParams().get(key) + ""));
                        }
                        params.put("apiParams", list);
                    }
                }
 
                if (formComponentSelect.getValues() != null) {
                    List<KeyValue> list = new ArrayList<>();
                    for (Iterator<String> its = formComponentSelect.getValues().keySet().iterator(); its.hasNext(); ) {
                        String key = its.next();
                        list.add(new KeyValue(key, formComponentSelect.getValues().get(key) + ""));
                    }
                    params.put("values", list);
                }
            }
            rowData.setParams(params);
            return rowData;
        }
 
    }
 
 
}