From f327fd44ac83dc1083f462a6b554263116a79d55 Mon Sep 17 00:00:00 2001 From: gjs Date: Tue, 20 Oct 2026 13:39:27 +0800 Subject: [PATCH] add apis --- deploy/apisix/lua/auth.lua | 4 + rpc/chore/chore.pb | Bin 16789 -> 16940 bytes rpc/chore/chore.proto | 38 +++ rpc/chore/pb/chore.pb.go | 284 +++++++++++------- rpc/chore/pb/chore_grpc.pb.go | 194 +++++++++++- services/chore/choreclient/chore.go | 35 ++- services/chore/internal/dao/answerUser.go | 6 + services/chore/internal/dao/system.go | 5 + .../internal/logic/apiAnswerIProgressLogic.go | 46 +++ .../internal/logic/apiAnswerItemsLogic.go | 46 +++ .../internal/logic/apiAnswerSaveLogic.go | 56 ++++ .../internal/logic/apiSystemInfoLogic.go | 47 +++ .../internal/logic/apiSystemItemsLogic.go | 45 +++ services/chore/internal/model/answerUser.go | 18 ++ services/chore/internal/server/choreServer.go | 28 +- services/chore/validator/system.go | 10 + 16 files changed, 748 insertions(+), 114 deletions(-) create mode 100644 services/chore/internal/dao/answerUser.go create mode 100644 services/chore/internal/logic/apiAnswerIProgressLogic.go create mode 100644 services/chore/internal/logic/apiAnswerItemsLogic.go create mode 100644 services/chore/internal/logic/apiAnswerSaveLogic.go create mode 100644 services/chore/internal/logic/apiSystemInfoLogic.go create mode 100644 services/chore/internal/logic/apiSystemItemsLogic.go create mode 100644 services/chore/internal/model/answerUser.go diff --git a/deploy/apisix/lua/auth.lua b/deploy/apisix/lua/auth.lua index f188adc..01ab588 100644 --- a/deploy/apisix/lua/auth.lua +++ b/deploy/apisix/lua/auth.lua @@ -31,6 +31,10 @@ function _M.access(conf, ctx) ["/api/v2/analysis/switch"] = true, ["/api/v2/analysis/user/delete"] = true, ["/api/v2/analysis/store/info"] = true, + + ["/api/v3/chore/answer/items"] = true, + ["/api/v3/chore/system/info"] = true, + ["/api/v3/chore/system/items"] = true, } local user_key = core.request.header(ctx, "authorization") diff --git a/rpc/chore/chore.pb b/rpc/chore/chore.pb index ed1299ffe27682ba9e1763526f79130fb3989704..df9ea1974c218e41a7ba607525d1055cd0a75a24 100644 GIT binary patch delta 584 zcmbQ*%($k7al=|BrjCTk>zPa#qbEOQ^5f;d}*} zGz?faF*0*Z&d>;zU&P2Q#OCbdAMENP(ZarnkyD7pKfu*b;yF7=$&1N%G_oiAYRa)f zcv+emKpj9ee*S*0VD&)VVXi@*Zjo>uA2pL@7BPwl@%y;?xrcbf2L!pgc}9SZhZs_z z6*u{cmO8}9&A+ssGqSUBykHmT_S>AN%gw~Jm1%Rez6K+j46 zPC`=pi3OSZWybnoS^Z+Lar&7cEmn+LLeX5ja1EY$Y57=;`DZVyB8lA;pazg3kzmJ6 zHn7#RR&BccWHOUHy0wXU#pS6*2x}9#gn-sMf<-+8it^KoQi~_Qw^y;!0P9y0l0~%; ns=olD672GDu*)Gv1SgiIPX1u8C9Q* zt~7&nvlFwb3e#Hd$(icWY?~OFIbN_&KB8_g`ImYyjO(i*H91!!3&y>!AvgKAM!Gyi z@ghb}Ar?P>KUaws_C<``LTq8KL7r}r63-_$Y9`CT)QAZ2`?&hKhj_#X1i89-M!332 zv`o^9gBcm8rM|ga>ltHxHzUw~fo?ykCPpDyAXA84uOLY;xu8IbAH;AjC~!+nEGaEY zEf$jJc*!or0TRthEK8IU0I|G)EVu$`j#unLY#`zEd?`K&6XF6178K=| zx<_aBdCZ>7Jn_KlX80$+>A}U=d6&g|CXu%Ru#rdU0$*J+l`6;RK znR#jXNU@}aC6 chore.RegionItem - 7, // 1: chore.Chore.Policy:input_type -> chore.PolicyReq - 8, // 2: chore.Chore.Upload:input_type -> chore.UploadReq - 11, // 3: chore.Chore.Test:input_type -> chore.TestReq - 12, // 4: chore.Chore.DecryptMobile:input_type -> chore.DecryptMobileReq - 13, // 5: chore.Chore.Regions:input_type -> chore.RegionsReq - 17, // 6: chore.Chore.SendSms:input_type -> chore.SendSmsReq - 1, // 7: chore.Chore.AnswerItems:input_type -> chore.EmptyReq - 3, // 8: chore.Chore.AnswerStatus:input_type -> chore.StatusReq - 2, // 9: chore.Chore.AnswerInfo:input_type -> chore.IdReq - 4, // 10: chore.Chore.AnswerCreate:input_type -> chore.EditReq - 4, // 11: chore.Chore.AnswerEdit:input_type -> chore.EditReq - 5, // 12: chore.Chore.SystemEdit:input_type -> chore.SystemEditReq - 3, // 13: chore.Chore.SystemStatus:input_type -> chore.StatusReq - 2, // 14: chore.Chore.SystemInfo:input_type -> chore.IdReq - 1, // 15: chore.Chore.SystemItems:input_type -> chore.EmptyReq - 9, // 16: chore.Chore.InternalUpload:input_type -> chore.InternalUploadReq - 14, // 17: chore.Chore.RegionsByIds:input_type -> chore.RegionsByIdsReq - 18, // 18: chore.Chore.InternalActionApplyLogCreate:input_type -> chore.InternalActionApplyLogCreateReq - 20, // 19: chore.Chore.SendPassword:input_type -> chore.SendPasswordReq - 0, // 20: chore.Chore.Policy:output_type -> chore.Response - 0, // 21: chore.Chore.Upload:output_type -> chore.Response - 0, // 22: chore.Chore.Test:output_type -> chore.Response - 0, // 23: chore.Chore.DecryptMobile:output_type -> chore.Response - 0, // 24: chore.Chore.Regions:output_type -> chore.Response - 0, // 25: chore.Chore.SendSms:output_type -> chore.Response - 0, // 26: chore.Chore.AnswerItems:output_type -> chore.Response - 0, // 27: chore.Chore.AnswerStatus:output_type -> chore.Response - 0, // 28: chore.Chore.AnswerInfo:output_type -> chore.Response - 0, // 29: chore.Chore.AnswerCreate:output_type -> chore.Response - 0, // 30: chore.Chore.AnswerEdit:output_type -> chore.Response - 0, // 31: chore.Chore.SystemEdit:output_type -> chore.Response - 0, // 32: chore.Chore.SystemStatus:output_type -> chore.Response - 0, // 33: chore.Chore.SystemInfo:output_type -> chore.Response - 0, // 34: chore.Chore.SystemItems:output_type -> chore.Response - 10, // 35: chore.Chore.InternalUpload:output_type -> chore.InternalUploadData - 16, // 36: chore.Chore.RegionsByIds:output_type -> chore.RegionsByIdsData - 19, // 37: chore.Chore.InternalActionApplyLogCreate:output_type -> chore.InternalActionApplyLogCreateData - 21, // 38: chore.Chore.SendPassword:output_type -> chore.SendPasswordResp - 20, // [20:39] is the sub-list for method output_type - 1, // [1:20] is the sub-list for method input_type + 16, // 0: chore.RegionsByIdsData.items:type_name -> chore.RegionItem + 8, // 1: chore.Chore.Policy:input_type -> chore.PolicyReq + 9, // 2: chore.Chore.Upload:input_type -> chore.UploadReq + 12, // 3: chore.Chore.Test:input_type -> chore.TestReq + 13, // 4: chore.Chore.DecryptMobile:input_type -> chore.DecryptMobileReq + 14, // 5: chore.Chore.Regions:input_type -> chore.RegionsReq + 18, // 6: chore.Chore.SendSms:input_type -> chore.SendSmsReq + 6, // 7: chore.Chore.ApiSystemItems:input_type -> chore.ApiSystemReq + 6, // 8: chore.Chore.ApiSystemInfo:input_type -> chore.ApiSystemReq + 1, // 9: chore.Chore.ApiAnswerItems:input_type -> chore.EmptyReq + 1, // 10: chore.Chore.ApiAnswerIProgress:input_type -> chore.EmptyReq + 1, // 11: chore.Chore.ApiAnswerSave:input_type -> chore.EmptyReq + 1, // 12: chore.Chore.AnswerItems:input_type -> chore.EmptyReq + 3, // 13: chore.Chore.AnswerStatus:input_type -> chore.StatusReq + 2, // 14: chore.Chore.AnswerInfo:input_type -> chore.IdReq + 4, // 15: chore.Chore.AnswerCreate:input_type -> chore.EditReq + 4, // 16: chore.Chore.AnswerEdit:input_type -> chore.EditReq + 5, // 17: chore.Chore.SystemEdit:input_type -> chore.SystemEditReq + 3, // 18: chore.Chore.SystemStatus:input_type -> chore.StatusReq + 2, // 19: chore.Chore.SystemInfo:input_type -> chore.IdReq + 1, // 20: chore.Chore.SystemItems:input_type -> chore.EmptyReq + 10, // 21: chore.Chore.InternalUpload:input_type -> chore.InternalUploadReq + 15, // 22: chore.Chore.RegionsByIds:input_type -> chore.RegionsByIdsReq + 19, // 23: chore.Chore.InternalActionApplyLogCreate:input_type -> chore.InternalActionApplyLogCreateReq + 21, // 24: chore.Chore.SendPassword:input_type -> chore.SendPasswordReq + 0, // 25: chore.Chore.Policy:output_type -> chore.Response + 0, // 26: chore.Chore.Upload:output_type -> chore.Response + 0, // 27: chore.Chore.Test:output_type -> chore.Response + 0, // 28: chore.Chore.DecryptMobile:output_type -> chore.Response + 0, // 29: chore.Chore.Regions:output_type -> chore.Response + 0, // 30: chore.Chore.SendSms:output_type -> chore.Response + 0, // 31: chore.Chore.ApiSystemItems:output_type -> chore.Response + 0, // 32: chore.Chore.ApiSystemInfo:output_type -> chore.Response + 0, // 33: chore.Chore.ApiAnswerItems:output_type -> chore.Response + 0, // 34: chore.Chore.ApiAnswerIProgress:output_type -> chore.Response + 0, // 35: chore.Chore.ApiAnswerSave:output_type -> chore.Response + 0, // 36: chore.Chore.AnswerItems:output_type -> chore.Response + 0, // 37: chore.Chore.AnswerStatus:output_type -> chore.Response + 0, // 38: chore.Chore.AnswerInfo:output_type -> chore.Response + 0, // 39: chore.Chore.AnswerCreate:output_type -> chore.Response + 0, // 40: chore.Chore.AnswerEdit:output_type -> chore.Response + 0, // 41: chore.Chore.SystemEdit:output_type -> chore.Response + 0, // 42: chore.Chore.SystemStatus:output_type -> chore.Response + 0, // 43: chore.Chore.SystemInfo:output_type -> chore.Response + 0, // 44: chore.Chore.SystemItems:output_type -> chore.Response + 11, // 45: chore.Chore.InternalUpload:output_type -> chore.InternalUploadData + 17, // 46: chore.Chore.RegionsByIds:output_type -> chore.RegionsByIdsData + 20, // 47: chore.Chore.InternalActionApplyLogCreate:output_type -> chore.InternalActionApplyLogCreateData + 22, // 48: chore.Chore.SendPassword:output_type -> chore.SendPasswordResp + 25, // [25:49] is the sub-list for method output_type + 1, // [1:25] 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 @@ -1388,7 +1450,7 @@ func file_chore_chore_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_chore_chore_proto_rawDesc), len(file_chore_chore_proto_rawDesc)), NumEnums: 0, - NumMessages: 22, + NumMessages: 23, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/chore/pb/chore_grpc.pb.go b/rpc/chore/pb/chore_grpc.pb.go index 00f194a..d6d04ee 100644 --- a/rpc/chore/pb/chore_grpc.pb.go +++ b/rpc/chore/pb/chore_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.2 -// - protoc v3.19.4 +// - protoc v4.25.8 // source: chore/chore.proto package chore @@ -25,6 +25,11 @@ const ( Chore_DecryptMobile_FullMethodName = "/chore.Chore/DecryptMobile" Chore_Regions_FullMethodName = "/chore.Chore/Regions" Chore_SendSms_FullMethodName = "/chore.Chore/SendSms" + Chore_ApiSystemItems_FullMethodName = "/chore.Chore/ApiSystemItems" + Chore_ApiSystemInfo_FullMethodName = "/chore.Chore/ApiSystemInfo" + Chore_ApiAnswerItems_FullMethodName = "/chore.Chore/ApiAnswerItems" + Chore_ApiAnswerIProgress_FullMethodName = "/chore.Chore/ApiAnswerIProgress" + Chore_ApiAnswerSave_FullMethodName = "/chore.Chore/ApiAnswerSave" Chore_AnswerItems_FullMethodName = "/chore.Chore/AnswerItems" Chore_AnswerStatus_FullMethodName = "/chore.Chore/AnswerStatus" Chore_AnswerInfo_FullMethodName = "/chore.Chore/AnswerInfo" @@ -50,6 +55,12 @@ type ChoreClient interface { DecryptMobile(ctx context.Context, in *DecryptMobileReq, opts ...grpc.CallOption) (*Response, error) Regions(ctx context.Context, in *RegionsReq, opts ...grpc.CallOption) (*Response, error) SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc.CallOption) (*Response, error) + ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) + ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + // ******************** 管理员接口 ******************** AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) AnswerStatus(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error) AnswerInfo(ctx context.Context, in *IdReq, opts ...grpc.CallOption) (*Response, error) @@ -133,6 +144,56 @@ func (c *choreClient) SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc. return out, nil } +func (c *choreClient) ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_ApiSystemItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *choreClient) ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_ApiSystemInfo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *choreClient) ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_ApiAnswerItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *choreClient) ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_ApiAnswerIProgress_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *choreClient) ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_ApiAnswerSave_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *choreClient) AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Response) @@ -273,6 +334,12 @@ type ChoreServer interface { DecryptMobile(context.Context, *DecryptMobileReq) (*Response, error) Regions(context.Context, *RegionsReq) (*Response, error) SendSms(context.Context, *SendSmsReq) (*Response, error) + ApiSystemItems(context.Context, *ApiSystemReq) (*Response, error) + ApiSystemInfo(context.Context, *ApiSystemReq) (*Response, error) + ApiAnswerItems(context.Context, *EmptyReq) (*Response, error) + ApiAnswerIProgress(context.Context, *EmptyReq) (*Response, error) + ApiAnswerSave(context.Context, *EmptyReq) (*Response, error) + // ******************** 管理员接口 ******************** AnswerItems(context.Context, *EmptyReq) (*Response, error) AnswerStatus(context.Context, *StatusReq) (*Response, error) AnswerInfo(context.Context, *IdReq) (*Response, error) @@ -314,6 +381,21 @@ func (UnimplementedChoreServer) Regions(context.Context, *RegionsReq) (*Response func (UnimplementedChoreServer) SendSms(context.Context, *SendSmsReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method SendSms not implemented") } +func (UnimplementedChoreServer) ApiSystemItems(context.Context, *ApiSystemReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiSystemItems not implemented") +} +func (UnimplementedChoreServer) ApiSystemInfo(context.Context, *ApiSystemReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiSystemInfo not implemented") +} +func (UnimplementedChoreServer) ApiAnswerItems(context.Context, *EmptyReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAnswerItems not implemented") +} +func (UnimplementedChoreServer) ApiAnswerIProgress(context.Context, *EmptyReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAnswerIProgress not implemented") +} +func (UnimplementedChoreServer) ApiAnswerSave(context.Context, *EmptyReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ApiAnswerSave not implemented") +} func (UnimplementedChoreServer) AnswerItems(context.Context, *EmptyReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method AnswerItems not implemented") } @@ -482,6 +564,96 @@ func _Chore_SendSms_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +func _Chore_ApiSystemItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiSystemReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).ApiSystemItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_ApiSystemItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).ApiSystemItems(ctx, req.(*ApiSystemReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Chore_ApiSystemInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ApiSystemReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).ApiSystemInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_ApiSystemInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).ApiSystemInfo(ctx, req.(*ApiSystemReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Chore_ApiAnswerItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).ApiAnswerItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_ApiAnswerItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).ApiAnswerItems(ctx, req.(*EmptyReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Chore_ApiAnswerIProgress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).ApiAnswerIProgress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_ApiAnswerIProgress_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).ApiAnswerIProgress(ctx, req.(*EmptyReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Chore_ApiAnswerSave_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).ApiAnswerSave(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_ApiAnswerSave_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).ApiAnswerSave(ctx, req.(*EmptyReq)) + } + return interceptor(ctx, in, info, handler) +} + func _Chore_AnswerItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(EmptyReq) if err := dec(in); err != nil { @@ -747,6 +919,26 @@ var Chore_ServiceDesc = grpc.ServiceDesc{ MethodName: "SendSms", Handler: _Chore_SendSms_Handler, }, + { + MethodName: "ApiSystemItems", + Handler: _Chore_ApiSystemItems_Handler, + }, + { + MethodName: "ApiSystemInfo", + Handler: _Chore_ApiSystemInfo_Handler, + }, + { + MethodName: "ApiAnswerItems", + Handler: _Chore_ApiAnswerItems_Handler, + }, + { + MethodName: "ApiAnswerIProgress", + Handler: _Chore_ApiAnswerIProgress_Handler, + }, + { + MethodName: "ApiAnswerSave", + Handler: _Chore_ApiAnswerSave_Handler, + }, { MethodName: "AnswerItems", Handler: _Chore_AnswerItems_Handler, diff --git a/services/chore/choreclient/chore.go b/services/chore/choreclient/chore.go index 6bd75fe..f06c3d3 100644 --- a/services/chore/choreclient/chore.go +++ b/services/chore/choreclient/chore.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.10.1 +// goctl 1.10.2 // Source: chore.proto package choreClient @@ -14,6 +14,7 @@ import ( ) type ( + ApiSystemReq = chore.ApiSystemReq DecryptMobileReq = chore.DecryptMobileReq DocumentReq = chore.DocumentReq EditReq = chore.EditReq @@ -44,6 +45,12 @@ type ( DecryptMobile(ctx context.Context, in *DecryptMobileReq, opts ...grpc.CallOption) (*Response, error) Regions(ctx context.Context, in *RegionsReq, opts ...grpc.CallOption) (*Response, error) SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc.CallOption) (*Response, error) + ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) + ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + // 管理员接口 AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) AnswerStatus(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error) AnswerInfo(ctx context.Context, in *IdReq, opts ...grpc.CallOption) (*Response, error) @@ -100,6 +107,32 @@ func (m *defaultChore) SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc return client.SendSms(ctx, in, opts...) } +func (m *defaultChore) ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.ApiSystemItems(ctx, in, opts...) +} + +func (m *defaultChore) ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.ApiSystemInfo(ctx, in, opts...) +} + +func (m *defaultChore) ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.ApiAnswerItems(ctx, in, opts...) +} + +func (m *defaultChore) ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.ApiAnswerIProgress(ctx, in, opts...) +} + +func (m *defaultChore) ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.ApiAnswerSave(ctx, in, opts...) +} + +// 管理员接口 func (m *defaultChore) AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { client := chore.NewChoreClient(m.cli.Conn()) return client.AnswerItems(ctx, in, opts...) diff --git a/services/chore/internal/dao/answerUser.go b/services/chore/internal/dao/answerUser.go new file mode 100644 index 0000000..1d669e2 --- /dev/null +++ b/services/chore/internal/dao/answerUser.go @@ -0,0 +1,6 @@ +package dao + +type UserAnswer struct { + Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Answer uint8 `gorm:"column:answer;type:tinyint(1);default:2;comment:答题状态,1为答完, 2为未答" json:"answer"` +} diff --git a/services/chore/internal/dao/system.go b/services/chore/internal/dao/system.go index 435f1ec..60269db 100644 --- a/services/chore/internal/dao/system.go +++ b/services/chore/internal/dao/system.go @@ -16,3 +16,8 @@ type SystemStatus struct { 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 ApiSystemInfo struct { + Type int32 `gorm:"column:type;type:tinyint(1);default:0;NOT NULL" json:"type"` + Content string `gorm:"column:content;type:text;default:'';NOT NULL" json:"content"` +} diff --git a/services/chore/internal/logic/apiAnswerIProgressLogic.go b/services/chore/internal/logic/apiAnswerIProgressLogic.go new file mode 100644 index 0000000..4f1c4ac --- /dev/null +++ b/services/chore/internal/logic/apiAnswerIProgressLogic.go @@ -0,0 +1,46 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + "lone-services/services/chore/internal/svc" + "strconv" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAnswerIProgressLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAnswerIProgressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerIProgressLogic { + return &ApiAnswerIProgressLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiAnswerIProgressLogic) ApiAnswerIProgress(in *chore.EmptyReq) (*chore.Response, error) { + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + var info dao.UserAnswer + w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}} + + err := model.AnswerUserModel{}.Init().GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + return l.ok(info) +} diff --git a/services/chore/internal/logic/apiAnswerItemsLogic.go b/services/chore/internal/logic/apiAnswerItemsLogic.go new file mode 100644 index 0000000..523185a --- /dev/null +++ b/services/chore/internal/logic/apiAnswerItemsLogic.go @@ -0,0 +1,46 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAnswerItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAnswerItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerItemsLogic { + return &ApiAnswerItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiAnswerItemsLogic) ApiAnswerItems(in *chore.EmptyReq) (*chore.Response, error) { + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + var info []dao.AnswerInfo + w := modelbase.Params{Eq: map[string]string{"status": utils.StringStatusOk}} + + err := model.AnswerModel{}.Init().Items(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + return l.ok(info) +} diff --git a/services/chore/internal/logic/apiAnswerSaveLogic.go b/services/chore/internal/logic/apiAnswerSaveLogic.go new file mode 100644 index 0000000..58b09af --- /dev/null +++ b/services/chore/internal/logic/apiAnswerSaveLogic.go @@ -0,0 +1,56 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + "strconv" + + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiAnswerSaveLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiAnswerSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerSaveLogic { + return &ApiAnswerSaveLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiAnswerSaveLogic) ApiAnswerSave(in *chore.EmptyReq) (*chore.Response, error) { + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + var info dao.UserAnswer + w := modelbase.Params{Eq: map[string]string{"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}} + + err := model.AnswerUserModel{}.Init().GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.SetError(utils.ErrorNotFund, "用户不存在")) + } + + info.Answer = utils.StatusOk + _, err = model.AnswerUserModel{}.Init().Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + return l.ok(info.Id) +} diff --git a/services/chore/internal/logic/apiSystemInfoLogic.go b/services/chore/internal/logic/apiSystemInfoLogic.go new file mode 100644 index 0000000..be0b982 --- /dev/null +++ b/services/chore/internal/logic/apiSystemInfoLogic.go @@ -0,0 +1,47 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + "lone-services/services/chore/validator" + "strconv" + + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiSystemInfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiSystemInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemInfoLogic { + return &ApiSystemInfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiSystemInfoLogic) ApiSystemInfo(in *chore.ApiSystemReq) (*chore.Response, error) { + var v validator.ApiSystemInfoValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + + var info []dao.ApiSystemInfo + w := modelbase.Params{Eq: map[string]string{"type": strconv.Itoa(int(in.Type))}} + err := model.SystemModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + + return l.ok(info) +} diff --git a/services/chore/internal/logic/apiSystemItemsLogic.go b/services/chore/internal/logic/apiSystemItemsLogic.go new file mode 100644 index 0000000..7213dbe --- /dev/null +++ b/services/chore/internal/logic/apiSystemItemsLogic.go @@ -0,0 +1,45 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + "strconv" + + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ApiSystemItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewApiSystemItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemItemsLogic { + return &ApiSystemItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ApiSystemItemsLogic) ApiSystemItems(in *chore.ApiSystemReq) (*chore.Response, error) { + var info []dao.ApiSystemInfo + w := modelbase.Params{} + if in.Type > utils.NumberZero { + w.Eq = make(map[string]string) + w.Eq["type"] = strconv.Itoa(int(in.Type)) + } + err := model.SystemModel{}.Init().Items(w, &info) + if err != nil { + return l.fail(utils.ErrorNotFund) + } + + return l.ok(info) +} diff --git a/services/chore/internal/model/answerUser.go b/services/chore/internal/model/answerUser.go new file mode 100644 index 0000000..ad05c45 --- /dev/null +++ b/services/chore/internal/model/answerUser.go @@ -0,0 +1,18 @@ +package model + +import ( + "lone-services/pkg/modelbase" +) + +type AnswerUserModel struct { + modelbase.Base +} + +func (m AnswerUserModel) TableName() string { + return modelbase.Prefix() + "answer_user" +} + +func (m AnswerUserModel) Init() AnswerUserModel { + m.Table = m.TableName() + return m +} diff --git a/services/chore/internal/server/choreServer.go b/services/chore/internal/server/choreServer.go index 53b3775..c8661eb 100644 --- a/services/chore/internal/server/choreServer.go +++ b/services/chore/internal/server/choreServer.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.10.1 +// goctl 1.10.2 // Source: chore.proto package server @@ -53,6 +53,32 @@ func (s *ChoreServer) SendSms(ctx context.Context, in *chore.SendSmsReq) (*chore return l.SendSms(in) } +func (s *ChoreServer) ApiSystemItems(ctx context.Context, in *chore.ApiSystemReq) (*chore.Response, error) { + l := logic.NewApiSystemItemsLogic(ctx, s.svcCtx) + return l.ApiSystemItems(in) +} + +func (s *ChoreServer) ApiSystemInfo(ctx context.Context, in *chore.ApiSystemReq) (*chore.Response, error) { + l := logic.NewApiSystemInfoLogic(ctx, s.svcCtx) + return l.ApiSystemInfo(in) +} + +func (s *ChoreServer) ApiAnswerItems(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) { + l := logic.NewApiAnswerItemsLogic(ctx, s.svcCtx) + return l.ApiAnswerItems(in) +} + +func (s *ChoreServer) ApiAnswerIProgress(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) { + l := logic.NewApiAnswerIProgressLogic(ctx, s.svcCtx) + return l.ApiAnswerIProgress(in) +} + +func (s *ChoreServer) ApiAnswerSave(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) { + l := logic.NewApiAnswerSaveLogic(ctx, s.svcCtx) + return l.ApiAnswerSave(in) +} + +// 管理员接口 func (s *ChoreServer) AnswerItems(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) { l := logic.NewAnswerItemsLogic(ctx, s.svcCtx) return l.AnswerItems(in) diff --git a/services/chore/validator/system.go b/services/chore/validator/system.go index 38d027f..51032e3 100644 --- a/services/chore/validator/system.go +++ b/services/chore/validator/system.go @@ -13,3 +13,13 @@ func (p SystemEditValidator) GetMessage() validate.ValidatorMessages { "Content.required": "Content 必传", } } + +type ApiSystemInfoValidator struct { + Type int32 `form:"type" json:"type" validate:"required"` +} + +func (p ApiSystemInfoValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Type.required": "Type 必传", + } +}