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