diff --git a/pom.xml b/pom.xml index 0805663..efc68bd 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,6 @@ 0.9.1 6.0.0 32.1.1-jre - 1.5.0 2.3.0 2.3.0 0.15.0 @@ -63,7 +62,7 @@ 3.2.2 3.11.0 3.1.2 - 1.3.0 + 1.5.0 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java index c522d26..6c3b286 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java @@ -2,13 +2,14 @@ package com.ruoyi; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration; /** * 启动程序 * * @author ruoyi */ -@SpringBootApplication +@SpringBootApplication(exclude = SpringDataWebAutoConfiguration.class) public class RuoYiApplication { public static void main(String[] args) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 325da9b..d54d155 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -39,21 +39,6 @@ mybatis-flex: username: postgres password: postgres@369 -# # 数据源-2 -# ds2: -# # 指定为HikariDataSource -# type: ${spring.datasource.type} -# # mysql数据库 -# driver-class-name: com.mysql.cj.jdbc.Driver -# url: jdbc:mysql://localhost:3306/ruoyi-flex?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true -# username: root -# password: Root@369 -# #postgresql数据库 -## driver-class-name: org.postgresql.Driver -## url: jdbc:postgresql://localhost:5432/ruoyi-flex?useUnicode=true&characterEncoding=utf8&useSSL=true&autoReconnect=true&reWriteBatchedInserts=true -## username: postgres -## password: postgres@369 - # redis 单机配置(单机与集群只能开启一个另一个需要注释掉) spring.data: redis: diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/CustomerController.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/CustomerController.java index 1b1b28a..650d67d 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/CustomerController.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/CustomerController.java @@ -3,7 +3,6 @@ package com.ruoyi.mf.controller; import java.util.List; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfProductController.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfProductController.java index 5fe6b4c..1917de3 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfProductController.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfProductController.java @@ -3,7 +3,6 @@ package com.ruoyi.mf.controller; import java.util.List; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfStudentController.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfStudentController.java index 0cc85a6..41a196e 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfStudentController.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/controller/MfStudentController.java @@ -3,7 +3,6 @@ package com.ruoyi.mf.controller; import java.util.List; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/CustomerServiceImpl.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/CustomerServiceImpl.java index b02349e..e0c1154 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/CustomerServiceImpl.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/CustomerServiceImpl.java @@ -2,7 +2,6 @@ package com.ruoyi.mf.service.impl; import java.util.Arrays; import java.util.List; -import java.util.Map; import cn.hutool.core.util.ObjectUtil; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; @@ -12,12 +11,10 @@ import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.orm.core.page.PageQuery; import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; -import com.ruoyi.common.core.utils.DateUtils; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; -import java.util.Arrays; import com.ruoyi.mf.domain.Goods; import com.ruoyi.mf.mapper.GoodsMapper; import static com.ruoyi.mf.domain.table.GoodsTableDef.GOODS; diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfProductServiceImpl.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfProductServiceImpl.java index d9a737c..3e9dd91 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfProductServiceImpl.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfProductServiceImpl.java @@ -2,16 +2,10 @@ package com.ruoyi.mf.service.impl; import java.util.Arrays; import java.util.List; -import java.util.Map; import cn.hutool.core.util.ObjectUtil; -import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.ruoyi.common.core.utils.MapstructUtils; -import com.ruoyi.common.core.utils.StringUtils; -import com.ruoyi.common.orm.core.page.PageQuery; -import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; -import com.ruoyi.common.core.utils.DateUtils; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfStudentServiceImpl.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfStudentServiceImpl.java index 362f912..b881f55 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfStudentServiceImpl.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/mf/service/impl/MfStudentServiceImpl.java @@ -2,17 +2,13 @@ package com.ruoyi.mf.service.impl; import java.util.Arrays; import java.util.List; -import java.util.Map; import cn.hutool.core.util.ObjectUtil; -import com.mybatisflex.annotation.UseDataSource; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.ruoyi.common.core.utils.MapstructUtils; -import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.orm.core.page.PageQuery; import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; -import com.ruoyi.common.core.utils.DateUtils; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -80,7 +76,6 @@ public class MfStudentServiceImpl extends BaseServiceImpl selectPage(MfStudentBo mfStudentBo) { diff --git a/ruoyi-modules/ruoyi-generator/pom.xml b/ruoyi-modules/ruoyi-generator/pom.xml index 921c40c..2110d6f 100644 --- a/ruoyi-modules/ruoyi-generator/pom.xml +++ b/ruoyi-modules/ruoyi-generator/pom.xml @@ -36,6 +36,11 @@ ruoyi-common-core + + com.ruoyi + ruoyi-common-log + + com.ruoyi ruoyi-common-web diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java index c0c8de8..9c37935 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/controller/GenController.java @@ -6,21 +6,16 @@ import java.util.List; import java.util.Map; import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.io.IoUtil; +import com.ruoyi.common.core.core.domain.R; +import com.ruoyi.common.log.annotation.Log; +import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.orm.core.page.TableDataInfo; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; -import org.apache.commons.io.IOUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.ruoyi.common.web.core.BaseController; -import com.ruoyi.common.core.core.domain.AjaxResult; import com.ruoyi.common.core.core.text.Convert; import com.ruoyi.generator.domain.GenTable; import com.ruoyi.generator.domain.GenTableColumn; @@ -36,8 +31,7 @@ import com.ruoyi.generator.service.IGenTableService; @Validated @RestController @RequestMapping("/tool/gen") -public class GenController extends BaseController -{ +public class GenController extends BaseController { @Resource private IGenTableService genTableService; @@ -49,8 +43,7 @@ public class GenController extends BaseController */ @SaCheckPermission("tool:gen:list") @GetMapping("/list") - public TableDataInfo genList(GenTable genTable) - { + public TableDataInfo genList(GenTable genTable) { return genTableService.selectPage(genTable); } @@ -59,17 +52,15 @@ public class GenController extends BaseController */ @SaCheckPermission("tool:gen:query") @GetMapping(value = "/{tableId}") - public AjaxResult getInfo(@PathVariable Long tableId) - { + public R> getInfo(@PathVariable Long tableId) { GenTable table = genTableService.selectGenTableById(tableId); List tables = genTableService.selectGenTableAll(); List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); - //table.setColumns(list); - Map map = new HashMap<>(); + Map map = new HashMap<>(3); map.put("info", table); map.put("rows", list); map.put("tables", tables); - return success(map); + return R.ok(map); } /** @@ -77,8 +68,7 @@ public class GenController extends BaseController */ @SaCheckPermission("tool:gen:list") @GetMapping("/db/list") - public TableDataInfo dataList(GenTable genTable) - { + public TableDataInfo dataList(GenTable genTable) { startPage(); List list = genTableService.selectDbTableList(genTable); return getDataTable(list); @@ -89,9 +79,8 @@ public class GenController extends BaseController */ @SaCheckPermission("tool:gen:list") @GetMapping(value = "/column/{tableId}") - public TableDataInfo columnList(@PathVariable("tableId") Long tableId) - { - TableDataInfo dataInfo = new TableDataInfo(); + public TableDataInfo columnList(@PathVariable("tableId") Long tableId) { + TableDataInfo dataInfo = new TableDataInfo<>(); List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); dataInfo.setRows(list); dataInfo.setTotal(list.size()); @@ -102,106 +91,104 @@ public class GenController extends BaseController * 导入表结构(保存) */ @SaCheckPermission("tool:gen:import") + @Log(title = "代码生成", businessType = BusinessType.IMPORT) @PostMapping("/importTable") - public AjaxResult importTableSave(String tables) - { + public R importTableSave(String tables) { String[] tableNames = Convert.toStrArray(tables); // 查询表信息 List tableList = genTableService.selectDbTableListByNames(tableNames); genTableService.importGenTable(tableList); - return success(); + return R.ok(); } /** * 修改保存代码生成业务 */ @SaCheckPermission("tool:gen:edit") + @Log(title = "代码生成", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult editSave(@Validated @RequestBody GenTable genTable) - { + public R editSave(@Validated @RequestBody GenTable genTable) { genTableService.validateEdit(genTable); genTableService.updateGenTable(genTable); - return success(); + return R.ok(); } /** * 删除代码生成 */ @SaCheckPermission("tool:gen:remove") + @Log(title = "代码生成", businessType = BusinessType.DELETE) @DeleteMapping("/{tableIds}") - public AjaxResult remove(@PathVariable Long[] tableIds) - { + public R remove(@PathVariable Long[] tableIds) { genTableService.deleteGenTableByIds(tableIds); - return success(); + return R.ok(); } /** - * 预览代码 + * 预览代码,前端界面类型frontType取值:0是element-js、1是element-ts、2是antdesign-ts */ @SaCheckPermission("tool:gen:preview") - @GetMapping("/preview/{tableId}") - public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException - { - Map dataMap = genTableService.previewCode(tableId); - return success(dataMap); + @GetMapping("/preview") + public R> preview(Long tableId, Integer frontType) throws IOException { + Map dataMap = genTableService.previewCode(tableId, frontType); + return R.ok(dataMap); } - /** - * 生成代码(下载方式) - */ - @SaCheckPermission("tool:gen:code") - @GetMapping("/download/{tableName}") - public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException - { - byte[] data = genTableService.downloadCode(tableName); - genCode(response, data); - } +// /** +// * 生成代码(下载方式) +// */ +// @SaCheckPermission("tool:gen:code") +// @Log(title = "代码生成", businessType = BusinessType.GENCODE) +// @GetMapping("/download/{tableId}") +// public void download(HttpServletResponse response, @PathVariable("tableId") Long tableId) throws IOException { +// byte[] data = genTableService.downloadCode(tableId); +// genCode(response, data); +// } /** - * 生成代码(自定义路径) + * 生成代码(自定义路径),前端界面类型frontType取值:0是element-js、1是element-ts、2是antdesign-ts */ @SaCheckPermission("tool:gen:code") - @GetMapping("/genCode/{tableName}") - public AjaxResult genCode(@PathVariable("tableName") String tableName) - { - genTableService.generatorCode(tableName); - return success(); + @Log(title = "代码生成", businessType = BusinessType.GENCODE) + @GetMapping("/genCode") + public R genCode(Long tableId, Integer frontType) { + genTableService.generatorCode(tableId, frontType); + return R.ok(); } /** * 同步数据库 */ @SaCheckPermission("tool:gen:edit") - @GetMapping("/synchDb/{tableName}") - public AjaxResult synchDb(@PathVariable("tableName") String tableName) - { - genTableService.synchDb(tableName); - return success(); + @Log(title = "代码生成", businessType = BusinessType.UPDATE) + @GetMapping("/synchDb/{tableId}") + public R synchDb(@PathVariable("tableId") Long tableId) { + genTableService.synchDb(tableId); + return R.ok(); } /** * 批量生成代码 */ @SaCheckPermission("tool:gen:code") + @Log(title = "代码生成", businessType = BusinessType.GENCODE) @GetMapping("/batchGenCode") - public void batchGenCode(HttpServletResponse response, String tables) throws IOException - { - String[] tableNames = Convert.toStrArray(tables); - byte[] data = genTableService.downloadCode(tableNames); + public void batchGenCode(HttpServletResponse response, String tableIdStr, Integer frontType) throws IOException { + String[] tableIds = Convert.toStrArray(tableIdStr); + byte[] data = genTableService.downloadCode(tableIds, frontType); genCode(response, data); } /** * 生成zip文件 */ - private void genCode(HttpServletResponse response, byte[] data) throws IOException - { + private void genCode(HttpServletResponse response, byte[] data) throws IOException { response.reset(); response.addHeader("Access-Control-Allow-Origin", "*"); response.addHeader("Access-Control-Expose-Headers", "Content-Disposition"); response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi-flex.zip\""); response.addHeader("Content-Length", "" + data.length); response.setContentType("application/octet-stream; charset=UTF-8"); - IOUtils.write(data, response.getOutputStream()); + IoUtil.write(response.getOutputStream(), false, data); } } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java index ca5ce02..a7e076e 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java @@ -11,10 +11,12 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.RelationOneToMany; import com.mybatisflex.annotation.Table; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import lombok.Data; +import lombok.EqualsAndHashCode; import org.apache.commons.lang3.ArrayUtils; import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.utils.StringUtils; @@ -36,6 +38,12 @@ public class GenTable implements Serializable @Id private Long tableId; + /** + * 数据源名称 + */ + @NotBlank(message = "数据源名称不能为空") + private String datasourceName; + /** 表名称 */ @NotBlank(message = "表名称不能为空") private String tableName; @@ -92,6 +100,8 @@ public class GenTable implements Serializable /** 表列信息 */ @Valid + @Column(ignore = true) + @RelationOneToMany(selfField = "tableId", targetField = "tableId",orderBy = "sort") private List columns; /** 其它生成选项 */ @@ -112,6 +122,7 @@ public class GenTable implements Serializable /* * 菜单id列表 */ + @Column(ignore = true) private List menuIds; /** 上级菜单ID字段 */ diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java index 5abcc5d..28984dd 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTableColumn.java @@ -190,7 +190,7 @@ public class GenTableColumn implements Serializable { return StringUtils.equalsAnyIgnoreCase(javaField, // BaseEntity - "createBy", "createTime", "updateBy", "updateTime", + "version","createBy", "createTime", "updateBy", "updateTime", // TreeEntity "parentName", "parentId", "orderNum", "ancestors"); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java index 16c90f7..0b208e6 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableColumnMapper.java @@ -23,14 +23,6 @@ public interface GenTableColumnMapper extends BaseMapper */ List selectDbTableColumnsByName(String tableName); - /** - * 删除业务字段 - * - * @param genTableColumns 列数据 - * @return 结果 - */ - int deleteGenTableColumns(List genTableColumns); - /** * 批量删除业务字段 * diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java index a4787fb..7636ec7 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/GenTableMapper.java @@ -31,8 +31,6 @@ public interface GenTableMapper extends BaseMapper */ List selectDbTableListByNames(String[] tableNames); - - /** * 查询表名称业务信息 * diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java index fc7f783..acb0c30 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableColumnServiceImpl.java @@ -40,8 +40,7 @@ public class GenTableColumnServiceImpl extends BaseServiceImpl selectGenTableColumnListByTableId(Long tableId) { - QueryWrapper queryWrapper = QueryWrapper.create() - .from(GEN_TABLE_COLUMN) + QueryWrapper queryWrapper = query() .where(GEN_TABLE_COLUMN.TABLE_ID.eq(tableId)) .orderBy(GEN_TABLE_COLUMN.SORT.asc()); return this.list(queryWrapper); diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java index 20d9729..ce74934 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java @@ -1,25 +1,29 @@ package com.ruoyi.generator.service; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import com.mybatisflex.core.FlexGlobalConfig; -import com.mybatisflex.core.dialect.DbType; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.ObjectUtil; +import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryMethods; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.row.Db; +import com.mybatisflex.core.BaseMapper; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.core.utils.StreamUtils; +import com.ruoyi.common.core.utils.file.FileUtils; import com.ruoyi.common.orm.core.page.PageQuery; import com.ruoyi.common.orm.core.page.TableDataInfo; import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; import com.ruoyi.common.security.utils.LoginHelper; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; @@ -30,7 +34,6 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.GenConstants; -import com.ruoyi.common.core.core.text.CharsetKit; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.generator.domain.GenTable; @@ -51,16 +54,12 @@ import static com.ruoyi.generator.domain.table.GenTableTableDef.GEN_TABLE; */ @Slf4j @Service -public class GenTableServiceImpl extends BaseServiceImpl implements IGenTableService -{ +public class GenTableServiceImpl extends BaseServiceImpl implements IGenTableService { @Resource private GenTableMapper genTableMapper; @Resource private GenTableColumnMapper genTableColumnMapper; - @Resource - private IGenTableColumnService genTableColumnService; - @Override public QueryWrapper query() { return super.query().from(GEN_TABLE); @@ -79,6 +78,7 @@ public class GenTableServiceImpl extends BaseServiceImpl selectPage(GenTable genTable) - { + public TableDataInfo selectPage(GenTable genTable) { QueryWrapper queryWrapper = buildQueryWrapper(genTable); Page page = this.pageAs(PageQuery.build(), queryWrapper, GenTable.class); return TableDataInfo.build(page); @@ -127,20 +120,18 @@ public class GenTableServiceImpl extends BaseServiceImpl selectDbTableList(GenTable genTable) - { + public List selectDbTableList(GenTable genTable) { return genTableMapper.selectDbTableList(genTable); } /** * 查询据库列表 * - * @param tableNames 表名称组 + * @param tableNames 表名称组 * @return 数据库表集合 */ @Override - public List selectDbTableListByNames(String[] tableNames) - { + public List selectDbTableListByNames(String[] tableNames) { return genTableMapper.selectDbTableListByNames(tableNames); } @@ -150,10 +141,8 @@ public class GenTableServiceImpl extends BaseServiceImpl selectGenTableAll() - { - QueryWrapper queryWrapper = QueryWrapper.create() - .from(GEN_TABLE) + public List selectGenTableAll() { + QueryWrapper queryWrapper = query() .leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID)) .orderBy(GEN_TABLE_COLUMN.SORT.asc()); return this.list(queryWrapper); @@ -163,12 +152,11 @@ public class GenTableServiceImpl extends BaseServiceImpl tableList) - { - try - { - for (GenTable table : tableList) - { + public void importGenTable(List tableList) { + try { + for (GenTable table : tableList) { String tableName = table.getTableName(); GenUtils.initTable(table); @@ -228,24 +210,27 @@ public class GenTableServiceImpl extends BaseServiceImpl genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); + List saveColumns = new ArrayList<>(); for (GenTableColumn column : genTableColumns) { GenUtils.initColumnField(column, table); + column.setCreateBy(loginUserId); column.setCreateTime(createTime); column.setUpdateBy(loginUserId); column.setUpdateTime(createTime); - genTableColumnMapper.insertSelective(column); + + saveColumns.add(column); + } + if (CollUtil.isNotEmpty(saveColumns)) { + genTableColumnMapper.insertBatch(saveColumns); } } } - } - catch (Exception e) - { + } catch (Exception e) { throw new ServiceException("导入失败:" + e.getMessage()); } } @@ -253,17 +238,15 @@ public class GenTableServiceImpl extends BaseServiceImpl previewCode(Long tableId) - { + public Map previewCode(Long tableId, Integer frontType) { Map dataMap = new LinkedHashMap<>(); // 查询表信息 GenTable table = selectGenTableById(tableId); - List list = genTableColumnService.selectGenTableColumnListByTableId(tableId); - table.setColumns(list); //设置生成的sys_menu6条记录的主键值 setMenuIds(table); @@ -276,9 +259,8 @@ public class GenTableServiceImpl extends BaseServiceImpl templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { + List templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType); + for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); @@ -291,31 +273,29 @@ public class GenTableServiceImpl extends BaseServiceImpl list = genTableColumnService.selectGenTableColumnListByTableId(table.getTableId()); - table.setColumns(list); + //GenTable table = genTableMapper.selectGenTableByName(tableName); + GenTable table = genTableMapper.selectOneWithRelationsById(tableId); // 设置主子表信息 setSubTable(table); //设置生成的sys_menu6条记录的主键值 @@ -328,22 +308,17 @@ public class GenTableServiceImpl extends BaseServiceImpl templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { - if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) - { + List templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType); + for (String template : templates) { + if (!StringUtils.containsAny(template, "sql.vm", "element.js.api.vm", "element.js.index.vue.vm", "element.js.index-tree.vue.vm")) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try - { + try { String path = getGenPath(table, template); - FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8); - } - catch (IOException e) - { + FileUtils.writeUtf8String(sw.toString(), path); + } catch (Exception e) { throw new ServiceException("渲染模板失败,表名:" + table.getTableName()); } } @@ -353,82 +328,80 @@ public class GenTableServiceImpl extends BaseServiceImpl tableColumns = table.getColumns(); - Map tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity())); + Map tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName); - List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); - if (StringUtils.isEmpty(dbTableColumns)) - { + List dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getTableName()); + if (CollUtil.isEmpty(dbTableColumns)) { throw new ServiceException("同步数据失败,原表结构不存在"); } - List dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList()); + List dbTableColumnNames = StreamUtils.toList(dbTableColumns, GenTableColumn::getColumnName); + List saveColumns = new ArrayList<>(); dbTableColumns.forEach(column -> { GenUtils.initColumnField(column, table); - if (tableColumnMap.containsKey(column.getColumnName())) - { + if (tableColumnMap.containsKey(column.getColumnName())) { GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName()); column.setColumnId(prevColumn.getColumnId()); - if (column.isList()) - { + if (column.isList()) { // 如果是列表,继续保留查询方式/字典类型选项 column.setDictType(prevColumn.getDictType()); column.setQueryType(prevColumn.getQueryType()); } if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() - && (column.isInsert() || column.isEdit()) - && ((column.isUsableColumn()) || (!column.isSuperColumn()))) - { + && (column.isInsert() || column.isEdit()) + && ((column.isUsableColumn()) || (!column.isSuperColumn()))) { // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 column.setIsRequired(prevColumn.getIsRequired()); column.setHtmlType(prevColumn.getHtmlType()); } + column.setVersion(prevColumn.getVersion()); column.setUpdateBy(loginUserId); column.setUpdateTime(createTime); - genTableColumnMapper.update(column); - } - else - { + } else { + column.setVersion(0); column.setCreateBy(loginUserId); column.setCreateTime(createTime); column.setUpdateBy(loginUserId); column.setUpdateTime(createTime); - - genTableColumnMapper.insertSelective(column); } + saveColumns.add(column); }); + if (CollUtil.isNotEmpty(saveColumns)) { + Db.executeBatch(saveColumns, 500, GenTableColumnMapper.class, BaseMapper::insertOrUpdate); + } - List delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList()); - if (StringUtils.isNotEmpty(delColumns)) - { - genTableColumnMapper.deleteGenTableColumns(delColumns); + List delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName())); + if (CollUtil.isNotEmpty(delColumns)) { + List ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId); + if (CollUtil.isNotEmpty(ids)) { + genTableColumnMapper.deleteBatchByIds(ids); + } } } /** * 批量生成代码(下载方式) * - * @param tableNames 表数组 + * @param tableIds 表ids + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts * @return 数据 */ @Override - public byte[] downloadCode(String[] tableNames) - { + public byte[] downloadCode(String[] tableIds, Integer frontType) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(outputStream); - for (String tableName : tableNames) - { - generatorCode(tableName, zip); + for (String tableId : tableIds) { + generatorCode(Long.parseLong(tableId), zip, frontType); } IOUtils.closeQuietly(zip); return outputStream.toByteArray(); @@ -437,12 +410,9 @@ public class GenTableServiceImpl extends BaseServiceImpl list = genTableColumnService.selectGenTableColumnListByTableId(table.getTableId()); - table.setColumns(list); + GenTable table = genTableMapper.selectOneWithRelationsById(tableId); // 设置主子表信息 setSubTable(table); //设置生成的sys_menu6条记录的主键值 @@ -455,24 +425,20 @@ public class GenTableServiceImpl extends BaseServiceImpl templates = VelocityUtils.getTemplateList(table.getTplCategory()); - for (String template : templates) - { + List templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType); + for (String template : templates) { // 渲染模板 StringWriter sw = new StringWriter(); Template tpl = Velocity.getTemplate(template, Constants.UTF8); tpl.merge(context, sw); - try - { + try { // 添加到zip zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); - IOUtils.write(sw.toString(), zip, Constants.UTF8); - IOUtils.closeQuietly(sw); + IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString()); + IoUtil.close(sw); zip.flush(); zip.closeEntry(); - } - catch (IOException e) - { + } catch (IOException e) { log.error("渲染模板失败,表名:" + table.getTableName(), e); } } @@ -484,32 +450,20 @@ public class GenTableServiceImpl extends BaseServiceImpl menuIds = new ArrayList<>(); for (int i = 0; i < 6; i++) { - menuIds.add(Long.valueOf(nowStr+"0"+i)); + menuIds.add(Long.valueOf(nowStr + "0" + i)); } table.setMenuIds(menuIds); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java index 922f0b4..cf112f9 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/service/IGenTableService.java @@ -13,15 +13,14 @@ import com.ruoyi.generator.domain.GenTable; * @author ruoyi * @author 数据小王子 */ -public interface IGenTableService extends IBaseService -{ +public interface IGenTableService extends IBaseService { /** * 查询据库列表 * * @param genTable 业务信息 * @return 数据库表集合 */ - public List selectDbTableList(GenTable genTable); + List selectDbTableList(GenTable genTable); /** * 分页查询业务列表 @@ -37,14 +36,14 @@ public interface IGenTableService extends IBaseService * @param tableNames 表名称组 * @return 数据库表集合 */ - public List selectDbTableListByNames(String[] tableNames); + List selectDbTableListByNames(String[] tableNames); /** * 查询所有表信息 * * @return 表信息集合 */ - public List selectGenTableAll(); + List selectGenTableAll(); /** * 查询业务信息 @@ -52,7 +51,7 @@ public interface IGenTableService extends IBaseService * @param id 业务ID * @return 业务信息 */ - public GenTable selectGenTableById(Long id); + GenTable selectGenTableById(Long id); /** * 修改业务 @@ -60,7 +59,7 @@ public interface IGenTableService extends IBaseService * @param genTable 业务信息 * @return 结果 */ - public void updateGenTable(GenTable genTable); + void updateGenTable(GenTable genTable); /** * 删除业务信息 @@ -68,58 +67,62 @@ public interface IGenTableService extends IBaseService * @param tableIds 需要删除的表数据ID * @return 结果 */ - public void deleteGenTableByIds(Long[] tableIds); + void deleteGenTableByIds(Long[] tableIds); /** * 导入表结构 * * @param tableList 导入表列表 */ - public void importGenTable(List tableList); + void importGenTable(List tableList); /** * 预览代码 * * @param tableId 表编号 + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts * @return 预览数据列表 */ - public Map previewCode(Long tableId); - - /** - * 生成代码(下载方式) - * - * @param tableName 表名称 - * @return 数据 - */ - public byte[] downloadCode(String tableName); + Map previewCode(Long tableId, Integer frontType); /** * 生成代码(自定义路径) * - * @param tableName 表名称 + * @param tableId 表ID + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts * @return 数据 */ - public void generatorCode(String tableName); + void generatorCode(Long tableId, Integer frontType); /** * 同步数据库 * - * @param tableName 表名称 + * @param tableId 表ID */ - public void synchDb(String tableName); + void synchDb(Long tableId); + + /** + * 生成代码(下载方式) + * + * @param tableId 表名称 + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts + * @return 数据 + */ + byte[] downloadCode(Long tableId, Integer frontType); /** * 批量生成代码(下载方式) * - * @param tableNames 表数组 + * @param tableIds 表ID数组 + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts * @return 数据 */ - public byte[] downloadCode(String[] tableNames); + byte[] downloadCode(String[] tableIds, Integer frontType); /** * 修改保存参数校验 * * @param genTable 业务信息 */ - public void validateEdit(GenTable genTable); + void validateEdit(GenTable genTable); } diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java index a631fe4..90b085b 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.Set; import cn.hutool.core.collection.CollUtil; -import com.mybatisflex.core.datasource.FlexDataSource; -import com.mybatisflex.core.dialect.DbTypeUtil; import com.ruoyi.common.orm.helper.DataBaseHelper; import org.apache.velocity.VelocityContext; import com.alibaba.fastjson2.JSON; @@ -24,15 +22,20 @@ import com.ruoyi.generator.domain.GenTableColumn; * @author ruoyi * @author 数据小王子 */ -public class VelocityUtils -{ - /** 项目空间路径 */ +public class VelocityUtils { + /** + * 项目空间路径 + */ private static final String PROJECT_PATH = "main/java"; - /** mybatis空间路径 */ + /** + * mybatis空间路径 + */ private static final String MYBATIS_PATH = "main/resources/mapper"; - /** 默认上级菜单,系统工具 */ + /** + * 默认上级菜单,系统工具 + */ private static final String DEFAULT_PARENT_MENU_ID = "3"; /** @@ -40,8 +43,7 @@ public class VelocityUtils * * @return 模板列表 */ - public static VelocityContext prepareContext(GenTable genTable) - { + public static VelocityContext prepareContext(GenTable genTable) { String moduleName = genTable.getModuleName(); String businessName = genTable.getBusinessName(); String packageName = genTable.getPackageName(); @@ -69,27 +71,23 @@ public class VelocityUtils velocityContext.put("table", genTable); velocityContext.put("dicts", getDicts(genTable)); setMenuVelocityContext(velocityContext, genTable); - if (GenConstants.TPL_TREE.equals(tplCategory)) - { + if (GenConstants.TPL_TREE.equals(tplCategory)) { setTreeVelocityContext(velocityContext, genTable); } - if (GenConstants.TPL_SUB.equals(tplCategory)) - { + if (GenConstants.TPL_SUB.equals(tplCategory)) { setSubVelocityContext(velocityContext, genTable); } return velocityContext; } - public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) - { + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); JSONObject paramsObj = JSON.parseObject(options); String parentMenuId = getParentMenuId(paramsObj); context.put("parentMenuId", parentMenuId); } - public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) - { + public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { String options = genTable.getOptions(); JSONObject paramsObj = JSON.parseObject(options); String treeCode = getTreecode(paramsObj); @@ -100,18 +98,15 @@ public class VelocityUtils context.put("treeParentCode", treeParentCode); context.put("treeName", treeName); context.put("expandColumn", getExpandColumn(genTable)); - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) - { + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); } - if (paramsObj.containsKey(GenConstants.TREE_NAME)) - { + if (paramsObj.containsKey(GenConstants.TREE_NAME)) { context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); } } - public static void setSubVelocityContext(VelocityContext context, GenTable genTable) - { + public static void setSubVelocityContext(VelocityContext context, GenTable genTable) { GenTable subTable = genTable.getSubTable(); String subTableName = genTable.getSubTableName(); String subTableFkName = genTable.getSubTableFkName(); @@ -133,10 +128,11 @@ public class VelocityUtils /** * 获取模板信息 * + * @param tplCategory 单表、树表、主子表 + * @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts * @return 模板列表 */ - public static List getTemplateList(String tplCategory) - { + public static List getTemplateList(String tplCategory, Integer frontType) { List templates = new ArrayList<>(); templates.add("vm/java/domain.java.vm"); templates.add("vm/java/vo.java.vm"); @@ -151,30 +147,62 @@ public class VelocityUtils } else { templates.add("vm/sql/mysql/sql.vm"); } - templates.add("vm/js/api.js.vm"); - if (GenConstants.TPL_CRUD.equals(tplCategory)) - { - templates.add("vm/vue/index.vue.vm"); + + switch (frontType) { + case 0 -> templates.add("vm/api/element.js.api.vm"); + case 1 -> { + templates.add("vm/api/element.ts.api.vm"); + templates.add("vm/api/element.ts.types.vm"); + } + case 2 -> { + templates.add("vm/api/antdesign.ts.index.vm"); + templates.add("vm/api/antdesign.ts.model.vm"); + } } - else if (GenConstants.TPL_TREE.equals(tplCategory)) - { - templates.add("vm/vue/index-tree.vue.vm"); - } - else if (GenConstants.TPL_SUB.equals(tplCategory)) - { - templates.add("vm/vue/index.vue.vm"); + + if (GenConstants.TPL_CRUD.equals(tplCategory)) { + switch (frontType) { + case 0 -> templates.add("vm/vue/element.js.index.vue.vm"); + case 1 -> templates.add("vm/vue/element.ts.index.vue.vm"); + case 2 -> { + templates.add("vm/vue/antdesign.ts.data.vm"); + templates.add("vm/vue/antdesign.ts.index.vue.vm"); + templates.add("vm/vue/antdesign.ts.modal.vue.vm"); + } + } + } else if (GenConstants.TPL_TREE.equals(tplCategory)) { + switch (frontType) { + case 0 -> templates.add("vm/vue/element.js.index-tree.vue.vm"); + case 1 -> templates.add("vm/vue/element.ts.index-tree.vue.vm"); + case 2 -> { + templates.add("vm/vue/antdesign.ts.data.vm"); + templates.add("vm/vue/antdesign.ts.index.vue.vm"); + templates.add("vm/vue/antdesign.ts.modal.vue.vm"); + } + } + + } else if (GenConstants.TPL_SUB.equals(tplCategory)) { templates.add("vm/java/sub-domain.java.vm"); templates.add("vm/java/sub-mapper.java.vm"); templates.add("vm/xml/sub-mapper.xml.vm"); + switch (frontType) { + case 0 -> templates.add("vm/vue/element.js.index.vue.vm"); + case 1 -> templates.add("vm/vue/element.ts.index.vue.vm"); + case 2 -> { + templates.add("vm/vue/antdesign.ts.data.vm"); + templates.add("vm/vue/antdesign.ts.index.vue.vm"); + templates.add("vm/vue/antdesign.ts.modal.vue.vm"); + } + } } + return templates; } /** * 获取文件名 */ - public static String getFileName(String template, GenTable genTable) - { + public static String getFileName(String template, GenTable genTable) { // 文件名称 String fileName = ""; // 包路径 @@ -189,25 +217,54 @@ public class VelocityUtils String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); String mybatisPath = MYBATIS_PATH + "/" + moduleName; String vuePath = "vue"; + String vbenPath = "vben"; + String BusinessName = StringUtils.capitalize(genTable.getBusinessName()); - switch (template) - { + switch (template) { case "vm/java/domain.java.vm" -> fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); - case "vm/java/sub-domain.java.vm" -> fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); + case "vm/java/sub-domain.java.vm" -> + fileName = StringUtils.format("{}/domain/{}.java", javaPath, genTable.getSubTable().getClassName()); case "vm/java/vo.java.vm" -> fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className); case "vm/java/bo.java.vm" -> fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className); - case "vm/java/mapper.java.vm" -> fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); - case "vm/java/sub-mapper.java.vm" -> fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, genTable.getSubTable().getClassName()); - case "vm/java/service.java.vm" -> fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); - case "vm/java/serviceImpl.java.vm" -> fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); - case "vm/java/controller.java.vm" -> fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); + case "vm/java/mapper.java.vm" -> + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); + case "vm/java/sub-mapper.java.vm" -> + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, genTable.getSubTable().getClassName()); + case "vm/java/service.java.vm" -> + fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); + case "vm/java/serviceImpl.java.vm" -> + fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); + case "vm/java/controller.java.vm" -> + fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); case "vm/xml/mapper.xml.vm" -> fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); - case "vm/xml/sub-mapper.xml.vm" -> fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, genTable.getSubTable().getClassName()); + case "vm/xml/sub-mapper.xml.vm" -> + fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, genTable.getSubTable().getClassName()); case "vm/sql/postgresql/sql.vm" -> fileName = businessName + "Menu(postgresql).sql"; case "vm/sql/mysql/sql.vm" -> fileName = businessName + "Menu(mysql).sql"; - case "vm/js/api.js.vm" -> fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); - case "vm/vue/index.vue.vm" -> fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); - case "vm/vue/index-tree.vue.vm" -> fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + case "vm/api/element.js.api.vm" -> + fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); + case "vm/api/element.ts.api.vm" -> + fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName); + case "vm/api/element.ts.types.vm" -> + fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName); + case "vm/api/antdesign.ts.index.vm" -> + fileName = StringUtils.format("{}/api/{}/{}/index.ts", vbenPath, moduleName, businessName); + case "vm/api/antdesign.ts.model.vm" -> + fileName = StringUtils.format("{}/api/{}/{}/model.ts", vbenPath, moduleName, businessName); + case "vm/vue/element.js.index.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + case "vm/vue/element.js.index-tree.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + case "vm/vue/element.ts.index.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + case "vm/vue/element.ts.index-tree.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + case "vm/vue/antdesign.ts.index.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vbenPath, moduleName, businessName); + case "vm/vue/antdesign.ts.data.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/{}.data.ts", vbenPath, moduleName, businessName, businessName); + case "vm/vue/antdesign.ts.modal.vue.vm" -> + fileName = StringUtils.format("{}/views/{}/{}/{}Modal.vue", vbenPath, moduleName, businessName, BusinessName); default -> fileName = "default.xml"; } @@ -220,8 +277,7 @@ public class VelocityUtils * @param packageName 包名称 * @return 包前缀名称 */ - public static String getPackagePrefix(String packageName) - { + public static String getPackagePrefix(String packageName) { int lastIndex = packageName.lastIndexOf("."); return StringUtils.substring(packageName, 0, lastIndex); } @@ -232,24 +288,18 @@ public class VelocityUtils * @param genTable 业务表对象 * @return 返回需要导入的包列表 */ - public static HashSet getImportList(GenTable genTable) - { + public static HashSet getImportList(GenTable genTable) { List columns = genTable.getColumns(); GenTable subGenTable = genTable.getSubTable(); HashSet importList = new HashSet<>(); - if (StringUtils.isNotNull(subGenTable)) - { + if (StringUtils.isNotNull(subGenTable)) { importList.add("java.util.List"); } - for (GenTableColumn column : columns) - { - if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) - { + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { importList.add("java.util.Date"); importList.add("com.fasterxml.jackson.annotation.JsonFormat"); - } - else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) - { + } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { importList.add("java.math.BigDecimal"); } } @@ -262,13 +312,11 @@ public class VelocityUtils * @param genTable 业务表对象 * @return 返回字典组 */ - public static String getDicts(GenTable genTable) - { + public static String getDicts(GenTable genTable) { List columns = genTable.getColumns(); Set dicts = new HashSet<>(); addDicts(dicts, columns); - if (StringUtils.isNotNull(genTable.getSubTable())) - { + if (StringUtils.isNotNull(genTable.getSubTable())) { List subColumns = genTable.getSubTable().getColumns(); addDicts(dicts, subColumns); } @@ -278,17 +326,14 @@ public class VelocityUtils /** * 添加字典列表 * - * @param dicts 字典列表 + * @param dicts 字典列表 * @param columns 列集合 */ - public static void addDicts(Set dicts, List columns) - { - for (GenTableColumn column : columns) - { + public static void addDicts(Set dicts, List columns) { + for (GenTableColumn column : columns) { if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( - column.getHtmlType(), - new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) - { + column.getHtmlType(), + new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { dicts.add("'" + column.getDictType() + "'"); } } @@ -297,12 +342,11 @@ public class VelocityUtils /** * 获取权限前缀 * - * @param moduleName 模块名称 + * @param moduleName 模块名称 * @param businessName 业务名称 * @return 返回权限前缀 */ - public static String getPermissionPrefix(String moduleName, String businessName) - { + public static String getPermissionPrefix(String moduleName, String businessName) { return StringUtils.format("{}:{}", moduleName, businessName); } @@ -312,11 +356,9 @@ public class VelocityUtils * @param paramsObj 生成其他选项 * @return 上级菜单ID字段 */ - public static String getParentMenuId(JSONObject paramsObj) - { + public static String getParentMenuId(JSONObject paramsObj) { if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) - && StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) - { + && StringUtils.isNotEmpty(paramsObj.getString(GenConstants.PARENT_MENU_ID))) { return paramsObj.getString(GenConstants.PARENT_MENU_ID); } return DEFAULT_PARENT_MENU_ID; @@ -328,10 +370,8 @@ public class VelocityUtils * @param paramsObj 生成其他选项 * @return 树编码 */ - public static String getTreecode(JSONObject paramsObj) - { - if (paramsObj.containsKey(GenConstants.TREE_CODE)) - { + public static String getTreecode(JSONObject paramsObj) { + if (paramsObj.containsKey(GenConstants.TREE_CODE)) { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); } return StringUtils.EMPTY; @@ -343,10 +383,8 @@ public class VelocityUtils * @param paramsObj 生成其他选项 * @return 树父编码 */ - public static String getTreeParentCode(JSONObject paramsObj) - { - if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) - { + public static String getTreeParentCode(JSONObject paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); } return StringUtils.EMPTY; @@ -358,10 +396,8 @@ public class VelocityUtils * @param paramsObj 生成其他选项 * @return 树名称 */ - public static String getTreeName(JSONObject paramsObj) - { - if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) - { + public static String getTreeName(JSONObject paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); } return StringUtils.EMPTY; @@ -373,20 +409,16 @@ public class VelocityUtils * @param genTable 业务表对象 * @return 展开按钮列序号 */ - public static int getExpandColumn(GenTable genTable) - { + public static int getExpandColumn(GenTable genTable) { String options = genTable.getOptions(); JSONObject paramsObj = JSON.parseObject(options); String treeName = paramsObj.getString(GenConstants.TREE_NAME); int num = 0; - for (GenTableColumn column : genTable.getColumns()) - { - if (column.isList()) - { + for (GenTableColumn column : genTable.getColumns()) { + if (column.isList()) { num++; String columnName = column.getColumnName(); - if (columnName.equals(treeName)) - { + if (columnName.equals(treeName)) { break; } } diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml index 88a8acf..273dce7 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml @@ -89,11 +89,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - delete from gen_table_column where column_id in - - #{item.columnId} - - - diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml index 6f65636..fd84875 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml @@ -1,34 +1,34 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + @@ -53,11 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + 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 - select table_name, table_comment, create_time, update_time from information_schema.tables @@ -97,9 +97,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by create_time desc - + - select table_name, table_comment, create_time, update_time from information_schema.tables where table_name NOT LIKE 'pj_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) @@ -128,20 +128,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{name} - + - + - + diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.index.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.index.vm new file mode 100644 index 0000000..8353cc7 --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.index.vm @@ -0,0 +1,60 @@ +import { defHttp } from '@/utils/http/axios'; +import { ID, IDS } from '@/api/base'; +import { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from './model'; + +/** + * 查询${functionName}列表 + * @param params + * @returns + */ +export function ${businessName}List(params?: ${BusinessName}Query) { + return defHttp.get<${BusinessName}VO[]>({ url: '/${moduleName}/${businessName}/list', params }); +} + +/** + * 导出${functionName}列表 + * @param params + * @returns + */ +export function ${businessName}Export(params?: ${BusinessName}Query) { + return defHttp.post( + { url: '/${moduleName}/${businessName}/export', params, responseType: 'blob' }, + { isTransformResponse: false }, + ); +} + +/** + * 查询${functionName}详细 + * @param ${pkColumn.javaField} id + * @returns + */ +export function ${businessName}Info(${pkColumn.javaField}: ID) { + return defHttp.get<${BusinessName}VO>({ url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField} }); +} + +/** + * 新增${functionName} + * @param data + * @returns + */ +export function ${businessName}Add(data: ${BusinessName}Form) { + return defHttp.postWithMsg({ url: '/${moduleName}/${businessName}', data }); +} + +/** + * 更新${functionName} + * @param data + * @returns + */ +export function ${businessName}Update(data: ${BusinessName}Form) { + return defHttp.putWithMsg({ url: '/${moduleName}/${businessName}', data }); +} + +/** + * 删除${functionName} + * @param ${pkColumn.javaField} id + * @returns + */ +export function ${businessName}Remove(${pkColumn.javaField}: ID | IDS) { + return defHttp.deleteWithMsg({ url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField} },); +} diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.model.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.model.vm new file mode 100644 index 0000000..f8272fe --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/antdesign.ts.model.vm @@ -0,0 +1,57 @@ +import { BaseEntity, PageQuery } from '@/api/base'; + +export interface ${BusinessName}VO { +#foreach ($column in $columns) +#if($column.list) + /** + * $column.columnComment + */ + $column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +#if ($table.tree) + /** + * 子对象 + */ + children: ${BusinessName}VO[]; +#end +} + +export interface ${BusinessName}Form extends BaseEntity { +#foreach ($column in $columns) +#if($column.insert || $column.edit) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +} + +export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{ + +#foreach ($column in $columns) +#if($column.query) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end + /** + * 日期范围参数 + */ + params?: any; +} diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/js/api.js.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.js.api.vm similarity index 100% rename from ruoyi-modules/ruoyi-generator/src/main/resources/vm/js/api.js.vm rename to ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.js.api.vm diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.api.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.api.vm new file mode 100644 index 0000000..3aa4a5f --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.api.vm @@ -0,0 +1,63 @@ +import request from '@/utils/request'; +import { AxiosPromise } from 'axios'; +import { ${BusinessName}VO, ${BusinessName}Form, ${BusinessName}Query } from '@/api/${moduleName}/${businessName}/types'; + +/** + * 查询${functionName}列表 + * @param query + * @returns {*} + */ + +export const list${BusinessName} = (query?: ${BusinessName}Query): AxiosPromise<${BusinessName}VO[]> => { + return request({ + url: '/${moduleName}/${businessName}/list', + method: 'get', + params: query + }); +}; + +/** + * 查询${functionName}详细 + * @param ${pkColumn.javaField} + */ +export const get${BusinessName} = (${pkColumn.javaField}: string | number): AxiosPromise<${BusinessName}VO> => { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'get' + }); +}; + +/** + * 新增${functionName} + * @param data + */ +export const add${BusinessName} = (data: ${BusinessName}Form) => { + return request({ + url: '/${moduleName}/${businessName}', + method: 'post', + data: data + }); +}; + +/** + * 修改${functionName} + * @param data + */ +export const update${BusinessName} = (data: ${BusinessName}Form) => { + return request({ + url: '/${moduleName}/${businessName}', + method: 'put', + data: data + }); +}; + +/** + * 删除${functionName} + * @param ${pkColumn.javaField} + */ +export const del${BusinessName} = (${pkColumn.javaField}: string | number | Array) => { + return request({ + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, + method: 'delete' + }); +}; diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.types.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.types.vm new file mode 100644 index 0000000..836a8f2 --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/api/element.ts.types.vm @@ -0,0 +1,54 @@ +export interface ${BusinessName}VO extends BaseEntity { +#foreach ($column in $columns) +#if($column.list) + /** + * $column.columnComment + */ + $column.javaField:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +#if ($table.tree) + /** + * 子对象 + */ + children: ${BusinessName}VO[]; +#end +} + +export interface ${BusinessName}Form { +#foreach ($column in $columns) +#if($column.insert || $column.edit) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end +} + +export interface ${BusinessName}Query #if(!${treeCode})extends PageQuery #end{ +#foreach ($column in $columns) +#if($column.query) + /** + * $column.columnComment + */ + $column.javaField?:#if($column.javaField.indexOf("id") != -1 || $column.javaField.indexOf("Id") != -1) string | number; + #elseif($column.javaType == 'Long' || $column.javaType == 'Integer' || $column.javaType == 'Double' || $column.javaType == 'Float' || $column.javaType == 'BigDecimal') number; + #elseif($column.javaType == 'Boolean') boolean; + #else string; + #end +#end +#end + /** + * 日期范围参数 + */ + params?: any; +} diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.data.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.data.vm new file mode 100644 index 0000000..34523a6 --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.data.vm @@ -0,0 +1,140 @@ +import { BasicColumn } from '@/components/Table'; +import { FormSchema } from '@/components/Form'; +#if(${dicts} != '') +import { getDictOptions } from '@/utils/dict'; +import { useRender } from '@/hooks/component/useRender'; +#end +export const formSchems: FormSchema[] = [ + #foreach($column in $columns) + #if($column.query) + #if($column.dictType) + #set($dictType=$column.dictType) + #else + #set($dictType="") + #end + #set($parentheseIndex=$column.columnComment.indexOf("(")) + #if($parentheseIndex != -1) + #set($comment=$column.columnComment.substring(0, $parentheseIndex)) + #else + #set($comment=$column.columnComment) + #end + #if($column.htmlType == "input") + #set($component="Input") + #elseif($column.htmlType == "textarea") + #set($component="InputTextArea") + #elseif($column.htmlType == "select") + #set($component="Select") + #elseif($column.htmlType == "radio") + #set($component="RadioButtonGroup") + #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN") + #set($component="DatePicker") + #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") + #set($component="RangePicker") + #else + #set($component="Input") + #end + { + label: '${comment}', + field: '${column.javaField}', + component: '${component}', + #if($dictType != "") + componentProps: { + options: getDictOptions('$dictType') + }, + #elseif($component == "DatePicker" || $component == "RangePicker") + componentProps: { + showTime: true, + format: 'YYYY-MM-DD HH:mm:ss', + valueFormat: 'YYYY-MM-DD HH:mm:ss', + }, + #end + }, + #end + #end +]; + +#if(${dicts} != '') +const { renderDict } = useRender(); +#end +export const columns: BasicColumn[] = [ + #foreach($column in $columns) + #if($column.list) + #if($column.dictType) + #set($dictType=$column.dictType) + #else + #set($dictType="") + #end + #set($parentheseIndex=$column.columnComment.indexOf("(")) + #if($parentheseIndex != -1) + #set($comment=$column.columnComment.substring(0, $parentheseIndex)) + #else + #set($comment=$column.columnComment) + #end + { + title: '${comment}', + dataIndex: '${column.javaField}', + #if($dictType != "") + customRender: ({ value }) => renderDict(value, '$dictType'), + #end + }, + #end + #end +]; + +export const modalSchemas: FormSchema[] = [ + #foreach($column in $columns) + #if($column.edit) + #if($column.dictType) + #set($dictType=$column.dictType) + #else + #set($dictType="") + #end + #set($parentheseIndex=$column.columnComment.indexOf("(")) + #if($parentheseIndex != -1) + #set($comment=$column.columnComment.substring(0, $parentheseIndex)) + #else + #set($comment=$column.columnComment) + #end + #if($column.htmlType == "input") + #set($component="Input") + #elseif($column.htmlType == "textarea") + #set($component="InputTextArea") + #elseif($column.htmlType == "select") + #set($component="Select") + #elseif($column.htmlType == "radio") + #set($component="RadioButtonGroup") + #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN") + #set($component="DatePicker") + #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") + #set($component="RangePicker") + #else + #set($component="Input") + #end + #if($column.required) + #set($required='true') + #else + #set($required='false') + #end + { + label: '${comment}', + field: '${column.javaField}', + required: ${required}, + component: '${component}', + #if($dictType != "") + componentProps: { + options: getDictOptions('$dictType') + }, + #elseif($component == "DatePicker" || $component == "RangePicker") + componentProps: { + showTime: true, + format: 'YYYY-MM-DD HH:mm:ss', + valueFormat: 'YYYY-MM-DD HH:mm:ss', + }, + #end + #if(${column.pk}) + show: false, + #end + }, + #end + #end +]; diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.index.vue.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.index.vue.vm new file mode 100644 index 0000000..f5af189 --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.index.vue.vm @@ -0,0 +1,121 @@ + + + + + diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.modal.vue.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.modal.vue.vm new file mode 100644 index 0000000..ac0e5de --- /dev/null +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/antdesign.ts.modal.vue.vm @@ -0,0 +1,65 @@ + + + + + diff --git a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/element.js.index-tree.vue.vm similarity index 97% rename from ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm rename to ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/element.js.index-tree.vue.vm index 50219d4..7aff166 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-modules/ruoyi-generator/src/main/resources/vm/vue/element.js.index-tree.vue.vm @@ -157,8 +157,7 @@ #foreach($column in $columns) #set($field=$column.javaField) -#if($column.insert && !$column.pk) -#if(($column.usableColumn) || (!$column.superColumn)) +#if(($column.insert || $column.edit) && !$column.pk) #set($parentheseIndex=$column.columnComment.indexOf("(")) #if($parentheseIndex != -1) #set($comment=$column.columnComment.substring(0, $parentheseIndex)) @@ -178,9 +177,15 @@ /> #elseif($column.htmlType == "input") - - + #if(${field} == "version") + + + #else + + + + #end #elseif($column.htmlType == "imageUpload") @@ -266,7 +271,6 @@ #end #end -#end #end