diff --git a/opsli-api/src/main/java/org/opsli/api/ApiFlag.java b/opsli-api/src/main/java/org/opsli/api/ApiFlag.java new file mode 100644 index 00000000..c025f123 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/ApiFlag.java @@ -0,0 +1,10 @@ +package org.opsli.api; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api + * @Author: Parker + * @CreateTime: 2020-11-21 15:15 + * @Description: 标示文件 请勿删除 + */ +public interface ApiFlag { } diff --git a/opsli-api/src/main/java/org/opsli/api/web/gentest/user/TestUserRestApi.java b/opsli-api/src/main/java/org/opsli/api/web/gentest/user/TestUserRestApi.java new file mode 100755 index 00000000..95615991 --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/web/gentest/user/TestUserRestApi.java @@ -0,0 +1,128 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.web.gentest.user; + +import org.opsli.api.base.result.ResultVo; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opsli.api.wrapper.gentest.user.TestUserModel; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.web.gentest.user + * @Author: 周鹏程 + * @CreateTime: 2020-11-22 12:12:05 + * @Description: 某系统用户 + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface TestUserRestApi { + + /** 标题 */ + String TITLE = "用户"; + + /** + * 某系统用户 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo get(TestUserModel model); + + /** + * 某系统用户 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * 某系统用户 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody TestUserModel model); + + /** + * 某系统用户 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody TestUserModel model); + + /** + * 某系统用户 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * 某系统用户 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * 某系统用户 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @GetMapping("/exportExcel") + ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * 某系统用户 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @GetMapping("/exportImport") + ResultVo excelImport(MultipartHttpServletRequest request); + + /** + * 某系统用户 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @GetMapping("/exportImport/template") + ResultVo importTemplate(HttpServletResponse response); + +} diff --git a/opsli-api/src/main/java/org/opsli/api/wrapper/gentest/user/TestUserModel.java b/opsli-api/src/main/java/org/opsli/api/wrapper/gentest/user/TestUserModel.java new file mode 100755 index 00000000..55be235e --- /dev/null +++ b/opsli-api/src/main/java/org/opsli/api/wrapper/gentest/user/TestUserModel.java @@ -0,0 +1,91 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.api.wrapper.gentest.user; + +import java.util.Date; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.api.wrapper.gentest.user + * @Author: 周鹏程 + * @CreateTime: 2020-11-22 12:12:05 + * @Description: 某系统用户 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class TestUserModel extends ApiWrapper { + + /** 名称 */ + @ApiModelProperty(value = "名称") + @ExcelProperty(value = "名称", order = 1) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL_WITH_CHINESE}) + @ValidationArgsLenMax(50) + private String name; + + /** 金钱 */ + @ApiModelProperty(value = "金钱") + @ExcelProperty(value = "金钱", order = 2) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_MONEY}) + @ValidationArgsLenMax(8) + private Double money; + + /** 年龄 */ + @ApiModelProperty(value = "年龄") + @ExcelProperty(value = "年龄", order = 3) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, ValiArgsType.IS_NUMBER}) + @ValidationArgsLenMax(5) + private Integer age; + + /** 生日 */ + @ApiModelProperty(value = "生日") + @ExcelProperty(value = "生日", order = 4) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, }) + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date birth; + + /** 是否启用 */ + @ApiModelProperty(value = "是否启用") + @ExcelProperty(value = "是否启用", order = 5) + @ExcelInfo( dictType = "no_yes" ) + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL, }) + @ValidationArgsLenMax(1) + private Character izUsable; + + + +} diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java index fc70e444..64fc1afd 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/HumpUtil.java @@ -76,6 +76,17 @@ public final class HumpUtil { return sb.toString().toLowerCase(); } + /** + * 首字母大写 + * @param str + * @return + */ + public static String captureName(String str) { + char[] cs = str.toCharArray(); + cs[0] -= 32; + return String.valueOf(cs); + } + public static void main(String[] args) { String aa = HumpUtil.humpToUnderline("tenantId"); String bb = HumpUtil.underlineToHump(aa); diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java index 946e071e..4111da47 100644 --- a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/Props.java @@ -16,10 +16,13 @@ package org.opsli.common.utils; import cn.hutool.core.convert.Convert; +import cn.hutool.core.io.IoUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ClassPathResource; import org.yaml.snakeyaml.Yaml; import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -94,7 +97,8 @@ public class Props { return; } - try (InputStream inputStream = Props.class.getResourceAsStream("/" + this.fileName)) { + ClassPathResource resource = new ClassPathResource("/" + this.fileName); + try (InputStream inputStream = resource.getInputStream()) { Yaml yaml = new Yaml(); temp = yaml.load(inputStream); diff --git a/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/ZipUtils.java b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/ZipUtils.java new file mode 100644 index 00000000..1aa7e847 --- /dev/null +++ b/opsli-base-support/opsli-common/src/main/java/org/opsli/common/utils/ZipUtils.java @@ -0,0 +1,91 @@ +package org.opsli.common.utils; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +/** + * @author Parker + * @date 2020-01-07 + *

+ * 文件流转压缩包工具类 + */ +public class ZipUtils { + /** + * 缓存区大小 + */ + private static final int BUFFER_SIZE = 2 * 1024; + + public static final String FILE_PATH = "path"; + public static final String FILE_NAME = "name"; + public static final String FILE_DATA = "data"; + + + + /** + * 压缩核心方法 + */ + private static void compress(ZipOutputStream zos, String path, String name, String data) throws Exception { + byte[] buf = new byte[BUFFER_SIZE]; + zos.putNextEntry(new ZipEntry(path + name)); + int len; + ByteArrayInputStream in = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); + while ((len = in.read(buf)) != -1) { + zos.write(buf, 0, len); + } + zos.closeEntry(); + in.close(); + } + + + /** + * 文本直接转zip压缩成文件 + * + * @param list -> map -> path 路径; name 文件名; data 具体文本内容; + * @param out 传入输出流 + * @throws RuntimeException 抛出异常 + */ + public static void toZip(List> list, OutputStream out) throws RuntimeException { + ZipOutputStream zos = null; + try { + zos = new ZipOutputStream(out, StandardCharsets.UTF_8); + for (Map map : list) { + String path = map.get("path"); + String name = map.get("name"); + String data = map.get("data"); + compress(zos, path, name, data); + } + } catch (Exception e) { + throw new RuntimeException("zip error from ZipUtils", e); + } finally { + if (zos != null) { + try { + zos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + public static void main(String[] args) throws Exception { + List> list = new ArrayList<>(); + OutputStream outputStream = new FileOutputStream(new File("/Users/system/Documents/脚本/opsli/test.zip")); + Map m1 = new HashMap(){{put("path","/f1/f2/f3/");put("name","1.txt");put("data","abcdefg");}}; + Map m2 = new HashMap(){{put("path","/f1/f2/f3/f4/");put("name","2.txt");put("data","abcdefg");}}; + Map m3 = new HashMap(){{put("path","");put("name","3.txt");put("data","abcdefg");}}; + + list.add(m1); + list.add(m2); + list.add(m3); + toZip(list, outputStream); + if (outputStream != null) { + outputStream.close(); + } + } +} diff --git a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java index b6fe777a..7e68c33a 100644 --- a/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java +++ b/opsli-base-support/opsli-core/src/main/java/org/opsli/core/waf/util/SQLFilterKit.java @@ -77,8 +77,10 @@ public final class SQLFilterKit { //转换成小写 //str = str.toLowerCase(); - //非法字符 - String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"}; + // 非法字符 + //String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"}; + // 非法字符(为了代码生成器 放开 delete update 扫描) + String[] keywords = {"master", "truncate", "insert", "select", "declare", "alter", "drop"}; // 替换非法字符 for (String keyword : keywords) { diff --git a/opsli-modulars/opsli-modulars-creater/pom.xml b/opsli-modulars/opsli-modulars-creater/pom.xml index 6dcb2c60..b83fd21b 100644 --- a/opsli-modulars/opsli-modulars-creater/pom.xml +++ b/opsli-modulars/opsli-modulars-creater/pom.xml @@ -11,5 +11,12 @@ opsli-modulars-creater + + + com.jfinal + enjoy + 4.9.03 + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java index 4842b59c..06483789 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/msg/CreaterMsg.java @@ -48,6 +48,14 @@ public enum CreaterMsg implements BaseMsg { EXCEPTION_IMPORT_NULL(50120,"未选中表,无法导入"), EXCEPTION_IMPORT_TABLE_NULL(50121,"暂无{}该表"), + /** + * 生成 + */ + EXCEPTION_CREATE_NULL(50140,"生成失败,数据为空"), + EXCEPTION_CREATE_TABLE_NULL(50140,"生成失败,暂无表数据"), + EXCEPTION_CREATE_FIELD_NULL(50121,"生成失败,暂无表字段"), + + ; private int code; diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/CodeBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/CodeBuilder.java new file mode 100644 index 00000000..57ad2873 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/CodeBuilder.java @@ -0,0 +1,159 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.strategy.create; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.IoUtil; +import com.jfinal.kit.Kv; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.opsli.api.ApiFlag; +import org.opsli.common.enums.DictType; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.common.utils.HumpUtil; +import org.opsli.common.utils.Props; +import org.opsli.common.utils.ZipUtils; +import org.opsli.core.creater.strategy.create.backend.JavaCodeBuilder; +import org.opsli.core.creater.strategy.create.foreend.VueCodeBuilder; +import org.opsli.core.creater.strategy.create.readme.ReadMeBuilder; +import org.opsli.core.creater.utils.EnjoyUtil; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterBuilderModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; + +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.creater.strategy.create.backend + * @Author: Parker + * @CreateTime: 2020-11-20 17:30 + * @Description: Java代码构建器 + */ +public enum CodeBuilder { + + INSTANCE; + + /** 排除字段 */ + private static final List EXCLUDE_FIELDS; + + public static final String API_PATH; + public static final String FILE_NAME = "OPSLI-CodeCreate"; + public static final String BASE_PATH = "/代码生成-"; + public static final String BACKEND_PATH = "/后端"; + public static final String FOREEND_PATH = "/前端"; + + + static { + Props props = new Props("creater.yaml"); + EXCLUDE_FIELDS = props.getList("opsli.exclude-fields"); + API_PATH = ApiFlag.class.getPackage().getName(); + } + + /** + * 构建 + */ + public void build(CreaterBuilderModel builderModel, HttpServletResponse response){ + if(builderModel == null) return; + + String dataStr = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"); + + CreaterTableAndColumnModel model = builderModel.getModel(); + + + // 数据库表名转驼峰 + model.setTableName( + HumpUtil.captureName( + HumpUtil.underlineToHump( + model.getTableName() + ) + ) + ); + + List columnList = model.getColumnList(); + //遍历排除字段 + columnList.removeIf(tmp -> EXCLUDE_FIELDS.contains(tmp.getFieldName())); + + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + OutputStream out = this.getOutputStream(response, dataStr); + try { + if(out != null){ + List> fileList = new ArrayList<>(); + // 处理后端代码 ==================== + // entity + fileList.add(JavaCodeBuilder.INSTANCE.createEntity(builderModel, dataStr)); + // mapper + fileList.add(JavaCodeBuilder.INSTANCE.createMapper(builderModel, dataStr)); + // mapper xml + fileList.add(JavaCodeBuilder.INSTANCE.createMapperXML(builderModel, dataStr)); + // service + fileList.add(JavaCodeBuilder.INSTANCE.createService(builderModel, dataStr)); + // service impl + fileList.add(JavaCodeBuilder.INSTANCE.createServiceImpl(builderModel, dataStr)); + // web + fileList.add(JavaCodeBuilder.INSTANCE.createWeb(builderModel, dataStr)); + // model + fileList.add(JavaCodeBuilder.INSTANCE.createModel(builderModel, dataStr)); + // api + fileList.add(JavaCodeBuilder.INSTANCE.createRestApi(builderModel, dataStr)); + + // 处理前端代码 ==================== + // index + fileList.add(VueCodeBuilder.INSTANCE.createIndex(builderModel, dataStr)); + // edit + fileList.add(VueCodeBuilder.INSTANCE.createEdit(builderModel, dataStr)); + // 前api + fileList.add(VueCodeBuilder.INSTANCE.createApi(builderModel, dataStr)); + + // 处理 ReadMe + fileList.add(ReadMeBuilder.INSTANCE.createReadMe(builderModel, dataStr)); + + // 生成zip文件 + ZipUtils.toZip(fileList, baos); + + // 输出流文件 + IoUtil.write(out,true, baos.toByteArray()); + } + }catch (Exception ignored){} + } + + + /** + * 导出文件时为Writer生成OutputStream + */ + private OutputStream getOutputStream(HttpServletResponse response, String dataStr){ + //创建本地文件 + try { + String fileName = FILE_NAME +"-"+ dataStr+".zip"; + response.addHeader("Content-Disposition", "attachment;filename=" + fileName); + return response.getOutputStream(); + } catch (IOException ignored) {} + return null; + } + + public static void main(String[] args) { + System.out.println(ValiArgsType.IS_NOT_NULL.toString()); + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/backend/JavaCodeBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/backend/JavaCodeBuilder.java new file mode 100644 index 00000000..d04976fc --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/backend/JavaCodeBuilder.java @@ -0,0 +1,379 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.strategy.create.backend; + +import cn.hutool.core.date.DateUtil; +import com.jfinal.kit.Kv; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.enums.DictType; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.common.utils.HumpUtil; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.common.utils.ZipUtils; +import org.opsli.core.creater.strategy.create.CodeBuilder; +import org.opsli.core.creater.utils.EnjoyUtil; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterBuilderModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.creater.strategy.create.backend + * @Author: Parker + * @CreateTime: 2020-11-20 17:30 + * @Description: Java代码构建器 + */ +public enum JavaCodeBuilder { + + INSTANCE; + + /** + * 生成Entity + * @param builderModelTmp + * @return + */ + public Map createEntity(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + List columnList = builderModel.getModel().getColumnList(); + // 处理数据 + for (CreaterTableColumnModel columnModel : columnList) { + // 数据库字段名转驼峰 + columnModel.setFieldName( + HumpUtil.underlineToHump( + columnModel.getFieldName() + ) + ); + } + + String codeStr = EnjoyUtil.render("/backend/entity/TemplateEntity.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("entity").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("entity").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+".java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 生成Mapper + * @param builderModelTmp + * @return + */ + public Map createMapper(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/mapper/TemplateMapper.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("mapper").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("mapper").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"Mapper.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 生成MapperXML + * @param builderModelTmp + * @return + */ + public Map createMapperXML(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/mapper/xml/TemplateMapperXML.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("mapper") + .append("/").append("xml").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("mapper") + .append("/").append("xml").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"Mapper.xml"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 生成Service + * @param builderModelTmp + * @return + */ + public Map createService(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/service/TemplateService.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("service").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("service").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + "I"+builderModel.getModel().getTableName()+"Service.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + + /** + * 生成 Service Impl + * @param builderModelTmp + * @return + */ + public Map createServiceImpl(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/service/impl/TemplateServiceImpl.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("service") + .append("/").append("impl").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("service") + .append("/").append("impl").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"ServiceImpl.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 生成 Web + * @param builderModelTmp + * @return + */ + public Map createWeb(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/web/TemplateRestController.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append("web").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(builderModel.getPackageName().replaceAll("\\.","/")) + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("web").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"RestController.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + + /** + * 生成Model + * @param builderModelTmp + * @return + */ + public Map createModel(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + // 处理数据 + List columnList = builderModel.getModel().getColumnList(); + for (CreaterTableColumnModel columnModel : columnList) { + // 数据库字段名转驼峰 + columnModel.setFieldName( + HumpUtil.underlineToHump( + columnModel.getFieldName() + ) + ); + + // 处理验证器 + String validateType = columnModel.getValidateType(); + if(StringUtils.isNotBlank(validateType)){ + String[] validateTypes = validateType.split(","); + StringBuilder stb = new StringBuilder(); + boolean izNotNull = false; + // 如果非空 则开启非空验证 + if(DictType.NO_YES_YES.getCode().equals(columnModel.getIzNotNull())){ + izNotNull = true; + stb.append("ValiArgsType.").append(ValiArgsType.IS_NOT_NULL); + } + + for (int i = 0; i < validateTypes.length; i++) { + String type = validateTypes[i]; + if(izNotNull){ + stb.append(", "); + izNotNull = false; + } + if(!ValiArgsType.IS_NOT_NULL.equals(ValiArgsType.valueOf(type))){ + stb.append("ValiArgsType.").append(type); + } + if(i < validateTypes.length -1 ){ + stb.append(", "); + } + } + columnModel.setValidateType(stb.toString()); + } + } + + String codeStr = EnjoyUtil.render("/backend/model/TemplateModel.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(CodeBuilder.API_PATH.replaceAll("\\.","/")) + .append("/").append("wrapper") + .append("/").append(builderModel.getModuleName()).append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(CodeBuilder.API_PATH.replaceAll("\\.","/")) + .append("/").append("wrapper") + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()).append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"Model.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + + /** + * 生成RestApi + * @param builderModelTmp + * @return + */ + public Map createRestApi(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + String codeStr = EnjoyUtil.render("/backend/api/TemplateRestApi.html", + this.createKv(builderModel) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(CodeBuilder.API_PATH.replaceAll("\\.","/")) + .append("/").append("web") + .append("/").append(builderModel.getModuleName()).append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.BACKEND_PATH) + .append("/").append(CodeBuilder.API_PATH.replaceAll("\\.","/")) + .append("/").append("web") + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()).append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, + builderModel.getModel().getTableName()+"RestApi.java"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 创建 Kv + * @param builderModel + * @return + */ + private Kv createKv(CreaterBuilderModel builderModel){ + return Kv.by("data", builderModel) + .set("currTime", DateUtil.now()) + .set("apiPath", CodeBuilder.API_PATH); + } + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/foreend/VueCodeBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/foreend/VueCodeBuilder.java new file mode 100644 index 00000000..701ee5f6 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/foreend/VueCodeBuilder.java @@ -0,0 +1,279 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.strategy.create.foreend; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateUtil; +import com.jfinal.kit.Kv; +import org.apache.commons.lang3.StringUtils; +import org.opsli.common.enums.DictType; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.common.utils.HumpUtil; +import org.opsli.common.utils.Props; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.common.utils.ZipUtils; +import org.opsli.core.creater.strategy.create.CodeBuilder; +import org.opsli.core.creater.utils.EnjoyUtil; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterBuilderModel; + +import java.util.*; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.creater.strategy.create.backend + * @Author: Parker + * @CreateTime: 2020-11-20 17:30 + * @Description: Vue代码构建器 + */ +public enum VueCodeBuilder { + + INSTANCE; + + /** 虚拟根路径 */ + private static final String BASE_API_PATH; + static { + Props props = new Props("application.yaml"); + BASE_API_PATH = props.getStr("server.servlet.api.path.global-prefix","/api/v1"); + } + + /** + * 生成 Index + * @param builderModelTmp + * @return + */ + public Map createIndex(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + List columnList = builderModel.getModel().getColumnList(); + // 处理数据 + for (CreaterTableColumnModel columnModel : columnList) { + // 数据库字段名转驼峰 + columnModel.setFieldName( + HumpUtil.underlineToHump( + columnModel.getFieldName() + ) + ); + } + + List queryList = new ArrayList<>(2); + // 简单检索 + List briefQueryList = new ArrayList<>(2); + // 更多检索 + List moreQueryList = new ArrayList<>(); + for (int i = 0; i < columnList.size(); i++) { + if(StringUtils.isNotBlank(columnList.get(i).getQueryType()) && + columnList.get(i).getIzShowList().equals(DictType.NO_YES_YES.getCode()) + ){ + queryList.add(columnList.get(i)); + } + } + // 筛选数据 + for (int i = 0; i < queryList.size(); i++) { + if(i < 2){ + briefQueryList.add(queryList.get(i)); + }else{ + moreQueryList.add(queryList.get(i)); + } + } + + + String codeStr = EnjoyUtil.render("/foreend/index/TemplateIndex.html", + this.createKv(builderModel) + .set("briefQueryList", briefQueryList) + .set("moreQueryList", moreQueryList) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue") + .append("/").append("views").append("/").append("modules") + .append("/").append(builderModel.getModuleName()).append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue") + .append("/").append("views").append("/").append("modules") + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()).append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, "index.vue"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + + /** + * 生成 Index + * @param builderModelTmp + * @return + */ + public Map createEdit(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + List columnList = builderModel.getModel().getColumnList(); + List> formList = new ArrayList<>(); + Map> valiDict = new HashMap<>(); + Set validataTypes = new HashSet<>(); + // 处理验证数据 + for (CreaterTableColumnModel columnModel : columnList) { + // 数据库字段名转驼峰 + columnModel.setFieldName( + HumpUtil.underlineToHump( + columnModel.getFieldName() + ) + ); + + // 处理验证器 + String validateType = columnModel.getValidateType(); + if(StringUtils.isNotBlank(validateType)){ + String[] validateTypes = validateType.split(","); + Set validateTypeSet = new HashSet<>(Arrays.asList(validateTypes)); + // 如果非空 则开启非空验证 + if(DictType.NO_YES_YES.getCode().equals(columnModel.getIzNotNull())){ + validateTypeSet.add(ValiArgsType.IS_NOT_NULL.toString()); + } + + List validateTypeList = new ArrayList<>(validateTypes.length); + for (String vali : validateTypeSet) { + validateTypeList.add( + HumpUtil.underlineToHump( + vali.toLowerCase() + ) + ); + } + + validataTypes.addAll(validateTypeList); + valiDict.put(columnModel.getFieldName(), validateTypeList); + } + } + + // 处理数据 + if(columnList.size() == 1){ + if(columnList.get(0).getIzShowForm().equals(DictType.NO_YES_YES.getCode()) && + StringUtils.isNotBlank(columnList.get(0).getShowType()) + ){ + List formTmpList = new ArrayList<>(); + formTmpList.add(columnList.get(0)); + formList.add(formTmpList); + } + }else{ + for (int i = 0; i < columnList.size(); i+=2) { + List formTmpList = new ArrayList<>(); + if(columnList.get(i).getIzShowForm().equals(DictType.NO_YES_YES.getCode()) && + StringUtils.isNotBlank(columnList.get(i).getShowType()) + ){ + formTmpList.add(columnList.get(i)); + if(i+1 < columnList.size()){ + formTmpList.add(columnList.get(i+1)); + } + formList.add(formTmpList); + } + } + } + + StringBuilder validataTypeStb = new StringBuilder(); + for (String validataType : validataTypes) { + validataTypeStb.append(validataType); + validataTypeStb.append(", "); + } + + String codeStr = EnjoyUtil.render("/foreend/components/TemplateEdit.html", + this.createKv(builderModel) + .set("formList", formList) + .set("valiDict", valiDict) + .set("validataTypes", validataTypeStb.toString()) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue") + .append("/").append("views").append("/").append("modules") + .append("/").append(builderModel.getModuleName()) + .append("/").append("components").append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue") + .append("/").append("views").append("/").append("modules") + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()) + .append("/").append("components").append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, builderModel.getModel().getTableName()+"ManagementEdit.vue"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 生成 Api + * @param builderModelTmp + * @return + */ + public Map createApi(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + List columnList = builderModel.getModel().getColumnList(); + // 处理数据 + for (CreaterTableColumnModel columnModel : columnList) { + // 数据库字段名转驼峰 + columnModel.setFieldName( + HumpUtil.underlineToHump( + columnModel.getFieldName() + ) + ); + } + + + String codeStr = EnjoyUtil.render("/foreend/api/TemplateApi.html", + this.createKv(builderModel) + .set("apiPath", BASE_API_PATH) + ); + + StringBuilder path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue").append("/").append("api") + .append("/").append(builderModel.getModuleName()).append("/"); + if(StringUtils.isNotBlank(builderModel.getSubModuleName())){ + path = new StringBuilder(); + path.append(CodeBuilder.BASE_PATH).append(dataStr).append(CodeBuilder.FOREEND_PATH) + .append("/").append("vue").append("/").append("api") + .append("/").append(builderModel.getModuleName()) + .append("/").append(builderModel.getSubModuleName()).append("/"); + } + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, path.toString()); + entityMap.put(ZipUtils.FILE_NAME, builderModel.getModel().getTableName()+"Management.js"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 创建 Kv + * @param builderModel + * @return + */ + private Kv createKv(CreaterBuilderModel builderModel){ + return Kv.by("data", builderModel) + .set("currTime", DateUtil.now()); + } + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/readme/ReadMeBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/readme/ReadMeBuilder.java new file mode 100644 index 00000000..84803e86 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/create/readme/ReadMeBuilder.java @@ -0,0 +1,75 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.core.creater.strategy.create.readme; + +import cn.hutool.core.date.DateUtil; +import com.jfinal.kit.Kv; +import org.opsli.common.utils.HumpUtil; +import org.opsli.common.utils.Props; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.common.utils.ZipUtils; +import org.opsli.core.creater.strategy.create.CodeBuilder; +import org.opsli.core.creater.utils.EnjoyUtil; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterBuilderModel; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.core.creater.strategy.create.backend + * @Author: Parker + * @CreateTime: 2020-11-20 17:30 + * @Description: ReadMe 构建器 + */ +public enum ReadMeBuilder { + + INSTANCE; + + /** + * 生成 ReadMe + * @param builderModelTmp + * @return + */ + public Map createReadMe(CreaterBuilderModel builderModelTmp, String dataStr){ + CreaterBuilderModel builderModel = + WrapperUtil.cloneTransformInstance(builderModelTmp, CreaterBuilderModel.class); + + String codeStr = EnjoyUtil.render("/readme/TemplateReadMe.html", + this.createKv(builderModel) + ); + + Map entityMap = new HashMap<>(); + entityMap.put(ZipUtils.FILE_PATH, CodeBuilder.BASE_PATH + dataStr + "/"); + entityMap.put(ZipUtils.FILE_NAME, "README.md"); + entityMap.put(ZipUtils.FILE_DATA, codeStr); + return entityMap; + } + + /** + * 创建 Kv + * @param builderModel + * @return + */ + private Kv createKv(CreaterBuilderModel builderModel){ + return Kv.by("data", builderModel) + .set("currTime", DateUtil.now()); + } + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java index 310e10f0..b1159836 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/MySQLSyncBuilder.java @@ -1,6 +1,22 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.creater.strategy.sync; import org.apache.commons.lang3.StringUtils; +import org.opsli.common.enums.DictType; import org.opsli.common.utils.Props; import org.opsli.core.creater.exception.CreaterException; import org.opsli.core.creater.msg.CreaterMsg; @@ -34,10 +50,6 @@ public class MySQLSyncBuilder implements SyncStrategy { /** 字符格式 */ private static final String CHARSET = "utf8mb4"; - /** 是 */ - private static final char YES = '1'; - /** 否 */ - private static final char NO = '0'; /** 排除表 */ private static final List EXCLUDE_TABLES; @@ -141,11 +153,11 @@ public class MySQLSyncBuilder implements SyncStrategy { } // 判断是否为主键 - if(YES == tmp.getIzPk()){ + if(DictType.NO_YES_YES.getCode().equals(tmp.getIzPk())){ str.append(" ").append("PRIMARY KEY"); }else{ // 判断是否非空 - if(YES == tmp.getIzNull()){ + if(DictType.NO_YES_YES.getCode().equals(tmp.getIzNotNull())){ str.append(" ").append("NOT NULL"); } } diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java index 26298ac6..271ad8c8 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/SyncStrategy.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.creater.strategy.sync; import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java index bc53bc61..d1665c19 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/entity/FieldTypeAttribute.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.creater.strategy.sync.mysql.entity; diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java index 52fd5622..c6edd7f7 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/strategy/sync/mysql/enums/MySQLSyncColumnType.java @@ -1,3 +1,18 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.opsli.core.creater.strategy.sync.mysql.enums; diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/utils/EnjoyUtil.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/utils/EnjoyUtil.java new file mode 100644 index 00000000..d9824195 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/core/creater/utils/EnjoyUtil.java @@ -0,0 +1,52 @@ +package org.opsli.core.creater.utils; + +import cn.hutool.core.io.IoUtil; +import com.jfinal.kit.Kv; +import com.jfinal.template.Engine; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ClassPathResource; + +import java.io.File; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +/*** + * jfinal魔板引擎 + * @author dufuzhong + */ +@Slf4j +public final class EnjoyUtil { + + private static final String BASE_PATH = "/tpl"; + + /** + * 根据具体魔板生成文件 + * @param templateFileName 模板文件名称 + * @param kv 渲染参数 + * @return + */ + public static String render(String templateFileName, Kv kv) { + + //ClassPathResource resource = new ClassPathResource(templateFileName); + // (InputStream inputStream = resource.getInputStream()) + String str = ""; + ClassPathResource resource = new ClassPathResource(BASE_PATH + templateFileName); + try (InputStream inputStream = resource.getInputStream()){ + String readTpl = IoUtil.read(inputStream, StandardCharsets.UTF_8); + + str = Engine.use() + // 开启预热模式 + .setDevMode(true) + .getTemplateByString(readTpl) + .renderToString(kv); + + } catch (Exception e) { + log.error("load config file {} error", templateFileName, e); + } + return str; + } + + + + private EnjoyUtil(){} +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java index 3e9e4ebe..61a9c971 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/entity/CreaterTableColumn.java @@ -49,22 +49,22 @@ public class CreaterTableColumn extends BaseEntity { private String fieldComments; /** 是否主键 */ - private Character izPk; + private String izPk; /** 是否可为空 */ - private Character izNull; + private String izNotNull; /** 是否列表字段 */ - private Character izShowList; + private String izShowList; /** 是否表单显示 */ - private Character izShowForm; + private String izShowForm; /** Java字段类型 */ private String javaType; /** 字段生成方案(文本框、文本域、字典选择) */ - private Character showType; + private String showType; /** 字典类型编号 */ private String dictTypeCode; @@ -75,6 +75,9 @@ public class CreaterTableColumn extends BaseEntity { /** 验证类别 */ private String validateType; + /** 检索类别 */ + private String queryType; + // ======================================== diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java index 6e57d12e..1e521ce7 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/column/wrapper/CreaterTableColumnModel.java @@ -15,7 +15,6 @@ */ package org.opsli.modulars.creater.column.wrapper; -import com.alibaba.excel.annotation.ExcelIgnore; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -90,7 +89,7 @@ public class CreaterTableColumnModel extends ApiWrapper { @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgsLenMax(1) - private Character izPk; + private String izPk; /** 是否可为空 */ @ApiModelProperty(value = "是否可为空") @@ -98,7 +97,7 @@ public class CreaterTableColumnModel extends ApiWrapper { @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgsLenMax(1) - private Character izNull; + private String izNotNull; /** 是否列表显示 */ @ApiModelProperty(value = "是否列表显示") @@ -106,7 +105,7 @@ public class CreaterTableColumnModel extends ApiWrapper { @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgsLenMax(1) - private Character izShowList; + private String izShowList; /** 是否表单显示 */ @ApiModelProperty(value = "是否表单显示") @@ -114,7 +113,7 @@ public class CreaterTableColumnModel extends ApiWrapper { @ExcelInfo(dictType = "no_yes") // 验证器 @ValidationArgsLenMax(1) - private Character izShowForm; + private String izShowForm; /** Java字段类型 */ @ApiModelProperty(value = "Java字段类型") @@ -131,7 +130,7 @@ public class CreaterTableColumnModel extends ApiWrapper { @ExcelInfo(dictType = "show_type") // 验证器 @ValidationArgsLenMax(1) - private Character showType; + private String showType; /** 字典类型编号 */ @ApiModelProperty(value = "字典类型编号") @@ -160,4 +159,13 @@ public class CreaterTableColumnModel extends ApiWrapper { @ValidationArgsLenMax(500) private String validateType; + /** 检索类别 */ + @ApiModelProperty(value = "检索类别") + @ExcelProperty(value = "检索类别", order = 16) + @ExcelInfo + // 验证器 + @ValidationArgs({ValiArgsType.IS_GENERAL}) + @ValidationArgsLenMax(100) + private String queryType; + } diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/api/CreaterLogsApi.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/api/CreaterLogsApi.java new file mode 100644 index 00000000..fa82749e --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/api/CreaterLogsApi.java @@ -0,0 +1,65 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.api; + +import org.opsli.api.base.result.ResultVo; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterLogsModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.test.web + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 代码生成器 - 生成记录 API + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface CreaterLogsApi { + + /** 标题 */ + String TITLE = "代码生成器 - 生成记录"; + + /** + * 生成记录 查一条 + * @param tableId 模型 + * @return ResultVo + */ + @GetMapping("/getByTableId") + ResultVo getByTableId(String tableId); + + /** + * 生成记录 修改 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/create") + void create(CreaterLogsModel model, HttpServletResponse response); + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/entity/CreaterLogs.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/entity/CreaterLogs.java new file mode 100644 index 00000000..c4fe08b2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/entity/CreaterLogs.java @@ -0,0 +1,57 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.entity; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-11-15 17:33 + * @Description: 代码生成器 - 生成日志 (便于二次生成时查看) + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterLogs extends BaseEntity { + + /** 归属表ID */ + private String tableId; + + + /** 包名 */ + private String packageName; + + /** 模块名 */ + private String moduleName; + + /** 子模块名 */ + private String subModuleName; + + /** 代码标题 */ + private String codeTitle; + + /** 代码标题简介 */ + private String codeTitleBrief; + + /** 作者名 */ + private String authorName; + + + // ======================================== + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/CreaterLogsMapper.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/CreaterLogsMapper.java new file mode 100644 index 00000000..e49a65d1 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/CreaterLogsMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.opsli.modulars.creater.createrlogs.entity.CreaterLogs; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:01 + * @Description: 代码生成器 - 生成日志 Mapper + */ +@Mapper +public interface CreaterLogsMapper extends BaseMapper { + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/xml/CreaterLogsMapper.xml b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/xml/CreaterLogsMapper.xml new file mode 100644 index 00000000..d0425f58 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/mapper/xml/CreaterLogsMapper.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/ICreateLogsService.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/ICreateLogsService.java new file mode 100644 index 00000000..32404e0c --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/ICreateLogsService.java @@ -0,0 +1,57 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.service; + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import org.opsli.modulars.creater.createrlogs.entity.CreaterLogs; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterLogsModel; + +import javax.servlet.http.HttpServletResponse; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-17 13:07 + * @Description: 代码生成器 - 表 接口 + */ +public interface ICreateLogsService extends CrudServiceInterface { + + /** + * 根据表Id 删除 + * @param tableId + */ + void delByTableId(String tableId); + + /** + * 根据表Id 批量删除 + * @param tableIds + */ + void delByTableIds(String[] tableIds); + + /** + * 根据表Id 查询 + * @param tableId + */ + CreaterLogsModel getByTableId(String tableId); + + /** + * 代码生成 + * @param model + */ + void create(CreaterLogsModel model, HttpServletResponse response); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/impl/CreateLogsServiceImpl.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/impl/CreateLogsServiceImpl.java new file mode 100644 index 00000000..0f6caed4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/service/impl/CreateLogsServiceImpl.java @@ -0,0 +1,139 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.core.base.service.impl.CrudServiceImpl; +import org.opsli.core.creater.exception.CreaterException; +import org.opsli.core.creater.msg.CreaterMsg; +import org.opsli.core.creater.strategy.create.CodeBuilder; +import org.opsli.core.persistence.querybuilder.GenQueryBuilder; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.modulars.creater.column.service.ITableColumnService; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.entity.CreaterLogs; +import org.opsli.modulars.creater.createrlogs.mapper.CreaterLogsMapper; +import org.opsli.modulars.creater.createrlogs.service.ICreateLogsService; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterBuilderModel; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterLogsModel; +import org.opsli.modulars.creater.table.service.ITableService; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-16 17:34 + * @Description: 代码生成器 - 表 接口实现类 + */ +@Service +public class CreateLogsServiceImpl extends CrudServiceImpl + implements ICreateLogsService { + + @Autowired(required = false) + private CreaterLogsMapper mapper; + @Autowired + private ITableService iTableService; + @Autowired + private ITableColumnService iTableColumnService; + + @Override + @Transactional(rollbackFor = Exception.class) + public void delByTableId(String tableId) { + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("table_id", tableId); + super.remove(wrapper); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delByTableIds(String[] tableIds) { + if(tableIds != null){ + for (String tableId : tableIds) { + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("table_id", tableId); + super.remove(wrapper); + } + } + } + + @Override + public CreaterLogsModel getByTableId(String tableId) { + QueryBuilder queryBuilder = + new GenQueryBuilder<>(); + QueryWrapper wrapper = queryBuilder.build(); + wrapper.eq("table_id", tableId); + return super.transformT2M( + this.getOne(wrapper) + ); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(CreaterLogsModel model, HttpServletResponse response) { + if(model == null){ + // 生成失败,数据为空 + throw new CreaterException(CreaterMsg.EXCEPTION_CREATE_NULL); + } + model.setVersion(null); + CreaterLogsModel saveModel = this.save(model); + if(saveModel != null){ + CreaterTableModel createrTableModel = iTableService.get(saveModel.getTableId()); + if(createrTableModel == null){ + // 生成失败,暂无表数据 + throw new CreaterException(CreaterMsg.EXCEPTION_CREATE_TABLE_NULL); + } + + CreaterTableAndColumnModel currTableModel = WrapperUtil.transformInstance( + createrTableModel, CreaterTableAndColumnModel.class + ); + List columnModelList = iTableColumnService. + getByTableId(currTableModel.getId()); + if(columnModelList == null || columnModelList.isEmpty()){ + // 生成失败,暂无表字段 + throw new CreaterException(CreaterMsg.EXCEPTION_CREATE_FIELD_NULL); + } + + + // 赋值表字段 + currTableModel.setColumnList(columnModelList); + + // 生成代码 + CreaterBuilderModel builderModel = WrapperUtil.transformInstance( + saveModel, CreaterBuilderModel.class + ); + builderModel.setModel(currTableModel); + + // 生成代码 + CodeBuilder.INSTANCE.build(builderModel, response); + + } + } +} + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/web/CreaterLogsRestController.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/web/CreaterLogsRestController.java new file mode 100644 index 00000000..fecad0c6 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/web/CreaterLogsRestController.java @@ -0,0 +1,90 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.web; + +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.common.exception.ServiceException; +import org.opsli.common.utils.WrapperUtil; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.creater.exception.CreaterException; +import org.opsli.core.creater.msg.CreaterMsg; +import org.opsli.core.creater.strategy.sync.util.SQLSyncUtil; +import org.opsli.core.msg.CoreMsg; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.opsli.modulars.creater.column.service.ITableColumnService; +import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.api.CreaterLogsApi; +import org.opsli.modulars.creater.createrlogs.entity.CreaterLogs; +import org.opsli.modulars.creater.createrlogs.service.ICreateLogsService; +import org.opsli.modulars.creater.createrlogs.wrapper.CreaterLogsModel; +import org.opsli.modulars.creater.importable.ImportTableUtil; +import org.opsli.modulars.creater.table.api.TableApi; +import org.opsli.modulars.creater.table.entity.CreaterTable; +import org.opsli.modulars.creater.table.service.ITableService; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; +import org.opsli.modulars.creater.table.wrapper.CreaterTableModel; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + + +/** + * @BelongsProject: opsli-boot + * @Author: Parker + * @CreateTime: 2020-09-13 17:40 + * @Description: 代码生成器 - 表 + */ +@Slf4j +@ApiRestController("/creater/logs") +public class CreaterLogsRestController extends BaseRestController + implements CreaterLogsApi { + + @ApiOperation(value = "获得当前表生成记录", notes = "获得当前表生成记录") + @RequiresPermissions("deve_creater_select") + @Override + public ResultVo getByTableId(String tableId) { + CreaterLogsModel byTableId = IService.getByTableId(tableId); + return ResultVo.success(byTableId); + } + + /** + * 代码生成 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "代码生成", notes = "代码生成") + @RequiresPermissions("deve_creater_create") + @EnableLog + @Override + public void create(CreaterLogsModel model, HttpServletResponse response) { + // 演示模式 不允许操作 + // super.demoError(); + + // 调用生成方法 + IService.create(model, response); + + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterBuilderModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterBuilderModel.java new file mode 100644 index 00000000..260a22ab --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterBuilderModel.java @@ -0,0 +1,64 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.wrapper; + +import com.alibaba.excel.annotation.ExcelIgnore; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.modulars.creater.table.wrapper.CreaterTableAndColumnModel; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.creater.createrlogs.wrapper + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 代码生成器 - 生成日志+代码模型 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterBuilderModel extends ApiWrapper { + + + /** 归属表ID */ + private String tableId; + + /** 包名 */ + private String packageName; + + /** 模块名 */ + private String moduleName; + + /** 子模块名 */ + private String subModuleName; + + /** 代码标题 */ + private String codeTitle; + + /** 代码标题简介 */ + private String codeTitleBrief; + + /** 作者名 */ + private String authorName; + + /** 代码模型 */ + private CreaterTableAndColumnModel model; + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterLogsModel.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterLogsModel.java new file mode 100644 index 00000000..1842a4ba --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/createrlogs/wrapper/CreaterLogsModel.java @@ -0,0 +1,96 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.creater.createrlogs.wrapper; + +import com.alibaba.excel.annotation.ExcelIgnore; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.api.base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.creater.createrlogs.wrapper + * @Author: Parker + * @CreateTime: 2020-09-16 17:33 + * @Description: 代码生成器 - 生成日志 (便于二次生成时查看) + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class CreaterLogsModel extends ApiWrapper { + + + /** 归属表ID */ + @ApiModelProperty(value = "归属表ID") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(19) + private String tableId; + + + /** 包名 */ + @ApiModelProperty(value = "包名") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(255) + private String packageName; + + /** 模块名 */ + @ApiModelProperty(value = "模块名") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(40) + private String moduleName; + + /** 子模块名 */ + @ApiModelProperty(value = "子模块名") + @ExcelIgnore + // 验证器 + @ValidationArgsLenMax(40) + private String subModuleName; + + + /** 代码标题 */ + @ApiModelProperty(value = "代码标题") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(100) + private String codeTitle; + + /** 代码标题简介 */ + @ApiModelProperty(value = "代码标题简介") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(100) + private String codeTitleBrief; + + /** 作者名 */ + @ApiModelProperty(value = "作者名") + @ExcelIgnore + // 验证器 + @ValidationArgs({ValiArgsType.IS_NOT_NULL}) + @ValidationArgsLenMax(64) + private String authorName; + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/entity/DatabaseColumn.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/entity/DatabaseColumn.java index 3b5bfff6..0d6f5a37 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/entity/DatabaseColumn.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/entity/DatabaseColumn.java @@ -54,10 +54,10 @@ public class DatabaseColumn { private String columnComment; /** 是否主键 */ - private Character izPk; + private String izPk; /** 是否可为空 */ - private Character izNull; + private String izNotNull; // ======================================== diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/mapper/xml/MySQLDatabaseTableMapper.xml b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/mapper/xml/MySQLDatabaseTableMapper.xml index 46690ffc..31c13bcf 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/mapper/xml/MySQLDatabaseTableMapper.xml +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/importable/mapper/xml/MySQLDatabaseTableMapper.xml @@ -27,7 +27,7 @@ NUMERIC_PRECISION AS columnPrecision, NUMERIC_SCALE AS columnScale, COLUMN_COMMENT AS columnComment, - IF( IS_NULLABLE = 'NO', '1', '0' ) AS izNull, + IF( IS_NULLABLE = 'NO', '1', '0' ) AS izNotNull, IF( COLUMN_KEY = 'PRI', '1', '0' ) AS izPk FROM INFORMATION_SCHEMA.COLUMNS diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java index 227c6f7f..c54ac459 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/api/TableApi.java @@ -49,7 +49,7 @@ public interface TableApi { String TITLE = "代码生成器 - 表"; /** - * 租户 查一条 + * 表 查一条 * @param model 模型 * @return ResultVo */ @@ -57,7 +57,7 @@ public interface TableApi { ResultVo get(CreaterTableModel model); /** - * 租户 查询分页 + * 表 查询分页 * @param pageNo 当前页 * @param pageSize 每页条数 * @param request request @@ -71,7 +71,7 @@ public interface TableApi { ); /** - * 租户 新增 + * 表 新增 * @param model 模型 * @return ResultVo */ @@ -79,7 +79,7 @@ public interface TableApi { ResultVo insert(@RequestBody CreaterTableAndColumnModel model); /** - * 租户 修改 + * 表 修改 * @param model 模型 * @return ResultVo */ @@ -87,7 +87,7 @@ public interface TableApi { ResultVo update(@RequestBody CreaterTableAndColumnModel model); /** - * 租户 删除 + * 表 删除 * @param id ID * @return ResultVo */ @@ -95,7 +95,7 @@ public interface TableApi { ResultVo del(String id); /** - * 租户 批量删除 + * 表 批量删除 * @param ids ID 数组 * @return ResultVo */ diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java index feb02ab8..065a5894 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/entity/CreaterTable.java @@ -40,7 +40,7 @@ public class CreaterTable extends BaseEntity { private String oldTableName; /** 表类型 */ - private Character tableType; + private String tableType; /** 数据库类型 */ private String jdbcType; @@ -50,7 +50,7 @@ public class CreaterTable extends BaseEntity { private String comments; /** 同步 */ - private Character izSync; + private String izSync; /** 备注 */ @TableField(updateStrategy = FieldStrategy.IGNORED) diff --git a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java index 8feb1ae6..06447c53 100644 --- a/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java +++ b/opsli-modulars/opsli-modulars-creater/src/main/java/org/opsli/modulars/creater/table/service/impl/TableServiceImpl.java @@ -17,13 +17,13 @@ package org.opsli.modulars.creater.table.service.impl; import cn.hutool.core.util.StrUtil; import org.opsli.common.enums.DictType; -import org.opsli.common.exception.ServiceException; import org.opsli.common.utils.WrapperUtil; import org.opsli.core.base.service.impl.CrudServiceImpl; import org.opsli.core.creater.exception.CreaterException; import org.opsli.core.creater.msg.CreaterMsg; import org.opsli.modulars.creater.column.service.ITableColumnService; import org.opsli.modulars.creater.column.wrapper.CreaterTableColumnModel; +import org.opsli.modulars.creater.createrlogs.service.ICreateLogsService; import org.opsli.modulars.creater.importable.ImportTableUtil; import org.opsli.modulars.creater.importable.entity.DatabaseColumn; import org.opsli.modulars.creater.importable.entity.DatabaseTable; @@ -56,6 +56,9 @@ public class TableServiceImpl extends CrudServiceImpl + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +#if(data.subModuleName != null && data.subModuleName != "") +package #(apiPath).web.#(data.moduleName+"."+data.subModuleName); +#else +package #(apiPath).web.#(data.moduleName); +#end + +import #(apiPath).base.result.ResultVo; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +#if(data.subModuleName != null && data.subModuleName != "") +import #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName).#(data.model.tableName)Model; +#else +import #(apiPath).wrapper.#(data.moduleName).#(data.model.tableName)Model; +#end + + +/** + * @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") + * @BelongsPackage: #(apiPath).web.#(data.moduleName+"."+data.subModuleName) +#else + * @BelongsPackage: #(apiPath).web.#(data.moduleName) +#end + * @Author: #(data.authorName) + * @CreateTime: #(currTime) + * @Description: #(data.codeTitle) + * + * 对外 API 直接 暴露 @GetMapping 或者 @PostMapping + * 对内也推荐 单机版 不需要设置 Mapping 但是调用方法得从Controller写起 + * + * 这样写法虽然比较绕,但是当单体项目想要改造微服务架构时 时非常容易的 + * + * + */ +public interface #(data.model.tableName)RestApi { + + /** 标题 */ + String TITLE = "#(data.codeTitleBrief)"; + + /** + * #(data.codeTitle) 查一条 + * @param model 模型 + * @return ResultVo + */ + @GetMapping("/get") + ResultVo<#(data.model.tableName)Model> get(#(data.model.tableName)Model model); + + /** + * #(data.codeTitle) 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @GetMapping("/findPage") + ResultVo findPage( + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest request + ); + + /** + * #(data.codeTitle) 新增 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/insert") + ResultVo insert(@RequestBody #(data.model.tableName)Model model); + + /** + * #(data.codeTitle) 修改 + * @param model 模型 + * @return ResultVo + */ + @PostMapping("/update") + ResultVo update(@RequestBody #(data.model.tableName)Model model); + + /** + * #(data.codeTitle) 删除 + * @param id ID + * @return ResultVo + */ + @PostMapping("/del") + ResultVo del(String id); + + /** + * #(data.codeTitle) 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @PostMapping("/delAll") + ResultVo delAll(String[] ids); + + /** + * #(data.codeTitle) Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @GetMapping("/exportExcel") + ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response); + + /** + * #(data.codeTitle) Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @GetMapping("/exportImport") + ResultVo excelImport(MultipartHttpServletRequest request); + + /** + * #(data.codeTitle) Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @GetMapping("/exportImport/template") + ResultVo importTemplate(HttpServletResponse response); + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/entity/TemplateEntity.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/entity/TemplateEntity.html new file mode 100644 index 00000000..d2f0cee2 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/entity/TemplateEntity.html @@ -0,0 +1,72 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +#if(data.subModuleName != null && data.subModuleName != "") +package #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity; +#else +package #(data.packageName+"."+data.moduleName).entity; +#end + +import java.util.Date; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") + * @BelongsPackage: #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity +#else + * @BelongsPackage: #(data.packageName+"."+data.moduleName).entity +#end + * @Author: #(data.authorName) + * @CreateTime: #(currTime) + * @Description: #(data.codeTitle) + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class #(data.model.tableName) extends BaseEntity { + + + #for(column : data.model.columnList) + ### 不等于 删除字段 和 不等于 租户字段放入上边 + #if(column.fieldName != "deleted" && column.fieldName != "tenantId") + /** #(column.fieldComments) */ + #if(!column.izNotNull) + @TableField(updateStrategy = FieldStrategy.IGNORED) + #end + private #(column.javaType) #(column.fieldName); + + #end + #end + + // ======================================== + + ### 专门处理 删除字段 和 租户字段 + #for(column : data.model.columnList) + #if(column.fieldName == "deleted") + /** 逻辑删除字段 */ + private Integer deleted; + #else if(column.fieldName == "tenantId") + /** 多租户字段 */ + private String tenantId; + #end + + #end + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/TemplateMapper.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/TemplateMapper.html new file mode 100644 index 00000000..8facce5f --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/TemplateMapper.html @@ -0,0 +1,45 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +#if(data.subModuleName != null && data.subModuleName != "") +package #(data.packageName+"."+data.moduleName+"."+data.subModuleName).mapper; +#else +package #(data.packageName+"."+data.moduleName).mapper; +#end + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +#if(data.subModuleName != null && data.subModuleName != "") +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity.#(data.model.tableName); +#else +import #(data.packageName+"."+data.moduleName).entity.#(data.model.tableName); +#end + +/** +* @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") +* @BelongsPackage: #(data.packageName+"."+data.moduleName+"."+data.subModuleName).mapper +#else +* @BelongsPackage: #(data.packageName+"."+data.moduleName).mapper +#end +* @Author: #(data.authorName) +* @CreateTime: #(currTime) +* @Description: #(data.codeTitle) Mapper +*/ +@Mapper +public interface #(data.model.tableName)Mapper extends BaseMapper<#(data.model.tableName)> { + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/xml/TemplateMapperXML.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/xml/TemplateMapperXML.html new file mode 100644 index 00000000..9aa68e99 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/mapper/xml/TemplateMapperXML.html @@ -0,0 +1,10 @@ + + +#if(data.subModuleName != null && data.subModuleName != "") + +#else + +#end + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/model/TemplateModel.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/model/TemplateModel.html new file mode 100644 index 00000000..64994268 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/model/TemplateModel.html @@ -0,0 +1,82 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +#if(data.subModuleName != null && data.subModuleName != "") +package #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName); +#else +package #(apiPath).wrapper.#(data.moduleName); +#end + +import java.util.Date; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import #(apiPath).base.warpper.ApiWrapper; +import org.opsli.common.annotation.validation.ValidationArgs; +import org.opsli.common.annotation.validation.ValidationArgsLenMax; +import org.opsli.common.enums.ValiArgsType; +import org.opsli.plugins.excel.annotation.ExcelInfo; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +/** + * @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") + * @BelongsPackage: #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName) +#else + * @BelongsPackage: #(apiPath).wrapper.#(data.moduleName) +#end + * @Author: #(data.authorName) + * @CreateTime: #(currTime) + * @Description: #(data.codeTitle) + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class #(data.model.tableName)Model extends ApiWrapper { + + #for(column : data.model.columnList) + ### 不等于 删除字段 和 不等于 租户字段放入上边 + #if(column.fieldName != "deleted" && column.fieldName != "tenantId") + /** #(column.fieldComments) */ + @ApiModelProperty(value = "#(column.fieldComments)") + @ExcelProperty(value = "#(column.fieldComments)", order = #(column.sort)) + #if(column.dictTypeCode != null && column.dictTypeCode != "") + @ExcelInfo( dictType = "#(column.dictTypeCode)" ) + #else + @ExcelInfo + #end + // 验证器 + #if(column.validateType != null && column.validateType != "") + @ValidationArgs({#(column.validateType)}) + #end + #if(column.fieldLength != null && column.fieldLength > 0) + #if(column.fieldPrecision != null && column.fieldPrecision > 0) + @ValidationArgsLenMax(#(column.fieldLength+column.fieldPrecision)) + #else + @ValidationArgsLenMax(#(column.fieldLength)) + #end + #end + #if(column.javaType == "Date") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + #end + private #(column.javaType) #(column.fieldName); + + #end + #end + + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/TemplateService.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/TemplateService.html new file mode 100644 index 00000000..5bca6cc4 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/TemplateService.html @@ -0,0 +1,46 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +#if(data.subModuleName != null && data.subModuleName != "") +package #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service; +#else +package #(data.packageName+"."+data.moduleName).service; +#end + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; + + +#if(data.subModuleName != null && data.subModuleName != "") +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName).#(data.model.tableName)Model; +#else +import #(data.packageName+"."+data.moduleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName).#(data.model.tableName)Model; +#end + +/** +* @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") +* @BelongsPackage: #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service +#else +* @BelongsPackage: #(data.packageName+"."+data.moduleName).service +#end +* @Author: #(data.authorName) +* @CreateTime: #(currTime) +* @Description: #(data.codeTitle) Service +*/ +public interface I#(data.model.tableName)Service extends CrudServiceInterface<#(data.model.tableName), #(data.model.tableName)Model> { + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/impl/TemplateServiceImpl.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/impl/TemplateServiceImpl.html new file mode 100644 index 00000000..528e53bb --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/service/impl/TemplateServiceImpl.html @@ -0,0 +1,59 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +#if(data.subModuleName != null && data.subModuleName != "") +package #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service.impl; +#else +package #(data.packageName+"."+data.moduleName).service.impl; +#end + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.opsli.core.base.service.impl.CrudServiceImpl; + +#if(data.subModuleName != null && data.subModuleName != "") +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName).#(data.model.tableName)Model; +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service.I#(data.model.tableName)Service; +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).mapper.#(data.model.tableName)Mapper; +#else +import #(data.packageName+"."+data.moduleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName).#(data.model.tableName)Model; +import #(data.packageName+"."+data.moduleName).service.I#(data.model.tableName)Service; +import #(data.packageName+"."+data.moduleName).mapper.#(data.model.tableName)Mapper; +#end + + +/** +* @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") +* @BelongsPackage: #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service.impl +#else +* @BelongsPackage: #(data.packageName+"."+data.moduleName).service.impl +#end +* @Author: #(data.authorName) +* @CreateTime: #(currTime) +* @Description: #(data.codeTitle) Service Impl +*/ +@Service +public class #(data.model.tableName)ServiceImpl extends CrudServiceImpl<#(data.model.tableName)Mapper, #(data.model.tableName), #(data.model.tableName)Model> + implements I#(data.model.tableName)Service { + + @Autowired(required = false) + private #(data.model.tableName)Mapper mapper; + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/web/TemplateRestController.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/web/TemplateRestController.html new file mode 100644 index 00000000..783c7174 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/backend/web/TemplateRestController.html @@ -0,0 +1,242 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +#if(data.subModuleName != null && data.subModuleName != "") +package #(data.packageName+"."+data.moduleName+"."+data.subModuleName).web; +#else +package #(data.packageName+"."+data.moduleName).web; +#end + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import #(apiPath).base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +#if(data.subModuleName != null && data.subModuleName != "") +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName+"."+data.subModuleName).#(data.model.tableName)Model; +import #(data.packageName+"."+data.moduleName+"."+data.subModuleName).service.I#(data.model.tableName)Service; +import #(apiPath).web.#(data.moduleName+"."+data.subModuleName).#(data.model.tableName)RestApi; +#else +import #(data.packageName+"."+data.moduleName).entity.#(data.model.tableName); +import #(apiPath).wrapper.#(data.moduleName).#(data.model.tableName)Model; +import #(data.packageName+"."+data.moduleName).service.I#(data.model.tableName)Service; +import #(apiPath).web.#(data.moduleName).#(data.model.tableName)RestApi; +#end + +/** +* @BelongsProject: opsli-boot +#if(data.subModuleName != null && data.subModuleName != "") +* @BelongsPackage: #(data.packageName+"."+data.moduleName+"."+data.subModuleName).web +#else +* @BelongsPackage: #(data.packageName+"."+data.moduleName).web +#end +* @Author: #(data.authorName) +* @CreateTime: #(currTime) +* @Description: #(data.codeTitle) Controller +*/ +@Slf4j +#if(data.subModuleName != null && data.subModuleName != "") +@ApiRestController("/#(data.moduleName)/#(data.subModuleName)") +#else +@ApiRestController("/#(data.moduleName)") +#end +public class #(data.model.tableName)RestController extends BaseRestController<#(data.model.tableName), #(data.model.tableName)Model, I#(data.model.tableName)Service> + implements #(data.model.tableName)RestApi { + + + /** + * #(data.codeTitleBrief) 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条#(data.codeTitleBrief)", notes = "获得单条#(data.codeTitleBrief) - ID") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_select") + #end + @Override + public ResultVo<#(data.model.tableName)Model> get(#(data.model.tableName)Model model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * #(data.codeTitleBrief) 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_select") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_select") + #end + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder<#(data.model.tableName)> queryBuilder = new WebQueryBuilder<>(#(data.model.tableName).class, request.getParameterMap()); + Page<#(data.model.tableName), #(data.model.tableName)Model> page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + /** + * #(data.codeTitleBrief) 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增#(data.codeTitleBrief)数据", notes = "新增#(data.codeTitleBrief)数据") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_insert") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_insert") + #end + @EnableLog + @Override + public ResultVo insert(#(data.model.tableName)Model model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增#(data.codeTitleBrief)成功"); + } + + /** + * #(data.codeTitleBrief) 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改#(data.codeTitleBrief)数据", notes = "修改#(data.codeTitleBrief)数据") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_update") + #end + @EnableLog + @Override + public ResultVo update(#(data.model.tableName)Model model) { + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改#(data.codeTitleBrief)成功"); + } + + + /** + * #(data.codeTitleBrief) 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除#(data.codeTitleBrief)数据", notes = "删除#(data.codeTitleBrief)数据") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_update") + #end + @EnableLog + @Override + public ResultVo del(String id){ + IService.delete(id); + return ResultVo.success("删除#(data.codeTitleBrief)成功"); + } + + /** + * #(data.codeTitleBrief) 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除#(data.codeTitleBrief)数据", notes = "批量删除#(data.codeTitleBrief)数据") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_update") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_update") + #end + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + IService.deleteAll(ids); + return ResultVo.success("批量删除#(data.codeTitleBrief)成功"); + } + + + /** + * #(data.codeTitleBrief) Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_export") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_export") + #end + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder<#(data.model.tableName)> queryBuilder = new WebQueryBuilder<>(#(data.model.tableName).class, request.getParameterMap()); + return super.excelExport(RoleApi.TITLE, queryBuilder.build(), response); + } + + /** + * #(data.codeTitleBrief) Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_import") + #end + @EnableLog + @Override + public ResultVo excelImport(MultipartHttpServletRequest request) { + return super.excelImport(request); + } + + /** + * #(data.codeTitleBrief) Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + #if(data.subModuleName != null && data.subModuleName != "") + @RequiresPermissions("#(data.moduleName.toLowerCase())_#(data.subModuleName.toLowerCase())_import") + #else + @RequiresPermissions("#(data.moduleName.toLowerCase())_import") + #end + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(RoleApi.TITLE, response); + } + +} diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/api/TemplateApi.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/api/TemplateApi.html new file mode 100644 index 00000000..a9c217ef --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/api/TemplateApi.html @@ -0,0 +1,63 @@ +import request from "@/utils/request"; + +export function getList(data) { + return request({ + #if(data.subModuleName != null && data.subModuleName != "") + url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/findPage", + #else + url: "#(apiPath)/#(data.moduleName)/findPage", + #end + method: "get", + params: data, + }); +} + + +export function doInsert(data) { + return request({ + #if(data.subModuleName != null && data.subModuleName != "") + url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/insert", + #else + url: "#(apiPath)/#(data.moduleName)/insert", + #end + method: "post", + data, + }); +} + +export function doUpdate(data) { + return request({ + #if(data.subModuleName != null && data.subModuleName != "") + url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/update", + #else + url: "#(apiPath)/#(data.moduleName)/update", + #end + method: "post", + data, + }); +} + +export function doDelete(data) { + return request({ + #if(data.subModuleName != null && data.subModuleName != "") + url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/del", + #else + url: "#(apiPath)/#(data.moduleName)/del", + #end + method: "post", + params: data, + }); +} + +export function doDeleteAll(data) { + return request({ + #if(data.subModuleName != null && data.subModuleName != "") + url: "#(apiPath)/#(data.moduleName)/#(data.subModuleName)/delAll", + #else + url: "#(apiPath)/#(data.moduleName)/delAll", + #end + method: "post", + params: data, + }); +} + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/components/TemplateEdit.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/components/TemplateEdit.html new file mode 100644 index 00000000..3cecb682 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/components/TemplateEdit.html @@ -0,0 +1,195 @@ + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/index/TemplateIndex.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/index/TemplateIndex.html new file mode 100644 index 00000000..280ce496 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/foreend/index/TemplateIndex.html @@ -0,0 +1,479 @@ + + + diff --git a/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/readme/TemplateReadMe.html b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/readme/TemplateReadMe.html new file mode 100644 index 00000000..d410fc43 --- /dev/null +++ b/opsli-modulars/opsli-modulars-creater/src/main/resources/tpl/readme/TemplateReadMe.html @@ -0,0 +1,59 @@ +> Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + +#[[## OPSLI 代码生成器]]# +> 生成 #(data.codeTitle)[#(data.model.tableName)] 代码 , 生成时间:#(currTime) + +> 作者: #(data.authorName) + +#[[### 后端]]# +> +``` +将 包目录下 后端代码 分别拷贝至 `api` 包下 和 `modulars` 下工程 + +api +试例: org.opsli.api.wrapper.模块名 + org.opsli.api.web.模块名 + +modulars +试例: org.opsli.modulars.模块名 +``` + +#[[### 前端]]# +``` +views 包里的代码为 vue展示层,拷贝至对应目录即可 + +试例: /src/views/modules/模块名/index.vue + +试例: /src/views/modules/模块名/components/代码名Edit.vue +``` +``` +api 包里的代码为 api接口层,拷贝至对应目录即可 + +试例: /src/api/模块名/api.js + +``` + +#[[### 菜单权限]]# +``` +需要增加对应菜单的操作权限 + +菜单配置: +编号: 如果不存在主路径则主路径编号为`#(data.moduleName.toLowerCase())`, +如果存在则子路径编号为`#(data.subModuleName.toLowerCase())` +类型:菜单 +主路径:`#(data.moduleName.toLowerCase())` (如果主路径存在,则不需要创建主路径) +子路径:`#(data.subModuleName.toLowerCase())` +#if(data.subModuleName != null && data.subModuleName != "") +组件路径: `views/modules/#(data.moduleName.toLowerCase())/#(data.subModuleName.toLowerCase())/index` +#else +组件路径: `views/modules/#(data.moduleName.toLowerCase())/index` +#end + +查看: `select` +新增: `insert` +修改: `update` +删除: `delete` +导入(暂时前端未公布): `import` +导出(暂时前端未公布): `export` + +``` diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java new file mode 100755 index 00000000..c48a6476 --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/entity/TestUser.java @@ -0,0 +1,68 @@ +/** + * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.opsli.modulars.gentest.user.entity; + +import java.util.Date; +import com.baomidou.mybatisplus.annotation.FieldStrategy; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableLogic; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.opsli.core.base.entity.BaseEntity; + +/** + * @BelongsProject: opsli-boot + * @BelongsPackage: org.opsli.modulars.gentest.user.entity + * @Author: 周鹏程 + * @CreateTime: 2020-11-22 12:12:05 + * @Description: 某系统用户 + */ +@Data +@EqualsAndHashCode(callSuper = false) +public class TestUser extends BaseEntity { + + + /** 名称 */ + private String name; + + /** 金钱 */ + private Double money; + + /** 年龄 */ + private Integer age; + + /** 生日 */ + private Date birth; + + /** 是否启用 */ + private Character izUsable; + + + // ======================================== + + + + + + + /** 多租户字段 */ + private String tenantId; + + /** 逻辑删除字段 */ + private Integer deleted; + + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/TestUserMapper.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/TestUserMapper.java new file mode 100755 index 00000000..4e2406bc --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/TestUserMapper.java @@ -0,0 +1,33 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.gentest.user.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.opsli.modulars.gentest.user.entity.TestUser; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.gentest.user.mapper +* @Author: 周鹏程 +* @CreateTime: 2020-11-22 12:12:05 +* @Description: 某系统用户 Mapper +*/ +@Mapper +public interface TestUserMapper extends BaseMapper { + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/xml/TestUserMapper.xml b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/xml/TestUserMapper.xml new file mode 100755 index 00000000..04a3b58c --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/mapper/xml/TestUserMapper.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/ITestUserService.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/ITestUserService.java new file mode 100755 index 00000000..58071656 --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/ITestUserService.java @@ -0,0 +1,33 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.gentest.user.service; + +import org.opsli.core.base.service.interfaces.CrudServiceInterface; + + +import org.opsli.modulars.gentest.user.entity.TestUser; +import org.opsli.api.wrapper.gentest.user.TestUserModel; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.gentest.user.service +* @Author: 周鹏程 +* @CreateTime: 2020-11-22 12:12:05 +* @Description: 某系统用户 Service +*/ +public interface ITestUserService extends CrudServiceInterface { + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/impl/TestUserServiceImpl.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/impl/TestUserServiceImpl.java new file mode 100755 index 00000000..31fa45f6 --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/service/impl/TestUserServiceImpl.java @@ -0,0 +1,44 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.gentest.user.service.impl; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.opsli.core.base.service.impl.CrudServiceImpl; + +import org.opsli.modulars.gentest.user.entity.TestUser; +import org.opsli.api.wrapper.gentest.user.TestUserModel; +import org.opsli.modulars.gentest.user.service.ITestUserService; +import org.opsli.modulars.gentest.user.mapper.TestUserMapper; + + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.gentest.user.service.impl +* @Author: 周鹏程 +* @CreateTime: 2020-11-22 12:12:05 +* @Description: 某系统用户 Service Impl +*/ +@Service +public class TestUserServiceImpl extends CrudServiceImpl + implements ITestUserService { + + @Autowired(required = false) + private TestUserMapper mapper; + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/web/TestUserRestController.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/web/TestUserRestController.java new file mode 100755 index 00000000..135d31a9 --- /dev/null +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/gentest/user/web/TestUserRestController.java @@ -0,0 +1,188 @@ +/** +* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com +*

+* Licensed under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. You may obtain a copy of +* the License at +*

+* http://www.apache.org/licenses/LICENSE-2.0 +*

+* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +* License for the specific language governing permissions and limitations under +* the License. +*/ +package org.opsli.modulars.gentest.user.web; + +import org.opsli.api.web.system.role.RoleApi; +import org.opsli.core.base.service.interfaces.CrudServiceInterface; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.opsli.api.base.result.ResultVo; +import org.opsli.common.annotation.ApiRestController; +import org.opsli.common.annotation.EnableLog; +import org.opsli.core.base.concroller.BaseRestController; +import org.opsli.core.persistence.Page; +import org.opsli.core.persistence.querybuilder.QueryBuilder; +import org.opsli.core.persistence.querybuilder.WebQueryBuilder; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.opsli.modulars.gentest.user.entity.TestUser; +import org.opsli.api.wrapper.gentest.user.TestUserModel; +import org.opsli.modulars.gentest.user.service.ITestUserService; +import org.opsli.api.web.gentest.user.TestUserRestApi; + +/** +* @BelongsProject: opsli-boot +* @BelongsPackage: org.opsli.modulars.gentest.user.web +* @Author: 周鹏程 +* @CreateTime: 2020-11-22 12:12:05 +* @Description: 某系统用户 Controller +*/ +@Slf4j +@ApiRestController("/gentest/user") +public class TestUserRestController extends BaseRestController + implements TestUserRestApi { + + + /** + * 用户 查一条 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "获得单条用户", notes = "获得单条用户 - ID") + @RequiresPermissions("gentest_user_select") + @Override + public ResultVo get(TestUserModel model) { + // 如果系统内部调用 则直接查数据库 + if(model != null && model.getIzApi() != null && model.getIzApi()){ + model = IService.get(model); + } + return ResultVo.success(model); + } + + /** + * 用户 查询分页 + * @param pageNo 当前页 + * @param pageSize 每页条数 + * @param request request + * @return ResultVo + */ + @ApiOperation(value = "获得分页数据", notes = "获得分页数据 - 查询构造器") + @RequiresPermissions("gentest_user_select") + @Override + public ResultVo findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { + + QueryBuilder queryBuilder = new WebQueryBuilder<>(TestUser.class, request.getParameterMap()); + Page page = new Page<>(pageNo, pageSize); + page.setQueryWrapper(queryBuilder.build()); + page = IService.findPage(page); + + return ResultVo.success(page.getBootstrapData()); + } + + /** + * 用户 新增 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "新增用户数据", notes = "新增用户数据") + @RequiresPermissions("gentest_user_insert") + @EnableLog + @Override + public ResultVo insert(TestUserModel model) { + // 调用新增方法 + IService.insert(model); + return ResultVo.success("新增用户成功"); + } + + /** + * 用户 修改 + * @param model 模型 + * @return ResultVo + */ + @ApiOperation(value = "修改用户数据", notes = "修改用户数据") + @RequiresPermissions("gentest_user_update") + @EnableLog + @Override + public ResultVo update(TestUserModel model) { + // 调用修改方法 + IService.update(model); + return ResultVo.success("修改用户成功"); + } + + + /** + * 用户 删除 + * @param id ID + * @return ResultVo + */ + @ApiOperation(value = "删除用户数据", notes = "删除用户数据") + @RequiresPermissions("gentest_user_update") + @EnableLog + @Override + public ResultVo del(String id){ + IService.delete(id); + return ResultVo.success("删除用户成功"); + } + + /** + * 用户 批量删除 + * @param ids ID 数组 + * @return ResultVo + */ + @ApiOperation(value = "批量删除用户数据", notes = "批量删除用户数据") + @RequiresPermissions("gentest_user_update") + @EnableLog + @Override + public ResultVo delAll(String[] ids){ + IService.deleteAll(ids); + return ResultVo.success("批量删除用户成功"); + } + + + /** + * 用户 Excel 导出 + * @param request request + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel", notes = "导出Excel") + @RequiresPermissions("gentest_user_export") + @EnableLog + @Override + public ResultVo exportExcel(HttpServletRequest request, HttpServletResponse response) { + QueryBuilder queryBuilder = new WebQueryBuilder<>(TestUser.class, request.getParameterMap()); + return super.excelExport(RoleApi.TITLE, queryBuilder.build(), response); + } + + /** + * 用户 Excel 导入 + * @param request 文件流 request + * @return ResultVo + */ + @ApiOperation(value = "导入Excel", notes = "导入Excel") + @RequiresPermissions("gentest_user_import") + @EnableLog + @Override + public ResultVo excelImport(MultipartHttpServletRequest request) { + return super.excelImport(request); + } + + /** + * 用户 Excel 下载导入模版 + * @param response response + * @return ResultVo + */ + @ApiOperation(value = "导出Excel模版", notes = "导出Excel模版") + @RequiresPermissions("gentest_user_import") + @Override + public ResultVo importTemplate(HttpServletResponse response) { + return super.importTemplate(RoleApi.TITLE, response); + } + +} diff --git a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java index 65df2a8e..0027b8c5 100644 --- a/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java +++ b/opsli-modulars/opsli-modulars-test/src/main/java/org/opsli/modulars/test/web/TestRestController.java @@ -39,7 +39,7 @@ public class TestRestController extends BaseRestController get(TestModel model) { // 如果系统内部调用 则直接查数据库 @@ -57,6 +57,7 @@ public class TestRestController extends BaseRestController findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) { @@ -74,7 +75,7 @@ public class TestRestController extends BaseRestController insert(TestModel model) { @@ -89,7 +90,7 @@ public class TestRestController extends BaseRestController update(TestModel model) { @@ -105,7 +106,7 @@ public class TestRestController extends BaseRestController del(String id){ @@ -120,7 +121,7 @@ public class TestRestController extends BaseRestController delAll(String[] ids){ @@ -136,7 +137,7 @@ public class TestRestController extends BaseRestController exportExcel(HttpServletRequest request, HttpServletResponse response) { @@ -150,7 +151,7 @@ public class TestRestController extends BaseRestController excelImport(MultipartHttpServletRequest request) { @@ -163,7 +164,7 @@ public class TestRestController extends BaseRestController importTemplate(HttpServletResponse response) { return super.importTemplate(RoleApi.TITLE, response);