diff --git a/deploy/apisix/lua/auth.lua b/deploy/apisix/lua/auth.lua index 2f68dbf..0ae0bea 100644 --- a/deploy/apisix/lua/auth.lua +++ b/deploy/apisix/lua/auth.lua @@ -112,7 +112,7 @@ function _M.access(conf, ctx) ngx.req.set_header("X-Sale-Province", tostring(json.province)) end if json.sale_mobile then - ngx.req.set_header("X-Sale-Mobile", tostring(json.mobile)) + ngx.req.set_header("X-Sale-Mobile", tostring(json.sale_mobile)) end if json.sale_name then ngx.req.set_header("X-Sale-Name", json.sale_name) @@ -123,6 +123,12 @@ function _M.access(conf, ctx) if json.group_id then ngx.req.set_header("X-Group-Id", tostring(json.group_id)) end + if json.group_name then + ngx.req.set_header("X-Group-Name", tostring(json.group_name)) + end + if json.type then + ngx.req.set_header("X-User-Type", tostring(json.type)) + end end ngx.req.set_header("X-Refresh", refresh or "") diff --git a/pkg/utils/loginInfo.go b/pkg/utils/loginInfo.go index 6874d9a..25a4919 100644 --- a/pkg/utils/loginInfo.go +++ b/pkg/utils/loginInfo.go @@ -25,6 +25,8 @@ type UserInfo struct { SaleMobile string // 销售手机 SaleProvince int64 // 销售省份 GroupId int64 // 分组ID + GroupName string // 分组名称 + Type uint8 // 用户类型 Valid bool } @@ -44,6 +46,8 @@ func GetUserFromCtx(ctx context.Context) UserInfo { saleName := md.Get("x-sale-name") saleId := md.Get("x-sale-id") groupId := md.Get("x-group-id") + groupName := md.Get("x-group-name") + Type := md.Get("x-user-type") province := md.Get("x-sale-province") mobile := md.Get("x-sale-mobile") @@ -60,6 +64,15 @@ func GetUserFromCtx(ctx context.Context) UserInfo { if len(storeName) > NumberZero { userInfo.StoreName = storeName[NumberZero] } + + if len(groupName) > NumberZero { + userInfo.GroupName = groupName[NumberZero] + } + if len(Type) > NumberZero { + TypeInt, _ := strconv.ParseInt(Type[NumberZero], NumberTen, NumberSixtyFourth) + userInfo.Type = uint8(TypeInt) + } + if len(storeId) > NumberZero { userInfo.StoreId, _ = strconv.ParseInt(storeId[NumberZero], NumberTen, NumberSixtyFourth) } diff --git a/rpc/admin/admin.pb b/rpc/admin/admin.pb index 8f3f07c..64f1cc8 100644 Binary files a/rpc/admin/admin.pb and b/rpc/admin/admin.pb differ diff --git a/rpc/admin/admin.proto b/rpc/admin/admin.proto index b78f025..87e7a72 100644 --- a/rpc/admin/admin.proto +++ b/rpc/admin/admin.proto @@ -125,6 +125,20 @@ message RoleRuleRequest { string rule = 2; } +message AdminNamesByIdsRequest { + repeated int64 ids = 1; +} + +message NamesItem { + int64 id = 1; + string name = 2; +} + +message AdminNamesByIdsResponse { + repeated NamesItem items = 1; +} + + message RoleNameRequest { string name = 1; int64 service_id = 2; @@ -332,4 +346,6 @@ service Admin { body: "*" }; }; + //传入IDS []int64,返回[]NamesItem{id int64,name string} + rpc AdminNamesByIds(AdminNamesByIdsRequest) returns(AdminNamesByIdsResponse); } \ No newline at end of file diff --git a/rpc/admin/pb/admin.pb.go b/rpc/admin/pb/admin.pb.go index 666f77a..807553e 100644 --- a/rpc/admin/pb/admin.pb.go +++ b/rpc/admin/pb/admin.pb.go @@ -1238,6 +1238,146 @@ func (x *RoleRuleRequest) GetRule() string { return "" } +type AdminNamesByIdsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Ids []int64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AdminNamesByIdsRequest) Reset() { + *x = AdminNamesByIdsRequest{} + mi := &file_admin_admin_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AdminNamesByIdsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AdminNamesByIdsRequest) ProtoMessage() {} + +func (x *AdminNamesByIdsRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_admin_proto_msgTypes[20] + 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 AdminNamesByIdsRequest.ProtoReflect.Descriptor instead. +func (*AdminNamesByIdsRequest) Descriptor() ([]byte, []int) { + return file_admin_admin_proto_rawDescGZIP(), []int{20} +} + +func (x *AdminNamesByIdsRequest) GetIds() []int64 { + if x != nil { + return x.Ids + } + return nil +} + +type NamesItem struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NamesItem) Reset() { + *x = NamesItem{} + mi := &file_admin_admin_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NamesItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NamesItem) ProtoMessage() {} + +func (x *NamesItem) ProtoReflect() protoreflect.Message { + mi := &file_admin_admin_proto_msgTypes[21] + 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 NamesItem.ProtoReflect.Descriptor instead. +func (*NamesItem) Descriptor() ([]byte, []int) { + return file_admin_admin_proto_rawDescGZIP(), []int{21} +} + +func (x *NamesItem) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *NamesItem) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type AdminNamesByIdsResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Items []*NamesItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AdminNamesByIdsResponse) Reset() { + *x = AdminNamesByIdsResponse{} + mi := &file_admin_admin_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AdminNamesByIdsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AdminNamesByIdsResponse) ProtoMessage() {} + +func (x *AdminNamesByIdsResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_admin_proto_msgTypes[22] + 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 AdminNamesByIdsResponse.ProtoReflect.Descriptor instead. +func (*AdminNamesByIdsResponse) Descriptor() ([]byte, []int) { + return file_admin_admin_proto_rawDescGZIP(), []int{22} +} + +func (x *AdminNamesByIdsResponse) GetItems() []*NamesItem { + if x != nil { + return x.Items + } + return nil +} + type RoleNameRequest struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -1248,7 +1388,7 @@ type RoleNameRequest struct { func (x *RoleNameRequest) Reset() { *x = RoleNameRequest{} - mi := &file_admin_admin_proto_msgTypes[20] + mi := &file_admin_admin_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1260,7 +1400,7 @@ func (x *RoleNameRequest) String() string { func (*RoleNameRequest) ProtoMessage() {} func (x *RoleNameRequest) ProtoReflect() protoreflect.Message { - mi := &file_admin_admin_proto_msgTypes[20] + mi := &file_admin_admin_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1273,7 +1413,7 @@ func (x *RoleNameRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RoleNameRequest.ProtoReflect.Descriptor instead. func (*RoleNameRequest) Descriptor() ([]byte, []int) { - return file_admin_admin_proto_rawDescGZIP(), []int{20} + return file_admin_admin_proto_rawDescGZIP(), []int{23} } func (x *RoleNameRequest) GetName() string { @@ -1302,7 +1442,7 @@ type RoleEditRequest struct { func (x *RoleEditRequest) Reset() { *x = RoleEditRequest{} - mi := &file_admin_admin_proto_msgTypes[21] + mi := &file_admin_admin_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1314,7 +1454,7 @@ func (x *RoleEditRequest) String() string { func (*RoleEditRequest) ProtoMessage() {} func (x *RoleEditRequest) ProtoReflect() protoreflect.Message { - mi := &file_admin_admin_proto_msgTypes[21] + mi := &file_admin_admin_proto_msgTypes[24] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1327,7 +1467,7 @@ func (x *RoleEditRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RoleEditRequest.ProtoReflect.Descriptor instead. func (*RoleEditRequest) Descriptor() ([]byte, []int) { - return file_admin_admin_proto_rawDescGZIP(), []int{21} + return file_admin_admin_proto_rawDescGZIP(), []int{24} } func (x *RoleEditRequest) GetId() int64 { @@ -1371,7 +1511,7 @@ type RoleItemsRequest struct { func (x *RoleItemsRequest) Reset() { *x = RoleItemsRequest{} - mi := &file_admin_admin_proto_msgTypes[22] + mi := &file_admin_admin_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1383,7 +1523,7 @@ func (x *RoleItemsRequest) String() string { func (*RoleItemsRequest) ProtoMessage() {} func (x *RoleItemsRequest) ProtoReflect() protoreflect.Message { - mi := &file_admin_admin_proto_msgTypes[22] + mi := &file_admin_admin_proto_msgTypes[25] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1396,7 +1536,7 @@ func (x *RoleItemsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RoleItemsRequest.ProtoReflect.Descriptor instead. func (*RoleItemsRequest) Descriptor() ([]byte, []int) { - return file_admin_admin_proto_rawDescGZIP(), []int{22} + return file_admin_admin_proto_rawDescGZIP(), []int{25} } func (x *RoleItemsRequest) GetPage() int32 { @@ -1525,7 +1665,14 @@ const file_admin_admin_proto_rawDesc = "" + "\x11data_tree_oneself\x18\x13 \x01(\tR\x0fdataTreeOneself\"5\n" + "\x0fRoleRuleRequest\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + - "\x04rule\x18\x02 \x01(\tR\x04rule\"D\n" + + "\x04rule\x18\x02 \x01(\tR\x04rule\"*\n" + + "\x16AdminNamesByIdsRequest\x12\x10\n" + + "\x03ids\x18\x01 \x03(\x03R\x03ids\"/\n" + + "\tNamesItem\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\"A\n" + + "\x17AdminNamesByIdsResponse\x12&\n" + + "\x05items\x18\x01 \x03(\v2\x10.admin.NamesItemR\x05items\"D\n" + "\x0fRoleNameRequest\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x1d\n" + "\n" + @@ -1542,7 +1689,7 @@ const file_admin_admin_proto_rawDesc = "" + "\n" + "service_id\x18\x03 \x01(\x03R\tserviceId\x12\x12\n" + "\x04name\x18\x04 \x01(\tR\x04name\x12\x16\n" + - "\x06status\x18\x05 \x01(\x05R\x06status2\x82\x16\n" + + "\x06status\x18\x05 \x01(\x05R\x06status2\xd4\x16\n" + "\x05Admin\x12V\n" + "\tAdminEdit\x12\x17.admin.AdminEditRequest\x1a\x0f.admin.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\"\x14/admin/v3/admin/edit\x12W\n" + "\vAdminStatus\x12\x14.admin.StatusRequest\x1a\x0f.admin.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/admin/status\x12X\n" + @@ -1578,7 +1725,8 @@ const file_admin_admin_proto_rawDesc = "" + "\tRoleItems\x12\x17.admin.RoleItemsRequest\x1a\x0f.admin.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/role/items\x12U\n" + "\n" + "RoleStatus\x12\x14.admin.StatusRequest\x1a\x0f.admin.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\"\x15/admin/v3/role/status\x12S\n" + - "\bRoleRule\x12\x16.admin.RoleRuleRequest\x1a\x0f.admin.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/admin/v3/role/ruleB\x19Z\x17lone-services/rpc/adminb\x06proto3" + "\bRoleRule\x12\x16.admin.RoleRuleRequest\x1a\x0f.admin.Response\"\x1e\x82\xd3\xe4\x93\x02\x18:\x01*\"\x13/admin/v3/role/rule\x12P\n" + + "\x0fAdminNamesByIds\x12\x1d.admin.AdminNamesByIdsRequest\x1a\x1e.admin.AdminNamesByIdsResponseB\x19Z\x17lone-services/rpc/adminb\x06proto3" var ( file_admin_admin_proto_rawDescOnce sync.Once @@ -1592,100 +1740,106 @@ func file_admin_admin_proto_rawDescGZIP() []byte { return file_admin_admin_proto_rawDescData } -var file_admin_admin_proto_msgTypes = make([]protoimpl.MessageInfo, 23) +var file_admin_admin_proto_msgTypes = make([]protoimpl.MessageInfo, 26) var file_admin_admin_proto_goTypes = []any{ - (*AdminEditRequest)(nil), // 0: admin.AdminEditRequest - (*StatusRequest)(nil), // 1: admin.StatusRequest - (*Response)(nil), // 2: admin.Response - (*PasswordRequest)(nil), // 3: admin.PasswordRequest - (*OwnPasswordRequest)(nil), // 4: admin.OwnPasswordRequest - (*AdminInfoRequest)(nil), // 5: admin.AdminInfoRequest - (*AdminItemsRequest)(nil), // 6: admin.AdminItemsRequest - (*LoginRequest)(nil), // 7: admin.LoginRequest - (*AdminEmptyRequest)(nil), // 8: admin.AdminEmptyRequest - (*InfoRequest)(nil), // 9: admin.InfoRequest - (*LoginKickedOutRequest)(nil), // 10: admin.LoginKickedOutRequest - (*ServiceEditRequest)(nil), // 11: admin.ServiceEditRequest - (*ServiceItemsRequest)(nil), // 12: admin.ServiceItemsRequest - (*ServiceNameRequest)(nil), // 13: admin.ServiceNameRequest - (*AuthoritySortRequest)(nil), // 14: admin.AuthoritySortRequest - (*AuthorityNameRequest)(nil), // 15: admin.AuthorityNameRequest - (*AuthorityItemsRequest)(nil), // 16: admin.AuthorityItemsRequest - (*RoutesRequest)(nil), // 17: admin.RoutesRequest - (*AuthorityEditRequest)(nil), // 18: admin.AuthorityEditRequest - (*RoleRuleRequest)(nil), // 19: admin.RoleRuleRequest - (*RoleNameRequest)(nil), // 20: admin.RoleNameRequest - (*RoleEditRequest)(nil), // 21: admin.RoleEditRequest - (*RoleItemsRequest)(nil), // 22: admin.RoleItemsRequest + (*AdminEditRequest)(nil), // 0: admin.AdminEditRequest + (*StatusRequest)(nil), // 1: admin.StatusRequest + (*Response)(nil), // 2: admin.Response + (*PasswordRequest)(nil), // 3: admin.PasswordRequest + (*OwnPasswordRequest)(nil), // 4: admin.OwnPasswordRequest + (*AdminInfoRequest)(nil), // 5: admin.AdminInfoRequest + (*AdminItemsRequest)(nil), // 6: admin.AdminItemsRequest + (*LoginRequest)(nil), // 7: admin.LoginRequest + (*AdminEmptyRequest)(nil), // 8: admin.AdminEmptyRequest + (*InfoRequest)(nil), // 9: admin.InfoRequest + (*LoginKickedOutRequest)(nil), // 10: admin.LoginKickedOutRequest + (*ServiceEditRequest)(nil), // 11: admin.ServiceEditRequest + (*ServiceItemsRequest)(nil), // 12: admin.ServiceItemsRequest + (*ServiceNameRequest)(nil), // 13: admin.ServiceNameRequest + (*AuthoritySortRequest)(nil), // 14: admin.AuthoritySortRequest + (*AuthorityNameRequest)(nil), // 15: admin.AuthorityNameRequest + (*AuthorityItemsRequest)(nil), // 16: admin.AuthorityItemsRequest + (*RoutesRequest)(nil), // 17: admin.RoutesRequest + (*AuthorityEditRequest)(nil), // 18: admin.AuthorityEditRequest + (*RoleRuleRequest)(nil), // 19: admin.RoleRuleRequest + (*AdminNamesByIdsRequest)(nil), // 20: admin.AdminNamesByIdsRequest + (*NamesItem)(nil), // 21: admin.NamesItem + (*AdminNamesByIdsResponse)(nil), // 22: admin.AdminNamesByIdsResponse + (*RoleNameRequest)(nil), // 23: admin.RoleNameRequest + (*RoleEditRequest)(nil), // 24: admin.RoleEditRequest + (*RoleItemsRequest)(nil), // 25: admin.RoleItemsRequest } var file_admin_admin_proto_depIdxs = []int32{ - 0, // 0: admin.Admin.AdminEdit:input_type -> admin.AdminEditRequest - 1, // 1: admin.Admin.AdminStatus:input_type -> admin.StatusRequest - 3, // 2: admin.Admin.Password:input_type -> admin.PasswordRequest - 4, // 3: admin.Admin.OwnPassword:input_type -> admin.OwnPasswordRequest - 5, // 4: admin.Admin.AdminInfo:input_type -> admin.AdminInfoRequest - 6, // 5: admin.Admin.AdminItems:input_type -> admin.AdminItemsRequest - 8, // 6: admin.Admin.AdminNames:input_type -> admin.AdminEmptyRequest - 8, // 7: admin.Admin.LoginRefresh:input_type -> admin.AdminEmptyRequest - 7, // 8: admin.Admin.Login:input_type -> admin.LoginRequest - 8, // 9: admin.Admin.LoginInfo:input_type -> admin.AdminEmptyRequest - 8, // 10: admin.Admin.LoginItems:input_type -> admin.AdminEmptyRequest - 10, // 11: admin.Admin.LoginKickedOut:input_type -> admin.LoginKickedOutRequest - 8, // 12: admin.Admin.LogOut:input_type -> admin.AdminEmptyRequest - 17, // 13: admin.Admin.LoginRoutes:input_type -> admin.RoutesRequest - 9, // 14: admin.Admin.ServiceInfo:input_type -> admin.InfoRequest - 11, // 15: admin.Admin.ServiceEdit:input_type -> admin.ServiceEditRequest - 12, // 16: admin.Admin.ServiceItems:input_type -> admin.ServiceItemsRequest - 1, // 17: admin.Admin.ServiceStatus:input_type -> admin.StatusRequest - 13, // 18: admin.Admin.ServiceNames:input_type -> admin.ServiceNameRequest - 9, // 19: admin.Admin.AuthorityInfo:input_type -> admin.InfoRequest - 18, // 20: admin.Admin.AuthorityEdit:input_type -> admin.AuthorityEditRequest - 16, // 21: admin.Admin.AuthorityItems:input_type -> admin.AuthorityItemsRequest - 1, // 22: admin.Admin.AuthorityStatus:input_type -> admin.StatusRequest - 15, // 23: admin.Admin.AuthorityNames:input_type -> admin.AuthorityNameRequest - 14, // 24: admin.Admin.AuthoritySort:input_type -> admin.AuthoritySortRequest - 20, // 25: admin.Admin.RoleNames:input_type -> admin.RoleNameRequest - 9, // 26: admin.Admin.RoleInfo:input_type -> admin.InfoRequest - 21, // 27: admin.Admin.RoleEdit:input_type -> admin.RoleEditRequest - 22, // 28: admin.Admin.RoleItems:input_type -> admin.RoleItemsRequest - 1, // 29: admin.Admin.RoleStatus:input_type -> admin.StatusRequest - 19, // 30: admin.Admin.RoleRule:input_type -> admin.RoleRuleRequest - 2, // 31: admin.Admin.AdminEdit:output_type -> admin.Response - 2, // 32: admin.Admin.AdminStatus:output_type -> admin.Response - 2, // 33: admin.Admin.Password:output_type -> admin.Response - 2, // 34: admin.Admin.OwnPassword:output_type -> admin.Response - 2, // 35: admin.Admin.AdminInfo:output_type -> admin.Response - 2, // 36: admin.Admin.AdminItems:output_type -> admin.Response - 2, // 37: admin.Admin.AdminNames:output_type -> admin.Response - 2, // 38: admin.Admin.LoginRefresh:output_type -> admin.Response - 2, // 39: admin.Admin.Login:output_type -> admin.Response - 2, // 40: admin.Admin.LoginInfo:output_type -> admin.Response - 2, // 41: admin.Admin.LoginItems:output_type -> admin.Response - 2, // 42: admin.Admin.LoginKickedOut:output_type -> admin.Response - 2, // 43: admin.Admin.LogOut:output_type -> admin.Response - 2, // 44: admin.Admin.LoginRoutes:output_type -> admin.Response - 2, // 45: admin.Admin.ServiceInfo:output_type -> admin.Response - 2, // 46: admin.Admin.ServiceEdit:output_type -> admin.Response - 2, // 47: admin.Admin.ServiceItems:output_type -> admin.Response - 2, // 48: admin.Admin.ServiceStatus:output_type -> admin.Response - 2, // 49: admin.Admin.ServiceNames:output_type -> admin.Response - 2, // 50: admin.Admin.AuthorityInfo:output_type -> admin.Response - 2, // 51: admin.Admin.AuthorityEdit:output_type -> admin.Response - 2, // 52: admin.Admin.AuthorityItems:output_type -> admin.Response - 2, // 53: admin.Admin.AuthorityStatus:output_type -> admin.Response - 2, // 54: admin.Admin.AuthorityNames:output_type -> admin.Response - 2, // 55: admin.Admin.AuthoritySort:output_type -> admin.Response - 2, // 56: admin.Admin.RoleNames:output_type -> admin.Response - 2, // 57: admin.Admin.RoleInfo:output_type -> admin.Response - 2, // 58: admin.Admin.RoleEdit:output_type -> admin.Response - 2, // 59: admin.Admin.RoleItems:output_type -> admin.Response - 2, // 60: admin.Admin.RoleStatus:output_type -> admin.Response - 2, // 61: admin.Admin.RoleRule:output_type -> admin.Response - 31, // [31:62] is the sub-list for method output_type - 0, // [0:31] 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 + 21, // 0: admin.AdminNamesByIdsResponse.items:type_name -> admin.NamesItem + 0, // 1: admin.Admin.AdminEdit:input_type -> admin.AdminEditRequest + 1, // 2: admin.Admin.AdminStatus:input_type -> admin.StatusRequest + 3, // 3: admin.Admin.Password:input_type -> admin.PasswordRequest + 4, // 4: admin.Admin.OwnPassword:input_type -> admin.OwnPasswordRequest + 5, // 5: admin.Admin.AdminInfo:input_type -> admin.AdminInfoRequest + 6, // 6: admin.Admin.AdminItems:input_type -> admin.AdminItemsRequest + 8, // 7: admin.Admin.AdminNames:input_type -> admin.AdminEmptyRequest + 8, // 8: admin.Admin.LoginRefresh:input_type -> admin.AdminEmptyRequest + 7, // 9: admin.Admin.Login:input_type -> admin.LoginRequest + 8, // 10: admin.Admin.LoginInfo:input_type -> admin.AdminEmptyRequest + 8, // 11: admin.Admin.LoginItems:input_type -> admin.AdminEmptyRequest + 10, // 12: admin.Admin.LoginKickedOut:input_type -> admin.LoginKickedOutRequest + 8, // 13: admin.Admin.LogOut:input_type -> admin.AdminEmptyRequest + 17, // 14: admin.Admin.LoginRoutes:input_type -> admin.RoutesRequest + 9, // 15: admin.Admin.ServiceInfo:input_type -> admin.InfoRequest + 11, // 16: admin.Admin.ServiceEdit:input_type -> admin.ServiceEditRequest + 12, // 17: admin.Admin.ServiceItems:input_type -> admin.ServiceItemsRequest + 1, // 18: admin.Admin.ServiceStatus:input_type -> admin.StatusRequest + 13, // 19: admin.Admin.ServiceNames:input_type -> admin.ServiceNameRequest + 9, // 20: admin.Admin.AuthorityInfo:input_type -> admin.InfoRequest + 18, // 21: admin.Admin.AuthorityEdit:input_type -> admin.AuthorityEditRequest + 16, // 22: admin.Admin.AuthorityItems:input_type -> admin.AuthorityItemsRequest + 1, // 23: admin.Admin.AuthorityStatus:input_type -> admin.StatusRequest + 15, // 24: admin.Admin.AuthorityNames:input_type -> admin.AuthorityNameRequest + 14, // 25: admin.Admin.AuthoritySort:input_type -> admin.AuthoritySortRequest + 23, // 26: admin.Admin.RoleNames:input_type -> admin.RoleNameRequest + 9, // 27: admin.Admin.RoleInfo:input_type -> admin.InfoRequest + 24, // 28: admin.Admin.RoleEdit:input_type -> admin.RoleEditRequest + 25, // 29: admin.Admin.RoleItems:input_type -> admin.RoleItemsRequest + 1, // 30: admin.Admin.RoleStatus:input_type -> admin.StatusRequest + 19, // 31: admin.Admin.RoleRule:input_type -> admin.RoleRuleRequest + 20, // 32: admin.Admin.AdminNamesByIds:input_type -> admin.AdminNamesByIdsRequest + 2, // 33: admin.Admin.AdminEdit:output_type -> admin.Response + 2, // 34: admin.Admin.AdminStatus:output_type -> admin.Response + 2, // 35: admin.Admin.Password:output_type -> admin.Response + 2, // 36: admin.Admin.OwnPassword:output_type -> admin.Response + 2, // 37: admin.Admin.AdminInfo:output_type -> admin.Response + 2, // 38: admin.Admin.AdminItems:output_type -> admin.Response + 2, // 39: admin.Admin.AdminNames:output_type -> admin.Response + 2, // 40: admin.Admin.LoginRefresh:output_type -> admin.Response + 2, // 41: admin.Admin.Login:output_type -> admin.Response + 2, // 42: admin.Admin.LoginInfo:output_type -> admin.Response + 2, // 43: admin.Admin.LoginItems:output_type -> admin.Response + 2, // 44: admin.Admin.LoginKickedOut:output_type -> admin.Response + 2, // 45: admin.Admin.LogOut:output_type -> admin.Response + 2, // 46: admin.Admin.LoginRoutes:output_type -> admin.Response + 2, // 47: admin.Admin.ServiceInfo:output_type -> admin.Response + 2, // 48: admin.Admin.ServiceEdit:output_type -> admin.Response + 2, // 49: admin.Admin.ServiceItems:output_type -> admin.Response + 2, // 50: admin.Admin.ServiceStatus:output_type -> admin.Response + 2, // 51: admin.Admin.ServiceNames:output_type -> admin.Response + 2, // 52: admin.Admin.AuthorityInfo:output_type -> admin.Response + 2, // 53: admin.Admin.AuthorityEdit:output_type -> admin.Response + 2, // 54: admin.Admin.AuthorityItems:output_type -> admin.Response + 2, // 55: admin.Admin.AuthorityStatus:output_type -> admin.Response + 2, // 56: admin.Admin.AuthorityNames:output_type -> admin.Response + 2, // 57: admin.Admin.AuthoritySort:output_type -> admin.Response + 2, // 58: admin.Admin.RoleNames:output_type -> admin.Response + 2, // 59: admin.Admin.RoleInfo:output_type -> admin.Response + 2, // 60: admin.Admin.RoleEdit:output_type -> admin.Response + 2, // 61: admin.Admin.RoleItems:output_type -> admin.Response + 2, // 62: admin.Admin.RoleStatus:output_type -> admin.Response + 2, // 63: admin.Admin.RoleRule:output_type -> admin.Response + 22, // 64: admin.Admin.AdminNamesByIds:output_type -> admin.AdminNamesByIdsResponse + 33, // [33:65] is the sub-list for method output_type + 1, // [1:33] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name } func init() { file_admin_admin_proto_init() } @@ -1699,7 +1853,7 @@ func file_admin_admin_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_admin_admin_proto_rawDesc), len(file_admin_admin_proto_rawDesc)), NumEnums: 0, - NumMessages: 23, + NumMessages: 26, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/admin/pb/admin_grpc.pb.go b/rpc/admin/pb/admin_grpc.pb.go index bdc46b8..4cc6da5 100644 --- a/rpc/admin/pb/admin_grpc.pb.go +++ b/rpc/admin/pb/admin_grpc.pb.go @@ -50,6 +50,7 @@ const ( Admin_RoleItems_FullMethodName = "/admin.Admin/RoleItems" Admin_RoleStatus_FullMethodName = "/admin.Admin/RoleStatus" Admin_RoleRule_FullMethodName = "/admin.Admin/RoleRule" + Admin_AdminNamesByIds_FullMethodName = "/admin.Admin/AdminNamesByIds" ) // AdminClient is the client API for Admin service. @@ -87,6 +88,8 @@ type AdminClient interface { RoleItems(ctx context.Context, in *RoleItemsRequest, opts ...grpc.CallOption) (*Response, error) RoleStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) RoleRule(ctx context.Context, in *RoleRuleRequest, opts ...grpc.CallOption) (*Response, error) + // 传入IDS []int64,返回[]NamesItem{id int64,name string} + AdminNamesByIds(ctx context.Context, in *AdminNamesByIdsRequest, opts ...grpc.CallOption) (*AdminNamesByIdsResponse, error) } type adminClient struct { @@ -407,6 +410,16 @@ func (c *adminClient) RoleRule(ctx context.Context, in *RoleRuleRequest, opts .. return out, nil } +func (c *adminClient) AdminNamesByIds(ctx context.Context, in *AdminNamesByIdsRequest, opts ...grpc.CallOption) (*AdminNamesByIdsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(AdminNamesByIdsResponse) + err := c.cc.Invoke(ctx, Admin_AdminNamesByIds_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // AdminServer is the server API for Admin service. // All implementations must embed UnimplementedAdminServer // for forward compatibility. @@ -442,6 +455,8 @@ type AdminServer interface { RoleItems(context.Context, *RoleItemsRequest) (*Response, error) RoleStatus(context.Context, *StatusRequest) (*Response, error) RoleRule(context.Context, *RoleRuleRequest) (*Response, error) + // 传入IDS []int64,返回[]NamesItem{id int64,name string} + AdminNamesByIds(context.Context, *AdminNamesByIdsRequest) (*AdminNamesByIdsResponse, error) mustEmbedUnimplementedAdminServer() } @@ -545,6 +560,9 @@ func (UnimplementedAdminServer) RoleStatus(context.Context, *StatusRequest) (*Re func (UnimplementedAdminServer) RoleRule(context.Context, *RoleRuleRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method RoleRule not implemented") } +func (UnimplementedAdminServer) AdminNamesByIds(context.Context, *AdminNamesByIdsRequest) (*AdminNamesByIdsResponse, error) { + return nil, status.Error(codes.Unimplemented, "method AdminNamesByIds not implemented") +} func (UnimplementedAdminServer) mustEmbedUnimplementedAdminServer() {} func (UnimplementedAdminServer) testEmbeddedByValue() {} @@ -1124,6 +1142,24 @@ func _Admin_RoleRule_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +func _Admin_AdminNamesByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AdminNamesByIdsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).AdminNamesByIds(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_AdminNamesByIds_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).AdminNamesByIds(ctx, req.(*AdminNamesByIdsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Admin_ServiceDesc is the grpc.ServiceDesc for Admin service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -1255,6 +1291,10 @@ var Admin_ServiceDesc = grpc.ServiceDesc{ MethodName: "RoleRule", Handler: _Admin_RoleRule_Handler, }, + { + MethodName: "AdminNamesByIds", + Handler: _Admin_AdminNamesByIds_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "admin/admin.proto", diff --git a/services/admin/adminClient/admin.go b/services/admin/adminClient/admin.go index 722d743..1f18494 100644 --- a/services/admin/adminClient/admin.go +++ b/services/admin/adminClient/admin.go @@ -14,29 +14,32 @@ import ( ) type ( - AdminEditRequest = admin.AdminEditRequest - AdminEmptyRequest = admin.AdminEmptyRequest - AdminInfoRequest = admin.AdminInfoRequest - AdminItemsRequest = admin.AdminItemsRequest - AuthorityEditRequest = admin.AuthorityEditRequest - AuthorityItemsRequest = admin.AuthorityItemsRequest - AuthorityNameRequest = admin.AuthorityNameRequest - AuthoritySortRequest = admin.AuthoritySortRequest - InfoRequest = admin.InfoRequest - LoginKickedOutRequest = admin.LoginKickedOutRequest - LoginRequest = admin.LoginRequest - OwnPasswordRequest = admin.OwnPasswordRequest - PasswordRequest = admin.PasswordRequest - Response = admin.Response - RoleEditRequest = admin.RoleEditRequest - RoleItemsRequest = admin.RoleItemsRequest - RoleNameRequest = admin.RoleNameRequest - RoleRuleRequest = admin.RoleRuleRequest - RoutesRequest = admin.RoutesRequest - ServiceEditRequest = admin.ServiceEditRequest - ServiceItemsRequest = admin.ServiceItemsRequest - ServiceNameRequest = admin.ServiceNameRequest - StatusRequest = admin.StatusRequest + AdminEditRequest = admin.AdminEditRequest + AdminEmptyRequest = admin.AdminEmptyRequest + AdminInfoRequest = admin.AdminInfoRequest + AdminItemsRequest = admin.AdminItemsRequest + AdminNamesByIdsRequest = admin.AdminNamesByIdsRequest + AdminNamesByIdsResponse = admin.AdminNamesByIdsResponse + AuthorityEditRequest = admin.AuthorityEditRequest + AuthorityItemsRequest = admin.AuthorityItemsRequest + AuthorityNameRequest = admin.AuthorityNameRequest + AuthoritySortRequest = admin.AuthoritySortRequest + InfoRequest = admin.InfoRequest + LoginKickedOutRequest = admin.LoginKickedOutRequest + LoginRequest = admin.LoginRequest + NamesItem = admin.NamesItem + OwnPasswordRequest = admin.OwnPasswordRequest + PasswordRequest = admin.PasswordRequest + Response = admin.Response + RoleEditRequest = admin.RoleEditRequest + RoleItemsRequest = admin.RoleItemsRequest + RoleNameRequest = admin.RoleNameRequest + RoleRuleRequest = admin.RoleRuleRequest + RoutesRequest = admin.RoutesRequest + ServiceEditRequest = admin.ServiceEditRequest + ServiceItemsRequest = admin.ServiceItemsRequest + ServiceNameRequest = admin.ServiceNameRequest + StatusRequest = admin.StatusRequest Admin interface { AdminEdit(ctx context.Context, in *AdminEditRequest, opts ...grpc.CallOption) (*Response, error) @@ -70,6 +73,8 @@ type ( RoleItems(ctx context.Context, in *RoleItemsRequest, opts ...grpc.CallOption) (*Response, error) RoleStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) RoleRule(ctx context.Context, in *RoleRuleRequest, opts ...grpc.CallOption) (*Response, error) + // 传入IDS []int64,返回[]NamesItem{id int64,name string} + AdminNamesByIds(ctx context.Context, in *AdminNamesByIdsRequest, opts ...grpc.CallOption) (*AdminNamesByIdsResponse, error) } defaultAdmin struct { @@ -237,3 +242,9 @@ func (m *defaultAdmin) RoleRule(ctx context.Context, in *RoleRuleRequest, opts . client := admin.NewAdminClient(m.cli.Conn()) return client.RoleRule(ctx, in, opts...) } + +// 传入IDS []int64,返回[]NamesItem{id int64,name string} +func (m *defaultAdmin) AdminNamesByIds(ctx context.Context, in *AdminNamesByIdsRequest, opts ...grpc.CallOption) (*AdminNamesByIdsResponse, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.AdminNamesByIds(ctx, in, opts...) +} diff --git a/services/admin/internal/dao/admin.go b/services/admin/internal/dao/admin.go index 0eb0093..4205c56 100644 --- a/services/admin/internal/dao/admin.go +++ b/services/admin/internal/dao/admin.go @@ -2,6 +2,11 @@ package dao import "lone-services/pkg/utils" +const ( + AdminTypeAdmin = 2 + AdminTypeSale = 1 +) + // Admin 公司内部人员表 type Admin struct { Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"` @@ -53,6 +58,9 @@ type AdminInfo struct { Type uint8 `json:"type" gorm:"type"` // 1:销售,2:管理员 SaleId int64 `json:"sale_id" gorm:"sale_id"` // 销售ID FailNumber int `gorm:"column:fail_number;type:tinyint(2);default:0;comment:连续登录失败次数" json:"fail_number"` + SaleName string `json:"sale_name" gorm:"-"` + GroupId int64 `json:"group_id" gorm:"-"` + GroupName string `json:"group_name" gorm:"-"` } type AdminInfoRet struct { diff --git a/services/admin/internal/dao/login.go b/services/admin/internal/dao/login.go index 04c0e41..29751e2 100644 --- a/services/admin/internal/dao/login.go +++ b/services/admin/internal/dao/login.go @@ -3,15 +3,21 @@ package dao import "lone-services/pkg/utils" type JwtInfo struct { - Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` - Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` - Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"` - Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"` - Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"` - LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;comment:最后一次登录时间" json:"last_time"` - Time int `json:"time"` - Roles []JwtInfoServices `json:"roles"` - Refresh string `json:"refresh"` + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` + Name string `gorm:"column:name;type:varchar(30);comment:真实姓名;NOT NULL" json:"name"` + Phone string `gorm:"column:phone;type:char(12);comment:电话" json:"phone"` + Email string `gorm:"column:email;type:varchar(255);comment:邮箱" json:"email"` + LastTime utils.CustomTime `gorm:"column:last_time;type:datetime;comment:最后一次登录时间" json:"last_time"` + Time int `json:"time"` + Roles []JwtInfoServices `json:"roles"` + Refresh string `json:"refresh"` + Type uint8 `json:"type" gorm:"type"` // 销售ID + SaleId int64 `json:"sale_id" gorm:"sale_id"` // 销售ID + SaleMobile string `json:"sale_mobile" gorm:"-"` + SaleName string `json:"sale_name" gorm:"-"` + GroupId int64 `json:"group_id" gorm:"-"` + GroupName string `json:"group_name" gorm:"-"` } type JwtOutInfo struct { diff --git a/services/admin/internal/logic/adminNamesByIdsLogic.go b/services/admin/internal/logic/adminNamesByIdsLogic.go new file mode 100644 index 0000000..a773d0e --- /dev/null +++ b/services/admin/internal/logic/adminNamesByIdsLogic.go @@ -0,0 +1,73 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + "lone-services/services/admin/internal/dao" + "lone-services/services/admin/internal/model" + "lone-services/services/admin/validator" + "strconv" + + "lone-services/rpc/admin/pb" + "lone-services/services/admin/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type AdminNamesByIdsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewAdminNamesByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminNamesByIdsLogic { + return &AdminNamesByIdsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 传入IDS []int64,返回[]NamesItem{id int64,name string} +func (l *AdminNamesByIdsLogic) AdminNamesByIds(in *admin.AdminNamesByIdsRequest) (*admin.AdminNamesByIdsResponse, error) { + var req validator.AdminNamesByIdsValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return nil, status.Error(codes.InvalidArgument, msg) + } + + ids := make([]string, utils.NumberZero, len(in.Ids)) + for _, id := range in.Ids { + ids = append(ids, strconv.FormatInt(id, utils.NumberTen)) + } + + w := modelbase.Params{ + In: map[string][]string{"id in ?": ids}, + Eq: map[string]string{"status": utils.StringStatusOk}, + } + var items []dao.AdminNames + err := model.AdminModel{}.Init().Items(w, &items) + if err != nil { + l.Logger.Error(err) + return nil, status.Error(codes.Code(utils.Fail.Code), utils.Fail.Msg) + } + if len(items) < utils.NumberOne { + return nil, status.Error(codes.Code(utils.ErrorNotFund.Code), utils.ErrorNotFund.Msg) + } + + var result []*admin.NamesItem + for item := range items { + mobile, dErr := utils.DecryptPhone(items[item].Phone) + if dErr == nil { + items[item].Phone = mobile + } + result = append(result, &admin.NamesItem{ + Id: int64(items[item].Id), + Name: items[item].Name, + }) + } + return &admin.AdminNamesByIdsResponse{Items: result}, nil +} diff --git a/services/admin/internal/logic/admininfologic.go b/services/admin/internal/logic/admininfologic.go index 300def6..1072aad 100644 --- a/services/admin/internal/logic/admininfologic.go +++ b/services/admin/internal/logic/admininfologic.go @@ -5,6 +5,7 @@ import ( "lone-services/pkg/modelbase" "lone-services/pkg/utils" admin "lone-services/rpc/admin/pb" + sale "lone-services/rpc/sale/pb" "lone-services/services/admin/internal/dao" "lone-services/services/admin/internal/model" "lone-services/services/admin/internal/svc" @@ -57,6 +58,24 @@ func (l *AdminInfoLogic) AdminInfo(in *admin.AdminInfoRequest) (*admin.Response, roles = append(roles, r) } } + if info.Type == dao.AdminTypeSale { + cli, err := svc.GetRpcClient(l.svcCtx.SaleSvcName) + if err != nil { + logx.Errorf("get rpc client err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + saleClient := sale.NewSaleClient(cli.Conn()) + saleInfo, err := saleClient.InfoInternal(context.Background(), &sale.InfoReq{Id: info.SaleId}) + if err != nil { + logx.Errorf("get sale err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + + info.GroupName = saleInfo.Group.Name + info.GroupId = saleInfo.GroupId + info.SaleName = saleInfo.Name + } + retData := dao.AdminInfoRet{ AdminInfo: info, Roles: roles, diff --git a/services/admin/internal/logic/loginlogic.go b/services/admin/internal/logic/loginlogic.go index 32f0770..56c4487 100644 --- a/services/admin/internal/logic/loginlogic.go +++ b/services/admin/internal/logic/loginlogic.go @@ -6,6 +6,7 @@ import ( "lone-services/pkg/redis" "lone-services/pkg/utils" admin "lone-services/rpc/admin/pb" + sale "lone-services/rpc/sale/pb" "lone-services/services/admin/internal/dao" "lone-services/services/admin/internal/model" "lone-services/services/admin/internal/svc" @@ -69,10 +70,31 @@ func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) { Id: info.Id, Name: info.Name, Email: info.Email, + Type: info.Type, Avatar: info.Avatar, LastTime: utils.Now(), } + if info.Type == dao.AdminTypeSale { + cli, err := svc.GetRpcClient(l.svcCtx.SaleSvcName) + if err != nil { + logx.Errorf("get rpc client err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + saleClient := sale.NewSaleClient(cli.Conn()) + saleInfo, err := saleClient.InfoInternal(context.Background(), &sale.InfoReq{Id: info.SaleId}) + if err != nil { + logx.Errorf("get sale err: %v", err) + return l.fail(utils.ErrorInternalServer) + } + + data.GroupName = saleInfo.Group.Name + data.GroupId = saleInfo.GroupId + data.SaleId = saleInfo.Id + data.SaleName = saleInfo.Name + data.SaleMobile = saleInfo.OriginMobile + } + data.Phone, _ = utils.DecryptPhone(info.Phone) retData := dao.Token{ diff --git a/services/admin/internal/server/adminServer.go b/services/admin/internal/server/adminServer.go index 198cb3e..780be42 100644 --- a/services/admin/internal/server/adminServer.go +++ b/services/admin/internal/server/adminServer.go @@ -177,3 +177,9 @@ func (s *AdminServer) RoleRule(ctx context.Context, in *admin.RoleRuleRequest) ( l := logic.NewRoleRuleLogic(ctx, s.svcCtx) return l.RoleRule(in) } + +// 传入IDS []int64,返回[]NamesItem{id int64,name string} +func (s *AdminServer) AdminNamesByIds(ctx context.Context, in *admin.AdminNamesByIdsRequest) (*admin.AdminNamesByIdsResponse, error) { + l := logic.NewAdminNamesByIdsLogic(ctx, s.svcCtx) + return l.AdminNamesByIds(in) +} diff --git a/services/admin/internal/svc/servicecontext.go b/services/admin/internal/svc/servicecontext.go index 5d16c9c..7418525 100644 --- a/services/admin/internal/svc/servicecontext.go +++ b/services/admin/internal/svc/servicecontext.go @@ -1,22 +1,96 @@ package svc import ( + "fmt" + "lone-services/pkg/discovery" "lone-services/pkg/utils" "lone-services/services/admin/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 + + SaleSvcName string //服务名 } func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { + //启动仅读取配置,不建立rpc连接 多个服务就多个 + SaleSvc := utils.GetConfigString("services.sale") + + if SaleSvc == utils.StringEmpty { + logx.Error("config services.sale empty") + } + return &ServiceContext{ - Config: c, - DB: db, - Prefix: utils.GetConfigString("mysql.prefix"), + Config: c, + DB: db, + Prefix: utils.GetConfigString("mysql.prefix"), + SaleSvcName: SaleSvc, } } diff --git a/services/admin/validator/admin.go b/services/admin/validator/admin.go index 53a81a4..e145a11 100644 --- a/services/admin/validator/admin.go +++ b/services/admin/validator/admin.go @@ -135,3 +135,14 @@ func (p LoginKickedOutValidator) GetMessage() validate.ValidatorMessages { "Id.required": "ID不能为空", } } + +type AdminNamesByIdsValidator struct { + Ids []int64 `validate:"required"` +} + +// GetMessage 提示消息 +func (p AdminNamesByIdsValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Ids.required": "ID不能为空", + } +} diff --git a/services/order/internal/logic/orderCreateLogic.go b/services/order/internal/logic/orderCreateLogic.go index 261d3eb..2652052 100644 --- a/services/order/internal/logic/orderCreateLogic.go +++ b/services/order/internal/logic/orderCreateLogic.go @@ -4,6 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + product "lone-services/rpc/product/pb" "lone-services/services/order/internal/dao" "lone-services/services/order/internal/model" "lone-services/services/order/validator" @@ -68,7 +69,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde ww := modelbase.Params{ Eq: map[string]string{ - "type": strconv.Itoa(dao.OrderTypeStore), + "type": strconv.Itoa(dao.OrderTypeStore), + "store_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen), }, } data.StoreId = int(adminInfo.ID) @@ -79,7 +81,6 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde data.SaleProvince = int(adminInfo.SaleProvince) data.CreateType = dao.OrderTypeStore data.Type = dao.OrderTypeStore - ww.Eq["store_id"] = strconv.FormatInt(adminInfo.ID, utils.NumberTen) data.OrderSn = svc.GetOrderSn(strconv.Itoa(dao.OrderTypeStore), adminInfo.ID) var cart dao.Cart @@ -96,6 +97,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde var totalPrice float64 errData := make(map[int64]int64) productItems := []dao.OrderProductCreate{} + + NumItems := make([]*product.NumberItem, utils.NumberZero) for _, item := range products.Items { if buyNum, ok := ids[item.Id]; ok { if buyNum > int64(item.Number) { @@ -103,6 +106,8 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.out(utils.Fail, item.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(item.Number))) } else { + 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{ @@ -143,20 +148,19 @@ func (l *OrderCreateLogic) OrderCreate(in *order.AdminCreateOrderRequest) (*orde return l.fail(utils.Fail) } - //TODO 扣库存接口 - //cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) - //if err != nil { - // mobileObj.Rollback() - // return l.fail(utils.Fail) - //} + cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) + if err != nil { + mobileObj.Rollback() + return l.fail(utils.Fail) + } - //productClient := product.NewProductClient(cli.Conn()) - //_, err = productClient.Number(l.ctx, &product.NumberReq{Id: item.Id, Type: utils.NumberOne, Number: buyNum}) - //if err != nil { - // mobileObj.Rollback() - // logx.Errorf("get products err: %v", err) - // return l.fail(utils.Fail, "产品库存不足") - //} + productClient := product.NewProductClient(cli.Conn()) + _, err = productClient.NumberItems(l.ctx, &product.NumberItemsReq{Type: utils.NumberOne, Items: NumItems}) + if err != nil { + mobileObj.Rollback() + logx.Errorf("get products err: %v", err) + return l.out(utils.Fail, "产品库存不足") + } mobileObj.Commit() diff --git a/services/order/internal/logic/webCreateLogic.go b/services/order/internal/logic/webCreateLogic.go index b68239d..0e362d8 100644 --- a/services/order/internal/logic/webCreateLogic.go +++ b/services/order/internal/logic/webCreateLogic.go @@ -4,6 +4,7 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + product "lone-services/rpc/product/pb" "lone-services/services/order/internal/dao" "lone-services/services/order/internal/model" "lone-services/services/order/validator" @@ -124,6 +125,8 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons var totalPrice float64 errData := make(map[int64]int64) productItems := []dao.OrderProductCreate{} + + NumItems := make([]*product.NumberItem, utils.NumberZero) for _, item := range products.Items { if buyNum, ok := ids[item.Id]; ok { if buyNum > int64(item.Number) { @@ -131,6 +134,8 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons return l.out(utils.Fail, item.Name+"购买数量超出库存,目前可以够买:"+strconv.Itoa(int(item.Number))) } else { + 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{ @@ -171,20 +176,19 @@ func (l *WebCreateLogic) WebCreate(in *order.CreateOrderRequest) (*order.Respons return l.fail(utils.Fail) } - //TODO 扣库存接口 - //cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) - //if err != nil { - // mobileObj.Rollback() - // return l.fail(utils.Fail) - //} + cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) + if err != nil { + mobileObj.Rollback() + return l.fail(utils.Fail) + } - //productClient := product.NewProductClient(cli.Conn()) - //_, err = productClient.Number(l.ctx, &product.NumberReq{Id: item.Id, Type: utils.NumberOne, Number: buyNum}) - //if err != nil { - // mobileObj.Rollback() - // logx.Errorf("get products err: %v", err) - // return l.fail(utils.Fail, "产品库存不足") - //} + productClient := product.NewProductClient(cli.Conn()) + _, err = productClient.NumberItems(l.ctx, &product.NumberItemsReq{Type: utils.NumberOne, Items: NumItems}) + if err != nil { + mobileObj.Rollback() + logx.Errorf("get products err: %v", err) + return l.out(utils.Fail, "产品库存不足") + } mobileObj.Commit() diff --git a/services/sale/run.toml b/services/sale/run.toml index 94aee8e..05a692a 100644 --- a/services/sale/run.toml +++ b/services/sale/run.toml @@ -2,7 +2,7 @@ login_out_time=43200 #api接口超时时间分 login_refresh_out_time=83200 name = "sale-service" - listenOn = "0.0.0.0:10300" + listenOn = "0.0.0.0:10900" mode = "dev" [log] path = "logs" @@ -52,7 +52,4 @@ db = 0 [encrypt] - data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" - -[services] - chore = "chore-service" \ No newline at end of file + data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" \ No newline at end of file