Browse Source
# Conflicts: # bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/ServiceNameConstants.java # bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/UserVip.java # bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/UserVipRecord.javafeature-1.1
129 changed files with 2733 additions and 214 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.ASSIGN_ID) |
|||
@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,52 @@ |
|||
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 io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.*; |
|||
|
|||
/** |
|||
* 绘画-模型风格表 |
|||
*/ |
|||
@ApiModel(value="com-bnyer-common-core-domain-PaintStyle") |
|||
@Getter |
|||
@Setter |
|||
@ToString |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@TableName(value = "img_paint_style") |
|||
public class PaintStyle extends BaseDomain { |
|||
|
|||
/** |
|||
* 模型风格名称 |
|||
*/ |
|||
@TableField(value = "`name`") |
|||
@ApiModelProperty(value="模型风格名称") |
|||
private String name; |
|||
|
|||
/** |
|||
* 模型名称 |
|||
*/ |
|||
@TableField(value = "model_name") |
|||
@ApiModelProperty(value="模型名称") |
|||
private String modelName; |
|||
|
|||
/** |
|||
* 模型风格图片 |
|||
*/ |
|||
@TableField(value = "img_url") |
|||
@ApiModelProperty(value="模型风格图片") |
|||
private String imgUrl; |
|||
|
|||
/** |
|||
* 是否热门(0->正常;1->热门) |
|||
*/ |
|||
@TableField(value = "is_hot") |
|||
@ApiModelProperty(value="是否热门(0->正常;1->热门)") |
|||
private String isHot; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
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 io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.*; |
|||
|
|||
/** |
|||
* 绘画-提示词表 |
|||
*/ |
|||
@ApiModel(value="com-bnyer-common-core-domain-Prompt") |
|||
@Getter |
|||
@Setter |
|||
@ToString |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@TableName(value = "img_prompt") |
|||
public class Prompt extends BaseDomain { |
|||
|
|||
/** |
|||
* 提示词 |
|||
*/ |
|||
@TableField(value = "`text`") |
|||
@ApiModelProperty(value="提示词") |
|||
private String text; |
|||
|
|||
/** |
|||
* 类型(0->绘画;1->gpt) |
|||
*/ |
|||
@TableField(value = "`type`") |
|||
@ApiModelProperty(value="类型(0->绘画;1->gpt)") |
|||
private String type; |
|||
|
|||
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,41 @@ |
|||
package com.bnyer.common.core.dto; |
|||
|
|||
import com.bnyer.common.core.domain.PaintStyle; |
|||
import com.bnyer.common.core.utils.bean.BeanUtils; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("绘画风格入参接收类") |
|||
public class PaintStyleDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="模型风格名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value="模型名称") |
|||
private String modelName; |
|||
|
|||
@ApiModelProperty(value="模型风格图片") |
|||
private String imgUrl; |
|||
|
|||
@ApiModelProperty(value="是否热门(0->正常;1->热门)") |
|||
private String isHot; |
|||
|
|||
@ApiModelProperty(value="排序") |
|||
private Integer sort; |
|||
|
|||
public PaintStyle extractParam(){ |
|||
PaintStyle paintStyle = new PaintStyle(); |
|||
BeanUtils.copyProperties(this,paintStyle); |
|||
return paintStyle; |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.bnyer.common.core.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("绘画风格分页接收类") |
|||
public class PaintStylePageDto extends BasePageDto { |
|||
|
|||
@ApiModelProperty(value="模型风格名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value="是否热门(0->正常;1->热门)") |
|||
private String isHot; |
|||
|
|||
@ApiModelProperty(value="是否显示 (0->隐藏;1->显示)") |
|||
private String isShow; |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.bnyer.common.core.dto; |
|||
|
|||
import com.bnyer.common.core.domain.Prompt; |
|||
import com.bnyer.common.core.utils.bean.BeanUtils; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("提示词入参接收类") |
|||
public class PromptDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="提示词") |
|||
private String text; |
|||
|
|||
@ApiModelProperty(value="类型(0->绘画;1->gpt)") |
|||
private String type; |
|||
|
|||
public Prompt extractParam(){ |
|||
Prompt prompt = new Prompt(); |
|||
BeanUtils.copyProperties(this,prompt); |
|||
return prompt; |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.bnyer.common.core.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("提示词分页接收类") |
|||
public class PromptPageDto extends BasePageDto { |
|||
|
|||
@ApiModelProperty(value="提示词") |
|||
private String text; |
|||
|
|||
@ApiModelProperty(value="类型(0->绘画;1->gpt)") |
|||
private String type; |
|||
|
|||
@ApiModelProperty(value="是否显示 (0->隐藏;1->显示)") |
|||
private String isShow; |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
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; |
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("艺术家自定义标签接收类") |
|||
public class SignFrontDto implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@NotEmpty(message = "标签名称必填!") |
|||
@ApiModelProperty(value="标签名称") |
|||
private String name; |
|||
|
|||
@NotNull(message = "父id必填!") |
|||
@ApiModelProperty(value="父id") |
|||
private Long parentId; |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
package com.bnyer.common.core.utils; |
|||
|
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
/** |
|||
* 汉译英工具类 |
|||
*/ |
|||
public class TranslateUtils { |
|||
|
|||
/** |
|||
* 字符串是否包含中文 |
|||
* |
|||
* @param str 待校验字符串 |
|||
* @return true 包含中文字符 false 不包含中文字符 |
|||
* @throws Exception |
|||
*/ |
|||
public static boolean isContainChinese(String str) throws Exception { |
|||
|
|||
if (StringUtils.isEmpty(str)) { |
|||
throw new Exception("文本内容为空!"); |
|||
} |
|||
Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]"); |
|||
Matcher m = p.matcher(str); |
|||
return m.find(); |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,140 @@ |
|||
<?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-services</artifactId> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<version>1.0.0</version> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>bnyer-ai</artifactId> |
|||
|
|||
<description> |
|||
bnyer-ai服务 |
|||
</description> |
|||
|
|||
<dependencies> |
|||
<!-- SpringCloud Alibaba Nacos --> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- SpringCloud Alibaba Nacos Config --> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- SpringCloud Alibaba Sentinel --> |
|||
<dependency> |
|||
<groupId>com.alibaba.cloud</groupId> |
|||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- SpringBoot Actuator --> |
|||
<dependency> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-starter-actuator</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- Swagger UI --> |
|||
<dependency> |
|||
<groupId>io.springfox</groupId> |
|||
<artifactId>springfox-swagger-ui</artifactId> |
|||
<version>${swagger.fox.version}</version> |
|||
</dependency> |
|||
|
|||
<!-- Mysql Connector --> |
|||
<dependency> |
|||
<groupId>mysql</groupId> |
|||
<artifactId>mysql-connector-java</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- bnyer Common DataSource --> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-datasource</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- bnyer Common DataScope --> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-datascope</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- bnyer Common Log --> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-log</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- bnyer Common core --> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-core</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- bnyer Common Swagger --> |
|||
<dependency> |
|||
<groupId>com.dimensionalnode</groupId> |
|||
<artifactId>bnyer-common-swagger</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- mybatis-plus --> |
|||
<dependency> |
|||
<groupId>com.baomidou</groupId> |
|||
<artifactId>mybatis-plus-boot-starter</artifactId> |
|||
</dependency> |
|||
|
|||
<!--任务调度中心--> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>com.xuxueli</groupId>--> |
|||
<!-- <artifactId>xxl-job-core</artifactId>--> |
|||
<!-- <version>2.3.1</version>--> |
|||
<!-- </dependency>--> |
|||
|
|||
<!--微信小程序工具包--> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>com.github.binarywang</groupId>--> |
|||
<!-- <artifactId>weixin-java-miniapp</artifactId>--> |
|||
<!-- <version>4.2.0</version>--> |
|||
<!-- </dependency>--> |
|||
|
|||
<!--七牛云--> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>com.qiniu</groupId>--> |
|||
<!-- <artifactId>qiniu-java-sdk</artifactId>--> |
|||
<!-- <version>7.2.18</version>--> |
|||
<!-- </dependency>--> |
|||
|
|||
<!--chatgpt--> |
|||
<dependency> |
|||
<groupId>com.github.plexpt</groupId> |
|||
<artifactId>chatgpt</artifactId> |
|||
<version>4.0.5</version> |
|||
</dependency> |
|||
|
|||
</dependencies> |
|||
|
|||
<build> |
|||
<finalName>${project.artifactId}</finalName> |
|||
<plugins> |
|||
<plugin> |
|||
<groupId>org.springframework.boot</groupId> |
|||
<artifactId>spring-boot-maven-plugin</artifactId> |
|||
<version>2.6.2</version> |
|||
<executions> |
|||
<execution> |
|||
<goals> |
|||
<goal>repackage</goal> |
|||
</goals> |
|||
</execution> |
|||
</executions> |
|||
</plugin> |
|||
</plugins> |
|||
</build> |
|||
|
|||
</project> |
|||
@ -0,0 +1,33 @@ |
|||
package com.bnyer.ai; |
|||
|
|||
import com.bnyer.common.security.annotation.EnableCustomConfig; |
|||
import com.bnyer.common.security.annotation.EnableRyFeignClients; |
|||
import com.bnyer.common.swagger.annotation.EnableCustomSwagger2; |
|||
import org.springframework.boot.SpringApplication; |
|||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|||
import org.springframework.scheduling.annotation.EnableAsync; |
|||
|
|||
/** |
|||
* ai模块 |
|||
* |
|||
* @author penny |
|||
*/ |
|||
@EnableCustomConfig |
|||
@EnableCustomSwagger2 |
|||
@EnableRyFeignClients |
|||
@SpringBootApplication |
|||
@EnableAsync |
|||
public class BnyerAiApplication |
|||
{ |
|||
public static void main(String[] args) |
|||
{ |
|||
SpringApplication.run(BnyerAiApplication.class, args); |
|||
System.out.println("(♥◠‿◠)ノ゙ bnyerAi服务启动成功 ლ(´ڡ`ლ)゙ \n" + |
|||
"__________ \n" + |
|||
"\\______ \\ ____ ___.__. ___________ \n" + |
|||
" | | _// < | |/ __ \\_ __ \\\n" + |
|||
" | | \\ | \\___ \\ ___/| | \\/\n" + |
|||
" |______ /___| / ____|\\___ >__| \n" + |
|||
" \\/ \\/\\/ \\/ \n"); |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.bnyer.ai.controller; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.bnyer.ai.service.ChatGptService; |
|||
import com.bnyer.common.core.domain.Feedback; |
|||
import com.bnyer.common.core.dto.FeedBackDto; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@Api(value = "【AI】接口",tags = "【AI】接口") |
|||
@RestController |
|||
@RequestMapping("/ai") |
|||
public class ChatGptController { |
|||
|
|||
@Autowired |
|||
private ChatGptService chatGptService; |
|||
|
|||
@ApiOperation(value="chat") |
|||
@PostMapping(value = "/chatWithGpt") |
|||
public AjaxResult chatWithGpt(){ |
|||
chatGptService.talkWithChatGpt(); |
|||
return AjaxResult.success(); |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
package com.bnyer.ai.service; |
|||
|
|||
public interface ChatGptService { |
|||
|
|||
void talkWithChatGpt(); |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
package com.bnyer.ai.service.impl; |
|||
|
|||
import com.bnyer.ai.service.ChatGptService; |
|||
import com.plexpt.chatgpt.ChatGPT; |
|||
import com.plexpt.chatgpt.entity.chat.ChatCompletion; |
|||
import com.plexpt.chatgpt.entity.chat.ChatCompletionResponse; |
|||
import com.plexpt.chatgpt.entity.chat.Message; |
|||
import com.plexpt.chatgpt.util.Proxys; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.net.Proxy; |
|||
import java.util.Arrays; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class ChatGptServiceImpl implements ChatGptService { |
|||
@Override |
|||
public void talkWithChatGpt() { |
|||
Proxy proxy = Proxys.http("18.179.21.104", 21584); |
|||
ChatGPT chatGPT = ChatGPT.builder() |
|||
.apiKey("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") |
|||
.proxy(proxy) |
|||
.timeout(100000) |
|||
.apiHost("https://api.openai.com/") //反向代理地址
|
|||
.build() |
|||
.init(); |
|||
|
|||
Message system = Message.ofSystem("你现在是一个诗人,专门写七言绝句"); |
|||
Message message = Message.of("写一段七言绝句诗,题目是:火锅!"); |
|||
|
|||
ChatCompletion chatCompletion = ChatCompletion.builder() |
|||
.model(ChatCompletion.Model.GPT_3_5_TURBO.getName()) |
|||
.messages(Arrays.asList(system, message)) |
|||
.maxTokens(3000) |
|||
.temperature(0.9) |
|||
.build(); |
|||
ChatCompletionResponse response = chatGPT.chatCompletion(chatCompletion); |
|||
Message res = response.getChoices().get(0).getMessage(); |
|||
System.out.println(res); |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
spring: |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
# 服务注册地址 |
|||
server-addr: http://117.50.61.7:8848 |
|||
# 命名空间地址 |
|||
namespace: c4f53d8c-0a91-4249-a804-f16f543ec3b0 |
|||
# 命名空间分组 |
|||
group: dev |
|||
config: |
|||
# 配置中心地址 |
|||
server-addr: http://117.50.61.7:8848 |
|||
# 配置文件格式 |
|||
file-extension: yml |
|||
# 命名空间地址 |
|||
namespace: c4f53d8c-0a91-4249-a804-f16f543ec3b0 |
|||
# 命名空间分组 |
|||
group: dev |
|||
# 共享配置 |
|||
shared-configs: |
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
|||
@ -0,0 +1,26 @@ |
|||
spring: |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
# 解决部署在不同服务器访问不到的问题,需暴露外网ip |
|||
ip: 81.69.47.31 |
|||
# 部署在不同服务器上的指定端口 |
|||
port: 9102 |
|||
# 服务注册地址 |
|||
server-addr: http://175.24.122.142:8848 |
|||
# 命名空间地址 |
|||
namespace: abfe8ee6-161b-4f8f-b61f-51663bbfa4f9 |
|||
# 命名空间分组 |
|||
group: grey |
|||
config: |
|||
# 配置中心地址 |
|||
server-addr: http://175.24.122.142:8848 |
|||
# 配置文件格式 |
|||
file-extension: yml |
|||
# 命名空间地址 |
|||
namespace: abfe8ee6-161b-4f8f-b61f-51663bbfa4f9 |
|||
# 命名空间分组 |
|||
group: grey |
|||
# 共享配置 |
|||
shared-configs: |
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
|||
@ -0,0 +1,22 @@ |
|||
spring: |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
# 服务注册地址 |
|||
server-addr: http://192.168.3.100:6001 |
|||
# 命名空间地址 |
|||
namespace: b133c9e5-9f8d-4ed4-9ebd-95557802889f |
|||
# 命名空间分组 |
|||
group: prod |
|||
config: |
|||
# 配置中心地址 |
|||
server-addr: http://192.168.3.100:6001 |
|||
# 配置文件格式 |
|||
file-extension: yml |
|||
# 命名空间地址 |
|||
namespace: b133c9e5-9f8d-4ed4-9ebd-95557802889f |
|||
# 命名空间分组 |
|||
group: prod |
|||
# 共享配置 |
|||
shared-configs: |
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
|||
@ -0,0 +1,22 @@ |
|||
spring: |
|||
cloud: |
|||
nacos: |
|||
discovery: |
|||
# 服务注册地址 |
|||
server-addr: http://117.50.61.7:8848 |
|||
# 命名空间地址 |
|||
namespace: 1bf94455-a046-41e3-b7e4-c12fd11c3690 |
|||
# 命名空间分组 |
|||
group: test |
|||
config: |
|||
# 配置中心地址 |
|||
server-addr: http://117.50.61.7:8848 |
|||
# 配置文件格式 |
|||
file-extension: yml |
|||
# 命名空间地址 |
|||
namespace: 1bf94455-a046-41e3-b7e4-c12fd11c3690 |
|||
# 命名空间分组 |
|||
group: test |
|||
# 共享配置 |
|||
shared-configs: |
|||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} |
|||
@ -0,0 +1,15 @@ |
|||
# Tomcat |
|||
server: |
|||
port: 9105 |
|||
|
|||
# Spring |
|||
spring: |
|||
main: |
|||
#解决循环依赖问题 |
|||
allow-circular-references: true |
|||
application: |
|||
# 应用名称 |
|||
name: bnyer-ai |
|||
profiles: |
|||
# 环境配置 |
|||
active: dev |
|||
@ -0,0 +1,74 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<configuration scan="true" scanPeriod="60 seconds" debug="false"> |
|||
<!-- 日志存放路径 --> |
|||
<property name="log.path" value="logs/bnyer-ai" /> |
|||
<!-- 日志输出格式 --> |
|||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" /> |
|||
|
|||
<!-- 控制台输出 --> |
|||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender"> |
|||
<encoder> |
|||
<pattern>${log.pattern}</pattern> |
|||
</encoder> |
|||
</appender> |
|||
|
|||
<!-- 系统日志输出 --> |
|||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<file>${log.path}/info.log</file> |
|||
<!-- 循环政策:基于时间创建日志文件 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 日志文件名格式 --> |
|||
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern> |
|||
<!-- 日志最大的历史 60天 --> |
|||
<maxHistory>20</maxHistory> |
|||
</rollingPolicy> |
|||
<encoder> |
|||
<pattern>${log.pattern}</pattern> |
|||
</encoder> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<!-- 过滤的级别 --> |
|||
<level>INFO</level> |
|||
<!-- 匹配时的操作:接收(记录) --> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<!-- 不匹配时的操作:拒绝(不记录) --> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|||
<file>${log.path}/error.log</file> |
|||
<!-- 循环政策:基于时间创建日志文件 --> |
|||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|||
<!-- 日志文件名格式 --> |
|||
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern> |
|||
<!-- 日志最大的历史 60天 --> |
|||
<maxHistory>20</maxHistory> |
|||
</rollingPolicy> |
|||
<encoder> |
|||
<pattern>${log.pattern}</pattern> |
|||
</encoder> |
|||
<filter class="ch.qos.logback.classic.filter.LevelFilter"> |
|||
<!-- 过滤的级别 --> |
|||
<level>ERROR</level> |
|||
<!-- 匹配时的操作:接收(记录) --> |
|||
<onMatch>ACCEPT</onMatch> |
|||
<!-- 不匹配时的操作:拒绝(不记录) --> |
|||
<onMismatch>DENY</onMismatch> |
|||
</filter> |
|||
</appender> |
|||
|
|||
<!-- 系统模块日志级别控制 --> |
|||
<logger name="com.bnyer" level="info" /> |
|||
<!-- Spring日志级别控制 --> |
|||
<logger name="org.springframework" level="warn" /> |
|||
|
|||
<root level="info"> |
|||
<appender-ref ref="console" /> |
|||
</root> |
|||
|
|||
<!--系统操作日志--> |
|||
<root level="info"> |
|||
<appender-ref ref="file_info" /> |
|||
<appender-ref ref="file_error" /> |
|||
</root> |
|||
</configuration> |
|||
@ -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,18 @@ |
|||
package com.bnyer.img.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.bnyer.common.core.domain.PaintStyle; |
|||
import com.bnyer.img.vo.PaintStyleVo; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface PaintStyleMapper extends BaseMapper<PaintStyle> { |
|||
|
|||
/** |
|||
* 获取绘画风格列表 |
|||
* @return - |
|||
*/ |
|||
List<PaintStyleVo> queryList(); |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.bnyer.img.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.bnyer.common.core.domain.Prompt; |
|||
import com.bnyer.img.vo.PromptVo; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Mapper |
|||
public interface PromptMapper extends BaseMapper<Prompt> { |
|||
/** |
|||
* 获取提示词列表 |
|||
* @param type 类型 |
|||
* @return - |
|||
*/ |
|||
List<PromptVo> queryList(String type); |
|||
} |
|||
@ -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,25 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface HotSearchKeywordService { |
|||
|
|||
/** |
|||
* 获取最近一个月搜索次数最多的前10条记录 |
|||
* @return - |
|||
*/ |
|||
List<String> getHotKeywordList(); |
|||
|
|||
/** |
|||
* 点击增长热搜词热度次数 |
|||
* @param keyword 热搜词 |
|||
* @return - |
|||
*/ |
|||
void incrementHotKeywordScore(String keyword); |
|||
|
|||
/** |
|||
* 新增热搜词 |
|||
* @param keyword 热搜词 |
|||
*/ |
|||
void insertHotKeyword(String keyword); |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.bnyer.img.vo.PaintStyleVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface PaintStyleService { |
|||
|
|||
/** |
|||
* 获取绘画风格列表 |
|||
* @return - |
|||
*/ |
|||
List<PaintStyleVo> queryPaintStyleList(); |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.bnyer.img.vo.PromptVo; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface PromptService { |
|||
|
|||
/** |
|||
* 随机获取8条提示词列表 |
|||
* @return - |
|||
*/ |
|||
List<PromptVo> queryPromptList(); |
|||
} |
|||
@ -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,65 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.bnyer.common.core.constant.RedisKeyConstant; |
|||
import com.bnyer.common.redis.service.RedisService; |
|||
import com.bnyer.img.service.HotSearchKeywordService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.redis.core.HashOperations; |
|||
import org.springframework.data.redis.core.ValueOperations; |
|||
import org.springframework.data.redis.core.ZSetOperations; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Set; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class HotSearchKeywordServiceImpl implements HotSearchKeywordService { |
|||
|
|||
@Autowired |
|||
private RedisService redisService; |
|||
|
|||
|
|||
|
|||
@Override |
|||
public List<String> getHotKeywordList() { |
|||
Long now = System.currentTimeMillis(); |
|||
List<String> result = new ArrayList<>(); |
|||
ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); |
|||
HashOperations hashOperations = redisService.redisTemplate.opsForHash(); |
|||
Set<String> value = zSetOperations.reverseRangeByScore(RedisKeyConstant.HOT_KEY_WORD_KEY, 0, Double.MAX_VALUE); |
|||
//key不为空的时候 推荐相关的最热前十名
|
|||
for (String val : value) { |
|||
if (result.size() > 9) {//只返回最热的前十名
|
|||
break; |
|||
} |
|||
Long time = Long.valueOf((String) hashOperations.get(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY, val)); |
|||
if ((now - time) < 2592000000L) {//返回最近一个月的数据
|
|||
result.add(val); |
|||
} else {//时间超过一个月没搜索就把这个词热度归0
|
|||
zSetOperations.add(RedisKeyConstant.HOT_KEY_WORD_KEY, val, 0); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public void incrementHotKeywordScore(String keyword) { |
|||
Long now = System.currentTimeMillis(); |
|||
ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); |
|||
HashOperations hashOperations = redisService.redisTemplate.opsForHash(); |
|||
zSetOperations.incrementScore(RedisKeyConstant.HOT_KEY_WORD_KEY, keyword, 1); |
|||
hashOperations.put(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY,keyword,String.valueOf(now)); |
|||
} |
|||
|
|||
@Override |
|||
public void insertHotKeyword(String keyword) { |
|||
Long now = System.currentTimeMillis(); |
|||
ZSetOperations zSetOperations = redisService.redisTemplate.opsForZSet(); |
|||
HashOperations hashOperations = redisService.redisTemplate.opsForHash(); |
|||
zSetOperations.incrementScore(RedisKeyConstant.HOT_KEY_WORD_KEY, keyword, 1); |
|||
hashOperations.put(RedisKeyConstant.HOT_KEY_WORD_TIME_KEY,keyword,String.valueOf(now)); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.bnyer.common.core.domain.PaintStyle; |
|||
import com.bnyer.img.mapper.PaintStyleMapper; |
|||
import com.bnyer.img.service.PaintStyleService; |
|||
import com.bnyer.img.vo.PaintStyleVo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Service |
|||
public class PaintStyleServiceImpl implements PaintStyleService { |
|||
|
|||
@Autowired |
|||
private PaintStyleMapper paintStyleMapper; |
|||
|
|||
@Override |
|||
public List<PaintStyleVo> queryPaintStyleList() { |
|||
return paintStyleMapper.queryList(); |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import com.bnyer.img.mapper.PromptMapper; |
|||
import com.bnyer.img.service.PromptService; |
|||
import com.bnyer.img.vo.PromptVo; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class PromptServiceimpl implements PromptService { |
|||
|
|||
@Autowired |
|||
private PromptMapper promptMapper; |
|||
|
|||
@Override |
|||
public List<PromptVo> queryPromptList() { |
|||
//type:0->绘画;1->gpt
|
|||
List<PromptVo> promptVos = promptMapper.queryList("0"); |
|||
List<PromptVo> news = new ArrayList<>(); |
|||
Map<Integer,String> map = new HashMap<>(); |
|||
//随机抽10条数据展示在页面上
|
|||
if (promptVos.size() <= 30) { |
|||
return promptVos; |
|||
}else{ |
|||
while (map.size() < 30) { |
|||
int random = (int)(Math.random() * promptVos.size()); |
|||
if (!map.containsKey(random)) { |
|||
map.put(random, ""); |
|||
news.add(promptVos.get(random)); |
|||
} |
|||
} |
|||
} |
|||
return news; |
|||
} |
|||
} |
|||
@ -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,31 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("绘画风格响应体") |
|||
public class PaintStyleVo implements Serializable { |
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="模型风格名称") |
|||
private String name; |
|||
|
|||
@ApiModelProperty(value="模型名称") |
|||
private String modelName; |
|||
|
|||
@ApiModelProperty(value="模型风格图片") |
|||
private String imgUrl; |
|||
|
|||
@ApiModelProperty(value="是否热门(0->正常;1->热门)") |
|||
private String isHot; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package com.bnyer.img.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("提示词响应体") |
|||
public class PromptVo implements Serializable { |
|||
|
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
@ApiModelProperty(value="提示词") |
|||
private String text; |
|||
|
|||
@ApiModelProperty(value="类型(0->绘画;1->gpt)") |
|||
private String type; |
|||
|
|||
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> |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue