From eb96aaa2efb7ed4015f19a835b00dea6fb4150cd Mon Sep 17 00:00:00 2001 From: gjs Date: Tue, 1 Sep 2026 15:38:59 +0800 Subject: [PATCH] epuiment --- pkg/validate/defValidator.go | 37 ++ rpc/equipment/equipment.pb | Bin 0 -> 14633 bytes rpc/equipment/equipment.proto | 84 +++ rpc/equipment/pb/equipment.pb.go | 565 ++++++++++++++++++ rpc/equipment/pb/equipment_grpc.pb.go | 273 +++++++++ services/equipment/.gitignore | 3 + services/equipment/Dockerfile | 37 ++ services/equipment/equipment.go | 170 ++++++ .../equipment/equipmentclient/equipment.go | 66 ++ services/equipment/internal/config/config.go | 13 + services/equipment/internal/dao/version.go | 39 ++ services/equipment/internal/logic/base.go | 44 ++ .../equipment/internal/logic/createLogic.go | 67 +++ .../equipment/internal/logic/editLogic.go | 81 +++ .../equipment/internal/logic/infoLogic.go | 51 ++ .../equipment/internal/logic/itemsLogic.go | 52 ++ .../equipment/internal/logic/statusLogic.go | 72 +++ services/equipment/internal/model/version.go | 23 + .../internal/server/equipmentServer.go | 49 ++ .../equipment/internal/svc/servicecontext.go | 23 + services/equipment/validator/version.go | 53 ++ services/task/internal/logic/infoLogic.go | 4 +- services/task/internal/logic/statusLogic.go | 4 +- services/task/validator/task.go | 28 +- 24 files changed, 1807 insertions(+), 31 deletions(-) create mode 100644 pkg/validate/defValidator.go create mode 100644 rpc/equipment/equipment.pb create mode 100644 rpc/equipment/equipment.proto create mode 100644 rpc/equipment/pb/equipment.pb.go create mode 100644 rpc/equipment/pb/equipment_grpc.pb.go create mode 100644 services/equipment/.gitignore create mode 100644 services/equipment/Dockerfile create mode 100644 services/equipment/equipment.go create mode 100644 services/equipment/equipmentclient/equipment.go create mode 100644 services/equipment/internal/config/config.go create mode 100644 services/equipment/internal/dao/version.go create mode 100644 services/equipment/internal/logic/base.go create mode 100644 services/equipment/internal/logic/createLogic.go create mode 100644 services/equipment/internal/logic/editLogic.go create mode 100644 services/equipment/internal/logic/infoLogic.go create mode 100644 services/equipment/internal/logic/itemsLogic.go create mode 100644 services/equipment/internal/logic/statusLogic.go create mode 100644 services/equipment/internal/model/version.go create mode 100644 services/equipment/internal/server/equipmentServer.go create mode 100644 services/equipment/internal/svc/servicecontext.go create mode 100644 services/equipment/validator/version.go diff --git a/pkg/validate/defValidator.go b/pkg/validate/defValidator.go new file mode 100644 index 0000000..4fec396 --- /dev/null +++ b/pkg/validate/defValidator.go @@ -0,0 +1,37 @@ +package validate + +const ( + FieldId = "Id.required" + FieldIdValue = "ID不能为空" + FieldStatus = "Status.required" + FieldStatusValue = "状态不能为空" + FieldTypeIn = "Type.oneof" + FieldTypeInValue = "类型传值不对" + FieldType = "Type.required" + FieldTypeValue = "类型不能为空" +) + +type StatusValidator struct { + Id int64 `form:"id" json:"id" validate:"required"` + Status int32 `form:"status" json:"status" validate:"required"` + Reason string `form:"reason" json:"reason" validate:"required_if=Status 2"` +} + +func (p StatusValidator) GetMessage() ValidatorMessages { + return ValidatorMessages{ + FieldId: FieldIdValue, + FieldStatus: FieldStatusValue, + "Reason.required_if": "禁用状态,理由不能为空", + } +} + +type InfoValidator struct { + Id int64 `form:"id" json:"id" validate:"required"` +} + +// GetMessage 提示消息 +func (p InfoValidator) GetMessage() ValidatorMessages { + return ValidatorMessages{ + FieldId: FieldIdValue, + } +} diff --git a/rpc/equipment/equipment.pb b/rpc/equipment/equipment.pb new file mode 100644 index 0000000000000000000000000000000000000000..a379a416b33bb8ae9254307d9249f060f772d6fa GIT binary patch literal 14633 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 literal 0 HcmV?d00001 diff --git a/rpc/equipment/equipment.proto b/rpc/equipment/equipment.proto new file mode 100644 index 0000000..01ca422 --- /dev/null +++ b/rpc/equipment/equipment.proto @@ -0,0 +1,84 @@ +syntax = "proto3"; + +package equipment; +option go_package="./equipment"; + +import "google/api/annotations.proto"; + +message Response { + int32 code = 1; + string msg = 2; + string data = 3; +} + +message CreateRequest { + string hardware_version =1; + string version =2; + string firmware_src =3; + string describe =4; + int32 type =5; + string soft_src =6; + string add_src =7; + string soft_config =8; +} + +message EditRequest { + int64 id = 1; + string hardware_version =2; + string version =3; + string firmware_src =4; + string describe =5; + int32 type =6; + string soft_src =7; + string add_src =8; + string soft_config =9; +} + +message ItemsRequest { + int32 page = 1; + int32 size =2; + int32 type =3; +} + +message IdRequest { + int64 id = 1; +} + +message StatusRequest { + int64 id = 1; + int32 status = 2; + string reason = 3; +} + +service Equipment { + rpc Items(ItemsRequest) returns(Response){ + option (google.api.http) = { + get: "/admin/v3/equipment/items" + body: "*" + }; + }; + rpc Info(IdRequest) returns(Response){ + option (google.api.http) = { + get: "/admin/v3/equipment/info" + body: "*" + }; + }; + rpc Create(CreateRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/equipment/create" + body: "*" + }; + }; + rpc Edit(EditRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/equipment/edit" + body: "*" + }; + }; + rpc Status(StatusRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/equipment/status" + body: "*" + }; + }; +} \ No newline at end of file diff --git a/rpc/equipment/pb/equipment.pb.go b/rpc/equipment/pb/equipment.pb.go new file mode 100644 index 0000000..0f49211 --- /dev/null +++ b/rpc/equipment/pb/equipment.pb.go @@ -0,0 +1,565 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v4.25.8 +// source: equipment/equipment.proto + +package equipment + +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 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_equipment_equipment_proto_msgTypes[0] + 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_equipment_equipment_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 Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{0} +} + +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 CreateRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + HardwareVersion string `protobuf:"bytes,1,opt,name=hardware_version,json=hardwareVersion,proto3" json:"hardware_version,omitempty"` + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + FirmwareSrc string `protobuf:"bytes,3,opt,name=firmware_src,json=firmwareSrc,proto3" json:"firmware_src,omitempty"` + Describe string `protobuf:"bytes,4,opt,name=describe,proto3" json:"describe,omitempty"` + Type int32 `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"` + SoftSrc string `protobuf:"bytes,6,opt,name=soft_src,json=softSrc,proto3" json:"soft_src,omitempty"` + AddSrc string `protobuf:"bytes,7,opt,name=add_src,json=addSrc,proto3" json:"add_src,omitempty"` + SoftConfig string `protobuf:"bytes,8,opt,name=soft_config,json=softConfig,proto3" json:"soft_config,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateRequest) Reset() { + *x = CreateRequest{} + mi := &file_equipment_equipment_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateRequest) ProtoMessage() {} + +func (x *CreateRequest) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_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 CreateRequest.ProtoReflect.Descriptor instead. +func (*CreateRequest) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateRequest) GetHardwareVersion() string { + if x != nil { + return x.HardwareVersion + } + return "" +} + +func (x *CreateRequest) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *CreateRequest) GetFirmwareSrc() string { + if x != nil { + return x.FirmwareSrc + } + return "" +} + +func (x *CreateRequest) GetDescribe() string { + if x != nil { + return x.Describe + } + return "" +} + +func (x *CreateRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *CreateRequest) GetSoftSrc() string { + if x != nil { + return x.SoftSrc + } + return "" +} + +func (x *CreateRequest) GetAddSrc() string { + if x != nil { + return x.AddSrc + } + return "" +} + +func (x *CreateRequest) GetSoftConfig() string { + if x != nil { + return x.SoftConfig + } + return "" +} + +type EditRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + HardwareVersion string `protobuf:"bytes,2,opt,name=hardware_version,json=hardwareVersion,proto3" json:"hardware_version,omitempty"` + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + FirmwareSrc string `protobuf:"bytes,4,opt,name=firmware_src,json=firmwareSrc,proto3" json:"firmware_src,omitempty"` + Describe string `protobuf:"bytes,5,opt,name=describe,proto3" json:"describe,omitempty"` + Type int32 `protobuf:"varint,6,opt,name=type,proto3" json:"type,omitempty"` + SoftSrc string `protobuf:"bytes,7,opt,name=soft_src,json=softSrc,proto3" json:"soft_src,omitempty"` + AddSrc string `protobuf:"bytes,8,opt,name=add_src,json=addSrc,proto3" json:"add_src,omitempty"` + SoftConfig string `protobuf:"bytes,9,opt,name=soft_config,json=softConfig,proto3" json:"soft_config,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EditRequest) Reset() { + *x = EditRequest{} + mi := &file_equipment_equipment_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EditRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EditRequest) ProtoMessage() {} + +func (x *EditRequest) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_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 EditRequest.ProtoReflect.Descriptor instead. +func (*EditRequest) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{2} +} + +func (x *EditRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *EditRequest) GetHardwareVersion() string { + if x != nil { + return x.HardwareVersion + } + return "" +} + +func (x *EditRequest) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *EditRequest) GetFirmwareSrc() string { + if x != nil { + return x.FirmwareSrc + } + return "" +} + +func (x *EditRequest) GetDescribe() string { + if x != nil { + return x.Describe + } + return "" +} + +func (x *EditRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *EditRequest) GetSoftSrc() string { + if x != nil { + return x.SoftSrc + } + return "" +} + +func (x *EditRequest) GetAddSrc() string { + if x != nil { + return x.AddSrc + } + return "" +} + +func (x *EditRequest) GetSoftConfig() string { + if x != nil { + return x.SoftConfig + } + return "" +} + +type ItemsRequest 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"` + Type int32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ItemsRequest) Reset() { + *x = ItemsRequest{} + mi := &file_equipment_equipment_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemsRequest) ProtoMessage() {} + +func (x *ItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_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 ItemsRequest.ProtoReflect.Descriptor instead. +func (*ItemsRequest) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{3} +} + +func (x *ItemsRequest) GetPage() int32 { + if x != nil { + return x.Page + } + return 0 +} + +func (x *ItemsRequest) GetSize() int32 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *ItemsRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +type IdRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *IdRequest) Reset() { + *x = IdRequest{} + mi := &file_equipment_equipment_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *IdRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IdRequest) ProtoMessage() {} + +func (x *IdRequest) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_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 IdRequest.ProtoReflect.Descriptor instead. +func (*IdRequest) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{4} +} + +func (x *IdRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type StatusRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` + Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *StatusRequest) Reset() { + *x = StatusRequest{} + mi := &file_equipment_equipment_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *StatusRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StatusRequest) ProtoMessage() {} + +func (x *StatusRequest) ProtoReflect() protoreflect.Message { + mi := &file_equipment_equipment_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 StatusRequest.ProtoReflect.Descriptor instead. +func (*StatusRequest) Descriptor() ([]byte, []int) { + return file_equipment_equipment_proto_rawDescGZIP(), []int{5} +} + +func (x *StatusRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *StatusRequest) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *StatusRequest) GetReason() string { + if x != nil { + return x.Reason + } + return "" +} + +var File_equipment_equipment_proto protoreflect.FileDescriptor + +const file_equipment_equipment_proto_rawDesc = "" + + "\n" + + "\x19equipment/equipment.proto\x12\tequipment\x1a\x1cgoogle/api/annotations.proto\"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\"\xfc\x01\n" + + "\rCreateRequest\x12)\n" + + "\x10hardware_version\x18\x01 \x01(\tR\x0fhardwareVersion\x12\x18\n" + + "\aversion\x18\x02 \x01(\tR\aversion\x12!\n" + + "\ffirmware_src\x18\x03 \x01(\tR\vfirmwareSrc\x12\x1a\n" + + "\bdescribe\x18\x04 \x01(\tR\bdescribe\x12\x12\n" + + "\x04type\x18\x05 \x01(\x05R\x04type\x12\x19\n" + + "\bsoft_src\x18\x06 \x01(\tR\asoftSrc\x12\x17\n" + + "\aadd_src\x18\a \x01(\tR\x06addSrc\x12\x1f\n" + + "\vsoft_config\x18\b \x01(\tR\n" + + "softConfig\"\x8a\x02\n" + + "\vEditRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12)\n" + + "\x10hardware_version\x18\x02 \x01(\tR\x0fhardwareVersion\x12\x18\n" + + "\aversion\x18\x03 \x01(\tR\aversion\x12!\n" + + "\ffirmware_src\x18\x04 \x01(\tR\vfirmwareSrc\x12\x1a\n" + + "\bdescribe\x18\x05 \x01(\tR\bdescribe\x12\x12\n" + + "\x04type\x18\x06 \x01(\x05R\x04type\x12\x19\n" + + "\bsoft_src\x18\a \x01(\tR\asoftSrc\x12\x17\n" + + "\aadd_src\x18\b \x01(\tR\x06addSrc\x12\x1f\n" + + "\vsoft_config\x18\t \x01(\tR\n" + + "softConfig\"J\n" + + "\fItemsRequest\x12\x12\n" + + "\x04page\x18\x01 \x01(\x05R\x04page\x12\x12\n" + + "\x04size\x18\x02 \x01(\x05R\x04size\x12\x12\n" + + "\x04type\x18\x03 \x01(\x05R\x04type\"\x1b\n" + + "\tIdRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"O\n" + + "\rStatusRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06status\x18\x02 \x01(\x05R\x06status\x12\x16\n" + + "\x06reason\x18\x03 \x01(\tR\x06reason2\xda\x03\n" + + "\tEquipment\x12[\n" + + "\x05Items\x12\x17.equipment.ItemsRequest\x1a\x13.equipment.Response\"$\x82\xd3\xe4\x93\x02\x1e:\x01*\x12\x19/admin/v3/equipment/items\x12V\n" + + "\x04Info\x12\x14.equipment.IdRequest\x1a\x13.equipment.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x12\x18/admin/v3/equipment/info\x12^\n" + + "\x06Create\x12\x18.equipment.CreateRequest\x1a\x13.equipment.Response\"%\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/admin/v3/equipment/create\x12X\n" + + "\x04Edit\x12\x16.equipment.EditRequest\x1a\x13.equipment.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/equipment/edit\x12^\n" + + "\x06Status\x12\x18.equipment.StatusRequest\x1a\x13.equipment.Response\"%\x82\xd3\xe4\x93\x02\x1f:\x01*\"\x1a/admin/v3/equipment/statusB\rZ\v./equipmentb\x06proto3" + +var ( + file_equipment_equipment_proto_rawDescOnce sync.Once + file_equipment_equipment_proto_rawDescData []byte +) + +func file_equipment_equipment_proto_rawDescGZIP() []byte { + file_equipment_equipment_proto_rawDescOnce.Do(func() { + file_equipment_equipment_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_equipment_equipment_proto_rawDesc), len(file_equipment_equipment_proto_rawDesc))) + }) + return file_equipment_equipment_proto_rawDescData +} + +var file_equipment_equipment_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_equipment_equipment_proto_goTypes = []any{ + (*Response)(nil), // 0: equipment.Response + (*CreateRequest)(nil), // 1: equipment.CreateRequest + (*EditRequest)(nil), // 2: equipment.EditRequest + (*ItemsRequest)(nil), // 3: equipment.ItemsRequest + (*IdRequest)(nil), // 4: equipment.IdRequest + (*StatusRequest)(nil), // 5: equipment.StatusRequest +} +var file_equipment_equipment_proto_depIdxs = []int32{ + 3, // 0: equipment.Equipment.Items:input_type -> equipment.ItemsRequest + 4, // 1: equipment.Equipment.Info:input_type -> equipment.IdRequest + 1, // 2: equipment.Equipment.Create:input_type -> equipment.CreateRequest + 2, // 3: equipment.Equipment.Edit:input_type -> equipment.EditRequest + 5, // 4: equipment.Equipment.Status:input_type -> equipment.StatusRequest + 0, // 5: equipment.Equipment.Items:output_type -> equipment.Response + 0, // 6: equipment.Equipment.Info:output_type -> equipment.Response + 0, // 7: equipment.Equipment.Create:output_type -> equipment.Response + 0, // 8: equipment.Equipment.Edit:output_type -> equipment.Response + 0, // 9: equipment.Equipment.Status:output_type -> equipment.Response + 5, // [5:10] is the sub-list for method output_type + 0, // [0:5] 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_equipment_equipment_proto_init() } +func file_equipment_equipment_proto_init() { + if File_equipment_equipment_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_equipment_equipment_proto_rawDesc), len(file_equipment_equipment_proto_rawDesc)), + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_equipment_equipment_proto_goTypes, + DependencyIndexes: file_equipment_equipment_proto_depIdxs, + MessageInfos: file_equipment_equipment_proto_msgTypes, + }.Build() + File_equipment_equipment_proto = out.File + file_equipment_equipment_proto_goTypes = nil + file_equipment_equipment_proto_depIdxs = nil +} diff --git a/rpc/equipment/pb/equipment_grpc.pb.go b/rpc/equipment/pb/equipment_grpc.pb.go new file mode 100644 index 0000000..a684109 --- /dev/null +++ b/rpc/equipment/pb/equipment_grpc.pb.go @@ -0,0 +1,273 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.2 +// - protoc v4.25.8 +// source: equipment/equipment.proto + +package equipment + +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 ( + Equipment_Items_FullMethodName = "/equipment.Equipment/Items" + Equipment_Info_FullMethodName = "/equipment.Equipment/Info" + Equipment_Create_FullMethodName = "/equipment.Equipment/Create" + Equipment_Edit_FullMethodName = "/equipment.Equipment/Edit" + Equipment_Status_FullMethodName = "/equipment.Equipment/Status" +) + +// EquipmentClient is the client API for Equipment 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 EquipmentClient interface { + Items(ctx context.Context, in *ItemsRequest, opts ...grpc.CallOption) (*Response, error) + Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Edit(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) + Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) +} + +type equipmentClient struct { + cc grpc.ClientConnInterface +} + +func NewEquipmentClient(cc grpc.ClientConnInterface) EquipmentClient { + return &equipmentClient{cc} +} + +func (c *equipmentClient) Items(ctx context.Context, in *ItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Equipment_Items_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *equipmentClient) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Equipment_Info_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *equipmentClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Equipment_Create_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *equipmentClient) Edit(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Equipment_Edit_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *equipmentClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Equipment_Status_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// EquipmentServer is the server API for Equipment service. +// All implementations must embed UnimplementedEquipmentServer +// for forward compatibility. +type EquipmentServer interface { + Items(context.Context, *ItemsRequest) (*Response, error) + Info(context.Context, *IdRequest) (*Response, error) + Create(context.Context, *CreateRequest) (*Response, error) + Edit(context.Context, *EditRequest) (*Response, error) + Status(context.Context, *StatusRequest) (*Response, error) + mustEmbedUnimplementedEquipmentServer() +} + +// UnimplementedEquipmentServer 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 UnimplementedEquipmentServer struct{} + +func (UnimplementedEquipmentServer) Items(context.Context, *ItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Items not implemented") +} +func (UnimplementedEquipmentServer) Info(context.Context, *IdRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Info not implemented") +} +func (UnimplementedEquipmentServer) Create(context.Context, *CreateRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Create not implemented") +} +func (UnimplementedEquipmentServer) Edit(context.Context, *EditRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Edit not implemented") +} +func (UnimplementedEquipmentServer) Status(context.Context, *StatusRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Status not implemented") +} +func (UnimplementedEquipmentServer) mustEmbedUnimplementedEquipmentServer() {} +func (UnimplementedEquipmentServer) testEmbeddedByValue() {} + +// UnsafeEquipmentServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to EquipmentServer will +// result in compilation errors. +type UnsafeEquipmentServer interface { + mustEmbedUnimplementedEquipmentServer() +} + +func RegisterEquipmentServer(s grpc.ServiceRegistrar, srv EquipmentServer) { + // If the following call panics, it indicates UnimplementedEquipmentServer 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(&Equipment_ServiceDesc, srv) +} + +func _Equipment_Items_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EquipmentServer).Items(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Equipment_Items_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EquipmentServer).Items(ctx, req.(*ItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Equipment_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(IdRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EquipmentServer).Info(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Equipment_Info_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EquipmentServer).Info(ctx, req.(*IdRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Equipment_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EquipmentServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Equipment_Create_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EquipmentServer).Create(ctx, req.(*CreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Equipment_Edit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EditRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EquipmentServer).Edit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Equipment_Edit_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EquipmentServer).Edit(ctx, req.(*EditRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Equipment_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EquipmentServer).Status(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Equipment_Status_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EquipmentServer).Status(ctx, req.(*StatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Equipment_ServiceDesc is the grpc.ServiceDesc for Equipment service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Equipment_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "equipment.Equipment", + HandlerType: (*EquipmentServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Items", + Handler: _Equipment_Items_Handler, + }, + { + MethodName: "Info", + Handler: _Equipment_Info_Handler, + }, + { + MethodName: "Create", + Handler: _Equipment_Create_Handler, + }, + { + MethodName: "Edit", + Handler: _Equipment_Edit_Handler, + }, + { + MethodName: "Status", + Handler: _Equipment_Status_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "equipment/equipment.proto", +} diff --git a/services/equipment/.gitignore b/services/equipment/.gitignore new file mode 100644 index 0000000..36d5ef0 --- /dev/null +++ b/services/equipment/.gitignore @@ -0,0 +1,3 @@ +run.toml +etc/equipment.yaml +tmp \ No newline at end of file diff --git a/services/equipment/Dockerfile b/services/equipment/Dockerfile new file mode 100644 index 0000000..e8162db --- /dev/null +++ b/services/equipment/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/equipment/ ./services/equipment/ + +WORKDIR /src/services/equipment + +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/equipment.yaml"] diff --git a/services/equipment/equipment.go b/services/equipment/equipment.go new file mode 100644 index 0000000..7da09bf --- /dev/null +++ b/services/equipment/equipment.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" + equipment "lone-services/rpc/equipment/pb" + "net" + "os" + "strconv" + + "lone-services/services/equipment/internal/config" + "lone-services/services/equipment/internal/server" + "lone-services/services/equipment/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/equipment.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) { + equipment.RegisterEquipmentServer(grpcServer, server.NewEquipmentServer(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/equipment/equipmentclient/equipment.go b/services/equipment/equipmentclient/equipment.go new file mode 100644 index 0000000..510f886 --- /dev/null +++ b/services/equipment/equipmentclient/equipment.go @@ -0,0 +1,66 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: equipment.proto + +package equipmentClient + +import ( + "context" + + "lone-services/rpc/equipment/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + CreateRequest = equipment.CreateRequest + EditRequest = equipment.EditRequest + IdRequest = equipment.IdRequest + ItemsRequest = equipment.ItemsRequest + Response = equipment.Response + StatusRequest = equipment.StatusRequest + + Equipment interface { + Items(ctx context.Context, in *ItemsRequest, opts ...grpc.CallOption) (*Response, error) + Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) + Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) + Edit(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) + Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) + } + + defaultEquipment struct { + cli zrpc.Client + } +) + +func NewEquipment(cli zrpc.Client) Equipment { + return &defaultEquipment{ + cli: cli, + } +} + +func (m *defaultEquipment) Items(ctx context.Context, in *ItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := equipment.NewEquipmentClient(m.cli.Conn()) + return client.Items(ctx, in, opts...) +} + +func (m *defaultEquipment) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) { + client := equipment.NewEquipmentClient(m.cli.Conn()) + return client.Info(ctx, in, opts...) +} + +func (m *defaultEquipment) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + client := equipment.NewEquipmentClient(m.cli.Conn()) + return client.Create(ctx, in, opts...) +} + +func (m *defaultEquipment) Edit(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) { + client := equipment.NewEquipmentClient(m.cli.Conn()) + return client.Edit(ctx, in, opts...) +} + +func (m *defaultEquipment) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := equipment.NewEquipmentClient(m.cli.Conn()) + return client.Status(ctx, in, opts...) +} diff --git a/services/equipment/internal/config/config.go b/services/equipment/internal/config/config.go new file mode 100644 index 0000000..a1979dd --- /dev/null +++ b/services/equipment/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/equipment/internal/dao/version.go b/services/equipment/internal/dao/version.go new file mode 100644 index 0000000..cf37c93 --- /dev/null +++ b/services/equipment/internal/dao/version.go @@ -0,0 +1,39 @@ +package dao + +type Version struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + HardwareVersion string `gorm:"column:hardware_version;type:varchar(32);default:'';NOT NULL" json:"hardware_version"` + Version string `gorm:"column:version;type:varchar(32);default:'';NOT NULL" json:"version"` + FirmwareSrc string `gorm:"column:firmware_src;type:varchar(255);default:'';NOT NULL" json:"firmware_src"` + SoftSrc string `gorm:"column:soft_src;type:varchar(255);default:'';NOT NULL" json:"soft_src"` + AddSrc string `gorm:"column:add_src;type:varchar(255);default:'';NOT NULL" json:"add_src"` + SoftConfig string `gorm:"column:soft_config;type:text" json:"soft_config"` + Describe string `gorm:"column:describe;type:varchar(255);default:'';NOT NULL" json:"describe"` + Status uint8 `gorm:"column:status;type:tinyint(1);default:1;NOT NULL" json:"status"` + Reason string `gorm:"column:reason;type:varchar(32);default:'';NOT NULL" json:"reason"` + Type uint8 `gorm:"column:type;type:tinyint(1);default:0;NOT NULL" json:"type"` + AdminId int64 `gorm:"column:admin_id;type:int(11);default:0;NOT NULL" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(32);default:'';NOT NULL" json:"admin_name"` +} + +type VersionInfo struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + HardwareVersion string `gorm:"column:hardware_version;type:varchar(32);default:'';NOT NULL" json:"hardware_version"` + Version string `gorm:"column:version;type:varchar(32);default:'';NOT NULL" json:"version"` + FirmwareSrc string `gorm:"column:firmware_src;type:varchar(255);default:'';NOT NULL" json:"firmware_src"` + SoftSrc string `gorm:"column:soft_src;type:varchar(255);default:'';NOT NULL" json:"soft_src"` + AddSrc string `gorm:"column:add_src;type:varchar(255);default:'';NOT NULL" json:"add_src"` + SoftConfig string `gorm:"column:soft_config;type:text" json:"soft_config"` + Describe string `gorm:"column:describe;type:varchar(255);default:'';NOT NULL" json:"describe"` + Status uint8 `gorm:"column:status;type:tinyint(1);default:1;NOT NULL" json:"status"` + Reason string `gorm:"column:reason;type:varchar(32);default:'';NOT NULL" json:"reason"` + Type uint8 `gorm:"column:type;type:tinyint(1);default:0;NOT NULL" json:"type"` +} + +type VersionStatus struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Status uint8 `gorm:"column:status;type:tinyint(1);default:1;NOT NULL" json:"status"` + Reason string `gorm:"column:reason;type:varchar(32);default:'';NOT NULL" json:"reason"` + AdminId int64 `gorm:"column:admin_id;type:int(11);default:0;NOT NULL" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(32);default:'';NOT NULL" json:"admin_name"` +} diff --git a/services/equipment/internal/logic/base.go b/services/equipment/internal/logic/base.go new file mode 100644 index 0000000..2d5ca51 --- /dev/null +++ b/services/equipment/internal/logic/base.go @@ -0,0 +1,44 @@ +package logic + +import ( + "lone-services/pkg/utils" + "lone-services/pkg/validate" + equipment "lone-services/rpc/equipment/pb" + "reflect" + + jsoniter "github.com/json-iterator/go" +) + +type BaseLogic struct { +} + +func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *equipment.Response { + rv := reflect.ValueOf(in) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &equipment.Response{ + Code: utils.ErrorParams.Code, + Msg: "request must be non‑nil proto pointer", + } + } + + resp := validate.ValidateFromProto(in, v) + if resp != utils.StringEmpty { + return &equipment.Response{ + Code: utils.ErrorParams.Code, + Msg: resp, + } + } + return nil +} + +func (l *BaseLogic) fail(status utils.Status) (*equipment.Response, error) { + return l.out(status, status.Msg) +} +func (l *BaseLogic) out(status utils.Status, msg string) (*equipment.Response, error) { + return &equipment.Response{Code: status.Code, Msg: msg}, nil +} + +func (l *BaseLogic) ok(data any) (*equipment.Response, error) { + buf, _ := jsoniter.Marshal(data) + return &equipment.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil +} diff --git a/services/equipment/internal/logic/createLogic.go b/services/equipment/internal/logic/createLogic.go new file mode 100644 index 0000000..098328e --- /dev/null +++ b/services/equipment/internal/logic/createLogic.go @@ -0,0 +1,67 @@ +package logic + +import ( + "context" + "lone-services/pkg/utils" + "lone-services/services/equipment/internal/dao" + "lone-services/services/equipment/internal/model" + "lone-services/services/task/validator" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type CreateLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic { + return &CreateLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *CreateLogic) Create(in *equipment.CreateRequest) (*equipment.Response, error) { + var v validator.TaskCreateValidator + 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) + } + data := dao.Version{ + Type: uint8(in.Type), + HardwareVersion: in.HardwareVersion, + FirmwareSrc: in.FirmwareSrc, + SoftSrc: in.SoftSrc, + SoftConfig: in.SoftConfig, + Version: in.Version, + Describe: in.Describe, + AddSrc: in.AddSrc, + AdminId: adminInfo.ID, + AdminName: adminInfo.Name, + } + + err := model.VersionModel{}.Init().Create(&data) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + action := utils.ActionAdd{ + NewContent: data, + Type: utils.LogActionTypeAdd, + ModuleName: utils.LogActionModuleEquipment, + } + utils.SetActionLog(adminInfo, action) + + return l.ok(data.Id) +} diff --git a/services/equipment/internal/logic/editLogic.go b/services/equipment/internal/logic/editLogic.go new file mode 100644 index 0000000..bde9709 --- /dev/null +++ b/services/equipment/internal/logic/editLogic.go @@ -0,0 +1,81 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/equipment/internal/dao" + "lone-services/services/equipment/internal/model" + "lone-services/services/task/validator" + "strconv" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type EditLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic { + return &EditLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *EditLogic) Edit(in *equipment.EditRequest) (*equipment.Response, error) { + var v validator.TaskEditValidator + 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) + } + + var info dao.Version + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + err := model.VersionModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleEquipment, + } + + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + info.HardwareVersion = in.HardwareVersion + info.Version = in.Version + info.FirmwareSrc = in.FirmwareSrc + info.Describe = in.Describe + info.SoftSrc = in.SoftSrc + info.AddSrc = in.AddSrc + info.SoftConfig = in.SoftConfig + info.Type = uint8(in.Type) + + row, err := model.VersionModel{}.Init().Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if row > utils.NumberZero { + action.NewContent = info + utils.SetActionLog(adminInfo, action) + } + + return l.ok(info.Id) +} diff --git a/services/equipment/internal/logic/infoLogic.go b/services/equipment/internal/logic/infoLogic.go new file mode 100644 index 0000000..4dda87c --- /dev/null +++ b/services/equipment/internal/logic/infoLogic.go @@ -0,0 +1,51 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + "lone-services/services/equipment/internal/dao" + "lone-services/services/equipment/internal/model" + "strconv" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type InfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic { + return &InfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *InfoLogic) Info(in *equipment.IdRequest) (*equipment.Response, error) { + var v validate.InfoValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + + var info dao.VersionInfo + modelObj := model.VersionModel{}.Init() + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + err := modelObj.GetOne(w, &info) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + return l.ok(info) +} diff --git a/services/equipment/internal/logic/itemsLogic.go b/services/equipment/internal/logic/itemsLogic.go new file mode 100644 index 0000000..6bedbe9 --- /dev/null +++ b/services/equipment/internal/logic/itemsLogic.go @@ -0,0 +1,52 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/equipment/internal/dao" + "lone-services/services/equipment/internal/model" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic { + return &ItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ItemsLogic) Items(in *equipment.ItemsRequest) (*equipment.Response, error) { + modelObj := model.VersionModel{}.Init() + w := modelbase.Params{ + Page: int(in.Page), + Size: int(in.Size), + } + if in.Type != utils.NumberZero { + w.Eq = map[string]string{"type": string(in.Type)} + } + + var data []dao.VersionInfo + err := modelObj.Items(w, &data) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + + if len(data) < utils.NumberOne { + return l.ok(data) + } + + return l.ok(data) +} diff --git a/services/equipment/internal/logic/statusLogic.go b/services/equipment/internal/logic/statusLogic.go new file mode 100644 index 0000000..df064dc --- /dev/null +++ b/services/equipment/internal/logic/statusLogic.go @@ -0,0 +1,72 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + "lone-services/services/equipment/internal/dao" + "lone-services/services/equipment/internal/model" + "strconv" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type StatusLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic { + return &StatusLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *StatusLogic) Status(in *equipment.StatusRequest) (*equipment.Response, error) { + var v validate.StatusValidator + 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) + } + var action = utils.ActionAdd{} + var info dao.VersionStatus + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + modelObj := model.VersionModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + action.OldContent = info + info.Status = uint8(in.Status) + info.Reason = in.Reason + info.AdminName = adminInfo.Name + info.AdminId = adminInfo.ID + row, editErr := modelObj.Edit(w, info) + if editErr != nil { + l.Logger.Error(editErr) + return l.fail(utils.Fail) + } + if row > utils.NumberZero { + action.NewContent = info + action.Reason = in.Reason + action.Type = utils.LogActionTypeStatus + action.ModuleName = utils.LogActionModuleEquipment + utils.SetActionLog(adminInfo, action) + } + return l.ok(utils.NumberOne) +} diff --git a/services/equipment/internal/model/version.go b/services/equipment/internal/model/version.go new file mode 100644 index 0000000..166562e --- /dev/null +++ b/services/equipment/internal/model/version.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/equipment/internal/dao" +) + +type VersionModel struct { + modelbase.Base +} + +func (m VersionModel) TableName() string { + return modelbase.Prefix() + "version" +} + +func (m VersionModel) Init() VersionModel { + m.Table = m.TableName() + return m +} + +func (m VersionModel) Create(data *dao.Version) error { + return m.Base.Create(data) +} diff --git a/services/equipment/internal/server/equipmentServer.go b/services/equipment/internal/server/equipmentServer.go new file mode 100644 index 0000000..17b7209 --- /dev/null +++ b/services/equipment/internal/server/equipmentServer.go @@ -0,0 +1,49 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: equipment.proto + +package server + +import ( + "context" + + "lone-services/rpc/equipment/pb" + "lone-services/services/equipment/internal/logic" + "lone-services/services/equipment/internal/svc" +) + +type EquipmentServer struct { + svcCtx *svc.ServiceContext + equipment.UnimplementedEquipmentServer +} + +func NewEquipmentServer(svcCtx *svc.ServiceContext) *EquipmentServer { + return &EquipmentServer{ + svcCtx: svcCtx, + } +} + +func (s *EquipmentServer) Items(ctx context.Context, in *equipment.ItemsRequest) (*equipment.Response, error) { + l := logic.NewItemsLogic(ctx, s.svcCtx) + return l.Items(in) +} + +func (s *EquipmentServer) Info(ctx context.Context, in *equipment.IdRequest) (*equipment.Response, error) { + l := logic.NewInfoLogic(ctx, s.svcCtx) + return l.Info(in) +} + +func (s *EquipmentServer) Create(ctx context.Context, in *equipment.CreateRequest) (*equipment.Response, error) { + l := logic.NewCreateLogic(ctx, s.svcCtx) + return l.Create(in) +} + +func (s *EquipmentServer) Edit(ctx context.Context, in *equipment.EditRequest) (*equipment.Response, error) { + l := logic.NewEditLogic(ctx, s.svcCtx) + return l.Edit(in) +} + +func (s *EquipmentServer) Status(ctx context.Context, in *equipment.StatusRequest) (*equipment.Response, error) { + l := logic.NewStatusLogic(ctx, s.svcCtx) + return l.Status(in) +} diff --git a/services/equipment/internal/svc/servicecontext.go b/services/equipment/internal/svc/servicecontext.go new file mode 100644 index 0000000..d51e45b --- /dev/null +++ b/services/equipment/internal/svc/servicecontext.go @@ -0,0 +1,23 @@ +package svc + +import ( + "lone-services/pkg/utils" + "lone-services/services/equipment/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/equipment/validator/version.go b/services/equipment/validator/version.go new file mode 100644 index 0000000..a10edf9 --- /dev/null +++ b/services/equipment/validator/version.go @@ -0,0 +1,53 @@ +package validator + +import "lone-services/pkg/validate" + +type VersionCreateValidator struct { + HardwareVersion string `form:"hardware_version" json:"hardware_version" validate:"required"` + Version string `form:"version" json:"version" validate:"required"` + FirmwareSrc string `form:"firmware_src" json:"firmware_src" validate:"required"` + Describe string `form:"describe" json:"describe" validate:"required"` + Type uint8 `form:"type" json:"type" validate:"required"` + SoftSrc string `form:"soft_src" json:"soft_src"` + AddSrc string `form:"add_src" json:"add_src"` + SoftConfig string `form:"soft_config" json:"soft_config"` +} + +func (p VersionCreateValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "HardwareVersion.required": "HardwareVersion 必传", + "Version.required": "Version 必传", + "FirmwareSrc.required": "FirmwareSrc 必传", + "Describe.required": "Describe 必传", + "Type.required": "Type 必传", + } +} + +type VersionEditValidator struct { + Id int `form:"id" json:"id" validate:"required"` + HardwareVersion string `form:"hardware_version" json:"hardware_version" validate:"required"` + Version string `form:"version" json:"version" validate:"required"` + FirmwareSrc string `form:"firmware_src" json:"firmware_src" validate:"required"` + Describe string `form:"describe" json:"describe" validate:"required"` + Type uint8 `form:"type" json:"type" validate:"required"` + SoftSrc string `form:"soft_src" json:"soft_src"` + AddSrc string `form:"add_src" json:"add_src"` + SoftConfig string `form:"soft_config" json:"soft_config"` +} + +func (p VersionEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "Id 必传", + "HardwareVersion.required": "HardwareVersion 必传", + "Version.required": "Version 必传", + "FirmwareSrc.required": "FirmwareSrc 必传", + "Describe.required": "Describe 必传", + "Type.required": "Type 必传", + } +} + +type VersionItemsValidator struct { + Page int `form:"page" json:"page"` + Size int `form:"size" json:"size"` + Type uint8 `form:"type" json:"type"` +} diff --git a/services/task/internal/logic/infoLogic.go b/services/task/internal/logic/infoLogic.go index ded6908..df32da3 100644 --- a/services/task/internal/logic/infoLogic.go +++ b/services/task/internal/logic/infoLogic.go @@ -4,10 +4,10 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + "lone-services/pkg/validate" product "lone-services/rpc/product/pb" "lone-services/services/task/internal/dao" "lone-services/services/task/internal/model" - "lone-services/services/task/validator" "strconv" "lone-services/rpc/task/pb" @@ -32,7 +32,7 @@ func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic { } func (l *InfoLogic) Info(in *task.IdRequest) (*task.Response, error) { - var v validator.TaskInfoValidator + var v validate.InfoValidator if fail := l.checkParams(in, &v); fail != nil { return fail, nil } diff --git a/services/task/internal/logic/statusLogic.go b/services/task/internal/logic/statusLogic.go index cc5ccff..79556d1 100644 --- a/services/task/internal/logic/statusLogic.go +++ b/services/task/internal/logic/statusLogic.go @@ -4,9 +4,9 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + "lone-services/pkg/validate" "lone-services/services/task/internal/dao" "lone-services/services/task/internal/model" - "lone-services/services/task/validator" "strconv" "lone-services/rpc/task/pb" @@ -31,7 +31,7 @@ func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogi } func (l *StatusLogic) Status(in *task.StatusRequest) (*task.Response, error) { - var v validator.TaskStatusValidator + var v validate.StatusValidator if fail := l.checkParams(in, &v); fail != nil { return fail, nil } diff --git a/services/task/validator/task.go b/services/task/validator/task.go index f99ed1c..abfc499 100644 --- a/services/task/validator/task.go +++ b/services/task/validator/task.go @@ -34,27 +34,12 @@ type TaskEditValidator struct { // GetMessage 提示消息 func (p TaskEditValidator) GetMessage() validate.ValidatorMessages { return validate.ValidatorMessages{ - "Id.required": "ID不能为空", + validate.FieldId: validate.FieldIdValue, "Task.required": "任务不能为空", "Award.required": "奖励不能为空", } } -type TaskStatusValidator struct { - Id int64 `form:"id" json:"id" validate:"required"` - Status int32 `form:"status" json:"status" validate:"required"` - Reason string `form:"reason" json:"reason" validate:"required_if=Status 2"` -} - -// GetMessage 提示消息 -func (p TaskStatusValidator) GetMessage() validate.ValidatorMessages { - return validate.ValidatorMessages{ - "Id.required": "ID不能为空", - "Status.required": "状态不能为空", - "Reason.required_if": "禁用状态,理由不能为空", - } -} - type TaskItemsValidator struct { Page int32 `form:"page" json:"page"` Size int32 `form:"size" json:"size"` @@ -78,14 +63,3 @@ type TaskAccountItemsValidator struct { func (p TaskAccountItemsValidator) GetMessage() validate.ValidatorMessages { return validate.ValidatorMessages{} } - -type TaskInfoValidator struct { - Id int64 `form:"id" json:"id" validate:"required"` -} - -// GetMessage 提示消息 -func (p TaskInfoValidator) GetMessage() validate.ValidatorMessages { - return validate.ValidatorMessages{ - "Id.required": "ID不能为空", - } -}