refactor(codegen): 移除 vform 无用代码

(cherry picked from commit 1bf57b916a66d61c6cfe52fdba827bb3c748c296)
This commit is contained in:
PIGCLOUD committed 2026-09-22 21:51:23 +08:00
1 parent 840732c52d
commit a810bf8f0b
15 files changed
-654

No files matched your search

-26
View File
@@ -422,7 +422,6 @@ INSERT INTO `sys_i18n` VALUES (18, 'router.documentExtension', '文档扩展', '
INSERT INTO `sys_i18n` VALUES (19, 'router.fileManagement', '文件管理', 'File Management', 'admin', '2023-02-24 10:28:44', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (20, 'router.platformDevelopment', '开发平台', 'Platform Development', 'admin', '2023-02-24 10:29:28', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (21, 'router.dataSourceManagement', '数据源管理', 'Data Source Management', 'admin', '2023-02-24 10:30:33', 'admin', '2023-03-06 14:33:20', '0');
INSERT INTO `sys_i18n` VALUES (22, 'router.formDesign', '表单设计', 'Form Design', 'admin', '2023-02-24 10:31:33', 'admin', '2023-03-06 14:33:28', '0');
INSERT INTO `sys_i18n` VALUES (23, 'router.appManagement', 'APP管理', 'App Management', 'admin', '2023-02-24 10:33:22', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (24, 'router.customerManagement', '客户管理', 'Customer Management', 'admin', '2023-02-24 10:35:30', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (25, 'router.appRole', 'APP角色', 'App Role', 'admin', '2023-02-24 10:36:17', '', NULL, '0');
@@ -774,7 +773,6 @@ INSERT INTO `sys_menu` VALUES (7804,'删除','app_appContacts_del',NULL,NULL,780
INSERT INTO `sys_menu` VALUES (7805,'导入导出','app_appContacts_export',NULL,NULL,7800,NULL,'1',1,'0',NULL,'1','admin','2025-05-29 17:30:31',' ',NULL,'0',1);
INSERT INTO `sys_menu` VALUES (9000,'开发平台',NULL,'/gen',NULL,-1,'iconfont icon-DevOps','1',9,'0','0','0','','2019-08-12 09:35:16','admin','2025-01-26 22:38:09','0',1);
INSERT INTO `sys_menu` VALUES (9005,'数据源管理',NULL,'/gen/datasource/index',NULL,9000,'iconfont icon-shujuyuanguanli','1',0,'0',NULL,'0','','2019-08-12 09:42:11','admin','2025-01-26 22:26:51','0',1);
INSERT INTO `sys_menu` VALUES (9006,'表单设计',NULL,'/gen/design/index',NULL,9000,'iconfont icon-AIshiyanshi','0',2,'0','0','0','','2019-08-16 10:08:56','admin','2023-02-23 14:06:50','0',1);
INSERT INTO `sys_menu` VALUES (9007,'生成页面',NULL,'/gen/gener/index',NULL,9000,'iconfont icon-tongzhi4','0',1,'0','0','0','admin','2023-02-20 09:58:23','admin','2023-02-20 14:41:43','0',1);
INSERT INTO `sys_menu` VALUES (9050,'元数据管理',NULL,'/gen/metadata',NULL,9000,'iconfont icon-yuanshujuguanli','1',9,'0','0','0','','2018-07-27 01:13:21','admin','2023-02-23 19:55:10','0',1);
INSERT INTO `sys_menu` VALUES (9051,'模板管理',NULL,'/gen/template/index',NULL,9050,'iconfont icon-mti-mobanguanli','1',5,'0','0','0','admin','2023-02-21 11:22:54','admin','2023-02-23 19:56:03','0',1);
@@ -1193,7 +1191,6 @@ INSERT INTO `sys_role_menu` VALUES (1, 7804);
INSERT INTO `sys_role_menu` VALUES (1, 7805);
INSERT INTO `sys_role_menu` VALUES (1, 9000);
INSERT INTO `sys_role_menu` VALUES (1, 9005);
INSERT INTO `sys_role_menu` VALUES (1, 9006);
INSERT INTO `sys_role_menu` VALUES (1, 9007);
INSERT INTO `sys_role_menu` VALUES (1, 9050);
INSERT INTO `sys_role_menu` VALUES (1, 9051);
@@ -2613,29 +2610,6 @@ INSERT INTO `gen_field_type` (`id`, `column_type`, `attr_type`, `package_name`,
INSERT INTO `gen_field_type` (`id`, `column_type`, `attr_type`, `package_name`, `default_form_type`, `default_query_form_type`, `create_time`, `create_by`, `update_time`, `update_by`, `del_flag`) VALUES (49,'bytea','String',NULL,'textarea','text','2026-04-07 20:47:09',NULL,'2026-04-07 20:47:09',NULL,'0');
COMMIT;
-- ----------------------------
-- Table structure for gen_form_conf
-- ----------------------------
DROP TABLE IF EXISTS `gen_form_conf`;
CREATE TABLE `gen_form_conf` (
`id` bigint NOT NULL COMMENT 'ID',
`ds_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '数据库名称',
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '表名称',
`form_info` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '表单信息',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0',
`tenant_id` bigint DEFAULT NULL COMMENT '所属租户',
PRIMARY KEY (`id`) USING BTREE,
KEY `table_name` (`table_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表单配置';
-- ----------------------------
-- Records of gen_form_conf
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for gen_group
-- ----------------------------
-3
View File
@@ -418,7 +418,6 @@ INSERT INTO `sys_i18n` VALUES (18, 'router.documentExtension', '文档扩展', '
INSERT INTO `sys_i18n` VALUES (19, 'router.fileManagement', '文件管理', 'File Management', 'admin', '2023-02-24 10:28:44', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (20, 'router.platformDevelopment', '开发平台', 'Platform Development', 'admin', '2023-02-24 10:29:28', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (21, 'router.dataSourceManagement', '数据源管理', 'Data Source Management', 'admin', '2023-02-24 10:30:33', 'admin', '2023-03-06 14:33:20', '0');
INSERT INTO `sys_i18n` VALUES (22, 'router.formDesign', '表单设计', 'Form Design', 'admin', '2023-02-24 10:31:33', 'admin', '2023-03-06 14:33:28', '0');
INSERT INTO `sys_i18n` VALUES (23, 'router.appManagement', 'APP管理', 'App Management', 'admin', '2023-02-24 10:33:22', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (24, 'router.customerManagement', '客户管理', 'Customer Management', 'admin', '2023-02-24 10:35:30', '', NULL, '0');
INSERT INTO `sys_i18n` VALUES (25, 'router.appRole', 'APP角色', 'App Role', 'admin', '2023-02-24 10:36:17', '', NULL, '0');
@@ -757,7 +756,6 @@ INSERT INTO `sys_menu` VALUES (7804,'删除','app_appContacts_del',NULL,NULL,780
INSERT INTO `sys_menu` VALUES (7805,'导入导出','app_appContacts_export',NULL,NULL,7800,NULL,'1',1,'0',NULL,'1','admin','2025-05-29 17:30:31',' ',NULL,'0',1);
INSERT INTO `sys_menu` VALUES (9000,'开发平台',NULL,'/gen',NULL,-1,'iconfont icon-DevOps','1',9,'0','0','0','','2019-08-12 09:35:16','admin','2025-01-26 22:38:09','0',1);
INSERT INTO `sys_menu` VALUES (9005,'数据源管理',NULL,'/gen/datasource/index',NULL,9000,'iconfont icon-shujuyuanguanli','1',0,'0',NULL,'0','','2019-08-12 09:42:11','admin','2025-01-26 22:26:51','0',1);
INSERT INTO `sys_menu` VALUES (9006,'表单设计',NULL,'/gen/design/index',NULL,9000,'iconfont icon-AIshiyanshi','0',2,'0','0','0','','2019-08-16 10:08:56','admin','2023-02-23 14:06:50','0',1);
INSERT INTO `sys_menu` VALUES (9007,'生成页面',NULL,'/gen/gener/index',NULL,9000,'iconfont icon-tongzhi4','0',1,'0','0','0','admin','2023-02-20 09:58:23','admin','2023-02-20 14:41:43','0',1);
INSERT INTO `sys_menu` VALUES (9050,'元数据管理',NULL,'/gen/metadata',NULL,9000,'iconfont icon-yuanshujuguanli','1',9,'0','0','0','','2018-07-27 01:13:21','admin','2023-02-23 19:55:10','0',1);
INSERT INTO `sys_menu` VALUES (9051,'模板管理',NULL,'/gen/template/index',NULL,9050,'iconfont icon-mti-mobanguanli','1',5,'0','0','0','admin','2023-02-21 11:22:54','admin','2023-02-23 19:56:03','0',1);
@@ -1178,7 +1176,6 @@ INSERT INTO `sys_role_menu` VALUES (1, 7804);
INSERT INTO `sys_role_menu` VALUES (1, 7805);
INSERT INTO `sys_role_menu` VALUES (1, 9000);
INSERT INTO `sys_role_menu` VALUES (1, 9005);
INSERT INTO `sys_role_menu` VALUES (1, 9006);
INSERT INTO `sys_role_menu` VALUES (1, 9007);
INSERT INTO `sys_role_menu` VALUES (1, 9050);
INSERT INTO `sys_role_menu` VALUES (1, 9051);
-23
View File
@@ -107,29 +107,6 @@ INSERT INTO `gen_field_type` (`id`, `column_type`, `attr_type`, `package_name`,
INSERT INTO `gen_field_type` (`id`, `column_type`, `attr_type`, `package_name`, `default_form_type`, `default_query_form_type`, `create_time`, `create_by`, `update_time`, `update_by`, `del_flag`) VALUES (49,'bytea','String',NULL,'textarea','text','2026-04-07 20:47:09',NULL,'2026-04-07 20:47:09',NULL,'0');
COMMIT;
-- ----------------------------
-- Table structure for gen_form_conf
-- ----------------------------
DROP TABLE IF EXISTS `gen_form_conf`;
CREATE TABLE `gen_form_conf` (
`id` bigint NOT NULL COMMENT 'ID',
`ds_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '数据库名称',
`table_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '表名称',
`form_info` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '表单信息',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '0',
`tenant_id` bigint DEFAULT NULL COMMENT '所属租户',
PRIMARY KEY (`id`) USING BTREE,
KEY `table_name` (`table_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表单配置';
-- ----------------------------
-- Records of gen_form_conf
-- ----------------------------
BEGIN;
COMMIT;
-- ----------------------------
-- Table structure for gen_group
-- ----------------------------
@@ -1,104 +0,0 @@
/*
* Copyright (c) 2018-2026, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.codegen.service.GenFormConfService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
* 表单管理
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/form")
@Tag(description = "form", name = "表单管理")
public class GenFormConfController {
private final GenFormConfService genRecordService;
/**
* 分页查询
* @param page 分页对象
* @param formConf 生成记录
* @return
*/
@Operation(description = "分页查询", summary = "分页查询")
@GetMapping("/page")
public R getGenFormConfPage(Page page, GenFormConf formConf) {
return R.ok(genRecordService.page(page, Wrappers.query(formConf)));
}
/**
* 通过id查询生成记录
* @param id id
* @return R
*/
@Operation(description = "通过id查询", summary = "通过id查询")
@GetMapping("/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(genRecordService.getById(id));
}
/**
* 新增生成记录
* @param formConf 生成记录
* @return R
*/
@Operation(description = "新增生成记录", summary = "新增生成记录")
@PostMapping
public R save(@RequestBody GenFormConf formConf) {
genRecordService.save(formConf);
return R.ok(formConf);
}
/**
* 修改生成记录
* @param formConf 生成记录
* @return R
*/
@Operation(description = "修改生成记录", summary = "修改生成记录")
@SysLog("修改生成记录")
@PutMapping
public R updateById(@RequestBody GenFormConf formConf) {
return R.ok(genRecordService.updateById(formConf));
}
/**
* 通过id删除生成记录
* @param id id
* @return R
*/
@Operation(description = "通过id删除生成记录", summary = "通过id删除生成记录")
@SysLog("通过id删除生成记录")
@DeleteMapping("/{id}")
public R removeById(@PathVariable Long id) {
return R.ok(genRecordService.removeById(id));
}
}
@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;
@@ -117,34 +116,4 @@ public class GeneratorController {
return generatorService.preview(tableId);
}
/**
* 获取表单设计器初始化数据
* @param dsName 数据源名称
* @param tableName 表名称
* @return json string
*/
@SneakyThrows
@GetMapping("/vform")
public String vform(String dsName, String tableName) {
return generatorService.vform(dsName, tableName);
}
/**
* 获取表单设计器初始化数据
* @param formId 表单ID
* @return json string
*/
@SneakyThrows
@GetMapping("/vform/sfc")
public void vformSfc(Long formId, HttpServletResponse response) {
String result = generatorService.vformSfc(formId);
byte[] data = result.getBytes(StandardCharsets.UTF_8);
response.reset();
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=form.vue");
response.setContentLength(data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.write(response.getOutputStream(), false, data);
}
}
@@ -1,94 +0,0 @@
/*
* Copyright (c) 2018-2026, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.pig4cloud.pigx.common.core.util.TenantTable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 生成记录
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@Data
@TenantTable
@TableName("gen_form_conf")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "生成记录")
public class GenFormConf extends Model<GenFormConf> {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "ID")
private Long id;
/**
* 数据源名称
*/
@Schema(description = "数据源名称")
private String dsName;
/**
* 表名称
*/
@Schema(description = "表名称")
private String tableName;
/**
* 表单信息
*/
@Schema(description = "表单信息")
private String formInfo;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 0-正常,1-删除
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
private String delFlag;
/**
* 所属租户
*/
@Schema(description = "所属租户", hidden = true)
private Long tenantId;
}
@@ -1,33 +0,0 @@
/*
* Copyright (c) 2018-2026, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 生成记录
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@Mapper
public interface GenFormConfMapper extends PigxBaseMapper<GenFormConf> {
}
@@ -1,42 +0,0 @@
/*
* Copyright (c) 2018-2026, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import java.util.List;
import java.util.Map;
/**
* 表单管理
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
public interface GenFormConfService extends IService<GenFormConf> {
/**
* 解析 form json
* @param formInfo json
* @return 字段
*/
Map<String, List<JSONObject>> parse(String formInfo);
}
@@ -50,23 +50,6 @@ public interface GeneratorService {
*/
void generatorCode(Long tableId);
/**
* 获取表单设计器需要的 JSON
*
* @param dsName 数据源名称
* @param tableName 表名称
* @return json string
*/
String vform(String dsName, String tableName);
/**
* 获取表单设计器需要的 JSON
*
* @param formId 数据源名称
* @return json string
*/
String vformSfc(Long formId);
/**
* 同步路由和菜单
*
@@ -1,105 +0,0 @@
/*
* Copyright (c) 2018-2026, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service.impl;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper;
import com.pig4cloud.pigx.codegen.service.GenFormConfService;
import com.pig4cloud.pigx.codegen.util.VFormConfigConsts;
import com.pig4cloud.pigx.codegen.util.VFormTypeEnum;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* 表单管理
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@Service
public class GenFormConfServiceImpl extends ServiceImpl<GenFormConfMapper, GenFormConf> implements GenFormConfService {
/**
* 表单解析方法
* @param formInfo json
* @return 字段列表
*/
@Override
public Map<String, List<JSONObject>> parse(String formInfo) {
JSONObject jsonObject = JSONUtil.parseObj(formInfo);
Map<String, List<JSONObject>> resultMap = new LinkedHashMap<>();
parseForm(jsonObject, resultMap);
return resultMap;
}
/**
* 解析 form config
* @param json 表单配置
* @param resultMap 返回结果
*/
private void parseForm(JSONObject json, Map<String, List<JSONObject>> resultMap) {
JSONArray widgetList = json.getJSONArray(VFormConfigConsts.widgetList);
String groupKey = json.getStr(VFormConfigConsts.groupKey, RandomUtil.randomString(5));
widgetList.stream().map(o -> (JSONObject) o).forEach(jsonObject -> {
String type = jsonObject.getStr(VFormConfigConsts.type);
if (VFormTypeEnum.GRID.getType().equals(type)) {
parseGrid(jsonObject, resultMap);
}
else if (VFormTypeEnum.GRID_COL.getType().equals(type)) {
parseForm(jsonObject, resultMap);
}
else {
int span = Optional.ofNullable(json.getJSONObject(VFormConfigConsts.options))
.map(options -> options.getInt(VFormConfigConsts.span, 24))
.orElse(24);
jsonObject.set(VFormConfigConsts.span, span);
List<JSONObject> jsonObjects = resultMap.computeIfAbsent(groupKey, k -> new ArrayList<>());
jsonObjects.add(jsonObject);
}
});
}
/**
* 解析 grid 容器
* @param jsonObject 入参
* @param resultMap 结果
*/
private void parseGrid(JSONObject jsonObject, Map<String, List<JSONObject>> resultMap) {
JSONArray cols = jsonObject.getJSONArray(VFormConfigConsts.cols);
String key = jsonObject.getStr(VFormConfigConsts.key);
cols.stream().map(o -> (JSONObject) o).forEach(col -> {
String colType = col.getStr(VFormConfigConsts.type);
if (VFormTypeEnum.GRID_COL.getType().equals(colType)) {
col.set(VFormConfigConsts.groupKey, key);
parseForm(col, resultMap);
}
if (VFormTypeEnum.GRID.getType().equals(colType)) {
parseGrid(col, resultMap);
}
});
}
}
@@ -25,20 +25,16 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.NamingCase;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.admin.api.entity.SysMenu;
import com.pig4cloud.pigx.admin.api.entity.SysRouteConf;
import com.pig4cloud.pigx.admin.api.feign.RemoteMenuService;
import com.pig4cloud.pigx.admin.api.feign.RemoteRouteConfService;
import com.pig4cloud.pigx.codegen.config.PigxCodeGenDefaultProperties;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.codegen.entity.GenTable;
import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity;
import com.pig4cloud.pigx.codegen.entity.GenTemplateEntity;
import com.pig4cloud.pigx.codegen.service.*;
import com.pig4cloud.pigx.codegen.util.DataModelConstants;
import com.pig4cloud.pigx.codegen.util.GeneratorStyleEnum;
import com.pig4cloud.pigx.codegen.util.VelocityKit;
import com.pig4cloud.pigx.codegen.util.vo.GroupVO;
import com.pig4cloud.pigx.common.core.constant.enums.MenuTypeEnum;
@@ -74,8 +70,6 @@ public class GeneratorServiceImpl implements GeneratorService {
private final GenTableColumnService columnService;
private final GenFormConfService formConfService;
private final GenFieldTypeService fieldTypeService;
private final GenTableService tableService;
@@ -208,67 +202,6 @@ public class GeneratorServiceImpl implements GeneratorService {
}
}
/**
* 获取表单设计器需要的 JSON 方法
*
* @param dsName 数据源名称
* @param tableName 表名称
* @return JSON 字符串
*/
@SneakyThrows
@Override
public String vform(String dsName, String tableName) {
// 查询表的元数据
GenTable genTable = tableService.queryOrBuildTable(dsName, tableName);
// 获取数据模型
Map<String, Object> dataModel = getDataModel(genTable.getId());
// 获取模板信息,Lambda 表达式简化代码
GenTemplateEntity genTemplateEntity = genTemplateService
.getOneOpt(Wrappers.<GenTemplateEntity>lambdaQuery()
.likeRight(GenTemplateEntity::getTemplateName, GeneratorStyleEnum.VFORM_JSON.getDesc())
.orderByDesc(GenTemplateEntity::getCreateTime), false)
.orElseThrow(() -> new CheckedException("模板不存在"));
// 渲染模板并返回结果
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
}
/**
* 获取sfc vue
*
* @param id 表单配置 ID
* @return JSON 字符串
*/
@SneakyThrows
@Override
public String vformSfc(Long id) {
// 获取表单配置信息
GenFormConf formConf = formConfService.getById(id);
// 查询表的元数据
GenTable genTable = tableService.queryOrBuildTable(formConf.getDsName(), formConf.getTableName());
// 获取数据模型
Map<String, Object> dataModel = getDataModel(genTable.getId());
// 解析组件列表
Map<String, List<JSONObject>> resultMap = formConfService.parse(formConf.getFormInfo());
// 遍历 widgetList
dataModel.put("resultMap", resultMap);
// 获取模板信息 查询模板中最新的 vform.json 文件
GenTemplateEntity genTemplateEntity = genTemplateService
.getOneOpt(Wrappers.<GenTemplateEntity>lambdaQuery()
.likeRight(GenTemplateEntity::getTemplateName, GeneratorStyleEnum.VFORM_VUE.getDesc())
.orderByDesc(GenTemplateEntity::getCreateTime), false)
.orElseThrow(() -> new CheckedException("模板不存在"));
// 渲染模板并返回结果
return VelocityKit.renderStr(genTemplateEntity.getTemplateCode(), dataModel);
}
/**
* 同步路由和菜单
*
@@ -1,29 +0,0 @@
package com.pig4cloud.pigx.codegen.util;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* 代码生成主题
*
* @author 冷冷
*/
@Getter
@RequiredArgsConstructor
public enum GeneratorStyleEnum {
VFORM_JSON(1L, "vform.json"),
VFORM_VUE(2L, "vform.vue");
/**
* 对应模板ID
*/
private final Long templateId;
/**
* 描述
*/
private final String desc;
}
@@ -1,25 +0,0 @@
package com.pig4cloud.pigx.codegen.util;
/**
* vform 的通用变量
*
* @author lengleng
* @date 2023/6/5
*/
public interface VFormConfigConsts {
String widgetList = "widgetList";
String groupKey = "groupKey";
String type = "type";
String options = "options";
String span = "span";
String cols = "cols";
String key = "key";
}
@@ -1,22 +0,0 @@
package com.pig4cloud.pigx.codegen.util;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* vfrom 字段类型
*
* @author lengleng
* @date 2023/6/5
*/
@Getter
@RequiredArgsConstructor
public enum VFormTypeEnum {
GRID("grid"),
GRID_COL("grid-col");
private final String type;
}
@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018-2025, lengleng All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
~ modification, are permitted provided that the following conditions are met:
~
~ Redistributions of source code must retain the above copyright notice,
~ this list of conditions and the following disclaimer.
~ Redistributions in binary form must reproduce the above copyright
~ notice, this list of conditions and the following disclaimer in the
~ documentation and/or other materials provided with the distribution.
~ Neither the name of the pig4cloud.com developer nor the names of its
~ contributors may be used to endorse or promote products derived from
~ this software without specific prior written permission.
~ Author: lengleng (wangiegie@gmail.com)
-->
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.codegen.mapper.GenFormConfMapper">
<resultMap id="genRecordMap" type="com.pig4cloud.pigx.codegen.entity.GenFormConf">
<id property="id" column="id"/>
<result property="tableName" column="table_name"/>
<result property="formInfo" column="form_info"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>