mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
Merge branch 'dev-new' into dev-new-rabbitmq
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.jsowell.common.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 统计函数执行耗时
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CostTime {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsowell.common.config;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -31,6 +32,16 @@ public class AliyunOssConfig {
|
||||
*/
|
||||
private String filehost;
|
||||
|
||||
/**
|
||||
* 蓝牙小程序文件路径
|
||||
*/
|
||||
private String bluetoothFileHost;
|
||||
|
||||
/**
|
||||
* 访问域名(上传蓝牙固件时用)
|
||||
*/
|
||||
private String interviewUrl;
|
||||
|
||||
/**
|
||||
* 访问域名
|
||||
*/
|
||||
@@ -76,6 +87,22 @@ public class AliyunOssConfig {
|
||||
this.filehost = filehost;
|
||||
}
|
||||
|
||||
public String getBluetoothFileHost() {
|
||||
return bluetoothFileHost;
|
||||
}
|
||||
|
||||
public void setBluetoothFileHost(String bluetoothFileHost) {
|
||||
this.bluetoothFileHost = bluetoothFileHost;
|
||||
}
|
||||
|
||||
public String getInterviewUrl() {
|
||||
return interviewUrl;
|
||||
}
|
||||
|
||||
public void setInterviewUrl(String interviewUrl) {
|
||||
this.interviewUrl = interviewUrl;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
@@ -86,13 +113,15 @@ public class AliyunOssConfig {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AliyunOssConfig{" +
|
||||
"endpoint='" + endpoint + '\'' +
|
||||
", accessKeyId='" + accessKeyId + '\'' +
|
||||
", accessKeySecret='" + accessKeySecret + '\'' +
|
||||
", bucketName='" + bucketName + '\'' +
|
||||
", filehost='" + filehost + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
'}';
|
||||
return new ToStringBuilder(this)
|
||||
.append("endpoint", endpoint)
|
||||
.append("accessKeyId", accessKeyId)
|
||||
.append("accessKeySecret", accessKeySecret)
|
||||
.append("bucketName", bucketName)
|
||||
.append("filehost", filehost)
|
||||
.append("bluetoothFileHost", bluetoothFileHost)
|
||||
.append("interviewUrl", interviewUrl)
|
||||
.append("url", url)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -344,4 +344,9 @@ public class CacheConstants {
|
||||
* 验证码有效期时长 redis key
|
||||
*/
|
||||
public static final String SMS_VERIFICATION_CODE_KEY = "sms_verification_code:";
|
||||
|
||||
/**
|
||||
* 根据桩号查询计费模板
|
||||
*/
|
||||
public static final String BILLING_TEMPLATE_BY_PILE_SN = "billing_template_by_pile_sn:";
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.jsowell.common.util.file;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PutObjectResult;
|
||||
import com.jsowell.common.config.AliyunOssConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -14,6 +17,7 @@ import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AliyunOssUploadUtils {
|
||||
|
||||
@@ -55,7 +59,8 @@ public class AliyunOssUploadUtils {
|
||||
// 文件路径名称
|
||||
filePathName = aliyunOssConfig.getFilehost() + "/" + dir_name + randomNumber + filePathName;
|
||||
try {
|
||||
ossClient.putObject(aliyunOssConfig.getBucketName(), filePathName, file.getInputStream());
|
||||
PutObjectResult putObjectResult = ossClient.putObject(aliyunOssConfig.getBucketName(), filePathName, file.getInputStream());
|
||||
// log.info("上传OSS成功, url:{}", putObjectResult.getResponse().getUri());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
@@ -67,7 +72,34 @@ public class AliyunOssUploadUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传到阿里云(车位相机用)
|
||||
* 上传蓝牙升级程序文件
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
public static String uploadBlueToothFile(MultipartFile file) {
|
||||
// 生成 OSSClient
|
||||
OSS ossClient = new OSSClientBuilder().build(aliyunOssConfig.getEndpoint(), aliyunOssConfig.getAccessKeyId(), aliyunOssConfig.getAccessKeySecret());
|
||||
|
||||
// 编码文件名
|
||||
String filePathName = FileUploadUtils.extractFilename(file);
|
||||
|
||||
// 拼装路径
|
||||
filePathName = aliyunOssConfig.getBluetoothFileHost() + "/files/" + filePathName;
|
||||
try {
|
||||
PutObjectResult putObjectResult = ossClient.putObject(aliyunOssConfig.getBucketName(), filePathName, file.getInputStream());
|
||||
// log.info("上传蓝牙升级文件到OSS成功, putObjectResult:{}", JSONObject.toJSONString(putObjectResult));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
}
|
||||
return aliyunOssConfig.getInterviewUrl() + "/" + filePathName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 车位相机图片上传到阿里云(车位相机用)
|
||||
* @param compressedImageBytes
|
||||
* @param fileName 文件名 (车位号 + 时间戳).jpg
|
||||
* @return
|
||||
|
||||
Reference in New Issue
Block a user