09040919:修改同步资产结构的逻辑

master
冷调 2024-09-04 09:19:50 +08:00
parent 51fdd1f6c1
commit c4a9063516
3 changed files with 26 additions and 4 deletions

View File

@ -30,8 +30,7 @@ public class DataValueController {
/**
* IDSQL
*
* @param basicId ID
* @param sql SQL
* @param dataValueModel IDsql
* @return DataValue{kltv}
*/
@PostMapping("/findTableValue")

View File

@ -258,6 +258,4 @@ public class TableInfoController {
}
return Result.success(tableInfoList);
}
}

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.source.domain.AssetAuthorization;
import com.muyu.source.domain.DataSource;
import com.muyu.source.domain.Structure;
import com.muyu.source.domain.TableInfo;
@ -46,6 +47,8 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
private TableInfoService tableInfoService;
@Resource
private StructureService structureService;
@Resource
private AssetAuthorizationService assetAuthorizationService;
private static final Long PARENTID = 0L;
private static final String DRIVERNAME = "com.mysql.cj.jdbc.Driver";
@ -160,11 +163,33 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
*/
@Override
public Integer syncAssetStructure(DataSource etlDataScore) {
try {
if (etlDataScore.getDataType().equals(MYSQL)) {
MysqlPool mysqlPool = new MysqlPool(etlDataScore);
mysqlPool.init();
Connection conn = mysqlPool.getConn();
TableInfo tableInfoServiceOne = tableInfoService.getOne(new LambdaQueryWrapper<>() {{
eq(TableInfo::getBasicId, etlDataScore.getId());
}});
//如果存在就删除
if(StringUtils.isNotNull(tableInfoServiceOne)){
List<TableInfo> list = tableInfoService.list(new LambdaQueryWrapper<>() {{
eq(TableInfo::getBasicId, etlDataScore.getId());
}});
list.forEach(tableInfo -> {
structureService.remove(new LambdaQueryWrapper<>(){{
eq(Structure::getTableId, tableInfo.getId());
}});
});
tableInfoService.remove(new LambdaQueryWrapper<>(){{
eq(TableInfo::getBasicId, etlDataScore.getId());
}});
assetAuthorizationService.remove(new LambdaQueryWrapper<>(){{
eq(AssetAuthorization::getTableId, tableInfoServiceOne.getId())
.eq(AssetAuthorization::getBasicId, etlDataScore.getId());
}});
}
TableInfo tableInfoInsert = TableInfo.builder()
.basicId(etlDataScore.getId())