Commit 098b6102 authored by 赵啸非's avatar 赵啸非

添加apipost生成接口文档逻辑

parent a0bf845e
...@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* 读取代码生成相关配置 * 读取代码生成相关配置
* *
...@@ -12,42 +13,60 @@ import org.springframework.stereotype.Component; ...@@ -12,42 +13,60 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@ConfigurationProperties(prefix = "gen") @ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "classpath:generator.yml" }) @PropertySource(value = {"classpath:generator.yml"})
public class GenConfig { public class GenConfig {
/** 作者 */ /**
* 作者
*/
public static String author; public static String author;
/** 生成包路径 */ /**
* 生成包路径
*/
public static String packageName; public static String packageName;
/** 生成moduleName */ /**
* 系统包路径
*/
public static String systemPackageName="com.mortals.xhx.base";
/**
* 生成moduleName
*/
public static String moduleName; public static String moduleName;
/** 自动去除表前缀,默认是false */ /**
* 系统module名称
*/
public static String systemModuleName="system";
/**
* 自动去除表前缀,默认是false
*/
public static boolean autoRemovePre; public static boolean autoRemovePre;
/** 表前缀(类名不会包含表前缀) */ /**
* 表前缀(类名不会包含表前缀)
*/
public static String tablePrefix; public static String tablePrefix;
public static String getAuthor() public static String systemTable="mortals_xhx_user,mortals_xhx_valid_code,mortals_xhx_uploadfile,mortals_xhx_task,mortals_xhx_table_index,mortals_xhx_role,mortals_xhx_role_auth,mortals_xhx_role_user,mortals_xhx_menu,mortals_xhx_oper_log,mortals_xhx_param,mortals_xhx_idgenerator,mortals_xhx_area";
{
public static String getAuthor() {
return author; return author;
} }
@Value("${author}") @Value("${author}")
public void setAuthor(String author) public void setAuthor(String author) {
{
GenConfig.author = author; GenConfig.author = author;
} }
public static String getPackageName() public static String getPackageName() {
{
return packageName; return packageName;
} }
@Value("${packageName}") @Value("${packageName}")
public void setPackageName(String packageName) public void setPackageName(String packageName) {
{
GenConfig.packageName = packageName; GenConfig.packageName = packageName;
} }
...@@ -55,30 +74,55 @@ public class GenConfig { ...@@ -55,30 +74,55 @@ public class GenConfig {
public static String getModuleName() { public static String getModuleName() {
return moduleName; return moduleName;
} }
@Value("${moduleName}") @Value("${moduleName}")
public void setModuleName(String moduleName) { public void setModuleName(String moduleName) {
GenConfig.moduleName = moduleName; GenConfig.moduleName = moduleName;
} }
public static boolean getAutoRemovePre() public static boolean getAutoRemovePre() {
{
return autoRemovePre; return autoRemovePre;
} }
@Value("${autoRemovePre}") @Value("${autoRemovePre}")
public void setAutoRemovePre(boolean autoRemovePre) public void setAutoRemovePre(boolean autoRemovePre) {
{
GenConfig.autoRemovePre = autoRemovePre; GenConfig.autoRemovePre = autoRemovePre;
} }
public static String getTablePrefix() public static String getTablePrefix() {
{
return tablePrefix; return tablePrefix;
} }
@Value("${tablePrefix}") @Value("${tablePrefix}")
public void setTablePrefix(String tablePrefix) public void setTablePrefix(String tablePrefix) {
{
GenConfig.tablePrefix = tablePrefix; GenConfig.tablePrefix = tablePrefix;
} }
public static String getSystemTable() {
return systemTable;
}
@Value("${systemTable}")
public static void setSystemTable(String systemTable) {
GenConfig.systemTable = systemTable;
}
public static String getSystemPackageName() {
return systemPackageName;
}
@Value("${systemPackageName}")
public static void setSystemPackageName(String systemPackageName) {
GenConfig.systemPackageName = systemPackageName;
}
public static String getSystemModuleName() {
return systemModuleName;
}
@Value("${systemModuleName}")
public static void setSystemModuleName(String systemModuleName) {
GenConfig.systemModuleName = systemModuleName;
}
} }
...@@ -114,6 +114,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge ...@@ -114,6 +114,7 @@ public class GentableServiceImpl extends AbstractCRUDServiceImpl<GentableDao, Ge
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error(e);
throw new AppException("导入失败:" + e.getMessage()); throw new AppException("导入失败:" + e.getMessage());
} }
} }
......
...@@ -352,6 +352,11 @@ public class UserEntity extends UserEntityExt implements IUser { ...@@ -352,6 +352,11 @@ public class UserEntity extends UserEntityExt implements IUser {
return ""; return "";
} }
@Override
public String getAreaCodes() {
return "";
}
/** /**
* 设置 站点id * 设置 站点id
* @param siteId * @param siteId
......
...@@ -197,7 +197,9 @@ public class GenConstants { ...@@ -197,7 +197,9 @@ public class GenConstants {
*/ */
public static final Integer NOREQUIRE = 0; public static final Integer NOREQUIRE = 0;
/**
* MySQL默认关键字
*/
public static final String[] MYSQL_KEYWORDS = {"add", "all", "alter", "analyze", "and", "as", "asc", "asensitive", "before", "between", "bigint", "binary", "blob", "both", "by", "call", "cascade", "case", "change", "char", "character", "check", "collate", "column", "condition", "connection", "constraint", "continue", "convert", "create", "cross", "current_date", "current_time", "current_timestamp", "current_user", "cursor", "database", "databases", "day_hour", "day_microsecond", "day_minute", "day_second", "dec", "decimal", "declare", "default", "delayed", "delete", "desc", "describe", "deterministic", "distinct", "distinctrow", "div", "double", "drop", "dual", "each", "else", "elseif", "enclosed", "escaped", "exists", "exit", "explain", "false", "fetch", "float", "float4", "float8", "for", "force", "foreign", "from", "fulltext", "goto", "grant", "group", "having", "high_priority", "hour_microsecond", "hour_minute", "hour_second", "if", "ignore", "in", "index", "infile", "inner", "inout", "insensitive", "insert", "int", "int1", "int2", "int3", "int4", "int8", "integer", "interval", "into", "is", "iterate", "join", "key", "keys", "kill", "label", "leading", "leave", "left", "like", "limit", "linear", "lines", "load", "localtime", "localtimestamp", "lock", "long", "longblob", "longtext", "loop", "low_priority", "match", "mediumblob", "mediumint", "mediumtext", "middleint", "minute_microsecond", "minute_second", "mod", "modifies", "natural", "not", "no_write_to_binlog", "null", "numeric", "on", "optimize", "option", "optionally", "or", "order", "out", "outer", "outfile", "precision", "primary", "procedure", "purge", "raid0", "range", "read", "reads", "real", "references", "regexp", "release", "rename", "repeat", "replace", "require", "restrict", "return", "revoke", "right", "rlike", "schema", "schemas", "second_microsecond", "select", "sensitive", "separator", "set", "show", "smallint", "spatial", "specific", "sql", "sqlexception", "sqlstate", "sqlwarning", "sql_big_result", "sql_calc_found_rows", "sql_small_result", "ssl", "starting", "straight_join", "table", "terminated", "then", "tinyblob", "tinyint", "tinytext", "to", "trailing", "trigger", "true", "undo", "union", "unique", "unlock", "unsigned", "update", "usage", "use", "using", "utc_date", "utc_time", "utc_timestamp", "values", "varbinary", "varchar", "varcharacter", "varying", "when", "where", "while", "with", "write", "x509", "xor", "year_month", "zerofill"}; public static final String[] MYSQL_KEYWORDS = {"add", "all", "alter", "analyze", "and", "as", "asc", "asensitive", "before", "between", "bigint", "binary", "blob", "both", "by", "call", "cascade", "case", "change", "char", "character", "check", "collate", "column", "condition", "connection", "constraint", "continue", "convert", "create", "cross", "current_date", "current_time", "current_timestamp", "current_user", "cursor", "database", "databases", "day_hour", "day_microsecond", "day_minute", "day_second", "dec", "decimal", "declare", "default", "delayed", "delete", "desc", "describe", "deterministic", "distinct", "distinctrow", "div", "double", "drop", "dual", "each", "else", "elseif", "enclosed", "escaped", "exists", "exit", "explain", "false", "fetch", "float", "float4", "float8", "for", "force", "foreign", "from", "fulltext", "goto", "grant", "group", "having", "high_priority", "hour_microsecond", "hour_minute", "hour_second", "if", "ignore", "in", "index", "infile", "inner", "inout", "insensitive", "insert", "int", "int1", "int2", "int3", "int4", "int8", "integer", "interval", "into", "is", "iterate", "join", "key", "keys", "kill", "label", "leading", "leave", "left", "like", "limit", "linear", "lines", "load", "localtime", "localtimestamp", "lock", "long", "longblob", "longtext", "loop", "low_priority", "match", "mediumblob", "mediumint", "mediumtext", "middleint", "minute_microsecond", "minute_second", "mod", "modifies", "natural", "not", "no_write_to_binlog", "null", "numeric", "on", "optimize", "option", "optionally", "or", "order", "out", "outer", "outfile", "precision", "primary", "procedure", "purge", "raid0", "range", "read", "reads", "real", "references", "regexp", "release", "rename", "repeat", "replace", "require", "restrict", "return", "revoke", "right", "rlike", "schema", "schemas", "second_microsecond", "select", "sensitive", "separator", "set", "show", "smallint", "spatial", "specific", "sql", "sqlexception", "sqlstate", "sqlwarning", "sql_big_result", "sql_calc_found_rows", "sql_small_result", "ssl", "starting", "straight_join", "table", "terminated", "then", "tinyblob", "tinyint", "tinytext", "to", "trailing", "trigger", "true", "undo", "union", "unique", "unlock", "unsigned", "update", "usage", "use", "using", "utc_date", "utc_time", "utc_timestamp", "values", "varbinary", "varchar", "varcharacter", "varying", "when", "where", "while", "with", "write", "x509", "xor", "year_month", "zerofill"};
public static final Set<String> KEYWORDS_SET = new HashSet<>(Arrays.asList(MYSQL_KEYWORDS)); public static final Set<String> KEYWORDS_SET = new HashSet<>(Arrays.asList(MYSQL_KEYWORDS));
......
...@@ -11,10 +11,7 @@ import com.mortals.xhx.common.key.GenConstants; ...@@ -11,10 +11,7 @@ import com.mortals.xhx.common.key.GenConstants;
import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.RegExUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -24,14 +21,24 @@ import java.util.stream.Collectors; ...@@ -24,14 +21,24 @@ import java.util.stream.Collectors;
* @date: 2021/9/28 15:35 * @date: 2021/9/28 15:35
*/ */
public class GenUtils { public class GenUtils {
/** /**
* 初始化表信息 * 初始化表信息
*/ */
public static void initTable(GentableEntity genTable, String operName) { public static void initTable(GentableEntity genTable, String operName) {
genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setClassName(convertClassName(genTable.getTableName()));
//packageName //packageName
genTable.setPackageName(GenConfig.getPackageName()); //判断表是否为系统表,如果是
genTable.setModuleName(GenConfig.getModuleName()); Set<String> systemTableSet = Arrays.asList(GenConfig.getSystemTable().split(",")).stream().collect(Collectors.toSet());
if(systemTableSet.contains(genTable.getTableName())){
genTable.setPackageName(GenConfig.getSystemPackageName());
genTable.setModuleName(GenConfig.getSystemModuleName());
}else{
genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(GenConfig.getModuleName());
}
genTable.setBusinessName(getBusinessName(genTable.getTableName())); genTable.setBusinessName(getBusinessName(genTable.getTableName()));
genTable.setFunctionName(replaceText(genTable.getTableComment())); genTable.setFunctionName(replaceText(genTable.getTableComment()));
genTable.setFunctionAuthor(GenConfig.getAuthor()); genTable.setFunctionAuthor(GenConfig.getAuthor());
......
# 代码生成 gen:
gen:
# 作者 # 作者
author: zxfei author: zxfei
# 默认生成包路径 # 默认生成包路径
packageName: com.mortals.xhx packageName: com.mortals.xhx
systemPackageName: com.mortals.xhx.base
# module名称 # module名称
moduleName: module moduleName: module
systemModuleName: system
# 自动去除表前缀,默认是false # 自动去除表前缀,默认是false
autoRemovePre: true autoRemovePre: true
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔) # 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix: sys_,mortals_xhx_,mortals_iot_,mortals_stp_,mortals_sys_ tablePrefix: sys_,mortals_xhx_,mortals_iot_,mortals_stp_,mortals_sys_,mortals_etl_,mortals_
\ No newline at end of file systemTable: mortals_xhx_user,mortals_xhx_valid_code,mortals_xhx_uploadfile,mortals_xhx_task,mortals_xhx_table_index,mortals_xhx_role,mortals_xhx_role_auth,mortals_xhx_role_user,mortals_xhx_menu,mortals_xhx_oper_log,mortals_xhx_param,mortals_xhx_idgenerator,mortals_xhx_area
\ No newline at end of file
...@@ -26,6 +26,7 @@ import java.util.Arrays; ...@@ -26,6 +26,7 @@ import java.util.Arrays;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*; import static com.mortals.framework.ap.SysConstains.*;
import com.mortals.xhx.common.code.*;
/** /**
* *
* ${functionName} * ${functionName}
...@@ -48,7 +49,8 @@ public class ${ClassName}Controller extends BaseCRUDJsonBodyMappingController<${ ...@@ -48,7 +49,8 @@ public class ${ClassName}Controller extends BaseCRUDJsonBodyMappingController<${
protected void init(Map<String, Object> model, Context context) { protected void init(Map<String, Object> model, Context context) {
<#list columns as column> <#list columns as column>
<#if column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5> <#if column.columnType?contains("tinyint") ||column.htmlType==3||column.htmlType==5>
this.addDict(model, "${column.javaField}", paramService.getParamBySecondOrganize("${ClassName}","${column.javaField}")); <#-- this.addDict(model, "${column.javaField}", paramService.getParamBySecondOrganize("${ClassName}","${column.javaField}"));-->
this.addDict(model, "${column.javaField}", ${column.javaField?cap_first}Enum.getEnumMap());
</#if> </#if>
</#list> </#list>
super.init(model, context); super.init(model, context);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment