增加主机信息功能

This commit is contained in:
2026-04-19 21:44:59 +08:00
parent bc5ab27986
commit f6637a255d
26 changed files with 95 additions and 2308 deletions

View File

@@ -0,0 +1,23 @@
package com.jeesite.modules.apps.Module.Dict;
import lombok.Data;
import java.io.Serializable;
@Data
public class DataColumn implements Serializable {
private String createTime; // 创建时间
private String columnId; // 字段ID
private String tableId; // 所属表ID
private String tableSchema;
private String tableName;
private String columnName; // 字段名
private String columnComment; // 字段注释
private String columnType; // 字段类型
private String dataType; // 数据类型
private Long maxLength; // 长度
private String isNullable; // 0非空 1可为空
private String isPrimaryKey; // 0否 1是主键
private Integer sort; // 排序
}

View File

@@ -0,0 +1,19 @@
package com.jeesite.modules.apps.Module.Dict;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class DataTable implements Serializable {
private String createTime; // 创建时间
private String tableId; // 表ID
private String sourceId; // 数据源ID
private String tableName; // 数据表名
private String tableComment; // 表注释
private Long tableRows; // 数据行数
private BigDecimal tableSize;
private String dataSource;
}

View File

@@ -0,0 +1,24 @@
package com.jeesite.modules.apps.Module.Dict;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class TableTree implements Serializable {
DataTable dataTable;
List<DataColumn> dataColumns;
public TableTree() {
}
public TableTree(DataTable dataTable, List<DataColumn> dataColumns) {
this.dataTable = dataTable;
this.dataColumns = dataColumns;
}
}

View File

@@ -1,26 +0,0 @@
package com.jeesite.modules.apps.Module;
import com.jeesite.modules.biz.entity.MyDataColumn;
import com.jeesite.modules.biz.entity.MyDataTable;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class TableTree implements Serializable {
MyDataTable dataTable;
List<MyDataColumn> dataColumns;
public TableTree() {
}
public TableTree(MyDataTable dataTable, List<MyDataColumn> dataColumns) {
this.dataTable = dataTable;
this.dataColumns = dataColumns;
}
}

View File

@@ -1,9 +1,9 @@
package com.jeesite.modules.apps.utils;
import com.jeesite.modules.apps.Module.TableTree;
import com.jeesite.modules.biz.entity.MyDataColumn;
import com.jeesite.modules.apps.Module.Dict.DataColumn;
import com.jeesite.modules.apps.Module.Dict.DataTable;
import com.jeesite.modules.apps.Module.Dict.TableTree;
import com.jeesite.modules.biz.entity.MyDataSource;
import com.jeesite.modules.biz.entity.MyDataTable;
import java.math.BigDecimal;
@@ -44,14 +44,14 @@ public class MysqlUtils {
* @return 数据库名 -> 表信息列表(包含字段)的映射
* @throws Exception 连接或查询异常
*/
public static Map<String, List<MyDataTable>> getMysqlSchemaInfo(Connection conn) throws Exception {
Map<String, List<MyDataTable>> result = new HashMap<>();
public static Map<String, List<DataTable>> getMysqlSchemaInfo(Connection conn) throws Exception {
Map<String, List<DataTable>> result = new HashMap<>();
// 1. 获取所有非系统数据库
List<String> databases = getNonSystemDatabases(conn);
logger.info("获取到非系统数据库数量:", databases.size());
// 2. 遍历数据库,获取表和字段信息
for (String dbName : databases) {
List<MyDataTable> tableInfos = getTablesByDatabase(conn, dbName);
List<DataTable> tableInfos = getTablesByDatabase(conn, dbName);
result.put(dbName, tableInfos);
}
return result;
@@ -80,8 +80,8 @@ public class MysqlUtils {
/**
* 获取指定数据库下的所有表信息(包含字段)
*/
private static List<MyDataTable> getTablesByDatabase(Connection conn, String dbName) throws SQLException {
List<MyDataTable> tableInfos = new ArrayList<>();
private static List<DataTable> getTablesByDatabase(Connection conn, String dbName) throws SQLException {
List<DataTable> tableInfos = new ArrayList<>();
String tableSql = "SELECT " +
"TABLE_NAME, TABLE_COMMENT, CREATE_TIME, UPDATE_TIME, " +
"DATA_LENGTH, INDEX_LENGTH, TABLE_ROWS " +
@@ -90,8 +90,8 @@ public class MysqlUtils {
tablePs.setString(1, dbName);
try (ResultSet tableRs = tablePs.executeQuery()) {
while (tableRs.next()) {
MyDataTable tableInfo = buildDataTableInfo(tableRs, dbName);
List<MyDataColumn> fields = getFieldsByTable(conn, dbName, tableInfo.getTableName());
DataTable tableInfo = buildDataTableInfo(tableRs, dbName);
List<DataColumn> fields = getFieldsByTable(conn, dbName, tableInfo.getTableName());
fields.forEach(field -> field.setTableId(tableInfo.getTableId()));
tableInfos.add(tableInfo);
}
@@ -103,8 +103,8 @@ public class MysqlUtils {
/**
* 构建DataTableInfo实体
*/
private static MyDataTable buildDataTableInfo(ResultSet tableRs, String dbName) throws SQLException {
MyDataTable dataTable = new MyDataTable();
private static DataTable buildDataTableInfo(ResultSet tableRs, String dbName) throws SQLException {
DataTable dataTable = new DataTable();
String runTime = DateUtils.getCurrentDateTime();
String createDate = tableRs.getString("CREATE_TIME");
String updateDate = tableRs.getString("UPDATE_TIME");
@@ -120,19 +120,17 @@ public class MysqlUtils {
dataTable.setTableSize(tableSize);
dataTable.setDataSource(dbName);
dataTable.setCreateTime(createDate != null ? createDate : runTime);
dataTable.setUpdateTime(updateDate != null ? updateDate : runTime);
dataTable.setDs(DateUtils.dsValue());
return dataTable;
}
/**
* 获取指定表的字段信息
*/
private static List<MyDataColumn> getFieldsByTable(Connection conn, String dbName, String tableName) throws SQLException {
List<MyDataColumn> columns = new ArrayList<>();
private static List<DataColumn> getFieldsByTable(Connection conn, String dbName, String tableName) throws SQLException {
List<DataColumn> columns = new ArrayList<>();
String fieldSql = "SELECT " +
"TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,DATA_TYPE, COLUMN_TYPE, COLUMN_COMMENT, " +
"ORDINAL_POSITION, CHARACTER_MAXIMUM_LENGTH " +
"ORDINAL_POSITION, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE,COLUMN_KEY " +
"FROM COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? " +
"ORDER BY ORDINAL_POSITION";
try (PreparedStatement fieldPs = conn.prepareStatement(fieldSql)) {
@@ -150,22 +148,22 @@ public class MysqlUtils {
/**
* 构建DataTableField实体
*/
private static MyDataColumn buildDataTableField(ResultSet fieldRs) throws SQLException {
MyDataColumn column = new MyDataColumn();
private static DataColumn buildDataTableField(ResultSet fieldRs) throws SQLException {
DataColumn column = new DataColumn();
column.setColumnId(KeyUtil.ObjKey(32, 0));
column.setTableSchema(fieldRs.getString("TABLE_SCHEMA"));
column.setTableName(fieldRs.getString("TABLE_NAME"));
column.setColumnName(fieldRs.getString("COLUMN_NAME"));
column.setDataType(fieldRs.getString("DATA_TYPE"));
column.setSort(fieldRs.getInt("ORDINAL_POSITION"));
column.setIsNullable(fieldRs.getString("IS_NULLABLE"));
column.setIsPrimaryKey(fieldRs.getString("COLUMN_KEY"));
column.setColumnComment(fieldRs.getString("COLUMN_COMMENT"));
Long length = fieldRs.getLong("CHARACTER_MAXIMUM_LENGTH");
if (length == 0 || fieldRs.wasNull()) {
length = extractLengthFromType(fieldRs.getString("COLUMN_TYPE"));
}
column.setMaxLength(length);
column.setCreateTime(new Date());
column.setDs(DateUtils.dsValue());
return column;
}
@@ -189,11 +187,11 @@ public class MysqlUtils {
List<TableTree> tableTrees = new ArrayList<>();
try {
Connection conn = getConnection(dbConfig.getDbHost(), dbConfig.getDbPort(), dbConfig.getUsername(), dbConfig.getPassword());
Map<String, List<MyDataTable>> schemaInfo = MysqlUtils.getMysqlSchemaInfo(conn);
for (Map.Entry<String, List<MyDataTable>> entry : schemaInfo.entrySet()) {
for (MyDataTable dataTable : entry.getValue()) {
Map<String, List<DataTable>> schemaInfo = MysqlUtils.getMysqlSchemaInfo(conn);
for (Map.Entry<String, List<DataTable>> entry : schemaInfo.entrySet()) {
for (DataTable dataTable : entry.getValue()) {
dataTable.setSourceId(dbConfig.getId());
List<MyDataColumn> dataTableFields = getFieldsByTable(conn, entry.getKey(), dataTable.getTableName());
List<DataColumn> dataTableFields = getFieldsByTable(conn, entry.getKey(), dataTable.getTableName());
dataTableFields.stream().forEach(tableField -> tableField.setTableId(dataTable.getTableId()));
tableTrees.add(new TableTree(dataTable, dataTableFields));
}

View File

@@ -1,8 +1,8 @@
package com.jeesite.modules.apps.utils;
import com.jeesite.modules.biz.entity.MyDataColumn;
import com.jeesite.modules.biz.entity.MyDataTable;
import com.jeesite.modules.apps.Module.Dict.DataColumn;
import com.jeesite.modules.apps.Module.Dict.DataTable;
import java.util.List;
@@ -14,13 +14,13 @@ public class SqlUtils {
*
* @return CREATE TABLE语句
*/
public static String CreateTableSql(MyDataTable dataTable, List<MyDataColumn> dataColumns) {
public static String CreateTableSql(DataTable dataTable, List<DataColumn> dataColumns) {
StringBuilder sb = new StringBuilder();
// 表定义开始
sb.append("CREATE TABLE ").append(dataTable.getTableName()).append(" (\n");
// 拼接字段定义
for (int i = 0; i < dataColumns.size(); i++) {
MyDataColumn dataColumn = dataColumns.get(i);
DataColumn dataColumn = dataColumns.get(i);
sb.append(" ").append(dataColumn.getColumnName()).append(" ");
// 处理字段类型和长度
if (dataColumn.getMaxLength() != null && dataColumn.getMaxLength() > 0) {
@@ -56,7 +56,7 @@ public class SqlUtils {
*
* @return 带注释的SELECT语句
*/
public static String SelectSqlComments(MyDataTable dataTable, List<MyDataColumn> dataColumns) {
public static String SelectSqlComments(DataTable dataTable, List<DataColumn> dataColumns) {
StringBuilder sb = new StringBuilder();
// 表注释
sb.append("-- 表名:").append(dataTable.getTableName()).append("\n");
@@ -66,7 +66,7 @@ public class SqlUtils {
sb.append("SELECT\n");
// 拼接字段(带注释)
for (int i = 0; i < dataColumns.size(); i++) {
MyDataColumn dataColumn = dataColumns.get(i);
DataColumn dataColumn = dataColumns.get(i);
// 拼接字段名
sb.append(" ").append(dataColumn.getColumnName());
if (i != dataColumns.size() - 1) {

View File

@@ -1,15 +0,0 @@
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.MyDataColumn;
/**
* 数据字段信息表 DAO 接口
* @author gaoxq
* @version 2026-04-19
*/
@MyBatisDao(dataSourceName="work")
public interface MyDataColumnDao extends CrudDao<MyDataColumn> {
}

View File

@@ -1,15 +0,0 @@
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.MyDataTable;
/**
* 数据表信息表 DAO 接口
* @author gaoxq
* @version 2026-04-19
*/
@MyBatisDao(dataSourceName="work")
public interface MyDataTableDao extends CrudDao<MyDataTable> {
}

View File

@@ -1,91 +0,0 @@
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 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 2026-04-19
*/
@EqualsAndHashCode(callSuper = true)
@Table(name = "my_data_column", alias = "a", label = "字段信息表信息", columns = {
@Column(name = "create_time", attrName = "createTime", label = "创建时间", isUpdateForce = true),
@Column(name = "column_id", attrName = "columnId", label = "字段ID", isPK = true),
@Column(name = "table_id", attrName = "tableId", label = "所属表ID"),
@Column(name = "table_schema", attrName = "tableSchema", label = "数据库名称"),
@Column(name = "table_name", attrName = "tableName", label = "所属表名称"),
@Column(name = "column_name", attrName = "columnName", label = "字段名", queryType = QueryType.LIKE),
@Column(name = "column_comment", attrName = "columnComment", label = "字段注释"),
@Column(name = "column_type", attrName = "columnType", label = "字段类型"),
@Column(name = "data_type", attrName = "dataType", label = "数据类型"),
@Column(name = "max_length", attrName = "maxLength", label = "长度", isUpdateForce = true),
@Column(name = "is_nullable", attrName = "isNullable", label = "0非空 1可为空"),
@Column(name = "is_primary_key", attrName = "isPrimaryKey", label = "0否 1是主键"),
@Column(name = "sort", attrName = "sort", label = "排序", isUpdateForce = true),
@Column(name = "update_time", attrName = "updateTime", label = "更新日期", isUpdateForce = true),
@Column(name = "ds", attrName = "ds", label = "日期分区"),
}, orderBy = "a.column_id DESC"
)
@Data
public class MyDataColumn extends DataEntity<MyDataColumn> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Date createTime; // 创建时间
private String columnId; // 字段ID
private String tableId; // 所属表ID
private String tableSchema;
private String tableName;
private String columnName; // 字段名
private String columnComment; // 字段注释
private String columnType; // 字段类型
private String dataType; // 数据类型
private Long maxLength; // 长度
private String isNullable; // 0非空 1可为空
private String isPrimaryKey; // 0否 1是主键
private Integer sort; // 排序
private Date updateTime; // 更新日期
private String ds;
@ExcelFields({
@ExcelField(title = "创建时间", attrName = "createTime", align = Align.CENTER, sort = 10, dataFormat = "yyyy-MM-dd hh:mm"),
@ExcelField(title = "字段ID", attrName = "columnId", align = Align.CENTER, sort = 20),
@ExcelField(title = "所属表ID", attrName = "tableId", align = Align.CENTER, sort = 30),
@ExcelField(title = "字段名", attrName = "columnName", align = Align.CENTER, sort = 40),
@ExcelField(title = "字段注释", attrName = "columnComment", align = Align.CENTER, sort = 50),
@ExcelField(title = "字段类型", attrName = "columnType", align = Align.CENTER, sort = 60),
@ExcelField(title = "数据类型", attrName = "dataType", align = Align.CENTER, sort = 70),
@ExcelField(title = "长度", attrName = "maxLength", align = Align.CENTER, sort = 80),
@ExcelField(title = "0非空 1可为空", attrName = "isNullable", align = Align.CENTER, sort = 90),
@ExcelField(title = "0否 1是主键", attrName = "isPrimaryKey", align = Align.CENTER, sort = 100),
@ExcelField(title = "排序", attrName = "sort", align = Align.CENTER, sort = 110),
@ExcelField(title = "update_time", attrName = "updateTime", align = Align.CENTER, sort = 120, dataFormat = "yyyy-MM-dd hh:mm"),
})
public MyDataColumn() {
this(null);
}
public MyDataColumn(String id) {
super(id);
}
}

View File

@@ -1,76 +0,0 @@
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;
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 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 java.io.Serial;
/**
* 数据表信息表 Entity
*
* @author gaoxq
* @version 2026-04-19
*/
@Table(name = "my_data_table", alias = "a", label = "数据表信息信息", columns = {
@Column(name = "create_time", attrName = "createTime", label = "创建时间", isUpdate = false, isUpdateForce = true),
@Column(name = "table_id", attrName = "tableId", label = "表ID", isPK = true),
@Column(name = "source_id", attrName = "sourceId", label = "数据源ID"),
@Column(name = "table_name", attrName = "tableName", label = "数据表名", queryType = QueryType.LIKE),
@Column(name = "table_comment", attrName = "tableComment", label = "表注释"),
@Column(name = "table_rows", attrName = "tableRows", label = "数据行数"),
@Column(name = "table_size", attrName = "tableSize", label = "数据表大小"),
@Column(name = "update_time", attrName = "updateTime", label = "更新日期"),
@Column(name = "data_source", attrName = "dataSource", label = "数据库名称"),
@Column(name = "ds", attrName = "ds", label = "日期分区"),
}, orderBy = "a.create_time DESC"
)
@Data
public class MyDataTable extends DataEntity<MyDataTable> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String createTime; // 创建时间
private String tableId; // 表ID
private String sourceId; // 数据源ID
private String tableName; // 数据表名
private String tableComment; // 表注释
private Long tableRows; // 数据行数
private BigDecimal tableSize;
private String updateTime; // 更新日期
private String dataSource;
private String ds;
@ExcelFields({
@ExcelField(title = "创建时间", attrName = "createTime", align = Align.CENTER, sort = 10, dataFormat = "yyyy-MM-dd hh:mm"),
@ExcelField(title = "表ID", attrName = "tableId", align = Align.CENTER, sort = 20),
@ExcelField(title = "数据源ID", attrName = "sourceId", align = Align.CENTER, sort = 30),
@ExcelField(title = "数据表名", attrName = "tableName", align = Align.CENTER, sort = 40),
@ExcelField(title = "表注释", attrName = "tableComment", align = Align.CENTER, sort = 50),
@ExcelField(title = "数据行数", attrName = "tableRows", align = Align.CENTER, sort = 60),
@ExcelField(title = "update_time", attrName = "updateTime", align = Align.CENTER, sort = 70, dataFormat = "yyyy-MM-dd hh:mm"),
})
public MyDataTable() {
this(null);
}
public MyDataTable(String id) {
super(id);
}
}

View File

@@ -1,134 +0,0 @@
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.MyDataColumn;
import com.jeesite.modules.biz.dao.MyDataColumnDao;
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 2026-04-19
*/
@Service
public class MyDataColumnService extends CrudService<MyDataColumnDao, MyDataColumn> {
/**
* 获取单条数据
* @param myDataColumn 主键
*/
@Override
public MyDataColumn get(MyDataColumn myDataColumn) {
return super.get(myDataColumn);
}
/**
* 查询分页数据
* @param myDataColumn 查询条件
* @param myDataColumn page 分页对象
*/
@Override
public Page<MyDataColumn> findPage(MyDataColumn myDataColumn) {
return super.findPage(myDataColumn);
}
/**
* 查询列表数据
* @param myDataColumn 查询条件
*/
@Override
public List<MyDataColumn> findList(MyDataColumn myDataColumn) {
return super.findList(myDataColumn);
}
/**
* 保存数据(插入或更新)
* @param myDataColumn 数据对象
*/
@Override
@Transactional
public void save(MyDataColumn myDataColumn) {
super.save(myDataColumn);
}
/**
* 导入数据
* @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<MyDataColumn> list = ei.getDataList(MyDataColumn.class);
for (MyDataColumn myDataColumn : list) {
try{
ValidatorUtils.validateWithException(myDataColumn);
this.save(myDataColumn);
successNum++;
successMsg.append("<br/>" + successNum + "、编号 " + myDataColumn.getId() + " 导入成功");
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、编号 " + myDataColumn.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 myDataColumn 数据对象
*/
@Override
@Transactional
public void updateStatus(MyDataColumn myDataColumn) {
super.updateStatus(myDataColumn);
}
/**
* 删除数据
* @param myDataColumn 数据对象
*/
@Override
@Transactional
public void delete(MyDataColumn myDataColumn) {
super.delete(myDataColumn);
}
}

View File

@@ -1,134 +0,0 @@
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.MyDataTable;
import com.jeesite.modules.biz.dao.MyDataTableDao;
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 2026-04-19
*/
@Service
public class MyDataTableService extends CrudService<MyDataTableDao, MyDataTable> {
/**
* 获取单条数据
* @param myDataTable 主键
*/
@Override
public MyDataTable get(MyDataTable myDataTable) {
return super.get(myDataTable);
}
/**
* 查询分页数据
* @param myDataTable 查询条件
* @param myDataTable page 分页对象
*/
@Override
public Page<MyDataTable> findPage(MyDataTable myDataTable) {
return super.findPage(myDataTable);
}
/**
* 查询列表数据
* @param myDataTable 查询条件
*/
@Override
public List<MyDataTable> findList(MyDataTable myDataTable) {
return super.findList(myDataTable);
}
/**
* 保存数据(插入或更新)
* @param myDataTable 数据对象
*/
@Override
@Transactional
public void save(MyDataTable myDataTable) {
super.save(myDataTable);
}
/**
* 导入数据
* @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<MyDataTable> list = ei.getDataList(MyDataTable.class);
for (MyDataTable myDataTable : list) {
try{
ValidatorUtils.validateWithException(myDataTable);
this.save(myDataTable);
successNum++;
successMsg.append("<br/>" + successNum + "、编号 " + myDataTable.getId() + " 导入成功");
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、编号 " + myDataTable.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 myDataTable 数据对象
*/
@Override
@Transactional
public void updateStatus(MyDataTable myDataTable) {
super.updateStatus(myDataTable);
}
/**
* 删除数据
* @param myDataTable 数据对象
*/
@Override
@Transactional
public void delete(MyDataTable myDataTable) {
super.delete(myDataTable);
}
}

View File

@@ -1,146 +0,0 @@
package com.jeesite.modules.biz.web;
import java.util.List;
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.MyDataColumn;
import com.jeesite.modules.biz.service.MyDataColumnService;
/**
* 数据字段信息表 Controller
* @author gaoxq
* @version 2026-04-19
*/
@Controller
@RequestMapping(value = "${adminPath}/biz/myDataColumn")
public class MyDataColumnController extends BaseController {
private final MyDataColumnService myDataColumnService;
public MyDataColumnController(MyDataColumnService myDataColumnService) {
this.myDataColumnService = myDataColumnService;
}
/**
* 获取数据
*/
@ModelAttribute
public MyDataColumn get(String columnId, boolean isNewRecord) {
return myDataColumnService.get(columnId, isNewRecord);
}
/**
* 查询列表
*/
@RequiresPermissions("biz:myDataColumn:view")
@RequestMapping(value = {"list", ""})
public String list(MyDataColumn myDataColumn, Model model) {
model.addAttribute("myDataColumn", myDataColumn);
return "modules/biz/myDataColumnList";
}
/**
* 查询列表数据
*/
@RequiresPermissions("biz:myDataColumn:view")
@RequestMapping(value = "listData")
@ResponseBody
public Page<MyDataColumn> listData(MyDataColumn myDataColumn, HttpServletRequest request, HttpServletResponse response) {
myDataColumn.setPage(new Page<>(request, response));
Page<MyDataColumn> page = myDataColumnService.findPage(myDataColumn);
return page;
}
/**
* 查看编辑表单
*/
@RequiresPermissions("biz:myDataColumn:view")
@RequestMapping(value = "form")
public String form(MyDataColumn myDataColumn, Model model) {
model.addAttribute("myDataColumn", myDataColumn);
return "modules/biz/myDataColumnForm";
}
/**
* 保存数据
*/
@RequiresPermissions("biz:myDataColumn:edit")
@PostMapping(value = "save")
@ResponseBody
public String save(@Validated MyDataColumn myDataColumn) {
myDataColumnService.save(myDataColumn);
return renderResult(Global.TRUE, text("保存字段信息表成功!"));
}
/**
* 导出数据
*/
@RequiresPermissions("biz:myDataColumn:view")
@RequestMapping(value = "exportData")
public void exportData(MyDataColumn myDataColumn, HttpServletResponse response) {
List<MyDataColumn> list = myDataColumnService.findList(myDataColumn);
String fileName = "字段信息表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
try(ExcelExport ee = new ExcelExport("字段信息表", MyDataColumn.class)){
ee.setDataList(list).write(response, fileName);
}
}
/**
* 下载模板
*/
@RequiresPermissions("biz:myDataColumn:view")
@RequestMapping(value = "importTemplate")
public void importTemplate(HttpServletResponse response) {
MyDataColumn myDataColumn = new MyDataColumn();
List<MyDataColumn> list = ListUtils.newArrayList(myDataColumn);
String fileName = "字段信息表模板.xlsx";
try(ExcelExport ee = new ExcelExport("字段信息表", MyDataColumn.class, Type.IMPORT)){
ee.setDataList(list).write(response, fileName);
}
}
/**
* 导入数据
*/
@ResponseBody
@RequiresPermissions("biz:myDataColumn:edit")
@PostMapping(value = "importData")
public String importData(MultipartFile file) {
try {
String message = myDataColumnService.importData(file);
return renderResult(Global.TRUE, "posfull:"+message);
} catch (Exception ex) {
return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
}
}
/**
* 删除数据
*/
@RequiresPermissions("biz:myDataColumn:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(MyDataColumn myDataColumn) {
myDataColumnService.delete(myDataColumn);
return renderResult(Global.TRUE, text("删除字段信息表成功!"));
}
}

View File

@@ -1,146 +0,0 @@
package com.jeesite.modules.biz.web;
import java.util.List;
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.MyDataTable;
import com.jeesite.modules.biz.service.MyDataTableService;
/**
* 数据表信息表 Controller
* @author gaoxq
* @version 2026-04-19
*/
@Controller
@RequestMapping(value = "${adminPath}/biz/myDataTable")
public class MyDataTableController extends BaseController {
private final MyDataTableService myDataTableService;
public MyDataTableController(MyDataTableService myDataTableService) {
this.myDataTableService = myDataTableService;
}
/**
* 获取数据
*/
@ModelAttribute
public MyDataTable get(String tableId, boolean isNewRecord) {
return myDataTableService.get(tableId, isNewRecord);
}
/**
* 查询列表
*/
@RequiresPermissions("biz:myDataTable:view")
@RequestMapping(value = {"list", ""})
public String list(MyDataTable myDataTable, Model model) {
model.addAttribute("myDataTable", myDataTable);
return "modules/biz/myDataTableList";
}
/**
* 查询列表数据
*/
@RequiresPermissions("biz:myDataTable:view")
@RequestMapping(value = "listData")
@ResponseBody
public Page<MyDataTable> listData(MyDataTable myDataTable, HttpServletRequest request, HttpServletResponse response) {
myDataTable.setPage(new Page<>(request, response));
Page<MyDataTable> page = myDataTableService.findPage(myDataTable);
return page;
}
/**
* 查看编辑表单
*/
@RequiresPermissions("biz:myDataTable:view")
@RequestMapping(value = "form")
public String form(MyDataTable myDataTable, Model model) {
model.addAttribute("myDataTable", myDataTable);
return "modules/biz/myDataTableForm";
}
/**
* 保存数据
*/
@RequiresPermissions("biz:myDataTable:edit")
@PostMapping(value = "save")
@ResponseBody
public String save(@Validated MyDataTable myDataTable) {
myDataTableService.save(myDataTable);
return renderResult(Global.TRUE, text("保存数据表信息成功!"));
}
/**
* 导出数据
*/
@RequiresPermissions("biz:myDataTable:view")
@RequestMapping(value = "exportData")
public void exportData(MyDataTable myDataTable, HttpServletResponse response) {
List<MyDataTable> list = myDataTableService.findList(myDataTable);
String fileName = "数据表信息" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
try(ExcelExport ee = new ExcelExport("数据表信息", MyDataTable.class)){
ee.setDataList(list).write(response, fileName);
}
}
/**
* 下载模板
*/
@RequiresPermissions("biz:myDataTable:view")
@RequestMapping(value = "importTemplate")
public void importTemplate(HttpServletResponse response) {
MyDataTable myDataTable = new MyDataTable();
List<MyDataTable> list = ListUtils.newArrayList(myDataTable);
String fileName = "数据表信息模板.xlsx";
try(ExcelExport ee = new ExcelExport("数据表信息", MyDataTable.class, Type.IMPORT)){
ee.setDataList(list).write(response, fileName);
}
}
/**
* 导入数据
*/
@ResponseBody
@RequiresPermissions("biz:myDataTable:edit")
@PostMapping(value = "importData")
public String importData(MultipartFile file) {
try {
String message = myDataTableService.importData(file);
return renderResult(Global.TRUE, "posfull:"+message);
} catch (Exception ex) {
return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
}
}
/**
* 删除数据
*/
@RequiresPermissions("biz:myDataTable:edit")
@RequestMapping(value = "delete")
@ResponseBody
public String delete(MyDataTable myDataTable) {
myDataTableService.delete(myDataTable);
return renderResult(Global.TRUE, text("删除数据表信息成功!"));
}
}

View File

@@ -1,15 +0,0 @@
<?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.MyDataColumnDao">
<!-- 查询数据
<select id="findList" resultType="MyDataColumn">
SELECT ${sqlMap.column.toSql()}
FROM ${sqlMap.table.toSql()}
<where>
${sqlMap.where.toSql()}
</where>
ORDER BY ${sqlMap.order.toSql()}
</select> -->
</mapper>

View File

@@ -1,15 +0,0 @@
<?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.MyDataTableDao">
<!-- 查询数据
<select id="findList" resultType="MyDataTable">
SELECT ${sqlMap.column.toSql()}
FROM ${sqlMap.table.toSql()}
<where>
${sqlMap.where.toSql()}
</where>
ORDER BY ${sqlMap.order.toSql()}
</select> -->
</mapper>