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;
|
}
|
}
|