Skip to content

Commit

Permalink
🎉 oss服务统一配置
Browse files Browse the repository at this point in the history
  • Loading branch information
smallchill committed May 26, 2019
1 parent 09bf54e commit 12bc2f2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public interface AppConstant {
* 工作流模块名称
*/
String APPLICATION_FLOW_NAME = APPLICATION_NAME_PREFIX + "flow";
/**
* 资源模块名称
*/
String APPLICATION_RESOURCE_NAME = APPLICATION_NAME_PREFIX + "resource";
/**
* 测试模块名称
*/
Expand Down
70 changes: 35 additions & 35 deletions blade-starter-develop/src/main/resources/templates/entity.java.vm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class $!{entity} extends Model<$!{entity}> {
public class $!{entity} implements Serializable {
#end

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;

## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in $!{table.fields})
Expand All @@ -64,42 +64,42 @@ public class $!{entity} implements Serializable {
#set($keyPropertyName=$!{field.propertyName})
#end
#if("$!field.comment" != "")
/**
* $!{field.comment}
*/
/**
* $!{field.comment}
*/
#if($!{swagger2})
@ApiModelProperty(value = "$!{field.comment}")
@ApiModelProperty(value = "$!{field.comment}")
#end
#end
#if($!{field.keyFlag})
## 主键
#if($!{field.keyIdentityFlag})
@TableId(value = "$!{field.name}", type = IdType.AUTO)
@TableId(value = "$!{field.name}", type = IdType.AUTO)
#elseif(!$null.isNull($!{idType}) && "$!idType" != "")
@TableId(value = "$!{field.name}", type = IdType.$!{idType})
@TableId(value = "$!{field.name}", type = IdType.$!{idType})
#elseif($!{field.convert})
@TableId("$!{field.name}")
@TableId("$!{field.name}")
#end
## 普通字段
#elseif($!{field.fill})
## ----- 存在字段填充设置 -----
#if($!{field.convert})
@TableField(value = "$!{field.name}", fill = FieldFill.$!{field.fill})
@TableField(value = "$!{field.name}", fill = FieldFill.$!{field.fill})
#else
@TableField(fill = FieldFill.$!{field.fill})
@TableField(fill = FieldFill.$!{field.fill})
#end
#elseif($!{field.convert})
@TableField("$!{field.name}")
@TableField("$!{field.name}")
#end
## 乐观锁注解
#if($!{versionFieldName}==$!{field.name})
@Version
@Version
#end
## 逻辑删除注解
#if($!{logicDeleteFieldName}==$!{field.name})
@TableLogic
@TableLogic
#end
private $!{field.propertyType} $!{field.propertyName};
private $!{field.propertyType} $!{field.propertyName};
#end
#end
## ---------- END 字段循环遍历 ----------
Expand All @@ -112,52 +112,52 @@ public class $!{entity} implements Serializable {
#set($getprefix="get")
#end

public $!{field.propertyType} $!{getprefix}$!{field.capitalName}() {
return $!{field.propertyName};
}
public $!{field.propertyType} $!{getprefix}$!{field.capitalName}() {
return $!{field.propertyName};
}

#if($!{entityBuilderModel})
public $!{entity} set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
public $!{entity} set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
#else
public void set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
public void set$!{field.capitalName}($!{field.propertyType} $!{field.propertyName}) {
#end
this.$!{field.propertyName} = $!{field.propertyName};
this.$!{field.propertyName} = $!{field.propertyName};
#if($!{entityBuilderModel})
return this;
return this;
#end
}
}
#end
#end

#if($!{entityColumnConstant})
#foreach($field in $!{table.fields})
public static final String $!{field.name.toUpperCase()} = "$!{field.name}";
public static final String $!{field.name.toUpperCase()} = "$!{field.name}";

#end
#end
#if($!{activeRecord})
@Override
protected Serializable pkVal() {
@Override
protected Serializable pkVal() {
#if($!{keyPropertyName})
return this.$!{keyPropertyName};
return this.$!{keyPropertyName};
#else
return this.id;
return this.id;
#end
}
}

#end
#if(!$!{entityLombokModel})
@Override
public String toString() {
return "$!{entity}{" +
@Override
public String toString() {
return "$!{entity}{" +
#foreach($field in $!{table.fields})
#if($!{velocityCount}==1)
"$!{field.propertyName}=" + $!{field.propertyName} +
"$!{field.propertyName}=" + $!{field.propertyName} +
#else
", $!{field.propertyName}=" + $!{field.propertyName} +
", $!{field.propertyName}=" + $!{field.propertyName} +
#end
#end
"}";
}
"}";
}
#end
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.model.OssFile;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -117,7 +118,8 @@ public OssFile statFile(String fileName) {
public OssFile statFile(String bucketName, String fileName) {
ObjectStat stat = client.statObject(getBucketName(bucketName), fileName);
OssFile ossFile = new OssFile();
ossFile.setName(stat.name());
ossFile.setName(Func.isEmpty(stat.name()) ? fileName : stat.name());
ossFile.setLink(fileLink(ossFile.getName()));
ossFile.setHash(String.valueOf(stat.hashCode()));
ossFile.setLength(stat.length());
ossFile.setPutTime(stat.createdTime());
Expand All @@ -126,12 +128,12 @@ public OssFile statFile(String bucketName, String fileName) {
}

@Override
public String getFilePath(String fileName) {
public String filePath(String fileName) {
return getBucketName().concat(StringPool.SLASH).concat(fileName);
}

@Override
public String getFilePath(String bucketName, String fileName) {
public String filePath(String bucketName, String fileName) {
return getBucketName(bucketName).concat(StringPool.SLASH).concat(fileName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BaseEntity implements Serializable {
/**
* 创建人
*/
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(value = "创建人")
private Long createUser;

Expand All @@ -63,6 +64,7 @@ public class BaseEntity implements Serializable {
/**
* 更新人
*/
@JsonSerialize(using = ToStringSerializer.class)
@ApiModelProperty(value = "更新人")
private Long updateUser;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public interface OssTemplate {
* @param fileName 存储桶对象名称
* @return String
*/
String getFilePath(String fileName);
String filePath(String fileName);

/**
* 获取文件相对路径
Expand All @@ -103,7 +103,7 @@ public interface OssTemplate {
* @param fileName 存储桶对象名称
* @return String
*/
String getFilePath(String bucketName, String fileName);
String filePath(String bucketName, String fileName);

/**
* 获取文件地址
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
*/
@Data
public class OssFile {
/**
* 文件地址
*/
private String link;
/**
* 文件名
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.qiniu.props.QiniuProperties;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -117,7 +118,7 @@ public void copyFile(String bucketName, String fileName, String destBucketName,
@Override
@SneakyThrows
public OssFile statFile(String fileName) {
return statFile(getBucketName(), fileName);
return statFile(qiniuProperties.getBucketName(), fileName);
}

@Override
Expand All @@ -126,35 +127,37 @@ public OssFile statFile(String bucketName, String fileName) {
FileInfo stat = bucketManager.stat(getBucketName(bucketName), fileName);
OssFile ossFile = new OssFile();
ossFile.setName(stat.key);
ossFile.setName(Func.isEmpty(stat.key) ? fileName : stat.key);
ossFile.setLink(fileLink(ossFile.getName()));
ossFile.setHash(stat.hash);
ossFile.setLength(stat.fsize);
ossFile.setPutTime(new Date(stat.putTime));
ossFile.setPutTime(new Date(stat.putTime / 10000));
ossFile.setContentType(stat.mimeType);
return ossFile;
}

@Override
@SneakyThrows
public String getFilePath(String fileName) {
public String filePath(String fileName) {
return getBucketName().concat(StringPool.SLASH).concat(fileName);
}

@Override
@SneakyThrows
public String getFilePath(String bucketName, String fileName) {
public String filePath(String bucketName, String fileName) {
return getBucketName(bucketName).concat(StringPool.SLASH).concat(fileName);
}

@Override
@SneakyThrows
public String fileLink(String fileName) {
return qiniuProperties.getEndpoint().concat(StringPool.SLASH).concat(getBucketName()).concat(StringPool.SLASH).concat(fileName);
return qiniuProperties.getEndpoint().concat(StringPool.SLASH).concat(fileName);
}

@Override
@SneakyThrows
public String fileLink(String bucketName, String fileName) {
return qiniuProperties.getEndpoint().concat(StringPool.SLASH).concat(getBucketName(bucketName)).concat(StringPool.SLASH).concat(fileName);
return qiniuProperties.getEndpoint().concat(StringPool.SLASH).concat(fileName);
}

@Override
Expand Down Expand Up @@ -189,15 +192,16 @@ public void putFile(String bucketName, String fileName, InputStream stream) {

@SneakyThrows
public Response put(String bucketName, InputStream stream, String key, boolean cover) {
makeBucket(getBucketName(bucketName));
makeBucket(bucketName);
Response response;
// 覆盖上传
if (cover) {
response = uploadManager.put(stream, key, getUploadToken(bucketName, key), null, null);
} else {
response = uploadManager.put(stream, key, getUploadToken(bucketName), null, null);
int retry = 0;
while (response.needRetry() && retry < qiniuProperties.getRetry()) {
int retryCount = 5;
while (response.needRetry() && retry < retryCount) {
response = uploadManager.put(stream, key, getUploadToken(bucketName), null, null);
retry++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,4 @@ public class QiniuProperties {
*/
private String bucketName = "bladex";

/**
* 重试次数
*/
private Integer retry = 5;

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ public class BladeTenantProperties {
/**
* 多租户系统数据表
*/
private List<String> bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual");
private List<String> bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual", "blade_oss");
}

0 comments on commit 12bc2f2

Please sign in to comment.