Skip to content
Merged
Show file tree
Hide file tree
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,6 +1,7 @@
package devkor.com.teamcback.domain.ble.controller;

import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
Expand All @@ -16,6 +17,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/ble")
Expand Down Expand Up @@ -63,4 +66,14 @@ public CommonResponse<BLETimePatternRes> getBLETimePattern(
return CommonResponse.success(bleService.getBLETimePattern(placeId));
}

@GetMapping("/list")
@Operation(summary = "BLE 가능 place 목록 조회",
description = "ble_device 테이블에 등록된 BLE 장비 목록(id, deviceName, placeId, capacity)을 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다.")
})
public CommonResponse<List<BLEDeviceListRes>> getBLEDeviceList() {
return CommonResponse.success(bleService.getBLEDeviceList());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package devkor.com.teamcback.domain.ble.dto.response;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class BLEDeviceListRes {

private Long id;
private String deviceName;
private Long placeId;
private Integer capacity;

public BLEDeviceListRes(Long id, String deviceName, Long placeId, int capacity) {
this.id = id;
this.deviceName = deviceName;
this.placeId = placeId;
this.capacity = capacity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class BLETimePatternRes {
private Long placeId; // 요청 placeId
private int[] hours; // {7,10,13,16,19,21,24}
private int[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
private String[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
private int[][] averages; // [dayIndex][timeIndex] 형태, 각 원소는 반올림된 int

public BLETimePatternRes(Long placeId, int[] timeSlots, int[] dayOfWeeks, int[][] averages) {
public BLETimePatternRes(Long placeId, int[] timeSlots, String[] dayOfWeeks, int[][] averages) {
this.placeId = placeId;
this.hours = timeSlots;
this.dayOfWeeks = dayOfWeeks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
Expand All @@ -21,6 +22,7 @@

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import static devkor.com.teamcback.global.response.ResultCode.NOT_FOUND_PLACE;
Expand All @@ -37,6 +39,9 @@ public class BLEService {
private static final int[] TIME_SLOTS = {7, 10, 13, 16, 19, 22};
//요일 라벨 (1=월요일, 7=일요일)
private static final int[] DAY_OF_WEEKS = {1, 2, 3, 4, 5, 6, 7};
private static final String[] DAY_OF_WEEK_LABELS = {
"mon", "tue", "wed", "thu", "fri", "sat", "sun"
};

@Transactional
public UpdateBLERes updateBLE(UpdateBLEReq updateBLEReq) {
Expand Down Expand Up @@ -83,9 +88,10 @@ public GetBLERes getBLE(Long placeId) {
status = BLEstatus.FAILURE;
}
else status = latest.getLastStatus();
// 사람 수를 예측 후 10의 배수로 리턴

int people = getBlEPeople(latest.getLastCount(), device);
people = (int) Math.round(people / 10.0) * 10;
// 사람 수를 예측 후 10의 배수로 리턴: 이젠 필요 없음
//people = (int) Math.round(people / 10.0) * 10;
return new GetBLERes(device, latest, status, people);
}

Expand Down Expand Up @@ -157,9 +163,27 @@ public BLETimePatternRes getBLETimePattern(Long placeId) {
return new BLETimePatternRes(
placeId,
TIME_SLOTS,
DAY_OF_WEEKS,
DAY_OF_WEEK_LABELS,
averages
);
}

@Transactional(readOnly = true)
public List<BLEDeviceListRes> getBLEDeviceList() {
List<BLEDevice> devices = bledeviceRepository.findAll();
List<BLEDeviceListRes> result = new ArrayList<>();

for (BLEDevice device : devices) {
Long placeId = null;
if (device.getPlace() != null) {
placeId = device.getPlace().getId();
}

BLEDeviceListRes dto = new BLEDeviceListRes(device.getId(), device.getDeviceName(), placeId, device.getCapacity());

result.add(dto);
}
return result;
}

}