2023.6.13

1. 完成了基本框架的所有接口
This commit is contained in:
KaiyuanOSG 2023-06-13 20:47:23 +08:00
parent 912f58a3eb
commit 83c46f6b07
20 changed files with 430 additions and 26 deletions

View File

@ -0,0 +1,25 @@
package com.sdut.labex.Factory;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.BorrowInfo;
/**
* File: BorrowInfoFactory
* Created: 2023/6/13
* Author: springforest
* Description:
*/
public class BorrowInfoFactory {
public static BorrowInfo createBorrowInfo(JSONObject jsonObject) {
BorrowInfo borrowInfo = new BorrowInfo();
borrowInfo.setId(jsonObject.getInteger("id"));
borrowInfo.setApplyUser(jsonObject.getString("applyUser"));
borrowInfo.setTime(jsonObject.getString("time"));
borrowInfo.setDate(jsonObject.getDate("date"));
borrowInfo.setApplyDate(jsonObject.getDate("applyDate"));
borrowInfo.setIsAdmit(jsonObject.getInteger("isAdmit"));
borrowInfo.setRoomName(jsonObject.getString("roomName"));
return borrowInfo;
}
}

View File

@ -0,0 +1,27 @@
package com.sdut.labex.Factory;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.Experiment;
/**
* File: ExperimentFactory
* Created: 2023/6/13
* Author: springforest
* Description:
*/
public class ExperimentFactory {
public static Experiment createExperiment(JSONObject jsonObject) {
Experiment experiment = new Experiment();
experiment.setId(jsonObject.getInteger("id"));
experiment.setName(jsonObject.getString("name"));
experiment.setTime(jsonObject.getString("time"));
experiment.setDate(jsonObject.getDate("date"));
experiment.setRoomName(jsonObject.getString("roomName"));
experiment.setStatus(jsonObject.getInteger("status"));
experiment.setClassName(jsonObject.getString("className"));
experiment.setApplyTime(jsonObject.getDate("applyTime"));
experiment.setApplyUser(jsonObject.getString("applyUser"));
return experiment;
}
}

View File

@ -1,11 +1,49 @@
package com.sdut.labex.controller;
import com.alibaba.fastjson.JSONObject;
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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* File: BorrowInfoController
* Created: 2023/6/12
* Author: springforest
* Description:
*/
@RestController
@CrossOrigin
public class BorrowInfoController {
@Resource
private BorrowInfoService borrowInfoService;
@PostMapping("/borrowInfo")
public ResVo addBorrowInfo(@RequestBody JSONObject jsonObject) {
BorrowInfo borrowInfo = BorrowInfoFactory.createBorrowInfo(jsonObject);
return borrowInfoService.addBorrowInfo(borrowInfo);
}
@PutMapping("/borrowInfo")
public ResVo updateBorrowInfo(@RequestBody JSONObject jsonObject) {
BorrowInfo borrowInfo = BorrowInfoFactory.createBorrowInfo(jsonObject);
return borrowInfoService.updateBorrowInfo(borrowInfo);
}
@DeleteMapping("/borrowInfo/{id}")
public ResVo deleteBorrowInfoById(@PathVariable("id") Integer id) {
return borrowInfoService.deleteBorrowInfoById(id);
}
@PostMapping("/borrowInfo/{pageNum}/{pageSize}")
public ResVo getBorrowInfo(@RequestBody JSONObject jsonObject,
@PathVariable("pageNum") int pageNum,
@PathVariable("pageSize") int pageSize) {
BorrowInfo borrowInfo = BorrowInfoFactory.createBorrowInfo(jsonObject);
return borrowInfoService.getBorrowInfo(borrowInfo, pageNum, pageSize);
}
}

View File

@ -1,6 +1,7 @@
package com.sdut.labex.controller;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.Factory.ExperimentFactory;
import com.sdut.labex.entity.Experiment;
import com.sdut.labex.service.ExperimentsService;
import com.sdut.labex.utils.ResVo;
@ -25,14 +26,11 @@ public class ExperimentsController {
@Resource
private ExperimentsService experimentsService;
//添加实验
@PostMapping("/experiment")
public ResVo applyExperiment(@RequestBody JSONObject jsonObject) {
Experiment experiment = new Experiment();
experiment.setName(jsonObject.getString("name"));
experiment.setTime(jsonObject.getString("time"));
experiment.setDate(jsonObject.getDate("date"));
experiment.setClassName(jsonObject.getString("className"));
experiment.setRoomName(jsonObject.getString("roomName"));
Experiment experiment = ExperimentFactory.createExperiment(jsonObject);
//获取当前时间
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@ -48,25 +46,42 @@ public class ExperimentsController {
return experimentsService.applyExperiment(experiment);
}
//修改实验信息
@PutMapping("/experiment")
public ResVo updateExperiment(@RequestBody JSONObject jsonObject) {
Experiment experiment = jsonObject.toJavaObject(Experiment.class);
return experimentsService.updateExperiment(experiment);
}
//删除实验
@DeleteMapping("/experiment/{id}")
public ResVo deleteExperiment(@PathVariable String id) {
return experimentsService.deleteExperiment(id);
}
//获取未审核的实验
@GetMapping("/unreviewed")
public ResVo getUnreviewedExperiments() {
return experimentsService.getUnreviewedExperiments();
}
//设置实验审核状态
@PutMapping("/isAdmitted/{id}{status}")
public ResVo isAdmit(@PathVariable Integer id, @PathVariable Integer status) {
return experimentsService.isAdmitted(id, status);
}
//获取实验列表
@PostMapping("/experiments/{pageNum}/{pageSize}")
public ResVo getExperiments(@RequestBody JSONObject jsonObject, @PathVariable int pageNum, @PathVariable int pageSize) {
Experiment experiment = ExperimentFactory.createExperiment(jsonObject);
return experimentsService.getExperiments(experiment, pageNum, pageSize);
}
//按ID获取实验
@GetMapping("/experiment/{id}")
public ResVo getExperiment(@PathVariable String id) {
return experimentsService.getExperiment(id);
}
}

View File

@ -1,11 +1,51 @@
package com.sdut.labex.controller;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.Room;
import com.sdut.labex.service.RoomService;
import com.sdut.labex.utils.ResVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* File: RoomController
* Created: 2023/6/12
* Author: springforest
* Description:
*/
@RestController
@CrossOrigin
public class RoomController {
@Resource
private RoomService roomService;
@GetMapping("/room")
public ResVo getAllRoom() {
return roomService.getAllRoom();
}
@PostMapping("/room")
public ResVo addRoom(@RequestBody JSONObject jsonObject) {
Room room = new Room();
room.setName(jsonObject.getString("name"));
room.setDescription(jsonObject.getString("description"));
room.setStatus(jsonObject.getInteger("status"));
return roomService.addRoom(room);
}
@PutMapping("/room")
public ResVo updateRoom(@RequestBody JSONObject jsonObject) {
Room room = new Room();
room.setId(jsonObject.getInteger("id"));
room.setName(jsonObject.getString("name"));
room.setDescription(jsonObject.getString("description"));
room.setStatus(jsonObject.getInteger("status"));
return roomService.updateRoom(room);
}
@DeleteMapping("/room/{id}")
public ResVo removeRoom(@PathVariable("id") int id) {
return roomService.deleteRoomById(id);
}
}

View File

@ -1,6 +1,13 @@
package com.sdut.labex.controller;
import com.alibaba.fastjson.JSONObject;
import com.sdut.labex.entity.TimeOption;
import com.sdut.labex.service.TimeOptionService;
import com.sdut.labex.utils.ResVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* File: TimeOptionController
@ -9,6 +16,34 @@ import org.springframework.stereotype.Controller;
* Description:
*/
@Controller
@CrossOrigin
public class TimeOptionController {
@Resource
private TimeOptionService timeOptionService;
@PostMapping("/timeOption")
public ResVo addTimeOption(@RequestBody JSONObject jsonObject) {
TimeOption timeOption = new TimeOption();
timeOption.setName(jsonObject.getString("name"));
return timeOptionService.addTimeOption(timeOption);
}
@PutMapping("/timeOption")
public ResVo updateTimeOption(@RequestBody JSONObject jsonObject) {
TimeOption timeOption = new TimeOption();
timeOption.setId(jsonObject.getInteger("id"));
timeOption.setName(jsonObject.getString("name"));
return timeOptionService.updateTimeOption(timeOption);
}
@DeleteMapping("/timeOption")
public ResVo deleteTimeOption(@RequestBody JSONObject jsonObject) {
return timeOptionService.deleteTimeOption(jsonObject.getInteger("id"));
}
@GetMapping("/timeOptions")
public ResVo getTimeOptions() {
return timeOptionService.getTimeOptions();
}
}

View File

@ -26,7 +26,7 @@ public class BorrowInfo implements Serializable {
/**
* 借用人
*/
private String name;
private String applyUser;
/**
* 时间
@ -49,9 +49,9 @@ public class BorrowInfo implements Serializable {
private Integer isAdmit;
/**
*
* 教室名称
*/
private Integer roomId;
private String roomName;
@TableField(exist = false)
private static final long serialVersionUID = 1L;

View File

@ -58,6 +58,11 @@ public class Experiment implements Serializable {
*/
private Date applyTime;
/**
* 申请人
*/
private String applyUser;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}

View File

@ -1,6 +1,7 @@
package com.sdut.labex.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdut.labex.entity.BorrowInfo;
import org.apache.ibatis.annotations.Mapper;
@ -12,7 +13,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface BorrowInfoMapper extends BaseMapper<BorrowInfo> {
public Page<BorrowInfo> queryBorrowInfoByOptions(Page<BorrowInfo> page, BorrowInfo borrowInfo);
}

View File

@ -1,6 +1,7 @@
package com.sdut.labex.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sdut.labex.entity.Experiment;
import org.apache.ibatis.annotations.Mapper;
@ -12,7 +13,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ExperimentsMapper extends BaseMapper<Experiment> {
public Page<Experiment> getExperimentsByPage(Page<Experiment> page, Experiment experiment);
}

View File

@ -2,6 +2,7 @@ package com.sdut.labex.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sdut.labex.entity.BorrowInfo;
import com.sdut.labex.utils.ResVo;
/**
* @author springforest
@ -10,4 +11,11 @@ import com.sdut.labex.entity.BorrowInfo;
*/
public interface BorrowInfoService extends IService<BorrowInfo> {
public ResVo addBorrowInfo(BorrowInfo borrowInfo);
public ResVo deleteBorrowInfoById(Integer id);
public ResVo updateBorrowInfo(BorrowInfo borrowInfo);
public ResVo getBorrowInfo(BorrowInfo borrowInfo, int pageNum, int pageSize);
}

View File

@ -18,7 +18,7 @@ public interface ExperimentsService extends IService<Experiment> {
public ResVo getExperiment(String id);
public ResVo getExperiments();
public ResVo getExperiments(Experiment experiment, int pageNum, int pageSize);
public ResVo getUnreviewedExperiments();

View File

@ -2,6 +2,7 @@ package com.sdut.labex.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sdut.labex.entity.Room;
import com.sdut.labex.utils.ResVo;
/**
* @author springforest
@ -10,4 +11,11 @@ import com.sdut.labex.entity.Room;
*/
public interface RoomService extends IService<Room> {
public ResVo getAllRoom();
public ResVo deleteRoomById(int id);
public ResVo addRoom(Room room);
public ResVo updateRoom(Room room);
}

View File

@ -2,6 +2,7 @@ package com.sdut.labex.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sdut.labex.entity.TimeOption;
import com.sdut.labex.utils.ResVo;
/**
* @author springforest
@ -9,5 +10,11 @@ import com.sdut.labex.entity.TimeOption;
* @createDate 2023-06-12 08:07:15
*/
public interface TimeOptionService extends IService<TimeOption> {
public ResVo addTimeOption(TimeOption timeOption);
public ResVo deleteTimeOption(int id);
public ResVo updateTimeOption(TimeOption timeOption);
public ResVo getTimeOptions();
}

View File

@ -1,11 +1,17 @@
package com.sdut.labex.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.BorrowInfo;
import com.sdut.labex.mapper.BorrowInfoMapper;
import com.sdut.labex.service.BorrowInfoService;
import com.sdut.labex.utils.ResVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* @author springforest
* @description 针对表borrowInfo(借用记录)的数据库操作Service实现
@ -15,6 +21,62 @@ import org.springframework.stereotype.Service;
public class BorrowInfoServiceImpl extends ServiceImpl<BorrowInfoMapper, BorrowInfo>
implements BorrowInfoService {
@Resource
private BorrowInfoMapper borrowInfoMapper;
@Override
public ResVo addBorrowInfo(BorrowInfo borrowInfo) {
try {
borrowInfoMapper.insert(borrowInfo);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("借用失败");
}
return ResVo.ok("借用成功");
}
@Override
public ResVo deleteBorrowInfoById(Integer id) {
if (borrowInfoMapper.selectById(id) == null) {
return ResVo.error("该借用记录不存在");
}
try {
borrowInfoMapper.deleteById(id);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("删除失败");
}
return ResVo.ok("删除成功");
}
@Override
public ResVo updateBorrowInfo(BorrowInfo borrowInfo) {
if (borrowInfoMapper.selectById(borrowInfo.getId()) == null) {
return ResVo.error("该借用记录不存在");
}
try {
borrowInfoMapper.updateById(borrowInfo);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("更新失败");
}
return ResVo.ok("更新成功");
}
@Override
public ResVo getBorrowInfo(BorrowInfo borrowInfo, int pageNum, int pageSize) {
Page<BorrowInfo> page = new Page<>(pageNum, pageSize);
borrowInfoMapper.queryBorrowInfoByOptions(page, borrowInfo);
Map<String, Object> res = new HashMap<>();
res.put("total", page.getTotal());
res.put("current", page.getCurrent());
res.put("list", page.getRecords());
return ResVo.ok(res);
}
}

View File

@ -1,6 +1,7 @@
package com.sdut.labex.service.impl;
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.entity.Experiment;
import com.sdut.labex.mapper.ExperimentsMapper;
@ -10,6 +11,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -77,18 +79,39 @@ public class ExperimentsServiceImpl extends ServiceImpl<ExperimentsMapper, Exper
}
@Override
public ResVo getExperiments() {
public ResVo getExperiments(Experiment experiment, int pageNum, int pageSize) {
Page<Experiment> page = new Page<>(pageNum, pageSize);
experimentsMapper.getExperimentsByPage(page, experiment);
Map<String, Object> res = new HashMap<>();
res.put("list", page.getRecords());
res.put("total", page.getTotal());
res.put("current", page.getCurrent());
return ResVo.ok(res);
}
@Override
public ResVo getUnreviewedExperiments() {
return null;
QueryWrapper<Experiment> queryWrapper = new QueryWrapper<>();
queryWrapper.select("status", "0");
List<Experiment> list = experimentsMapper.selectList(queryWrapper);
Map<String, Object> map = new HashMap<>();
map.put("list", list);
return ResVo.ok(map);
}
@Override
public ResVo isAdmitted(int id, int status) {
return null;
Experiment experiment = experimentsMapper.selectById(id);
if (experiment == null)
return ResVo.error("该实验不存在");
experiment.setStatus(status);
try {
experimentsMapper.updateById(experiment);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error();
}
return ResVo.ok();
}
}

View File

@ -4,8 +4,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.Room;
import com.sdut.labex.mapper.RoomMapper;
import com.sdut.labex.service.RoomService;
import com.sdut.labex.utils.ResVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author springforest
* @description 针对表room(房间)的数据库操作Service实现
@ -15,6 +21,58 @@ import org.springframework.stereotype.Service;
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room>
implements RoomService {
@Resource
private RoomMapper roomMapper;
@Override
public ResVo getAllRoom() {
List<Room> list = roomMapper.selectList(null);
Map<String, Object> map = new HashMap<>();
map.put("list", list);
return ResVo.ok(map);
}
@Override
public ResVo deleteRoomById(int id) {
if (roomMapper.selectById(id) == null) {
return ResVo.error("该房间不存在");
}
try {
roomMapper.deleteById(id);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("删除失败");
}
return ResVo.ok("删除成功");
}
@Override
public ResVo addRoom(Room room) {
try {
roomMapper.insert(room);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("添加失败");
}
return ResVo.ok("添加成功");
}
@Override
public ResVo updateRoom(Room room) {
if (roomMapper.selectById(room.getId()) == null) {
return ResVo.error("该房间不存在");
}
try {
roomMapper.updateById(room);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("更新失败");
}
return ResVo.ok("更新成功");
}
}

View File

@ -4,8 +4,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdut.labex.entity.TimeOption;
import com.sdut.labex.mapper.TimeOptionMapper;
import com.sdut.labex.service.TimeOptionService;
import com.sdut.labex.utils.ResVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author springforest
* @description 针对表timeOption(时间)的数据库操作Service实现
@ -14,7 +20,49 @@ import org.springframework.stereotype.Service;
@Service
public class TimeOptionServiceImpl extends ServiceImpl<TimeOptionMapper, TimeOption>
implements TimeOptionService {
@Resource
private TimeOptionMapper timeOptionMapper;
@Override
public ResVo addTimeOption(TimeOption timeOption) {
try {
timeOptionMapper.insert(timeOption);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("添加失败");
}
return ResVo.ok("添加成功");
}
@Override
public ResVo deleteTimeOption(int id) {
try {
timeOptionMapper.deleteById(id);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("删除失败");
}
return ResVo.ok("删除成功");
}
@Override
public ResVo updateTimeOption(TimeOption timeOption) {
try {
timeOptionMapper.updateById(timeOption);
} catch (Exception e) {
e.printStackTrace();
return ResVo.error("更新失败");
}
return ResVo.ok("更新成功");
}
@Override
public ResVo getTimeOptions() {
List<TimeOption> list = timeOptionMapper.selectList(null);
Map<String, Object> res = new HashMap<>();
res.put("list", list);
return ResVo.ok(res);
}
}

View File

@ -6,18 +6,17 @@
<resultMap id="BaseResultMap" type="com.sdut.labex.entity.BorrowInfo">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="applyUser" column="apply_user" jdbcType="VARCHAR"/>
<result property="time" column="time" jdbcType="VARCHAR"/>
<result property="date" column="date" jdbcType="DATE"/>
<result property="applyDate" column="apply_date" jdbcType="TIMESTAMP"/>
<result property="isAdmit" column="is_admit" jdbcType="INTEGER"/>
<result property="roomId" column="room_id" jdbcType="INTEGER"/>
<result property="roomName" column="room_name" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
id
,name,time,
date,apply_date,is_admit,
room_id
</sql>
<select id="queryBorrowInfoByOptions" resultType="com.sdut.labex.entity.BorrowInfo">
select *
from borrow_info
</select>
</mapper>

View File

@ -20,4 +20,8 @@
date,room_name,status,
class_name
</sql>
<select id="getExperimentsByPage" resultType="com.sdut.labex.entity.Experiment">
</select>
</mapper>