added student create and join group

DEV
PeterAlbus 3 years ago
parent ed5bb0b3f9
commit 5689ee40df

@ -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;
/**

@ -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<Group> 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";
}
}
}

@ -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 +

@ -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();

@ -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<Group> getGroupListByActivity(Long activityId)
{
QueryWrapper<Group> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("activity_id",activityId);
return groupDao.selectList(queryWrapper);
List<Group> 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)
{

@ -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);
}
}

@ -49,6 +49,12 @@
</template>
{{showedActivity.activityType}}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
活动人数
</template>
{{showedActivity.minPeople}}-{{showedActivity.maxPeople}}人
</el-descriptions-item>
<el-descriptions-item>
<template #label>
创建日期
@ -96,11 +102,22 @@
</div>
</template>
<h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<p>要求人数:{{item.minPeople}}-{{item.maxPeople}}人</p>
<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">
<div style="text-align: center">
<el-pagination
background
layout="total, sizes ,prev, pager, next, jumper"
:total="allActivitiesResult.length"
:page-sizes="[5, 10, 20, 40]"
v-model:page-size="pageSize"
v-model:current-page="currentPage">
</el-pagination>
</div>
<div class="activity-list-card" v-for="(item,index) in currentPageAllActivities">
<el-card class="box-card" shadow="hover">
<template #header>
<div class="card-header">
@ -110,6 +127,7 @@
</template>
<div>
<h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<p>要求人数:{{item.minPeople}}-{{item.maxPeople}}人</p>
<p>{{item.activityIntroduction}}</p>
</div>
</el-card>
@ -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){

@ -64,6 +64,12 @@
</template>
{{activity.activityType}}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
活动人数
</template>
{{activity.minPeople}}-{{activity.maxPeople}}人
</el-descriptions-item>
<el-descriptions-item>
<template #label>
负责老师
@ -98,13 +104,28 @@
<el-row v-if="form.isNewGroup">
<el-col :span="12">
<el-form-item label="小组名称" >
<el-input v-model="form.groupName"></el-input>
<el-input v-model="form.group.groupName"></el-input>
</el-form-item>
</el-col>
</el-row>
<div class="button-group">
<div class="button-group" v-if="form.isNewGroup">
<el-button type="primary" @click="newGroup">创建小组并参加活动</el-button>
</div>
<div class="group-list" v-if="!form.isNewGroup">
<el-table :data="groupListResult" style="width: 100%">
<el-table-column prop="groupName" label="小组名"></el-table-column>
<el-table-column prop="gmtCreate" label="创建日期"></el-table-column>
<el-table-column prop="leaderName" label="组长姓名"></el-table-column>
<el-table-column align="right">
<template #header>
<el-input v-model="keyWord" size="mini" placeholder="搜索姓名/组名"></el-input>
</template>
<template #default="scope">
<el-button size="mini" @click="joinGroup(scope.row.groupId)">加入</el-button>
</template>
</el-table-column>
</el-table>
</div>
</el-form>
</div>
</div>
@ -131,14 +152,15 @@
group:{
groupName:'',
activityId:'${activity.getActivityId()}'
},
groupId:0
}
},
activity:{
activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
minPeople:'${activity.getMinPeople()}',
maxPeople:'${activity.getMaxPeople()}',
gmtCreate:'${activity.getFormattedCreateDate()}',
teachers:[
<c:forEach items="${activity.getTeacherList()}" var="teacher">
@ -152,6 +174,18 @@
</c:forEach>
]
},
groupList:[
<c:forEach items="${groupList}" var="group">
{
groupId:'${group.getGroupId()}',
groupName:'${group.getGroupName()}',
leaderId:'${group.getLeaderId()}',
leaderName:'${group.getLeaderName()}',
gmtCreate:'${group.getFormattedCreateDate()}'
},
</c:forEach>
],
keyWord:'',
activeIndex:'3'
}
},
@ -187,7 +221,43 @@
}
}).then(res=>{
this.loading=false
if(res.data==="fail")
if(res.data==="error")
{
this.$message.error('创建小组失败!')
}
else
{
location.href="/"
}
})
})
},
joinGroup(id){
this.$messageBox.confirm(
'参与社会实践活动后不可更改小组,不可退出,确认申请?',
'警告',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
axios({
method: "post",
url: "/student/participateWithOldGroup",
data: {
groupId:id
},
transformRequest: [ function(data){
return Qs.stringify(data) //使用Qs将请求参数序列化
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded' //必须设置传输方式
}
}).then(res=>{
this.loading=false
if(res.data==="error")
{
this.$message.error('创建小组失败!')
}
@ -197,9 +267,26 @@
}
})
})
}
},
computed:{
groupListResult:function (){
let result=[];
if(this.keyWord==='')
{
return this.groupList;
}
for(let i=0;i<this.groupList.length;i++)
{
let str=this.groupList[i].groupName;
let str_leader=this.groupList[i].leaderName;
if(str.search(this.keyWord)!==-1||str_leader.search(this.keyWord)!==-1)
{
result.push(this.groupList[i]);
}
}
return result;
},
}
};
const app = Vue.createApp(App);

@ -0,0 +1,16 @@
<%--
Created by IntelliJ IDEA.
User: peteralbus
Date: 2021/12/19
Time: 22:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>填写报告</title>
</head>
<body>
</body>
</html>

@ -0,0 +1,82 @@
<%--
Created by IntelliJ IDEA.
User: peteralbus
Date: 2021/12/19
Time: 22:25
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" %>
<!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="//unpkg.com/element-plus@1.1.0-beta.9/dist/index.css" />
</head>
<body>
<div id="app">
<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">
<el-card style="width:320px">
<div style="text-align:center">
<img src="${pageContext.request.contextPath}/img/2.png" alt="">
<h3>A high quality UI Toolkit based on Vue.js</h3>
</div>
</el-card>
</div>
</el-main>
</el-container>
</div>
</div>
<footer>
<%@ include file="/jsp/foot.html" %>
</footer>
</div>
<script>
const App = {
data() {
return{
title:'小组正在形成',
user:{
username:'',
realName:'',
avatarSrc: ''
},
activeIndex:'3'
}
},
mounted(){
this.user.realName='${realName}'
this.user.username='${username}'
this.user.avatarSrc='${avatarSrc}'
},
methods: {
goBack(){
window.history.go(-1);
}
}
};
const app = Vue.createApp(App);
app.use(ElementPlus);
app.mount("#app");
</script>
</body>
</html>

@ -86,7 +86,10 @@
<el-button class="button" type="text" @click="toModify(item.activityId)">管理</el-button>
</div>
</template>
<div>{{item.activityIntroduction}}</div>
<div>
<p>要求人数:{{item.minPeople}}-{{item.maxPeople}}人</p>
<p>{{item.activityIntroduction}}</p>
</div>
</el-card>
</div>
<el-divider content-position="left">所有活动</el-divider>
@ -110,6 +113,7 @@
</template>
<div>
<h5>负责老师:<span v-for="i in item.teachers">{{i.realName}}&emsp;</span></h5>
<p>要求人数:{{item.minPeople}}-{{item.maxPeople}}人</p>
<p>{{item.activityIntroduction}}</p>
</div>
</el-card>
@ -184,6 +188,9 @@
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
minPeople:'${activity.getMinPeople()}',
maxPeople:'${activity.getMaxPeople()}',
gmtCreate:'${activity.getFormattedCreateDate()}',
teachers:teachers
})
</c:forEach>
@ -203,6 +210,9 @@
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
minPeople:'${activity.getMinPeople()}',
maxPeople:'${activity.getMaxPeople()}',
gmtCreate:'${activity.getFormattedCreateDate()}',
teachers:teachers
})
</c:forEach>

@ -57,6 +57,12 @@
</template>
{{activity.activityType}}
</el-descriptions-item>
<el-descriptions-item>
<template #label>
活动人数
</template>
{{activity.minPeople}}-{{activity.maxPeople}}人
</el-descriptions-item>
<el-descriptions-item>
<template #label>
创建日期
@ -101,6 +107,8 @@
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
minPeople:'${activity.getMinPeople()}',
maxPeople:'${activity.getMaxPeople()}',
gmtCreate:'${activity.getFormattedCreateDate()}'
},
activeIndex:'2'

@ -48,6 +48,9 @@
<el-option label="暖心公益" value="暖心公益"></el-option>
</el-select>
</el-form-item>
<el-form-item label="参加人数">
<el-slider v-model="range" range :max="50" :min="1"> </el-slider>
</el-form-item>
<el-form-item label="活动介绍" prop="activityIntroduction">
<el-input type="textarea" :rows="10" v-model="activity.activityIntroduction"></el-input>
</el-form-item>
@ -75,11 +78,14 @@
realName:'',
avatarSrc: ''
},
range:[${activity.getMinPeople()},${activity.getMaxPeople()}],
activity:{
activityId: '${activity.getActivityId()}',
activityName: '${activity.getActivityName()}',
activityType:'${activity.getActivityType()}',
activityIntroduction:'${activity.getActivityIntroduction()}',
minPeople:${activity.getMinPeople()},
maxPeople:${activity.getMaxPeople()},
gmtCreate:'${activity.getFormattedCreateDate()}'
},
rules: {
@ -109,6 +115,8 @@
this.$refs[name].validate((valid) => {
if (valid) {
this.loading=true
this.form.minPeople=this.range[0]
this.form.maxPeople=this.range[1]
axios({
method: "post",
url: "/teacher/modifyActivity",

Loading…
Cancel
Save