Merge branch 'dev/dev_xp' into dev/dev

This commit is contained in:
2025-06-23 13:09:13 +08:00
5 changed files with 46 additions and 10 deletions

View File

@@ -5,6 +5,9 @@ import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
@@ -65,4 +68,11 @@ public enum CreditsEventsEnum {
return Arrays.asList(SLOGAN.name, LOGO.name, PATTERN.name, MOOD_BOARD.name, SKETCH_BOARD.name, return Arrays.asList(SLOGAN.name, LOGO.name, PATTERN.name, MOOD_BOARD.name, SKETCH_BOARD.name,
TO_PRODUCT_IMAGE.name, RELIGHT.name, IMAGE_TO_SKETCH.name, POSE_TRANSFORMATION.name); TO_PRODUCT_IMAGE.name, RELIGHT.name, IMAGE_TO_SKETCH.name, POSE_TRANSFORMATION.name);
} }
private static final Map<String, CreditsEventsEnum> BY_TASK_NAME = Arrays.stream(values())
.collect(Collectors.toMap(CreditsEventsEnum::getName, Function.identity()));
public static CreditsEventsEnum getByTaskName(String taskName){
return BY_TASK_NAME.get(taskName);
}
} }

View File

@@ -114,7 +114,8 @@ public class ElementController {
public Response<List<CollectionElementVO>> selectedImageSeg( public Response<List<CollectionElementVO>> selectedImageSeg(
@RequestPart(value = "file", required = false) MultipartFile[] file, @RequestPart(value = "file", required = false) MultipartFile[] file,
@RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "类型必须是sketch或product") String type, @RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "类型必须是sketch或product") String type,
@RequestParam(value = "id", required = false) Long id) { @RequestParam(value = "id", required = false) Long id,
@RequestParam(value = "sourceType", required = false) @Pattern(regexp = "library|upload", message = "id是从library中获取的还是上传的") String sourceType) {
// 过滤空文件 // 过滤空文件
List<MultipartFile> nonEmptyFiles = Arrays.stream(file) List<MultipartFile> nonEmptyFiles = Arrays.stream(file)
.filter(item -> !item.isEmpty()) .filter(item -> !item.isEmpty())
@@ -127,7 +128,7 @@ public class ElementController {
throw new BusinessException("不能同时提供文件上传和ID"); throw new BusinessException("不能同时提供文件上传和ID");
} }
return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type)); return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type, sourceType));
} }
} }

View File

@@ -139,6 +139,6 @@ public interface CollectionElementService extends IService<CollectionElement> {
List<CollectionElement> getByProjectId(Long projectId); List<CollectionElement> getByProjectId(Long projectId);
List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type); List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type, String sourceType);
} }

View File

@@ -991,13 +991,14 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
} }
// 对于上传图片或者从library选择的图片进行图片分割 // 对于上传图片或者从library选择的图片进行图片分割
public List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type) { public List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type, String sourceType) {
Long accountId = UserContext.getUserHolder().getId(); Long accountId = UserContext.getUserHolder().getId();
List<CollectionElementVO> resp = new ArrayList<>(); List<CollectionElementVO> resp = new ArrayList<>();
List<ImageSegmentation.ImageDate> imageDates = new ArrayList<>(); List<ImageSegmentation.ImageDate> imageDates = new ArrayList<>();
boolean isUploadMode = !files.isEmpty(); boolean isUploadMode = !files.isEmpty();
Library library = null; Library library = null;
CollectionElement collectionElement = null;
// 判断是否是上传的图片 // 判断是否是上传的图片
if (isUploadMode) { if (isUploadMode) {
@@ -1017,7 +1018,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url())); resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url()));
} }
} }
} else if (Objects.nonNull(id)) { } else if (Objects.nonNull(id) && sourceType.equals("library")) {
library = libraryService.getById(id); library = libraryService.getById(id);
// 判断从library中选择的图片是否有分割数据 // 判断从library中选择的图片是否有分割数据
if (Objects.isNull(library)) { if (Objects.isNull(library)) {
@@ -1032,6 +1033,17 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
List<String> restoredList = Arrays.asList(library.getSegmentedData().split(",")); List<String> restoredList = Arrays.asList(library.getSegmentedData().split(","));
resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), restoredList)); resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), restoredList));
} }
} else if (Objects.nonNull(id) && sourceType.equals("upload")) {
collectionElement = collectionElementMapper.selectById(id);
// 判断id对应的数据是否存在
if (Objects.isNull(collectionElement)) {
throw new BusinessException("get.file.failed");
}
// 上传的图片分割数据没存(原因:上传的数据一般不会被再次使用,存储意义不大;上传存储表中数据复杂,添加字段,浪费多)
ImageSegmentation.ImageDate imageDate = new ImageSegmentation().new ImageDate();
imageDate.setImage_url(collectionElement.getUrl());
imageDate.setImage_type(type);
imageDates.add(imageDate);
} }
// 处理需要分割的图片 // 处理需要分割的图片
@@ -1052,13 +1064,15 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
(imageData.getImage_url(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME), false); (imageData.getImage_url(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME), false);
redisUtil.addToString(key, new Gson().toJson(imageData), CommonConstant.GENERATE_RESULT_EXPIRE_TIME); redisUtil.addToString(key, new Gson().toJson(imageData), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url())); resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url()));
} else { } else if (sourceType.equals("library")){
// 从library中选择的图片需要更新数据库中对应图片的分割数据 // 从library中选择的图片需要更新数据库中对应图片的分割数据
String segmentedData = String.join(",", imageData.getClothing_url()); String segmentedData = String.join(",", imageData.getClothing_url());
library.setSegmentedData(segmentedData); library.setSegmentedData(segmentedData);
library.setUpdateDate(new Date()); library.setUpdateDate(new Date());
libraryService.updateById(library); libraryService.updateById(library);
resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), imageData.getClothing_url())); resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), imageData.getClothing_url()));
}else {
resp.add(createCollectionElementVO(accountId, id, collectionElement.getLevel1Type(), collectionElement.getUrl(), imageData.getClothing_url()));
} }
} }
} }

View File

@@ -30,6 +30,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
@Service @Service
@@ -218,7 +219,12 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
sum = sum.add(currentDeduction); sum = sum.add(currentDeduction);
// 3、获取当前积分 // 3、获取当前积分
BigDecimal existingCredits = accountMapper.selectById(accountId).getCredits(); Account account = accountMapper.selectById(accountId);
if (account == null) {
log.error("账户:{} 不存在", accountId);
throw new BusinessException("账户不存在");
}
BigDecimal existingCredits = Optional.ofNullable(account.getCredits()).orElse(BigDecimal.ZERO);
BigDecimal subtract = existingCredits.subtract(sum); BigDecimal subtract = existingCredits.subtract(sum);
// 4、判断剩余积分是否够本次操作 // 4、判断剩余积分是否够本次操作
@@ -272,6 +278,7 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
String key = creditsDeduction + ":" + accountId + ":" + taskId; String key = creditsDeduction + ":" + accountId + ":" + taskId;
// 1、获取当前任务id对应的积分 // 1、获取当前任务id对应的积分
String value = redisUtil.getFromString(key); String value = redisUtil.getFromString(key);
log.info("taskId为{},需消耗积分:{}", taskId, value);
// 1.1 没有。返回,报错,未找到当前任务 // 1.1 没有。返回,报错,未找到当前任务
if (StringUtil.isNullOrEmpty(value)) { if (StringUtil.isNullOrEmpty(value)) {
@@ -325,7 +332,11 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
String changeEvent = creditsDetail.getChangeEvent(); String changeEvent = creditsDetail.getChangeEvent();
BigDecimal currentCredits = accountMapper.selectById(accountId).getCredits(); BigDecimal currentCredits = accountMapper.selectById(accountId).getCredits();
String credits = "0"; String credits = "0";
if (changeEvent.equals("Logo") || CreditsEventsEnum eventsEnum = CreditsEventsEnum.getByTaskName(changeEvent);
if (Objects.nonNull(eventsEnum)){
credits = eventsEnum.getValue();
}
/*if (changeEvent.equals("Logo") ||
changeEvent.equals("Pattern") || changeEvent.equals("Pattern") ||
changeEvent.equals("MoodBoard") || changeEvent.equals("MoodBoard") ||
changeEvent.equals("SketchBoard")) { changeEvent.equals("SketchBoard")) {
@@ -336,10 +347,11 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
credits = CreditsEventsEnum.POSE_TRANSFORMATION.getValue(); credits = CreditsEventsEnum.POSE_TRANSFORMATION.getValue();
}else if (changeEvent.equals("Other")){ }else if (changeEvent.equals("Other")){
credits = CreditsEventsEnum.OTHER.getValue(); credits = CreditsEventsEnum.OTHER.getValue();
} }*/
// BigDecimal finalCredits = currentCredits.subtract(new BigDecimal(credits)); // BigDecimal finalCredits = currentCredits.subtract(new BigDecimal(credits));
String changeCredits = "-" + credits; String changeCredits = "-" + credits;
log.info("taskId:{},扣除的积分为:{}", taskId, changeCredits);
UpdateWrapper<CreditsDetail> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<CreditsDetail> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda() updateWrapper.lambda()
@@ -348,7 +360,6 @@ public class CreditsServiceImpl extends ServiceImpl<CreditsDetailMapper, Credits
.set(CreditsDetail::getCredits, currentCredits); .set(CreditsDetail::getCredits, currentCredits);
baseMapper.update(null, updateWrapper); baseMapper.update(null, updateWrapper);
} }
public CreditsDetail queryDetailByTaskId(String taskId) { public CreditsDetail queryDetailByTaskId(String taskId) {