parent
40f03ba1d0
commit
534b538f6e
@ -0,0 +1,18 @@
|
|||||||
|
package org.opsli.common.annotation;
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数配置
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
public @interface OptionDict {
|
||||||
|
|
||||||
|
/** 参数编码 */
|
||||||
|
String value();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.core.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.opsli.core.autoconfigure.properties.GlobalProperties;
|
||||||
|
import org.opsli.core.msg.CoreMsg;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import static org.opsli.common.constants.OrderConstants.UTIL_ORDER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.core.utils
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2020-09-19 20:03
|
||||||
|
* @Description: 系统配置参数 工具类
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Order(UTIL_ORDER)
|
||||||
|
@Component
|
||||||
|
@Lazy(false)
|
||||||
|
public class GlobalPropertiesUtil {
|
||||||
|
|
||||||
|
/** 系统信息 */
|
||||||
|
private static GlobalProperties GLOBAL_PROPERTIES;
|
||||||
|
|
||||||
|
/** 增加初始状态开关 防止异常使用 */
|
||||||
|
private static boolean IS_INIT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得 系统配置信息
|
||||||
|
* @return GlobalProperties
|
||||||
|
*/
|
||||||
|
public static GlobalProperties getGlobalProperties(){
|
||||||
|
// 判断 工具类是否初始化完成
|
||||||
|
ThrowExceptionUtil.isThrowException(!IS_INIT,
|
||||||
|
CoreMsg.OTHER_EXCEPTION_UTILS_INIT);
|
||||||
|
|
||||||
|
return GLOBAL_PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
public void init(GlobalProperties globalProperties){
|
||||||
|
// 获得 配置信息
|
||||||
|
GlobalPropertiesUtil.GLOBAL_PROPERTIES = globalProperties;
|
||||||
|
|
||||||
|
IS_INIT = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package org.opsli.core.utils;
|
||||||
|
|
||||||
|
import org.opsli.common.base.msg.BaseMsg;
|
||||||
|
import org.opsli.common.exception.ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 抛出异常工具类
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2021年5月7日18:32:32
|
||||||
|
*/
|
||||||
|
public final class ThrowExceptionUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 直接抛出异常
|
||||||
|
* @param msg 异常信息
|
||||||
|
*/
|
||||||
|
public static void throwException(BaseMsg msg){
|
||||||
|
throw new ServiceException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否抛出异常
|
||||||
|
* @param msg 异常信息
|
||||||
|
*/
|
||||||
|
public static void isThrowException(boolean isError, BaseMsg msg){
|
||||||
|
if(isError){
|
||||||
|
throw new ServiceException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ThrowExceptionUtil(){}
|
||||||
|
}
|
@ -1,58 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.oss.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 本地存储 参数类型
|
|
||||||
*
|
|
||||||
* @author Parker
|
|
||||||
*/
|
|
||||||
public enum LocalStorageType {
|
|
||||||
|
|
||||||
/** 本地存储服务 */
|
|
||||||
DOMAIN("storage_local_domain", "域名"),
|
|
||||||
PATH_PREFIX("storage_local_path_prefix", "路径前缀"),
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
private final String desc;
|
|
||||||
|
|
||||||
public static LocalStorageType getType(String cacheType) {
|
|
||||||
LocalStorageType[] var1 = values();
|
|
||||||
for (LocalStorageType type : var1) {
|
|
||||||
if (type.code.equalsIgnoreCase(cacheType)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return this.desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =================
|
|
||||||
|
|
||||||
LocalStorageType(final String code, final String desc) {
|
|
||||||
this.code = code;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.oss.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 存储服务类型
|
|
||||||
*
|
|
||||||
* @author Parker
|
|
||||||
*/
|
|
||||||
public enum OssConfType {
|
|
||||||
|
|
||||||
/** 存储服务类型 */
|
|
||||||
STORAGE_TYPE("storage_type", "存储服务类型"),
|
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
private final String code;
|
|
||||||
private final String desc;
|
|
||||||
|
|
||||||
public static OssConfType getType(String cacheType) {
|
|
||||||
OssConfType[] var1 = values();
|
|
||||||
for (OssConfType type : var1) {
|
|
||||||
if (type.code.equalsIgnoreCase(cacheType)) {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc() {
|
|
||||||
return this.desc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =================
|
|
||||||
|
|
||||||
OssConfType(final String code, final String desc) {
|
|
||||||
this.code = code;
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,18 @@
|
|||||||
|
package org.opsli.plugins.oss.factory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息 接口
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
* @date 2021年5月7日17:39:32
|
||||||
|
*/
|
||||||
|
public interface ConfigFactory<Conf> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
Conf getConfig();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.plugins.oss.factory;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.opsli.common.annotation.OptionDict;
|
||||||
|
import org.opsli.common.annotation.validation.ValidationArgs;
|
||||||
|
import org.opsli.common.annotation.validation.ValidationArgsLenMax;
|
||||||
|
import org.opsli.common.enums.ValiArgsType;
|
||||||
|
import org.opsli.core.utils.OptionsUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地存储配置工程
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
public enum LocalConfigFactory implements ConfigFactory<LocalConfigFactory.LocalConfig> {
|
||||||
|
|
||||||
|
/** 实例对象 */
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得配置信息
|
||||||
|
* @return LocalConfig
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public LocalConfig getConfig() {
|
||||||
|
LocalConfig config = new LocalConfig();
|
||||||
|
// 获得缓存参数配置
|
||||||
|
OptionsUtil.getOptionByBean(config);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地存储配置
|
||||||
|
*
|
||||||
|
* @author Parker
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class LocalConfig implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 域名 */
|
||||||
|
@ApiModelProperty(value = "域名")
|
||||||
|
@ValidationArgs({ValiArgsType.IS_NOT_NULL})
|
||||||
|
@ValidationArgsLenMax(100)
|
||||||
|
@OptionDict("storage_local_domain")
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
/** 前缀 */
|
||||||
|
@ApiModelProperty(value = "前缀")
|
||||||
|
@ValidationArgsLenMax(100)
|
||||||
|
@OptionDict("storage_local_path_prefix")
|
||||||
|
private String pathPrefix;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue