fix(代码生成): 读取表信息去掉缓存,避免数据库同步修改

This commit is contained in:
冷冷 2024-08-27 13:20:07 +08:00
parent 7dd19322fb
commit 1d1b4706c3
2 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,8 @@ package com.pig4cloud.pig.codegen.config;
import cn.smallbun.screw.core.constant.DefaultConstants;
import lombok.Data;
import org.anyline.util.ConfigTable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@ -14,7 +16,7 @@ import org.springframework.context.annotation.Configuration;
@Data
@Configuration(proxyBeanMethods = false)
@ConfigurationProperties(prefix = PigCodeGenDefaultProperties.PREFIX)
public class PigCodeGenDefaultProperties {
public class PigCodeGenDefaultProperties implements InitializingBean {
public static final String PREFIX = "codegen";
@ -73,4 +75,9 @@ public class PigCodeGenDefaultProperties {
*/
private String generatorType = "0";
@Override
public void afterPropertiesSet() throws Exception {
ConfigTable.KEEP_ADAPTER = 0;
}
}

View File

@ -41,6 +41,7 @@ import lombok.RequiredArgsConstructor;
import org.anyline.metadata.Column;
import org.anyline.metadata.Database;
import org.anyline.metadata.Table;
import org.anyline.proxy.CacheProxy;
import org.anyline.proxy.ServiceProxy;
import org.anyline.service.AnylineService;
import org.jetbrains.annotations.NotNull;
@ -96,6 +97,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
public List<String> queryTableColumn(String dsName, String tableName) {
// 手动切换数据源
DynamicDataSourceContextHolder.push(dsName);
CacheProxy.clear();
return ServiceProxy.metadata().columns(tableName).values().stream().map(Column::getName).toList();
}
@ -109,6 +111,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
public IPage queryTablePage(Page<Table> page, GenTable table) {
// 手动切换数据源
DynamicDataSourceContextHolder.push(table.getDsName());
CacheProxy.clear();
List<Table> tableList = ServiceProxy.metadata().tables().values().stream().filter(t -> {
if (StrUtil.isBlank(table.getTableName())) {
return true;
@ -132,6 +135,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
public List<String> queryTableList(String dsName) {
// 手动切换数据源
DynamicDataSourceContextHolder.push(dsName);
CacheProxy.clear();
return ServiceProxy.metadata().tables().values().stream().map(Table::getName).toList();
}
@ -170,6 +174,7 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
// 查询表是否存在
GenTable table = new GenTable();
// 从数据库获取表信息
CacheProxy.clear();
AnylineService service = ServiceProxy.service();
Table tableMetadata = service.metadata().table(tableName);
Database database = service.metadata().database();