admin
2021-09-30 1a1a315efb1b5dc294013126f35819e36565040c
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
package org.yeshi.utils.generater.vo.admin;
 
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.generater.annotation.admin.form.Select;
import org.yeshi.utils.generater.annotation.admin.form.Text;
import org.yeshi.utils.generater.annotation.admin.form.TextArea;
import org.yeshi.utils.generater.entity.KeyValue;
import org.yeshi.utils.generater.entity.admin.AdminGeneraterInfo;
import org.yeshi.utils.generater.entity.admin.FormRowData;
import org.yeshi.utils.generater.entity.admin.FormVerifyType;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author Administrator
 * @title: FormAddInfo
 * @description: 构建修改的输出类
 * @date 2021/9/26 10:07
 */
public class ListInfoVO {
    private String title;
    private List<FormRowData> searchFormRows;
    //显示的字段
    private List<Map<String, Object>> showFileds;
    //进入页面就需要请求的数据
    private List<FormHttpRequestInfoVO> preRequestList;
    private List<FormInputRegexVerifyVO> regexVerifyList;
    //列表接口
    private String listApi;
    //添加页路径
    private String addPagePath;
    //更新页路径
    private String updatePagePath;
 
 
    public static class Builder {
 
        private AdminGeneraterInfo generaterInfo;
 
        public Builder setAdminInfo(AdminGeneraterInfo generaterInfo) {
            this.generaterInfo = generaterInfo;
            return this;
        }
 
        public ListInfoVO build() {
            ListInfoVO vo = new ListInfoVO();
            vo.setListApi(generaterInfo.getControllerData().mapping() + "/list");
            vo.setAddPagePath("add.html");
            vo.setUpdatePagePath("update.html");
            vo.setSearchFormRows(generaterInfo.getSearchFormRows());
            vo.setShowFileds(generaterInfo.getShowDataList());
            vo.setTitle("修改" + generaterInfo.getControllerData().title());
            //遍历需要正则表达式的Text或者TextArea
            List<FormInputRegexVerifyVO> verifyVOList = new ArrayList<>();
            for (FormRowData row : vo.getSearchFormRows()) {
                if (!row.getType().equalsIgnoreCase(Text.class.getSimpleName()) && !row.getType().equalsIgnoreCase(TextArea.class.getSimpleName())) {
                    continue;
                }
                if (row.getParams() == null)
                    continue;
                if ((row.getParams().get("verifyType")) != FormVerifyType.regex)
                    continue;
                FormInputRegexVerifyVO verifyVO = new FormInputRegexVerifyVO();
                verifyVO.setExpression(row.getParams().get("verifyValue") + "");
                verifyVO.setKey("_" + row.getKey());
                verifyVO.setMsg(row.getParams().get("verifyNotifyMsg") + "");
                verifyVOList.add(verifyVO);
            }
            vo.setRegexVerifyList(verifyVOList);
            //提取select中的网络请求
            List<FormHttpRequestInfoVO> formHttpRequestInfoVOList = new ArrayList<>();
            for (FormRowData row : vo.getSearchFormRows()) {
                if (!row.getType().equalsIgnoreCase(Select.class.getSimpleName())) {
                    continue;
                }
                if (row.getParams() == null)
                    continue;
 
                String apiPath = row.getParams().get("apiPath") + "";
                if (StringUtil.isNullOrEmpty(apiPath)) {
                    continue;
                }
                FormHttpRequestInfoVO requestInfoVO = new FormHttpRequestInfoVO();
                Map<String, String> apiParams = new HashMap<>();
                if (((List) row.getParams().get("apiParams")).size() > 0) {
                    List<KeyValue> apiParamsList = (List<KeyValue>) row.getParams().get("apiParams");
                    for (KeyValue kv : apiParamsList) {
                        apiParams.put(kv.getKey(), kv.getValue());
                    }
                }
                requestInfoVO.setParams(apiParams);
                requestInfoVO.setUrl(apiPath);
                //TODO 暂时固定为post,后面再支持其他的功能
                requestInfoVO.setType("POST");
                requestInfoVO.setFillTarget("select[name=" + row.getKey() + "]");
                formHttpRequestInfoVOList.add(requestInfoVO);
            }
 
 
            for (FormRowData row : vo.getSearchFormRows()) {
                //layui更改验证
                String layVerify = "";
                if (row.getParams() != null && row.getParams().get("require") != null && (Boolean) row.getParams().get("require")) {
                    layVerify += "required|";
                }
                if (row.getParams() != null && row.getParams().get("verifyType") != null) {
                    FormVerifyType verifyType = (FormVerifyType) row.getParams().get("verifyType");
                    if (verifyType == FormVerifyType.regex) {
                        //自定义的验证名称为下划线+name
                        layVerify += "_" + row.getKey();
                    } else if (verifyType != FormVerifyType.none) {
                        layVerify += verifyType.name();
                    }
                }
                if (layVerify.endsWith("|"))
                    layVerify = layVerify.substring(0, layVerify.length() - 1);
                //重新赋值,表单中直接取值
                row.getParams().put("verifyValue", layVerify);
            }
 
            vo.setPreRequestList(formHttpRequestInfoVOList);
            return vo;
        }
 
    }
 
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
    public List<FormRowData> getSearchFormRows() {
        return searchFormRows;
    }
 
    public void setSearchFormRows(List<FormRowData> searchFormRows) {
        this.searchFormRows = searchFormRows;
    }
 
    public List<FormHttpRequestInfoVO> getPreRequestList() {
        return preRequestList;
    }
 
    public void setPreRequestList(List<FormHttpRequestInfoVO> preRequestList) {
        this.preRequestList = preRequestList;
    }
 
    public List<FormInputRegexVerifyVO> getRegexVerifyList() {
        return regexVerifyList;
    }
 
    public void setRegexVerifyList(List<FormInputRegexVerifyVO> regexVerifyList) {
        this.regexVerifyList = regexVerifyList;
    }
 
    public String getListApi() {
        return listApi;
    }
 
    public void setListApi(String listApi) {
        this.listApi = listApi;
    }
 
    public String getAddPagePath() {
        return addPagePath;
    }
 
    public void setAddPagePath(String addPagePath) {
        this.addPagePath = addPagePath;
    }
 
    public String getUpdatePagePath() {
        return updatePagePath;
    }
 
    public void setUpdatePagePath(String updatePagePath) {
        this.updatePagePath = updatePagePath;
    }
 
    public List<Map<String, Object>> getShowFileds() {
        return showFileds;
    }
 
    public void setShowFileds(List<Map<String, Object>> showFileds) {
        this.showFileds = showFileds;
    }
}