From 309d5278cb57760646c9f4bf42cd1dd7e911a83e Mon Sep 17 00:00:00 2001 From: gjs Date: Sat, 31 Oct 2026 10:31:43 +0800 Subject: [PATCH] add apis --- rpc/water/pb/water.pb.go | 511 ++++++++++++++++-- rpc/water/pb/water_grpc.pb.go | 332 +++++++++++- rpc/water/water.pb | Bin 14582 -> 15876 bytes rpc/water/water.proto | 100 ++++ services/water/internal/dao/users.go | 22 + services/water/internal/dao/warning.go | 31 ++ .../water/internal/logic/addWarningLogic.go | 54 ++ .../water/internal/logic/applyStatusLogic.go | 61 +++ .../water/internal/logic/applyUserLogic.go | 62 +++ .../water/internal/logic/changeAdminLogic.go | 32 ++ .../water/internal/logic/getWarningLogic.go | 57 ++ .../water/internal/logic/getWaterInfoLogic.go | 68 +++ services/water/internal/logic/usersLogic.go | 69 +++ .../internal/logic/warningStatusLogic.go | 60 ++ services/water/internal/server/waterServer.go | 48 ++ services/water/internal/svc/rpc.go | 25 + services/water/internal/svc/servicecontext.go | 84 ++- services/water/model/users.go | 23 + services/water/model/warning.go | 23 + services/water/validator/users.go | 53 ++ services/water/validator/warning.go | 34 ++ services/water/waterClient/water.go | 87 ++- 22 files changed, 1783 insertions(+), 53 deletions(-) create mode 100644 services/water/internal/dao/users.go create mode 100644 services/water/internal/dao/warning.go create mode 100644 services/water/internal/logic/addWarningLogic.go create mode 100644 services/water/internal/logic/applyStatusLogic.go create mode 100644 services/water/internal/logic/applyUserLogic.go create mode 100644 services/water/internal/logic/changeAdminLogic.go create mode 100644 services/water/internal/logic/getWarningLogic.go create mode 100644 services/water/internal/logic/getWaterInfoLogic.go create mode 100644 services/water/internal/logic/usersLogic.go create mode 100644 services/water/internal/logic/warningStatusLogic.go create mode 100644 services/water/internal/svc/rpc.go create mode 100644 services/water/model/users.go create mode 100644 services/water/model/warning.go create mode 100644 services/water/validator/users.go create mode 100644 services/water/validator/warning.go diff --git a/rpc/water/pb/water.pb.go b/rpc/water/pb/water.pb.go index ddfc15e..6639d5a 100644 --- a/rpc/water/pb/water.pb.go +++ b/rpc/water/pb/water.pb.go @@ -386,6 +386,394 @@ func (*EmptyRequest) Descriptor() ([]byte, []int) { return file_water_water_proto_rawDescGZIP(), []int{6} } +type AddWarningRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + Time string `protobuf:"bytes,2,opt,name=time,proto3" json:"time,omitempty"` + Type int32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"` + Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddWarningRequest) Reset() { + *x = AddWarningRequest{} + mi := &file_water_water_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddWarningRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddWarningRequest) ProtoMessage() {} + +func (x *AddWarningRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddWarningRequest.ProtoReflect.Descriptor instead. +func (*AddWarningRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{7} +} + +func (x *AddWarningRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *AddWarningRequest) GetTime() string { + if x != nil { + return x.Time + } + return "" +} + +func (x *AddWarningRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *AddWarningRequest) GetContent() string { + if x != nil { + return x.Content + } + return "" +} + +type GetWarningItemsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` + Size int32 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + HostCode string `protobuf:"bytes,3,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + Type int32 `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetWarningItemsRequest) Reset() { + *x = GetWarningItemsRequest{} + mi := &file_water_water_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetWarningItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetWarningItemsRequest) ProtoMessage() {} + +func (x *GetWarningItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetWarningItemsRequest.ProtoReflect.Descriptor instead. +func (*GetWarningItemsRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{8} +} + +func (x *GetWarningItemsRequest) GetPage() int32 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *GetWarningItemsRequest) GetSize() int32 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *GetWarningItemsRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *GetWarningItemsRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +type WarningStatusRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *WarningStatusRequest) Reset() { + *x = WarningStatusRequest{} + mi := &file_water_water_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *WarningStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WarningStatusRequest) ProtoMessage() {} + +func (x *WarningStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use WarningStatusRequest.ProtoReflect.Descriptor instead. +func (*WarningStatusRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{9} +} + +func (x *WarningStatusRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *WarningStatusRequest) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +type ChangeAdminRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ChangeAdminRequest) Reset() { + *x = ChangeAdminRequest{} + mi := &file_water_water_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ChangeAdminRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ChangeAdminRequest) ProtoMessage() {} + +func (x *ChangeAdminRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ChangeAdminRequest.ProtoReflect.Descriptor instead. +func (*ChangeAdminRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{10} +} + +func (x *ChangeAdminRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *ChangeAdminRequest) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +type UsersRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *UsersRequest) Reset() { + *x = UsersRequest{} + mi := &file_water_water_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *UsersRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UsersRequest) ProtoMessage() {} + +func (x *UsersRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UsersRequest.ProtoReflect.Descriptor instead. +func (*UsersRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{11} +} + +func (x *UsersRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +type ApplyUserRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApplyUserRequest) Reset() { + *x = ApplyUserRequest{} + mi := &file_water_water_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApplyUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApplyUserRequest) ProtoMessage() {} + +func (x *ApplyUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApplyUserRequest.ProtoReflect.Descriptor instead. +func (*ApplyUserRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{12} +} + +func (x *ApplyUserRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *ApplyUserRequest) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +type ApplyStatusRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ApplyStatusRequest) Reset() { + *x = ApplyStatusRequest{} + mi := &file_water_water_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ApplyStatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ApplyStatusRequest) ProtoMessage() {} + +func (x *ApplyStatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ApplyStatusRequest.ProtoReflect.Descriptor instead. +func (*ApplyStatusRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{13} +} + +func (x *ApplyStatusRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *ApplyStatusRequest) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + type SettingRequest struct { state protoimpl.MessageState `protogen:"open.v1"` HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` @@ -401,7 +789,7 @@ type SettingRequest struct { func (x *SettingRequest) Reset() { *x = SettingRequest{} - mi := &file_water_water_proto_msgTypes[7] + mi := &file_water_water_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -413,7 +801,7 @@ func (x *SettingRequest) String() string { func (*SettingRequest) ProtoMessage() {} func (x *SettingRequest) ProtoReflect() protoreflect.Message { - mi := &file_water_water_proto_msgTypes[7] + mi := &file_water_water_proto_msgTypes[14] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -426,7 +814,7 @@ func (x *SettingRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SettingRequest.ProtoReflect.Descriptor instead. func (*SettingRequest) Descriptor() ([]byte, []int) { - return file_water_water_proto_rawDescGZIP(), []int{7} + return file_water_water_proto_rawDescGZIP(), []int{14} } func (x *SettingRequest) GetHostCode() string { @@ -503,7 +891,31 @@ const file_water_water_proto_rawDesc = "" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + "\x04data\x18\x03 \x01(\tR\x04data\"\x0e\n" + - "\fEmptyRequest\"\xeb\x01\n" + + "\fEmptyRequest\"r\n" + + "\x11AddWarningRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12\x12\n" + + "\x04time\x18\x02 \x01(\tR\x04time\x12\x12\n" + + "\x04type\x18\x03 \x01(\x05R\x04type\x12\x18\n" + + "\acontent\x18\x04 \x01(\tR\acontent\"q\n" + + "\x16GetWarningItemsRequest\x12\x12\n" + + "\x04page\x18\x01 \x01(\x05R\x04page\x12\x12\n" + + "\x04size\x18\x02 \x01(\x05R\x04size\x12\x1b\n" + + "\thost_code\x18\x03 \x01(\tR\bhostCode\x12\x12\n" + + "\x04type\x18\x04 \x01(\x05R\x04type\">\n" + + "\x14WarningStatusRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06status\x18\x02 \x01(\x05R\x06status\"J\n" + + "\x12changeAdminRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12\x17\n" + + "\auser_id\x18\x02 \x01(\x03R\x06userId\"+\n" + + "\fUsersRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\"H\n" + + "\x10ApplyUserRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12\x17\n" + + "\auser_id\x18\x02 \x01(\x03R\x06userId\"<\n" + + "\x12ApplyStatusRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06status\x18\x02 \x01(\x05R\x06status\"\xeb\x01\n" + "\x0eSettingRequest\x12\x1b\n" + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12!\n" + "\fsalt_percent\x18\x02 \x01(\x05R\vsaltPercent\x12\x1a\n" + @@ -512,7 +924,7 @@ const file_water_water_proto_rawDesc = "" + "\n" + "use_number\x18\x05 \x01(\x05R\tuseNumber\x12\x16\n" + "\x06soften\x18\x06 \x01(\x05R\x06soften\x12#\n" + - "\rno_disturbing\x18\a \x01(\tR\fnoDisturbing2\x97\x04\n" + + "\rno_disturbing\x18\a \x01(\tR\fnoDisturbing2\xfd\t\n" + "\x05Water\x12Z\n" + "\tWifiCheck\x12\x17.water.WifiCheckRequest\x1a\x0f.water.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x12\x18/api/v3/water/wifi/check\x12T\n" + "\aWifiSet\x12\x15.water.WifiSetRequest\x1a\x0f.water.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/api/v3/water/wifi/set\x12Q\n" + @@ -520,7 +932,17 @@ const file_water_water_proto_rawDesc = "" + "\bLogItems\x12\x16.water.LogItemsRequest\x1a\x0f.water.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\x12\x17/api/v3/water/log/items\x12S\n" + "\aSetting\x12\x15.water.SettingRequest\x1a\x0f.water.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/api/v3/water/setting\x12[\n" + "\n" + - "GetSetting\x12\x16.water.HostCodeRequest\x1a\x0f.water.Response\"$\x82\xd3\xe4\x93\x02\x1e:\x01*\x12\x19/api/v3/water/get/settingB\tZ\a./waterb\x06proto3" + "GetSetting\x12\x16.water.HostCodeRequest\x1a\x0f.water.Response\"$\x82\xd3\xe4\x93\x02\x1e:\x01*\x12\x19/api/v3/water/get/setting\x12S\n" + + "\fGetWaterInfo\x12\x13.water.EmptyRequest\x1a\x0f.water.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\x12\x12/api/v3/water/info\x12^\n" + + "\n" + + "GetWarning\x12\x1d.water.GetWarningItemsRequest\x1a\x0f.water.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/api/v3/water/warning\x12]\n" + + "\n" + + "AddWarning\x12\x18.water.AddWarningRequest\x1a\x0f.water.Response\"$\x82\xd3\xe4\x93\x02\x1e:\x01*\"\x19/api/v3/water/warning/add\x12f\n" + + "\rWarningStatus\x12\x1b.water.WarningStatusRequest\x1a\x0f.water.Response\"'\x82\xd3\xe4\x93\x02!:\x01*\"\x1c/api/v3/water/warning/status\x12U\n" + + "\tApplyUser\x12\x17.water.ApplyUserRequest\x1a\x0f.water.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/api/v3/water/apply\x12`\n" + + "\vApplyStatus\x12\x19.water.ApplyStatusRequest\x1a\x0f.water.Response\"%\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/api/v3/water/apply/status\x12`\n" + + "\vchangeAdmin\x12\x19.water.changeAdminRequest\x1a\x0f.water.Response\"%\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/api/v3/water/change/admin\x12M\n" + + "\x05Users\x12\x13.water.UsersRequest\x1a\x0f.water.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/api/v3/water/usersB\tZ\a./waterb\x06proto3" var ( file_water_water_proto_rawDescOnce sync.Once @@ -534,35 +956,58 @@ func file_water_water_proto_rawDescGZIP() []byte { return file_water_water_proto_rawDescData } -var file_water_water_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_water_water_proto_msgTypes = make([]protoimpl.MessageInfo, 15) var file_water_water_proto_goTypes = []any{ - (*WifiCheckRequest)(nil), // 0: water.WifiCheckRequest - (*WifiSetRequest)(nil), // 1: water.WifiSetRequest - (*HostCodeRequest)(nil), // 2: water.HostCodeRequest - (*LogItemsRequest)(nil), // 3: water.LogItemsRequest - (*AddLogRequest)(nil), // 4: water.AddLogRequest - (*Response)(nil), // 5: water.Response - (*EmptyRequest)(nil), // 6: water.EmptyRequest - (*SettingRequest)(nil), // 7: water.SettingRequest + (*WifiCheckRequest)(nil), // 0: water.WifiCheckRequest + (*WifiSetRequest)(nil), // 1: water.WifiSetRequest + (*HostCodeRequest)(nil), // 2: water.HostCodeRequest + (*LogItemsRequest)(nil), // 3: water.LogItemsRequest + (*AddLogRequest)(nil), // 4: water.AddLogRequest + (*Response)(nil), // 5: water.Response + (*EmptyRequest)(nil), // 6: water.EmptyRequest + (*AddWarningRequest)(nil), // 7: water.AddWarningRequest + (*GetWarningItemsRequest)(nil), // 8: water.GetWarningItemsRequest + (*WarningStatusRequest)(nil), // 9: water.WarningStatusRequest + (*ChangeAdminRequest)(nil), // 10: water.changeAdminRequest + (*UsersRequest)(nil), // 11: water.UsersRequest + (*ApplyUserRequest)(nil), // 12: water.ApplyUserRequest + (*ApplyStatusRequest)(nil), // 13: water.ApplyStatusRequest + (*SettingRequest)(nil), // 14: water.SettingRequest } var file_water_water_proto_depIdxs = []int32{ - 0, // 0: water.Water.WifiCheck:input_type -> water.WifiCheckRequest - 1, // 1: water.Water.WifiSet:input_type -> water.WifiSetRequest - 4, // 2: water.Water.AddLog:input_type -> water.AddLogRequest - 3, // 3: water.Water.LogItems:input_type -> water.LogItemsRequest - 7, // 4: water.Water.Setting:input_type -> water.SettingRequest - 2, // 5: water.Water.GetSetting:input_type -> water.HostCodeRequest - 5, // 6: water.Water.WifiCheck:output_type -> water.Response - 5, // 7: water.Water.WifiSet:output_type -> water.Response - 5, // 8: water.Water.AddLog:output_type -> water.Response - 5, // 9: water.Water.LogItems:output_type -> water.Response - 5, // 10: water.Water.Setting:output_type -> water.Response - 5, // 11: water.Water.GetSetting:output_type -> water.Response - 6, // [6:12] is the sub-list for method output_type - 0, // [0:6] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 0, // 0: water.Water.WifiCheck:input_type -> water.WifiCheckRequest + 1, // 1: water.Water.WifiSet:input_type -> water.WifiSetRequest + 4, // 2: water.Water.AddLog:input_type -> water.AddLogRequest + 3, // 3: water.Water.LogItems:input_type -> water.LogItemsRequest + 14, // 4: water.Water.Setting:input_type -> water.SettingRequest + 2, // 5: water.Water.GetSetting:input_type -> water.HostCodeRequest + 6, // 6: water.Water.GetWaterInfo:input_type -> water.EmptyRequest + 8, // 7: water.Water.GetWarning:input_type -> water.GetWarningItemsRequest + 7, // 8: water.Water.AddWarning:input_type -> water.AddWarningRequest + 9, // 9: water.Water.WarningStatus:input_type -> water.WarningStatusRequest + 12, // 10: water.Water.ApplyUser:input_type -> water.ApplyUserRequest + 13, // 11: water.Water.ApplyStatus:input_type -> water.ApplyStatusRequest + 10, // 12: water.Water.changeAdmin:input_type -> water.changeAdminRequest + 11, // 13: water.Water.Users:input_type -> water.UsersRequest + 5, // 14: water.Water.WifiCheck:output_type -> water.Response + 5, // 15: water.Water.WifiSet:output_type -> water.Response + 5, // 16: water.Water.AddLog:output_type -> water.Response + 5, // 17: water.Water.LogItems:output_type -> water.Response + 5, // 18: water.Water.Setting:output_type -> water.Response + 5, // 19: water.Water.GetSetting:output_type -> water.Response + 5, // 20: water.Water.GetWaterInfo:output_type -> water.Response + 5, // 21: water.Water.GetWarning:output_type -> water.Response + 5, // 22: water.Water.AddWarning:output_type -> water.Response + 5, // 23: water.Water.WarningStatus:output_type -> water.Response + 5, // 24: water.Water.ApplyUser:output_type -> water.Response + 5, // 25: water.Water.ApplyStatus:output_type -> water.Response + 5, // 26: water.Water.changeAdmin:output_type -> water.Response + 5, // 27: water.Water.Users:output_type -> water.Response + 14, // [14:28] is the sub-list for method output_type + 0, // [0:14] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_water_water_proto_init() } @@ -576,7 +1021,7 @@ func file_water_water_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_water_water_proto_rawDesc), len(file_water_water_proto_rawDesc)), NumEnums: 0, - NumMessages: 8, + NumMessages: 15, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/water/pb/water_grpc.pb.go b/rpc/water/pb/water_grpc.pb.go index a04fcb4..db7df77 100644 --- a/rpc/water/pb/water_grpc.pb.go +++ b/rpc/water/pb/water_grpc.pb.go @@ -19,12 +19,20 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - Water_WifiCheck_FullMethodName = "/water.Water/WifiCheck" - Water_WifiSet_FullMethodName = "/water.Water/WifiSet" - Water_AddLog_FullMethodName = "/water.Water/AddLog" - Water_LogItems_FullMethodName = "/water.Water/LogItems" - Water_Setting_FullMethodName = "/water.Water/Setting" - Water_GetSetting_FullMethodName = "/water.Water/GetSetting" + Water_WifiCheck_FullMethodName = "/water.Water/WifiCheck" + Water_WifiSet_FullMethodName = "/water.Water/WifiSet" + Water_AddLog_FullMethodName = "/water.Water/AddLog" + Water_LogItems_FullMethodName = "/water.Water/LogItems" + Water_Setting_FullMethodName = "/water.Water/Setting" + Water_GetSetting_FullMethodName = "/water.Water/GetSetting" + Water_GetWaterInfo_FullMethodName = "/water.Water/GetWaterInfo" + Water_GetWarning_FullMethodName = "/water.Water/GetWarning" + Water_AddWarning_FullMethodName = "/water.Water/AddWarning" + Water_WarningStatus_FullMethodName = "/water.Water/WarningStatus" + Water_ApplyUser_FullMethodName = "/water.Water/ApplyUser" + Water_ApplyStatus_FullMethodName = "/water.Water/ApplyStatus" + Water_ChangeAdmin_FullMethodName = "/water.Water/changeAdmin" + Water_Users_FullMethodName = "/water.Water/Users" ) // WaterClient is the client API for Water service. @@ -37,6 +45,22 @@ type WaterClient interface { LogItems(ctx context.Context, in *LogItemsRequest, opts ...grpc.CallOption) (*Response, error) Setting(ctx context.Context, in *SettingRequest, opts ...grpc.CallOption) (*Response, error) GetSetting(ctx context.Context, in *HostCodeRequest, opts ...grpc.CallOption) (*Response, error) + // 获取月,日量 + GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 获取 流量计 液位计 侵水计 超声 四种设备异常警告 + GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 添加 流量计 液位计 侵水计 超声 四种设备异常警 + AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error) + // 状态 + WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error) + // 申请 + ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error) + // 同意 + ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error) + // 转移管理人 + ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error) + // 管理人列表 + Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error) } type waterClient struct { @@ -107,6 +131,86 @@ func (c *waterClient) GetSetting(ctx context.Context, in *HostCodeRequest, opts return out, nil } +func (c *waterClient) GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_GetWaterInfo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_GetWarning_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_AddWarning_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_WarningStatus_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_ApplyUser_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_ApplyStatus_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_ChangeAdmin_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_Users_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // WaterServer is the server API for Water service. // All implementations must embed UnimplementedWaterServer // for forward compatibility. @@ -117,6 +221,22 @@ type WaterServer interface { LogItems(context.Context, *LogItemsRequest) (*Response, error) Setting(context.Context, *SettingRequest) (*Response, error) GetSetting(context.Context, *HostCodeRequest) (*Response, error) + // 获取月,日量 + GetWaterInfo(context.Context, *EmptyRequest) (*Response, error) + // 获取 流量计 液位计 侵水计 超声 四种设备异常警告 + GetWarning(context.Context, *GetWarningItemsRequest) (*Response, error) + // 添加 流量计 液位计 侵水计 超声 四种设备异常警 + AddWarning(context.Context, *AddWarningRequest) (*Response, error) + // 状态 + WarningStatus(context.Context, *WarningStatusRequest) (*Response, error) + // 申请 + ApplyUser(context.Context, *ApplyUserRequest) (*Response, error) + // 同意 + ApplyStatus(context.Context, *ApplyStatusRequest) (*Response, error) + // 转移管理人 + ChangeAdmin(context.Context, *ChangeAdminRequest) (*Response, error) + // 管理人列表 + Users(context.Context, *UsersRequest) (*Response, error) mustEmbedUnimplementedWaterServer() } @@ -145,6 +265,30 @@ func (UnimplementedWaterServer) Setting(context.Context, *SettingRequest) (*Resp func (UnimplementedWaterServer) GetSetting(context.Context, *HostCodeRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method GetSetting not implemented") } +func (UnimplementedWaterServer) GetWaterInfo(context.Context, *EmptyRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method GetWaterInfo not implemented") +} +func (UnimplementedWaterServer) GetWarning(context.Context, *GetWarningItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method GetWarning not implemented") +} +func (UnimplementedWaterServer) AddWarning(context.Context, *AddWarningRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method AddWarning not implemented") +} +func (UnimplementedWaterServer) WarningStatus(context.Context, *WarningStatusRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method WarningStatus not implemented") +} +func (UnimplementedWaterServer) ApplyUser(context.Context, *ApplyUserRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApplyUser not implemented") +} +func (UnimplementedWaterServer) ApplyStatus(context.Context, *ApplyStatusRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApplyStatus not implemented") +} +func (UnimplementedWaterServer) ChangeAdmin(context.Context, *ChangeAdminRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ChangeAdmin not implemented") +} +func (UnimplementedWaterServer) Users(context.Context, *UsersRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Users not implemented") +} func (UnimplementedWaterServer) mustEmbedUnimplementedWaterServer() {} func (UnimplementedWaterServer) testEmbeddedByValue() {} @@ -274,6 +418,150 @@ func _Water_GetSetting_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Water_GetWaterInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).GetWaterInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_GetWaterInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).GetWaterInfo(ctx, req.(*EmptyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_GetWarning_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetWarningItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).GetWarning(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_GetWarning_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).GetWarning(ctx, req.(*GetWarningItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_AddWarning_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddWarningRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).AddWarning(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_AddWarning_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).AddWarning(ctx, req.(*AddWarningRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_WarningStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WarningStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).WarningStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_WarningStatus_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).WarningStatus(ctx, req.(*WarningStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_ApplyUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApplyUserRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).ApplyUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_ApplyUser_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).ApplyUser(ctx, req.(*ApplyUserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_ApplyStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApplyStatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).ApplyStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_ApplyStatus_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).ApplyStatus(ctx, req.(*ApplyStatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_ChangeAdmin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ChangeAdminRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).ChangeAdmin(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_ChangeAdmin_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).ChangeAdmin(ctx, req.(*ChangeAdminRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_Users_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UsersRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).Users(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_Users_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).Users(ctx, req.(*UsersRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Water_ServiceDesc is the grpc.ServiceDesc for Water service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -305,6 +593,38 @@ var Water_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetSetting", Handler: _Water_GetSetting_Handler, }, + { + MethodName: "GetWaterInfo", + Handler: _Water_GetWaterInfo_Handler, + }, + { + MethodName: "GetWarning", + Handler: _Water_GetWarning_Handler, + }, + { + MethodName: "AddWarning", + Handler: _Water_AddWarning_Handler, + }, + { + MethodName: "WarningStatus", + Handler: _Water_WarningStatus_Handler, + }, + { + MethodName: "ApplyUser", + Handler: _Water_ApplyUser_Handler, + }, + { + MethodName: "ApplyStatus", + Handler: _Water_ApplyStatus_Handler, + }, + { + MethodName: "changeAdmin", + Handler: _Water_ChangeAdmin_Handler, + }, + { + MethodName: "Users", + Handler: _Water_Users_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "water/water.proto", diff --git a/rpc/water/water.pb b/rpc/water/water.pb index 17ae92c3013345c2bd74ebd49d445d87f0ee6939..2c6bbfc344e08392d8766f9d7fda0be17ad5fae8 100644 GIT binary patch delta 940 zcmbV~&r2Io5XZ?zO?Mi_P9(eWXMHFwDY%EIE2R};k*MHhMLhXq$*##l-E6WiNJRb;wj3K6QPn5Am{U-KC@n`HD*; z0P8NVzMBHI-U#V&wc$hz)p{ffZ+MOfk|!ZCo2;CHB#rWZ%{@o21bHWQ;Iu#}SxQ811tPr(#lHRqRlCCU=-8(+>k9Ck1mK)WihT z?j}oY;jE2W$ utils.NumberZero { + return l.fail(utils.ErrorExist) + } + + info.UserId = in.UserId + info.HostCode = in.HostCode + + err = model.UsersModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) +} diff --git a/services/water/internal/logic/changeAdminLogic.go b/services/water/internal/logic/changeAdminLogic.go new file mode 100644 index 0000000..39572c7 --- /dev/null +++ b/services/water/internal/logic/changeAdminLogic.go @@ -0,0 +1,32 @@ +package logic + +import ( + "context" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ChangeAdminLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewChangeAdminLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ChangeAdminLogic { + return &ChangeAdminLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 转移管理人 +func (l *ChangeAdminLogic) ChangeAdmin(in *water.ChangeAdminRequest) (*water.Response, error) { + // todo: add your logic here and delete this line + + return &water.Response{}, nil +} diff --git a/services/water/internal/logic/getWarningLogic.go b/services/water/internal/logic/getWarningLogic.go new file mode 100644 index 0000000..acb7610 --- /dev/null +++ b/services/water/internal/logic/getWarningLogic.go @@ -0,0 +1,57 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/internal/dao" + "lone-services/services/water/model" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetWarningLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewGetWarningLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWarningLogic { + return &GetWarningLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 获取 流量计 液位计 侵水计 超声 四种设备异常警告 +func (l *GetWarningLogic) GetWarning(in *water.GetWarningItemsRequest) (*water.Response, error) { + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + w := modelbase.Params{ + Page: int(in.Page), + Size: int(in.Size)} + + w.Eq = make(map[string]string) + if len(in.HostCode) > utils.NumberZero { + w.Eq["host_code"] = in.HostCode + } + if in.Type > utils.NumberZero { + w.Eq["type"] = string(in.Type) + } + + var info []dao.WarningInfo + items, err := model.WarningModel{}.Init().Page(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + + return l.ok(items) +} diff --git a/services/water/internal/logic/getWaterInfoLogic.go b/services/water/internal/logic/getWaterInfoLogic.go new file mode 100644 index 0000000..15be3c2 --- /dev/null +++ b/services/water/internal/logic/getWaterInfoLogic.go @@ -0,0 +1,68 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/internal/dao" + "lone-services/services/water/model" + "time" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetWaterInfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewGetWaterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWaterInfoLogic { + return &GetWaterInfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 获取月,日量 +func (l *GetWaterInfoLogic) GetWaterInfo(in *water.EmptyRequest) (*water.Response, error) { + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + date := utils.Now().Format(time.DateOnly) + w := modelbase.Params{Eq: map[string]string{"date": date}} + var logDate dao.LogDate + err := model.LogDateModel{}.Init().GetOne(w, &logDate) + if err != nil { + return l.fail(utils.Fail) + } + type ret struct { + date int64 + month int64 + } + var retData ret + if logDate.Id > utils.NumberZero { + retData.date = logDate.Water + + } + + month := utils.Now().Format("2006-01") + w = modelbase.Params{Eq: map[string]string{"month": month}} + var monthDate dao.LogDate + err = model.LogDateModel{}.Init().GetOne(w, &monthDate) + if err != nil { + return l.fail(utils.Fail) + } + if logDate.Id > utils.NumberZero { + retData.date = monthDate.Water + + } + return l.ok(retData) +} diff --git a/services/water/internal/logic/usersLogic.go b/services/water/internal/logic/usersLogic.go new file mode 100644 index 0000000..f8d4d8a --- /dev/null +++ b/services/water/internal/logic/usersLogic.go @@ -0,0 +1,69 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/internal/dao" + "lone-services/services/water/model" + "lone-services/services/water/validator" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type UsersLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewUsersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsersLogic { + return &UsersLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 管理人列表 +func (l *UsersLogic) Users(in *water.UsersRequest) (*water.Response, error) { + var v validator.UserItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + w := modelbase.Params{Eq: map[string]string{"host_code": in.HostCode, "status": utils.StringStatusOk}} + + var info []dao.UsersInfo + err := model.UsersModel{}.Init().Items(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + + ids := []int64{} + for _, v := range info { + ids = append(ids, v.UserId) + } + + userItems := svc.GetUsers(ids, l.svcCtx.UserSvcName) + + idsName := make(map[int64]string) + for _, val := range userItems { + idsName[val.Id] = val.Name + } + for k, v := range info { + if kVal, ok := idsName[v.UserId]; ok { + info[k].UserName = kVal + } + } + + return l.ok(info) +} diff --git a/services/water/internal/logic/warningStatusLogic.go b/services/water/internal/logic/warningStatusLogic.go new file mode 100644 index 0000000..3bc7edc --- /dev/null +++ b/services/water/internal/logic/warningStatusLogic.go @@ -0,0 +1,60 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/internal/dao" + "lone-services/services/water/model" + "lone-services/services/water/validator" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type WarningStatusLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewWarningStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WarningStatusLogic { + return &WarningStatusLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 状态 +func (l *WarningStatusLogic) WarningStatus(in *water.WarningStatusRequest) (*water.Response, error) { + var v validator.WarningStatusValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + w := modelbase.Params{Eq: map[string]string{"id": string(in.Id)}} + + var info dao.WarningInfo + err := model.WarningModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + info.Status = in.Status + _, err = model.WarningModel{}.Init().Edit(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) +} diff --git a/services/water/internal/server/waterServer.go b/services/water/internal/server/waterServer.go index a3405a3..f53de56 100644 --- a/services/water/internal/server/waterServer.go +++ b/services/water/internal/server/waterServer.go @@ -52,3 +52,51 @@ func (s *WaterServer) GetSetting(ctx context.Context, in *water.HostCodeRequest) l := logic.NewGetSettingLogic(ctx, s.svcCtx) return l.GetSetting(in) } + +// 获取月,日量 +func (s *WaterServer) GetWaterInfo(ctx context.Context, in *water.EmptyRequest) (*water.Response, error) { + l := logic.NewGetWaterInfoLogic(ctx, s.svcCtx) + return l.GetWaterInfo(in) +} + +// 获取 流量计 液位计 侵水计 超声 四种设备异常警告 +func (s *WaterServer) GetWarning(ctx context.Context, in *water.GetWarningItemsRequest) (*water.Response, error) { + l := logic.NewGetWarningLogic(ctx, s.svcCtx) + return l.GetWarning(in) +} + +// 添加 流量计 液位计 侵水计 超声 四种设备异常警 +func (s *WaterServer) AddWarning(ctx context.Context, in *water.AddWarningRequest) (*water.Response, error) { + l := logic.NewAddWarningLogic(ctx, s.svcCtx) + return l.AddWarning(in) +} + +// 状态 +func (s *WaterServer) WarningStatus(ctx context.Context, in *water.WarningStatusRequest) (*water.Response, error) { + l := logic.NewWarningStatusLogic(ctx, s.svcCtx) + return l.WarningStatus(in) +} + +// 申请 +func (s *WaterServer) ApplyUser(ctx context.Context, in *water.ApplyUserRequest) (*water.Response, error) { + l := logic.NewApplyUserLogic(ctx, s.svcCtx) + return l.ApplyUser(in) +} + +// 同意 +func (s *WaterServer) ApplyStatus(ctx context.Context, in *water.ApplyStatusRequest) (*water.Response, error) { + l := logic.NewApplyStatusLogic(ctx, s.svcCtx) + return l.ApplyStatus(in) +} + +// 转移管理人 +func (s *WaterServer) ChangeAdmin(ctx context.Context, in *water.ChangeAdminRequest) (*water.Response, error) { + l := logic.NewChangeAdminLogic(ctx, s.svcCtx) + return l.ChangeAdmin(in) +} + +// 管理人列表 +func (s *WaterServer) Users(ctx context.Context, in *water.UsersRequest) (*water.Response, error) { + l := logic.NewUsersLogic(ctx, s.svcCtx) + return l.Users(in) +} diff --git a/services/water/internal/svc/rpc.go b/services/water/internal/svc/rpc.go new file mode 100644 index 0000000..3f14d2a --- /dev/null +++ b/services/water/internal/svc/rpc.go @@ -0,0 +1,25 @@ +package svc + +import ( + "context" + user "lone-services/rpc/user/pb" + + "github.com/zeromicro/go-zero/core/logx" +) + +func GetUsers(ids []int64, name string) []*user.UserBriefItem { + cli, err := GetRpcClient(name) + if err != nil { + logx.Error(err) + return nil + } + + client := user.NewUserClient(cli.Conn()) + items, err := client.InternalUsersByIds(context.Background(), &user.InternalUsersByIdsReq{Ids: ids}) + if err != nil { + logx.Errorf("get store err: %v", err) + return nil + } + + return items.Items +} diff --git a/services/water/internal/svc/servicecontext.go b/services/water/internal/svc/servicecontext.go index 963d6f0..1bba829 100644 --- a/services/water/internal/svc/servicecontext.go +++ b/services/water/internal/svc/servicecontext.go @@ -1,22 +1,94 @@ package svc import ( + "fmt" + "lone-services/pkg/discovery" "lone-services/pkg/utils" "lone-services/services/water/internal/config" + "net" + "strconv" + "sync" + "time" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/zrpc" "gorm.io/gorm" ) +type rpcClientCacheEntry struct { + cli zrpc.Client + target string + expireAt time.Time +} + +const rpcClientCacheTTL = 30 * time.Second //缓存过期时间 + +var ( + rpcCacheLock sync.Mutex + rpcCache = make(map[string]*rpcClientCacheEntry) +) + +func GetRpcClient(serviceName string) (zrpc.Client, error) { + if serviceName == utils.StringEmpty { + err := fmt.Errorf("rpc serviceName is empty") + logx.Error(err) + return nil, err + } + + cacheKey := serviceName + + rpcCacheLock.Lock() + entry, ok := rpcCache[cacheKey] + if ok && time.Now().Before(entry.expireAt) { + rpcCacheLock.Unlock() + return entry.cli, nil + } + delete(rpcCache, cacheKey) + rpcCacheLock.Unlock() + + inst, err := discovery.Pick(serviceName) + if err != nil { + err = fmt.Errorf("discovery pick %s failed: %w", serviceName, err) + logx.Error(err) + return nil, err + } + + target := net.JoinHostPort(inst.IP, strconv.FormatUint(inst.Port, utils.NumberTen)) + + cli := zrpc.MustNewClient(zrpc.RpcClientConf{ + Target: target, + Timeout: utils.RpcTimeOut, //rpc调用超时5s + }) + + rpcCacheLock.Lock() + rpcCache[cacheKey] = &rpcClientCacheEntry{ + cli: cli, + target: target, + expireAt: time.Now().Add(rpcClientCacheTTL), + } + rpcCacheLock.Unlock() + + return cli, nil +} + type ServiceContext struct { - Config config.Config - DB *gorm.DB - Prefix string + Config config.Config + DB *gorm.DB + Prefix string + UserSvcName string } func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { + //启动仅读取配置,不建立rpc连接 多个服务就多个 + userSvc := utils.GetConfigString("services.user") + if userSvc == utils.StringEmpty { + logx.Error("config services.user empty") + } + return &ServiceContext{ - Config: c, - DB: db, - Prefix: utils.GetConfigString("mysql.prefix"), + Config: c, + DB: db, + Prefix: utils.GetConfigString("mysql.prefix"), + UserSvcName: userSvc, } } diff --git a/services/water/model/users.go b/services/water/model/users.go new file mode 100644 index 0000000..63e5725 --- /dev/null +++ b/services/water/model/users.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/internal/dao" +) + +type UsersModel struct { + modelbase.Base +} + +func (m UsersModel) TableName() string { + return modelbase.Prefix() + "users" +} + +func (m UsersModel) Init() UsersModel { + m.Table = m.TableName() + return m +} + +func (m UsersModel) Create(data *dao.UsersCreate) error { + return m.Base.Create(data) +} diff --git a/services/water/model/warning.go b/services/water/model/warning.go new file mode 100644 index 0000000..e96e539 --- /dev/null +++ b/services/water/model/warning.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/internal/dao" +) + +type WarningModel struct { + modelbase.Base +} + +func (m WarningModel) TableName() string { + return modelbase.Prefix() + "warning" +} + +func (m WarningModel) Init() WarningModel { + m.Table = m.TableName() + return m +} + +func (m WarningModel) Create(data *dao.UsersCreate) error { + return m.Base.Create(data) +} diff --git a/services/water/validator/users.go b/services/water/validator/users.go new file mode 100644 index 0000000..3d07ffe --- /dev/null +++ b/services/water/validator/users.go @@ -0,0 +1,53 @@ +package validator + +import "lone-services/pkg/validate" + +type UserApplyValidator struct { + HostCode string `validate:"required"` + UserId int64 `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p UserApplyValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + "UserId.required": "用户不能为空", + } +} + +type UserStatusValidator struct { + Id int64 `validate:"required"` + Status int32 `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p UserStatusValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Status.required": "状态不能为空", + } +} + +type UserChangeValidator struct { + HostCode string `validate:"required"` + UserId int64 `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p UserChangeValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + "UserId.required": "用户不能为空", + } +} + +type UserItemsValidator struct { + HostCode string `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p UserItemsValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + } +} diff --git a/services/water/validator/warning.go b/services/water/validator/warning.go new file mode 100644 index 0000000..5447691 --- /dev/null +++ b/services/water/validator/warning.go @@ -0,0 +1,34 @@ +package validator + +import "lone-services/pkg/validate" + +// WarningAddValidator 查看列表 +type WarningAddValidator struct { + HostCode string `validate:"required"` + Time string `validate:"required"` + Type int64 `validate:"required"` + Content string `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p WarningAddValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + "Time.required": "时间不能为空", + "Type.required": "类型不能为空", + "Content.required": "内容不能为空", + } +} + +type WarningStatusValidator struct { + Id int64 `validate:"required"` + Status int32 `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p WarningStatusValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Status.required": "状态不能为空", + } +} diff --git a/services/water/waterClient/water.go b/services/water/waterClient/water.go index 1e21bf0..2010501 100644 --- a/services/water/waterClient/water.go +++ b/services/water/waterClient/water.go @@ -14,14 +14,21 @@ import ( ) type ( - AddLogRequest = water.AddLogRequest - EmptyRequest = water.EmptyRequest - HostCodeRequest = water.HostCodeRequest - LogItemsRequest = water.LogItemsRequest - Response = water.Response - SettingRequest = water.SettingRequest - WifiCheckRequest = water.WifiCheckRequest - WifiSetRequest = water.WifiSetRequest + AddLogRequest = water.AddLogRequest + AddWarningRequest = water.AddWarningRequest + ApplyStatusRequest = water.ApplyStatusRequest + ApplyUserRequest = water.ApplyUserRequest + ChangeAdminRequest = water.ChangeAdminRequest + EmptyRequest = water.EmptyRequest + GetWarningItemsRequest = water.GetWarningItemsRequest + HostCodeRequest = water.HostCodeRequest + LogItemsRequest = water.LogItemsRequest + Response = water.Response + SettingRequest = water.SettingRequest + UsersRequest = water.UsersRequest + WarningStatusRequest = water.WarningStatusRequest + WifiCheckRequest = water.WifiCheckRequest + WifiSetRequest = water.WifiSetRequest Water interface { WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) @@ -30,6 +37,22 @@ type ( LogItems(ctx context.Context, in *LogItemsRequest, opts ...grpc.CallOption) (*Response, error) Setting(ctx context.Context, in *SettingRequest, opts ...grpc.CallOption) (*Response, error) GetSetting(ctx context.Context, in *HostCodeRequest, opts ...grpc.CallOption) (*Response, error) + // 获取月,日量 + GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) + // 获取 流量计 液位计 侵水计 超声 四种设备异常警告 + GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error) + // 添加 流量计 液位计 侵水计 超声 四种设备异常警 + AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error) + // 状态 + WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error) + // 申请 + ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error) + // 同意 + ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error) + // 转移管理人 + ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error) + // 管理人列表 + Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error) } defaultWater struct { @@ -72,3 +95,51 @@ func (m *defaultWater) GetSetting(ctx context.Context, in *HostCodeRequest, opts client := water.NewWaterClient(m.cli.Conn()) return client.GetSetting(ctx, in, opts...) } + +// 获取月,日量 +func (m *defaultWater) GetWaterInfo(ctx context.Context, in *EmptyRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.GetWaterInfo(ctx, in, opts...) +} + +// 获取 流量计 液位计 侵水计 超声 四种设备异常警告 +func (m *defaultWater) GetWarning(ctx context.Context, in *GetWarningItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.GetWarning(ctx, in, opts...) +} + +// 添加 流量计 液位计 侵水计 超声 四种设备异常警 +func (m *defaultWater) AddWarning(ctx context.Context, in *AddWarningRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.AddWarning(ctx, in, opts...) +} + +// 状态 +func (m *defaultWater) WarningStatus(ctx context.Context, in *WarningStatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.WarningStatus(ctx, in, opts...) +} + +// 申请 +func (m *defaultWater) ApplyUser(ctx context.Context, in *ApplyUserRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.ApplyUser(ctx, in, opts...) +} + +// 同意 +func (m *defaultWater) ApplyStatus(ctx context.Context, in *ApplyStatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.ApplyStatus(ctx, in, opts...) +} + +// 转移管理人 +func (m *defaultWater) ChangeAdmin(ctx context.Context, in *ChangeAdminRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.ChangeAdmin(ctx, in, opts...) +} + +// 管理人列表 +func (m *defaultWater) Users(ctx context.Context, in *UsersRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.Users(ctx, in, opts...) +}