feat():字典表查询

ruoyi_test
sunshine7058 2024-04-27 16:25:10 +08:00
parent cf374cfedd
commit 9f39f0a474
12 changed files with 107 additions and 140 deletions

View File

@ -38,11 +38,7 @@ public class DictData extends BaseEntity {
*/
private String dictValue;
/**
*
* Id
*/
private String dictType;
/**
* (0 1)
*/
private String status;
private Long dictTypeId;
}

View File

@ -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();
}
}

View File

@ -52,7 +52,7 @@ public class TableData {
/**
*
**/
private Long length;
private Integer length;
/**
*
**/

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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>