派生自 projectDept/qhighschool

胡仁荣
2023-10-08 c257eda25e4c9cb6fdfa8a9a85c2dd7be67b5a49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.qxueyou.scc.config;
 
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.qxueyou.scc.teach.res.service.impl.HweiYunOBSServiceImpl;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * @ClassName: HweiOBSConfig
 * @Description: 华为云OBS配置类
 * @Author: wuhuiju
 * @Date: 2021-12-21 15:56
 * @Version: 1.0
 */
//@Data
//@Slf4j
@Configuration
public class HweiOBSConfig {
 
    private final Logger log = LogManager.getLogger(HweiOBSConfig.class);
    public HweiOBSConfig() {
    }
 
    public HweiOBSConfig(String accessKey, String securityKey, String endPoint, String bucketName) {
        this.accessKey = accessKey;
        this.securityKey = securityKey;
        this.endPoint = endPoint;
        this.bucketName = bucketName;
    }
 
    public String getAccessKey() {
        return accessKey;
    }
 
    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }
 
    public String getSecurityKey() {
        return securityKey;
    }
 
    public void setSecurityKey(String securityKey) {
        this.securityKey = securityKey;
    }
 
    public String getEndPoint() {
        return endPoint;
    }
 
    public void setEndPoint(String endPoint) {
        this.endPoint = endPoint;
    }
 
    public String getBucketName() {
        return bucketName;
    }
 
    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }
 
    /**
     * 访问密钥AK
     */
    @Value("${hwyun.obs.accessKey}")
    private String accessKey;
 
    /**
     * 访问密钥SK
     */
    @Value("${hwyun.obs.securityKey}")
    private String securityKey;
 
    /**
     * 终端节点
     */
    @Value("${hwyun.obs.endPoint}")
    private String endPoint;
 
    /**
     * 桶
     */
    @Value("${hwyun.obs.bucketName}")
    private String bucketName;
 
    /**
     * @Description 获取OBS客户端实例
     * @author wuhuiju
     * @date 2022/12/2 15:57
     * @return
     * @return: com.obs.services.ObsClient
     */
    public ObsClient getInstance() {
        return new ObsClient(accessKey, securityKey, endPoint);
    }
 
 
    /**
     * @Description 销毁OBS客户端实例
     * @author wuhuiju
     * @date 2022/12/2 17:32
     * @param: obsClient
     * @return
     */
    public void destroy(ObsClient obsClient){
        try {
            obsClient.close();
        } catch (ObsException e) {
            log.error("obs执行失败", e);
        } catch (Exception e) {
            log.error("执行失败", e);
        }
    }
 
    /**
     * @Description 微服务文件存放路径
     * @author wuhuiju
     * @date 2022/12/2 15:57
     * @return
     * @return: java.lang.String
     */
    public static String getObjectKey() {
        // 项目或者服务名称 + 日期存储方式
        return "Hwei" + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date() )+ "/";
    }
}