Browse Source

feat:上传更新

wangshan 3 years ago
parent
commit
67cabe845f

+ 6 - 1
api/internal/logic/uploadlogic.go

@@ -1,10 +1,12 @@
 package logic
 package logic
 
 
 import (
 import (
+	"app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
 	"context"
 	"context"
 	"io/ioutil"
 	"io/ioutil"
-	"app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
+	"log"
 	"net/http"
 	"net/http"
+	"time"
 
 
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/common"
 
 
@@ -33,11 +35,14 @@ func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Req
 func (l *UploadLogic) Upload(req *types.UploadReq) (resp *types.CommonRes, err error) {
 func (l *UploadLogic) Upload(req *types.UploadReq) (resp *types.CommonRes, err error) {
 	file, fileheader, _ := l.r.FormFile("file")
 	file, fileheader, _ := l.r.FormFile("file")
 	bt, _ := ioutil.ReadAll(file)
 	bt, _ := ioutil.ReadAll(file)
+	t1 := time.Now()
 	upload, err0 := l.svcCtx.Consumer.InfoFileUpload(l.ctx, &consumer.InfoFileUploadReq{
 	upload, err0 := l.svcCtx.Consumer.InfoFileUpload(l.ctx, &consumer.InfoFileUploadReq{
 		FileName: fileheader.Filename,
 		FileName: fileheader.Filename,
 		File:     bt,
 		File:     bt,
 		FileSize: fileheader.Size,
 		FileSize: fileheader.Size,
 	})
 	})
+	log.Println("---", time.Since(t1))
+	log.Println("upload:", upload)
 	if err0 != nil {
 	if err0 != nil {
 		return &types.CommonRes{
 		return &types.CommonRes{
 			Err_code: -1,
 			Err_code: -1,

+ 1 - 2
rpc/common/common.go

@@ -1,7 +1,6 @@
 package main
 package main
 
 
 import (
 import (
-	"app.yhyue.com/moapp/jyInfo/rpc/util"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 
 
@@ -33,7 +32,7 @@ func main() {
 		common.RegisterCommonServer(grpcServer, srv)
 		common.RegisterCommonServer(grpcServer, srv)
 	})
 	})
 	//日志记录
 	//日志记录
-	s.AddUnaryInterceptors(util.CustomInterceptors)
+	//s.AddUnaryInterceptors(util.CustomInterceptors)
 	defer s.Stop()
 	defer s.Stop()
 
 
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)

+ 8 - 3
rpc/consumer/consumer.go

@@ -2,14 +2,13 @@ package main
 
 
 import (
 import (
 	"fmt"
 	"fmt"
+	"github.com/zeromicro/go-zero/core/logx"
 	"log"
 	"log"
 
 
 	IC "app.yhyue.com/moapp/jyInfo/rpc/consumer/init"
 	IC "app.yhyue.com/moapp/jyInfo/rpc/consumer/init"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/server"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/server"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/type/consumer"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/type/consumer"
-	"app.yhyue.com/moapp/jyInfo/rpc/util"
-
 	mc "app.yhyue.com/moapp/jybase/common"
 	mc "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/endless"
 	"app.yhyue.com/moapp/jybase/endless"
 	"github.com/zeromicro/go-zero/core/service"
 	"github.com/zeromicro/go-zero/core/service"
@@ -38,7 +37,13 @@ func main() {
 		}
 		}
 	})
 	})
 	//日志记录
 	//日志记录
-	s.AddUnaryInterceptors(util.CustomInterceptors)
+	err := logx.SetUp(logx.LogConf{
+		Mode:  "file",
+		Level: "info",
+		Path:  "./logs",
+	})
+	log.Println("err;", err)
+	//s.AddUnaryInterceptors(util.CustomInterceptors)
 	defer s.Stop()
 	defer s.Stop()
 
 
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)

+ 4 - 0
rpc/consumer/internal/logic/infofileuploadlogic.go

@@ -5,7 +5,9 @@ import (
 	model "app.yhyue.com/moapp/jyInfo/rpc/model/oss"
 	model "app.yhyue.com/moapp/jyInfo/rpc/model/oss"
 	"bytes"
 	"bytes"
 	"context"
 	"context"
+	"log"
 	"strings"
 	"strings"
+	"time"
 
 
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/consumer"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
 	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
@@ -33,7 +35,9 @@ func (l *InfoFileUploadLogic) InfoFileUpload(in *consumer.InfoFileUploadReq) (*c
 	var resp consumer.InfoFileUploadResp
 	var resp consumer.InfoFileUploadResp
 	//model.InitOss()
 	//model.InitOss()
 	key := model.GetHashKey(in.File) + model.TypeByExt(in.FileName)
 	key := model.GetHashKey(in.File) + model.TypeByExt(in.FileName)
+	t1 := time.Now()
 	b, err := model.OssPutObject(key, bytes.NewReader(in.File), mc.InterfaceToStr(IC.C.Oss.OssBucketName))
 	b, err := model.OssPutObject(key, bytes.NewReader(in.File), mc.InterfaceToStr(IC.C.Oss.OssBucketName))
+	log.Println("----------", time.Since(t1))
 	fileSize := mc.InterfaceToStr(in.FileSize/1024) + "KB"
 	fileSize := mc.InterfaceToStr(in.FileSize/1024) + "KB"
 	if err == nil && b {
 	if err == nil && b {
 		var data consumer.InfoFileUploadData
 		var data consumer.InfoFileUploadData

+ 0 - 77
rpc/consumer/internal/server/informationserver.go

@@ -1,77 +0,0 @@
-// Code generated by goctl. DO NOT EDIT!
-// Source: consumer.proto
-
-package server
-
-import (
-	"context"
-
-	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/logic"
-	"app.yhyue.com/moapp/jyInfo/rpc/consumer/internal/svc"
-	"app.yhyue.com/moapp/jyInfo/rpc/consumer/type/consumer"
-)
-
-type InformationServer struct {
-	svcCtx *svc.ServiceContext
-	consumer.UnimplementedConsumerServer
-}
-
-func NewInformationServer(svcCtx *svc.ServiceContext) *InformationServer {
-	return &InformationServer{
-		svcCtx: svcCtx,
-	}
-}
-
-// 发布信息
-func (s *InformationServer) PublishInfo(ctx context.Context, in *consumer.PublishInfoReq) (*consumer.PublishInfoResp, error) {
-	l := logic.NewPublishInfoLogic(ctx, s.svcCtx)
-	return l.PublishInfo(in)
-}
-
-// 根据用户id获取当月已发布信息数量
-func (s *InformationServer) InfoByUserId(ctx context.Context, in *consumer.UserIdReq) (*consumer.InfoByUserIdResp, error) {
-	l := logic.NewInfoByUserIdLogic(ctx, s.svcCtx)
-	return l.InfoByUserId(in)
-}
-
-// 关联公告
-func (s *InformationServer) InfoRelated(ctx context.Context, in *consumer.UserIdReq) (*consumer.InfoRelatedResp, error) {
-	l := logic.NewInfoRelatedLogic(ctx, s.svcCtx)
-	return l.InfoRelated(in)
-}
-
-// 我的发布列表
-func (s *InformationServer) MyPublishList(ctx context.Context, in *consumer.MyPublishListReq) (*consumer.MyPublishListResp, error) {
-	l := logic.NewMyPublishListLogic(ctx, s.svcCtx)
-	return l.MyPublishList(in)
-}
-
-// 更新发布的信息0:获取详情;1:物理删除()
-func (s *InformationServer) InfoChange(ctx context.Context, in *consumer.InfoDetailReq) (*consumer.InfoDetailResp, error) {
-	l := logic.NewInfoChangeLogic(ctx, s.svcCtx)
-	return l.InfoChange(in)
-}
-
-// 信息审核状态查询
-func (s *InformationServer) StatusQuery(ctx context.Context, in *consumer.StatusReq) (*consumer.StatusResp, error) {
-	l := logic.NewStatusQueryLogic(ctx, s.svcCtx)
-	return l.StatusQuery(in)
-}
-
-// 供应信息查询
-func (s *InformationServer) SupplyInfoSearch(ctx context.Context, in *consumer.SupplyInfoSearchReq) (*consumer.SupplyInfoSearchResp, error) {
-	l := logic.NewSupplyInfoSearchLogic(ctx, s.svcCtx)
-	return l.SupplyInfoSearch(in)
-}
-
-// 供应信息详情(前端页面查询结果详情请求地址)
-func (s *InformationServer) SupplyInfoDetail(ctx context.Context, in *consumer.StatusReq) (*consumer.SupplyInfoDetailResp, error) {
-	l := logic.NewSupplyInfoDetailLogic(ctx, s.svcCtx)
-	return l.SupplyInfoDetail(in)
-}
-
-// 上传附件
-func (s *InformationServer) InfoFileUpload(ctx context.Context, in *consumer.InfoFileUploadReq) (*consumer.InfoFileUploadResp, error) {
-	l := logic.NewInfoFileUploadLogic(ctx, s.svcCtx)
-	return l.InfoFileUpload(in)
-}

+ 1 - 2
rpc/manager/manager.go

@@ -1,7 +1,6 @@
 package main
 package main
 
 
 import (
 import (
-	"app.yhyue.com/moapp/jyInfo/rpc/util"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 
 
@@ -41,7 +40,7 @@ func main() {
 		}
 		}
 	})
 	})
 	//日志记录
 	//日志记录
-	s.AddUnaryInterceptors(util.CustomInterceptors)
+	//s.AddUnaryInterceptors(util.CustomInterceptors)
 	defer s.Stop()
 	defer s.Stop()
 
 
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)
 	fmt.Printf("Starting rpc server at %s...\n", IC.C.ListenOn)

+ 1 - 3
rpc/model/oss/oss.go

@@ -1,13 +1,12 @@
 package model
 package model
 
 
 import (
 import (
+	"app.yhyue.com/moapp/jybase/common"
 	"crypto/sha256"
 	"crypto/sha256"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
 	"os"
 	"os"
 
 
-	"app.yhyue.com/moapp/jybase/common"
-
 	"github.com/aliyun/aliyun-oss-go-sdk/oss"
 	"github.com/aliyun/aliyun-oss-go-sdk/oss"
 )
 )
 
 
@@ -38,7 +37,6 @@ func OssPutObject(objectName string, fd io.Reader, ossBucketName string) (bool,
 			fmt.Println("file upload false:", err)
 			fmt.Println("file upload false:", err)
 		}
 		}
 	}(objectName, fd)
 	}(objectName, fd)
-
 	return true, nil
 	return true, nil
 }
 }
 
 

+ 30 - 24
rpc/util/customInterceptors.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
+	"strings"
 	"time"
 	"time"
 
 
 	"app.yhyue.com/moapp/jyInfo/rpc/model"
 	"app.yhyue.com/moapp/jyInfo/rpc/model"
@@ -14,30 +15,35 @@ import (
 
 
 //自定义拦截器 保存请求日志
 //自定义拦截器 保存请求日志
 func CustomInterceptors(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
 func CustomInterceptors(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
-	fmt.Println("拦截器")
-	log.Println("方法名:", info.FullMethod, "  参数:", req)
+	fmt.Println("拦截器", info.FullMethod)
+	go func() {
+		if strings.Contains(info.FullMethod, "InfoFileUpload") {
+			return
+		}
+		log.Println("方法名:", info.FullMethod, "  参数:", req)
 
 
-	var dat map[string]interface{}
-	reqByte, err := json.Marshal(req)
-	if err != nil {
-		log.Println("---req----:", err)
-	}
-	if err := json.Unmarshal(reqByte, &dat); err == nil {
-		fmt.Println(dat)
-	}
-	appId := dat["appId"]
-	userId := dat["userId"]
-	resp, err = handler(ctx, req)
-	fmt.Println("返回值", resp, err, appId)
-	respByte, err := json.Marshal(resp)
-	if len(respByte) > 200 {
-		respByte = respByte[:200]
-	}
-	if err != nil {
-		log.Println("---resp----:", err)
-	}
-	if model.Mysql.InsertBySql("INSERT INTO `info_log`(`func`, `userId`, `appId`, `req`, `res`, `time`) VALUES (?,?,?,?,?,?)", info.FullMethod, userId, appId, string(reqByte), string(respByte), time.Now().Local()) < 1 {
-		log.Println("保存日志异常:", userId)
-	}
+		var dat map[string]interface{}
+		reqByte, err := json.Marshal(req)
+		if err != nil {
+			log.Println("---req----:", err)
+		}
+		if err := json.Unmarshal(reqByte, &dat); err == nil {
+			fmt.Println(dat)
+		}
+		appId := dat["appId"]
+		userId := dat["userId"]
+		resp, err = handler(ctx, req)
+		fmt.Println("返回值", resp, err, appId)
+		respByte, err := json.Marshal(resp)
+		if len(respByte) > 200 {
+			respByte = respByte[:200]
+		}
+		if err != nil {
+			log.Println("---resp----:", err)
+		}
+		if model.Mysql.InsertBySql("INSERT INTO `info_log`(`func`, `userId`, `appId`, `req`, `res`, `time`) VALUES (?,?,?,?,?,?)", info.FullMethod, userId, appId, string(reqByte), string(respByte), time.Now().Local()) < 1 {
+			log.Println("保存日志异常:", userId)
+		}
+	}()
 	return resp, err
 	return resp, err
 }
 }