2023.6.17

1. 修复了实时课表的BUG
2. 完善了查看借用记录
This commit is contained in:
KaiyuanOSG 2023-06-17 11:07:46 +08:00
parent 9819b9b97a
commit e44e7d9afb
11 changed files with 249 additions and 193 deletions

View File

@ -6,6 +6,7 @@ import com.sdut.labex.Factory.BorrowInfoFactory;
import com.sdut.labex.entity.BorrowInfo;
import com.sdut.labex.service.BorrowInfoService;
import com.sdut.labex.utils.ResVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -20,6 +21,7 @@ import java.util.List;
*/
@RestController
@CrossOrigin
@Slf4j
public class BorrowInfoController {
@Resource
@ -60,6 +62,10 @@ public class BorrowInfoController {
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
BorrowInfo borrowInfo = BorrowInfoFactory.createBorrowInfo(jsonObject);
if (borrowInfo != null) {
borrowInfo.setTime(jsonObject.getString("time"));
}
log.error("borrowInfo: " + borrowInfo);
return borrowInfoService.getBorrowInfo(borrowInfo, pageNum, pageSize);
}
}

View File

@ -3,6 +3,7 @@ package com.sdut.labex.controller;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.service.TableService;
import com.sdut.labex.utils.ResVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -14,6 +15,7 @@ import javax.annotation.Resource;
* Author: springforest
* Description:
*/
@Slf4j
@RestController
@CrossOrigin
public class TableController {

View File

@ -0,0 +1,20 @@
package com.sdut.labex.dto;
import lombok.Data;
/**
* File: BorrowInfoDTO
* Created: 2023/6/17
* Author: springforest
* Description:
*/
@Data
public class BorrowInfoDTO {
private Integer id;
private String roomName;
private String date;
private String time;
private String applyUser;
private String applyDate;
private int isAdmit;
}

View File

@ -22,8 +22,6 @@ public interface BorrowInfoMapper extends BaseMapper<BorrowInfo> {
public void addTimeTable(Map<String, String> map);
public List<BorrowInfo> listAllByDateAndRoom(String date, String room);
public List<Room> notBorrowedYet(@Param("timeList") List<String> timeList, @Param("date") String date);
}

View File

@ -4,15 +4,18 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.dto.BorrowInfoDTO;
import com.sdut.labex.entity.BorrowInfo;
import com.sdut.labex.entity.Room;
import com.sdut.labex.mapper.BorrowInfoMapper;
import com.sdut.labex.service.BorrowInfoService;
import com.sdut.labex.utils.FormatDate;
import com.sdut.labex.utils.ResVo;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -80,10 +83,21 @@ public class BorrowInfoServiceImpl extends ServiceImpl<BorrowInfoMapper, BorrowI
public ResVo getBorrowInfo(BorrowInfo borrowInfo, int pageNum, int pageSize) {
Page<BorrowInfo> page = new Page<>(pageNum, pageSize);
borrowInfoMapper.queryBorrowInfoByOptions(page, borrowInfo);
List<BorrowInfo> list = page.getRecords();
List<BorrowInfoDTO> resList = new ArrayList<>();
for (BorrowInfo item : list) {
BorrowInfoDTO m = new BorrowInfoDTO();
BeanUtil.copyProperties(item, m);
m.setDate(FormatDate.formatDate(item.getDate()));
m.setApplyDate(FormatDate.formatDate(item.getApplyDate()));
resList.add(m);
}
Map<String, Object> res = new HashMap<>();
res.put("total", page.getTotal());
res.put("current", page.getCurrent());
res.put("list", page.getRecords());
res.put("list", resList);
return ResVo.ok(res);
}

View File

@ -41,15 +41,17 @@ public class TableServiceImpl implements TableService {
@Override
public ResVo getUnUsedTable(String room, String date) {
QueryWrapper<BorrowInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("date", date);
queryWrapper.eq("date", date)
.eq("room_name", room);
List<BorrowInfo> borrowedList = borrowInfoMapper.selectList(queryWrapper);
Map<String, Set<String>> tempMap = new HashMap<>();
Map<String, List<String>> tempMap = new HashMap<>();
// 获取所有教室
List<Room> roomList = roomMapper.selectList(null);
List<TimeOption> timeOptionList = timeOptionMapper.selectList(new QueryWrapper<TimeOption>().orderByAsc("order_number"));
// 获取所有时间按顺序
List<TimeOption> timeOptionList = timeOptionMapper.selectList(null);
for (TimeOption time : timeOptionList) {
Set<String> rooms = new HashSet<>();
List<String> rooms = new ArrayList<>();
tempMap.put(time.getName(), rooms);
}
@ -60,17 +62,21 @@ public class TableServiceImpl implements TableService {
Map<String, Object> map = new HashMap<>();
List<List<String>> res = new ArrayList<>();
// 获取不在borrowedList中的教室
for (TimeOption key : timeOptionList) {
List<String> rooms = new ArrayList<>();
for (Room item : roomMapper.selectList(new QueryWrapper<Room>().in("name", tempMap.get(key.getName())))) {
rooms.add(item.getName());
for (Room item : roomList) {
if (!tempMap.get(key.getName()).contains(item.getName())) {
rooms.add(item.getName());
}
}
res.add(rooms);
}
// Remove rooms that are not equal to the provided room when room is not null
if (room != null && !room.isEmpty()) {
for (List<String> rooms : res) {
rooms.removeIf(r -> !r.contains(room));
rooms.removeIf(r -> !r.equals(room));
}
}

View File

@ -0,0 +1,29 @@
package com.sdut.labex.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* File: FormatDate
* Created: 2023/6/17
* Author: springforest
* Description:
*/
public class FormatDate {
public static String formatDate(Date date) {
SimpleDateFormat dateFormat;
if (isMidnightTime(date)) {
dateFormat = new SimpleDateFormat("yyyy-MM-dd");
} else {
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
return dateFormat.format(date);
}
private static boolean isMidnightTime(Date date) {
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
String timeString = timeFormat.format(date);
return timeString.equals("00:00:00");
}
}

View File

@ -18,22 +18,22 @@
VALUES (#{applyUser}, #{time}, #{date}, #{applyDate}, 1, #{roomName});
</insert>
<select id="queryBorrowInfoByOptions" resultType="com.sdut.labex.entity.BorrowInfo">
select *
from borrow_info
</select>
<select id="listAllByDateAndRoom" resultType="com.sdut.labex.entity.BorrowInfo">
<select id="queryBorrowInfoByOptions" resultType="com.sdut.labex.entity.BorrowInfo" parameterType="object">
select *
from borrow_info
<where>
<if test="date != null">
date = #{date}
<if test="borrowInfo.date != null">
and date = #{borrowInfo.date}
</if>
<if test="room != null">
and room_name = #{room}
<if test="borrowInfo.time != null and borrowInfo.time!=''">
and time = #{borrowInfo.time}
</if>
<if test="borrowInfo.roomName != null and borrowInfo.roomName != ''">
and room_name = #{borrowInfo.roomName}
</if>
</where>
</select>
<select id="notBorrowedYet" resultType="com.sdut.labex.entity.Room">

View File

@ -59,21 +59,19 @@ export default {
},
methods: {
init() {
//
this.tableData = [];
//borrowFormDate
let tempDate = this.subForm.date;
for (let i = 0; i < 7; i++) {
let subFormCopy = Object.assign({}, this.subForm); //
subFormCopy.date = this.setTimes(tempDate, i);
this.tableData.push({
date: this.setTimes(tempDate, i).substring(5, 10),
date: subFormCopy.date.substring(5, 10),
rooms: []
})
this.subForm.date = this.setTimes(tempDate, i);
});
setTimeout(() => {
this.getTableData(i);
this.getTableData(i, subFormCopy); // getTableData
}, 200);
}
//
this.subForm.date = tempDate;
},
getAllRoom() {
@ -84,14 +82,15 @@ export default {
this.rooms = res.data.list;
})
},
getTableData(offset) {
getTableData(offset, subForm) {
console.log(subForm); // subForm
this.$http({
url: '/getUnusedTable',
method: 'post',
data: this.subForm
data: subForm
}).then(res => {
this.tableData[offset].rooms = res.data.list;
})
});
},
//
setTimes(selDate, offset) {

View File

@ -1,85 +1,85 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import {createRouter, createWebHashHistory} from 'vue-router'
const routes = [
{
path: '/',
redirect:'/Login'
},
{
path: '/Home',
name: 'Home',
redirect: '/BorrowRoom',
component: () => import('../views/Home.vue'),
//---------------------教室借用相关-----------------------------
children:[
{
path: '/BorrowRoom',
name: 'BorrowRoom',
component: () => import('../views/BorrowRoom/BorrowRoom.vue')
},
{
path: '/BorrowInfoList',
name: 'BorrowInfoList',
component: () => import('../views/BorrowRoom/RecordList.vue')
},
//---------------------管理员部分-----------------------------
{
path: '/Admit',
name: 'Admit',
component: () => import('../views/Admin/Admit.vue')
},
{
path: '/UserManage',
name: 'UserManage',
component: () => import('../views/Admin/UserManage.vue')
},
{
path: '/RoomTimeAndReasonManage',
name: 'RoomTimeAndReasonManage',
component: () => import('../views/Admin/RoomAndTimeManage.vue')
},
{
path: '/Personal',
name: 'Personal',
component: () => import('../views/Personal.vue')
},
//---------------------教师--------------------------------------------------------------------------
{
path: '/ApplyExperiment',
name: 'ApplyExperiment',
component: () => import('../views/ApplyExperiment/ApplyExperiment.vue')
}
]
},
//---------------------用户/Admin--------------------------------------------------------------------
{
path: '/Login',
name: 'Login',
component: () => import('../views/Login.vue')
},
{
path: '/',
redirect: '/Login'
},
{
path: '/Home',
name: 'Home',
redirect: '/BorrowRoom',
component: () => import('../views/Home.vue'),
//---------------------教室借用相关-----------------------------
children: [
{
path: '/BorrowRoom',
name: 'BorrowRoom',
component: () => import('../views/BorrowRoom/BorrowRoom.vue')
},
{
path: '/RecordList',
name: 'RecordList',
component: () => import('../views/BorrowRoom/RecordList.vue')
},
//---------------------管理员部分-----------------------------
{
path: '/Admit',
name: 'Admit',
component: () => import('../views/Admin/Admit.vue')
},
{
path: '/UserManage',
name: 'UserManage',
component: () => import('../views/Admin/UserManage.vue')
},
{
path: '/RoomTimeAndReasonManage',
name: 'RoomTimeAndReasonManage',
component: () => import('../views/Admin/RoomAndTimeManage.vue')
},
{
path: '/Personal',
name: 'Personal',
component: () => import('../views/Personal.vue')
},
//---------------------教师--------------------------------------------------------------------------
{
path: '/ApplyExperiment',
name: 'ApplyExperiment',
component: () => import('../views/ApplyExperiment/ApplyExperiment.vue')
}
]
},
//---------------------用户/Admin--------------------------------------------------------------------
{
path: '/Login',
name: 'Login',
component: () => import('../views/Login.vue')
},
]
const router = createRouter({
history: createWebHashHistory(),
routes
history: createWebHashHistory(),
routes
})
//导航守卫
//开启前先做白名单
router.beforeEach((to, from, next) => {
//页面拦截
if (to.name !== 'Login') {
let role = window.sessionStorage.getItem("role");
// let token = window.sessionStorage.getItem("token");
if (!role) {
// return next({ name: 'Login' });
//页面拦截
if (to.name !== 'Login') {
let role = window.sessionStorage.getItem("role");
// let token = window.sessionStorage.getItem("token");
if (!role) {
// return next({ name: 'Login' });
}
return next();
} else {
return next();
}
return next();
} else {
return next();
}
})

View File

@ -47,36 +47,35 @@
<el-button type="primary" style="margin-right: 10px;" :loading="loading">下载模板</el-button>
</a>
<el-breadcrumb :separator-icon="ArrowRight" style="margin-right: 20px;">
<el-date-picker v-model="this.startDate" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" placeholder="学期开始日期"/>
<el-date-picker v-model="this.startDate" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
placeholder="学期开始日期"/>
</el-breadcrumb>
<el-upload :on-change="fileChange" :show-file-list="false" :auto-upload="false">
<el-button type="warning" :loading="loading">上传</el-button>
</el-upload>
</el-form-item>
<el-form-item label="下载记录" v-show="userInfo.role === 'admin'">
<el-button type="primary" @click="exportExcel">导出记录</el-button>
</el-form-item>
</el-form>
<el-divider />
<el-divider/>
<div>
<el-table :data="borrowInfo" stripe border v-loading="loading" :highlight-current-row="true">
<el-table-column align="center" prop="date" label="日期" width="120" />
<el-table-column align="center" prop="time" label="时间" width="120" />
<el-table-column align="center" prop="roomName" label="教室名称" width="100" />
<el-table-column align="center" prop="reason" label="用途" width="180"/>
<el-table-column align="center" prop="name" label="借用人" />
<el-table-column align="center" prop="applyDate" label="申请时间" width="200"/>
<el-table-column align="center" width="100" label="状态">
<el-table :data="borrowInfo" stripe border v-loading="loading" :highlight-current-row="true">
<el-table-column align="center" prop="date" label="日期"/>
<el-table-column align="center" prop="time" label="时间"/>
<el-table-column align="center" prop="roomName" label="教室名称"/>
<el-table-column align="center" prop="applyUser" label="借用人"/>
<el-table-column align="center" prop="applyDate" label="申请时间"/>
<el-table-column align="center" width="100" label="状态">
<template #default="scope">
<el-tag v-show="scope.row.isAdmit === '0'" type="warning">待审核</el-tag>
<el-tag v-show="scope.row.isAdmit === '2'" type="danger">拒绝</el-tag>
<el-tag v-show="scope.row.isAdmit === '1'" type="success">通过</el-tag>
<el-tag v-show="scope.row.isAdmit === 0" type="warning">待审核</el-tag>
<el-tag v-show="scope.row.isAdmit === 2" type="danger">拒绝</el-tag>
<el-tag v-show="scope.row.isAdmit === 1" type="success">通过</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="操作">
<template #default="scope">
<el-button type="danger" @click="cancel(scope.row.id)" v-show="userInfo.role === 'admin' || userInfo.username === scope.row.name">撤销</el-button>
<el-button type="danger" @click="cancel(scope.row.id)"
v-show="userInfo.role === 'admin' || userInfo.username === scope.row.name">撤销
</el-button>
</template>
</el-table-column>
</el-table>
@ -95,36 +94,42 @@
<script>
import {ElMessage} from "element-plus";
import {ArrowRight} from "@element-plus/icons-vue";
let formData = new FormData;
export default {
name: "BorrowInfoList",
data(){
return{
loading:true,
TimeOption:[],
Rooms:[],
computed: {
ArrowRight() {
return ArrowRight
}
},
data() {
return {
loading: true,
TimeOption: [],
Rooms: [],
userInfo:{
userId:'',
role:'',
username:'',
userDepart:'',
userInfo: {
userId: '',
role: '',
username: '',
userDepart: '',
},
borrowInfo:[],
borrowInfo: [],
subForm:{
date:'',
time:'',
reason:'',
userId:'',
roomName:'',
pageNum:1,
subForm: {
date: '',
time: null,
userId: '',
roomName: '',
pageNum: 1,
pageSize: 30,
total:0
total: 0
},
startDate:null,
startDate: null,
}
},
mounted() {
@ -136,64 +141,64 @@ export default {
this.getAllTimeOptions();
console.log(this.userInfo)
},
methods:{
getAllTimeOptions(){
methods: {
getAllTimeOptions() {
this.loading = true;
this.$http({
url:'/timeOption',
method:'get',
}).then(({data})=>{
for(let i=0;i<data.list.length;i++){
url: '/timeOption',
method: 'get',
}).then(({data}) => {
for (let i = 0; i < data.list.length; i++) {
this.TimeOption.push({
label:data.list[i].name,
key:data.list[i].name,
value:data.list[i].name
label: data.list[i].name,
key: data.list[i].name,
value: data.list[i].name
})
}
this.loading = false;
})
},
getAllRooms(){
getAllRooms() {
this.loading = true;
this.$http({
url:'/room',
method:'get',
}).then(({data})=>{
for(let i=0;i<data.list.length;i++){
url: '/room',
method: 'get',
}).then(({data}) => {
for (let i = 0; i < data.list.length; i++) {
this.Rooms.push({
label:data.list[i].name,
key:data.list[i].name,
value:data.list[i].name
label: data.list[i].name,
key: data.list[i].name,
value: data.list[i].name
})
}
this.loading = false;
})
},
getBorrowInfo(){
getBorrowInfo() {
this.loading = true;
this.$http({
method:'post',
url: '/borrowInfo',
data:this.subForm
}).then(res =>{
method: 'post',
url: '/borrowInfo/' + this.subForm.pageNum + '/' + this.subForm.pageSize,
data: this.subForm
}).then(res => {
console.log(res);
if (res.data.code !== 200){
if (res.data.code !== 200) {
ElMessage({
message: '教室信息获取失败',
type: 'error',
})
}else {
this.borrowInfo = res.data.RBI;
} else {
this.borrowInfo = res.data.list;
this.subForm.total = res.data.total;
}
this.loading = false;
})
},
cancel(id){
cancel(id) {
this.$http({
method:'delete',
method: 'delete',
url: '/borrowInfo/' + parseInt(id),
}).then(res =>{
}).then(res => {
ElMessage({
message: '撤销成功',
type: 'success',
@ -208,16 +213,16 @@ export default {
this.importTimeTable();
},
importTimeTable(){
importTimeTable() {
this.loading = true;
if (this.startDate === null || this.subForm.roomName === ''){
if (this.startDate === null || this.subForm.roomName === '') {
alert("请选择日期和教室");
this.loading = false;
return;
}
formData.append("startDate",this.startDate);
formData.append("roomName",this.subForm.roomName);
formData.append("startDate", this.startDate);
formData.append("roomName", this.subForm.roomName);
this.$http({
method: 'post',
@ -246,29 +251,6 @@ export default {
this.loading = false;
})
},
exportExcel() {
this.loading = true;
this.$http({
method: 'get',
url: '/borrowInfo/exportExcel',
responseType: "arraybuffer"
}).then((file) => {
//
let content = file.data;
// a
let elink = document.createElement("a");
//
elink.download ="借用记录.xls";
elink.style.display = "none";
let blob = new Blob([content], {type: "application/xls"})
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
this.loading = false;
})
},
}
}
</script>