From 4ce6fb4190a4370e14a7aff236d17b896b8c4dd2 Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 13 Oct 2025 13:50:51 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=E4=B8=BAdesign=E7=9A=84=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=EF=BC=88collection=5Fsort=EF=BC=89=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E7=BA=A6=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/AccountServiceImpl.java | 2 + .../impl/CollectionSortServiceImpl.java | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java index d5a2daee..6fe96c43 100644 --- a/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/AccountServiceImpl.java @@ -2550,6 +2550,8 @@ public class AccountServiceImpl extends ServiceImpl impl } subAccount.setSystemUser(subUserRole); subAccount.setLanguage(Language.ENGLISH.name()); + subAccount.setValidStartTime(adminAcc.getValidStartTime()); + subAccount.setValidEndTime(adminAcc.getValidEndTime()); subAccount.setCreateDate(new Date()); subAccount.setIsTrial(0); subAccount.setIsBeginner(1); diff --git a/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java index b970201b..d922754d 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionSortServiceImpl.java @@ -1,5 +1,6 @@ package com.ai.da.service.impl; +import com.ai.da.common.config.exception.BusinessException; import com.ai.da.mapper.primary.CollectionSortMapper; import com.ai.da.mapper.primary.entity.CollectionSort; import com.ai.da.model.dto.CollectionSortDTO; @@ -8,12 +9,14 @@ import com.ai.da.service.CollectionSortService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.List; +import java.util.Map; import java.util.Objects; @Slf4j @@ -50,7 +53,7 @@ public class CollectionSortServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); qw.lambda().eq(CollectionSort::getProjectId, projectId); @@ -64,6 +67,39 @@ public class CollectionSortServiceImpl extends ServiceImpl 0) { + try { + Integer maxSort = getMaxSortFromDB(projectId, parentId); + return maxSort + 1; + } catch (DuplicateKeyException e) { + // 如果发生唯一约束冲突,重试 + if (retryCount == 0) { + throw new BusinessException("获取排序号失败,请重试"); + } + } + } + throw new BusinessException("获取排序号失败"); + } + + private Integer getMaxSortFromDB(Long projectId, Long parentId) { + QueryWrapper qw = new QueryWrapper<>(); + qw.select("COALESCE(MAX(sort), 0) as maxSort") + .eq("project_id", projectId); + + if (null != parentId) { + qw.eq("parent_id", parentId); + } else { + qw.isNull("parent_id"); + } + + Map result = baseMapper.selectMaps(qw).get(0); + return (Integer) result.get("maxSort"); } @Override