refactor: rename proto RPCs and facade methods to follow conventions

Proto RPC renames:
- command_history.proto: Call→CallCommand, List→ListByPage
- event_history.proto: Report→ReportEvent, List→ListByPage
- point_value.proto: LastValue→GetLastValue, HistoryValue→ListHistoryValues

Facade interface renames:
- StatusHealthFacade: selectDeviceStatusesByIds→listDeviceStatusesByIds,
  selectDeviceStatusesByProfileId→listDeviceStatusesByProfileId,
  selectDriverStatusesByIds→listDriverStatusesByIds

Update all gRPC server implementations, client stubs, and test files.
This commit is contained in:
pnoker
2026-06-06 00:03:20 +08:00
parent 87f2263e74
commit a7b19611a3
13 changed files with 61 additions and 61 deletions
@@ -28,9 +28,9 @@ option objc_class_prefix = "Data";
option java_multiple_files = true;
service CommandHistoryApi {
rpc Call (GrpcCommandCallVO) returns (GrpcRString);
rpc CallCommand (GrpcCommandCallVO) returns (GrpcRString);
rpc GetByRecordId (GrpcStringQuery) returns (GrpcRCommandHistoryDTO);
rpc List (GrpcCommandHistoryQuery) returns (GrpcRPageCommandHistoryDTO);
rpc ListByPage (GrpcCommandHistoryQuery) returns (GrpcRPageCommandHistoryDTO);
}
message GrpcCommandCallVO {
@@ -29,9 +29,9 @@ option objc_class_prefix = "Data";
option java_multiple_files = true;
service EventHistoryApi {
rpc Report (GrpcEventReportVO) returns (GrpcRString);
rpc ReportEvent (GrpcEventReportVO) returns (GrpcRString);
rpc GetByRecordId (GrpcStringQuery) returns (GrpcREventHistoryDTO);
rpc List (GrpcEventHistoryQuery) returns (GrpcRPageEventHistoryDTO);
rpc ListByPage (GrpcEventHistoryQuery) returns (GrpcRPageEventHistoryDTO);
}
message GrpcEventReportVO {
@@ -30,10 +30,10 @@ option java_multiple_files = true;
// Service interface defining RPC calls related to point values
service PointValueApi {
// Query the latest collected value of a device point
rpc LastValue (GrpcPointValueQuery) returns (GrpcRPointValueDTO);
rpc GetLastValue (GrpcPointValueQuery) returns (GrpcRPointValueDTO);
// Query historical values of a device point
rpc HistoryValue (GrpcPointValueHistoryQuery) returns (GrpcRPointValueStringList);
rpc ListHistoryValues (GrpcPointValueHistoryQuery) returns (GrpcRPointValueStringList);
// Send a read command to a device for a specific point
rpc ReadCommand (GrpcPointValueCommandQuery) returns (GrpcRBoolean);
@@ -209,7 +209,7 @@ public class DeviceTool {
if (ids.isEmpty()) {
return AgenticToolResult.invalid("No valid device IDs provided.");
}
Map<Long, String> statuses = facade.selectDeviceStatusesByIds(tenantId, ids);
Map<Long, String> statuses = facade.listDeviceStatusesByIds(tenantId, ids);
if (AgenticToolUtil.isEmpty(statuses)) {
return AgenticToolResult.empty("No device statuses found.", Map.of());
}
@@ -228,7 +228,7 @@ public class DeviceTool {
if (Objects.isNull(facade)) {
return AgenticToolResult.unavailable(AgenticConstant.ToolMessage.STATUS_HEALTH_UNAVAILABLE);
}
Map<Long, String> statuses = facade.selectDeviceStatusesByProfileId(tenantId, profileId);
Map<Long, String> statuses = facade.listDeviceStatusesByProfileId(tenantId, profileId);
if (AgenticToolUtil.isEmpty(statuses)) {
return AgenticToolResult.empty("No device statuses found for profile ID: " + profileId, Map.of());
}
@@ -140,7 +140,7 @@ public class DriverTool {
if (ids.isEmpty()) {
return AgenticToolResult.invalid("No valid driver IDs provided.");
}
Map<Long, String> statuses = facade.selectDriverStatusesByIds(tenantId, ids);
Map<Long, String> statuses = facade.listDriverStatusesByIds(tenantId, ids);
if (AgenticToolUtil.isEmpty(statuses)) {
return AgenticToolResult.empty("No driver statuses found.", Map.of());
}
@@ -61,7 +61,7 @@ public class CommandHistoryServer extends CommandHistoryApiGrpc.CommandHistoryAp
private final CommandHistoryService commandHistoryService;
@Override
public void call(GrpcCommandCallVO request, StreamObserver<GrpcRString> responseObserver) {
public void callCommand(GrpcCommandCallVO request, StreamObserver<GrpcRString> responseObserver) {
try {
CommandCallVO vo = new CommandCallVO();
vo.setDeviceId(request.getDeviceId());
@@ -73,13 +73,13 @@ public class CommandHistoryServer extends CommandHistoryApiGrpc.CommandHistoryAp
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(recordId)
.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("CommandHistoryServer.call failed", e);
log.error("CommandHistoryServer.callCommand failed", e);
responseObserver.onNext(GrpcRString.newBuilder()
.setResult(GrpcR.newBuilder()
.setOk(false)
@@ -101,14 +101,14 @@ public class CommandHistoryServer extends CommandHistoryApiGrpc.CommandHistoryAp
response.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build());
response.setData(toGrpcDTO(recordDO));
} else {
response.setResult(GrpcR.newBuilder()
.setOk(false)
.setCode(ResponseEnum.NO_RESOURCE.getCode())
.setMessage(ResponseEnum.NO_RESOURCE.getText())
.setMessage(ResponseEnum.NO_RESOURCE.getRemark())
.build());
}
responseObserver.onNext(response.build());
@@ -127,7 +127,7 @@ public class CommandHistoryServer extends CommandHistoryApiGrpc.CommandHistoryAp
}
@Override
public void list(GrpcCommandHistoryQuery request, StreamObserver<GrpcRPageCommandHistoryDTO> responseObserver) {
public void listByPage(GrpcCommandHistoryQuery request, StreamObserver<GrpcRPageCommandHistoryDTO> responseObserver) {
try {
CommandHistoryQueryVO queryVO = new CommandHistoryQueryVO();
queryVO.setDeviceId(request.getDeviceId() != 0 ? request.getDeviceId() : null);
@@ -150,13 +150,13 @@ public class CommandHistoryServer extends CommandHistoryApiGrpc.CommandHistoryAp
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(pageDataBuilder.build())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("CommandHistoryServer.list failed", e);
log.error("CommandHistoryServer.listByPage failed", e);
responseObserver.onNext(GrpcRPageCommandHistoryDTO.newBuilder()
.setResult(GrpcR.newBuilder()
.setOk(false)
@@ -61,7 +61,7 @@ public class EventHistoryServer extends EventHistoryApiGrpc.EventHistoryApiImplB
private final EventHistoryService eventHistoryService;
@Override
public void report(GrpcEventReportVO request, StreamObserver<GrpcRString> responseObserver) {
public void reportEvent(GrpcEventReportVO request, StreamObserver<GrpcRString> responseObserver) {
try {
EventReportVO vo = new EventReportVO();
vo.setDeviceId(request.getDeviceId());
@@ -74,13 +74,13 @@ public class EventHistoryServer extends EventHistoryApiGrpc.EventHistoryApiImplB
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(recordId)
.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("EventHistoryServer.report failed", e);
log.error("EventHistoryServer.reportEvent failed", e);
responseObserver.onNext(GrpcRString.newBuilder()
.setResult(GrpcR.newBuilder()
.setOk(false)
@@ -102,14 +102,14 @@ public class EventHistoryServer extends EventHistoryApiGrpc.EventHistoryApiImplB
response.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build());
response.setData(toGrpcDTO(recordDO));
} else {
response.setResult(GrpcR.newBuilder()
.setOk(false)
.setCode(ResponseEnum.NO_RESOURCE.getCode())
.setMessage(ResponseEnum.NO_RESOURCE.getText())
.setMessage(ResponseEnum.NO_RESOURCE.getRemark())
.build());
}
responseObserver.onNext(response.build());
@@ -128,7 +128,7 @@ public class EventHistoryServer extends EventHistoryApiGrpc.EventHistoryApiImplB
}
@Override
public void list(GrpcEventHistoryQuery request, StreamObserver<GrpcRPageEventHistoryDTO> responseObserver) {
public void listByPage(GrpcEventHistoryQuery request, StreamObserver<GrpcRPageEventHistoryDTO> responseObserver) {
try {
EventHistoryQueryVO queryVO = new EventHistoryQueryVO();
queryVO.setDeviceId(request.getDeviceId() != 0 ? request.getDeviceId() : null);
@@ -153,13 +153,13 @@ public class EventHistoryServer extends EventHistoryApiGrpc.EventHistoryApiImplB
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(pageDataBuilder.build())
.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("EventHistoryServer.list failed", e);
log.error("EventHistoryServer.listByPage failed", e);
responseObserver.onNext(GrpcRPageEventHistoryDTO.newBuilder()
.setResult(GrpcR.newBuilder()
.setOk(false)
@@ -57,7 +57,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
private final PointCommandService pointCommandService;
@Override
public void lastValue(GrpcPointValueQuery request, StreamObserver<GrpcRPointValueDTO> responseObserver) {
public void getLastValue(GrpcPointValueQuery request, StreamObserver<GrpcRPointValueDTO> responseObserver) {
try {
// latest() with a page query — simplified: query by device+point, return
// first result
@@ -78,13 +78,13 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
response.setResult(GrpcR.newBuilder()
.setOk(false)
.setCode(ResponseEnum.NO_RESOURCE.getCode())
.setMessage(ResponseEnum.NO_RESOURCE.getText())
.setMessage(ResponseEnum.NO_RESOURCE.getRemark())
.build());
} else {
response.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build());
io.github.pnoker.common.entity.bo.PointValueBO bo = page.getRecords().getFirst();
@@ -102,7 +102,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
responseObserver.onNext(response.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("PointValueServer.lastValue failed, tenantId={}, deviceId={}, pointId={}", request.getTenantId(),
log.error("PointValueServer.getLastValue failed, tenantId={}, deviceId={}, pointId={}", request.getTenantId(),
request.getDeviceId(), request.getPointId(), e);
responseObserver.onNext(GrpcRPointValueDTO.newBuilder()
.setResult(GrpcR.newBuilder()
@@ -116,8 +116,8 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
}
@Override
public void historyValue(GrpcPointValueHistoryQuery request,
StreamObserver<GrpcRPointValueStringList> responseObserver) {
public void listHistoryValues(GrpcPointValueHistoryQuery request,
StreamObserver<GrpcRPointValueStringList> responseObserver) {
try {
List<String> history = pointValueService.history(request.getTenantId(), request.getDeviceId(),
request.getPointId(), request.getCount());
@@ -126,7 +126,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build());
if (Objects.nonNull(history)) {
@@ -135,7 +135,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
responseObserver.onNext(response.build());
responseObserver.onCompleted();
} catch (Exception e) {
log.error("PointValueServer.historyValue failed, tenantId={}, deviceId={}, pointId={}, count={}",
log.error("PointValueServer.listHistoryValues failed, tenantId={}, deviceId={}, pointId={}, count={}",
request.getTenantId(), request.getDeviceId(), request.getPointId(), request.getCount(), e);
responseObserver.onNext(GrpcRPointValueStringList.newBuilder()
.setResult(GrpcR.newBuilder()
@@ -160,7 +160,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(true)
.build());
@@ -193,7 +193,7 @@ public class PointValueServer extends PointValueApiGrpc.PointValueApiImplBase {
.setResult(GrpcR.newBuilder()
.setOk(true)
.setCode(ResponseEnum.OK.getCode())
.setMessage(ResponseEnum.OK.getText())
.setMessage(ResponseEnum.OK.getRemark())
.build())
.setData(true)
.build());
@@ -97,7 +97,7 @@ class PointValueServerTest {
.build()));
when(pointValueService.latest(any())).thenReturn(page);
GrpcRPointValueDTO response = stub.lastValue(GrpcPointValueQuery.newBuilder()
GrpcRPointValueDTO response = stub.getLastValue(GrpcPointValueQuery.newBuilder()
.setTenantId(1L)
.setDeviceId(10L)
.setPointId(20L)
@@ -113,7 +113,7 @@ class PointValueServerTest {
empty.setRecords(List.of());
when(pointValueService.latest(any())).thenReturn(empty);
GrpcRPointValueDTO response = stub.lastValue(GrpcPointValueQuery.newBuilder()
GrpcRPointValueDTO response = stub.getLastValue(GrpcPointValueQuery.newBuilder()
.setTenantId(1L).setDeviceId(10L).setPointId(20L).build());
assertThat(response.getResult().getOk()).isFalse();
assertThat(response.getResult().getCode()).isEqualTo(ResponseEnum.NO_RESOURCE.getCode());
@@ -123,7 +123,7 @@ class PointValueServerTest {
void lastValueReturnsFailureEnvelopeOnException() {
when(pointValueService.latest(any())).thenThrow(new NotFoundException("Device does not exist"));
GrpcRPointValueDTO response = stub.lastValue(GrpcPointValueQuery.newBuilder()
GrpcRPointValueDTO response = stub.getLastValue(GrpcPointValueQuery.newBuilder()
.setTenantId(1L).setDeviceId(99L).setPointId(20L).build());
assertThat(response.getResult().getOk()).isFalse();
assertThat(response.getResult().getCode()).isEqualTo(ResponseEnum.FAILURE.getCode());
@@ -135,7 +135,7 @@ class PointValueServerTest {
when(pointValueService.history(eq(1L), eq(10L), eq(20L), eq(50)))
.thenReturn(List.of("v1", "v2", "v3"));
GrpcRPointValueStringList response = stub.historyValue(GrpcPointValueHistoryQuery.newBuilder()
GrpcRPointValueStringList response = stub.listHistoryValues(GrpcPointValueHistoryQuery.newBuilder()
.setTenantId(1L).setDeviceId(10L).setPointId(20L).setCount(50)
.build());
assertThat(response.getResult().getOk()).isTrue();
@@ -147,7 +147,7 @@ class PointValueServerTest {
when(pointValueService.history(any(), any(), any(), eq(50)))
.thenThrow(new NotFoundException("Point does not exist"));
GrpcRPointValueStringList response = stub.historyValue(GrpcPointValueHistoryQuery.newBuilder()
GrpcRPointValueStringList response = stub.listHistoryValues(GrpcPointValueHistoryQuery.newBuilder()
.setTenantId(1L).setDeviceId(10L).setPointId(99L).setCount(50)
.build());
assertThat(response.getResult().getOk()).isFalse();
@@ -32,11 +32,11 @@ import java.util.Map;
*/
public interface StatusHealthFacade {
Map<Long, String> selectDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds);
Map<Long, String> listDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds);
Map<Long, String> selectDeviceStatusesByProfileId(Long tenantId, Long profileId);
Map<Long, String> listDeviceStatusesByProfileId(Long tenantId, Long profileId);
Map<Long, String> selectDriverStatusesByIds(Long tenantId, Collection<Long> driverIds);
Map<Long, String> listDriverStatusesByIds(Long tenantId, Collection<Long> driverIds);
FacadeDriverDeviceStatusSummaryBO getDriverDeviceStatusSummary(Long tenantId, Long driverId);
@@ -64,10 +64,10 @@ public class PointValueGrpcFacade implements PointValueFacade {
.setPointId(pointId)
.setTenantId(tenantId)
.build();
GrpcRPointValueDTO response = grpcFacadeSupport.call("PointValueFacade.lastValue", pointValueApiBlockingStub,
stub -> stub.lastValue(request));
GrpcRPointValueDTO response = grpcFacadeSupport.call("PointValueFacade.getLastValue", pointValueApiBlockingStub,
stub -> stub.getLastValue(request));
if (!response.getResult().getOk()) {
guardOrThrow(response.getResult(), "lastValue");
guardOrThrow(response.getResult(), "getLastValue");
return null;
}
if (!response.hasData()) {
@@ -84,10 +84,10 @@ public class PointValueGrpcFacade implements PointValueFacade {
.setTenantId(tenantId)
.setCount(count)
.build();
GrpcRPointValueStringList response = grpcFacadeSupport.call("PointValueFacade.history", pointValueApiBlockingStub,
stub -> stub.historyValue(request));
GrpcRPointValueStringList response = grpcFacadeSupport.call("PointValueFacade.listHistoryValues", pointValueApiBlockingStub,
stub -> stub.listHistoryValues(request));
if (!response.getResult().getOk()) {
guardOrThrow(response.getResult(), "history");
guardOrThrow(response.getResult(), "listHistoryValues");
return Collections.emptyList();
}
return response.getDataList();
@@ -58,30 +58,30 @@ public class StatusHealthGrpcFacade implements StatusHealthFacade {
private final GrpcFacadeSupport grpcFacadeSupport;
@Override
public Map<Long, String> selectDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds) {
public Map<Long, String> listDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds) {
GrpcIdsStatusQuery request = idsQuery(tenantId, deviceIds);
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.selectDeviceStatusesByIds",
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.listDeviceStatusesByIds",
statusHealthApiBlockingStub, stub -> stub.deviceStatusesByIds(request));
return statusMap(response.getResult(), response.getDataMap(), "selectDeviceStatusesByIds");
return statusMap(response.getResult(), response.getDataMap(), "listDeviceStatusesByIds");
}
@Override
public Map<Long, String> selectDeviceStatusesByProfileId(Long tenantId, Long profileId) {
public Map<Long, String> listDeviceStatusesByProfileId(Long tenantId, Long profileId) {
GrpcProfileStatusQuery request = GrpcProfileStatusQuery.newBuilder()
.setTenantId(Objects.requireNonNullElse(tenantId, 0L))
.setProfileId(Objects.requireNonNullElse(profileId, 0L))
.build();
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.selectDeviceStatusesByProfileId",
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.listDeviceStatusesByProfileId",
statusHealthApiBlockingStub, stub -> stub.deviceStatusesByProfileId(request));
return statusMap(response.getResult(), response.getDataMap(), "selectDeviceStatusesByProfileId");
return statusMap(response.getResult(), response.getDataMap(), "listDeviceStatusesByProfileId");
}
@Override
public Map<Long, String> selectDriverStatusesByIds(Long tenantId, Collection<Long> driverIds) {
public Map<Long, String> listDriverStatusesByIds(Long tenantId, Collection<Long> driverIds) {
GrpcIdsStatusQuery request = idsQuery(tenantId, driverIds);
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.selectDriverStatusesByIds",
GrpcRStatusMap response = grpcFacadeSupport.call("StatusHealthFacade.listDriverStatusesByIds",
statusHealthApiBlockingStub, stub -> stub.driverStatusesByIds(request));
return statusMap(response.getResult(), response.getDataMap(), "selectDriverStatusesByIds");
return statusMap(response.getResult(), response.getDataMap(), "listDriverStatusesByIds");
}
@Override
@@ -62,7 +62,7 @@ public class StatusHealthLocalFacade implements StatusHealthFacade {
private final SystemHealthService systemHealthService;
@Override
public Map<Long, String> selectDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds) {
public Map<Long, String> listDeviceStatusesByIds(Long tenantId, Collection<Long> deviceIds) {
List<FacadeDeviceBO> devices = deviceFacade.listByIds(tenantId, deviceIds);
Map<Long, String> result = new LinkedHashMap<>();
devices.forEach(device -> result.put(device.getId(), deviceStatus(tenantId, device.getId())));
@@ -70,7 +70,7 @@ public class StatusHealthLocalFacade implements StatusHealthFacade {
}
@Override
public Map<Long, String> selectDeviceStatusesByProfileId(Long tenantId, Long profileId) {
public Map<Long, String> listDeviceStatusesByProfileId(Long tenantId, Long profileId) {
List<FacadeDeviceBO> devices = deviceFacade.listByProfileId(tenantId, profileId);
Map<Long, String> result = new LinkedHashMap<>();
devices.forEach(device -> result.put(device.getId(), deviceStatus(tenantId, device.getId())));
@@ -78,7 +78,7 @@ public class StatusHealthLocalFacade implements StatusHealthFacade {
}
@Override
public Map<Long, String> selectDriverStatusesByIds(Long tenantId, Collection<Long> driverIds) {
public Map<Long, String> listDriverStatusesByIds(Long tenantId, Collection<Long> driverIds) {
List<FacadeDriverBO> drivers = driverFacade.listByIds(tenantId, driverIds);
Map<Long, String> result = new LinkedHashMap<>();
drivers.forEach(driver -> result.put(driver.getId(), driverStatus(tenantId, driver.getId())));