refactor(service): 为服务类添加全局事务管理
- 在 GroupingServiceImpl、ImageServiceImpl、MarkdownFileServiceImpl、RegistrationCodeServiceImpl、SystemSettingServiceImpl、TrashServiceImpl 和 UserServiceImpl 类上添加了 @Transactional 注解- 移除了 GroupingServiceImpl 中的局部 @Transactional 注解 - 此修改确保了每个服务类
This commit is contained in:
@@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class GroupingServiceImpl
|
public class GroupingServiceImpl
|
||||||
extends ServiceImpl<GroupingMapper, Grouping>
|
extends ServiceImpl<GroupingMapper, Grouping>
|
||||||
implements GroupingService {
|
implements GroupingService {
|
||||||
@@ -52,7 +53,6 @@ public class GroupingServiceImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
|
||||||
public void deleteGrouping(Long id) {
|
public void deleteGrouping(Long id) {
|
||||||
// 1. 使用 LambdaUpdateWrapper 软删除分组本身,确保 isDeleted 和 deletedAt 都被更新
|
// 1. 使用 LambdaUpdateWrapper 软删除分组本身,确保 isDeleted 和 deletedAt 都被更新
|
||||||
LambdaUpdateWrapper<Grouping> groupingUpdateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<Grouping> groupingUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.test.bijihoudaun.service.ImageService;
|
|||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -23,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class ImageServiceImpl
|
public class ImageServiceImpl
|
||||||
extends ServiceImpl<ImageMapper, Image>
|
extends ServiceImpl<ImageMapper, Image>
|
||||||
implements ImageService {
|
implements ImageService {
|
||||||
|
|||||||
@@ -16,11 +16,13 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class MarkdownFileServiceImpl
|
public class MarkdownFileServiceImpl
|
||||||
extends ServiceImpl<MarkdownFileMapper, MarkdownFile>
|
extends ServiceImpl<MarkdownFileMapper, MarkdownFile>
|
||||||
implements MarkdownFileService {
|
implements MarkdownFileService {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class RegistrationCodeServiceImpl extends ServiceImpl<RegistrationCodeMapper, RegistrationCode> implements RegistrationCodeService {
|
public class RegistrationCodeServiceImpl extends ServiceImpl<RegistrationCodeMapper, RegistrationCode> implements RegistrationCodeService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import com.test.bijihoudaun.entity.SystemSetting;
|
|||||||
import com.test.bijihoudaun.mapper.SystemSettingMapper;
|
import com.test.bijihoudaun.mapper.SystemSettingMapper;
|
||||||
import com.test.bijihoudaun.service.SystemSettingService;
|
import com.test.bijihoudaun.service.SystemSettingService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class SystemSettingServiceImpl extends ServiceImpl<SystemSettingMapper, SystemSetting> implements SystemSettingService {
|
public class SystemSettingServiceImpl extends ServiceImpl<SystemSettingMapper, SystemSetting> implements SystemSettingService {
|
||||||
|
|
||||||
private static final String REGISTRATION_ENABLED_KEY = "registration.enabled";
|
private static final String REGISTRATION_ENABLED_KEY = "registration.enabled";
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class TrashServiceImpl implements TrashService {
|
public class TrashServiceImpl implements TrashService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -17,12 +17,14 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService, UserDetailsService {
|
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService, UserDetailsService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
Reference in New Issue
Block a user