调整代码生成模板.

This commit is contained in:
lijiahang
2023-08-16 17:03:34 +08:00
parent d19cc66baa
commit 5ca656409d
5 changed files with 27 additions and 50 deletions

View File

@@ -25,7 +25,6 @@ import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
import com.orion.lang.define.collect.MultiLinkedHashMap; import com.orion.lang.define.collect.MultiLinkedHashMap;
import com.orion.lang.utils.Enums; import com.orion.lang.utils.Enums;
import com.orion.lang.utils.Strings; import com.orion.lang.utils.Strings;
import com.orion.lang.utils.VariableStyles;
import com.orion.lang.utils.io.Files1; import com.orion.lang.utils.io.Files1;
import com.orion.lang.utils.reflect.BeanMap; import com.orion.lang.utils.reflect.BeanMap;
import com.orion.lang.utils.reflect.Fields; import com.orion.lang.utils.reflect.Fields;
@@ -278,36 +277,6 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
}); });
} }
/**
* 生成 sql 文件
*
* @param customFiles customFiles
* @param tableInfo tableInfo
* @param objectMap objectMap
*/
private void generatorSqlFile(@NotNull List<CustomFile> customFiles, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
String outPath = getConfigBuilder().getGlobalConfig().getOutputDir();
GenTable table = tables.get(tableInfo.getName());
BeanMap beanMap = BeanMap.create(table, "enums");
// 模块名称首字母大写
beanMap.put("moduleFirstUpper", Strings.firstUpper(table.getModule()));
// 功能名称首字母大写
beanMap.put("featureFirstUpper", Strings.firstUpper(table.getFeature()));
// 功能名称全大写
beanMap.put("featureAllUpper", table.getFeature().toUpperCase());
objectMap.put("vue", beanMap);
// 生成文件
customFiles.forEach(file -> {
// 文件路径
String filePath = outPath
+ "/" + Strings.format(file.getPackageName(), beanMap)
+ "/" + Strings.format(file.getFileName(), beanMap);
// 输出文件
this.outputFile(Files1.newFile(filePath), objectMap, file.getTemplatePath(), file.isFileOverride());
});
}
/** /**
* 是否为后端文件 * 是否为后端文件
* *
@@ -349,10 +318,8 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
List<Class<? extends Enum<?>>> enums = table.getEnums(); List<Class<? extends Enum<?>>> enums = table.getEnums();
Map<String, MultiLinkedHashMap<String, String, Object>> enumMap = new LinkedHashMap<>(); Map<String, MultiLinkedHashMap<String, String, Object>> enumMap = new LinkedHashMap<>();
for (Class<? extends Enum<?>> e : enums) { for (Class<? extends Enum<?>> e : enums) {
// 大驼峰文件名称转为蛇形大写
String enumTypeName = VariableStyles.BIG_HUMP.toSerpentine(e.getSimpleName()).toUpperCase();
MultiLinkedHashMap<String, String, Object> fieldValueMap = Enums.getFieldValueMap(e); MultiLinkedHashMap<String, String, Object> fieldValueMap = Enums.getFieldValueMap(e);
enumMap.put(enumTypeName, fieldValueMap); enumMap.put(e.getSimpleName(), fieldValueMap);
} }
return enumMap; return enumMap;
} }

View File

@@ -1,25 +1,28 @@
-- 执行完成后 需要在菜单页面刷新缓存 -- 执行完成后 需要在菜单页面刷新缓存
-- 设置临时子菜单id -- 父菜单
INSERT INTO system_menu
(parent_id, name, type, sort, visible, status, cache)
VALUES
(0, '${vue.comment}管理', 1, 10, 1, 1, 1);
-- 设置临时父菜单id
SELECT @TMP_PARENT_ID:=LAST_INSERT_ID(); SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
-- 父菜单
INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache)
VALUES (0, '${vue.comment}管理', 1, 10, 1, 1, 1);
-- 子菜单 -- 子菜单
INSERT INTO system_menu (parent_id, name, type, sort, visible, status, cache, component) INSERT INTO system_menu
VALUES (@TMP_PARENT_ID, '$vue.comment', 2, 10, 1, 1, 1, '$vue.module$vue.featureFirstUpper'); (parent_id, name, type, sort, visible, status, cache, component)
VALUES
(@TMP_PARENT_ID, '$vue.comment', 2, 10, 1, 1, 1, '$vue.module$vue.featureFirstUpper');
-- 设置临时子菜单id -- 设置临时子菜单id
SELECT @TMP_SUB_ID:=LAST_INSERT_ID(); SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
-- 功能 -- 功能
INSERT INTO system_menu (parent_id, name, permission, type, sort) INSERT INTO system_menu
VALUES (@TMP_SUB_ID, '创建$vue.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 10); (parent_id, name, permission, type, sort)
INSERT INTO system_menu (parent_id, name, permission, type, sort) VALUES
VALUES (@TMP_SUB_ID, '修改$vue.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 20); (@TMP_SUB_ID, '查询$vue.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 10),
INSERT INTO system_menu (parent_id, name, permission, type, sort) (@TMP_SUB_ID, '创建$vue.comment', '${package.ModuleName}:${typeHyphen}:create', 3, 20),
VALUES (@TMP_SUB_ID, '查询$vue.comment', '${package.ModuleName}:${typeHyphen}:query', 3, 30); (@TMP_SUB_ID, '修改$vue.comment', '${package.ModuleName}:${typeHyphen}:update', 3, 30),
INSERT INTO system_menu (parent_id, name, permission, type, sort) (@TMP_SUB_ID, '删除$vue.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40);
VALUES (@TMP_SUB_ID, '删除$vue.comment', '${package.ModuleName}:${typeHyphen}:delete', 3, 40);

View File

@@ -3,7 +3,7 @@
body-class="modal-form" body-class="modal-form"
title-align="start" title-align="start"
:title="title" :title="title"
:top="120" :top="80"
:align-center="false" :align-center="false"
:draggable="true" :draggable="true"
:mask-closable="false" :mask-closable="false"
@@ -55,6 +55,8 @@
import formRules from '../types/form.rules'; import formRules from '../types/form.rules';
import { create${vue.featureFirstUpper}, update${vue.featureFirstUpper} } from '@/api/${vue.module}/${vue.feature}'; import { create${vue.featureFirstUpper}, update${vue.featureFirstUpper} } from '@/api/${vue.module}/${vue.feature}';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
import { } from '../types/enum.types';
import { toOptions } from '@/utils/enum';
const { visible, setVisible } = useVisible(); const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();

View File

@@ -115,6 +115,8 @@
import useLoading from '@/hooks/loading'; import useLoading from '@/hooks/loading';
import columns from '../types/table.columns'; import columns from '../types/table.columns';
import { defaultPagination, defaultRowSelection } from '@/types/table'; import { defaultPagination, defaultRowSelection } from '@/types/table';
import { } from '../types/enum.types';
import { toOptions } from '@/utils/enum';
const tableRenderData = ref<${vue.featureFirstUpper}QueryResponse[]>(); const tableRenderData = ref<${vue.featureFirstUpper}QueryResponse[]>();
const { loading, setLoading } = useLoading(); const { loading, setLoading } = useLoading();

View File

@@ -18,6 +18,7 @@ const columns = [
ellipsis: true, ellipsis: true,
tooltip: true, tooltip: true,
#elseif(${field.propertyType} == 'Date') #elseif(${field.propertyType} == 'Date')
width: 180,
render: ({ record }) => { render: ({ record }) => {
return record.${field.propertyName} && dateFormat(new Date(record.${field.propertyName})); return record.${field.propertyName} && dateFormat(new Date(record.${field.propertyName}));
}, },
@@ -27,6 +28,7 @@ const columns = [
dataIndex: 'createTime', dataIndex: 'createTime',
slotName: 'createTime', slotName: 'createTime',
align: 'center', align: 'center',
width: 180,
render: ({ record }) => { render: ({ record }) => {
return dateFormat(new Date(record.createTime)); return dateFormat(new Date(record.createTime));
}, },
@@ -35,6 +37,7 @@ const columns = [
dataIndex: 'updateTime', dataIndex: 'updateTime',
slotName: 'updateTime', slotName: 'updateTime',
align: 'center', align: 'center',
width: 180,
render: ({ record }) => { render: ({ record }) => {
return dateFormat(new Date(record.updateTime)); return dateFormat(new Date(record.updateTime));
}, },