[feat][M]: 新增在新增实验室时允许默认生成时间段

master
Romesum 5 years ago
parent 9670802c4c
commit 1657b2cb9f

@ -2,14 +2,17 @@ package com.hzu.bookingsystem.controller;
import com.hzu.bookingsystem.VO.ResultVO;
import com.hzu.bookingsystem.bean.LabBean;
import com.hzu.bookingsystem.bean.LabTimeBean;
import com.hzu.bookingsystem.converter.Map2Object;
import com.hzu.bookingsystem.dto.LabDTO;
import com.hzu.bookingsystem.service.LabService;
import com.hzu.bookingsystem.service.LabTimeService;
import com.hzu.bookingsystem.utils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -19,28 +22,45 @@ import java.util.Map;
public class LabController {
@Autowired
private LabService labService;
@Autowired
private LabTimeService labTimeService;
@Autowired
private UserController userController;
//创建实验室
@PostMapping(value = "/addLab" , consumes = "application/json")
public ResultVO addLab(@RequestBody Map<String,Object> map){
@PostMapping(value = "/addLab", consumes = "application/json")
public ResultVO addLab(@RequestBody Map<String, Object> map, HttpServletRequest request) {
//转换对象
LabBean lab1 = (LabBean) Map2Object.map2Object(map,LabBean.class);
System.out.println(lab1);
//查重
if(labService.findByName(lab1.getName()) != null)
{
return ResultVOUtil.error(-1,"该实验室已存在");
System.out.println(map);
LabBean lab1 = (LabBean) Map2Object.map2Object(map, LabBean.class);
//判断是否
LabBean newLab = labService.add(lab1);
// 插入16周所有可选时间段
if ((Boolean) map.get("fastInsert")) {
LabTimeBean labTime1 = (LabTimeBean) Map2Object.map2Object(map, LabTimeBean.class);
for (int i = 1; i <= 7; i++) {
for (int j = 1; j <= 5; j++) {
for (int k = 1; k <= 16; k++) {
labTimeService.add(LabTimeBean.builder()
.labId(newLab.getLabId())
.year(labTime1.getYear()).semester(labTime1.getSemester()).week(k).day(i).time(j)
.creatorId(userController.getUIdByCookie(request))
.status(0)
.createTime(new Date())
.build());
}
}
}
}
labService.add(lab1);
return ResultVOUtil.success();
}
//通过LabId删除实验室
@PostMapping(value = "/deleteLab" , consumes = "application/json")
public ResultVO deleteLab(@RequestBody LabBean lab){
@PostMapping(value = "/deleteLab", consumes = "application/json")
public ResultVO deleteLab(@RequestBody LabBean lab) {
//查找实验室是否存在
LabBean lab1 = labService.findByLabId(lab.getLabId());
if(lab1 == null) {
if (lab1 == null) {
return ResultVOUtil.error(-1, "该实验室不存在");
} else {
labService.deleteByLabId(lab1.getLabId());
@ -49,12 +69,12 @@ public class LabController {
}
//修改实验室信息
@PostMapping(value = "/updateLab" , consumes = "application/json")
public ResultVO updateLab(@RequestBody Map<String,Object> map , HttpServletRequest request){
@PostMapping(value = "/updateLab", consumes = "application/json")
public ResultVO updateLab(@RequestBody Map<String, Object> map, HttpServletRequest request) {
//转换对象
LabBean lab1 = (LabBean) Map2Object.map2Object(map,LabBean.class);
if(lab1.getLabId() == null){
return ResultVOUtil.error(-1,"该实验室不存在,无法修改");
LabBean lab1 = (LabBean) Map2Object.map2Object(map, LabBean.class);
if (lab1.getLabId() == null) {
return ResultVOUtil.error(-1, "该实验室不存在,无法修改");
} else {
labService.update(lab1);
}
@ -62,8 +82,8 @@ public class LabController {
}
//查找实验室
@GetMapping(value = "/findByLabId" , consumes = "application/json")
public ResultVO<Map<String,Object>> findByLabId(@RequestParam("LabId") Integer labId){
@GetMapping(value = "/findByLabId", consumes = "application/json")
public ResultVO<Map<String, Object>> findByLabId(@RequestParam("LabId") Integer labId) {
LabBean lab1 = labService.findByLabId(labId);
System.out.println(lab1);
return ResultVOUtil.success(lab1);
@ -71,7 +91,7 @@ public class LabController {
//查找所有实验室列表
@GetMapping(value = "/getLabList")
public ResultVO getLabList(){
public ResultVO getLabList() {
List<LabDTO> labList = labService.findAllLabInfo();
return ResultVOUtil.success(labList);
}

@ -159,4 +159,29 @@ public class LabTimeController {
return ResultVOUtil.success(labTimeService.findWeeks(labTime.getLabId(), labTime.getYear(), labTime.getSemester(), labTime.getDay(), labTime.getTime()));
}
// /**
// * author 吴志岳
// * 一键插入该学年学期 16周所有可选时间段
// */
// @PostMapping(value = "/fastInsert", consumes = "application/json")
// public ResultVO fastInsert(@RequestBody Map<String, Object> map, HttpServletRequest request) {
// //转换对象
// LabTimeBean labTime1 = (LabTimeBean) Map2Object.map2Object(map, LabTimeBean.class);
// // 插入16周所有可选时间段
// for (int i = 1; i <= 7; i++) {
// for (int j = 1; j <= 5; j++) {
// for (int k = 1; k <= 16; k++){
// labTimeService.add(LabTimeBean.builder()
// .labId((Integer)map.get("labId"))
// .year(labTime1.getYear()).semester(labTime1.getSemester()).week(k).day(i).time(j)
// .creatorId(userController.getUIdByCookie(request))
// .status(0)
// .createTime(new Date())
// .build());
// }
// }
// }
// return ResultVOUtil.success();
// }
}

Loading…
Cancel
Save