Browse Source

feature-1.0-img:新增兑换AI绘画次数

feature-1.0-img
‘‘ 3 years ago
parent
commit
54fe592e98
  1. 7
      bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/CdkLog.java
  2. 2
      bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/PaintCdk.java
  3. 6
      bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/PaintCdkUseDto.java
  4. 2
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java
  5. 3
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/PaintCdkService.java
  6. 14
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/StableDiffusionService.java
  7. 12
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/PaintCdkServiceImpl.java
  8. 12
      bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java
  9. 3
      bnyer-services/bnyer-img/src/main/resources/com/bnyer/img/mapper/CdkLogMapper.xml

7
bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/CdkLog.java

@ -36,6 +36,13 @@ public class CdkLog implements Serializable {
@ApiModelProperty(value="兑换码") @ApiModelProperty(value="兑换码")
private String cdk; private String cdk;
/**
* 兑换次数
*/
@TableField(value = "paint_num")
@ApiModelProperty(value="兑换次数")
private int paintNum;
/** /**
* 用户id * 用户id
*/ */

2
bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/domain/PaintCdk.java

@ -41,7 +41,7 @@ public class PaintCdk implements Serializable {
*/ */
@TableField(value = "paint_num") @TableField(value = "paint_num")
@ApiModelProperty(value="兑换次数") @ApiModelProperty(value="兑换次数")
private String paintNum; private int paintNum;
/** /**
* 是否显示 (0->隐藏1->显示) * 是否显示 (0->隐藏1->显示)

6
bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/PaintCdkUseDto.java

@ -23,6 +23,10 @@ public class PaintCdkUseDto implements Serializable {
private Long userId; private Long userId;
@NotNull(message = "平台渠道不能为空!") @NotNull(message = "平台渠道不能为空!")
@ApiModelProperty(value="平台(0->通用;1->抖音;2->快手;3->微信)") @ApiModelProperty(value="平台(0->hub;1->抖音;2->快手;3->微信)")
private String source; private String source;
@NotNull(message = "应用不能为空!")
@ApiModelProperty(value="应用(0->次元意境)")
private String appType;
} }

2
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java

@ -456,7 +456,7 @@ public class TiktokMiniController extends BaseController {
@ApiOperation(value="使用cdk") @ApiOperation(value="使用cdk")
@PostMapping(value = "/useCdk") @PostMapping(value = "/useCdk")
public AjaxResult useCdk(@Validated @RequestBody @ApiParam("ai绘画对象") PaintCdkUseDto dto){ public AjaxResult useCdk(@Validated @RequestBody @ApiParam("ai绘画对象") PaintCdkUseDto dto){
paintCdkService.useCdk(dto.getCdk(),dto.getSource(),dto.getUserId()); paintCdkService.useCdk(dto.getCdk(),dto.getSource(),dto.getUserId(),dto.getAppType());
return AjaxResult.success(); return AjaxResult.success();
} }
} }

3
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/PaintCdkService.java

@ -24,6 +24,7 @@ public interface PaintCdkService {
* @param cdk 兑换码 * @param cdk 兑换码
* @param source 平台 * @param source 平台
* @param userId 用户id * @param userId 用户id
* @param appType 应用
*/ */
void useCdk(String cdk,String source,Long userId); void useCdk(String cdk,String source,Long userId,String appType);
} }

14
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/StableDiffusionService.java

@ -6,7 +6,21 @@ import com.bnyer.common.core.vo.TextToImgVo;
public interface StableDiffusionService { public interface StableDiffusionService {
/**
* 文生图
* @param param
* @return
*/
TextToImgVo textToImg(TextToImgDto param); TextToImgVo textToImg(TextToImgDto param);
void imgToImg(); void imgToImg();
/**
* 增加ai绘画次数
* @param appType 应用
* @param platform 平台
* @param userId 用户id
* @param paintNUm 绘画次数
*/
void addPlatformUserAiPaintNum(String appType,String platform,Long userId,int paintNUm);
} }

12
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/PaintCdkServiceImpl.java

@ -8,6 +8,7 @@ import com.bnyer.common.core.utils.uuid.IdUtils;
import com.bnyer.img.mapper.CdkLogMapper; import com.bnyer.img.mapper.CdkLogMapper;
import com.bnyer.img.mapper.PaintCdkMapper; import com.bnyer.img.mapper.PaintCdkMapper;
import com.bnyer.img.service.PaintCdkService; import com.bnyer.img.service.PaintCdkService;
import com.bnyer.img.service.StableDiffusionService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -25,6 +26,9 @@ public class PaintCdkServiceImpl implements PaintCdkService {
@Autowired @Autowired
private CdkLogMapper cdkLogMapper; private CdkLogMapper cdkLogMapper;
@Autowired
private StableDiffusionService stableDiffusionService;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void generatorCdk(String source,int paintNum) { public void generatorCdk(String source,int paintNum) {
@ -53,19 +57,21 @@ public class PaintCdkServiceImpl implements PaintCdkService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void useCdk(String cdk, String source,Long userId) { public void useCdk(String cdk, String source,Long userId,String appType) {
//检查cdk是否被使用过 //检查cdk是否被使用过
PaintCdk paintCdk = checkCdk(cdk, source); PaintCdk paintCdk = checkCdk(cdk, source);
if(paintCdk == null){ if(paintCdk == null){
throw new ServiceException("该兑换码已被使用!"); throw new ServiceException("该兑换码不存在或已被使用!");
}else{ }else{
//TODO 增加用户绘画次数 //增加用户绘画次数
stableDiffusionService.addPlatformUserAiPaintNum(appType,source,userId,paintCdk.getPaintNum());
//修改cdk状态 //修改cdk状态
paintCdk.setIsUse("1"); paintCdk.setIsUse("1");
paintCdkMapper.updateById(paintCdk); paintCdkMapper.updateById(paintCdk);
//写入使用记录 //写入使用记录
CdkLog cdkLog = new CdkLog(); CdkLog cdkLog = new CdkLog();
cdkLog.setCreateTime(new Date()); cdkLog.setCreateTime(new Date());
cdkLog.setPaintNum(paintCdk.getPaintNum());
cdkLog.setSource(source); cdkLog.setSource(source);
cdkLog.setIsShow("1"); cdkLog.setIsShow("1");
cdkLog.setCdk(cdk); cdkLog.setCdk(cdk);

12
bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/StableDiffusionServiceImpl.java

@ -140,7 +140,7 @@ public class StableDiffusionServiceImpl implements StableDiffusionService {
paint.setHeight(param.getHeight() == null ? "512" : String.valueOf(param.getHeight())); paint.setHeight(param.getHeight() == null ? "512" : String.valueOf(param.getHeight()));
paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth())); paint.setWidth(param.getWidth() == null ? "512" : String.valueOf(param.getWidth()));
paint.setIsShow("1"); paint.setIsShow("1");
paint.setSource("1"); paint.setSource(param.getPlatform());
paint.setPainterId(param.getPainterId()); paint.setPainterId(param.getPainterId());
paint.setPainterName(param.getPainterName()); paint.setPainterName(param.getPainterName());
aiPaintService.insert(paint); aiPaintService.insert(paint);
@ -176,4 +176,14 @@ public class StableDiffusionServiceImpl implements StableDiffusionService {
public void imgToImg() { public void imgToImg() {
} }
@Override
public void addPlatformUserAiPaintNum(String appType, String platform, Long userId, int patinNum) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String date = df.format(new Date());
String hashKey = appType+":"+platform+":"+userId;
log.info("日期【{}】应用【{}】平台【{}】用户【{}】ai绘画次数+【{}】",date,appType,platform,userId,patinNum);
String redisKey = RedisKeyConstant.PLATFORM_USER_AI_PAINT_KEY + date;
redisService.hashIncr(redisKey, hashKey, -patinNum);
}
} }

3
bnyer-services/bnyer-img/src/main/resources/com/bnyer/img/mapper/CdkLogMapper.xml

@ -6,6 +6,7 @@
<!--@Table img_cdk_log--> <!--@Table img_cdk_log-->
<id column="id" jdbcType="BIGINT" property="id" /> <id column="id" jdbcType="BIGINT" property="id" />
<result column="cdk" jdbcType="VARCHAR" property="cdk" /> <result column="cdk" jdbcType="VARCHAR" property="cdk" />
<result column="paint_num" jdbcType="INTEGER" property="paintNum" />
<result column="user_id" jdbcType="BIGINT" property="userId" /> <result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="source" jdbcType="CHAR" property="source" /> <result column="source" jdbcType="CHAR" property="source" />
<result column="is_show" jdbcType="CHAR" property="isShow" /> <result column="is_show" jdbcType="CHAR" property="isShow" />
@ -13,6 +14,6 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, cdk, user_id, `source`, is_show, create_time id, cdk, user_id, `source`, is_show, create_time,paint_num
</sql> </sql>
</mapper> </mapper>
Loading…
Cancel
Save