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 0000000..f0d4ae4 Binary files /dev/null and b/rpc/water/water.pb differ diff --git a/rpc/water/water.proto b/rpc/water/water.proto new file mode 100644 index 0000000..c27615c --- /dev/null +++ b/rpc/water/water.proto @@ -0,0 +1,90 @@ +syntax = "proto3"; + +package water; +option go_package="./water"; +import "google/api/annotations.proto"; + +message WifiCheckRequest { + string host_code = 1; +} + +message WifiSetRequest { + string host_code = 1; +} + +message HostCodeRequest { + string host_code = 1; +} + +message LogItemsRequest { + int32 page = 1; + int32 size = 2; + string time = 3; + string host_code = 4; +} + +message AddLogRequest { + string host_code = 1; + string data = 2; + string time = 3; +} + +message Response { + int32 code = 1; + string msg = 2; + string data = 3; +} + +message EmptyRequest { + +} + +message SettingRequest { + string host_code = 1; + int32 salt_percent =2; + int32 hardness = 3; + string refresh_time = 4; + int32 use_number = 5; + int32 soften = 6; +} + + +service Water { + rpc WifiCheck(WifiCheckRequest) returns (Response) { + option (google.api.http) = { + get: "/api/v3/water/wifi/check" + body: "*" + }; + } + rpc WifiSet(WifiSetRequest) returns (Response) { + option (google.api.http) = { + post: "/api/v3/water/wifi/set" + body: "*" + }; + } + + rpc AddLog(AddLogRequest) returns (Response) { + option (google.api.http) = { + get: "/api/v3/water/add/log" + body: "*" + }; + } + rpc LogItems(LogItemsRequest) returns (Response) { + option (google.api.http) = { + get: "/api/v3/water/log/items" + body: "*" + }; + } + rpc Setting(SettingRequest) returns (Response) { + option (google.api.http) = { + get: "/api/v3/water/setting" + body: "*" + }; + } + rpc GetSetting(HostCodeRequest) returns (Response) { + option (google.api.http) = { + get: "/api/v3/water/get/setting" + body: "*" + }; + } +} diff --git a/services/equipment/internal/logic/apiUnBindLogic.go b/services/equipment/internal/logic/apiUnBindLogic.go index c7305a2..16a58f3 100644 --- a/services/equipment/internal/logic/apiUnBindLogic.go +++ b/services/equipment/internal/logic/apiUnBindLogic.go @@ -45,6 +45,7 @@ func (l *ApiUnBindLogic) ApiUnBind(in *equipment.ApiUnBindRequest) (*equipment.R w := modelbase.Params{ Eq: map[string]string{ "host_code": in.HostCode, + "type": strconv.Itoa(int(in.Type)), "user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen), "status": utils.StringStatusOk}, } @@ -62,6 +63,7 @@ func (l *ApiUnBindLogic) ApiUnBind(in *equipment.ApiUnBindRequest) (*equipment.R host := dao.BindHistoryCreate{ HostCode: v.HostCode, UserId: adminInfo.ID, + Type: in.Type, Status: utils.StatusFail, } modelObj.Begin() diff --git a/services/water/.gitignore b/services/water/.gitignore new file mode 100644 index 0000000..fd3a2f0 --- /dev/null +++ b/services/water/.gitignore @@ -0,0 +1,3 @@ +run.toml +etc/water.yaml +tmp \ No newline at end of file diff --git a/services/water/Dockerfile b/services/water/Dockerfile new file mode 100644 index 0000000..e6156c8 --- /dev/null +++ b/services/water/Dockerfile @@ -0,0 +1,37 @@ +FROM golang:1.26.5-alpine AS builder + +WORKDIR /src + +ENV GOPROXY=https://goproxy.cn,direct \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +COPY pkg ./pkg +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +COPY rpc/ ./rpc +COPY services/water/ ./services/water/ + +WORKDIR /src/services/water + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -ldflags="-s -w" -o /out/main ./ + +FROM alpine:3.22 + +WORKDIR /app + +ENV TZ=Asia/Shanghai + +RUN apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /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...) +}