diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 1d0c38a..1bee3d6 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 express sale wecom" + SERVICES="bff product admin user ad chore express sale wecom task equipment" pattern_for() { case "$1" in @@ -90,6 +90,8 @@ jobs: - express - sale - wecom + - task + - equipment env: BUILD_LIST: ${{ needs.changes.outputs.build_list }} NAME: lone/${{ matrix.name }} diff --git a/deploy/apisix/lua/auth.lua b/deploy/apisix/lua/auth.lua index a1656ae..fefe3e7 100644 --- a/deploy/apisix/lua/auth.lua +++ b/deploy/apisix/lua/auth.lua @@ -14,6 +14,7 @@ function _M.access(conf, ctx) ["/api/v3/login"] = true, ["/admin/v3/login"] = true, ["/admin/v3/refresh"] = true, + ["/api/v3/version"] = true, } local user_key = core.request.header(ctx, "authorization") 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 0000000..cc08249 Binary files /dev/null and b/rpc/equipment/equipment.pb differ diff --git a/rpc/equipment/equipment.proto b/rpc/equipment/equipment.proto new file mode 100644 index 0000000..b49f5ce --- /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/version/items" + body: "*" + }; + }; + rpc Info(IdRequest) returns(Response){ + option (google.api.http) = { + get: "/admin/v3/version/info" + body: "*" + }; + }; + rpc Create(CreateRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/version/create" + body: "*" + }; + }; + rpc Edit(EditRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/version/edit" + body: "*" + }; + }; + rpc Status(StatusRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/version/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..cbd6f8d --- /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\xd0\x03\n" + + "\tEquipment\x12Y\n" + + "\x05Items\x12\x17.equipment.ItemsRequest\x1a\x13.equipment.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\x12\x17/admin/v3/version/items\x12T\n" + + "\x04Info\x12\x14.equipment.IdRequest\x1a\x13.equipment.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\x12\x16/admin/v3/version/info\x12\\\n" + + "\x06Create\x12\x18.equipment.CreateRequest\x1a\x13.equipment.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/version/create\x12V\n" + + "\x04Edit\x12\x16.equipment.EditRequest\x1a\x13.equipment.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/version/edit\x12\\\n" + + "\x06Status\x12\x18.equipment.StatusRequest\x1a\x13.equipment.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/version/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/rpc/task/pb/task.pb.go b/rpc/task/pb/task.pb.go index 7785f5f..e1853bb 100644 --- a/rpc/task/pb/task.pb.go +++ b/rpc/task/pb/task.pb.go @@ -118,23 +118,110 @@ func (*EmtpyRequest) Descriptor() ([]byte, []int) { return file_task_task_proto_rawDescGZIP(), []int{1} } +type CreateRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Type int32 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"` + Time int32 `protobuf:"varint,2,opt,name=time,proto3" json:"time,omitempty"` + Province int64 `protobuf:"varint,3,opt,name=province,proto3" json:"province,omitempty"` + ProvinceName string `protobuf:"bytes,4,opt,name=province_name,json=provinceName,proto3" json:"province_name,omitempty"` + Task int32 `protobuf:"varint,5,opt,name=task,proto3" json:"task,omitempty"` + Award float64 `protobuf:"fixed64,6,opt,name=award,proto3" json:"award,omitempty"` + ProductId int64 `protobuf:"varint,7,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CreateRequest) Reset() { + *x = CreateRequest{} + mi := &file_task_task_proto_msgTypes[2] + 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_task_task_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 CreateRequest.ProtoReflect.Descriptor instead. +func (*CreateRequest) Descriptor() ([]byte, []int) { + return file_task_task_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateRequest) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *CreateRequest) GetTime() int32 { + if x != nil { + return x.Time + } + return 0 +} + +func (x *CreateRequest) GetProvince() int64 { + if x != nil { + return x.Province + } + return 0 +} + +func (x *CreateRequest) GetProvinceName() string { + if x != nil { + return x.ProvinceName + } + return "" +} + +func (x *CreateRequest) GetTask() int32 { + if x != nil { + return x.Task + } + return 0 +} + +func (x *CreateRequest) GetAward() float64 { + if x != nil { + return x.Award + } + return 0 +} + +func (x *CreateRequest) GetProductId() int64 { + if x != nil { + return x.ProductId + } + return 0 +} + type EditRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` - Time int32 `protobuf:"varint,3,opt,name=time,proto3" json:"time,omitempty"` - Province int64 `protobuf:"varint,4,opt,name=province,proto3" json:"province,omitempty"` - ProvinceName string `protobuf:"bytes,5,opt,name=province_name,json=provinceName,proto3" json:"province_name,omitempty"` - Task string `protobuf:"bytes,6,opt,name=task,proto3" json:"task,omitempty"` - Award string `protobuf:"bytes,7,opt,name=award,proto3" json:"award,omitempty"` - ProductId int64 `protobuf:"varint,8,opt,name=product_id,json=productId,proto3" json:"product_id,omitempty"` + Task int32 `protobuf:"varint,2,opt,name=task,proto3" json:"task,omitempty"` + Award float64 `protobuf:"fixed64,3,opt,name=award,proto3" json:"award,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *EditRequest) Reset() { *x = EditRequest{} - mi := &file_task_task_proto_msgTypes[2] + mi := &file_task_task_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -146,7 +233,7 @@ func (x *EditRequest) String() string { func (*EditRequest) ProtoMessage() {} func (x *EditRequest) ProtoReflect() protoreflect.Message { - mi := &file_task_task_proto_msgTypes[2] + mi := &file_task_task_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -159,7 +246,7 @@ func (x *EditRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use EditRequest.ProtoReflect.Descriptor instead. func (*EditRequest) Descriptor() ([]byte, []int) { - return file_task_task_proto_rawDescGZIP(), []int{2} + return file_task_task_proto_rawDescGZIP(), []int{3} } func (x *EditRequest) GetId() int64 { @@ -169,52 +256,17 @@ func (x *EditRequest) GetId() int64 { return 0 } -func (x *EditRequest) GetType() int32 { - if x != nil { - return x.Type - } - return 0 -} - -func (x *EditRequest) GetTime() int32 { - if x != nil { - return x.Time - } - return 0 -} - -func (x *EditRequest) GetProvince() int64 { - if x != nil { - return x.Province - } - return 0 -} - -func (x *EditRequest) GetProvinceName() string { - if x != nil { - return x.ProvinceName - } - return "" -} - -func (x *EditRequest) GetTask() string { +func (x *EditRequest) GetTask() int32 { if x != nil { return x.Task } - return "" + return 0 } -func (x *EditRequest) GetAward() string { +func (x *EditRequest) GetAward() float64 { if x != nil { return x.Award } - return "" -} - -func (x *EditRequest) GetProductId() int64 { - if x != nil { - return x.ProductId - } return 0 } @@ -227,7 +279,7 @@ type IdRequest struct { func (x *IdRequest) Reset() { *x = IdRequest{} - mi := &file_task_task_proto_msgTypes[3] + mi := &file_task_task_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -239,7 +291,7 @@ func (x *IdRequest) String() string { func (*IdRequest) ProtoMessage() {} func (x *IdRequest) ProtoReflect() protoreflect.Message { - mi := &file_task_task_proto_msgTypes[3] + mi := &file_task_task_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -252,7 +304,7 @@ func (x *IdRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use IdRequest.ProtoReflect.Descriptor instead. func (*IdRequest) Descriptor() ([]byte, []int) { - return file_task_task_proto_rawDescGZIP(), []int{3} + return file_task_task_proto_rawDescGZIP(), []int{4} } func (x *IdRequest) GetId() int64 { @@ -273,7 +325,7 @@ type StatusRequest struct { func (x *StatusRequest) Reset() { *x = StatusRequest{} - mi := &file_task_task_proto_msgTypes[4] + mi := &file_task_task_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -285,7 +337,7 @@ func (x *StatusRequest) String() string { func (*StatusRequest) ProtoMessage() {} func (x *StatusRequest) ProtoReflect() protoreflect.Message { - mi := &file_task_task_proto_msgTypes[4] + mi := &file_task_task_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -298,7 +350,7 @@ func (x *StatusRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use StatusRequest.ProtoReflect.Descriptor instead. func (*StatusRequest) Descriptor() ([]byte, []int) { - return file_task_task_proto_rawDescGZIP(), []int{4} + return file_task_task_proto_rawDescGZIP(), []int{5} } func (x *StatusRequest) GetId() int64 { @@ -331,27 +383,30 @@ const file_task_task_proto_rawDesc = "" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + "\x04data\x18\x03 \x01(\tR\x04data\"\x0e\n" + - "\fEmtpyRequest\"\xcf\x01\n" + + "\fEmtpyRequest\"\xc1\x01\n" + + "\rCreateRequest\x12\x12\n" + + "\x04type\x18\x01 \x01(\x05R\x04type\x12\x12\n" + + "\x04time\x18\x02 \x01(\x05R\x04time\x12\x1a\n" + + "\bprovince\x18\x03 \x01(\x03R\bprovince\x12#\n" + + "\rprovince_name\x18\x04 \x01(\tR\fprovinceName\x12\x12\n" + + "\x04task\x18\x05 \x01(\x05R\x04task\x12\x14\n" + + "\x05award\x18\x06 \x01(\x01R\x05award\x12\x1d\n" + + "\n" + + "product_id\x18\a \x01(\x03R\tproductId\"G\n" + "\vEditRequest\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + - "\x04type\x18\x02 \x01(\x05R\x04type\x12\x12\n" + - "\x04time\x18\x03 \x01(\x05R\x04time\x12\x1a\n" + - "\bprovince\x18\x04 \x01(\x03R\bprovince\x12#\n" + - "\rprovince_name\x18\x05 \x01(\tR\fprovinceName\x12\x12\n" + - "\x04task\x18\x06 \x01(\tR\x04task\x12\x14\n" + - "\x05award\x18\a \x01(\tR\x05award\x12\x1d\n" + - "\n" + - "product_id\x18\b \x01(\x03R\tproductId\"\x1b\n" + + "\x04task\x18\x02 \x01(\x05R\x04task\x12\x14\n" + + "\x05award\x18\x03 \x01(\x01R\x05award\"\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\x88\x03\n" + + "\x06reason\x18\x03 \x01(\tR\x06reason2\x8a\x03\n" + "\x04Task\x12L\n" + "\x05Items\x12\x12.task.EmtpyRequest\x1a\x0e.task.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/task/items\x12G\n" + - "\x04Info\x12\x0f.task.IdRequest\x1a\x0e.task.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\x12\x13/admin/v3/task/info\x12M\n" + - "\x06Create\x12\x11.task.EditRequest\x1a\x0e.task.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/admin/v3/task/create\x12I\n" + + "\x04Info\x12\x0f.task.IdRequest\x1a\x0e.task.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\x12\x13/admin/v3/task/info\x12O\n" + + "\x06Create\x12\x13.task.CreateRequest\x1a\x0e.task.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/admin/v3/task/create\x12I\n" + "\x04Edit\x12\x11.task.EditRequest\x1a\x0e.task.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/admin/v3/task/edit\x12O\n" + "\x06Status\x12\x13.task.StatusRequest\x1a\x0e.task.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/admin/v3/task/statusB\bZ\x06./taskb\x06proto3" @@ -367,20 +422,21 @@ func file_task_task_proto_rawDescGZIP() []byte { return file_task_task_proto_rawDescData } -var file_task_task_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_task_task_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_task_task_proto_goTypes = []any{ (*Response)(nil), // 0: task.Response (*EmtpyRequest)(nil), // 1: task.EmtpyRequest - (*EditRequest)(nil), // 2: task.EditRequest - (*IdRequest)(nil), // 3: task.IdRequest - (*StatusRequest)(nil), // 4: task.StatusRequest + (*CreateRequest)(nil), // 2: task.CreateRequest + (*EditRequest)(nil), // 3: task.EditRequest + (*IdRequest)(nil), // 4: task.IdRequest + (*StatusRequest)(nil), // 5: task.StatusRequest } var file_task_task_proto_depIdxs = []int32{ 1, // 0: task.Task.Items:input_type -> task.EmtpyRequest - 3, // 1: task.Task.Info:input_type -> task.IdRequest - 2, // 2: task.Task.Create:input_type -> task.EditRequest - 2, // 3: task.Task.Edit:input_type -> task.EditRequest - 4, // 4: task.Task.Status:input_type -> task.StatusRequest + 4, // 1: task.Task.Info:input_type -> task.IdRequest + 2, // 2: task.Task.Create:input_type -> task.CreateRequest + 3, // 3: task.Task.Edit:input_type -> task.EditRequest + 5, // 4: task.Task.Status:input_type -> task.StatusRequest 0, // 5: task.Task.Items:output_type -> task.Response 0, // 6: task.Task.Info:output_type -> task.Response 0, // 7: task.Task.Create:output_type -> task.Response @@ -404,7 +460,7 @@ func file_task_task_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_task_task_proto_rawDesc), len(file_task_task_proto_rawDesc)), NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/task/pb/task_grpc.pb.go b/rpc/task/pb/task_grpc.pb.go index 04d1706..67a6c5b 100644 --- a/rpc/task/pb/task_grpc.pb.go +++ b/rpc/task/pb/task_grpc.pb.go @@ -32,7 +32,7 @@ const ( type TaskClient interface { Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) - Create(ctx context.Context, in *EditRequest, 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) } @@ -65,7 +65,7 @@ func (c *taskClient) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallO return out, nil } -func (c *taskClient) Create(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) { +func (c *taskClient) 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, Task_Create_FullMethodName, in, out, cOpts...) @@ -101,7 +101,7 @@ func (c *taskClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc type TaskServer interface { Items(context.Context, *EmtpyRequest) (*Response, error) Info(context.Context, *IdRequest) (*Response, error) - Create(context.Context, *EditRequest) (*Response, error) + Create(context.Context, *CreateRequest) (*Response, error) Edit(context.Context, *EditRequest) (*Response, error) Status(context.Context, *StatusRequest) (*Response, error) mustEmbedUnimplementedTaskServer() @@ -120,7 +120,7 @@ func (UnimplementedTaskServer) Items(context.Context, *EmtpyRequest) (*Response, func (UnimplementedTaskServer) Info(context.Context, *IdRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Info not implemented") } -func (UnimplementedTaskServer) Create(context.Context, *EditRequest) (*Response, error) { +func (UnimplementedTaskServer) Create(context.Context, *CreateRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Create not implemented") } func (UnimplementedTaskServer) Edit(context.Context, *EditRequest) (*Response, error) { @@ -187,7 +187,7 @@ func _Task_Info_Handler(srv interface{}, ctx context.Context, dec func(interface } func _Task_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EditRequest) + in := new(CreateRequest) if err := dec(in); err != nil { return nil, err } @@ -199,7 +199,7 @@ func _Task_Create_Handler(srv interface{}, ctx context.Context, dec func(interfa FullMethod: Task_Create_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TaskServer).Create(ctx, req.(*EditRequest)) + return srv.(TaskServer).Create(ctx, req.(*CreateRequest)) } return interceptor(ctx, in, info, handler) } diff --git a/rpc/task/task.pb b/rpc/task/task.pb index 56dff6b..c887dc7 100644 Binary files a/rpc/task/task.pb and b/rpc/task/task.pb differ diff --git a/rpc/task/task.proto b/rpc/task/task.proto index 157bec1..be9bda7 100644 --- a/rpc/task/task.proto +++ b/rpc/task/task.proto @@ -14,15 +14,20 @@ message Response { message EmtpyRequest { } +message CreateRequest { + int32 type =1; + int32 time =2; + int64 province =3; + string province_name =4; + int32 task =5; + double award =6; + int64 product_id =7; +} + message EditRequest { int64 id = 1; - int32 type =2; - int32 time =3; - int64 province =4; - string province_name =5; - string task =6; - string award =7; - int64 product_id =8; + int32 task =2; + double award =3; } message IdRequest { @@ -48,7 +53,7 @@ service Task { body: "*" }; }; - rpc Create(EditRequest) returns(Response){ + rpc Create(CreateRequest) returns(Response){ option (google.api.http) = { post: "/admin/v3/task/create" body: "*" 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..7209daa --- /dev/null +++ b/services/equipment/Dockerfile @@ -0,0 +1,39 @@ +FROM golang:1.26.5-alpine AS builder + +ARG SERVICE_NAME=equipment + +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/${SERVICE_NAME}/ ./services/${SERVICE_NAME}/ + +WORKDIR /src/services/${SERVICE_NAME} + +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..4e8c408 --- /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/equipment/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.VersionCreateValidator + 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..f5524a1 --- /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/equipment/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.VersionEditValidator + 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..4fda8bc --- /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 int32 `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 int64 `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 int32 `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/express/internal/logic/editLogic.go b/services/express/internal/logic/editLogic.go index 09dc965..aeba1f7 100644 --- a/services/express/internal/logic/editLogic.go +++ b/services/express/internal/logic/editLogic.go @@ -46,6 +46,9 @@ func (l *EditLogic) Edit(in *express.CreateRequest) (*express.Response, error) { 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, diff --git a/services/express/internal/logic/infoLogic.go b/services/express/internal/logic/infoLogic.go index 9e8df5d..0f0be6a 100644 --- a/services/express/internal/logic/infoLogic.go +++ b/services/express/internal/logic/infoLogic.go @@ -42,6 +42,8 @@ func (l *InfoLogic) Info(in *express.IdRequest) (*express.Response, error) { 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/order/internal/logic/orderCreateLogic.go b/services/order/internal/logic/orderCreateLogic.go index 2652052..79514aa 100644 --- a/services/order/internal/logic/orderCreateLogic.go +++ b/services/order/internal/logic/orderCreateLogic.go @@ -94,7 +94,6 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.fail(utils.Fail) } keys := make([]string, utils.NumberZero, len(products.Items)) - var totalPrice float64 errData := make(map[int64]int64) productItems := []dao.OrderProductCreate{} @@ -109,12 +108,11 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde numItem := &product.NumberItem{Id: item.Id, Number: uint32(buyNum)} NumItems = append(NumItems, numItem) keys = append(keys, strconv.Itoa(int(item.Id))) - totalPrice += item.Price * float64(buyNum) productItems = append(productItems, dao.OrderProductCreate{ OrderSn: data.OrderSn, ProductId: int(item.Id), ProductName: item.Name, - Price: item.Price, + Price: utils.NumberZero, Number: int(buyNum), }) } @@ -124,7 +122,7 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.out(utils.Fail, "购买信息不存在") } data.ProductIds = strings.Join(keys, utils.DecollatorComma) - data.TotalPrice = totalPrice + data.TotalPrice = utils.NumberZero mobileObj := model.OrderModel{}.Init() mobileObj.Begin() diff --git a/services/order/internal/logic/webCreateLogic.go b/services/order/internal/logic/webCreateLogic.go index 0e362d8..5a63666 100644 --- a/services/order/internal/logic/webCreateLogic.go +++ b/services/order/internal/logic/webCreateLogic.go @@ -137,12 +137,19 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons numItem := &product.NumberItem{Id: item.Id, Number: uint32(buyNum)} NumItems = append(NumItems, numItem) keys = append(keys, strconv.Itoa(int(item.Id))) - totalPrice += item.Price * float64(buyNum) + price := item.Price + switch in.Type { + case dao.CartTypeSale: + price = item.SalePrice + case dao.CartTypeStore: + price = item.StorePrice + } + totalPrice += utils.RoundFloat(price * float64(buyNum)) productItems = append(productItems, dao.OrderProductCreate{ OrderSn: data.OrderSn, ProductId: int(item.Id), ProductName: item.Name, - Price: item.Price, + Price: utils.RoundFloat(item.Price), Number: int(buyNum), }) } diff --git a/services/order/internal/logic/webCreateOneLogic.go b/services/order/internal/logic/webCreateOneLogic.go index 4063edc..e40ea47 100644 --- a/services/order/internal/logic/webCreateOneLogic.go +++ b/services/order/internal/logic/webCreateOneLogic.go @@ -117,12 +117,12 @@ func (l *WebCreateOneLogic) WebCreateOne(in *order.CreateOrderOneRequest) (*orde OrderSn: data.OrderSn, ProductId: int(in.ProductId), ProductName: productInfo.Name, - Price: productInfo.Price, + Price: utils.RoundFloat(productInfo.Price), Number: int(in.Num), } data.ProductIds = strconv.FormatInt(in.ProductId, utils.NumberTen) - data.TotalPrice = float64(in.Num) * productInfo.Price + data.TotalPrice = utils.RoundFloat(float64(in.Num) * productInfo.Price) mobileObj := model.OrderModel{}.Init() mobileObj.Begin() diff --git a/services/task/.gitignore b/services/task/.gitignore new file mode 100644 index 0000000..6d3dca9 --- /dev/null +++ b/services/task/.gitignore @@ -0,0 +1,2 @@ +run.toml +etc/task.yaml \ No newline at end of file diff --git a/services/task/Dockerfile b/services/task/Dockerfile new file mode 100644 index 0000000..a01be90 --- /dev/null +++ b/services/task/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/task/ ./services/task/ + +WORKDIR /src/services/task + +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/task.yaml"] diff --git a/services/task/internal/config/config.go b/services/task/internal/config/config.go new file mode 100644 index 0000000..a1979dd --- /dev/null +++ b/services/task/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/task/internal/dao/task.go b/services/task/internal/dao/task.go new file mode 100644 index 0000000..8b8f8b6 --- /dev/null +++ b/services/task/internal/dao/task.go @@ -0,0 +1,48 @@ +package dao + +const ( + TaskTimeMonth = 1 //为月 + TaskTimeQuarter = 2 //为季度 + TaskTimeHalfYear = 3 //为半年 + TaskTimeYear = 4 //为一年 +) + +type TaskCreate struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Type int32 `gorm:"column:type;type:tinyint(4) unsigned;default:0;comment:1、为销售,2为销售人;NOT NULL" json:"type"` + Time int32 `gorm:"column:time;type:tinyint(4) unsigned;default:0;comment:时间,1为月,2为季度,3为半年,4为一年" json:"time"` + Province int64 `gorm:"column:province;type:int(11);default:0;comment:省;NOT NULL" json:"province"` + ProvinceName string `gorm:"column:province_name;type:varchar(100);comment:省名" json:"province_name"` + ProductId int64 `json:"product_id" gorm:"product_id"` // 产品ID + Task int32 `gorm:"column:task;type:int(11) unsigned;default:0;comment:任务 盒数" json:"task"` + Award float64 `gorm:"column:award;type:decimal(10,2);comment:奖励金额/盒" json:"award"` + AdminId int64 `gorm:"column:admin_id;type:int(11)" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(255)" json:"admin_name"` +} + +type TaskInfo struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Type int32 `gorm:"column:type;type:tinyint(4) unsigned;default:0;comment:1、为销售,2为销售人;NOT NULL" json:"type"` + Time int32 `gorm:"column:time;type:tinyint(4) unsigned;default:0;comment:时间,1为月,2为季度,3为半年,4为一年" json:"time"` + Province int `gorm:"column:province;type:int(11);default:0;comment:省;NOT NULL" json:"province"` + ProvinceName string `gorm:"column:province_name;type:varchar(100);comment:省名" json:"province_name"` + ProductId int64 `json:"product_id" gorm:"product_id"` // 产品ID + ProductName string `gorm:"-" json:"product_name"` + Task int32 `gorm:"column:task;type:int(11) unsigned;default:0;comment:任务 盒数" json:"task"` + Award float64 `gorm:"column:award;type:decimal(10,2);comment:奖励金额/盒" json:"award"` + AdminId int64 `gorm:"column:admin_id;type:int(11)" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(255)" json:"admin_name"` + Reason string `gorm:"column:reason;type:varchar(255);comment:禁用原因" json:"reason"` + Status int32 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"` +} + +type TaskStatus struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"` + Type int32 `gorm:"column:type;type:tinyint(4) unsigned;default:0;comment:1、为销售,2为销售人;NOT NULL" json:"type"` + Time int32 `gorm:"column:time;type:tinyint(4) unsigned;default:0;comment:时间,1为月,2为季度,3为半年,4为一年" json:"time"` + Province int64 `gorm:"column:province;type:int(11);default:0;comment:省;NOT NULL" json:"province"` + Reason string `gorm:"column:reason;type:varchar(255);comment:禁用原因" json:"reason"` + Status int32 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"` + AdminId int64 `gorm:"column:admin_id;type:int(11)" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(255)" json:"admin_name"` +} diff --git a/services/task/internal/logic/base.go b/services/task/internal/logic/base.go new file mode 100644 index 0000000..32f0479 --- /dev/null +++ b/services/task/internal/logic/base.go @@ -0,0 +1,44 @@ +package logic + +import ( + "lone-services/pkg/utils" + "lone-services/pkg/validate" + task "lone-services/rpc/task/pb" + "reflect" + + jsoniter "github.com/json-iterator/go" +) + +type BaseLogic struct { +} + +func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *task.Response { + rv := reflect.ValueOf(in) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &task.Response{ + Code: utils.ErrorParams.Code, + Msg: "request must be non‑nil proto pointer", + } + } + + resp := validate.ValidateFromProto(in, v) + if resp != utils.StringEmpty { + return &task.Response{ + Code: utils.ErrorParams.Code, + Msg: resp, + } + } + return nil +} + +func (l *BaseLogic) fail(status utils.Status) (*task.Response, error) { + return l.out(status, status.Msg) +} +func (l *BaseLogic) out(status utils.Status, msg string) (*task.Response, error) { + return &task.Response{Code: status.Code, Msg: msg}, nil +} + +func (l *BaseLogic) ok(data any) (*task.Response, error) { + buf, _ := jsoniter.Marshal(data) + return &task.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil +} diff --git a/services/task/internal/logic/createLogic.go b/services/task/internal/logic/createLogic.go new file mode 100644 index 0000000..fc20c6e --- /dev/null +++ b/services/task/internal/logic/createLogic.go @@ -0,0 +1,66 @@ +package logic + +import ( + "context" + "lone-services/pkg/utils" + "lone-services/services/task/internal/dao" + "lone-services/services/task/internal/model" + "lone-services/services/task/validator" + + "lone-services/rpc/task/pb" + "lone-services/services/task/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 *task.CreateRequest) (*task.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.TaskCreate{ + Type: in.Type, + Time: in.Time, + ProvinceName: in.ProvinceName, + ProductId: in.ProductId, + Task: in.Task, + Award: utils.RoundFloat(in.Award), + Province: in.Province, + AdminId: adminInfo.ID, + AdminName: adminInfo.Name, + } + + err := model.TaskModel{}.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.LogActionModuleTask, + } + utils.SetActionLog(adminInfo, action) + + return l.ok(data.Id) +} diff --git a/services/task/internal/logic/editLogic.go b/services/task/internal/logic/editLogic.go new file mode 100644 index 0000000..61a93b2 --- /dev/null +++ b/services/task/internal/logic/editLogic.go @@ -0,0 +1,75 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/task/internal/dao" + "lone-services/services/task/internal/model" + "lone-services/services/task/validator" + "strconv" + + "lone-services/rpc/task/pb" + "lone-services/services/task/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 *task.EditRequest) (*task.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.TaskCreate + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + err := model.TaskModel{}.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.LogActionModuleTask, + } + + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + info.Task = in.Task + info.Award = in.Award + + row, err := model.TaskModel{}.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/task/internal/logic/infoLogic.go b/services/task/internal/logic/infoLogic.go new file mode 100644 index 0000000..df32da3 --- /dev/null +++ b/services/task/internal/logic/infoLogic.go @@ -0,0 +1,69 @@ +package logic + +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" + "strconv" + + "lone-services/rpc/task/pb" + "lone-services/services/task/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 *task.IdRequest) (*task.Response, error) { + var v validate.InfoValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + + var info dao.TaskInfo + modelObj := model.TaskModel{}.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.ProductId < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) + if err != nil { + logx.Errorf("get rpc client err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + productClient := product.NewProductClient(cli.Conn()) + productInfo, err := productClient.InfoById(context.Background(), &product.InfoByIdReq{Id: info.ProductId}) + if err != nil { + logx.Errorf("get products err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + info.ProductName = productInfo.Name + + return l.ok(info) +} diff --git a/services/task/internal/logic/itemsLogic.go b/services/task/internal/logic/itemsLogic.go new file mode 100644 index 0000000..e9fa268 --- /dev/null +++ b/services/task/internal/logic/itemsLogic.go @@ -0,0 +1,72 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + product "lone-services/rpc/product/pb" + "lone-services/services/task/internal/dao" + "lone-services/services/task/internal/model" + + "lone-services/rpc/task/pb" + "lone-services/services/task/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 *task.EmtpyRequest) (*task.Response, error) { + modelObj := model.TaskModel{}.Init() + w := modelbase.Params{} + + var data []dao.TaskInfo + err := modelObj.Items(w, &data) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + + var ids []int64 + if len(data) < utils.NumberOne { + return l.ok(data) + } + for _, productItem := range data { + ids = append(ids, productItem.ProductId) + } + cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) + if err != nil { + logx.Errorf("get rpc client err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + productClient := product.NewProductClient(cli.Conn()) + productItems, err := productClient.ItemsByIds(context.Background(), &product.ItemsByIdsReq{Ids: ids}) + if err != nil { + logx.Errorf("get products err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + names := make(map[int64]string) + for _, productItem := range productItems.Items { + names[productItem.Id] = productItem.Name + } + for key, dataItem := range data { + if _, ok := names[dataItem.ProductId]; ok { + l.Logger.Error(ok) + data[key].ProductName = names[dataItem.ProductId] + } + } + + return l.ok(data) +} diff --git a/services/task/internal/logic/statusLogic.go b/services/task/internal/logic/statusLogic.go new file mode 100644 index 0000000..79556d1 --- /dev/null +++ b/services/task/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/task/internal/dao" + "lone-services/services/task/internal/model" + "strconv" + + "lone-services/rpc/task/pb" + "lone-services/services/task/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 *task.StatusRequest) (*task.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.TaskStatus + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + modelObj := model.TaskModel{}.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 = 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.LogActionModuleTask + utils.SetActionLog(adminInfo, action) + } + return l.ok(utils.NumberOne) +} diff --git a/services/task/internal/model/task.go b/services/task/internal/model/task.go new file mode 100644 index 0000000..db62f92 --- /dev/null +++ b/services/task/internal/model/task.go @@ -0,0 +1,23 @@ +package model + +import ( + "lone-services/pkg/modelbase" + "lone-services/services/task/internal/dao" +) + +type TaskModel struct { + modelbase.Base +} + +func (m TaskModel) TableName() string { + return modelbase.Prefix() + "task" +} + +func (m TaskModel) Init() TaskModel { + m.Table = m.TableName() + return m +} + +func (m TaskModel) Create(data *dao.TaskCreate) error { + return m.Base.Create(data) +} diff --git a/services/task/internal/server/taskServer.go b/services/task/internal/server/taskServer.go new file mode 100644 index 0000000..3148711 --- /dev/null +++ b/services/task/internal/server/taskServer.go @@ -0,0 +1,49 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: task.proto + +package server + +import ( + "context" + + "lone-services/rpc/task/pb" + "lone-services/services/task/internal/logic" + "lone-services/services/task/internal/svc" +) + +type TaskServer struct { + svcCtx *svc.ServiceContext + task.UnimplementedTaskServer +} + +func NewTaskServer(svcCtx *svc.ServiceContext) *TaskServer { + return &TaskServer{ + svcCtx: svcCtx, + } +} + +func (s *TaskServer) Items(ctx context.Context, in *task.EmtpyRequest) (*task.Response, error) { + l := logic.NewItemsLogic(ctx, s.svcCtx) + return l.Items(in) +} + +func (s *TaskServer) Info(ctx context.Context, in *task.IdRequest) (*task.Response, error) { + l := logic.NewInfoLogic(ctx, s.svcCtx) + return l.Info(in) +} + +func (s *TaskServer) Create(ctx context.Context, in *task.CreateRequest) (*task.Response, error) { + l := logic.NewCreateLogic(ctx, s.svcCtx) + return l.Create(in) +} + +func (s *TaskServer) Edit(ctx context.Context, in *task.EditRequest) (*task.Response, error) { + l := logic.NewEditLogic(ctx, s.svcCtx) + return l.Edit(in) +} + +func (s *TaskServer) Status(ctx context.Context, in *task.StatusRequest) (*task.Response, error) { + l := logic.NewStatusLogic(ctx, s.svcCtx) + return l.Status(in) +} diff --git a/services/task/internal/svc/servicecontext.go b/services/task/internal/svc/servicecontext.go new file mode 100644 index 0000000..b1ec499 --- /dev/null +++ b/services/task/internal/svc/servicecontext.go @@ -0,0 +1,96 @@ +package svc + +import ( + "fmt" + "lone-services/pkg/discovery" + "lone-services/pkg/utils" + "lone-services/services/task/internal/config" + "net" + "strconv" + "sync" + "time" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/zrpc" + "gorm.io/gorm" +) + +type rpcClientCacheEntry struct { + cli zrpc.Client + target string + expireAt time.Time +} + +const rpcClientCacheTTL = 30 * time.Second //缓存过期时间 + +var ( + rpcCacheLock sync.Mutex + rpcCache = make(map[string]*rpcClientCacheEntry) +) + +func GetRpcClient(serviceName string) (zrpc.Client, error) { + if serviceName == utils.StringEmpty { + err := fmt.Errorf("rpc serviceName is empty") + logx.Error(err) + return nil, err + } + + cacheKey := serviceName + + rpcCacheLock.Lock() + entry, ok := rpcCache[cacheKey] + if ok && time.Now().Before(entry.expireAt) { + rpcCacheLock.Unlock() + return entry.cli, nil + } + delete(rpcCache, cacheKey) + rpcCacheLock.Unlock() + + inst, err := discovery.Pick(serviceName) + if err != nil { + err = fmt.Errorf("discovery pick %s failed: %w", serviceName, err) + logx.Error(err) + return nil, err + } + + target := net.JoinHostPort(inst.IP, strconv.FormatUint(inst.Port, utils.NumberTen)) + + cli := zrpc.MustNewClient(zrpc.RpcClientConf{ + Target: target, + Timeout: utils.RpcTimeOut, //rpc调用超时5s + }) + + rpcCacheLock.Lock() + rpcCache[cacheKey] = &rpcClientCacheEntry{ + cli: cli, + target: target, + expireAt: time.Now().Add(rpcClientCacheTTL), + } + rpcCacheLock.Unlock() + + return cli, nil +} + +type ServiceContext struct { + Config config.Config + DB *gorm.DB + Prefix string + + ProductSvcName string //服务名 +} + +func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { + //启动仅读取配置,不建立rpc连接 多个服务就多个 + productSvc := utils.GetConfigString("services.product") + + if productSvc == utils.StringEmpty { + logx.Error("config services.product empty") + } + + return &ServiceContext{ + Config: c, + DB: db, + Prefix: utils.GetConfigString("mysql.prefix"), + ProductSvcName: productSvc, + } +} diff --git a/services/task/run.toml b/services/task/run.toml new file mode 100644 index 0000000..caa1552 --- /dev/null +++ b/services/task/run.toml @@ -0,0 +1,46 @@ +[base] + port = 8060 + name = "task-service" + listenOn = "0.0.0.0:10101" + mode = "dev" +[log] + path = "logs" + serviceName = "task-service" + mode = "file" + encoding = "plain" + level = "info" + keepDays = 7 + maxSize = 50 + maxBackups = 5 + compress = false +# 测试的地址 +[mysql] + host = '39.106.171.204' + port = 33066 + user = 'root' + password = 'MOLXRZNOU4Y4' + database = 'dms-task' + charset = 'utf8mb4' + prefix = '' + debug = true +[mysql_read] + host = '39.106.171.204' + port = 33066 + user = 'root' + password = 'MOLXRZNOU4Y4' + database = 'dms-task' + charset = 'utf8mb4' + prefix = '' + +[redis] + host = '39.106.171.204' + password = 'lLMLcuPpzSj' + port = 6379 + db = 1 +[log-redis] + host = '39.106.171.204' + password = 'lLMLcuPpzSj' + port = 6379 + db = 3 +[services] + product = "product-service" \ No newline at end of file diff --git a/services/task/task.go b/services/task/task.go new file mode 100644 index 0000000..5f81601 --- /dev/null +++ b/services/task/task.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" + task "lone-services/rpc/task/pb" + "lone-services/services/task/internal/config" + "lone-services/services/task/internal/server" + "lone-services/services/task/internal/svc" + "net" + "os" + "strconv" + + "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/task.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) { + task.RegisterTaskServer(grpcServer, server.NewTaskServer(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/task/taskclient/task.go b/services/task/taskclient/task.go new file mode 100644 index 0000000..39d059c --- /dev/null +++ b/services/task/taskclient/task.go @@ -0,0 +1,66 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.2 +// Source: task.proto + +package taskClient + +import ( + "context" + + "lone-services/rpc/task/pb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + CreateRequest = task.CreateRequest + EditRequest = task.EditRequest + EmtpyRequest = task.EmtpyRequest + IdRequest = task.IdRequest + Response = task.Response + StatusRequest = task.StatusRequest + + Task interface { + Items(ctx context.Context, in *EmtpyRequest, 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) + } + + defaultTask struct { + cli zrpc.Client + } +) + +func NewTask(cli zrpc.Client) Task { + return &defaultTask{ + cli: cli, + } +} + +func (m *defaultTask) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) { + client := task.NewTaskClient(m.cli.Conn()) + return client.Items(ctx, in, opts...) +} + +func (m *defaultTask) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) { + client := task.NewTaskClient(m.cli.Conn()) + return client.Info(ctx, in, opts...) +} + +func (m *defaultTask) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) { + client := task.NewTaskClient(m.cli.Conn()) + return client.Create(ctx, in, opts...) +} + +func (m *defaultTask) Edit(ctx context.Context, in *EditRequest, opts ...grpc.CallOption) (*Response, error) { + client := task.NewTaskClient(m.cli.Conn()) + return client.Edit(ctx, in, opts...) +} + +func (m *defaultTask) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := task.NewTaskClient(m.cli.Conn()) + return client.Status(ctx, in, opts...) +} diff --git a/services/task/tmp/runner-build b/services/task/tmp/runner-build new file mode 100644 index 0000000..51e032d Binary files /dev/null and b/services/task/tmp/runner-build differ diff --git a/services/task/validator/task.go b/services/task/validator/task.go new file mode 100644 index 0000000..abfc499 --- /dev/null +++ b/services/task/validator/task.go @@ -0,0 +1,65 @@ +package validator + +import "lone-services/pkg/validate" + +type TaskCreateValidator struct { + Type int32 `form:"type" json:"type" validate:"required"` + Time int32 `form:"time" json:"time" validate:"required"` + ProductId int64 `form:"product_id" json:"product_id" validate:"required"` + Province int64 `form:"province" json:"province" validate:"required"` + ProvinceName string `form:"province_name" json:"province_name" validate:"required"` + Task int32 `form:"task" json:"task" validate:"required"` + Award float64 `form:"award" json:"award" validate:"required"` +} + +// GetMessage 提示消息 +func (p TaskCreateValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Type.required": "类型不能为空", + "Time.required": "时间不能为空", + "ProductId.required": "产品ID不能为空", + "Province.required": "省份不能为空", + "ProvinceName.required": "省份名不能为空", + "Task.required": "任务不能为空", + "Award.required": "奖励不能为空", + } +} + +type TaskEditValidator struct { + Id int64 `form:"id" json:"id" validate:"required"` + Task int32 `form:"task" json:"task" validate:"required"` + Award float64 `form:"award" json:"award" validate:"required"` +} + +// GetMessage 提示消息 +func (p TaskEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + validate.FieldId: validate.FieldIdValue, + "Task.required": "任务不能为空", + "Award.required": "奖励不能为空", + } +} + +type TaskItemsValidator struct { + Page int32 `form:"page" json:"page"` + Size int32 `form:"size" json:"size"` +} + +// GetMessage 提示消息 +func (p TaskItemsValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{} +} + +type TaskAccountItemsValidator struct { + Name string `form:"name" json:"name"` + Page int32 `form:"page" json:"page"` + Size int32 `form:"size" json:"size"` + Type int32 `form:"type" json:"type"` + Time int32 `form:"time" json:"time"` + Month string `form:"month" json:"month"` +} + +// GetMessage 提示消息 +func (p TaskAccountItemsValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{} +}