BUGFIX:design中的排序问题 倒序问题 再次修改
This commit is contained in:
@@ -1127,7 +1127,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
@Resource
|
||||
private UserLikeGroupService userLikeGroupService;
|
||||
|
||||
public String poseTransform(PoseTransformDTO poseTransformDTO){
|
||||
public ToProductImageResultVO poseTransform(PoseTransformDTO poseTransformDTO){
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
Long projectId = poseTransformDTO.getProjectId();
|
||||
String productImage = poseTransformDTO.getProductImage();
|
||||
@@ -1164,25 +1164,33 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
poseTransformation.setCreateTime(LocalDateTime.now());
|
||||
poseTransformationMapper.insert(poseTransformation);
|
||||
// 满足条件下添加到like
|
||||
addPoseTransferLike(poseTransformDTO, poseTransformation.getId());
|
||||
userLikeGroupService.reArrangeSort(projectId, poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), poseTransformDTO.getParentId());
|
||||
Integer sort = addPoseTransferLike(poseTransformDTO, poseTransformation.getId());
|
||||
Integer reSort = userLikeGroupService.rearrangeChildSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(),
|
||||
poseTransformDTO.getParentId(), poseTransformDTO.getUserLikeSortId());
|
||||
|
||||
if (flag){
|
||||
// 6、添加预扣除积分到redis
|
||||
creditsService.addRecordToCreditsDeduction(accountId, taskId, creditsEventsEnum);
|
||||
// 6.1 添加积分扣除记录到db
|
||||
creditsService.preInsert(accountId, creditsEventsEnum.getName(), taskId, Boolean.TRUE, null);
|
||||
return taskId;
|
||||
ToProductImageResultVO toProductImageResultVO = new ToProductImageResultVO();
|
||||
toProductImageResultVO.setTaskId(taskId);
|
||||
toProductImageResultVO.setSort(Objects.isNull(reSort) ? sort : reSort);
|
||||
return toProductImageResultVO;
|
||||
}
|
||||
throw new BusinessException("pose transformation error", ResultEnum.ERROR.getCode());
|
||||
}
|
||||
|
||||
private void addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){
|
||||
private Integer addPoseTransferLike(PoseTransformDTO poseTransformDTO, Long poseTransformationId){
|
||||
if (Objects.nonNull(poseTransformDTO.getParentId())
|
||||
&& !poseTransformDTO.getParentId().equals(0L)){
|
||||
disOrLikePose(poseTransformationId, "like",
|
||||
Object object = disOrLikePose(poseTransformationId, "like",
|
||||
poseTransformDTO.getProjectId(), poseTransformDTO.getParentId());
|
||||
if (object instanceof CollectionSort){
|
||||
return ((CollectionSort) object).getSort();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Resource
|
||||
@@ -1324,13 +1332,12 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
public Object disOrLikePose(Long transformedId, String likeOrDislike, Long projectId, Long collectionSortParentId){
|
||||
PoseTransformation poseTransformation = poseTransformationMapper.selectById(transformedId);
|
||||
Long collectionSortId = null;
|
||||
CollectionSort collectionSort = null;
|
||||
if (Objects.nonNull(poseTransformation)){
|
||||
if (likeOrDislike.equals("like")){
|
||||
poseTransformation.setIsLiked((byte)1);
|
||||
if (null != collectionSortParentId) {
|
||||
CollectionSort collectionSort = designService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId);
|
||||
collectionSortId = collectionSort.getId();
|
||||
collectionSort = designService.addCollectionSort(poseTransformation.getId(), CollectionType.POSE_TRANSFORM.getValue(), projectId, collectionSortParentId);
|
||||
}
|
||||
}else if (likeOrDislike.equals("dislike")){
|
||||
poseTransformation.setIsLiked((byte)0);
|
||||
@@ -1343,8 +1350,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
if (null != collectionSortId) {
|
||||
return collectionSortId;
|
||||
if (Objects.nonNull(collectionSort)) {
|
||||
return collectionSort;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
private PoseTransformationMapper poseTransformationMapper;
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ToProductImageResult> toProduct(ToProductImageDTO toProductImageDTO) {
|
||||
public List<ToProductImageResultVO> toProduct(ToProductImageDTO toProductImageDTO) {
|
||||
// 判断用户当前积分是否够本次生成消耗
|
||||
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
||||
&& toProductImageDTO.getModelName().equals("flux");
|
||||
@@ -412,7 +412,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
toProductImageRecordMapper.insert(toProductImageRecord);
|
||||
|
||||
List<ToProductImageResult> result = new ArrayList<>();
|
||||
List<ToProductImageResultVO> result = new ArrayList<>();
|
||||
boolean childFlag = !StringUtil.isNullOrEmpty(toProductImageDTO.getAgeGroup())
|
||||
&& toProductImageDTO.getAgeGroup().equals("Child");
|
||||
int i = 0;
|
||||
@@ -456,7 +456,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}else {
|
||||
sb.append(",high quality clothing details,").append(prompt).append(",8K realistic,HDR");
|
||||
}
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
|
||||
if (fluxTask){
|
||||
if (childFlag){
|
||||
sb.append(", Children's face");
|
||||
@@ -488,11 +488,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
// 满足条件情况下默认添加到like
|
||||
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
// 重新排序
|
||||
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId());
|
||||
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
|
||||
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
|
||||
// 将生成结果的排序返回
|
||||
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
|
||||
result.add(toProductImageResult);
|
||||
}else {
|
||||
if (StringUtils.isEmpty(prompt)) {
|
||||
sb.append(",high quality clothing details,8K realistic,HDR");
|
||||
@@ -502,7 +505,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
|
||||
taskId = UUID.randomUUID() + "-" + i + "-" + userHolder.getId();
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
|
||||
|
||||
if (fluxTask){
|
||||
taskId = generateService.flux(creditsEventsEnum, sb.toString(), toProductElement.getUrl(), childFlag);
|
||||
@@ -532,11 +535,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
toProductImageResult.setResultType(CollectionType.TO_PRODUCT_IMAGE.getValue());
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
// 满足条件情况下默认添加到like
|
||||
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
// 重新排序
|
||||
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), toProductImageVO.getParentId());
|
||||
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(),
|
||||
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
|
||||
// 将生成结果的排序返回
|
||||
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
|
||||
result.add(toProductImageResult);
|
||||
}
|
||||
i ++;
|
||||
sb = new StringBuilder("The best quality, masterpiece, real image.");
|
||||
@@ -548,57 +554,39 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addToProductLike(Long parentId, Long toProductImageResultId, Long projectId){
|
||||
if (Objects.nonNull(parentId)
|
||||
&& !parentId.equals(0L)){
|
||||
productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId),
|
||||
private Integer addToProductLike(Long parentId, Long toProductImageResultId, Long projectId){
|
||||
if (Objects.nonNull(parentId) && !parentId.equals(0L)){
|
||||
CollectionSort collectionSort = productImageLike(new ProductImageLikeDTO(Collections.singletonList(toProductImageResultId),
|
||||
projectId, parentId));
|
||||
return Objects.nonNull(collectionSort) ? collectionSort.getSort() : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 只有当使用子集中的元素进行生成时,才需要重新排序
|
||||
* @param childId 生成元素的id
|
||||
* @param parentId 父级id
|
||||
* @param relationType 生成功能
|
||||
* @param userLikeSortId 子集排序表中的id
|
||||
*/
|
||||
@Transactional
|
||||
public void reArrangeSort(Long projectId, Long generateResultId, String relationType, Long parentId) {
|
||||
// 1. 处理子集排序
|
||||
rearrangeChildSort(generateResultId, parentId, relationType);
|
||||
// 2. 处理父级排序
|
||||
rearrangeParentSort(projectId, parentId);
|
||||
}
|
||||
|
||||
private void rearrangeChildSort(Long childId, Long parentId, String relationType) {
|
||||
if (Objects.isNull(childId)) {
|
||||
return;
|
||||
public Integer rearrangeChildSort(Long childId, String relationType, Long parentId, Long userLikeSortId) {
|
||||
if (Objects.isNull(userLikeSortId)) {
|
||||
return null;
|
||||
}
|
||||
CollectionSort child = collectionSortMapper.selectOne(new QueryWrapper<CollectionSort>().eq("relation_id", childId));
|
||||
if (child == null || !child.getRelationType().equals(relationType)) {
|
||||
return;
|
||||
if (!child.getRelationType().equals(relationType)) {
|
||||
return null;
|
||||
}
|
||||
if (child.getSort() == 1) {
|
||||
return; // 已经是第一位,无需处理
|
||||
}
|
||||
// 更新其他子集的排序
|
||||
if (!"Design".equals(relationType)) {
|
||||
collectionSortMapper.increaseGenerateSortBelow(parentId, relationType, child.getSort());
|
||||
}
|
||||
// 更新当前子集为第一位
|
||||
child.setSort(1);
|
||||
CollectionSort collectionSort = collectionSortMapper.selectById(userLikeSortId);
|
||||
child.setSort(collectionSort.getSort());
|
||||
// 原来排序的大于等于userLikeSortId的排序的,都要+1
|
||||
collectionSortMapper.increaseGenerateSortAbove(parentId, relationType, collectionSort.getSort() - 1);
|
||||
// 当前的生成结果则填入userLikeSortId的排序位置
|
||||
child.setUpdateTime(LocalDateTime.now());
|
||||
collectionSortMapper.updateById(child);
|
||||
}
|
||||
|
||||
private void rearrangeParentSort(Long projectId, Long parentId) {
|
||||
CollectionSort parent = collectionSortMapper.selectById(parentId);
|
||||
if (parent == null || !"Design".equals(parent.getRelationType())) {
|
||||
return;
|
||||
}
|
||||
if (parent.getSort() == 1) {
|
||||
return; // 已经是第一位,无需处理
|
||||
}
|
||||
// 更新其他父级的排序
|
||||
collectionSortMapper.increaseDesignSortBelow(projectId, "Design", parent.getSort());
|
||||
// 更新当前父级为第一位
|
||||
parent.setSort(1);
|
||||
parent.setUpdateTime(LocalDateTime.now());
|
||||
collectionSortMapper.updateById(parent);
|
||||
return collectionSort.getSort();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -690,7 +678,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long productImageLike(ProductImageLikeDTO productImageLikeDTO) {
|
||||
public CollectionSort productImageLike(ProductImageLikeDTO productImageLikeDTO) {
|
||||
List<Long> toProductImageResultId = productImageLikeDTO.getToProductImageResultId();
|
||||
QueryWrapper<ToProductImageResult> qw = new QueryWrapper<>();
|
||||
qw.lambda().in(ToProductImageResult::getId, toProductImageResultId);
|
||||
@@ -698,19 +686,17 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
toProductImageResult.setIsLike(1);
|
||||
toProductImageResultMapper.update(toProductImageResult, qw);
|
||||
ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultId.get(0));
|
||||
Long collectionSortId = null;
|
||||
CollectionSort collectionSort = null;
|
||||
if (toProductImageResult1.getResultType().equals("Relight")) {
|
||||
if (null != productImageLikeDTO.getCollectionSortParentId()) {
|
||||
CollectionSort collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
|
||||
collectionSortId = collectionSort.getId();
|
||||
collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.RELIGHT.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
|
||||
}
|
||||
}else {
|
||||
if (null != productImageLikeDTO.getCollectionSortParentId()) {
|
||||
CollectionSort collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
|
||||
collectionSortId = collectionSort.getId();
|
||||
collectionSort = designService.addCollectionSort(toProductImageResult1.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue(), productImageLikeDTO.getProjectId(), productImageLikeDTO.getCollectionSortParentId());
|
||||
}
|
||||
}
|
||||
return collectionSortId;
|
||||
return collectionSort;
|
||||
}
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@@ -1046,7 +1032,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<ToProductImageResult> relight(ToProductImageDTO toProductImageDTO) {
|
||||
public List<ToProductImageResultVO> relight(ToProductImageDTO toProductImageDTO) {
|
||||
// 判断用户当前积分是否够本次生成消耗
|
||||
boolean fluxTask = !StringUtil.isNullOrEmpty(toProductImageDTO.getModelName())
|
||||
&& toProductImageDTO.getModelName().equals("flux");
|
||||
@@ -1089,7 +1075,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
toProductImageRecordMapper.insert(toProductImageRecord);
|
||||
|
||||
List<ToProductImageResult> result = new ArrayList<>();
|
||||
List<ToProductImageResultVO> result = new ArrayList<>();
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -1108,7 +1094,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
}
|
||||
}
|
||||
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
|
||||
if (fluxTask){
|
||||
taskId = generateService.flux(creditsEventsEnum, s, toProductImageResult1.getUrl(), false);
|
||||
toProductImageResult.setModelName("flux");
|
||||
@@ -1135,14 +1121,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
|
||||
// 满足条件情况下默认添加到like
|
||||
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
// 重新排序
|
||||
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId());
|
||||
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
|
||||
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
|
||||
// 将生成结果的排序返回
|
||||
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
|
||||
result.add(toProductImageResult);
|
||||
}else {
|
||||
ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageVO.getElementId());
|
||||
ToProductImageResult toProductImageResult = new ToProductImageResult();
|
||||
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO();
|
||||
if (fluxTask){
|
||||
taskId = generateService.flux(CreditsEventsEnum.RELIGHT_FLUX, s, toProductElement.getUrl(), false);
|
||||
toProductImageResult.setModelName("flux");
|
||||
@@ -1169,11 +1159,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
toProductImageResult.setResultType(CollectionType.RELIGHT.getValue());
|
||||
toProductImageResultMapper.insert(toProductImageResult);
|
||||
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
|
||||
result.add(toProductImageResult);
|
||||
// 满足条件情况下默认添加到like
|
||||
addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
Integer sort = addToProductLike(toProductImageVO.getParentId(), toProductImageResult.getId(), toProductImageDTO.getProjectId());
|
||||
// 重新排序
|
||||
reArrangeSort(projectId, toProductImageResult.getId(), CollectionType.RELIGHT.getValue(), toProductImageVO.getParentId());
|
||||
Integer reSort = rearrangeChildSort(toProductImageResult.getId(), CollectionType.RELIGHT.getValue(),
|
||||
toProductImageVO.getParentId(), toProductImageVO.getUserLikeSortId());
|
||||
// 将生成结果的排序返回
|
||||
toProductImageResult.setSort(Objects.isNull(reSort) ? sort : reSort);
|
||||
result.add(toProductImageResult);
|
||||
}
|
||||
// 添加需要扣除的积分到预扣除区
|
||||
creditsService.addRecordToCreditsDeduction(userHolder.getId(), taskId, creditsEventsEnum);
|
||||
|
||||
Reference in New Issue
Block a user