Browse Source

file upload

wangyunpeng 2 months ago
parent
commit
326caedefc

+ 49 - 0
api-module/src/main/java/com/tzld/piaoquan/api/controller/FileController.java

@@ -0,0 +1,49 @@
+package com.tzld.piaoquan.api.controller;
+
+import com.stuuudy.commons.external.filestorage.alibaba.AliOssConfig;
+import com.stuuudy.commons.external.filestorage.enums.EnumPublicBuckets;
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
+import com.tzld.piaoquan.api.common.exception.CommonException;
+import com.tzld.piaoquan.api.model.param.FileUploadParam;
+import com.tzld.piaoquan.api.model.vo.FileInfo;
+import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
+import com.tzld.piaoquan.growth.common.utils.AliOssFileTool;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+@RestController
+@RequestMapping("/file")
+public class FileController {
+
+    @PostMapping("/upload")
+    public CommonResponse<FileInfo> fileUpload(@Validated FileUploadParam param, BindingResult bindingResult) throws IOException {
+        if (bindingResult.hasErrors()) {
+            return CommonResponse.create(ExceptionEnum.PARAM_ERROR.getCode(), bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
+        if (StringUtils.isBlank(param.getFileUri())) {
+            String fileName = param.getFile().getOriginalFilename();
+            if (StringUtils.isBlank(fileName)) {
+                param.setFileUri("temp/" + System.currentTimeMillis());
+            } else {
+                param.setFileUri("temp/" + System.currentTimeMillis() + "_" + fileName.replace(" ", "_"));
+            }
+        }
+        String fileUrl = AliOssFileTool.saveInPublicReturnHost(param.getFile().getInputStream(),
+                EnumPublicBuckets.PUBBUCKET, param.getFileUri(), param.getFileType());
+        FileInfo fileInfo = new FileInfo();
+        fileInfo.setFileUrl(fileUrl);
+        String bucketName = AliOssConfig.getBucket(EnumPublicBuckets.PUBBUCKET.getBucketName());
+        boolean isExistFile = AliOssFileTool.getOssClient().doesObjectExist(bucketName, param.getFileUri());
+        if (!isExistFile){
+            throw new CommonException(ExceptionEnum.PARAM_ERROR.getCode(), "上传文件不存在!!");
+        }
+        return CommonResponse.create(fileInfo);
+    }
+
+}

+ 17 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/param/FileUploadParam.java

@@ -0,0 +1,17 @@
+package com.tzld.piaoquan.api.model.param;
+
+import com.stuuudy.commons.external.filestorage.enums.EnumFileType;
+import lombok.Data;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.validation.constraints.NotNull;
+@Data
+public class FileUploadParam {
+    @NotNull(message = "文件不能为空")
+    private MultipartFile file;
+
+    private String fileUri;
+
+    @NotNull(message = "文件类型不能为空")
+    private EnumFileType fileType;
+}

+ 25 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/FileInfo.java

@@ -0,0 +1,25 @@
+package com.tzld.piaoquan.api.model.vo;
+
+import lombok.Data;
+
+/**
+ * @author sunxy
+ */
+@Data
+public class FileInfo {
+
+    /**
+     * 文件名
+     */
+    private String fileName;
+
+    /**
+     * 文件URL
+     */
+    private String fileUrl;
+
+    /**
+     * 文件Size,单位KB
+     */
+    private Double fileSize;
+}

+ 16 - 0
api-module/src/main/resources/application.properties

@@ -63,3 +63,19 @@ author.interceptor.excludeUris[1]=/api-docs
 author.interceptor.excludeUris[2]=/swagger-ui.html
 author.interceptor.excludeUris[3]=/error
 author.interceptor.excludeUris[4]=/csrf
+
+oss.growth.accessKey=LTAIP6x1l3DXfSxm
+oss.growth.secretKey=KbTaM9ars4OX3PMS6Xm7rtxGr1FLon
+oss.growth.ossEndPoint=oss-cn-hangzhou.aliyuncs.com
+oss.growth.videoEndPoint=slicevideo.yishihui.com
+oss.growth.expiration=3600
+oss.growth.projectName=growth
+oss.growth.cdnDomain=http://rescdn.yishihui.com/
+oss.growth.imgDomain=http://rescdn.yishihui.com/
+oss.growth.videoDomain=http://rescdn.yishihui.com/
+oss.growth.lvvideoDomain=https://lvupload.piaoquantv.com/
+oss.growth.pubBucket=public:art-pubbucket,publicVideo:art-pubbucket
+oss.growth.priBucket=private:art-pribucket,privateVideo:art-privideo,privateVideoIn:art-privideo-in
+oss.growth.priEndPoint=pricdn.yishihui.com
+oss.growth.needPress=true
+oss.growth.internal.endPoint=oss-cn-hangzhou.aliyuncs.com

+ 27 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/common/enums/EnumUploadFileType.java

@@ -0,0 +1,27 @@
+package com.tzld.piaoquan.growth.common.common.enums;
+
+public enum EnumUploadFileType {
+	FILE(4,"4"),
+	GIF(5,"5"),
+	VIDEO(2,"2"),
+	VOICE(3,"3"),
+	PICTURE(1,"1");
+	private Integer intType;
+	private String strType;
+	EnumUploadFileType(Integer intType, String strType){
+		this.intType = intType;
+		this.strType = strType;
+	}
+	public Integer getIntType() {
+		return intType;
+	}
+	public void setIntType(Integer intType) {
+		this.intType = intType;
+	}
+	public String getStrType() {
+		return strType;
+	}
+	public void setStrType(String strType) {
+		this.strType = strType;
+	}
+}

+ 376 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/config/AliOssConfig.java

@@ -0,0 +1,376 @@
+package com.tzld.piaoquan.growth.common.config;
+
+import com.aliyun.oss.ClientConfiguration;
+import com.aliyun.oss.OSSClient;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.profile.DefaultProfile;
+import com.tzld.piaoquan.growth.common.model.vo.PolicyDetailVO;
+import com.tzld.piaoquan.growth.common.utils.AliOssFileTool;
+import com.tzld.piaoquan.growth.common.utils.PropertiesUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import javax.annotation.PostConstruct;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * @author zhaoyuchun
+ */
+@Configuration
+public class AliOssConfig {
+	/** 图片服务域名 **/
+	// public String picEndPoint;
+	/** 对象存储域名 **/
+	private static String ossEndPoint;
+	/** 阿里云accesskeyId **/
+	private static String accessKeyId;
+	/** 过期时间,单位秒 **/
+	private static long expiration;
+	/** 阿里云accessKeySecret **/
+	private static String accessKeySecret;
+	/** 文件系统配置文件地址 **/
+	public String configPath;
+	private static Boolean needPress;
+	private static String projectName;
+	private static String videoEndPoint;
+	private static String internalEndPoint;
+	private static OSSClient ossClient;
+	private static OSSClient priClient;
+	private static OSSClient videoClient;
+	private static OSSClient internalOssClient;
+
+	private static String snapshotLocation;
+	private static OSSClient ossReadOnlyClient;
+	private static IAcsClient mAcsClient;
+
+	private static DefaultAcsClient defaultAcsClient;
+	public static final String PIPELINEID = "abe6a0b9b9334858913eb416974485d2";
+	public static final String MTS_REGION = "cn-hangzhou";
+	public static final String OSS_REGION = "oss-cn-hangzhou";
+	private static PolicyDetailVO policyDetail;
+	static {
+		policyDetail = new PolicyDetailVO();
+		policyDetail.setVersion("1");
+		List<PolicyDetailVO.PolicyVO> statement = new ArrayList<PolicyDetailVO.PolicyVO>();
+		PolicyDetailVO.PolicyVO policy = new PolicyDetailVO.PolicyVO();
+		List<String> action = new ArrayList<String>();
+		List<String> resource = new ArrayList<String>();
+		action.add("oss:PutObject");
+		action.add("oss:AbortMultipartUpload");
+		action.add("oss:ListParts");
+		action.add("oss:AbortMultipartUpload");
+		action.add("oss:ListObjects");
+		resource.add("*");
+		policy.setEffect("Allow");
+		policy.setAction(action);
+		policy.setResource(resource);
+		statement.add(policy);
+		policyDetail.setStatement(statement);
+
+	}
+
+
+	public static OSSClient getVideoClient() {
+		return videoClient;
+	}
+
+	public void setVideoClient(OSSClient videoClient) {
+		AliOssConfig.videoClient = videoClient;
+	}
+
+	public static String cdnDomain;
+	public static String imgDomain;
+	public static String videoDomain;
+	public static String lvvideoDomain;
+	public static String pubBucket;
+	public static String priBucket;
+	public static String priEndPoint;
+	public static HashMap<String, String> bucketes = new HashMap<String, String>();
+	private static Logger logger = Logger.getLogger(AliOssFileTool.class);
+	public static String SUFFIX = "https://";
+	private String tmpStr;
+	@PostConstruct
+	public void init() throws Exception {
+		logger.info("初始化oss参数");
+		try {
+			setOssEndPoint(ossEndPoint);
+			setProjectName(projectName);
+			setExpiration(Long.valueOf(expiration));
+			setVideoEndPoint(videoEndPoint);
+			setAccessKeyId(accessKeyId);
+			setAccessKeySecret(accessKeySecret);
+			setCdnDomain(cdnDomain);
+			setImgDomain(imgDomain);
+			setVideoDomain(videoDomain);
+			setInternalEndPoint(internalEndPoint);
+			setPubBucket(pubBucket);
+			try{
+				String[] buckets = pubBucket.split(",");
+				for (String bucket : buckets) {
+					String[] bucketParms = bucket.split(":");
+					String bucketKey = bucketParms[0];
+					String bucketName = bucketParms[1];
+					AliOssConfig.bucketes.put(bucketKey, bucketName);
+				}
+			}catch(Exception e){
+				e.printStackTrace();
+			}
+			setPriBucket(priBucket);
+			String[] buckets = priBucket.split(",");
+			for (String bucket : buckets) {
+				String[] bucketParms = bucket.split(":");
+				String bucketKey = bucketParms[0];
+				String bucketName = bucketParms[1];
+				AliOssConfig.bucketes.put(bucketKey, bucketName);
+			}
+			setNeedPress(needPress);
+			setLvvideoDomain(lvvideoDomain);
+			setpriEndPoint(priEndPoint);
+			setSnapshotLocation("");
+
+			setOssClient(new OSSClient(SUFFIX + ossEndPoint, accessKeyId, accessKeySecret));
+			setInternalOssClient(new OSSClient(SUFFIX + internalEndPoint, accessKeyId, accessKeySecret));
+			setPriClient(new OSSClient(SUFFIX + priEndPoint, accessKeyId, accessKeySecret));
+			setVideoClient(new OSSClient(SUFFIX + videoEndPoint, accessKeyId, accessKeySecret));
+			DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
+			setDefaultAcsClient(new DefaultAcsClient(profile));
+		} catch (Exception e) {
+			logger.error("配置文件读取失败");
+			throw e;
+		}
+
+	}
+	@Value("${oss.growth.priEndPoint}")
+	public void setpriEndPoint(String priEndPoint) {
+		AliOssConfig.priEndPoint = priEndPoint;
+	}
+
+	public static OSSClient getOssReadOnlyClient() {
+		if (AliOssConfig.ossReadOnlyClient == null) {
+			ClientConfiguration conf = new ClientConfiguration();
+			// 设置OSSClient允许打开的最大HTTP连接数,默认为1024个。
+			conf.setMaxConnections(500);
+			// 设置Socket层传输数据的超时时间,默认为50000毫秒。
+			conf.setSocketTimeout(40000);
+			// 设置建立连接的超时时间,默认为50000毫秒。
+			conf.setConnectionTimeout(10000);
+			// 设置从连接池中获取连接的超时时间(单位:毫秒),默认不超时。
+			conf.setConnectionRequestTimeout(1000);
+			// 设置连接空闲超时时间。超时则关闭连接,默认为60000毫秒。
+			conf.setIdleConnectionTime(10000);
+			// 设置失败请求重试次数,默认为3次。
+			conf.setMaxErrorRetry(5);
+			AliOssConfig.ossReadOnlyClient = new OSSClient(SUFFIX + getOssEndPoint(), 
+					PropertiesUtils.getReadOnlyAccessKeyId(),
+					PropertiesUtils.getReadOnlyAccessKeySecret(),
+					conf );
+		}
+		return AliOssConfig.ossReadOnlyClient;
+	}
+	@Value("${oss.growth.internal.endPoint}")
+	public void setInternalEndPoint(String internalEndPoint) {
+		AliOssConfig.internalEndPoint = internalEndPoint;
+	}
+
+	public static String getInternalEndPoint() {
+		return internalEndPoint;
+	}
+	public static String getBucket(String key) {
+		String bucket = AliOssConfig.bucketes.get(key);
+		if (StringUtils.isEmpty(bucket)) {
+			logger.error(String.format("bucket key[%s]不存在", key));
+		}
+		return bucket;
+	}
+
+	public static String getSnapshotLocation() {
+		return snapshotLocation;
+	}
+
+	public void setSnapshotLocation(String snapshotLocation ) {
+		AliOssConfig.snapshotLocation = snapshotLocation;
+	}
+	
+	public static String getProjectName() {
+		return projectName;
+	}
+
+	@Value("${oss.growth.projectName}")
+	public void setProjectName(String projectName) {
+		AliOssConfig.projectName = projectName;
+	}
+
+
+	public static OSSClient getOssClient() {
+		return ossClient;
+	}
+
+	public void setOssClient(OSSClient ossClient) {
+		AliOssConfig.ossClient = ossClient;
+	}
+
+	public static OSSClient getInternalOssClient() {
+		return internalOssClient;
+	}
+
+	public void setInternalOssClient(OSSClient internalOssClient) {
+		AliOssConfig.internalOssClient = internalOssClient;
+	}
+
+	public static String getOssEndPoint() {
+		return ossEndPoint;
+	}
+
+	@Value("${oss.growth.ossEndPoint}")
+	public void setOssEndPoint(String ossEndPoint) {
+		AliOssConfig.ossEndPoint = ossEndPoint;
+	}
+
+	public static String getAccessKeyId() {
+		return accessKeyId;
+	}
+	@Value("${oss.growth.accessKey}")
+	public void setAccessKeyId(String accessKeyId) {
+		AliOssConfig.accessKeyId = accessKeyId;
+	}
+
+
+
+	public static String getAccessKeySecret() {
+		return accessKeySecret;
+	}
+	@Value("${oss.growth.secretKey}")
+	public void setAccessKeySecret(String accessKeySecret) {
+		AliOssConfig.accessKeySecret = accessKeySecret;
+	}
+
+	public String getConfigPath() {
+		return configPath;
+	}
+
+	public void setConfigPath(String configPath) {
+		this.configPath = configPath;
+	}
+
+	public static String getCdnDomain() {
+		return cdnDomain;
+	}
+	@Value("${oss.growth.cdnDomain}")
+	public void setCdnDomain(String cdnDomain) {
+		AliOssConfig.cdnDomain = cdnDomain;
+	}
+
+	public static String getImgDomain() {
+		return imgDomain;
+	}
+
+	@Value("${oss.growth.imgDomain}")
+	public void setImgDomain(String imgDomain) {
+		AliOssConfig.imgDomain = imgDomain;
+	}
+	@Value("${oss.growth.pubBucket}")
+	public void setPubBucket(String pubBucket) {
+		AliOssConfig.pubBucket = pubBucket;
+	}
+	@Value("${oss.growth.priBucket}")
+	public void setPriBucket(String priBucket) {
+		AliOssConfig.priBucket = priBucket;
+	}
+
+	public static HashMap<String, String> getBucketes() {
+		return bucketes;
+	}
+
+	public void setBucketes(HashMap<String, String> bucketes) {
+		AliOssConfig.bucketes = bucketes;
+	}
+
+
+	public static Boolean getNeedPress() {
+		return needPress;
+	}
+	@Value("${oss.growth.needPress}")
+	public void setNeedPress(Boolean needPress) {
+		AliOssConfig.needPress = needPress;
+	}
+
+	public static String getVideoDomain() {
+		return videoDomain;
+	}
+	@Value("${oss.growth.videoDomain}")
+	public void setVideoDomain(String videoDomain) {
+		AliOssConfig.videoDomain = videoDomain;
+	}
+
+	public static String getVideoEndPoint() {
+		return videoEndPoint;
+	}
+	@Value("${oss.growth.videoEndPoint}")
+	public void setVideoEndPoint(String videoEndPoint) {
+		AliOssConfig.videoEndPoint = videoEndPoint;
+	}
+
+
+	public static long getExpiration() {
+		return expiration;
+	}
+	@Value("${oss.growth.expiration}")
+	public void setExpiration(long expiration) {
+		AliOssConfig.expiration = expiration;
+	}
+
+	public static PolicyDetailVO getPolicyDetail() {
+		return policyDetail;
+	}
+
+	public void setPolicyDetail(PolicyDetailVO policyDetail) {
+		AliOssConfig.policyDetail = policyDetail;
+	}
+
+	public static OSSClient getPriClient() {
+		return priClient;
+	}
+
+	public void setPriClient(OSSClient priClient) {
+		AliOssConfig.priClient = priClient;
+	}
+
+	public static DefaultAcsClient getDefaultAcsClient() {
+		return defaultAcsClient;
+	}
+
+	public void setDefaultAcsClient(DefaultAcsClient defaultAcsClient) {
+		AliOssConfig.defaultAcsClient = defaultAcsClient;
+	}
+
+	public static String getLvvideoDomain() {
+		return lvvideoDomain;
+	}
+	@Value("${oss.growth.lvvideoDomain}")
+	public void setLvvideoDomain(String lvvideoDomain) {
+		AliOssConfig.lvvideoDomain = lvvideoDomain;
+	}
+	
+	public static OSSClient getShangHaiInternalOssClient() {
+		return new OSSClient(SUFFIX + "oss-cn-shanghai.aliyuncs.com", accessKeyId, accessKeySecret);
+	} 
+	
+	public static IAcsClient getIAcsClient() {
+		if (AliOssConfig.mAcsClient == null) {
+			DefaultProfile profile = DefaultProfile.getProfile(getMpsRegionId(), // 地域ID
+					getAccessKeyId(), // RAM账号的AccessKey ID
+					getAccessKeySecret()); // RAM账号Access Key Secret
+			mAcsClient = new DefaultAcsClient(profile);
+		}
+		return AliOssConfig.mAcsClient;
+	}
+	public static String getMpsRegionId() {
+		return PropertiesUtils.getValue("oss.longvideo.transcode.mpsRegionId");
+	}
+}

+ 49 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/vo/PolicyDetailVO.java

@@ -0,0 +1,49 @@
+package com.tzld.piaoquan.growth.common.model.vo;
+
+import java.util.List;
+
+public class PolicyDetailVO {
+	public List<PolicyVO> Statement;
+	public String Version;
+
+	public List<PolicyVO> getStatement() {
+		return Statement;
+	}
+
+	public void setStatement(List<PolicyVO> statement) {
+		Statement = statement;
+	}
+
+	public String getVersion() {
+		return Version;
+	}
+
+	public void setVersion(String version) {
+		Version = version;
+	}
+
+	public static class PolicyVO {
+		public List<String> Action;
+		public String Effect;
+		public List<String> Resource;
+		public List<String> getAction() {
+			return Action;
+		}
+		public void setAction(List<String> action) {
+			Action = action;
+		}
+		public String getEffect() {
+			return Effect;
+		}
+		public void setEffect(String effect) {
+			Effect = effect;
+		}
+		public List<String> getResource() {
+			return Resource;
+		}
+		public void setResource(List<String> resource) {
+			Resource = resource;
+		}
+		
+	}
+}

+ 1382 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/AliOssFileTool.java

@@ -0,0 +1,1382 @@
+package com.tzld.piaoquan.growth.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyun.opensearch.sdk.dependencies.org.apache.commons.codec.binary.Base64;
+import com.aliyun.oss.*;
+import com.aliyun.oss.common.utils.BinaryUtil;
+import com.aliyun.oss.model.*;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.http.ProtocolType;
+import com.aliyuncs.mts.model.v20140618.SubmitJobsRequest;
+import com.aliyuncs.mts.model.v20140618.SubmitJobsResponse;
+import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobRequest;
+import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse;
+import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse.MediaInfoJob.Properties;
+import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.profile.IClientProfile;
+import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
+import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
+import com.stuuudy.commons.external.filestorage.alibaba.OSSFileDO;
+import com.stuuudy.commons.external.filestorage.enums.*;
+import com.stuuudy.commons.util.BlankUtil;
+import com.stuuudy.commons.util.CompressImage;
+import com.stuuudy.commons.util.MD5.Md5Util;
+import com.stuuudy.commons.util.exception.CommonsException;
+import com.stuuudy.commons.util.exception.EnumErrorException;
+import com.tzld.piaoquan.growth.common.common.enums.EnumUploadFileType;
+import com.tzld.piaoquan.growth.common.config.AliOssConfig;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Mac;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import javax.imageio.ImageIO;
+import javax.xml.crypto.dsig.SignatureMethod;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.security.DigestInputStream;
+import java.security.InvalidKeyException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+
+/**
+ * (阿里对象存储工具类)<BR>
+ * AliOssFileTool<BR>
+ * 创建人:陈海 <BR>
+ * 时间:2016年7月18日-下午12:47:52 <BR>
+ *
+ * @version 1.0.0
+ */
+@Component
+public class AliOssFileTool extends AliOssConfig {
+
+    private static Logger logger = Logger.getLogger(AliOssFileTool.class);
+
+    private static final String ENCODE_TYPE = "UTF-8";
+    private static final String ALGORITHM = "HmacSHA1";
+    private static final String HTTP_METHOD = "GET";
+    private static final String SEPARATOR = "&";
+    private static final String EQUAL = "=";
+
+    public static String saveInPublicWithPress(InputStream inputStream, EnumPublicBuckets bucket, String key, EnumFileType type,
+                                               EnumFileSuffix fileSuffix) throws OSSException, ClientException {
+        inputStream = compressImg(inputStream, fileSuffix, type);
+        return saveInPublicNoPress(inputStream, bucket, key, type);
+    }
+
+    public static String saveInPublicReturnHost(InputStream inputStream, EnumPublicBuckets bucket, String fullKey,
+                                                EnumFileType type) {
+        String path = saveInPublic(inputStream, bucket, fullKey, type);
+        // 保存路径
+        return CdnUtil.getCdnUrlHost(type) + path;
+
+    }
+
+    public static String saveInPublic(InputStream inputStream, EnumPublicBuckets bucket, String fullKey, EnumFileType type) {
+        String bucketName = getBucket(bucket.getBucketName());
+        if (EnumFileType.VOICE.equals(type)) {
+            ObjectMetadata om = new ObjectMetadata();
+            om.setContentType("audio/mpeg");
+            getOssClient().putObject(bucketName, fullKey, inputStream, om);
+        } else {
+            getOssClient().putObject(bucketName, fullKey, inputStream);
+        }
+        return fullKey;
+
+    }
+
+    public static String moveFile(EnumPublicBuckets sourceBucket, String sourceKey, EnumPublicBuckets targetBucket, String targetKey) {
+        getOssClient().copyObject(getBucket(sourceBucket.getBucketName()), sourceKey,
+                getBucket(targetBucket.getBucketName()), targetKey);
+        if (!StringUtils.equals(sourceKey, targetKey)) {
+            getOssClient().deleteObject(getBucket(sourceBucket.getBucketName()), sourceKey);
+        }
+        return targetKey;
+    }
+
+    public static void deleteFile(EnumPublicBuckets bucket, String key) {
+        getOssClient().deleteObject(getBucket(bucket.getBucketName()), key);
+    }
+
+    public static String saveInPublicNoPress(InputStream inputStream, EnumPublicBuckets bucket, String key,
+                                             EnumFileType type) throws OSSException, ClientException {
+        String fullKey = getProjectName() + "/" + type.getLocation() + key;
+        saveInPublic(inputStream, bucket, fullKey, type);
+        return fullKey;
+    }
+
+    /**
+     * (网络资源上传) 方法名saveURLInPublicNoPress
+     *
+     * @param url        资源地址
+     * @param key
+     * @param type
+     * @param fileSuffix
+     * @return
+     * @throws OSSException
+     * @throws ClientException
+     * @throws IOException     String
+     * @throws @version        1.0
+     * @author 创建人:何振斌
+     * @time 创建日期:2018年3月12日 下午7:10:00
+     */
+    public static String saveURLInPublicNoPress(String url, String bucketName, String key, EnumFileType type,
+                                                EnumFileSuffix fileSuffix) throws OSSException, ClientException, IOException {
+        String fullKey = getProjectName() + "/" + type.getLocation() + key;
+        InputStream inputStream = null;
+        if (!BlankUtil.isBlank(url)) {
+            inputStream = new URL(url).openStream();
+        }
+        if (EnumFileType.VOICE.equals(type)) {
+            ObjectMetadata om = new ObjectMetadata();
+            om.setContentType("audio/mpeg");
+            getOssClient().putObject(bucketName, fullKey, inputStream, om);
+        } else {
+            getOssClient().putObject(bucketName, fullKey, inputStream);
+        }
+        return getProjectName() + "/" + type.getLocation() + key;
+    }
+
+    /**
+     * (根据名称和类型保存文件,返回是否成功)<BR>
+     * 方法名:saveWiteKeyAndType<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年7月18日-下午1:02:10 <BR>
+     *
+     * @param inputStream 文件流
+     * @param bucket      空间名称
+     * @param key         文件保存在服务器上的另存名
+     * @param type        枚举文件类型,声音或图片等
+     * @return boolean<BR>
+     * @throws IOException
+     * @throws ClientException
+     * @throws OSSException
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static boolean saveInPrivate(InputStream inputStream, EnumPrivateBuckets bucket, String key,
+                                        EnumFileType type, EnumFileSuffix suffix) throws OSSException, ClientException, IOException {
+        inputStream = compressImg(inputStream, suffix, type);
+        String bucketName = getBucket(bucket.getBucketName());
+        String fullKey = getProjectName() + "/" + type.getLocation() + key;
+        getOssClient().putObject(bucketName, fullKey, inputStream);
+        return true;
+    }
+
+    /**
+     * (获取前缀为prefix的全部文件)<BR>
+     * 方法名:listFileInFolder<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2017年1月20日-下午4:59:25 <BR>
+     *
+     * @param bucket
+     * @param prefix
+     * @return List<OSSObjectSummary><BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static List<OSSObjectSummary> listFileInFolder(EnumPublicBuckets bucket, String prefix) {
+        final int maxKeys = 200;
+        String nextMarker = null;
+        ObjectListing objectListing;
+        List<OSSObjectSummary> sums = new ArrayList<OSSObjectSummary>();
+        // 递归列出fun目录下的所有文件
+        do {
+            ListObjectsRequest listObjectsRequest = new ListObjectsRequest(getBucket(bucket.getBucketName()));
+            listObjectsRequest.setPrefix(prefix);
+            listObjectsRequest.withMarker(nextMarker).withMaxKeys(maxKeys);
+            objectListing = getOssClient().listObjects(listObjectsRequest);
+            List<OSSObjectSummary> temp = objectListing.getObjectSummaries();
+            if (temp != null) {
+                sums.addAll(temp);
+            }
+            nextMarker = objectListing.getNextMarker();
+        } while (objectListing.isTruncated());
+        return sums;
+    }
+
+    /**
+     * (判断是否存在文件)<BR>
+     * 方法名:isExist<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年11月21日-下午3:54:36 <BR>
+     *
+     * @param bucket
+     * @param key
+     * @param type
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static boolean isExist(EnumPrivateBuckets bucket, String key, EnumFileType type) {
+        String fullKey = getProjectName() + "/" + type.getLocation() + key;
+        return getOssClient().doesObjectExist(getBucket(bucket.getBucketName()), fullKey);
+    }
+
+    public static final String REGION_CN_HANGZHOU = "cn-hangzhou";
+    public static final String STS_API_VERSION = "2015-04-01";
+
+    public static AssumeRoleResponse getTempUserToken(long durationSeconds, Integer uid)
+            throws com.aliyuncs.exceptions.ClientException {
+
+        // 只有 RAM用户(子账号)才能调用 AssumeRole 接口
+        // 阿里云主账号的AccessKeys不能用于发起AssumeRole请求
+        // 请首先在RAM控制台创建一个RAM用户,并为这个用户创建AccessKeys
+        String accessKeyId = "LTAIQLkVvDFXRO7j";
+        String accessKeySecret = "aOnxO0xyoa0lDmTxTI1cNmVLNotF15";
+
+        // RoleArn 需要在 RAM 控制台上获取
+        String roleArn = "acs:ram::1894469520484605:role/aliyunosstokengeneratorrole";
+        String policy = JSONObject.toJSONString(AliOssFileTool.getPolicyDetail());
+        // RoleSessionName 是临时Token的会话名称,自己指定用于标识你的用户,主要用于审计,或者用于区分Token颁发给谁
+        // 但是注意RoleSessionName的长度和规则,不要有空格,只能有'-' '_' 字母和数字等字符
+        // 具体规则请参考API文档中的格式要求
+        String roleSessionName = "uid_" + uid;
+
+        // 此处必须为 HTTPS
+        ProtocolType protocolType = ProtocolType.HTTPS;
+
+        try {
+            final AssumeRoleResponse stsResponse = assumeRole(accessKeyId, accessKeySecret, roleArn, roleSessionName,
+                    policy, protocolType, durationSeconds);
+            return stsResponse;
+            /*
+             * Map<String, String> respMap = new LinkedHashMap<String, String>();
+             * respMap.put("status", "200"); respMap.put("AccessKeyId",
+             * stsResponse.getCredentials().getAccessKeyId());
+             * respMap.put("AccessKeySecret",
+             * stsResponse.getCredentials().getAccessKeySecret());
+             * respMap.put("SecurityToken",
+             * stsResponse.getCredentials().getSecurityToken()); respMap.put("Expiration",
+             * stsResponse.getCredentials().getExpiration());
+             */
+
+        } catch (ClientException e) {
+            throw e;
+        }
+
+    }
+
+    protected static AssumeRoleResponse assumeRole(String accessKeyId, String accessKeySecret, String roleArn,
+                                                   String roleSessionName, String policy, ProtocolType protocolType, long durationSeconds)
+            throws com.aliyuncs.exceptions.ClientException {
+        try {
+            // 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
+            IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);
+            DefaultAcsClient client = new DefaultAcsClient(profile);
+
+            // 创建一个 AssumeRoleRequest 并设置请求参数
+            final AssumeRoleRequest request = new AssumeRoleRequest();
+            request.setVersion(STS_API_VERSION);
+            request.setMethod(MethodType.POST);
+            request.setProtocol(protocolType);
+
+            request.setRoleArn(roleArn);
+            request.setRoleSessionName(roleSessionName);
+            request.setPolicy(policy);
+            request.setDurationSeconds(durationSeconds);
+
+            // 发起请求,并得到response
+            final AssumeRoleResponse response = client.getAcsResponse(request);
+
+            return response;
+        } catch (com.aliyuncs.exceptions.ClientException e) {
+            throw e;
+        }
+    }
+
+    /**
+     * (判断是否存在文件)<BR>
+     * 方法名:isExist<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年11月21日-下午3:54:36 <BR>
+     *
+     * @param bucket
+     * @param key
+     * @param type
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    @Deprecated
+    public boolean isExist(EnumPublicBuckets bucket, String key, EnumFileType type) {
+        String fullKey = getProjectName() + "/" + type.getLocation() + key;
+        return getOssClient().doesObjectExist(getBucket(bucket.getBucketName()), fullKey);
+    }
+
+    /**
+     * (用bucket名称和完整key 判断文件是否存在)<BR>
+     * 方法名:isExist<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2017年5月12日-下午6:38:49 <BR>
+     *
+     * @param bucket
+     * @param fullKey
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static boolean isExist(String bucket, String fullKey) {
+        return getOssClient().doesObjectExist(bucket, fullKey);
+    }
+
+    /**
+     * 文件是否存在 内网
+     *
+     * @param bucket
+     * @param fullKey
+     * @return
+     */
+    public static boolean isExistOfInternal(String bucket, String fullKey) {
+        return getInternalOssClient().doesObjectExist(bucket, fullKey);
+    }
+
+    /**
+     * (删除oss文件)<BR>
+     * 方法名:delFile<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年7月20日-上午10:44:52 <BR>
+     *
+     * @param bucket 存储空间名称
+     * @param key    文件保存在服务器上的另存名
+     * @param type   枚举文件类型,声音或图片等
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static boolean delFile(EnumAllBuckets bucket, String key, EnumFileType type) {
+        getOssClient().deleteObject(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key);
+        return true;
+    }
+
+    public static boolean deleteObject(String bucketName, String objectKey) {
+        getInternalOssClient().deleteObject(bucketName, objectKey);
+        return true;
+    }
+
+    public static boolean deleteObjects(String bucketName, List<String> objectKeys) {
+        if (objectKeys == null || objectKeys.size() == 0) {
+            return false;
+        }
+        DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(bucketName);
+        deleteObjectsRequest.setKeys(objectKeys);
+        deleteObjectsRequest.setQuiet(true);
+        getInternalOssClient().deleteObjects(deleteObjectsRequest);
+        return true;
+    }
+
+    /**
+     * (获取经处理的图片签名url)<BR>
+     * 方法名:getPicUrlWithSign<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年7月18日-下午1:07:23 <BR>
+     *
+     * @param bucket 空间名称
+     * @param key    文件保存在服务器上的名称
+     * @param type   枚举文件类型,声音或图片等
+     * @return String<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static String getPicUrl(EnumPrivateBuckets bucket, String key, EnumFileType type, Long expiresSec) {
+        if (expiresSec == null) {
+            expiresSec = getExpiration();
+        }
+        Date expires = new Date(new Date().getTime() + getExpiration() * 1000);
+        String picUrl = getPriClient().generatePresignedUrl(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key, expires).toString();
+        return picUrl;
+    }
+
+    /**
+     * (获取文件对象的签名url)<BR>
+     * 方法名:getUrlWithSign<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年7月18日-下午1:05:50 <BR>
+     *
+     * @param bucket 空间名称
+     * @param key    文件保存在服务器上的名称
+     * @param type   枚举文件类型,声音或图片等
+     * @return String<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static String getUrl(EnumPrivateBuckets bucket, String key, EnumFileType type, Long expiresSec) {
+        if (expiresSec == null) {
+            expiresSec = getExpiration();
+        }
+        Date expires = new Date(new Date().getTime() + expiresSec * 1000);
+        String url = "";
+        if (type.equals(EnumFileType.VIDEO)) {
+            url = getVideoClient().generatePresignedUrl(getBucket(bucket.getBucketName()),
+                    getProjectName() + "/" + type.getLocation() + key, expires).toString();
+        } else {
+            url = getPriClient().generatePresignedUrl(getBucket(bucket.getBucketName()),
+                    getProjectName() + "/" + type.getLocation() + key, expires).toString();
+        }
+        return url;
+    }
+
+    public static String getUrlWithOssEndPoint(EnumPrivateBuckets bucket, String key, EnumFileType type,
+                                               Long expiresSec) {
+        if (expiresSec == null) {
+            expiresSec = getExpiration();
+        }
+        Date expires = new Date(new Date().getTime() + expiresSec * 1000);
+        return getOssClient().generatePresignedUrl(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key, expires).toString();
+    }
+
+    /**
+     * (获取object)<BR>
+     * 方法名:getObject<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年12月28日-上午10:55:43 <BR>
+     *
+     * @param bucket
+     * @param key
+     * @param type
+     * @return OSSObject<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static OSSObject getObject(EnumPrivateBuckets bucket, String key, EnumFileType type) {
+        OSSObject ossObject = getOssClient().getObject(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key);
+        return ossObject;
+    }
+
+    public static OSSObject getPubObject(EnumAllBuckets bucket, String key, EnumFileType type) {
+        OSSObject ossObject = getOssClient().getObject(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key);
+        return ossObject;
+    }
+
+    public static OSSObject getPubObject(String bucketName, String fullKey) {
+        OSSObject ossObject = getOssClient().getObject(bucketName, fullKey);
+        return ossObject;
+    }
+
+    public static OSSObject getInternalPubObject(String bucketName, String fullKey) {
+        OSSObject ossObject = getInternalOssClient().getObject(bucketName, fullKey);
+        return ossObject;
+    }
+
+    public static ObjectMetadata getPubObjectMedeta(EnumAllBuckets bucket, String key, EnumFileType type) {
+        ObjectMetadata ossObjectMeta = getOssClient().getObjectMetadata(getBucket(bucket.getBucketName()),
+                getProjectName() + "/" + type.getLocation() + key);
+        return ossObjectMeta;
+    }
+
+    public static String calcFileMD5(String bucketName, String objectKey) {
+        try {
+            OSSObject ossObj = getOssClient().getObject(bucketName, objectKey);
+            MessageDigest md = MessageDigest.getInstance("MD5");
+            try (DigestInputStream digestInputStream = new DigestInputStream(ossObj.getObjectContent(), md)) {
+                // 读取数据流并更新 MD5
+                byte[] buffer = new byte[8192];
+                while (digestInputStream.read(buffer) != -1) {
+                    // DigestInputStream 会自动更新 MessageDigest
+                }
+            } catch (Exception e) {
+                logger.info("读取oss文件异常: ", e);
+                return "";
+            }
+
+            // 获取最终的 MD5 值
+            byte[] md5Bytes = md.digest();
+            // 转换为十六进制字符串
+            StringBuilder sb = new StringBuilder();
+            for (byte b : md5Bytes) {
+                sb.append(String.format("%02x", b));
+            }
+
+            String md5 = sb.toString();
+            logger.info(String.format("buketName: %s, objectKey: %s, MD5: %s", bucketName, objectKey, md5));
+
+            return md5;
+        } catch (Exception e) {
+            logger.error("计算文件MD5异常: ", e);
+        }
+        return "";
+    }
+    /**
+     * (重命名文件,实现是先拷贝文件,再删掉旧的文件)<BR>
+     * 方法名:renameFile<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2016年8月1日-下午4:03:09 <BR>
+     *
+     * @param srcBucket
+     * @param srckey
+     * @param destkey
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    @Deprecated
+    public boolean renameFile(EnumAllBuckets srcBucket, String srckey, String destkey, EnumFileType srcType,
+                              EnumFileType destType) {
+
+        // 拷贝Object
+        getOssClient().copyObject(getBucket(srcBucket.getBucketName()),
+                getProjectName() + "/" + srcType.getLocation() + srckey, getBucket(srcBucket.getBucketName()),
+                getProjectName() + "/" + destType.getLocation() + destkey);
+        delFile(srcBucket, srckey, srcType);
+        return true;
+    }
+
+    /**
+     * (将oss srckey 命名为 destkey)<BR>
+     * 方法名:renameFileWithFullKey<BR>
+     * 创建人:陈海 <BR>
+     * 时间:2017年9月16日-下午5:24:39 <BR>
+     *
+     * @param srcBucket
+     * @param srckey
+     * @param destkey
+     * @return boolean<BR>
+     * @throws <BR>
+     * @since 1.0.0
+     */
+    public static boolean renameFileWithFullKey(EnumAllBuckets srcBucket, String srckey, String destkey) {
+
+        // 拷贝Object
+        getOssClient().copyObject(getBucket(srcBucket.getBucketName()), srckey, getBucket(srcBucket.getBucketName()),
+                destkey);
+        getOssClient().deleteObject(getBucket(srcBucket.getBucketName()), srckey);
+        return true;
+    }
+
+    public static boolean renameFileWithFullKeyFromInternal(EnumAllBuckets srcBucket, String srckey, String destkey, long size) {
+        // 拷贝Object
+        if (size < 1024 * 1024 * 1024) {
+            getInternalOssClient().copyObject(getBucket(srcBucket.getBucketName()), srckey,
+                    getBucket(srcBucket.getBucketName()), destkey);
+        } else {
+            multipartCopyObjectFromInternal(getBucket(srcBucket.getBucketName()), srckey,
+                    getBucket(srcBucket.getBucketName()), destkey);
+        }
+        getInternalOssClient().deleteObject(getBucket(srcBucket.getBucketName()), srckey);
+        return true;
+    }
+
+    // 分片拷贝object,大于1G的文件需要分片拷贝
+    public static void multipartCopyObjectFromInternal(String sourceBucketName, String sourceObjectName,
+                                                       String destinationBucketName, String destinationObjectName) {
+        OSSClient ossClient = getInternalOssClient();
+        ObjectMetadata objectMetadata = ossClient.getObjectMetadata(sourceBucketName, sourceObjectName);
+        // 获取被拷贝文件的大小。
+        long contentLength = objectMetadata.getContentLength();
+
+        // 设置分片大小为10MB。
+        long partSize = 1024 * 1024 * 10;
+
+        // 计算分片总数。
+        int partCount = (int) (contentLength / partSize);
+        if (contentLength % partSize != 0) {
+            partCount++;
+        }
+        logger.info("oss 分片拷贝开始,sourceObjectName:" + sourceObjectName + ",size:" + contentLength + ",partCount:" + partCount);
+        // 初始化拷贝任务。可以通过InitiateMultipartUploadRequest指定目标文件元信息。
+        InitiateMultipartUploadRequest initiateMultipartUploadRequest = new InitiateMultipartUploadRequest(
+                destinationBucketName, destinationObjectName);
+        InitiateMultipartUploadResult initiateMultipartUploadResult = ossClient
+                .initiateMultipartUpload(initiateMultipartUploadRequest);
+        String uploadId = initiateMultipartUploadResult.getUploadId();
+
+        // 分片拷贝。
+        List<PartETag> partETags = new ArrayList<PartETag>();
+        for (int i = 0; i < partCount; i++) {
+            // 计算每个分片的大小。
+            long skipBytes = partSize * i;
+            long size = partSize < contentLength - skipBytes ? partSize : contentLength - skipBytes;
+
+            // 创建UploadPartCopyRequest。可以通过UploadPartCopyRequest指定限定条件。
+            UploadPartCopyRequest uploadPartCopyRequest = new UploadPartCopyRequest(sourceBucketName, sourceObjectName,
+                    destinationBucketName, destinationObjectName);
+            uploadPartCopyRequest.setUploadId(uploadId);
+            uploadPartCopyRequest.setPartSize(size);
+            uploadPartCopyRequest.setBeginIndex(skipBytes);
+            uploadPartCopyRequest.setPartNumber(i + 1);
+            UploadPartCopyResult uploadPartCopyResult = ossClient.uploadPartCopy(uploadPartCopyRequest);
+
+            // 将返回的分片ETag保存到partETags中。
+            partETags.add(uploadPartCopyResult.getPartETag());
+        }
+
+        // 提交分片拷贝任务。
+        CompleteMultipartUploadRequest completeMultipartUploadRequest = new CompleteMultipartUploadRequest(
+                destinationBucketName, destinationObjectName, uploadId, partETags);
+        ossClient.completeMultipartUpload(completeMultipartUploadRequest);
+        logger.info("oss 分片拷贝结束,sourceObjectName:" + sourceObjectName + ",size:" + contentLength + ",partCount:" + partCount);
+    }
+
+    public static void copyObject(String srcBucketName, String srcObjectKey,
+                                  String destBucketName, String destObjectKey) {
+        getOssClient().copyObject(srcBucketName, srcObjectKey, destBucketName, destObjectKey);
+    }
+
+    public static void copyObjectFromInternal(String srcBucketName, String srcObjectKey,
+                                              String destBucketName, String destObjectKey) {
+        getInternalOssClient().copyObject(srcBucketName, srcObjectKey, destBucketName, destObjectKey);
+    }
+
+    private static InputStream compressImg(InputStream stream, EnumFileSuffix suffix, EnumFileType fileType) {
+        if (!getNeedPress()) {
+            return stream;
+        }
+        if (suffix == EnumFileSuffix.JPG || suffix == EnumFileSuffix.PNG || suffix == EnumFileSuffix.JPEG
+                || suffix == EnumFileSuffix.BMP) {
+            try {
+                byte[] file = CompressImage.compress(stream, 1080);
+                if (file != null) {
+                    stream = new ByteArrayInputStream(file);
+                } else {
+                    logger.warn("图片上传有误");
+                    return null;
+                }
+            } catch (Exception e) {
+                logger.error("图片压缩失败", e);
+                if (null != stream) {
+                    try {
+                        stream.close();
+                    } catch (IOException e1) {
+                    }
+                }
+                throw new CommonsException(EnumErrorException.PIC_FORMAT_ERROR);
+            }
+        }
+        return stream;
+    }
+
+    public static String submitPubTranscodeJob(EnumPublicBuckets inputBucket, EnumAllBuckets outputBucket,
+                                               String fullKey, String outPutKey, String templateId) {
+        OSSFileDO inputFile = new OSSFileDO(OSS_REGION, getBucket(EnumAllBuckets.PUBVIDEOBUCKET.getBucketName()),
+                fullKey);
+        JSONArray outputs = new JSONArray();
+        JSONObject outPutConfig = new JSONObject();
+        outPutConfig.put("OutputObject", outPutKey);
+        outPutConfig.put("TemplateId", templateId);
+        outputs.add(outPutConfig);
+        SubmitJobsRequest request = new SubmitJobsRequest();
+        request.setInput(inputFile.toJsonString());
+        request.setOutputs(outputs.toJSONString());
+        request.setPipelineId(PIPELINEID);
+        request.setOutputBucket(getBucket(outputBucket.getBucketName()));
+        request.setOutputLocation(OSS_REGION);
+        Integer outputJobCount = 1;
+
+        SubmitJobsResponse response = null;
+        try {
+            response = getDefaultAcsClient().getAcsResponse(request);
+            if (response.getJobResultList().size() != outputJobCount) {
+                throw new RuntimeException("SubmitJobsRequest Size failed");
+            }
+            return response.getJobResultList().get(0).getJob().getJobId();
+        } catch (ServerException e) {
+            logger.error("submitTranscodeJob Server failed", e);
+            throw new CommonsException(EnumErrorException.TRANS_CODE_SERVER_ERROR);
+        } catch (com.aliyuncs.exceptions.ClientException e) {
+            logger.error("submitTranscodeJob Client failed", e);
+            throw new CommonsException(EnumErrorException.TRANS_CODE_CLIENT_ERROR);
+        }
+    }
+
+    public static String getPubPicAverageColor(EnumAllBuckets bucket, String key) {
+        String style = "image/average-hue";
+        try {
+            GetObjectRequest request = new GetObjectRequest(getBucket(bucket.getBucketName()), key);
+            request.setProcess(style);
+            OSSObject obj = getOssClient().getObject(request);
+            if (obj != null) {
+                String a = IOUtils.toString(obj.getObjectContent());
+                JSONObject jo = (JSONObject) JSONObject.parse(a);
+                String rgb = jo.getString("RGB");
+                if (rgb != null) {
+                    rgb = rgb.replace("0x", "#");
+                }
+                return rgb;
+            }
+        } catch (Exception e) {
+            throw new CommonsException(EnumErrorException.TRANS_CODE_CLIENT_ERROR);
+        }
+        return null;
+    }
+
+    public static Properties getPubObjMediaInfoData(String bucketName, String fullKey) {
+        DefaultAcsClient client = getDefaultAcsClient();
+        SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
+        request.setReadTimeout(Integer.MAX_VALUE);
+        SubmitMediaInfoJobResponse response = new SubmitMediaInfoJobResponse();
+        JSONObject json = new JSONObject();
+        json.put("Location", "oss-cn-hangzhou");
+        json.put("Bucket", bucketName);
+        json.put("Object", fullKey);
+        request.setInput(json.toJSONString());
+        try {
+            response = client.getAcsResponse(request);
+            // String width = response.getMediaInfoJob().getProperties().getWidth();
+            // String height = response.getMediaInfoJob().getProperties().getHeight();
+            return response.getMediaInfoJob().getProperties();
+
+        } catch (Exception e) {
+            throw new CommonsException(EnumErrorException.TRANS_CODE_CLIENT_ERROR, e);
+        }
+    }
+
+    public static Map<String, String> getUploadPolicy(String fileName, Integer fileType, String bucketName)
+            throws Exception {
+
+        if (EnumUploadFileType.VIDEO.getIntType().equals(fileType)) {
+            fileName = "/video/" + fileName;
+        } else if (EnumUploadFileType.VOICE.getIntType().equals(fileType)) {
+            fileName = "/voice/" + fileName;
+        } else if (EnumUploadFileType.FILE.getIntType().equals(fileType)) {
+            fileName = "/file/" + fileName;
+        } else {
+            fileName = "/pic/" + fileName;
+        }
+        // String host = "http://" + bucket + "." + AliOssConfig.getOssEndPoint();
+
+        long expireTime = 60 * 60 * 4;
+        long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
+        Date expiration = new Date(expireEndTime);
+        PolicyConditions policyConds = new PolicyConditions();
+        policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 5261334938L);
+
+        policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY,
+                AliOssConfig.getProjectName() + fileName);
+        String postPolicy = AliOssConfig.getOssClient().generatePostPolicy(expiration, policyConds);
+        byte[] binaryData = postPolicy.getBytes("utf-8");
+        String encodedPolicy = BinaryUtil.toBase64String(binaryData);
+        String postSignature = AliOssConfig.getOssClient().calculatePostSignature(postPolicy);
+        Map<String, String> respMap = new LinkedHashMap<String, String>();
+        respMap.put("accessId", AliOssConfig.getAccessKeyId());
+        respMap.put("policy", encodedPolicy);
+        respMap.put("signature", postSignature);
+        respMap.put("fileName", AliOssConfig.getProjectName() + fileName);
+
+        if ("clipres".equals(bucketName)) {
+            respMap.put("host", PropertiesUtils.getValue("oss.clipres.upload.domain"));
+        } else {
+            respMap.put("host", AliOssConfig.getLvvideoDomain());
+        }
+
+        // respMap.put("host", "https://oss.zuluki.com");
+        // respMap.put("callback", getCallBackStr(signUploadParams));
+        respMap.put("expire", String.valueOf(expireEndTime / 1000));
+        return respMap;
+    }
+
+    public static String getSignaturedUrl(String fileName, Boolean isPrivate) {
+
+        if (StringUtils.isBlank(fileName)) {
+            return fileName;
+        }
+        if (StringUtils.startsWith(fileName, "https")) {
+            return fileName;
+        }
+        String host = AliOssConfig.getVideoDomain();
+        fileName = host + fileName;
+        return fileName;
+    }
+
+    public static String getSignaturedInternalUrl(String fileName, Boolean isPrivate) throws Exception {
+        if (StringUtils.isBlank(fileName)) {
+            return fileName;
+        }
+        if (StringUtils.startsWith(fileName, "https")) {
+            return fileName;
+        }
+        String bucket = getBucket(isPrivate);
+        String host = "http://" + bucket + "." + AliOssConfig.getInternalEndPoint();
+        fileName = host + "/" + fileName;
+        return fileName;
+    }
+
+    public static String saveVideoCoverImagFromInternal(File file, Integer fileType, Boolean isPrivate, Long videoId)
+            throws Exception {
+        Date begin = new Date();
+        logger.info(String.format("开始往阿里云OSS上传封面图片,当前时间为:%s", begin.getTime()));
+        String bucketName = getBucket(isPrivate);
+
+        String fullKey = getVideoCoverImagPath(fileType, isPrivate, videoId.toString(), null);
+        AliOssConfig.getInternalOssClient().putObject(bucketName, fullKey, file);
+        Date end = new Date();
+        logger.info(String.format("阿里云OSS上传封面图片完成,总耗时为 %s 毫秒。图片地址为:%s, 正在执行下一步。。", end.getTime() - begin.getTime(),
+                fullKey));
+        return fullKey;
+    }
+
+    public static String saveVideoCoverImagFromInternal(InputStream input, Integer fileType, Boolean isPrivate,
+                                                        String filePrex, String dic) throws Exception {
+        Date begin = new Date();
+        logger.info(String.format("开始往阿里云OSS上传图片,当前时间为:%s", begin.getTime()));
+        String bucketName = getBucket(isPrivate);
+
+        String fullKey = getVideoCoverImagPath(fileType, isPrivate, filePrex, dic);
+        // AliOssConfig.getOssClient().putObject(bucketName, fullKey, file);
+        AliOssConfig.getInternalOssClient().putObject(bucketName, fullKey, input);
+        Date end = new Date();
+        logger.info(
+                String.format("阿里云OSS上传图片完成,总耗时为 %s 毫秒。图片地址为:%s, 正在执行下一步。。", end.getTime() - begin.getTime(), fullKey));
+        return fullKey;
+    }
+
+    public static String getVideoCoverImagPath(Integer fileType, Boolean isPrivate, String filePrex, String dic)
+            throws Exception {
+        String fileName = UUID.randomUUID().toString().replaceAll("-", "") + Calendar.getInstance().getTimeInMillis()
+                + "_" + filePrex;
+        if (StringUtils.isNotBlank(dic)) {
+            fileName = (dic + "/" + fileName);
+        }
+        if (EnumUploadFileType.VIDEO.getIntType().equals(fileType)) {
+            fileName = "/video/" + fileName;
+        } else if (EnumUploadFileType.VOICE.getIntType().equals(fileType)) {
+            fileName = "/voice/" + fileName;
+        } else {
+            fileName = "/pic/" + fileName;
+        }
+        String fullKey = AliOssConfig.getProjectName() + fileName;
+        return fullKey;
+    }
+
+    public static String getBucket(boolean isPrivate) {
+        if (isPrivate) {
+            return AliOssFileTool.getBucket(EnumAllBuckets.PRIVIDEOBUCKET.getBucketName());
+        } else {
+            return AliOssFileTool.getBucket(EnumAllBuckets.PUBVIDEOBUCKET.getBucketName());
+        }
+    }
+
+    public static ObjectMetadata getObjectMetadata(String fileName) throws Exception {
+
+        // Endpoint以杭州为例,其它Region请按实际情况填写。
+        // 创建OSSClient实例。
+        OSSClient ossClient = new OSSClient(AliOssConfig.getInternalEndPoint(), AliOssConfig.getAccessKeyId(),
+                AliOssConfig.getAccessKeySecret());
+        // // 获取文件的部分元信息。
+        // SimplifiedObjectMeta objectMeta = ossClient.getSimplifiedObjectMeta(
+        // getBucket(false), fileName);
+        // logger.info( "SimplifiedObjectMeta==="+ JSON.toJSONString(objectMeta));
+        // 获取文件的全部元信息。
+        ObjectMetadata metadata = ossClient.getObjectMetadata(getBucket(false), fileName);
+        // logger.info( "metadata==="+ JSON.toJSONString(metadata));
+        return metadata;
+    }
+
+    /**
+     * 获取部分元信息
+     *
+     * @param bucketName
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    public static SimplifiedObjectMeta getSimpleObjectMetadata(String bucketName, String fileName) throws Exception {
+        OSS ossClient = new OSSClientBuilder().build(AliOssConfig.getInternalEndPoint(), AliOssConfig.getAccessKeyId(),
+                AliOssConfig.getAccessKeySecret());
+        SimplifiedObjectMeta metadata = ossClient.getSimplifiedObjectMeta(bucketName, fileName);
+        ossClient.shutdown();
+        return metadata;
+    }
+
+    /**
+     * 获取全部元信息
+     *
+     * @param bucketName
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    public static ObjectMetadata getObjectMetadata(String bucketName, String fileName) throws Exception {
+//		OSS ossClient = new OSSClientBuilder().build(AliOssConfig.getInternalEndPoint(), AliOssConfig.getAccessKeyId(),
+//				AliOssConfig.getAccessKeySecret());
+//		// 获取文件的全部元信息
+//		ObjectMetadata metadata = ossClient.getObjectMetadata(bucketName, fileName);
+//		ossClient.shutdown();
+//		return metadata;
+        ObjectMetadata metadata = getInternalOssClient().getObjectMetadata(bucketName, fileName);
+        return metadata;
+    }
+
+//    public static void main(String[] args) throws Exception {
+////		String a = JSONObject.toJSONString(AliOssFileTool.getDefaultAcsClient());
+////		System.out.println(a);
+//    }
+
+    public static Map<String, String> buildCommonParameters() {
+        Map<String, String> parameterMap = new HashMap<>();
+        // 请求公共参数
+        parameterMap.put("Version", "2014-06-18");
+        parameterMap.put("AccessKeyId", AliOssConfig.getAccessKeyId()); // 此处请替换成您自己的AccessKeyId
+        // parameterMap.put("Timestamp",
+        // "2018-07-27T13:03:45Z");//此处将时间戳固定只是测试需要,这样此示例中生成的签名值就不会变,方便您对比验证,可变时间戳的生成需要用下边这句替换
+        parameterMap.put("Timestamp", DateUtils.formatIso8601Date(new Date()));
+        parameterMap.put("SignatureMethod", "HMAC-SHA1");
+        parameterMap.put("SignatureVersion", "1.0");
+        // parameterMap.put("SignatureNonce", "4902260a-516a-4b6a-a455-45b653cf6150");
+        // //此处将唯一随机数固定只是测试需要,这样此示例中生成的签名值就不会变,方便您对比验证,可变唯一随机数的生成需要用下边这句替换
+        parameterMap.put("SignatureNonce", UUID.randomUUID().toString());
+        parameterMap.put("Format", "JSON"); // 另外支持JSON格式
+        return parameterMap;
+    }
+
+    /**
+     * @Title: sendAsyncSnapshotJob @Description: 获取发送视频批量截图的任务的URL,此接口为异步任务 @param
+     * fileName 要截图的视频的路径,如 longvideo/video/XXXXX,其中XXXXX为视频名称 @param
+     * snapshotPath 截图后的图片输出路径,如
+     * longvideo/snapshot/XXXXX,截图时会自动在文件名后面加序号,输出路径为空时,自动指定为longvideo/snapshot/XXXXX @param
+     * startMillseconds 截图时间,单位毫秒 @param interval
+     * 截图间隔时间,若指定则表示异步模式序列截图,Interval必须大于等于0,默认10,单位秒。其中Interval=0表示根据视频时长平均截图。 @param
+     * snapshotNumber
+     * 截图数量,若指定则表示异步模式序列截图,且必须大于0,当Time+Interval*Num的截取点超过视频时长时,后续截图自动失效,截图完成时返回实际截取的个数;当Num=1,忽略Interval参数,表示异步单张截图 @return @throws
+     * Exception @author 王树杞 @date 2018年7月27日 下午5:17:31 @version 2.0 @throws
+     */
+    public static String sendAsyncSnapshotJob(String fileName, String snapshotPath, Integer startMillseconds,
+                                              Integer interval, Integer snapshotNumber) throws Exception {
+
+        // 首先获取公众参数
+        Map<String, String> parameterMap = buildCommonParameters();
+        parameterMap.put("Action", "SubmitSnapshotJob");
+
+        Map<String, String> inputParamsMap = new HashMap<>();
+        inputParamsMap.put("Bucket", AliOssFileTool.getBucket(false));
+        inputParamsMap.put("Location", AliOssFileTool.getSnapshotLocation());
+        inputParamsMap.put("Object", URLEncoder.encode(fileName, "UTF-8"));
+        parameterMap.put("Input", JSON.toJSONString(inputParamsMap));
+        Map<String, String> snapshotConfig = new HashMap<>();
+        Map<String, String> outPutFile = new HashMap<>();
+        outPutFile.put("Bucket", AliOssFileTool.getBucket(false));
+        outPutFile.put("Location", AliOssFileTool.getSnapshotLocation());
+        if (StringUtils.isBlank(snapshotPath)) {
+            snapshotPath = fileName.replace("/video/", "/snapshot/");
+        }
+        outPutFile.put("Object", URLEncoder.encode(snapshotPath + "_{Count}", "UTF-8"));
+        snapshotConfig.put("Interval", interval.toString());
+        snapshotConfig.put("Num", snapshotNumber.toString());
+        parameterMap.put("PipelineId", "abe6a0b9b9334858913eb416974485d2");
+
+        snapshotConfig.put("OutputFile", JSON.toJSONString(outPutFile));
+        parameterMap.put("SnapshotConfig", JSON.toJSONString(snapshotConfig));
+
+        String canonicalizedQueryString = buildCanonicalizedQueryString(parameterMap);
+        String stringToSign = buildStringToSign(canonicalizedQueryString);
+        String signature = buildSignature(AliOssConfig.getAccessKeySecret(), stringToSign);
+
+        return buildRequestURL(signature, parameterMap);
+
+    }
+
+    /**
+     * @Title: sendSyncSnapshotJob @Description: 获取发送某个视频的同步截图的任务URL地址 @param
+     * fileName 视频路径 @param snapshotPath 输出的截图路径 @param startMillseconds
+     * 截图的时间戳 @return 某个视频的同步截图的任务URL地址 @throws Exception @author 王树杞 @date
+     * 2018年7月27日 下午8:07:47 @version 2.0 @throws
+     */
+    public static String sendSyncSnapshotJob(String fileName, String snapshotPath, Integer startMillseconds)
+            throws Exception {
+
+        // 首先获取公众参数
+        Map<String, String> parameterMap = buildCommonParameters();
+        parameterMap.put("Action", "SubmitSnapshotJob");
+
+        Map<String, String> inputParamsMap = new HashMap<>();
+        inputParamsMap.put("Bucket", AliOssFileTool.getBucket(false));
+        inputParamsMap.put("Location", AliOssFileTool.getSnapshotLocation());
+        inputParamsMap.put("Object", URLEncoder.encode(fileName, "UTF-8"));
+        parameterMap.put("Input", JSON.toJSONString(inputParamsMap));
+        Map<String, String> snapshotConfig = new HashMap<>();
+        Map<String, String> outPutFile = new HashMap<>();
+        outPutFile.put("Bucket", AliOssFileTool.getBucket(false));
+        outPutFile.put("Location", AliOssFileTool.getSnapshotLocation());
+        if (StringUtils.isBlank(snapshotPath)) {
+            snapshotPath = fileName.replace("/video/", "/snapshot/");
+        }
+        outPutFile.put("Object", URLEncoder.encode(snapshotPath, "UTF-8"));
+        snapshotConfig.put("Time", startMillseconds.toString());
+        snapshotConfig.put("OutputFile", JSON.toJSONString(outPutFile));
+        parameterMap.put("SnapshotConfig", JSON.toJSONString(snapshotConfig));
+
+        String canonicalizedQueryString = buildCanonicalizedQueryString(parameterMap);
+        String stringToSign = buildStringToSign(canonicalizedQueryString);
+        String signature = buildSignature(AliOssConfig.getAccessKeySecret(), stringToSign);
+
+        return buildRequestURL(signature, parameterMap);
+
+    }
+
+    private static String percentEncode(String value) throws UnsupportedEncodingException {
+        return URLEncoder.encode(value, ENCODE_TYPE).replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
+    }
+
+    private static String buildCanonicalizedQueryString(Map<String, String> parameterMap)
+            throws UnsupportedEncodingException {
+        // 对参数进行排序
+        List<String> sortedKeys = new ArrayList<String>(parameterMap.keySet());
+        Collections.sort(sortedKeys);
+        StringBuilder temp = new StringBuilder();
+        for (String key : sortedKeys) {
+            // 此处需要对key和value进行编码
+            String value = parameterMap.get(key);
+            temp.append(SEPARATOR).append(percentEncode(key)).append(EQUAL).append(percentEncode(value));
+        }
+        return temp.toString().substring(1);
+    }
+
+    private static String buildStringToSign(String canonicalizedQueryString) throws UnsupportedEncodingException {
+        // 生成stringToSign字符
+        StringBuilder temp = new StringBuilder();
+        temp.append(HTTP_METHOD).append(SEPARATOR);
+        temp.append(percentEncode("/")).append(SEPARATOR);
+        // 此处需要对canonicalizedQueryString进行编码
+        temp.append(percentEncode(canonicalizedQueryString));
+        return temp.toString();
+    }
+
+    private static String buildSignature(String keySecret, String stringToSign)
+            throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException {
+        SecretKey key = new SecretKeySpec((keySecret + SEPARATOR).getBytes(ENCODE_TYPE), SignatureMethod.HMAC_SHA1);
+        Mac mac = Mac.getInstance(ALGORITHM);
+        mac.init(key);
+        byte[] hashBytes = mac.doFinal(stringToSign.toString().getBytes(ENCODE_TYPE));
+        byte[] base64Bytes = new Base64().encode(hashBytes);
+        String base64UTF8String = new String(base64Bytes, "utf-8");
+        return URLEncoder.encode(base64UTF8String, ENCODE_TYPE);
+    }
+
+    private static String buildRequestURL(String signature, Map<String, String> parameterMap)
+            throws UnsupportedEncodingException {
+        // 生成请求URL
+        StringBuilder temp = new StringBuilder("http://mts.cn-hangzhou.aliyuncs.com?");
+        temp.append(URLEncoder.encode("Signature", ENCODE_TYPE)).append("=").append(signature);
+        for (Map.Entry<String, String> e : parameterMap.entrySet()) {
+            temp.append("&").append(percentEncode(e.getKey())).append("=").append(percentEncode(e.getValue()));
+        }
+        return temp.toString();
+    }
+
+    public static String saveInputStreamPic(InputStream inputStream, String bucket, String project, String dir,
+                                            String key) throws OSSException, ClientException, IOException {
+        String fullKey = project + "/" + dir + "/" + key;
+        ObjectMetadata objectMetadata = new ObjectMetadata();
+        objectMetadata.setContentType("image/jpg");
+        getOssClient().putObject(bucket, fullKey, inputStream, objectMetadata);
+        return fullKey;
+    }
+
+    public static String sendImageToAliOss(BufferedImage image) throws Exception {
+
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        ImageIO.write(image, "jpg", os);
+        InputStream is = new ByteArrayInputStream(os.toByteArray());
+        // 将生成的图片往OSS里面上传
+        String random = UUID.randomUUID().toString().replaceAll("-", "") + new Random().nextLong();
+        String key = Md5Util.encoderByMd5(random);
+        String coverImgPath = AliOssFileTool.saveVideoCoverImagFromInternal(is, key);
+        return coverImgPath;
+    }
+
+    public static String saveVideoCoverImagFromInternal(InputStream inputStream, String key)
+            throws OSSException, ClientException, IOException {
+        String bucketName = AliOssConfig.getBucket(EnumAllBuckets.PUBVIDEOBUCKET.getBucketName());
+        String fullKey = getProjectName() + "/pic/video/cover/" + DateUtils.dateToStringyyyyMMdd(new Date()) + "/"
+                + key;
+        ObjectMetadata objectMetadata = new ObjectMetadata();
+        objectMetadata.setContentType("image/jpg");
+        getInternalOssClient().putObject(bucketName, fullKey, inputStream, objectMetadata);
+        return fullKey;
+
+    }
+
+    /**
+     * @param duration   时长,如果是图片则传0,视频则传视频时长
+     * @param isInternal 是否内网访问
+     * @return
+     * @return String
+     * @Title: generatePresignedUrl
+     * @Description:得到对象的临时访问URL
+     * @author 王树杞
+     * @date 2019年2月25日 上午11:04:22
+     * @version 2.0
+     */
+    public static String generatePresignedUrl(String filePath, Integer duration, boolean isInternal) {
+
+        if (StringUtils.isEmpty(filePath)) {
+            return null;
+        }
+
+        if (filePath.startsWith("http")) {
+            filePath = filePath.replace(PropertiesUtils.getDownloadDomain(), "");
+            filePath = filePath.replace("https://weappupload.piaoquantv.com/", "");
+            filePath = filePath.replace("https://testweappupload.yishihui.com/", "");
+            filePath = filePath.replace("https://lvupload.piaoquantv.com/", "");
+        }
+
+        if (filePath.contains("Signature") && filePath.contains("OSSAccessKeyId")) {
+            return filePath;
+        }
+
+        if (duration == null) {
+            duration = 0;
+        }
+        // 设置URL过期时间为视频时长+3天。
+        // 单位为秒;
+        Date expiration = new Date(new Date().getTime() + (duration + (3 * 24 * 60 * 60)) * 1000);
+//		//一分钟
+//		Date expiration = new Date(new Date().getTime() +( 60) * 1000);
+        // 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
+
+        URL url = getOssReadOnlyClient().generatePresignedUrl(PropertiesUtils.getVideoBucket(),
+                filePath, expiration, HttpMethod.GET);
+        String path = url.getFile();
+        if (StringUtils.startsWith(path, "/")) {
+            return StringUtils.substring(path, 1);
+        }
+        return path;
+
+    }
+
+    public static String saveObjectFromInternal(InputStream inputStream, String fullKey)
+            throws OSSException, ClientException, IOException {
+        String bucketName = PropertiesUtils.getVideoBucket();
+        getInternalOssClient().putObject(bucketName, fullKey, inputStream);
+        return fullKey;
+    }
+
+    public static String saveObjectFromInternal(String bucketName, String url, String fullKey)
+            throws Exception {
+        InputStream inputStream = new URL(url).openStream();
+        getInternalOssClient().putObject(bucketName, fullKey, inputStream);
+        if (inputStream != null) {
+            inputStream.close();
+        }
+        return fullKey;
+    }
+
+    public static boolean checkObjectExistFromInternal(String bucketName, String fullKey) {
+        return getInternalOssClient().doesObjectExist(bucketName, fullKey);
+    }
+
+    public static String uploadShangHaiVideo(InputStream inputStream, String key, String bucketName) {
+        ObjectMetadata objectMetadata = new ObjectMetadata();
+        objectMetadata.setContentType("video/mp4");
+        getShangHaiInternalOssClient().putObject(bucketName, key, inputStream, objectMetadata);
+        return key;
+    }
+
+    public static boolean isShangHaiExist(String bucket, String fullKey) {
+        return getShangHaiInternalOssClient().doesObjectExist(bucket, fullKey);
+    }
+
+    public static Boolean isStorageClassArchive(String bucket, String key) throws OSSException, ClientException {
+        ObjectMetadata objectMetadata = getInternalOssClient().getObjectMetadata(bucket, key);
+        StorageClass storageClass = objectMetadata.getObjectStorageClass();
+        return storageClass == StorageClass.Archive;
+    }
+
+    public static boolean isStorageClassColdArchive(String bucket, String key) throws OSSException, ClientException {
+        ObjectMetadata objectMetadata = getInternalOssClient().getObjectMetadata(bucket, key);
+        StorageClass storageClass = objectMetadata.getObjectStorageClass();
+        return storageClass == StorageClass.ColdArchive;
+    }
+
+    public static void setStorageClassToArchive(String bucket, String key) throws OSSException, ClientException {
+        // 创建CopyObjectRequest对象。
+        CopyObjectRequest request = new CopyObjectRequest(bucket, key, bucket, key);
+
+        // 创建ObjectMetadata对象。
+        ObjectMetadata objectMetadata = new ObjectMetadata();
+
+        // 封装header,此处以设置存储类型为归档类型为例。
+        objectMetadata.setHeader("x-oss-storage-class", StorageClass.Archive);
+        request.setNewObjectMetadata(objectMetadata);
+
+        // 更改文件存储类型。
+        CopyObjectResult result = getInternalOssClient().copyObject(request);
+    }
+
+    public static void recoverVideoAsync(String bucket, String srckey) {
+        OSSClient ossInternalClient = getInternalOssClient();
+        ObjectMetadata objectMetadata = ossInternalClient.getObjectMetadata(bucket, srckey);
+        // 校验文件是否为归档文件。
+        StorageClass storageClass = objectMetadata.getObjectStorageClass();
+        if (storageClass == StorageClass.Archive) {
+            // 解冻文件。
+            try {
+                ossInternalClient.restoreObject(bucket, srckey);
+            } catch (Exception e) {
+                // TODO Auto-generated catch blockvideo-common/src/main/java/com/weiqu/video/common/enums/ExceptionCodeEnum.java
+//				e.printStackTrace();
+                logger.error("视频可能在解冻中");
+            }
+        } else if (storageClass == StorageClass.ColdArchive) {
+            // 解冻文件。
+            try {
+                RestoreJobParameters parameters = new RestoreJobParameters(RestoreTier.RESTORE_TIER_EXPEDITED);
+                RestoreConfiguration configuration = new RestoreConfiguration(3, parameters);
+                ossInternalClient.restoreObject(bucket, srckey, configuration);
+            } catch (Exception ex) {
+                logger.error("视频可能在解冻中", ex);
+            }
+        }
+    }
+
+    public static Boolean isRestoreCompleted(String bucket, String key) throws OSSException, ClientException {
+        ObjectMetadata objectMetadata = getInternalOssClient().getObjectMetadata(bucket, key);
+        Boolean isRestoreCompleted = false;
+        try {
+            isRestoreCompleted = objectMetadata.isRestoreCompleted();
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+//			e.printStackTrace();
+            logger.error("视频可能在解冻中");
+        }
+
+        return isRestoreCompleted;
+    }
+
+    /**
+     * @param path
+     * @param path
+     * @return
+     * @ApiModelProperty(value="冻结状态: -1:无须解冻  0:待解冻  1:解冻中  2:解冻完成")
+     */
+    public static Integer getFrozenStatus(String path) {
+        if (path.startsWith("http") && !path.startsWith(PropertiesUtils.getDownloadDomain())) {
+            logger.info("getFrozenStatus-outer size video, path :" + path);
+            return -1;
+        }
+        String realPath = path.replace(PropertiesUtils.getDownloadDomain(), "");
+        String bucketName = PropertiesUtils.getVideoBucket();
+        ObjectMetadata objectMetadata = null;
+        try {
+            objectMetadata = getInternalOssClient().getObjectMetadata(bucketName, realPath);
+        } catch (Exception ex) {
+            logger.error("getFrozenStatus-error", ex);
+            return -1;
+        }
+
+        if (Objects.isNull(objectMetadata)) {
+            logger.error("getFrozenStatus-error, path :" + path + " do not has metaData");
+            return -1;
+        }
+        StorageClass storageClass = objectMetadata.getObjectStorageClass();
+        if (storageClass != StorageClass.Archive && storageClass != StorageClass.ColdArchive) {
+            logger.info("getFrozenStatus, path :" + path + " do not in Archive status");
+            return -1;
+        }
+        try {
+            // 解冻完成
+            boolean isRestoreCompleted = objectMetadata.isRestoreCompleted();
+            if (isRestoreCompleted) {
+                return 2;
+            } else {
+                return 1;
+            }
+        } catch (NullPointerException e) {
+            logger.info("getFrozenStatus, path :" + path + " waiting for forzed!");
+            return 0;
+        }
+    }
+
+
+    public static Map<String, Object> getMediaAllInfo(String inPath) {
+        return getMediaAllInfo(inPath, PropertiesUtils.getVideoBucket());
+    }
+
+    public static Map<String, Object> getMediaAllInfo(String inPath, String bucketName) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        String encodedInput;
+        try {
+            encodedInput = URLEncoder.encode(inPath, "utf-8");
+        } catch (UnsupportedEncodingException e) {
+            logger.error("获取元数据输入流解析错误", e);
+            map.put("status", "1");
+            return map;
+        }
+        SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
+        JSONObject input = new JSONObject();
+        input.put("Bucket", bucketName);
+        input.put("Location", PropertiesUtils.getTranscodeLocation());
+        input.put("Object", encodedInput);
+        request.setInput(input.toJSONString());
+        request.setPipelineId(PropertiesUtils.getTranscodePipelineId());
+        try {
+            SubmitMediaInfoJobResponse response = new SubmitMediaInfoJobResponse();
+            response = AliOssConfig.getIAcsClient().getAcsResponse(request);
+            if (response.getMediaInfoJob().getState() != null
+                    && response.getMediaInfoJob().getState().equalsIgnoreCase("Fail")) {
+                logger.error("获取元数据错误:" + JSONObject.toJSONString(response.getMediaInfoJob())
+                        + ",requestId:" + response.getRequestId());
+                map.put("status", "2");
+                return map;
+            }
+            Properties properties = response.getMediaInfoJob().getProperties();
+            Properties.Streams.VideoStream videoStream = null;
+            if (CollectionUtils.isNotEmpty(properties.getStreams().getVideoStreamList())) {
+                videoStream = properties.getStreams().getVideoStreamList().get(0);
+            }
+            Properties.Format format = properties.getFormat();
+            logger.info("videoStream:" + JSONObject.toJSONString(videoStream));
+            logger.info("format:" + JSONObject.toJSONString(format));
+            map.put("status", "0");
+            if (properties.getWidth() != null) {
+                map.put("width", Integer.parseInt(properties.getWidth()) + "");
+            }
+            if (properties.getHeight() != null) {
+                map.put("height", Integer.parseInt(properties.getHeight()) + "");
+            }
+            if (videoStream != null) {
+                map.put("rotate", videoStream.getRotate());
+                map.put("codeName", videoStream.getCodecName());
+            }
+            if (format != null) {
+                map.put("size", format.getSize());
+                //设置成long类型的 大于0少于1的设置成1
+                if (Double.parseDouble(format.getDuration()) > 0 && Double.parseDouble(format.getDuration()) < 1) {
+                    map.put("duration", new Double(1).longValue());
+                } else {
+                    map.put("duration", StringUtils.isEmpty(format.getDuration()) ? 0 : new Double(Double.parseDouble(format.getDuration())).longValue());
+                }
+                map.put("bitRate", StringUtils.isEmpty(format.getBitrate()) ? 0 : new Double(Double.parseDouble(format.getBitrate())).longValue() * 1000);
+            }
+        } catch (ServerException e) {
+            logger.error("获取元数据服务器异常", e);
+            map.put("status", "3");
+        } catch (ClientException e) {
+            logger.error("获取元数据客户端异常", e);
+            map.put("status", "4");
+        } catch (Exception e) {
+            logger.error("获取元数据异常", e);
+            map.put("status", "5");
+        }
+        return map;
+    }
+
+    public static CopyObjectResult setStorageClassToColdArchive(String bucket, String key) {
+        CopyObjectRequest request = new CopyObjectRequest(bucket, key, bucket, key);
+        ObjectMetadata objectMetadata = new ObjectMetadata();
+
+        // 封装header,此处以设置存储类型为归档类型为例。
+        objectMetadata.setHeader("x-oss-storage-class", StorageClass.ColdArchive);
+        request.setNewObjectMetadata(objectMetadata);
+
+        // 更改文件存储类型。
+        return getInternalOssClient().copyObject(request);
+    }
+
+
+}

+ 155 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/CdnUtil.java

@@ -0,0 +1,155 @@
+package com.tzld.piaoquan.growth.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.cdn.model.v20141111.DescribeDomainBpsDataRequest;
+import com.aliyuncs.cdn.model.v20141111.DescribeDomainBpsDataResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.stuuudy.commons.external.filestorage.enums.EnumFileType;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Objects;
+
+public class CdnUtil {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(CdnUtil.class);
+
+//    public static final String VIDEO_CDN_URL_HOST = "https://xycdn.yishihui.com/";
+    public static final String VIDEO_CDN_URL_HOST = "http://rescdn.yishihui.com/";
+
+    public static final String PICTURE_CDN_URL_HOST_PICTURE = "http://rescdn.yishihui.com/";
+    public static final String DOWNLOAD_CDN_URL_HOST_PICTURE = "https://rescdn.yishihui.com/";
+
+
+    private static IAcsClient client;
+
+    static {
+        if (Objects.isNull(client)) {
+            DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAInlg8tWvBeiJe", "hDu5v2nrOmdY0AjlqGnZkW57mxCOLO");
+            /** use STS Token
+             DefaultProfile profile = DefaultProfile.getProfile(
+             "<your-region-id>",           // The region ID
+             "<your-access-key-id>",       // The AccessKey ID of the RAM account
+             "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
+             "<your-sts-token>");          // STS Token
+             **/
+            client = new DefaultAcsClient(profile);
+        }
+    }
+
+
+    public static Double getDescribeDomainBpsData() {
+        DescribeDomainBpsDataRequest request = new DescribeDomainBpsDataRequest();
+        //需要时区为GMT
+        LocalDateTime endTime = LocalDateTime.now().plusHours(-8);
+        LocalDateTime startTime = endTime.plusMinutes(-10);
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String[] starts = startTime.format(df).split(" ");
+        String[] ends = endTime.format(df).split(" ");
+        String start = starts[0] + "T" + starts[1] + "Z";
+        String end = ends[0] + "T" + ends[1] + "Z";
+        request.setStartTime(start);
+        request.setEndTime(end);
+        LOGGER.info("getDescribeDomainBpsData request = {}", JSON.toJSONString(request));
+        try {
+            DescribeDomainBpsDataResponse response = client.getAcsResponse(request);
+            LOGGER.info("getDescribeDomainBpsData response = {}", JSON.toJSONString(response));
+            if (Objects.isNull(response) || Objects.isNull(response.getBpsDataPerInterval())
+                    || response.getBpsDataPerInterval().isEmpty() || response.getBpsDataPerInterval().size() <= 1) {
+                //只有1条可能不准确
+                return null;
+            }
+            DescribeDomainBpsDataResponse.DataModule module1 = response.getBpsDataPerInterval().get(1);
+            if (Objects.nonNull(module1) && Objects.equals("0", module1.getValue())) {
+                return null;
+            }
+            DescribeDomainBpsDataResponse.DataModule module = response.getBpsDataPerInterval().get(0);
+            if (Objects.nonNull(module) && Objects.nonNull(module.getValue())) {
+                return Double.parseDouble(module.getValue()) / 1000 / 1000 / 1000;
+            }
+        } catch (ServerException e) {
+            LOGGER.error("getDescribeDomainBpsData ServerException", e);
+        } catch (ClientException e) {
+            LOGGER.error("getDescribeDomainBpsData ClientException", e);
+        }
+        return null;
+    }
+
+    public static String getCdnUrlHost(EnumFileType fileType) {
+        if (Objects.isNull(fileType)) {
+            return null;
+        }
+        switch (fileType) {
+            case VIDEO:
+                return VIDEO_CDN_URL_HOST;
+            case PICTURE:
+                return PICTURE_CDN_URL_HOST_PICTURE;
+        }
+        return null;
+    }
+
+//    public static void main(String[] args_) throws Exception {
+//        DescribeDomainBpsDataRequest request = new DescribeDomainBpsDataRequest();
+//        //需要时区为GMT
+//        LocalDateTime endTime = LocalDateTime.now().plusHours(-8);
+//        LocalDateTime startTime = endTime.plusMinutes(-10);
+//        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+//        String[] starts = startTime.format(df).split(" ");
+//        String[] ends = endTime.format(df).split(" ");
+//        String start = starts[0] + "T" + starts[1] + "Z";
+//        String end = ends[0] + "T" + ends[1] + "Z";
+//        request.setStartTime(start);
+//        request.setEndTime(end);
+//        System.out.println("---" + JSON.toJSONString(request));
+//        try {
+//            DescribeDomainBpsDataResponse response = client.getAcsResponse(request);
+//
+//            System.out.println("---" + JSON.toJSONString(response));
+//            DescribeDomainBpsDataResponse.DataModule module = response.getBpsDataPerInterval().get(0);
+//
+//            System.out.println("---" + module.getValue());
+//            double d = Double.valueOf(module.getValue()) / 1000 / 1000 / 1000;
+//            System.out.println(d);
+//
+////            System.out.println(new Gson().toJson(response));
+//        } catch (ServerException e) {
+//            e.printStackTrace();
+//        } catch (ClientException e) {
+//            System.out.println("ErrCode:" + e.getErrCode());
+//            System.out.println("ErrMsg:" + e.getErrMsg());
+//            System.out.println("RequestId:" + e.getRequestId());
+//        }
+//
+//    }
+
+    public static String getFileExtensionFromUrl(String uri) {
+        if (StringUtils.isBlank(uri)) {
+            return "";
+        }
+        String fileExtension = "";
+        try {
+            if (uri.contains(".")) {
+                int lastDotIndex = uri.lastIndexOf('.');
+                if (lastDotIndex > 0) {
+                    fileExtension = uri.substring(lastDotIndex + 1);
+                }
+            }
+        } catch (Exception e) {
+            LOGGER.error("getFileExtensionFromURL error", e);
+        }
+        return fileExtension;
+    }
+
+    public static void main(String[] args) {
+        String url = "ad/material_1564536000000.mp4";
+        System.out.println(getFileExtensionFromUrl(url));
+    }
+
+}

+ 1128 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/DateUtils.java

@@ -0,0 +1,1128 @@
+package com.tzld.piaoquan.growth.common.utils;
+
+import com.stuuudy.commons.util.date.CalendarUtil;
+import org.apache.commons.lang3.StringUtils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * 日期工具类
+ * 
+ * @author AKuo
+ * @since 1.0
+ * @date 2014-4-29 下午3:28:04
+ */
+public abstract class DateUtils {
+
+	private static final long ONE_MINUTE = 60;
+	private static final long ONE_HOUR = 3600;
+	private static final long ONE_DAY = 86400;
+	private static final long ONE_MONTH = 2592000;
+	private static final long ONE_YEAR = 31104000;
+	public static final String PATTERN_ONLY_DATE = "yyyy-MM-dd";
+	private static final String PATTERN_ONLY_TIME = "HH:mm:ss";
+	private static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss";
+	public static final String yyyyMMdd_HHmmss= "yyyy-MM-dd HH:mm:ss";
+
+	public static final String yyyyMMdd = "yyyyMMdd";
+
+	/**
+	 * 日期对象转字符串,用户指定格式化对象
+	 * 
+	 * @param date
+	 *            日期对象
+	 * @param dateFormat
+	 *            格式化对象
+	 * @return
+	 */
+	public static String dateToString(Date date, SimpleDateFormat dateFormat) {
+		if (date == null) {
+			throw new IllegalArgumentException("date can't be null");
+		}
+		return dateFormat.format(date);
+	}
+
+	/**
+	 * 日期对象转字符串,用户指定格式
+	 * 
+	 * @param date
+	 *            日期对象
+	 * @param pattern
+	 *            格式化
+	 * @return
+	 */
+	public static String dateToString(Date date, String pattern) {
+		return dateToString(date, getSimpleDateFormat(pattern));
+	}
+
+	/**
+	 * 字符串转日期对象,用户指定格式化对象
+	 * 
+	 * @param datestr
+	 *            日期字符串
+	 * @param dateFormat
+	 *            格式化对象
+	 * @return Date
+	 * @throws ParseException
+	 *             解析异常
+	 */
+	public static Date parse(String datestr, SimpleDateFormat dateFormat) throws ParseException {
+		if (datestr == null) {
+			throw new IllegalArgumentException("datestr can't be null");
+		}
+		return dateFormat.parse(datestr);
+	}
+
+	/**
+	 * 字符串转日期对象,用户指定格式
+	 * 
+	 * @param datestr
+	 *            日期字符串
+	 * @param pattern
+	 *            格式化
+	 * @return Date
+	 * @throws ParseException
+	 *             解析异常
+	 */
+	public static Date parse(String datestr, String pattern) throws ParseException {
+		return parse(datestr, getSimpleDateFormat(pattern));
+	}
+
+	/**
+	 * 根据格式获取格式化对象
+	 * 
+	 * @param pattern
+	 * @return
+	 */
+	private static SimpleDateFormat getSimpleDateFormat(String pattern) {
+		if (pattern == null) {
+			throw new IllegalArgumentException("pattern can't be null");
+		}
+		return new SimpleDateFormat(pattern);
+	}
+
+	/**
+	 * 日期转字符串,格式:yyyy-MM-dd
+	 * 
+	 * @param date
+	 *            时间值
+	 * @return
+	 */
+	public static String dateToString_only_date(Date date) {
+		return dateToString(date, PATTERN_ONLY_DATE);
+	}
+
+	/**
+	 * 当前日期转字符串,格式:yyyy-MM-dd
+	 * 
+	 * @return
+	 */
+	public static String nowToString_only_date() {
+		return dateToString_only_date(new Date());
+	}
+
+	/**
+	 * 字符串转日期,格式:yyyy-MM-dd
+	 * 
+	 * @param strDate
+	 *            日期字符串
+	 * @return Date
+	 * @throws ParseException
+	 *             解析异常
+	 */
+	public static Date parse_only_date(String strDate) throws ParseException {
+		return parse(strDate, PATTERN_ONLY_DATE);
+	}
+
+	/**
+	 * 日期转字符串,格式:HH:mm:ss
+	 * 
+	 * @param date
+	 *            时间值
+	 * @return
+	 */
+	public static String dateToString_only_time(Date date) {
+		return dateToString(date, PATTERN_ONLY_TIME);
+	}
+
+	/**
+	 * 当前日期转字符串,格式:HH:mm:ss
+	 * 
+	 * @return
+	 */
+	public static String nowToString_only_time() {
+		return dateToString_only_time(new Date());
+	}
+
+	/**
+	 * 字符串转日期,格式:HH:mm:ss
+	 * 
+	 * @param strDate
+	 *            日期字符串
+	 * @return Date
+	 * @throws ParseException
+	 *             解析异常
+	 */
+	public static Date parse_only_time(String strDate) throws ParseException {
+		return parse(strDate, PATTERN_ONLY_TIME);
+	}
+
+	/**
+	 * 日期转字符串,格式:yyyy-MM-dd HH:mm:ss
+	 * 
+	 * @param date
+	 *            时间值
+	 * @return
+	 */
+	public static String dateToString(Date date) {
+		return dateToString(date, PATTERN_DATETIME);
+	}
+
+	/**
+	 * 当前日期转字符串,格式:yyyy-MM-dd HH:mm:ss
+	 * 
+	 * @return
+	 */
+	public static String nowToString() {
+		return dateToString(new Date());
+	}
+
+	/**
+	 * 字符串转日期,格式:yyyy-MM-dd HH:mm:ss
+	 * 
+	 * @param strDate
+	 *            日期字符串
+	 * @return Date
+	 * @throws ParseException
+	 *             解析异常
+	 */
+	public static Date parse(String strDate) throws ParseException {
+		return parse(strDate, PATTERN_DATETIME);
+	}
+
+	/**
+	 * 多少年以前
+	 * 
+	 * @param manyYears
+	 *            多少年,传正数
+	 * @return
+	 */
+	public static Date beforeManyYears(Integer manyYears) {
+		return beforeManyYears(null, manyYears);
+	}
+
+	/**
+	 * 多少天以前
+	 * 
+	 * @param manyDays
+	 *            多少天,传正数
+	 * @return
+	 */
+	public static Date beforeManyDays(Integer manyDays) {
+		return beforeManyDays(null, manyDays);
+	}
+
+	/**
+	 * 多少年以前
+	 * 
+	 * @param date
+	 *            日期对象,不传默认是当前
+	 * @param manyYears
+	 *            多少年,传正数
+	 * @return
+	 */
+	public static Date beforeManyYears(Date date, Integer manyYears) {
+		if (manyYears > 0) {
+			manyYears = 0 - manyYears;
+		}
+		Calendar calendar = Calendar.getInstance();
+		if (date != null) {
+			calendar.setTime(date);
+		}
+		calendar.add(Calendar.YEAR, manyYears);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 多少天以前
+	 * 
+	 * @param date
+	 *            日期对象,不传默认是当前
+	 * @param manyDays
+	 *            多少天,传正数
+	 * @return
+	 */
+	public static Date beforeManyDays(Date date, Integer manyDays) {
+		if (manyDays > 0) {
+			manyDays = 0 - manyDays;
+		}
+		Calendar calendar = Calendar.getInstance();
+		if (date != null) {
+			calendar.setTime(date);
+		}
+		calendar.add(Calendar.DAY_OF_YEAR, manyDays);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 多少年以后
+	 * 
+	 * @param manyYears
+	 *            多少年,传正数
+	 * @return
+	 */
+	public static Date afterManyYears(Integer manyYears) {
+		return afterManyYears(null, manyYears);
+	}
+
+	/**
+	 * 多少天以后
+	 * 
+	 * @param manyDays
+	 *            多少天,传正数
+	 * @return
+	 */
+	public static Date afterManyDays(Integer manyDays) {
+		return afterManyDays(null, manyDays);
+	}
+
+	/**
+	 * 多少年以后
+	 * 
+	 * @param date
+	 *            日期对象,不传默认是当前
+	 * @param manyYears
+	 *            多少年,传正数
+	 * @return
+	 */
+	public static Date afterManyYears(Date date, Integer manyYears) {
+		if (manyYears < 0) {
+			manyYears = 0 - manyYears;
+		}
+		Calendar calendar = Calendar.getInstance();
+		if (date != null) {
+			calendar.setTime(date);
+		}
+		calendar.add(Calendar.YEAR, manyYears);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 多少天以后
+	 * 
+	 * @param date
+	 *            日期对象,不传默认是当前
+	 * @param manyDays
+	 *            多少天,传正数
+	 * @return
+	 */
+	public static Date afterManyDays(Date date, Integer manyDays) {
+		if (manyDays < 0) {
+			manyDays = 0 - manyDays;
+		}
+		Calendar calendar = Calendar.getInstance();
+		if (date != null) {
+			calendar.setTime(date);
+		}
+		calendar.add(Calendar.DAY_OF_YEAR, manyDays);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 当天开始的时间
+	 * 
+	 * @return
+	 */
+	public static Date todayBegin() {
+		return dayBegin(new Date());
+	}
+
+	/**
+	 * 获得某个日期对象的开始时间
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Date dayBegin(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.HOUR_OF_DAY, 0);
+		calendar.set(Calendar.MINUTE, 0);
+		calendar.set(Calendar.SECOND, 0);
+		calendar.set(Calendar.MILLISECOND, 0);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 当天结束的时间
+	 * 
+	 * @return
+	 */
+	public static Date todayEnd() {
+		return dayEnd(new Date());
+	}
+
+	/**
+	 * 获得某个日期对象的结束时间
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Date dayEnd(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.HOUR_OF_DAY, 23);
+		calendar.set(Calendar.MINUTE, 59);
+		calendar.set(Calendar.SECOND, 59);
+		calendar.set(Calendar.MILLISECOND, 999);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 日期偏移,返回格式:yyyyMMdd
+	 * 
+	 * @param date
+	 * @param offsetday
+	 * @return
+	 */
+	public static Date getDateByDayOffset(Date date, int offset) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.DAY_OF_YEAR, offset);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 日期偏移
+	 * 
+	 * @param date
+	 *            要偏移的日期
+	 * @param type
+	 *            偏移的位置
+	 * @param offset
+	 *            偏移量
+	 * @return
+	 */
+	public static Date getDateByDayOffset(Date date, int type, int offset) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(type, offset);
+		return calendar.getTime();
+	}
+
+	private static final long base = 1388505600000l;// 1970-2014年的毫秒数,做为基数被减掉,以减少长度
+
+	/**
+	 * 获取2014年1月1日到现在的秒数
+	 * 
+	 * @return String
+	 */
+	public static String getMyUnixSecStr() {
+		return getMyUnixSec().toString();
+	}
+
+	/**
+	 * 获取unix时间戳
+	 * 
+	 * @return
+	 */
+	public static long getUnixSec() {
+		return System.currentTimeMillis() / 1000;
+	}
+
+	/**
+	 * 获取2014年1月1日到现在的秒数
+	 * 
+	 * @return Long
+	 */
+	public static Long getMyUnixSec() {
+		return System.currentTimeMillis() - base;
+	}
+
+	/**
+	 * 获取2014年1月1日到现在的秒数
+	 * 
+	 * @return Long
+	 */
+	public static Long getMyUnixSec(Date date) {
+		return date.getTime() - base;
+	}
+
+	/**
+	 * 获取当前时间前几天的时间
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getBeforeTimeOfDay(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.add(Calendar.DAY_OF_YEAR, 0 - timing);
+		return c.getTime();
+	}
+
+	/**
+	 * 获取当前时间前几天的时间-具体到秒
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getBeforeDateOfTime(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE) - timing, c.get(Calendar.HOUR_OF_DAY),
+				c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
+		return c.getTime();
+	}
+
+	private static long ns = 1000; // 一秒钟的毫秒数
+
+	/**
+	 * 毫秒转具体秒数
+	 * 
+	 * @param time
+	 * @return
+	 */
+	public static long getdiffTimeSec(long time) {
+		return time / ns;
+	}
+
+	/**
+	 * 获取日期目录形式的字符串
+	 * 
+	 * @return String yyyy-MM-dd
+	 */
+	public static Date nowDate() {
+		Calendar cal_now = Calendar.getInstance();
+		return cal_now.getTime();
+	}
+
+	private static final SimpleDateFormat format_date_Hour = new SimpleDateFormat("HH");
+
+	public static int getDateHour() throws Exception {
+		String hour = format_date_Hour.format(new Date());
+		return Integer.parseInt(hour);
+	}
+
+	private static final SimpleDateFormat format_date_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+	/**
+	 * 某日期的开始
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Date dayTimeBegin(String date) {
+		Date r = null;
+		try {
+			r = format_date_time.parse(date + " 00:00:00");
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return r;
+	}
+
+	/**
+	 * 某日期的结束
+	 * 
+	 * @param date
+	 * @return
+	 */
+	public static Date dayTimeEnd(String date) {
+		Date r = null;
+		try {
+			r = format_date_time.parse(date + " 23:59:59");
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return r;
+	}
+
+	/**
+	 * 获取当前时间后几小时的时间
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getAfterTimeOfHours(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) + timing,
+				c.get(Calendar.MINUTE), c.get(Calendar.SECOND));
+		return c.getTime();
+	}
+
+	/**
+	 * 获取日期目录形式的字符串
+	 * 
+	 * @return Date yyyy-MM-dd HH:mm:ss->yyyy-MM-dd
+	 */
+	public static Date dateToDay(Date date) {
+		try {
+			String sdate = dateString(date);
+			return formatDateDay(sdate);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	private static final SimpleDateFormat format_date = new SimpleDateFormat("yyyy-MM-dd");
+
+	/**
+	 * 获取日期目录形式的字符串
+	 * 
+	 * @param date
+	 * @return String yyyy-MM-dd
+	 */
+	public static String dateString(Date date) {
+		return format_date.format(date);
+	}
+
+	/**
+	 * 将字符串转换成标准时间格式
+	 * 
+	 * @param date
+	 *            yyyy-MM-dd
+	 * @return
+	 */
+	public static Date formatDateDay(String date) {
+		Date new_date = null;
+		try {
+			new_date = format_date.parse(date);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return new_date;
+	}
+
+	public static Date combinationDateTime(Date d, Date t) {
+		String date = dateString(d);
+		String time = dateToStrTime(t);
+		return formatMinutes(date + " " + time);
+	}
+
+	private static final SimpleDateFormat format_time = new SimpleDateFormat("HH:mm:ss");
+
+	/**
+	 * 获取日期目录形式的字符串
+	 * 
+	 * @param date
+	 * @return String HH:mm:ss
+	 */
+	public static String dateToStrTime(Date time) {
+		return format_time.format(time);
+	}
+
+	private static final SimpleDateFormat format_date_minutes = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+	/**
+	 * 将字符串转换成标准时间格式
+	 * 
+	 * @param date
+	 *            yyyy-MM-dd HH:mm
+	 * @return
+	 */
+	public static Date formatMinutes(String date) {
+		Date new_date = null;
+		try {
+			new_date = format_date_minutes.parse(date);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return new_date;
+	}
+
+	/**
+	 * 计算某个日期到当前日期之间相差的天数
+	 * 
+	 * @param smdate
+	 *            较小的时间
+	 * @param bdate
+	 *            较大的时间
+	 * @return List<Date> 相差天数
+	 */
+	public static List<Date> daysBetweenNowDate(Date smdate, Date bdate) {
+		if (bdate == null || smdate == null || bdate.getTime() < smdate.getTime()) {
+			throw new IllegalArgumentException();
+		}
+		List<Date> dates = new ArrayList<Date>();
+		Calendar cal_sm = Calendar.getInstance();
+		cal_sm.setTime(smdate);
+		Calendar cal_big = Calendar.getInstance();
+		cal_big.setTime(bdate);
+		Calendar cal_now = Calendar.getInstance();
+		while (dateCompare(cal_now, cal_sm)) {
+			dates.add(cal_sm.getTime());
+			cal_sm.add(Calendar.DAY_OF_YEAR, +1);
+			if (dateCompare(cal_sm, cal_big)) {
+				break;
+			}
+		}
+		return dates;
+	}
+
+	/**
+	 * 把日期集合转换成字符串集合
+	 * 
+	 * @param List
+	 *            <Date>
+	 * @return List<String> yyyy-MM-dd
+	 */
+	public static List<String> dateStringList(List<Date> datelist) {
+		List<String> list = new ArrayList<String>();
+		for (Date date : datelist) {
+			list.add(format_date.format(date));
+		}
+		return list;
+	}
+
+	private static final SimpleDateFormat format_month = new SimpleDateFormat("yyyy-MM");
+
+	/**
+	 * 将字符串转换成标准时间格式
+	 * 
+	 * @param date
+	 *            yyyy-MM
+	 * @return
+	 */
+	public static Date formatDateMonth(String date) {
+		Date new_date = null;
+		try {
+			new_date = format_month.parse(date);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+		return new_date;
+	}
+
+	/**
+	 * 返回指定日期的月的第一天
+	 * 
+	 * @param year
+	 * @param month
+	 * @return
+	 */
+	public static Date getFirstDayOfMonth(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
+		calendar.set(Calendar.HOUR_OF_DAY, 0);
+		calendar.set(Calendar.MINUTE, 0);
+		calendar.set(Calendar.SECOND, 0);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 返回指定日期的月的最后一天
+	 * 
+	 * @param year
+	 * @param month
+	 * @return
+	 */
+	public static Date getLastDayOfMonth(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
+		calendar.roll(Calendar.DATE, -1);
+		calendar.set(Calendar.HOUR_OF_DAY, 23);
+		calendar.set(Calendar.MINUTE, 59);
+		calendar.set(Calendar.SECOND, 59);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 将当前时间转换成标准时间格式
+	 * 
+	 * @param date
+	 *            yyyy-MM-dd
+	 * @return
+	 */
+	public static Date dateToDate(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.HOUR_OF_DAY, 0);
+		calendar.set(Calendar.MINUTE, 0);
+		calendar.set(Calendar.SECOND, 0);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 获取当前时间后几分钟的时间
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getAfterTimeOfMinutes(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY),
+				c.get(Calendar.MINUTE) + timing, 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 将当前时间转换成标准时间格式
+	 * 
+	 * @param date
+	 *            yyyy-MM-dd HH:mm
+	 * @return
+	 */
+	public static Date dateToDateMinutes(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.SECOND, 0);
+		return calendar.getTime();
+	}
+
+	/**
+	 * 获取当前时间前几小时的时间
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getBeforeTimeOfHours(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) - timing,
+				c.get(Calendar.MINUTE), 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 获取当前时间前几天的时间-具体到分钟
+	 * 
+	 * @param now
+	 * @param timing
+	 * @return
+	 */
+	public static Date getBeforeTimeOfDate(Date now, int timing) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(now);
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE) - timing, c.get(Calendar.HOUR_OF_DAY),
+				c.get(Calendar.MINUTE), 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 上一小时开始的时间
+	 * 
+	 * @return
+	 */
+	public static Date preHourBegin() {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) - 1, 0, 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 上一小时结束的时间
+	 * 
+	 * @return
+	 */
+	public static Date preHourEnd() {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) - 1, 59,
+				59);
+		return c.getTime();
+	}
+
+	/**
+	 * 上一小时开始的时间
+	 *
+	 * @return
+	 */
+	public static Date preHourBegin(Integer hour) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) - hour, 0, 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 上一小时结束的时间
+	 *
+	 * @return
+	 */
+	public static Date preHourEnd(Integer hour) {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR_OF_DAY) -hour, 59,
+				59);
+		return c.getTime();
+	}
+
+
+	/**
+	 * 上一天开始的时间
+	 * 
+	 * @return
+	 */
+	public static Date preDayBegin() {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE) - 1, 0, 0, 0);
+		return c.getTime();
+	}
+
+	/**
+	 * 上一天结束的时间
+	 * 
+	 * @return
+	 */
+	public static Date preDayEnd() {
+		Calendar c = Calendar.getInstance();
+		c.setTime(new Date());
+		c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE) - 1, 23, 59, 59);
+		return c.getTime();
+	}
+
+	public static Date getMonday() {
+		Calendar calendar = Calendar.getInstance();
+		while (calendar.get(Calendar.DAY_OF_WEEK) != 2) {
+			calendar.add(Calendar.DAY_OF_YEAR, -1);
+		}
+		return calendar.getTime();
+	}
+
+	private static final SimpleDateFormat format_only_date = new SimpleDateFormat("yyyyMMdd");
+
+	/**
+	 * 日期偏移,返回格式:yyyyMMdd
+	 * 
+	 * @param date
+	 * @param offsetday
+	 * @return
+	 */
+	public static String dayOffset(Date date, int offset) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.DAY_OF_YEAR, offset);
+		return format_only_date.format(calendar.getTime());
+	}
+
+	/**
+	 * 根据用户生日计算年龄
+	 */
+	public static int getAgeByBirthday(Date birthday) {
+		Calendar cal = Calendar.getInstance();
+		if (cal.before(birthday)) {
+			throw new IllegalArgumentException("The birthDay is before Now.It's unbelievable!");
+		}
+		int yearNow = cal.get(Calendar.YEAR);
+		int monthNow = cal.get(Calendar.MONTH) + 1;
+		int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
+		cal.setTime(birthday);
+		int yearBirth = cal.get(Calendar.YEAR);
+		int monthBirth = cal.get(Calendar.MONTH) + 1;
+		int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
+		int age = yearNow - yearBirth;
+		if (monthNow <= monthBirth) {
+			if (monthNow == monthBirth) {
+				// monthNow==monthBirth
+				if (dayOfMonthNow < dayOfMonthBirth) {
+					age--;
+				}
+			} else {
+				// monthNow>monthBirth
+				age--;
+			}
+		}
+		return age;
+	}
+
+	/**
+	 * 计算两个日期之间相差的天数
+	 * 
+	 * @param smdate
+	 *            较小的时间
+	 * @param bdate
+	 *            较大的时间
+	 * @return List<Date> 相差天数
+	 */
+	public static List<Date> daysBetween(Date smdate, Date bdate) {
+		List<Date> dates = new ArrayList<Date>();
+		if (bdate == null || smdate == null || bdate.getTime() < smdate.getTime()) {
+			return dates;
+		}
+		Calendar cal_sm = Calendar.getInstance();
+		cal_sm.setTime(smdate);
+		Calendar cal_big = Calendar.getInstance();
+		cal_big.setTime(bdate);
+		while (dateCompare(cal_big, cal_sm)) {
+			dates.add(cal_sm.getTime());
+			cal_sm.add(Calendar.DAY_OF_YEAR, +1);
+		}
+		return dates;
+	}
+
+	/**
+	 * 对比两个日历中的日期哪个大,不对比时间
+	 * 
+	 * @param c1
+	 *            日历1
+	 * @param c2
+	 *            日历2
+	 * @return 返回c1是否比c2大
+	 */
+	private static boolean dateCompare(Calendar c1, Calendar c2) {
+		return c1.get(Calendar.YEAR) > c2.get(Calendar.YEAR) || (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)
+				&& c1.get(Calendar.DAY_OF_YEAR) > c2.get(Calendar.DAY_OF_YEAR));
+	}
+
+	public static String formatIso8601Date(Date date) {
+		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+		df.setTimeZone(new SimpleTimeZone(8, "GMT"));
+		return df.format(date);
+	}
+
+	/**
+	 * 日期型转化成字符串类型
+	 * 
+	 * @param format
+	 * @param date
+	 * @return
+	 */
+	public static String dateToStringyyyyMMdd(Date date) {
+		return new SimpleDateFormat(yyyyMMdd).format(date);
+	}
+	
+	public static Date hourPlus(Date date,int hours ) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.HOUR, hours);
+		return calendar.getTime();
+	}
+
+	public static Date dayPlus(Date date, int days) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.DATE, days);
+		return calendar.getTime();
+	}
+
+	public static Date minutePlus(Date date, int minutes) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.MINUTE, minutes);
+		return calendar.getTime();
+	}
+
+	public static Date secondPlus(Date date, int seconds) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.add(Calendar.SECOND, seconds);
+		return calendar.getTime();
+	}
+	
+	public static String formatDateByPattern(String format, Date date) {
+		SimpleDateFormat simple = new SimpleDateFormat(format);
+		return simple.format(date);
+	}
+	public static void main(String[] args) throws  Exception{
+		System.out.println(preHourBegin(14));
+		System.out.println(preHourEnd(14));
+		Date gmtModified = new Date();
+		System.out.println(DateUtils.dateToString(gmtModified ,"MM月dd日HH:mm"));
+
+		System.out.println(dateToString_only_date(dayPlus(new Date(),7)));
+
+	}
+
+	public static boolean isSameDay(Date gmtCreate, Date currentDatetime) {
+
+		return org.apache.commons.lang.time.DateUtils.isSameDay(gmtCreate, currentDatetime);
+	}
+
+
+
+	/**
+	 * 距离现在多久
+	 *
+	 * @param date
+	 * @return
+	 *
+	 */
+	public static String fromTodayDescr(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		int nowYear = calendar.get(Calendar.YEAR);
+		int nowDate = calendar.get(Calendar.DATE);
+		calendar.setTime(date);
+		int timeYear = calendar.get(Calendar.YEAR);
+		int timeDate = calendar.get(Calendar.DATE);
+		long time = date.getTime() / 1000;
+		long now = new Date().getTime() / 1000;
+		long ago = now - time;
+		if (ago < 0) {
+			ago = 1;
+		}
+		if (ago <= ONE_MINUTE)
+			return "1分钟内";
+		else if (ago < 3600) {
+			return ago / ONE_MINUTE + "分钟前";
+		} else if (ago < ONE_DAY) {
+			if (nowDate == timeDate) {
+				return ago / ONE_HOUR + "小时前";
+			}
+		}
+		if (ago < ONE_DAY * 2) {
+			Date beginToday = CalendarUtil.getBeginTimeOfAddDays(new Date(), 0);
+			Date beginYesterday = CalendarUtil.getBeginTimeOfAddDays(new Date(), -1);
+			if (date.after(beginYesterday) && date.before(beginToday)) {
+				return "昨天 " + formatDateByPattern("HH:mm", date);
+			}
+		}
+		if (nowYear == timeYear) {
+			return formatDateByPattern("MM-dd HH:mm", date);
+		} else {
+			return formatDateByPattern("yyyy-MM-dd HH:mm", date);
+		}
+	}
+
+	public static Date longToDate(String millis) {
+		if (StringUtils.isBlank(millis)) {
+			return new Date();
+		}
+		Calendar cal = Calendar.getInstance();
+		cal.setTimeInMillis(Long.parseLong(millis));
+		Date date = cal.getTime();
+		return date;
+	}
+	public static String longToDate(Long second,String patten) {
+		if(second==null){
+			return "";
+		}
+		try {
+			Long s=second.longValue();
+			Calendar calendar = Calendar.getInstance();
+			calendar.setTimeInMillis(s);
+			Date date = calendar.getTime();
+			SimpleDateFormat format = new SimpleDateFormat(patten);
+			String dateString = format.format(date);
+			return dateString;
+		}catch (Exception e){
+		}
+		return "";
+	}
+
+	/**
+	 * 计算两个时间的分钟
+	 */
+	public static Integer calculateMinuteTime(Long startTime,Long endTime) {
+		long dateDiff = startTime - endTime;
+		if (dateDiff < 0) {
+			return 0;
+		} else {
+			return (int) (dateDiff / 1000 / 60); // 分钟
+		}
+	}
+}

+ 23 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/utils/PropertiesUtils.java

@@ -65,5 +65,28 @@ public class PropertiesUtils {
     }
 
 
+    public static String getVideoBucket() {
+        return getProperties().getProperty("oss.longvideo.bucket");
+    }
+
+    public static String getDownloadDomain() {
+        return getProperties().getProperty("oss.longvideo.cdnDomain");
+    }
+
+    public static String getTranscodeLocation() {
+        return getProperties().getProperty("oss.longvideo.transcode.location");
+    }
+
+    public static String getTranscodePipelineId() {
+        return getProperties().getProperty("oss.longvideo.transcode.PipelineId");
+    }
+
+    public static String getReadOnlyAccessKeyId() {
+        return getProperties().getProperty("oss.video.readonly.accessKey");
+    }
+
+    public static String getReadOnlyAccessKeySecret() {
+        return getProperties().getProperty("oss.video.readonly.secretKey");
+    }
 
 }

+ 10 - 0
pom.xml

@@ -235,6 +235,16 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>com.stuuudy.commons</groupId>
+            <artifactId>commons-external</artifactId>
+            <version>1.0-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-validation</artifactId>
+        </dependency>
 
     </dependencies>