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

@@ -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>