集成MP + 数据源注入

dev
1iyc 1 week ago
parent 2c844c6df5
commit 58a14e31c2

@ -20,6 +20,7 @@
<spring-framework.version>5.3.33</spring-framework.version>
<spring-security.version>5.7.12</spring-security.version>
<druid.version>1.2.23</druid.version>
<mp.version>3.4.1</mp.version>
<bitwalker.version>1.21</bitwalker.version>
<swagger.version>3.0.0</swagger.version>
<kaptcha.version>2.3.3</kaptcha.version>
@ -70,6 +71,20 @@
<version>${druid.version}</version>
</dependency>
<!-- Mybatis-Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mp.version}</version>
</dependency>
<!-- MyBatis-Plus 分页插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>${mp.version}</version>
</dependency>
<!-- 解析客户端操作系统、浏览器等 -->
<dependency>
<groupId>eu.bitwalker</groupId>
@ -77,12 +92,6 @@
<version>${bitwalker.version}</version>
</dependency>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.boot.version}</version>
</dependency>
<!-- 获取系统信息 -->
<dependency>
@ -181,6 +190,12 @@
<version>${sync.version}</version>
</dependency>
<dependency>
<groupId>com.lyr</groupId>
<artifactId>sync-gather</artifactId>
<version>${sync.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
@ -191,6 +206,7 @@
<module>sync-quartz</module>
<module>sync-generator</module>
<module>sync-common</module>
<module>sync-gather</module>
</modules>
<packaging>pom</packaging>

@ -61,6 +61,12 @@
<artifactId>sync-generator</artifactId>
</dependency>
<!-- 数据采集-->
<dependency>
<groupId>com.lyr</groupId>
<artifactId>sync-gather</artifactId>
</dependency>
</dependencies>

@ -33,7 +33,6 @@ public class SysLogininforController extends BaseController {
@PreAuthorize("@ss.hasPermi('monitor:logininfor:list')")
@GetMapping("/list")
public TableDataInfo list(SysLogininfor logininfor) {
startPage();
List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
return getDataTable(list);
}

@ -29,7 +29,7 @@ public class SysOperlogController extends BaseController {
@PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
@GetMapping("/list")
public TableDataInfo list(SysOperLog operLog) {
startPage();
List<SysOperLog> list = operLogService.selectOperLogList(operLog);
return getDataTable(list);
}

@ -33,7 +33,7 @@ public class SysConfigController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:config:list')")
@GetMapping("/list")
public TableDataInfo list(SysConfig config) {
startPage();
List<SysConfig> list = configService.selectConfigList(config);
return getDataTable(list);
}

@ -36,7 +36,7 @@ public class SysDictDataController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:dict:list')")
@GetMapping("/list")
public TableDataInfo list(SysDictData dictData) {
startPage();
List<SysDictData> list = dictDataService.selectDictDataList(dictData);
return getDataTable(list);
}

@ -30,7 +30,7 @@ public class SysDictTypeController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:dict:list')")
@GetMapping("/list")
public TableDataInfo list(SysDictType dictType) {
startPage();
List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
return getDataTable(list);
}

@ -31,7 +31,7 @@ public class SysNoticeController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:notice:list')")
@GetMapping("/list")
public TableDataInfo list(SysNotice notice) {
startPage();
List<SysNotice> list = noticeService.selectNoticeList(notice);
return getDataTable(list);
}

@ -33,7 +33,7 @@ public class SysPostController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:post:list')")
@GetMapping("/list")
public TableDataInfo list(SysPost post) {
startPage();
List<SysPost> list = postService.selectPostList(post);
return getDataTable(list);
}

@ -51,7 +51,7 @@ public class SysRoleController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/list")
public TableDataInfo list(SysRole role) {
startPage();
List<SysRole> list = roleService.selectRoleList(role);
return getDataTable(list);
}
@ -171,7 +171,7 @@ public class SysRoleController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/allocatedList")
public TableDataInfo allocatedList(SysUser user) {
startPage();
List<SysUser> list = userService.selectAllocatedList(user);
return getDataTable(list);
}
@ -182,7 +182,7 @@ public class SysRoleController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:role:list')")
@GetMapping("/authUser/unallocatedList")
public TableDataInfo unallocatedList(SysUser user) {
startPage();
List<SysUser> list = userService.selectUnallocatedList(user);
return getDataTable(list);
}

@ -52,7 +52,7 @@ public class SysUserController extends BaseController {
@PreAuthorize("@ss.hasPermi('system:user:list')")
@GetMapping("/list")
public TableDataInfo list(SysUser user) {
startPage();
List<SysUser> list = userService.selectUserList(user);
return getDataTable(list);
}

@ -0,0 +1,19 @@
package com.lyr.web.controller.tool;
import com.lyr.framework.manager.DataSourceManagerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author liyc
* @date 2024/10/30
* @description TODO
**/
@RestController("/dataSourceManager")
public class DataSourceManagerController {
}

@ -100,25 +100,23 @@ token:
# 令牌有效期默认30分钟
expireTime: 30
# MyBatis配置
mybatis:
# 搜索指定包别名
mybatis-plus:
typeAliasesPackage: com.lyr.**.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
helperDialect: mysql
supportMethodsArguments: true
params: count=countSql
mapperPackage: com.lyr.**.mapper
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
global-config:
db-config:
id-type: AUTO
banner: off
# Swagger配置
swagger:
# 是否开启swagger
enabled: true
enabled: false
# 请求前缀
pathMapping: /dev-api

@ -100,25 +100,23 @@ token:
# 令牌有效期默认30分钟
expireTime: 30
# MyBatis配置
mybatis:
# 搜索指定包别名
mybatis-plus:
typeAliasesPackage: com.lyr.**.domain
# 配置mapper的扫描找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
helperDialect: mysql
supportMethodsArguments: true
params: count=countSql
mapperPackage: com.lyr.**.mapper
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
global-config:
db-config:
id-type: AUTO
banner: off
# Swagger配置
swagger:
# 是否开启swagger
enabled: true
enabled: false
# 请求前缀
pathMapping: /dev-api

@ -35,11 +35,6 @@
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<!-- 自定义验证注解 -->
<dependency>

@ -1,18 +1,12 @@
package com.lyr.common.core.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lyr.common.constant.HttpStatus;
import com.lyr.common.core.domain.AjaxResult;
import com.lyr.common.core.domain.model.LoginUser;
import com.lyr.common.core.page.PageDomain;
import com.lyr.common.core.page.TableDataInfo;
import com.lyr.common.core.page.TableSupport;
import com.lyr.common.utils.DateUtils;
import com.lyr.common.utils.PageUtils;
import com.lyr.common.utils.SecurityUtils;
import com.lyr.common.utils.StringUtils;
import com.lyr.common.utils.sql.SqlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
@ -44,31 +38,6 @@ public class BaseController {
});
}
/**
*
*/
protected void startPage() {
PageUtils.startPage();
}
/**
*
*/
protected void startOrderBy() {
PageDomain pageDomain = TableSupport.buildPageRequest();
if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) {
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
PageHelper.orderBy(orderBy);
}
}
/**
* 线
*/
protected void clearPage() {
PageUtils.clearPage();
}
/**
*
*/
@ -78,7 +47,7 @@ public class BaseController {
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
rspData.setRows(list);
rspData.setTotal(new PageInfo(list).getTotal());
// rspData.setTotal(new Page(list).getTotal());
return rspData;
}

@ -1,32 +0,0 @@
package com.lyr.common.utils;
import com.github.pagehelper.PageHelper;
import com.lyr.common.core.page.PageDomain;
import com.lyr.common.core.page.TableSupport;
import com.lyr.common.utils.sql.SqlUtil;
/**
*
*
* @author ruoyi
*/
public class PageUtils extends PageHelper {
/**
*
*/
public static void startPage() {
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
Boolean reasonable = pageDomain.getReasonable();
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
}
/**
* 线
*/
public static void clearPage() {
PageHelper.clearPage();
}
}

@ -35,6 +35,22 @@
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.8.1.jre8</version>
</dependency>
<!-- 验证码 -->
<dependency>
<groupId>pro.fessional</groupId>

@ -18,7 +18,6 @@ import org.springframework.context.annotation.Primary;
import javax.servlet.*;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
@ -46,10 +45,15 @@ public class DruidConfig {
@Bean(name = "dynamicDataSource")
@Primary
public DynamicDataSource dataSource(DataSource masterDataSource) {
Map<Object, Object> targetDataSources = new HashMap<>();
DynamicDataSource dynamicDataSource = new DynamicDataSource();
dynamicDataSource.setDefaultTargetDataSource(masterDataSource);
dynamicDataSource.addTargetDataSource(DataSourceType.MASTER.name(), masterDataSource);
dynamicDataSource.addTargetDataSource(DataSourceType.SLAVE.name(), "slaveDataSource");
return dynamicDataSource;
/* Map<Object, Object> targetDataSources = new HashMap<>();
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
return new DynamicDataSource(masterDataSource, targetDataSources);
return new DynamicDataSource(masterDataSource, targetDataSources);*/
}
/**
@ -87,8 +91,7 @@ public class DruidConfig {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
// 重置缓冲区,响应头不会被重置
response.resetBuffer();
@ -109,4 +112,6 @@ public class DruidConfig {
registrationBean.addUrlPatterns(commonJsPattern);
return registrationBean;
}
}

@ -1,29 +1,10 @@
package com.lyr.framework.config;
import com.lyr.common.utils.StringUtils;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.ClassUtils;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Mybatis*
@ -31,79 +12,14 @@ import java.util.List;
* @author ruoyi
*/
@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
public class MyBatisConfig {
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
@Autowired
private Environment env;
public static String setTypeAliasesPackage(String typeAliasesPackage) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
List<String> allResult = new ArrayList<String>();
try {
for (String aliasesPackage : typeAliasesPackage.split(",")) {
List<String> result = new ArrayList<String>();
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
Resource[] resources = resolver.getResources(aliasesPackage);
if (resources != null && resources.length > 0) {
MetadataReader metadataReader = null;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
try {
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
if (result.size() > 0) {
HashSet<String> hashResult = new HashSet<String>(result);
allResult.addAll(hashResult);
}
}
if (allResult.size() > 0) {
typeAliasesPackage = String.join(",", allResult.toArray(new String[0]));
} else {
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
}
} catch (IOException e) {
e.printStackTrace();
}
return typeAliasesPackage;
}
public Resource[] resolveMapperLocations(String[] mapperLocations) {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<Resource> resources = new ArrayList<Resource>();
if (mapperLocations != null) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
// ignore
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
String mapperLocations = env.getProperty("mybatis.mapperLocations");
String configLocation = env.getProperty("mybatis.configLocation");
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
VFS.addImplClass(SpringBootVFS.class);
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
return sessionFactory.getObject();
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}

@ -112,6 +112,7 @@ public class SecurityConfig {
// 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
.antMatchers("/gather/*", "/gather/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();
})

@ -1,9 +1,12 @@
package com.lyr.framework.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import com.lyr.common.utils.spring.SpringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import javax.sql.DataSource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
@ -11,14 +14,52 @@ import java.util.Map;
* @author ruoyi
*/
public class DynamicDataSource extends AbstractRoutingDataSource {
private static Map<Object, Object> targetDataSources = new ConcurrentHashMap<>();
@Override
protected Object determineCurrentLookupKey() {
return DynamicDataSourceContextHolder.getDataSourceType();
}
public DynamicDataSource() {
super.setTargetDataSources(targetDataSources);
}
public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) {
super.setDefaultTargetDataSource(defaultTargetDataSource);
super.setTargetDataSources(targetDataSources);
super.afterPropertiesSet();
}
@Override
protected Object determineCurrentLookupKey() {
return DynamicDataSourceContextHolder.getDataSourceType();
public void addTargetDataSource(Object key, Object dataSource) {
if (dataSource instanceof String) {
try {
SpringUtils.getBean(dataSource.toString());
this.targetDataSources.put(key, dataSource);
} catch (Exception e) {
}
} else {
this.targetDataSources.put(key, dataSource);
}
super.afterPropertiesSet(); // 重新初始化数据源
}
public void removeTargetDataSource(Object key) {
this.targetDataSources.remove(key);
super.afterPropertiesSet(); // 重新初始化数据源
}
public void print() {
DruidDataSource resolvedDefaultDataSource = (DruidDataSource) getResolvedDefaultDataSource();
System.out.println("主数据源:" + resolvedDefaultDataSource.getUrl());
Map<Object, DataSource> resolvedDataSources = getResolvedDataSources();
for (Map.Entry<Object, DataSource> entry : resolvedDataSources.entrySet()) {
DruidDataSource value = (DruidDataSource) entry.getValue();
System.out.println("数据源[" + entry.getKey() + "]:" + value.getUrl());
}
}
}

@ -0,0 +1,57 @@
package com.lyr.framework.manager;
import com.lyr.framework.datasource.DynamicDataSource;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.sql.DataSource;
/**
* @author liyc
* @date 2024/10/30
* @description TODO
**/
@Component
public class DataSourceManagerService implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Resource
private DynamicDataSource dynamicDataSource;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
public void print() {
dynamicDataSource.print();
}
public void registerDataSources(String beanName, DataSource dataSource) {
DataSource resolvedDefaultDataSource = dynamicDataSource.getResolvedDefaultDataSource();
dynamicDataSource.setDefaultTargetDataSource(resolvedDefaultDataSource);
dynamicDataSource.addTargetDataSource(beanName, dataSource);
}
public void add() {
/* // 构建数据源
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:sqlserver://192.168.3.28:1433;DatabaseName=BiDataDeYue;encrypt=true;trustServerCertificate=true;");
dataSource.setUsername("sa");
dataSource.setPassword("mssql_whdZeB");
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
try {
DataSource resolvedDefaultDataSource = dynamicDataSource.getResolvedDefaultDataSource();
dynamicDataSource.setDefaultTargetDataSource(resolvedDefaultDataSource);
dynamicDataSource.addTargetDataSource("deYueMssql", dataSource);
} catch (BeansException e) {
}*/
}
}

@ -13,6 +13,7 @@ import com.lyr.common.utils.MessageUtils;
import com.lyr.common.utils.StringUtils;
import com.lyr.common.utils.ip.IpUtils;
import com.lyr.framework.manager.AsyncManager;
import com.lyr.framework.manager.DataSourceManagerService;
import com.lyr.framework.manager.factory.AsyncFactory;
import com.lyr.framework.security.context.AuthenticationContextHolder;
import com.lyr.system.service.ISysConfigService;

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.lyr</groupId>
<artifactId>sync</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>sync-gather</artifactId>
<description>
数据采集模块
</description>
<dependencies>
<!-- 通用工具-->
<dependency>
<groupId>com.lyr</groupId>
<artifactId>sync-common</artifactId>
</dependency>
<!-- 框架 -->
<dependency>
<groupId>com.lyr</groupId>
<artifactId>sync-framework</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,34 @@
package com.lyr.gather.controller;
import com.lyr.gather.service.DataSourceConfigService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* @author liyc
* @date 2024/10/30
* @description TODO
**/
@RestController
@RequestMapping("/gather")
public class DataSourceConfigController {
@Resource
private DataSourceConfigService dataSourceConfigService;
@GetMapping("/print")
public void print() {
dataSourceConfigService.print();
}
@GetMapping("/add")
public void add() {
dataSourceConfigService.add();
}
}

@ -0,0 +1,68 @@
package com.lyr.gather.domain.vo;
import com.lyr.common.annotation.Excel;
import lombok.Data;
/**
* @author liyc
* @date 2024/10/30
* @description TODO
**/
@Data
public class DataSourceConfig {
private static final long serialVersionUID = 1L;
/**
*
*/
private Long id;
/**
*
*/
@Excel(name = "数据源的唯一名称,用于标识不同的数据源")
private String name;
/**
* MySQL, PostgreSQL
*/
@Excel(name = "数据库类型,例如 MySQL, PostgreSQL 等")
private String dbType;
/**
* URL
*/
@Excel(name = "数据库连接URL")
private String url;
/**
*
*/
@Excel(name = "数据库用户名")
private String username;
/**
*
*/
@Excel(name = "数据库密码")
private String password;
/**
*
*/
@Excel(name = "数据库驱动类名")
private String driverClassName;
@Excel(name = "bean名称")
private String beanName;
/**
* 1 0
*/
@Excel(name = "是否启用该数据源1 表示启用0 表示禁用")
private Integer isEnabled;
}

@ -0,0 +1,7 @@
package com.lyr.gather.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lyr.gather.domain.vo.DataSourceConfig;
public interface DataSourceConfigMapper extends BaseMapper<DataSourceConfig> {
}

@ -0,0 +1,11 @@
package com.lyr.gather.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.lyr.gather.domain.vo.DataSourceConfig;
public interface DataSourceConfigService extends IService<DataSourceConfig> {
void print();
void add();
}

@ -0,0 +1,48 @@
package com.lyr.gather.service.impl;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyr.framework.manager.DataSourceManagerService;
import com.lyr.gather.domain.vo.DataSourceConfig;
import com.lyr.gather.mapper.DataSourceConfigMapper;
import com.lyr.gather.service.DataSourceConfigService;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
@Service
public class DataSourceConfigServiceImpl extends ServiceImpl<DataSourceConfigMapper, DataSourceConfig> implements DataSourceConfigService {
@Resource
private DataSourceManagerService dataSourceManagerService;
@PostConstruct
private void registered() {
List<DataSourceConfig> configList = this.lambdaQuery().eq(DataSourceConfig::getIsEnabled, 1).list();
configList.stream().forEach(e -> {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(e.getDriverClassName());
dataSource.setUrl(e.getUrl());
dataSource.setUsername(e.getUsername());
dataSource.setPassword(e.getPassword());
dataSourceManagerService.registerDataSources(e.getBeanName(), dataSource);
});
}
@Override
public void print() {
dataSourceManagerService.print();
}
@Override
public void add() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:sqlserver://192.168.3.28:1433;DatabaseName=BiDataDeYue;encrypt=true;trustServerCertificate=true;");
dataSource.setUsername("sa");
dataSource.setPassword("mssql_whdZeB");
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dataSourceManagerService.registerDataSources("biDataDeYue", dataSource);
}
}

@ -49,7 +49,7 @@ public class GenController extends BaseController {
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/list")
public TableDataInfo genList(GenTable genTable) {
startPage();
List<GenTable> list = genTableService.selectGenTableList(genTable);
return getDataTable(list);
}
@ -76,7 +76,7 @@ public class GenController extends BaseController {
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
@GetMapping("/db/list")
public TableDataInfo dataList(GenTable genTable) {
startPage();
List<GenTable> list = genTableService.selectDbTableList(genTable);
return getDataTable(list);
}

@ -44,7 +44,7 @@ public class ${ClassName}Controller extends BaseController {
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className}) {
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
}

@ -44,7 +44,7 @@ public class ${ClassName}Controller extends BaseController {
@GetMapping("/list")
#if($table.crud || $table.sub)
public TableDataInfo list(${ClassName} ${className}) {
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
}

@ -38,7 +38,7 @@ public class SysJobController extends BaseController {
@PreAuthorize("@ss.hasPermi('monitor:job:list')")
@GetMapping("/list")
public TableDataInfo list(SysJob sysJob) {
startPage();
List<SysJob> list = jobService.selectJobList(sysJob);
return getDataTable(list);
}

@ -32,7 +32,7 @@ public class SysJobLogController extends BaseController {
@PreAuthorize("@ss.hasPermi('monitor:job:list')")
@GetMapping("/list")
public TableDataInfo list(SysJobLog sysJobLog) {
startPage();
List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
return getDataTable(list);
}

@ -23,6 +23,16 @@
<artifactId>sync-common</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
</dependencies>
</project>

@ -1,5 +1,6 @@
package com.lyr.system.domain;
import com.lyr.common.utils.StringUtils;
/**

@ -1,5 +1,6 @@
package com.lyr.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lyr.common.core.domain.entity.SysDept;
import org.apache.ibatis.annotations.Param;
@ -10,7 +11,7 @@ import java.util.List;
*
* @author ruoyi
*/
public interface SysDeptMapper {
public interface SysDeptMapper extends BaseMapper<SysDept> {
/**
*
*

@ -2,6 +2,7 @@ package com.lyr.system.service.impl;
import com.lyr.common.core.domain.entity.SysDictData;
import com.lyr.common.utils.DictUtils;
import com.lyr.common.utils.spring.SpringUtils;
import com.lyr.system.mapper.SysDictDataMapper;
import com.lyr.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;

@ -23,8 +23,18 @@
</resultMap>
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
d.del_flag, d.create_by, d.create_time
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.phone,
d.email,
d.status,
d.del_flag,
d.create_by,
d.create_time
from sys_dept d
</sql>
@ -61,27 +71,47 @@
</select>
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.phone,
d.email,
d.status,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
from sys_dept d
where d.dept_id = #{deptId}
</select>
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
select count(1)
from sys_user
where dept_id = #{deptId}
and del_flag = '0'
</select>
<select id="hasChildByDeptId" parameterType="Long" resultType="int">
select count(1) from sys_dept
where del_flag = '0' and parent_id = #{deptId} limit 1
select count(1)
from sys_dept
where del_flag = '0'
and parent_id = #{deptId}
limit 1
</select>
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
select * from sys_dept where find_in_set(#{deptId}, ancestors)
select *
from sys_dept
where find_in_set(#{deptId}, ancestors)
</select>
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
select count(*)
from sys_dept
where status = 0
and del_flag = '0'
and find_in_set(#{deptId}, ancestors)
</select>
<select id="checkDeptNameUnique" resultMap="SysDeptResult">
@ -155,7 +185,9 @@
</update>
<delete id="deleteDeptById" parameterType="Long">
update sys_dept set del_flag = '2' where dept_id = #{deptId}
update sys_dept
set del_flag = '2'
where dept_id = #{deptId}
</delete>
</mapper>

@ -23,8 +23,18 @@
</resultMap>
<sql id="selectDeptVo">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
d.del_flag, d.create_by, d.create_time
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.phone,
d.email,
d.status,
d.del_flag,
d.create_by,
d.create_time
from sys_dept d
</sql>
@ -61,27 +71,47 @@
</select>
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
select d.dept_id,
d.parent_id,
d.ancestors,
d.dept_name,
d.order_num,
d.leader,
d.phone,
d.email,
d.status,
(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
from sys_dept d
where d.dept_id = #{deptId}
</select>
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
select count(1)
from sys_user
where dept_id = #{deptId}
and del_flag = '0'
</select>
<select id="hasChildByDeptId" parameterType="Long" resultType="int">
select count(1) from sys_dept
where del_flag = '0' and parent_id = #{deptId} limit 1
select count(1)
from sys_dept
where del_flag = '0'
and parent_id = #{deptId}
limit 1
</select>
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
select * from sys_dept where find_in_set(#{deptId}, ancestors)
select *
from sys_dept
where find_in_set(#{deptId}, ancestors)
</select>
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
select count(*) from sys_dept where status = 0 and del_flag = '0' and find_in_set(#{deptId}, ancestors)
select count(*)
from sys_dept
where status = 0
and del_flag = '0'
and find_in_set(#{deptId}, ancestors)
</select>
<select id="checkDeptNameUnique" resultMap="SysDeptResult">
@ -155,7 +185,9 @@
</update>
<delete id="deleteDeptById" parameterType="Long">
update sys_dept set del_flag = '2' where dept_id = #{deptId}
update sys_dept
set del_flag = '2'
where dept_id = #{deptId}
</delete>
</mapper>
Loading…
Cancel
Save