From 12bc2f22c78bd336f53382f1b09ae5dd95430c96 Mon Sep 17 00:00:00 2001 From: smallchill Date: Sun, 26 May 2019 21:54:02 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20oss=E6=9C=8D=E5=8A=A1=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/launch/constant/AppConstant.java | 4 ++ .../main/resources/templates/entity.java.vm | 70 +++++++++---------- .../springblade/core/minio/MinioTemplate.java | 8 ++- .../springblade/core/mp/base/BaseEntity.java | 2 + .../org/springblade/core/oss/OssTemplate.java | 4 +- .../springblade/core/oss/model/OssFile.java | 4 ++ .../springblade/core/qiniu/QiniuTemplate.java | 20 +++--- .../core/qiniu/props/QiniuProperties.java | 5 -- .../core/tenant/BladeTenantProperties.java | 2 +- 9 files changed, 65 insertions(+), 54 deletions(-) diff --git a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java index 0b9e718..9112ced 100644 --- a/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java +++ b/blade-core-launch/src/main/java/org/springblade/core/launch/constant/AppConstant.java @@ -77,6 +77,10 @@ public interface AppConstant { * 工作流模块名称 */ String APPLICATION_FLOW_NAME = APPLICATION_NAME_PREFIX + "flow"; + /** + * 资源模块名称 + */ + String APPLICATION_RESOURCE_NAME = APPLICATION_NAME_PREFIX + "resource"; /** * 测试模块名称 */ diff --git a/blade-starter-develop/src/main/resources/templates/entity.java.vm b/blade-starter-develop/src/main/resources/templates/entity.java.vm index 673906b..f70a51e 100644 --- a/blade-starter-develop/src/main/resources/templates/entity.java.vm +++ b/blade-starter-develop/src/main/resources/templates/entity.java.vm @@ -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}) @@ -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 字段循环遍历 ---------- @@ -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 } diff --git a/blade-starter-minio/src/main/java/org/springblade/core/minio/MinioTemplate.java b/blade-starter-minio/src/main/java/org/springblade/core/minio/MinioTemplate.java index 4572590..5f7e169 100644 --- a/blade-starter-minio/src/main/java/org/springblade/core/minio/MinioTemplate.java +++ b/blade-starter-minio/src/main/java/org/springblade/core/minio/MinioTemplate.java @@ -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; @@ -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()); @@ -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); } diff --git a/blade-starter-mybatis/src/main/java/org/springblade/core/mp/base/BaseEntity.java b/blade-starter-mybatis/src/main/java/org/springblade/core/mp/base/BaseEntity.java index 2be9387..beaa8e0 100644 --- a/blade-starter-mybatis/src/main/java/org/springblade/core/mp/base/BaseEntity.java +++ b/blade-starter-mybatis/src/main/java/org/springblade/core/mp/base/BaseEntity.java @@ -49,6 +49,7 @@ public class BaseEntity implements Serializable { /** * 创建人 */ + @JsonSerialize(using = ToStringSerializer.class) @ApiModelProperty(value = "创建人") private Long createUser; @@ -63,6 +64,7 @@ public class BaseEntity implements Serializable { /** * 更新人 */ + @JsonSerialize(using = ToStringSerializer.class) @ApiModelProperty(value = "更新人") private Long updateUser; diff --git a/blade-starter-oss/src/main/java/org/springblade/core/oss/OssTemplate.java b/blade-starter-oss/src/main/java/org/springblade/core/oss/OssTemplate.java index 1fc2074..4853b48 100644 --- a/blade-starter-oss/src/main/java/org/springblade/core/oss/OssTemplate.java +++ b/blade-starter-oss/src/main/java/org/springblade/core/oss/OssTemplate.java @@ -94,7 +94,7 @@ public interface OssTemplate { * @param fileName 存储桶对象名称 * @return String */ - String getFilePath(String fileName); + String filePath(String fileName); /** * 获取文件相对路径 @@ -103,7 +103,7 @@ public interface OssTemplate { * @param fileName 存储桶对象名称 * @return String */ - String getFilePath(String bucketName, String fileName); + String filePath(String bucketName, String fileName); /** * 获取文件地址 diff --git a/blade-starter-oss/src/main/java/org/springblade/core/oss/model/OssFile.java b/blade-starter-oss/src/main/java/org/springblade/core/oss/model/OssFile.java index 869df0a..1684fdd 100644 --- a/blade-starter-oss/src/main/java/org/springblade/core/oss/model/OssFile.java +++ b/blade-starter-oss/src/main/java/org/springblade/core/oss/model/OssFile.java @@ -27,6 +27,10 @@ */ @Data public class OssFile { + /** + * 文件地址 + */ + private String link; /** * 文件名 */ diff --git a/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/QiniuTemplate.java b/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/QiniuTemplate.java index ff546ad..4833708 100644 --- a/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/QiniuTemplate.java +++ b/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/QiniuTemplate.java @@ -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; @@ -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 @@ -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 @@ -189,7 +192,7 @@ 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) { @@ -197,7 +200,8 @@ public Response put(String bucketName, InputStream stream, String key, boolean c } 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++; } diff --git a/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/props/QiniuProperties.java b/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/props/QiniuProperties.java index 2b4a70f..9d07267 100644 --- a/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/props/QiniuProperties.java +++ b/blade-starter-qiniu/src/main/java/org/springblade/core/qiniu/props/QiniuProperties.java @@ -58,9 +58,4 @@ public class QiniuProperties { */ private String bucketName = "bladex"; - /** - * 重试次数 - */ - private Integer retry = 5; - } diff --git a/blade-starter-tenant/src/main/java/org/springblade/core/tenant/BladeTenantProperties.java b/blade-starter-tenant/src/main/java/org/springblade/core/tenant/BladeTenantProperties.java index a971140..aa027a4 100644 --- a/blade-starter-tenant/src/main/java/org/springblade/core/tenant/BladeTenantProperties.java +++ b/blade-starter-tenant/src/main/java/org/springblade/core/tenant/BladeTenantProperties.java @@ -47,5 +47,5 @@ public class BladeTenantProperties { /** * 多租户系统数据表 */ - private List bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual"); + private List bladeTables = Arrays.asList("blade_notice", "blade_log_api", "blade_log_error", "blade_log_usual", "blade_oss"); }