diff --git a/src/main/java/com/peteralbus/controller/StudentController.java b/src/main/java/com/peteralbus/controller/StudentController.java index 1eef99e..72ee38b 100644 --- a/src/main/java/com/peteralbus/controller/StudentController.java +++ b/src/main/java/com/peteralbus/controller/StudentController.java @@ -56,8 +56,7 @@ public class StudentController Participate participate=participateService.getByUserAndActivity(user.getUserId(), activityId); if(participate!=null) { - modelAndView.setViewName("redirect: /student/manageActivity?activityId="+activityId); - return modelAndView; + return new ModelAndView("redirect: /student/manageActivity?activityId="+activityId); } modelAndView.addObject("activity",activity); List groupList=groupService.getGroupListByActivity(activityId); @@ -71,34 +70,61 @@ public class StudentController ModelAndView modelAndView=PrincipalUtil.getBasicModelAndView(); Subject subject = SecurityUtils.getSubject(); User user=(User)subject.getPrincipal(); + modelAndView.addObject("userId",user.getUserId()); Activity activity= activityService.getActivityById(activityId); Participate participate=participateService.getByUserAndActivity(user.getUserId(), activityId); if(participate==null) { throw new UnauthorizedException(); } - Long memberCount=groupService.getMemberCount(participate.getGroupId()); - if(memberCount<=activity.getMinPeople()) + Group group=groupService.getById(participate.getGroupId()); + Long memberCount=groupService.getMemberCount(group.getGroupId()); + List memberList=groupService.getGroupMember(group.getGroupId()); + modelAndView.addObject("group",group); + modelAndView.addObject("memberList",memberList); + if(participate.getAccept()) { - if(participate.getAccept()) + if(memberCount getGroupMember(Long groupId) + { + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("group_id",groupId); + List memberList=participateDao.selectList(queryWrapper); + for(Participate participate:memberList) + { + User user= userDao.selectById(participate.getUserId()); + participate.setUsername(user.getUsername()); + participate.setRealName(user.getRealName()); + } + return memberList; + } public int insertGroup(Group group) { return groupDao.insert(group); diff --git a/src/main/java/com/peteralbus/service/ParticipateService.java b/src/main/java/com/peteralbus/service/ParticipateService.java index 49c1550..0f6c868 100644 --- a/src/main/java/com/peteralbus/service/ParticipateService.java +++ b/src/main/java/com/peteralbus/service/ParticipateService.java @@ -7,6 +7,7 @@ import com.peteralbus.entity.Group; import com.peteralbus.entity.Participate; import com.peteralbus.entity.User; import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authz.UnauthorizedException; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -59,4 +60,33 @@ public class ParticipateService participate.setAccept(false); return participateDao.insert(participate); } + public int acceptJoin(Long participateId) + { + Participate participate=participateDao.selectById(participateId); + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + if(groupDao.selectById(participate.getGroupId()).getLeaderId().equals(user.getUserId())) + { + participate.setAccept(true); + return participateDao.updateById(participate); + } + else + { + throw new UnauthorizedException(); + } + } + public int refuseJoin(Long participateId) + { + Participate participate=participateDao.selectById(participateId); + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + if(groupDao.selectById(participate.getGroupId()).getLeaderId().equals(user.getUserId())) + { + return participateDao.deleteById(participate); + } + else + { + throw new UnauthorizedException(); + } + } } diff --git a/src/main/resources/mapper/ActivityDao.xml b/src/main/resources/mapper/ActivityDao.xml index cadc46c..4ea00ab 100644 --- a/src/main/resources/mapper/ActivityDao.xml +++ b/src/main/resources/mapper/ActivityDao.xml @@ -6,12 +6,12 @@