Add activity pages for student and change the method of get list of teacher.

DEV
PeterAlbus 3 years ago
parent 9fc0e1b8e9
commit cf8c20f4d6

@ -66,15 +66,7 @@ public class AccountController
{ {
final String roleAdmin="admin"; final String roleAdmin="admin";
ModelAndView modelAndView=new ModelAndView(); ModelAndView modelAndView=new ModelAndView();
Subject subject = SecurityUtils.getSubject(); modelAndView.setViewName("redirect: /index");
if(subject.hasRole(roleAdmin))
{
modelAndView.setViewName("redirect: /admin/index");
}
else
{
modelAndView.setViewName("redirect: /index");
}
return modelAndView; return modelAndView;
} }
} }

@ -0,0 +1,39 @@
package com.peteralbus.controller;
import com.peteralbus.entity.Activity;
import com.peteralbus.entity.User;
import com.peteralbus.service.ActivityService;
import com.peteralbus.util.PrincipalUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/**
* The type Student controller.
* @author peteralbus
*/
@Controller
@RequestMapping("/student")
public class StudentController
{
@Autowired
ActivityService activityService;
@RequestMapping("/activities")
public ModelAndView activities()
{
ModelAndView modelAndView=PrincipalUtil.getBasicModelAndView();
Subject subject = SecurityUtils.getSubject();
User user=(User)subject.getPrincipal();
List<Activity> activityList=activityService.getActivityByStudent(user.getUserId());
modelAndView.addObject("activityList",activityList);
List<Activity> allActivities=activityService.getActivities();
modelAndView.addObject("allActivities",allActivities);
modelAndView.setViewName("/jsp/student/activities.jsp");
return modelAndView;
}
}

@ -40,6 +40,7 @@ public class TeacherController
User user=(User)subject.getPrincipal(); User user=(User)subject.getPrincipal();
List<Activity> activityList=activityService.getActivityByTeacher(user.getUserId()); List<Activity> activityList=activityService.getActivityByTeacher(user.getUserId());
modelAndView.addObject("activityList",activityList); modelAndView.addObject("activityList",activityList);
System.out.println(activityList);
List<Activity> allActivities=activityService.getActivities(); List<Activity> allActivities=activityService.getActivities();
modelAndView.addObject("allActivities",allActivities); modelAndView.addObject("allActivities",allActivities);
modelAndView.setViewName("/jsp/teacher/activity.jsp"); modelAndView.setViewName("/jsp/teacher/activity.jsp");
@ -82,12 +83,12 @@ public class TeacherController
} }
else else
{ {
return "error"; return "error:didn't do any change";
} }
} }
catch (Exception e) catch (Exception e)
{ {
return "error"+e.getMessage(); return "error:"+e.getMessage();
} }
} }
@ResponseBody @ResponseBody

@ -2,6 +2,7 @@ package com.peteralbus.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peteralbus.entity.Activity; import com.peteralbus.entity.Activity;
import com.peteralbus.entity.User;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List; import java.util.List;
@ -22,6 +23,22 @@ public interface ActivityDao extends BaseMapper<Activity>
*/ */
List<Activity> getActivityByTeacher(Long userId); List<Activity> getActivityByTeacher(Long userId);
/**
* Gets activity by student.
*
* @param userId the user id
* @return the activity by student
*/
List<Activity> getActivityByStudent(Long userId);
/**
* Gets teacher list.
*
* @param activityId the activity id
* @return the teacher list
*/
List<User> getTeacherList(Long activityId);
/** /**
* Gets activities. * Gets activities.
* *

@ -34,7 +34,7 @@ public class Activity implements Serializable
@TableLogic @TableLogic
private Integer isDelete; private Integer isDelete;
@TableField(exist = false) @TableField(exist = false)
private List<String> teacherNameList; private List<User> teacherList;
public Long getActivityId() public Long getActivityId()
{ {
@ -121,14 +121,14 @@ public class Activity implements Serializable
this.isDelete = isDelete; this.isDelete = isDelete;
} }
public List<String> getTeacherNameList() public List<User> getTeacherList()
{ {
return teacherNameList; return teacherList;
} }
public void setTeacherNameList(List<String> teacherNameList) public void setTeacherList(List<User> teacherList)
{ {
this.teacherNameList = teacherNameList; this.teacherList = teacherList;
} }
@Override @Override
@ -143,7 +143,7 @@ public class Activity implements Serializable
", gmtCreate=" + gmtCreate + ", gmtCreate=" + gmtCreate +
", gmtModified=" + gmtModified + ", gmtModified=" + gmtModified +
", isDelete=" + isDelete + ", isDelete=" + isDelete +
", teacherNameList=" + teacherNameList + ", teacherList=" + teacherList +
'}'; '}';
} }
} }

@ -58,11 +58,33 @@ public class ActivityService
} }
public List<Activity> getActivityByTeacher(Long teacherId) public List<Activity> getActivityByTeacher(Long teacherId)
{ {
return activityDao.getActivityByTeacher(teacherId); List<Activity> activityList=activityDao.getActivityByTeacher(teacherId);
for(Activity activity:activityList)
{
List<User> teacherList=activityDao.getTeacherList(activity.getActivityId());
activity.setTeacherList(teacherList);
}
return activityList;
}
public List<Activity> getActivityByStudent(Long studentId)
{
List<Activity> activityList=activityDao.getActivityByStudent(studentId);
for(Activity activity:activityList)
{
List<User> teacherList=activityDao.getTeacherList(activity.getActivityId());
activity.setTeacherList(teacherList);
}
return activityList;
} }
public List<Activity> getActivities() public List<Activity> getActivities()
{ {
return activityDao.getActivities(); List<Activity> activityList=activityDao.getActivities();
for(Activity activity:activityList)
{
List<User> teacherList=activityDao.getTeacherList(activity.getActivityId());
activity.setTeacherList(teacherList);
}
return activityList;
} }
public int getCount() public int getCount()
{ {

@ -172,8 +172,6 @@
/login=anon /login=anon
/jsp/account/** =anon /jsp/account/** =anon
/jsp/admin/** = roles[admin]
/logout = logout /logout = logout
/** = authc /** = authc
<!-- /**=authc 所有的url都必须通过认证才可以访问 --> <!-- /**=authc 所有的url都必须通过认证才可以访问 -->

@ -3,29 +3,24 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.peteralbus.dao.ActivityDao"> <mapper namespace="com.peteralbus.dao.ActivityDao">
<resultMap id="activityWithTeacher" type="com.peteralbus.entity.Activity"> <select id="getActivityByTeacher" parameterType="java.lang.Long" resultType="com.peteralbus.entity.Activity">
<id property="activityId" column="activity_id"/> select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified
<result property="activityName" column="activity_name"/>
<result property="activityType" column="activity_type"/>
<result property="activityIntroduction" column="activity_introduction"/>
<result property="version" column="version"/>
<result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/>
<collection property="teacherNameList" javaType="list" ofType="String">
<constructor>
<arg column="real_name"/>
</constructor>
</collection>
</resultMap>
<select id="getActivityByTeacher" parameterType="java.lang.Long" resultMap="activityWithTeacher">
select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified,user.real_name
from social_practice_sys.activity,social_practice_sys.user,social_practice_sys.manage
where activity.is_delete=0 and user.user_id=#{userId} and user.user_id=manage.user_id and manage.activity_id=activity.activity_id
</select>
<select id="getActivities" resultMap="activityWithTeacher">
select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified,user.real_name
from social_practice_sys.activity,social_practice_sys.user,social_practice_sys.manage from social_practice_sys.activity,social_practice_sys.user,social_practice_sys.manage
where activity.is_delete=0 and user.user_id=manage.user_id and manage.activity_id=activity.activity_id where activity.is_delete=0 and user.user_id=#{userId} and user.user_id=manage.user_id and manage.activity_id=activity.activity_id
</select>
<select id="getActivityByStudent" parameterType="java.lang.Long" resultType="com.peteralbus.entity.Activity">
select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified
from activity,participate,user
where user.user_id=#{userId} and activity.activity_id=participate.activity_id and user.user_id=participate.user_id and activity.is_delete=0
</select>
<select id="getTeacherList" parameterType="java.lang.Long" resultType="com.peteralbus.entity.User">
select user.user_id,username,real_name,user_phone,avatar_src from activity,user,manage
where activity.activity_id=#{activityId} and manage.activity_id=activity.activity_id and manage.user_id=user.user_id and manage.is_delete=0 and user.is_delete=0
</select>
<select id="getActivities" resultType="com.peteralbus.entity.Activity">
select activity.activity_id, activity_name, activity_type, activity_introduction, activity.version, activity.gmt_create, activity.gmt_modified
from activity
where activity.is_delete=0
</select> </select>
<select id="getCount" resultType="int"> <select id="getCount" resultType="int">
select count(*) from social_practice_sys.activity select count(*) from social_practice_sys.activity

@ -0,0 +1,20 @@
.activity-list{
display: flex;
flex-direction: column;
}
.activity-list-top{
display: flex;
justify-content: space-between;
align-items: center;
}
.activity-list-card{
margin: 20px;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}

@ -15,11 +15,17 @@
<template #title>活动列表</template> <template #title>活动列表</template>
</el-menu-item> </el-menu-item>
</shiro:hasRole> </shiro:hasRole>
<el-menu-item index="3"> <shiro:hasRole name="student">
<el-menu-item index="3" onclick="location.href='/student/activities'">
<i class="el-icon-s-data"></i>
<template #title>活动列表</template>
</el-menu-item>
</shiro:hasRole>
<el-menu-item index="9">
<i class="el-icon-document"></i> <i class="el-icon-document"></i>
<template #title>Navigator Three</template> <template #title>Navigator Three</template>
</el-menu-item> </el-menu-item>
<el-menu-item index="4"> <el-menu-item index="10">
<i class="el-icon-setting"></i> <i class="el-icon-setting"></i>
<template #title>Navigator Four</template> <template #title>Navigator Four</template>
</el-menu-item> </el-menu-item>

@ -0,0 +1,252 @@
<%--
Created by IntelliJ IDEA.
User: peteralbus
Date: 2021/12/18
Time: 12:15
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<title>社会实践活动列表</title>
<!-- 导入 Vue 3 -->
<script src="${pageContext.request.contextPath}/vue/vue@next/vue.global.js"></script>
<!-- 导入组件库 -->
<script src="${pageContext.request.contextPath}/vue/element/index.full.js"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/vue/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/teacher/activity.css">
<link rel="stylesheet" href="//unpkg.com/element-plus@1.1.0-beta.9/dist/index.css" />
</head>
<body>
<div id="app">
<el-dialog
v-model="dialogVisible"
title="Tips"
>
<div style="text-align:center">
<el-descriptions
title="活动情况"
:column="1"
border
>
<template #extra>
<el-button type="primary" size="small">参与活动</el-button>
</template>
<el-descriptions-item>
<template #label>
活动名称
</template>
{{showedActivity.activityName}}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
活动类别
</template>
{{showedActivity.activityType}}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
创建日期
</template>
{{showedActivity.gmtCreate}}
</el-descriptions-item>
</el-descriptions>
</div>
<br/>
<div>
<el-descriptions :column="1" border>
<el-descriptions-item>
<template #label>
简介
</template>
{{showedActivity.activityIntroduction}}
</el-descriptions-item>
</el-descriptions>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">Cancel</el-button>
<el-button type="primary" @click="dialogVisible = false"
>Confirm</el-button>
</span>
</template>
</el-dialog>
<header>
<%@ include file="/jsp/header.html" %>
</header>
<div class="main">
<div class="container">
<el-container>
<el-aside width="80px">
<%@ include file="/jsp/aside.html" %>
</el-aside>
<el-main>
<el-page-header icon="el-icon-arrow-left" :content="title" @back="goBack"></el-page-header>
<br/>
<div class="container">
<div class="activity-list">
<div class="activity-list-top">
<el-input v-model="keyWord" prefix-icon="el-icon-search" placeholder="请输入活动名搜索" style="width: 50%"></el-input>
</div>
<el-divider content-position="left">参加的活动</el-divider>
<div class="activity-list-card" v-for="item in activityListResult">
<el-card class="box-card" shadow="hover">
<template #header>
<div class="card-header">
<span>{{item.activityName}}<el-tag size="mini">{{item.activityType}}</el-tag></span>
<el-button class="button" type="text" @click="toModify(item.activityId)">管理</el-button>
</div>
</template>
<h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<div>{{item.activityIntroduction}}</div>
</el-card>
</div>
<el-divider content-position="left">所有活动</el-divider>
<div class="activity-list-card" v-for="(item,index) in allActivitiesResult">
<el-card class="box-card" shadow="hover">
<template #header>
<div class="card-header">
<span>{{item.activityName}}<el-tag size="mini">{{item.activityType}}</el-tag></span>
<el-button class="button" type="text" @click="showDetail(index)">查看详情</el-button>
</div>
</template>
<div>
<h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<p>{{item.activityIntroduction}}</p>
</div>
</el-card>
</div>
</div>
</div>
</el-main>
</el-container>
</div>
</div>
<footer>
<%@ include file="/jsp/foot.html" %>
</footer>
</div>
<script>
const App = {
data() {
return{
title:'社会实践活动列表',
keyWord:'',
user:{
username:'',
realName:'',
avatarSrc: ''
},
activityList:[],
allActivities:[],
showedActivity:{
activityId: '',
activityName: '',
activityType:'',
activityIntroduction:''
},
dialogVisible:false,
activeIndex:'3'
}
},
mounted(){
this.user.realName='${realName}'
this.user.username='${username}'
this.user.avatarSrc='${avatarSrc}'
let teachers
<c:forEach items="${activityList}" var="activity">
teachers=[]
<c:forEach items="${activity.getTeacherList()}" var="teacher">
teachers.push({
userId:'${teacher.getUserId()}',
username:'${teacher.getUsername()}',
realName:'${teacher.getRealName()}',
userPhone:'${teacher.getUserPhone()}',
avatarSrc:'${teacher.getAvatarSrc()}'
})
</c:forEach>
this.activityList.push({
activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
gmtCreate:'${activity.getFormattedCreateDate()}',
teachers:teachers
})
</c:forEach>
<c:forEach items="${allActivities}" var="activity">
teachers=[]
<c:forEach items="${activity.getTeacherList()}" var="teacher">
teachers.push({
userId:'${teacher.getUserId()}',
username:'${teacher.getUsername()}',
realName:'${teacher.getRealName()}',
userPhone:'${teacher.getUserPhone()}',
avatarSrc:'${teacher.getAvatarSrc()}'
})
</c:forEach>
this.allActivities.push({
activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
gmtCreate:'${activity.getFormattedCreateDate()}',
teachers:teachers
})
</c:forEach>
},
computed:{
activityListResult:function (){
let result=[];
if(this.keyWord==='')
{
return this.activityList;
}
for(let i=0;i<this.activityList.length;i++)
{
let str=this.activityList[i].activityName;
if(str.search(this.keyWord)!==-1)
{
result.push(this.activityList[i]);
}
}
return result;
},
allActivitiesResult:function (){
let result=[];
if(this.keyWord==='')
{
return this.allActivities;
}
for(let i=0;i<this.allActivities.length;i++)
{
let str=this.allActivities[i].activityName;
if(str.search(this.keyWord)!==-1)
{
result.push(this.allActivities[i]);
}
}
return result;
}
},
methods: {
goBack(){
window.history.go(-1);
},
showDetail(index){
this.showedActivity=this.allActivitiesResult[index];
this.dialogVisible=true
},
}
};
const app = Vue.createApp(App);
app.use(ElementPlus);
app.mount("#app");
</script>
</body>
</html>

@ -36,8 +36,8 @@
</el-aside> </el-aside>
<el-main> <el-main>
<el-page-header icon="el-icon-arrow-left" :content="title" @back="goBack"></el-page-header> <el-page-header icon="el-icon-arrow-left" :content="title" @back="goBack"></el-page-header>
<br/>
<div class="container"> <div class="container">
<br/>
<div class="activity-list"> <div class="activity-list">
<div class="activity-list-top"> <div class="activity-list-top">
<el-input v-model="keyWord" prefix-icon="el-icon-search" placeholder="请输入活动名搜索" style="width: 50%"></el-input> <el-input v-model="keyWord" prefix-icon="el-icon-search" placeholder="请输入活动名搜索" style="width: 50%"></el-input>
@ -96,7 +96,7 @@
</div> </div>
</template> </template>
<div> <div>
<h5>负责老师:<span v-for="i in item.teachers">{{i}}&emsp;</span></h5> <h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<p>{{item.activityIntroduction}}</p> <p>{{item.activityIntroduction}}</p>
</div> </div>
</el-card> </el-card>
@ -149,26 +149,43 @@
this.user.realName='${realName}' this.user.realName='${realName}'
this.user.username='${username}' this.user.username='${username}'
this.user.avatarSrc='${avatarSrc}' this.user.avatarSrc='${avatarSrc}'
let teachers
<c:forEach items="${activityList}" var="activity"> <c:forEach items="${activityList}" var="activity">
teachers=[]
<c:forEach items="${activity.getTeacherList()}" var="teacher">
teachers.push({
userId:'${teacher.getUserId()}',
username:'${teacher.getUsername()}',
realName:'${teacher.getRealName()}',
userPhone:'${teacher.getUserPhone()}',
avatarSrc:'${teacher.getAvatarSrc()}'
})
</c:forEach>
this.activityList.push({ this.activityList.push({
activityId: '${activity.getActivityId()}', activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}', activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}', activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}' activityIntroduction:'${activity.getActivityIntroduction()}',
teachers:teachers
}) })
</c:forEach> </c:forEach>
let teachersName=[]
<c:forEach items="${allActivities}" var="activity"> <c:forEach items="${allActivities}" var="activity">
teachersName=[] teachers=[]
<c:forEach items="${activity.getTeacherNameList()}" var="teacherName"> <c:forEach items="${activity.getTeacherList()}" var="teacher">
teachersName.push('${teacherName}') teachers.push({
</c:forEach> userId:'${teacher.getUserId()}',
username:'${teacher.getUsername()}',
realName:'${teacher.getRealName()}',
userPhone:'${teacher.getUserPhone()}',
avatarSrc:'${teacher.getAvatarSrc()}'
})
</c:forEach>
this.allActivities.push({ this.allActivities.push({
activityId: '${activity.getActivityId()}', activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}', activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}', activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}', activityIntroduction:'${activity.getActivityIntroduction()}',
teachers:teachersName teachers:teachers
}) })
</c:forEach> </c:forEach>
}, },

Loading…
Cancel
Save