opt:增加主从同步功能

This commit is contained in:
zhangzq
2025-02-10 15:55:28 +08:00
parent 6e94f7f4f3
commit 856a48ac22
14 changed files with 153 additions and 85 deletions

View File

@@ -9,7 +9,7 @@ import org.springframework.context.annotation.Primary;
import javax.sql.DataSource;
@Configuration
//@Configuration
@Slf4j
public class DataBaseConfig {

View File

@@ -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);
// }
}

View File

@@ -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>>();

View File

@@ -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;

View File

@@ -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);

View File

@@ -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("新增用户")

View File

@@ -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"/>

View File

@@ -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();

View File

@@ -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"));
});