代码生成支持乐观锁、多UI前端
This commit is contained in:
parent
4ee432bfee
commit
da582764a7
3
pom.xml
3
pom.xml
@ -33,7 +33,6 @@
|
|||||||
<jwt.version>0.9.1</jwt.version>
|
<jwt.version>0.9.1</jwt.version>
|
||||||
<servlet-api.version>6.0.0</servlet-api.version>
|
<servlet-api.version>6.0.0</servlet-api.version>
|
||||||
<guava.version>32.1.1-jre</guava.version>
|
<guava.version>32.1.1-jre</guava.version>
|
||||||
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
|
|
||||||
<springdoc.version>2.3.0</springdoc.version>
|
<springdoc.version>2.3.0</springdoc.version>
|
||||||
<springdoc-openapi-starter-common.version>2.3.0</springdoc-openapi-starter-common.version>
|
<springdoc-openapi-starter-common.version>2.3.0</springdoc-openapi-starter-common.version>
|
||||||
<therapi-runtime-javadoc.version>0.15.0</therapi-runtime-javadoc.version>
|
<therapi-runtime-javadoc.version>0.15.0</therapi-runtime-javadoc.version>
|
||||||
@ -63,7 +62,7 @@
|
|||||||
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
||||||
<maven-compiler-plugin.verison>3.11.0</maven-compiler-plugin.verison>
|
<maven-compiler-plugin.verison>3.11.0</maven-compiler-plugin.verison>
|
||||||
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
|
||||||
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
|
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
@ -2,13 +2,14 @@ package com.ruoyi;
|
|||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动程序
|
* 启动程序
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication(exclude = SpringDataWebAutoConfiguration.class)
|
||||||
public class RuoYiApplication
|
public class RuoYiApplication
|
||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
@ -39,21 +39,6 @@ mybatis-flex:
|
|||||||
username: postgres
|
username: postgres
|
||||||
password: postgres@369
|
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 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
# redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||||
spring.data:
|
spring.data:
|
||||||
redis:
|
redis:
|
||||||
|
@ -3,7 +3,6 @@ package com.ruoyi.mf.controller;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.constraints.*;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -3,7 +3,6 @@ package com.ruoyi.mf.controller;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.constraints.*;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -3,7 +3,6 @@ package com.ruoyi.mf.controller;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.validation.constraints.*;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -2,7 +2,6 @@ package com.ruoyi.mf.service.impl;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
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.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.core.utils.DateUtils;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import com.ruoyi.mf.domain.Goods;
|
import com.ruoyi.mf.domain.Goods;
|
||||||
import com.ruoyi.mf.mapper.GoodsMapper;
|
import com.ruoyi.mf.mapper.GoodsMapper;
|
||||||
import static com.ruoyi.mf.domain.table.GoodsTableDef.GOODS;
|
import static com.ruoyi.mf.domain.table.GoodsTableDef.GOODS;
|
||||||
|
@ -2,16 +2,10 @@ package com.ruoyi.mf.service.impl;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
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.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.core.utils.DateUtils;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -2,17 +2,13 @@ package com.ruoyi.mf.service.impl;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.mybatisflex.annotation.UseDataSource;
|
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
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.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.core.utils.DateUtils;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -80,7 +76,6 @@ public class MfStudentServiceImpl extends BaseServiceImpl<MfStudentMapper, MfStu
|
|||||||
* @param mfStudentBo 学生信息表Bo
|
* @param mfStudentBo 学生信息表Bo
|
||||||
* @return 分页学生信息表集合
|
* @return 分页学生信息表集合
|
||||||
*/
|
*/
|
||||||
//@UseDataSource("ds2") //多数据源演示
|
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<MfStudentVo> selectPage(MfStudentBo mfStudentBo)
|
public TableDataInfo<MfStudentVo> selectPage(MfStudentBo mfStudentBo)
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
<artifactId>ruoyi-common-core</artifactId>
|
<artifactId>ruoyi-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-common-log</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
<artifactId>ruoyi-common-web</artifactId>
|
<artifactId>ruoyi-common-web</artifactId>
|
||||||
|
@ -6,21 +6,16 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
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 com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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 com.ruoyi.common.web.core.BaseController;
|
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.common.core.core.text.Convert;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
import com.ruoyi.generator.domain.GenTable;
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
@ -36,8 +31,7 @@ import com.ruoyi.generator.service.IGenTableService;
|
|||||||
@Validated
|
@Validated
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/tool/gen")
|
@RequestMapping("/tool/gen")
|
||||||
public class GenController extends BaseController
|
public class GenController extends BaseController {
|
||||||
{
|
|
||||||
@Resource
|
@Resource
|
||||||
private IGenTableService genTableService;
|
private IGenTableService genTableService;
|
||||||
|
|
||||||
@ -49,8 +43,7 @@ public class GenController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:list")
|
@SaCheckPermission("tool:gen:list")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public TableDataInfo<GenTable> genList(GenTable genTable)
|
public TableDataInfo<GenTable> genList(GenTable genTable) {
|
||||||
{
|
|
||||||
return genTableService.selectPage(genTable);
|
return genTableService.selectPage(genTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,17 +52,15 @@ public class GenController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:query")
|
@SaCheckPermission("tool:gen:query")
|
||||||
@GetMapping(value = "/{tableId}")
|
@GetMapping(value = "/{tableId}")
|
||||||
public AjaxResult getInfo(@PathVariable Long tableId)
|
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
|
||||||
{
|
|
||||||
GenTable table = genTableService.selectGenTableById(tableId);
|
GenTable table = genTableService.selectGenTableById(tableId);
|
||||||
List<GenTable> tables = genTableService.selectGenTableAll();
|
List<GenTable> tables = genTableService.selectGenTableAll();
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
||||||
//table.setColumns(list);
|
Map<String, Object> map = new HashMap<>(3);
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
map.put("info", table);
|
map.put("info", table);
|
||||||
map.put("rows", list);
|
map.put("rows", list);
|
||||||
map.put("tables", tables);
|
map.put("tables", tables);
|
||||||
return success(map);
|
return R.ok(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,8 +68,7 @@ public class GenController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:list")
|
@SaCheckPermission("tool:gen:list")
|
||||||
@GetMapping("/db/list")
|
@GetMapping("/db/list")
|
||||||
public TableDataInfo dataList(GenTable genTable)
|
public TableDataInfo dataList(GenTable genTable) {
|
||||||
{
|
|
||||||
startPage();
|
startPage();
|
||||||
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
@ -89,9 +79,8 @@ public class GenController extends BaseController
|
|||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:list")
|
@SaCheckPermission("tool:gen:list")
|
||||||
@GetMapping(value = "/column/{tableId}")
|
@GetMapping(value = "/column/{tableId}")
|
||||||
public TableDataInfo columnList(@PathVariable("tableId") Long tableId)
|
public TableDataInfo<GenTableColumn> columnList(@PathVariable("tableId") Long tableId) {
|
||||||
{
|
TableDataInfo<GenTableColumn> dataInfo = new TableDataInfo<>();
|
||||||
TableDataInfo dataInfo = new TableDataInfo();
|
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
||||||
dataInfo.setRows(list);
|
dataInfo.setRows(list);
|
||||||
dataInfo.setTotal(list.size());
|
dataInfo.setTotal(list.size());
|
||||||
@ -102,106 +91,104 @@ public class GenController extends BaseController
|
|||||||
* 导入表结构(保存)
|
* 导入表结构(保存)
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:import")
|
@SaCheckPermission("tool:gen:import")
|
||||||
|
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
|
||||||
@PostMapping("/importTable")
|
@PostMapping("/importTable")
|
||||||
public AjaxResult importTableSave(String tables)
|
public R<Void> importTableSave(String tables) {
|
||||||
{
|
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
String[] tableNames = Convert.toStrArray(tables);
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
|
||||||
genTableService.importGenTable(tableList);
|
genTableService.importGenTable(tableList);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存代码生成业务
|
* 修改保存代码生成业务
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:edit")
|
@SaCheckPermission("tool:gen:edit")
|
||||||
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public AjaxResult editSave(@Validated @RequestBody GenTable genTable)
|
public R<Void> editSave(@Validated @RequestBody GenTable genTable) {
|
||||||
{
|
|
||||||
genTableService.validateEdit(genTable);
|
genTableService.validateEdit(genTable);
|
||||||
genTableService.updateGenTable(genTable);
|
genTableService.updateGenTable(genTable);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除代码生成
|
* 删除代码生成
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:remove")
|
@SaCheckPermission("tool:gen:remove")
|
||||||
|
@Log(title = "代码生成", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{tableIds}")
|
@DeleteMapping("/{tableIds}")
|
||||||
public AjaxResult remove(@PathVariable Long[] tableIds)
|
public R<Void> remove(@PathVariable Long[] tableIds) {
|
||||||
{
|
|
||||||
genTableService.deleteGenTableByIds(tableIds);
|
genTableService.deleteGenTableByIds(tableIds);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览代码
|
* 预览代码,前端界面类型frontType取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:preview")
|
@SaCheckPermission("tool:gen:preview")
|
||||||
@GetMapping("/preview/{tableId}")
|
@GetMapping("/preview")
|
||||||
public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException
|
public R<Map<String, String>> preview(Long tableId, Integer frontType) throws IOException {
|
||||||
{
|
Map<String, String> dataMap = genTableService.previewCode(tableId, frontType);
|
||||||
Map<String, String> dataMap = genTableService.previewCode(tableId);
|
return R.ok(dataMap);
|
||||||
return success(dataMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 生成代码(下载方式)
|
// * 生成代码(下载方式)
|
||||||
*/
|
// */
|
||||||
@SaCheckPermission("tool:gen:code")
|
// @SaCheckPermission("tool:gen:code")
|
||||||
@GetMapping("/download/{tableName}")
|
// @Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
|
// @GetMapping("/download/{tableId}")
|
||||||
{
|
// public void download(HttpServletResponse response, @PathVariable("tableId") Long tableId) throws IOException {
|
||||||
byte[] data = genTableService.downloadCode(tableName);
|
// byte[] data = genTableService.downloadCode(tableId);
|
||||||
genCode(response, data);
|
// genCode(response, data);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径),前端界面类型frontType取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:code")
|
@SaCheckPermission("tool:gen:code")
|
||||||
@GetMapping("/genCode/{tableName}")
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
public AjaxResult genCode(@PathVariable("tableName") String tableName)
|
@GetMapping("/genCode")
|
||||||
{
|
public R<Void> genCode(Long tableId, Integer frontType) {
|
||||||
genTableService.generatorCode(tableName);
|
genTableService.generatorCode(tableId, frontType);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:edit")
|
@SaCheckPermission("tool:gen:edit")
|
||||||
@GetMapping("/synchDb/{tableName}")
|
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
|
||||||
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
|
@GetMapping("/synchDb/{tableId}")
|
||||||
{
|
public R<Void> synchDb(@PathVariable("tableId") Long tableId) {
|
||||||
genTableService.synchDb(tableName);
|
genTableService.synchDb(tableId);
|
||||||
return success();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量生成代码
|
* 批量生成代码
|
||||||
*/
|
*/
|
||||||
@SaCheckPermission("tool:gen:code")
|
@SaCheckPermission("tool:gen:code")
|
||||||
|
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
||||||
@GetMapping("/batchGenCode")
|
@GetMapping("/batchGenCode")
|
||||||
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
|
public void batchGenCode(HttpServletResponse response, String tableIdStr, Integer frontType) throws IOException {
|
||||||
{
|
String[] tableIds = Convert.toStrArray(tableIdStr);
|
||||||
String[] tableNames = Convert.toStrArray(tables);
|
byte[] data = genTableService.downloadCode(tableIds, frontType);
|
||||||
byte[] data = genTableService.downloadCode(tableNames);
|
|
||||||
genCode(response, data);
|
genCode(response, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成zip文件
|
* 生成zip文件
|
||||||
*/
|
*/
|
||||||
private void genCode(HttpServletResponse response, byte[] data) throws IOException
|
private void genCode(HttpServletResponse response, byte[] data) throws IOException {
|
||||||
{
|
|
||||||
response.reset();
|
response.reset();
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||||
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi-flex.zip\"");
|
response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi-flex.zip\"");
|
||||||
response.addHeader("Content-Length", "" + data.length);
|
response.addHeader("Content-Length", "" + data.length);
|
||||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||||
IOUtils.write(data, response.getOutputStream());
|
IoUtil.write(response.getOutputStream(), false, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,12 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.mybatisflex.annotation.Column;
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
|
import com.mybatisflex.annotation.RelationOneToMany;
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import com.ruoyi.common.core.constant.GenConstants;
|
import com.ruoyi.common.core.constant.GenConstants;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
@ -36,6 +38,12 @@ public class GenTable implements Serializable
|
|||||||
@Id
|
@Id
|
||||||
private Long tableId;
|
private Long tableId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "数据源名称不能为空")
|
||||||
|
private String datasourceName;
|
||||||
|
|
||||||
/** 表名称 */
|
/** 表名称 */
|
||||||
@NotBlank(message = "表名称不能为空")
|
@NotBlank(message = "表名称不能为空")
|
||||||
private String tableName;
|
private String tableName;
|
||||||
@ -92,6 +100,8 @@ public class GenTable implements Serializable
|
|||||||
|
|
||||||
/** 表列信息 */
|
/** 表列信息 */
|
||||||
@Valid
|
@Valid
|
||||||
|
@Column(ignore = true)
|
||||||
|
@RelationOneToMany(selfField = "tableId", targetField = "tableId",orderBy = "sort")
|
||||||
private List<GenTableColumn> columns;
|
private List<GenTableColumn> columns;
|
||||||
|
|
||||||
/** 其它生成选项 */
|
/** 其它生成选项 */
|
||||||
@ -112,6 +122,7 @@ public class GenTable implements Serializable
|
|||||||
/*
|
/*
|
||||||
* 菜单id列表
|
* 菜单id列表
|
||||||
*/
|
*/
|
||||||
|
@Column(ignore = true)
|
||||||
private List<Long> menuIds;
|
private List<Long> menuIds;
|
||||||
|
|
||||||
/** 上级菜单ID字段 */
|
/** 上级菜单ID字段 */
|
||||||
|
@ -190,7 +190,7 @@ public class GenTableColumn implements Serializable
|
|||||||
{
|
{
|
||||||
return StringUtils.equalsAnyIgnoreCase(javaField,
|
return StringUtils.equalsAnyIgnoreCase(javaField,
|
||||||
// BaseEntity
|
// BaseEntity
|
||||||
"createBy", "createTime", "updateBy", "updateTime",
|
"version","createBy", "createTime", "updateBy", "updateTime",
|
||||||
// TreeEntity
|
// TreeEntity
|
||||||
"parentName", "parentId", "orderNum", "ancestors");
|
"parentName", "parentId", "orderNum", "ancestors");
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,6 @@ public interface GenTableColumnMapper extends BaseMapper<GenTableColumn>
|
|||||||
*/
|
*/
|
||||||
List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除业务字段
|
|
||||||
*
|
|
||||||
* @param genTableColumns 列数据
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除业务字段
|
* 批量删除业务字段
|
||||||
*
|
*
|
||||||
|
@ -31,8 +31,6 @@ public interface GenTableMapper extends BaseMapper<GenTable>
|
|||||||
*/
|
*/
|
||||||
List<GenTable> selectDbTableListByNames(String[] tableNames);
|
List<GenTable> selectDbTableListByNames(String[] tableNames);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询表名称业务信息
|
* 查询表名称业务信息
|
||||||
*
|
*
|
||||||
|
@ -40,8 +40,7 @@ public class GenTableColumnServiceImpl extends BaseServiceImpl<GenTableColumnMap
|
|||||||
@Override
|
@Override
|
||||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
|
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
|
||||||
{
|
{
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
QueryWrapper queryWrapper = query()
|
||||||
.from(GEN_TABLE_COLUMN)
|
|
||||||
.where(GEN_TABLE_COLUMN.TABLE_ID.eq(tableId))
|
.where(GEN_TABLE_COLUMN.TABLE_ID.eq(tableId))
|
||||||
.orderBy(GEN_TABLE_COLUMN.SORT.asc());
|
.orderBy(GEN_TABLE_COLUMN.SORT.asc());
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
package com.ruoyi.generator.service;
|
package com.ruoyi.generator.service;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import com.mybatisflex.core.FlexGlobalConfig;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import com.mybatisflex.core.dialect.DbType;
|
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.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryMethods;
|
import com.mybatisflex.core.query.QueryMethods;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
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.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.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.security.utils.LoginHelper;
|
import com.ruoyi.common.security.utils.LoginHelper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.velocity.Template;
|
import org.apache.velocity.Template;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
@ -30,7 +34,6 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.core.constant.Constants;
|
import com.ruoyi.common.core.constant.Constants;
|
||||||
import com.ruoyi.common.core.constant.GenConstants;
|
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.exception.ServiceException;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.generator.domain.GenTable;
|
import com.ruoyi.generator.domain.GenTable;
|
||||||
@ -51,16 +54,12 @@ import static com.ruoyi.generator.domain.table.GenTableTableDef.GEN_TABLE;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTable> implements IGenTableService
|
public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTable> implements IGenTableService {
|
||||||
{
|
|
||||||
@Resource
|
@Resource
|
||||||
private GenTableMapper genTableMapper;
|
private GenTableMapper genTableMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private GenTableColumnMapper genTableColumnMapper;
|
private GenTableColumnMapper genTableColumnMapper;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private IGenTableColumnService genTableColumnService;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryWrapper query() {
|
public QueryWrapper query() {
|
||||||
return super.query().from(GEN_TABLE);
|
return super.query().from(GEN_TABLE);
|
||||||
@ -79,6 +78,7 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
queryWrapper.and(GEN_TABLE.CREATE_TIME.between(params.get("beginTime"), params.get("endTime")));
|
queryWrapper.and(GEN_TABLE.CREATE_TIME.between(params.get("beginTime"), params.get("endTime")));
|
||||||
}
|
}
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,20 +88,14 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @return 业务信息
|
* @return 业务信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public GenTable selectGenTableById(Long id)
|
public GenTable selectGenTableById(Long id) {
|
||||||
{
|
|
||||||
/*SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
/*SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||||
FROM gen_table t
|
FROM gen_table t
|
||||||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||||
where t.table_id = #{tableId} order by c.sort*/
|
where t.table_id = #{tableId} order by c.sort*/
|
||||||
|
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
GenTable genTable = genTableMapper.selectOneWithRelationsById(id);
|
||||||
.from(GEN_TABLE)
|
|
||||||
.leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID))
|
|
||||||
.where(GEN_TABLE.TABLE_ID.eq(id))
|
|
||||||
.orderBy(GEN_TABLE_COLUMN.SORT.asc());
|
|
||||||
GenTable genTable = this.getOne(queryWrapper);
|
|
||||||
setTableFromOptions(genTable);
|
setTableFromOptions(genTable);
|
||||||
return genTable;
|
return genTable;
|
||||||
}
|
}
|
||||||
@ -113,8 +107,7 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @return 分页集合
|
* @return 分页集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo<GenTable> selectPage(GenTable genTable)
|
public TableDataInfo<GenTable> selectPage(GenTable genTable) {
|
||||||
{
|
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(genTable);
|
QueryWrapper queryWrapper = buildQueryWrapper(genTable);
|
||||||
Page<GenTable> page = this.pageAs(PageQuery.build(), queryWrapper, GenTable.class);
|
Page<GenTable> page = this.pageAs(PageQuery.build(), queryWrapper, GenTable.class);
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
@ -127,8 +120,7 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GenTable> selectDbTableList(GenTable genTable)
|
public List<GenTable> selectDbTableList(GenTable genTable) {
|
||||||
{
|
|
||||||
return genTableMapper.selectDbTableList(genTable);
|
return genTableMapper.selectDbTableList(genTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +131,7 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames)
|
public List<GenTable> selectDbTableListByNames(String[] tableNames) {
|
||||||
{
|
|
||||||
return genTableMapper.selectDbTableListByNames(tableNames);
|
return genTableMapper.selectDbTableListByNames(tableNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,10 +141,8 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @return 表信息集合
|
* @return 表信息集合
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<GenTable> selectGenTableAll()
|
public List<GenTable> selectGenTableAll() {
|
||||||
{
|
QueryWrapper queryWrapper = query()
|
||||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
||||||
.from(GEN_TABLE)
|
|
||||||
.leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID))
|
.leftJoin(GEN_TABLE_COLUMN).on(GEN_TABLE_COLUMN.TABLE_ID.eq(GEN_TABLE.TABLE_ID))
|
||||||
.orderBy(GEN_TABLE_COLUMN.SORT.asc());
|
.orderBy(GEN_TABLE_COLUMN.SORT.asc());
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
@ -166,9 +155,8 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* 结果
|
* 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateGenTable(GenTable genTable)
|
public void updateGenTable(GenTable genTable) {
|
||||||
{
|
|
||||||
String options = JSON.toJSONString(genTable.getParams());
|
String options = JSON.toJSONString(genTable.getParams());
|
||||||
genTable.setOptions(options);
|
genTable.setOptions(options);
|
||||||
|
|
||||||
@ -178,10 +166,8 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
genTable.setUpdateTime(createTime);
|
genTable.setUpdateTime(createTime);
|
||||||
|
|
||||||
boolean updated = this.updateById(genTable);
|
boolean updated = this.updateById(genTable);
|
||||||
if (updated)
|
if (updated) {
|
||||||
{
|
for (GenTableColumn genTableColumn : genTable.getColumns()) {
|
||||||
for (GenTableColumn genTableColumn : genTable.getColumns())
|
|
||||||
{
|
|
||||||
genTableColumn.setUpdateBy(loginUserId);
|
genTableColumn.setUpdateBy(loginUserId);
|
||||||
genTableColumn.setUpdateTime(createTime);
|
genTableColumn.setUpdateTime(createTime);
|
||||||
genTableColumnMapper.update(genTableColumn);
|
genTableColumnMapper.update(genTableColumn);
|
||||||
@ -196,9 +182,8 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* 结果
|
* 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteGenTableByIds(Long[] tableIds)
|
public void deleteGenTableByIds(Long[] tableIds) {
|
||||||
{
|
|
||||||
genTableMapper.deleteBatchByIds(Arrays.asList(tableIds));
|
genTableMapper.deleteBatchByIds(Arrays.asList(tableIds));
|
||||||
genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
|
genTableColumnMapper.deleteGenTableColumnByIds(tableIds);
|
||||||
}
|
}
|
||||||
@ -210,12 +195,9 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void importGenTable(List<GenTable> tableList)
|
public void importGenTable(List<GenTable> tableList) {
|
||||||
{
|
try {
|
||||||
try
|
for (GenTable table : tableList) {
|
||||||
{
|
|
||||||
for (GenTable table : tableList)
|
|
||||||
{
|
|
||||||
String tableName = table.getTableName();
|
String tableName = table.getTableName();
|
||||||
GenUtils.initTable(table);
|
GenUtils.initTable(table);
|
||||||
|
|
||||||
@ -228,24 +210,27 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
|
|
||||||
|
|
||||||
boolean saved = this.save(table);
|
boolean saved = this.save(table);
|
||||||
if (saved)
|
if (saved) {
|
||||||
{
|
|
||||||
// 保存列信息
|
// 保存列信息
|
||||||
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||||
|
List<GenTableColumn> saveColumns = new ArrayList<>();
|
||||||
for (GenTableColumn column : genTableColumns)
|
for (GenTableColumn column : genTableColumns)
|
||||||
{
|
{
|
||||||
GenUtils.initColumnField(column, table);
|
GenUtils.initColumnField(column, table);
|
||||||
|
|
||||||
column.setCreateBy(loginUserId);
|
column.setCreateBy(loginUserId);
|
||||||
column.setCreateTime(createTime);
|
column.setCreateTime(createTime);
|
||||||
column.setUpdateBy(loginUserId);
|
column.setUpdateBy(loginUserId);
|
||||||
column.setUpdateTime(createTime);
|
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());
|
throw new ServiceException("导入失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,16 +239,14 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* 预览代码
|
* 预览代码
|
||||||
*
|
*
|
||||||
* @param tableId 表编号
|
* @param tableId 表编号
|
||||||
|
* @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
* @return 预览数据列表
|
* @return 预览数据列表
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> previewCode(Long tableId)
|
public Map<String, String> previewCode(Long tableId, Integer frontType) {
|
||||||
{
|
|
||||||
Map<String, String> dataMap = new LinkedHashMap<>();
|
Map<String, String> dataMap = new LinkedHashMap<>();
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = selectGenTableById(tableId);
|
GenTable table = selectGenTableById(tableId);
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
|
|
||||||
table.setColumns(list);
|
|
||||||
|
|
||||||
//设置生成的sys_menu6条记录的主键值
|
//设置生成的sys_menu6条记录的主键值
|
||||||
setMenuIds(table);
|
setMenuIds(table);
|
||||||
@ -276,9 +259,8 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||||
|
|
||||||
// 获取模板列表
|
// 获取模板列表
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType);
|
||||||
for (String template : templates)
|
for (String template : templates) {
|
||||||
{
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
@ -291,31 +273,29 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
/**
|
/**
|
||||||
* 生成代码(下载方式)
|
* 生成代码(下载方式)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableId 表id
|
||||||
|
* @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] downloadCode(String tableName)
|
public byte[] downloadCode(Long tableId, Integer frontType) {
|
||||||
{
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
generatorCode(tableName, zip);
|
generatorCode(tableId, zip, frontType);
|
||||||
IOUtils.closeQuietly(zip);
|
IoUtil.close(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableId 表ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void generatorCode(String tableName)
|
public void generatorCode(Long tableId, Integer frontType) {
|
||||||
{
|
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
//GenTable table = genTableMapper.selectGenTableByName(tableName);
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(table.getTableId());
|
GenTable table = genTableMapper.selectOneWithRelationsById(tableId);
|
||||||
table.setColumns(list);
|
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
//设置生成的sys_menu6条记录的主键值
|
//设置生成的sys_menu6条记录的主键值
|
||||||
@ -328,22 +308,17 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||||
|
|
||||||
// 获取模板列表
|
// 获取模板列表
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType);
|
||||||
for (String template : templates)
|
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")) {
|
||||||
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm"))
|
|
||||||
{
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
String path = getGenPath(table, template);
|
String path = getGenPath(table, template);
|
||||||
FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
|
FileUtils.writeUtf8String(sw.toString(), path);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
|
throw new ServiceException("渲染模板失败,表名:" + table.getTableName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,82 +328,80 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableId 表ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void synchDb(String tableName)
|
public void synchDb(Long tableId) {
|
||||||
{
|
|
||||||
Long loginUserId = LoginHelper.getUserId();
|
Long loginUserId = LoginHelper.getUserId();
|
||||||
Date createTime = new Date();
|
Date createTime = new Date();
|
||||||
|
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
GenTable table = genTableMapper.selectOneWithRelationsById(tableId);
|
||||||
List<GenTableColumn> tableColumns = table.getColumns();
|
List<GenTableColumn> tableColumns = table.getColumns();
|
||||||
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
|
Map<String, GenTableColumn> tableColumnMap = StreamUtils.toIdentityMap(tableColumns, GenTableColumn::getColumnName);
|
||||||
|
|
||||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getTableName());
|
||||||
if (StringUtils.isEmpty(dbTableColumns))
|
if (CollUtil.isEmpty(dbTableColumns)) {
|
||||||
{
|
|
||||||
throw new ServiceException("同步数据失败,原表结构不存在");
|
throw new ServiceException("同步数据失败,原表结构不存在");
|
||||||
}
|
}
|
||||||
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
List<String> dbTableColumnNames = StreamUtils.toList(dbTableColumns, GenTableColumn::getColumnName);
|
||||||
|
|
||||||
|
List<GenTableColumn> saveColumns = new ArrayList<>();
|
||||||
dbTableColumns.forEach(column -> {
|
dbTableColumns.forEach(column -> {
|
||||||
GenUtils.initColumnField(column, table);
|
GenUtils.initColumnField(column, table);
|
||||||
if (tableColumnMap.containsKey(column.getColumnName()))
|
if (tableColumnMap.containsKey(column.getColumnName())) {
|
||||||
{
|
|
||||||
GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
|
GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
|
||||||
column.setColumnId(prevColumn.getColumnId());
|
column.setColumnId(prevColumn.getColumnId());
|
||||||
if (column.isList())
|
if (column.isList()) {
|
||||||
{
|
|
||||||
// 如果是列表,继续保留查询方式/字典类型选项
|
// 如果是列表,继续保留查询方式/字典类型选项
|
||||||
column.setDictType(prevColumn.getDictType());
|
column.setDictType(prevColumn.getDictType());
|
||||||
column.setQueryType(prevColumn.getQueryType());
|
column.setQueryType(prevColumn.getQueryType());
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
|
if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()
|
||||||
&& (column.isInsert() || column.isEdit())
|
&& (column.isInsert() || column.isEdit())
|
||||||
&& ((column.isUsableColumn()) || (!column.isSuperColumn())))
|
&& ((column.isUsableColumn()) || (!column.isSuperColumn()))) {
|
||||||
{
|
|
||||||
// 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
|
// 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
|
||||||
column.setIsRequired(prevColumn.getIsRequired());
|
column.setIsRequired(prevColumn.getIsRequired());
|
||||||
column.setHtmlType(prevColumn.getHtmlType());
|
column.setHtmlType(prevColumn.getHtmlType());
|
||||||
}
|
}
|
||||||
|
column.setVersion(prevColumn.getVersion());
|
||||||
column.setUpdateBy(loginUserId);
|
column.setUpdateBy(loginUserId);
|
||||||
column.setUpdateTime(createTime);
|
column.setUpdateTime(createTime);
|
||||||
genTableColumnMapper.update(column);
|
} else {
|
||||||
}
|
column.setVersion(0);
|
||||||
else
|
|
||||||
{
|
|
||||||
column.setCreateBy(loginUserId);
|
column.setCreateBy(loginUserId);
|
||||||
column.setCreateTime(createTime);
|
column.setCreateTime(createTime);
|
||||||
column.setUpdateBy(loginUserId);
|
column.setUpdateBy(loginUserId);
|
||||||
column.setUpdateTime(createTime);
|
column.setUpdateTime(createTime);
|
||||||
|
|
||||||
genTableColumnMapper.insertSelective(column);
|
|
||||||
}
|
}
|
||||||
|
saveColumns.add(column);
|
||||||
});
|
});
|
||||||
|
if (CollUtil.isNotEmpty(saveColumns)) {
|
||||||
|
Db.executeBatch(saveColumns, 500, GenTableColumnMapper.class, BaseMapper::insertOrUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
|
List<GenTableColumn> delColumns = StreamUtils.filter(tableColumns, column -> !dbTableColumnNames.contains(column.getColumnName()));
|
||||||
if (StringUtils.isNotEmpty(delColumns))
|
if (CollUtil.isNotEmpty(delColumns)) {
|
||||||
{
|
List<Long> ids = StreamUtils.toList(delColumns, GenTableColumn::getColumnId);
|
||||||
genTableColumnMapper.deleteGenTableColumns(delColumns);
|
if (CollUtil.isNotEmpty(ids)) {
|
||||||
|
genTableColumnMapper.deleteBatchByIds(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量生成代码(下载方式)
|
* 批量生成代码(下载方式)
|
||||||
*
|
*
|
||||||
* @param tableNames 表数组
|
* @param tableIds 表ids
|
||||||
|
* @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
* @return 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] downloadCode(String[] tableNames)
|
public byte[] downloadCode(String[] tableIds, Integer frontType) {
|
||||||
{
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
for (String tableName : tableNames)
|
for (String tableId : tableIds) {
|
||||||
{
|
generatorCode(Long.parseLong(tableId), zip, frontType);
|
||||||
generatorCode(tableName, zip);
|
|
||||||
}
|
}
|
||||||
IOUtils.closeQuietly(zip);
|
IOUtils.closeQuietly(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
@ -437,12 +410,9 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
/**
|
/**
|
||||||
* 查询表信息并生成代码
|
* 查询表信息并生成代码
|
||||||
*/
|
*/
|
||||||
private void generatorCode(String tableName, ZipOutputStream zip)
|
private void generatorCode(Long tableId, ZipOutputStream zip, Integer frontType) {
|
||||||
{
|
|
||||||
// 查询表信息
|
// 查询表信息
|
||||||
GenTable table = genTableMapper.selectGenTableByName(tableName);
|
GenTable table = genTableMapper.selectOneWithRelationsById(tableId);
|
||||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(table.getTableId());
|
|
||||||
table.setColumns(list);
|
|
||||||
// 设置主子表信息
|
// 设置主子表信息
|
||||||
setSubTable(table);
|
setSubTable(table);
|
||||||
//设置生成的sys_menu6条记录的主键值
|
//设置生成的sys_menu6条记录的主键值
|
||||||
@ -455,24 +425,20 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
VelocityContext context = VelocityUtils.prepareContext(table);
|
VelocityContext context = VelocityUtils.prepareContext(table);
|
||||||
|
|
||||||
// 获取模板列表
|
// 获取模板列表
|
||||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory(), frontType);
|
||||||
for (String template : templates)
|
for (String template : templates) {
|
||||||
{
|
|
||||||
// 渲染模板
|
// 渲染模板
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||||
tpl.merge(context, sw);
|
tpl.merge(context, sw);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// 添加到zip
|
// 添加到zip
|
||||||
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
|
zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table)));
|
||||||
IOUtils.write(sw.toString(), zip, Constants.UTF8);
|
IoUtil.write(zip, StandardCharsets.UTF_8, false, sw.toString());
|
||||||
IOUtils.closeQuietly(sw);
|
IoUtil.close(sw);
|
||||||
zip.flush();
|
zip.flush();
|
||||||
zip.closeEntry();
|
zip.closeEntry();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
log.error("渲染模板失败,表名:" + table.getTableName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -484,32 +450,20 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void validateEdit(GenTable genTable)
|
public void validateEdit(GenTable genTable) {
|
||||||
{
|
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
|
||||||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory()))
|
|
||||||
{
|
|
||||||
String options = JSON.toJSONString(genTable.getParams());
|
String options = JSON.toJSONString(genTable.getParams());
|
||||||
JSONObject paramsObj = JSON.parseObject(options);
|
JSONObject paramsObj = JSON.parseObject(options);
|
||||||
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE)))
|
if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
|
||||||
{
|
|
||||||
throw new ServiceException("树编码字段不能为空");
|
throw new ServiceException("树编码字段不能为空");
|
||||||
}
|
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
|
||||||
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE)))
|
|
||||||
{
|
|
||||||
throw new ServiceException("树父编码字段不能为空");
|
throw new ServiceException("树父编码字段不能为空");
|
||||||
}
|
} else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
|
||||||
else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME)))
|
|
||||||
{
|
|
||||||
throw new ServiceException("树名称字段不能为空");
|
throw new ServiceException("树名称字段不能为空");
|
||||||
}
|
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
|
||||||
else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
|
if (StringUtils.isEmpty(genTable.getSubTableName())) {
|
||||||
{
|
|
||||||
if (StringUtils.isEmpty(genTable.getSubTableName()))
|
|
||||||
{
|
|
||||||
throw new ServiceException("关联子表的表名不能为空");
|
throw new ServiceException("关联子表的表名不能为空");
|
||||||
}
|
} else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
|
||||||
else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
|
|
||||||
{
|
|
||||||
throw new ServiceException("子表关联的外键名不能为空");
|
throw new ServiceException("子表关联的外键名不能为空");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,33 +475,25 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
*
|
*
|
||||||
* @param table 业务表信息
|
* @param table 业务表信息
|
||||||
*/
|
*/
|
||||||
public void setPkColumn(GenTable table)
|
public void setPkColumn(GenTable table) {
|
||||||
{
|
for (GenTableColumn column : table.getColumns()) {
|
||||||
for (GenTableColumn column : table.getColumns())
|
if (column.isPk()) {
|
||||||
{
|
|
||||||
if (column.isPk())
|
|
||||||
{
|
|
||||||
table.setPkColumn(column);
|
table.setPkColumn(column);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.isNull(table.getPkColumn()))
|
if (ObjectUtil.isNull(table.getPkColumn())) {
|
||||||
{
|
table.setPkColumn(table.getColumns().getFirst());
|
||||||
table.setPkColumn(table.getColumns().get(0));
|
|
||||||
}
|
}
|
||||||
if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
|
if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
|
||||||
{
|
for (GenTableColumn column : table.getSubTable().getColumns()) {
|
||||||
for (GenTableColumn column : table.getSubTable().getColumns())
|
if (column.isPk()) {
|
||||||
{
|
|
||||||
if (column.isPk())
|
|
||||||
{
|
|
||||||
table.getSubTable().setPkColumn(column);
|
table.getSubTable().setPkColumn(column);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.isNull(table.getSubTable().getPkColumn()))
|
if (ObjectUtil.isNull(table.getSubTable().getPkColumn())) {
|
||||||
{
|
table.getSubTable().setPkColumn(table.getSubTable().getColumns().getFirst());
|
||||||
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,11 +503,9 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
*
|
*
|
||||||
* @param table 业务表信息
|
* @param table 业务表信息
|
||||||
*/
|
*/
|
||||||
public void setSubTable(GenTable table)
|
public void setSubTable(GenTable table) {
|
||||||
{
|
|
||||||
String subTableName = table.getSubTableName();
|
String subTableName = table.getSubTableName();
|
||||||
if (StringUtils.isNotEmpty(subTableName))
|
if (StringUtils.isNotEmpty(subTableName)) {
|
||||||
{
|
|
||||||
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
|
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,11 +515,9 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
*
|
*
|
||||||
* @param genTable 设置后的生成对象
|
* @param genTable 设置后的生成对象
|
||||||
*/
|
*/
|
||||||
public void setTableFromOptions(GenTable genTable)
|
public void setTableFromOptions(GenTable genTable) {
|
||||||
{
|
|
||||||
JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
|
JSONObject paramsObj = JSON.parseObject(genTable.getOptions());
|
||||||
if (StringUtils.isNotNull(paramsObj))
|
if (StringUtils.isNotNull(paramsObj)) {
|
||||||
{
|
|
||||||
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
|
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
|
||||||
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
|
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
|
||||||
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
||||||
@ -597,11 +539,9 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
* @param template 模板文件路径
|
* @param template 模板文件路径
|
||||||
* @return 生成地址
|
* @return 生成地址
|
||||||
*/
|
*/
|
||||||
public static String getGenPath(GenTable table, String template)
|
public static String getGenPath(GenTable table, String template) {
|
||||||
{
|
|
||||||
String genPath = table.getGenPath();
|
String genPath = table.getGenPath();
|
||||||
if (StringUtils.equals(genPath, "/"))
|
if (StringUtils.equals(genPath, "/")) {
|
||||||
{
|
|
||||||
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
|
return System.getProperty("user.dir") + File.separator + "src" + File.separator + VelocityUtils.getFileName(template, table);
|
||||||
}
|
}
|
||||||
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
return genPath + File.separator + VelocityUtils.getFileName(template, table);
|
||||||
@ -610,10 +550,10 @@ public class GenTableServiceImpl extends BaseServiceImpl<GenTableMapper, GenTabl
|
|||||||
/**
|
/**
|
||||||
* 设置生成的sys_menu6条记录的主键值
|
* 设置生成的sys_menu6条记录的主键值
|
||||||
* 日期时间格式YYYYMMDDHHMMSS转化为数值,然后+01
|
* 日期时间格式YYYYMMDDHHMMSS转化为数值,然后+01
|
||||||
* @param table
|
*
|
||||||
|
* @param table table
|
||||||
*/
|
*/
|
||||||
private void setMenuIds(GenTable table)
|
private void setMenuIds(GenTable table) {
|
||||||
{
|
|
||||||
String nowStr = DateUtils.dateTimeNow();
|
String nowStr = DateUtils.dateTimeNow();
|
||||||
List<Long> menuIds = new ArrayList<>();
|
List<Long> menuIds = new ArrayList<>();
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
|
@ -13,15 +13,14 @@ import com.ruoyi.generator.domain.GenTable;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @author 数据小王子
|
* @author 数据小王子
|
||||||
*/
|
*/
|
||||||
public interface IGenTableService extends IBaseService<GenTable>
|
public interface IGenTableService extends IBaseService<GenTable> {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 查询据库列表
|
* 查询据库列表
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectDbTableList(GenTable genTable);
|
List<GenTable> selectDbTableList(GenTable genTable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询业务列表
|
* 分页查询业务列表
|
||||||
@ -37,14 +36,14 @@ public interface IGenTableService extends IBaseService<GenTable>
|
|||||||
* @param tableNames 表名称组
|
* @param tableNames 表名称组
|
||||||
* @return 数据库表集合
|
* @return 数据库表集合
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectDbTableListByNames(String[] tableNames);
|
List<GenTable> selectDbTableListByNames(String[] tableNames);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询所有表信息
|
* 查询所有表信息
|
||||||
*
|
*
|
||||||
* @return 表信息集合
|
* @return 表信息集合
|
||||||
*/
|
*/
|
||||||
public List<GenTable> selectGenTableAll();
|
List<GenTable> selectGenTableAll();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询业务信息
|
* 查询业务信息
|
||||||
@ -52,7 +51,7 @@ public interface IGenTableService extends IBaseService<GenTable>
|
|||||||
* @param id 业务ID
|
* @param id 业务ID
|
||||||
* @return 业务信息
|
* @return 业务信息
|
||||||
*/
|
*/
|
||||||
public GenTable selectGenTableById(Long id);
|
GenTable selectGenTableById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改业务
|
* 修改业务
|
||||||
@ -60,7 +59,7 @@ public interface IGenTableService extends IBaseService<GenTable>
|
|||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public void updateGenTable(GenTable genTable);
|
void updateGenTable(GenTable genTable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除业务信息
|
* 删除业务信息
|
||||||
@ -68,58 +67,62 @@ public interface IGenTableService extends IBaseService<GenTable>
|
|||||||
* @param tableIds 需要删除的表数据ID
|
* @param tableIds 需要删除的表数据ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public void deleteGenTableByIds(Long[] tableIds);
|
void deleteGenTableByIds(Long[] tableIds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入表结构
|
* 导入表结构
|
||||||
*
|
*
|
||||||
* @param tableList 导入表列表
|
* @param tableList 导入表列表
|
||||||
*/
|
*/
|
||||||
public void importGenTable(List<GenTable> tableList);
|
void importGenTable(List<GenTable> tableList);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览代码
|
* 预览代码
|
||||||
*
|
*
|
||||||
* @param tableId 表编号
|
* @param tableId 表编号
|
||||||
|
* @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
* @return 预览数据列表
|
* @return 预览数据列表
|
||||||
*/
|
*/
|
||||||
public Map<String, String> previewCode(Long tableId);
|
Map<String, String> previewCode(Long tableId, Integer frontType);
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(下载方式)
|
|
||||||
*
|
|
||||||
* @param tableName 表名称
|
|
||||||
* @return 数据
|
|
||||||
*/
|
|
||||||
public byte[] downloadCode(String tableName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成代码(自定义路径)
|
* 生成代码(自定义路径)
|
||||||
*
|
*
|
||||||
* @param tableName 表名称
|
* @param tableId 表ID
|
||||||
|
* @param frontType 前端界面类型取值:0是element-js、1是element-ts、2是antdesign-ts
|
||||||
* @return 数据
|
* @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 数据
|
* @return 数据
|
||||||
*/
|
*/
|
||||||
public byte[] downloadCode(String[] tableNames);
|
byte[] downloadCode(String[] tableIds, Integer frontType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存参数校验
|
* 修改保存参数校验
|
||||||
*
|
*
|
||||||
* @param genTable 业务信息
|
* @param genTable 业务信息
|
||||||
*/
|
*/
|
||||||
public void validateEdit(GenTable genTable);
|
void validateEdit(GenTable genTable);
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
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 com.ruoyi.common.orm.helper.DataBaseHelper;
|
||||||
import org.apache.velocity.VelocityContext;
|
import org.apache.velocity.VelocityContext;
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
@ -24,15 +22,20 @@ import com.ruoyi.generator.domain.GenTableColumn;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
* @author 数据小王子
|
* @author 数据小王子
|
||||||
*/
|
*/
|
||||||
public class VelocityUtils
|
public class VelocityUtils {
|
||||||
{
|
/**
|
||||||
/** 项目空间路径 */
|
* 项目空间路径
|
||||||
|
*/
|
||||||
private static final String PROJECT_PATH = "main/java";
|
private static final String PROJECT_PATH = "main/java";
|
||||||
|
|
||||||
/** mybatis空间路径 */
|
/**
|
||||||
|
* mybatis空间路径
|
||||||
|
*/
|
||||||
private static final String MYBATIS_PATH = "main/resources/mapper";
|
private static final String MYBATIS_PATH = "main/resources/mapper";
|
||||||
|
|
||||||
/** 默认上级菜单,系统工具 */
|
/**
|
||||||
|
* 默认上级菜单,系统工具
|
||||||
|
*/
|
||||||
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
private static final String DEFAULT_PARENT_MENU_ID = "3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +43,7 @@ public class VelocityUtils
|
|||||||
*
|
*
|
||||||
* @return 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public static VelocityContext prepareContext(GenTable genTable)
|
public static VelocityContext prepareContext(GenTable genTable) {
|
||||||
{
|
|
||||||
String moduleName = genTable.getModuleName();
|
String moduleName = genTable.getModuleName();
|
||||||
String businessName = genTable.getBusinessName();
|
String businessName = genTable.getBusinessName();
|
||||||
String packageName = genTable.getPackageName();
|
String packageName = genTable.getPackageName();
|
||||||
@ -69,27 +71,23 @@ public class VelocityUtils
|
|||||||
velocityContext.put("table", genTable);
|
velocityContext.put("table", genTable);
|
||||||
velocityContext.put("dicts", getDicts(genTable));
|
velocityContext.put("dicts", getDicts(genTable));
|
||||||
setMenuVelocityContext(velocityContext, genTable);
|
setMenuVelocityContext(velocityContext, genTable);
|
||||||
if (GenConstants.TPL_TREE.equals(tplCategory))
|
if (GenConstants.TPL_TREE.equals(tplCategory)) {
|
||||||
{
|
|
||||||
setTreeVelocityContext(velocityContext, genTable);
|
setTreeVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
if (GenConstants.TPL_SUB.equals(tplCategory))
|
if (GenConstants.TPL_SUB.equals(tplCategory)) {
|
||||||
{
|
|
||||||
setSubVelocityContext(velocityContext, genTable);
|
setSubVelocityContext(velocityContext, genTable);
|
||||||
}
|
}
|
||||||
return velocityContext;
|
return velocityContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
|
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSON.parseObject(options);
|
JSONObject paramsObj = JSON.parseObject(options);
|
||||||
String parentMenuId = getParentMenuId(paramsObj);
|
String parentMenuId = getParentMenuId(paramsObj);
|
||||||
context.put("parentMenuId", parentMenuId);
|
context.put("parentMenuId", parentMenuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
|
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSON.parseObject(options);
|
JSONObject paramsObj = JSON.parseObject(options);
|
||||||
String treeCode = getTreecode(paramsObj);
|
String treeCode = getTreecode(paramsObj);
|
||||||
@ -100,18 +98,15 @@ public class VelocityUtils
|
|||||||
context.put("treeParentCode", treeParentCode);
|
context.put("treeParentCode", treeParentCode);
|
||||||
context.put("treeName", treeName);
|
context.put("treeName", treeName);
|
||||||
context.put("expandColumn", getExpandColumn(genTable));
|
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));
|
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));
|
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();
|
GenTable subTable = genTable.getSubTable();
|
||||||
String subTableName = genTable.getSubTableName();
|
String subTableName = genTable.getSubTableName();
|
||||||
String subTableFkName = genTable.getSubTableFkName();
|
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 模板列表
|
* @return 模板列表
|
||||||
*/
|
*/
|
||||||
public static List<String> getTemplateList(String tplCategory)
|
public static List<String> getTemplateList(String tplCategory, Integer frontType) {
|
||||||
{
|
|
||||||
List<String> templates = new ArrayList<>();
|
List<String> templates = new ArrayList<>();
|
||||||
templates.add("vm/java/domain.java.vm");
|
templates.add("vm/java/domain.java.vm");
|
||||||
templates.add("vm/java/vo.java.vm");
|
templates.add("vm/java/vo.java.vm");
|
||||||
@ -151,30 +147,62 @@ public class VelocityUtils
|
|||||||
} else {
|
} else {
|
||||||
templates.add("vm/sql/mysql/sql.vm");
|
templates.add("vm/sql/mysql/sql.vm");
|
||||||
}
|
}
|
||||||
templates.add("vm/js/api.js.vm");
|
|
||||||
if (GenConstants.TPL_CRUD.equals(tplCategory))
|
switch (frontType) {
|
||||||
{
|
case 0 -> templates.add("vm/api/element.js.api.vm");
|
||||||
templates.add("vm/vue/index.vue.vm");
|
case 1 -> {
|
||||||
|
templates.add("vm/api/element.ts.api.vm");
|
||||||
|
templates.add("vm/api/element.ts.types.vm");
|
||||||
}
|
}
|
||||||
else if (GenConstants.TPL_TREE.equals(tplCategory))
|
case 2 -> {
|
||||||
{
|
templates.add("vm/api/antdesign.ts.index.vm");
|
||||||
templates.add("vm/vue/index-tree.vue.vm");
|
templates.add("vm/api/antdesign.ts.model.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-domain.java.vm");
|
||||||
templates.add("vm/java/sub-mapper.java.vm");
|
templates.add("vm/java/sub-mapper.java.vm");
|
||||||
templates.add("vm/xml/sub-mapper.xml.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;
|
return templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件名
|
* 获取文件名
|
||||||
*/
|
*/
|
||||||
public static String getFileName(String template, GenTable genTable)
|
public static String getFileName(String template, GenTable genTable) {
|
||||||
{
|
|
||||||
// 文件名称
|
// 文件名称
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
// 包路径
|
// 包路径
|
||||||
@ -189,25 +217,54 @@ public class VelocityUtils
|
|||||||
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
|
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
|
||||||
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
|
||||||
String vuePath = "vue";
|
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/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/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/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/mapper.java.vm" ->
|
||||||
case "vm/java/sub-mapper.java.vm" -> fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, genTable.getSubTable().getClassName());
|
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
|
||||||
case "vm/java/service.java.vm" -> fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
|
case "vm/java/sub-mapper.java.vm" ->
|
||||||
case "vm/java/serviceImpl.java.vm" -> fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
|
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, genTable.getSubTable().getClassName());
|
||||||
case "vm/java/controller.java.vm" -> fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
|
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/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/postgresql/sql.vm" -> fileName = businessName + "Menu(postgresql).sql";
|
||||||
case "vm/sql/mysql/sql.vm" -> fileName = businessName + "Menu(mysql).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/api/element.js.api.vm" ->
|
||||||
case "vm/vue/index.vue.vm" -> fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
|
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
|
||||||
case "vm/vue/index-tree.vue.vm" -> fileName = StringUtils.format("{}/views/{}/{}/index.vue", 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";
|
default -> fileName = "default.xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +277,7 @@ public class VelocityUtils
|
|||||||
* @param packageName 包名称
|
* @param packageName 包名称
|
||||||
* @return 包前缀名称
|
* @return 包前缀名称
|
||||||
*/
|
*/
|
||||||
public static String getPackagePrefix(String packageName)
|
public static String getPackagePrefix(String packageName) {
|
||||||
{
|
|
||||||
int lastIndex = packageName.lastIndexOf(".");
|
int lastIndex = packageName.lastIndexOf(".");
|
||||||
return StringUtils.substring(packageName, 0, lastIndex);
|
return StringUtils.substring(packageName, 0, lastIndex);
|
||||||
}
|
}
|
||||||
@ -232,24 +288,18 @@ public class VelocityUtils
|
|||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 返回需要导入的包列表
|
* @return 返回需要导入的包列表
|
||||||
*/
|
*/
|
||||||
public static HashSet<String> getImportList(GenTable genTable)
|
public static HashSet<String> getImportList(GenTable genTable) {
|
||||||
{
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
GenTable subGenTable = genTable.getSubTable();
|
GenTable subGenTable = genTable.getSubTable();
|
||||||
HashSet<String> importList = new HashSet<>();
|
HashSet<String> importList = new HashSet<>();
|
||||||
if (StringUtils.isNotNull(subGenTable))
|
if (StringUtils.isNotNull(subGenTable)) {
|
||||||
{
|
|
||||||
importList.add("java.util.List");
|
importList.add("java.util.List");
|
||||||
}
|
}
|
||||||
for (GenTableColumn column : columns)
|
for (GenTableColumn column : columns) {
|
||||||
{
|
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
|
||||||
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType()))
|
|
||||||
{
|
|
||||||
importList.add("java.util.Date");
|
importList.add("java.util.Date");
|
||||||
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
|
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");
|
importList.add("java.math.BigDecimal");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,13 +312,11 @@ public class VelocityUtils
|
|||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 返回字典组
|
* @return 返回字典组
|
||||||
*/
|
*/
|
||||||
public static String getDicts(GenTable genTable)
|
public static String getDicts(GenTable genTable) {
|
||||||
{
|
|
||||||
List<GenTableColumn> columns = genTable.getColumns();
|
List<GenTableColumn> columns = genTable.getColumns();
|
||||||
Set<String> dicts = new HashSet<>();
|
Set<String> dicts = new HashSet<>();
|
||||||
addDicts(dicts, columns);
|
addDicts(dicts, columns);
|
||||||
if (StringUtils.isNotNull(genTable.getSubTable()))
|
if (StringUtils.isNotNull(genTable.getSubTable())) {
|
||||||
{
|
|
||||||
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
||||||
addDicts(dicts, subColumns);
|
addDicts(dicts, subColumns);
|
||||||
}
|
}
|
||||||
@ -281,14 +329,11 @@ public class VelocityUtils
|
|||||||
* @param dicts 字典列表
|
* @param dicts 字典列表
|
||||||
* @param columns 列集合
|
* @param columns 列集合
|
||||||
*/
|
*/
|
||||||
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
|
public static void addDicts(Set<String> dicts, List<GenTableColumn> columns) {
|
||||||
{
|
for (GenTableColumn column : columns) {
|
||||||
for (GenTableColumn column : columns)
|
|
||||||
{
|
|
||||||
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
||||||
column.getHtmlType(),
|
column.getHtmlType(),
|
||||||
new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX }))
|
new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) {
|
||||||
{
|
|
||||||
dicts.add("'" + column.getDictType() + "'");
|
dicts.add("'" + column.getDictType() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,8 +346,7 @@ public class VelocityUtils
|
|||||||
* @param businessName 业务名称
|
* @param businessName 业务名称
|
||||||
* @return 返回权限前缀
|
* @return 返回权限前缀
|
||||||
*/
|
*/
|
||||||
public static String getPermissionPrefix(String moduleName, String businessName)
|
public static String getPermissionPrefix(String moduleName, String businessName) {
|
||||||
{
|
|
||||||
return StringUtils.format("{}:{}", moduleName, businessName);
|
return StringUtils.format("{}:{}", moduleName, businessName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,11 +356,9 @@ public class VelocityUtils
|
|||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 上级菜单ID字段
|
* @return 上级菜单ID字段
|
||||||
*/
|
*/
|
||||||
public static String getParentMenuId(JSONObject paramsObj)
|
public static String getParentMenuId(JSONObject paramsObj) {
|
||||||
{
|
|
||||||
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
|
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 paramsObj.getString(GenConstants.PARENT_MENU_ID);
|
||||||
}
|
}
|
||||||
return DEFAULT_PARENT_MENU_ID;
|
return DEFAULT_PARENT_MENU_ID;
|
||||||
@ -328,10 +370,8 @@ public class VelocityUtils
|
|||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树编码
|
* @return 树编码
|
||||||
*/
|
*/
|
||||||
public static String getTreecode(JSONObject paramsObj)
|
public static String getTreecode(JSONObject paramsObj) {
|
||||||
{
|
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
|
||||||
if (paramsObj.containsKey(GenConstants.TREE_CODE))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
@ -343,10 +383,8 @@ public class VelocityUtils
|
|||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树父编码
|
* @return 树父编码
|
||||||
*/
|
*/
|
||||||
public static String getTreeParentCode(JSONObject paramsObj)
|
public static String getTreeParentCode(JSONObject paramsObj) {
|
||||||
{
|
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
@ -358,10 +396,8 @@ public class VelocityUtils
|
|||||||
* @param paramsObj 生成其他选项
|
* @param paramsObj 生成其他选项
|
||||||
* @return 树名称
|
* @return 树名称
|
||||||
*/
|
*/
|
||||||
public static String getTreeName(JSONObject paramsObj)
|
public static String getTreeName(JSONObject paramsObj) {
|
||||||
{
|
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) {
|
||||||
if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME))
|
|
||||||
{
|
|
||||||
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
|
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
|
||||||
}
|
}
|
||||||
return StringUtils.EMPTY;
|
return StringUtils.EMPTY;
|
||||||
@ -373,20 +409,16 @@ public class VelocityUtils
|
|||||||
* @param genTable 业务表对象
|
* @param genTable 业务表对象
|
||||||
* @return 展开按钮列序号
|
* @return 展开按钮列序号
|
||||||
*/
|
*/
|
||||||
public static int getExpandColumn(GenTable genTable)
|
public static int getExpandColumn(GenTable genTable) {
|
||||||
{
|
|
||||||
String options = genTable.getOptions();
|
String options = genTable.getOptions();
|
||||||
JSONObject paramsObj = JSON.parseObject(options);
|
JSONObject paramsObj = JSON.parseObject(options);
|
||||||
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
||||||
int num = 0;
|
int num = 0;
|
||||||
for (GenTableColumn column : genTable.getColumns())
|
for (GenTableColumn column : genTable.getColumns()) {
|
||||||
{
|
if (column.isList()) {
|
||||||
if (column.isList())
|
|
||||||
{
|
|
||||||
num++;
|
num++;
|
||||||
String columnName = column.getColumnName();
|
String columnName = column.getColumnName();
|
||||||
if (columnName.equals(treeName))
|
if (columnName.equals(treeName)) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="deleteGenTableColumns">
|
|
||||||
delete from gen_table_column where column_id in
|
|
||||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
|
||||||
#{item.columnId}
|
|
||||||
</foreach>
|
|
||||||
</delete>
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
@ -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<Blob>(
|
||||||
|
{ 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<void>({ url: '/${moduleName}/${businessName}', data });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新${functionName}
|
||||||
|
* @param data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function ${businessName}Update(data: ${BusinessName}Form) {
|
||||||
|
return defHttp.putWithMsg<void>({ url: '/${moduleName}/${businessName}', data });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除${functionName}
|
||||||
|
* @param ${pkColumn.javaField} id
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function ${businessName}Remove(${pkColumn.javaField}: ID | IDS) {
|
||||||
|
return defHttp.deleteWithMsg<void>({ url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField} },);
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
@ -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<string | number>) => {
|
||||||
|
return request({
|
||||||
|
url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField},
|
||||||
|
method: 'delete'
|
||||||
|
});
|
||||||
|
};
|
@ -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;
|
||||||
|
}
|
@ -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
|
||||||
|
];
|
@ -0,0 +1,121 @@
|
|||||||
|
<template>
|
||||||
|
<PageWrapper dense>
|
||||||
|
<BasicTable @register="registerTable">
|
||||||
|
<template #tableTitle>
|
||||||
|
<Space>
|
||||||
|
<a-button
|
||||||
|
type="primary"
|
||||||
|
:pre-icon="IconEnum.ADD"
|
||||||
|
@click="handleAdd"
|
||||||
|
v-auth="'${permissionPrefix}:add'"
|
||||||
|
>新增${functionName}</a-button
|
||||||
|
>
|
||||||
|
<a-button
|
||||||
|
:preIcon="IconEnum.DELETE"
|
||||||
|
danger
|
||||||
|
@click="multipleRemove(${businessName}Remove)"
|
||||||
|
:disabled="!selected"
|
||||||
|
v-auth="'${permissionPrefix}:remove'"
|
||||||
|
>选中删除</a-button
|
||||||
|
>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
<template #toolbar>
|
||||||
|
<Space>
|
||||||
|
<a-button
|
||||||
|
:preIcon="IconEnum.EXPORT"
|
||||||
|
color="warning"
|
||||||
|
@click="downloadExcel(${businessName}Export, '${functionName}数据')"
|
||||||
|
ghost
|
||||||
|
v-auth="'${permissionPrefix}:export'"
|
||||||
|
>导出数据</a-button
|
||||||
|
>
|
||||||
|
</Space>
|
||||||
|
</template>
|
||||||
|
<template #bodyCell="{ column, record }">
|
||||||
|
<template v-if="column.key === 'action'">
|
||||||
|
<TableAction
|
||||||
|
stopButtonPropagation
|
||||||
|
:actions="[
|
||||||
|
{
|
||||||
|
label: '修改',
|
||||||
|
icon: IconEnum.EDIT,
|
||||||
|
type: 'primary',
|
||||||
|
ghost: true,
|
||||||
|
auth: '${permissionPrefix}:edit',
|
||||||
|
onClick: handleEdit.bind(null, record),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
icon: IconEnum.DELETE,
|
||||||
|
type: 'danger',
|
||||||
|
ghost: true,
|
||||||
|
auth: '${permissionPrefix}:remove',
|
||||||
|
popConfirm: {
|
||||||
|
placement: 'left',
|
||||||
|
title: '是否删除${functionName}[' + record.${pkColumn.javaField} + ']?',
|
||||||
|
confirm: handleDelete.bind(null, record),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
<${BusinessName}Modal @register="registerModal" @reload="reloadWithCallback" />
|
||||||
|
</PageWrapper>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { PageWrapper } from '@/components/Page';
|
||||||
|
import { BasicTable, useTable, TableAction } from '@/components/Table';
|
||||||
|
import { Space } from 'ant-design-vue';
|
||||||
|
import { ${businessName}List, ${businessName}Export, ${businessName}Remove } from '@/api/${moduleName}/${businessName}';
|
||||||
|
import { downloadExcel } from '@/utils/file/download';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
import ${BusinessName}Modal from './${BusinessName}Modal.vue';
|
||||||
|
import { formSchems, columns } from './${businessName}.data';
|
||||||
|
import { IconEnum } from '@/enums/appEnum';
|
||||||
|
|
||||||
|
defineOptions({ name: '${BusinessName}' });
|
||||||
|
|
||||||
|
const [registerTable, { reload, reloadWithCallback, multipleRemove, selected }] = useTable({
|
||||||
|
rowSelection: {
|
||||||
|
type: 'checkbox',
|
||||||
|
},
|
||||||
|
api: ${businessName}List,
|
||||||
|
showIndexColumn: false,
|
||||||
|
rowKey: '${pkColumn.javaField}',
|
||||||
|
useSearchForm: true,
|
||||||
|
formConfig: {
|
||||||
|
schemas: formSchems,
|
||||||
|
baseColProps: {
|
||||||
|
span: 8,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
columns: columns,
|
||||||
|
actionColumn: {
|
||||||
|
width: 200,
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerModal, { openModal }] = useModal();
|
||||||
|
|
||||||
|
function handleEdit(record: Recordable) {
|
||||||
|
openModal(true, { record, update: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
openModal(true, { update: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDelete(record: Recordable) {
|
||||||
|
await ${businessName}Remove([record.${pkColumn.javaField}]);
|
||||||
|
await reload();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<BasicModal
|
||||||
|
v-bind="$attrs"
|
||||||
|
:title="title"
|
||||||
|
@register="registerInnerModal"
|
||||||
|
@ok="handleSubmit"
|
||||||
|
@cancel="resetForm"
|
||||||
|
>
|
||||||
|
<BasicForm @register="registerForm" />
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal';
|
||||||
|
import { BasicForm, useForm } from '@/components/Form';
|
||||||
|
import { computed, ref, unref } from 'vue';
|
||||||
|
import { ${businessName}Info, ${businessName}Add, ${businessName}Update } from '@/api/${moduleName}/${businessName}';
|
||||||
|
import { modalSchemas } from './${businessName}.data';
|
||||||
|
|
||||||
|
defineOptions({ name: '${BusinessName}Modal' });
|
||||||
|
|
||||||
|
const emit = defineEmits(['register', 'reload']);
|
||||||
|
|
||||||
|
const isUpdate = ref<boolean>(false);
|
||||||
|
const title = computed<string>(() => {
|
||||||
|
return isUpdate.value ? '编辑${functionName}' : '新增${functionName}';
|
||||||
|
});
|
||||||
|
|
||||||
|
const [registerInnerModal, { modalLoading, closeModal }] = useModalInner(
|
||||||
|
async (data: { record?: Recordable; update: boolean }) => {
|
||||||
|
const { record, update } = data;
|
||||||
|
isUpdate.value = update;
|
||||||
|
if (update && record) {
|
||||||
|
const ret = await ${businessName}Info(record.${pkColumn.javaField});
|
||||||
|
await setFieldsValue(ret);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetForm, validate }] = useForm({
|
||||||
|
labelWidth: 100,
|
||||||
|
showActionButtonGroup: false,
|
||||||
|
baseColProps: { span: 24 },
|
||||||
|
schemas: modalSchemas,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
modalLoading(true);
|
||||||
|
const data = await validate();
|
||||||
|
if (unref(isUpdate)) {
|
||||||
|
await ${businessName}Update(data);
|
||||||
|
} else {
|
||||||
|
await ${businessName}Add(data);
|
||||||
|
}
|
||||||
|
await resetForm();
|
||||||
|
emit('reload', closeModal);
|
||||||
|
} catch (e) {
|
||||||
|
} finally {
|
||||||
|
modalLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped></style>
|
@ -157,8 +157,7 @@
|
|||||||
<el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#set($field=$column.javaField)
|
#set($field=$column.javaField)
|
||||||
#if($column.insert && !$column.pk)
|
#if(($column.insert || $column.edit) && !$column.pk)
|
||||||
#if(($column.usableColumn) || (!$column.superColumn))
|
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
@ -178,9 +177,15 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
#elseif($column.htmlType == "input")
|
#elseif($column.htmlType == "input")
|
||||||
|
#if(${field} == "version")
|
||||||
|
<el-form-item label="${comment}" prop="${field}" v-show="false">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#else
|
||||||
<el-form-item label="${comment}" prop="${field}">
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
#end
|
||||||
#elseif($column.htmlType == "imageUpload")
|
#elseif($column.htmlType == "imageUpload")
|
||||||
<el-form-item label="${comment}" prop="${field}">
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
<image-upload v-model="form.${field}"/>
|
<image-upload v-model="form.${field}"/>
|
||||||
@ -266,7 +271,6 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
|
||||||
#end
|
#end
|
||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@ -375,9 +379,13 @@ function reset() {
|
|||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.htmlType == "checkbox")
|
#if($column.htmlType == "checkbox")
|
||||||
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
#if(${column.javaField} == "version")
|
||||||
|
$column.javaField: 0#if($foreach.count != $columns.size()),#end
|
||||||
#else
|
#else
|
||||||
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
};
|
};
|
||||||
proxy.resetForm("${businessName}Ref");
|
proxy.resetForm("${businessName}Ref");
|
@ -167,8 +167,7 @@
|
|||||||
<el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
|
<el-form ref="${businessName}Ref" :model="form" :rules="rules" label-width="80px">
|
||||||
#foreach($column in $columns)
|
#foreach($column in $columns)
|
||||||
#set($field=$column.javaField)
|
#set($field=$column.javaField)
|
||||||
#if($column.insert && !$column.pk)
|
#if(($column.insert || $column.edit) && !$column.pk)
|
||||||
#if(($column.usableColumn) || (!$column.superColumn))
|
|
||||||
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
#if($parentheseIndex != -1)
|
#if($parentheseIndex != -1)
|
||||||
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
@ -177,9 +176,15 @@
|
|||||||
#end
|
#end
|
||||||
#set($dictType=$column.dictType)
|
#set($dictType=$column.dictType)
|
||||||
#if($column.htmlType == "input")
|
#if($column.htmlType == "input")
|
||||||
|
#if(${field} == "version")
|
||||||
|
<el-form-item label="${comment}" prop="${field}" v-show="false">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#else
|
||||||
<el-form-item label="${comment}" prop="${field}">
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
#end
|
||||||
#elseif($column.htmlType == "imageUpload")
|
#elseif($column.htmlType == "imageUpload")
|
||||||
<el-form-item label="${comment}" prop="${field}">
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
<image-upload v-model="form.${field}"/>
|
<image-upload v-model="form.${field}"/>
|
||||||
@ -266,7 +271,6 @@
|
|||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#end
|
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
<el-divider content-position="center">${subTable.functionName}信息</el-divider>
|
<el-divider content-position="center">${subTable.functionName}信息</el-divider>
|
||||||
<el-row :gutter="10" class="mb8">
|
<el-row :gutter="10" class="mb8">
|
||||||
@ -451,9 +455,13 @@ function reset() {
|
|||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.htmlType == "checkbox")
|
#if($column.htmlType == "checkbox")
|
||||||
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
#if(${column.javaField} == "version")
|
||||||
|
$column.javaField: 0#if($foreach.count != $columns.size()),#end
|
||||||
#else
|
#else
|
||||||
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
$column.javaField: null#if($foreach.count != $columns.size()),#end
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
#end
|
#end
|
||||||
};
|
};
|
||||||
#if($table.sub)
|
#if($table.sub)
|
@ -0,0 +1,511 @@
|
|||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
|
<div class="search" v-show="showSearch">
|
||||||
|
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#set($dictType=$column.dictType)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#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" || $column.htmlType == "textarea")
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-input v-model="queryParams.${column.javaField}" placeholder="请输入${comment}" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-date-picker clearable
|
||||||
|
v-model="queryParams.${column.javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
<el-form-item label="${comment}" style="width: 308px">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="dateRange${AttrName}"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
type="daterange"
|
||||||
|
range-separator="-"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="handleAdd()" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
<el-table
|
||||||
|
v-loading="loading"
|
||||||
|
:data="${businessName}List"
|
||||||
|
row-key="${treeCode}"
|
||||||
|
:default-expand-all="isExpandAll"
|
||||||
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
|
||||||
|
ref="${businessName}TableRef"
|
||||||
|
>
|
||||||
|
#foreach($column in $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)
|
||||||
|
#elseif($column.list && $column.htmlType == "datetime")
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||||
|
<template #default="scope">
|
||||||
|
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && $column.htmlType == "imageUpload")
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template #default="scope">
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
|
||||||
|
#else
|
||||||
|
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField}"/>
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && "" != $javaField)
|
||||||
|
#if(${foreach.index} == 1)
|
||||||
|
<el-table-column label="${comment}" prop="${javaField}" />
|
||||||
|
#else
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tooltip content="修改" placement="top">
|
||||||
|
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']" />
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="新增" placement="top">
|
||||||
|
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['${moduleName}:${businessName}:add']" />
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']" />
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
</el-card>
|
||||||
|
<!-- 添加或修改${functionName}对话框 -->
|
||||||
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
|
<el-form ref="${businessName}FormRef" :model="form" :rules="rules" label-width="80px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#set($field=$column.javaField)
|
||||||
|
#if(($column.insert || $column.edit) && !$column.pk)
|
||||||
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
#if($parentheseIndex != -1)
|
||||||
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
|
#else
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
#end
|
||||||
|
#set($dictType=$column.dictType)
|
||||||
|
#if("" != $treeParentCode && $column.javaField == $treeParentCode)
|
||||||
|
<el-form-item label="${comment}" prop="${treeParentCode}">
|
||||||
|
<el-tree-select
|
||||||
|
v-model="form.${treeParentCode}"
|
||||||
|
:data="${businessName}Options"
|
||||||
|
:props="{ value: '${treeCode}', label: '${treeName}', children: 'children' }"
|
||||||
|
value-key="${treeCode}"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
check-strictly
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "input")
|
||||||
|
#if(${field} == "version")
|
||||||
|
<el-form-item label="${comment}" prop="${field}" v-show="false">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#else
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#elseif($column.htmlType == "imageUpload")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<image-upload v-model="form.${field}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<file-upload v-model="form.${field}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<editor v-model="form.${field}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||||
|
:value="parseInt(dict.value)"
|
||||||
|
#else
|
||||||
|
:value="dict.value"
|
||||||
|
#end
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-checkbox-group v-model="form.${field}">
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value">
|
||||||
|
{{dict.label}}
|
||||||
|
</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-checkbox-group v-model="form.${field}">
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-radio-group v-model="form.${field}">
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||||
|
:label="parseInt(dict.value)"
|
||||||
|
#else
|
||||||
|
:label="dict.value"
|
||||||
|
#end
|
||||||
|
>{{dict.label}}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-radio-group v-model="form.${field}">
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-date-picker clearable
|
||||||
|
v-model="form.${field}"
|
||||||
|
type="datetime"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
placeholder="选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="${BusinessName}" lang="ts">
|
||||||
|
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
|
||||||
|
import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
|
||||||
|
|
||||||
|
type ${BusinessName}Option = {
|
||||||
|
${treeCode}: number;
|
||||||
|
${treeName}: string;
|
||||||
|
children?: ${BusinessName}Option[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
|
||||||
|
#if(${dicts} != '')
|
||||||
|
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||||
|
const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
|
||||||
|
#end
|
||||||
|
|
||||||
|
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||||
|
const ${businessName}Options = ref<${BusinessName}Option[]>([]);
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const isExpandAll = ref(true);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
const ${businessName}FormRef = ref<ElFormInstance>();
|
||||||
|
const ${businessName}TableRef = ref<ElTableInstance>()
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
const dateRange${AttrName} = ref<[DateModelType, DateModelType]>(['', '']);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
const initFormData: ${BusinessName}Form = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.insert || $column.edit)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
#if(${column.javaField} == "version")
|
||||||
|
$column.javaField: 0#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
|
||||||
|
const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
|
||||||
|
form: {...initFormData},
|
||||||
|
queryParams: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
params: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.insert || $column.edit)
|
||||||
|
#if($column.required)
|
||||||
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
#if($parentheseIndex != -1)
|
||||||
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
|
#else
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
#end
|
||||||
|
$column.javaField: [
|
||||||
|
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
|
||||||
|
]#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
/** 查询${functionName}列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
queryParams.value.params = {};
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
proxy?.addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
const res = await list${BusinessName}(queryParams.value);
|
||||||
|
const data = proxy?.handleTree<${BusinessName}VO>(res.data, '${treeCode}', '${treeParentCode}');
|
||||||
|
if (data) {
|
||||||
|
${businessName}List.value = data;
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 查询${functionName}下拉树结构 */
|
||||||
|
const getTreeselect = async () => {
|
||||||
|
const res = await list${BusinessName}();
|
||||||
|
${businessName}Options.value = [];
|
||||||
|
const data: ${BusinessName}Option = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
|
||||||
|
data.children = proxy?.handleTree<${BusinessName}Option>(res.data, '${treeCode}', '${treeParentCode}');
|
||||||
|
${businessName}Options.value.push(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 取消按钮
|
||||||
|
const cancel = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 表单重置
|
||||||
|
const reset = () => {
|
||||||
|
form.value = {...initFormData}
|
||||||
|
${businessName}FormRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
dateRange${AttrName}.value = ['', ''];
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
const handleAdd = (row?: ${BusinessName}VO) => {
|
||||||
|
reset();
|
||||||
|
getTreeselect();
|
||||||
|
if (row != null && row.${treeCode}) {
|
||||||
|
form.value.${treeParentCode} = row.${treeCode};
|
||||||
|
} else {
|
||||||
|
form.value.${treeParentCode} = 0;
|
||||||
|
}
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '添加${functionName}';
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const handleToggleExpandAll = () => {
|
||||||
|
isExpandAll.value = !isExpandAll.value;
|
||||||
|
toggleExpandAll(${businessName}List.value, isExpandAll.value)
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 展开/折叠操作 */
|
||||||
|
const toggleExpandAll = (data: ${BusinessName}VO[], status: boolean) => {
|
||||||
|
data.forEach((item) => {
|
||||||
|
${businessName}TableRef.value?.toggleRowExpansion(item, status)
|
||||||
|
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status)
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
const handleUpdate = async (row: ${BusinessName}VO) => {
|
||||||
|
reset();
|
||||||
|
await getTreeselect();
|
||||||
|
if (row != null) {
|
||||||
|
form.value.${treeParentCode} = row.${treeParentCode};
|
||||||
|
}
|
||||||
|
const res = await get${BusinessName}(row.${pkColumn.javaField});
|
||||||
|
Object.assign(form.value, res.data);
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
form.value.$column.javaField = form.value.${column.javaField}.split(",");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = '修改${functionName}';
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提交按钮 */
|
||||||
|
const submitForm = () => {
|
||||||
|
${businessName}FormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
buttonLoading.value = true;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
form.value.$column.javaField = form.value.${column.javaField}.join(",");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
if (form.value.${pkColumn.javaField}) {
|
||||||
|
await update${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
} else {
|
||||||
|
await add${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
}
|
||||||
|
proxy?.#[[$modal]]#.msgSuccess('操作成功');
|
||||||
|
dialog.visible = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (row: ${BusinessName}VO) => {
|
||||||
|
await proxy?.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?');
|
||||||
|
loading.value = true;
|
||||||
|
await del${BusinessName}(row.${pkColumn.javaField}).finally(() => loading.value = false);
|
||||||
|
await getList();
|
||||||
|
proxy?.#[[$modal]]#.msgSuccess('删除成功');
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
@ -0,0 +1,478 @@
|
|||||||
|
<template>
|
||||||
|
<div class="p-2">
|
||||||
|
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
|
||||||
|
<div class="search" v-show="showSearch">
|
||||||
|
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#set($dictType=$column.dictType)
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
#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" || $column.htmlType == "textarea")
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-input v-model="queryParams.${column.javaField}" placeholder="请输入${comment}" clearable style="width: 240px" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable>
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
|
||||||
|
<el-form-item label="${comment}" prop="${column.javaField}">
|
||||||
|
<el-date-picker clearable
|
||||||
|
v-model="queryParams.${column.javaField}"
|
||||||
|
type="date"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
placeholder="请选择${comment}"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
<el-form-item label="${comment}" style="width: 308px">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="dateRange${AttrName}"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
type="daterange"
|
||||||
|
range-separator="-"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</div>
|
||||||
|
</transition>
|
||||||
|
|
||||||
|
<el-card shadow="never">
|
||||||
|
<template #header>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['${moduleName}:${businessName}:add']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['${moduleName}:${businessName}:edit']">修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['${moduleName}:${businessName}:remove']">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['${moduleName}:${businessName}:export']">导出</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
#foreach($column in $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)
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" v-if="${column.list}" />
|
||||||
|
#elseif($column.list && $column.htmlType == "datetime")
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
|
||||||
|
<template #default="scope">
|
||||||
|
<span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && $column.htmlType == "imageUpload")
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<image-preview :src="scope.row.${javaField}" :width="50" :height="50"/>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && $column.dictType && "" != $column.dictType)
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}">
|
||||||
|
<template #default="scope">
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField} ? scope.row.${javaField}.split(',') : []"/>
|
||||||
|
#else
|
||||||
|
<dict-tag :options="${column.dictType}" :value="scope.row.${javaField}"/>
|
||||||
|
#end
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
#elseif($column.list && "" != $javaField)
|
||||||
|
<el-table-column label="${comment}" align="center" prop="${javaField}" />
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tooltip content="修改" placement="top">
|
||||||
|
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['${moduleName}:${businessName}:edit']"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
<el-tooltip content="删除" placement="top">
|
||||||
|
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['${moduleName}:${businessName}:remove']"></el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total>0"
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNum"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</el-card>
|
||||||
|
<!-- 添加或修改${functionName}对话框 -->
|
||||||
|
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||||
|
<el-form ref="${businessName}FormRef" :model="form" :rules="rules" label-width="80px">
|
||||||
|
#foreach($column in $columns)
|
||||||
|
#set($field=$column.javaField)
|
||||||
|
#if(($column.insert || $column.edit) && !$column.pk)
|
||||||
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
#if($parentheseIndex != -1)
|
||||||
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
|
#else
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
#end
|
||||||
|
#set($dictType=$column.dictType)
|
||||||
|
#if($column.htmlType == "input")
|
||||||
|
#if(${field} == "version")
|
||||||
|
<el-form-item label="${comment}" prop="${field}" v-show="false">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#else
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-input v-model="form.${field}" placeholder="请输入${comment}" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#elseif($column.htmlType == "imageUpload")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<image-upload v-model="form.${field}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "fileUpload")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<file-upload v-model="form.${field}"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "editor")
|
||||||
|
<el-form-item label="${comment}">
|
||||||
|
<editor v-model="form.${field}" :min-height="192"/>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||||
|
<el-option
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||||
|
:value="parseInt(dict.value)"
|
||||||
|
#else
|
||||||
|
:value="dict.value"
|
||||||
|
#end
|
||||||
|
></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "select" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-select v-model="form.${field}" placeholder="请选择${comment}">
|
||||||
|
<el-option label="请选择字典生成" value="" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-checkbox-group v-model="form.${field}">
|
||||||
|
<el-checkbox
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.value">
|
||||||
|
{{dict.label}}
|
||||||
|
</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "checkbox" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-checkbox-group v-model="form.${field}">
|
||||||
|
<el-checkbox>请选择字典生成</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio" && "" != $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-radio-group v-model="form.${field}">
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in ${dictType}"
|
||||||
|
:key="dict.value"
|
||||||
|
#if($column.javaType == "Integer" || $column.javaType == "Long")
|
||||||
|
:label="parseInt(dict.value)"
|
||||||
|
#else
|
||||||
|
:label="dict.value"
|
||||||
|
#end
|
||||||
|
>{{dict.label}}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "radio" && $dictType)
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-radio-group v-model="form.${field}">
|
||||||
|
<el-radio label="1">请选择字典生成</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "datetime")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-date-picker clearable
|
||||||
|
v-model="form.${field}"
|
||||||
|
type="datetime"
|
||||||
|
value-format="YYYY-MM-DD HH:mm:ss"
|
||||||
|
placeholder="请选择${comment}">
|
||||||
|
</el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
#elseif($column.htmlType == "textarea")
|
||||||
|
<el-form-item label="${comment}" prop="${field}">
|
||||||
|
<el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
|
||||||
|
</el-form-item>
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="${BusinessName}" lang="ts">
|
||||||
|
import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from '@/api/${moduleName}/${businessName}';
|
||||||
|
import { ${BusinessName}VO, ${BusinessName}Query, ${BusinessName}Form } from '@/api/${moduleName}/${businessName}/types';
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||||
|
#if(${dicts} != '')
|
||||||
|
#set($dictsNoSymbol=$dicts.replace("'", ""))
|
||||||
|
const { ${dictsNoSymbol} } = toRefs<any>(proxy?.useDict(${dicts}));
|
||||||
|
#end
|
||||||
|
|
||||||
|
const ${businessName}List = ref<${BusinessName}VO[]>([]);
|
||||||
|
const buttonLoading = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const ids = ref<Array<string | number>>([]);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
const dateRange${AttrName} = ref<[DateModelType, DateModelType]>(['', '']);
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
|
const queryFormRef = ref<ElFormInstance>();
|
||||||
|
const ${businessName}FormRef = ref<ElFormInstance>();
|
||||||
|
|
||||||
|
const dialog = reactive<DialogOption>({
|
||||||
|
visible: false,
|
||||||
|
title: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
const initFormData: ${BusinessName}Form = {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.insert || $column.edit)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
$column.javaField: []#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
#if(${column.javaField} == "version")
|
||||||
|
$column.javaField: 0#if($foreach.count != $columns.size()),#end
|
||||||
|
#else
|
||||||
|
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
};
|
||||||
|
const data = reactive<PageData<${BusinessName}Form, ${BusinessName}Query>>({
|
||||||
|
form: {...initFormData},
|
||||||
|
queryParams: {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#if($column.htmlType != "datetime" || $column.queryType != "BETWEEN")
|
||||||
|
$column.javaField: undefined,
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
params: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.query)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
$column.javaField: undefined#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.insert || $column.edit)
|
||||||
|
#if($column.required)
|
||||||
|
#set($parentheseIndex=$column.columnComment.indexOf("("))
|
||||||
|
#if($parentheseIndex != -1)
|
||||||
|
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
|
||||||
|
#else
|
||||||
|
#set($comment=$column.columnComment)
|
||||||
|
#end
|
||||||
|
$column.javaField: [
|
||||||
|
{ required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
|
||||||
|
]#if($foreach.count != $columns.size()),#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
/** 查询${functionName}列表 */
|
||||||
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
queryParams.value.params = {};
|
||||||
|
#break
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
proxy?.addDateRange(queryParams.value, dateRange${AttrName}.value, '${AttrName}');
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
const res = await list${BusinessName}(queryParams.value);
|
||||||
|
${businessName}List.value = res.rows;
|
||||||
|
total.value = res.total;
|
||||||
|
loading.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 取消按钮 */
|
||||||
|
const cancel = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 表单重置 */
|
||||||
|
const reset = () => {
|
||||||
|
form.value = {...initFormData};
|
||||||
|
${businessName}FormRef.value?.resetFields();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
const handleQuery = () => {
|
||||||
|
queryParams.value.pageNum = 1;
|
||||||
|
getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
const resetQuery = () => {
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
|
||||||
|
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
|
||||||
|
dateRange${AttrName}.value = ['', ''];
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
queryFormRef.value?.resetFields();
|
||||||
|
handleQuery();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 多选框选中数据 */
|
||||||
|
const handleSelectionChange = (selection: ${BusinessName}VO[]) => {
|
||||||
|
ids.value = selection.map(item => item.${pkColumn.javaField});
|
||||||
|
single.value = selection.length != 1;
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
const handleAdd = () => {
|
||||||
|
reset();
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = "添加${functionName}";
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
const handleUpdate = async (row?: ${BusinessName}VO) => {
|
||||||
|
reset();
|
||||||
|
const _${pkColumn.javaField} = row?.${pkColumn.javaField} || ids.value[0]
|
||||||
|
const res = await get${BusinessName}(_${pkColumn.javaField});
|
||||||
|
Object.assign(form.value, res.data);
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
form.value.$column.javaField = form.value.${column.javaField}.split(",");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
dialog.visible = true;
|
||||||
|
dialog.title = "修改${functionName}";
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 提交按钮 */
|
||||||
|
const submitForm = () => {
|
||||||
|
${businessName}FormRef.value?.validate(async (valid: boolean) => {
|
||||||
|
if (valid) {
|
||||||
|
buttonLoading.value = true;
|
||||||
|
#foreach ($column in $columns)
|
||||||
|
#if($column.htmlType == "checkbox")
|
||||||
|
form.value.$column.javaField = form.value.${column.javaField}.join(",");
|
||||||
|
#end
|
||||||
|
#end
|
||||||
|
if (form.value.${pkColumn.javaField}) {
|
||||||
|
await update${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
} else {
|
||||||
|
await add${BusinessName}(form.value).finally(() => buttonLoading.value = false);
|
||||||
|
}
|
||||||
|
proxy?.#[[$modal]]#.msgSuccess("修改成功");
|
||||||
|
dialog.visible = false;
|
||||||
|
await getList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
const handleDelete = async (row?: ${BusinessName}VO) => {
|
||||||
|
const _${pkColumn.javaField}s = row?.${pkColumn.javaField} || ids.value;
|
||||||
|
await proxy?.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + _${pkColumn.javaField}s + '"的数据项?').finally(() => loading.value = false);
|
||||||
|
await del${BusinessName}(_${pkColumn.javaField}s);
|
||||||
|
proxy?.#[[$modal]]#.msgSuccess("删除成功");
|
||||||
|
await getList();
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
const handleExport = () => {
|
||||||
|
proxy?.download('${moduleName}/${businessName}/export', {
|
||||||
|
...queryParams.value
|
||||||
|
}, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user