Browse Source

Merge branch 'dev_v1.0.16_wh' of BaseService/biService into feature/v1.0.16

王浩 1 year ago
parent
commit
3d7dc4e974

+ 9 - 3
entity/entity.go

@@ -50,6 +50,9 @@ var (
 	PublicKey        = ""
 	GmailAuth        []*mail.GmailAuth
 	UpdataProjectUrl string
+	ExportDirectory  string
+	ExportUrl        string
+	ExportCount      int
 )
 
 type HlyjS struct {
@@ -221,11 +224,14 @@ func (h *Handler) HandleMessage(m *nsq.Message) error {
 	}
 	return nil
 }
+func InitConfig(directory, projectUrl, exportUrl string, count int) {
+	ExportDirectory = directory
+	UpdataProjectUrl = projectUrl
+	ExportUrl = exportUrl
+	ExportCount = count
+}
 
 // 初始化reidis
-func InitUrl(url string) {
-	UpdataProjectUrl = url
-}
 func InitRedis(redisAddr []string) {
 	redis.InitRedisBySize(strings.Join(redisAddr, ","), 100, 30, 300)
 }

+ 1 - 1
rpc/biService.proto

@@ -156,5 +156,5 @@ service BiService {
 	rpc myInfo (MyInfoReq) returns (Reply); //用户身份
 	rpc allInfoExport (ExportReq) returns (Reply); //资讯全量导出
 	rpc allProjectExport (ExportReq) returns (Reply); //项目全量导出
-	rpc infoOperate (OperateReq) returns (Reply); //数据操作
+	rpc infoOperate (OperateReq) returns (Resp); //数据操作
 }

+ 1 - 1
rpc/biservice.go

@@ -36,7 +36,7 @@ func main() {
 	entity.InitEntEs(c.EntEs.Version, c.EntEs.Address, c.EntEs.UserName, c.EntEs.Password, c.EntEs.DbSize)
 	entity.InitArea()
 	entity.InitRedis(c.RedisAddress)
-	entity.InitUrl(c.UpdateProjectUrl)
+	entity.InitConfig(c.ExportDirectory, c.UpdateProjectUrl, c.ExportUrl, c.ExportCount)
 	//合力亿捷
 	entity.GetHlyj(c.Hlyj.Appid, c.Hlyj.Account, c.Hlyj.Secret, c.Hlyj.TokenUrl, c.Hlyj.CallUrl, c.Hlyj.Integratedid, c.Hlyj.CallFlag)
 	//nsq

+ 2 - 2
rpc/biservice/biservice.go

@@ -51,7 +51,7 @@ type (
 		MyInfo(ctx context.Context, in *MyInfoReq, opts ...grpc.CallOption) (*Reply, error)
 		AllInfoExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*Reply, error)
 		AllProjectExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*Reply, error)
-		InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Reply, error)
+		InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Resp, error)
 	}
 
 	defaultBiService struct {
@@ -135,7 +135,7 @@ func (m *defaultBiService) AllProjectExport(ctx context.Context, in *ExportReq,
 	return client.AllProjectExport(ctx, in, opts...)
 }
 
-func (m *defaultBiService) InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Reply, error) {
+func (m *defaultBiService) InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Resp, error) {
 	client := pb.NewBiServiceClient(m.cli.Conn())
 	return client.InfoOperate(ctx, in, opts...)
 }

+ 3 - 0
rpc/etc/biservice.yaml

@@ -114,3 +114,6 @@ Mail:
     Pwd: "ue9Rg9Sf4CVtdm5a"
     User: "public03@topnet.net.cn"
 UpdateProjectUrl: "https://tieta.spdata.jianyu360.com/updateProject"
+ExportDirectory: "D:/top_git_projects/biService"
+ExportUrl: "https://jybx-webtest.jydev.jianyu360.com/tietaRes"
+ExportCount: 15000

+ 3 - 0
rpc/internal/config/config.go

@@ -73,4 +73,7 @@ type Config struct {
 		User string
 	}
 	UpdateProjectUrl string
+	ExportDirectory  string
+	ExportCount      int
+	ExportUrl        string
 }

+ 1 - 1
rpc/internal/logic/allinfoexportlogic.go

@@ -26,7 +26,7 @@ func NewAllInfoExportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *All
 
 func (l *AllInfoExportLogic) AllInfoExport(in *pb.ExportReq) (*pb.Reply, error) {
 	// todo: add your logic here and delete this line
-	(&service.ExportReq{
+	go (&service.ExportReq{
 		Mail:       in.Mail,
 		Mapping:    in.Mapping,
 		PositionId: in.PositionId,

+ 1 - 1
rpc/internal/logic/allprojectexportlogic.go

@@ -26,7 +26,7 @@ func NewAllProjectExportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
 
 func (l *AllProjectExportLogic) AllProjectExport(in *pb.ExportReq) (*pb.Reply, error) {
 	// todo: add your logic here and delete this line
-	(&service.ExportReq{
+	go (&service.ExportReq{
 		Mail:       in.Mail,
 		Mapping:    in.Mapping,
 		PositionId: in.PositionId,

+ 7 - 3
rpc/internal/logic/infooperatelogic.go

@@ -3,6 +3,7 @@ package logic
 import (
 	"bp.jydev.jianyu360.cn/BaseService/biService/service"
 	"context"
+	"github.com/gogf/gf/v2/util/gconv"
 
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/biService/rpc/pb"
@@ -24,11 +25,14 @@ func NewInfoOperateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoO
 	}
 }
 
-func (l *InfoOperateLogic) InfoOperate(in *pb.OperateReq) (*pb.Reply, error) {
+func (l *InfoOperateLogic) InfoOperate(in *pb.OperateReq) (*pb.Resp, error) {
 	// todo: add your logic here and delete this line
-	(&service.Operate{
+	fool := (&service.Operate{
 		OperateType: in.Type,
 		NewId:       in.NewId,
 	}).InfoOperate()
-	return &pb.Reply{}, nil
+	return &pb.Resp{
+		ErrorCode: gconv.Int64(!fool),
+		ErrorMsg:  "",
+	}, nil
 }

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

@@ -92,7 +92,7 @@ func (s *BiServiceServer) AllProjectExport(ctx context.Context, in *pb.ExportReq
 	return l.AllProjectExport(in)
 }
 
-func (s *BiServiceServer) InfoOperate(ctx context.Context, in *pb.OperateReq) (*pb.Reply, error) {
+func (s *BiServiceServer) InfoOperate(ctx context.Context, in *pb.OperateReq) (*pb.Resp, error) {
 	l := logic.NewInfoOperateLogic(ctx, s.svcCtx)
 	return l.InfoOperate(in)
 }

+ 5 - 5
rpc/pb/biService.pb.go

@@ -1699,7 +1699,7 @@ var file_biService_proto_rawDesc = []byte{
 	0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x65, 0x77, 0x49, 0x64, 0x18,
 	0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6e, 0x65, 0x77, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04,
 	0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,
-	0x32, 0xf9, 0x04, 0x0a, 0x09, 0x42, 0x69, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x30,
+	0x32, 0xf8, 0x04, 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, 0x79, 0x44, 0x61, 0x74, 0x61, 0x41, 0x73, 0x73, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70,
@@ -1736,10 +1736,10 @@ var file_biService_proto_rawDesc = []byte{
 	0x78, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x06, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79,
 	0x12, 0x26, 0x0a, 0x10, 0x61, 0x6c, 0x6c, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x45, 0x78,
 	0x70, 0x6f, 0x72, 0x74, 0x12, 0x0a, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x52, 0x65, 0x71,
-	0x1a, 0x06, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x22, 0x0a, 0x0b, 0x69, 0x6e, 0x66, 0x6f,
+	0x1a, 0x06, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x21, 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, 0x06, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x42, 0x06, 0x5a, 0x04,
-	0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x65, 0x52, 0x65, 0x71, 0x1a, 0x05, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e,
+	0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -1814,7 +1814,7 @@ var file_biService_proto_depIdxs = []int32{
 	10, // 31: BiService.myInfo:output_type -> Reply
 	10, // 32: BiService.allInfoExport:output_type -> Reply
 	10, // 33: BiService.allProjectExport:output_type -> Reply
-	10, // 34: BiService.infoOperate:output_type -> Reply
+	9,  // 34: BiService.infoOperate:output_type -> Resp
 	20, // [20:35] is the sub-list for method output_type
 	5,  // [5:20] is the sub-list for method input_type
 	5,  // [5:5] is the sub-list for extension type_name

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

@@ -54,7 +54,7 @@ type BiServiceClient interface {
 	MyInfo(ctx context.Context, in *MyInfoReq, opts ...grpc.CallOption) (*Reply, error)
 	AllInfoExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*Reply, error)
 	AllProjectExport(ctx context.Context, in *ExportReq, opts ...grpc.CallOption) (*Reply, error)
-	InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Reply, error)
+	InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Resp, error)
 }
 
 type biServiceClient struct {
@@ -191,8 +191,8 @@ func (c *biServiceClient) AllProjectExport(ctx context.Context, in *ExportReq, o
 	return out, nil
 }
 
-func (c *biServiceClient) InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Reply, error) {
-	out := new(Reply)
+func (c *biServiceClient) InfoOperate(ctx context.Context, in *OperateReq, opts ...grpc.CallOption) (*Resp, error) {
+	out := new(Resp)
 	err := c.cc.Invoke(ctx, BiService_InfoOperate_FullMethodName, in, out, opts...)
 	if err != nil {
 		return nil, err
@@ -218,7 +218,7 @@ type BiServiceServer interface {
 	MyInfo(context.Context, *MyInfoReq) (*Reply, error)
 	AllInfoExport(context.Context, *ExportReq) (*Reply, error)
 	AllProjectExport(context.Context, *ExportReq) (*Reply, error)
-	InfoOperate(context.Context, *OperateReq) (*Reply, error)
+	InfoOperate(context.Context, *OperateReq) (*Resp, error)
 	mustEmbedUnimplementedBiServiceServer()
 }
 
@@ -268,7 +268,7 @@ func (UnimplementedBiServiceServer) AllInfoExport(context.Context, *ExportReq) (
 func (UnimplementedBiServiceServer) AllProjectExport(context.Context, *ExportReq) (*Reply, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method AllProjectExport not implemented")
 }
-func (UnimplementedBiServiceServer) InfoOperate(context.Context, *OperateReq) (*Reply, error) {
+func (UnimplementedBiServiceServer) InfoOperate(context.Context, *OperateReq) (*Resp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method InfoOperate not implemented")
 }
 func (UnimplementedBiServiceServer) mustEmbedUnimplementedBiServiceServer() {}

+ 20 - 6
service/exprot.go

@@ -9,6 +9,7 @@ import (
 	"github.com/xuri/excelize/v2"
 	"io"
 	"log"
+	"math/rand"
 	"os"
 	"path/filepath"
 	"strings"
@@ -35,6 +36,9 @@ func (a *ExportReq) AllProjectExport() {
 		exportKey = append(exportKey, valueArr[1])
 	}
 	timeStr := time.Now().Format("20060102150405")
+	rand.Seed(time.Now().UnixNano())
+	randomInt := rand.Intn(10000) // 生成0到9999之间的随机整数
+	timeStr = fmt.Sprintf("%s%s", timeStr, gconv.String(randomInt))
 	pathArr := export("customer_data_ttzl_project", tableColumn, exportKey, timeStr)
 	if len(pathArr) > 0 {
 		pathstr := compressFiles(pathArr, timeStr)
@@ -60,6 +64,9 @@ func (a *ExportReq) AllInfoExport() {
 		exportKey = append(exportKey, valueArr[1])
 	}
 	timeStr := time.Now().Format("20060102150405")
+	rand.Seed(time.Now().UnixNano())
+	randomInt := rand.Intn(10000) // 生成0到9999之间的随机整数
+	timeStr = fmt.Sprintf("%s%s", timeStr, gconv.String(randomInt))
 	pathArr := export("customer_data_ttzl", tableColumn, exportKey, timeStr)
 	if len(pathArr) > 0 {
 		pathstr := compressFiles(pathArr, timeStr)
@@ -75,6 +82,7 @@ func (a *ExportReq) AllInfoExport() {
 	}
 }
 
+// 导出开始
 func export(table string, tableColumn []string, key []interface{}, timeStr string) []string {
 	pathArr := []string{}
 	sqlStr := fmt.Sprintf("SELECT %s FROM %s", strings.Join(tableColumn, ","), table)
@@ -83,7 +91,7 @@ func export(table string, tableColumn []string, key []interface{}, timeStr strin
 	a := 0
 	path := ""
 	BiService.SelectByBath(1, func(l *[]map[string]interface{}) bool {
-		if a%2000 == 0 && a > 0 {
+		if a%ExportCount == 0 && a > 0 {
 			a = 0
 			//入excel处理
 			writer, file, path = Warehousing(writer, file, fileCounter, key, timeStr)
@@ -94,12 +102,14 @@ func export(table string, tableColumn []string, key []interface{}, timeStr strin
 		a++
 		return true
 	}, sqlStr)
-	if a > 0 && a != 2000 {
+	if a > 0 && a != ExportCount {
 		writer, file, path = Warehousing(writer, file, fileCounter, key, timeStr)
 		pathArr = append(pathArr, path)
 	}
 	return pathArr
 }
+
+// 数据处理
 func dataHandle(writer *excelize.StreamWriter, l *[]map[string]interface{}, a int, tableColumn []string) {
 	for _, value := range *l {
 		valueArr := []interface{}{}
@@ -110,10 +120,12 @@ func dataHandle(writer *excelize.StreamWriter, l *[]map[string]interface{}, a in
 		writer.SetRow(cell, valueArr)
 	}
 }
+
+// 入excel
 func Warehousing(writer *excelize.StreamWriter, file *excelize.File, fileCounter int, key []interface{}, timeStr string) (*excelize.StreamWriter, *excelize.File, string) {
 	log.Println(fmt.Sprintf("开始第%d数据", fileCounter))
 	writer.Flush()
-	folderPath := fmt.Sprintf("static/excel/%s", timeStr)
+	folderPath := fmt.Sprintf("%s/%s", ExportDirectory, timeStr)
 	_, err := os.Stat(folderPath)
 	if os.IsNotExist(err) {
 		//创建文件夹
@@ -131,6 +143,7 @@ func Warehousing(writer *excelize.StreamWriter, file *excelize.File, fileCounter
 	return writer, file, fileName
 }
 
+// excel初始化
 func InirWrite(key []interface{}) (*excelize.StreamWriter, *excelize.File) {
 	//文件初始化
 	file := excelize.NewFile()
@@ -143,6 +156,7 @@ func InirWrite(key []interface{}) (*excelize.StreamWriter, *excelize.File) {
 	return writer, file
 }
 
+// 发送邮箱
 func sendMail(target_mail string, path string) bool {
 	mailStr := "<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>铁塔全量标讯数据导出</title>\n</head>\n<body>\n<div>\n    <p>铁塔全量标讯数据已导出成功,请查收附件,导出时间:%s,请点击链接下载数据:<a href=\"%s\">%s</a></p>\n  </div>\n</body>"
 	html := fmt.Sprintf(mailStr, time.Now().Format(DateTime), path, path)
@@ -165,7 +179,7 @@ func sendMail(target_mail string, path string) bool {
 
 // 文件压缩
 func compressFiles(filePattern []string, timeStr string) string {
-	folderPath := fmt.Sprintf("static/zip/%s", timeStr)
+	folderPath := fmt.Sprintf("%s/%s", ExportDirectory, timeStr)
 	_, err := os.Stat(folderPath)
 	if os.IsNotExist(err) {
 		//创建文件夹
@@ -174,7 +188,7 @@ func compressFiles(filePattern []string, timeStr string) string {
 			log.Println("创建文件夹失败:", err)
 		}
 	}
-	zipFilename := fmt.Sprintf("%s/output%s.zip", folderPath, timeStr)
+	zipFilename := fmt.Sprintf("%s/%s.zip", folderPath, timeStr)
 	// 创建 ZIP 文件
 	zipFile, err := os.Create(zipFilename)
 	if err != nil {
@@ -216,5 +230,5 @@ func compressFiles(filePattern []string, timeStr string) string {
 		log.Fatal(err)
 	}
 	log.Printf("Files compressed to: %s", absPath)
-	return zipFilename
+	return fmt.Sprintf("%s/%s/%s.zip", ExportUrl, timeStr, timeStr)
 }