|
|
@@ -11,6 +11,7 @@ import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.modules.alioss.bo.OssCallbackParam;
|
|
|
+import com.zhongzheng.modules.alioss.bo.OssRequest;
|
|
|
import com.zhongzheng.modules.alioss.service.OssService;
|
|
|
import com.zhongzheng.modules.alioss.vo.ResultBean;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -46,11 +47,11 @@ public class OssServiceImpl implements OssService {
|
|
|
private OSSClient ossClient;
|
|
|
|
|
|
@Override
|
|
|
- public ResultBean getPolicy() {
|
|
|
+ public ResultBean getPolicy(OssRequest ossRequest) {
|
|
|
JSONObject resultBean = new JSONObject();
|
|
|
// 存储目录
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
- String dir = ALIYUN_OSS_DIR_PREFIX+sdf.format(new Date())+"/"+ this.generateRandomFilename();
|
|
|
+
|
|
|
+ String dir = ALIYUN_OSS_DIR_PREFIX+ this.generateRandomFilename(ossRequest);
|
|
|
// 签名有效期
|
|
|
long expireEndTime = System.currentTimeMillis() + ALIYUN_OSS_EXPIRE * 1000;
|
|
|
Date expiration = new Date(expireEndTime);
|
|
|
@@ -84,12 +85,12 @@ public class OssServiceImpl implements OssService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public String generateRandomFilename() {
|
|
|
+ public String generateRandomFilename(OssRequest ossRequest) {
|
|
|
String RandomFilename = "";
|
|
|
//生成随机数
|
|
|
Random rand = new Random();
|
|
|
int random = rand.nextInt();
|
|
|
-
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
Calendar calCurrent = Calendar.getInstance();
|
|
|
int intDay = calCurrent.get(Calendar.DATE);
|
|
|
int intMonth = calCurrent.get(Calendar.MONTH) + 1;
|
|
|
@@ -98,6 +99,29 @@ public class OssServiceImpl implements OssService {
|
|
|
String.valueOf(intDay) + "_";
|
|
|
|
|
|
RandomFilename = now + String.valueOf(random > 0 ? random : (-1) * random);
|
|
|
+ switch(ossRequest.getImageStatus()){
|
|
|
+ case 0 :
|
|
|
+ RandomFilename = "avatar"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 1 :
|
|
|
+ RandomFilename = "IDNumber"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 2 :
|
|
|
+ RandomFilename = "QuestionBank"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 3 :
|
|
|
+ RandomFilename = "guide"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 4 :
|
|
|
+ RandomFilename = "advertising"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 5 :
|
|
|
+ RandomFilename = "IDCard"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ case 6 :
|
|
|
+ RandomFilename = "file"+"/"+sdf.format(new Date())+"/"+RandomFilename;
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
return RandomFilename;
|
|
|
|