| | |
| | | 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.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author Administrator |
| | |
| | | //entity类 |
| | | private Class entity; |
| | | //controller注解对象 |
| | | private AdminController controllerData; |
| | | private AdminControllerData controllerData; |
| | | //修改的表单行数据 |
| | | private List<FormRowData> updateFormRows; |
| | | //添加的表单行数据 |
| | |
| | | |
| | | 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; |
| | |
| | | this.entity = entity; |
| | | } |
| | | |
| | | public AdminController getControllerData() { |
| | | public AdminControllerData getControllerData() { |
| | | return controllerData; |
| | | } |
| | | |
| | | public void setControllerData(AdminController controllerData) { |
| | | public void setControllerData(AdminControllerData controllerData) { |
| | | this.controllerData = controllerData; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | if (entity == null) { |
| | | throw new Exception("尚未设置entity"); |
| | | } |
| | | //查询是否需要生成管理界面与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); |
| | | info.setControllerData((AdminController) an); |
| | | info.setSearchFormRows(AnotationUtil.getFormRowData(searchFormClass)); |
| | | info.setAddFormRows(AnotationUtil.getFormRowData(entity)); |
| | | info.setUpdateFormRows(AnotationUtil.getUpdateFormRowData(entity)); |
| | | info.setShowDataList(AnotationUtil.getShowDataList(entity)); |
| | | return info; |
| | | |
| | | 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()); |
| | | 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()); |
| | | 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; |
| | | } |
| | | |
| | | } |
| | | |
| | | |