|
@@ -24,6 +24,8 @@ import org.dromara.system.service.IEnrollService;
|
|
|
import org.dromara.system.service.IGameAthleteService;
|
|
|
import org.dromara.system.service.IGameEventProjectService;
|
|
|
import org.dromara.system.service.IGameTeamService;
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
+import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -39,11 +41,17 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@RequiredArgsConstructor
|
|
|
@Service
|
|
|
-public class IEnrollServiceImpl implements IEnrollService {
|
|
|
+public class IEnrollServiceImpl implements IEnrollService, ApplicationContextAware {
|
|
|
|
|
|
private final IGameEventProjectService gameEventProjectService;
|
|
|
private final IGameTeamService gameTeamService;
|
|
|
private final IGameAthleteService gameAthleteService;
|
|
|
+ private ApplicationContext applicationContext;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setApplicationContext(ApplicationContext applicationContext) {
|
|
|
+ this.applicationContext = applicationContext;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 使用poi生成报名表模板
|
|
@@ -189,8 +197,18 @@ public class IEnrollServiceImpl implements IEnrollService {
|
|
|
// }
|
|
|
//1.解析报名信息
|
|
|
List<EnrollProjectVo> enrollList = parseData(file);
|
|
|
- //2.保存报名信息
|
|
|
- return this.saveEnrollData(enrollList, eventId);
|
|
|
+ //2.通过代理对象调用,确保事务生效
|
|
|
+ return getSelf().saveEnrollData(enrollList, eventId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取代理对象
|
|
|
+ */
|
|
|
+ private IEnrollServiceImpl getSelf() {
|
|
|
+ // 方式1:通过ApplicationContext获取代理bean
|
|
|
+ return applicationContext.getBean(IEnrollServiceImpl.class);
|
|
|
+ // 方式2:使用AopContext(需要开启@EnableAspectJAutoProxy(exposeProxy = true))
|
|
|
+ // return (GameEventService) AopContext.currentProxy();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -541,6 +559,7 @@ public class IEnrollServiceImpl implements IEnrollService {
|
|
|
// }
|
|
|
// return true;
|
|
|
// }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean saveEnrollData(List<EnrollProjectVo> dataList, Long eventId) {
|
|
|
// 1. 根据队伍分类成Map
|
|
@@ -576,7 +595,6 @@ public class IEnrollServiceImpl implements IEnrollService {
|
|
|
for (Map.Entry<String, List<EnrollProjectVo>> entry : groupedByTeam.entrySet()) {
|
|
|
String teamName = entry.getKey();
|
|
|
List<EnrollProjectVo> athletes = entry.getValue();
|
|
|
-
|
|
|
Long teamId;
|
|
|
AtomicInteger currentNumber;
|
|
|
boolean isNewTeam = false;
|