Compare commits

..

No commits in common. "7f59db44ce5ef0dd810156e038283287b8ef5777" and "54fe820d26bdfb33038f55671826005175e64fc5" have entirely different histories.

7 changed files with 29 additions and 77 deletions

View File

@ -1,7 +1,6 @@
package cn.bunny.core.template; package cn.bunny.core.template;
import cn.bunny.domain.dto.VmsArgumentDto; import cn.bunny.domain.dto.VmsArgumentDto;
import cn.bunny.domain.entity.TableMetaData;
import cn.bunny.utils.TypeConvertUtil; import cn.bunny.utils.TypeConvertUtil;
import org.apache.velocity.Template; import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext; import org.apache.velocity.VelocityContext;
@ -19,17 +18,17 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
private final VmsArgumentDto dto; private final VmsArgumentDto dto;
private final String path; private final String path;
private final TableMetaData tableMetaData; private final String tableName;
/** /**
* @param dto 类名称可以自定义格式为 xxx_xxx * @param dto 类名称可以自定义格式为 xxx_xxx
* @param path 当前路径 * @param path 当前路径
* @param tableMetaData 表名称 * @param tableName 表名称
*/ */
public VmsArgumentDtoBaseVmsGeneratorTemplate(VmsArgumentDto dto, String path, TableMetaData tableMetaData) { public VmsArgumentDtoBaseVmsGeneratorTemplate(VmsArgumentDto dto, String path, String tableName) {
this.dto = dto; this.dto = dto;
this.path = path; this.path = path;
this.tableMetaData = tableMetaData; this.tableName = tableName;
} }
/** /**
@ -39,11 +38,6 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
*/ */
@Override @Override
void addContext(VelocityContext context) { void addContext(VelocityContext context) {
// 当前的表名
String tableName = tableMetaData.getTableName();
// 表的注释内容
String comment = tableMetaData.getComment();
// 当前日期 // 当前日期
String date = new SimpleDateFormat(dto.getSimpleDateFormat()).format(new Date()); String date = new SimpleDateFormat(dto.getSimpleDateFormat()).format(new Date());
context.put("date", date); context.put("date", date);
@ -55,7 +49,7 @@ public class VmsArgumentDtoBaseVmsGeneratorTemplate extends AbstractVmsGenerator
context.put("requestMapping", dto.getRequestMapping()); context.put("requestMapping", dto.getRequestMapping());
// 表字段的注释内容 // 表字段的注释内容
context.put("comment", comment); context.put("comment", dto.getComment());
// 设置包名称 // 设置包名称
context.put("package", dto.getPackageName()); context.put("package", dto.getPackageName());

View File

@ -36,11 +36,13 @@ public class VmsArgumentDto {
@Schema(name = "tablePrefixes", description = "去除表前缀") @Schema(name = "tablePrefixes", description = "去除表前缀")
private String tablePrefixes; private String tablePrefixes;
@Schema(name = "comment", description = "注释内容")
private String comment;
@Schema(name = "path", description = "路径") @Schema(name = "path", description = "路径")
private List<String> path; private List<String> path;
@Schema(name = "sql", description = "SQL 语句") @Schema(name = "sql", description = "SQL 语句")
private String sql; private String sql;
} }

View File

@ -62,7 +62,7 @@ public class VmsServiceImpl implements VmsService {
// 下载文件名称 // 下载文件名称
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
String digestHex = MD5.create().digestHex(currentTimeMillis + ""); String digestHex = MD5.create().digestHex(currentTimeMillis + "");
String generateZipFilename = "generator-" + digestHex.substring(0, 4) + ".zip"; String generateZipFilename = digestHex + ".zip";
// 设置响应头 // 设置响应头
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();

View File

@ -44,7 +44,7 @@ public class VmsCodeGeneratorService {
return dto.getPath().stream() return dto.getPath().stream()
.map(path -> { .map(path -> {
VmsArgumentDtoBaseVmsGeneratorTemplate generator = new VmsArgumentDtoBaseVmsGeneratorTemplate(dto, path, tableMetaData); VmsArgumentDtoBaseVmsGeneratorTemplate generator = new VmsArgumentDtoBaseVmsGeneratorTemplate(dto, path, tableName);
StringWriter writer = generator.generatorCodeTemplate(tableMetaData, columnInfoList); StringWriter writer = generator.generatorCodeTemplate(tableMetaData, columnInfoList);
String processedPath = VmsUtil.handleVmFilename(path, tableMetaData.getTableName()); String processedPath = VmsUtil.handleVmFilename(path, tableMetaData.getTableName());

View File

@ -1,7 +1,7 @@
// axios 配置 // axios 配置
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: 'http://localhost:8800/api', baseURL: 'http://localhost:8800/api',
timeout: 16000, timeout: 10000,
headers: {'Content-Type': 'application/json;charset=utf-8'}, headers: {'Content-Type': 'application/json;charset=utf-8'},
}); });

View File

@ -18,12 +18,12 @@ const MainForm = {
<form class="card-body row" @submit.prevent="handleSubmit" novalidate> <form class="card-body row" @submit.prevent="handleSubmit" novalidate>
<!-- 基本信息输入区域 --> <!-- 基本信息输入区域 -->
<div class="col-md-4 mb-3 has-validation"> <div class="col-md-4 mb-3 has-validation">
<label class="form-label fw-medium" for="author">作者名称</label> <label class="form-label fw-medium" for="authorName">作者名称</label>
<input class="form-control border-secondary" :class="{ 'is-invalid': errors.author }" <input class="form-control border-secondary" :class="{ 'is-invalid': errors.authorName }"
id="author" placeholder="输入作者名称" v-model="form.author" type="text" id="authorName" placeholder="输入作者名称" v-model="form.authorName" type="text"
@input="validateField('author')"> @input="validateField('authorName')">
<div class="invalid-feedback"> <div class="invalid-feedback">
{{ errors.author || '请输入作者名称' }} {{ errors.authorName || '请输入作者名称' }}
</div> </div>
</div> </div>
<div class="col-md-4 mb-3 has-validation"> <div class="col-md-4 mb-3 has-validation">
@ -62,9 +62,13 @@ const MainForm = {
{{ errors.tablePrefixes || '请输入去除开头前缀' }} {{ errors.tablePrefixes || '请输入去除开头前缀' }}
</div> </div>
</div> </div>
<div class="col-md-4 mb-3">
<label class="form-label fw-medium" for="comment">注释内容</label>
<input class="form-control border-secondary" id="comment" placeholder="注释内容" v-model="form.comment"
type="text" />
</div>
<div class="col-md-12" v-show="form.tableNames.length > 0"> <div class="col-md-12" v-show="form.tableNames.length > 0">
<label class="form-label fw-medium" for="tableNames">已选择的要生成表({{form.tableNames.length}})</label> <label class="form-label fw-medium" for="comment">已选择的要生成表({{form.tableNames.length}})</label>
<span class="badge rounded-pill text-bg-dark me-1" v-for="(item,index) in form.tableNames" :ket="index">{{item}}</span> <span class="badge rounded-pill text-bg-dark me-1" v-for="(item,index) in form.tableNames" :ket="index">{{item}}</span>
</div> </div>
@ -137,7 +141,7 @@ const MainForm = {
@click="onClearGeneratorData">清空生成记录</button> @click="onClearGeneratorData">清空生成记录</button>
</div> </div>
<div class="col-md-4 d-grid gap-2"> <div class="col-md-4 d-grid gap-2">
<button class="btn btn-primary text-white" type="button" @click="onDownloadZip">下载ZIP</button> <button class="btn btn-primary text-white" type="button">下载ZIP</button>
</div> </div>
</div> </div>
</form> </form>
@ -162,7 +166,7 @@ const MainForm = {
webList: ref([]), webList: ref([]),
// 错误信息对象 // 错误信息对象
errors: { errors: {
author: '', authorName: '',
requestMapping: '', requestMapping: '',
packageName: '', packageName: '',
simpleDateFormat: '', simpleDateFormat: '',
@ -213,7 +217,7 @@ const MainForm = {
let isValid = true; let isValid = true;
// 验证文本字段 // 验证文本字段
const textFields = ['author', 'requestMapping', 'packageName', 'simpleDateFormat', 'tablePrefixes']; const textFields = ['authorName', 'requestMapping', 'packageName', 'simpleDateFormat', 'tablePrefixes'];
textFields.forEach(field => { textFields.forEach(field => {
if (!this.validateField(field)) { if (!this.validateField(field)) {
isValid = false; isValid = false;
@ -268,54 +272,6 @@ const MainForm = {
this.webList = data.web.map(item => ({...item, checked: false})); this.webList = data.web.map(item => ({...item, checked: false}));
}, },
/**
* 下载Zip文件
* @returns {Promise<void>}
*/
async onDownloadZip() {
try {
const response = await axiosInstance({
url: "/vms/downloadByZip",
method: "POST",
data: this.form,
responseType: 'blob' // 重要指定响应类型为blob
});
// 从响应头中获取文件名
const contentDisposition = response.headers['content-disposition'];
let fileName = 'download.zip';
if (contentDisposition) {
const fileNameMatch = contentDisposition.match(/filename=(.+)/);
if (fileNameMatch && fileNameMatch[1]) {
fileName = fileNameMatch[1];
// 处理可能的编码文件名如UTF-8编码
if (fileName.startsWith("UTF-8''")) {
fileName = decodeURIComponent(fileName.replace("UTF-8''", ''));
}
}
}
// 创建Blob对象
const blob = new Blob([response.data]);
// 创建下载链接
const downloadUrl = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = downloadUrl;
link.download = fileName;
document.body.appendChild(link);
// 触发点击下载
link.click();
// 清理
window.URL.revokeObjectURL(downloadUrl);
document.body.removeChild(link);
} catch (error) {
console.error('下载失败:', error);
}
},
/** /**
* 全选指定列表 * 全选指定列表
* @param {Array} list - 要处理的列表 * @param {Array} list - 要处理的列表

View File

@ -116,7 +116,7 @@
// 提交的表单 // 提交的表单
form: ref({ form: ref({
// 作者名称 // 作者名称
author: "Bunny", authorName: "Bunny",
// requestMapping名称 // requestMapping名称
requestMapping: "/api", requestMapping: "/api",
// 表名称 // 表名称
@ -128,7 +128,7 @@
// 去除开头前缀 // 去除开头前缀
tablePrefixes: "t_,sys_,qrtz_,log_", tablePrefixes: "t_,sys_,qrtz_,log_",
// 生成代码路径 // 生成代码路径
path: [], path: []
}), }),
// 是否显示生成页面 // 是否显示生成页面
generatorPageFlag: ref(false), generatorPageFlag: ref(false),