修改代码生成模板
This commit is contained in:
@@ -15,6 +15,8 @@ import com.orion.lang.utils.ansi.style.color.AnsiForeground;
|
||||
import com.orion.lang.utils.ext.yml.YmlExt;
|
||||
import com.orion.ops.framework.mybatis.core.domain.BaseDO;
|
||||
import com.orion.ops.framework.mybatis.core.mapper.IMapper;
|
||||
import com.orion.ops.launch.generator.core.GenTable;
|
||||
import com.orion.ops.launch.generator.core.VelocityTemplateEngine;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.io.File;
|
||||
@@ -44,10 +46,12 @@ public class CodeGenerator {
|
||||
// new GenTable("system_user", "用户", "user")
|
||||
// .vue("user", "user")
|
||||
// .enums(UserStatusEnum.class),
|
||||
new GenTable("host", "主机", "host")
|
||||
.vue("asset", "host")
|
||||
new GenTable("host_key", "主机秘钥", "host")
|
||||
.vue("asset", "host-key")
|
||||
.ignoreTest(),
|
||||
new GenTable("host_identity", "主机身份", "host")
|
||||
.vue("asset", "host-identity")
|
||||
.ignoreTest(),
|
||||
new GenTable("host_config", "主机配置", "host").ignoreTest(),
|
||||
};
|
||||
// jdbc 配置 - 使用配置文件
|
||||
File yamlFile = new File("orion-ops-launch/src/main/resources/application-dev.yaml");
|
||||
@@ -386,6 +390,7 @@ public class CodeGenerator {
|
||||
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码复制后请先 clean 模块父工程\n")
|
||||
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 后端代码复制后请先执行单元测试检测是否正常\n")
|
||||
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- vue 代码需要注意同一模块的 router 需要自行合并\n")
|
||||
.append(AnsiForeground.BRIGHT_BLUE.and(AnsiFont.BOLD), "- 菜单 sql 执行完成后 需要在菜单页面刷新缓存\n")
|
||||
.toString();
|
||||
System.out.print(line);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.orion.ops.launch.generator;
|
||||
package com.orion.ops.launch.generator.core;
|
||||
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import lombok.Data;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.orion.ops.launch.generator;
|
||||
package com.orion.ops.launch.generator.core;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.config.ConstVal;
|
||||
@@ -25,6 +25,7 @@ import com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine;
|
||||
import com.orion.lang.define.collect.MultiLinkedHashMap;
|
||||
import com.orion.lang.utils.Enums;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.lang.utils.VariableStyles;
|
||||
import com.orion.lang.utils.io.Files1;
|
||||
import com.orion.lang.utils.reflect.BeanMap;
|
||||
import com.orion.lang.utils.reflect.Fields;
|
||||
@@ -309,12 +310,18 @@ public class VelocityTemplateEngine extends AbstractTemplateEngine {
|
||||
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());
|
||||
// 模块名称实体
|
||||
beanMap.put("moduleEntity", VariableStyles.SPINE.toBigHump(table.getModule()));
|
||||
// 模块名称实体
|
||||
beanMap.put("moduleEntityFirstLower", Strings.firstLower(beanMap.get("moduleEntity")));
|
||||
// 模块名称常量
|
||||
beanMap.put("moduleConst", VariableStyles.SPINE.toSerpentine(table.getModule()).toUpperCase());
|
||||
// 功能名称实体
|
||||
beanMap.put("featureEntity", VariableStyles.SPINE.toBigHump(table.getFeature()));
|
||||
// 功能名称实体
|
||||
beanMap.put("featureEntityFirstLower", Strings.firstLower(beanMap.get("featureEntity")));
|
||||
// 功能名称常量
|
||||
beanMap.put("featureConst", VariableStyles.SPINE.toSerpentine(table.getFeature()).toUpperCase());
|
||||
// 枚举
|
||||
beanMap.put("enums", this.getEnumMap(table));
|
||||
objectMap.put("vue", beanMap);
|
||||
@@ -13,7 +13,7 @@ SELECT @TMP_PARENT_ID:=LAST_INSERT_ID();
|
||||
INSERT INTO system_menu
|
||||
(parent_id, name, type, sort, visible, status, cache, component)
|
||||
VALUES
|
||||
(@TMP_PARENT_ID, '$vue.comment', 2, 10, 1, 1, 1, '$vue.module$vue.featureFirstUpper');
|
||||
(@TMP_PARENT_ID, '$vue.comment', 2, 10, 1, 1, 1, '$vue.moduleEntityFirstLower$vue.featureEntity');
|
||||
|
||||
-- 设置临时子菜单id
|
||||
SELECT @TMP_SUB_ID:=LAST_INSERT_ID();
|
||||
|
||||
@@ -5,7 +5,7 @@ import { DataGrid, Pagination } from '@/types/global';
|
||||
/**
|
||||
* ${table.comment}创建请求
|
||||
*/
|
||||
export interface ${vue.featureFirstUpper}CreateRequest {
|
||||
export interface ${vue.featureEntity}CreateRequest {
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$!field.propertyName" != "id")
|
||||
#if("$field.propertyType" == "String" || "$field.propertyType" == "Date")
|
||||
@@ -24,14 +24,14 @@ export interface ${vue.featureFirstUpper}CreateRequest {
|
||||
/**
|
||||
* ${table.comment}更新请求
|
||||
*/
|
||||
export interface ${vue.featureFirstUpper}UpdateRequest extends ${vue.featureFirstUpper}CreateRequest {
|
||||
export interface ${vue.featureEntity}UpdateRequest extends ${vue.featureEntity}CreateRequest {
|
||||
id: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment}查询请求
|
||||
*/
|
||||
export interface ${vue.featureFirstUpper}QueryRequest extends Pagination {
|
||||
export interface ${vue.featureEntity}QueryRequest extends Pagination {
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$field.propertyType" == "String" || "$field.propertyType" == "Date")
|
||||
${field.propertyName}?: string;
|
||||
@@ -48,7 +48,7 @@ export interface ${vue.featureFirstUpper}QueryRequest extends Pagination {
|
||||
/**
|
||||
* ${table.comment}查询响应
|
||||
*/
|
||||
export interface ${vue.featureFirstUpper}QueryResponse {
|
||||
export interface ${vue.featureEntity}QueryResponse {
|
||||
#foreach($field in ${table.fields})
|
||||
#if("$field.propertyType" == "String")
|
||||
${field.propertyName}?: string;
|
||||
@@ -69,29 +69,29 @@ export interface ${vue.featureFirstUpper}QueryResponse {
|
||||
/**
|
||||
* $apiComment.create
|
||||
*/
|
||||
export function create${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}CreateRequest) {
|
||||
export function create${vue.featureEntity}(request: ${vue.featureEntity}CreateRequest) {
|
||||
return axios.post('/${package.ModuleName}/${typeHyphen}/create', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.updateById
|
||||
*/
|
||||
export function update${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}UpdateRequest) {
|
||||
export function update${vue.featureEntity}(request: ${vue.featureEntity}UpdateRequest) {
|
||||
return axios.put('/${package.ModuleName}/${typeHyphen}/update', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.getById
|
||||
*/
|
||||
export function get${vue.featureFirstUpper}(id: number) {
|
||||
return axios.get<${vue.featureFirstUpper}QueryResponse>('/${package.ModuleName}/${typeHyphen}/get', { params: { id } });
|
||||
export function get${vue.featureEntity}(id: number) {
|
||||
return axios.get<${vue.featureEntity}QueryResponse>('/${package.ModuleName}/${typeHyphen}/get', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.listByIdList
|
||||
*/
|
||||
export function get${vue.featureFirstUpper}List(idList: Array<number>) {
|
||||
return axios.get<${vue.featureFirstUpper}QueryResponse[]>('/${package.ModuleName}/${typeHyphen}/list', {
|
||||
export function get${vue.featureEntity}List(idList: Array<number>) {
|
||||
return axios.get<${vue.featureEntity}QueryResponse[]>('/${package.ModuleName}/${typeHyphen}/list', {
|
||||
params: { idList },
|
||||
paramsSerializer: params => {
|
||||
return qs.stringify(params, { arrayFormat: 'comma' });
|
||||
@@ -102,28 +102,28 @@ export function get${vue.featureFirstUpper}List(idList: Array<number>) {
|
||||
/**
|
||||
* $apiComment.listAll
|
||||
*/
|
||||
export function get${vue.featureFirstUpper}ListAll(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||
return axios.post<Array<${vue.featureFirstUpper}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/list-all', request);
|
||||
export function get${vue.featureEntity}ListAll(request: ${vue.featureEntity}QueryRequest) {
|
||||
return axios.post<Array<${vue.featureEntity}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/list-all', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.queryPage
|
||||
*/
|
||||
export function get${vue.featureFirstUpper}Page(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||
return axios.post<DataGrid<${vue.featureFirstUpper}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/query', request);
|
||||
export function get${vue.featureEntity}Page(request: ${vue.featureEntity}QueryRequest) {
|
||||
return axios.post<DataGrid<${vue.featureEntity}QueryResponse>>('/${package.ModuleName}/${typeHyphen}/query', request);
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.deleteById
|
||||
*/
|
||||
export function delete${vue.featureFirstUpper}(id: number) {
|
||||
export function delete${vue.featureEntity}(id: number) {
|
||||
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete', { params: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* $apiComment.batchDeleteByIdList
|
||||
*/
|
||||
export function batchDelete${vue.featureFirstUpper}(idList: Array<number>) {
|
||||
export function batchDelete${vue.featureEntity}(idList: Array<number>) {
|
||||
return axios.delete('/${package.ModuleName}/${typeHyphen}/delete-batch', {
|
||||
params: { idList },
|
||||
paramsSerializer: params => {
|
||||
@@ -135,6 +135,6 @@ export function batchDelete${vue.featureFirstUpper}(idList: Array<number>) {
|
||||
/**
|
||||
* $apiComment.export
|
||||
*/
|
||||
export function export${vue.featureFirstUpper}(request: ${vue.featureFirstUpper}QueryRequest) {
|
||||
export function export${vue.featureEntity}(request: ${vue.featureEntity}QueryRequest) {
|
||||
return axios.post('/${package.ModuleName}/${typeHyphen}/export', request);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { DEFAULT_LAYOUT } from '../base';
|
||||
import { AppRouteRecordRaw } from '../types';
|
||||
|
||||
const $vue.featureAllUpper: AppRouteRecordRaw = {
|
||||
name: '$vue.module',
|
||||
const $vue.moduleConst: AppRouteRecordRaw = {
|
||||
name: '$vue.moduleEntityFirstLower',
|
||||
path: '/$vue.module',
|
||||
component: DEFAULT_LAYOUT,
|
||||
children: [
|
||||
{
|
||||
name: '$vue.module$vue.featureFirstUpper',
|
||||
name: '$vue.moduleEntityFirstLower$vue.featureEntity',
|
||||
path: '/$vue.module/$vue.feature',
|
||||
component: () => import('@/views/$vue.module/$vue.feature/index.vue'),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default $vue.featureAllUpper;
|
||||
export default $vue.moduleConst;
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
import useLoading from '@/hooks/loading';
|
||||
import useVisible from '@/hooks/visible';
|
||||
import formRules from '../types/form.rules';
|
||||
import { create${vue.featureFirstUpper}, update${vue.featureFirstUpper} } from '@/api/${vue.module}/${vue.feature}';
|
||||
import { create${vue.featureEntity}, update${vue.featureEntity} } from '@/api/${vue.module}/${vue.feature}';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { } from '../types/enum.types';
|
||||
import { } from '../types/const';
|
||||
@@ -114,12 +114,12 @@
|
||||
}
|
||||
if (isAddHandle.value) {
|
||||
// 新增
|
||||
await create${vue.featureFirstUpper}(formModel as any);
|
||||
await create${vue.featureEntity}(formModel as any);
|
||||
Message.success('创建成功');
|
||||
emits('added');
|
||||
} else {
|
||||
// 修改
|
||||
await update${vue.featureFirstUpper}(formModel as any);
|
||||
await update${vue.featureEntity}(formModel as any);
|
||||
Message.success('修改成功');
|
||||
emits('updated');
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { batchDelete${vue.featureFirstUpper}, delete${vue.featureFirstUpper}, get${vue.featureFirstUpper}Page, ${vue.featureFirstUpper}QueryRequest, ${vue.featureFirstUpper}QueryResponse } from '@/api/${vue.module}/${vue.feature}';
|
||||
import { batchDelete${vue.featureEntity}, delete${vue.featureEntity}, get${vue.featureEntity}Page, ${vue.featureEntity}QueryRequest, ${vue.featureEntity}QueryResponse } from '@/api/${vue.module}/${vue.feature}';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import useLoading from '@/hooks/loading';
|
||||
import columns from '../types/table.columns';
|
||||
@@ -119,7 +119,7 @@
|
||||
import { } from '../types/const';
|
||||
import { toOptions } from '@/utils/enum';
|
||||
|
||||
const tableRenderData = ref<${vue.featureFirstUpper}QueryResponse[]>();
|
||||
const tableRenderData = ref<${vue.featureEntity}QueryResponse[]>();
|
||||
const { loading, setLoading } = useLoading();
|
||||
const emits = defineEmits(['openAdd', 'openUpdate']);
|
||||
|
||||
@@ -127,7 +127,7 @@
|
||||
const selectedKeys = ref<number[]>([]);
|
||||
const rowSelection = reactive(defaultRowSelection());
|
||||
|
||||
const formModel = reactive<${vue.featureFirstUpper}QueryRequest>({
|
||||
const formModel = reactive<${vue.featureEntity}QueryRequest>({
|
||||
#foreach($field in ${table.fields})
|
||||
${field.propertyName}: undefined,
|
||||
#end
|
||||
@@ -138,7 +138,7 @@
|
||||
try {
|
||||
setLoading(true);
|
||||
// 调用删除接口
|
||||
await batchDelete${vue.featureFirstUpper}(selectedKeys.value);
|
||||
await batchDelete${vue.featureEntity}(selectedKeys.value);
|
||||
Message.success(`成功删除${selectedKeys.value.length}条数据`);
|
||||
selectedKeys.value = [];
|
||||
// 重新加载数据
|
||||
@@ -153,7 +153,7 @@
|
||||
try {
|
||||
setLoading(true);
|
||||
// 调用删除接口
|
||||
await delete${vue.featureFirstUpper}(id);
|
||||
await delete${vue.featureEntity}(id);
|
||||
Message.success('删除成功');
|
||||
// 重新加载数据
|
||||
await fetchTableData();
|
||||
@@ -177,10 +177,10 @@
|
||||
});
|
||||
|
||||
// 加载数据
|
||||
const doFetchTableData = async (request: ${vue.featureFirstUpper}QueryRequest) => {
|
||||
const doFetchTableData = async (request: ${vue.featureEntity}QueryRequest) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { data } = await get${vue.featureFirstUpper}Page(request);
|
||||
const { data } = await get${vue.featureEntity}Page(request);
|
||||
tableRenderData.value = data.rows;
|
||||
pagination.total = data.total;
|
||||
pagination.current = request.page;
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: '${vue.module}${vue.featureFirstUpper}'
|
||||
name: '${vue.module}-${vue.feature}'
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import ${vue.featureFirstUpper}Table from './components/${vue.feature}-table.vue';
|
||||
import ${vue.featureFirstUpper}FormModal from './components/${vue.feature}-form-modal.vue';
|
||||
import ${vue.featureEntity}Table from './components/${vue.feature}-table.vue';
|
||||
import ${vue.featureEntity}FormModal from './components/${vue.feature}-form-modal.vue';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const table = ref();
|
||||
|
||||
Reference in New Issue
Block a user