14 changed files with 391 additions and 25 deletions
@ -1,14 +0,0 @@ |
|||||||
package com.hnac.hzims.bigmodel.datasource.service; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* @Author: huangxing |
|
||||||
* @Date: 2024/06/28 14:22 |
|
||||||
*/ |
|
||||||
public interface IDataSourceService { |
|
||||||
|
|
||||||
List<Map<String,Object>> queryList(String sql); |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,32 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.datasource.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/05 08:19 |
||||||
|
*/ |
||||||
|
@ApiModel(value = "",description = "") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode |
||||||
|
public class SqlVO implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty("执行sql") |
||||||
|
@NotBlank |
||||||
|
private String sql; |
||||||
|
|
||||||
|
@ApiModelProperty("执行人") |
||||||
|
@NotBlank |
||||||
|
private String userId; |
||||||
|
|
||||||
|
@ApiModelProperty("执行sql设计表信息") |
||||||
|
private List<TableAuthVO> tableAuthVOList; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.datasource.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 17:29 |
||||||
|
*/ |
||||||
|
@ApiModel(value = "表鉴权对象",description = "表鉴权对象") |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode |
||||||
|
public class TableAuthVO implements Serializable { |
||||||
|
|
||||||
|
@ApiModelProperty("鉴权类型,目前不为空即为平台数据权限") |
||||||
|
private String auth; |
||||||
|
|
||||||
|
@ApiModelProperty("数据源名称") |
||||||
|
private String datasourceName; |
||||||
|
|
||||||
|
@ApiModelProperty("数据表名称") |
||||||
|
private String tableName; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.controller; |
||||||
|
|
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.service.TableColumnService; |
||||||
|
import com.hnac.hzinfo.log.annotation.Business; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 09:28 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/table/info") |
||||||
|
@Api(value = "数据库表、列信息查询管理",tags = "数据库表、列信息查询管理") |
||||||
|
@Business(module = BigModelConstants.APP_NAME,value = "数据库表、列信息查询管理",ignore = false) |
||||||
|
@AllArgsConstructor |
||||||
|
public class TableColumnController { |
||||||
|
|
||||||
|
private final TableColumnService tableColumnService; |
||||||
|
|
||||||
|
@ApiOperation("获取数据库") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
@GetMapping("/getDatabase") |
||||||
|
public R<List<Map<String,Object>>> getDatabase() { |
||||||
|
return R.data(tableColumnService.getDatabase()); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取数据库表列表") |
||||||
|
@ApiOperationSupport(order = 2) |
||||||
|
@GetMapping("/getTables") |
||||||
|
public R<List<Map<String,Object>>> getTables(@RequestParam @ApiParam(value = "数据库名") String database) { |
||||||
|
return R.data(tableColumnService.getTables(database)); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation("获取数据库表列列表") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
@GetMapping("/getColumns") |
||||||
|
public R<List<Map<String,Object>>> getColumns(@RequestParam @ApiParam(value = "数据库名") String database, |
||||||
|
@RequestParam @ApiParam(value = "数据库表名") String tableName) { |
||||||
|
return R.data(tableColumnService.getColumns(database,tableName)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,61 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.controller; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import com.hnac.hzims.bigmodel.BigModelConstants; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.entity.TableInfoEntity; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.service.TableInfoService; |
||||||
|
import com.hnac.hzinfo.log.annotation.Business; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.annotations.ApiParam; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.validation.Valid; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 15:26 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/tableInfo") |
||||||
|
@Api(value = "数据库信息管理",tags = "数据库信息管理") |
||||||
|
@AllArgsConstructor |
||||||
|
@Business(module = BigModelConstants.APP_NAME,value = "数据库信息管理",ignore = false) |
||||||
|
public class TableInfoController { |
||||||
|
|
||||||
|
private final TableInfoService tableInfoService; |
||||||
|
|
||||||
|
@PostMapping("/save") |
||||||
|
@ApiOperation("保存数据库信息") |
||||||
|
@ApiOperationSupport(order = 1) |
||||||
|
public R save(@RequestBody @Valid TableInfoEntity req) { |
||||||
|
return R.data(tableInfoService.save(req)); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping("/update") |
||||||
|
@ApiOperation("编辑数据库信息") |
||||||
|
@ApiOperationSupport(order = 2) |
||||||
|
public R update(@RequestBody TableInfoEntity req) { |
||||||
|
return R.data(tableInfoService.updateById(req)); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/listPage") |
||||||
|
@ApiOperation("数据库信息列表查询") |
||||||
|
@ApiOperationSupport(order = 3) |
||||||
|
public R<IPage<TableInfoEntity>> listPage(Query query, TableInfoEntity req) { |
||||||
|
return R.data(tableInfoService.page(Condition.getPage(query),Condition.getQueryWrapper(req).lambda())); |
||||||
|
} |
||||||
|
|
||||||
|
@DeleteMapping("/removeByIds") |
||||||
|
@ApiOperation("删除数据库信息") |
||||||
|
@ApiOperationSupport(order = 4) |
||||||
|
public R removeByIds(@RequestParam @ApiParam("id,按逗号分隔") String ids) { |
||||||
|
return R.status(tableInfoService.removeByIds(Func.toLongList(",",ids))); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.entity; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
import org.springblade.core.tenant.mp.TenantEntity; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 15:45 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class DataRecordEntity extends TenantEntity { |
||||||
|
|
||||||
|
private String tableId; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.mp.support.QueryField; |
||||||
|
import org.springblade.core.mp.support.SqlCondition; |
||||||
|
import org.springblade.core.tenant.mp.TenantEntity; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 14:59 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("mysql_table_info") |
||||||
|
@EqualsAndHashCode |
||||||
|
@ApiModel(value = "数据库信息",description = "数据库信息") |
||||||
|
public class TableInfoEntity extends TenantEntity implements Serializable { |
||||||
|
|
||||||
|
@TableField("db_source") |
||||||
|
@ApiModelProperty("数据源") |
||||||
|
@NotBlank |
||||||
|
@QueryField(condition = SqlCondition.LIKE) |
||||||
|
private String datasource; |
||||||
|
|
||||||
|
@TableField("db_name") |
||||||
|
@ApiModelProperty("数据库") |
||||||
|
@NotBlank |
||||||
|
@QueryField(condition = SqlCondition.EQUAL) |
||||||
|
private String database; |
||||||
|
|
||||||
|
@ApiModelProperty("数据库表名") |
||||||
|
@NotBlank |
||||||
|
@QueryField(condition = SqlCondition.EQUAL) |
||||||
|
private String tableName; |
||||||
|
|
||||||
|
@ApiModelProperty("数据库表描述信息") |
||||||
|
@NotBlank |
||||||
|
@QueryField(condition = SqlCondition.LIKE) |
||||||
|
private String tableDesc; |
||||||
|
|
||||||
|
@ApiModelProperty("数据库表列信息") |
||||||
|
@NotBlank |
||||||
|
private String propDesc; |
||||||
|
|
||||||
|
@ApiModelProperty("举例") |
||||||
|
@NotBlank |
||||||
|
private String example; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.entity.TableInfoEntity; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 15:25 |
||||||
|
*/ |
||||||
|
public interface TableInfoMapper extends BaseMapper<TableInfoEntity> { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.service; |
||||||
|
|
||||||
|
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 09:29 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@RequiredArgsConstructor |
||||||
|
@Slf4j |
||||||
|
public class TableColumnService { |
||||||
|
|
||||||
|
private final DataSourceService dataSourceService; |
||||||
|
|
||||||
|
public List<Map<String,Object>> getDatabase() { |
||||||
|
String sql = "select distinct `table_schema` from `tables` where `table_schema` <> 'information_schema';"; |
||||||
|
return dataSourceService.queryListOnSpecificDataSource(sql,"information"); |
||||||
|
} |
||||||
|
|
||||||
|
public List<Map<String, Object>> getTables(String database) { |
||||||
|
String sql = "select distinct `table_name` from `tables` where `table_schema` = '" + database + "';"; |
||||||
|
return dataSourceService.queryListOnSpecificDataSource(sql,"information"); |
||||||
|
} |
||||||
|
|
||||||
|
public List<Map<String, Object>> getColumns(String database,String tableName) { |
||||||
|
String sql = "select `COLUMN_NAME` from `COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';"; |
||||||
|
return dataSourceService.queryListOnSpecificDataSource(sql,"information"); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package com.hnac.hzims.bigmodel.maintenance.service; |
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.entity.TableInfoEntity; |
||||||
|
import com.hnac.hzims.bigmodel.maintenance.mapper.TableInfoMapper; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author: huangxing |
||||||
|
* @Date: 2024/07/04 15:23 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Slf4j |
||||||
|
@DS("hznlm") |
||||||
|
public class TableInfoService extends BaseServiceImpl<TableInfoMapper, TableInfoEntity> { |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue