From 8046e1ec6384d646d3552209299df906af8d6bdf Mon Sep 17 00:00:00 2001 From: PeterAlbus Date: Tue, 21 Dec 2021 18:07:03 +0800 Subject: [PATCH] finished almost all pages of student and teacher. --- .../controller/AdminController.java | 1 + .../controller/StudentController.java | 26 +- .../controller/TeacherController.java | 96 ++++- .../java/com/peteralbus/entity/Group.java | 12 + .../java/com/peteralbus/entity/Record.java | 12 + .../peteralbus/service/ActivityService.java | 30 +- .../com/peteralbus/service/GroupService.java | 48 ++- .../service/ParticipateService.java | 24 ++ .../com/peteralbus/service/RecordService.java | 38 ++ .../peteralbus/service/ScoreGroupService.java | 29 ++ .../peteralbus/service/ScoreStuService.java | 31 ++ .../com/peteralbus/util/PrincipalUtil.java | 1 + src/main/webapp/jsp/admin/home.jsp | 42 --- src/main/webapp/jsp/student/activities.jsp | 28 +- .../webapp/jsp/student/activityResult.jsp | 21 +- src/main/webapp/jsp/student/applyActivity.jsp | 4 +- .../webapp/jsp/student/manageActivity.jsp | 36 +- src/main/webapp/jsp/student/waitGroup.jsp | 34 ++ src/main/webapp/jsp/teacher/manageGroup.jsp | 340 ++++++++++++++++++ .../webapp/jsp/teacher/modifyActivity.jsp | 37 +- 20 files changed, 810 insertions(+), 80 deletions(-) create mode 100644 src/main/java/com/peteralbus/service/ScoreGroupService.java create mode 100644 src/main/java/com/peteralbus/service/ScoreStuService.java delete mode 100644 src/main/webapp/jsp/admin/home.jsp create mode 100644 src/main/webapp/jsp/teacher/manageGroup.jsp diff --git a/src/main/java/com/peteralbus/controller/AdminController.java b/src/main/java/com/peteralbus/controller/AdminController.java index b34e7ed..a40a2c5 100644 --- a/src/main/java/com/peteralbus/controller/AdminController.java +++ b/src/main/java/com/peteralbus/controller/AdminController.java @@ -23,4 +23,5 @@ public class AdminController { return new ModelAndView("/jsp/admin/home.jsp"); } + } diff --git a/src/main/java/com/peteralbus/controller/StudentController.java b/src/main/java/com/peteralbus/controller/StudentController.java index 81a54f9..1913fff 100644 --- a/src/main/java/com/peteralbus/controller/StudentController.java +++ b/src/main/java/com/peteralbus/controller/StudentController.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import java.util.List; +import java.util.Map; /** * The type Student controller. @@ -70,7 +71,6 @@ 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) @@ -104,6 +104,8 @@ public class StudentController } if(participate.getFinished()) { + Map map=groupService.getScore(group.getGroupId()); + modelAndView.addObject("score",map); modelAndView.setViewName("/jsp/student/activityResult.jsp"); } modelAndView.addObject("activity",activity); @@ -176,4 +178,26 @@ public class StudentController return "error"; } } + @ResponseBody + @RequestMapping("/deleteParticipate") + public String deleteActivity(Long participationId) + { + try + { + int result=participateService.deleteParticipate(participationId); + if(result>0) + { + return "success"; + } + else + { + return "error"; + } + } + catch (Exception e) + { + e.printStackTrace(); + return "error:"+e.getMessage(); + } + } } diff --git a/src/main/java/com/peteralbus/controller/TeacherController.java b/src/main/java/com/peteralbus/controller/TeacherController.java index 7b346dd..7c6b401 100644 --- a/src/main/java/com/peteralbus/controller/TeacherController.java +++ b/src/main/java/com/peteralbus/controller/TeacherController.java @@ -1,11 +1,7 @@ package com.peteralbus.controller; -import com.peteralbus.entity.Activity; -import com.peteralbus.entity.Group; -import com.peteralbus.entity.User; -import com.peteralbus.service.ActivityService; -import com.peteralbus.service.GroupService; -import com.peteralbus.service.UserService; +import com.peteralbus.entity.*; +import com.peteralbus.service.*; import com.peteralbus.util.PrincipalUtil; import net.bytebuddy.implementation.bytecode.Throw; import org.apache.shiro.SecurityUtils; @@ -20,6 +16,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import java.util.List; +import java.util.Map; /** * The type Teacher controller. @@ -35,6 +32,12 @@ public class TeacherController UserService userService; @Autowired GroupService groupService; + @Autowired + RecordService recordService; + @Autowired + ScoreGroupService scoreGroupService; + @Autowired + ScoreStuService scoreStuService; @RequiresRoles(value={"teacher"}, logical= Logical.OR) @RequestMapping("/activities") public ModelAndView activities() @@ -78,13 +81,34 @@ public class TeacherController modelAndView.setViewName("/jsp/teacher/modifyActivity.jsp"); return modelAndView; } + @RequestMapping("/manageGroup") + public ModelAndView manageGroup(Long groupId) + { + ModelAndView modelAndView=PrincipalUtil.getBasicModelAndView(); + Subject subject = SecurityUtils.getSubject(); + User user=(User)subject.getPrincipal(); + Group group=groupService.getById(groupId); + Activity activity= activityService.getActivityById(group.getActivityId()); + List memberList=groupService.getGroupMember(group.getGroupId()); + List recordList=recordService.selectByGroup(groupId); + modelAndView.addObject("group",group); + modelAndView.addObject("memberList",memberList); + modelAndView.addObject("recordList",recordList); + modelAndView.addObject("activity",activity); + modelAndView.addObject("isFinished",memberList.get(0).getFinished()); + modelAndView.addObject("isScored",scoreGroupService.getScored(user.getUserId(),groupId)); + Map map=groupService.getScore(groupId); + modelAndView.addObject("score",map); + modelAndView.setViewName("/jsp/teacher/manageGroup.jsp"); + return modelAndView; + } @ResponseBody @RequestMapping("/addActivity") public String addActivity(Activity activity) { try { - int result=activityService.updateActivity(activity); + int result=activityService.addActivity(activity); if(result>0) { return "success"; @@ -121,6 +145,27 @@ public class TeacherController } } @ResponseBody + @RequestMapping("/deleteActivity") + public String deleteActivity(Long activityId) + { + try + { + int result=activityService.deleteActivity(activityId); + if(result>0) + { + return "success"; + } + else + { + return "error"; + } + } + catch (Exception e) + { + return "error:"+e.getMessage(); + } + } + @ResponseBody @RequestMapping("/addTeacherToActivity") public String addTeacherToActivity(Long userId,Long activityId) { @@ -135,4 +180,41 @@ public class TeacherController } return "error"; } + @ResponseBody + @RequestMapping("/setRead") + public String setRead(Long recordId) + { + int result= recordService.setRead(recordId); + if(result>0) + { + return "success"; + } + return "error"; + } + @ResponseBody + @RequestMapping("/scoreStu") + public String scoreStu(ScoreStu scoreStu) + { + int result=scoreStuService.insert(scoreStu); + if(result>0) + { + return "success"; + } + return "error"; + } + @ResponseBody + @RequestMapping("/scoreGroup") + public String scoreGroup(ScoreGroup scoreGroup) + { + if(scoreGroupService.getScored(scoreGroup.getTeacherId(),scoreGroup.getGroupId())) + { + return "error"; + } + int result=scoreGroupService.insert(scoreGroup); + if(result>0) + { + return "success"; + } + return "error"; + } } diff --git a/src/main/java/com/peteralbus/entity/Group.java b/src/main/java/com/peteralbus/entity/Group.java index b69919d..129c21d 100644 --- a/src/main/java/com/peteralbus/entity/Group.java +++ b/src/main/java/com/peteralbus/entity/Group.java @@ -26,6 +26,8 @@ public class Group implements Serializable private Long memberCount; @TableField(exist = false) private List memberList; + @TableField(exist = false) + private Boolean isFinished; private Long activityId; @Version private Integer version; @@ -155,6 +157,16 @@ public class Group implements Serializable this.memberList = memberList; } + public Boolean getFinished() + { + return isFinished; + } + + public void setFinished(Boolean finished) + { + isFinished = finished; + } + @Override public String toString() { diff --git a/src/main/java/com/peteralbus/entity/Record.java b/src/main/java/com/peteralbus/entity/Record.java index 897b9ec..6f3d5d6 100644 --- a/src/main/java/com/peteralbus/entity/Record.java +++ b/src/main/java/com/peteralbus/entity/Record.java @@ -21,6 +21,8 @@ public class Record implements Serializable private String recordTitle; private String recordContent; private Boolean isRead; + @TableField(exist = false) + private String authorName; @Version private Integer version; @TableField(fill = FieldFill.INSERT) @@ -129,6 +131,16 @@ public class Record implements Serializable this.isDelete = isDelete; } + public String getAuthorName() + { + return authorName; + } + + public void setAuthorName(String authorName) + { + this.authorName = authorName; + } + @Override public String toString() { diff --git a/src/main/java/com/peteralbus/service/ActivityService.java b/src/main/java/com/peteralbus/service/ActivityService.java index d1ac6fa..ad43ba8 100644 --- a/src/main/java/com/peteralbus/service/ActivityService.java +++ b/src/main/java/com/peteralbus/service/ActivityService.java @@ -1,10 +1,7 @@ package com.peteralbus.service; 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.dao.*; import com.peteralbus.entity.*; import com.sun.org.apache.xpath.internal.operations.Bool; import org.apache.shiro.SecurityUtils; @@ -32,6 +29,8 @@ public class ActivityService private ParticipateDao participateDao; @Autowired private ManageDao manageDao; + @Autowired + private RecordDao recordDao; /** * Add activity int. @@ -164,4 +163,27 @@ public class ActivityService { return activityDao.getCount(); } + + public int deleteActivity(Long activityId) + { + int result=0; + QueryWrapper manageQueryWrapper=new QueryWrapper<>(); + manageQueryWrapper.eq("activity_id",activityId); + result=manageDao.delete(manageQueryWrapper); + QueryWrapper participateQueryWrapper=new QueryWrapper<>(); + participateQueryWrapper.eq("activity_id",activityId); + List participateList=participateDao.selectList(participateQueryWrapper); + for(Participate participate:participateList) + { + QueryWrapper recordQueryWrapper=new QueryWrapper<>(); + recordQueryWrapper.eq("participation_id",participate.getParticipationId()); + result=recordDao.delete(recordQueryWrapper); + } + result=participateDao.delete(participateQueryWrapper); + QueryWrapper groupQueryWrapper=new QueryWrapper<>(); + groupQueryWrapper.eq("activity_id",activityId); + result=groupDao.delete(groupQueryWrapper); + result=activityDao.deleteById(activityId); + return result; + } } diff --git a/src/main/java/com/peteralbus/service/GroupService.java b/src/main/java/com/peteralbus/service/GroupService.java index 4b6a81b..f7d7e3b 100644 --- a/src/main/java/com/peteralbus/service/GroupService.java +++ b/src/main/java/com/peteralbus/service/GroupService.java @@ -1,17 +1,16 @@ package com.peteralbus.service; +import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.peteralbus.dao.GroupDao; -import com.peteralbus.dao.ParticipateDao; -import com.peteralbus.dao.UserDao; -import com.peteralbus.entity.Group; -import com.peteralbus.entity.Participate; -import com.peteralbus.entity.User; +import com.peteralbus.dao.*; +import com.peteralbus.entity.*; 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; /** * The type Group service. @@ -37,6 +36,12 @@ public class GroupService @Autowired ParticipateDao participateDao; + @Autowired + ScoreGroupDao scoreGroupDao; + + @Autowired + ScoreStuDao scoreStuDao; + /** * Gets group list by activity. * @@ -54,6 +59,7 @@ public class GroupService group.setLeaderName(user.getRealName()); List memberList=this.getGroupMember(group.getGroupId()); group.setMemberList(memberList); + group.setFinished(memberList.get(0).getFinished()); Long memberCount=this.getMemberCount(group.getGroupId()); group.setMemberCount(memberCount); } @@ -109,6 +115,36 @@ public class GroupService return memberList; } + public Map getScore(Long groupId) + { + Map map=new HashMap<>(); + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("group_id",groupId); + List scoreGroupList=scoreGroupDao.selectList(queryWrapper); + double sum=0; + for(ScoreGroup scoreGroup:scoreGroupList) + { + map.put(userDao.selectById(scoreGroup.getTeacherId()).getRealName()+"-小组评分:",scoreGroup.getScoreValue()); + sum+=scoreGroup.getScoreValue(); + } + map.put("小组总评分:",sum/scoreGroupList.size()); + List memberList=this.getGroupMember(groupId); + for(Participate member:memberList) + { + QueryWrapper scoreStuQueryWrapper=new QueryWrapper<>(); + scoreStuQueryWrapper.eq("participation_id",member.getParticipationId()); + List scoreStuList=scoreStuDao.selectList(scoreStuQueryWrapper); + sum=0; + for(ScoreStu scoreStu:scoreStuList) + { + map.put(userDao.selectById(scoreStu.getTeacherId()).getRealName()+"-"+member.getRealName()+":",scoreStu.getScoreValue()); + sum+=scoreStu.getScoreValue(); + } + map.put(member.getRealName()+"总评分:",sum/scoreStuList.size()); + } + return map; + } + /** * Insert group int. * diff --git a/src/main/java/com/peteralbus/service/ParticipateService.java b/src/main/java/com/peteralbus/service/ParticipateService.java index 7ada833..934a05f 100644 --- a/src/main/java/com/peteralbus/service/ParticipateService.java +++ b/src/main/java/com/peteralbus/service/ParticipateService.java @@ -3,8 +3,10 @@ package com.peteralbus.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.peteralbus.dao.GroupDao; import com.peteralbus.dao.ParticipateDao; +import com.peteralbus.dao.RecordDao; import com.peteralbus.entity.Group; import com.peteralbus.entity.Participate; +import com.peteralbus.entity.Record; import com.peteralbus.entity.User; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.UnauthorizedException; @@ -12,6 +14,8 @@ import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + /** * The type Participate service. * @author peteralbus @@ -30,6 +34,9 @@ public class ParticipateService @Autowired GroupDao groupDao; + @Autowired + RecordDao recordDao; + /** * Gets by user and activity. * @@ -142,4 +149,21 @@ public class ParticipateService throw new UnauthorizedException(); } } + + public int deleteParticipate(Long participationId) + { + Participate participate=participateDao.selectById(participationId); + Group group=groupDao.selectById(participate.getGroupId()); + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("group_id",group.getGroupId()); + Long count=participateDao.selectCount(queryWrapper); + if(group.getLeaderId().equals(participate.getUserId())&&count>=2) + { + return 0; + } + QueryWrapper recordQueryWrapper=new QueryWrapper<>(); + recordQueryWrapper.eq("participation_id",participate.getParticipationId()); + recordDao.delete(recordQueryWrapper); + return participateDao.deleteById(participationId); + } } diff --git a/src/main/java/com/peteralbus/service/RecordService.java b/src/main/java/com/peteralbus/service/RecordService.java index d7cce60..ce403d8 100644 --- a/src/main/java/com/peteralbus/service/RecordService.java +++ b/src/main/java/com/peteralbus/service/RecordService.java @@ -1,11 +1,17 @@ package com.peteralbus.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.peteralbus.dao.GroupDao; +import com.peteralbus.dao.ParticipateDao; import com.peteralbus.dao.RecordDao; +import com.peteralbus.dao.UserDao; +import com.peteralbus.entity.Group; +import com.peteralbus.entity.Participate; import com.peteralbus.entity.Record; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -21,6 +27,12 @@ public class RecordService */ @Autowired RecordDao recordDao; + @Autowired + GroupDao groupDao; + @Autowired + ParticipateDao participateDao; + @Autowired + UserDao userDao; /** * Insert record int. @@ -45,4 +57,30 @@ public class RecordService queryWrapper.eq("participation_id",participationId); return recordDao.selectList(queryWrapper); } + + public List selectByGroup(Long groupId) + { + Group group= groupDao.selectById(groupId); + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("group_id",groupId); + List participateList=participateDao.selectList(queryWrapper); + List recordList=new ArrayList<>(); + for(Participate participate:participateList) + { + List records=this.selectByParticipate(participate.getParticipationId()); + for(Record record:records) + { + record.setAuthorName(userDao.selectById(participate.getUserId()).getRealName()); + } + recordList.addAll(records); + } + return recordList; + } + + public int setRead(Long recordId) + { + Record record=recordDao.selectById(recordId); + record.setRead(true); + return recordDao.updateById(record); + } } diff --git a/src/main/java/com/peteralbus/service/ScoreGroupService.java b/src/main/java/com/peteralbus/service/ScoreGroupService.java new file mode 100644 index 0000000..27febe1 --- /dev/null +++ b/src/main/java/com/peteralbus/service/ScoreGroupService.java @@ -0,0 +1,29 @@ +package com.peteralbus.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.peteralbus.dao.ScoreGroupDao; +import com.peteralbus.entity.ScoreGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * The type Score group service. + * @author peteralbus + */ +@Service +public class ScoreGroupService +{ + @Autowired + ScoreGroupDao scoreGroupDao; + public int insert(ScoreGroup scoreGroup) + { + return scoreGroupDao.insert(scoreGroup); + } + public Boolean getScored(Long teacherId,Long groupId) + { + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("teacher_id",teacherId); + queryWrapper.eq("group_id",groupId); + return scoreGroupDao.selectCount(queryWrapper) > 0; + } +} diff --git a/src/main/java/com/peteralbus/service/ScoreStuService.java b/src/main/java/com/peteralbus/service/ScoreStuService.java new file mode 100644 index 0000000..ee8e1d9 --- /dev/null +++ b/src/main/java/com/peteralbus/service/ScoreStuService.java @@ -0,0 +1,31 @@ +package com.peteralbus.service; + +import com.peteralbus.dao.ParticipateDao; +import com.peteralbus.dao.ScoreStuDao; +import com.peteralbus.entity.Participate; +import com.peteralbus.entity.ScoreStu; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * The type Score stu service. + * @author peteralbus + */ +@Service +public class ScoreStuService +{ + @Autowired + ScoreStuDao scoreStuDao; + @Autowired + ParticipateDao participateDao; + public int insert(ScoreStu scoreStu) + { + if(scoreStuDao.insert(scoreStu)>0) + { + Participate participate=participateDao.selectById(scoreStu.getParticipationId()); + participate.setFinished(true); + return participateDao.updateById(participate); + } + return 0; + } +} diff --git a/src/main/java/com/peteralbus/util/PrincipalUtil.java b/src/main/java/com/peteralbus/util/PrincipalUtil.java index dc1bf90..09d8c07 100644 --- a/src/main/java/com/peteralbus/util/PrincipalUtil.java +++ b/src/main/java/com/peteralbus/util/PrincipalUtil.java @@ -23,6 +23,7 @@ public class PrincipalUtil modelAndView.addObject("realName",user.getRealName()); modelAndView.addObject("username",user.getUsername()); modelAndView.addObject("avatarSrc",user.getAvatarSrc()); + modelAndView.addObject("userId",user.getUserId()); return modelAndView; } } diff --git a/src/main/webapp/jsp/admin/home.jsp b/src/main/webapp/jsp/admin/home.jsp deleted file mode 100644 index 0a4b6cb..0000000 --- a/src/main/webapp/jsp/admin/home.jsp +++ /dev/null @@ -1,42 +0,0 @@ -<%-- - Created by IntelliJ IDEA. - User: PeterAlbus - Date: 2021/12/8 - Time: 14:28 ---%> -<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> -<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> - - - - 管理员界面 - - - - - - - - -
-

- 已登录!登出 -

-
- - - diff --git a/src/main/webapp/jsp/student/activities.jsp b/src/main/webapp/jsp/student/activities.jsp index 0e87299..302df48 100644 --- a/src/main/webapp/jsp/student/activities.jsp +++ b/src/main/webapp/jsp/student/activities.jsp @@ -106,7 +106,20 @@ +
+ +
所有活动 +
+ + +
@@ -181,6 +182,7 @@ groupName:'${group.getGroupName()}', leaderId:'${group.getLeaderId()}', leaderName:'${group.getLeaderName()}', + isFinished:${group.getFinished()}, gmtCreate:'${group.getFormattedCreateDate()}' }, diff --git a/src/main/webapp/jsp/student/manageActivity.jsp b/src/main/webapp/jsp/student/manageActivity.jsp index aab743e..a50ef28 100644 --- a/src/main/webapp/jsp/student/manageActivity.jsp +++ b/src/main/webapp/jsp/student/manageActivity.jsp @@ -52,6 +52,7 @@ border > @@ -112,7 +113,7 @@ -

{{item.recordTitle}}

+

{{item.recordTitle}}未读

{{item.recordContent}}

@@ -168,7 +169,8 @@ { recordTitle:'${record.getRecordTitle()}', recordContent:'${record.getRecordContent()}', - gmtCreate:'${record.getFormattedCreateDate()}' + gmtCreate:'${record.getFormattedCreateDate()}', + isRead:${record.getRead()}, }, ], @@ -319,6 +321,36 @@ this.$message.error("出现异常,提交失败") }) }) + }, + deleteParticipate(){ + this.$messageBox.confirm( + '确认退出吗?你填写的活动记录将消失!', + '警告', + { + confirmButtonText: '确认', + cancelButtonText: '取消', + type: 'warning', + } + ) + .then(() => { + axios({ + method: "get", + url: "/student/deleteParticipate?participationId="+this.form.participationId, + }) + .then(res => { + if(res.data==="success") + { + location.href="/student/activities" + } + else + { + this.$message.error("组长在组员没有退出时,不能退出社会实践活动!") + } + }) + .catch(res=>{ + this.$message.error("出现异常,提交失败") + }) + }) } } }; diff --git a/src/main/webapp/jsp/student/waitGroup.jsp b/src/main/webapp/jsp/student/waitGroup.jsp index 04ba75c..5079b04 100644 --- a/src/main/webapp/jsp/student/waitGroup.jsp +++ b/src/main/webapp/jsp/student/waitGroup.jsp @@ -51,6 +51,9 @@ :column="1" border > +