diff --git a/README.md b/README.md index cedefcdf..25412480 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ com.ruoyi ├── ruoyi-common // 通用模块 │ └── ruoyi-common-core // 核心模块 │ └── ruoyi-common-datascope // 权限范围 +│ └── ruoyi-common-datasource // 多数据源 │ └── ruoyi-common-log // 日志记录 │ └── ruoyi-common-redis // 缓存服务 │ └── ruoyi-common-security // 安全模块 @@ -107,7 +108,7 @@ com.ruoyi - + diff --git a/bin/run-auth.bat b/bin/run-auth.bat new file mode 100644 index 00000000..6f2f9763 --- /dev/null +++ b/bin/run-auth.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] auth̡ +echo. + +cd %~dp0 +cd ../ruoyi-auth/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-auth.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-gateway.bat b/bin/run-gateway.bat new file mode 100644 index 00000000..0a9d776a --- /dev/null +++ b/bin/run-gateway.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] gateway̡ +echo. + +cd %~dp0 +cd ../ruoyi-gateway/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-gateway.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-modules-file.bat b/bin/run-modules-file.bat new file mode 100644 index 00000000..8ff427ad --- /dev/null +++ b/bin/run-modules-file.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] modules-file̡ +echo. + +cd %~dp0 +cd ../ruoyi-modules/ruoyi-file/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-modules-file.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-modules-gen.bat b/bin/run-modules-gen.bat new file mode 100644 index 00000000..7f8e95a2 --- /dev/null +++ b/bin/run-modules-gen.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] modules-gen̡ +echo. + +cd %~dp0 +cd ../ruoyi-modules/ruoyi-gen/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-modules-gen.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-modules-job.bat b/bin/run-modules-job.bat new file mode 100644 index 00000000..1f6f7e7f --- /dev/null +++ b/bin/run-modules-job.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] modules-job̡ +echo. + +cd %~dp0 +cd ../ruoyi-modules/ruoyi-job/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-modules-job.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-modules-system.bat b/bin/run-modules-system.bat new file mode 100644 index 00000000..d43e08cb --- /dev/null +++ b/bin/run-modules-system.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] modules-system̡ +echo. + +cd %~dp0 +cd ../ruoyi-modules/ruoyi-system/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-modules-system.jar + +cd bin +pause \ No newline at end of file diff --git a/bin/run-monitor.bat b/bin/run-monitor.bat new file mode 100644 index 00000000..d90a0c7a --- /dev/null +++ b/bin/run-monitor.bat @@ -0,0 +1,14 @@ +@echo off +echo. +echo [Ϣ] monitor̡ +echo. + +cd %~dp0 +cd ../ruoyi-visual/ruoyi-monitor/target + +set JAVA_OPTS=-Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m + +java -Dfile.encoding=utf-8 -jar %JAVA_OPTS% ruoyi-visual-monitor.jar + +cd bin +pause \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5dcf2a0b..eac204ec 100644 --- a/pom.xml +++ b/pom.xml @@ -17,22 +17,22 @@ UTF-8 UTF-8 1.8 - 2.3.4.RELEASE - Hoxton.SR8 + 2.3.7.RELEASE + Hoxton.SR9 2.2.3.RELEASE - 2.3.0 + 2.3.1 2.1.3 2.9.2 1.5.24 1.26.5 2.3.2 1.3.0 - 1.2.2 + 1.2.4 3.2.1 2.5 1.3.3 1.7 - 1.2.74 + 1.2.75 8.0.3 4.1.2 2.6.2 diff --git a/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories b/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories index e9bf345c..19bdae5d 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories +++ b/ruoyi-api/ruoyi-api-system/src/main/resources/META-INF/spring.factories @@ -1,3 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.ruoyi.system.api.factory.RemoteUserFallbackFactory,\ - com.ruoyi.system.api.factory.RemoteLogFallbackFactory + com.ruoyi.system.api.factory.RemoteLogFallbackFactory, \ + com.ruoyi.system.api.factory.RemoteFileFallbackFactory diff --git a/ruoyi-auth/pom.xml b/ruoyi-auth/pom.xml index cf5fdf0b..9fef8436 100644 --- a/ruoyi-auth/pom.xml +++ b/ruoyi-auth/pom.xml @@ -61,6 +61,7 @@ + ${project.artifactId} org.springframework.boot diff --git a/ruoyi-auth/src/main/resources/bootstrap.yml b/ruoyi-auth/src/main/resources/bootstrap.yml index a965b3ba..e6848419 100644 --- a/ruoyi-auth/src/main/resources/bootstrap.yml +++ b/ruoyi-auth/src/main/resources/bootstrap.yml @@ -21,4 +21,5 @@ spring: # 配置文件格式 file-extension: yml # 共享配置 - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java index af1e09a6..975eca3f 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java @@ -144,7 +144,7 @@ public @interface Excel public enum ColumnType { - NUMERIC(0), STRING(1); + NUMERIC(0), STRING(1), IMAGE(2); private final int value; ColumnType(int value) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java index 29f21eee..122c4631 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java @@ -13,6 +13,9 @@ public class GenConstants /** 树表(增删改查) */ public static final String TPL_TREE = "tree"; + /** 主子表(增删改查) */ + public static final String TPL_SUB = "sub"; + /** 树编码字段 */ public static final String TREE_CODE = "treeCode"; @@ -29,8 +32,10 @@ public class GenConstants public static final String PARENT_MENU_NAME = "parentMenuName"; /** 数据库字符串类型 */ - public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2", "tinytext", "text", - "mediumtext", "longtext" }; + public static final String[] COLUMNTYPE_STR = { "char", "varchar", "nvarchar", "varchar2" }; + + /** 数据库文本类型 */ + public static final String[] COLUMNTYPE_TEXT = { "tinytext", "text", "mediumtext", "longtext" }; /** 数据库时间类型 */ public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; @@ -74,8 +79,11 @@ public class GenConstants /** 日期控件 */ public static final String HTML_DATETIME = "datetime"; - /** 上传控件 */ - public static final String HTML_UPLOAD_IMAGE = "uploadImage"; + /** 图片上传控件 */ + public static final String HTML_IMAGE_UPLOAD = "imageUpload"; + + /** 文件上传控件 */ + public static final String HTML_FILE_UPLOAD = "fileUpload"; /** 富文本控件 */ public static final String HTML_EDITOR = "editor"; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/SecurityUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/SecurityUtils.java index 3c5bf20b..f2225bea 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/SecurityUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/SecurityUtils.java @@ -17,7 +17,8 @@ public class SecurityUtils */ public static String getUsername() { - return ServletUtils.getRequest().getHeader(CacheConstants.DETAILS_USERNAME); + String username = ServletUtils.getRequest().getHeader(CacheConstants.DETAILS_USERNAME); + return ServletUtils.urlDecode(username); } /** diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java index 5346483d..6809f29f 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java @@ -1,6 +1,9 @@ package com.ruoyi.common.core.utils; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.net.URLEncoder; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.Map; @@ -10,6 +13,7 @@ import javax.servlet.http.HttpSession; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.text.Convert; /** @@ -173,4 +177,40 @@ public class ServletUtils } return false; } + + /** + * 内容编码 + * + * @param str 内容 + * @return 编码后的内容 + */ + public static String urlEncode(String str) + { + try + { + return URLEncoder.encode(str, Constants.UTF8); + } + catch (UnsupportedEncodingException e) + { + return ""; + } + } + + /** + * 内容解码 + * + * @param str 内容 + * @return 解码后的内容 + */ + public static String urlDecode(String str) + { + try + { + return URLDecoder.decode(str, Constants.UTF8); + } + catch (UnsupportedEncodingException e) + { + return ""; + } + } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileTypeUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileTypeUtils.java index 64dc7568..1629fcd4 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileTypeUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/FileTypeUtils.java @@ -44,4 +44,33 @@ public class FileTypeUtils } return fileName.substring(separatorIndex + 1).toLowerCase(); } + + /** + * 获取文件类型 + * + * @param photoByte 文件字节码 + * @return 后缀(不含".") + */ + public static String getFileExtendName(byte[] photoByte) + { + String strFileExtendName = "JPG"; + if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) + && ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) + { + strFileExtendName = "GIF"; + } + else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) + { + strFileExtendName = "JPG"; + } + else if ((photoByte[0] == 66) && (photoByte[1] == 77)) + { + strFileExtendName = "BMP"; + } + else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) + { + strFileExtendName = "PNG"; + } + return strFileExtendName; + } } \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/ImageUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/ImageUtils.java new file mode 100644 index 00000000..f8fa776a --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/file/ImageUtils.java @@ -0,0 +1,86 @@ +package com.ruoyi.common.core.utils.file; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; +import java.util.Arrays; +import org.apache.poi.util.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 图片处理工具类 + * + * @author ruoyi + */ +public class ImageUtils +{ + private static final Logger log = LoggerFactory.getLogger(ImageUtils.class); + + public static byte[] getImage(String imagePath) + { + InputStream is = getFile(imagePath); + try + { + return IOUtils.toByteArray(is); + } + catch (Exception e) + { + log.error("图片加载异常 {}", e); + return null; + } + finally + { + IOUtils.closeQuietly(is); + } + } + + public static InputStream getFile(String imagePath) + { + try + { + byte[] result = readFile(imagePath); + result = Arrays.copyOf(result, result.length); + return new ByteArrayInputStream(result); + } + catch (Exception e) + { + log.error("获取图片异常 {}", e); + } + return null; + } + + /** + * 读取文件为字节数据 + * + * @param key 地址 + * @return 字节数据 + */ + public static byte[] readFile(String url) + { + InputStream in = null; + ByteArrayOutputStream baos = null; + try + { + // 网络地址 + URL urlObj = new URL(url); + URLConnection urlConnection = urlObj.openConnection(); + urlConnection.setConnectTimeout(30 * 1000); + urlConnection.setReadTimeout(60 * 1000); + urlConnection.setDoInput(true); + in = urlConnection.getInputStream(); + return IOUtils.toByteArray(in); + } + catch (Exception e) + { + log.error("访问文件异常 {}", e); + return null; + } + finally + { + IOUtils.closeQuietly(baos); + } + } +} diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index 8914a91f..f754a2ca 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -20,10 +20,12 @@ import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.DataValidation; import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.usermodel.DataValidationHelper; import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.HorizontalAlignment; @@ -35,6 +37,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.ss.util.CellRangeAddressList; import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFDataValidation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +48,8 @@ import com.ruoyi.common.core.annotation.Excels; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.core.utils.file.FileTypeUtils; +import com.ruoyi.common.core.utils.file.ImageUtils; import com.ruoyi.common.core.utils.reflect.ReflectUtils; /** @@ -96,6 +101,11 @@ public class ExcelUtil */ private List fields; + /** + * 最大高度 + */ + private short maxHeight; + /** * 统计列表 */ @@ -233,7 +243,15 @@ public class ExcelUtil } else { - val = Convert.toStr(val); + String dateFormat = field.getAnnotation(Excel.class).dateFormat(); + if (StringUtils.isNotEmpty(dateFormat)) + { + val = DateUtils.parseDateToStr(dateFormat, (Date) val); + } + else + { + val = Convert.toStr(val); + } } } else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) @@ -512,6 +530,47 @@ public class ExcelUtil { cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); } + else if (ColumnType.IMAGE == attr.cellType()) + { + ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), + cell.getRow().getRowNum() + 1); + String imagePath = Convert.toStr(value); + if (StringUtils.isNotEmpty(imagePath)) + { + byte[] data = ImageUtils.getImage(imagePath); + getDrawingPatriarch(cell.getSheet()).createPicture(anchor, + cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); + } + } + } + + /** + * 获取画布 + */ + public static Drawing getDrawingPatriarch(Sheet sheet) + { + if (sheet.getDrawingPatriarch() == null) + { + sheet.createDrawingPatriarch(); + } + return sheet.getDrawingPatriarch(); + } + + /** + * 获取图片类型,设置图片插入类型 + */ + public int getImageType(byte[] value) + { + String type = FileTypeUtils.getFileExtendName(value); + if ("JPG".equalsIgnoreCase(type)) + { + return Workbook.PICTURE_TYPE_JPEG; + } + else if ("PNG".equalsIgnoreCase(type)) + { + return Workbook.PICTURE_TYPE_PNG; + } + return Workbook.PICTURE_TYPE_JPEG; } /** @@ -527,7 +586,6 @@ public class ExcelUtil { // 设置列宽 sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256)); - row.setHeight((short) (attr.height() * 20)); } // 如果设置了提示信息则鼠标放上去提示. if (StringUtils.isNotEmpty(attr.prompt())) @@ -552,7 +610,7 @@ public class ExcelUtil try { // 设置行高 - row.setHeight((short) (attr.height() * 20)); + row.setHeight(maxHeight); // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. if (attr.isExport()) { @@ -851,6 +909,21 @@ public class ExcelUtil } } this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); + this.maxHeight = getRowHeight(); + } + + /** + * 根据注解获取最大行高 + */ + public short getRowHeight() + { + double maxHeight = 0; + for (Object[] os : this.fields) + { + Excel excel = (Excel) os[1]; + maxHeight = maxHeight > excel.height() ? maxHeight : excel.height(); + } + return (short) (maxHeight * 20); } /** @@ -921,7 +994,7 @@ public class ExcelUtil } else { - if ((Double) val % 1 > 0) + if ((Double) val % 1 != 0) { val = new BigDecimal(val.toString()); } diff --git a/ruoyi-common/ruoyi-common-datasource/pom.xml b/ruoyi-common/ruoyi-common-datasource/pom.xml index c891aec1..363a8ed0 100644 --- a/ruoyi-common/ruoyi-common-datasource/pom.xml +++ b/ruoyi-common/ruoyi-common-datasource/pom.xml @@ -30,6 +30,12 @@ dynamic-datasource-spring-boot-starter ${dynamic-ds.version} + + + + io.seata + seata-spring-boot-starter + \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java index d0a557e8..e76018e7 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java @@ -20,7 +20,7 @@ import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import com.alibaba.fastjson.JSON; -import com.ruoyi.common.core.constant.CacheConstants; +import com.ruoyi.common.core.utils.SecurityUtils; import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.ip.IpUtils; @@ -93,8 +93,7 @@ public class LogAspect operLog.setJsonResult(JSON.toJSONString(jsonResult)); operLog.setOperUrl(ServletUtils.getRequest().getRequestURI()); - HttpServletRequest request = ServletUtils.getRequest(); - String username = request.getHeader(CacheConstants.DETAILS_USERNAME); + String username = SecurityUtils.getUsername(); if (StringUtils.isNotBlank(username)) { operLog.setOperName(username); diff --git a/ruoyi-gateway/pom.xml b/ruoyi-gateway/pom.xml index 2a71ce68..1c522469 100644 --- a/ruoyi-gateway/pom.xml +++ b/ruoyi-gateway/pom.xml @@ -85,6 +85,7 @@ + ${project.artifactId} org.springframework.boot diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java index c0bdd7a4..0da5fa06 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/config/SwaggerProvider.java @@ -10,6 +10,11 @@ import org.springframework.stereotype.Component; import springfox.documentation.swagger.web.SwaggerResource; import springfox.documentation.swagger.web.SwaggerResourcesProvider; +/** + * 聚合系统接口 + * + * @author ruoyi + */ @Component public class SwaggerProvider implements SwaggerResourcesProvider { diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java index 36c72d6b..1bd39940 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java @@ -20,6 +20,7 @@ import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.domain.R; +import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties; @@ -78,7 +79,7 @@ public class AuthFilter implements GlobalFilter, Ordered redisService.expire(getTokenKey(token), EXPIRE_TIME); // 设置用户信息到请求 ServerHttpRequest mutableReq = exchange.getRequest().mutate().header(CacheConstants.DETAILS_USER_ID, userid) - .header(CacheConstants.DETAILS_USERNAME, username).build(); + .header(CacheConstants.DETAILS_USERNAME, ServletUtils.urlEncode(username)).build(); ServerWebExchange mutableExchange = exchange.mutate().request(mutableReq).build(); return chain.filter(mutableExchange); diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java index 60a006f2..80c64605 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/handler/SentinelFallbackHandler.java @@ -12,7 +12,7 @@ import reactor.core.publisher.Mono; /** * 自定义限流异常处理 - * + * * @author ruoyi */ public class SentinelFallbackHandler implements WebExceptionHandler @@ -21,7 +21,7 @@ public class SentinelFallbackHandler implements WebExceptionHandler { ServerHttpResponse serverHttpResponse = exchange.getResponse(); serverHttpResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8"); - byte[] datas = "{\"status\":429,\"message\":\"请求超过最大数,请稍后再试\"}".getBytes(StandardCharsets.UTF_8); + byte[] datas = "{\"code\":429,\"msg\":\"请求超过最大数,请稍后再试\"}".getBytes(StandardCharsets.UTF_8); DataBuffer buffer = serverHttpResponse.bufferFactory().wrap(datas); return serverHttpResponse.writeWith(Mono.just(buffer)); } diff --git a/ruoyi-gateway/src/main/resources/bootstrap.yml b/ruoyi-gateway/src/main/resources/bootstrap.yml index 2e6e19bd..12e59d42 100644 --- a/ruoyi-gateway/src/main/resources/bootstrap.yml +++ b/ruoyi-gateway/src/main/resources/bootstrap.yml @@ -23,7 +23,8 @@ spring: # 配置文件格式 file-extension: yml # 共享配置 - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} sentinel: # 取消控制台懒加载 eager: true diff --git a/ruoyi-modules/ruoyi-file/pom.xml b/ruoyi-modules/ruoyi-file/pom.xml index 8a98e56c..a799a19b 100644 --- a/ruoyi-modules/ruoyi-file/pom.xml +++ b/ruoyi-modules/ruoyi-file/pom.xml @@ -76,6 +76,7 @@ + ${project.artifactId} org.springframework.boot diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java index 8c5a1985..a49168c2 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java @@ -3,7 +3,6 @@ package com.ruoyi.file.utils; import java.io.File; import java.io.IOException; import org.apache.commons.io.FilenameUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.core.exception.file.FileNameLengthLimitExceededException; import com.ruoyi.common.core.exception.file.FileSizeLimitExceededException; @@ -30,12 +29,6 @@ public class FileUploadUtils */ public static final int DEFAULT_FILE_NAME_LENGTH = 100; - /** - * 资源映射路径 前缀 - */ - @Value("${file.prefix}") - public String localFilePrefix; - /** * 根据文件路径上传 * @@ -110,7 +103,7 @@ public class FileUploadUtils desc.getParentFile().mkdirs(); } } - return desc; + return desc.isAbsolute() ? desc : desc.getAbsoluteFile(); } private static final String getPathFileName(String fileName) throws IOException diff --git a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml index 67100937..8efb2b11 100644 --- a/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-file/src/main/resources/bootstrap.yml @@ -21,4 +21,5 @@ spring: # 配置文件格式 file-extension: yml # 共享配置 - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/ruoyi-modules/ruoyi-gen/pom.xml b/ruoyi-modules/ruoyi-gen/pom.xml index 48457392..e1f5c744 100644 --- a/ruoyi-modules/ruoyi-gen/pom.xml +++ b/ruoyi-modules/ruoyi-gen/pom.xml @@ -75,6 +75,7 @@ + ${project.artifactId} org.springframework.boot diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java index bcfe1bb5..49c146df 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/controller/GenController.java @@ -63,10 +63,12 @@ public class GenController extends BaseController public AjaxResult getInfo(@PathVariable Long talbleId) { GenTable table = genTableService.selectGenTableById(talbleId); + List tables = genTableService.selectGenTableAll(); List list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); Map map = new HashMap(); map.put("info", table); map.put("rows", list); + map.put("tables", tables); return AjaxResult.success(map); } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java index 8b62ae74..d08b7325 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java @@ -28,11 +28,17 @@ public class GenTable extends BaseEntity @NotBlank(message = "表描述不能为空") private String tableComment; + /** 关联父表的表名 */ + private String subTableName; + + /** 本表关联父表的外键名 */ + private String subTableFkName; + /** 实体类名称(首字母大写) */ @NotBlank(message = "实体类名称不能为空") private String className; - /** 使用的模板(crud单表操作 tree树表操作) */ + /** 使用的模板(crud单表操作 tree树表操作 sub主子表操作) */ private String tplCategory; /** 生成包路径 */ @@ -64,6 +70,9 @@ public class GenTable extends BaseEntity /** 主键信息 */ private GenTableColumn pkColumn; + /** 子表信息 */ + private GenTable subTable; + /** 表列信息 */ @Valid private List columns; @@ -116,6 +125,26 @@ public class GenTable extends BaseEntity this.tableComment = tableComment; } + public String getSubTableName() + { + return subTableName; + } + + public void setSubTableName(String subTableName) + { + this.subTableName = subTableName; + } + + public String getSubTableFkName() + { + return subTableFkName; + } + + public void setSubTableFkName(String subTableFkName) + { + this.subTableFkName = subTableFkName; + } + public String getClassName() { return className; @@ -216,6 +245,15 @@ public class GenTable extends BaseEntity this.pkColumn = pkColumn; } + public GenTable getSubTable() + { + return subTable; + } + + public void setSubTable(GenTable subTable) + { + this.subTable = subTable; + } public List getColumns() { return columns; @@ -286,6 +324,15 @@ public class GenTable extends BaseEntity this.parentMenuName = parentMenuName; } + public boolean isSub() + { + return isSub(this.tplCategory); + } + + public static boolean isSub(String tplCategory) + { + return tplCategory != null && StringUtils.equals(GenConstants.TPL_SUB, tplCategory); + } public boolean isTree() { return isTree(this.tplCategory); diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java index 9b364b96..2f3e99df 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTableColumn.java @@ -60,7 +60,7 @@ public class GenTableColumn extends BaseEntity /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ private String queryType; - /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、upload上传控件、editor富文本控件) */ + /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件、image图片上传控件、upload文件上传控件、editor富文本控件) */ private String htmlType; /** 字典类型 */ @@ -139,6 +139,11 @@ public class GenTableColumn extends BaseEntity return javaField; } + public String getCapJavaField() + { + return StringUtils.capitalize(javaField); + } + public void setIsPk(String isPk) { this.isPk = isPk; diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java index b5ef2985..3d36d88e 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/mapper/GenTableMapper.java @@ -34,6 +34,13 @@ public interface GenTableMapper */ public List selectDbTableListByNames(String[] tableNames); + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + public List selectGenTableAll(); + /** * 查询表ID业务信息 * diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java index 34e6d751..1e656200 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java @@ -102,6 +102,17 @@ public class GenTableServiceImpl implements IGenTableService return genTableMapper.selectDbTableListByNames(tableNames); } + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + @Override + public List selectGenTableAll() + { + return genTableMapper.selectGenTableAll(); + } + /** * 修改业务 * @@ -179,14 +190,16 @@ public class GenTableServiceImpl implements IGenTableService * @param tableId 表编号 * @return 预览数据列表 */ + @Override public Map previewCode(Long tableId) { Map dataMap = new LinkedHashMap<>(); // 查询表信息 GenTable table = genTableMapper.selectGenTableById(tableId); - // 查询列信息 - List columns = table.getColumns(); - setPkColumn(table, columns); + // 设置主子表信息 + setSubTable(table); + // 设置主键列信息 + setPkColumn(table); VelocityInitializer.initVelocity(); VelocityContext context = VelocityUtils.prepareContext(table); @@ -230,9 +243,10 @@ public class GenTableServiceImpl implements IGenTableService { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); - // 查询列信息 - List columns = table.getColumns(); - setPkColumn(table, columns); + // 设置主子表信息 + setSubTable(table); + // 设置主键列信息 + setPkColumn(table); VelocityInitializer.initVelocity(); @@ -275,6 +289,10 @@ public class GenTableServiceImpl implements IGenTableService List tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + if (StringUtils.isEmpty(dbTableColumns)) + { + throw new CustomException("同步数据失败,原表结构不存在"); + } List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); dbTableColumns.forEach(column -> { @@ -318,9 +336,10 @@ public class GenTableServiceImpl implements IGenTableService { // 查询表信息 GenTable table = genTableMapper.selectGenTableByName(tableName); - // 查询列信息 - List columns = table.getColumns(); - setPkColumn(table, columns); + // 设置主子表信息 + setSubTable(table); + // 设置主键列信息 + setPkColumn(table); VelocityInitializer.initVelocity(); @@ -374,6 +393,17 @@ public class GenTableServiceImpl implements IGenTableService { throw new CustomException("树名称字段不能为空"); } + else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) + { + if (StringUtils.isEmpty(genTable.getSubTableName())) + { + throw new CustomException("关联子表的表名不能为空"); + } + else if (StringUtils.isEmpty(genTable.getSubTableFkName())) + { + throw new CustomException("子表关联的外键名不能为空"); + } + } } } @@ -381,11 +411,10 @@ public class GenTableServiceImpl implements IGenTableService * 设置主键列信息 * * @param table 业务表信息 - * @param columns 业务字段列表 */ - public void setPkColumn(GenTable table, List columns) + public void setPkColumn(GenTable table) { - for (GenTableColumn column : columns) + for (GenTableColumn column : table.getColumns()) { if (column.isPk()) { @@ -395,7 +424,35 @@ public class GenTableServiceImpl implements IGenTableService } if (StringUtils.isNull(table.getPkColumn())) { - table.setPkColumn(columns.get(0)); + table.setPkColumn(table.getColumns().get(0)); + } + if (GenConstants.TPL_SUB.equals(table.getTplCategory())) + { + for (GenTableColumn column : table.getSubTable().getColumns()) + { + if (column.isPk()) + { + table.getSubTable().setPkColumn(column); + break; + } + } + if (StringUtils.isNull(table.getSubTable().getPkColumn())) + { + table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0)); + } + } + } + /** + * 设置主子表信息 + * + * @param table 业务表信息 + */ + public void setSubTable(GenTable table) + { + String subTableName = table.getSubTableName(); + if (StringUtils.isNotEmpty(subTableName)) + { + table.setSubTable(genTableMapper.selectGenTableByName(subTableName)); } } diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java index 010f92bc..3d6e0ff6 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/IGenTableService.java @@ -35,6 +35,13 @@ public interface IGenTableService */ public List selectDbTableListByNames(String[] tableNames); + /** + * 查询所有表信息 + * + * @return 表信息集合 + */ + public List selectGenTableAll(); + /** * 查询业务信息 * diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java index f3860585..aa22ddbb 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/GenUtils.java @@ -40,13 +40,14 @@ public class GenUtils column.setCreateBy(table.getCreateBy()); // 设置java字段名 column.setJavaField(StringUtils.toCamelCase(columnName)); + // 设置默认类型 + column.setJavaType(GenConstants.TYPE_STRING); - if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) { - column.setJavaType(GenConstants.TYPE_STRING); // 字符串长度超过500设置为文本域 Integer columnLength = getColumnLength(column.getColumnType()); - String htmlType = columnLength >= 500 ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; + String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; column.setHtmlType(htmlType); } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) @@ -58,7 +59,7 @@ public class GenUtils { column.setHtmlType(GenConstants.HTML_INPUT); - // 如果是浮点型 + // 如果是浮点型 统一用BigDecimal String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) { @@ -111,10 +112,15 @@ public class GenUtils { column.setHtmlType(GenConstants.HTML_SELECT); } - // 文件字段设置上传控件 + // 图片字段设置图片上传控件 else if (StringUtils.endsWithIgnoreCase(columnName, "image")) { - column.setHtmlType(GenConstants.HTML_UPLOAD_IMAGE); + column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); + } + // 文件字段设置文件上传控件 + else if (StringUtils.endsWithIgnoreCase(columnName, "file")) + { + column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); } // 内容字段设置富文本控件 else if (StringUtils.endsWithIgnoreCase(columnName, "content")) diff --git a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java index 2830c985..8fe36a83 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java @@ -23,13 +23,13 @@ public class VelocityUtils /** mybatis空间路径 */ private static final String MYBATIS_PATH = "main/resources/mapper"; - + /** 默认上级菜单,系统工具 */ private static final String DEFAULT_PARENT_MENU_ID = "3"; /** * 设置模板变量信息 - * + * * @return 模板列表 */ public static VelocityContext prepareContext(GenTable genTable) @@ -54,7 +54,7 @@ public class VelocityUtils velocityContext.put("author", genTable.getFunctionAuthor()); velocityContext.put("datetime", DateUtils.getDate()); velocityContext.put("pkColumn", genTable.getPkColumn()); - velocityContext.put("importList", getImportList(genTable.getColumns())); + velocityContext.put("importList", getImportList(genTable)); velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); @@ -63,9 +63,13 @@ public class VelocityUtils { setTreeVelocityContext(velocityContext, genTable); } + if (GenConstants.TPL_SUB.equals(tplCategory)) + { + setSubVelocityContext(velocityContext, genTable); + } return velocityContext; } - + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); @@ -96,9 +100,27 @@ public class VelocityUtils } } + public static void setSubVelocityContext(VelocityContext context, GenTable genTable) + { + GenTable subTable = genTable.getSubTable(); + String subTableName = genTable.getSubTableName(); + String subTableFkName = genTable.getSubTableFkName(); + String subClassName = genTable.getSubTable().getClassName(); + String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName); + + context.put("subTable", subTable); + context.put("subTableName", subTableName); + context.put("subTableFkName", subTableFkName); + context.put("subTableFkClassName", subTableFkClassName); + context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName)); + context.put("subClassName", subClassName); + context.put("subclassName", StringUtils.uncapitalize(subClassName)); + context.put("subImportList", getImportList(genTable.getSubTable())); + } + /** * 获取模板信息 - * + * * @return 模板列表 */ public static List getTemplateList(String tplCategory) @@ -120,6 +142,11 @@ public class VelocityUtils { templates.add("vm/vue/index-tree.vue.vm"); } + else if (GenConstants.TPL_SUB.equals(tplCategory)) + { + templates.add("vm/vue/index.vue.vm"); + templates.add("vm/java/sub-domain.java.vm"); + } return templates; } @@ -147,6 +174,10 @@ public class VelocityUtils { fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); } + if (template.contains("sub-domain.java.vm") && StringUtils.equals(GenConstants.TPL_SUB, genTable.getTplCategory())) + { + fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); + } else if (template.contains("mapper.java.vm")) { fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); @@ -188,7 +219,7 @@ public class VelocityUtils /** * 获取包前缀 - * + * * @param packageName 包名称 * @return 包前缀名称 */ @@ -202,12 +233,18 @@ public class VelocityUtils /** * 根据列类型获取导入包 * - * @param columns 列集合 + * @param genTable 业务表对象 * @return 返回需要导入的包列表 */ - public static HashSet getImportList(List columns) + public static HashSet getImportList(GenTable genTable) { + List columns = genTable.getColumns(); + GenTable subGenTable = genTable.getSubTable(); HashSet importList = new HashSet(); + if (StringUtils.isNotNull(subGenTable)) + { + importList.add("java.util.List"); + } for (GenTableColumn column : columns) { if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) @@ -225,7 +262,7 @@ public class VelocityUtils /** * 获取权限前缀 - * + * * @param moduleName 模块名称 * @param businessName 业务名称 * @return 返回权限前缀 @@ -237,7 +274,7 @@ public class VelocityUtils /** * 获取上级菜单ID字段 - * + * * @param paramsObj 生成其他选项 * @return 上级菜单ID字段 */ @@ -252,7 +289,7 @@ public class VelocityUtils /** * 获取树编码 - * + * * @param paramsObj 生成其他选项 * @return 树编码 */ @@ -267,7 +304,7 @@ public class VelocityUtils /** * 获取树父编码 - * + * * @param paramsObj 生成其他选项 * @return 树父编码 */ @@ -282,7 +319,7 @@ public class VelocityUtils /** * 获取树名称 - * + * * @param paramsObj 生成其他选项 * @return 树名称 */ @@ -297,7 +334,7 @@ public class VelocityUtils /** * 获取需要在哪一列上面显示展开按钮 - * + * * @param genTable 业务表对象 * @return 展开按钮列序号 */ diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml index ed0f82b5..bb8b76b1 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/bootstrap.yml @@ -21,4 +21,5 @@ spring: # 配置文件格式 file-extension: yml # 共享配置 - shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml index eea10019..a243a02d 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/mapper/generator/GenTableMapper.xml @@ -5,24 +5,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -52,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table + select table_id, table_name, table_comment, sub_table_name, sub_table_fk_name, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table + + insert into gen_table ( table_name, @@ -156,6 +172,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" table_name = #{tableName}, table_comment = #{tableComment}, + sub_table_name = #{subTableName}, + sub_table_fk_name = #{subTableFkName}, class_name = #{className}, function_author = #{functionAuthor}, gen_type = #{genType}, diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm index 67d8e6cc..7ac19872 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm @@ -20,7 +20,7 @@ import ${packageName}.service.I${ClassName}Service; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.utils.poi.ExcelUtil; -#if($table.crud) +#if($table.crud || $table.sub) import com.ruoyi.common.core.web.page.TableDataInfo; #elseif($table.tree) #end @@ -43,7 +43,7 @@ public class ${ClassName}Controller extends BaseController */ @PreAuthorize(hasPermi = "${permissionPrefix}:list") @GetMapping("/list") -#if($table.crud) +#if($table.crud || $table.sub) public TableDataInfo list(${ClassName} ${className}) { startPage(); diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm index 92b089a9..3e6be024 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/domain.java.vm @@ -6,7 +6,7 @@ import ${import}; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; -#if($table.crud) +#if($table.crud || $table.sub) import com.ruoyi.common.core.web.domain.BaseEntity; #elseif($table.tree) import com.ruoyi.common.core.web.domain.TreeEntity; @@ -18,7 +18,7 @@ import com.ruoyi.common.core.web.domain.TreeEntity; * @author ${author} * @date ${datetime} */ -#if($table.crud) +#if($table.crud || $table.sub) #set($Entity="BaseEntity") #elseif($table.tree) #set($Entity="TreeEntity") @@ -49,6 +49,11 @@ public class ${ClassName} extends ${Entity} private $column.javaType $column.javaField; #end +#end +#if($table.sub) + /** $table.subTable.functionName信息 */ + private List<${subClassName}> ${subclassName}List; + #end #foreach ($column in $columns) #if(!$table.isSuperColumn($column.javaField)) @@ -69,6 +74,18 @@ public class ${ClassName} extends ${Entity} #end #end +#if($table.sub) + public List<${subClassName}> get${subClassName}List() + { + return ${subclassName}List; + } + + public void set${subClassName}List(List<${subClassName}> ${subclassName}List) + { + this.${subclassName}List = ${subclassName}List; + } + +#end @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) @@ -79,6 +96,9 @@ public class ${ClassName} extends ${Entity} #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #end .append("${column.javaField}", get${AttrName}()) +#end +#if($table.sub) + .append("${subclassName}List", get${subClassName}List()) #end .toString(); } diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm index 5502baf6..4c02b0f4 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/mapper.java.vm @@ -2,6 +2,9 @@ package ${packageName}.mapper; import java.util.List; import ${packageName}.domain.${ClassName}; +#if($table.sub) +import ${packageName}.domain.${subClassName}; +#end /** * ${functionName}Mapper接口 @@ -58,4 +61,31 @@ public interface ${ClassName}Mapper * @return 结果 */ public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); +#if($table.sub) + + /** + * 批量删除${subTable.functionName} + * + * @param customerIds 需要删除的数据ID + * @return 结果 + */ + public int delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaType}[] ${pkColumn.javaField}s); + + /** + * 批量新增${subTable.functionName} + * + * @param ${subclassName}List ${subTable.functionName}列表 + * @return 结果 + */ + public int batch${subClassName}(List<${subClassName}> ${subclassName}List); + + + /** + * 通过${functionName}ID删除${subTable.functionName}信息 + * + * @param roleId 角色ID + * @return 结果 + */ + public int delete${subClassName}By${subTableFkClassName}(${pkColumn.javaType} ${pkColumn.javaField}); +#end } diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm index f6cc71ce..2e928e03 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/serviceImpl.java.vm @@ -9,6 +9,12 @@ import com.ruoyi.common.core.utils.DateUtils; #end import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +#if($table.sub) +import java.util.ArrayList; +import com.ruoyi.common.core.utils.StringUtils; +import org.springframework.transaction.annotation.Transactional; +import ${packageName}.domain.${subClassName}; +#end import ${packageName}.mapper.${ClassName}Mapper; import ${packageName}.domain.${ClassName}; import ${packageName}.service.I${ClassName}Service; @@ -55,6 +61,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ${className} ${functionName} * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int insert${ClassName}(${ClassName} ${className}) { @@ -63,7 +72,13 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service ${className}.setCreateTime(DateUtils.getNowDate()); #end #end +#if($table.sub) + int rows = ${className}Mapper.insert${ClassName}(${className}); + insert${subClassName}(${className}); + return rows; +#else return ${className}Mapper.insert${ClassName}(${className}); +#end } /** @@ -72,6 +87,9 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ${className} ${functionName} * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int update${ClassName}(${ClassName} ${className}) { @@ -79,6 +97,10 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service #if($column.javaField == 'updateTime') ${className}.setUpdateTime(DateUtils.getNowDate()); #end +#end +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}()); + insert${subClassName}(${className}); #end return ${className}Mapper.update${ClassName}(${className}); } @@ -89,9 +111,15 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service * @param ${pkColumn.javaField}s 需要删除的${functionName}ID * @return 结果 */ +#if($table.sub) + @Transactional +#end @Override public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s); +#end return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); } @@ -104,6 +132,35 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service @Override public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) { +#if($table.sub) + ${className}Mapper.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField}); +#end return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); } +#if($table.sub) + + /** + * 新增${subTable.functionName}信息 + * + * @param ${className} ${functionName}对象 + */ + public void insert${subClassName}(${ClassName} ${className}) + { + List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List(); + Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}(); + if (StringUtils.isNotNull(${subclassName}List)) + { + List<${subClassName}> list = new ArrayList<${subClassName}>(); + for (${subClassName} ${subclassName} : ${subclassName}List) + { + ${subclassName}.set${subTableFkClassName}(${pkColumn.javaField}); + list.add(${subclassName}); + } + if (list.size() > 0) + { + ${className}Mapper.batch${subClassName}(list); + } + } + } +#end } diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/sub-domain.java.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/sub-domain.java.vm new file mode 100644 index 00000000..2e039ff6 --- /dev/null +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/sub-domain.java.vm @@ -0,0 +1,76 @@ +package ${packageName}.domain; + +#foreach ($import in $subImportList) +import ${import}; +#end +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.annotation.Excel; +import com.ruoyi.common.core.web.domain.BaseEntity; + +/** + * ${subTable.functionName}对象 ${subTableName} + * + * @author ${author} + * @date ${datetime} + */ +public class ${subClassName} extends BaseEntity +{ + private static final long serialVersionUID = 1L; + +#foreach ($column in $subTable.columns) +#if(!$table.isSuperColumn($column.javaField)) + /** $column.columnComment */ +#if($column.list) +#set($parentheseIndex=$column.columnComment.indexOf("(")) +#if($parentheseIndex != -1) +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) +#else +#set($comment=$column.columnComment) +#end +#if($parentheseIndex != -1) + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") +#elseif($column.javaType == 'Date') + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") +#else + @Excel(name = "${comment}") +#end +#end + private $column.javaType $column.javaField; + +#end +#end +#foreach ($column in $subTable.columns) +#if(!$table.isSuperColumn($column.javaField)) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + public void set${AttrName}($column.javaType $column.javaField) + { + this.$column.javaField = $column.javaField; + } + + public $column.javaType get${AttrName}() + { + return $column.javaField; + } +#end +#end + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) +#foreach ($column in $subTable.columns) +#if($column.javaField.length() > 2 && $column.javaField.substring(1,2).matches("[A-Z]")) +#set($AttrName=$column.javaField) +#else +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) +#end + .append("${column.javaField}", get${AttrName}()) +#end + .toString(); + } +} diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm index 9c31d0d6..d4c5e42f 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm @@ -64,7 +64,7 @@ #end #end - 搜索 + 搜索 重置 @@ -73,6 +73,7 @@ -#elseif($column.htmlType == "uploadImage") +#elseif($column.htmlType == "imageUpload") - + + +#elseif($column.htmlType == "fileUpload") + + #elseif($column.htmlType == "editor") @@ -243,8 +248,14 @@ import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${Busin import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; #foreach($column in $columns) -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") -import UploadImage from '@/components/UploadImage'; +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload") +import ImageUpload from '@/components/ImageUpload'; +#break +#end +#end +#foreach($column in $columns) +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload") +import FileUpload from '@/components/FileUpload'; #break #end #end @@ -259,8 +270,14 @@ export default { name: "${BusinessName}", components: { #foreach($column in $columns) -#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage") - UploadImage, +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload") + ImageUpload, +#break +#end +#end +#foreach($column in $columns) +#if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload") + FileUpload, #break #end #end diff --git a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm index ce24e371..d01c0799 100644 --- a/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm @@ -64,7 +64,7 @@ #end #end - 搜索 + 搜索 重置 @@ -73,6 +73,7 @@ -#elseif($column.htmlType == "uploadImage") +#elseif($column.htmlType == "imageUpload") - + + +#elseif($column.htmlType == "fileUpload") + + #elseif($column.htmlType == "editor") @@ -257,6 +265,38 @@ #end #end #end +#end +#if($table.sub) + ${subTable.functionName}信息 + + + 添加 + + + 删除 + + + + + +#foreach($column in $subTable.columns) +#set($javaField=$column.javaField) +#set($parentheseIndex=$column.columnComment.indexOf("(")) +#if($parentheseIndex != -1) +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) +#else +#set($comment=$column.columnComment) +#end +#if($column.pk || $javaField == ${subTableFkclassName}) +#elseif($column.list && "" != $javaField) + + + +#end +#end + #end + diff --git a/ruoyi-ui/src/layout/components/TagsView/index.vue b/ruoyi-ui/src/layout/components/TagsView/index.vue index dce967cf..c16a4c24 100644 --- a/ruoyi-ui/src/layout/components/TagsView/index.vue +++ b/ruoyi-ui/src/layout/components/TagsView/index.vue @@ -153,7 +153,7 @@ export default { }) }, closeOthersTags() { - this.$router.push(this.selectedTag) + this.$router.push(this.selectedTag).catch(()=>{}); this.$store.dispatch('tagsView/delOthersViews', this.selectedTag).then(() => { this.moveToCurrentTag() }) diff --git a/ruoyi-ui/src/layout/components/global.js b/ruoyi-ui/src/layout/components/global.js deleted file mode 100644 index 5d2b5b3e..00000000 --- a/ruoyi-ui/src/layout/components/global.js +++ /dev/null @@ -1,3 +0,0 @@ -import Vue from 'vue' -const global = new Vue() -export default global diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index 9d680d97..e81fda33 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -21,9 +21,6 @@ import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, import Pagination from "@/components/Pagination"; // 自定义表格工具扩展 import RightToolbar from "@/components/RightToolbar" -// 代码高亮插件 -import hljs from 'highlight.js' -import 'highlight.js/styles/github-gist.css' // 全局方法挂载 Vue.prototype.getDicts = getDicts @@ -53,7 +50,6 @@ Vue.component('Pagination', Pagination) Vue.component('RightToolbar', RightToolbar) Vue.use(permission) -Vue.use(hljs.vuePlugin); /** * If you don't want to use mock-server diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue index 6b2139ea..8ec1aca4 100644 --- a/ruoyi-ui/src/views/login.vue +++ b/ruoyi-ui/src/views/login.vue @@ -48,7 +48,7 @@ diff --git a/ruoyi-ui/src/views/monitor/job/index.vue b/ruoyi-ui/src/views/monitor/job/index.vue index 79821257..d11de4a9 100644 --- a/ruoyi-ui/src/views/monitor/job/index.vue +++ b/ruoyi-ui/src/views/monitor/job/index.vue @@ -31,7 +31,7 @@ - 搜索 + 搜索 重置 @@ -40,6 +40,7 @@ - 搜索 + 搜索 重置 @@ -65,6 +65,7 @@ - 搜索 + 搜索 重置 diff --git a/ruoyi-ui/src/views/system/config/index.vue b/ruoyi-ui/src/views/system/config/index.vue index 7c2f3e98..13c71133 100644 --- a/ruoyi-ui/src/views/system/config/index.vue +++ b/ruoyi-ui/src/views/system/config/index.vue @@ -44,7 +44,7 @@ > - 搜索 + 搜索 重置 @@ -53,6 +53,7 @@ - 搜索 + 搜索 重置 @@ -30,6 +30,7 @@ - 搜索 + 搜索 重置 @@ -40,6 +40,7 @@ - 搜索 + 搜索 重置 @@ -59,6 +59,7 @@ - 搜索 + 搜索 重置 @@ -59,6 +59,7 @@ - 搜索 + 搜索 重置 @@ -30,6 +30,7 @@ - 搜索 + 搜索 重置 @@ -39,6 +39,7 @@ - 搜索 + 搜索 重置 @@ -75,6 +75,7 @@ - 搜索 + 搜索 重置 @@ -39,6 +39,7 @@ - 搜索 + 搜索 重置 @@ -59,6 +59,7 @@ - 搜索 + 搜索 重置 @@ -86,6 +86,7 @@ 导出 - + - - - - - - + + + + + + - + @@ -413,6 +418,16 @@ export default { status: undefined, deptId: undefined }, + // 列信息 + columns: [ + { key: 0, label: `用户编号`, visible: true }, + { key: 1, label: `用户名称`, visible: true }, + { key: 2, label: `用户昵称`, visible: true }, + { key: 3, label: `部门`, visible: true }, + { key: 4, label: `手机号码`, visible: true }, + { key: 5, label: `状态`, visible: true }, + { key: 6, label: `创建时间`, visible: true } + ], // 表单校验 rules: { userName: [ diff --git a/ruoyi-ui/src/views/tool/gen/editTable.vue b/ruoyi-ui/src/views/tool/gen/editTable.vue index fea958e3..39071894 100644 --- a/ruoyi-ui/src/views/tool/gen/editTable.vue +++ b/ruoyi-ui/src/views/tool/gen/editTable.vue @@ -90,7 +90,8 @@ - + + @@ -112,7 +113,7 @@ - + @@ -143,6 +144,8 @@ export default { activeName: "cloum", // 表格的高度 tableHeight: document.documentElement.scrollHeight - 245 + "px", + // 表信息 + tables: [], // 表列信息 cloumns: [], // 字典信息 @@ -160,6 +163,7 @@ export default { getGenTable(tableId).then(res => { this.cloumns = res.data.rows; this.info = res.data.info; + this.tables = res.data.tables; }); /** 查询字典下拉列表 */ getDictOptionselect().then(response => { diff --git a/ruoyi-ui/src/views/tool/gen/genInfoForm.vue b/ruoyi-ui/src/views/tool/gen/genInfoForm.vue index f09cf7c9..926376c9 100644 --- a/ruoyi-ui/src/views/tool/gen/genInfoForm.vue +++ b/ruoyi-ui/src/views/tool/gen/genInfoForm.vue @@ -4,9 +4,10 @@ 生成模板 - + + @@ -126,8 +127,8 @@ @@ -144,8 +145,8 @@ @@ -162,8 +163,47 @@ + + + + + +

关联信息

+ + + + 关联子表的表名 + + + + + + + + + + + + + 子表关联的外键名 + + + + + + @@ -185,6 +225,10 @@ export default { type: Object, default: null }, + tables: { + type: Array, + default: null + }, menus: { type: Array, default: [] @@ -192,6 +236,7 @@ export default { }, data() { return { + subColumns: [], rules: { tplCategory: [ { required: true, message: "请选择生成模板", trigger: "blur" } @@ -207,11 +252,16 @@ export default { ], functionName: [ { required: true, message: "请输入生成功能名", trigger: "blur" } - ] + ], } }; }, created() {}, + watch: { + 'info.subTableName': function(val) { + this.setSubTableColumns(val); + } + }, methods: { /** 转换菜单数据结构 */ normalizer(node) { @@ -223,6 +273,27 @@ export default { label: node.menuName, children: node.children }; + }, + /** 选择子表名触发 */ + subSelectChange(value) { + this.info.subTableFkName = ''; + }, + /** 选择生成模板触发 */ + tplSelectChange(value) { + if(value !== 'sub') { + this.info.subTableName = ''; + this.info.subTableFkName = ''; + } + }, + /** 设置关联外键 */ + setSubTableColumns(value) { + for (var item in this.tables) { + const name = this.tables[item].tableName; + if (value === name) { + this.subColumns = this.tables[item].columns; + break; + } + } } } }; diff --git a/ruoyi-ui/src/views/tool/gen/index.vue b/ruoyi-ui/src/views/tool/gen/index.vue index 23594914..cc3a1082 100644 --- a/ruoyi-ui/src/views/tool/gen/index.vue +++ b/ruoyi-ui/src/views/tool/gen/index.vue @@ -32,7 +32,7 @@ > - 搜索 + 搜索 重置 @@ -41,6 +41,7 @@ - +