同步ruoyi4,1最新版本,修复订单发货及其规格修改bug

This commit is contained in:
hupeng committed 2019-12-10 11:49:08 +08:00
1 parent d2306354db
commit 49e46e68c4
156 files changed
+12006 -10025

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>ruoyi</artifactId>
<groupId>com.ruoyi</groupId>
<version>4.0.0</version>
<version>4.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -45,10 +45,10 @@ public class LogAspect
*
* @param joinPoint 切点
*/
@AfterReturning(pointcut = "logPointCut()")
public void doAfterReturning(JoinPoint joinPoint)
@AfterReturning(pointcut = "logPointCut()", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, Object jsonResult)
{
handleLog(joinPoint, null);
handleLog(joinPoint, null, jsonResult);
}
/**
@@ -60,10 +60,10 @@ public class LogAspect
@AfterThrowing(value = "logPointCut()", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, Exception e)
{
handleLog(joinPoint, e);
handleLog(joinPoint, e, null);
}
protected void handleLog(final JoinPoint joinPoint, final Exception e)
protected void handleLog(final JoinPoint joinPoint, final Exception e, Object jsonResult)
{
try
{
@@ -83,6 +83,8 @@ public class LogAspect
// 请求的地址
String ip = ShiroUtils.getIp();
operLog.setOperIp(ip);
// 返回参数
operLog.setJsonResult(JSON.marshal(jsonResult));
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
if (currentUser != null)
@@ -104,6 +106,8 @@ public class LogAspect
String className = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
operLog.setMethod(className + "." + methodName + "()");
// 设置请求方式
operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
// 处理设置注解上的参数
getControllerMethodDescription(controllerLog, operLog);
// 保存数据库
@@ -13,7 +13,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
// 表示通过aop框架暴露该代理对象,AopContext能够访问
@EnableAspectJAutoProxy(exposeProxy = true)
// 指定要扫描的Mapper类的包的路径
@MapperScan("com.ruoyi.*.mapper")
@MapperScan("com.ruoyi.**.mapper")
public class ApplicationConfig
{
@@ -0,0 +1,108 @@
package com.ruoyi.framework.config;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.sql.DataSource;
import org.apache.ibatis.io.VFS;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.util.ClassUtils;
/**
* Mybatis支持*匹配扫描包
*
* @author ruoyi
*/
@Configuration
public class MyBatisConfig
{
@Autowired
private Environment env;
static final String DEFAULT_RESOURCE_PATTERN = "**/*.class";
public static String setTypeAliasesPackage(String typeAliasesPackage)
{
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
List<String> allResult = new ArrayList<String>();
try
{
for (String aliasesPackage : typeAliasesPackage.split(","))
{
List<String> result = new ArrayList<String>();
aliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
+ ClassUtils.convertClassNameToResourcePath(aliasesPackage.trim()) + "/" + DEFAULT_RESOURCE_PATTERN;
Resource[] resources = resolver.getResources(aliasesPackage);
if (resources != null && resources.length > 0)
{
MetadataReader metadataReader = null;
for (Resource resource : resources)
{
if (resource.isReadable())
{
metadataReader = metadataReaderFactory.getMetadataReader(resource);
try
{
result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName());
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
}
if (result.size() > 0)
{
HashSet<String> hashResult = new HashSet<String>(result);
allResult.addAll(hashResult);
}
}
if (allResult.size() > 0)
{
typeAliasesPackage = String.join(",", (String[]) allResult.toArray(new String[0]));
}
else
{
throw new RuntimeException("mybatis typeAliasesPackage 路径扫描错误,参数typeAliasesPackage:" + typeAliasesPackage + "未找到任何包");
}
}
catch (IOException e)
{
e.printStackTrace();
}
return typeAliasesPackage;
}
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
{
String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
String mapperLocations = env.getProperty("mybatis.mapperLocations");
String configLocation = env.getProperty("mybatis.configLocation");
typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
VFS.addImplClass(SpringBootVFS.class);
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocations));
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
return sessionFactory.getObject();
}
}
@@ -8,6 +8,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
/**
@@ -40,7 +41,7 @@ public class ResourcesConfig implements WebMvcConfigurer
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
/** 本地文件上传路径 */
registry.addResourceHandler("/profile/**").addResourceLocations("file:" + Global.getProfile() + "/");
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + Global.getProfile() + "/");
/** swagger配置 */
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
@@ -199,7 +199,7 @@ public class ShiroConfig
* 安全管理器
*/
@Bean
public SecurityManager securityManager(UserRealm userRealm, SpringSessionValidationScheduler springSessionValidationScheduler)
public SecurityManager securityManager(UserRealm userRealm)
{
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// 设置realm.
@@ -1,6 +1,8 @@
package com.ruoyi.framework.manager;
import com.ruoyi.framework.shiro.web.session.SpringSessionValidationScheduler;
import net.sf.ehcache.CacheManager;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -20,11 +22,15 @@ public class ShutdownManager
@Autowired(required = false)
private SpringSessionValidationScheduler springSessionValidationScheduler;
@Autowired(required = false)
private EhCacheManager ehCacheManager;
@PreDestroy
public void destroy()
{
shutdownSpringSessionValidationScheduler();
shutdownAsyncManager();
shutdownEhCacheManager();
}
/**
@@ -61,4 +67,21 @@ public class ShutdownManager
logger.error(e.getMessage(), e);
}
}
private void shutdownEhCacheManager()
{
try
{
logger.info("====关闭缓存====");
if (ehCacheManager != null)
{
CacheManager cacheManager = ehCacheManager.getCacheManager();
cacheManager.shutdown();
}
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
}
}
}
@@ -19,7 +19,6 @@ import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.exception.user.CaptchaException;
import com.ruoyi.common.exception.user.RoleBlockedException;
import com.ruoyi.common.exception.user.UserBlockedException;
@@ -83,4 +83,8 @@ public class SysPasswordService
return new Md5Hash(username + password + salt).toHex().toString();
}
public void unlock(String loginName){
loginRecordCache.remove(loginName);
}
}
@@ -8,7 +8,6 @@ import org.apache.shiro.web.session.mgt.WebSessionContext;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.IpUtils;
import com.ruoyi.common.utils.ServletUtils;
import eu.bitwalker.useragentutils.UserAgent;
/**
@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.Threads;
@@ -39,6 +40,7 @@ public class SpringSessionValidationScheduler implements SessionValidationSchedu
*/
@Autowired
@Qualifier("sessionManager")
@Lazy
private ValidatingSessionManager sessionManager;
// 相隔多久检查一次session的有效性,单位毫秒,默认就是10分钟
@@ -7,7 +7,6 @@ import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.SimplePrincipalCollection;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.shiro.realm.UserRealm;
@@ -1,8 +1,14 @@
package com.ruoyi.framework.web.service;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.security.PermissionUtils;
import com.ruoyi.common.utils.StringUtils;
/**
* RuoYi首创 js调用 thymeleaf 实现按钮权限可见性
@@ -12,38 +18,217 @@ import com.ruoyi.common.utils.security.PermissionUtils;
@Service("permission")
public class PermissionService
{
private static final Logger log = LoggerFactory.getLogger(PermissionService.class);
/** 没有权限,hidden用于前端隐藏按钮 */
public static final String NOACCESS = "hidden";
private static final String ROLE_DELIMETER = ",";
private static final String PERMISSION_DELIMETER = ",";
/**
* 验证用户是否具备某权限,无权限返回hidden用于前端隐藏(如需返回Boolean使用isPermitted)
*
* @param permission 权限字符串
* @return 用户是否具备某权限
*/
public String hasPermi(String permission)
{
return isPermittedOperator(permission) ? "" : "hidden";
return isPermitted(permission) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否不具备某权限,与 hasPermi逻辑相反。无权限返回hidden用于前端隐藏(如需返回Boolean使用isLacksPermitted)
*
* @param permission 权限字符串
* @return 用户是否不具备某权限
*/
public String lacksPermi(String permission)
{
return isLacksPermitted(permission) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否具有以下任意一个权限,无权限返回hidden用于隐藏(如需返回Boolean使用hasAnyPermissions)
*
* @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
* @return 用户是否具有以下任意一个权限
*/
public String hasAnyPermi(String permissions)
{
return hasAnyPermissions(permissions, PERMISSION_DELIMETER) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否具备某角色,无权限返回hidden用于隐藏(如需返回Boolean使用isRole)
*
* @param role 角色字符串
* @return 用户是否具备某角色
*/
public String hasRole(String role)
{
return hasRoleOperator(role) ? "" : "hidden";
return isRole(role) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否不具备某角色,与hasRole逻辑相反。无权限返回hidden用于隐藏(如需返回Boolean使用isLacksRole)
*
* @param role 角色字符串
* @return 用户是否不具备某角色
*/
public String lacksRole(String role)
{
return isLacksRole(role) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否具有以下任意一个角色,无权限返回hidden用于隐藏(如需返回Boolean使用isAnyRoles)
*
* @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
* @return 用户是否具有以下任意一个角色
*/
public String hasAnyRoles(String roles)
{
return isAnyRoles(roles, ROLE_DELIMETER) ? StringUtils.EMPTY : NOACCESS;
}
/**
* 验证用户是否认证通过或已记住的用户。
*
* @return 用户是否认证通过或已记住的用户
*/
public boolean isUser()
{
Subject subject = SecurityUtils.getSubject();
return subject != null && subject.getPrincipal() != null;
}
/**
* 判断用户是否拥有某个权限
*
* @param permission 权限字符串
* @return 结果
* @return 用户是否具备某权限
*/
private boolean isPermittedOperator(String permission)
public boolean isPermitted(String permission)
{
return SecurityUtils.getSubject().isPermitted(permission);
}
/**
* 判断用户是否不具备某权限,与 isPermitted逻辑相反。
*
* @param permission 权限名称
* @return 用户是否不具备某权限
*/
public boolean isLacksPermitted(String permission)
{
return isPermitted(permission) != true;
}
/**
* 验证用户是否具有以下任意一个权限。
*
* @param permissions 以 PERMISSION_NAMES_DELIMETER 为分隔符的权限列表
* @return 用户是否具有以下任意一个权限
*/
public boolean hasAnyPermissions(String permissions)
{
return hasAnyPermissions(permissions, PERMISSION_DELIMETER);
}
/**
* 验证用户是否具有以下任意一个权限。
*
* @param permissions 以 delimeter 为分隔符的权限列表
* @param delimeter 权限列表分隔符
* @return 用户是否具有以下任意一个权限
*/
public boolean hasAnyPermissions(String permissions, String delimeter)
{
Subject subject = SecurityUtils.getSubject();
if (subject != null)
{
if (delimeter == null || delimeter.length() == 0)
{
delimeter = PERMISSION_DELIMETER;
}
for (String permission : permissions.split(delimeter))
{
if (permission != null && subject.isPermitted(permission.trim()) == true)
{
return true;
}
}
}
return false;
}
/**
* 判断用户是否拥有某个角色
*
* @param role 角色字符串
* @return 结果
* @return 用户是否具备某角色
*/
private boolean hasRoleOperator(String role)
public boolean isRole(String role)
{
return SecurityUtils.getSubject().hasRole(role);
}
/**
* 验证用户是否不具备某角色,与 isRole逻辑相反。
*
* @param role 角色名称
* @return 用户是否不具备某角色
*/
public boolean isLacksRole(String role)
{
return isRole(role) != true;
}
/**
* 验证用户是否具有以下任意一个角色。
*
* @param roles 以 ROLE_NAMES_DELIMETER 为分隔符的角色列表
* @return 用户是否具有以下任意一个角色
*/
public boolean isAnyRoles(String roles)
{
return isAnyRoles(roles, ROLE_DELIMETER);
}
/**
* 验证用户是否具有以下任意一个角色。
*
* @param roles 以 delimeter 为分隔符的角色列表
* @param delimeter 角色列表分隔符
* @return 用户是否具有以下任意一个角色
*/
public boolean isAnyRoles(String roles, String delimeter)
{
Subject subject = SecurityUtils.getSubject();
if (subject != null)
{
if (delimeter == null || delimeter.length() == 0)
{
delimeter = ROLE_DELIMETER;
}
for (String role : roles.split(delimeter))
{
if (subject.hasRole(role.trim()) == true)
{
return true;
}
}
}
return false;
}
/**
* 返回用户属性值
*
@@ -52,6 +237,26 @@ public class PermissionService
*/
public Object getPrincipalProperty(String property)
{
return PermissionUtils.getPrincipalProperty(property);
Subject subject = SecurityUtils.getSubject();
if (subject != null)
{
Object principal = subject.getPrincipal();
try
{
BeanInfo bi = Introspector.getBeanInfo(principal.getClass());
for (PropertyDescriptor pd : bi.getPropertyDescriptors())
{
if (pd.getName().equals(property) == true)
{
return pd.getReadMethod().invoke(principal, (Object[]) null);
}
}
}
catch (Exception e)
{
log.error("Error reading property [{}] from principal of type [{}]", property, principal.getClass().getName());
}
}
return null;
}
}