Browse Source

导出数据发送邮件接口修改

Jianghan 1 year ago
parent
commit
c2d3a871e1

+ 1 - 1
api/internal/logic/sendmaillogic.go

@@ -25,7 +25,7 @@ func NewSendMailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendMail
 }
 
 func (l *SendMailLogic) SendMail(req *types.ExportByDbReq) (resp *types.BiResp, err error) {
-	res, err := l.svcCtx.BiServiceRpc.ExportDataByDb(l.ctx, &biservice.ExportByDbReq{
+	res, err := l.svcCtx.BiServiceRpc.SendMail(l.ctx, &biservice.ExportByDbReq{
 		Token:   req.Token,
 		Title:   req.Title,
 		Content: req.Content,

+ 1 - 1
rpc/biService.proto

@@ -165,5 +165,5 @@ service BiService {
 	rpc allInfoExport (ExportReq) returns (BiReply); //资讯全量导出
 	rpc allProjectExport (ExportReq) returns (BiReply); //项目全量导出
 	rpc infoOperate (OperateReq) returns (BiReply); //数据操作
-	rpc exportDataByDb (ExportByDbReq) returns (BiReply); //数据导出(通用)
+	rpc sendMail (ExportByDbReq) returns (BiReply); //数据导出(通用)
 }

+ 3 - 3
rpc/biservice/biservice.go

@@ -53,7 +53,7 @@ type (
 		AllInfoExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*BiReply, error)
 		AllProjectExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*BiReply, error)
 		InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*BiReply, error)
-		ExportDataByDb(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error)
+		SendMail(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error)
 	}
 
 	defaultBiService struct {
@@ -142,7 +142,7 @@ func (m *defaultBiService) InfoOperate(ctx context.Context, in *OperateReq, opts
 	return client.InfoOperate(ctx, in, opts...)
 }
 
-func (m *defaultBiService) ExportDataByDb(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error) {
+func (m *defaultBiService) SendMail(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error) {
 	client := pb.NewBiServiceClient(m.cli.Conn())
-	return client.ExportDataByDb(ctx, in, opts...)
+	return client.SendMail(ctx, in, opts...)
 }

+ 14 - 0
rpc/internal/logic/T_test.go

@@ -0,0 +1,14 @@
+package logic
+
+import (
+	"fmt"
+	"testing"
+)
+
+func TokenTest(t *testing.T) {
+	content := "你好老师,这是导出的数据"
+	mail := "516807046@qq.com"
+	query := "select t1.全称 as FULL_NAME,t0.CREATE_TIME as CREATE_TIME,coalesce(t0.pv_resp_person,t0.ofv_resp_person,t0.onv_resp_person) as SFZ,coalesce(t0.pv_visitor,t0.ofv_visitor,t0.onv_visitor) as BFZ,coalesce(t0.pv_visit_time,t0.ofv_visit_time,t0.onv_visit_time) as BFSJ,t0.FOLLOW_STATUS as FOLLOW_STATUS,coalesce(t0.pv_next_follow_time,t0.ofv_next_follow_time,t0.onv_next_follow_time) as XCGJSJ,coalesce(t0.pv_content,t0.ofv_content,t0.onv_content) as NR from crm.follow_record t0 left join (select t0.id as ID,t1.full_name as 全称 from crm.task t0 left join crm.custom t1 on (t0.source_id=t1.id) where (t0.source=3)) t1 on (t0.task_id=t1.ID) where (t0.CREATE_TIME>=str_to_date('2024-02-01','%Y-%m-%d') and t0.CREATE_TIME<str_to_date('2024-02-02','%Y-%m-%d') AND t0.CREATE_PERSON IN ('孙振杰','陈瑞文','朱凤超')) order by coalesce(t0.pv_visit_time,t0.ofv_visit_time,t0.onv_visit_time) desc limit 6"
+	title := "数据导出"
+	RsaEncrypt([]byte(fmt.Sprintf("%s&%s&%s&%s", content, mail, query, title)))
+}

+ 18 - 10
rpc/internal/logic/exportdatabydblogic.go → rpc/internal/logic/sendmaillogic.go

@@ -1,27 +1,29 @@
 package logic
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"bp.jydev.jianyu360.cn/BaseService/biService/entity"
-	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
-	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
 	"bp.jydev.jianyu360.cn/BaseService/biService/service"
 	"context"
-	"encoding/base64"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/tjfoc/gmsm/sm4"
-	"github.com/zeromicro/go-zero/core/logx"
 	"regexp"
+
+	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
+
+	"github.com/zeromicro/go-zero/core/logx"
 )
 
-type ExportDataByDbLogic struct {
+type SendMailLogic struct {
 	ctx    context.Context
 	svcCtx *svc.ServiceContext
 	logx.Logger
 }
 
-func NewExportDataByDbLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExportDataByDbLogic {
-	return &ExportDataByDbLogic{
+func NewSendMailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendMailLogic {
+	return &SendMailLogic{
 		ctx:    ctx,
 		svcCtx: svcCtx,
 		Logger: logx.WithContext(ctx),
@@ -31,8 +33,14 @@ func NewExportDataByDbLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ex
 var reg1 = regexp.MustCompile("(?i)(insert|delete|update|master|truncate|declare|exec|alter|use)\\s")
 var reg2 = regexp.MustCompile("(?i)(select|from)\\s")
 
-func (l *ExportDataByDbLogic) ExportDataByDb(in *pb.ExportByDbReq) (*pb.BiReply, error) {
-
+func (l *SendMailLogic) SendMail(in *pb.ExportByDbReq) (*pb.BiReply, error) {
+	if in.Query != "" && in.Token != "" && in.Title != "" && in.Content != "" && in.Mails != "" {
+		return &pb.BiReply{
+			ErrorCode: 1,
+			ErrorMsg:  "参数不能为空",
+			Data:      nil,
+		}, nil
+	}
 	if reg1.MatchString(in.Query) && !reg2.MatchString(in.Query) {
 		return &pb.BiReply{
 			ErrorCode: 1,
@@ -65,5 +73,5 @@ func (l *ExportDataByDbLogic) ExportDataByDb(in *pb.ExportByDbReq) (*pb.BiReply,
 func RsaEncrypt(data []byte) string {
 	key := []byte(entity.PublicKey)
 	b, _ := sm4.Sm4Ecb(key, data, true)
-	return base64.StdEncoding.EncodeToString(b)
+	return common.GetMd5String(string(b))
 }

+ 3 - 3
rpc/internal/server/biserviceserver.go

@@ -97,7 +97,7 @@ func (s *BiServiceServer) InfoOperate(ctx context.Context, in *pb.OperateReq) (*
 	return l.InfoOperate(in)
 }
 
-func (s *BiServiceServer) ExportDataByDb(ctx context.Context, in *pb.ExportByDbReq) (*pb.BiReply, error) {
-	l := logic.NewExportDataByDbLogic(ctx, s.svcCtx)
-	return l.ExportDataByDb(in)
+func (s *BiServiceServer) SendMail(ctx context.Context, in *pb.ExportByDbReq) (*pb.BiReply, error) {
+	l := logic.NewSendMailLogic(ctx, s.svcCtx)
+	return l.SendMail(in)
 }

+ 7 - 8
rpc/pb/biService.pb.go

@@ -1795,7 +1795,7 @@ var file_biService_proto_rawDesc = []byte{
 	0x6d, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x61, 0x69,
 	0x6c, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28,
 	0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x79, 0x70,
-	0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x32, 0xb1,
+	0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x79, 0x70, 0x65, 0x32, 0xab,
 	0x05, 0x0a, 0x09, 0x42, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x30, 0x0a, 0x0b,
 	0x6d, 0x79, 0x44, 0x61, 0x74, 0x61, 0x41, 0x73, 0x73, 0x65, 0x74, 0x12, 0x0f, 0x2e, 0x4d, 0x79,
 	0x44, 0x61, 0x74, 0x61, 0x41, 0x73, 0x73, 0x65, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x10, 0x2e, 0x4d,
@@ -1836,11 +1836,10 @@ var file_biService_proto_rawDesc = []byte{
 	0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x08, 0x2e, 0x42, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79,
 	0x12, 0x24, 0x0a, 0x0b, 0x69, 0x6e, 0x66, 0x6f, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12,
 	0x0b, 0x2e, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x08, 0x2e, 0x42,
-	0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x2a, 0x0a, 0x0e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74,
-	0x44, 0x61, 0x74, 0x61, 0x42, 0x79, 0x44, 0x62, 0x12, 0x0e, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72,
-	0x74, 0x42, 0x79, 0x44, 0x62, 0x52, 0x65, 0x71, 0x1a, 0x08, 0x2e, 0x42, 0x69, 0x52, 0x65, 0x70,
-	0x6c, 0x79, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
-	0x6f, 0x33,
+	0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x24, 0x0a, 0x08, 0x73, 0x65, 0x6e, 0x64, 0x4d, 0x61,
+	0x69, 0x6c, 0x12, 0x0e, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x79, 0x44, 0x62, 0x52,
+	0x65, 0x71, 0x1a, 0x08, 0x2e, 0x42, 0x69, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x06, 0x5a, 0x04,
+	0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -1902,7 +1901,7 @@ var file_biService_proto_depIdxs = []int32{
 	20, // 17: BiService.allInfoExport:input_type -> ExportReq
 	20, // 18: BiService.allProjectExport:input_type -> ExportReq
 	21, // 19: BiService.infoOperate:input_type -> OperateReq
-	22, // 20: BiService.exportDataByDb:input_type -> ExportByDbReq
+	22, // 20: BiService.sendMail:input_type -> ExportByDbReq
 	1,  // 21: BiService.myDataAsset:output_type -> MyDataAssetResp
 	4,  // 22: BiService.addProject:output_type -> AddProjectResp
 	6,  // 23: BiService.getInfoId:output_type -> GetInfoIdResp
@@ -1918,7 +1917,7 @@ var file_biService_proto_depIdxs = []int32{
 	10, // 33: BiService.allInfoExport:output_type -> BiReply
 	10, // 34: BiService.allProjectExport:output_type -> BiReply
 	10, // 35: BiService.infoOperate:output_type -> BiReply
-	10, // 36: BiService.exportDataByDb:output_type -> BiReply
+	10, // 36: BiService.sendMail:output_type -> BiReply
 	21, // [21:37] is the sub-list for method output_type
 	5,  // [5:21] is the sub-list for method input_type
 	5,  // [5:5] is the sub-list for extension type_name

+ 13 - 13
rpc/pb/biService_grpc.pb.go

@@ -34,7 +34,7 @@ const (
 	BiService_AllInfoExport_FullMethodName    = "/BiService/allInfoExport"
 	BiService_AllProjectExport_FullMethodName = "/BiService/allProjectExport"
 	BiService_InfoOperate_FullMethodName      = "/BiService/infoOperate"
-	BiService_ExportDataByDb_FullMethodName   = "/BiService/exportDataByDb"
+	BiService_SendMail_FullMethodName         = "/BiService/sendMail"
 )
 
 // BiServiceClient is the client API for BiService service.
@@ -56,7 +56,7 @@ type BiServiceClient interface {
 	AllInfoExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*BiReply, error)
 	AllProjectExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*BiReply, error)
 	InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*BiReply, error)
-	ExportDataByDb(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error)
+	SendMail(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error)
 }
 
 type biServiceClient struct {
@@ -202,9 +202,9 @@ func (c *biServiceClient) InfoOperate(ctx context.Context, in *OperateReq, opts
 	return out, nil
 }
 
-func (c *biServiceClient) ExportDataByDb(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error) {
+func (c *biServiceClient) SendMail(ctx context.Context, in *ExportByDbReq, opts ...grpc.CallOption) (*BiReply, error) {
 	out := new(BiReply)
-	err := c.cc.Invoke(ctx, BiService_ExportDataByDb_FullMethodName, in, out, opts...)
+	err := c.cc.Invoke(ctx, BiService_SendMail_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
 	}
@@ -230,7 +230,7 @@ type BiServiceServer interface {
 	AllInfoExport(context.Context, *ExportReq) (*BiReply, error)
 	AllProjectExport(context.Context, *ExportReq) (*BiReply, error)
 	InfoOperate(context.Context, *OperateReq) (*BiReply, error)
-	ExportDataByDb(context.Context, *ExportByDbReq) (*BiReply, error)
+	SendMail(context.Context, *ExportByDbReq) (*BiReply, error)
 	mustEmbedUnimplementedBiServiceServer()
 }
 
@@ -283,8 +283,8 @@ func (UnimplementedBiServiceServer) AllProjectExport(context.Context, *ExportReq
 func (UnimplementedBiServiceServer) InfoOperate(context.Context, *OperateReq) (*BiReply, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method InfoOperate not implemented")
 }
-func (UnimplementedBiServiceServer) ExportDataByDb(context.Context, *ExportByDbReq) (*BiReply, error) {
-	return nil, status.Errorf(codes.Unimplemented, "method ExportDataByDb not implemented")
+func (UnimplementedBiServiceServer) SendMail(context.Context, *ExportByDbReq) (*BiReply, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method SendMail not implemented")
 }
 func (UnimplementedBiServiceServer) mustEmbedUnimplementedBiServiceServer() {}
 
@@ -569,20 +569,20 @@ func _BiService_InfoOperate_Handler(srv interface{}, ctx context.Context, dec fu
 	return interceptor(ctx, in, info, handler)
 }
 
-func _BiService_ExportDataByDb_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+func _BiService_SendMail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 	in := new(ExportByDbReq)
 	if err := dec(in); err != nil {
 		return nil, err
 	}
 	if interceptor == nil {
-		return srv.(BiServiceServer).ExportDataByDb(ctx, in)
+		return srv.(BiServiceServer).SendMail(ctx, in)
 	}
 	info := &grpc.UnaryServerInfo{
 		Server:     srv,
-		FullMethod: BiService_ExportDataByDb_FullMethodName,
+		FullMethod: BiService_SendMail_FullMethodName,
 	}
 	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
-		return srv.(BiServiceServer).ExportDataByDb(ctx, req.(*ExportByDbReq))
+		return srv.(BiServiceServer).SendMail(ctx, req.(*ExportByDbReq))
 	}
 	return interceptor(ctx, in, info, handler)
 }
@@ -655,8 +655,8 @@ var BiService_ServiceDesc = grpc.ServiceDesc{
 			Handler:    _BiService_InfoOperate_Handler,
 		},
 		{
-			MethodName: "exportDataByDb",
-			Handler:    _BiService_ExportDataByDb_Handler,
+			MethodName: "sendMail",
+			Handler:    _BiService_SendMail_Handler,
 		},
 	},
 	Streams:  []grpc.StreamDesc{},