feat: 新增又拍云存储服务

v1.4.1
Carina 4 years ago
parent 1fb255174c
commit ab4356c846

@ -35,12 +35,24 @@ public class ServiceException extends RuntimeException{
this.errorMessage = errorMessage;
}
public ServiceException(Integer code, String errorMessage, Throwable e) {
super(errorMessage, e);
this.code = code;
this.errorMessage = errorMessage;
}
public ServiceException(BaseMsg msg) {
super(msg.getMessage());
this.code = msg.getCode();
this.errorMessage = msg.getMessage();
}
public ServiceException(BaseMsg msg, Throwable e) {
super(msg.getMessage(), e);
this.code = msg.getCode();
this.errorMessage = msg.getMessage();
}
public Integer getCode() {
return code;
}

@ -1,3 +1,18 @@
/**
* 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.common.utils;
import java.util.ArrayList;

@ -41,6 +41,13 @@
<version>${plugins.version}</version>
</dependency>
<!-- 引入邮件插件 -->
<dependency>
<groupId>org.opsliframework.boot</groupId>
<artifactId>opsli-plugins-email</artifactId>
<version>${plugins.version}</version>
</dependency>
<!-- 引入Redis插件 -->
<dependency>
<groupId>org.opsliframework.boot</groupId>

@ -17,12 +17,9 @@ package org.opsli.core.base.controller;
import cn.hutool.core.annotation.AnnotationUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.util.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

@ -33,7 +33,7 @@ import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiCryptoAsymmetric;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.options.CryptoConfigFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@ -84,8 +84,7 @@ public class ApiCryptoAsymmetricAop {
CryptoAsymmetric cryptoAsymmetric = null;
if(annotation != null && annotation.enable()){
asymmetric = CryptoPlugin.getAsymmetric();
cryptoAsymmetric =
OptionsUtil.getOptionByBean(asymmetric.createNilModel());
cryptoAsymmetric = CryptoConfigFactory.INSTANCE.getCryptoAsymmetric();
}
// 1. 请求解密

@ -0,0 +1,113 @@
/**
* 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.options;
import lombok.Data;
import opsli.plugins.crypto.enums.CryptoAsymmetricType;
import opsli.plugins.crypto.enums.CryptoSymmetricType;
import opsli.plugins.crypto.model.CryptoAsymmetric;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.common.annotation.OptionDict;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.utils.ValidatorUtil;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
public enum CryptoConfigFactory {
/** 实例对象 */
INSTANCE;
/**
*
* @return LocalConfig
*/
public CryptoAsymmetric getCryptoSymmetric() {
CryptoSymmetricOption option = new CryptoSymmetricOption();
// 获得缓存参数配置
OptionsUtil.getOptionByBean(option);
// 验证配置
ValidatorUtil.verify(option);
// 转化对象
return WrapperUtil.transformInstance(option, CryptoAsymmetric.class);
}
/**
*
* @return LocalConfig
*/
public CryptoAsymmetric getCryptoAsymmetric() {
CryptoAsymmetricOption option = new CryptoAsymmetricOption();
// 获得缓存参数配置
OptionsUtil.getOptionByBean(option);
// 验证配置
ValidatorUtil.verify(option);
// 转化对象
return WrapperUtil.transformInstance(option, CryptoAsymmetric.class);
}
// =======================
/**
*
*
* @author Parker
* @date 202151715:59:52
*/
@Data
public static class CryptoSymmetricOption {
/** 加解密类别 */
@OptionDict("crypto_symmetric")
private CryptoSymmetricType cryptoType;
/** 私钥 */
@OptionDict("crypto_symmetric_private_key")
private String privateKey;
}
/**
*
*
* @author Parker
* @date 202151715:59:52
*/
@Data
public static class CryptoAsymmetricOption {
/** 加解密类别 */
@OptionDict("crypto_asymmetric")
private CryptoAsymmetricType cryptoType;
/** 公钥 */
@OptionDict("crypto_asymmetric_public_key")
private String publicKey;
/** 私钥 */
@OptionDict("crypto_asymmetric_private_key")
private String privateKey;
}
}

@ -0,0 +1,106 @@
/**
* 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.options;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.opsli.common.annotation.OptionDict;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.enums.ValidatorType;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.utils.ValidatorUtil;
import org.opsli.plugins.email.conf.EmailConfig;
import java.io.Serializable;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
public enum EmailConfigFactory {
/** 实例对象 */
INSTANCE;
/**
*
* @return LocalConfig
*/
public EmailConfig getConfig() {
EmailConfigOption option = new EmailConfigOption();
// 获得缓存参数配置
OptionsUtil.getOptionByBean(option);
// 验证配置
ValidatorUtil.verify(option);
// 转化对象
return WrapperUtil.transformInstance(option, EmailConfig.class);
}
// =======================
/**
*
*
* @author Parker
*/
@Data
public static class EmailConfigOption implements Serializable {
private static final long serialVersionUID = 1L;
/** SMTP地址 */
@ApiModelProperty(value = "SMTP地址")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_smtp")
private String smtp;
/** SMTP端口 */
@ApiModelProperty(value = "SMTP端口")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_port")
private Integer port;
/** 开启SSL认证 */
@ApiModelProperty(value = "开启SSL认证")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_ssl_enable")
private String sslEnable;
/** 邮箱账号 */
@ApiModelProperty(value = "邮箱账号")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_account")
private String account;
/** 邮箱密码 */
@ApiModelProperty(value = "邮箱密码")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_password")
private String password;
/** 发件人 */
@ApiModelProperty(value = "发件人")
@Validator({ValidatorType.IS_NOT_NULL})
@OptionDict("email_addresser")
private String addresser;
}
}

@ -22,12 +22,12 @@ import cn.hutool.core.util.ReflectUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType;
import org.opsli.common.utils.DefPatternPool;
import org.opsli.common.msg.ValidatorMsg;
import org.opsli.api.wrapper.system.dict.DictModel;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.exception.ServiceException;
import java.lang.reflect.Field;

@ -1,63 +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.email.enums;
/**
* Email
*
* @author Parker
* @date 2020-09-19 20:03
*/
public enum EmailType {
/** SMTP 服务 */
EMAIL_SMTP("email_smtp", "SMTP地址"),
EMAIL_PORT("email_port", "SMTP端口"),
EMAIL_SSL_ENABLE("email_ssl_enable", "开启SSL认证"),
EMAIL_ACCOUNT("email_account", "邮箱账号"),
EMAIL_PASSWORD("email_password", "邮箱账号密码"),
EMAIL_ADDRESSER("email_addresser", "发件人"),
;
private final String code;
private final String desc;
public static EmailType getType(String cacheType) {
EmailType[] types = values();
for (EmailType type : types) {
if (type.code.equalsIgnoreCase(cacheType)) {
return type;
}
}
return null;
}
public String getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
// =================
EmailType(final String code, final String desc) {
this.code = code;
this.desc = desc;
}
}

@ -1,102 +0,0 @@
package org.opsli.plugins.email.service.impl;
import cn.hutool.core.convert.Convert;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import org.opsli.api.wrapper.system.options.OptionsModel;
import org.opsli.common.enums.DictType;
import org.opsli.core.utils.OptionsUtil;
import org.opsli.core.utils.ValidatorUtil;
import org.opsli.plugins.email.enums.EmailType;
import org.opsli.plugins.email.service.IEmailService;
import org.opsli.plugins.email.wrapper.EmailModel;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Collections;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
@Service
public class EmailServiceImpl implements IEmailService {
@Override
public String send(String to, String subject, String content) {
// 发送邮件
return this.send(Collections.singletonList(to), subject ,content);
}
@Override
public String send(Collection<String> tos, String subject, String content) {
// 发送邮件
return this.send(tos, subject ,content, false);
}
@Override
public String send(String to, String subject, String content, boolean isHtml) {
// 发送邮件
return this.send(Collections.singletonList(to), subject ,content, isHtml);
}
@Override
public String send(Collection<String> tos, String subject, String content, boolean isHtml) {
// 校验发送邮件数据是否正确
for (String to : tos) {
EmailModel emailModel = new EmailModel();
emailModel.setTo(to);
emailModel.setSubject(subject);
emailModel.setContent(content);
ValidatorUtil.verify(emailModel);
}
// 获得配置信息
MailAccount mailAccount = this.getMailAccount();
// 发送邮件
return MailUtil.send(mailAccount, tos , subject ,content, isHtml);
}
/**
*
* @return MailAccount
*/
private MailAccount getMailAccount(){
// 获得配置数据
OptionsModel smtp = OptionsUtil.getOptionByCode(EmailType.EMAIL_SMTP.getCode());
OptionsModel port = OptionsUtil.getOptionByCode(EmailType.EMAIL_PORT.getCode());
OptionsModel sslEnable = OptionsUtil.getOptionByCode(EmailType.EMAIL_SSL_ENABLE.getCode());
OptionsModel account = OptionsUtil.getOptionByCode(EmailType.EMAIL_ACCOUNT.getCode());
OptionsModel password = OptionsUtil.getOptionByCode(EmailType.EMAIL_PASSWORD.getCode());
OptionsModel addresser = OptionsUtil.getOptionByCode(EmailType.EMAIL_ADDRESSER.getCode());
MailAccount mailAccount = new MailAccount();
mailAccount.setAuth(true);
if(smtp != null){
mailAccount.setHost(smtp.getOptionValue());
}
if(port != null){
mailAccount.setPort(Convert.toInt(port.getOptionValue()));
}
if(sslEnable != null){
mailAccount.setSslEnable(
DictType.NO_YES_YES.getValue().equals(sslEnable.getOptionValue()));
}
if(account != null){
mailAccount.setUser(account.getOptionValue());
}
if(password != null){
mailAccount.setPass(password.getOptionValue());
}
if(addresser != null){
mailAccount.setFrom(addresser.getOptionValue());
}
return mailAccount;
}
}

@ -1,39 +0,0 @@
package org.opsli.plugins.email.wrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.enums.ValidatorType;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class EmailModel {
/** 收件人 */
@ApiModelProperty(value = "收件人")
@Validator({ValidatorType.IS_EMAIL, ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(200)
private String to;
/** 主题 */
@ApiModelProperty(value = "主题")
@Validator({ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(200)
private String subject;
/** 内容 */
@ApiModelProperty(value = "内容")
@ValidatorLenMax(20000)
private String content;
}

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.plugins.oss.factory;
package org.opsli.plugins.oss.conf;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ -0,0 +1,102 @@
/**
* 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.conf;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.opsli.common.annotation.OptionDict;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.enums.ValidatorType;
import org.opsli.core.utils.OptionsUtil;
import java.io.Serializable;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
public enum UpYunConfigFactory implements ConfigFactory<UpYunConfigFactory.UpYunConfig> {
/** 实例对象 */
INSTANCE;
/**
*
* @return LocalConfig
*/
@Override
public UpYunConfig getConfig() {
UpYunConfig config = new UpYunConfig();
// 获得缓存参数配置
OptionsUtil.getOptionByBean(config);
return config;
}
// =======================
/**
*
*
* @author Parker
*/
@Data
public static class UpYunConfig implements Serializable {
private static final long serialVersionUID = 1L;
/** 域名 */
@ApiModelProperty(value = "域名")
@Validator({ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(100)
@OptionDict("storage_upyun_domain")
private String domain;
/** 前缀 */
@ApiModelProperty(value = "前缀")
@ValidatorLenMax(100)
@OptionDict("storage_upyun_path_prefix")
private String pathPrefix;
/** 操作员用户名 */
@ApiModelProperty(value = "操作员用户名")
@Validator({ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(100)
@OptionDict("storage_upyun_username")
private String username;
/** 操作员密码 */
@ApiModelProperty(value = "操作员密码")
@Validator({ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(100)
@OptionDict("storage_upyun_password")
private String password;
/** 存储仓库名 */
@ApiModelProperty(value = "存储仓库名")
@Validator({ValidatorType.IS_NOT_NULL})
@ValidatorLenMax(100)
@OptionDict("storage_upyun_bucket_name")
private String bucketName;
}
}

@ -25,6 +25,8 @@ public enum OssStorageType {
/** 存储服务类型 */
LOCAL("local", "本地"),
UP_YUN("upYun", "又拍云"),
;

@ -0,0 +1,44 @@
/**
* 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.exception;
import org.opsli.common.base.msg.BaseMsg;
import org.opsli.common.exception.ServiceException;
/**
*
*
* @author Parker
* @date 2020-09-16 11:47
*/
public class StoragePluginException extends ServiceException {
public StoragePluginException(Integer code, String errorMessage) {
super(code, errorMessage);
}
public StoragePluginException(Integer code, String errorMessage, Throwable e) {
super(code, errorMessage);
}
public StoragePluginException(BaseMsg msg) {
super(msg);
}
public StoragePluginException(BaseMsg msg, Throwable e) {
super(msg);
}
}

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.plugins.oss;
package org.opsli.plugins.oss.msg;
import org.opsli.common.base.msg.BaseMsg;
@ -29,8 +29,8 @@ public enum OssMsg implements BaseMsg {
/**
* OSS
*/
EXCEPTION_UPLOAD_ERROR(90500, "上传文件失败,请检查配置信息"),
EXCEPTION_UPLOAD_AUTH_ERROR(90501, "权限认证异常")
;

@ -18,6 +18,7 @@ package org.opsli.plugins.oss.service;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
@ -25,7 +26,7 @@ import java.io.File;
import java.io.InputStream;
/**
* ()
* (...)
*
* @author Parker
* @date 202143016:12:45
@ -33,7 +34,7 @@ import java.io.InputStream;
public abstract class BaseOssStorageService implements OssStorageService {
/** 文件夹前缀 */
private static final String FOLDER_PREFIX = "/";
public static final String FOLDER_PREFIX = "/";
private static final String FOLDER_WINDOWS_PREFIX = "\\";
/**
@ -118,10 +119,7 @@ public abstract class BaseOssStorageService implements OssStorageService {
if(isHandleFirst){
// 如果 第一位不是 / 则加 /
char firstChar = path.charAt(0);
if(!StringUtils.equals(FOLDER_PREFIX, Convert.toStr(firstChar))){
path = FOLDER_PREFIX + path;
}
path = StrUtil.prependIfMissing(path, FOLDER_PREFIX);
}
// 如果最后一位 是 / 则减 /

@ -17,14 +17,14 @@ package org.opsli.plugins.oss.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.opsli.core.autoconfigure.properties.GlobalProperties;
import org.opsli.core.utils.GlobalPropertiesUtil;
import org.opsli.core.utils.ValidatorUtil;
import org.opsli.plugins.oss.enums.OssStorageType;
import org.opsli.plugins.oss.factory.LocalConfigFactory;
import org.opsli.plugins.oss.conf.LocalConfigFactory;
import org.opsli.plugins.oss.service.BaseOssStorageService;
import java.io.File;
@ -80,12 +80,12 @@ public class LocalStorageServiceImpl extends BaseOssStorageService {
// 静态路径
String genPath = globalProperties != null && globalProperties.getWeb() != null &&
StringUtils.isNotEmpty(globalProperties.getWeb().getUploadPath())
StrUtil.isNotEmpty(globalProperties.getWeb().getUploadPath())
? globalProperties.getWeb().getUploadPath()
: FileUtil.getUserHomePath();
// 静态路径前缀 默认为空
String pathPrefix = StringUtils.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
// 文件夹名称
String folderName = DateUtil.format(currDate, "yyyyMMdd");
@ -138,12 +138,12 @@ public class LocalStorageServiceImpl extends BaseOssStorageService {
// 静态路径
String genPath = globalProperties != null && globalProperties.getWeb() != null &&
StringUtils.isNotEmpty(globalProperties.getWeb().getUploadPath())
StrUtil.isNotEmpty(globalProperties.getWeb().getUploadPath())
? globalProperties.getWeb().getUploadPath()
: FileUtil.getUserHomePath();
// 静态路径前缀 默认为空
String pathPrefix = StringUtils.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
// 文件夹名称
String folderName = DateUtil.format(currDate, "yyyyMMdd");

@ -0,0 +1,169 @@
/**
* 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.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.upyun.RestManager;
import com.upyun.UpException;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Response;
import org.apache.commons.io.FileUtils;
import org.opsli.core.autoconfigure.properties.GlobalProperties;
import org.opsli.core.utils.GlobalPropertiesUtil;
import org.opsli.core.utils.ValidatorUtil;
import org.opsli.plugins.oss.conf.LocalConfigFactory;
import org.opsli.plugins.oss.conf.UpYunConfigFactory;
import org.opsli.plugins.oss.enums.OssStorageType;
import org.opsli.plugins.oss.exception.StoragePluginException;
import org.opsli.plugins.oss.msg.OssMsg;
import org.opsli.plugins.oss.service.BaseOssStorageService;
import org.springframework.http.HttpStatus;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
/**
*
*
* @author Parker
* @date 202143014:09:08
*/
@Slf4j
public class UpYunStorageServiceImpl extends BaseOssStorageService {
@Override
public OssStorageType getType() {
return OssStorageType.UP_YUN;
}
@Override
public String getDomain() {
// 获得配置信息
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
return config.getDomain();
}
@Override
public FileAttr upload(File file) {
// 非空判断
if(FileUtil.isEmpty(file)){
return new FileAttr();
}
// 获得配置信息
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
// 验证对象
ValidatorUtil.verify(config);
// 当前时间戳
long currentTimeMillis = System.currentTimeMillis();
// 当前时间
Date currDate = DateUtil.date(currentTimeMillis);
// 静态路径前缀 默认为空
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
// 文件夹名称
String folderName = DateUtil.format(currDate, "yyyyMMdd");
// 包 名称
String packageName = StrUtil.appendIfMissing(
super.handlePath(pathPrefix) + super.handlePath(folderName),
BaseOssStorageService.FOLDER_PREFIX);
// 文件属性
FileAttr fileAttr = super.getFileAttr(file);
// 设置文件路径
fileAttr.setFileStoragePath(packageName + fileAttr.getName() + fileAttr.getSuffix());
try {
// 获得又拍云 服务
RestManager restManager = this.getService(config);
restManager.writeFile(fileAttr.getFileStoragePath(), file, null);
}catch (IOException | UpException e){
// 上传文件失败,请检查配置信息
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_ERROR, e);
}
return fileAttr;
}
@Override
public FileAttr upload(InputStream inputStream, String suffix) {
// 获得配置信息
UpYunConfigFactory.UpYunConfig config = UpYunConfigFactory.INSTANCE.getConfig();
// 验证对象
ValidatorUtil.verify(config);
// 当前时间戳
long currentTimeMillis = System.currentTimeMillis();
// 当前时间
Date currDate = DateUtil.date(currentTimeMillis);
// 静态路径前缀 默认为空
String pathPrefix = StrUtil.isNotEmpty(config.getPathPrefix())?config.getPathPrefix():"";
// 文件夹名称
String folderName = DateUtil.format(currDate, "yyyyMMdd");
// 包 名称
String packageName = StrUtil.appendIfMissing(
super.handlePath(pathPrefix) + super.handlePath(folderName),
BaseOssStorageService.FOLDER_PREFIX);
// 文件属性
FileAttr fileAttr = super.getFileAttr(inputStream, suffix);
// 设置文件路径
fileAttr.setFileStoragePath(
config.getDomain() + packageName + fileAttr.getRandomFileNameAndSuffix());
try {
// 获得又拍云 服务
RestManager restManager = this.getService(config);
Response response = restManager.writeFile(packageName + fileAttr.getRandomFileNameAndSuffix(),
inputStream, null);
int code = response.code();
if(HttpStatus.UNAUTHORIZED.value() == code){
// 权限认证异常
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_AUTH_ERROR);
}
}catch (IOException | UpException e){
// 上传文件失败,请检查配置信息
throw new StoragePluginException(OssMsg.EXCEPTION_UPLOAD_ERROR, e);
}
return fileAttr;
}
/**
*
* @return RestManager
*/
private RestManager getService(UpYunConfigFactory.UpYunConfig config){
return new RestManager(config.getBucketName(),
config.getUsername(), config.getPassword());
}
}

@ -16,7 +16,6 @@
package org.opsli.modulars.generator.logs.wrapper;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -24,7 +23,6 @@ import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
/**
* -

@ -22,23 +22,17 @@ import cn.hutool.core.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.exception.ServiceException;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.core.utils.UserUtil;
import org.opsli.modulars.generator.template.api.GenTemplateDetailRestApi;
import org.opsli.modulars.generator.template.wrapper.GenTemplateDetailModel;
import org.opsli.plugins.generator.msg.GeneratorMsg;
import org.opsli.plugins.generator.utils.GenTemplateUtil;
import org.opsli.plugins.generator.utils.GeneratorHandleUtil;
import org.springframework.web.multipart.MultipartHttpServletRequest;

@ -18,7 +18,6 @@ package org.opsli.modulars.generator.template.web;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@ -18,10 +18,6 @@ package org.opsli.modulars.generator.template.wrapper;
import java.math.BigDecimal;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -29,11 +25,8 @@ import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* Model

@ -17,10 +17,6 @@
package org.opsli.modulars.generator.template.wrapper;
import java.math.BigDecimal;
import java.util.Date;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -28,11 +24,8 @@ import lombok.EqualsAndHashCode;
import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.validator.Validator;
import org.opsli.common.annotation.validator.ValidatorLenMax;
import org.opsli.common.annotation.validator.ValidatorLenMin;
import org.opsli.common.enums.ValidatorType;
import org.opsli.plugins.excel.annotation.ExcelInfo;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
/**
* Model

@ -23,21 +23,18 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.opsli.api.base.result.ResultVo;
import org.opsli.api.web.system.role.RoleApi;
import org.opsli.api.web.system.tenant.TenantApi;
import org.opsli.api.wrapper.system.tenant.TenantModel;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.common.annotation.EnableLog;
import org.opsli.common.annotation.RequiresPermissionsCus;
import org.opsli.common.enums.DictType;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
import org.opsli.modulars.system.SystemMsg;
import org.opsli.modulars.system.tenant.entity.SysTenant;
import org.opsli.modulars.system.tenant.service.ITenantService;
import org.springframework.web.multipart.MultipartHttpServletRequest;

@ -5,7 +5,8 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.opsli.api.base.result.ResultVo;
import org.opsli.common.annotation.ApiRestController;
import org.opsli.plugins.email.service.IEmailService;
import org.opsli.core.options.EmailConfigFactory;
import org.opsli.plugins.email.EmailPlugin;
import org.opsli.plugins.email.wrapper.EmailModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@ -24,7 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody;
public class EmailRestController {
@Autowired
private IEmailService iEmailService;
private EmailPlugin emailPlugin;
/**
*
@ -35,13 +36,13 @@ public class EmailRestController {
@PostMapping("/testSend")
public ResultVo<?> testSend(@RequestBody EmailModel model) {
try {
iEmailService
.send(model.getTo(), model.getSubject(), model.getContent());
emailPlugin
.send(model.getTo(), model.getSubject(), model.getContent(),
EmailConfigFactory.INSTANCE.getConfig());
return ResultVo.success("邮件发送成功");
}catch (Exception e){
return ResultVo.error("邮件发送失败 - " + e.getMessage());
}
}
}

@ -17,7 +17,6 @@ package opsli.plugins.crypto.model;
import lombok.Data;
import opsli.plugins.crypto.enums.CryptoAsymmetricType;
import org.opsli.common.annotation.OptionDict;
/**
*
@ -29,15 +28,12 @@ import org.opsli.common.annotation.OptionDict;
public class CryptoAsymmetric {
/** 加解密类别 */
@OptionDict("crypto_asymmetric")
private CryptoAsymmetricType cryptoType;
/** 公钥 */
@OptionDict("crypto_asymmetric_public_key")
private String publicKey;
/** 私钥 */
@OptionDict("crypto_asymmetric_private_key")
private String privateKey;
}

@ -17,7 +17,6 @@ package opsli.plugins.crypto.model;
import lombok.Data;
import opsli.plugins.crypto.enums.CryptoSymmetricType;
import org.opsli.common.annotation.OptionDict;
/**
*
@ -29,11 +28,9 @@ import org.opsli.common.annotation.OptionDict;
public class CryptoSymmetric {
/** 加解密类别 */
@OptionDict("crypto_symmetric")
private CryptoSymmetricType cryptoType;
/** 私钥 */
@OptionDict("crypto_symmetric_private_key")
private String privateKey;
}

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opsli-plugins</artifactId>
<groupId>org.opsliframework.boot</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>opsli-plugins-email</artifactId>
<version>${project.parent.version}</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

@ -13,9 +13,11 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.plugins.email.service;
package org.opsli.plugins.email;
import org.opsli.plugins.email.conf.EmailConfig;
import java.util.Collection;
@ -25,7 +27,7 @@ import java.util.Collection;
* @author Parker
* @date 2020-09-19 20:03
*/
public interface IEmailService {
public interface EmailPlugin {
/**
@ -33,18 +35,20 @@ public interface IEmailService {
* @param to
* @param subject
* @param content
* @param emailConfig
* @return String
*/
String send(String to, String subject, String content);
String send(String to, String subject, String content, EmailConfig emailConfig);
/**
*
* @param tos ()
* @param subject
* @param content
* @param emailConfig
* @return String
*/
String send(Collection<String> tos, String subject, String content);
String send(Collection<String> tos, String subject, String content, EmailConfig emailConfig);
/**
*
@ -52,9 +56,10 @@ public interface IEmailService {
* @param subject
* @param content
* @param isHtml Html
* @param emailConfig
* @return String
*/
String send(String to, String subject, String content, boolean isHtml);
String send(String to, String subject, String content, boolean isHtml, EmailConfig emailConfig);
/**
*
@ -62,9 +67,10 @@ public interface IEmailService {
* @param subject
* @param content
* @param isHtml Html
* @param emailConfig
* @return String
*/
String send(Collection<String> tos, String subject, String content, boolean isHtml);
String send(Collection<String> tos, String subject, String content, boolean isHtml, EmailConfig emailConfig);
}

@ -0,0 +1,35 @@
package org.opsli.plugins.email.conf;
import lombok.Data;
import java.io.Serializable;
/**
*
*
* @author Parker
*/
@Data
public class EmailConfig implements Serializable {
private static final long serialVersionUID = 1L;
/** SMTP地址 */
private String smtp;
/** SMTP端口 */
private Integer port;
/** 开启SSL认证 */
private String sslEnable;
/** 邮箱账号 */
private String account;
/** 邮箱密码 */
private String password;
/** 发件人 */
private String addresser;
}

@ -0,0 +1,36 @@
/**
* 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.email.exception;
import org.opsli.common.base.msg.BaseMsg;
import org.opsli.common.exception.ServiceException;
/**
*
*
* @author Parker
* @date 2020-09-16 11:47
*/
public class EmailPluginException extends ServiceException {
public EmailPluginException(Integer code, String errorMessage) {
super(code, errorMessage);
}
public EmailPluginException(BaseMsg msg) {
super(msg);
}
}

@ -0,0 +1,58 @@
/**
* 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.email.msg;
import org.opsli.common.base.msg.BaseMsg;
/**
* -
*
* @author Parker
* @date 2020-09-19 20:03
*/
public enum EmailMsg implements BaseMsg {
/**
*
*/
EXCEPTION_CONFIG_INIT_NULL(90400, "邮件服务初始化异常"),
EXCEPTION_MODEL_TO_NULL(90401, "收件人不可为空"),
EXCEPTION_MODEL_SUBJECT_NULL(90402, "主题不可为空"),
EXCEPTION_MODEL_CONTENT_NULL(90403, "内容不可为空"),
;
private final int code;
private final String message;
EmailMsg(int code, String message){
this.code = code;
this.message = message;
}
@Override
public Integer getCode() {
return this.code;
}
@Override
public String getMessage() {
return this.message;
}
}

@ -0,0 +1,105 @@
package org.opsli.plugins.email.service;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import org.opsli.common.enums.DictType;
import org.opsli.plugins.email.EmailPlugin;
import org.opsli.plugins.email.conf.EmailConfig;
import org.opsli.plugins.email.exception.EmailPluginException;
import org.opsli.plugins.email.msg.EmailMsg;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Collections;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
@Service
public class EmailPluginImpl implements EmailPlugin {
@Override
public String send(String to, String subject, String content, EmailConfig emailConfig) {
// 发送邮件
return this.send(Collections.singletonList(to), subject , content, emailConfig);
}
@Override
public String send(Collection<String> tos, String subject, String content,
EmailConfig emailConfig) {
// 发送邮件
return this.send(tos, subject ,content, false, emailConfig);
}
@Override
public String send(String to, String subject, String content,
boolean isHtml, EmailConfig emailConfig) {
// 发送邮件
return this.send(Collections.singletonList(to), subject ,
content, isHtml, emailConfig);
}
@Override
public String send(Collection<String> tos, String subject, String content,
boolean isHtml, EmailConfig emailConfig) {
// 校验发送邮件数据是否正确
this.verify(tos, subject, content);
// 获得配置信息
MailAccount mailAccount = this.getMailAccount(emailConfig);
// 发送邮件
return MailUtil.send(mailAccount, tos , subject ,content, isHtml);
}
/**
*
* @param tos ()
* @param subject
* @param content
*/
private void verify(Collection<String> tos, String subject, String content){
// 校验发送邮件数据是否正确
for (String to : tos) {
if(StrUtil.isEmpty(to)){
// 收件人不可为空
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_TO_NULL);
}
if(StrUtil.isEmpty(subject)){
// 主题不可为空
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_SUBJECT_NULL);
}
if(StrUtil.isEmpty(content)){
// 内容不可为空
throw new EmailPluginException(EmailMsg.EXCEPTION_MODEL_CONTENT_NULL);
}
}
}
/**
*
* @return MailAccount
*/
private MailAccount getMailAccount(EmailConfig emailConfig){
if(emailConfig == null){
// 邮件服务初始化异常
throw new EmailPluginException(EmailMsg.EXCEPTION_CONFIG_INIT_NULL);
}
MailAccount mailAccount = new MailAccount();
mailAccount.setAuth(true);
mailAccount.setHost(emailConfig.getSmtp());
mailAccount.setPort(emailConfig.getPort());
mailAccount.setSslEnable(
DictType.NO_YES_YES.getValue().equals(emailConfig.getSslEnable()));
mailAccount.setUser(emailConfig.getAccount());
mailAccount.setPass(emailConfig.getPassword());
mailAccount.setFrom(emailConfig.getAddresser());
return mailAccount;
}
}

@ -0,0 +1,25 @@
package org.opsli.plugins.email.wrapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author Parker
* @date 2020-09-19 20:03
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class EmailModel {
/** 收件人 */
private String to;
/** 主题 */
private String subject;
/** 内容 */
private String content;
}

@ -20,7 +20,6 @@ import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import java.lang.reflect.Field;
import java.util.ArrayList;

@ -22,6 +22,7 @@
<module>opsli-plugins-redisson</module>
<module>opsli-plugins-waf</module>
<module>opsli-plugins-crypto</module>
<module>opsli-plugins-email</module>
</modules>
<dependencyManagement>

@ -331,6 +331,69 @@
<!-- ———————————————————— 集成工具 - 结束 ———————————————————— -->
<!-- ———————————————————— OSS云存储 - 开始 ———————————————————— -->
<!-- 又拍云 USS -->
<dependency>
<groupId>com.upyun</groupId>
<artifactId>java-sdk</artifactId>
<version>4.2.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 百度云 BOS -->
<dependency>
<groupId>com.baidubce</groupId>
<artifactId>bce-java-sdk</artifactId>
<version>0.10.162</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 腾讯云 COS -->
<dependency>
<groupId>com.qcloud</groupId>
<artifactId>cos_api</artifactId>
<version>5.6.38</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 七牛云 Kodo -->
<dependency>
<groupId>com.qiniu</groupId>
<artifactId>qiniu-java-sdk</artifactId>
<version>7.4.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 阿里云 OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- 华为云 OBS -->
<dependency>
<groupId>com.huaweicloud</groupId>
<artifactId>esdk-obs-java</artifactId>
<version>3.20.6.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<!-- ———————————————————— OSS云存储 - 结束 ———————————————————— -->
</dependencies>

Loading…
Cancel
Save