fix():表条数bug修复,字典表完善
parent
9f39f0a474
commit
97dc2cde0e
|
@ -124,6 +124,14 @@ public class DataSourceController extends BaseController {
|
||||||
public Result testConnection(@RequestBody DataSource dataSource) {
|
public Result testConnection(@RequestBody DataSource dataSource) {
|
||||||
return Result.success(dataSourceService.testConnection(dataSource));
|
return Result.success(dataSourceService.testConnection(dataSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改字段是否为字典
|
||||||
|
*/
|
||||||
|
@PostMapping("/updTableData")
|
||||||
|
public Result updateTableData(@RequestBody TableData tableData){
|
||||||
|
return Result.success(dataSourceService.updTableData(tableData));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 同步数据
|
* 同步数据
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package com.muyu.data.source.controller;
|
package com.muyu.data.source.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.data.source.domain.DictData;
|
||||||
|
import com.muyu.data.source.service.DictDataService;
|
||||||
|
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.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -14,4 +22,32 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
@RequestMapping("/dictData")
|
@RequestMapping("/dictData")
|
||||||
public class DictDataCpntroller {
|
public class DictDataCpntroller {
|
||||||
|
|
||||||
|
@RequestMapping("/dictData")
|
||||||
|
public class DictDataController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DictDataService dictDataService;
|
||||||
|
|
||||||
|
// 添加字典数据
|
||||||
|
@PostMapping("addDictData")
|
||||||
|
public Result addDictData(@RequestBody DictData dictData) {
|
||||||
|
dictDataService.save(dictData);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改字典数据
|
||||||
|
@PostMapping("editDictData")
|
||||||
|
public Result editDictData(@RequestBody DictData dictData) {
|
||||||
|
dictDataService.updateById(dictData);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典数据
|
||||||
|
@GetMapping("/delDictData/{id}")
|
||||||
|
public Result delDictData(@PathVariable("id") Long id) {
|
||||||
|
dictDataService.removeById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
package com.muyu.data.source.controller;
|
package com.muyu.data.source.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
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.service.DictDataService;
|
||||||
import com.muyu.data.source.service.DictTypeService;
|
import com.muyu.data.source.service.DictTypeService;
|
||||||
|
import java.util.List;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -21,8 +29,38 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
public class DictTypeController {
|
public class DictTypeController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DictTypeService dictTypeService;
|
private DictTypeService dictTypeService;
|
||||||
@GetMapping("/getDictDataList/{id}")
|
|
||||||
public Result getDictDataList(@PathVariable("id") Long id){
|
|
||||||
return Result.success(dictTypeService.getDictDataList(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DictDataService dictDataService;
|
||||||
|
|
||||||
|
// 查询字典类型数据
|
||||||
|
@GetMapping("/getDictDataList/{id}")
|
||||||
|
public Result<List<DictDataResp>> getDictDataList(@PathVariable("id") Long id) {
|
||||||
|
List<DictDataResp> dictDataRespList = dictTypeService.getDictDataList(id);
|
||||||
|
return Result.success(dictDataRespList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加字典类型
|
||||||
|
@PostMapping("/addDictType")
|
||||||
|
public Result addDictType(@RequestBody DictType dictType) {
|
||||||
|
dictTypeService.save(dictType);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典类型
|
||||||
|
@GetMapping("/delDictType/{id}")
|
||||||
|
public Result delDictType(@PathVariable("id") Long id) {
|
||||||
|
// 删除字典类型
|
||||||
|
dictTypeService.removeById(id);
|
||||||
|
// 删除相对应的字典数据
|
||||||
|
dictDataService.remove(new LambdaQueryWrapper<>(){{
|
||||||
|
eq(DictData::getDictTypeId,id);
|
||||||
|
}});
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.data.source.service;
|
package com.muyu.data.source.service;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.data.source.domain.AssetDataSource;
|
import com.muyu.data.source.domain.AssetDataSource;
|
||||||
import com.muyu.data.source.domain.Children;
|
import com.muyu.data.source.domain.Children;
|
||||||
import com.muyu.data.source.domain.TableData;
|
import com.muyu.data.source.domain.TableData;
|
||||||
|
@ -26,7 +27,7 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
|
|
||||||
Boolean testConnection(DataSource dataSource);
|
Boolean testConnection(DataSource dataSource);
|
||||||
|
|
||||||
Boolean syncConnection(DataSource dataSource);
|
Result syncConnection(DataSource dataSource);
|
||||||
|
|
||||||
List<AssetDataSource> getAssetList();
|
List<AssetDataSource> getAssetList();
|
||||||
|
|
||||||
|
@ -41,4 +42,6 @@ public interface DataSourceService extends IService<DataSource> {
|
||||||
List<TableData> selectTableData(Long id);
|
List<TableData> selectTableData(Long id);
|
||||||
|
|
||||||
CountResp getTableDataCount(Long id);
|
CountResp getTableDataCount(Long id);
|
||||||
|
|
||||||
|
Result updTableData(TableData tableData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.data.source.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.core.utils.ObjUtils;
|
import com.muyu.common.core.utils.ObjUtils;
|
||||||
import com.muyu.data.source.domain.AssetDataSource;
|
import com.muyu.data.source.domain.AssetDataSource;
|
||||||
import com.muyu.data.source.domain.Children;
|
import com.muyu.data.source.domain.Children;
|
||||||
|
@ -149,17 +150,23 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean syncConnection(DataSource dataSource) {
|
public Result syncConnection(DataSource dataSource) {
|
||||||
if ("mysql".equals(dataSource.getDataType())) {
|
AssetDataSource assetDataSourceOne=assetDataSourceService.getOne(new LambdaQueryWrapper<AssetDataSource>(){{
|
||||||
AssetDataSource assetDataSource = AssetDataSource.builder()
|
eq(AssetDataSource::getId, dataSource.getId());
|
||||||
.name(dataSource.getName())
|
}});
|
||||||
.systemName(dataSource.getSystemName())
|
if (assetDataSourceOne==null){
|
||||||
.databaseName(dataSource.getDatabaseName())
|
AssetDataSource assetDataSource=AssetDataSource.builder()
|
||||||
.type("dataSource")
|
.id(Long.valueOf(Math.toIntExact(dataSource.getId())))
|
||||||
.build();
|
.name(dataSource.getName())
|
||||||
return assetDataSourceService.save(assetDataSource);
|
.systemName(dataSource.getSystemName())
|
||||||
}
|
.databaseName(dataSource.getDatabaseName())
|
||||||
return false;
|
.type("dataSoure")
|
||||||
|
.build();
|
||||||
|
return Result.success(assetDataSourceService.save(assetDataSource));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return Result.error("数据源已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -201,12 +208,11 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
String tableName = rs.getString("TABLE_NAME");
|
String tableName = rs.getString("TABLE_NAME");
|
||||||
String tableComment = rs.getString("TABLE_COMMENT");
|
String tableComment = rs.getString("TABLE_COMMENT");
|
||||||
;
|
|
||||||
|
|
||||||
Children children = Children.builder()
|
Children children = Children.builder()
|
||||||
.name(tableName)
|
.name(tableName)
|
||||||
.annotation(tableComment)
|
.annotation(tableComment)
|
||||||
.dataTotal(Long.valueOf(rs.getRow()))
|
|
||||||
.type("dataTable")
|
.type("dataTable")
|
||||||
.build();
|
.build();
|
||||||
children.setAssetId(assetDataSource.getId());
|
children.setAssetId(assetDataSource.getId());
|
||||||
|
@ -220,6 +226,32 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
childrenService.list(new LambdaQueryWrapper<Children>(){{
|
||||||
|
eq(Children::getAssetId, assetDataSource.getId());
|
||||||
|
}});
|
||||||
|
try {
|
||||||
|
Class.forName(databaseType.getDriverManager());
|
||||||
|
Connection connection = DriverManager.getConnection(jdbcUrl, dataSource.getUser(), dataSource.getPassword());
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
childrenList.forEach(children -> {
|
||||||
|
String sql="select count(*) as tableNum from `" + dataSource.getDatabaseName() + "`." + children.getName();
|
||||||
|
try {
|
||||||
|
ResultSet rs = statement.executeQuery(sql);
|
||||||
|
while (rs.next()){
|
||||||
|
Long tableNum = rs.getLong("tableNum");
|
||||||
|
children.setDataTotal(tableNum);
|
||||||
|
childrenService.updateById(children);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//返回表描述
|
//返回表描述
|
||||||
|
@ -342,6 +374,11 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result updTableData(TableData tableData) {
|
||||||
|
return Result.success(tableDataService.updateById(tableData));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getJavaType(String driveClass, String url, String username, String password, String tableName,
|
public static String getJavaType(String driveClass, String url, String username, String password, String tableName,
|
||||||
String columnName) {
|
String columnName) {
|
||||||
|
|
Loading…
Reference in New Issue