parent
9614014e29
commit
91fea4084d
30 changed files with 784 additions and 747 deletions
@ -1,96 +0,0 @@ |
|||||||
package org.springblade.plugin.operation.database.entity; |
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField; |
|
||||||
import com.baomidou.mybatisplus.annotation.TableName; |
|
||||||
import lombok.Data; |
|
||||||
import lombok.EqualsAndHashCode; |
|
||||||
import org.springblade.core.tenant.mp.TenantEntity; |
|
||||||
|
|
||||||
@Data |
|
||||||
@TableName("t_data_table") |
|
||||||
@EqualsAndHashCode(callSuper = true) |
|
||||||
public class DataTable extends TenantEntity { |
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库id |
|
||||||
*/ |
|
||||||
private Long dataBaseId; |
|
||||||
|
|
||||||
/** |
|
||||||
* 模块名称 |
|
||||||
*/ |
|
||||||
private String systemModuleName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 表名称 |
|
||||||
*/ |
|
||||||
private String dataTableName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 中文别名 |
|
||||||
*/ |
|
||||||
private String dataTableAlias; |
|
||||||
|
|
||||||
/** |
|
||||||
* 管理部门id |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private Long deptId; |
|
||||||
|
|
||||||
/** |
|
||||||
* 管理部门 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String deptName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 运维公司id |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private Long company; |
|
||||||
|
|
||||||
/** |
|
||||||
* 运维公司 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String companyName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库名称 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String dataBaseName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库中文别名 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String dataBaseAlias; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库类型 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private Integer dataBaseType; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库ip |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String dataBaseIp; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库端口 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String dataBasePort; |
|
||||||
|
|
||||||
/** |
|
||||||
* 系统名称 |
|
||||||
*/ |
|
||||||
@TableField(exist = false) |
|
||||||
private String systemName; |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,36 @@ |
|||||||
|
package org.springblade.plugin.operation.database.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.core.tenant.mp.TenantEntity; |
||||||
|
|
||||||
|
@Data |
||||||
|
@TableName("t_module_datatable") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class ModuleDatatable extends TenantEntity { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据库id |
||||||
|
*/ |
||||||
|
private Long projectDatabaseId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 表名称 |
||||||
|
*/ |
||||||
|
private String datatableModuleName; |
||||||
|
|
||||||
|
/** |
||||||
|
* 中文别名 |
||||||
|
*/ |
||||||
|
private String dataTableAlias; |
||||||
|
|
||||||
|
/** |
||||||
|
* 模块名称(先留着,不给前端返回) |
||||||
|
*/ |
||||||
|
private String systemModuleName; |
||||||
|
|
||||||
|
} |
||||||
@ -1,22 +0,0 @@ |
|||||||
|
|
||||||
package org.springblade.plugin.operation.database.mapper; |
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|
||||||
import org.apache.ibatis.annotations.Param; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataBase; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataTable; |
|
||||||
import org.springblade.plugin.operation.database.vo.DataBaseVO; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* Mapper 接口 |
|
||||||
* |
|
||||||
* @author BladeX |
|
||||||
*/ |
|
||||||
public interface DataTableMapper extends BaseMapper<DataTable> { |
|
||||||
|
|
||||||
List<DataBaseVO> page(@Param("dataBase")DataBase dataBase, @Param("current")long current, @Param("size")long size); |
|
||||||
|
|
||||||
long dataCount(@Param("dataBase")DataBase dataBase); |
|
||||||
} |
|
||||||
@ -1,58 +0,0 @@ |
|||||||
<?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="org.springblade.plugin.operation.database.mapper.DataTableMapper"> |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<select id="page" resultType="org.springblade.plugin.operation.database.vo.DataBaseVO"> |
|
||||||
select |
|
||||||
b.data_base_ip, |
|
||||||
b.data_base_port, |
|
||||||
b.data_base_name, |
|
||||||
b.data_base_type, |
|
||||||
b.data_base_alias, |
|
||||||
b.system_name, |
|
||||||
t.system_module_name, |
|
||||||
b.dept_id, |
|
||||||
b.company, |
|
||||||
t.data_table_name, |
|
||||||
t.data_table_alias |
|
||||||
from t_data_base b left join t_data_table t on b.id = t.data_base_id |
|
||||||
where t.is_deleted = 0 |
|
||||||
<if test="dataBase.getDataBaseName!=null and dataBase.getDataBaseName != ''"> |
|
||||||
and b.data_base_name = #{dataBase.dataBaseName} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getDataBaseType!=null"> |
|
||||||
and b.data_base_type = #{dataBase.dataBaseType} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getDeptId!=null"> |
|
||||||
and b.dept_id = #{dataBase.deptId} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getCompany!=null"> |
|
||||||
and b.company = #{dataBase.company} |
|
||||||
</if> |
|
||||||
order by t.create_time DESC |
|
||||||
LIMIT #{current},#{size} |
|
||||||
</select> |
|
||||||
|
|
||||||
<select id="dataCount" resultType="long"> |
|
||||||
select |
|
||||||
count(*) |
|
||||||
from t_data_base b left join t_data_table t on b.id = t.data_base_id |
|
||||||
where t.is_deleted = 0 |
|
||||||
<if test="dataBase.getDataBaseName!=null and dataBase.getDataBaseName != ''"> |
|
||||||
and b.data_base_name = #{dataBase.dataBaseName} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getDataBaseType!=null"> |
|
||||||
and b.data_base_type = #{dataBase.dataBaseType} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getDeptId!=null"> |
|
||||||
and b.dept_id = #{dataBase.deptId} |
|
||||||
</if> |
|
||||||
<if test="dataBase.getCompany!=null"> |
|
||||||
and b.company = #{dataBase.company} |
|
||||||
</if> |
|
||||||
</select> |
|
||||||
|
|
||||||
|
|
||||||
</mapper> |
|
||||||
@ -0,0 +1,22 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabase; |
||||||
|
import org.springblade.plugin.operation.database.entity.ModuleDatatable; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabaseVo; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper 接口 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
public interface ModuleDatatableMapper extends BaseMapper<ModuleDatatable> { |
||||||
|
|
||||||
|
List<ProjectDatabaseVo> page(@Param("dataBase") ProjectDatabase dataBase, @Param("current")long current, @Param("size")long size); |
||||||
|
|
||||||
|
long dataCount(@Param("dataBase") ProjectDatabase dataBase); |
||||||
|
} |
||||||
@ -0,0 +1,63 @@ |
|||||||
|
<?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="org.springblade.plugin.operation.database.mapper.ModuleDatatableMapper"> |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<select id="page" resultType="org.springblade.plugin.operation.database.entity.ProjectDatabaseVo"> |
||||||
|
select |
||||||
|
b.data_base_ip, |
||||||
|
b.data_base_port, |
||||||
|
b.database_project_name, |
||||||
|
b.type, |
||||||
|
b.data_base_alias, |
||||||
|
b.system_name, |
||||||
|
b.dept_id, |
||||||
|
b.company, |
||||||
|
t.datatable_module_name, |
||||||
|
t.data_table_alias |
||||||
|
from t_project_database b left join t_module_datatable t on b.id = t.project_database_id |
||||||
|
where t.is_deleted = 0 |
||||||
|
<if test="dataBase.getDatabaseProjectName!=null and dataBase.getDatabaseProjectName != ''"> |
||||||
|
and b.database_project_name = #{dataBase.databaseProjectName} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getDatatableModuleName!=null and dataBase.getDatatableModuleName != ''"> |
||||||
|
and t.datatable_module_name = #{dataBase.datatableModuleName} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getType!=null"> |
||||||
|
and b.type = #{dataBase.type} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getDeptId!=null"> |
||||||
|
and b.dept_id = #{dataBase.deptId} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getCompany!=null"> |
||||||
|
and b.company = #{dataBase.company} |
||||||
|
</if> |
||||||
|
order by t.create_time DESC |
||||||
|
LIMIT #{current},#{size} |
||||||
|
</select> |
||||||
|
|
||||||
|
<select id="dataCount" resultType="long"> |
||||||
|
select |
||||||
|
count(*) |
||||||
|
from t_project_database b left join t_module_datatable t on b.id = t.project_database_id |
||||||
|
where t.is_deleted = 0 |
||||||
|
<if test="dataBase.getDatabaseProjectName!=null and dataBase.getDatabaseProjectName != ''"> |
||||||
|
and b.database_project_name = #{dataBase.databaseProjectName} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getDatatableModuleName!=null and dataBase.getDatatableModuleName != ''"> |
||||||
|
and t.datatable_module_name = #{dataBase.datatableModuleName} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getType!=null"> |
||||||
|
and b.type = #{dataBase.type} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getDeptId!=null"> |
||||||
|
and b.dept_id = #{dataBase.deptId} |
||||||
|
</if> |
||||||
|
<if test="dataBase.getCompany!=null"> |
||||||
|
and b.company = #{dataBase.company} |
||||||
|
</if> |
||||||
|
</select> |
||||||
|
|
||||||
|
|
||||||
|
</mapper> |
||||||
@ -1,5 +1,5 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?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"> |
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
<mapper namespace="org.springblade.plugin.operation.database.mapper.DataBaseMapper"> |
<mapper namespace="org.springblade.plugin.operation.database.mapper.ProjectDatabaseMapper"> |
||||||
|
|
||||||
</mapper> |
</mapper> |
||||||
@ -1,16 +0,0 @@ |
|||||||
|
|
||||||
package org.springblade.plugin.operation.database.service; |
|
||||||
|
|
||||||
import org.springblade.core.mp.base.BaseService; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataBase; |
|
||||||
import org.springframework.web.multipart.MultipartFile; |
|
||||||
|
|
||||||
/** |
|
||||||
* 服务类 |
|
||||||
* |
|
||||||
* @author BladeX |
|
||||||
*/ |
|
||||||
public interface IDataBaseService extends BaseService<DataBase> { |
|
||||||
|
|
||||||
boolean dataImport(MultipartFile file); |
|
||||||
} |
|
||||||
@ -1,20 +0,0 @@ |
|||||||
|
|
||||||
package org.springblade.plugin.operation.database.service; |
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
||||||
import org.springblade.core.mp.base.BaseService; |
|
||||||
import org.springblade.core.mp.support.Query; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataBase; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataTable; |
|
||||||
import org.springblade.plugin.operation.database.vo.DataBaseVO; |
|
||||||
|
|
||||||
/** |
|
||||||
* 服务类 |
|
||||||
* |
|
||||||
* |
|
||||||
* @author BladeX |
|
||||||
*/ |
|
||||||
public interface IDataTableService extends BaseService<DataTable> { |
|
||||||
|
|
||||||
IPage<DataBaseVO> pageVO(IPage<DataBaseVO> page, DataBase dataBase); |
|
||||||
} |
|
||||||
@ -0,0 +1,19 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabase; |
||||||
|
import org.springblade.plugin.operation.database.entity.ModuleDatatable; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabaseVo; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务类 |
||||||
|
* |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
public interface IModuleDatatableService extends BaseService<ModuleDatatable> { |
||||||
|
|
||||||
|
IPage<ProjectDatabaseVo> pageVO(IPage<ProjectDatabaseVo> page, ProjectDatabase dataBase); |
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service; |
||||||
|
|
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabase; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabasePo; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
public interface IProjectDatabaseService extends BaseService<ProjectDatabase> { |
||||||
|
|
||||||
|
String dataImport(MultipartFile file); |
||||||
|
|
||||||
|
boolean saveProAndMod(ProjectDatabasePo dataBase) ; |
||||||
|
} |
||||||
@ -1,138 +0,0 @@ |
|||||||
|
|
||||||
package org.springblade.plugin.operation.database.service.impl; |
|
||||||
|
|
||||||
import com.alibaba.nacos.common.utils.CollectionUtils; |
|
||||||
import com.alibaba.nacos.common.utils.StringUtils; |
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import org.springblade.core.excel.util.ExcelUtil; |
|
||||||
import org.springblade.core.mp.base.BaseServiceImpl; |
|
||||||
import org.springblade.core.secure.utils.AuthUtil; |
|
||||||
import org.springblade.core.tool.utils.BeanUtil; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataBase; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataTable; |
|
||||||
import org.springblade.plugin.operation.database.excel.DatabaseExcel; |
|
||||||
import org.springblade.plugin.operation.database.mapper.DataBaseMapper; |
|
||||||
import org.springblade.plugin.operation.database.service.IDataBaseService; |
|
||||||
import org.springblade.plugin.operation.database.service.IDataTableService; |
|
||||||
import org.springblade.system.cache.DictBizCache; |
|
||||||
import org.springblade.system.feign.ISysClient; |
|
||||||
import org.springblade.system.user.entity.User; |
|
||||||
import org.springblade.system.user.feign.IUserClient; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
import org.springframework.transaction.annotation.Transactional; |
|
||||||
import org.springframework.web.multipart.MultipartFile; |
|
||||||
|
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
/** |
|
||||||
* 服务实现类 |
|
||||||
* @author BladeX |
|
||||||
*/ |
|
||||||
@Service |
|
||||||
@AllArgsConstructor |
|
||||||
public class DataBaseServiceImpl extends BaseServiceImpl<DataBaseMapper, DataBase> implements IDataBaseService { |
|
||||||
|
|
||||||
private final IDataTableService dataTableService; |
|
||||||
|
|
||||||
private final ISysClient sysClient; |
|
||||||
|
|
||||||
private final IUserClient userClient; |
|
||||||
|
|
||||||
@Override |
|
||||||
@Transactional(rollbackFor = Exception.class) |
|
||||||
public boolean dataImport(MultipartFile file) { |
|
||||||
List<DatabaseExcel> excelList = ExcelUtil.read(file, DatabaseExcel.class); |
|
||||||
if (CollectionUtils.isNotEmpty(excelList)) { |
|
||||||
// List<DataTable> dataTableList = new ArrayList<>();
|
|
||||||
for (DatabaseExcel item : excelList) { |
|
||||||
// 如果数据库类型不存在,跳过这条数据
|
|
||||||
if (StringUtils.isBlank(DictBizCache.getKey("database_type", item.getDataBaseType()))) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
Integer databaseType = Integer.parseInt(DictBizCache.getKey("database_type", item.getDataBaseType())); |
|
||||||
LambdaQueryWrapper<DataBase> wrapper = new LambdaQueryWrapper<>(); |
|
||||||
wrapper.select(DataBase::getId); |
|
||||||
wrapper.eq(DataBase::getDataBaseName, item.getDataBaseName()); |
|
||||||
// wrapper.eq(DataBase::getDataBaseType, databaseType);
|
|
||||||
wrapper.eq(DataBase::getDataBaseIp, item.getDataBaseIp()); |
|
||||||
wrapper.eq(DataBase::getDataBasePort,item.getDataBasePort()); |
|
||||||
DataBase base = getOne(wrapper); |
|
||||||
if (base == null) { |
|
||||||
// 数据库
|
|
||||||
DataBase dataBase = BeanUtil.copy(item, DataBase.class); |
|
||||||
String data = sysClient.getDeptIds(AuthUtil.getTenantId(), item.getDeptId()).getData(); |
|
||||||
User user = userClient.userInfoByName(AuthUtil.getTenantId(), item.getCompany()).getData(); |
|
||||||
dataBase.setDataBaseType(databaseType); |
|
||||||
dataBase.setDeptId(Long.parseLong(data)); |
|
||||||
dataBase.setCompany(user.getId()); |
|
||||||
save(dataBase); |
|
||||||
|
|
||||||
// 数据表
|
|
||||||
DataTable dataTable = BeanUtil.copy(item, DataTable.class); |
|
||||||
dataTable.setDataBaseId(dataBase.getId()); |
|
||||||
// dataTableList.add(dataTable);
|
|
||||||
dataTableService.save(dataTable); |
|
||||||
} else { |
|
||||||
LambdaQueryWrapper<DataTable> queryWrapper = new LambdaQueryWrapper<>(); |
|
||||||
queryWrapper.eq(DataTable::getDataBaseId, base.getId()); |
|
||||||
queryWrapper.eq(DataTable::getDataTableName, item.getDataTableName()); |
|
||||||
int count = dataTableService.count(queryWrapper); |
|
||||||
if (count <= 0) { |
|
||||||
// 数据表
|
|
||||||
DataTable dataTable = BeanUtil.copy(item, DataTable.class); |
|
||||||
dataTable.setDataBaseId(base.getId()); |
|
||||||
dataTableService.save(dataTable); |
|
||||||
// dataTableList.add(dataTable);
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// excelList.forEach(item -> {
|
|
||||||
// String key = DictBizCache.getKey("database_type", item.getDataBaseType());
|
|
||||||
// if (StringUtils.isBlank(key)) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// Integer databaseType = Integer.parseInt(DictBizCache.getKey("database_type", item.getDataBaseType()));
|
|
||||||
// LambdaQueryWrapper<DataBase> wrapper = new LambdaQueryWrapper<>();
|
|
||||||
// wrapper.select(DataBase::getId);
|
|
||||||
// wrapper.eq(DataBase::getDataBaseName, item.getDataBaseName());
|
|
||||||
//// wrapper.eq(DataBase::getDataBaseType, databaseType);
|
|
||||||
// wrapper.eq(DataBase::getDataBaseIp, item.getDataBaseIp());
|
|
||||||
// wrapper.eq(DataBase::getDataBasePort,item.getDataBasePort());
|
|
||||||
// DataBase base = getOne(wrapper);
|
|
||||||
// if (base == null) {
|
|
||||||
// // 数据库
|
|
||||||
// DataBase dataBase = BeanUtil.copy(item, DataBase.class);
|
|
||||||
// String data = sysClient.getDeptIds(AuthUtil.getTenantId(), item.getDeptId()).getData();
|
|
||||||
// User user = userClient.userInfoByName(AuthUtil.getTenantId(), item.getCompany()).getData();
|
|
||||||
// dataBase.setDataBaseType(databaseType);
|
|
||||||
// dataBase.setDeptId(Long.parseLong(data));
|
|
||||||
// dataBase.setCompany(user.getId());
|
|
||||||
// save(dataBase);
|
|
||||||
//
|
|
||||||
// // 数据表
|
|
||||||
// DataTable dataTable = BeanUtil.copy(item, DataTable.class);
|
|
||||||
// dataTable.setDataBaseId(dataBase.getId());
|
|
||||||
//// dataTableList.add(dataTable);
|
|
||||||
// dataTableService.save(dataTable);
|
|
||||||
// } else {
|
|
||||||
// LambdaQueryWrapper<DataTable> queryWrapper = new LambdaQueryWrapper<>();
|
|
||||||
// queryWrapper.eq(DataTable::getDataBaseId, base.getId());
|
|
||||||
// queryWrapper.eq(DataTable::getDataTableName, item.getDataTableName());
|
|
||||||
// int count = dataTableService.count(queryWrapper);
|
|
||||||
// if (count <= 0) {
|
|
||||||
// // 数据表
|
|
||||||
// DataTable dataTable = BeanUtil.copy(item, DataTable.class);
|
|
||||||
// dataTable.setDataBaseId(base.getId());
|
|
||||||
// dataTableService.save(dataTable);
|
|
||||||
//// dataTableList.add(dataTable);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// return dataTableService.saveBatch(dataTableList);
|
|
||||||
return true; |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,31 +0,0 @@ |
|||||||
|
|
||||||
package org.springblade.plugin.operation.database.service.impl; |
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
||||||
import lombok.AllArgsConstructor; |
|
||||||
import org.springblade.core.mp.base.BaseServiceImpl; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataBase; |
|
||||||
import org.springblade.plugin.operation.database.entity.DataTable; |
|
||||||
import org.springblade.plugin.operation.database.mapper.DataTableMapper; |
|
||||||
import org.springblade.plugin.operation.database.service.IDataTableService; |
|
||||||
import org.springblade.plugin.operation.database.vo.DataBaseVO; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
|
|
||||||
/** |
|
||||||
* 服务实现类 |
|
||||||
* |
|
||||||
* @author BladeX |
|
||||||
*/ |
|
||||||
@Service |
|
||||||
@AllArgsConstructor |
|
||||||
public class DataTableServiceImpl extends BaseServiceImpl<DataTableMapper, DataTable> implements IDataTableService { |
|
||||||
|
|
||||||
private final DataTableMapper dataTableMapper; |
|
||||||
|
|
||||||
@Override |
|
||||||
public IPage<DataBaseVO> pageVO(IPage<DataBaseVO> page, DataBase dataBase) { |
|
||||||
page.setTotal(dataTableMapper.dataCount(dataBase)); |
|
||||||
return page.setRecords(dataTableMapper.page(dataBase, (page.getCurrent() - 1) * page.getSize(), page.getSize())); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -0,0 +1,31 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabase; |
||||||
|
import org.springblade.plugin.operation.database.entity.ModuleDatatable; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabaseVo; |
||||||
|
import org.springblade.plugin.operation.database.mapper.ModuleDatatableMapper; |
||||||
|
import org.springblade.plugin.operation.database.service.IModuleDatatableService; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务实现类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class ModuleDatatableServiceImpl extends BaseServiceImpl<ModuleDatatableMapper, ModuleDatatable> implements IModuleDatatableService { |
||||||
|
|
||||||
|
private final ModuleDatatableMapper moduleDatatableMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<ProjectDatabaseVo> pageVO(IPage<ProjectDatabaseVo> page, ProjectDatabase dataBase) { |
||||||
|
page.setTotal(moduleDatatableMapper.dataCount(dataBase)); |
||||||
|
return page.setRecords(moduleDatatableMapper.page(dataBase, (page.getCurrent() - 1) * page.getSize(), page.getSize())); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,183 @@ |
|||||||
|
|
||||||
|
package org.springblade.plugin.operation.database.service.impl; |
||||||
|
|
||||||
|
import com.alibaba.nacos.common.utils.CollectionUtils; |
||||||
|
import com.alibaba.nacos.common.utils.StringUtils; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springblade.core.excel.util.ExcelUtil; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.core.tool.utils.BeanUtil; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabase; |
||||||
|
import org.springblade.plugin.operation.database.entity.ModuleDatatable; |
||||||
|
import org.springblade.plugin.operation.database.entity.ProjectDatabasePo; |
||||||
|
import org.springblade.plugin.operation.database.excel.DatabaseExcel; |
||||||
|
import org.springblade.plugin.operation.database.mapper.ProjectDatabaseMapper; |
||||||
|
import org.springblade.plugin.operation.database.service.IProjectDatabaseService; |
||||||
|
import org.springblade.plugin.operation.database.service.IModuleDatatableService; |
||||||
|
import org.springblade.system.cache.DictBizCache; |
||||||
|
import org.springblade.system.feign.ISysClient; |
||||||
|
import org.springblade.system.user.entity.User; |
||||||
|
import org.springblade.system.user.feign.IUserClient; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务实现类 |
||||||
|
* |
||||||
|
* @author BladeX |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
public class ProjectDatabaseServiceImpl extends BaseServiceImpl<ProjectDatabaseMapper, ProjectDatabase> implements IProjectDatabaseService { |
||||||
|
|
||||||
|
private final IModuleDatatableService dataTableService; |
||||||
|
|
||||||
|
private final ISysClient sysClient; |
||||||
|
|
||||||
|
private final IUserClient userClient; |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor = Exception.class) |
||||||
|
public String dataImport(MultipartFile file) { |
||||||
|
List<DatabaseExcel> excelList = ExcelUtil.read(file, DatabaseExcel.class); |
||||||
|
int total = excelList.size(); |
||||||
|
int success = 0; |
||||||
|
int lose = 0; |
||||||
|
if (CollectionUtils.isNotEmpty(excelList)) { |
||||||
|
for (DatabaseExcel item : excelList) { |
||||||
|
// 如果类型不存在,跳过这条数据
|
||||||
|
if (StringUtils.isBlank(DictBizCache.getKey("database_type", item.getType())) || |
||||||
|
StringUtils.isBlank(item.getDatabaseProjectName()) || |
||||||
|
StringUtils.isBlank(item.getDatatableModuleName()) || |
||||||
|
StringUtils.isBlank(item.getDeptId()) || |
||||||
|
StringUtils.isBlank(item.getCompany())) { |
||||||
|
lose++; |
||||||
|
continue; |
||||||
|
} |
||||||
|
Integer databaseType = Integer.parseInt(DictBizCache.getKey("database_type", item.getType())); |
||||||
|
String data = sysClient.getDeptIds(AuthUtil.getTenantId(), item.getDeptId()).getData(); |
||||||
|
User user = userClient.userInfoByName(AuthUtil.getTenantId(), item.getCompany()).getData(); |
||||||
|
|
||||||
|
LambdaQueryWrapper<ProjectDatabase> wrapper = new LambdaQueryWrapper<>(); |
||||||
|
// wrapper.select(ProjectDatabase::getId);
|
||||||
|
wrapper.eq(ProjectDatabase::getDatabaseProjectName, item.getDatabaseProjectName()); |
||||||
|
// if (StringUtils.isNotBlank(item.getDataBaseIp())) {
|
||||||
|
// wrapper.eq(ProjectDatabase::getDataBaseIp, item.getDataBaseIp());
|
||||||
|
// }
|
||||||
|
ProjectDatabase base = getOne(wrapper); |
||||||
|
if (base == null) { |
||||||
|
// 数据库
|
||||||
|
ProjectDatabase dataBase = BeanUtil.copy(item, ProjectDatabase.class); |
||||||
|
|
||||||
|
dataBase.setType(databaseType); |
||||||
|
dataBase.setDeptId(Long.parseLong(data)); |
||||||
|
dataBase.setCompany(user.getId()); |
||||||
|
save(dataBase); |
||||||
|
|
||||||
|
// 数据表
|
||||||
|
ModuleDatatable dataTable = BeanUtil.copy(item, ModuleDatatable.class); |
||||||
|
dataTable.setProjectDatabaseId(dataBase.getId()); |
||||||
|
dataTableService.save(dataTable); |
||||||
|
} else { |
||||||
|
if (item.getDataBaseIp() == null) { item.setDataBaseIp(""); } |
||||||
|
if (base.getDataBaseIp() == null) { base.setDataBaseIp(""); } |
||||||
|
if (item.getDataBasePort() == null) { item.setDataBasePort(""); } |
||||||
|
if (base.getDataBasePort() == null) { base.setDataBasePort(""); } |
||||||
|
if (item.getDataBaseAlias() == null) { item.setDataBaseAlias(""); } |
||||||
|
if (base.getDataBaseAlias() == null) { base.setDataBaseAlias(""); } |
||||||
|
if (item.getSystemName() == null) { item.setSystemName(""); } |
||||||
|
if (base.getSystemName() == null) { base.setSystemName(""); } |
||||||
|
|
||||||
|
if (!item.getDataBaseIp().equals(base.getDataBaseIp()) || |
||||||
|
!item.getDataBasePort().equals(base.getDataBasePort()) || |
||||||
|
!item.getDataBaseAlias().equals(base.getDataBaseAlias()) || |
||||||
|
!item.getSystemName().equals(base.getSystemName()) || |
||||||
|
!item.getDatabaseProjectName().equals(base.getDatabaseProjectName()) || |
||||||
|
!databaseType.equals(base.getType()) || |
||||||
|
!Long.valueOf(data).equals(base.getDeptId()) || |
||||||
|
!user.getId().equals(base.getCompany()) |
||||||
|
) { |
||||||
|
lose++; |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
LambdaQueryWrapper<ModuleDatatable> queryWrapper = new LambdaQueryWrapper<>(); |
||||||
|
queryWrapper.eq(ModuleDatatable::getProjectDatabaseId, base.getId()); |
||||||
|
queryWrapper.eq(ModuleDatatable::getDatatableModuleName, item.getDatatableModuleName()); |
||||||
|
int count = dataTableService.count(queryWrapper); |
||||||
|
if (count <= 0) { |
||||||
|
// 数据表
|
||||||
|
ModuleDatatable dataTable = BeanUtil.copy(item, ModuleDatatable.class); |
||||||
|
dataTable.setProjectDatabaseId(base.getId()); |
||||||
|
dataTableService.save(dataTable); |
||||||
|
} else { |
||||||
|
success++; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return "共" + total + "条数据,导入成功" + (total - lose - success) + "条;导入失败" + lose + "条;数据重复" + success + "条!"; |
||||||
|
} |
||||||
|
return "数据为空,无法导入!"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor = Exception.class) |
||||||
|
public boolean saveProAndMod(ProjectDatabasePo dataBase) { |
||||||
|
// 条件查询数据库/系统数据
|
||||||
|
LambdaQueryWrapper<ProjectDatabase> wrapper = new LambdaQueryWrapper<>(); |
||||||
|
wrapper.eq(ProjectDatabase::getDatabaseProjectName, dataBase.getDatabaseProjectName()); |
||||||
|
if (StringUtils.isNotBlank(dataBase.getDataBaseIp())) { |
||||||
|
wrapper.eq(ProjectDatabase::getDataBaseIp, dataBase.getDataBaseIp()); |
||||||
|
} |
||||||
|
ProjectDatabase database = getOne(wrapper); |
||||||
|
|
||||||
|
// 创建数据表/模块对象集合
|
||||||
|
List<ModuleDatatable> moduleDatatableList = new ArrayList<>(); |
||||||
|
|
||||||
|
// 传过来的数据表/模块数据
|
||||||
|
List<ModuleDatatable> moduleDatatables = dataBase.getModuleDatatables(); |
||||||
|
|
||||||
|
LambdaQueryWrapper<ModuleDatatable> queryWrapper = new LambdaQueryWrapper<>(); |
||||||
|
if (database == null) { |
||||||
|
save(dataBase); |
||||||
|
if (CollectionUtils.isNotEmpty(moduleDatatables)) { |
||||||
|
for (ModuleDatatable moduleDatatable : moduleDatatables) { |
||||||
|
queryWrapper.eq(ModuleDatatable::getProjectDatabaseId, dataBase.getId()); |
||||||
|
queryWrapper.eq(ModuleDatatable::getDatatableModuleName, moduleDatatable.getDatatableModuleName()); |
||||||
|
int count = dataTableService.count(queryWrapper); |
||||||
|
if (count == 0) { |
||||||
|
moduleDatatable.setProjectDatabaseId(dataBase.getId()); |
||||||
|
moduleDatatableList.add(moduleDatatable); |
||||||
|
} |
||||||
|
queryWrapper.clear(); |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
if (CollectionUtils.isNotEmpty(moduleDatatables)) { |
||||||
|
for (ModuleDatatable moduleDatatable : moduleDatatables) { |
||||||
|
queryWrapper.eq(ModuleDatatable::getProjectDatabaseId, database.getId()); |
||||||
|
queryWrapper.eq(ModuleDatatable::getDatatableModuleName, moduleDatatable.getDatatableModuleName()); |
||||||
|
int count = dataTableService.count(queryWrapper); |
||||||
|
if (count == 0) { |
||||||
|
moduleDatatable.setProjectDatabaseId(database.getId()); |
||||||
|
moduleDatatableList.add(moduleDatatable); |
||||||
|
} |
||||||
|
queryWrapper.clear(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(moduleDatatableList)) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return dataTableService.saveBatch(moduleDatatableList); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -1,74 +0,0 @@ |
|||||||
package org.springblade.plugin.operation.database.vo; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
@Data |
|
||||||
public class DataBaseVO { |
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L; |
|
||||||
|
|
||||||
/** |
|
||||||
* 模块名称 |
|
||||||
*/ |
|
||||||
private String systemModuleName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 表名称 |
|
||||||
*/ |
|
||||||
private String dataTableName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 中文别名 |
|
||||||
*/ |
|
||||||
private String dataTableAlias; |
|
||||||
|
|
||||||
/** |
|
||||||
* 管理部门 |
|
||||||
*/ |
|
||||||
private String deptName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 运维公司 |
|
||||||
*/ |
|
||||||
private String companyName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 管理部门id |
|
||||||
*/ |
|
||||||
private Long deptId; |
|
||||||
|
|
||||||
/** |
|
||||||
* 运维公司id |
|
||||||
*/ |
|
||||||
private Long company; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库名称 |
|
||||||
*/ |
|
||||||
private String dataBaseName; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库中文别名 |
|
||||||
*/ |
|
||||||
private String dataBaseAlias; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库类型 |
|
||||||
*/ |
|
||||||
private Integer dataBaseType; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库ip |
|
||||||
*/ |
|
||||||
private String dataBaseIp; |
|
||||||
|
|
||||||
/** |
|
||||||
* 数据库端口 |
|
||||||
*/ |
|
||||||
private String dataBasePort; |
|
||||||
|
|
||||||
/** |
|
||||||
* 系统名称 |
|
||||||
*/ |
|
||||||
private String systemName; |
|
||||||
} |
|
||||||
Loading…
Reference in new issue