dev
parent
51f5fccae3
commit
5d13b00a56
|
|
@ -13,19 +13,46 @@ public class OSSKit {
|
|||
private static OSSClient _ossClient;
|
||||
private static String bucketName;
|
||||
|
||||
public static OSSClient getCli() {
|
||||
return OSSKit._ossClient;
|
||||
private static String endpoint;
|
||||
private static String accessKeyId = "LTAIqQ3TXBgNGBWi";
|
||||
private static String accessKeySecret = "CGbPXdfX4xca3uaN2cOmTzjsG4jd6O";
|
||||
|
||||
public static void init(String endpoint, String bucketName) {
|
||||
OSSKit.endpoint = endpoint;
|
||||
OSSKit.bucketName = bucketName;
|
||||
}
|
||||
|
||||
public static void setCli(OSSClient cli, String bucketName) {
|
||||
OSSKit._ossClient = cli;
|
||||
OSSKit.bucketName = bucketName;
|
||||
public static void start() {
|
||||
try {
|
||||
OSSKit._ossClient = new OSSClient(OSSKit.endpoint, OSSKit.accessKeyId, OSSKit.accessKeySecret);
|
||||
|
||||
if (!OSSKit._ossClient.doesBucketExist(OSSKit.bucketName)) {
|
||||
log.error("bucket %s 不存在", OSSKit.bucketName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean stop() {
|
||||
if (OSSKit._ossClient != null) {
|
||||
OSSKit._ossClient.shutdown();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean putObject(String key, File file) throws Exception {
|
||||
if (_ossClient == null) {
|
||||
log.error("没有初始化 OSSMgrClient");
|
||||
return false;
|
||||
|
||||
OSSKit.start();
|
||||
|
||||
if (_ossClient == null) {
|
||||
log.error("OSSMgrClient 初始化失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StrKit.notBlank(key) || file == null || !file.exists() || file.isDirectory()) {
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
package com.cowr.common.oss;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.jfinal.plugin.IPlugin;
|
||||
|
||||
public class OSSPlugin implements IPlugin {
|
||||
private OSSClient _ossClient;
|
||||
public static OSSPlugin cli;
|
||||
|
||||
private String endpoint;
|
||||
private static String accessKeyId = "LTAIqQ3TXBgNGBWi";
|
||||
private static String accessKeySecret = "CGbPXdfX4xca3uaN2cOmTzjsG4jd6O";
|
||||
private String bucketName;
|
||||
|
||||
public OSSPlugin(String endpoint, String bucketName) {
|
||||
this.endpoint = endpoint;
|
||||
this.bucketName = bucketName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
try {
|
||||
this._ossClient = new OSSClient(this.endpoint, this.accessKeyId, this.accessKeySecret);
|
||||
|
||||
if (!this._ossClient.doesBucketExist(this.bucketName)) {
|
||||
this._ossClient.createBucket(this.bucketName);
|
||||
}
|
||||
|
||||
OSSKit.setCli(this._ossClient, bucketName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 不论是否发生异常,都要返回 true,否则 jfinal 启动不起来
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
if (this._ossClient != null) {
|
||||
this._ossClient.shutdown();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package com.cowr.local.ssjygl.main;
|
|||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.wall.WallFilter;
|
||||
import com.cowr.common.ctrl.HomeController;
|
||||
import com.cowr.common.oss.OSSPlugin;
|
||||
import com.cowr.common.oss.OSSKit;
|
||||
import com.cowr.local.ssjygl.customer.pact.CustomerPactController;
|
||||
import com.cowr.ssjygl.actioncmdlog.ActionCmdLogController;
|
||||
import com.cowr.local.ssjygl.authlicense.AuthLicenseController;
|
||||
|
|
@ -281,9 +281,6 @@ public class Config extends JFinalConfig {
|
|||
0
|
||||
));
|
||||
}
|
||||
|
||||
// 没有外网时,oss 连接失败会导致系统启动失败
|
||||
me.add(new OSSPlugin(configprop.get("endpoint"), configprop.get("bucketName")));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -361,6 +358,14 @@ public class Config extends JFinalConfig {
|
|||
deviceThread.setSupermarket_id(CliCacheData.SUP.getId());
|
||||
deviceThread.start();
|
||||
// }
|
||||
|
||||
OSSKit.init(configprop.get("endpoint"), configprop.get("bucketName"));
|
||||
// 系统启动时没有网络会 start 失败
|
||||
try {
|
||||
OSSKit.start();
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
@ -382,6 +387,8 @@ public class Config extends JFinalConfig {
|
|||
if (socketio != null) {
|
||||
socketio.stop();
|
||||
}
|
||||
|
||||
OSSKit.stop();
|
||||
}
|
||||
|
||||
public static boolean isDev() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue