Skip to content

Commit 2c59770

Browse files
authored
Merge pull request #245 from DevKor-github/feat/ble2
11.26 수정사항 반영
2 parents 89bd976 + be260f3 commit 2c59770

4 files changed

Lines changed: 63 additions & 5 deletions

File tree

src/main/java/devkor/com/teamcback/domain/ble/controller/BLEController.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package devkor.com.teamcback.domain.ble.controller;
22

33
import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
4+
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
45
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
56
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
67
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
@@ -16,6 +17,8 @@
1617
import lombok.RequiredArgsConstructor;
1718
import org.springframework.web.bind.annotation.*;
1819

20+
import java.util.List;
21+
1922
@RestController
2023
@RequiredArgsConstructor
2124
@RequestMapping("/api/ble")
@@ -63,4 +66,14 @@ public CommonResponse<BLETimePatternRes> getBLETimePattern(
6366
return CommonResponse.success(bleService.getBLETimePattern(placeId));
6467
}
6568

69+
@GetMapping("/list")
70+
@Operation(summary = "BLE 가능 place 목록 조회",
71+
description = "ble_device 테이블에 등록된 BLE 장비 목록(id, deviceName, placeId, capacity)을 반환")
72+
@ApiResponses(value = {
73+
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다.")
74+
})
75+
public CommonResponse<List<BLEDeviceListRes>> getBLEDeviceList() {
76+
return CommonResponse.success(bleService.getBLEDeviceList());
77+
}
78+
6679
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package devkor.com.teamcback.domain.ble.dto.response;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class BLEDeviceListRes {
9+
10+
private Long id;
11+
private String deviceName;
12+
private Long placeId;
13+
private Integer capacity;
14+
15+
public BLEDeviceListRes(Long id, String deviceName, Long placeId, int capacity) {
16+
this.id = id;
17+
this.deviceName = deviceName;
18+
this.placeId = placeId;
19+
this.capacity = capacity;
20+
}
21+
}

src/main/java/devkor/com/teamcback/domain/ble/dto/response/BLETimePatternRes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
public class BLETimePatternRes {
77
private Long placeId; // 요청 placeId
88
private int[] hours; // {7,10,13,16,19,21,24}
9-
private int[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
9+
private String[] dayOfWeeks; // {1,2,3,4,5,6,7} (java.time.DayOfWeek 값)
1010
private int[][] averages; // [dayIndex][timeIndex] 형태, 각 원소는 반올림된 int
1111

12-
public BLETimePatternRes(Long placeId, int[] timeSlots, int[] dayOfWeeks, int[][] averages) {
12+
public BLETimePatternRes(Long placeId, int[] timeSlots, String[] dayOfWeeks, int[][] averages) {
1313
this.placeId = placeId;
1414
this.hours = timeSlots;
1515
this.dayOfWeeks = dayOfWeeks;

src/main/java/devkor/com/teamcback/domain/ble/service/BLEService.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import devkor.com.teamcback.domain.ble.dto.request.UpdateBLEReq;
5+
import devkor.com.teamcback.domain.ble.dto.response.BLEDeviceListRes;
56
import devkor.com.teamcback.domain.ble.dto.response.BLETimePatternRes;
67
import devkor.com.teamcback.domain.ble.dto.response.GetBLERes;
78
import devkor.com.teamcback.domain.ble.dto.response.UpdateBLERes;
@@ -21,6 +22,7 @@
2122

2223
import java.time.Duration;
2324
import java.time.LocalDateTime;
25+
import java.util.ArrayList;
2426
import java.util.List;
2527

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

4146
@Transactional
4247
public UpdateBLERes updateBLE(UpdateBLEReq updateBLEReq) {
@@ -83,9 +88,10 @@ public GetBLERes getBLE(Long placeId) {
8388
status = BLEstatus.FAILURE;
8489
}
8590
else status = latest.getLastStatus();
86-
// 사람 수를 예측 후 10의 배수로 리턴
91+
8792
int people = getBlEPeople(latest.getLastCount(), device);
88-
people = (int) Math.round(people / 10.0) * 10;
93+
// 사람 수를 예측 후 10의 배수로 리턴: 이젠 필요 없음
94+
//people = (int) Math.round(people / 10.0) * 10;
8995
return new GetBLERes(device, latest, status, people);
9096
}
9197

@@ -157,9 +163,27 @@ public BLETimePatternRes getBLETimePattern(Long placeId) {
157163
return new BLETimePatternRes(
158164
placeId,
159165
TIME_SLOTS,
160-
DAY_OF_WEEKS,
166+
DAY_OF_WEEK_LABELS,
161167
averages
162168
);
163169
}
164170

171+
@Transactional(readOnly = true)
172+
public List<BLEDeviceListRes> getBLEDeviceList() {
173+
List<BLEDevice> devices = bledeviceRepository.findAll();
174+
List<BLEDeviceListRes> result = new ArrayList<>();
175+
176+
for (BLEDevice device : devices) {
177+
Long placeId = null;
178+
if (device.getPlace() != null) {
179+
placeId = device.getPlace().getId();
180+
}
181+
182+
BLEDeviceListRes dto = new BLEDeviceListRes(device.getId(), device.getDeviceName(), placeId, device.getCapacity());
183+
184+
result.add(dto);
185+
}
186+
return result;
187+
}
188+
165189
}

0 commit comments

Comments
 (0)