Jeecg-Boot 2.1.2版本发布

This commit is contained in:
zhangdaihao
2019-11-21 18:17:25 +08:00
parent 1cbc85382f
commit f742ae22a8
84 changed files with 2284 additions and 33459 deletions

View File

@ -116,10 +116,13 @@ public class ShiroConfig {
//测试示例
filterChainDefinitionMap.put("/test/jeecgDemo/html", "anon"); //模板页面
filterChainDefinitionMap.put("/test/jeecgDemo/redis/**", "anon"); //redis测试
//排除Online请求
filterChainDefinitionMap.put("/auto/cgform/**", "anon");
//websocket排除
filterChainDefinitionMap.put("/websocket/**", "anon");
// 添加自己的过滤器并且取名为jwt
Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
filterMap.put("jwt", new JwtFilter());
@ -205,7 +208,9 @@ public class ShiroConfig {
public RedisManager redisManager() {
log.info("===============(2)创建RedisManager,连接Redis..URL= " + host + ":" + port);
RedisManager redisManager = new RedisManager();
redisManager.setHost(host + ":" + port);//老版本是分别setHost和setPort,新版本只需要setHost就可以了
redisManager.setHost(host);
redisManager.setPort(oConvertUtils.getInt(port));
redisManager.setTimeout(0);
if (!StringUtils.isEmpty(redisPassword)) {
redisManager.setPassword(redisPassword);
}

View File

@ -136,35 +136,23 @@ public class MybatisInterceptor implements Interceptor {
log.debug("------field.name------" + field.getName());
try {
if ("updateBy".equals(field.getName())) {
field.setAccessible(true);
Object local_updateBy = field.get(parameter);
field.setAccessible(false);
if (local_updateBy == null || local_updateBy.equals("")) {
String updateBy = "jeecg";
// 获取登录用户信息
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if (sysUser != null) {
// 登录账号
updateBy = sysUser.getUsername();
}
if (oConvertUtils.isNotEmpty(updateBy)) {
field.setAccessible(true);
field.set(parameter, updateBy);
field.setAccessible(false);
}
//获取登录用户信息
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
if (sysUser != null) {
// 登录账号
String updateBy = sysUser.getUsername();
field.setAccessible(true);
field.set(parameter, updateBy);
field.setAccessible(false);
}
}
if ("updateTime".equals(field.getName())) {
field.setAccessible(true);
Object local_updateDate = field.get(parameter);
field.set(parameter, new Date());
field.setAccessible(false);
if (local_updateDate == null || local_updateDate.equals("")) {
field.setAccessible(true);
field.set(parameter, new Date());
field.setAccessible(false);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,35 +0,0 @@
package org.jeecg.config.oss;
import org.jeecg.config.oss.OSSAutoConfiguration.OSSConfigurationImportSelector;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
/**
* Object Storage Service auto configuration.
*/
@Configuration
@EnableConfigurationProperties(OSSProperties.class)
@Import(OSSConfigurationImportSelector.class)
public class OSSAutoConfiguration {
/**
* {@link ImportSelector} to add {@link OSSType} configuration classes.
*/
static class OSSConfigurationImportSelector implements ImportSelector {
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
OSSType[] types = OSSType.values();
String[] imports = new String[types.length];
for (int i = 0; i < types.length; i++) {
imports[i] = OSSConfigurations.getConfigurationClass(types[i]);
}
return imports;
}
}
}

View File

@ -1,43 +0,0 @@
package org.jeecg.config.oss;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.context.properties.bind.BindException;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
/**
* General OSS condition used with all OSS configuration classes.
*/
public class OSSCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
String sourceClass = "";
if (metadata instanceof ClassMetadata) {
sourceClass = ((ClassMetadata) metadata).getClassName();
}
ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
Environment environment = context.getEnvironment();
try {
BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
if (!specified.isBound()) {
return ConditionOutcome.match(message.because("automatic OSS type"));
}
OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
if (specified.get() == required) {
return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
}
}
catch (BindException ex) {
}
return ConditionOutcome.noMatch(message.because("unknown OSS type"));
}
}

View File

@ -1,44 +0,0 @@
package org.jeecg.config.oss;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import org.jeecg.config.oss.aliyun.AliYunOSSAutoConfiguration;
import org.jeecg.config.oss.tencent.QcCOSAutoConfiguration;
import org.springframework.util.Assert;
/**
* Mappings between {@link OSSType} and {@code @Configuration}.
*/
final class OSSConfigurations {
private static final Map<OSSType, Class<?>> MAPPINGS;
static {
Map<OSSType, Class<?>> mappings = new EnumMap<>(OSSType.class);
mappings.put(OSSType.ALIYUN, AliYunOSSAutoConfiguration.class);
mappings.put(OSSType.QC, QcCOSAutoConfiguration.class);
MAPPINGS = Collections.unmodifiableMap(mappings);
}
private OSSConfigurations() {
}
public static String getConfigurationClass(OSSType ossType) {
Class<?> configurationClass = MAPPINGS.get(ossType);
Assert.state(configurationClass != null, () -> "Unknown OSS type " + ossType);
return configurationClass.getName();
}
public static OSSType getType(String configurationClassName) {
for (Map.Entry<OSSType, Class<?>> entry : MAPPINGS.entrySet()) {
if (entry.getValue().getName().equals(configurationClassName)) {
return entry.getKey();
}
}
throw new IllegalStateException("Unknown configuration class " + configurationClassName);
}
}

View File

@ -1,15 +0,0 @@
package org.jeecg.config.oss;
import java.io.InputStream;
/**
* 简单上传,删除对象接口.
* 可扩展
*/
public interface OSSManager {
void upload(String fileName, InputStream inputStream);
void delete(String fileName);
}

View File

@ -1,48 +0,0 @@
package org.jeecg.config.oss;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Configuration properties for OSS support.
*/
@Getter
@Setter
@ConfigurationProperties(prefix = "jeecg.oss")
public class OSSProperties {
/**
* OSS type.
*/
private OSSType type;
/**
* OSS Endpoint.
*/
private String endpoint;
/**
* OSS Access key.
*/
private String accessKey;
/**
* OSS Secret key.
*/
private String secretKey;
/**
* OSS Bucket Name.
*/
private String bucketName;
/**
* Additional OSS properties.
*/
private Map<String, String> properties = new HashMap<>();
}

View File

@ -1,10 +0,0 @@
package org.jeecg.config.oss;
/**
* Supported OSS types.
*/
public enum OSSType {
ALIYUN, QC
}

View File

@ -0,0 +1,31 @@
package org.jeecg.config.oss;
import org.jeecg.common.util.oss.OssBootUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OssBootConfiguration {
@Value("${jeecg.oss.endpoint}")
private String endpoint;
@Value("${jeecg.oss.accessKey}")
private String accessKeyId;
@Value("${jeecg.oss.secretKey}")
private String accessKeySecret;
@Value("${jeecg.oss.bucketName}")
private String bucketName;
@Value("${jeecg.oss.staticDomain}")
private String staticDomain;
@Bean
public void initOssBootConfiguration() {
OssBootUtil.setEndPoint(endpoint);
OssBootUtil.setAccessKeyId(accessKeyId);
OssBootUtil.setAccessKeySecret(accessKeySecret);
OssBootUtil.setBucketName(bucketName);
OssBootUtil.setStaticDomain(staticDomain);
}
}

View File

@ -1,81 +0,0 @@
package org.jeecg.config.oss.aliyun;
import java.util.Map;
import java.util.Properties;
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.comm.Protocol;
import org.jeecg.config.oss.OSSCondition;
import org.jeecg.config.oss.OSSManager;
import org.jeecg.config.oss.OSSProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
/**
* AliYun OSS configuration.
*/
@Configuration
@ConditionalOnClass({ OSS.class })
@ConditionalOnProperty(prefix = "jeecg.oss", name = "type",havingValue = "aliyun")
@Conditional(OSSCondition.class)
public class AliYunOSSAutoConfiguration {
private final OSSProperties properties;
public AliYunOSSAutoConfiguration(OSSProperties ossProperties) {
this.properties = ossProperties;
}
@Bean
@ConditionalOnMissingBean
public ClientBuilderConfiguration clientConfiguration(OSSProperties ossProperties) {
Properties properties = asProperties(ossProperties.getProperties());
ClientBuilderConfiguration configuration = new ClientBuilderConfiguration();
configuration.setMaxConnections(Integer.parseInt(properties.getProperty("aliyun.maxConnections", "5")));
configuration.setSocketTimeout(Integer.parseInt(properties.getProperty("aliyun.socketTimeout", "50000")));
configuration
.setConnectionTimeout(Integer.parseInt(properties.getProperty("aliyun.connectionTimeout", "50000")));
configuration.setConnectionRequestTimeout(
Integer.parseInt(properties.getProperty("aliyun.connectionRequestTimeout", "-1")));
configuration
.setIdleConnectionTime(Integer.parseInt(properties.getProperty("aliyun.idleConnectionTime", "60000")));
configuration.setMaxErrorRetry(Integer.parseInt(properties.getProperty("aliyun.maxErrorRetry", "3")));
configuration.setSupportCname(Boolean.parseBoolean(properties.getProperty("aliyun.supportCname", "false")));
configuration.setSLDEnabled(Boolean.parseBoolean(properties.getProperty("aliyun.sldEnabled", "false")));
configuration.setProtocol(Protocol.HTTP);
if (Protocol.HTTPS.toString().equals(properties.getProperty("aliyun.protocol"))) {
configuration.setProtocol(Protocol.HTTPS);
}
if (properties.getProperty("aliyun.userAgent") != null) {
configuration.setUserAgent(properties.getProperty("aliyun.userAgent"));
}
return configuration;
}
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean
public OSS ossClient(ClientBuilderConfiguration clientConfiguration) {
return new OSSClientBuilder().build(this.properties.getEndpoint(), this.properties.getAccessKey(),
this.properties.getSecretKey(), clientConfiguration);
}
@Bean
@ConditionalOnMissingBean
public OSSManager ossManager(OSS ossClient) {
return new AliYunOSSManager(ossClient, this.properties);
}
private Properties asProperties(Map<String, String> source) {
Properties properties = new Properties();
properties.putAll(source);
return properties;
}
}

View File

@ -1,33 +0,0 @@
package org.jeecg.config.oss.aliyun;
import java.io.InputStream;
import com.aliyun.oss.OSS;
import org.jeecg.config.oss.OSSManager;
import org.jeecg.config.oss.OSSProperties;
/**
* Object Storage Service of AliYun.
*/
public class AliYunOSSManager implements OSSManager {
private OSS client;
private OSSProperties properties;
AliYunOSSManager(OSS client, OSSProperties properties) {
this.client = client;
this.properties = properties;
}
@Override
public void upload(String fileName, InputStream inputStream) {
this.client.putObject(this.properties.getBucketName(), fileName, inputStream);
}
@Override
public void delete(String fileName) {
this.client.deleteObject(this.properties.getBucketName(), fileName);
}
}

View File

@ -1,71 +0,0 @@
package org.jeecg.config.oss.tencent;
import java.util.Map;
import java.util.Properties;
import com.qcloud.cos.COS;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import org.jeecg.config.oss.OSSCondition;
import org.jeecg.config.oss.OSSManager;
import org.jeecg.config.oss.OSSProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnClass({ COS.class })
@ConditionalOnProperty(prefix = "jeecg.oss", name = "type",havingValue = "qc")
@Conditional(OSSCondition.class)
public class QcCOSAutoConfiguration {
private final OSSProperties properties;
public QcCOSAutoConfiguration(OSSProperties ossProperties) {
this.properties = ossProperties;
}
@Bean
@ConditionalOnMissingBean
public ClientConfig clientConfiguration(OSSProperties ossProperties) {
Properties properties = asProperties(ossProperties.getProperties());
ClientConfig configuration = new ClientConfig();
configuration.setMaxConnectionsCount(Integer.parseInt(properties.getProperty("qc.maxConnectionsCount", "5")));
configuration.setSocketTimeout(Integer.parseInt(properties.getProperty("qc.socketTimeout", "50000")));
configuration.setConnectionTimeout(Integer.parseInt(properties.getProperty("qc.connectionTimeout", "50000")));
configuration.setConnectionRequestTimeout(
Integer.parseInt(properties.getProperty("qc.connectionRequestTimeout", "-1")));
configuration.setRegion(new Region(properties.getProperty("qc.region")));
if (properties.getProperty("qc.userAgent") != null) {
configuration.setUserAgent(properties.getProperty("qc.userAgent"));
}
return configuration;
}
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean
public COS ossClient(ClientConfig clientConfig) {
COSCredentials cred = new BasicCOSCredentials(this.properties.getAccessKey(), this.properties.getSecretKey());
return new COSClient(cred, clientConfig);
}
@Bean
@ConditionalOnMissingBean
public OSSManager ossManager(COS client) {
return new QcCOSManager(client, this.properties);
}
private Properties asProperties(Map<String, String> source) {
Properties properties = new Properties();
properties.putAll(source);
return properties;
}
}

View File

@ -1,39 +0,0 @@
package org.jeecg.config.oss.tencent;
import java.io.InputStream;
import com.qcloud.cos.COS;
import com.qcloud.cos.model.ObjectMetadata;
import org.jeecg.config.oss.OSSManager;
import org.jeecg.config.oss.OSSProperties;
/**
* Object Storage Service of Tencent cloud.
*/
public class QcCOSManager implements OSSManager {
private COS client;
private OSSProperties properties;
QcCOSManager(COS client, OSSProperties properties) {
this.client = client;
this.properties = properties;
}
@Override
public void upload(String fileName, InputStream inputStream) {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(10);
objectMetadata.setContentType("application/octet-stream");
this.client.putObject(this.properties.getBucketName(),
this.properties.getProperties().get("qc.prefix") + "/" + fileName, inputStream, objectMetadata);
}
@Override
public void delete(String fileName) {
this.client.deleteObject(this.properties.getBucketName(),
this.properties.getProperties().get("qc.prefix") + "/" + fileName);
}
}