25 changed files with 655 additions and 22 deletions
@ -0,0 +1,26 @@ |
|||
<?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>bnyer-api</artifactId> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>bnyer-api-file</artifactId> |
|||
|
|||
<description> |
|||
bnyer-api-file文件服务接口模块 |
|||
</description> |
|||
|
|||
<dependencies> |
|||
<!-- bnyer Common Core--> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-core</artifactId> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
</project> |
|||
@ -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<String> uploadBanner(@RequestPart(name = "file") MultipartFile file); |
|||
|
|||
/** |
|||
* 批量上传文件到七牛云 |
|||
* @param files 文件 |
|||
* @return - |
|||
*/ |
|||
@PostMapping("/uploadBatch") |
|||
R<List<String>> uploadBatch(MultipartFile[] files); |
|||
|
|||
} |
|||
@ -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<RemoteFileService> |
|||
{ |
|||
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<String> uploadBanner(MultipartFile file) { |
|||
return R.fail("远程调用minio文件上传失败:" + throwable.getMessage()); |
|||
} |
|||
|
|||
@Override |
|||
public R<List<String>> uploadBatch(MultipartFile[] files) { |
|||
return R.fail("远程调用七牛云批量文件上传失败:" + throwable.getMessage()); |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration = com.bnyer.file.api.factory.RemoteFileFallbackFactory |
|||
|
|||
@ -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; |
|||
} |
|||
@ -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; |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -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; |
|||
@ -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<AiPaint> { |
|||
|
|||
/** |
|||
* 获取ai绘画分页 |
|||
* @param source 来源 |
|||
* @param painterId 绘画者id |
|||
* @return - |
|||
*/ |
|||
List<AiPaintVo> queryPage(@Param("source") String source,@Param("painterId") Long painterId); |
|||
|
|||
/** |
|||
* 获取ai绘画详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
AiPaintVo queryDetails(Long id); |
|||
} |
|||
@ -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<Long> ids); |
|||
|
|||
/** |
|||
* 获取绘画者ai绘画分页 |
|||
* @param params 分页参数 |
|||
* @return - |
|||
*/ |
|||
List<AiPaintVo> queryPage(AiPaintPageDto params); |
|||
|
|||
/** |
|||
* 获取ai绘画详情 |
|||
* @param id 主键id |
|||
* @return - |
|||
*/ |
|||
AiPaintVo queryDetails(Long id); |
|||
|
|||
|
|||
} |
|||
@ -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<Long> ids) { |
|||
return aiPaintMapper.deleteBatchIds(ids); |
|||
} |
|||
|
|||
@Override |
|||
public List<AiPaintVo> queryPage(AiPaintPageDto params) { |
|||
return aiPaintMapper.queryPage(params.getSource(),params.getPainterId()); |
|||
} |
|||
|
|||
@Override |
|||
public AiPaintVo queryDetails(Long id) { |
|||
return aiPaintMapper.queryDetails(id); |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.bnyer.img.mapper.AiPaintMapper"> |
|||
<resultMap id="BaseResultMap" type="com.bnyer.common.core.domain.AiPaint"> |
|||
<!--@mbg.generated--> |
|||
<!--@Table img_ai_paint--> |
|||
<id column="id" jdbcType="BIGINT" property="id" /> |
|||
<result column="paint_id" jdbcType="VARCHAR" property="paintId" /> |
|||
<result column="painter_id" jdbcType="BIGINT" property="painterId" /> |
|||
<result column="painter_name" jdbcType="VARCHAR" property="painterName" /> |
|||
<result column="img_url" jdbcType="VARCHAR" property="imgUrl" /> |
|||
<result column="prompt" jdbcType="LONGVARCHAR" property="prompt" /> |
|||
<result column="model" jdbcType="VARCHAR" property="model" /> |
|||
<result column="style_name" jdbcType="VARCHAR" property="styleName" /> |
|||
<result column="height" jdbcType="VARCHAR" property="height" /> |
|||
<result column="width" jdbcType="VARCHAR" property="width" /> |
|||
<result column="is_show" jdbcType="CHAR" property="isShow" /> |
|||
<result column="source" jdbcType="CHAR" property="source" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
<!--@mbg.generated--> |
|||
id, paint_id, painter_id, painter_name, img_url, prompt, model,style_name, height, width, is_show, |
|||
`source`, create_time |
|||
</sql> |
|||
|
|||
<select id="queryPage" resultType="com.bnyer.img.vo.AiPaintVo"> |
|||
select |
|||
id, paint_id,painter_name,img_url, prompt, style_name,height, width,create_time,source |
|||
from img_ai_paint |
|||
where is_show = '1' and source = #{source} and painter_id = #{painterId} |
|||
order by create_time desc |
|||
</select> |
|||
|
|||
<select id="queryDetails" resultType="com.bnyer.img.vo.AiPaintVo"> |
|||
select |
|||
id, paint_id,painter_name,img_url, prompt, style_name,height, width,create_time,source |
|||
from img_ai_paint where id = #{id} |
|||
</select> |
|||
</mapper> |
|||
Loading…
Reference in new issue