共通字段自动填充
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,19 @@ package com.ruoyi.common.core.exception.user;
|
|||
|
||||
import com.ruoyi.common.core.exception.base.BaseException;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 用户信息异常类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class UserException extends BaseException
|
||||
{
|
||||
public class UserException extends BaseException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserException(String code, Object[] args)
|
||||
{
|
||||
public UserException(String code, Object[] args) {
|
||||
super("user", code, args, null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
package com.ruoyi.common.core.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
|
@ -21,64 +17,62 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
|||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 客户端工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class ServletUtils
|
||||
{
|
||||
public class ServletUtils {
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter(String name)
|
||||
{
|
||||
public static String getParameter(String name) {
|
||||
return getRequest().getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter(String name, String defaultValue)
|
||||
{
|
||||
public static String getParameter(String name, String defaultValue) {
|
||||
return Convert.toStr(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt(String name)
|
||||
{
|
||||
public static Integer getParameterToInt(String name) {
|
||||
return Convert.toInt(getRequest().getParameter(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Integer参数
|
||||
*/
|
||||
public static Integer getParameterToInt(String name, Integer defaultValue)
|
||||
{
|
||||
public static Integer getParameterToInt(String name, Integer defaultValue) {
|
||||
return Convert.toInt(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Boolean参数
|
||||
*/
|
||||
public static Boolean getParameterToBool(String name)
|
||||
{
|
||||
public static Boolean getParameterToBool(String name) {
|
||||
return Convert.toBool(getRequest().getParameter(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Boolean参数
|
||||
*/
|
||||
public static Boolean getParameterToBool(String name, Boolean defaultValue)
|
||||
{
|
||||
public static Boolean getParameterToBool(String name, Boolean defaultValue) {
|
||||
return Convert.toBool(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
|
|
@ -88,8 +82,7 @@ public class ServletUtils
|
|||
* @param request 请求对象{@link ServletRequest}
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, String[]> getParams(ServletRequest request)
|
||||
{
|
||||
public static Map<String, String[]> getParams(ServletRequest request) {
|
||||
final Map<String, String[]> map = request.getParameterMap();
|
||||
return Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
|
@ -100,11 +93,9 @@ public class ServletUtils
|
|||
* @param request 请求对象{@link ServletRequest}
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, String> getParamMap(ServletRequest request)
|
||||
{
|
||||
public static Map<String, String> getParamMap(ServletRequest request) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
|
||||
{
|
||||
for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) {
|
||||
params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
|
||||
}
|
||||
return params;
|
||||
|
|
@ -113,14 +104,10 @@ public class ServletUtils
|
|||
/**
|
||||
* 获取request
|
||||
*/
|
||||
public static HttpServletRequest getRequest()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static HttpServletRequest getRequest() {
|
||||
try {
|
||||
return getRequestAttributes().getRequest();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -128,14 +115,10 @@ public class ServletUtils
|
|||
/**
|
||||
* 获取response
|
||||
*/
|
||||
public static HttpServletResponse getResponse()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static HttpServletResponse getResponse() {
|
||||
try {
|
||||
return getRequestAttributes().getResponse();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -143,42 +126,32 @@ public class ServletUtils
|
|||
/**
|
||||
* 获取session
|
||||
*/
|
||||
public static HttpSession getSession()
|
||||
{
|
||||
public static HttpSession getSession() {
|
||||
return getRequest().getSession();
|
||||
}
|
||||
|
||||
public static ServletRequestAttributes getRequestAttributes()
|
||||
{
|
||||
try
|
||||
{
|
||||
public static ServletRequestAttributes getRequestAttributes() {
|
||||
try {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
return (ServletRequestAttributes) attributes;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHeader(HttpServletRequest request, String name)
|
||||
{
|
||||
public static String getHeader(HttpServletRequest request, String name) {
|
||||
String value = request.getHeader(name);
|
||||
if (StringUtils.isEmpty(value))
|
||||
{
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return urlDecode(value);
|
||||
}
|
||||
|
||||
public static Map<String, String> getHeaders(HttpServletRequest request)
|
||||
{
|
||||
public static Map<String, String> getHeaders(HttpServletRequest request) {
|
||||
Map<String, String> map = new LinkedCaseInsensitiveMap<>();
|
||||
Enumeration<String> enumeration = request.getHeaderNames();
|
||||
if (enumeration != null)
|
||||
{
|
||||
while (enumeration.hasMoreElements())
|
||||
{
|
||||
if (enumeration != null) {
|
||||
while (enumeration.hasMoreElements()) {
|
||||
String key = enumeration.nextElement();
|
||||
String value = request.getHeader(key);
|
||||
map.put(key, value);
|
||||
|
|
@ -189,47 +162,37 @@ public class ServletUtils
|
|||
|
||||
/**
|
||||
* 将字符串渲染到客户端
|
||||
*
|
||||
*
|
||||
* @param response 渲染对象
|
||||
* @param string 待渲染的字符串
|
||||
* @param string 待渲染的字符串
|
||||
*/
|
||||
public static void renderString(HttpServletResponse response, String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static void renderString(HttpServletResponse response, String string) {
|
||||
try {
|
||||
response.setStatus(200);
|
||||
response.setContentType("application/json");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.getWriter().print(string);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是Ajax异步请求
|
||||
*
|
||||
* @param request
|
||||
*/
|
||||
public static boolean isAjaxRequest(HttpServletRequest request)
|
||||
{
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
String accept = request.getHeader("accept");
|
||||
if (accept != null && accept.contains("application/json"))
|
||||
{
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String xRequestedWith = request.getHeader("X-Requested-With");
|
||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest"))
|
||||
{
|
||||
if (xRequestedWith != null && xRequestedWith.contains("XMLHttpRequest")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml"))
|
||||
{
|
||||
if (StringUtils.inStringIgnoreCase(uri, ".json", ".xml")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -239,36 +202,28 @@ public class ServletUtils
|
|||
|
||||
/**
|
||||
* 内容编码
|
||||
*
|
||||
*
|
||||
* @param str 内容
|
||||
* @return 编码后的内容
|
||||
*/
|
||||
public static String urlEncode(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String urlEncode(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, Constants.UTF8);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容解码
|
||||
*
|
||||
*
|
||||
* @param str 内容
|
||||
* @return 解码后的内容
|
||||
*/
|
||||
public static String urlDecode(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static String urlDecode(String str) {
|
||||
try {
|
||||
return URLDecoder.decode(str, Constants.UTF8);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
|
@ -277,11 +232,10 @@ public class ServletUtils
|
|||
* 设置webflux模型响应
|
||||
*
|
||||
* @param response ServerHttpResponse
|
||||
* @param value 响应内容
|
||||
* @param value 响应内容
|
||||
* @return Mono<Void>
|
||||
*/
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value)
|
||||
{
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value) {
|
||||
return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL);
|
||||
}
|
||||
|
||||
|
|
@ -289,12 +243,11 @@ public class ServletUtils
|
|||
* 设置webflux模型响应
|
||||
*
|
||||
* @param response ServerHttpResponse
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @return Mono<Void>
|
||||
*/
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code)
|
||||
{
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code) {
|
||||
return webFluxResponseWriter(response, HttpStatus.OK, value, code);
|
||||
}
|
||||
|
||||
|
|
@ -302,28 +255,26 @@ public class ServletUtils
|
|||
* 设置webflux模型响应
|
||||
*
|
||||
* @param response ServerHttpResponse
|
||||
* @param status http状态码
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @param status http状态码
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @return Mono<Void>
|
||||
*/
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code)
|
||||
{
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code) {
|
||||
return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置webflux模型响应
|
||||
*
|
||||
* @param response ServerHttpResponse
|
||||
* @param response ServerHttpResponse
|
||||
* @param contentType content-type
|
||||
* @param status http状态码
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @param status http状态码
|
||||
* @param code 响应状态码
|
||||
* @param value 响应内容
|
||||
* @return Mono<Void>
|
||||
*/
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code)
|
||||
{
|
||||
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code) {
|
||||
response.setStatusCode(status);
|
||||
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
|
||||
R<?> result = R.fail(code, value.toString());
|
||||
|
|
|
|||
|
|
@ -58,6 +58,35 @@ public class BaseEntity implements Serializable {
|
|||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private Map<String, Object> params;
|
||||
|
||||
@JsonIgnore
|
||||
public void setCommonForInsert(String createBy, Date createTime) {
|
||||
this.createBy = createBy;
|
||||
this.createTime = createTime;
|
||||
setCommonForUpdate(createBy, createTime);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setCommonForInsert(String createBy) {
|
||||
setCommonForInsert(createBy, new Date());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setCommonForUpdate(String updateBy, Date updateTime) {
|
||||
this.updateBy = updateBy;
|
||||
this.updateTime = updateTime;
|
||||
if (this instanceof ExtBaseEntity ext) {
|
||||
if (ext.getUpdateCount() == null) {
|
||||
ext.setUpdateCount(0);
|
||||
} else {
|
||||
ext.setUpdateCount(ext.getUpdateCount() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setCommonForUpdate(String updateBy) {
|
||||
setCommonForUpdate(updateBy, new Date());
|
||||
}
|
||||
|
||||
public String getSearchValue() {
|
||||
return searchValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
package com.ruoyi.common.datascope.aspect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.context.SecurityContextHolder;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
|
@ -16,6 +9,13 @@ import com.ruoyi.common.security.utils.SecurityUtils;
|
|||
import com.ruoyi.system.api.domain.SysRole;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据过滤处理
|
||||
|
|
@ -86,7 +86,7 @@ public class DataScopeAspect {
|
|||
*/
|
||||
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias, String permission) {
|
||||
StringBuilder sqlString = new StringBuilder();
|
||||
List<String> conditions = new ArrayList<String>();
|
||||
List<String> conditions = new ArrayList<>();
|
||||
|
||||
for (SysRole role : user.getRoles()) {
|
||||
String dataScope = role.getDataScope();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
package com.ruoyi.common.datascope.mybatis;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import com.ruoyi.common.core.web.domain.ExtBaseEntity;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 共通字段自动填充插件
|
||||
* <p>
|
||||
* 注:该插件仅针对自己写的mapper.xml里的insert和update语句生效,对Dynamic SQL无效
|
||||
* </p>
|
||||
*
|
||||
* @author Alan Scipio
|
||||
* created on 2024/2/6
|
||||
*/
|
||||
@Intercepts({
|
||||
@Signature(
|
||||
type = Executor.class,
|
||||
method = "update",
|
||||
args = {MappedStatement.class, Object.class}
|
||||
)
|
||||
})
|
||||
public class AutoFillPlugin implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
Object parameter = invocation.getArgs()[1];
|
||||
if (parameter instanceof BaseEntity entity) {
|
||||
MappedStatement statement = (MappedStatement) invocation.getArgs()[0];
|
||||
String commandType = statement.getSqlCommandType().name();
|
||||
|
||||
Date now = DateUtils.getNowDate();
|
||||
String userId = SecurityUtils.getUserIdStr();
|
||||
|
||||
if ("INSERT".equals(commandType)) {
|
||||
// insert时的自动填充
|
||||
entity.setCommonForInsert(userId, now);
|
||||
} else if ("UPDATE".equals(commandType)) {
|
||||
// update时的自动填充
|
||||
entity.setCommonForUpdate(userId, now);
|
||||
}
|
||||
|
||||
if (entity instanceof ExtBaseEntity extEntity) {
|
||||
// ExtBaseEntity的自动填充
|
||||
if (extEntity.getUpdateCount() == null) {
|
||||
extEntity.setUpdateCount(0);
|
||||
} else {
|
||||
extEntity.setUpdateCount(extEntity.getUpdateCount() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,11 +6,10 @@ import com.ruoyi.system.api.model.LoginUser;
|
|||
|
||||
/**
|
||||
* Token 权限验证工具类
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class AuthUtil
|
||||
{
|
||||
public class AuthUtil {
|
||||
/**
|
||||
* 底层的 AuthLogic 对象
|
||||
*/
|
||||
|
|
@ -19,149 +18,134 @@ public class AuthUtil
|
|||
/**
|
||||
* 会话注销
|
||||
*/
|
||||
public static void logout()
|
||||
{
|
||||
public static void logout() {
|
||||
authLogic.logout();
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话注销,根据指定Token
|
||||
*
|
||||
*
|
||||
* @param token 指定token
|
||||
*/
|
||||
public static void logoutByToken(String token)
|
||||
{
|
||||
public static void logoutByToken(String token) {
|
||||
authLogic.logoutByToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验当前会话是否已经登录,如未登录,则抛出异常
|
||||
*/
|
||||
public static void checkLogin()
|
||||
{
|
||||
public static void checkLogin() {
|
||||
authLogic.checkLogin();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息
|
||||
*
|
||||
*
|
||||
* @param token 指定token
|
||||
* @return 用户信息
|
||||
*/
|
||||
public static LoginUser getLoginUser(String token)
|
||||
{
|
||||
public static LoginUser getLoginUser(String token) {
|
||||
return authLogic.getLoginUser(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前用户有效期
|
||||
*
|
||||
*
|
||||
* @param loginUser 用户信息
|
||||
*/
|
||||
public static void verifyLoginUserExpire(LoginUser loginUser)
|
||||
{
|
||||
public static void verifyLoginUserExpire(LoginUser loginUser) {
|
||||
authLogic.verifyLoginUserExpire(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定角色标识, 返回true或false
|
||||
*
|
||||
*
|
||||
* @param role 角色标识
|
||||
* @return 是否含有指定角色标识
|
||||
*/
|
||||
public static boolean hasRole(String role)
|
||||
{
|
||||
public static boolean hasRole(String role) {
|
||||
return authLogic.hasRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定角色标识, 如果验证未通过,则抛出异常: NotRoleException
|
||||
*
|
||||
*
|
||||
* @param role 角色标识
|
||||
*/
|
||||
public static void checkRole(String role)
|
||||
{
|
||||
public static void checkRole(String role) {
|
||||
authLogic.checkRole(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注解传入参数鉴权, 如果验证未通过,则抛出异常: NotRoleException
|
||||
*
|
||||
*
|
||||
* @param requiresRoles 角色权限注解
|
||||
*/
|
||||
public static void checkRole(RequiresRoles requiresRoles)
|
||||
{
|
||||
public static void checkRole(RequiresRoles requiresRoles) {
|
||||
authLogic.checkRole(requiresRoles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定角色标识 [指定多个,必须全部验证通过]
|
||||
*
|
||||
*
|
||||
* @param roles 角色标识数组
|
||||
*/
|
||||
public static void checkRoleAnd(String... roles)
|
||||
{
|
||||
public static void checkRoleAnd(String... roles) {
|
||||
authLogic.checkRoleAnd(roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定角色标识 [指定多个,只要其一验证通过即可]
|
||||
*
|
||||
*
|
||||
* @param roles 角色标识数组
|
||||
*/
|
||||
public static void checkRoleOr(String... roles)
|
||||
{
|
||||
public static void checkRoleOr(String... roles) {
|
||||
authLogic.checkRoleOr(roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定权限, 返回true或false
|
||||
*
|
||||
*
|
||||
* @param permission 权限码
|
||||
* @return 是否含有指定权限
|
||||
*/
|
||||
public static boolean hasPermi(String permission)
|
||||
{
|
||||
public static boolean hasPermi(String permission) {
|
||||
return authLogic.hasPermi(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定权限, 如果验证未通过,则抛出异常: NotPermissionException
|
||||
*
|
||||
*
|
||||
* @param permission 权限码
|
||||
*/
|
||||
public static void checkPermi(String permission)
|
||||
{
|
||||
public static void checkPermi(String permission) {
|
||||
authLogic.checkPermi(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据注解传入参数鉴权, 如果验证未通过,则抛出异常: NotPermissionException
|
||||
*
|
||||
*
|
||||
* @param requiresPermissions 权限注解
|
||||
*/
|
||||
public static void checkPermi(RequiresPermissions requiresPermissions)
|
||||
{
|
||||
public static void checkPermi(RequiresPermissions requiresPermissions) {
|
||||
authLogic.checkPermi(requiresPermissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定权限 [指定多个,必须全部验证通过]
|
||||
*
|
||||
*
|
||||
* @param permissions 权限码数组
|
||||
*/
|
||||
public static void checkPermiAnd(String... permissions)
|
||||
{
|
||||
public static void checkPermiAnd(String... permissions) {
|
||||
authLogic.checkPermiAnd(permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号是否含有指定权限 [指定多个,只要其一验证通过即可]
|
||||
*
|
||||
*
|
||||
* @param permissions 权限码数组
|
||||
*/
|
||||
public static void checkPermiOr(String... permissions)
|
||||
{
|
||||
public static void checkPermiOr(String... permissions) {
|
||||
authLogic.checkPermiOr(permissions);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.ruoyi.common.core.constant.HttpStatus;
|
|||
import com.ruoyi.common.core.exception.DemoModeException;
|
||||
import com.ruoyi.common.core.exception.InnerAuthException;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.exception.auth.LoginExpiredException;
|
||||
import com.ruoyi.common.core.exception.auth.NotPermissionException;
|
||||
import com.ruoyi.common.core.exception.auth.NotRoleException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
|
|
@ -25,16 +26,14 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||
* @author ruoyi
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler
|
||||
{
|
||||
public class GlobalExceptionHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* 权限码异常
|
||||
*/
|
||||
@ExceptionHandler(NotPermissionException.class)
|
||||
public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
|
||||
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
||||
|
|
@ -44,8 +43,7 @@ public class GlobalExceptionHandler
|
|||
* 角色权限异常
|
||||
*/
|
||||
@ExceptionHandler(NotRoleException.class)
|
||||
public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
|
||||
return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
|
||||
|
|
@ -55,8 +53,7 @@ public class GlobalExceptionHandler
|
|||
* 请求方式不支持
|
||||
*/
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
|
||||
return AjaxResult.error(e.getMessage());
|
||||
|
|
@ -66,8 +63,7 @@ public class GlobalExceptionHandler
|
|||
* 业务异常
|
||||
*/
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) {
|
||||
log.error(e.getMessage(), e);
|
||||
Integer code = e.getCode();
|
||||
return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
|
||||
|
|
@ -77,8 +73,7 @@ public class GlobalExceptionHandler
|
|||
* 请求路径中缺少必需的路径变量
|
||||
*/
|
||||
@ExceptionHandler(MissingPathVariableException.class)
|
||||
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
|
||||
return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
|
||||
|
|
@ -88,8 +83,7 @@ public class GlobalExceptionHandler
|
|||
* 请求参数类型不匹配
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
|
||||
return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
|
||||
|
|
@ -99,8 +93,7 @@ public class GlobalExceptionHandler
|
|||
* 拦截未知的运行时异常
|
||||
*/
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',发生未知异常.", requestURI, e);
|
||||
return AjaxResult.error(e.getMessage());
|
||||
|
|
@ -110,8 +103,7 @@ public class GlobalExceptionHandler
|
|||
* 系统异常
|
||||
*/
|
||||
@ExceptionHandler(Exception.class)
|
||||
public AjaxResult handleException(Exception e, HttpServletRequest request)
|
||||
{
|
||||
public AjaxResult handleException(Exception e, HttpServletRequest request) {
|
||||
String requestURI = request.getRequestURI();
|
||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
||||
return AjaxResult.error(e.getMessage());
|
||||
|
|
@ -121,8 +113,7 @@ public class GlobalExceptionHandler
|
|||
* 自定义验证异常
|
||||
*/
|
||||
@ExceptionHandler(BindException.class)
|
||||
public AjaxResult handleBindException(BindException e)
|
||||
{
|
||||
public AjaxResult handleBindException(BindException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
String message = e.getAllErrors().getFirst().getDefaultMessage();
|
||||
return AjaxResult.error(message);
|
||||
|
|
@ -132,8 +123,7 @@ public class GlobalExceptionHandler
|
|||
* 自定义验证异常
|
||||
*/
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
|
||||
{
|
||||
public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
String message = e.getBindingResult().getFieldError().getDefaultMessage();
|
||||
return AjaxResult.error(message);
|
||||
|
|
@ -143,8 +133,7 @@ public class GlobalExceptionHandler
|
|||
* 内部认证异常
|
||||
*/
|
||||
@ExceptionHandler(InnerAuthException.class)
|
||||
public AjaxResult handleInnerAuthException(InnerAuthException e)
|
||||
{
|
||||
public AjaxResult handleInnerAuthException(InnerAuthException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
|
||||
|
|
@ -152,8 +141,15 @@ public class GlobalExceptionHandler
|
|||
* 演示模式异常
|
||||
*/
|
||||
@ExceptionHandler(DemoModeException.class)
|
||||
public AjaxResult handleDemoModeException(DemoModeException e)
|
||||
{
|
||||
public AjaxResult handleDemoModeException(DemoModeException e) {
|
||||
return AjaxResult.error("演示模式,不允许操作");
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录过期异常
|
||||
*/
|
||||
@ExceptionHandler(LoginExpiredException.class)
|
||||
public AjaxResult handleLoginExpiredException(LoginExpiredException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@ public class TokenService {
|
|||
if (StringUtils.isNotEmpty(token)) {
|
||||
String userKey = JwtUtils.getUserKey(token);
|
||||
user = redisService.getCacheObject(getTokenKey(userKey));
|
||||
return user;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户信息异常'{}'", e.getMessage());
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import com.ruoyi.common.core.utils.ServletUtils;
|
|||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 权限获取工具类
|
||||
*
|
||||
|
|
@ -22,6 +24,11 @@ public class SecurityUtils {
|
|||
return SecurityContextHolder.getUserId();
|
||||
}
|
||||
|
||||
public static String getUserIdStr() {
|
||||
Long userId = SecurityContextHolder.getUserId();
|
||||
return userId == null ? "UNKNOWN" : String.valueOf(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户名称
|
||||
*/
|
||||
|
|
@ -47,7 +54,7 @@ public class SecurityUtils {
|
|||
* 获取请求token
|
||||
*/
|
||||
public static String getToken() {
|
||||
return getToken(ServletUtils.getRequest());
|
||||
return getToken(Objects.requireNonNull(ServletUtils.getRequest()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn)
|
||||
{
|
||||
return genTableColumnMapper.updateGenTableColumn(genTableColumn);
|
||||
}
|
||||
@Override
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn) {
|
||||
return genTableColumnMapper.insertGenTableColumn(genTableColumn);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import ${packageName}.domain.${subClassName};
|
||||
#end
|
||||
import com.ruoyi.common.core.web.domain.ExtBaseEntity;
|
||||
import com.ruoyi.common.security.utils.SecurityUtilsExt
|
||||
import ${packageName}.mapper.${ClassName}Mapper;
|
||||
import ${packageName}.domain.${ClassName};
|
||||
import ${packageName}.mapper.${ClassName}DynamicSqlSupport;
|
||||
|
|
@ -167,9 +168,11 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service
|
|||
${className}Mapper.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
||||
#end
|
||||
## return ${className}Mapper.delete(dsl -> dsl.where(${ClassName}DynamicSqlSupport.${pkColumn.javaField}, SqlBuilder.isIn(${pkColumn.javaField}s)));
|
||||
String userId = SecurityUtilsExt.getUserIdStr();
|
||||
UpdateStatementProvider provider = SqlBuilder.update(UnitInfoDynamicSqlSupport.${className})
|
||||
.set(${ClassName}DynamicSqlSupport.deleteFlag).equalTo(ExtBaseEntity.DELETED)
|
||||
.set(${ClassName}DynamicSqlSupport.updateTime).equalTo(DateUtils.getNowDate())
|
||||
.set(${ClassName}DynamicSqlSupport.updateBy).equalTo(userId)
|
||||
.where(${ClassName}DynamicSqlSupport.unitCode, SqlBuilder.isIn(${pkColumn.javaField}s))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@
|
|||
<!-- MyBatis3 动态SQL生成 -->
|
||||
<context id="mbg" targetRuntime="MyBatis3DynamicSql">
|
||||
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.ruoyi.common.datasource.mybatis.gen.RyasMyBatisDynamicPlugin"/>
|
||||
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
|
||||
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
|
||||
|
||||
<commentGenerator>
|
||||
<property name="suppressAllComments" value="false"/>
|
||||
<property name="suppressDate" value="true"/>
|
||||
|
|
@ -17,7 +22,7 @@
|
|||
userId="root"
|
||||
password="password"/>
|
||||
|
||||
<!-- Java 模型 -->
|
||||
<!-- Java Entity -->
|
||||
<javaModelGenerator targetPackage="com.ruoyi.system.domain" targetProject="ruoyi-modules/ruoyi-system/src/main/java">
|
||||
<property name="rootClass" value="com.ruoyi.common.core.web.domain.BaseEntity"/>
|
||||
<property name="enableSubPackages" value="true" />
|
||||
|
|
@ -25,9 +30,9 @@
|
|||
</javaModelGenerator>
|
||||
|
||||
<!-- Mapper.xml (对于MyBatis动态SQL特性来说不再需要) -->
|
||||
<sqlMapGenerator targetPackage="mappers" targetProject="ruoyi-modules/ruoyi-system/src/main/resources">
|
||||
<property name="enableSubPackages" value="true" />
|
||||
</sqlMapGenerator>
|
||||
<!-- <sqlMapGenerator targetPackage="com.ruoyi.system.mapper" targetProject="ruoyi-modules/ruoyi-system/src/main/resources">-->
|
||||
<!-- <property name="enableSubPackages" value="true" />-->
|
||||
<!-- </sqlMapGenerator>-->
|
||||
|
||||
<!-- Mapper.java -->
|
||||
<javaClientGenerator targetPackage="com.ruoyi.system.mapper" targetProject="ruoyi-modules/ruoyi-system/src/main/java" type="XMLMAPPER">
|
||||
|
|
|
|||
|
|
@ -2,13 +2,16 @@ package com.ruoyi.wms.domain;
|
|||
|
||||
import com.ruoyi.common.core.web.domain.ExtBaseEntity;
|
||||
import jakarta.annotation.Generated;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Database Table Remarks:
|
||||
* 单位基础信息表
|
||||
*
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table SF_WMS_M_UNIT_INFO
|
||||
*/
|
||||
public class UnitInfo extends ExtBaseEntity {
|
||||
public class UnitInfo extends ExtBaseEntity implements Serializable {
|
||||
/**
|
||||
* Database Column Remarks:
|
||||
* 单位代码
|
||||
|
|
@ -58,6 +61,9 @@ public class UnitInfo extends ExtBaseEntity {
|
|||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: SF_WMS_M_UNIT_INFO.REMARK_5")
|
||||
private String remark5;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source field: SF_WMS_M_UNIT_INFO.UNIT_CODE")
|
||||
public String getUnitCode() {
|
||||
return unitCode;
|
||||
|
|
@ -127,4 +133,23 @@ public class UnitInfo extends ExtBaseEntity {
|
|||
public void setRemark5(String remark5) {
|
||||
this.remark5 = remark5 == null ? null : remark5.trim();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", unitCode=").append(unitCode);
|
||||
sb.append(", unitName=").append(unitName);
|
||||
sb.append(", remark1=").append(remark1);
|
||||
sb.append(", remark2=").append(remark2);
|
||||
sb.append(", remark3=").append(remark3);
|
||||
sb.append(", remark4=").append(remark4);
|
||||
sb.append(", remark5=").append(remark5);
|
||||
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,9 @@
|
|||
package com.ruoyi.wms.mapper;
|
||||
|
||||
import static com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport.*;
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||
|
||||
import com.ruoyi.common.security.utils.SecurityUtilsExt;
|
||||
import com.ruoyi.wms.domain.UnitInfo;
|
||||
import jakarta.annotation.Generated;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.ResultMap;
|
||||
import org.apache.ibatis.annotations.Results;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.mybatis.dynamic.sql.BasicColumn;
|
||||
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
|
||||
|
|
@ -23,11 +14,14 @@ import org.mybatis.dynamic.sql.update.UpdateDSL;
|
|||
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
|
||||
import org.mybatis.dynamic.sql.update.UpdateModel;
|
||||
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
|
||||
import org.mybatis.dynamic.sql.util.mybatis3.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport.*;
|
||||
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
|
||||
|
||||
@Mapper
|
||||
public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<UnitInfo>, CommonUpdateMapper {
|
||||
|
|
@ -78,6 +72,7 @@ public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, C
|
|||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
default int insert(UnitInfo row) {
|
||||
row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());
|
||||
return MyBatis3Utils.insert(this::insert, row, unitInfo, c ->
|
||||
c.map(unitCode).toProperty("unitCode")
|
||||
.map(unitName).toProperty("unitName")
|
||||
|
|
@ -98,6 +93,9 @@ public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, C
|
|||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
default int insertMultiple(Collection<UnitInfo> records) {
|
||||
for (UnitInfo row : records) {
|
||||
row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());
|
||||
}
|
||||
return MyBatis3Utils.insertMultiple(this::insertMultiple, records, unitInfo, c ->
|
||||
c.map(unitCode).toProperty("unitCode")
|
||||
.map(unitName).toProperty("unitName")
|
||||
|
|
@ -118,6 +116,7 @@ public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, C
|
|||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
default int insertSelective(UnitInfo row) {
|
||||
row.setCommonForInsert(SecurityUtilsExt.getUserIdStr());
|
||||
return MyBatis3Utils.insert(this::insert, row, unitInfo, c ->
|
||||
c.map(unitCode).toPropertyWhenPresent("unitCode", row::getUnitCode)
|
||||
.map(unitName).toPropertyWhenPresent("unitName", row::getUnitName)
|
||||
|
|
@ -183,6 +182,7 @@ public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, C
|
|||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
static UpdateDSL<UpdateModel> updateSelectiveColumns(UnitInfo row, UpdateDSL<UpdateModel> dsl) {
|
||||
row.setCommonForUpdate(SecurityUtilsExt.getUserIdStr());
|
||||
return dsl.set(unitCode).equalToWhenPresent(row::getUnitCode)
|
||||
.set(unitName).equalToWhenPresent(row::getUnitName)
|
||||
.set(remark1).equalToWhenPresent(row::getRemark1)
|
||||
|
|
@ -221,6 +221,7 @@ public interface UnitInfoMapper extends CommonCountMapper, CommonDeleteMapper, C
|
|||
|
||||
@Generated(value="org.mybatis.generator.api.MyBatisGenerator", comments="Source Table: SF_WMS_M_UNIT_INFO")
|
||||
default int updateByPrimaryKeySelective(UnitInfo row) {
|
||||
row.setCommonForUpdate(SecurityUtilsExt.getUserIdStr());
|
||||
return update(c ->
|
||||
c.set(unitName).equalToWhenPresent(row::getUnitName)
|
||||
.set(remark1).equalToWhenPresent(row::getRemark1)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.ruoyi.common.core.utils.DateUtils;
|
|||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.uuid.snowflake.SnowFlakeIdGenerator;
|
||||
import com.ruoyi.common.core.web.domain.ExtBaseEntity;
|
||||
import com.ruoyi.common.security.utils.SecurityUtilsExt;
|
||||
import com.ruoyi.wms.domain.UnitInfo;
|
||||
import com.ruoyi.wms.mapper.UnitInfoDynamicSqlSupport;
|
||||
import com.ruoyi.wms.mapper.UnitInfoMapper;
|
||||
|
|
@ -70,7 +71,6 @@ public class UnitInfoServiceImpl implements IUnitInfoService {
|
|||
if (StringUtils.isBlank(unitInfo.getUnitCode())) {
|
||||
unitInfo.setUnitCode(SnowFlakeIdGenerator.nextId());
|
||||
}
|
||||
unitInfo.setCreateTime(DateUtils.getNowDate());
|
||||
return unitInfoMapper.insertSelective(unitInfo);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,6 @@ public class UnitInfoServiceImpl implements IUnitInfoService {
|
|||
*/
|
||||
@Override
|
||||
public int updateUnitInfo(UnitInfo unitInfo) {
|
||||
unitInfo.setUpdateTime(DateUtils.getNowDate());
|
||||
return unitInfoMapper.updateByPrimaryKeySelective(unitInfo);
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +93,11 @@ public class UnitInfoServiceImpl implements IUnitInfoService {
|
|||
*/
|
||||
@Override
|
||||
public int deleteUnitInfoByUnitCodes(String[] unitCodes) {
|
||||
String userId = SecurityUtilsExt.getUserIdStr();
|
||||
UpdateStatementProvider provider = SqlBuilder.update(UnitInfoDynamicSqlSupport.unitInfo)
|
||||
.set(UnitInfoDynamicSqlSupport.deleteFlag).equalTo(ExtBaseEntity.DELETED)
|
||||
.set(UnitInfoDynamicSqlSupport.updateTime).equalTo(DateUtils.getNowDate())
|
||||
.set(UnitInfoDynamicSqlSupport.updateBy).equalTo(userId)
|
||||
.where(UnitInfoDynamicSqlSupport.unitCode, SqlBuilder.isIn(unitCodes))
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3);
|
||||
|
|
@ -114,7 +115,6 @@ public class UnitInfoServiceImpl implements IUnitInfoService {
|
|||
UnitInfo record = new UnitInfo();
|
||||
record.setUnitCode(unitCode);
|
||||
record.setDeleteFlag(ExtBaseEntity.DELETED);
|
||||
record.setUpdateTime(DateUtils.getNowDate());
|
||||
return unitInfoMapper.updateByPrimaryKey(record);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@
|
|||
<!-- MyBatis3 动态SQL生成 -->
|
||||
<context id="mbg" targetRuntime="MyBatis3DynamicSql">
|
||||
|
||||
<!-- 插件 -->
|
||||
<plugin type="com.ruoyi.common.datasource.mybatis.gen.RyasMyBatisDynamicPlugin"/>
|
||||
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
|
||||
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
|
||||
|
||||
<commentGenerator>
|
||||
<property name="suppressAllComments" value="false"/>
|
||||
<property name="suppressDate" value="true"/>
|
||||
|
|
@ -17,17 +22,17 @@
|
|||
userId="root"
|
||||
password="password"/>
|
||||
|
||||
<!-- Java 模型 -->
|
||||
<!-- Java Entity -->
|
||||
<javaModelGenerator targetPackage="com.ruoyi.wms.domain" targetProject="ruoyi-modules/ruoyi-wms/src/main/java">
|
||||
<property name="rootClass" value="com.ruoyi.common.core.web.domain.ExtBaseEntity"/>
|
||||
<property name="enableSubPackages" value="true" />
|
||||
<property name="trimStrings" value="true" />
|
||||
</javaModelGenerator>
|
||||
|
||||
<!-- Mapper.xml (对于MyBatis动态SQL特性来说不再需要) -->
|
||||
<sqlMapGenerator targetPackage="mappers" targetProject="ruoyi-modules/ruoyi-wms/src/main/resources">
|
||||
<property name="enableSubPackages" value="true" />
|
||||
</sqlMapGenerator>
|
||||
<!-- Mapper.xml (对于MyBatis动态SQL来说不需要) -->
|
||||
<!-- <sqlMapGenerator targetPackage="com.ruoyi.wms.mapper" targetProject="ruoyi-modules/ruoyi-wms/src/main/resources">-->
|
||||
<!-- <property name="enableSubPackages" value="true" />-->
|
||||
<!-- </sqlMapGenerator>-->
|
||||
|
||||
<!-- Mapper.java -->
|
||||
<javaClientGenerator targetPackage="com.ruoyi.wms.mapper" targetProject="ruoyi-modules/ruoyi-wms/src/main/java" type="XMLMAPPER">
|
||||
|
|
|
|||
Loading…
Reference in New Issue