|
|
|
@ -5,7 +5,12 @@ import java.io.IOException;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.utils.uuid.UUID;
|
|
|
|
|
import com.ruoyi.system.api.domain.SysUser;
|
|
|
|
|
import com.ruoyi.system.domain.SysUserDatasource;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserDatasourceService;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
@ -37,6 +42,12 @@ public class SysDatasourceController extends BaseController
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDatasourceService sysDatasourceService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserDatasourceService sysUserDatasourceService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询数据管理列表
|
|
|
|
|
*/
|
|
|
|
@ -82,6 +93,8 @@ public class SysDatasourceController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
UUID uuid = UUID.randomUUID();
|
|
|
|
|
sysDatasource.setId(uuid.toString());
|
|
|
|
|
//将数据源分配给管理员
|
|
|
|
|
AddUserDataSource(sysDatasource);
|
|
|
|
|
return toAjax(sysDatasourceService.insertSysDatasource(sysDatasource));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,6 +117,56 @@ public class SysDatasourceController extends BaseController
|
|
|
|
|
@DeleteMapping("/{ids}")
|
|
|
|
|
public AjaxResult remove(@PathVariable String[] ids)
|
|
|
|
|
{
|
|
|
|
|
//删除已经分配的数据源
|
|
|
|
|
DeleteUserDataSource(ids);
|
|
|
|
|
return toAjax(sysDatasourceService.deleteSysDatasourceByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 每次增加数据源均分配给超级管理员
|
|
|
|
|
* @param sysDatasource
|
|
|
|
|
*/
|
|
|
|
|
public void AddUserDataSource(SysDatasource sysDatasource){
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
SysUser sysUser = userService.selectUserByUserName("admin");
|
|
|
|
|
SysUserDatasource sysUserDatasource = new SysUserDatasource();
|
|
|
|
|
sysUserDatasource.setUserId(sysUser.getUserId().toString());
|
|
|
|
|
sysUserDatasource.setDatasourceId(sysDatasource.getId());
|
|
|
|
|
int i = sysUserDatasourceService.insertSysUserDatasource(sysUserDatasource);
|
|
|
|
|
if(i>0){
|
|
|
|
|
logger.info("数据源:"+sysDatasource.getParkName()+";分配成功!");
|
|
|
|
|
}else {
|
|
|
|
|
logger.info("数据源:"+sysDatasource.getParkName()+";分配成功!");
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
logger.error("数据源分配异常:"+ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除绑定信息
|
|
|
|
|
* @param ids
|
|
|
|
|
*/
|
|
|
|
|
public void DeleteUserDataSource(String[] ids){
|
|
|
|
|
try{
|
|
|
|
|
for (String id : ids) {
|
|
|
|
|
SysUserDatasource sysUserDatasource = new SysUserDatasource();
|
|
|
|
|
sysUserDatasource.setDatasourceId(id);
|
|
|
|
|
List<SysUserDatasource> sysUserDatasources = sysUserDatasourceService.selectSysUserDatasourceList(sysUserDatasource);
|
|
|
|
|
if(sysUserDatasources.size() > 0){
|
|
|
|
|
Long[] ageArray = sysUserDatasources.stream()
|
|
|
|
|
.map(SysUserDatasource::getId)
|
|
|
|
|
.toArray(Long[]::new);
|
|
|
|
|
|
|
|
|
|
int i = sysUserDatasourceService.deleteSysUserDatasourceByIds(ageArray);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
logger.error("删除绑定数据信息异常:"+ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|