Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.edu.bit.ruixin.community.controller;

import cn.edu.bit.ruixin.base.common.CommonResult;
import cn.edu.bit.ruixin.base.common.ResultCode;
import cn.edu.bit.ruixin.base.common.exp.CommonResult;
import cn.edu.bit.ruixin.community.annotation.MsgSecCheck;
import cn.edu.bit.ruixin.community.domain.Appointment;
import cn.edu.bit.ruixin.community.domain.Room;
Expand All @@ -12,7 +11,9 @@
import cn.edu.bit.ruixin.community.service.ScheduleService;
import cn.edu.bit.ruixin.community.service.UserService;
import cn.edu.bit.ruixin.community.vo.AppointmentInfoVo;
import cn.edu.bit.ruixin.community.vo.PageVo;
import lombok.Getter;
import lombok.NoArgsConstructor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -64,31 +65,25 @@ private AppointmentInfoVo getAppointmentInfoVo(Appointment appointment) {

@PreAuthorize("hasAuthority('appointCheck')")
@GetMapping("")
public CommonResult lookupAppointmentById(@RequestParam("id") Integer id) {
public CommonResult<AppointmentInfoReturnVo> lookupAppointmentById(@RequestParam("id") Integer id) {
Appointment appointment = appointmentService.getAppointmentById(id);
AppointmentInfoVo infoVo = getAppointmentInfoVo(appointment);

return CommonResult.ok(ResultCode.SUCCESS).data("appointment", infoVo);
return CommonResult.<AppointmentInfoReturnVo>ok()
.data(new AppointmentInfoReturnVo(infoVo));
}

@PreAuthorize("hasAuthority('appointCheck')")
@GetMapping("/{current}/{limit}/{schoolId}")
public CommonResult lookupAppointmentBySchoolId(@PathVariable("current") int current, @PathVariable("limit") int limit, @PathVariable("schoolId") String schoolId) {
public CommonResult<PageVo<AppointmentInfoVo>> lookupAppointmentBySchoolId(@PathVariable("current") int current, @PathVariable("limit") int limit, @PathVariable("schoolId") String schoolId) {
// 构造分页对象
Pageable pageable = PageRequest.of(current, limit);
Page<Appointment> page = appointmentService.getAppointmentsBySchoolId(pageable, schoolId);
List<Appointment> list = page.getContent();

List<AppointmentInfoVo> infoVos = new ArrayList<>();
list.forEach(appointment -> infoVos.add(getAppointmentInfoVo(appointment)));

Map<String, Object> map = new HashMap<>();
map.put("totalElements", page.getTotalElements());
map.put("totalPages", page.getTotalPages());
map.put("hasNext", page.hasNext());
map.put("hasPrevious", page.hasPrevious());
map.put("items", infoVos);
return CommonResult.ok(ResultCode.SUCCESS).data(map);
PageVo<AppointmentInfoVo> res = PageVo.convertToVo(page)
.foreach(appointment -> getAppointmentInfoVo(appointment));
return CommonResult.<PageVo<AppointmentInfoVo>>ok()
.data(res);
}

/**
Expand All @@ -98,12 +93,13 @@ public CommonResult lookupAppointmentBySchoolId(@PathVariable("current") int cur
*/
@PreAuthorize("hasAuthority('appointCheck')")
@GetMapping("all")
public CommonResult getAllAppointment(@RequestParam(required = false, name = "status") String status) {
public CommonResult<AppointmentListReturnVo> getAllAppointment(@RequestParam(required = false, name = "status") String status) {
List<Appointment> list = appointmentService.getAllAppointment(status);
List<AppointmentInfoVo> infoVos = new ArrayList<>();
list.forEach(appointment -> infoVos.add(getAppointmentInfoVo(appointment)));

return CommonResult.ok(ResultCode.SUCCESS).data("appointments", infoVos);
return CommonResult.<AppointmentListReturnVo>ok()
.data(new AppointmentListReturnVo(infoVos));
}

/**
Expand All @@ -115,35 +111,27 @@ public CommonResult getAllAppointment(@RequestParam(required = false, name = "st
*/
@PreAuthorize("hasAuthority('appointCheck')")
@GetMapping("/{current}/{limit}")
public CommonResult getAppointmentPages(@PathVariable("current") int current, @PathVariable("limit") int limit, @RequestParam(required = false, name = "status") String status) {
public CommonResult<PageVo<AppointmentInfoVo>> getAppointmentPages(@PathVariable("current") int current, @PathVariable("limit") int limit, @RequestParam(required = false, name = "status") String status) {
// 构造排序对象
// Sort sort = Sort.by(Sort.Direction.DESC, "launchDate", "execDate", "launchTime");
// 构造分页对象
Pageable pageable = PageRequest.of(current, limit);
Page<Appointment> page = appointmentService.getAppointmentPages(pageable, status);
List<Appointment> list = page.getContent();

List<AppointmentInfoVo> infoVos = new ArrayList<>();
list.forEach(appointment -> infoVos.add(getAppointmentInfoVo(appointment)));
PageVo<AppointmentInfoVo> res = PageVo.convertToVo(page)
.foreach(appointment -> getAppointmentInfoVo(appointment));

Map<String, Object> map = new HashMap<>();
map.put("totalElements", page.getTotalElements());
map.put("totalPages", page.getTotalPages());
map.put("hasNext", page.hasNext());
map.put("hasPrevious", page.hasPrevious());
map.put("items", infoVos);
return CommonResult.ok(ResultCode.SUCCESS).data(map);
return CommonResult.<PageVo<AppointmentInfoVo>>ok().data(res);
}

@PreAuthorize("hasAuthority('appointCheck')")
@MsgSecCheck({"conductor", "checkNote"})
@PutMapping("/check/{appointmentId}")
public CommonResult check(@PathVariable(name = "appointmentId") Integer id,
public CommonResult<Void> check(@PathVariable(name = "appointmentId") Integer id,
@RequestParam(required = true, name = "status") String status,
@RequestParam(required = true, name = "conductor") String conductor,
@RequestParam("checkNote") String checkNote) {
appointmentService.checkOutAppointment(id, status, conductor, checkNote);
return CommonResult.ok(ResultCode.SUCCESS).msg("审批操作成功!");
return CommonResult.<Void>ok().msg("审批操作成功!");
}

/**
Expand All @@ -153,17 +141,19 @@ public CommonResult check(@PathVariable(name = "appointmentId") Integer id,
*/
@PreAuthorize("hasAuthority('appoint')")
@PostMapping("/appoint")
public CommonResult appoint(@RequestBody(required = true) AppointmentInfoVo[] infoVos) {
public CommonResult<AppointmentConfilctingReturnVo> appoint(@RequestBody(required = true) AppointmentInfoVo[] infoVos) {
List<Appointment> appointments = Arrays.stream(infoVos)
.map(infoVo -> AppointmentInfoVo.convertToPo(infoVo))
.collect(Collectors.toList());

List<Appointment> deletedAppointments = appointmentService.addNewAppointmentsByAdmin(appointments);
AppointmentConfilctingReturnVo res = new AppointmentConfilctingReturnVo(
deletedAppointments.stream()
.map(appointment -> getAppointmentInfoVo(appointment))
.collect(Collectors.toList()));

return CommonResult.ok(ResultCode.SUCCESS).msg("管理员预约成功").data("conflictingAppointments",
deletedAppointments.stream()
.map(appointment -> getAppointmentInfoVo(appointment))
.collect(Collectors.toList()));
return CommonResult.<AppointmentConfilctingReturnVo>ok()
.msg("管理员预约成功").data(res);
}

/**
Expand All @@ -173,9 +163,9 @@ public CommonResult appoint(@RequestBody(required = true) AppointmentInfoVo[] in
*/
@PreAuthorize("hasAuthority('appoint')")
@PutMapping("/cancel")
public CommonResult cancel(@RequestBody(required = true) Integer[] ids) {
public CommonResult<Void> cancel(@RequestBody(required = true) Integer[] ids) {
appointmentService.cancelAppointmentsByAdminThroughIds(ids);
return CommonResult.ok(ResultCode.SUCCESS).msg("撤销预约成功!");
return CommonResult.<Void>ok().msg("撤销预约成功!");
}

/**
Expand All @@ -184,15 +174,16 @@ public CommonResult cancel(@RequestBody(required = true) Integer[] ids) {
*/
@PreAuthorize("hasAuthority('appoint')")
@GetMapping("/allByAdmin")
public CommonResult getAllAppointmentAppointedByAdmin() {
public CommonResult<AppointmentListReturnVo> getAllAppointmentAppointedByAdmin() {
List<Appointment> appointments = appointmentService.getAllAppointmentsAppointedByAdmin();
return CommonResult.ok(ResultCode.SUCCESS)
.data("appointments", appointments.stream()
.map(appointment -> {
AppointmentInfoVo appointmentInfoVo = getAppointmentInfoVo(appointment);
return appointmentInfoVo;
})
.collect(Collectors.toList()));
return CommonResult.<AppointmentListReturnVo>ok()
.data(new AppointmentListReturnVo(
appointments.stream()
.map(appointment -> {
AppointmentInfoVo appointmentInfoVo = getAppointmentInfoVo(appointment);
return appointmentInfoVo;
})
.collect(Collectors.toList())));
}

/**
Expand All @@ -201,9 +192,9 @@ public CommonResult getAllAppointmentAppointedByAdmin() {
*/
@PreAuthorize("hasAuthority('appoint')")
@GetMapping("/availablePeriod")
public CommonResult getAvailablePeriodByRoomId(@RequestParam(name = "roomId") Integer roomId, @RequestParam(name = "conductor") String conductor, @RequestParam(name = "date") String date) {
Map result = roomService.getRoomFreeTimeByAdmin(roomId, conductor, date);
return CommonResult.ok(ResultCode.SUCCESS)
public CommonResult<Map<String,List<Schedule>>> getAvailablePeriodByRoomId(@RequestParam(name = "roomId") Integer roomId, @RequestParam(name = "conductor") String conductor, @RequestParam(name = "date") String date) {
Map<String,List<Schedule>> result = roomService.getRoomFreeTimeByAdmin(roomId, conductor, date);
return CommonResult.<Map<String,List<Schedule>>>ok()
.data(result);
}

Expand All @@ -213,37 +204,76 @@ public CommonResult getAvailablePeriodByRoomId(@RequestParam(name = "roomId") In
*/
@PreAuthorize("hasAuthority('appointCheck')")
@GetMapping("/allTime")
public CommonResult getAllTimeByAdmin() {
public CommonResult<ScheduleListVo> getAllTimeByAdmin() {
List<Schedule> scheduleList = scheduleService.getAllTime();
return CommonResult.<ScheduleListVo>ok()
.data(ScheduleListVo.getFrom(scheduleList));
}
}

@Getter
class scheduleBeginTime {
private Integer id;
private String beginTime;

public scheduleBeginTime(Integer id, String beginTime) {
this.id = id;
this.beginTime = beginTime;
}
@Getter
@NoArgsConstructor
class ScheduleListVo {

@Getter
class scheduleBeginTime {
private Integer id;
private String beginTime;

public scheduleBeginTime(Schedule schedule) {
this.id = schedule.getId();
this.beginTime = schedule.getBegin();
}
}

@Getter
class scheduleEndTime {
private Integer id;
private String endTime;
@Getter
class scheduleEndTime {
private Integer id;
private String endTime;

public scheduleEndTime(Integer id, String endTime) {
this.id = id;
this.endTime = endTime;
}
public scheduleEndTime(Schedule schedule) {
this.id = schedule.getId();
this.endTime = schedule.getEnd();
}
}
private List<scheduleBeginTime> beginTimes;
private List<scheduleEndTime> endTimes;

public static ScheduleListVo getFrom(List<Schedule> scheduleList) {
ScheduleListVo res = new ScheduleListVo();
res.beginTimes = scheduleList.stream()
.map(schedule -> res.new scheduleBeginTime(schedule))
.collect(Collectors.toList());
res.endTimes = scheduleList.stream()
.map(schedule -> res.new scheduleEndTime(schedule))
.collect(Collectors.toList());
return res;
}
}

@Getter
class AppointmentInfoReturnVo {
private AppointmentInfoVo appointment;

AppointmentInfoReturnVo(AppointmentInfoVo infovo){
this.appointment = infovo;
}
}

@Getter
class AppointmentListReturnVo {
private List<AppointmentInfoVo> appointments;

AppointmentListReturnVo(List<AppointmentInfoVo> infovo){
this.appointments = infovo;
}
}

return CommonResult.ok(ResultCode.SUCCESS)
.data("beginTimes", scheduleList.stream()
.map(schedule -> new scheduleBeginTime(schedule.getId(), schedule.getBegin()))
.collect(Collectors.toList()))
.data("endTimes", scheduleList.stream()
.map(schedule -> new scheduleEndTime(schedule.getId(), schedule.getEnd()))
.collect(Collectors.toList()));
@Getter
class AppointmentConfilctingReturnVo {
private List<AppointmentInfoVo> conflictingAppointments;

AppointmentConfilctingReturnVo(List<AppointmentInfoVo> infovo){
this.conflictingAppointments = infovo;
}
}