parent
6b6658f9a1
commit
09b96b5cfa
@ -0,0 +1,19 @@
|
||||
package com.ruoyi.common.core.exception.auth;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 登录过期异常
|
||||
*
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/6
|
||||
*/
|
||||
public class LoginExpiredException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public LoginExpiredException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
package com.ruoyi.common.core.exception.auth;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 未能通过的登录认证异常
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class NotLoginException extends RuntimeException
|
||||
{
|
||||
public class NotLoginException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NotLoginException(String message)
|
||||
{
|
||||
public NotLoginException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
@ -1,79 +1,72 @@
|
||||
package com.ruoyi.common.core.exception.base;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 基础异常
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class BaseException extends RuntimeException
|
||||
{
|
||||
public class BaseException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
private String module;
|
||||
private final String module;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private String code;
|
||||
private final String code;
|
||||
|
||||
/**
|
||||
* 错误码对应的参数
|
||||
*/
|
||||
private Object[] args;
|
||||
private final Object[] args;
|
||||
|
||||
/**
|
||||
* 错误消息
|
||||
*/
|
||||
private String defaultMessage;
|
||||
private final String defaultMessage;
|
||||
|
||||
public BaseException(String module, String code, Object[] args, String defaultMessage)
|
||||
{
|
||||
public BaseException(String module, String code, Object[] args, String defaultMessage) {
|
||||
this.module = module;
|
||||
this.code = code;
|
||||
this.args = args;
|
||||
this.defaultMessage = defaultMessage;
|
||||
}
|
||||
|
||||
public BaseException(String module, String code, Object[] args)
|
||||
{
|
||||
public BaseException(String module, String code, Object[] args) {
|
||||
this(module, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String module, String defaultMessage)
|
||||
{
|
||||
public BaseException(String module, String defaultMessage) {
|
||||
this(module, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
public BaseException(String code, Object[] args)
|
||||
{
|
||||
public BaseException(String code, Object[] args) {
|
||||
this(null, code, args, null);
|
||||
}
|
||||
|
||||
public BaseException(String defaultMessage)
|
||||
{
|
||||
public BaseException(String defaultMessage) {
|
||||
this(null, null, null, defaultMessage);
|
||||
}
|
||||
|
||||
public String getModule()
|
||||
{
|
||||
public String getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public Object[] getArgs()
|
||||
{
|
||||
public Object[] getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public String getDefaultMessage()
|
||||
{
|
||||
public String getDefaultMessage() {
|
||||
return defaultMessage;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package com.ruoyi.common.datascope.mybatis;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/6
|
||||
*/
|
||||
@Configuration
|
||||
public class MyBatisConfig {
|
||||
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
//添加MyBatis插件
|
||||
AutoFillPlugin autoFillPlugin = new AutoFillPlugin();
|
||||
sqlSessionFactory.getConfiguration().addInterceptor(autoFillPlugin);
|
||||
}
|
||||
|
||||
}
|
@ -1 +1,2 @@
|
||||
com.ruoyi.common.datascope.aspect.DataScopeAspect
|
||||
com.ruoyi.common.datascope.mybatis.MyBatisConfig
|
||||
|
@ -0,0 +1,98 @@
|
||||
package com.ruoyi.common.datasource.mybatis.gen;
|
||||
|
||||
import org.mybatis.generator.api.IntrospectedTable;
|
||||
import org.mybatis.generator.api.PluginAdapter;
|
||||
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
|
||||
import org.mybatis.generator.api.dom.java.Interface;
|
||||
import org.mybatis.generator.api.dom.java.Method;
|
||||
import org.mybatis.generator.internal.util.StringUtility;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/6
|
||||
*/
|
||||
public class RyasMyBatisDynamicPlugin extends PluginAdapter {
|
||||
|
||||
// 校验插件配置的正确性
|
||||
@Override
|
||||
public boolean validate(List<String> warnings) {
|
||||
// 插件使用前提是targetRuntime为MyBatis3DynamicSql
|
||||
if (StringUtility.stringHasValue(context.getTargetRuntime()) && !"MyBatis3DynamicSql".equalsIgnoreCase(context.getTargetRuntime())) {
|
||||
warnings.add("Ryas MyBatisDynamic Plugin: " + this.getClass().getTypeName() + "Required targetRuntime must be 'MyBatis3DynamicSql' !");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// int insert(UnitInfo row)
|
||||
@Override
|
||||
public boolean clientInsertMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForInsert(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
// int insertMultiple(Collection<UnitInfo> records)
|
||||
@Override
|
||||
public boolean clientInsertMultipleMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForInsertMultiple(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
// int insertSelective(UnitInfo row)
|
||||
@Override
|
||||
public boolean clientInsertSelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForInsert(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
// UpdateDSL<UpdateModel> updateSelectiveColumns(UnitInfo row, UpdateDSL<UpdateModel> dsl)
|
||||
@Override
|
||||
public boolean clientUpdateSelectiveColumnsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForUpdate(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
// int updateByPrimaryKey(UnitInfo row)
|
||||
@Override
|
||||
public boolean clientUpdateByPrimaryKeyWithoutBLOBsMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForUpdate(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
// int updateByPrimaryKeySelective(UnitInfo row)
|
||||
@Override
|
||||
public boolean clientUpdateByPrimaryKeySelectiveMethodGenerated(Method method, Interface interfaze, IntrospectedTable introspectedTable) {
|
||||
setForUpdate(method, interfaze);
|
||||
return true;
|
||||
}
|
||||
|
||||
//===============================================================================================================================
|
||||
|
||||
private void setForInsert(Method method, Interface interfaze) {
|
||||
addSecurityUtilsImport(interfaze);
|
||||
List<String> bodyLines = method.getBodyLines();
|
||||
bodyLines.addFirst("row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());");
|
||||
}
|
||||
|
||||
private void setForInsertMultiple(Method method, Interface interfaze) {
|
||||
addSecurityUtilsImport(interfaze);
|
||||
List<String> bodyLines = method.getBodyLines();
|
||||
//从头插入,所以需要倒着
|
||||
bodyLines.addFirst("}");
|
||||
bodyLines.addFirst("row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());");
|
||||
bodyLines.addFirst("for (UnitInfo row : records) {");
|
||||
}
|
||||
|
||||
private void setForUpdate(Method method, Interface interfaze) {
|
||||
addSecurityUtilsImport(interfaze);
|
||||
List<String> bodyLines = method.getBodyLines();
|
||||
bodyLines.addFirst("row.setCommonForUpdate(SecurityUtilsExt.getUserIdStr());");
|
||||
}
|
||||
|
||||
private void addSecurityUtilsImport(Interface interfaze) {
|
||||
interfaze.addImportedType(new FullyQualifiedJavaType("com.ruoyi.common.security.utils.SecurityUtilsExt"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.ruoyi.common.security.utils;
|
||||
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.core.exception.auth.LoginExpiredException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.security.auth.AuthUtil;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/6
|
||||
*/
|
||||
public class SecurityUtilsExt {
|
||||
|
||||
/**
|
||||
* 获取用户ID
|
||||
*/
|
||||
public static Long getUserIdFromRedis() {
|
||||
LoginUser loginUser = getLoginUserFromRedis();
|
||||
if (loginUser == null) {
|
||||
throw new LoginExpiredException("用户登录已过期,请重新登录");
|
||||
}
|
||||
return loginUser.getUserid();
|
||||
}
|
||||
|
||||
public static String getUserIdStr() {
|
||||
Long userId = getUserIdFromRedis();
|
||||
return userId == null ? "UNKNOWN" : String.valueOf(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户名称
|
||||
*/
|
||||
public static String getUsernameFromRedis() {
|
||||
LoginUser loginUser = getLoginUserFromRedis();
|
||||
assert loginUser != null;
|
||||
return loginUser.getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录用户信息
|
||||
*/
|
||||
public static LoginUser getLoginUserFromRedis() {
|
||||
//从请求头里获取token
|
||||
String token = SecurityUtils.getToken();
|
||||
if (StringUtils.isNotEmpty(token)) {
|
||||
//从redis里获取用户信息
|
||||
LoginUser loginUser = AuthUtil.getLoginUser(token);
|
||||
if (loginUser != null) {
|
||||
//将用户信息存入线程变量(或更新)
|
||||
SecurityContextHolder.set(SecurityConstants.LOGIN_USER, loginUser);
|
||||
return loginUser;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +1,60 @@
|
||||
package com.ruoyi.gen.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface GenTableColumnMapper
|
||||
{
|
||||
public interface GenTableColumnMapper {
|
||||
/**
|
||||
* 根据表名称查询列信息
|
||||
*
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 列信息
|
||||
*/
|
||||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||
List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumns 列数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
||||
int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
||||
|
||||
/**
|
||||
* 批量删除业务字段
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumnByIds(Long[] ids);
|
||||
int deleteGenTableColumnByIds(Long[] ids);
|
||||
}
|
@ -1,68 +1,64 @@
|
||||
package com.ruoyi.gen.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
import com.ruoyi.gen.mapper.GenTableColumnMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层实现
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class GenTableColumnServiceImpl implements IGenTableColumnService
|
||||
{
|
||||
@Autowired
|
||||
private GenTableColumnMapper genTableColumnMapper;
|
||||
public class GenTableColumnServiceImpl implements IGenTableColumnService {
|
||||
@Autowired
|
||||
private GenTableColumnMapper genTableColumnMapper;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId)
|
||||
{
|
||||
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) {
|
||||
return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 删除业务字段对象
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids)
|
||||
{
|
||||
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||
}
|
||||
@Override
|
||||
public int deleteGenTableColumnByIds(String ids) {
|
||||
return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||
}
|
||||
}
|
@ -1,44 +1,45 @@
|
||||
package com.ruoyi.gen.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.gen.domain.GenTableColumn;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 业务字段 服务层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IGenTableColumnService
|
||||
{
|
||||
public interface IGenTableColumnService {
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段信息
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumnByIds(String ids);
|
||||
int deleteGenTableColumnByIds(String ids);
|
||||
}
|
||||
|
Loading…
Reference in new issue