diff --git a/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java b/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java index 889c51a8..64ada86f 100644 --- a/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java +++ b/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java @@ -27,6 +27,7 @@ public enum CreditsEventsEnum { MOOD_BOARD("MoodBoard","5"), SKETCH_BOARD("SketchBoard","5"), TO_PRODUCT_IMAGE("ToProductImage","5"), + RELIGHT("Relight","5"), QUESTIONNAIRE("Questionnaire","100"), OTHER("Other","5"); diff --git a/src/main/java/com/ai/da/common/utils/RedisUtil.java b/src/main/java/com/ai/da/common/utils/RedisUtil.java index e15bc5d0..0d5c6153 100644 --- a/src/main/java/com/ai/da/common/utils/RedisUtil.java +++ b/src/main/java/com/ai/da/common/utils/RedisUtil.java @@ -178,14 +178,17 @@ public class RedisUtil { } public List getLikedPortfolios(Long userId) { + // 获取所有包含PORTFOLIO_LIKE_KEY的键 Set likedPortfolios = redisTemplate.keys(PORTFOLIO_LIKE_KEY + "*"); + // 如果没有喜欢的,返回空列表 if (likedPortfolios == null || likedPortfolios.isEmpty()) { return new ArrayList<>(); } + // 过滤出包含指定用户ID的键,并提取投资组合ID return likedPortfolios.stream() - .filter(key -> redisTemplate.opsForSet().isMember(key, userId.toString())) + .filter(key -> redisTemplate.opsForSet().isMember(key, String.valueOf(userId))) .map(key -> Long.valueOf(key.replace(PORTFOLIO_LIKE_KEY, ""))) .collect(Collectors.toList()); } diff --git a/src/main/java/com/ai/da/model/vo/PortfolioVO.java b/src/main/java/com/ai/da/model/vo/PortfolioVO.java index fb7b7366..6ccc2352 100644 --- a/src/main/java/com/ai/da/model/vo/PortfolioVO.java +++ b/src/main/java/com/ai/da/model/vo/PortfolioVO.java @@ -22,4 +22,8 @@ public class PortfolioVO extends Portfolio { private String originalUserName; private String originalPortfolioName; + + private Integer isMine; + + private Integer selected; } diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index c5c5132e..a13db92f 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -3311,7 +3311,7 @@ public class PythonService { return text; } - public Boolean toProductImage(String url, String taskId, String prompt, BigDecimal imageStrength) { + public Boolean toProductImage(String url, String taskId, String prompt, BigDecimal imageStrength, String productType) { // todo 限流校验 // AccessLimitUtils.validate("design",5); OkHttpClient client = new OkHttpClient().newBuilder() @@ -3327,6 +3327,7 @@ public class PythonService { map.put("image_url", url); map.put("prompt", prompt); map.put("image_strength", imageStrength); + map.put("product_type", productType); log.info("toProductImage请求python 参数:####{}", map); String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty); System.out.println(param); @@ -3334,7 +3335,7 @@ public class PythonService { Request request = new Request.Builder() // .url(accessPythonIp + ":" + accessPythonPort + "/api/generate_product_image") // .url(accessPythonIp + ":9996/api/generate_product_image") - .url(accessPythonIp + ":9994/api/generate_product_image") + .url(accessPythonIp + ":9996/api/generate_product_image") .method("POST", body) .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==") .addHeader("Content-Type", "application/json") @@ -3355,7 +3356,7 @@ public class PythonService { throw new BusinessException("toProductImage.interface.exception"); } - public Boolean relight(String url, String taskId, String prompt, String direction) { + public Boolean relight(String url, String taskId, String prompt, String direction, String relightType) { // todo 限流校验 // AccessLimitUtils.validate("design",5); OkHttpClient client = new OkHttpClient().newBuilder() @@ -3371,6 +3372,7 @@ public class PythonService { map.put("image_url", url); map.put("prompt", prompt); map.put("direction", direction); + map.put("product_type", relightType); log.info("relightImage请求python 参数:####{}", map); String param = JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty); log.info(param); diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 15703886..528159bc 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -742,6 +742,17 @@ public class GenerateServiceImpl extends ServiceImpl i String status = imageName.equals("white_image.jpg") ? "Invalid" : "Success"; GenerateResultVO generateResultVO = new GenerateResultVO(taskId, toProductImageResult.getId(), url, status, category); redisUtil.addToString(key, new Gson().toJson(generateResultVO), CommonConstant.GENERATE_RESULT_EXPIRE_TIME); + + Long accountId = Long.parseLong(taskId.substring(taskId.lastIndexOf("-") + 1)); + if (!status.equals("Invalid")){ + // 4、扣除积分 + Boolean b = creditsService.taskCreditsDeduction(accountId, taskId); + // 3、记录积分变更 + if (b) creditsService.insertToCreditsDetail(accountId, + CreditsEventsEnum.RELIGHT.getName(), + CreditsEventsEnum.RELIGHT.getValue(), + "negative"); + } } // 判断试用用户试用generate机会是否使用完毕 每个board 3次机会 diff --git a/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java b/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java index 356ca744..4e104c83 100644 --- a/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PortfolioServiceImpl.java @@ -425,7 +425,7 @@ public class PortfolioServiceImpl extends ServiceImpl likedPortfolioIdList = redisUtil.getLikedPortfolios(userHolder.getId()); + List likedPortfolioIdList = redisUtil.getLikedPortfolios(88L); if (!CollectionUtils.isEmpty(likedPortfolioIdList)) { qw.lambda().in(Portfolio::getId, likedPortfolioIdList); } @@ -494,6 +494,27 @@ public class PortfolioServiceImpl extends ServiceImpl getSelectedQw = new QueryWrapper<>(); + getSelectedQw.lambda().eq(UserLikeGroup::getAccountId, userHolder.getId()); + getSelectedQw.lambda().eq(UserLikeGroup::getOriginalPortfolioId, vo.getId()); + List userLikeGroups = userLikeGroupMapper.selectList(getSelectedQw); + if (CollectionUtils.isEmpty(userLikeGroups)) { + vo.setSelected(0); + }else { + vo.setSelected(1); + } + } + } + return vo; } @@ -650,7 +671,15 @@ public class PortfolioServiceImpl extends ServiceImpl existSameNameQw = new QueryWrapper<>(); + existSameNameQw.lambda().eq(Workspace::getWorkSpaceName, workspaceName); + existSameNameQw.lambda().eq(Workspace::getAccountId, authPrincipalVo.getId()); + List existSameNameList = workspaceMapper.selectList(existSameNameQw); + if (!CollectionUtils.isEmpty(existSameNameList)) { + workspaceName = workspaceName + "_copy"; + } + workspaceNew.setWorkSpaceName(workspaceName); workspaceNew.setAccountId(accountId); workspaceNew.setIsDeleted(0); workspaceNew.setIsLastIndex(1); diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 92673484..4ff57b99 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -253,8 +253,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl relight(ToProductImageDTO toProductImageDTO) { + // 判断用户当前积分是否够本次生成消耗 + Boolean preDeduction = creditsService.creditsPreDeduction(CreditsEventsEnum.RELIGHT, toProductImageDTO.getToProductImageVOList().size()); + if (!preDeduction) { + throw new BusinessException("Not enough Credits"); + } + AuthPrincipalVo userHolder = UserContext.getUserHolder(); Long userLikeGroupId = toProductImageDTO.getUserLikeGroupId(); ToProductImageRecord toProductImageRecord = new ToProductImageRecord(); @@ -474,12 +486,22 @@ public class UserLikeGroupServiceImpl extends ServiceImpl