dev
parent
9b3624a0af
commit
003fc2a901
|
|
@ -138,6 +138,12 @@
|
||||||
<version>4.5.3</version>
|
<version>4.5.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
|
<version>2.8.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.cowr.common.oss;
|
||||||
|
|
||||||
|
import com.aliyun.oss.OSSClient;
|
||||||
|
import com.aliyun.oss.model.ObjectMetadata;
|
||||||
|
import com.jfinal.kit.StrKit;
|
||||||
|
import com.jfinal.log.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
public class OSSKit {
|
||||||
|
private static Log log = Log.getLog(OSSKit.class);
|
||||||
|
private static OSSClient _ossClient;
|
||||||
|
private static String bucketName;
|
||||||
|
|
||||||
|
public static OSSClient getCli() {
|
||||||
|
return OSSKit._ossClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCli(OSSClient cli, String bucketName) {
|
||||||
|
OSSKit._ossClient = cli;
|
||||||
|
OSSKit.bucketName = bucketName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean putObject(String key, File file) throws Exception {
|
||||||
|
if (_ossClient == null) {
|
||||||
|
log.error("没有初始化 OSSMgrClient");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StrKit.notBlank(key) || file == null || !file.exists() || file.isDirectory()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long st = System.currentTimeMillis();
|
||||||
|
|
||||||
|
ObjectMetadata meta = new ObjectMetadata();
|
||||||
|
meta.setContentDisposition("attachment; filename=" + URLEncoder.encode(file.getName(), "UTF-8"));
|
||||||
|
|
||||||
|
_ossClient.putObject(bucketName, key, file, meta);
|
||||||
|
|
||||||
|
log.debug("oss put time: " + (System.currentTimeMillis() - st) + ", file size: " + file.length());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean delObject(String key) throws Exception {
|
||||||
|
if (_ossClient == null) {
|
||||||
|
log.error("没有初始化 OSSMgrClient");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_ossClient.doesObjectExist(bucketName, key)) {
|
||||||
|
_ossClient.deleteObject(bucketName, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// new OSSPlugin("oss-cn-shenzhen.aliyuncs.com", "hsjygl").start();
|
||||||
|
// ObjectListing list = OSSKit.getCli().listObjects(new ListObjectsRequest("hsjygl").withMaxKeys(1000).withPrefix("file"));
|
||||||
|
//
|
||||||
|
// List<OSSObjectSummary> arr = list.getObjectSummaries();
|
||||||
|
//
|
||||||
|
// while (arr.size() > 999){
|
||||||
|
// System.out.println("继续删除:" + arr.size());
|
||||||
|
//
|
||||||
|
// for(OSSObjectSummary obj : arr){
|
||||||
|
// if(obj.getSize() == 0){
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if( obj.getLastModified().getTime() < System.currentTimeMillis() - 4 * 60 * 60 * 1000 ){
|
||||||
|
// System.out.println(obj.getKey() + " " + obj.getLastModified() + " " + obj.getSize());
|
||||||
|
// OSSKit.getCli().deleteObject("hsjygl", obj.getKey());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// arr = list.getObjectSummaries();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// System.out.println(list);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
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);
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stop() {
|
||||||
|
if (this._ossClient != null) {
|
||||||
|
this._ossClient.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.cowr.local.ssjygl.jobs;
|
package com.cowr.local.ssjygl.jobs;
|
||||||
|
|
||||||
|
import com.cowr.local.ssjygl.ossfilelog.OssfileLogService;
|
||||||
import com.cowr.local.ssjygl.synctask.SyncTaskService;
|
import com.cowr.local.ssjygl.synctask.SyncTaskService;
|
||||||
import com.jfinal.log.Log;
|
import com.jfinal.log.Log;
|
||||||
import org.quartz.Job;
|
import org.quartz.Job;
|
||||||
|
|
@ -14,5 +15,11 @@ public class SyncJob implements Job {
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
OssfileLogService.me.checkUploadStatus();
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cowr.local.ssjygl.main;
|
||||||
import com.alibaba.druid.filter.stat.StatFilter;
|
import com.alibaba.druid.filter.stat.StatFilter;
|
||||||
import com.alibaba.druid.wall.WallFilter;
|
import com.alibaba.druid.wall.WallFilter;
|
||||||
import com.cowr.common.ctrl.HomeController;
|
import com.cowr.common.ctrl.HomeController;
|
||||||
|
import com.cowr.common.oss.OSSPlugin;
|
||||||
import com.cowr.ssjygl.actioncmdlog.ActionCmdLogController;
|
import com.cowr.ssjygl.actioncmdlog.ActionCmdLogController;
|
||||||
import com.cowr.local.ssjygl.authlicense.AuthLicenseController;
|
import com.cowr.local.ssjygl.authlicense.AuthLicenseController;
|
||||||
import com.cowr.local.ssjygl.authlicense.AuthLicenseSyncService;
|
import com.cowr.local.ssjygl.authlicense.AuthLicenseSyncService;
|
||||||
|
|
@ -272,6 +273,8 @@ public class Config extends JFinalConfig {
|
||||||
0
|
0
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
me.add(new OSSPlugin(configprop.get("endpoint"), configprop.get("bucketName")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.cowr.local.ssjygl.ossfilelog;
|
||||||
|
|
||||||
|
import com.cowr.common.oss.OSSKit;
|
||||||
|
import com.cowr.model.OssfileLog;
|
||||||
|
import com.jfinal.kit.StrKit;
|
||||||
|
import com.jfinal.log.Log;
|
||||||
|
import com.jfinal.plugin.activerecord.Db;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OssfileLogService {
|
||||||
|
private static Log log = Log.getLog(OssfileLogService.class);
|
||||||
|
public static OssfileLogService me = new OssfileLogService();
|
||||||
|
|
||||||
|
public void save(String transport_id, String osskey, String absolutepath){
|
||||||
|
OssfileLog ossfile = new OssfileLog();
|
||||||
|
ossfile.setId(StrKit.getRandomUUID());
|
||||||
|
ossfile.setTransportId(transport_id);
|
||||||
|
ossfile.setOsskey(osskey);
|
||||||
|
ossfile.setAbsolutepath(absolutepath);
|
||||||
|
ossfile.setCreateTime(new Date());
|
||||||
|
ossfile.setState(0);
|
||||||
|
|
||||||
|
ossfile.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkUploadStatus(){
|
||||||
|
List<OssfileLog> logs = OssfileLog.dao.find("select * from ossfile_log t where t.state = 0 limit 10");
|
||||||
|
List<OssfileLog> ups = new ArrayList<>();
|
||||||
|
|
||||||
|
log.debug("上传 %s 张图片到 oss", logs.size());
|
||||||
|
|
||||||
|
for(OssfileLog ossfile : logs){
|
||||||
|
try {
|
||||||
|
if(OSSKit.putObject(ossfile.getOsskey(), new File(ossfile.getAbsolutepath()))){
|
||||||
|
ossfile.setState(1);
|
||||||
|
|
||||||
|
ups.add(ossfile);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!ups.isEmpty()){
|
||||||
|
Db.batchUpdate(ups, ups.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,6 +10,7 @@ import com.cowr.local.ssjygl.devicectrl.common.Const;
|
||||||
import com.cowr.local.ssjygl.main.CliCacheData;
|
import com.cowr.local.ssjygl.main.CliCacheData;
|
||||||
import com.cowr.local.ssjygl.main.Config;
|
import com.cowr.local.ssjygl.main.Config;
|
||||||
import com.cowr.local.ssjygl.order.LocalOrderService;
|
import com.cowr.local.ssjygl.order.LocalOrderService;
|
||||||
|
import com.cowr.local.ssjygl.ossfilelog.OssfileLogService;
|
||||||
import com.cowr.local.ssjygl.synctask.SyncTaskService;
|
import com.cowr.local.ssjygl.synctask.SyncTaskService;
|
||||||
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
|
import com.cowr.local.ssjygl.system.sysuser.SysuserSyncService;
|
||||||
import com.cowr.model.*;
|
import com.cowr.model.*;
|
||||||
|
|
@ -264,6 +265,10 @@ public class TransportSyncService {
|
||||||
try {
|
try {
|
||||||
boolean ret = transport.save() && SyncTaskService.me.save(new SyncTask().addSaveData(transport));
|
boolean ret = transport.save() && SyncTaskService.me.save(new SyncTask().addSaveData(transport));
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
OssfileLogService.me.save(transport.getId(), transport.getFirstPic(), file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -314,6 +319,10 @@ public class TransportSyncService {
|
||||||
try {
|
try {
|
||||||
boolean ret = transport.update() && SyncTaskService.me.save(new SyncTask().addUpdateData(transport));
|
boolean ret = transport.update() && SyncTaskService.me.save(new SyncTask().addUpdateData(transport));
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
OssfileLogService.me.save(transport.getId(), transport.getSecondPic(), file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -374,6 +383,10 @@ public class TransportSyncService {
|
||||||
try {
|
try {
|
||||||
boolean ret = finalTransport.save() && SyncTaskService.me.save(new SyncTask().addSaveData(finalTransport));
|
boolean ret = finalTransport.save() && SyncTaskService.me.save(new SyncTask().addSaveData(finalTransport));
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
OssfileLogService.me.save(finalTransport.getId(), finalTransport.getFirstPic(), file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -398,6 +411,10 @@ public class TransportSyncService {
|
||||||
try {
|
try {
|
||||||
boolean ret = finalTransport1.update() && SyncTaskService.me.save(new SyncTask().addUpdateData(finalTransport1));
|
boolean ret = finalTransport1.update() && SyncTaskService.me.save(new SyncTask().addUpdateData(finalTransport1));
|
||||||
|
|
||||||
|
if(ret){
|
||||||
|
OssfileLogService.me.save(finalTransport1.getId(), finalTransport1.getSecondPic(), file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
|
|
||||||
devMode=true
|
devMode=true
|
||||||
|
|
||||||
|
endpoint=oss-cn-shenzhen-internal.aliyuncs.com
|
||||||
|
#正式、测试的附件,都存入正式的 oss 中
|
||||||
|
bucketName=ssjygl-xsx-static
|
||||||
|
|
||||||
#本地服务 和 云端服务 socket 通信
|
#本地服务 和 云端服务 socket 通信
|
||||||
socketserver.enable=true
|
socketserver.enable=true
|
||||||
#socketserver.host=120.77.59.235
|
#socketserver.host=120.77.59.235
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
|
|
||||||
devMode=true
|
devMode=true
|
||||||
|
|
||||||
|
endpoint=oss-cn-shenzhen.aliyuncs.com
|
||||||
|
#正式、测试的附件,都存入正式的 oss 中
|
||||||
|
bucketName=ssjygl-xsx-static
|
||||||
|
|
||||||
#本地服务 和 云端服务 socket 通信
|
#本地服务 和 云端服务 socket 通信
|
||||||
socketserver.enable=true
|
socketserver.enable=true
|
||||||
socketserver.host=47.112.109.118
|
socketserver.host=47.112.109.118
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue