From aefb8d0c12604627ef34b2a7e39dd1cf89b07a7b Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Fri, 26 Dec 2025 23:13:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=94=B9=E8=BF=9B=E3=80=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/corewing/app/common/Result.java | 5 +++ .../corewing/app/common/base/BaseEntity.java | 4 +-- .../app/config/Knife4jConfiguration.java | 35 +++++++++++++++++++ .../com/corewing/app/entity/AppModel.java | 16 +++++++++ .../corewing/app/entity/AppModelCategory.java | 7 ++++ .../app/entity/AppModelDownloadLog.java | 7 ++++ .../corewing/app/entity/AppModelFavorite.java | 1 - .../com/corewing/app/entity/AppModelFile.java | 10 +++++- .../app/service/impl/AppModelServiceImpl.java | 12 +++++-- src/main/resources/application.properties | 28 --------------- 10 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 src/main/java/com/corewing/app/config/Knife4jConfiguration.java diff --git a/src/main/java/com/corewing/app/common/Result.java b/src/main/java/com/corewing/app/common/Result.java index 50f2025..eee4a4d 100644 --- a/src/main/java/com/corewing/app/common/Result.java +++ b/src/main/java/com/corewing/app/common/Result.java @@ -1,6 +1,7 @@ package com.corewing.app.common; import com.corewing.app.util.I18nUtil; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; @@ -16,21 +17,25 @@ public class Result implements Serializable { /** * 状态码 */ + @ApiModelProperty("状态码") private Integer code; /** * 返回消息 */ + @ApiModelProperty("消息内容") private String message; /** * 返回数据 */ + @ApiModelProperty("数据") private T data; /** * 成功标识 */ + @ApiModelProperty("是否成功") private Boolean success; public Result(Integer code, String message, T data, Boolean success) { diff --git a/src/main/java/com/corewing/app/common/base/BaseEntity.java b/src/main/java/com/corewing/app/common/base/BaseEntity.java index 0757964..8a3a3d7 100644 --- a/src/main/java/com/corewing/app/common/base/BaseEntity.java +++ b/src/main/java/com/corewing/app/common/base/BaseEntity.java @@ -14,7 +14,7 @@ public class BaseEntity { * 创建时间 */ @TableField(fill = FieldFill.INSERT) - private LocalDateTime createTime; + private Date createTime; /** * 创建人 */ @@ -23,7 +23,7 @@ public class BaseEntity { * 修改时间 */ @TableField(fill = FieldFill.UPDATE) - private LocalDateTime updateTime; + private Date updateTime; /** * 修改人 */ diff --git a/src/main/java/com/corewing/app/config/Knife4jConfiguration.java b/src/main/java/com/corewing/app/config/Knife4jConfiguration.java new file mode 100644 index 0000000..612b071 --- /dev/null +++ b/src/main/java/com/corewing/app/config/Knife4jConfiguration.java @@ -0,0 +1,35 @@ +package com.corewing.app.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +@Configuration +@EnableSwagger2WebMvc +public class Knife4jConfiguration { + + @Bean(value = "defaultApi") + public Docket defaultApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(new ApiInfoBuilder() + .title("CoreWing APP APIs") + .description("CoreWing APP APIs") + .contact(new Contact("CoreWing", "www.corewing.com", "main@corewing.com")) + .version("1.0") + .build()) + //分组名称 + .groupName("1.1.0版本") + .select() + //这里指定Controller扫描包路径 + .apis(RequestHandlerSelectors.basePackage("com.corewing.app.modules.app")) + .paths(PathSelectors.any()) + .build(); + } + +} diff --git a/src/main/java/com/corewing/app/entity/AppModel.java b/src/main/java/com/corewing/app/entity/AppModel.java index 3181a1b..ff3fa0f 100644 --- a/src/main/java/com/corewing/app/entity/AppModel.java +++ b/src/main/java/com/corewing/app/entity/AppModel.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.corewing.app.common.base.CommonEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -16,38 +17,53 @@ import java.util.List; public class AppModel extends CommonEntity { @TableId + @ApiModelProperty("模型id") private String id; + @ApiModelProperty("用户id") private Long userId; + @ApiModelProperty("模型标题") private String title; + @ApiModelProperty("模型描述") private String description; + @ApiModelProperty("分类id") private String categoryId; + @ApiModelProperty("模型封面(base64)") private String coverImage; + @ApiModelProperty("是否公开:(1公开,0私有)") private String isPublic; + @ApiModelProperty("状态:(1正常,0下架,2审核中)") private String status; + @ApiModelProperty("下载次数") private int downloadCount; + @ApiModelProperty("点赞次数") private int likeCount; + @ApiModelProperty("收藏次数") private int favoriteCount; + @ApiModelProperty("备注") private String remark; + @ApiModelProperty("扩展参数") private String extJson; + @ApiModelProperty("暂未使用【点击详情接口获取文件模型】") @TableField(exist = false) private List modelFile; /** * 分类名称 */ + @ApiModelProperty("分类名称") @TableField(exist = false) private String categoryTitle; diff --git a/src/main/java/com/corewing/app/entity/AppModelCategory.java b/src/main/java/com/corewing/app/entity/AppModelCategory.java index 380e414..17f8fb6 100644 --- a/src/main/java/com/corewing/app/entity/AppModelCategory.java +++ b/src/main/java/com/corewing/app/entity/AppModelCategory.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.corewing.app.common.base.CommonEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,16 +14,22 @@ import lombok.EqualsAndHashCode; public class AppModelCategory extends CommonEntity { @TableId + @ApiModelProperty("分类id") private String id; + @ApiModelProperty("分类名称") private String name; + @ApiModelProperty("父级id") private String parentId; + @ApiModelProperty("排序码") private int sortCode; + @ApiModelProperty("备注") private String remark; + @ApiModelProperty("扩展参数") private String extJson; } diff --git a/src/main/java/com/corewing/app/entity/AppModelDownloadLog.java b/src/main/java/com/corewing/app/entity/AppModelDownloadLog.java index 480e203..6075f12 100644 --- a/src/main/java/com/corewing/app/entity/AppModelDownloadLog.java +++ b/src/main/java/com/corewing/app/entity/AppModelDownloadLog.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.corewing.app.common.base.CommonEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -13,16 +14,22 @@ import lombok.EqualsAndHashCode; public class AppModelDownloadLog extends CommonEntity { @TableId + @ApiModelProperty("id") private String id; + @ApiModelProperty("用户id") private Long userId; + @ApiModelProperty("模型id") private String modelId; + @ApiModelProperty("下载ip") private String ipAddress; + @ApiModelProperty("下载备注") private String remark; + @ApiModelProperty("扩展参数") private String extJson; diff --git a/src/main/java/com/corewing/app/entity/AppModelFavorite.java b/src/main/java/com/corewing/app/entity/AppModelFavorite.java index b537828..82587b9 100644 --- a/src/main/java/com/corewing/app/entity/AppModelFavorite.java +++ b/src/main/java/com/corewing/app/entity/AppModelFavorite.java @@ -1,6 +1,5 @@ package com.corewing.app.entity; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.corewing.app.common.base.CommonEntity; diff --git a/src/main/java/com/corewing/app/entity/AppModelFile.java b/src/main/java/com/corewing/app/entity/AppModelFile.java index 076f1fd..cd1710d 100644 --- a/src/main/java/com/corewing/app/entity/AppModelFile.java +++ b/src/main/java/com/corewing/app/entity/AppModelFile.java @@ -3,6 +3,7 @@ package com.corewing.app.entity; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.corewing.app.common.base.CommonEntity; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -12,19 +13,26 @@ import lombok.EqualsAndHashCode; public class AppModelFile extends CommonEntity { @TableId + @ApiModelProperty("id") private String id; + @ApiModelProperty("模型id") private String modelId; + @ApiModelProperty("文件名称") private String fileName; + @ApiModelProperty("文件类型") private String fileType; + @ApiModelProperty("文件大小") private Long fileSize; + @ApiModelProperty("文件地址") private String fileUrl; - private String sortCode; + @ApiModelProperty("文件排序") + private int sortCode; } diff --git a/src/main/java/com/corewing/app/service/impl/AppModelServiceImpl.java b/src/main/java/com/corewing/app/service/impl/AppModelServiceImpl.java index 67fed4c..cf47df9 100644 --- a/src/main/java/com/corewing/app/service/impl/AppModelServiceImpl.java +++ b/src/main/java/com/corewing/app/service/impl/AppModelServiceImpl.java @@ -22,10 +22,12 @@ import com.corewing.app.util.OSSUploadUtil; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; import java.util.List; +import java.util.stream.IntStream; @Service public class AppModelServiceImpl extends ServiceImpl implements AppModelService { @@ -146,10 +148,13 @@ public class AppModelServiceImpl extends ServiceImpl i appModel.setStatus("1"); appModel.setUserId(Long.valueOf(StpUtil.getLoginId().toString())); this.save(appModel); - + // 获取文件列表 + List files = modelCreateRequest.getFiles(); // 上传文件 - modelCreateRequest.getFiles().forEach(item -> { + IntStream.range(0, files.size()).forEach(index -> { + MultipartFile item = files.get(index); // 通过索引获取文件 try { + // 这里可以直接使用 index 作为下标(从0开始) String downloadUrl = OSSUploadUtil.uploadFile(item.getInputStream(), "customModel/" + item.getOriginalFilename()); AppModelFile modelFile = new AppModelFile(); modelFile.setFileName(item.getOriginalFilename()); @@ -157,10 +162,11 @@ public class AppModelServiceImpl extends ServiceImpl i modelFile.setFileSize(item.getSize()); modelFile.setFileType(item.getContentType()); modelFile.setModelId(appModel.getId()); + modelFile.setSortCode(index); modelFileService.save(modelFile); } catch (IOException e) { - throw new RuntimeException("创建模型失败"); + throw new RuntimeException("创建模型失败,文件下标:" + index + ",文件名:" + item.getOriginalFilename()); } }); return true; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3a1fc1e..40a850b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -112,31 +112,3 @@ knife4j.setting.language=zh_cn knife4j.basic.enable=true knife4j.basic.username=corewing knife4j.basic.password=Aaa123.. -# ===================== Knife4j OpenAPI 全局文档配置 ===================== -# 文档标题 -knife4j.openapi.title=CoreWing APP API -# 文档描述(支持Markdown,换行用\n,特殊符号保留) - -knife4j.openapi.description= -# 作者邮箱 -knife4j.openapi.email= -# 联系人 -knife4j.openapi.concat= -# 文档官网地址 -knife4j.openapi.url= -# 文档版本 -knife4j.openapi.version=v1.0 -# 许可证 -knife4j.openapi.license= - - - -# ===================== Knife4j 分组配置 ===================== -# 分组名称 -knife4j.openapi.group.test1.group-name=APP接口 -# 接口扫描规则:package(按包扫描)、path(按路径匹配)、api(按注解匹配) -knife4j.openapi.group.test1.api-rule=package -# 按包扫描的资源(数组,用[索引]标识多个包) -knife4j.openapi.group.test1.api-rule-resources[0]=com.corewing.app.modules.app -# 若有多个包,继续添加索引 -# knife4j.openapi.group.test1.api-rule-resources[1]=com.knife4j.demo.new4