feat:资产授权(初)
parent
646e4c2c41
commit
a8ab134f83
|
@ -1,7 +1,10 @@
|
|||
package com.muyu.etl.domain;
|
||||
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,6 +15,9 @@ import java.util.List;
|
|||
* @Date 2024/4/22 19:39
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AssetModel extends BaseEntity {
|
||||
private Long id;
|
||||
private Long dataAssetId;
|
||||
|
@ -26,6 +32,9 @@ public class AssetModel extends BaseEntity {
|
|||
private String defaultValue;
|
||||
private String isDict;
|
||||
private String dictKey;
|
||||
/**
|
||||
* 字典ID
|
||||
*/
|
||||
private Long dictionaryId;
|
||||
private List<DictionaryData> dictionaryDatas;
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.etl.domain.custom;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class Statistics {
|
||||
|
||||
/**
|
||||
* 数据资产ID
|
||||
*/
|
||||
private Long dataAsset;
|
||||
|
||||
/**
|
||||
* 资产模型ID
|
||||
*/
|
||||
private Long assetModel;
|
||||
|
||||
/**
|
||||
* 数据模型ID
|
||||
*/
|
||||
private Long dataModel;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.etl.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
public class AssetAccreditReq {
|
||||
|
||||
private List<Long> deptIds;
|
||||
private Long userId;
|
||||
private Long dataAssetId;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.etl.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder
|
||||
public class SourceAccreditReq {
|
||||
|
||||
private List<Long> deptIds;
|
||||
private Long userId;
|
||||
private Long dataSourceId;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.etl.mapper;
|
||||
|
||||
import com.muyu.etl.domain.AssetAccredit;
|
||||
import com.muyu.etl.domain.req.AssetAccreditReq;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AssetAccreditMapper {
|
||||
|
||||
List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit);
|
||||
|
||||
public AssetAccredit selectAssetAccreditById(Long id);
|
||||
|
||||
void insertAssetAccredit(AssetAccreditReq assetAccreditReq);
|
||||
|
||||
public int updateAssetAccredit(AssetAccredit assetAccredit);
|
||||
|
||||
public int deleteAssetAccreditByIds(Long[] ids);
|
||||
|
||||
public int deleteAssetAccreditById(Long id);
|
||||
|
||||
List<AssetAccredit> getAssetAccreditByDataAssetId(Long id);
|
||||
|
||||
void deleteAssetAccreditByDeptUser(@Param("deptIds") List<Long> deptIds, @Param("userId") Long userId, @Param("dataAssetId") Long dataAssetId);
|
||||
|
||||
List<AssetAccredit> getSourceAccreditByUserId(Long userId);
|
||||
|
||||
void insertBachAssetAccredit(@Param("assetAccredits") List<AssetAccredit> assetAccredits);
|
||||
|
||||
}
|
|
@ -68,4 +68,6 @@ public interface DataAssetMapper
|
|||
|
||||
List<DataAsset> selectById(Long id);
|
||||
|
||||
List<DataAsset> getDataAssetByAssetId(@Param("assetIds") List<Long> assetIds);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.etl.mapper;
|
||||
|
||||
import com.muyu.etl.domain.SourceAccredit;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SourceAccreditMapper {
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public SourceAccredit selectSourceAccreditById(Long id);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param sourceAccredit 【请填写功能名称】
|
||||
* @return 【请填写功能名称】集合
|
||||
*/
|
||||
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit);
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param sourceAccredit 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertSourceAccredit(SourceAccredit sourceAccredit);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param sourceAccredit 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSourceAccredit(SourceAccredit sourceAccredit);
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSourceAccreditById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除【请填写功能名称】
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSourceAccreditByIds(Long[] ids);
|
||||
|
||||
void deleteSourceAccreditBySourceIds(@Param("sourceIds") List<Long> sourceIds);
|
||||
|
||||
List<SourceAccredit> getSourceAccreditByDataSourceId(@Param("id") Long id);
|
||||
|
||||
List<SourceAccredit> getSourceAccreditByUserId(@Param("id") Long id);
|
||||
|
||||
void insertBatchSourceAccredit(@Param("sourceAccredits") List<SourceAccredit> sourceAccredits);
|
||||
|
||||
void deleteSourceAccreditByDeptUser(@Param("deptIds") List<Long> deptIds, @Param("userId") Long userId, @Param("dataSourceId") Long dataSourceId);
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.muyu.etl.service;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.etl.domain.AssetAccredit;
|
||||
import com.muyu.etl.domain.req.AssetAccreditReq;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface AssetAccreditService {
|
||||
|
||||
List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit);
|
||||
|
||||
AssetAccredit selectAssetAccreditById(Long id);
|
||||
|
||||
public Result insertAssetAccredit(AssetAccreditReq assetAccreditReq);
|
||||
|
||||
public int updateAssetAccredit(AssetAccredit assetAccredit);
|
||||
|
||||
public int deleteAssetAccreditByIds(Long[] ids);
|
||||
|
||||
public int deleteAssetAccreditById(Long id);
|
||||
|
||||
Result getAssetAccreditByDataAssetId(Long id);
|
||||
|
||||
Result deleteAssetAccreditByAssetId(AssetAccreditReq assetAccreditReq);
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.etl.service;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.etl.domain.DictionaryData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -54,4 +55,9 @@ public interface DictionaryDataService {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDictionaryDataById(Long id);
|
||||
|
||||
Result getDictionaryList(Long dataSourceId);
|
||||
|
||||
Result delDict(Long id);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package com.muyu.etl.service;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.etl.domain.SourceAccredit;
|
||||
import com.muyu.etl.domain.req.SourceAccreditReq;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Service接口
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2024-04-25
|
||||
*/
|
||||
@Service
|
||||
public interface SourceAccreditService {
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 【请填写功能名称】
|
||||
*/
|
||||
public SourceAccredit selectSourceAccreditById(Long id);
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param sourceAccredit 【请填写功能名称】
|
||||
* @return 【请填写功能名称】集合
|
||||
*/
|
||||
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit);
|
||||
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
* @param sourceAccreditReq 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public Result insertSourceAccredit(SourceAccreditReq sourceAccreditReq);
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
* @param sourceAccredit 【请填写功能名称】
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateSourceAccredit(SourceAccredit sourceAccredit);
|
||||
|
||||
/**
|
||||
* 批量删除【请填写功能名称】
|
||||
*
|
||||
* @param ids 需要删除的【请填写功能名称】主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSourceAccreditByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 删除【请填写功能名称】信息
|
||||
*
|
||||
* @param id 【请填写功能名称】主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteSourceAccreditById(Long id);
|
||||
|
||||
Result getSourceAccreditByDataSourceId(Long id);
|
||||
|
||||
Result deleteSourceAccreditBySourceIds(SourceAccreditReq sourceAccreditReq);
|
||||
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
package com.muyu.etl.service.impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.etl.domain.AssetAccredit;
|
||||
import com.muyu.etl.domain.model.AccreditModel;
|
||||
import com.muyu.etl.domain.req.AssetAccreditReq;
|
||||
import com.muyu.etl.mapper.AssetAccreditMapper;
|
||||
import com.muyu.etl.service.AssetAccreditService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @ClassName AssetAccreditServiceImpl
|
||||
* @Description 描述
|
||||
* @Author HaoRan.Zhang
|
||||
* @Date 2024/4/28 15:11
|
||||
*/
|
||||
@Service
|
||||
public class AssetAccreditServiceImpl implements AssetAccreditService {
|
||||
|
||||
@Autowired
|
||||
private AssetAccreditMapper assetAccreditMapper;
|
||||
|
||||
@Override
|
||||
public List<AssetAccredit> selectAssetAccreditList(AssetAccredit assetAccredit) {
|
||||
List<AssetAccredit> assetAccredits = assetAccreditMapper.selectAssetAccreditList(assetAccredit);
|
||||
return assetAccredits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssetAccredit selectAssetAccreditById(Long id) {
|
||||
AssetAccredit assetAccredit = assetAccreditMapper.selectAssetAccreditById(id);
|
||||
return assetAccredit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result insertAssetAccredit(AssetAccreditReq assetAccreditReq) {
|
||||
|
||||
// 根据资产ID删除资产授权信息
|
||||
deleteAssetAccreditByAssetId(assetAccreditReq);
|
||||
List<AssetAccredit> assetAccredits = new ArrayList<>();
|
||||
// 判断用户ID是否为空,不为空则为用户授权,为空则为部门授权
|
||||
if (assetAccreditReq.getUserId()!=null){
|
||||
// 为用户授权时,创建资产授权信息
|
||||
AssetAccredit assetAccredit = new AssetAccredit();
|
||||
assetAccredit.setDataAssetId(assetAccreditReq.getDataAssetId());
|
||||
assetAccredit.setUserId(assetAccreditReq.getUserId());
|
||||
assetAccredit.setCreateBy(SecurityUtils.getUsername());
|
||||
assetAccredit.setCreateTime(new Date());
|
||||
assetAccredits.add(assetAccredit);
|
||||
}else{
|
||||
// 为部门授权时,循环遍历部门ID,创建相应的资产授权信息
|
||||
assetAccreditReq.getDeptIds().stream()
|
||||
.map(deptId ->{
|
||||
AssetAccredit assetAccredit = new AssetAccredit();
|
||||
assetAccredit.setDataAssetId(assetAccreditReq.getDataAssetId());
|
||||
assetAccredit.setDeptId(deptId);
|
||||
assetAccredit.setCreateBy(SecurityUtils.getUsername());
|
||||
assetAccredit.setCreateTime(new Date());
|
||||
return assetAccredit;
|
||||
}).toList();
|
||||
}
|
||||
// 将资产授权信息插入数据库
|
||||
assetAccreditMapper.insertBachAssetAccredit(assetAccredits);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateAssetAccredit(AssetAccredit assetAccredit) {
|
||||
assetAccredit.setUpdateTime(DateUtils.getNowDate());
|
||||
return assetAccreditMapper.updateAssetAccredit(assetAccredit);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int deleteAssetAccreditByIds(Long[] ids) {
|
||||
return assetAccreditMapper.deleteAssetAccreditByIds(ids);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteAssetAccreditById(Long id) {
|
||||
return assetAccreditMapper.deleteAssetAccreditById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据资产ID获取资产授权信息。
|
||||
*
|
||||
* @param id 数据资产的ID,不能为空。
|
||||
* @return 返回一个Result对象,其中包含授权模型AccreditModel,包括部门授权ID集合和用户授权ID集合。
|
||||
*/
|
||||
@Override
|
||||
public Result getAssetAccreditByDataAssetId(Long id) {
|
||||
// 通过数据资产ID查询所有的资产授权信息
|
||||
List<AssetAccredit> assetAccreditList = assetAccreditMapper.getAssetAccreditByDataAssetId(id);
|
||||
|
||||
// 通过流操作取出部门Id集合,过滤掉空值
|
||||
List<Long> deptListIds = assetAccreditList.stream().map(AssetAccredit::getDeptId).filter(Objects::nonNull).toList();
|
||||
|
||||
// 通过流操作取出用户ID集合,过滤掉空值
|
||||
List<Long> userListIds = assetAccreditList.stream().map(AssetAccredit::getUserId).filter(Objects::nonNull).toList();
|
||||
|
||||
// 创建授权模型,并设置部门和用户授权ID集合
|
||||
AccreditModel accreditModel = new AccreditModel();
|
||||
accreditModel.setDeptAccreditModelIds(deptListIds);
|
||||
accreditModel.setUserAccreditModelIds(userListIds);
|
||||
|
||||
// 返回成功结果,包含授权模型
|
||||
return Result.success(accreditModel);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Result deleteAssetAccreditByAssetId(AssetAccreditReq assetAccreditReq)
|
||||
{
|
||||
/**
|
||||
* 根据用户或部门删除资产授权记录。
|
||||
* 如果用户ID非空,则根据用户ID和数据资产ID删除授权记录。
|
||||
* 如果用户ID空,则根据部门ID列表和数据资产ID删除授权记录。
|
||||
*
|
||||
* @param assetAccreditReq 包含用户ID、部门ID列表和数据资产ID的资产授权请求对象。
|
||||
* @return 返回操作成功的结果对象。
|
||||
*/
|
||||
if (assetAccreditReq.getUserId()!=null){
|
||||
// 根据用户ID和数据资产ID删除授权记录
|
||||
assetAccreditMapper.deleteAssetAccreditByDeptUser(null,assetAccreditReq.getUserId(),assetAccreditReq.getDataAssetId());
|
||||
}else{
|
||||
// 根据部门ID列表和数据资产ID删除授权记录
|
||||
assetAccreditMapper.deleteAssetAccreditByDeptUser(assetAccreditReq.getDeptIds(),null,assetAccreditReq.getDataAssetId());
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -4,11 +4,11 @@ package com.muyu.etl.service.impl;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysRole;
|
||||
import com.muyu.etl.domain.*;
|
||||
import com.muyu.etl.domain.Dictionary;
|
||||
import com.muyu.etl.mapper.AssetModelMapper;
|
||||
import com.muyu.etl.mapper.DataAssetMapper;
|
||||
import com.muyu.etl.mapper.DataSourceMapper;
|
||||
import com.muyu.etl.domain.custom.Statistics;
|
||||
import com.muyu.etl.mapper.*;
|
||||
import com.muyu.etl.service.DataSourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -38,6 +38,12 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
@Autowired
|
||||
private DictionaryServiceImpl dictionaryService;
|
||||
|
||||
@Autowired
|
||||
private SourceAccreditMapper sourceAccreditMapper;
|
||||
|
||||
@Autowired
|
||||
private AssetAccreditMapper assetAccreditMapper;
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
|
@ -58,8 +64,27 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
*/
|
||||
@Override
|
||||
public List<DataSource> selectDataSourceList(DataSource dataSource) {
|
||||
List<DataSource> dataSourceList = new ArrayList<>();
|
||||
List<DataSource> dataSources = dataSourceMapper.selectDataSourceList(dataSource);
|
||||
return dataSources;
|
||||
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
|
||||
if (roles.get(0).getRoleId()==1){
|
||||
dataSourceList = dataSources;
|
||||
}else{
|
||||
ArrayList<Long> longs = new ArrayList<>();
|
||||
List<Long> sourceIds = sourceAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream()
|
||||
.map(SourceAccredit::getDataSourceId)
|
||||
.filter(Objects::nonNull).toList();
|
||||
List<Long> asserId = assetAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream()
|
||||
.map(AssetAccredit::getDataAssetId)
|
||||
.filter(Objects::nonNull).toList();
|
||||
if (!asserId.isEmpty()){
|
||||
List<Long> longList = dataAssetMapper.getDataAssetByAssetId(asserId).stream().map(DataAsset::getDataSourceId).toList();
|
||||
longs.addAll(longList);
|
||||
}
|
||||
longs.addAll(sourceIds);
|
||||
dataSourceList = dataSources.stream().filter(dataSource1 -> longs.contains(dataSource1.getId())).toList();
|
||||
}
|
||||
return dataSourceList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,11 +116,6 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
{
|
||||
dataSource.setUpdateTime(DateUtils.getNowDate());
|
||||
dataSource.setUpdateBy(SecurityUtils.getUsername());
|
||||
if("Mysql".equals(dataSource.getType())){
|
||||
dataSource.setJdbcDriver("com.mysql.cj.jdbc.Driver");
|
||||
}else {
|
||||
dataSource.setJdbcDriver("org.postgresql.Driver");
|
||||
}
|
||||
return dataSourceMapper.updateDataSource(dataSource);
|
||||
}
|
||||
|
||||
|
@ -232,84 +252,56 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
* @return 资产模型列表,每个资产模型代表数据表中的一列
|
||||
*/
|
||||
public List<AssetModel> getTableAssets(DataSource dataSource,String tableName){
|
||||
// 根据数据源获取用户名和密码
|
||||
String username = dataSource.getUsername();
|
||||
String password = dataSource.getPassword();
|
||||
// 设置MySQL JDBC驱动类名和数据库连接URL
|
||||
String jdbcDriver="com.mysql.cj.jdbc.Driver";
|
||||
String url = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
|
||||
String url = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
Connection con = null;
|
||||
ArrayList<AssetModel> tableAssets = new ArrayList<>();
|
||||
Map<String, String> typeMap = getTypeMap(dataSource, tableName);
|
||||
try{
|
||||
// 加载JDBC驱动
|
||||
Class.forName(jdbcDriver);
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
// 建立数据库连接
|
||||
con = DriverManager.getConnection(url,username,password);
|
||||
con = DriverManager.getConnection(url,dataSource.getUsername(),dataSource.getPassword());
|
||||
}catch (SQLException | ClassNotFoundException exception){
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
try{
|
||||
// 预编译SQL语句,查询指定数据库和数据表的列信息
|
||||
PreparedStatement preparedStatement = con.prepareStatement("SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE,COLUMN_KEY,COLUMN_DEFAULT,COLUMN_COMMENT,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '"+dataSource.getDatabaseName()+"' AND TABLE_NAME = '"+tableName+"'");
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
// 遍历查询结果,创建并填充资产模型列表
|
||||
while (resultSet.next()){
|
||||
AssetModel assetModel = new AssetModel();
|
||||
assetModel.setComment(resultSet.getString("COLUMN_COMMENT"));
|
||||
assetModel.setName(resultSet.getString("COLUMN_NAME"));
|
||||
// int decimalPlaces = resultSet.getInt("DECIMAL_PLACES");
|
||||
// 设置列长度或精度
|
||||
if (resultSet.getString("CHARACTER_MAXIMUM_LENGTH")!=null){
|
||||
assetModel.setLength(resultSet.getString("CHARACTER_MAXIMUM_LENGTH"));
|
||||
}else if (resultSet.getString("NUMERIC_PRECISION")!=null){
|
||||
assetModel.setLength(resultSet.getString("NUMERIC_PRECISION"));
|
||||
}else{
|
||||
assetModel.setLength("-");
|
||||
// 获取数据库元数据
|
||||
DatabaseMetaData metaData = con.getMetaData();
|
||||
// 查询表的所有列信息
|
||||
ResultSet columnsRS = metaData.getColumns(dataSource.getDatabaseName(),dataSource.getModeName(), tableName, "%");
|
||||
// 查询表的主键列信息
|
||||
ResultSet primaryKeyRS = metaData.getPrimaryKeys(dataSource.getDatabaseName(), dataSource.getModeName(), tableName);
|
||||
String primaryKeyColumnName ="";// 保存主键列名
|
||||
// 遍历结果集,获取主键列名
|
||||
while (primaryKeyRS.next()) {
|
||||
primaryKeyColumnName = primaryKeyRS.getString("COLUMN_NAME");
|
||||
}
|
||||
if (resultSet.getString("NUMERIC_SCALE")!=null){
|
||||
assetModel.setDecimalPlaces(resultSet.getString("NUMERIC_SCALE"));
|
||||
}else{
|
||||
assetModel.setDecimalPlaces("0");
|
||||
// 遍历列信息,为每个列创建AssetModel实例,并添加到列表中
|
||||
while (columnsRS.next()) {
|
||||
// 根据数据库列信息构建AssetModel实例
|
||||
AssetModel build = AssetModel.builder()
|
||||
// 构建表字段信息
|
||||
.createBy(SecurityUtils.getUsername()) // 通过安全工具获取当前用户名
|
||||
.createTime(new Date()) // 设置创建时间为当前时间
|
||||
.length(String.valueOf(columnsRS.getInt("COLUMN_SIZE"))) // 设置字段长度
|
||||
.decimalPlaces(String.valueOf(columnsRS.getInt("DECIMAL_DIGITS"))) // 设置小数位数
|
||||
.name(columnsRS.getString("COLUMN_NAME")) // 设置字段名称
|
||||
.type(columnsRS.getString("TYPE_NAME")) // 设置字段类型
|
||||
.mappingType(typeMap.get(columnsRS.getString("COLUMN_NAME"))) // 设置映射类型
|
||||
.dictKey("") // 设置字典键,默认为空
|
||||
.isDict("") // 设置是否为字典字段,默认为空
|
||||
.isNull(columnsRS.getString("IS_NULLABLE").substring(0, 1)) // 设置字段是否可为空
|
||||
.isPrimaryKey(columnsRS.getString("COLUMN_NAME").equals(primaryKeyColumnName) ? "Y" : "N") // 设置字段是否为 primary key
|
||||
.comment(columnsRS.getString("REMARKS")==null || columnsRS.getString("REMARKS")=="" ? "-" : columnsRS.getString("REMARKS")) // 设置字段注释,若为空则默认为 "-"
|
||||
.defaultValue(columnsRS.getString("COLUMN_DEF")==null || columnsRS.getString("COLUMN_DEF")=="" ? "-":columnsRS.getString("COLUMN_DEF")) // 设置字段默认值,若为空则默认为 "-"
|
||||
.build(); // 构建并返回字段信息对象
|
||||
tableAssets.add(build);
|
||||
}
|
||||
|
||||
// 设置是否可为空
|
||||
if (resultSet.getString("IS_NULLABLE").equals("YES")){
|
||||
assetModel.setIsNull("Y");
|
||||
}else{
|
||||
assetModel.setIsNull("N");
|
||||
}
|
||||
// 设置是否有默认值
|
||||
if (resultSet.getString("COLUMN_DEFAULT")!=null){
|
||||
|
||||
assetModel.setDefaultValue(resultSet.getString("COLUMN_DEFAULT"));
|
||||
}else{
|
||||
assetModel.setDefaultValue("-");
|
||||
}
|
||||
// 初始化其他属性
|
||||
assetModel.setIsDict("");
|
||||
assetModel.setDictKey("");
|
||||
|
||||
assetModel.setType("s");
|
||||
// assetModel.setDecimalPlaces("0");
|
||||
|
||||
String dataType = mapDataTypeToJavaClass(resultSet.getString("DATA_TYPE"));
|
||||
assetModel.setMappingType(dataType);
|
||||
assetModel.setType(resultSet.getString("DATA_TYPE"));
|
||||
// 设置是否为主键
|
||||
if ("PRI".equals(resultSet.getString("COLUMN_KEY"))){
|
||||
assetModel.setIsPrimaryKey("Y");
|
||||
}else{
|
||||
assetModel.setIsPrimaryKey("N");
|
||||
}
|
||||
// 设置创建者和创建时间
|
||||
assetModel.setCreateBy(SecurityUtils.getUsername());
|
||||
assetModel.setCreateTime(new Date());
|
||||
tableAssets.add(assetModel);
|
||||
}
|
||||
|
||||
preparedStatement.close();
|
||||
columnsRS.close();
|
||||
primaryKeyRS.close();
|
||||
}catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -317,27 +309,33 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
}
|
||||
//获取表结构
|
||||
public AssetsModule getAssets(DataSource dataSource){
|
||||
String user = dataSource.getUsername();
|
||||
String password = dataSource.getPassword();
|
||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||
String jdbcUrl = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
Connection conn = null;
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
HashMap<String, String> map = new HashMap<>(); // 用于存储列名和对应的数据类型的映射关系
|
||||
// 通过dataSource和表名获取表资产信息
|
||||
List<AssetModel> tableAssets = getTableAssets(dataSource,dataSource.getTableName());
|
||||
try {
|
||||
Class.forName(jdbcDriver);
|
||||
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
// 加载JDBC驱动并获取数据库连接 从传过来的信息里获取驱动
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
conn = DriverManager.getConnection(jdbcUrl, dataSource.getUsername(), dataSource.getPassword());
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
// 准备查询语句并执行
|
||||
PreparedStatement pst = conn.prepareStatement("select * from "+dataSource.getTableName()+" where 1=1");
|
||||
ResultSet resultSet = pst.executeQuery();
|
||||
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||
|
||||
// 遍历结果集元数据,构建列名和数据类型的映射关系
|
||||
for(int i = 1; i <= rsd.getColumnCount(); i++) {
|
||||
String substring = rsd.getColumnClassName(i).substring(rsd.getColumnClassName(i).indexOf("java.lang.") + 10);
|
||||
map.put(rsd.getColumnName(i),substring);
|
||||
}
|
||||
|
||||
// 根据映射关系,设置AssetModel的类型
|
||||
for (AssetModel tableAsset : tableAssets) {
|
||||
tableAsset.setType(map.get(tableAsset.getName()));
|
||||
}
|
||||
|
@ -346,6 +344,7 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 创建AssetsModule并设置结构信息,然后返回
|
||||
AssetsModule assetsModule = new AssetsModule();
|
||||
assetsModule.setStructure(map);
|
||||
return assetsModule;
|
||||
|
@ -353,37 +352,37 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
|
||||
//获取数据表结构
|
||||
public AssetsModule getStructure(DataSource dataSource){
|
||||
String user = dataSource.getUsername();
|
||||
String password = dataSource.getPassword();
|
||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||
String jdbcUrl = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
String jdbcUrl = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
Connection conn = null;
|
||||
List<Map<String, VTClass>> kvtList = new ArrayList<>();
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
try {
|
||||
Class.forName(jdbcDriver);
|
||||
conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
// 加载数据库驱动并建立连接
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
conn = DriverManager.getConnection(jdbcUrl,dataSource.getUsername(),dataSource.getPassword());
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
// 准备语句并执行查询
|
||||
PreparedStatement pst = conn.prepareStatement(dataSource.getSql());
|
||||
ResultSet resultSet = pst.executeQuery();
|
||||
ResultSetMetaData rsd = resultSet.getMetaData();
|
||||
|
||||
// 处理查询结果,生成列名与java类型的映射
|
||||
for(int i = 1; i <= rsd.getColumnCount(); i++) {
|
||||
String substring = rsd.getColumnClassName(i).substring(rsd.getColumnClassName(i).indexOf("java.lang.") + 10);
|
||||
System.out.print("java类型:"+substring);
|
||||
System.out.print(" 数据库类型:"+rsd.getColumnTypeName(i));
|
||||
System.out.print(" 字段名称:"+rsd.getColumnName(i));
|
||||
System.out.println();
|
||||
map.put(rsd.getColumnName(i),substring);
|
||||
}
|
||||
|
||||
int columnCount = rsd.getColumnCount();
|
||||
// 遍历每一行的数据
|
||||
|
||||
// 遍历查询结果,填充数据到list中
|
||||
while (resultSet.next()){
|
||||
Map<String, VTClass> stringVTClassHashMap = new HashMap<>();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
// 根据列索引或列名获取数据
|
||||
String columnName = rsd.getColumnName(i);
|
||||
String type = map.get(columnName);
|
||||
Object value = resultSet.getObject(i);
|
||||
|
@ -399,6 +398,8 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 构建并返回AssetsModule对象
|
||||
AssetsModule assetsModule = new AssetsModule();
|
||||
assetsModule.setKvtList(kvtList);
|
||||
assetsModule.setStructure(map);
|
||||
|
@ -424,54 +425,90 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
//数据同步
|
||||
@Override
|
||||
public Result synchronization(DataSource dataSource) {
|
||||
List<DataSource> dataSources = dataSourceMapper.selectId(dataSource.getId());
|
||||
List<Long> longs = dataSources.stream().map(DataSource::getId).toList();
|
||||
System.out.println("数据源的ID"+longs);
|
||||
|
||||
ArrayList<Long> longArrayList = new ArrayList<>();
|
||||
|
||||
for (Long aLong : longs) {
|
||||
List<DataSource> dataSources = dataSourceMapper.selectId(dataSource.getId()); // 根据数据源ID查询所有相关数据源
|
||||
List<Long> longList = dataSources.stream().map(DataSource::getId).toList(); // 提取数据源ID列表
|
||||
ArrayList<Long> l = new ArrayList<>();
|
||||
for (Long aLong : longList) {
|
||||
// 对于每个数据源ID,查询其关联的所有数据模型
|
||||
List<DataAsset> dataAssets = dataAssetMapper.selectById(aLong);
|
||||
List<Long> longList = dataAssets.stream().map(DataAsset::getId).toList();
|
||||
System.out.println("数据模型的Id"+longList);
|
||||
longArrayList.addAll(longList);
|
||||
// 提取数据模型ID列表
|
||||
List<Long> longs = dataAssets.stream().map(DataAsset::getId).toList();
|
||||
System.out.println("数据模型的Id" + longs); // 打印数据模型ID列表
|
||||
l.addAll(longs); // 将数据模型ID列表添加到总列表中
|
||||
}
|
||||
|
||||
Long[] longs2 = longArrayList.toArray(Long[]::new);
|
||||
if (longs2.length != 0){
|
||||
assetModelMapper.clearTable1(longs2);
|
||||
|
||||
Long[] dataAssetIdList = l.toArray(Long[]::new);
|
||||
if (dataAssetIdList.length != 0){
|
||||
assetModelMapper.clearTable1(dataAssetIdList);
|
||||
}
|
||||
String username = dataSource.getUsername();
|
||||
String password = dataSource.getPassword();
|
||||
String jdbcDriver = "com.mysql.cj.jdbc.Driver";
|
||||
String databaseName=dataSource.getDatabaseName();
|
||||
String url = "jdbc:mysql://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
String url = "jdbc:"+dataSource.getType().toLowerCase()+"://"+dataSource.getLinkAddress()+":"+dataSource.getPort()+"/"+dataSource.getDatabaseName();
|
||||
Connection conn= null;
|
||||
String sql;
|
||||
// 创建一个空的数据资产列表
|
||||
ArrayList<DataAsset> dataAssets = new ArrayList<>();
|
||||
try{
|
||||
// 加载 JDBC 驱动
|
||||
Class.forName(jdbcDriver);
|
||||
Class.forName(dataSource.getJdbcDriver());
|
||||
// 获取数据库连接
|
||||
conn = DriverManager.getConnection(url, username, password);
|
||||
// 构造 SQL 查询语句,用于从 INFORMATION_SCHEMA.TABLES 表中获取表名、表注释和表行数
|
||||
String sql="SELECT TABLE_NAME t_name,TABLE_COMMENT table_comment,TABLE_ROWS table_rows,(SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '"+dataSource.getDatabaseName()+"' and TABLE_NAME=t_name) fields FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='"+dataSource.getDatabaseName()+"'";
|
||||
// 准备 SQL 语句并执行查询
|
||||
conn = DriverManager.getConnection(url, dataSource.getUsername(), dataSource.getPassword());
|
||||
if (dataSource.getType().equals("MySql")){
|
||||
sql="SELECT TABLE_NAME t_name,TABLE_COMMENT table_comment,TABLE_ROWS table_rows,(SELECT count(*) FROM INFORMATION_SCHEMA.columns WHERE TABLE_SCHEMA = '"+dataSource.getDatabaseName()+"' and TABLE_NAME=t_name) fields FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='"+dataSource.getDatabaseName()+"'";
|
||||
}else{
|
||||
sql="SELECT \n" +
|
||||
" c.relname AS t_name,\n" +
|
||||
" pgd.description AS table_comment,\n" +
|
||||
" COUNT(col.column_name) AS fields,\n" +
|
||||
" c.reltuples AS table_rows\n" +
|
||||
"FROM \n" +
|
||||
" pg_catalog.pg_class c\n" +
|
||||
"LEFT JOIN \n" +
|
||||
" pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" +
|
||||
"LEFT JOIN \n" +
|
||||
" pg_catalog.pg_description pgd ON pgd.objoid = c.oid\n" +
|
||||
"LEFT JOIN \n" +
|
||||
" information_schema.columns col ON c.relname = col.table_name AND n.nspname = col.table_schema\n" +
|
||||
"WHERE \n" +
|
||||
" n.nspname = '"+dataSource.getModeName()+"' \n" +
|
||||
"AND \n" +
|
||||
" c.relkind = 'r' \n" +
|
||||
"GROUP BY \n" +
|
||||
" c.relname, pgd.description, c.reltuples";
|
||||
}
|
||||
// 准备 SQL 语句并执行查询 根据传过来的参数进行查询 可重用
|
||||
PreparedStatement preparedStatement = conn.prepareStatement(sql);
|
||||
// 使用executeQuery 进行查询 以结果集的形式返回
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
// 遍历结果集,将每条记录转换为DataAsset对象,并添加到数据列表中
|
||||
while (resultSet.next()){
|
||||
dataAssets.add(new DataAsset().dataAssetBuild(dataSource,resultSet));
|
||||
DataAsset dataAsset = new DataAsset();
|
||||
// 设置表名
|
||||
dataAsset.setTableName(resultSet.getString("t_name"));
|
||||
// 设置表注释
|
||||
dataAsset.setTableComment(resultSet.getString("table_comment"));
|
||||
// 设置表行数
|
||||
dataAsset.setTableCount(resultSet.getLong("table_rows"));
|
||||
// 设置字段数
|
||||
dataAsset.setFields(resultSet.getLong("fields"));
|
||||
// 设置数据源ID
|
||||
dataAsset.setDataSourceId(dataSource.getId());
|
||||
// 设置创建者为当前登录用户
|
||||
dataAsset.setCreateBy(SecurityUtils.getUsername());
|
||||
// 设置创建时间为当前时间
|
||||
dataAsset.setCreateTime(new Date());
|
||||
// 将DataAsset对象添加到数据列表中
|
||||
dataAssets.add(dataAsset);
|
||||
}
|
||||
|
||||
// 将 DataAsset 对象的 ID 提取出来并转换为 Long 数组
|
||||
int i = dataSourceMapper.clearTable(new Long[]{dataSource.getId()});
|
||||
dataSourceMapper.batchAdd(dataAssets);
|
||||
Long id = dataSource.getId(); // 从数据源获取ID
|
||||
Long[] a = new Long[1];
|
||||
a[0] = id; // 将ID存入数组
|
||||
int i = dataSourceMapper.clearTable(a); // 使用ID清理相关表
|
||||
dataSourceMapper.batchAdd(dataAssets); // 批量添加数据资产
|
||||
// 遍历每个数据资产,为其添加对应的资产模型
|
||||
for (DataAsset dataAsset : dataAssets) {
|
||||
List<AssetModel> tableAssets = getTableAssets(dataSource, dataAsset.getTableName());
|
||||
tableAssets.stream().forEach(assetModel -> assetModel.setDataAssetId(dataAsset.getId()));
|
||||
assetModelMapper.batchInsert(tableAssets);
|
||||
List<AssetModel> tableAssets = getTableAssets(dataSource, dataAsset.getTableName()); // 获取表资产
|
||||
tableAssets.stream().forEach(assetModel -> assetModel.setDataAssetId(dataAsset.getId())); // 关联数据资产ID
|
||||
assetModelMapper.batchInsert(tableAssets); // 批量插入资产模型
|
||||
}
|
||||
}catch (SQLException | ClassNotFoundException exception){
|
||||
throw new RuntimeException(exception);
|
||||
|
@ -481,21 +518,37 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
|
||||
@Override
|
||||
public Result dataAssetList(DataSource dataSource) {
|
||||
// 创建一个新的DataAsset实例,并设置其数据源ID
|
||||
DataAsset dataAsset = new DataAsset();
|
||||
dataAsset.setDataSourceId(dataSource.getId());
|
||||
List<DataAsset> dataAssetList = new ArrayList<>();
|
||||
// 根据数据源ID查询数据资产列表
|
||||
List<DataAsset> dataAssets = dataAssetMapper.selectDataAssetList(dataAsset);
|
||||
return Result.success(dataAssets);
|
||||
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
|
||||
if (roles.get(0).getRoleId() ==1){
|
||||
dataAssetList = dataAssets;
|
||||
}else{
|
||||
List<Long> assetIds = assetAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream().map(AssetAccredit::getDataAssetId).filter(Objects::nonNull).toList();
|
||||
dataAssets = dataAssets.stream().filter(dataAsset1 -> assetIds.contains(dataAsset1.getId())).toList();
|
||||
}
|
||||
// 返回查询结果的成功响应
|
||||
return Result.success(dataAssetList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result assetModelList(DataAsset dataAsset) {
|
||||
// 创建资产模型实例,并设置数据资产ID
|
||||
AssetModel assetModel = new AssetModel();
|
||||
assetModel.setDataAssetId(dataAsset.getId());
|
||||
// 根据资产模型查询资产模型列表
|
||||
List<AssetModel> assetModels = assetModelMapper.selectAssetModelList(assetModel);
|
||||
// 将资产模型列表中的字典键提取为字符串列表
|
||||
List<String> strings = assetModels.stream().map(AssetModel::getDictKey).toList();
|
||||
// 如果字符串列表不为空,则查询相应的字典数据
|
||||
if (!strings.isEmpty()){
|
||||
Result<List<Dictionary>> dictionaryDataList = dictionaryService.getDictionaryDataList(strings);
|
||||
List<Dictionary> data = dictionaryDataList.getData();
|
||||
// 为每个资产模型匹配并设置字典数据
|
||||
assetModels.stream().forEach(assetModel1 -> {
|
||||
data.stream().forEach(dictionary -> {
|
||||
if (assetModel1.getDictKey().equals(dictionary.getDictionaryKey())) {
|
||||
|
@ -503,8 +556,8 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
// 返回成功的查询结果,包含资产模型列表
|
||||
return Result.success(assetModels);
|
||||
}
|
||||
|
||||
|
@ -516,28 +569,46 @@ public class DataSourceServiceImpl implements DataSourceService{
|
|||
* @return Result 包含统计信息的结果对象,其中成功时携带Statistics对象,包含数据资产数量、数据模型数量和资产模型数量。
|
||||
*/
|
||||
public Result statisticsInfo() {
|
||||
long datasum;
|
||||
long assetssum;
|
||||
List<DataSource> dataSourcesList = new ArrayList<>();
|
||||
// 查询所有的数据源
|
||||
List<DataSource> dataSources = dataSourceMapper.selectDataSourceList(new DataSource());
|
||||
// 查出数据源ID列表
|
||||
List<Long> longs = dataSources.stream().map(s -> s.getId()).toList();
|
||||
// 根据数据源ID列表查询
|
||||
List<DataAsset> dataAssets = dataSourceMapper.selectDataAssetBachId(longs);
|
||||
// 初始化统计信息对象
|
||||
Statistics statistics = new Statistics();
|
||||
// 统计数据资产的数量
|
||||
statistics.setDataAsset((long) longs.size());
|
||||
System.out.println(statistics.getDataAsset());
|
||||
List<SysRole> roles = SecurityUtils.getLoginUser().getSysUser().getRoles();
|
||||
List<Long> assetIds;
|
||||
if (roles.get(0).getRoleId()==1){
|
||||
assetIds = new ArrayList<>();
|
||||
dataSourcesList = dataSources;
|
||||
}else{
|
||||
ArrayList<Long> longs1 = new ArrayList<>();
|
||||
List<Long> sourceIds = sourceAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream().map(SourceAccredit::getDataSourceId).filter(Objects::nonNull).toList();
|
||||
assetIds = assetAccreditMapper.getSourceAccreditByUserId(SecurityUtils.getUserId()).stream().map(AssetAccredit::getDataAssetId).filter(Objects::nonNull).toList();
|
||||
if (!assetIds.isEmpty()){
|
||||
List<Long> longs = dataAssetMapper.getDataAssetByAssetId(assetIds).stream().map(DataAsset::getDataSourceId).toList();
|
||||
longs1.addAll(longs);
|
||||
}
|
||||
longs1.addAll(sourceIds);
|
||||
dataSourcesList = dataSources.stream().filter(dataSource -> longs1.contains(dataSource.getId())).toList();
|
||||
}
|
||||
List<Long> longList = dataSourcesList.stream().map(dataSource -> dataSource.getId()).toList();
|
||||
com.muyu.etl.domain.custom.Statistics statistics= new Statistics();
|
||||
if (!longList.isEmpty()){
|
||||
List<DataAsset> dataAssetByAssetId = dataAssetMapper.getDataAssetByAssetId(longList);
|
||||
if (roles.get(0).getRoleId()!=1){
|
||||
dataSourcesList = dataSourcesList.stream().filter(dataSource -> longList.contains(dataSource.getId())).toList();
|
||||
}
|
||||
statistics.setDataAsset(Long.valueOf(dataSourcesList.size()));
|
||||
long sum;
|
||||
long sum1;
|
||||
// 统计所有数据资产的字段总数
|
||||
datasum = dataAssets.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getFields())).sum();
|
||||
sum = dataAssetByAssetId.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getFields())).sum();
|
||||
// 统计所有数据资产的表数量
|
||||
assetssum = dataAssets.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getTableCount())).sum();
|
||||
System.out.println("数据"+datasum);
|
||||
System.out.println("资产"+assetssum);
|
||||
sum1 = dataAssetByAssetId.stream().mapToLong(dataAsset -> Long.valueOf(dataAsset.getTableCount())).sum();
|
||||
// 设置数据模型数量和资产模型数量
|
||||
statistics.setDataModel(datasum);
|
||||
statistics.setAssetModel(assetssum);
|
||||
statistics.setDataModel(sum);
|
||||
statistics.setAssetModel(sum1);
|
||||
}else{
|
||||
statistics.setDataAsset(0L);
|
||||
statistics.setAssetModel(0L);
|
||||
}
|
||||
// 返回携带统计信息的成功结果
|
||||
return Result.success(statistics);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.muyu.etl.service.impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.etl.domain.Dictionary;
|
||||
import com.muyu.etl.domain.DictionaryData;
|
||||
import com.muyu.etl.mapper.AssetModelMapper;
|
||||
import com.muyu.etl.mapper.DictionaryDataMapper;
|
||||
import com.muyu.etl.mapper.DictionaryMapper;
|
||||
import com.muyu.etl.service.AssetModelService;
|
||||
import com.muyu.etl.service.DictionaryDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -12,9 +17,16 @@ import java.util.List;
|
|||
|
||||
@Service
|
||||
public class DictionaryDataServiceImpl implements DictionaryDataService {
|
||||
|
||||
@Autowired
|
||||
private DictionaryDataMapper dictionaryDataMapper;
|
||||
|
||||
@Autowired
|
||||
private DictionaryMapper dictionaryMapper;
|
||||
|
||||
@Autowired
|
||||
private AssetModelMapper assetModelMapper;
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
|
@ -90,4 +102,66 @@ public class DictionaryDataServiceImpl implements DictionaryDataService {
|
|||
{
|
||||
return dictionaryDataMapper.deleteDictionaryDataById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据源对应的字典列表。
|
||||
*
|
||||
* @param dataSourceId 数据源ID,用于查询与之相关的字典列表。
|
||||
* @return 返回字典列表的成功结果,其中包含了字典及其相关数据。
|
||||
*/
|
||||
@Override
|
||||
public Result getDictionaryList(Long dataSourceId) {
|
||||
// 从字典mapper中查询指定数据源ID的字典列表
|
||||
List<Dictionary> dictionaryList = dictionaryMapper.getDictionaryList(dataSourceId);
|
||||
if (!dictionaryList.isEmpty()){
|
||||
// 将字典列表中每个字典的ID提取出来,形成一个新的ID列表
|
||||
List<Long> longs = dictionaryList.stream()
|
||||
.map(Dictionary::getId).toList();
|
||||
// 根据提取出的ID列表,从字典数据mapper中查询相应的字典数据列表
|
||||
List<DictionaryData> dictionaryDataList = dictionaryDataMapper.getDictionaryDataList(longs);
|
||||
// 为每个字典设置其对应的字典数据列表
|
||||
dictionaryList.stream()
|
||||
.forEach(dictionary->{
|
||||
// 过滤出与当前字典ID匹配的字典数据,并为当前字典设置这个列表
|
||||
dictionaryDataList.stream().filter(dictionaryData -> dictionaryData.getDictionaryId().equals(dictionary.getId()) ).toList();
|
||||
dictionary.setDictionaryDataList(dictionaryDataList);
|
||||
});
|
||||
}
|
||||
// 返回成功结果,包含处理后的字典列表
|
||||
return Result.success(dictionaryList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result delDict(Long id) {
|
||||
dictionaryDataMapper.deleteDictionaryDataBy(id);
|
||||
dictionaryMapper.deleteDictionaryById(id);
|
||||
assetModelMapper.updateAssetModelDiction(id);
|
||||
return Result.success();
|
||||
}
|
||||
/**
|
||||
* 获取字典数据列表。
|
||||
*
|
||||
* @param string 一个字符串列表,代表需要查询的字典项的标识符。
|
||||
* @return 返回一个结果对象,其中包含了查询到的字典数据列表。如果查询成功,则结果对象的状态为成功,并附带字典数据列表;如果查询失败,则结果对象的状态为失败,并可能包含错误信息。
|
||||
*/
|
||||
public Result getDictionaryDataList(List<String> string){
|
||||
// 通过字符串列表查询字典数据列表
|
||||
List<Dictionary> dictionaryDataList = dictionaryMapper.getDictionaryDataList(string);
|
||||
if (!dictionaryDataList.isEmpty()){
|
||||
// 将字典数据列表中的每个字典项的ID提取出来,形成一个新的ID列表
|
||||
List<Long> longs = dictionaryDataList.stream()
|
||||
.map(Dictionary::getId).toList();
|
||||
// 根据ID列表查询相应的字典详细数据列表
|
||||
List<DictionaryData> dictionaryDataList1 = dictionaryDataMapper.getDictionaryDataList(longs);
|
||||
// 为每个字典项设置其详细的字典数据列表
|
||||
dictionaryDataList.stream()
|
||||
.forEach(dictionary -> {
|
||||
dictionaryDataList1.stream().filter(dictionaryData -> dictionaryData.getDictionaryId() ==(dictionary.getId())).toList();
|
||||
dictionary.setDictionaryDataList(dictionaryDataList1);
|
||||
});
|
||||
}
|
||||
// 返回成功结果,包含处理后的字典数据列表
|
||||
return Result.success(dictionaryDataList);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package com.muyu.etl.service.impl;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.etl.domain.SourceAccredit;
|
||||
import com.muyu.etl.domain.model.AccreditModel;
|
||||
import com.muyu.etl.domain.req.SourceAccreditReq;
|
||||
import com.muyu.etl.mapper.SourceAccreditMapper;
|
||||
import com.muyu.etl.service.SourceAccreditService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @ClassName SourceAccreditServiceImpl
|
||||
* @Description 描述
|
||||
* @Author HaoRan.Zhang
|
||||
* @Date 2024/4/29 15:06
|
||||
*/
|
||||
@Service
|
||||
public class SourceAccreditServiceImpl implements SourceAccreditService {
|
||||
@Autowired
|
||||
private SourceAccreditMapper sourceAccreditMapper;
|
||||
@Override
|
||||
public SourceAccredit selectSourceAccreditById(Long id) {
|
||||
SourceAccredit sourceAccredit = sourceAccreditMapper.selectSourceAccreditById(id);
|
||||
return sourceAccredit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SourceAccredit> selectSourceAccreditList(SourceAccredit sourceAccredit) {
|
||||
List<SourceAccredit> sourceAccredits = sourceAccreditMapper.selectSourceAccreditList(sourceAccredit);
|
||||
return sourceAccredits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result insertSourceAccredit(SourceAccreditReq sourceAccreditReq) {
|
||||
deleteSourceAccreditBySourceIds(sourceAccreditReq);
|
||||
List<SourceAccredit> sourceAccredits = new ArrayList<>();
|
||||
if (sourceAccreditReq.getUserId()!=null){
|
||||
SourceAccredit sourceAccredit = new SourceAccredit();
|
||||
sourceAccredit.setDataSourceId(sourceAccreditReq.getDataSourceId());
|
||||
sourceAccredit.setUserId(sourceAccreditReq.getUserId());
|
||||
sourceAccredit.setCreateBy(SecurityUtils.getUsername());
|
||||
sourceAccredit.setCreateTime(new Date());
|
||||
sourceAccredits.add(sourceAccredit);
|
||||
}else{
|
||||
sourceAccredits = sourceAccreditReq.getDeptIds().stream()
|
||||
.map(deptId -> {
|
||||
SourceAccredit sourceAccredit = new SourceAccredit();
|
||||
sourceAccredit.setDataSourceId(sourceAccreditReq.getDataSourceId());
|
||||
sourceAccredit.setDeptId(deptId);
|
||||
sourceAccredit.setCreateBy(SecurityUtils.getUsername());
|
||||
sourceAccredit.setCreateTime(new Date());
|
||||
return sourceAccredit;
|
||||
}).toList();
|
||||
}
|
||||
sourceAccreditMapper.insertBatchSourceAccredit(sourceAccredits);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSourceAccredit(SourceAccredit sourceAccredit) {
|
||||
sourceAccredit.setUpdateTime(DateUtils.getNowDate());
|
||||
return sourceAccreditMapper.updateSourceAccredit(sourceAccredit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteSourceAccreditByIds(Long[] ids) {
|
||||
return sourceAccreditMapper.deleteSourceAccreditByIds(ids);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteSourceAccreditById(Long id) {
|
||||
return sourceAccreditMapper.deleteSourceAccreditById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getSourceAccreditByDataSourceId(Long id) {
|
||||
List<SourceAccredit> sourceAccreditList = sourceAccreditMapper.getSourceAccreditByDataSourceId(id);
|
||||
List<Long> userAccreditIds = sourceAccreditList.stream().map(SourceAccredit::getUserId).filter(Objects::nonNull).toList();
|
||||
List<Long> deptAccreditIds = sourceAccreditList.stream().map(SourceAccredit::getDeptId).filter(Objects::nonNull).toList();
|
||||
AccreditModel accreditModel = new AccreditModel();
|
||||
accreditModel.setDeptAccreditModelIds(deptAccreditIds);
|
||||
accreditModel.setUserAccreditModelIds(userAccreditIds);
|
||||
return Result.success(accreditModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deleteSourceAccreditBySourceIds(SourceAccreditReq sourceAccreditReq) {
|
||||
if (sourceAccreditReq.getUserId()!=null){
|
||||
sourceAccreditMapper.deleteSourceAccreditByDeptUser(null,sourceAccreditReq.getUserId(),sourceAccreditReq.getDataSourceId());
|
||||
}else{
|
||||
sourceAccreditMapper.deleteSourceAccreditByDeptUser(sourceAccreditReq.getDeptIds(),null,sourceAccreditReq.getDataSourceId());
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.etl.mapper.AssetAccreditMapper">
|
||||
|
||||
<resultMap type="com.muyu.etl.domain.AssetAccredit" id="AssetAccreditResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="dataAssetId" column="data_asset_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAssetAccreditVo">
|
||||
select id, dept_id, data_asset_id, user_id, remark, create_by, create_time, update_by, update_time from asset_accredit
|
||||
</sql>
|
||||
|
||||
<select id="selectAssetAccreditList" parameterType="com.muyu.etl.domain.AssetAccredit" resultMap="AssetAccreditResult">
|
||||
<include refid="selectAssetAccreditVo"/>
|
||||
<where>
|
||||
<if test="deptId != null "> and dept_id = #{deptId}</if>
|
||||
<if test="dataAssetId != null "> and data_asset_id = #{dataAssetId}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectAssetAccreditById" parameterType="Long" resultMap="AssetAccreditResult">
|
||||
<include refid="selectAssetAccreditVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="getAssetAccreditByDataAssetId" resultType="com.muyu.etl.domain.AssetAccredit">
|
||||
<include refid="selectAssetAccreditVo"></include>
|
||||
<where>
|
||||
and data_asset_id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
<select id="getAssetAccreditByUserId" resultType="com.muyu.etl.domain.AssetAccredit">
|
||||
<include refid="selectAssetAccreditVo"></include>
|
||||
<where>
|
||||
and user_id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
<select id="getSourceAccreditByUserId" resultType="com.muyu.etl.domain.AssetAccredit">
|
||||
<include refid="selectAssetAccreditVo"></include>
|
||||
<where>
|
||||
and user_id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertAssetAccredit" parameterType="com.muyu.etl.domain.AssetAccredit" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into asset_accredit
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null">dept_id,</if>
|
||||
<if test="dataAssetId != null">data_asset_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null">#{deptId},</if>
|
||||
<if test="dataAssetId != null">#{dataAssetId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="insertBatchAssetAccredit">
|
||||
insert into asset_accredit
|
||||
<trim prefix="(" suffix=")">
|
||||
dept_id,
|
||||
data_asset_id,
|
||||
user_id,
|
||||
create_by,
|
||||
create_time
|
||||
</trim>
|
||||
values
|
||||
<foreach collection="assetAccredits" item="assetAccredit" separator=",">
|
||||
(
|
||||
<if test="assetAccredit.deptId !=null">#{assetAccredit.deptId},</if>
|
||||
<if test="assetAccredit.deptId ==null">null,</if>
|
||||
#{assetAccredit.dataAssetId},
|
||||
<if test="assetAccredit.userId !=null">#{assetAccredit.userId},</if>
|
||||
<if test="assetAccredit.userId ==null">null,</if>
|
||||
#{assetAccredit.createBy},
|
||||
#{assetAccredit.createTime}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="insertBachAssetAccredit">
|
||||
insert into asset_accredit
|
||||
<trim prefix="(" suffix=")">
|
||||
dept_id,
|
||||
data_asset_id,
|
||||
user_id,
|
||||
create_by,
|
||||
create_time
|
||||
</trim>
|
||||
values
|
||||
<foreach collection="assetAccredits" item="assetAccredit" separator=",">
|
||||
(
|
||||
<if test="assetAccredit.deptId !=null">#{assetAccredit.deptId},</if>
|
||||
<if test="assetAccredit.deptId ==null">null,</if>
|
||||
#{assetAccredit.dataAssetId},
|
||||
<if test="assetAccredit.userId !=null">#{assetAccredit.userId},</if>
|
||||
<if test="assetAccredit.userId ==null">null,</if>
|
||||
#{assetAccredit.createBy},
|
||||
#{assetAccredit.createTime}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateAssetAccredit" parameterType="com.muyu.etl.domain.AssetAccredit">
|
||||
update asset_accredit
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="deptId != null">dept_id = #{deptId},</if>
|
||||
<if test="dataAssetId != null">data_asset_id = #{dataAssetId},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteAssetAccreditById" parameterType="Long">
|
||||
delete from asset_accredit where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteAssetAccreditByIds" parameterType="String">
|
||||
delete from asset_accredit where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteAssetAccreditByAssetId">
|
||||
delete from asset_accredit where data_asset_id in
|
||||
<foreach item="assetId" collection="assetIds" open="(" separator="," close=")">
|
||||
#{assetId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteAssetAccreditByDeptUser">
|
||||
delete from asset_accredit where
|
||||
data_asset_id = #{dataAssetId}
|
||||
<if test="userId !=null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="deptIds != null">
|
||||
and dept_id in
|
||||
<foreach item="deptId" collection="deptIds" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</if>
|
||||
</delete>
|
||||
</mapper>
|
|
@ -37,10 +37,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectDataAssetVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="com.muyu.etl.domain.DataAsset">
|
||||
select * from data_asset where data_source_id= #{id}
|
||||
</select>
|
||||
|
||||
<select id="getDataAssetByAssetId" resultType="com.muyu.etl.domain.DataAsset">
|
||||
<include refid="selectDataAssetVo"/>
|
||||
<where>
|
||||
and id in (
|
||||
<foreach collection="assetIds" item="id" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
)
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertDataAsset" parameterType="com.muyu.etl.domain.DataAsset" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into data_asset
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.muyu.etl.mapper.SourceAccreditMapper">
|
||||
|
||||
<resultMap type="com.muyu.etl.domain.SourceAccredit" id="SourceAccreditResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="deptId" column="dept_id" />
|
||||
<result property="dataSourceId" column="datasource_id" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectSourceAccreditVo">
|
||||
select id, dept_id, datasource_id, user_id, remark, create_by, create_time, update_by, update_time from source_accredit
|
||||
</sql>
|
||||
|
||||
<select id="selectSourceAccreditList" parameterType="com.muyu.etl.domain.SourceAccredit" resultMap="SourceAccreditResult">
|
||||
<include refid="selectSourceAccreditVo"/>
|
||||
<where>
|
||||
<if test="deptId != null "> and dept_id = #{deptId}</if>
|
||||
<if test="dataSourceId != null "> and datasource_id = #{dataSourceId}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectSourceAccreditById" parameterType="Long" resultMap="SourceAccreditResult">
|
||||
<include refid="selectSourceAccreditVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="getSourceAccreditByDataSourceId" resultType="com.muyu.etl.domain.SourceAccredit">
|
||||
<include refid="selectSourceAccreditVo"></include>
|
||||
<where>
|
||||
and datasource_id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
<select id="getSourceAccreditByUserId" resultType="com.muyu.etl.domain.SourceAccredit">
|
||||
<include refid="selectSourceAccreditVo"></include>
|
||||
<where>
|
||||
and user_id = #{id}
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertSourceAccredit" parameterType="com.muyu.etl.domain.SourceAccredit" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into source_accredit
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null">dept_id,</if>
|
||||
<if test="dataSourceId != null">datasource_id,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null">#{dept_id},</if>
|
||||
<if test="dataSourceId != null">#{dataSourceId},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="insertBatchSourceAccredit">
|
||||
insert into source_accredit
|
||||
<trim prefix="(" suffix=")">
|
||||
dept_id,
|
||||
datasource_id,
|
||||
user_id,
|
||||
create_by,
|
||||
create_time
|
||||
</trim>
|
||||
values
|
||||
<foreach collection="sourceAccredits" item="sourceAccredit" separator=",">
|
||||
(
|
||||
<if test="sourceAccredit.deptId !=null">#{sourceAccredit.deptId},</if>
|
||||
<if test="sourceAccredit.deptId ==null">null,</if>
|
||||
#{sourceAccredit.dataSourceId},
|
||||
<if test="sourceAccredit.userId !=null">#{sourceAccredit.userId},</if>
|
||||
<if test="sourceAccredit.userId ==null">null,</if>
|
||||
#{sourceAccredit.createBy},
|
||||
#{sourceAccredit.createTime}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateSourceAccredit" parameterType="com.muyu.etl.domain.SourceAccredit">
|
||||
update source_accredit
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="deptId != null">dept_id = #{deptId},</if>
|
||||
<if test="dataSourceId != null">datasource_id = #{dataSourceId},</if>
|
||||
<if test="userId != null">user_id = #{userId},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteSourceAccreditById" parameterType="Long">
|
||||
delete from source_accredit where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteSourceAccreditByIds" parameterType="String">
|
||||
delete from source_accredit where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteSourceAccreditBySourceIds">
|
||||
delete from source_accredit where datasource_id in
|
||||
<foreach item="sourceId" collection="sourceIds" open="(" separator="," close=")">
|
||||
#{sourceId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<delete id="deleteSourceAccreditByDeptUser">
|
||||
delete from source_accredit where
|
||||
datasource_id = #{dataSourceId}
|
||||
<if test="userId !=null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="deptIds != null">
|
||||
and dept_id in
|
||||
<foreach item="deptId" collection="deptIds" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</if>
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue