|
|
|
@@ -32,17 +32,24 @@ import com.xueyi.system.resource.controller.api.BaseApiController; |
|
|
|
import com.xueyi.system.staff.mapper.DmStaffMapper; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 会议室预约管理 API |
|
|
|
@@ -292,7 +299,7 @@ public class DmMeetingInnerApiController extends BaseApiController { |
|
|
|
@GetMapping(value = "/lists") |
|
|
|
public JSONObject listAllInner() { |
|
|
|
List<DmMeetingOrdersPo> list = dmMeetingOrdersMapper.findAllList(); |
|
|
|
List<DmMeetingOrdersDto> res = new ArrayList<>(); |
|
|
|
List<DmMeetingOrdersPo> res = new ArrayList<>(); |
|
|
|
list.forEach(item -> { |
|
|
|
DmMeetingOrdersDto dto = dmMeetingOrdersConverter.mapperDto(item); |
|
|
|
DmMeetingRoomsPo mr = dmMeetingRoomsMapper.findById(dto.getSpaceId()); |
|
|
|
@@ -303,4 +310,128 @@ public class DmMeetingInnerApiController extends BaseApiController { |
|
|
|
return outputSuccess(res).toJSON(); |
|
|
|
} |
|
|
|
|
|
|
|
List freeTimePart (Long roomId, List<DmMeetingOrdersPo> objects, String currentTime) { |
|
|
|
List<JSONObject> freeTimeList = new ArrayList<>(); |
|
|
|
|
|
|
|
if (null == objects || objects.size() ==0) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", currentTime); |
|
|
|
json.put("endTime", 0); |
|
|
|
json.put("roomId", roomId); |
|
|
|
freeTimeList.add(json); |
|
|
|
return freeTimeList; |
|
|
|
} |
|
|
|
if (objects.size() ==1) { |
|
|
|
DmMeetingOrdersPo current = objects.get(0); |
|
|
|
if (DateUtils.formatDate(current.getStartTime(), "HH:mm").compareTo(currentTime) > 0 ) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", currentTime); |
|
|
|
json.put("endTime", DateUtils.formatDate(current.getStartTime(), "HH:mm")); |
|
|
|
json.put("roomId", roomId); |
|
|
|
freeTimeList.add(json); |
|
|
|
} |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", DateUtils.formatDate(current.getEndTime(), "HH:mm")); |
|
|
|
json.put("endTime", 0); |
|
|
|
json.put("roomId", roomId); |
|
|
|
freeTimeList.add(json); |
|
|
|
return freeTimeList; |
|
|
|
} |
|
|
|
|
|
|
|
if (objects.size() > 1) |
|
|
|
for (int i = 0; i < objects.size() - 1; i++) { |
|
|
|
DmMeetingOrdersPo current = objects.get(i); |
|
|
|
DmMeetingOrdersPo next = objects.get(i + 1); |
|
|
|
|
|
|
|
Date freeStartTime = current.getEndTime(); |
|
|
|
Date freeEndTime = next.getStartTime(); |
|
|
|
|
|
|
|
String freeStartTimeStr = DateUtils.formatDate(current.getEndTime(), "HH:mm"); |
|
|
|
String freeEndTimeStr = DateUtils.formatDate(next.getStartTime(), "HH:mm"); |
|
|
|
|
|
|
|
if (i==0 && DateUtils.formatDate(current.getStartTime(), "HH:mm").compareTo(currentTime) > 0 ) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", currentTime); |
|
|
|
json.put("endTime", DateUtils.formatDate(current.getStartTime(), "HH:mm")); |
|
|
|
json.put("roomId", roomId); |
|
|
|
freeTimeList.add(json); |
|
|
|
} |
|
|
|
|
|
|
|
if (freeStartTime.before(freeEndTime)) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", freeStartTimeStr); |
|
|
|
json.put("endTime", freeEndTimeStr); |
|
|
|
json.put("roomId", roomId); |
|
|
|
freeTimeList.add(json); |
|
|
|
} |
|
|
|
|
|
|
|
if (i==objects.size() - 2) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
json.put("startTime", freeEndTimeStr); |
|
|
|
json.put("endTime", 0); |
|
|
|
json.put("roomId", current.getSpaceId()); |
|
|
|
freeTimeList.add(json); |
|
|
|
} |
|
|
|
} |
|
|
|
return freeTimeList; |
|
|
|
} |
|
|
|
|
|
|
|
@InnerAuth |
|
|
|
@GetMapping("/recent/{deptId}/{dateStr}") |
|
|
|
@ResponseBody |
|
|
|
public List<JSONObject> recent(@PathVariable(value = "deptId") Long deptId,@PathVariable(value = "dateStr") String dateStr,@RequestParam(value = "roomId", required = false) Long roomId, HttpServletRequest request) { |
|
|
|
|
|
|
|
List<DmMeetingOrdersPo> list = new ArrayList<>(); |
|
|
|
List<Long> ids = new ArrayList<>(); |
|
|
|
if (null == roomId) { |
|
|
|
DmMeetingRoomsPo dm = new DmMeetingRoomsPo(); |
|
|
|
dm.setDeptId(deptId); |
|
|
|
List<DmMeetingRoomsPo> pos = dmMeetingRoomsMapper.selectRoomList(dm); |
|
|
|
ids = pos.stream().map(DmMeetingRoomsPo::getId).collect(Collectors.toList()); |
|
|
|
list = dmMeetingOrdersMapper.findListByDateStr(dateStr); |
|
|
|
} else { |
|
|
|
DmMeetingRoomsPo po = dmMeetingRoomsMapper.findById(roomId); |
|
|
|
list = dmMeetingOrdersMapper.findListByDate(dateStr, po.getId()); |
|
|
|
ids.add(roomId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//过滤掉今天的已经过去的预约记录,并按开始时间进行排序 |
|
|
|
list = list.stream().filter(t->DateUtils.formatDate(t.getOrderDate(), "yyyy-MM-dd").compareTo(DateUtils.formatDate(new Date(), "yyyy-MM-dd"))>0 || (DateUtils.formatDate(t.getOrderDate(), "yyyy-MM-dd").compareTo(DateUtils.formatDate(new Date(), "yyyy-MM-dd"))==0 && DateUtils.formatDate(t.getStartTime(), "HH:mm").compareTo(DateUtils.formatDate(new Date(), "HH:mm"))>0)).sorted((o1, o2) -> o2.getStartTime().compareTo(o1.getStartTime())).collect(Collectors.toList());; |
|
|
|
|
|
|
|
/*List<String> times = new ArrayList<>(); |
|
|
|
for (int i = 0 ;i<list.size();i++){ |
|
|
|
times.add(DateUtils.formatDate(list.get(i).getStartTime(),"HH:mm")); |
|
|
|
times.add(DateUtils.formatDate(list.get(i).getEndTime(),"HH:mm")); |
|
|
|
}*/ |
|
|
|
|
|
|
|
//获得当前时间开始最近的整点,或者半点 |
|
|
|
LocalTime currentTime = LocalTime.now(); |
|
|
|
if (currentTime.getMinute() >= 30) { |
|
|
|
currentTime = currentTime.plusHours(1).withMinute(0).withSecond(0); |
|
|
|
} else { |
|
|
|
currentTime = currentTime.withMinute(30).withSecond(0); |
|
|
|
} |
|
|
|
|
|
|
|
String currentStr = currentTime.format(DateTimeFormatter.ofPattern("HH:mm")); |
|
|
|
Map<Long, List<DmMeetingOrdersPo>> groupedByRoom = list.stream() |
|
|
|
.collect(Collectors.groupingBy(DmMeetingOrdersPo::getSpaceId)); |
|
|
|
|
|
|
|
Map<Long, List<JSONObject>> freeTime = new HashMap<>(); |
|
|
|
|
|
|
|
for(int i=0;i<ids.size();i++){ |
|
|
|
Long key = ids.get(i); |
|
|
|
//groupedByRoom.get(key)可能为空 |
|
|
|
freeTime.put(key, freeTimePart(key, groupedByRoom.get(key), currentStr)); |
|
|
|
} |
|
|
|
List<JSONObject> arr = new ArrayList<>(); |
|
|
|
for (int i=0;i<freeTime.keySet().size();i++){ |
|
|
|
Long key = (Long) freeTime.keySet().toArray()[i]; |
|
|
|
List<JSONObject> value = freeTime.get(key); |
|
|
|
arr.addAll(freeTime.get(key)); |
|
|
|
} |
|
|
|
arr = arr.stream().sorted((o1, o2) -> o2.getString("startTime").compareTo(o1.getString("startTime"))).collect(Collectors.toList()); |
|
|
|
return arr; |
|
|
|
} |
|
|
|
|
|
|
|
} |