diff --git a/src/main/java/com/peteralbus/controller/PageController.java b/src/main/java/com/peteralbus/controller/PageController.java index 351f947..17cc19b 100644 --- a/src/main/java/com/peteralbus/controller/PageController.java +++ b/src/main/java/com/peteralbus/controller/PageController.java @@ -5,7 +5,9 @@ import com.peteralbus.util.PrincipalUtil; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; /** diff --git a/src/main/java/com/peteralbus/controller/StudentController.java b/src/main/java/com/peteralbus/controller/StudentController.java index e4fb3e8..d0ea050 100644 --- a/src/main/java/com/peteralbus/controller/StudentController.java +++ b/src/main/java/com/peteralbus/controller/StudentController.java @@ -5,6 +5,7 @@ import com.peteralbus.entity.Group; import com.peteralbus.entity.User; import com.peteralbus.service.ActivityService; import com.peteralbus.service.GroupService; +import com.peteralbus.service.ParticipateService; import com.peteralbus.util.PrincipalUtil; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; @@ -28,6 +29,8 @@ public class StudentController ActivityService activityService; @Autowired GroupService groupService; + @Autowired + ParticipateService participateService; @RequestMapping("/activities") public ModelAndView activities() { @@ -48,22 +51,47 @@ public class StudentController Activity activity= activityService.getActivityById(activityId); modelAndView.addObject("activity",activity); List groupList=groupService.getGroupListByActivity(activityId); - modelAndView.addObject(groupList); + modelAndView.addObject("groupList",groupList); modelAndView.setViewName("/jsp/student/applyActivity.jsp"); return modelAndView; } + public ModelAndView manageActivity(Long activityId) + { + ModelAndView modelAndView=PrincipalUtil.getBasicModelAndView(); + modelAndView.setViewName("/jsp/student/manageActivity.jsp"); + return modelAndView; + } @ResponseBody @RequestMapping("/participateWithNewGroup") public String participateWithNewGroup(Group group) { - int result=activityService.participateWithNewGroup(group); + int result=participateService.participateWithNewGroup(group); + if(result>0) + { + return "success"; + } + else + { + return "error"; + } + } + @ResponseBody + @RequestMapping("/participateWithOldGroup") + public String participateWithOldGroup(Long groupId) + { + Group group=groupService.getById(groupId); + if(group==null) + { + return "error:未找到该小组"; + } + int result=participateService.participateWithOldGroup(group); if(result>0) { return "success"; } else { - return "fail"; + return "error"; } } } diff --git a/src/main/java/com/peteralbus/entity/Group.java b/src/main/java/com/peteralbus/entity/Group.java index 698a9db..67e354b 100644 --- a/src/main/java/com/peteralbus/entity/Group.java +++ b/src/main/java/com/peteralbus/entity/Group.java @@ -6,6 +6,7 @@ import org.springframework.format.annotation.DateTimeFormat; import java.io.Serializable; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * The type Group. @@ -18,6 +19,8 @@ public class Group implements Serializable private Long groupId; private String groupName; private Long leaderId; + @TableField(exist = false) + private String leaderName; private Long activityId; @Version private Integer version; @@ -92,6 +95,11 @@ public class Group implements Serializable this.gmtCreate = gmtCreate; } + public String getFormattedCreateDate(){ + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return getGmtCreate().format(formatter); + } + public LocalDateTime getGmtModified() { return gmtModified; @@ -112,6 +120,16 @@ public class Group implements Serializable this.isDelete = isDelete; } + public String getLeaderName() + { + return leaderName; + } + + public void setLeaderName(String leaderName) + { + this.leaderName = leaderName; + } + @Override public String toString() { @@ -119,6 +137,7 @@ public class Group implements Serializable "groupId=" + groupId + ", groupName='" + groupName + '\'' + ", leaderId=" + leaderId + + ", leaderName='" + leaderName + '\'' + ", activityId=" + activityId + ", version=" + version + ", gmtCreate=" + gmtCreate + diff --git a/src/main/java/com/peteralbus/service/ActivityService.java b/src/main/java/com/peteralbus/service/ActivityService.java index 87c3772..914ea4b 100644 --- a/src/main/java/com/peteralbus/service/ActivityService.java +++ b/src/main/java/com/peteralbus/service/ActivityService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peteralbus.dao.ActivityDao; import com.peteralbus.dao.GroupDao; import com.peteralbus.dao.ManageDao; +import com.peteralbus.dao.ParticipateDao; import com.peteralbus.entity.*; import com.sun.org.apache.xpath.internal.operations.Bool; import org.apache.shiro.SecurityUtils; @@ -25,9 +26,9 @@ public class ActivityService @Autowired private ActivityDao activityDao; @Autowired - private GroupService groupService; + private GroupDao groupDao; @Autowired - private ParticipateService participateService; + private ParticipateDao participateDao; @Autowired private ManageDao manageDao; public int addActivity(Activity activity) @@ -91,24 +92,6 @@ public class ActivityService } return activityList; } - public int participateWithNewGroup(Group group) - { - Subject subject = SecurityUtils.getSubject(); - User user=(User)subject.getPrincipal(); - group.setLeaderId(user.getUserId()); - int result=groupService.insertGroup(group); - if(result>0) - { - Participate participate=new Participate(); - participate.setUserId(group.getLeaderId()); - participate.setGroupId(group.getGroupId()); - participate.setActivityId(group.getActivityId()); - participate.setFinished(false); - participate.setAccept(true); - result=participateService.insertParticipate(participate); - } - return result; - } public int getCount() { return activityDao.getCount(); diff --git a/src/main/java/com/peteralbus/service/GroupService.java b/src/main/java/com/peteralbus/service/GroupService.java index 697fd80..9034fd6 100644 --- a/src/main/java/com/peteralbus/service/GroupService.java +++ b/src/main/java/com/peteralbus/service/GroupService.java @@ -2,7 +2,9 @@ package com.peteralbus.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peteralbus.dao.GroupDao; +import com.peteralbus.dao.UserDao; import com.peteralbus.entity.Group; +import com.peteralbus.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -17,11 +19,23 @@ public class GroupService { @Autowired GroupDao groupDao; + @Autowired + UserDao userDao; public List getGroupListByActivity(Long activityId) { QueryWrapper queryWrapper=new QueryWrapper<>(); queryWrapper.eq("activity_id",activityId); - return groupDao.selectList(queryWrapper); + List groupList=groupDao.selectList(queryWrapper); + for(Group group:groupList) + { + User user=userDao.selectById(group.getLeaderId()); + group.setLeaderName(user.getRealName()); + } + return groupList; + } + public Group getById(Long groupId) + { + return groupDao.selectById(groupId); } public int insertGroup(Group group) { diff --git a/src/main/java/com/peteralbus/service/ParticipateService.java b/src/main/java/com/peteralbus/service/ParticipateService.java index b1d27eb..3e8dbab 100644 --- a/src/main/java/com/peteralbus/service/ParticipateService.java +++ b/src/main/java/com/peteralbus/service/ParticipateService.java @@ -1,7 +1,12 @@ package com.peteralbus.service; +import com.peteralbus.dao.GroupDao; import com.peteralbus.dao.ParticipateDao; +import com.peteralbus.entity.Group; import com.peteralbus.entity.Participate; +import com.peteralbus.entity.User; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -10,8 +15,40 @@ public class ParticipateService { @Autowired ParticipateDao participateDao; + @Autowired + GroupDao groupDao; public int insertParticipate(Participate participate) { return participateDao.insert(participate); } + public int participateWithNewGroup(Group group) + { + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + group.setLeaderId(user.getUserId()); + int result=groupDao.insert(group); + if(result>0) + { + Participate participate=new Participate(); + participate.setUserId(group.getLeaderId()); + participate.setGroupId(group.getGroupId()); + participate.setActivityId(group.getActivityId()); + participate.setFinished(false); + participate.setAccept(true); + result=participateDao.insert(participate); + } + return result; + } + public int participateWithOldGroup(Group group) + { + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + Participate participate=new Participate(); + participate.setUserId(user.getUserId()); + participate.setGroupId(group.getGroupId()); + participate.setActivityId(group.getActivityId()); + participate.setFinished(false); + participate.setAccept(false); + return participateDao.insert(participate); + } } diff --git a/src/main/webapp/jsp/student/activities.jsp b/src/main/webapp/jsp/student/activities.jsp index 65a9819..7d3bddc 100644 --- a/src/main/webapp/jsp/student/activities.jsp +++ b/src/main/webapp/jsp/student/activities.jsp @@ -49,6 +49,12 @@ {{showedActivity.activityType}} + + + {{showedActivity.minPeople}}-{{showedActivity.maxPeople}}人 +
负责老师:{{i.realName}} 
+

要求人数:{{item.minPeople}}-{{item.maxPeople}}人

{{item.activityIntroduction}}
所有活动 -
+
+ + +
+
负责老师:{{i.realName}} 
+

要求人数:{{item.minPeople}}-{{item.maxPeople}}人

{{item.activityIntroduction}}

@@ -144,6 +162,8 @@ activityIntroduction:'' }, dialogVisible:false, + currentPage:1, + pageSize:5, activeIndex:'3' } }, @@ -168,6 +188,8 @@ activityName: '${activity.getActivityName()}', activityType:'${activity.getActivityType()}', activityIntroduction:'${activity.getActivityIntroduction()}', + minPeople:'${activity.getMinPeople()}', + maxPeople:'${activity.getMaxPeople()}', gmtCreate:'${activity.getFormattedCreateDate()}', teachers:teachers }) @@ -188,6 +210,8 @@ activityName: '${activity.getActivityName()}', activityType:'${activity.getActivityType()}', activityIntroduction:'${activity.getActivityIntroduction()}', + minPeople:'${activity.getMinPeople()}', + maxPeople:'${activity.getMaxPeople()}', gmtCreate:'${activity.getFormattedCreateDate()}', teachers:teachers }) @@ -225,6 +249,9 @@ } } return result; + }, + currentPageAllActivities:function (){ + return this.allActivitiesResult.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize) } }, methods: { @@ -232,7 +259,7 @@ window.history.go(-1); }, showDetail(index){ - this.showedActivity=this.allActivitiesResult[index]; + this.showedActivity=this.currentPageAllActivities[index]; this.dialogVisible=true }, toApply(id){ diff --git a/src/main/webapp/jsp/student/applyActivity.jsp b/src/main/webapp/jsp/student/applyActivity.jsp index fe1bfb6..29e81cb 100644 --- a/src/main/webapp/jsp/student/applyActivity.jsp +++ b/src/main/webapp/jsp/student/applyActivity.jsp @@ -64,6 +64,12 @@ {{activity.activityType}} + + + {{activity.minPeople}}-{{activity.maxPeople}}人 + -
{{item.activityIntroduction}}
+
+

要求人数:{{item.minPeople}}-{{item.maxPeople}}人

+

{{item.activityIntroduction}}

+
所有活动 @@ -110,6 +113,7 @@
负责老师:{{i.realName}} 
+

要求人数:{{item.minPeople}}-{{item.maxPeople}}人

{{item.activityIntroduction}}

@@ -184,6 +188,9 @@ activityName: '${activity.getActivityName()}', activityType:'${activity.getActivityType()}', activityIntroduction:'${activity.getActivityIntroduction()}', + minPeople:'${activity.getMinPeople()}', + maxPeople:'${activity.getMaxPeople()}', + gmtCreate:'${activity.getFormattedCreateDate()}', teachers:teachers }) @@ -203,6 +210,9 @@ activityName: '${activity.getActivityName()}', activityType:'${activity.getActivityType()}', activityIntroduction:'${activity.getActivityIntroduction()}', + minPeople:'${activity.getMinPeople()}', + maxPeople:'${activity.getMaxPeople()}', + gmtCreate:'${activity.getFormattedCreateDate()}', teachers:teachers }) diff --git a/src/main/webapp/jsp/teacher/activityDetail.jsp b/src/main/webapp/jsp/teacher/activityDetail.jsp index 991669c..5d084ba 100644 --- a/src/main/webapp/jsp/teacher/activityDetail.jsp +++ b/src/main/webapp/jsp/teacher/activityDetail.jsp @@ -57,6 +57,12 @@ {{activity.activityType}} + + + {{activity.minPeople}}-{{activity.maxPeople}}人 +