Skip to content

Commit

Permalink
refactor(generator): 优化代码生成列配置代码,取消后端部分默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Aug 30, 2024
1 parent bd7bf43 commit f5ee2b5
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,22 @@ public class FieldConfigDO implements Serializable {
public FieldConfigDO(@NonNull Column column) {
this.setTableName(column.getTableName());
this.setColumnName(column.getName());
this.setColumnType(StrUtil.splitToArray(column.getTypeName(), StringConstants.SPACE)[0].toLowerCase());
this.setColumnType(column.getTypeName());
this.setColumnSize(Convert.toStr(column.getSize()));
this.setComment(column.getComment());
this.setIsRequired(!column.isPk() && !column.isNullable());
this.setShowInList(true);
this.setShowInForm(this.getIsRequired());
this.setShowInQuery(this.getIsRequired());
this.setFormType(FormTypeEnum.INPUT);
this.setQueryType("String".equals(this.getFieldType()) ? QueryTypeEnum.LIKE : QueryTypeEnum.EQ);
}

public void setColumnName(String columnName) {
this.columnName = columnName;
this.fieldName = StrUtil.toCamelCase(this.columnName);
}

public void setColumnType(String columnType) {
String[] arr = StrUtil.splitToArray(columnType, StringConstants.SPACE);
this.columnType = arr.length > 1 ? arr[0].toLowerCase() : columnType.toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@

package top.continew.admin.generator.model.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import top.continew.admin.common.constant.RegexConstants;
import top.continew.starter.core.util.StrUtils;

import java.io.Serial;
import java.io.Serializable;
Expand Down Expand Up @@ -118,21 +113,7 @@ public class GenConfigDO implements Serializable {
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;

/**
* 类名前缀
*/
@Setter(AccessLevel.NONE)
@JsonIgnore
@TableField(exist = false)
private String classNamePrefix;

public GenConfigDO(String tableName) {
this.tableName = tableName;
}

public String getClassNamePrefix() {
String rawClassName = StrUtils.blankToDefault(this.tablePrefix, this.tableName, prefix -> StrUtil
.removePrefix(this.tableName, prefix));
return StrUtil.upperFirst(StrUtil.toCamelCase(rawClassName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package top.continew.admin.generator.model.entity;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.StrUtils;

import java.io.Serial;
import java.util.List;
import java.util.Set;

/**
* 内部生成配置信息
*
* @author zhangqcc
* @since 2024/8/30 19:35
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class InnerGenConfigDO extends GenConfigDO {

@Serial
private static final long serialVersionUID = 1L;

/**
* 字段配置信息
*/
private List<FieldConfigDO> fieldConfigs;

/**
* 生成时间
*/
private String datetime;

/**
* API 模块名称
*/
private String apiModuleName;

/**
* API 名称
*/
private String apiName;

/**
* 类名
*/
private String className;

/**
* 类名前缀
*/
private String classNamePrefix;

/**
* 子包名称
*/
private String subPackageName;

/**
* 字典编码列表
*/
private Set<String> dictCodes;

/**
* 是否包含必填字段
*/
private boolean hasRequiredField;

/**
* 是否包含字典字段
*/
private boolean hasDictField;

/**
* 是否包含 BigDecimal 字段
*/
private boolean hasBigDecimalField;

/**
* 是否包含 List 字段
*/
private boolean hasListField;

/**
* 是否包含 Time 包字段
*/
private boolean hasTimeField;

public InnerGenConfigDO() {
}

public InnerGenConfigDO(GenConfigDO genConfig) {
BeanUtil.copyProperties(genConfig, this);
this.setDatetime(DateUtil.date().toString("yyyy/MM/dd HH:mm"));
this.setApiName(StrUtil.lowerFirst(this.getClassNamePrefix()));
}

@Override
public void setPackageName(String packageName) {
super.setPackageName(packageName);
String realPackageName = this.getPackageName();
this.setApiModuleName(StrUtil.subSuf(realPackageName, StrUtil
.lastIndexOfIgnoreCase(realPackageName, StringConstants.DOT) + 1));
}

public String getClassNamePrefix() {
String tableName = super.getTableName();
String rawClassName = StrUtils.blankToDefault(super.getTablePrefix(), tableName, prefix -> StrUtil
.removePrefix(tableName, prefix));
return StrUtil.upperFirst(StrUtil.toCamelCase(rawClassName));
}
}
Loading

0 comments on commit f5ee2b5

Please sign in to comment.