From 9c8ce51f4ff14e87757a7cc6941ca5ca458a6411 Mon Sep 17 00:00:00 2001 From: gjs Date: Fri, 16 Oct 2026 17:40:51 +0800 Subject: [PATCH] water --- .gitea/workflows/cd-test.yml | 1 + .gitea/workflows/ci.yml | 3 +- rpc/water/pb/water.pb.go | 572 ++++++++++++++++++ rpc/water/pb/water_grpc.pb.go | 311 ++++++++++ rpc/water/water.pb | Bin 0 -> 14523 bytes rpc/water/water.proto | 90 +++ .../internal/logic/apiUnBindLogic.go | 2 + services/water/.gitignore | 3 + services/water/Dockerfile | 37 ++ services/water/dao/log.go | 18 + services/water/dao/setting.go | 39 ++ services/water/internal/config/config.go | 13 + services/water/internal/logic/addLogLogic.go | 50 ++ services/water/internal/logic/base.go | 44 ++ .../water/internal/logic/getSettingLogic.go | 51 ++ .../water/internal/logic/logItemsLogic.go | 58 ++ services/water/internal/logic/settingLogic.go | 79 +++ .../water/internal/logic/wifiCheckLogic.go | 55 ++ services/water/internal/logic/wifiSetLogic.go | 67 ++ services/water/internal/server/waterServer.go | 54 ++ services/water/internal/svc/servicecontext.go | 22 + services/water/model/log.go | 23 + services/water/model/setting.go | 23 + services/water/validator/log.go | 19 + services/water/validator/setting.go | 15 + services/water/water.go | 170 ++++++ services/water/waterClient/water.go | 74 +++ 27 files changed, 1892 insertions(+), 1 deletion(-) create mode 100644 rpc/water/pb/water.pb.go create mode 100644 rpc/water/pb/water_grpc.pb.go create mode 100644 rpc/water/water.pb create mode 100644 rpc/water/water.proto create mode 100644 services/water/.gitignore create mode 100644 services/water/Dockerfile create mode 100644 services/water/dao/log.go create mode 100644 services/water/dao/setting.go create mode 100644 services/water/internal/config/config.go create mode 100644 services/water/internal/logic/addLogLogic.go create mode 100644 services/water/internal/logic/base.go create mode 100644 services/water/internal/logic/getSettingLogic.go create mode 100644 services/water/internal/logic/logItemsLogic.go create mode 100644 services/water/internal/logic/settingLogic.go create mode 100644 services/water/internal/logic/wifiCheckLogic.go create mode 100644 services/water/internal/logic/wifiSetLogic.go create mode 100644 services/water/internal/server/waterServer.go create mode 100644 services/water/internal/svc/servicecontext.go create mode 100644 services/water/model/log.go create mode 100644 services/water/model/setting.go create mode 100644 services/water/validator/log.go create mode 100644 services/water/validator/setting.go create mode 100644 services/water/water.go create mode 100644 services/water/waterClient/water.go diff --git a/.gitea/workflows/cd-test.yml b/.gitea/workflows/cd-test.yml index bdf6afa..a0b7696 100644 --- a/.gitea/workflows/cd-test.yml +++ b/.gitea/workflows/cd-test.yml @@ -50,4 +50,5 @@ jobs: docker pull ${{ vars.REGISTRY }}/lone/message:latest docker pull ${{ vars.REGISTRY }}/lone/support:latest docker pull ${{ vars.REGISTRY }}/lone/percutaneous:latest + docker pull ${{ vars.REGISTRY }}/lone/water:latest docker compose up -d diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index b4d881e..f034865 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: - name: Detect changes id: filter run: | - SERVICES="bff product admin user ad chore order express sale wecom task equipment record payment factory message support percutaneous" + SERVICES="bff product admin user ad chore order express sale wecom task equipment record payment factory message support percutaneous water" pattern_for() { case "$1" in @@ -99,6 +99,7 @@ jobs: - order - support - percutaneous + - water env: BUILD_LIST: ${{ needs.changes.outputs.build_list }} NAME: lone/${{ matrix.name }} diff --git a/rpc/water/pb/water.pb.go b/rpc/water/pb/water.pb.go new file mode 100644 index 0000000..08680db --- /dev/null +++ b/rpc/water/pb/water.pb.go @@ -0,0 +1,572 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v4.25.8 +// source: water/water.proto + +package water + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type WifiCheckRequest 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 *WifiCheckRequest) Reset() { + *x = WifiCheckRequest{} + mi := &file_water_water_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *WifiCheckRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WifiCheckRequest) ProtoMessage() {} + +func (x *WifiCheckRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[0] + 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 WifiCheckRequest.ProtoReflect.Descriptor instead. +func (*WifiCheckRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{0} +} + +func (x *WifiCheckRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +type WifiSetRequest 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 *WifiSetRequest) Reset() { + *x = WifiSetRequest{} + mi := &file_water_water_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *WifiSetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WifiSetRequest) ProtoMessage() {} + +func (x *WifiSetRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[1] + 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 WifiSetRequest.ProtoReflect.Descriptor instead. +func (*WifiSetRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{1} +} + +func (x *WifiSetRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +type HostCodeRequest 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 *HostCodeRequest) Reset() { + *x = HostCodeRequest{} + mi := &file_water_water_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *HostCodeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HostCodeRequest) ProtoMessage() {} + +func (x *HostCodeRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[2] + 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 HostCodeRequest.ProtoReflect.Descriptor instead. +func (*HostCodeRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{2} +} + +func (x *HostCodeRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +type LogItemsRequest 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"` + Time string `protobuf:"bytes,3,opt,name=time,proto3" json:"time,omitempty"` + HostCode string `protobuf:"bytes,4,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *LogItemsRequest) Reset() { + *x = LogItemsRequest{} + mi := &file_water_water_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *LogItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LogItemsRequest) ProtoMessage() {} + +func (x *LogItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[3] + 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 LogItemsRequest.ProtoReflect.Descriptor instead. +func (*LogItemsRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{3} +} + +func (x *LogItemsRequest) GetPage() int32 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *LogItemsRequest) GetSize() int32 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *LogItemsRequest) GetTime() string { + if x != nil { + return x.Time + } + return "" +} + +func (x *LogItemsRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +type AddLogRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HostCode string `protobuf:"bytes,1,opt,name=host_code,json=hostCode,proto3" json:"host_code,omitempty"` + Data string `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Time string `protobuf:"bytes,3,opt,name=time,proto3" json:"time,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AddLogRequest) Reset() { + *x = AddLogRequest{} + mi := &file_water_water_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AddLogRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddLogRequest) ProtoMessage() {} + +func (x *AddLogRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[4] + 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 AddLogRequest.ProtoReflect.Descriptor instead. +func (*AddLogRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{4} +} + +func (x *AddLogRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *AddLogRequest) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +func (x *AddLogRequest) GetTime() string { + if x != nil { + return x.Time + } + return "" +} + +type Response struct { + state protoimpl.MessageState `protogen:"open.v1"` + Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg,omitempty"` + Data string `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Response) Reset() { + *x = Response{} + mi := &file_water_water_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Response) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Response) ProtoMessage() {} + +func (x *Response) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[5] + 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 Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{5} +} + +func (x *Response) GetCode() int32 { + if x != nil { + return x.Code + } + return 0 +} + +func (x *Response) GetMsg() string { + if x != nil { + return x.Msg + } + return "" +} + +func (x *Response) GetData() string { + if x != nil { + return x.Data + } + return "" +} + +type EmptyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EmptyRequest) Reset() { + *x = EmptyRequest{} + mi := &file_water_water_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EmptyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EmptyRequest) ProtoMessage() {} + +func (x *EmptyRequest) ProtoReflect() protoreflect.Message { + mi := &file_water_water_proto_msgTypes[6] + 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 EmptyRequest.ProtoReflect.Descriptor instead. +func (*EmptyRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{6} +} + +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"` + SaltPercent int32 `protobuf:"varint,2,opt,name=salt_percent,json=saltPercent,proto3" json:"salt_percent,omitempty"` + Hardness int32 `protobuf:"varint,3,opt,name=hardness,proto3" json:"hardness,omitempty"` + RefreshTime string `protobuf:"bytes,4,opt,name=refresh_time,json=refreshTime,proto3" json:"refresh_time,omitempty"` + UseNumber int32 `protobuf:"varint,5,opt,name=use_number,json=useNumber,proto3" json:"use_number,omitempty"` + Soften int32 `protobuf:"varint,6,opt,name=soften,proto3" json:"soften,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SettingRequest) Reset() { + *x = SettingRequest{} + mi := &file_water_water_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SettingRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SettingRequest) ProtoMessage() {} + +func (x *SettingRequest) 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 SettingRequest.ProtoReflect.Descriptor instead. +func (*SettingRequest) Descriptor() ([]byte, []int) { + return file_water_water_proto_rawDescGZIP(), []int{7} +} + +func (x *SettingRequest) GetHostCode() string { + if x != nil { + return x.HostCode + } + return "" +} + +func (x *SettingRequest) GetSaltPercent() int32 { + if x != nil { + return x.SaltPercent + } + return 0 +} + +func (x *SettingRequest) GetHardness() int32 { + if x != nil { + return x.Hardness + } + return 0 +} + +func (x *SettingRequest) GetRefreshTime() string { + if x != nil { + return x.RefreshTime + } + return "" +} + +func (x *SettingRequest) GetUseNumber() int32 { + if x != nil { + return x.UseNumber + } + return 0 +} + +func (x *SettingRequest) GetSoften() int32 { + if x != nil { + return x.Soften + } + return 0 +} + +var File_water_water_proto protoreflect.FileDescriptor + +const file_water_water_proto_rawDesc = "" + + "\n" + + "\x11water/water.proto\x12\x05water\x1a\x1cgoogle/api/annotations.proto\"/\n" + + "\x10WifiCheckRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\"-\n" + + "\x0eWifiSetRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\".\n" + + "\x0fHostCodeRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\"j\n" + + "\x0fLogItemsRequest\x12\x12\n" + + "\x04page\x18\x01 \x01(\x05R\x04page\x12\x12\n" + + "\x04size\x18\x02 \x01(\x05R\x04size\x12\x12\n" + + "\x04time\x18\x03 \x01(\tR\x04time\x12\x1b\n" + + "\thost_code\x18\x04 \x01(\tR\bhostCode\"T\n" + + "\rAddLogRequest\x12\x1b\n" + + "\thost_code\x18\x01 \x01(\tR\bhostCode\x12\x12\n" + + "\x04data\x18\x02 \x01(\tR\x04data\x12\x12\n" + + "\x04time\x18\x03 \x01(\tR\x04time\"D\n" + + "\bResponse\x12\x12\n" + + "\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\"\xc6\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" + + "\bhardness\x18\x03 \x01(\x05R\bhardness\x12!\n" + + "\frefresh_time\x18\x04 \x01(\tR\vrefreshTime\x12\x1d\n" + + "\n" + + "use_number\x18\x05 \x01(\x05R\tuseNumber\x12\x16\n" + + "\x06soften\x18\x06 \x01(\x05R\x06soften2\x97\x04\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" + + "\x06AddLog\x12\x14.water.AddLogRequest\x1a\x0f.water.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/api/v3/water/add/log\x12W\n" + + "\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" + +var ( + file_water_water_proto_rawDescOnce sync.Once + file_water_water_proto_rawDescData []byte +) + +func file_water_water_proto_rawDescGZIP() []byte { + file_water_water_proto_rawDescOnce.Do(func() { + file_water_water_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_water_water_proto_rawDesc), len(file_water_water_proto_rawDesc))) + }) + return file_water_water_proto_rawDescData +} + +var file_water_water_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +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 +} +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 +} + +func init() { file_water_water_proto_init() } +func file_water_water_proto_init() { + if File_water_water_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + 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, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_water_water_proto_goTypes, + DependencyIndexes: file_water_water_proto_depIdxs, + MessageInfos: file_water_water_proto_msgTypes, + }.Build() + File_water_water_proto = out.File + file_water_water_proto_goTypes = nil + file_water_water_proto_depIdxs = nil +} diff --git a/rpc/water/pb/water_grpc.pb.go b/rpc/water/pb/water_grpc.pb.go new file mode 100644 index 0000000..a04fcb4 --- /dev/null +++ b/rpc/water/pb/water_grpc.pb.go @@ -0,0 +1,311 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.2 +// - protoc v4.25.8 +// source: water/water.proto + +package water + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +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" +) + +// WaterClient is the client API for Water service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type WaterClient interface { + WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) + WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error) + AddLog(ctx context.Context, in *AddLogRequest, opts ...grpc.CallOption) (*Response, error) + 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) +} + +type waterClient struct { + cc grpc.ClientConnInterface +} + +func NewWaterClient(cc grpc.ClientConnInterface) WaterClient { + return &waterClient{cc} +} + +func (c *waterClient) WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_WifiCheck_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_WifiSet_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) AddLog(ctx context.Context, in *AddLogRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_AddLog_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) LogItems(ctx context.Context, in *LogItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_LogItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) Setting(ctx context.Context, in *SettingRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_Setting_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *waterClient) GetSetting(ctx context.Context, in *HostCodeRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Water_GetSetting_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. +type WaterServer interface { + WifiCheck(context.Context, *WifiCheckRequest) (*Response, error) + WifiSet(context.Context, *WifiSetRequest) (*Response, error) + AddLog(context.Context, *AddLogRequest) (*Response, error) + LogItems(context.Context, *LogItemsRequest) (*Response, error) + Setting(context.Context, *SettingRequest) (*Response, error) + GetSetting(context.Context, *HostCodeRequest) (*Response, error) + mustEmbedUnimplementedWaterServer() +} + +// UnimplementedWaterServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedWaterServer struct{} + +func (UnimplementedWaterServer) WifiCheck(context.Context, *WifiCheckRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method WifiCheck not implemented") +} +func (UnimplementedWaterServer) WifiSet(context.Context, *WifiSetRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method WifiSet not implemented") +} +func (UnimplementedWaterServer) AddLog(context.Context, *AddLogRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method AddLog not implemented") +} +func (UnimplementedWaterServer) LogItems(context.Context, *LogItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method LogItems not implemented") +} +func (UnimplementedWaterServer) Setting(context.Context, *SettingRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Setting not implemented") +} +func (UnimplementedWaterServer) GetSetting(context.Context, *HostCodeRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method GetSetting not implemented") +} +func (UnimplementedWaterServer) mustEmbedUnimplementedWaterServer() {} +func (UnimplementedWaterServer) testEmbeddedByValue() {} + +// UnsafeWaterServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to WaterServer will +// result in compilation errors. +type UnsafeWaterServer interface { + mustEmbedUnimplementedWaterServer() +} + +func RegisterWaterServer(s grpc.ServiceRegistrar, srv WaterServer) { + // If the following call panics, it indicates UnimplementedWaterServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Water_ServiceDesc, srv) +} + +func _Water_WifiCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WifiCheckRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).WifiCheck(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_WifiCheck_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).WifiCheck(ctx, req.(*WifiCheckRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_WifiSet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(WifiSetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).WifiSet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_WifiSet_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).WifiSet(ctx, req.(*WifiSetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_AddLog_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AddLogRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).AddLog(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_AddLog_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).AddLog(ctx, req.(*AddLogRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_LogItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LogItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).LogItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_LogItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).LogItems(ctx, req.(*LogItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_Setting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SettingRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).Setting(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_Setting_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).Setting(ctx, req.(*SettingRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Water_GetSetting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HostCodeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WaterServer).GetSetting(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Water_GetSetting_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WaterServer).GetSetting(ctx, req.(*HostCodeRequest)) + } + 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) +var Water_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "water.Water", + HandlerType: (*WaterServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "WifiCheck", + Handler: _Water_WifiCheck_Handler, + }, + { + MethodName: "WifiSet", + Handler: _Water_WifiSet_Handler, + }, + { + MethodName: "AddLog", + Handler: _Water_AddLog_Handler, + }, + { + MethodName: "LogItems", + Handler: _Water_LogItems_Handler, + }, + { + MethodName: "Setting", + Handler: _Water_Setting_Handler, + }, + { + MethodName: "GetSetting", + Handler: _Water_GetSetting_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "water/water.proto", +} diff --git a/rpc/water/water.pb b/rpc/water/water.pb new file mode 100644 index 0000000000000000000000000000000000000000..f0d4ae4340f8c7ba24deff7f2aa3893071bf7e04 GIT binary patch literal 14523 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 /etc/timezone + +COPY --from=builder /out/main . + +CMD ["./main", "-f", "etc/water.yaml"] diff --git a/services/water/dao/log.go b/services/water/dao/log.go new file mode 100644 index 0000000..9784600 --- /dev/null +++ b/services/water/dao/log.go @@ -0,0 +1,18 @@ +package dao + +import "lone-services/pkg/utils" + +type LogCreate struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Data string `json:"data" gorm:"data"` // 数据 +} + +type LogInfo struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + HostCode string `json:"host_code" gorm:"host_code"` // 设备号 + Data string `json:"data" gorm:"data"` // 数据 + CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` +} diff --git a/services/water/dao/setting.go b/services/water/dao/setting.go new file mode 100644 index 0000000..6531866 --- /dev/null +++ b/services/water/dao/setting.go @@ -0,0 +1,39 @@ +package dao + +import "lone-services/pkg/utils" + +const ( + UserTypeStore = 1 + UserTypeUser = 2 + + WifiDone = 1 + WifiNotDone = 2 +) + +type SettingCreate struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 + HostCode string `json:"host_code" gorm:"host_code"` // 设备 + WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 + Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 + RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 + SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 + UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 + Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 +} + +type WifiInfo struct { + Id int64 `json:"id" gorm:"id"` + UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID + UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店 + HostCode string `json:"host_code" gorm:"host_code"` // 设备 + WifiDone int32 `json:"wifi_done" gorm:"wifi_done"` // 是否配置了wifi,2为没有配置,1为配置了 + Hardness int32 `json:"hardness" gorm:"hardness"` // 水的硬度 + RefreshTime string `json:"refresh_time" gorm:"refresh_time"` // 重生时间 + SaltPercent int32 `json:"salt_percent" gorm:"salt_percent"` // 盐量最大100 + UseNumber int32 `json:"use_number" gorm:"use_number"` // 剩余使用次数 + Soften int32 `json:"soften" gorm:"soften"` // 软化最大100 + UpdateTime utils.CustomTime `json:"update_time" gorm:"update_time"` + CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"` +} diff --git a/services/water/internal/config/config.go b/services/water/internal/config/config.go new file mode 100644 index 0000000..a1979dd --- /dev/null +++ b/services/water/internal/config/config.go @@ -0,0 +1,13 @@ +package config + +type Config struct { + Nacos NacosConf +} + +type NacosConf struct { + Hosts []string + NamespaceId string `json:",optional"` + Group string `json:",optional"` + RegisterIP string `json:",optional"` + ConfigID string `json:",optional"` +} diff --git a/services/water/internal/logic/addLogLogic.go b/services/water/internal/logic/addLogLogic.go new file mode 100644 index 0000000..c1e9869 --- /dev/null +++ b/services/water/internal/logic/addLogLogic.go @@ -0,0 +1,50 @@ +package logic + +import ( + "context" + "lone-services/pkg/utils" + "lone-services/services/water/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 AddLogLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewAddLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogLogic { + return &AddLogLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *AddLogLogic) AddLog(in *water.AddLogRequest) (*water.Response, error) { + var v validator.LogAddValidator + 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) + } + info := dao.LogCreate{ + Data: in.Data, + HostCode: in.HostCode, + UserId: adminInfo.ID, + } + err := model.LogModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) +} diff --git a/services/water/internal/logic/base.go b/services/water/internal/logic/base.go new file mode 100644 index 0000000..f0885e2 --- /dev/null +++ b/services/water/internal/logic/base.go @@ -0,0 +1,44 @@ +package logic + +import ( + "lone-services/pkg/utils" + "lone-services/pkg/validate" + water "lone-services/rpc/water/pb" + "reflect" + + jsoniter "github.com/json-iterator/go" +) + +type BaseLogic struct { +} + +func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *water.Response { + rv := reflect.ValueOf(in) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &water.Response{ + Code: utils.ErrorParams.Code, + Msg: "request must be non‑nil proto pointer", + } + } + + resp := validate.ValidateFromProto(in, v) + if resp != utils.StringEmpty { + return &water.Response{ + Code: utils.ErrorParams.Code, + Msg: resp, + } + } + return nil +} + +func (l *BaseLogic) fail(status utils.Status) (*water.Response, error) { + return l.out(status, status.Msg) +} +func (l *BaseLogic) out(status utils.Status, msg string) (*water.Response, error) { + return &water.Response{Code: status.Code, Msg: msg}, nil +} + +func (l *BaseLogic) ok(data any) (*water.Response, error) { + buf, _ := jsoniter.Marshal(data) + return &water.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil +} diff --git a/services/water/internal/logic/getSettingLogic.go b/services/water/internal/logic/getSettingLogic.go new file mode 100644 index 0000000..fd0078c --- /dev/null +++ b/services/water/internal/logic/getSettingLogic.go @@ -0,0 +1,51 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/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 GetSettingLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewGetSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSettingLogic { + return &GetSettingLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetSettingLogic) GetSetting(in *water.HostCodeRequest) (*water.Response, error) { + var v validator.HostCodeValidator + 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}} + var info dao.SettingCreate + err := model.SettingModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.ok(false) + } + return l.ok(info) +} diff --git a/services/water/internal/logic/logItemsLogic.go b/services/water/internal/logic/logItemsLogic.go new file mode 100644 index 0000000..d19b350 --- /dev/null +++ b/services/water/internal/logic/logItemsLogic.go @@ -0,0 +1,58 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/dao" + "lone-services/services/water/model" + "lone-services/services/water/validator" + "strings" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type LogItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewLogItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LogItemsLogic { + return &LogItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *LogItemsLogic) LogItems(in *water.LogItemsRequest) (*water.Response, error) { + var v validator.HostCodeValidator + 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{ + Page: int(in.Page), + Size: int(in.Size), + Eq: map[string]string{"host_code": in.HostCode}} + times := strings.Split(in.Time, utils.CentralHorizontalLine) + if len(times) == utils.NumberTwo { + w.Between = map[string][2]string{"create_time": {in.Time, in.Time}} + } + var info []dao.LogInfo + items, err := model.LogModel{}.Init().Page(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + + return l.ok(items) +} diff --git a/services/water/internal/logic/settingLogic.go b/services/water/internal/logic/settingLogic.go new file mode 100644 index 0000000..d3a5527 --- /dev/null +++ b/services/water/internal/logic/settingLogic.go @@ -0,0 +1,79 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/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 SettingLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SettingLogic { + return &SettingLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *SettingLogic) Setting(in *water.SettingRequest) (*water.Response, error) { + var v validator.HostCodeValidator + 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}} + var info dao.SettingCreate + err := model.SettingModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.ok(false) + } + change := false + if in.Hardness < utils.NumberZero && info.Hardness != in.Hardness { + change = true + info.Hardness = in.Hardness + } + if in.Soften < utils.NumberZero && info.Soften != in.Soften { + change = true + info.Soften = in.Soften + } + if in.UseNumber < utils.NumberZero && info.UseNumber != in.UseNumber { + change = true + info.UseNumber = in.UseNumber + } + if in.SaltPercent < utils.NumberZero && info.SaltPercent != in.SaltPercent { + change = true + info.SaltPercent = in.SaltPercent + } + if in.RefreshTime != "" && info.RefreshTime != in.RefreshTime { + change = true + info.RefreshTime = in.RefreshTime + } + if change { + _, err = model.SettingModel{}.Init().Edit(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(true) + } + return l.ok(false) +} diff --git a/services/water/internal/logic/wifiCheckLogic.go b/services/water/internal/logic/wifiCheckLogic.go new file mode 100644 index 0000000..2071dfb --- /dev/null +++ b/services/water/internal/logic/wifiCheckLogic.go @@ -0,0 +1,55 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/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 WifiCheckLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewWifiCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WifiCheckLogic { + return &WifiCheckLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *WifiCheckLogic) WifiCheck(in *water.WifiCheckRequest) (*water.Response, error) { + var v validator.HostCodeValidator + 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}} + var info dao.WifiInfo + err := model.SettingModel{}.Init().Items(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.ok(false) + } + if info.WifiDone == dao.WifiNotDone { + return l.ok(false) + } + return l.ok(true) +} diff --git a/services/water/internal/logic/wifiSetLogic.go b/services/water/internal/logic/wifiSetLogic.go new file mode 100644 index 0000000..7aaf4d9 --- /dev/null +++ b/services/water/internal/logic/wifiSetLogic.go @@ -0,0 +1,67 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/water/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 WifiSetLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewWifiSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WifiSetLogic { + return &WifiSetLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *WifiSetLogic) WifiSet(in *water.WifiSetRequest) (*water.Response, error) { + var v validator.HostCodeValidator + 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}} + var info dao.SettingCreate + err := model.SettingModel{}.Init().Items(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + info.UserId = adminInfo.ID + info.UserType = int32(adminInfo.Type) + info.HostCode = in.HostCode + info.WifiDone = dao.WifiDone + err = model.SettingModel{}.Init().Create(&info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) + } + if info.WifiDone == dao.WifiNotDone { + info.WifiDone = dao.WifiDone + _, err = model.SettingModel{}.Init().Edit(w, &info) + if err != nil { + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) + } + return l.ok(utils.NumberOne) +} diff --git a/services/water/internal/server/waterServer.go b/services/water/internal/server/waterServer.go new file mode 100644 index 0000000..a3405a3 --- /dev/null +++ b/services/water/internal/server/waterServer.go @@ -0,0 +1,54 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: water.proto + +package server + +import ( + "context" + + "lone-services/rpc/water/pb" + "lone-services/services/water/internal/logic" + "lone-services/services/water/internal/svc" +) + +type WaterServer struct { + svcCtx *svc.ServiceContext + water.UnimplementedWaterServer +} + +func NewWaterServer(svcCtx *svc.ServiceContext) *WaterServer { + return &WaterServer{ + svcCtx: svcCtx, + } +} + +func (s *WaterServer) WifiCheck(ctx context.Context, in *water.WifiCheckRequest) (*water.Response, error) { + l := logic.NewWifiCheckLogic(ctx, s.svcCtx) + return l.WifiCheck(in) +} + +func (s *WaterServer) WifiSet(ctx context.Context, in *water.WifiSetRequest) (*water.Response, error) { + l := logic.NewWifiSetLogic(ctx, s.svcCtx) + return l.WifiSet(in) +} + +func (s *WaterServer) AddLog(ctx context.Context, in *water.AddLogRequest) (*water.Response, error) { + l := logic.NewAddLogLogic(ctx, s.svcCtx) + return l.AddLog(in) +} + +func (s *WaterServer) LogItems(ctx context.Context, in *water.LogItemsRequest) (*water.Response, error) { + l := logic.NewLogItemsLogic(ctx, s.svcCtx) + return l.LogItems(in) +} + +func (s *WaterServer) Setting(ctx context.Context, in *water.SettingRequest) (*water.Response, error) { + l := logic.NewSettingLogic(ctx, s.svcCtx) + return l.Setting(in) +} + +func (s *WaterServer) GetSetting(ctx context.Context, in *water.HostCodeRequest) (*water.Response, error) { + l := logic.NewGetSettingLogic(ctx, s.svcCtx) + return l.GetSetting(in) +} diff --git a/services/water/internal/svc/servicecontext.go b/services/water/internal/svc/servicecontext.go new file mode 100644 index 0000000..963d6f0 --- /dev/null +++ b/services/water/internal/svc/servicecontext.go @@ -0,0 +1,22 @@ +package svc + +import ( + "lone-services/pkg/utils" + "lone-services/services/water/internal/config" + + "gorm.io/gorm" +) + +type ServiceContext struct { + Config config.Config + DB *gorm.DB + Prefix string +} + +func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { + return &ServiceContext{ + Config: c, + DB: db, + Prefix: utils.GetConfigString("mysql.prefix"), + } +} diff --git a/services/water/model/log.go b/services/water/model/log.go new file mode 100644 index 0000000..a4e71ea --- /dev/null +++ b/services/water/model/log.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/dao" +) + +type LogModel struct { + modelbase.Base +} + +func (m LogModel) TableName() string { + return modelbase.Prefix() + "log" +} + +func (m LogModel) Init() LogModel { + m.Table = m.TableName() + return m +} + +func (m LogModel) Create(data *dao.LogCreate) error { + return m.Base.Create(data) +} diff --git a/services/water/model/setting.go b/services/water/model/setting.go new file mode 100644 index 0000000..b92e26d --- /dev/null +++ b/services/water/model/setting.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/water/dao" +) + +type SettingModel struct { + modelbase.Base +} + +func (m SettingModel) TableName() string { + return modelbase.Prefix() + "setting" +} + +func (m SettingModel) Init() SettingModel { + m.Table = m.TableName() + return m +} + +func (m SettingModel) Create(data *dao.SettingCreate) error { + return m.Base.Create(data) +} diff --git a/services/water/validator/log.go b/services/water/validator/log.go new file mode 100644 index 0000000..af8a2ea --- /dev/null +++ b/services/water/validator/log.go @@ -0,0 +1,19 @@ +package validator + +import "lone-services/pkg/validate" + +// LogAddValidator 查看列表 +type LogAddValidator struct { + HostCode string `validate:"required"` + Data string `validate:"required"` + Time string `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p LogAddValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + "Time.required": "时间不能为空", + "Data.required": "数据不能为空", + } +} diff --git a/services/water/validator/setting.go b/services/water/validator/setting.go new file mode 100644 index 0000000..9834d18 --- /dev/null +++ b/services/water/validator/setting.go @@ -0,0 +1,15 @@ +package validator + +import "lone-services/pkg/validate" + +// HostCodeValidator 查看列表 +type HostCodeValidator struct { + HostCode string `validate:"required"` +} + +// GetMessage 查看列表 - 提示消息 +func (p HostCodeValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HostCode.required": "设备不能为空", + } +} diff --git a/services/water/water.go b/services/water/water.go new file mode 100644 index 0000000..e1a39e1 --- /dev/null +++ b/services/water/water.go @@ -0,0 +1,170 @@ +package main + +import ( + "flag" + "lone-services/pkg/discovery" + "lone-services/pkg/logRedis" + "lone-services/pkg/modelbase" + "lone-services/pkg/mysql" + "lone-services/pkg/redis" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + water "lone-services/rpc/water/pb" + "net" + "os" + "strconv" + + "lone-services/services/water/internal/config" + "lone-services/services/water/internal/server" + "lone-services/services/water/internal/svc" + + "github.com/zeromicro/go-zero/core/conf" + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/core/service" + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +var configFile = flag.String("f", "etc/water.yaml", "the config file") + +func main() { + flag.Parse() + var c config.Config + conf.MustLoad(*configFile, &c) + + // Nacos配置拉取初始化 + nacosParam := utils.NacosConfig{ + Hosts: c.Nacos.Hosts, + NamespaceId: c.Nacos.NamespaceId, + Group: c.Nacos.Group, + ConfigID: c.Nacos.ConfigID, + } + utils.InitConfig(nacosParam) + + // 日志配置 + logConf := logx.LogConf{ + ServiceName: utils.GetConfigString("log.serviceName"), + Mode: utils.GetConfigString("log.mode"), + Encoding: utils.GetConfigString("log.encoding"), + Level: utils.GetConfigString("log.level"), + Path: utils.GetConfigString("log.path"), + KeepDays: utils.GetConfigInt("log.keepDays"), + MaxSize: utils.GetConfigInt("log.maxSize"), + MaxBackups: utils.GetConfigInt("log.maxBackups"), + Compress: utils.GetConfigBool("log.compress"), + } + logx.SetUp(logConf) + logx.AddWriter(logx.NewWriter(os.Stdout)) + + listenOn := utils.GetConfigString("base.listenOn") + mode := utils.GetConfigString("base.mode") + serviceName := utils.GetConfigString("base.name") + + // 初始化服务发现 + if err := discovery.Init(discovery.Config{ + Hosts: c.Nacos.Hosts, + NamespaceId: c.Nacos.NamespaceId, + Group: c.Nacos.Group, + }); err != nil { + logx.Errorf("nacos init: %v", err) + os.Exit(1) + } + + port, err := listenPort(listenOn) + if err != nil { + logx.Errorf("parse ListenOn: %v", err) + os.Exit(1) + } + + // 注册服务 + if err := discovery.Register(discovery.Instance{ + ServiceName: serviceName, + IP: c.Nacos.RegisterIP, + Port: port, + Group: c.Nacos.Group, + }); err != nil { + logx.Errorf("nacos register: %v", err) + os.Exit(1) + } + logx.Infof("服务注册成功: %s:%d", c.Nacos.RegisterIP, port) + + defer func() { + if err := discovery.Deregister(); err != nil { + logx.Errorf("nacos deregister: %v", err) + } + }() + + // 初始化MySQL + db, err := mysql.New(mysql.Config{ + Host: utils.GetConfigString("mysql.host"), + Port: utils.GetConfigInt("mysql.port"), + User: utils.GetConfigString("mysql.user"), + Password: utils.GetConfigString("mysql.password"), + Database: utils.GetConfigString("mysql.database"), + Charset: utils.GetConfigString("mysql.charset"), + Prefix: utils.GetConfigString("mysql.prefix"), + ReadHost: utils.GetConfigString("mysql_read.host"), + ReadPort: utils.GetConfigInt("mysql_read.port"), + ReadUser: utils.GetConfigString("mysql_read.user"), + ReadPassword: utils.GetConfigString("mysql_read.password"), + ReadDatabase: utils.GetConfigString("mysql_read.database"), + }) + if err != nil { + logx.Errorf("mysql init: %v", err) + os.Exit(1) + } + + // 初始化Redis + if err := redis.Init(redis.Config{ + Host: utils.GetConfigString("redis.host"), + Port: utils.GetConfigInt("redis.port"), + Password: utils.GetConfigString("redis.password"), + DB: utils.GetConfigInt("redis.db"), + }); err != nil { + logx.Errorf("redis init: %v", err) + os.Exit(1) + } + + if err := logRedis.Init(logRedis.LogRedisConfig{ + Host: utils.GetConfigString("log-redis.host"), + Port: utils.GetConfigInt("log-redis.port"), + Password: utils.GetConfigString("log-redis.password"), + DB: utils.GetConfigInt("log-redis.db"), + }); err != nil { + logx.Errorf("log redis init: %v", err) + os.Exit(1) + } + + debug := utils.GetConfigBool("mysql.debug") + modelbase.Init(db, modelbase.Config{Prefix: utils.GetConfigString("mysql.prefix"), Debug: debug}) + + // 初始化服务信息 + rpcConf := zrpc.RpcServerConf{ + ListenOn: listenOn, + } + rpcConf.Mode = mode + ctx := svc.NewServiceContext(c, db) + + s := zrpc.MustNewServer(rpcConf, func(grpcServer *grpc.Server) { + water.RegisterWaterServer(grpcServer, server.NewWaterServer(ctx)) + if mode == service.DevMode || mode == service.TestMode { + reflection.Register(grpcServer) + } + }) + defer s.Stop() + + s.AddUnaryInterceptors(validate.UnaryServerInterceptor(validate.MustNew())) + + logx.Infof("Starting rpc server at %s...", listenOn) + s.Start() +} + +// listenPort 拆分端口 +func listenPort(listenOn string) (uint64, error) { + _, portStr, err := net.SplitHostPort(listenOn) + if err != nil { + return utils.NumberZero, err + } + return strconv.ParseUint(portStr, utils.NumberTen, utils.NumberSixtyFourth) +} diff --git a/services/water/waterClient/water.go b/services/water/waterClient/water.go new file mode 100644 index 0000000..1e21bf0 --- /dev/null +++ b/services/water/waterClient/water.go @@ -0,0 +1,74 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: water.proto + +package waterClient + +import ( + "context" + + "lone-services/rpc/water/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +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 + + Water interface { + WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) + WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error) + AddLog(ctx context.Context, in *AddLogRequest, opts ...grpc.CallOption) (*Response, error) + 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) + } + + defaultWater struct { + cli zrpc.Client + } +) + +func NewWater(cli zrpc.Client) Water { + return &defaultWater{ + cli: cli, + } +} + +func (m *defaultWater) WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.WifiCheck(ctx, in, opts...) +} + +func (m *defaultWater) WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.WifiSet(ctx, in, opts...) +} + +func (m *defaultWater) AddLog(ctx context.Context, in *AddLogRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.AddLog(ctx, in, opts...) +} + +func (m *defaultWater) LogItems(ctx context.Context, in *LogItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.LogItems(ctx, in, opts...) +} + +func (m *defaultWater) Setting(ctx context.Context, in *SettingRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.Setting(ctx, in, opts...) +} + +func (m *defaultWater) GetSetting(ctx context.Context, in *HostCodeRequest, opts ...grpc.CallOption) (*Response, error) { + client := water.NewWaterClient(m.cli.Conn()) + return client.GetSetting(ctx, in, opts...) +}