1、generate 积分扣除并添加相关积分详细
2、获取服装category bug修改
This commit is contained in:
@@ -21,10 +21,14 @@ public enum CreditsEventsEnum {
|
|||||||
// SUPER_RESOLUTION("Super Resolution","30"),
|
// SUPER_RESOLUTION("Super Resolution","30"),
|
||||||
SUPER_RESOLUTION("Super Resolution","10"),
|
SUPER_RESOLUTION("Super Resolution","10"),
|
||||||
SLOGAN("Slogan","10"),
|
SLOGAN("Slogan","10"),
|
||||||
NORMAL_GENERATE("Normal_Generate","5"),
|
LOGO("Logo","5"),
|
||||||
|
PATTERN("Pattern","5"),
|
||||||
|
MOOD_BOARD("MoodBoard","5"),
|
||||||
|
SKETCH_BOARD("SketchBoard","5"),
|
||||||
|
TO_PRODUCT_IMAGE("ToProductImage","5"),
|
||||||
QUESTIONNAIRE("Questionnaire","100"),
|
QUESTIONNAIRE("Questionnaire","100"),
|
||||||
|
|
||||||
OTHER("Other","10");
|
OTHER("Other","5");
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import java.math.BigDecimal;
|
|||||||
public class CreditsDetail extends BaseEntity {
|
public class CreditsDetail extends BaseEntity {
|
||||||
/** 用户id */
|
/** 用户id */
|
||||||
private Long accountId;
|
private Long accountId;
|
||||||
|
/** 任务id或uuid */
|
||||||
|
private String taskId;
|
||||||
/** 积分变更事件 */
|
/** 积分变更事件 */
|
||||||
private String changeEvent;
|
private String changeEvent;
|
||||||
/** 变更积分 ( + 表示加,- 表示减) */
|
/** 变更积分 ( + 表示加,- 表示减) */
|
||||||
|
|||||||
@@ -3160,8 +3160,9 @@ public class PythonService {
|
|||||||
try {
|
try {
|
||||||
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
|
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
|
||||||
if (result && jsonObject.get("msg").equals("OK!")) {
|
if (result && jsonObject.get("msg").equals("OK!")) {
|
||||||
JSONObject data = jsonObject.getJSONObject("data");
|
// JSONObject data = jsonObject.getJSONObject("data");
|
||||||
JSONArray list = JSONArray.parseArray(data.get("list").toString());
|
// JSONArray list = JSONArray.parseArray(data.get("list").toString());
|
||||||
|
JSONArray list = jsonObject.getJSONArray("data");
|
||||||
JSONObject map = (JSONObject) list.get(0);
|
JSONObject map = (JSONObject) list.get(0);
|
||||||
return map.get("category").toString();
|
return map.get("category").toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,11 @@ public interface CreditsService extends IService<CreditsDetail> {
|
|||||||
|
|
||||||
void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum);
|
void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum);
|
||||||
|
|
||||||
void taskCreditsDeduction(Long accountId, String taskId);
|
Boolean taskCreditsDeduction(Long accountId, String taskId);
|
||||||
|
|
||||||
CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits);
|
CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits);
|
||||||
|
|
||||||
|
void preInsert(Long accountId, String changeEventName, String taskId);
|
||||||
|
|
||||||
|
void updateChangedCredits(String accountId, String taskId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.ai.da.model.dto.QueryIncomeOrExpenditureDTO;
|
|||||||
import com.ai.da.service.AccountService;
|
import com.ai.da.service.AccountService;
|
||||||
import com.ai.da.service.CreditsService;
|
import com.ai.da.service.CreditsService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
@@ -190,8 +191,10 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
|||||||
* 3、执行成功后,从redis中拿出当前任务id对应需要扣除的积分,扣除积分,更新数据库积分,移除redis的记录
|
* 3、执行成功后,从redis中拿出当前任务id对应需要扣除的积分,扣除积分,更新数据库积分,移除redis的记录
|
||||||
* 4、执行失败,直接移除记录
|
* 4、执行失败,直接移除记录
|
||||||
*/
|
*/
|
||||||
/** 积分预扣除 */
|
/**
|
||||||
public Boolean creditsPreDeduction(CreditsEventsEnum event, Integer num){
|
* 积分预扣除
|
||||||
|
*/
|
||||||
|
public Boolean creditsPreDeduction(CreditsEventsEnum event, Integer num) {
|
||||||
|
|
||||||
Long accountId = UserContext.getUserHolder().getId();
|
Long accountId = UserContext.getUserHolder().getId();
|
||||||
|
|
||||||
@@ -208,7 +211,7 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
|||||||
BigDecimal subtract = existingCredits.subtract(new BigDecimal(sum));
|
BigDecimal subtract = existingCredits.subtract(new BigDecimal(sum));
|
||||||
|
|
||||||
// 3、判断剩余积分是否够本次操作
|
// 3、判断剩余积分是否够本次操作
|
||||||
if (subtract.compareTo(BigDecimal.ZERO) < 0){
|
if (subtract.compareTo(BigDecimal.ZERO) < 0) {
|
||||||
// 3.1 不够,直接返回余额不够,充值
|
// 3.1 不够,直接返回余额不够,充值
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
}
|
}
|
||||||
@@ -217,27 +220,29 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum){
|
public void addRecordToCreditsDeduction(Long accountId, String taskId, CreditsEventsEnum creditsEventsEnum) {
|
||||||
// 5、添加当前任务的预扣积分到redis 任务有效期一天,若待扣积分两天还没被移除,说明任务已经失败,待扣积分自动失效
|
// 5、添加当前任务的预扣积分到redis 任务有效期一天,若待扣积分两天还没被移除,说明任务已经失败,待扣积分自动失效
|
||||||
redisUtil.addToString(creditsDeduction + ":" + accountId + ":" + taskId, creditsEventsEnum.getValue(), CommonConstant.CREDITS_EXPIRE_TIME);
|
redisUtil.addToString(creditsDeduction + ":" + accountId + ":" + taskId, creditsEventsEnum.getValue(), CommonConstant.CREDITS_EXPIRE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 执行扣除积分,更新数据库 */
|
/**
|
||||||
|
* 执行扣除积分,更新数据库
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void taskCreditsDeduction(Long accountId, String taskId){
|
public Boolean taskCreditsDeduction(Long accountId, String taskId) {
|
||||||
log.info("指定任务的积分扣除 : {}",taskId);
|
log.info("指定任务的积分扣除 : {}", taskId);
|
||||||
String key = creditsDeduction + ":" + accountId + ":" + taskId;
|
String key = creditsDeduction + ":" + accountId + ":" + taskId;
|
||||||
// 1、获取当前任务id对应的积分
|
// 1、获取当前任务id对应的积分
|
||||||
String value = redisUtil.getFromString(key);
|
String value = redisUtil.getFromString(key);
|
||||||
|
|
||||||
// 1.1 没有。返回,报错,未找到当前任务
|
// 1.1 没有。返回,报错,未找到当前任务
|
||||||
if (StringUtil.isNullOrEmpty(value)){
|
if (StringUtil.isNullOrEmpty(value)) {
|
||||||
log.info("当前任务 {} 不存在,或当前任务已完成积分扣除", taskId);
|
log.info("当前任务 {} 不存在,或当前任务已完成积分扣除", taskId);
|
||||||
return;
|
return Boolean.FALSE;
|
||||||
// throw new BusinessException("当前任务不存在,无法扣除积分");
|
// throw new BusinessException("当前任务不存在,无法扣除积分");
|
||||||
}else {
|
} else {
|
||||||
log.info("指定任务 {} 扣除积分 {}",taskId, value);
|
log.info("指定任务 {} 扣除积分 {}", taskId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2、操作数据库,扣除积分
|
// 2、操作数据库,扣除积分
|
||||||
@@ -247,9 +252,10 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
|||||||
|
|
||||||
// 3、从redis中移除当前待扣积分
|
// 3、从redis中移除当前待扣积分
|
||||||
redisUtil.removeFromString(key);
|
redisUtil.removeFromString(key);
|
||||||
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits){
|
public CreditsDetail getByAccountIdAndChangeEvent(Long accountId, String changeEvent, String changedCredits) {
|
||||||
QueryWrapper<CreditsDetail> qw = new QueryWrapper<>();
|
QueryWrapper<CreditsDetail> qw = new QueryWrapper<>();
|
||||||
qw.eq("account_id", accountId);
|
qw.eq("account_id", accountId);
|
||||||
qw.eq("change_event", changeEvent);
|
qw.eq("change_event", changeEvent);
|
||||||
@@ -258,4 +264,50 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
|
|||||||
return baseMapper.selectOne(qw);
|
return baseMapper.selectOne(qw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preInsert(Long accountId, String changeEventName, String taskId) {
|
||||||
|
CreditsDetail creditsDetail = new CreditsDetail();
|
||||||
|
Account account = accountMapper.selectById(accountId);
|
||||||
|
creditsDetail.setAccountId(accountId);
|
||||||
|
creditsDetail.setTaskId(taskId);
|
||||||
|
creditsDetail.setChangeEvent(changeEventName);
|
||||||
|
creditsDetail.setChangedCredits("-0");
|
||||||
|
creditsDetail.setCredits(account.getCredits());
|
||||||
|
creditsDetail.setCreateTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
baseMapper.insert(creditsDetail);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateChangedCredits(String accountId, String taskId) {
|
||||||
|
QueryWrapper<CreditsDetail> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("account_id", accountId)
|
||||||
|
.eq("task_id", taskId);
|
||||||
|
|
||||||
|
CreditsDetail creditsDetail = baseMapper.selectOne(queryWrapper);
|
||||||
|
String changeEvent = creditsDetail.getChangeEvent();
|
||||||
|
BigDecimal currentCredits = creditsDetail.getCredits();
|
||||||
|
String credits = "0";
|
||||||
|
if (changeEvent.equals("Logo") ||
|
||||||
|
changeEvent.equals("Pattern") ||
|
||||||
|
changeEvent.equals("MoodBoard") ||
|
||||||
|
changeEvent.equals("SketchBoard")) {
|
||||||
|
credits = CreditsEventsEnum.LOGO.getValue();
|
||||||
|
}else if (changeEvent.equals("Slogan")){
|
||||||
|
credits = CreditsEventsEnum.SLOGAN.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
BigDecimal finalCredits = currentCredits.subtract(new BigDecimal(credits));
|
||||||
|
String changeCredits = "-" + credits;
|
||||||
|
|
||||||
|
UpdateWrapper<CreditsDetail> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.lambda()
|
||||||
|
.eq(CreditsDetail::getTaskId, taskId)
|
||||||
|
.set(CreditsDetail::getChangedCredits, changeCredits)
|
||||||
|
.set(CreditsDetail::getCredits, finalCredits);
|
||||||
|
|
||||||
|
baseMapper.update(null, updateWrapper);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,11 +143,11 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
String jsonString = "";
|
String jsonString = "";
|
||||||
HashMap<String, String> params = new HashMap<>();
|
HashMap<String, String> params = new HashMap<>();
|
||||||
// 3.1 确定不同类型的印花分别调哪个接口
|
// 3.1 确定不同类型的印花分别调哪个接口
|
||||||
if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())){
|
if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())) {
|
||||||
switch(generateThroughImageTextDTO.getLevel2Type()){
|
switch (generateThroughImageTextDTO.getLevel2Type()) {
|
||||||
case "Logo":
|
case "Logo":
|
||||||
path = CommonConstant.GENERATE_SINGLE_LOGO;
|
path = CommonConstant.GENERATE_SINGLE_LOGO;
|
||||||
params.put("tasks_id",generateThroughImageTextDTO.getUniqueId());
|
params.put("tasks_id", generateThroughImageTextDTO.getUniqueId());
|
||||||
params.put("prompt", text);
|
params.put("prompt", text);
|
||||||
params.put("seed", generateThroughImageTextDTO.getSeed());
|
params.put("seed", generateThroughImageTextDTO.getSeed());
|
||||||
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
|
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
|
||||||
@@ -155,8 +155,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
case "Slogan":
|
case "Slogan":
|
||||||
path = CommonConstant.GENERATE_SLOGAN;
|
path = CommonConstant.GENERATE_SLOGAN;
|
||||||
port = CommonConstant.PYTHON_PORT_9997;
|
port = CommonConstant.PYTHON_PORT_9997;
|
||||||
params.put("num_point","16");
|
params.put("num_point", "16");
|
||||||
params.put("tasks_id",generateThroughImageTextDTO.getUniqueId());
|
params.put("tasks_id", generateThroughImageTextDTO.getUniqueId());
|
||||||
params.put("prompt", text);
|
params.put("prompt", text);
|
||||||
params.put("image_url", collectionElement.getUrl());
|
params.put("image_url", collectionElement.getUrl());
|
||||||
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
|
jsonString = JSON.toJSONString(params, SerializerFeature.WriteMapNullValue);
|
||||||
@@ -166,7 +166,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
mode, category, generateThroughImageTextDTO.getGender());
|
mode, category, generateThroughImageTextDTO.getGender());
|
||||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
|
GenerateToPythonDTO generateToPythonDTO = new GenerateToPythonDTO(generateThroughImageTextDTO.getUniqueId(), text, Objects.isNull(collectionElement) ? "" : collectionElement.getUrl(),
|
||||||
mode, category, generateThroughImageTextDTO.getGender());
|
mode, category, generateThroughImageTextDTO.getGender());
|
||||||
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
jsonString = JSON.toJSONString(generateToPythonDTO, SerializerFeature.WriteMapNullValue);
|
||||||
@@ -231,9 +231,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||||
|
|
||||||
// 执行积分扣除
|
// 执行积分扣除
|
||||||
String accountId = taskId.substring(taskId.lastIndexOf("-") + 1);
|
// ** 注:如果生成的图片都是空白 则不扣积分
|
||||||
String uuid = taskId.substring(0,taskId.substring(0, taskId.lastIndexOf("-")).lastIndexOf("-"));
|
if (!status.equals("Invalid")){
|
||||||
creditsService.taskCreditsDeduction(Long.parseLong(accountId), uuid);
|
String accountId = taskId.substring(taskId.lastIndexOf("-") + 1);
|
||||||
|
String uuid = taskId.substring(0, taskId.substring(0, taskId.lastIndexOf("-")).lastIndexOf("-"));
|
||||||
|
Boolean flag = creditsService.taskCreditsDeduction(Long.parseLong(accountId), uuid);
|
||||||
|
if (flag) creditsService.updateChangedCredits(accountId, uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
@@ -315,7 +319,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
text = "Flat coating,romantic,soft,pencil strokes,accentuating and widening the depth of pencil strokes,paper patterns,block colors,crayons,reducing image contrast,and hand drawn painting marks," + translated + ", fabric print, high quality";
|
text = "Flat coating,romantic,soft,pencil strokes,accentuating and widening the depth of pencil strokes,paper patterns,block colors,crayons,reducing image contrast,and hand drawn painting marks," + translated + ", fabric print, high quality";
|
||||||
} else if (userInput.contains("Real Style")) {
|
} else if (userInput.contains("Real Style")) {
|
||||||
text = "Still life photography,hyper realism,3d,deepened projection,increased permutation value,increased concavity and convexity value," + translated + ", fabric print, high quality";
|
text = "Still life photography,hyper realism,3d,deepened projection,increased permutation value,increased concavity and convexity value," + translated + ", fabric print, high quality";
|
||||||
}else {
|
} else {
|
||||||
text = translated;
|
text = translated;
|
||||||
}
|
}
|
||||||
// text = userInput + ", fabric print, high quality";
|
// text = userInput + ", fabric print, high quality";
|
||||||
@@ -475,33 +479,34 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
return new PrepareForGenerateVO(0);
|
return new PrepareForGenerateVO(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CreditsEventsEnum creditsEventsEnum = CreditsEventsEnum.NORMAL_GENERATE;
|
CreditsEventsEnum creditsEventsEnum = CreditsEventsEnum.OTHER;
|
||||||
int times = 4;
|
int times = 4;
|
||||||
// 当level1Type为Print_board时,level2Type为pattern时需要确定generateType
|
// 当level1Type为Print_board时,level2Type为pattern时需要确定generateType
|
||||||
if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())){
|
if (generateThroughImageTextDTO.getLevel1Type().equals(PRINT_BOARD.getRealName())) {
|
||||||
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getLevel2Type())){
|
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getLevel2Type())) {
|
||||||
throw new BusinessException("level2Type.cannot.be.empty");
|
throw new BusinessException("level2Type.cannot.be.empty");
|
||||||
}else if (!CollectionLevel2TypeEnum.printType().contains(generateThroughImageTextDTO.getLevel2Type())){
|
} else if (!CollectionLevel2TypeEnum.printType().contains(generateThroughImageTextDTO.getLevel2Type())) {
|
||||||
throw new BusinessException("unknown.parameter.level2Type");
|
throw new BusinessException("unknown.parameter.level2Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pattern 参数校验
|
// Pattern 参数校验
|
||||||
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.Pattern.getRealName())){
|
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.Pattern.getRealName())) {
|
||||||
String text = generateThroughImageTextDTO.getText();
|
String text = generateThroughImageTextDTO.getText();
|
||||||
Long elementId = generateThroughImageTextDTO.getCollectionElementId();
|
Long elementId = generateThroughImageTextDTO.getCollectionElementId();
|
||||||
Generate generate = new Generate();
|
Generate generate = new Generate();
|
||||||
validateGeneraType(generate, text, elementId);
|
validateGeneraType(generate, text, elementId);
|
||||||
// 校验后获取
|
// 校验后获取
|
||||||
generateThroughImageTextDTO.setGenerateType(generate.getGenerateType());
|
generateThroughImageTextDTO.setGenerateType(generate.getGenerateType());
|
||||||
|
creditsEventsEnum = CreditsEventsEnum.PATTERN;
|
||||||
}
|
}
|
||||||
// Slogan 参数校验
|
// Slogan 参数校验
|
||||||
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.SLOGAN.getRealName())){
|
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.SLOGAN.getRealName())) {
|
||||||
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getSloganBase64())){
|
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getSloganBase64())) {
|
||||||
log.error("Printboard-Slogan模式下,slogan image为空");
|
log.error("Printboard-Slogan模式下,slogan image为空");
|
||||||
throw new BusinessException("slogan.image.cannot.be.empty");
|
throw new BusinessException("slogan.image.cannot.be.empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getText())){
|
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getText())) {
|
||||||
log.error("Printboard-Slogan模式下,slogan text为空");
|
log.error("Printboard-Slogan模式下,slogan text为空");
|
||||||
throw new BusinessException("slogan.style.cannot.be.empty");
|
throw new BusinessException("slogan.style.cannot.be.empty");
|
||||||
}
|
}
|
||||||
@@ -532,20 +537,25 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Logo参数校验
|
// Logo参数校验
|
||||||
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.LOGO.getRealName())){
|
if (generateThroughImageTextDTO.getLevel2Type().equals(CollectionLevel2TypeEnum.LOGO.getRealName())) {
|
||||||
// logo模式下一次只生成一张
|
// logo模式下一次只生成一张
|
||||||
times = 1;
|
times = 1;
|
||||||
// 校验是否输入内容
|
// 校验是否输入内容
|
||||||
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getText().trim())){
|
if (StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getText().trim())) {
|
||||||
throw new BusinessException("please.input.the.prompt");
|
throw new BusinessException("please.input.the.prompt");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验seed的取值范围
|
// 校验seed的取值范围
|
||||||
int seed = Integer.parseInt(generateThroughImageTextDTO.getSeed());
|
int seed = Integer.parseInt(generateThroughImageTextDTO.getSeed());
|
||||||
if (seed < 0 || seed > 99999){
|
if (seed < 0 || seed > 99999) {
|
||||||
throw new BusinessException("the.value.range.of.seed");
|
throw new BusinessException("the.value.range.of.seed");
|
||||||
}
|
}
|
||||||
|
creditsEventsEnum = CreditsEventsEnum.LOGO;
|
||||||
}
|
}
|
||||||
|
} else if (generateThroughImageTextDTO.getLevel1Type().equals(MOOD_BOARD.getRealName())) {
|
||||||
|
creditsEventsEnum = CreditsEventsEnum.MOOD_BOARD;
|
||||||
|
} else if (generateThroughImageTextDTO.getLevel1Type().equals(SKETCH_BOARD.getRealName())) {
|
||||||
|
creditsEventsEnum = CreditsEventsEnum.SKETCH_BOARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2、判断用户当前积分是否够本次生成消耗
|
// 2、判断用户当前积分是否够本次生成消耗
|
||||||
@@ -580,6 +590,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
|
|
||||||
// 6、添加预扣除积分到redis
|
// 6、添加预扣除积分到redis
|
||||||
creditsService.addRecordToCreditsDeduction(generateThroughImageTextDTO.getUserId(), uuid, creditsEventsEnum);
|
creditsService.addRecordToCreditsDeduction(generateThroughImageTextDTO.getUserId(), uuid, creditsEventsEnum);
|
||||||
|
// 6.1 添加积分扣除记录到db
|
||||||
|
creditsService.preInsert(generateThroughImageTextDTO.getUserId(), creditsEventsEnum.getName(), uuid);
|
||||||
|
|
||||||
// 7、返回唯一id
|
// 7、返回唯一id
|
||||||
return new PrepareForGenerateVO(taskIdList, 2 - trialsCount);
|
return new PrepareForGenerateVO(taskIdList, 2 - trialsCount);
|
||||||
@@ -665,15 +677,15 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
String path;
|
String path;
|
||||||
if (type.equals("Logo")){
|
if (type.equals("Logo")) {
|
||||||
path = CommonConstant.GENERATE_LOGO_SINGLE_CANCEL;
|
path = CommonConstant.GENERATE_LOGO_SINGLE_CANCEL;
|
||||||
}else {
|
} else {
|
||||||
path = CommonConstant.GENERATE_CANCEL;
|
path = CommonConstant.GENERATE_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
String key = generateResultKey + ":" + uniqueId;
|
String key = generateResultKey + ":" + uniqueId;
|
||||||
GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class);
|
GenerateResultVO generateResultVO = new Gson().fromJson(redisUtil.getFromString(key), GenerateResultVO.class);
|
||||||
if (Objects.isNull(generateResultVO)){
|
if (Objects.isNull(generateResultVO)) {
|
||||||
log.warn("任务不存在,无法取消");
|
log.warn("任务不存在,无法取消");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user