♻️ Refactoring code. #5106 优化代码模块,重构代码实体中boolean 类型
This commit is contained in:
1 parent
8f76c03896
commit
83c1f41327
10 files changed
+137
-101
No files matched your search
+1
-1
@@ -21,6 +21,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.pig4cloud.pigx.codegen.service.GeneratorService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -29,7 +30,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ public class GenTable extends Model<GenTable> {
|
||||
* 生成方式 0:zip压缩包 1:自定义目录
|
||||
*/
|
||||
@Schema(description = "生成方式 0:zip压缩包 1:自定义目录")
|
||||
private Integer generatorType;
|
||||
private String generatorType;
|
||||
|
||||
/**
|
||||
* 后端生成路径
|
||||
|
||||
+7
-7
@@ -94,22 +94,22 @@ public class GenTableColumnEntity extends Model<GenDatasourceConf> {
|
||||
/**
|
||||
* 主键 0:否 1:是
|
||||
*/
|
||||
private boolean primaryPk;
|
||||
private String primaryPk;
|
||||
|
||||
/**
|
||||
* 基类字段 0:否 1:是
|
||||
*/
|
||||
private boolean baseField;
|
||||
private String baseField;
|
||||
|
||||
/**
|
||||
* 表单项 0:否 1:是
|
||||
*/
|
||||
private boolean formItem;
|
||||
private String formItem;
|
||||
|
||||
/**
|
||||
* 表单必填 0:否 1:是
|
||||
*/
|
||||
private boolean formRequired;
|
||||
private String formRequired;
|
||||
|
||||
/**
|
||||
* 表单类型
|
||||
@@ -124,17 +124,17 @@ public class GenTableColumnEntity extends Model<GenDatasourceConf> {
|
||||
/**
|
||||
* 列表项 0:否 1:是
|
||||
*/
|
||||
private boolean gridItem;
|
||||
private String gridItem;
|
||||
|
||||
/**
|
||||
* 列表排序 0:否 1:是
|
||||
*/
|
||||
private boolean gridSort;
|
||||
private String gridSort;
|
||||
|
||||
/**
|
||||
* 查询项 0:否 1:是
|
||||
*/
|
||||
private boolean queryItem;
|
||||
private String queryItem;
|
||||
|
||||
/**
|
||||
* 查询方式
|
||||
|
||||
+5
-4
@@ -157,7 +157,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
table.setTableComment(MapUtil.getStr(queryTable, "tableComment"));
|
||||
table.setDbType(MapUtil.getStr(queryTable, "dbType"));
|
||||
table.setFormLayout(FormLayoutEnum.TWO.getValue());
|
||||
table.setGeneratorType(GeneratorTypeEnum.ZIP_DOWNLOAD.ordinal());
|
||||
table.setGeneratorType(GeneratorTypeEnum.ZIP_DOWNLOAD.getValue());
|
||||
table.setClassName(NamingCase.toPascalCase(tableName));
|
||||
table.setModuleName(GenKit.getModuleName(table.getPackageName()));
|
||||
table.setFunctionName(GenKit.getFunctionName(tableName));
|
||||
@@ -177,10 +177,11 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
genTableColumnEntity.setFieldComment(MapUtil.getStr(columnMap, "comments"));
|
||||
genTableColumnEntity.setFieldType(MapUtil.getStr(columnMap, "dataType"));
|
||||
String columnKey = MapUtil.getStr(columnMap, "columnKey");
|
||||
genTableColumnEntity.setPrimaryPk(StringUtils.isNotBlank(columnKey) && "PRI".equalsIgnoreCase(columnKey));
|
||||
genTableColumnEntity.setPrimaryPk((StringUtils.isNotBlank(columnKey) && "PRI".equalsIgnoreCase(columnKey))
|
||||
? BoolFillEnum.TRUE.getValue() : BoolFillEnum.FALSE.getValue());
|
||||
genTableColumnEntity.setAutoFill(AutoFillEnum.DEFAULT.name());
|
||||
genTableColumnEntity.setFormItem(true);
|
||||
genTableColumnEntity.setGridItem(true);
|
||||
genTableColumnEntity.setFormItem(BoolFillEnum.TRUE.getValue());
|
||||
genTableColumnEntity.setGridItem(BoolFillEnum.TRUE.getValue());
|
||||
|
||||
// 审计字段处理
|
||||
if (EnumUtil.contains(CommonColumnFiledEnum.class, columnName)) {
|
||||
|
||||
+5
-4
@@ -22,6 +22,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
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.pig4cloud.pigx.codegen.entity.GenFormConf;
|
||||
@@ -298,21 +299,21 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
// 按字段类型分组,使用 Map 存储不同类型的字段列表
|
||||
Map<Boolean, List<GenTableColumnEntity>> typeMap = table.getFieldList()
|
||||
.stream()
|
||||
.collect(Collectors.partitioningBy(GenTableColumnEntity::isPrimaryPk));
|
||||
.collect(Collectors.partitioningBy(columnEntity -> BooleanUtil.toBoolean(columnEntity.getPrimaryPk().toString())));
|
||||
|
||||
// 从分组后的 Map 中获取不同类型的字段列表
|
||||
List<GenTableColumnEntity> primaryList = typeMap.get(true);
|
||||
List<GenTableColumnEntity> formList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(GenTableColumnEntity::isFormItem)
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getFormItem().toString()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> gridList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(GenTableColumnEntity::isGridItem)
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getGridItem().toString()))
|
||||
.collect(Collectors.toList());
|
||||
List<GenTableColumnEntity> queryList = typeMap.get(false)
|
||||
.stream()
|
||||
.filter(GenTableColumnEntity::isQueryItem)
|
||||
.filter(columnEntity -> BooleanUtil.toBoolean(columnEntity.getQueryItem().toString()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(primaryList)) {
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.pig4cloud.pigx.codegen.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* boolean 类型枚举
|
||||
*
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum BoolFillEnum {
|
||||
|
||||
/**
|
||||
* true
|
||||
*/
|
||||
TRUE("1"),
|
||||
/**
|
||||
* false
|
||||
*/
|
||||
FALSE("0");
|
||||
|
||||
private final String value;
|
||||
|
||||
}
|
||||
+10
-10
@@ -16,38 +16,38 @@ public enum CommonColumnFiledEnum {
|
||||
/**
|
||||
* create_by 字段
|
||||
*/
|
||||
create_by(false, false, AutoFillEnum.INSERT.name(), 100),
|
||||
create_by("0", "0", AutoFillEnum.INSERT.name(), 100),
|
||||
|
||||
/**
|
||||
* create_time 字段
|
||||
*/
|
||||
create_time(false, false, AutoFillEnum.INSERT.name(), 101),
|
||||
create_time("0", "0", AutoFillEnum.INSERT.name(), 101),
|
||||
/**
|
||||
* update_by 字段
|
||||
*/
|
||||
update_by(false, false, AutoFillEnum.INSERT_UPDATE.name(), 102),
|
||||
update_by("0", "0", AutoFillEnum.INSERT_UPDATE.name(), 102),
|
||||
/**
|
||||
* update_time 字段
|
||||
*/
|
||||
update_time(false, false, AutoFillEnum.INSERT_UPDATE.name(), 103),
|
||||
update_time("0", "0", AutoFillEnum.INSERT_UPDATE.name(), 103),
|
||||
/**
|
||||
* del_flag 字段
|
||||
*/
|
||||
del_flag(false, false, AutoFillEnum.DEFAULT.name(), 104),
|
||||
del_flag("0", "0", AutoFillEnum.DEFAULT.name(), 104),
|
||||
/**
|
||||
* tenant_id 字段
|
||||
*/
|
||||
tenant_id(false, false, AutoFillEnum.DEFAULT.name(), 105);
|
||||
tenant_id("0", "0", AutoFillEnum.DEFAULT.name(), 105);
|
||||
|
||||
/**
|
||||
* 表单是否默认显示
|
||||
* 表单是否默认显示 1/0
|
||||
*/
|
||||
private Boolean formItem;
|
||||
private String formItem;
|
||||
|
||||
/**
|
||||
* 表格是否默认显示
|
||||
* 表格是否默认显示 1/0
|
||||
*/
|
||||
private Boolean gridItem;
|
||||
private String gridItem;
|
||||
|
||||
/**
|
||||
* 自动填充策略
|
||||
|
||||
+11
-4
@@ -1,19 +1,26 @@
|
||||
package com.pig4cloud.pigx.codegen.util;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 代码生成方式 枚举
|
||||
*
|
||||
* @author 阿沐 babamu@126.com
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GeneratorTypeEnum {
|
||||
|
||||
/**
|
||||
* zip压缩包
|
||||
* zip压缩包 0
|
||||
*/
|
||||
ZIP_DOWNLOAD,
|
||||
ZIP_DOWNLOAD("0"),
|
||||
/**
|
||||
* 自定义目录
|
||||
* 自定义目录 1
|
||||
*/
|
||||
CUSTOM_DIRECTORY;
|
||||
CUSTOM_DIRECTORY("1");
|
||||
|
||||
private final String value;
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user