fix 同步数据改成异步
parent
59cc24f8c9
commit
1b2ea812ee
|
@ -24,5 +24,7 @@ public class ServiceNameConstants {
|
|||
|
||||
public static final String MUYU_KVT = "muyu-kvt";
|
||||
|
||||
|
||||
|
||||
public static final String MUYU_RULE_ENGINE ="muyu-rule-engine" ;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.common.system.remote;
|
||||
|
||||
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.remote.factory.RemoteDeptFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门服务 RemoteDeptService
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/5/11
|
||||
*/
|
||||
@FeignClient(contextId = "RemoteDeptService",
|
||||
value = ServiceNameConstants.FILE_SERVICE,
|
||||
fallbackFactory = RemoteDeptFallbackFactory.class)
|
||||
|
||||
public interface RemoteDeptService {
|
||||
|
||||
@PostMapping("/selectDept")
|
||||
public Result<List<SysDept>> deptList();
|
||||
@PostMapping("/selectDeptList")
|
||||
public Result<List<SysDept>> selectDeptList (@RequestBody Long deptId);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.common.system.remote.factory;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.system.domain.SysDept;
|
||||
import com.muyu.common.system.remote.RemoteDeptService;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门服务 RemoteDeptFallbackFactory
|
||||
*
|
||||
* @author LeYang
|
||||
* on 2024/5/11
|
||||
*/
|
||||
@Component
|
||||
public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptService> {
|
||||
@Override
|
||||
public RemoteDeptService create(Throwable cause) {
|
||||
return new RemoteDeptService() {
|
||||
@Override
|
||||
public Result<List<SysDept>> deptList() {
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<SysDept>> selectDeptList(Long deptId) {
|
||||
return Result.error(cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -35,5 +35,4 @@ public class DataDisplay {
|
|||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,10 +6,6 @@ import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* MuyuApplication
|
||||
*
|
||||
|
@ -21,7 +17,11 @@ import java.sql.*;
|
|||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class MuyuApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MuyuApplication.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -304,4 +304,10 @@ public class KvtController extends BaseController {
|
|||
List<Object> list= kvtService.selectTableName(tableName);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("/addDepartment")
|
||||
public Result selectDepartment(@RequestBody PermissionsUser permissionsUser){
|
||||
kvtService.AddDepartment(permissionsUser);
|
||||
return Result.success("添加成功");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,4 +80,6 @@ public interface KvtService extends IService<Kvt> {
|
|||
List<String> selectTable(String databaseName);
|
||||
|
||||
List<Object> selectTableName(String tableName);
|
||||
|
||||
void AddDepartment(PermissionsUser permissionsUser);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.muyu.kvt.permissions.PermissionsUser;
|
|||
import com.muyu.kvt.service.KvtService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.*;
|
||||
|
@ -97,7 +98,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
queryWrapper.eq(Kvt::getMaxWaitSize, kvt.getMaxWaitSize());
|
||||
}
|
||||
|
||||
|
||||
this.collect();
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
|
@ -218,8 +219,29 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return list;
|
||||
}
|
||||
|
||||
public void user() {
|
||||
public SysUser sysUser() {
|
||||
Result<SysUser> sysUserResult = remoteUserSer.selectUserId(SecurityUtils.getUserId());
|
||||
SysUser data = sysUserResult.getData();
|
||||
return data;
|
||||
}
|
||||
|
||||
public List<PermissionsUser> collect() {
|
||||
SysUser data = this.sysUser();
|
||||
List<PermissionsUser> permissionsUsers = this.selectPermission();
|
||||
if (permissionsUsers == null) {
|
||||
log.info("权限表为空");
|
||||
}
|
||||
//我想循序遍历 permissionsUsers 选出 跟当前用户的id 以及还有部门id添加到一个集合当中
|
||||
List<PermissionsUser> collect = permissionsUsers.stream()
|
||||
.map(permissionsUser -> {
|
||||
if (permissionsUser.getUserId().equals(data.getUserId()) && permissionsUser.getDeptId().equals(data.getDeptId())) {
|
||||
return permissionsUser;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
log.info("查询权限表的用户id部门id相比较" + collect);
|
||||
return collect;
|
||||
|
||||
}
|
||||
|
||||
|
@ -308,7 +330,9 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
private RemoteUserService remoteUserSer;
|
||||
|
||||
public Result mysql(Kvt kvt) {
|
||||
|
||||
//开始时间
|
||||
long time = System.currentTimeMillis();
|
||||
log.info("开始时间",time);
|
||||
//用户名
|
||||
String user = kvt.getUsername();
|
||||
//密码
|
||||
|
@ -339,6 +363,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
//获取表名
|
||||
String tableName = resultSet.getString("table_name");
|
||||
|
||||
|
||||
//添加资产展示数据
|
||||
this.dataDisplayAdd(tableName, connection, kvt);
|
||||
//添加数据结构
|
||||
|
@ -358,6 +383,9 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
baseMapper.DeptUserKvtAdd(build);
|
||||
|
||||
resultSet.close();
|
||||
//结束时间
|
||||
long time2 = System.currentTimeMillis();
|
||||
log.info("总耗时",time2-time);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
|
@ -373,6 +401,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
* @param connection
|
||||
* @param kvt
|
||||
*/
|
||||
@Async
|
||||
public void dataDisplayAdd(String tableName, Connection connection, Kvt kvt) {
|
||||
try {
|
||||
//查询表中的数据
|
||||
|
@ -403,6 +432,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println(dataDisplays);
|
||||
if (dataDisplays != null && dataDisplays.size() != 0) {
|
||||
baseMapper.dataDisplayAdd(dataDisplays);
|
||||
|
@ -423,7 +453,9 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
* @param kvt
|
||||
* @param tableName
|
||||
*/
|
||||
private void dataStructureAdd(Connection connection, Kvt kvt, String tableName) {
|
||||
|
||||
@Async
|
||||
public void dataStructureAdd(Connection connection, Kvt kvt, String tableName) {
|
||||
try {
|
||||
PreparedStatement preparedStatement = null;
|
||||
DataStructure build = null;
|
||||
|
@ -641,6 +673,7 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
|
||||
while (resultSet.next()) {
|
||||
String tableName = resultSet.getString("table_name");
|
||||
|
||||
//添加资产展示数据
|
||||
this.dataDisplayAdd(tableName, connection, kvt);
|
||||
//添加数据结构
|
||||
|
@ -776,6 +809,26 @@ public class KvtServiceImpl extends ServiceImpl<KvtMapper, Kvt> implements KvtSe
|
|||
return baseMapper.selectTableName(tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddDepartment(PermissionsUser permissionsUser) {
|
||||
//查询出permissionsUser根据deptId 查询部门的下面所有的部门以及所有的用户添加到permissionsUser
|
||||
List<SysDept> deptList = baseMapper.deptList();
|
||||
deptList.forEach(dept -> {
|
||||
if (dept.getParentId().equals(permissionsUser.getDeptId())) {
|
||||
permissionsUser.setDeptId(dept.getDeptId());
|
||||
permissionsUser.setTbaleName(permissionsUser.getTbaleName());
|
||||
baseMapper.permissionsUserAdd(permissionsUser);
|
||||
}
|
||||
if (dept.getChildren() != null) {
|
||||
dept.getChildren().forEach(children -> {
|
||||
permissionsUser.setDeptId(children.getDeptId());
|
||||
permissionsUser.setTbaleName(permissionsUser.getTbaleName());
|
||||
baseMapper.permissionsUserAdd(permissionsUser);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 根据库名跟表名查询字段信息
|
||||
*
|
||||
|
|
|
@ -110,4 +110,10 @@ public class SysDeptController extends BaseController {
|
|||
deptService.checkDeptDataScope(deptId);
|
||||
return toAjax(deptService.deleteDeptById(deptId));
|
||||
}
|
||||
//查询id查询子部门的
|
||||
@PostMapping("/selectDeptList")
|
||||
public Result<List<SysDept>> selectDeptList (@RequestBody Long deptId) {
|
||||
List<SysDept> list= deptService.selectNormalChildrenDeptByIds(deptId);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,4 +128,5 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
}
|
||||
|
|
|
@ -135,4 +135,7 @@ public interface SysDeptService extends IService<SysDept> {
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById (Long deptId);
|
||||
|
||||
|
||||
List<SysDept> selectNormalChildrenDeptByIds(Long deptId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.constant.UserConstants;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
|
@ -280,6 +281,15 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||
return deptMapper.deleteDeptById(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> selectNormalChildrenDeptByIds(Long deptId) {
|
||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysDept::getParentId, deptId);
|
||||
List<SysDept> list = this.list(queryWrapper);
|
||||
return list.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue