feat():字典表查询
parent
cf374cfedd
commit
9f39f0a474
|
@ -38,11 +38,7 @@ public class DictData extends BaseEntity {
|
|||
*/
|
||||
private String dictValue;
|
||||
/**
|
||||
* 字典类型
|
||||
* 字典类型Id
|
||||
*/
|
||||
private String dictType;
|
||||
/**
|
||||
* 状态 (0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
private Long dictTypeId;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.muyu.data.source.domain;
|
|||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.data.source.domain.resp.DictDataResp;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -26,8 +28,8 @@ public class DictType {
|
|||
/**
|
||||
* 字典主键
|
||||
*/
|
||||
@TableId(value = "dict_id", type = IdType.AUTO)
|
||||
private Long dictId;
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字典名称
|
||||
|
@ -38,7 +40,17 @@ public class DictType {
|
|||
*/
|
||||
private String dictType;
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
* 数据源Id
|
||||
*/
|
||||
private String status;
|
||||
private Long assetId;
|
||||
|
||||
public DictDataResp toDictDataResp (List<DictData> list){
|
||||
return DictDataResp.builder()
|
||||
.id(this.getId())
|
||||
.dictName(this.getDictName())
|
||||
.dictType(this.getDictType())
|
||||
.assetId(this.getAssetId())
|
||||
.dictData(list)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class TableData {
|
|||
/**
|
||||
* 长度
|
||||
**/
|
||||
private Long length;
|
||||
private Integer length;
|
||||
/**
|
||||
* 小数位
|
||||
**/
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package com.muyu.data.source.domain.resp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 字段描述
|
||||
*
|
||||
* @author HuFangMing
|
||||
* @ClassName: ColumnResp
|
||||
* @createTime: 2024/4/23 20:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ColumnResp {
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
**/
|
||||
private String columnName;
|
||||
/**
|
||||
* 字段描述
|
||||
**/
|
||||
private String columnComment;
|
||||
/**
|
||||
* 是否主键
|
||||
**/
|
||||
private String columnKey;
|
||||
/**
|
||||
* 字段类型
|
||||
**/
|
||||
private String columnType;
|
||||
/**
|
||||
* 长度
|
||||
**/
|
||||
private Long length;
|
||||
/**
|
||||
* 小数位
|
||||
**/
|
||||
private Long numericScale;
|
||||
/**
|
||||
* 是否为空
|
||||
**/
|
||||
private String isNullable;
|
||||
/**
|
||||
* 默认值
|
||||
**/
|
||||
private String columnDefault;
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.muyu.data.source.domain.resp;
|
||||
|
||||
import com.muyu.data.source.domain.DictData;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 字典类型数据
|
||||
*
|
||||
* @author HuFangMing
|
||||
* @ClassName: DictDataResp
|
||||
* @createTime: 2024/4/26 17:13
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DictDataResp {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 字典名称
|
||||
*/
|
||||
private String dictName;
|
||||
/**
|
||||
* 字典类型
|
||||
*/
|
||||
private String dictType;
|
||||
/**
|
||||
* 数据源编号
|
||||
*/
|
||||
private Long assetId;
|
||||
/**
|
||||
* 字典数据集合
|
||||
*/
|
||||
private List<DictData> dictData;
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.muyu.data.source.domain.resp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 数据库表结构
|
||||
*
|
||||
* @author HuFangMing
|
||||
* @ClassName: Table
|
||||
* @createTime: 2024/4/23 21:21
|
||||
*/
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Table {
|
||||
|
||||
/**
|
||||
* 表名称
|
||||
*/
|
||||
private String tableName;
|
||||
/**
|
||||
* 表注释
|
||||
*/
|
||||
private String tableComment;
|
||||
/**
|
||||
* 表数据条数
|
||||
*/
|
||||
private Long tableRows;
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
package com.muyu.data.source.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.service.DictTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -14,5 +19,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("/dictType")
|
||||
public class DictTypeController {
|
||||
|
||||
@Autowired
|
||||
private DictTypeService dictTypeService;
|
||||
@GetMapping("/getDictDataList/{id}")
|
||||
public Result getDictDataList(@PathVariable("id") Long id){
|
||||
return Result.success(dictTypeService.getDictDataList(id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
package com.muyu.data.source.mapper;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.data.source.domain.AssetDataSource;
|
||||
import com.muyu.data.source.domain.Children;
|
||||
import com.muyu.data.source.domain.TableData;
|
||||
import com.muyu.data.source.domain.resp.ColumnResp;
|
||||
import com.muyu.data.source.domain.resp.Table;
|
||||
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.data.source.domain.DataSource;
|
||||
|
@ -21,7 +14,4 @@ import org.apache.ibatis.annotations.Param;
|
|||
public interface DataSourceMapper extends BaseMapper<DataSource> {
|
||||
|
||||
|
||||
List<ColumnResp> selectColumn(@Param("databaseName") String databaseName, @Param("tableName") String tableName);
|
||||
|
||||
List<Table> selectTable(@Param("databaseName") String databaseName);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.muyu.data.source.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.data.source.domain.DictType;
|
||||
import com.muyu.data.source.domain.resp.DictDataResp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典类型业务层
|
||||
|
@ -14,4 +16,6 @@ import com.muyu.data.source.domain.DictType;
|
|||
|
||||
public interface DictTypeService extends IService<DictType> {
|
||||
|
||||
List<DictDataResp> getDictDataList(Long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.muyu.data.source.domain.DataSource;
|
|||
import com.muyu.data.source.domain.DatabaseType;
|
||||
import com.muyu.data.source.domain.TableData;
|
||||
import com.muyu.data.source.domain.req.ShowTableReq;
|
||||
import com.muyu.data.source.domain.resp.ColumnResp;
|
||||
import com.muyu.data.source.domain.resp.CountResp;
|
||||
import com.muyu.data.source.mapper.DataSourceMapper;
|
||||
import com.muyu.data.source.service.AssetDataSourceService;
|
||||
|
@ -26,10 +25,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -288,7 +284,7 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
.isPrimaryKey(columnKey.equals("PRI") ? "Y" : "N")
|
||||
.type(columnType)
|
||||
.mappingType(javaType)
|
||||
.length(Long.valueOf(length))
|
||||
.length(length)
|
||||
.decimalPlaces(Long.valueOf(numericScale))
|
||||
.isNull(isNullable.equals("YES") ? "Y" : "N")
|
||||
.defaultValue(columnDefault)
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package com.muyu.data.source.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.data.source.domain.DictData;
|
||||
import com.muyu.data.source.domain.DictType;
|
||||
import com.muyu.data.source.domain.resp.DictDataResp;
|
||||
import com.muyu.data.source.mapper.DictTypeMapper;
|
||||
import com.muyu.data.source.service.DictDataService;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 字典类型实现层
|
||||
|
@ -12,7 +19,27 @@ import com.muyu.data.source.mapper.DictTypeMapper;
|
|||
* @createTime: 2024/4/26 16:45
|
||||
*/
|
||||
|
||||
|
||||
@Service
|
||||
public class DictTypeServiceImpl extends ServiceImpl<DictTypeMapper, DictType> implements com.muyu.data.source.service.DictTypeService {
|
||||
|
||||
@Autowired
|
||||
private DictDataService dictDataService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<DictDataResp> getDictDataList(Long id) {
|
||||
List<DictType> dictTypeList = list(new LambdaQueryWrapper<>() {{
|
||||
eq(DictType::getAssetId, id);
|
||||
}});
|
||||
|
||||
List<DictDataResp> dictDataRespList = dictTypeList.stream().map(dictType -> {
|
||||
List<DictData> dictDataList = dictDataService.list(new LambdaQueryWrapper<>() {{
|
||||
eq(DictData::getDictTypeId, dictType.getId());
|
||||
}});
|
||||
return dictType.toDictDataResp(dictDataList);
|
||||
}).toList();
|
||||
|
||||
return dictDataRespList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,28 +34,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
|
||||
|
||||
<select id="selectTable" resultType="com.muyu.data.source.domain.resp.Table">
|
||||
select table_name,
|
||||
table_comment,
|
||||
table_rows
|
||||
from INFORMATION_SCHEMA.Tables
|
||||
where table_schema = #{databaseName}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<select id="selectColumn" resultType="com.muyu.data.source.domain.resp.ColumnResp">
|
||||
SELECT COLUMN_NAME as column_name,
|
||||
COLUMN_COMMENT as column_comment,
|
||||
column_key as column_key,
|
||||
DATA_TYPE as column_type,
|
||||
CHARACTER_MAXIMUM_LENGTH as length,
|
||||
NUMERIC_SCALE as numeric_scale,
|
||||
IS_NULLABLE as is_nullable,
|
||||
COLUMN_DEFAULT as column_default
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
where table_schema = #{databaseName}
|
||||
AND table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue