diff --git a/bnyer-api/bnyer-api-file/pom.xml b/bnyer-api/bnyer-api-file/pom.xml new file mode 100644 index 0000000..3517d20 --- /dev/null +++ b/bnyer-api/bnyer-api-file/pom.xml @@ -0,0 +1,26 @@ + + + + bnyer-api + com.dimensionalnode + 1.0.0 + + 4.0.0 + + bnyer-api-file + + + bnyer-api-file文件服务接口模块 + + + + + + com.dimensionalnode + bnyer-common-core + + + + \ No newline at end of file diff --git a/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/RemoteFileService.java b/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/RemoteFileService.java new file mode 100644 index 0000000..782a2b7 --- /dev/null +++ b/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/RemoteFileService.java @@ -0,0 +1,40 @@ +package com.bnyer.file.api; + +import com.bnyer.common.core.constant.ServiceNameConstants; +import com.bnyer.common.core.domain.R; +import com.bnyer.file.api.factory.RemoteFileFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * 文件服务 + * + * @author penny + * @date 2023/04/15 11:03 + */ +@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class) +public interface RemoteFileService { + + + /** + * 上传文件到minio + * @param file 文件 + * @return - + */ + @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + R uploadBanner(@RequestPart(name = "file") MultipartFile file); + + /** + * 批量上传文件到七牛云 + * @param files 文件 + * @return - + */ + @PostMapping("/uploadBatch") + R> uploadBatch(MultipartFile[] files); + +} diff --git a/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/factory/RemoteFileFallbackFactory.java b/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/factory/RemoteFileFallbackFactory.java new file mode 100644 index 0000000..4ac58a7 --- /dev/null +++ b/bnyer-api/bnyer-api-file/src/main/java/com/bnyer/file/api/factory/RemoteFileFallbackFactory.java @@ -0,0 +1,40 @@ +package com.bnyer.file.api.factory; + +import com.bnyer.common.core.domain.R; +import com.bnyer.file.api.RemoteFileService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +/** + * 文件服务降级处理 + * + * @author penny + */ +@Component +public class RemoteFileFallbackFactory implements FallbackFactory +{ + private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class); + + + @Override + public RemoteFileService create(Throwable throwable) { + log.error("api文件服务调用失败:{}", throwable.getMessage()); + return new RemoteFileService() + { + @Override + public R uploadBanner(MultipartFile file) { + return R.fail("远程调用minio文件上传失败:" + throwable.getMessage()); + } + + @Override + public R> uploadBatch(MultipartFile[] files) { + return R.fail("远程调用七牛云批量文件上传失败:" + throwable.getMessage()); + } + }; + } +} diff --git a/bnyer-api/bnyer-api-file/src/main/resources/META-INF/spring.factories b/bnyer-api/bnyer-api-file/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..30b9bc6 --- /dev/null +++ b/bnyer-api/bnyer-api-file/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration = com.bnyer.file.api.factory.RemoteFileFallbackFactory + diff --git a/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteFileService.java b/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteSystemFileService.java similarity index 80% rename from bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteFileService.java rename to bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteSystemFileService.java index 6f72f20..f98c707 100644 --- a/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteFileService.java +++ b/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/RemoteSystemFileService.java @@ -12,11 +12,11 @@ import com.bnyer.system.api.domain.SysFile; /** * 文件服务 - * + * * @author ruoyi */ -@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class) -public interface RemoteFileService +@FeignClient(contextId = "remoteSystemFileService", value = ServiceNameConstants.SYSTEM_FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class) +public interface RemoteSystemFileService { /** * 上传文件 diff --git a/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/factory/RemoteFileFallbackFactory.java b/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/factory/RemoteFileFallbackFactory.java index 5c5ec5d..a270e60 100644 --- a/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/factory/RemoteFileFallbackFactory.java +++ b/bnyer-api/bnyer-api-system/src/main/java/com/bnyer/system/api/factory/RemoteFileFallbackFactory.java @@ -6,24 +6,24 @@ import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import com.bnyer.common.core.domain.R; -import com.bnyer.system.api.RemoteFileService; +import com.bnyer.system.api.RemoteSystemFileService; import com.bnyer.system.api.domain.SysFile; /** * 文件服务降级处理 - * + * * @author ruoyi */ @Component -public class RemoteFileFallbackFactory implements FallbackFactory +public class RemoteFileFallbackFactory implements FallbackFactory { private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class); @Override - public RemoteFileService create(Throwable throwable) + public RemoteSystemFileService create(Throwable throwable) { log.error("文件服务调用失败:{}", throwable.getMessage()); - return new RemoteFileService() + return new RemoteSystemFileService() { @Override public R upload(MultipartFile file) diff --git a/bnyer-api/pom.xml b/bnyer-api/pom.xml index 78c3b28..69e5e4d 100644 --- a/bnyer-api/pom.xml +++ b/bnyer-api/pom.xml @@ -11,6 +11,7 @@ bnyer-api-system bnyer-api-img + bnyer-api-file bnyer-api diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/ServiceNameConstants.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/ServiceNameConstants.java index dd160bb..edf8047 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/ServiceNameConstants.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/ServiceNameConstants.java @@ -18,12 +18,17 @@ public class ServiceNameConstants public static final String SYSTEM_SERVICE = "bnyer-system"; /** - * 文件服务的serviceid + * 系统文件服务的serviceid */ - public static final String FILE_SERVICE = "bnyer-file"; + public static final String SYSTEM_FILE_SERVICE = "bnyer-system-file"; /** * 图文服务的serviceid */ public static final String IMG_SERVICE = "bnyer-img"; + + /** + * 文件服务的serviceid + */ + public static final String FILE_SERVICE = "bnyer-file"; } diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/AiPaint.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/AiPaint.java new file mode 100644 index 0000000..57726d9 --- /dev/null +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/AiPaint.java @@ -0,0 +1,122 @@ +package com.bnyer.common.core.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; +import java.util.Date; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +/** + * ai绘画内容表 + */ +@ApiModel(value="com-bnyer-common-core-domain-AiPaint") +@Getter +@Setter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "img_ai_paint") +public class AiPaint implements Serializable { + /** + * 主键Id + */ + @TableId(value = "id", type = IdType.AUTO) + @ApiModelProperty(value="主键Id") + private Long id; + + /** + * 作品编号 + */ + @TableField(value = "paint_id") + @ApiModelProperty(value="作品编号") + private String paintId; + + /** + * 绘图者id + */ + @TableField(value = "painter_id") + @ApiModelProperty(value="绘图者id") + private Long painterId; + + /** + * 绘图者昵称 + */ + @TableField(value = "painter_name") + @ApiModelProperty(value="绘图者昵称") + private String painterName; + + /** + * 图片 + */ + @TableField(value = "img_url") + @ApiModelProperty(value="图片") + private String imgUrl; + + /** + * 关键词 + */ + @TableField(value = "prompt") + @ApiModelProperty(value="关键词") + private String prompt; + + /** + * 模型名称 + */ + @TableField(value = "model") + @ApiModelProperty(value="模型风格名称") + private String model; + + /** + * 风格名称 + */ + @TableField(value = "style_name") + @ApiModelProperty(value="风格名称") + private String styleName; + + /** + * 图片高度 + */ + @TableField(value = "height") + @ApiModelProperty(value="图片高度") + private String height; + + /** + * 图片宽度 + */ + @TableField(value = "width") + @ApiModelProperty(value="图片宽度") + private String width; + + /** + * 是否显示 (0->隐藏;1->显示) + */ + @TableField(value = "is_show") + @ApiModelProperty(value="是否显示 (0->隐藏;1->显示)") + private String isShow; + + /** + * 平台(0->Hub;1->抖音;2->快手;3->微信) + */ + @TableField(value = "`source`") + @ApiModelProperty(value="平台(0->Hub;1->抖音;2->快手;3->微信)") + private String source; + + /** + * 创建时间 + */ + @TableField(value = "create_time") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value="创建时间") + private Date createTime; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/AiPaintPageDto.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/AiPaintPageDto.java new file mode 100644 index 0000000..e341256 --- /dev/null +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/AiPaintPageDto.java @@ -0,0 +1,23 @@ +package com.bnyer.common.core.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@Getter +@Setter +@ApiModel("ai绘画前端分页接收类") +public class AiPaintPageDto extends BasePageDto { + + @NotEmpty(message = "平台渠道不能为空!") + @ApiModelProperty(value="平台渠道") + private String source; + + @NotNull(message = "绘图者id不能为空!") + @ApiModelProperty(value="绘图者id") + private Long painterId; +} diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/TextToImgDto.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/TextToImgDto.java index dd825b1..1a98f7a 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/TextToImgDto.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/TextToImgDto.java @@ -5,8 +5,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.Serializable; @@ -27,6 +25,16 @@ public class TextToImgDto implements Serializable { @ApiModelProperty(value="提示词") private String prompt; - @ApiModelProperty(value="风格") - private String samplerIndex; + @ApiModelProperty(value="模型") + private String modelName; + + @ApiModelProperty(value="风格名称") + private String styleName; + + @ApiModelProperty(value="绘图者id") + private Long painterId; + + @ApiModelProperty(value="绘图者昵称") + private String painterName; + } diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/Base64ToMultipartFileUtils.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/Base64ToMultipartFileUtils.java new file mode 100644 index 0000000..4e45867 --- /dev/null +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/Base64ToMultipartFileUtils.java @@ -0,0 +1,84 @@ +package com.bnyer.common.core.utils.file; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +/** + * @author + * @date 2023/04/16 16:40 + * @description 转换base64为文件流 + */ +public class Base64ToMultipartFileUtils implements MultipartFile { + + private final byte[] fileContent; + + private final String name; + private final String extension; + private final String contentType; + + private final String originalFilename; + + /** + * @param base64 + * @param dataUri 格式类似于: data:image/png;base64 + */ + public Base64ToMultipartFileUtils(String base64, String dataUri, String name, String originalfilename) { + this.fileContent = Base64.getDecoder().decode(base64.getBytes(StandardCharsets.UTF_8)); + this.extension = dataUri.split(";")[0].split("/")[1]; + this.contentType = dataUri.split(";")[0].split(":")[1]; + this.originalFilename = originalfilename; + this.name = name; + } + + /** + * 【重要】必须与请求接收方参数名称一致,否则找不到参数 + * @return + */ + @Override + public String getName() { + return this.name; + } + + @Override + public String getOriginalFilename() { + return originalFilename; + } + + @Override + public String getContentType() { + return contentType; + } + + @Override + public boolean isEmpty() { + return fileContent == null || fileContent.length == 0; + } + + @Override + public long getSize() { + return fileContent.length; + } + + @Override + public byte[] getBytes() throws IOException { + return fileContent; + } + + @Override + public ByteArrayInputStream getInputStream() throws IOException { + return new ByteArrayInputStream(fileContent); + } + + @Override + public void transferTo(File file) throws IOException, IllegalStateException { + try (FileOutputStream fos = new FileOutputStream(file)) { + fos.write(fileContent); + } + } + +} \ No newline at end of file diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/ImageUtils.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/ImageUtils.java index 95a64a3..3e00ca7 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/ImageUtils.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/utils/file/ImageUtils.java @@ -1,6 +1,7 @@ package com.bnyer.common.core.utils.file; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; @@ -8,6 +9,8 @@ import java.util.Arrays; import org.apache.poi.util.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; +import sun.misc.BASE64Decoder; /** * 图片处理工具类 diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/vo/TextToImgVo.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/vo/TextToImgVo.java index 04c408e..1469e43 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/vo/TextToImgVo.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/vo/TextToImgVo.java @@ -1,11 +1,13 @@ package com.bnyer.common.core.vo; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; import java.io.Serializable; +import java.util.Date; import java.util.List; @@ -17,5 +19,12 @@ public class TextToImgVo implements Serializable { @ApiModelProperty(value="图片base64集合") private List images; + @ApiModelProperty(value="创作时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date paintTime; + + @ApiModelProperty(value="作品id") + private String paintId; + private static final long serialVersionUID = 1L; } diff --git a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java index 8715f17..9fc7636 100644 --- a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java +++ b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/controller/SysFileController.java @@ -107,7 +107,7 @@ public class SysFileController { @ApiOperation(value="批量上传到minio") @PostMapping("/upload") @ResponseBody - public R uploadBanner(@RequestParam("file") MultipartFile file) { + public R uploadBanner(@RequestParam("file") MultipartFile file) { String url = null; try { url = minioService.uploadBanner(file); diff --git a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/MinioSysFileServiceImpl.java similarity index 97% rename from bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java rename to bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/MinioSysFileServiceImpl.java index 532ca94..c8e0d8b 100644 --- a/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/MinioSysFileServiceImpl.java +++ b/bnyer-services/bnyer-file/src/main/java/com/bnyer/file/service/impl/MinioSysFileServiceImpl.java @@ -1,7 +1,8 @@ -package com.bnyer.file.service; +package com.bnyer.file.service.impl; import com.bnyer.common.core.exception.ServiceException; import com.bnyer.file.config.MinioConfig; +import com.bnyer.file.service.MinioService; import com.bnyer.file.utils.FileUploadUtils; import com.bnyer.file.utils.ImgUtil; import io.minio.MinioClient; diff --git a/bnyer-services/bnyer-img/pom.xml b/bnyer-services/bnyer-img/pom.xml index 2902bc4..63cd400 100644 --- a/bnyer-services/bnyer-img/pom.xml +++ b/bnyer-services/bnyer-img/pom.xml @@ -83,6 +83,13 @@ bnyer-common-swagger + + + com.dimensionalnode + bnyer-api-file + 1.0.0 + + com.baomidou diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java index 95f0b4e..463399c 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java @@ -89,6 +89,9 @@ public class TiktokMiniController extends BaseController { @Autowired private StableDiffusionService stableDiffusionService; + @Autowired + private AiPaintService aiPaintService; + @ApiOperation(value="查询banner列表") @GetMapping(value = "/listBanner") public AjaxResult listBanner(){ @@ -423,4 +426,12 @@ public class TiktokMiniController extends BaseController { public AjaxResult textToImg(@Validated @RequestBody @ApiParam("文生图对象") TextToImgDto param){ return AjaxResult.success(stableDiffusionService.textToImg(param)); } + + @ApiOperation(value="获取绘画者ai绘画分页") + @PostMapping(value = "/getAiPaintPage") + public TableDataInfo getAiPaintPage(@Validated @RequestBody @ApiParam("ai绘画对象") AiPaintPageDto dto){ + PageHelper.startPage(dto.getPageNum(), dto.getPageSize()); + List aiPaintList = aiPaintService.queryPage(dto); + return getDataTable(aiPaintList); + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/mapper/AiPaintMapper.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/mapper/AiPaintMapper.java new file mode 100644 index 0000000..3489e22 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/mapper/AiPaintMapper.java @@ -0,0 +1,29 @@ +package com.bnyer.img.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.bnyer.common.core.domain.AiPaint; +import com.bnyer.common.core.dto.AiPaintPageDto; +import com.bnyer.img.vo.AiPaintVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface AiPaintMapper extends BaseMapper { + + /** + * 获取ai绘画分页 + * @param source 来源 + * @param painterId 绘画者id + * @return - + */ + List queryPage(@Param("source") String source,@Param("painterId") Long painterId); + + /** + * 获取ai绘画详情 + * @param id 主键id + * @return - + */ + AiPaintVo queryDetails(Long id); +} \ No newline at end of file diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/AiPaintService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/AiPaintService.java new file mode 100644 index 0000000..875e2ed --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/AiPaintService.java @@ -0,0 +1,40 @@ +package com.bnyer.img.service; + +import com.bnyer.common.core.domain.AiPaint; +import com.bnyer.common.core.dto.AiPaintPageDto; +import com.bnyer.img.vo.AiPaintVo; + +import java.util.List; + +public interface AiPaintService { + + /** + * 新增ai绘画 + * @param aiPaint ai绘画 + * @return - + */ + int insert(AiPaint aiPaint); + + /** + * 批量删除ai绘画 + * @param ids id数组 + * @return - + */ + int delete(List ids); + + /** + * 获取绘画者ai绘画分页 + * @param params 分页参数 + * @return - + */ + List queryPage(AiPaintPageDto params); + + /** + * 获取ai绘画详情 + * @param id 主键id + * @return - + */ + AiPaintVo queryDetails(Long id); + + +} diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/AiPaintServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/AiPaintServiceImpl.java new file mode 100644 index 0000000..22c0a59 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/AiPaintServiceImpl.java @@ -0,0 +1,44 @@ +package com.bnyer.img.service.impl; + +import cn.hutool.core.util.IdUtil; +import com.bnyer.common.core.domain.AiPaint; +import com.bnyer.common.core.dto.AiPaintPageDto; +import com.bnyer.common.core.utils.uuid.IdUtils; +import com.bnyer.img.mapper.AiPaintMapper; +import com.bnyer.img.service.AiPaintService; +import com.bnyer.img.vo.AiPaintVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; + +@Service +public class AiPaintServiceImpl implements AiPaintService { + + @Autowired + private AiPaintMapper aiPaintMapper; + + @Override + @Transactional(rollbackFor = Exception.class) + public int insert(AiPaint aiPaint) { + return aiPaintMapper.insert(aiPaint); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int delete(List ids) { + return aiPaintMapper.deleteBatchIds(ids); + } + + @Override + public List queryPage(AiPaintPageDto params) { + return aiPaintMapper.queryPage(params.getSource(),params.getPainterId()); + } + + @Override + public AiPaintVo queryDetails(Long id) { + return aiPaintMapper.queryDetails(id); + } +} diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java index 6b588b8..3edf36a 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java @@ -1,15 +1,25 @@ package com.bnyer.img.service.impl; +import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.bnyer.common.core.domain.AiPaint; +import com.bnyer.common.core.domain.R; import com.bnyer.common.core.dto.TextToImgDto; +import com.bnyer.common.core.utils.file.Base64ToMultipartFileUtils; +import com.bnyer.common.core.utils.file.ImageUtils; import com.bnyer.common.core.vo.TextToImgVo; +import com.bnyer.file.api.RemoteFileService; +import com.bnyer.img.service.AiPaintService; import com.bnyer.img.service.StableDiffusionService; +import com.bnyer.system.api.RemoteSystemFileService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,11 +31,18 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { @Autowired private RestTemplate restTemplate; + @Autowired + private AiPaintService aiPaintService; + + @Autowired + private RemoteFileService remoteFileService; + @Override public TextToImgVo textToImg(TextToImgDto param) { + //TODO 根据选择的风格来选择模型 Map map = new HashMap<>(); - map.put("width",param.getWidth()); - map.put("height",param.getHeight()); + map.put("width",param.getWidth() == null ? 512 : param.getWidth()); + map.put("height",param.getHeight() == null ? 512 : param.getHeight()); map.put("prompt", param.getPrompt()); map.put("seed",-1); map.put("batch_size",1); @@ -33,15 +50,45 @@ public class StableDiffusionServiceImpl implements StableDiffusionService { map.put("restore_faces",false); map.put("tiling",false); map.put("eta",0); - map.put("sampler_index","Euler"); + map.put("sampler_index","DPM++ 2S a Karras"); //map.put("sampler_index",param.getSamplerIndex()); map.put("steps",20); map.put("negative_prompt","nsfw"); + log.info("请求stable_diffusion请求体为:【{}】", JSON.toJSONString(map)); JSONObject jsonObject = restTemplate.postForObject("http://localhost:7860/sdapi/v1/txt2img", map, JSONObject.class); log.info("请求stable_diffusion响应体的为:【{}】", JSON.toJSONString(jsonObject)); TextToImgVo img = new TextToImgVo(); if(jsonObject != null && jsonObject.getJSONArray("images").size() > 0){ - img.setImages(jsonObject.getJSONArray("images").toJavaList(String.class)); + List images = jsonObject.getJSONArray("images").toJavaList(String.class); + img.setImages(images); + String paintId = null; + Date paintTime = null; + for (String image : images) { + //base64转file + MultipartFile file = new Base64ToMultipartFileUtils(image, "data:image/png;base64", "file", "tempSDImg"); + //上传图片到七牛云/minio + String imgStr = remoteFileService.uploadBanner(file).getData(); + //保存生辰该图片到ai绘画表 + AiPaint paint = new AiPaint(); + //paint.setId(); 主键改成雪花算法后启用 + paintId = IdUtil.getSnowflakeNextIdStr(); + paintTime = new Date(); + paint.setPaintId(paintId); + paint.setCreateTime(paintTime); + paint.setImgUrl(imgStr); + paint.setPrompt(param.getPrompt()); + paint.setModel(param.getModelName()); + paint.setStyleName(param.getStyleName()); + paint.setHeight(param.getHeight() == null ? "512" : String.valueOf(param.getHeight())); + paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth())); + paint.setIsShow("1"); + paint.setSource("1"); + paint.setPainterId(param.getPainterId()); + paint.setPainterName(param.getPainterName()); + aiPaintService.insert(paint); + } + img.setPaintId(paintId); + img.setPaintTime(paintTime); } return img; diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/vo/AiPaintVo.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/vo/AiPaintVo.java new file mode 100644 index 0000000..fe21d96 --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/vo/AiPaintVo.java @@ -0,0 +1,50 @@ +package com.bnyer.img.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.Date; + + +@Getter +@Setter +@ApiModel("ai绘画响应体") +public class AiPaintVo implements Serializable { + + @ApiModelProperty(value="主键Id") + private Long id; + + @ApiModelProperty(value="作品编号") + private String paintId; + + @ApiModelProperty(value="绘图者昵称") + private String painterName; + + @ApiModelProperty(value="图片") + private String imgUrl; + + @ApiModelProperty(value="关键词") + private String prompt; + + @ApiModelProperty(value="风格名称") + private String styleName; + + @ApiModelProperty(value="图片高度") + private String height; + + @ApiModelProperty(value="图片宽度") + private String width; + + @ApiModelProperty(value="平台(0->Hub;1->抖音;2->快手;3->微信)") + private String source; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value="创建时间") + private Date createTime; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/bnyer-services/bnyer-img/src/main/resources/com/bnyer/img/mapper/AiPaintMapper.xml b/bnyer-services/bnyer-img/src/main/resources/com/bnyer/img/mapper/AiPaintMapper.xml new file mode 100644 index 0000000..e5011ba --- /dev/null +++ b/bnyer-services/bnyer-img/src/main/resources/com/bnyer/img/mapper/AiPaintMapper.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + id, paint_id, painter_id, painter_name, img_url, prompt, model,style_name, height, width, is_show, + `source`, create_time + + + + + + \ No newline at end of file diff --git a/bnyer-services/bnyer-system/src/main/java/com/bnyer/system/controller/SysProfileController.java b/bnyer-services/bnyer-system/src/main/java/com/bnyer/system/controller/SysProfileController.java index 0d664d0..91d4dfa 100644 --- a/bnyer-services/bnyer-system/src/main/java/com/bnyer/system/controller/SysProfileController.java +++ b/bnyer-services/bnyer-system/src/main/java/com/bnyer/system/controller/SysProfileController.java @@ -1,6 +1,8 @@ package com.bnyer.system.controller; import java.io.IOException; + +import com.bnyer.system.api.RemoteSystemFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -19,7 +21,6 @@ import com.bnyer.common.log.annotation.Log; import com.bnyer.common.log.enums.BusinessType; import com.bnyer.common.security.service.TokenService; import com.bnyer.common.security.utils.SecurityUtils; -import com.bnyer.system.api.RemoteFileService; import com.bnyer.system.api.domain.SysFile; import com.bnyer.system.api.domain.SysUser; import com.bnyer.system.api.model.LoginUser; @@ -41,7 +42,7 @@ public class SysProfileController extends BaseController private TokenService tokenService; @Autowired - private RemoteFileService remoteFileService; + private RemoteSystemFileService remoteFileService; /** * 个人信息