wangchuanjin 1 жил өмнө
parent
commit
abc614623d

+ 12 - 0
public/entity/base_ent_empower.go

@@ -77,6 +77,18 @@ func (b *base_ent_empower) ReEmpower(appid, function_code string, ent_id int64,
 	})
 }
 
+//授权
+func (b *base_ent_empower) Empower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
+	fields := []string{"appid", "ent_id", "ent_user_id", "function_code", "create_time"}
+	nowFormat := NowFormat(Date_Full_Layout)
+	values := []interface{}{}
+	for _, v := range ent_user_id {
+		values = append(values, appid, ent_id, Int64All(v), function_code, nowFormat)
+	}
+	r1, _ := Mysql_BaseService.InsertBatch("base_ent_empower", fields, values)
+	return r1 == int64(len(ent_user_id))
+}
+
 //取消授权
 func (b *base_ent_empower) CancelEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) bool {
 	args := []interface{}{appid, function_code, ent_id}

+ 24 - 0
public/service/power.go

@@ -168,6 +168,30 @@ func ReEmpower(appid, function_code string, ent_id int64, ent_user_id []int64) (
 	return 0, nil
 }
 
+/*
+ * 授权
+ * @param appid
+ * @param function_code 功能代码
+ * @param ent_id 企业id
+ * @param ent_user_id 企业用户id
+ * @return 0:失败 1:成功
+ */
+func Empower(appid, function_code string, ent_id int64, ent_user_id []int64) (int64, error) {
+	if appid == "" {
+		return 0, errors.New("无效的参数appid")
+	} else if function_code == "" {
+		return 0, errors.New("无效的参数function_code")
+	} else if ent_id == 0 {
+		return 0, errors.New("无效的参数ent_id")
+	} else if len(ent_user_id) == 0 {
+		return 0, errors.New("无效的参数ent_user_id")
+	}
+	if Base_ent_empower.Empower(appid, function_code, ent_id, ent_user_id) {
+		return 1, nil
+	}
+	return 0, nil
+}
+
 /*
  * 取消授权
  * @param appid

+ 37 - 0
rpc/internal/logic/empowerlogic.go

@@ -0,0 +1,37 @@
+package logic
+
+import (
+	"context"
+	"fmt"
+
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type EmpowerLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewEmpowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EmpowerLogic {
+	return &EmpowerLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 授权
+func (l *EmpowerLogic) Empower(in *pb.EmpowerReq) (*pb.Resp, error) {
+	resp := &pb.Resp{}
+	status, err := CancelEmpower(in.Appid, in.FunctionCode, in.EntId, in.EntUserId)
+	if err != nil {
+		l.Error(fmt.Sprintf("%+v", in), err)
+	}
+	resp.Status = status
+	return resp, nil
+}

+ 6 - 0
rpc/internal/server/resourceserver.go

@@ -52,6 +52,12 @@ func (s *ResourceServer) ReEmpower(ctx context.Context, in *pb.EmpowerReq) (*pb.
 	return l.ReEmpower(in)
 }
 
+// 授权
+func (s *ResourceServer) Empower(ctx context.Context, in *pb.EmpowerReq) (*pb.Resp, error) {
+	l := logic.NewEmpowerLogic(ctx, s.svcCtx)
+	return l.Empower(in)
+}
+
 // 取消授权
 func (s *ResourceServer) CancelEmpower(ctx context.Context, in *pb.EmpowerReq) (*pb.Resp, error) {
 	l := logic.NewCancelEmpowerLogic(ctx, s.svcCtx)

+ 28 - 24
rpc/pb/resource.pb.go

@@ -962,7 +962,7 @@ var file_resource_proto_rawDesc = []byte{
 	0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x65, 0x6e, 0x74, 0x55, 0x73, 0x65, 0x72,
 	0x49, 0x64, 0x22, 0x27, 0x0a, 0x0d, 0x48, 0x61, 0x73, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x52,
 	0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20,
-	0x03, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x32, 0xb8, 0x02, 0x0a, 0x08,
+	0x03, 0x28, 0x09, 0x52, 0x06, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x32, 0xd7, 0x02, 0x0a, 0x08,
 	0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x50, 0x6f, 0x77, 0x65,
 	0x72, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x12, 0x09, 0x2e, 0x50, 0x6f, 0x77, 0x65, 0x72, 0x52,
 	0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x0a, 0x43, 0x68, 0x65,
@@ -974,16 +974,18 @@ var file_resource_proto_rawDesc = []byte{
 	0x52, 0x65, 0x63, 0x68, 0x61, 0x72, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65,
 	0x73, 0x70, 0x12, 0x1f, 0x0a, 0x09, 0x52, 0x65, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12,
 	0x0b, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52,
-	0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x0d, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x6d, 0x70,
-	0x6f, 0x77, 0x65, 0x72, 0x12, 0x0b, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65,
-	0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x30, 0x0a, 0x0b, 0x45, 0x6d, 0x70, 0x6f,
-	0x77, 0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x0f, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65,
-	0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77,
-	0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2a, 0x0a, 0x09, 0x48, 0x61,
-	0x73, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x12, 0x0d, 0x2e, 0x48, 0x61, 0x73, 0x70, 0x6f, 0x77,
-	0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x0e, 0x2e, 0x48, 0x61, 0x73, 0x70, 0x6f, 0x77, 0x65,
-	0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06,
-	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x65, 0x73, 0x70, 0x12, 0x1d, 0x0a, 0x07, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x0b,
+	0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65,
+	0x73, 0x70, 0x12, 0x23, 0x0a, 0x0d, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x45, 0x6d, 0x70, 0x6f,
+	0x77, 0x65, 0x72, 0x12, 0x0b, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x52, 0x65, 0x71,
+	0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x30, 0x0a, 0x0b, 0x45, 0x6d, 0x70, 0x6f, 0x77,
+	0x65, 0x72, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x0f, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65, 0x72,
+	0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6f, 0x77, 0x65,
+	0x72, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x2a, 0x0a, 0x09, 0x48, 0x61, 0x73,
+	0x70, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x12, 0x0d, 0x2e, 0x48, 0x61, 0x73, 0x70, 0x6f, 0x77, 0x65,
+	0x72, 0x73, 0x52, 0x65, 0x71, 0x1a, 0x0e, 0x2e, 0x48, 0x61, 0x73, 0x70, 0x6f, 0x77, 0x65, 0x72,
+	0x73, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70,
+	0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -1019,19 +1021,21 @@ var file_resource_proto_depIdxs = []int32{
 	3,  // 3: Resource.Deduction:input_type -> DeductionReq
 	4,  // 4: Resource.Recharge:input_type -> RechargeReq
 	5,  // 5: Resource.ReEmpower:input_type -> EmpowerReq
-	5,  // 6: Resource.CancelEmpower:input_type -> EmpowerReq
-	6,  // 7: Resource.EmpowerList:input_type -> EmpowerListReq
-	9,  // 8: Resource.Haspowers:input_type -> HaspowersReq
-	8,  // 9: Resource.PowerHandle:output_type -> Resp
-	8,  // 10: Resource.CheckPower:output_type -> Resp
-	8,  // 11: Resource.Deduction:output_type -> Resp
-	8,  // 12: Resource.Recharge:output_type -> Resp
-	8,  // 13: Resource.ReEmpower:output_type -> Resp
-	8,  // 14: Resource.CancelEmpower:output_type -> Resp
-	7,  // 15: Resource.EmpowerList:output_type -> EmpowerListResp
-	10, // 16: Resource.Haspowers:output_type -> HaspowersResp
-	9,  // [9:17] is the sub-list for method output_type
-	1,  // [1:9] is the sub-list for method input_type
+	5,  // 6: Resource.Empower:input_type -> EmpowerReq
+	5,  // 7: Resource.CancelEmpower:input_type -> EmpowerReq
+	6,  // 8: Resource.EmpowerList:input_type -> EmpowerListReq
+	9,  // 9: Resource.Haspowers:input_type -> HaspowersReq
+	8,  // 10: Resource.PowerHandle:output_type -> Resp
+	8,  // 11: Resource.CheckPower:output_type -> Resp
+	8,  // 12: Resource.Deduction:output_type -> Resp
+	8,  // 13: Resource.Recharge:output_type -> Resp
+	8,  // 14: Resource.ReEmpower:output_type -> Resp
+	8,  // 15: Resource.Empower:output_type -> Resp
+	8,  // 16: Resource.CancelEmpower:output_type -> Resp
+	7,  // 17: Resource.EmpowerList:output_type -> EmpowerListResp
+	10, // 18: Resource.Haspowers:output_type -> HaspowersResp
+	10, // [10:19] is the sub-list for method output_type
+	1,  // [1:10] 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

+ 38 - 0
rpc/pb/resource_grpc.pb.go

@@ -32,6 +32,8 @@ type ResourceClient interface {
 	Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error)
 	//重新授权
 	ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
+	//授权
+	Empower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 	//取消授权
 	CancelEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 	//授权列表
@@ -93,6 +95,15 @@ func (c *resourceClient) ReEmpower(ctx context.Context, in *EmpowerReq, opts ...
 	return out, nil
 }
 
+func (c *resourceClient) Empower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
+	out := new(Resp)
+	err := c.cc.Invoke(ctx, "/Resource/Empower", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 func (c *resourceClient) CancelEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
 	out := new(Resp)
 	err := c.cc.Invoke(ctx, "/Resource/CancelEmpower", in, out, opts...)
@@ -134,6 +145,8 @@ type ResourceServer interface {
 	Recharge(context.Context, *RechargeReq) (*Resp, error)
 	//重新授权
 	ReEmpower(context.Context, *EmpowerReq) (*Resp, error)
+	//授权
+	Empower(context.Context, *EmpowerReq) (*Resp, error)
 	//取消授权
 	CancelEmpower(context.Context, *EmpowerReq) (*Resp, error)
 	//授权列表
@@ -162,6 +175,9 @@ func (UnimplementedResourceServer) Recharge(context.Context, *RechargeReq) (*Res
 func (UnimplementedResourceServer) ReEmpower(context.Context, *EmpowerReq) (*Resp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method ReEmpower not implemented")
 }
+func (UnimplementedResourceServer) Empower(context.Context, *EmpowerReq) (*Resp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method Empower not implemented")
+}
 func (UnimplementedResourceServer) CancelEmpower(context.Context, *EmpowerReq) (*Resp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method CancelEmpower not implemented")
 }
@@ -274,6 +290,24 @@ func _Resource_ReEmpower_Handler(srv interface{}, ctx context.Context, dec func(
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Resource_Empower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(EmpowerReq)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ResourceServer).Empower(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/Resource/Empower",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ResourceServer).Empower(ctx, req.(*EmpowerReq))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 func _Resource_CancelEmpower_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(EmpowerReq)
 	if err := dec(in); err != nil {
@@ -355,6 +389,10 @@ var Resource_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "ReEmpower",
 			Handler:    _Resource_ReEmpower_Handler,
 		},
+		{
+			MethodName: "Empower",
+			Handler:    _Resource_Empower_Handler,
+		},
 		{
 			MethodName: "CancelEmpower",
 			Handler:    _Resource_CancelEmpower_Handler,

+ 2 - 0
rpc/resource.proto

@@ -97,6 +97,8 @@ service Resource {
   rpc Recharge(RechargeReq) returns(Resp);
   //重新授权
   rpc ReEmpower(EmpowerReq) returns(Resp);
+  //授权
+  rpc Empower(EmpowerReq) returns(Resp);
   //取消授权
   rpc CancelEmpower(EmpowerReq) returns(Resp);
   //授权列表

+ 8 - 0
rpc/resource/resource.go

@@ -36,6 +36,8 @@ type (
 		Recharge(ctx context.Context, in *RechargeReq, opts ...grpc.CallOption) (*Resp, error)
 		// 重新授权
 		ReEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
+		// 授权
+		Empower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 		// 取消授权
 		CancelEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error)
 		// 授权列表
@@ -85,6 +87,12 @@ func (m *defaultResource) ReEmpower(ctx context.Context, in *EmpowerReq, opts ..
 	return client.ReEmpower(ctx, in, opts...)
 }
 
+// 授权
+func (m *defaultResource) Empower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
+	client := pb.NewResourceClient(m.cli.Conn())
+	return client.Empower(ctx, in, opts...)
+}
+
 // 取消授权
 func (m *defaultResource) CancelEmpower(ctx context.Context, in *EmpowerReq, opts ...grpc.CallOption) (*Resp, error) {
 	client := pb.NewResourceClient(m.cli.Conn())