|
@@ -7,15 +7,17 @@ import cn.iselab.mooctest.site.models.*;
|
|
|
import cn.iselab.mooctest.site.service.CompetitionService;
|
|
|
import cn.iselab.mooctest.site.web.data.AddonsVO;
|
|
|
import org.apache.commons.collections.IteratorUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @author tangshanshan
|
|
|
* @date 2017/11/3
|
|
|
*/
|
|
@@ -61,7 +63,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
|
|
|
@Override
|
|
|
public Qualification getQualification(Long competitionId, Long userId) {
|
|
|
- return qualificationDao.findLatestQulificationByCompetitionIdAndUserId(competitionId,userId);
|
|
|
+ return qualificationDao.findLatestQulificationByCompetitionIdAndUserId(competitionId, userId);
|
|
|
}
|
|
|
|
|
|
// @Override
|
|
@@ -78,7 +80,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
Qualification qualification1 = qualificationDao.findByCompetitionIdAndUserIdAndStatus(qualification.getCompetitionId(),
|
|
|
qualification.getUserId(), qualification.getStatus());
|
|
|
//System.out.println(qualification1.toString());
|
|
|
- if(qualification1 == null) {
|
|
|
+ if (qualification1 == null) {
|
|
|
//修改原有数据
|
|
|
|
|
|
//插入新数据
|
|
@@ -91,6 +93,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
}
|
|
|
return qualification1;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public List<Qualification> getQualificationByCompetitionIdAndIndex(Long competitionId, Integer status) {
|
|
|
return qualificationDao.findByCompetitionIdAndStatus(competitionId, status);
|
|
@@ -123,7 +126,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
competition2Exam.setCompetitionId(competitionId);
|
|
|
int index = 1;
|
|
|
ArrayList<Competition2Exam> competition2Exams = competition2ExamDao.findByCompetitionIdOrderByIndexDesc(competitionId);
|
|
|
- if (competition2Exams.size()>0) {
|
|
|
+ if (competition2Exams.size() > 0) {
|
|
|
index = competition2Exams.get(0).getIndex() + 1;
|
|
|
}
|
|
|
competition2Exam.setIndex(index);
|
|
@@ -139,15 +142,15 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
|
|
|
@Override
|
|
|
public List<AddOns2Qualification> updateAddons(List<AddOns2Qualification> addonsList, Long qualificationId, Integer type) {
|
|
|
- List<AddOns2Qualification> deletedAddons = addOns2QualificationDao.findByQualificationIdAndAddonsType(qualificationId,type);
|
|
|
+ List<AddOns2Qualification> deletedAddons = addOns2QualificationDao.findByQualificationIdAndAddonsType(qualificationId, type);
|
|
|
addOns2QualificationDao.delete(deletedAddons);
|
|
|
|
|
|
List<AddOns2Qualification> savedAddons = IteratorUtils.toList(addOns2QualificationDao.save(addonsList).iterator());
|
|
|
|
|
|
List<String> changedAddons = deletedAddons.stream().map(AddOns2Qualification::getEmail).collect(Collectors.toList());
|
|
|
changedAddons.addAll(savedAddons.stream().map(AddOns2Qualification::getEmail).collect(Collectors.toList()));
|
|
|
- if(type == AddOns2Qualification.ADDONS_TYPE_TEACHER){
|
|
|
- eventUtil.post(new UpdateContestMentorEvent(qualificationId,changedAddons));
|
|
|
+ if (type == AddOns2Qualification.ADDONS_TYPE_TEACHER) {
|
|
|
+ eventUtil.post(new UpdateContestMentorEvent(qualificationId, changedAddons));
|
|
|
}
|
|
|
return savedAddons;
|
|
|
}
|
|
@@ -164,6 +167,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
competition2ExamDao.save(result);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public Competition2Exam getCompetition2TaskbyCompetitionIdAndIndex(Long competitionId, Integer index) {
|
|
|
return competition2ExamDao.findByCompetitionIdAndIndex(competitionId, index);
|
|
@@ -172,7 +176,7 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
@Override
|
|
|
public Competition2Exam updateCompetition2TaskbyCompetitionIdAndIndex(Long competitionId, Integer index, boolean activeStatusAfterUpdating) {
|
|
|
Competition2Exam result = competition2ExamDao.findByCompetitionIdAndIndex(competitionId, index);
|
|
|
- if(result.isActive() == activeStatusAfterUpdating) {
|
|
|
+ if (result.isActive() == activeStatusAfterUpdating) {
|
|
|
return result;
|
|
|
}
|
|
|
result.setActive(activeStatusAfterUpdating);
|
|
@@ -180,12 +184,26 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public boolean checkAddons(List<AddonsVO> addonsList, Long qualificationId, Integer type) {
|
|
|
- if (type == null)
|
|
|
- return false;
|
|
|
- if (type == 0)
|
|
|
- return true;
|
|
|
+ public Map<String, Object> checkAddons(List<AddonsVO> addonsList, Long qualificationId, Integer type) {
|
|
|
+ Map<String, Object> res = new HashMap<>();
|
|
|
+// if (type == null)
|
|
|
+// return false;
|
|
|
+// if (type == 0)
|
|
|
+// return true;
|
|
|
+ if (type == null) {
|
|
|
+ res.put("code", 1);
|
|
|
+ res.put("message", "类型出错");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ if (type == 0) {
|
|
|
+ res.put("code", 0);
|
|
|
+ res.put("message", "修改成功");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ //获取当前用户信息
|
|
|
+ Long currentUserId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
//获取当前队伍比赛信息
|
|
|
Qualification qualification = qualificationDao.findOne(qualificationId);
|
|
|
//获取所有参加当前比赛的队伍
|
|
@@ -199,7 +217,10 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
for (AddonsVO currAddons : addonsList) {
|
|
|
//如果信息已存在则返回错误
|
|
|
if (currAddons.getEmail().equals(addons.getEmail())) {
|
|
|
- return false;
|
|
|
+ res.put("code", 2);
|
|
|
+ res.put("message", "修改失败,队员'"+addons.getEmail()+"'已加入其它队伍!");
|
|
|
+ return res;
|
|
|
+ //return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -209,15 +230,54 @@ public class CompetitionServiceImpl implements CompetitionService {
|
|
|
for (AddonsVO addonsVO : addonsList) {
|
|
|
User user = userDao.findByEmail(addonsVO.getEmail());
|
|
|
if (null != user) {
|
|
|
+ //查看添加的队员是否为当前登录用户
|
|
|
+ if (user.getId().equals(currentUserId)){
|
|
|
+ res.put("code", 4);
|
|
|
+ res.put("message", "修改失败,队员'"+user.getEmail()+"'已是队长,无法添加为队员");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
for (Qualification temp : qualifications) {
|
|
|
if (temp.getUserId().equals(user.getId())) {
|
|
|
- return false;
|
|
|
+ res.put("code", 3);
|
|
|
+ res.put("message", "修改失败,队员'"+user.getEmail()+"'已是其他队伍的队长");
|
|
|
+ return res;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //默认返回
|
|
|
- return true;
|
|
|
+ res.put("code", 0);
|
|
|
+ res.put("message", "修改成功");
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> checkEnterCompetition(Long competitionId, Long userId){
|
|
|
+ //获取所有competitionId与当前参加的比赛id相同的队伍
|
|
|
+ List<Qualification> qualifications = qualificationDao.findByCompetitionId(competitionId);
|
|
|
+ //获取当前用户信息
|
|
|
+ User user = userDao.findById(userId);
|
|
|
+ Map<String, Object> res = new HashMap<>();
|
|
|
+ for (Qualification qualification : qualifications){
|
|
|
+ Long captainId = qualification.getUserId();
|
|
|
+ //当队长id与参赛的id相同,说明该用户已经是其他队伍的队长,返回错误信息
|
|
|
+ if (captainId.equals(userId)){
|
|
|
+ res.put("code", 1);
|
|
|
+ res.put("message", "您(" + user.getEmail() + ")已参加该比赛,无法再次报名");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ //获取该队伍的所有队员信息
|
|
|
+ List<AddOns2Qualification> addOns2Qualifications = addOns2QualificationDao.findByQualificationId(qualification.getId());
|
|
|
+ //遍历所有队员信息,如果存在队员邮箱与当前用户邮箱相同,说明该用户已加入其他队伍,返回错误信息
|
|
|
+ for (AddOns2Qualification addOns2Qualification:addOns2Qualifications){
|
|
|
+ if (addOns2Qualification.getEmail().equals(user.getEmail())){
|
|
|
+ res.put("code", 2);
|
|
|
+ res.put("message", "您(" + user.getEmail() + ")已加入其他队伍,无法再次报名");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.put("code", 0);
|
|
|
+ res.put("message", "加入成功");
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|