opt:增加主从同步功能
This commit is contained in:
@@ -113,6 +113,11 @@
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shardingsphere</groupId>
|
||||
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
|
||||
<version>5.1.1</version>
|
||||
</dependency>
|
||||
<!--Spring boot 核心 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -201,8 +206,8 @@
|
||||
<!-- druid数据源驱动 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>${druid.version}</version>
|
||||
<artifactId>druid</artifactId>
|
||||
<version>1.1.20</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Primary;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
//@Configuration
|
||||
@Slf4j
|
||||
public class DataBaseConfig {
|
||||
|
||||
|
||||
@@ -30,18 +30,18 @@ public class MybatisPlusConfig {
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
// // 分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
//乐观锁插件
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void datainnit() {
|
||||
String url = ((DruidDataSource) dataSource).getUrl();
|
||||
System.out.println("项目数据库地址:" + url);
|
||||
log.debug("项目数据库地址:{}", url);
|
||||
}
|
||||
// @PostConstruct
|
||||
// public void datainnit() {
|
||||
// String url = ((DruidDataSource) dataSource).getUrl();
|
||||
// System.out.println("项目数据库地址:" + url);
|
||||
// log.debug("项目数据库地址:{}", url);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class WQLCore {
|
||||
//解析wql文件的根目录
|
||||
public static String ROOT = "wql";
|
||||
//数据库默认名
|
||||
public static String defalutDBName = "dataSource";
|
||||
public static String defalutDBName = "shardingSphereDataSource";
|
||||
//wql源文件
|
||||
public static HashMap<String, ArrayList<String>> wqlMap = new HashMap<String, ArrayList<String>>();
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class WQLObject implements Serializable, Cloneable {
|
||||
private static final long serialVersionUID = 3512111887957792224L;
|
||||
|
||||
|
||||
private String dbname = "dataSource"; //指定使用的数据库
|
||||
private String dbname = "shardingSphereDataSource"; //指定使用的数据库
|
||||
|
||||
public WQLObject setDbname(String dbname) {
|
||||
this.dbname = dbname;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
* 创 建 者 :yumeng
|
||||
* 创建时间:2014-07-01 14:25:35
|
||||
* 文件版本:v1.0
|
||||
* 文件版本:v1.0
|
||||
*
|
||||
*******************************************************/
|
||||
package org.nl.modules.wql.core.engine.object;
|
||||
@@ -47,7 +47,7 @@ public class WO implements Serializable, Cloneable {
|
||||
public WP wp;
|
||||
|
||||
private String code = ""; //当前交易编号
|
||||
private String dbname = "dataSource"; //指定使用的数据库
|
||||
private String dbname = "shardingSphereDataSource"; //指定使用的数据库
|
||||
|
||||
public WO setDbname(String dbname) {
|
||||
this.dbname = dbname;
|
||||
@@ -368,7 +368,7 @@ public class WO implements Serializable, Cloneable {
|
||||
// //this.wp.conn = null;
|
||||
//// this.wp.utx=null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } else {
|
||||
// try {
|
||||
//// if(this.wp.utx!=null){
|
||||
@@ -410,7 +410,7 @@ public class WO implements Serializable, Cloneable {
|
||||
// DBConnection.freeConnection(this.wp.conn,this.dbname);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if(this.wp._success){
|
||||
// log.debug(this.code+"执行成功");
|
||||
// this.wp.rb.setSucess(1);
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
@@ -32,6 +34,7 @@ import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.system.service.user.ISysUserService;
|
||||
import org.nl.system.service.user.dao.SysUser;
|
||||
import org.nl.system.service.user.dto.SysUserDetail;
|
||||
import org.nl.system.service.user.dto.UserQuery;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -39,6 +42,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -58,7 +62,11 @@ public class UserController {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(UserQuery query, PageQuery page) {
|
||||
return new ResponseEntity(TableDataInfo.build(userService.getUserDetail(query, page)), HttpStatus.OK);
|
||||
Page<Object> startPage = PageHelper.startPage(page.getPage() + 1, page.getSize());
|
||||
List<SysUserDetail> userDetail = userService.getUserDetail(query, page);
|
||||
TableDataInfo<SysUserDetail> build = TableDataInfo.build(userDetail);
|
||||
build.setTotalElements(startPage.getTotal());
|
||||
return new ResponseEntity(build, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增用户")
|
||||
|
||||
@@ -55,13 +55,8 @@
|
||||
<result column="updateTime" property="update_time"/>
|
||||
<result column="extpersonId" property="extperson_id"/>
|
||||
<result column="extuserId" property="extuser_id"/>
|
||||
<collection property="depts" ofType="org.nl.system.service.dept.dao.SysDept">
|
||||
<id property="dept_id" column="dept_id"/>
|
||||
<result column="dept_name" property="name"/>
|
||||
</collection>
|
||||
<collection property="roles" ofType="org.nl.system.service.role.dao.SysRole">
|
||||
<id property="role_id" column="role_id"/>
|
||||
</collection>
|
||||
<collection property="depts" ofType="org.nl.system.service.dept.dao.SysDept" column="user_id" select="selectDept"></collection>
|
||||
<collection property="roles" ofType="org.nl.system.service.role.dao.SysRole" column="user_id" select="selectRole"></collection>
|
||||
</resultMap>
|
||||
<select id="getUserDetail" resultMap="UserDetail">
|
||||
SELECT
|
||||
@@ -93,7 +88,20 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDept" resultType="org.nl.system.service.dept.dao.SysDept">
|
||||
select
|
||||
sys_dept.dept_id as deptId,
|
||||
sys_dept.name as name
|
||||
from sys_dept
|
||||
left join sys_user_dept
|
||||
on sys_user_dept.dept_id = sys_dept.dept_id
|
||||
where user_id = #{user_id}
|
||||
</select>
|
||||
<select id="selectRole" resultType="org.nl.system.service.role.dao.SysRole">
|
||||
select role_id as roleId
|
||||
from sys_users_roles
|
||||
where user_id = #{user_id}
|
||||
</select>
|
||||
<select id="getDetailForMap" resultType="java.util.Map">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
@@ -121,7 +122,7 @@ public class ISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> imp
|
||||
}
|
||||
}, Date.class);
|
||||
try {
|
||||
|
||||
|
||||
BeanUtils.populate(sysUser, userDetail);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
|
||||
@@ -480,7 +480,7 @@ public class ClassstandardServiceImpl implements ClassstandardService {
|
||||
|
||||
//添加子节点
|
||||
try {
|
||||
List<Entity> list = Db.use((DataSource) SpringContextHolder.getBean("dataSource")).query(sql);
|
||||
List<Entity> list = Db.use((DataSource) SpringContextHolder.getBean("shardingSphereDataSource")).query(sql);
|
||||
list.forEach(item -> {
|
||||
set.add(item.getStr("class_id"));
|
||||
});
|
||||
|
||||
@@ -2,58 +2,103 @@ server:
|
||||
port: 9999
|
||||
#配置数据源
|
||||
spring:
|
||||
datasource:
|
||||
druid:
|
||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:88lmsdb}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl_lms5}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||
username: ${DB_USER:root}
|
||||
# password: ${DB_PWD:NLABC&hl123}
|
||||
password: ${DB_PWD:12356}
|
||||
# 初始连接数
|
||||
initial-size: 5
|
||||
# 最小连接数
|
||||
min-idle: 15
|
||||
# 最大连接数
|
||||
max-active: 30
|
||||
# 超时时间(以秒数为单位)
|
||||
remove-abandoned-timeout: 180
|
||||
# 获取连接超时时间
|
||||
max-wait: 3000
|
||||
# 连接有效性检测时间
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 连接在池中最小生存的时间
|
||||
min-evictable-idle-time-millis: 300000
|
||||
# 连接在池中最大生存的时间
|
||||
max-evictable-idle-time-millis: 900000
|
||||
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
|
||||
test-while-idle: true
|
||||
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个
|
||||
test-on-borrow: true
|
||||
# 是否在归还到池中前进行检验
|
||||
test-on-return: false
|
||||
# 检测连接是否有效
|
||||
validation-query: select 1
|
||||
# 配置监控统计
|
||||
webStatFilter:
|
||||
enabled: true
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
filters:
|
||||
DruidFilter,stat
|
||||
# query-timeout: 1
|
||||
# stat:
|
||||
# enabled: true
|
||||
# # 记录慢SQL
|
||||
# log-slow-sql: true
|
||||
# slow-sql-millis: 1000
|
||||
# merge-sql: true
|
||||
# wall:
|
||||
# config:
|
||||
# multi-statement-allow: true
|
||||
shardingsphere:
|
||||
datasource:
|
||||
names: master,slave
|
||||
master:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 初始连接数
|
||||
initial-size: 20
|
||||
# 最小连接数
|
||||
min-idle: 30
|
||||
# 最大连接数
|
||||
max-active: 300
|
||||
# 是否自动回收超时连接
|
||||
socket-timeout: 10
|
||||
query-time-out: 7
|
||||
transaction-query-timeout: 30
|
||||
# 获取连接超时时间
|
||||
max-wait: 4000
|
||||
# 连接有效性检测时间
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 连接在池中最小生存的时间
|
||||
min-evictable-idle-time-millis: 300000
|
||||
# 连接在池中最大生存的时间
|
||||
max-evictable-idle-time-millis: 900000
|
||||
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
|
||||
test-while-idle: true
|
||||
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个
|
||||
test-on-borrow: true
|
||||
# 是否在归还到池中前进行检验
|
||||
test-on-return: false
|
||||
# 检测连接是否有效
|
||||
validation-query: select 1
|
||||
# 配置监控统计
|
||||
webStatFilter:
|
||||
enabled: true
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
filters:
|
||||
DruidFilter,stat
|
||||
url: jdbc:mysql://localhost:3306/lms?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 123456
|
||||
slave:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 初始连接数
|
||||
initial-size: 20
|
||||
# 最小连接数
|
||||
min-idle: 30
|
||||
# 最大连接数
|
||||
max-active: 300
|
||||
# 是否自动回收超时连接
|
||||
socket-timeout: 10
|
||||
query-time-out: 7
|
||||
transaction-query-timeout: 30
|
||||
# 获取连接超时时间
|
||||
max-wait: 4000
|
||||
# 连接有效性检测时间
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 连接在池中最小生存的时间
|
||||
min-evictable-idle-time-millis: 300000
|
||||
# 连接在池中最大生存的时间
|
||||
max-evictable-idle-time-millis: 900000
|
||||
# 指明连接是否被空闲连接回收器(如果有)进行检验.如果检测失败,则连接将被从池中去除
|
||||
test-while-idle: true
|
||||
# 指明是否在从池中取出连接前进行检验,如果检验失败, 则从池中去除连接并尝试取出另一个
|
||||
test-on-borrow: true
|
||||
# 是否在归还到池中前进行检验
|
||||
test-on-return: false
|
||||
# 检测连接是否有效
|
||||
validation-query: select 1
|
||||
# 配置监控统计
|
||||
webStatFilter:
|
||||
enabled: true
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
reset-enable: false
|
||||
filters:
|
||||
DruidFilter,stat
|
||||
url: jdbc:mysql://localhost:3306/lms?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: 123456
|
||||
rules:
|
||||
readwrite-splitting:
|
||||
data-sources:
|
||||
db:
|
||||
type: Static
|
||||
props:
|
||||
#接口有事务,读写分离不生效,默认全部使用主库
|
||||
write-data-source-name: master
|
||||
read-data-source-names: slave
|
||||
#负载均衡算法名称
|
||||
load-balancer-name: round-robin
|
||||
|
||||
redis:
|
||||
#数据库索引
|
||||
database: ${REDIS_DB:15}
|
||||
|
||||
@@ -16,10 +16,11 @@ spring:
|
||||
initial-size: 5
|
||||
# 最小连接数
|
||||
min-idle: 15
|
||||
socket-timeout: 10
|
||||
# 最大连接数
|
||||
query-time-out: 5
|
||||
transaction-query-timeout: 20
|
||||
max-active: 220
|
||||
# 超时时间(以秒数为单位)
|
||||
remove-abandoned-timeout: 180
|
||||
# 获取连接超时时间
|
||||
max-wait: 2000
|
||||
# 连接有效性检测时间
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"dev": "vue-cli-service serve",
|
||||
"dev2": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
|
||||
"build:prod": "vue-cli-service build",
|
||||
"build:prod": "export NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build",
|
||||
"build:stage": "vue-cli-service build --mode staging",
|
||||
"preview": "node build/index.js --preview",
|
||||
"lint": "eslint --ext .js,.vue src",
|
||||
|
||||
@@ -142,7 +142,7 @@
|
||||
style="width: 100%;"
|
||||
@selection-change="crud.selectionChangeHandler"
|
||||
>
|
||||
<el-table-column :selectable="checkboxT" type="selection" width="55" />
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="username" label="用户名" :min-width="flexWidth('username',crud.data,'用户名')" />
|
||||
<el-table-column
|
||||
prop="person_name"
|
||||
@@ -260,7 +260,7 @@
|
||||
style="width: 100%;"
|
||||
@selection-change="getRows"
|
||||
>
|
||||
<el-table-column :selectable="checkboxT" type="selection" width="55" />
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="label" label="权限范围" />
|
||||
<el-table-column label="数据权限">
|
||||
<template slot-scope="scope">
|
||||
|
||||
Reference in New Issue
Block a user