修改
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package com.jeesite.modules.app.Job;
|
||||
|
||||
import com.jeesite.modules.app.dao.TableTree;
|
||||
import com.jeesite.modules.app.utils.LoggerUtils;
|
||||
import com.jeesite.modules.app.utils.MysqlUtils;
|
||||
import com.jeesite.modules.biz.entity.BizDbConfig;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
import com.jeesite.modules.biz.service.BizDbConfigService;
|
||||
import com.jeesite.modules.biz.service.BizTableFieldService;
|
||||
import com.jeesite.modules.biz.service.BizTableInfoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Controller
|
||||
public class dataJob {
|
||||
|
||||
|
||||
@Resource
|
||||
private BizDbConfigService dbConfigService;
|
||||
@Resource
|
||||
private BizTableInfoService tableInfoService;
|
||||
@Resource
|
||||
private BizTableFieldService tableFieldService;
|
||||
|
||||
|
||||
@Resource(name = "hostMonitorExecutor")
|
||||
private ThreadPoolTaskExecutor hostMonitorExecutor;
|
||||
|
||||
|
||||
private static final LoggerUtils logger = LoggerUtils.getInstance();
|
||||
|
||||
/**
|
||||
* 数据字典更新
|
||||
*/
|
||||
@Scheduled(cron = "10 30 2 * * ?")
|
||||
public void getDataManager() {
|
||||
BizDbConfig dbConfig = new BizDbConfig();
|
||||
dbConfig.setIsEnabled("1");
|
||||
List<BizDbConfig> configList = dbConfigService.findList(dbConfig);
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>(configList.size());
|
||||
for (BizDbConfig config : configList) {
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
List<TableTree> tableTrees = MysqlUtils.getTableTrees(config);
|
||||
for (TableTree tableTree : tableTrees) {
|
||||
BizTableInfo tableInfo = tableTree.getTableInfo();
|
||||
tableInfoService.insert(tableInfo);
|
||||
List<BizTableField> tableFields = tableTree.getTableFields();
|
||||
for (BizTableField tableField : tableFields) {
|
||||
tableFieldService.insert(tableField);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}, hostMonitorExecutor); // 指定使用配置的线程池
|
||||
futures.add(future);
|
||||
}
|
||||
try {
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
|
||||
.get(30, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import com.jeesite.modules.app.utils.LoggerUtils;
|
||||
import com.jeesite.modules.app.utils.NetworkUtils;
|
||||
import com.jeesite.modules.biz.service.BizServerInfoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -24,7 +23,6 @@ import org.springframework.stereotype.Controller;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Controller
|
||||
public class hostJob {
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package com.jeesite.modules.app.dao;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据表字段信息表
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-11-17
|
||||
*/
|
||||
@Data
|
||||
public class DataTableField implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 字段唯一标识(主键)
|
||||
*/
|
||||
private String fieldId;
|
||||
|
||||
/**
|
||||
* 关联的数据表ID(外键,关联data_table_info.table_id)
|
||||
*/
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 数据来源
|
||||
*/
|
||||
private String dataSource;
|
||||
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
private String dataName;
|
||||
|
||||
/**
|
||||
* 字段序号(表示字段在表中的顺序)
|
||||
*/
|
||||
private Integer fieldOrder;
|
||||
|
||||
/**
|
||||
* 字段类型(如:int、varchar、datetime等)
|
||||
*/
|
||||
private String fieldType;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段长度(如varchar(50)中的50,数值型可表示精度)
|
||||
*/
|
||||
private Long fieldLength;
|
||||
|
||||
/**
|
||||
* 字段说明
|
||||
*/
|
||||
private String fieldRemark;
|
||||
|
||||
/**
|
||||
* 分区日期
|
||||
*/
|
||||
private String ds;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package com.jeesite.modules.app.dao;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据表基础信息表
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2025-11-17
|
||||
*/
|
||||
@Data
|
||||
public class DataTableInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 数据表唯一标识(主键)
|
||||
*/
|
||||
private String tableId;
|
||||
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
private String dataName;
|
||||
|
||||
/**
|
||||
* 数据表描述
|
||||
*/
|
||||
private String tableComment;
|
||||
|
||||
/**
|
||||
* 数据表大小(单位:MB)
|
||||
*/
|
||||
private BigDecimal tableSize;
|
||||
|
||||
/**
|
||||
* 数据来源(如:业务系统、文件导入等)
|
||||
*/
|
||||
private String dataSource;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 记录条数
|
||||
*/
|
||||
private Long dataRows;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remarks;
|
||||
|
||||
/**
|
||||
* 数据标识
|
||||
*/
|
||||
private String dbId;
|
||||
|
||||
/**
|
||||
* 分区日期
|
||||
*/
|
||||
private String ds;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.jeesite.modules.app.dao;
|
||||
|
||||
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -9,14 +11,14 @@ import java.util.List;
|
||||
@Data
|
||||
public class TableTree implements Serializable {
|
||||
|
||||
DataTableInfo tableInfo;
|
||||
BizTableInfo tableInfo;
|
||||
|
||||
List<DataTableField> tableFields;
|
||||
List<BizTableField> tableFields;
|
||||
|
||||
public TableTree() {
|
||||
}
|
||||
|
||||
public TableTree(DataTableInfo tableInfo, List<DataTableField> tableFields) {
|
||||
public TableTree(BizTableInfo tableInfo, List<BizTableField> tableFields) {
|
||||
this.tableInfo = tableInfo;
|
||||
this.tableFields = tableFields;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.jeesite.modules.app.utils;
|
||||
|
||||
|
||||
import com.jeesite.modules.app.dao.DataTableField;
|
||||
import com.jeesite.modules.app.dao.DataTableInfo;
|
||||
import com.jeesite.modules.app.dao.TableTree;
|
||||
import com.jeesite.modules.biz.entity.BizDbConfig;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -45,14 +45,14 @@ public class MysqlUtils {
|
||||
* @return 数据库名 -> 表信息列表(包含字段)的映射
|
||||
* @throws Exception 连接或查询异常
|
||||
*/
|
||||
public static Map<String, List<DataTableInfo>> getMysqlSchemaInfo(Connection conn) throws Exception {
|
||||
Map<String, List<DataTableInfo>> result = new HashMap<>();
|
||||
public static Map<String, List<BizTableInfo>> getMysqlSchemaInfo(Connection conn) throws Exception {
|
||||
Map<String, List<BizTableInfo>> result = new HashMap<>();
|
||||
// 1. 获取所有非系统数据库
|
||||
List<String> databases = getNonSystemDatabases(conn);
|
||||
logger.info("获取到非系统数据库数量:", databases.size());
|
||||
// 2. 遍历数据库,获取表和字段信息
|
||||
for (String dbName : databases) {
|
||||
List<DataTableInfo> tableInfos = getTablesByDatabase(conn, dbName);
|
||||
List<BizTableInfo> tableInfos = getTablesByDatabase(conn, dbName);
|
||||
result.put(dbName, tableInfos);
|
||||
}
|
||||
return result;
|
||||
@@ -81,8 +81,8 @@ public class MysqlUtils {
|
||||
/**
|
||||
* 获取指定数据库下的所有表信息(包含字段)
|
||||
*/
|
||||
private static List<DataTableInfo> getTablesByDatabase(Connection conn, String dbName) throws SQLException {
|
||||
List<DataTableInfo> tableInfos = new ArrayList<>();
|
||||
private static List<BizTableInfo> getTablesByDatabase(Connection conn, String dbName) throws SQLException {
|
||||
List<BizTableInfo> tableInfos = new ArrayList<>();
|
||||
String tableSql = "SELECT " +
|
||||
"TABLE_NAME, TABLE_COMMENT, CREATE_TIME, UPDATE_TIME, " +
|
||||
"DATA_LENGTH, INDEX_LENGTH, TABLE_ROWS " +
|
||||
@@ -91,8 +91,8 @@ public class MysqlUtils {
|
||||
tablePs.setString(1, dbName);
|
||||
try (ResultSet tableRs = tablePs.executeQuery()) {
|
||||
while (tableRs.next()) {
|
||||
DataTableInfo tableInfo = buildDataTableInfo(tableRs, dbName);
|
||||
List<DataTableField> fields = getFieldsByTable(conn, dbName, tableInfo.getDataName());
|
||||
BizTableInfo tableInfo = buildDataTableInfo(tableRs, dbName);
|
||||
List<BizTableField> fields = getFieldsByTable(conn, dbName, tableInfo.getDataName());
|
||||
fields.forEach(field -> field.setTableId(tableInfo.getTableId()));
|
||||
tableInfos.add(tableInfo);
|
||||
}
|
||||
@@ -104,8 +104,8 @@ public class MysqlUtils {
|
||||
/**
|
||||
* 构建DataTableInfo实体
|
||||
*/
|
||||
private static DataTableInfo buildDataTableInfo(ResultSet tableRs, String dbName) throws SQLException {
|
||||
DataTableInfo tableInfo = new DataTableInfo();
|
||||
private static BizTableInfo buildDataTableInfo(ResultSet tableRs, String dbName) throws SQLException {
|
||||
BizTableInfo tableInfo = new BizTableInfo();
|
||||
tableInfo.setTableId(vId.getUid());
|
||||
tableInfo.setDataName(tableRs.getString("TABLE_NAME"));
|
||||
tableInfo.setTableComment(tableRs.getString("TABLE_COMMENT"));
|
||||
@@ -127,8 +127,8 @@ public class MysqlUtils {
|
||||
/**
|
||||
* 获取指定表的字段信息
|
||||
*/
|
||||
private static List<DataTableField> getFieldsByTable(Connection conn, String dbName, String tableName) throws SQLException {
|
||||
List<DataTableField> fields = new ArrayList<>();
|
||||
private static List<BizTableField> getFieldsByTable(Connection conn, String dbName, String tableName) throws SQLException {
|
||||
List<BizTableField> fields = new ArrayList<>();
|
||||
String fieldSql = "SELECT " +
|
||||
"TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE, COLUMN_TYPE, COLUMN_COMMENT, " +
|
||||
"ORDINAL_POSITION, CHARACTER_MAXIMUM_LENGTH " +
|
||||
@@ -149,8 +149,8 @@ public class MysqlUtils {
|
||||
/**
|
||||
* 构建DataTableField实体
|
||||
*/
|
||||
private static DataTableField buildDataTableField(ResultSet fieldRs) throws SQLException {
|
||||
DataTableField field = new DataTableField();
|
||||
private static BizTableField buildDataTableField(ResultSet fieldRs) throws SQLException {
|
||||
BizTableField field = new BizTableField();
|
||||
field.setFieldId(vId.getUid());
|
||||
field.setDataSource(fieldRs.getString("TABLE_SCHEMA"));
|
||||
field.setDataName(fieldRs.getString("TABLE_NAME"));
|
||||
@@ -163,7 +163,7 @@ public class MysqlUtils {
|
||||
length = extractLengthFromType(fieldRs.getString("COLUMN_TYPE"));
|
||||
}
|
||||
field.setFieldLength(length);
|
||||
field.setCreateTime(LocalDateTime.now());
|
||||
field.setCreateTime(new Date());
|
||||
field.setDs(vDate.dsValue());
|
||||
return field;
|
||||
}
|
||||
@@ -188,11 +188,11 @@ public class MysqlUtils {
|
||||
List<TableTree> tableTrees = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = getConnection(dbConfig.getDbIp(), dbConfig.getDbPort(), dbConfig.getDbUsername(), dbConfig.getDbPassword());
|
||||
Map<String, List<DataTableInfo>> schemaInfo = MysqlUtils.getMysqlSchemaInfo(conn);
|
||||
for (Map.Entry<String, List<DataTableInfo>> entry : schemaInfo.entrySet()) {
|
||||
for (DataTableInfo tableInfo : entry.getValue()) {
|
||||
Map<String, List<BizTableInfo>> schemaInfo = MysqlUtils.getMysqlSchemaInfo(conn);
|
||||
for (Map.Entry<String, List<BizTableInfo>> entry : schemaInfo.entrySet()) {
|
||||
for (BizTableInfo tableInfo : entry.getValue()) {
|
||||
tableInfo.setDbId(dbConfig.getId());
|
||||
List<DataTableField> dataTableFields = getFieldsByTable(conn, entry.getKey(), tableInfo.getDataName());
|
||||
List<BizTableField> dataTableFields = getFieldsByTable(conn, entry.getKey(), tableInfo.getDataName());
|
||||
dataTableFields.stream().forEach(tableField -> tableField.setTableId(tableInfo.getTableId()));
|
||||
tableTrees.add(new TableTree(tableInfo, dataTableFields));
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.jeesite.modules.app.utils;
|
||||
|
||||
|
||||
import com.jeesite.modules.app.dao.DataTableField;
|
||||
import com.jeesite.modules.app.dao.DataTableInfo;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.entity.BizTableInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,13 +16,13 @@ public class SqlUtils {
|
||||
* @param fieldList 字段列表
|
||||
* @return CREATE TABLE语句
|
||||
*/
|
||||
public static String CreateTableSql(DataTableInfo tableInfo, List<DataTableField> fieldList) {
|
||||
public static String CreateTableSql(BizTableInfo tableInfo, List<BizTableField> fieldList) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 表定义开始
|
||||
sb.append("CREATE TABLE ").append(tableInfo.getDataName()).append(" (\n");
|
||||
// 拼接字段定义
|
||||
for (int i = 0; i < fieldList.size(); i++) {
|
||||
DataTableField field = fieldList.get(i);
|
||||
BizTableField field = fieldList.get(i);
|
||||
sb.append(" ").append(field.getFieldName()).append(" ");
|
||||
// 处理字段类型和长度
|
||||
if (field.getFieldLength() != null && field.getFieldLength() > 0) {
|
||||
@@ -66,7 +66,7 @@ public class SqlUtils {
|
||||
* @param fieldList 字段列表
|
||||
* @return 带注释的SELECT语句
|
||||
*/
|
||||
public static String SelectSqlComments(DataTableInfo tableInfo, List<DataTableField> fieldList) {
|
||||
public static String SelectSqlComments(BizTableInfo tableInfo, List<BizTableField> fieldList) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 表注释
|
||||
sb.append("-- 表名:").append(tableInfo.getDataName()).append("\n");
|
||||
@@ -76,7 +76,7 @@ public class SqlUtils {
|
||||
sb.append("SELECT\n");
|
||||
// 拼接字段(带注释)
|
||||
for (int i = 0; i < fieldList.size(); i++) {
|
||||
DataTableField field = fieldList.get(i);
|
||||
BizTableField field = fieldList.get(i);
|
||||
// 拼接字段名
|
||||
sb.append(" ").append(field.getFieldName());
|
||||
// 非最后一个字段加逗号(先处理逗号)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jeesite.modules.biz.dao;
|
||||
|
||||
import com.jeesite.common.dao.CrudDao;
|
||||
import com.jeesite.common.mybatis.annotation.MyBatisDao;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
|
||||
/**
|
||||
* 字段信息DAO接口
|
||||
* @author gaoxq
|
||||
* @version 2025-12-02
|
||||
*/
|
||||
@MyBatisDao(dataSourceName="work")
|
||||
public interface BizTableFieldDao extends CrudDao<BizTableField> {
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import java.io.Serial;
|
||||
@Column(name = "f_flow_id", attrName = "fflowId", label = "流程id", isUpdate = false, isQuery = false),
|
||||
@Column(name = "f_flow_task_id", attrName = "fflowTaskId", label = "流程任务主键", isUpdate = false, isQuery = false),
|
||||
@Column(name = "f_flow_state", attrName = "fflowState", label = "流程任务状态", isUpdate = false, isQuery = false, isUpdateForce = true),
|
||||
}, orderBy = "a.id DESC"
|
||||
}, orderBy = "a.create_time DESC"
|
||||
)
|
||||
@Data
|
||||
public class BizDbConfig extends DataEntity<BizDbConfig> implements Serializable {
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.jeesite.modules.biz.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jeesite.common.mybatis.annotation.JoinTable;
|
||||
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import com.jeesite.common.entity.DataEntity;
|
||||
import com.jeesite.common.mybatis.annotation.Column;
|
||||
import com.jeesite.common.mybatis.annotation.Table;
|
||||
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelFields;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 字段信息Entity
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-02
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table(name = "biz_table_field", alias = "a", label = "字段信息信息", columns = {
|
||||
@Column(name = "create_time", attrName = "createTime", label = "创建时间", isUpdate = false, isUpdateForce = true),
|
||||
@Column(name = "field_id", attrName = "fieldId", label = "唯一标识", isPK = true),
|
||||
@Column(name = "table_id", attrName = "tableId", label = "数据标识"),
|
||||
@Column(name = "data_source", attrName = "dataSource", label = "数据来源"),
|
||||
@Column(name = "data_name", attrName = "dataName", label = "数据表名称", queryType = QueryType.LIKE),
|
||||
@Column(name = "field_order", attrName = "fieldOrder", label = "字段序号", isQuery = false),
|
||||
@Column(name = "field_type", attrName = "fieldType", label = "字段类型", isQuery = false),
|
||||
@Column(name = "field_name", attrName = "fieldName", label = "字段名称", queryType = QueryType.LIKE),
|
||||
@Column(name = "field_length", attrName = "fieldLength", label = "字段长度", isQuery = false),
|
||||
@Column(name = "field_remark", attrName = "fieldRemark", label = "字段说明"),
|
||||
@Column(name = "ds", attrName = "ds", label = "分区日期"),
|
||||
@Column(name = "f_tenant_id", attrName = "ftenantId", label = "租户id", isUpdate = false, isQuery = false),
|
||||
@Column(name = "f_flow_id", attrName = "fflowId", label = "流程id", isUpdate = false, isQuery = false),
|
||||
@Column(name = "f_flow_task_id", attrName = "fflowTaskId", label = "流程任务主键", isUpdate = false, isQuery = false),
|
||||
@Column(name = "f_flow_state", attrName = "fflowState", label = "流程任务状态", isUpdate = false, isQuery = false, isUpdateForce = true),
|
||||
}, joinTable = {
|
||||
@JoinTable(type = Type.LEFT_JOIN, entity = BizTableInfo.class, attrName = "this", alias = "b",
|
||||
on = "a.table_id = b.table_id AND a.ds = b.ds",
|
||||
columns = {
|
||||
@Column(name = "table_comment", attrName = "tableComment", label = "数据表描述"),
|
||||
@Column(name = "db_id", attrName = "dbId", label = "数据标识"),
|
||||
}),
|
||||
@JoinTable(type = Type.LEFT_JOIN, entity = BizDbConfig.class, attrName = "this", alias = "c",
|
||||
on = "b.db_id = c.id",
|
||||
columns = {
|
||||
@Column(name = "db_type", attrName = "dbType", label = "数据库类型"),
|
||||
@Column(name = "db_name", attrName = "dbName", label = "数据库名称"),
|
||||
@Column(name = "db_ip", attrName = "dbIp", label = "数据库IP"),
|
||||
|
||||
}),
|
||||
}, orderBy = "a.create_time DESC"
|
||||
)
|
||||
@Data
|
||||
public class BizTableField extends DataEntity<BizTableField> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Date createTime; // 创建时间
|
||||
private String fieldId; // 唯一标识
|
||||
private String tableId; // 数据标识
|
||||
private String dataSource; // 数据来源
|
||||
private String dataName; // 数据表名称
|
||||
private Integer fieldOrder; // 字段序号
|
||||
private String fieldType; // 字段类型
|
||||
private String fieldName; // 字段名称
|
||||
private Long fieldLength; // 字段长度
|
||||
private String fieldRemark; // 字段说明
|
||||
private String ds; // 分区日期
|
||||
private String ftenantId; // 租户id
|
||||
private String fflowId; // 流程id
|
||||
private String fflowTaskId; // 流程任务主键
|
||||
private Integer fflowState; // 流程任务状态
|
||||
|
||||
private String dbId;
|
||||
private String tableComment;
|
||||
|
||||
private String dbType;
|
||||
private String dbName;
|
||||
private String dbIp;
|
||||
|
||||
@ExcelFields({
|
||||
@ExcelField(title = "创建时间", attrName = "createTime", align = Align.CENTER, sort = 10, dataFormat = "yyyy-MM-dd hh:mm"),
|
||||
@ExcelField(title = "唯一标识", attrName = "fieldId", align = Align.CENTER, sort = 20),
|
||||
@ExcelField(title = "数据标识", attrName = "dbName", align = Align.CENTER, sort = 30),
|
||||
@ExcelField(title = "数据来源", attrName = "dataSource", align = Align.CENTER, sort = 40),
|
||||
@ExcelField(title = "数据表名称", attrName = "dataName", align = Align.CENTER, sort = 50),
|
||||
@ExcelField(title = "字段序号", attrName = "fieldOrder", align = Align.CENTER, sort = 60),
|
||||
@ExcelField(title = "字段类型", attrName = "fieldType", align = Align.CENTER, sort = 70),
|
||||
@ExcelField(title = "字段名称", attrName = "fieldName", align = Align.CENTER, sort = 80),
|
||||
@ExcelField(title = "字段长度", attrName = "fieldLength", align = Align.CENTER, sort = 90),
|
||||
@ExcelField(title = "字段说明", attrName = "fieldRemark", align = Align.CENTER, sort = 100),
|
||||
@ExcelField(title = "分区日期", attrName = "ds", align = Align.CENTER, sort = 110),
|
||||
})
|
||||
public BizTableField() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public BizTableField(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Date getCreateTime_gte() {
|
||||
return sqlMap.getWhere().getValue("create_time", QueryType.GTE);
|
||||
}
|
||||
|
||||
public void setCreateTime_gte(Date createTime) {
|
||||
sqlMap.getWhere().and("create_time", QueryType.GTE, createTime);
|
||||
}
|
||||
|
||||
public Date getCreateTime_lte() {
|
||||
return sqlMap.getWhere().getValue("create_time", QueryType.LTE);
|
||||
}
|
||||
|
||||
public void setCreateTime_lte(Date createTime) {
|
||||
sqlMap.getWhere().and("create_time", QueryType.LTE, createTime);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jeesite.modules.biz.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jeesite.common.mybatis.annotation.JoinTable;
|
||||
@@ -58,15 +59,15 @@ public class BizTableInfo extends DataEntity<BizTableInfo> implements Serializab
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Date createTime; // 创建时间
|
||||
private String createTime; // 创建时间
|
||||
private String tableId; // 唯一标识
|
||||
private String dataName; // 数据表名称
|
||||
private String tableComment; // 数据表描述
|
||||
private Double tableSize; // 数据表大小
|
||||
private BigDecimal tableSize; // 数据表大小
|
||||
private String dataSource; // 数据来源
|
||||
private String creator; // 创建人员
|
||||
private Long dataRows; // 记录条数
|
||||
private Date updateTime; // 更新时间
|
||||
private String updateTime; // 更新时间
|
||||
private String dbId; // 数据标识
|
||||
private String ds; // 分区日期
|
||||
private String ftenantId; // 租户id
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.jeesite.modules.biz.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.service.CrudService;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.dao.BizTableFieldDao;
|
||||
import com.jeesite.common.service.ServiceException;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.validator.ValidatorUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelImport;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 字段信息Service
|
||||
* @author gaoxq
|
||||
* @version 2025-12-02
|
||||
*/
|
||||
@Service
|
||||
public class BizTableFieldService extends CrudService<BizTableFieldDao, BizTableField> {
|
||||
|
||||
/**
|
||||
* 获取单条数据
|
||||
* @param bizTableField 主键
|
||||
*/
|
||||
@Override
|
||||
public BizTableField get(BizTableField bizTableField) {
|
||||
return super.get(bizTableField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分页数据
|
||||
* @param bizTableField 查询条件
|
||||
* @param bizTableField page 分页对象
|
||||
*/
|
||||
@Override
|
||||
public Page<BizTableField> findPage(BizTableField bizTableField) {
|
||||
return super.findPage(bizTableField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
* @param bizTableField 查询条件
|
||||
*/
|
||||
@Override
|
||||
public List<BizTableField> findList(BizTableField bizTableField) {
|
||||
return super.findList(bizTableField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据(插入或更新)
|
||||
* @param bizTableField 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(BizTableField bizTableField) {
|
||||
super.save(bizTableField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* @param file 导入的数据文件
|
||||
*/
|
||||
@Transactional
|
||||
public String importData(MultipartFile file) {
|
||||
if (file == null){
|
||||
throw new ServiceException(text("请选择导入的数据文件!"));
|
||||
}
|
||||
int successNum = 0; int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
||||
List<BizTableField> list = ei.getDataList(BizTableField.class);
|
||||
for (BizTableField bizTableField : list) {
|
||||
try{
|
||||
ValidatorUtils.validateWithException(bizTableField);
|
||||
this.save(bizTableField);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、编号 " + bizTableField.getId() + " 导入成功");
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、编号 " + bizTableField.getId() + " 导入失败:";
|
||||
if (e instanceof ConstraintViolationException){
|
||||
ConstraintViolationException cve = (ConstraintViolationException)e;
|
||||
for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
||||
msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
||||
}
|
||||
}else{
|
||||
msg += e.getMessage();
|
||||
}
|
||||
failureMsg.append(msg);
|
||||
logger.error(msg, e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
failureMsg.append(e.getMessage());
|
||||
return failureMsg.toString();
|
||||
}
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}else{
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param bizTableField 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateStatus(BizTableField bizTableField) {
|
||||
super.updateStatus(bizTableField);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param bizTableField 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(BizTableField bizTableField) {
|
||||
super.delete(bizTableField);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.jeesite.modules.biz.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jeesite.modules.app.utils.vDate;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelExport;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import com.jeesite.modules.biz.entity.BizTableField;
|
||||
import com.jeesite.modules.biz.service.BizTableFieldService;
|
||||
|
||||
/**
|
||||
* 字段信息Controller
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-02
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/biz/tableField")
|
||||
public class BizTableFieldController extends BaseController {
|
||||
|
||||
private final BizTableFieldService bizTableFieldService;
|
||||
|
||||
public BizTableFieldController(BizTableFieldService bizTableFieldService) {
|
||||
this.bizTableFieldService = bizTableFieldService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*/
|
||||
@ModelAttribute
|
||||
public BizTableField get(String fieldId, boolean isNewRecord) {
|
||||
return bizTableFieldService.get(fieldId, isNewRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(BizTableField bizTableField, Model model) {
|
||||
model.addAttribute("bizTableField", bizTableField);
|
||||
return "modules/biz/bizTableFieldList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:view")
|
||||
@RequestMapping(value = "listData")
|
||||
@ResponseBody
|
||||
public Page<BizTableField> listData(BizTableField bizTableField, HttpServletRequest request, HttpServletResponse response) {
|
||||
bizTableField.setDs(vDate.dsValue());
|
||||
bizTableField.setPage(new Page<>(request, response));
|
||||
Page<BizTableField> page = bizTableFieldService.findPage(bizTableField);
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看编辑表单
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(BizTableField bizTableField, Model model) {
|
||||
model.addAttribute("bizTableField", bizTableField);
|
||||
return "modules/biz/bizTableFieldForm";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:edit")
|
||||
@PostMapping(value = "save")
|
||||
@ResponseBody
|
||||
public String save(@Validated BizTableField bizTableField) {
|
||||
bizTableFieldService.save(bizTableField);
|
||||
return renderResult(Global.TRUE, text("保存字段信息成功!"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:view")
|
||||
@RequestMapping(value = "exportData")
|
||||
public void exportData(BizTableField bizTableField, HttpServletResponse response) {
|
||||
List<BizTableField> list = bizTableFieldService.findList(bizTableField);
|
||||
String fileName = "字段信息" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("字段信息", BizTableField.class)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载模板
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:view")
|
||||
@RequestMapping(value = "importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
BizTableField bizTableField = new BizTableField();
|
||||
List<BizTableField> list = ListUtils.newArrayList(bizTableField);
|
||||
String fileName = "字段信息模板.xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("字段信息", BizTableField.class, Type.IMPORT)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequiresPermissions("biz:tableField:edit")
|
||||
@PostMapping(value = "importData")
|
||||
public String importData(MultipartFile file) {
|
||||
try {
|
||||
String message = bizTableFieldService.importData(file);
|
||||
return renderResult(Global.TRUE, "posfull:" + message);
|
||||
} catch (Exception ex) {
|
||||
return renderResult(Global.FALSE, "posfull:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*/
|
||||
@RequiresPermissions("biz:tableField:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
@ResponseBody
|
||||
public String delete(BizTableField bizTableField) {
|
||||
bizTableFieldService.delete(bizTableField);
|
||||
return renderResult(Global.TRUE, text("删除字段信息成功!"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.jeesite.modules.biz.dao.BizTableFieldDao">
|
||||
|
||||
<!-- 查询数据
|
||||
<select id="findList" resultType="BizTableField">
|
||||
SELECT ${sqlMap.column.toSql()}
|
||||
FROM ${sqlMap.table.toSql()}
|
||||
<where>
|
||||
${sqlMap.where.toSql()}
|
||||
</where>
|
||||
ORDER BY ${sqlMap.order.toSql()}
|
||||
</select> -->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user