Browse Source

Merge branch 'master' of https://app.yhyue.com/moapp/jy_docs

wanghuidong 4 years ago
parent
commit
0fb0aeaefb

+ 9 - 2
rpc/stdlib/internal/logic/docofflogic.go

@@ -1,7 +1,9 @@
 package logic
 
 import (
+	stdlibService "app.yhyue.com/moapp/jydocs/services/stdlib"
 	"context"
+	"fmt"
 
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
@@ -25,6 +27,11 @@ func NewDocOffLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocOffLogi
 
 func (l *DocOffLogic) DocOff(in *stdlib.DocChangeReq) (*stdlib.DocChangeResp, error) {
 	// todo: add your logic here and delete this line
-
-	return &stdlib.DocChangeResp{}, nil
+	err := stdlibService.ChangeDocumentOff(in.Id, in.Reason)
+	fmt.Print(err)
+	if err == nil {
+		return &stdlib.DocChangeResp{State: true}, nil
+	} else {
+		return &stdlib.DocChangeResp{State: false}, nil
+	}
 }

+ 10 - 3
rpc/stdlib/internal/logic/doconlogic.go

@@ -1,10 +1,11 @@
 package logic
 
 import (
-	"context"
-
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
+	stdlibService "app.yhyue.com/moapp/jydocs/services/stdlib"
+	"context"
+	"fmt"
 
 	"github.com/tal-tech/go-zero/core/logx"
 )
@@ -25,6 +26,12 @@ func NewDocOnLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocOnLogic
 
 func (l *DocOnLogic) DocOn(in *stdlib.DocChangeReq) (*stdlib.DocChangeResp, error) {
 	// todo: add your logic here and delete this line
+	err := stdlibService.ChangeDocumentOn(in.Id, in.Reason)
+	fmt.Println(err)
+	if err == nil {
+		return &stdlib.DocChangeResp{State: true}, nil
+	} else {
+		return &stdlib.DocChangeResp{State: false}, nil
+	}
 
-	return &stdlib.DocChangeResp{}, nil
 }

+ 17 - 16
rpc/stdlib/stdlib.proto

@@ -10,34 +10,35 @@ message DocQueryRequest {
 }
 
 message DocQueryResponse {
-    int32 code =1;    //响应代码
-    string message=2; //响应消息
-    repeated Doc docs=3;//文档列表集合,没有分页参数
-    int32 total = 4; //总数
+  int32 code = 1;    //响应代码
+  string message = 2; //响应消息
+  repeated Doc docs = 3;//文档列表集合,没有分页参数
+  int32 total = 4; //总数
 }
 
 
 
 message Doc {
-    string id=1;//文档id
-    string name=2;//文档名称
-    int32 type=3;//文档类型
-    int32 fileSize=4;//文档大小
-    int32 pageSize=5;//文档页码数
-    string tags=6;//文档标签
-    string userId=7;//上传人id
+  string id = 1;//文档id
+  string name = 2;//文档名称
+  int32 type = 3;//文档类型
+  int32 fileSize = 4;//文档大小
+  int32 pageSize = 5;//文档页码数
+  string tags = 6;//文档标签
+  string userId = 7;//上传人id
 }
 
 message DocChangeReq {
-	string id = 1; //文档id
+  string id = 1; //文档id
+  int32 reason = 2; //处理原因 1机审通过上架 2人审通过上加  10投诉下架 11过期下架
 }
 
 message DocChangeResp {
-	bool state = 1; //是否成功
+  bool state = 1; //是否成功
 }
 
 service Stdlib {
-  	rpc DocQuery(DocQueryRequest) returns(DocQueryResponse); //文档检索
-	rpc DocOn(DocChangeReq) returns(DocChangeResp); //文档上架
-	rpc DocOff(DocChangeReq) returns(DocChangeResp); //文档下架
+  rpc DocQuery(DocQueryRequest) returns(DocQueryResponse); //文档检索
+  rpc DocOn(DocChangeReq) returns(DocChangeResp); //文档上架
+  rpc DocOff(DocChangeReq) returns(DocChangeResp); //文档下架
 }

+ 29 - 20
rpc/stdlib/stdlib/stdlib.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
-// 	protoc-gen-go v1.23.0
-// 	protoc        v3.11.4
+// 	protoc-gen-go v1.25.0
+// 	protoc        v3.15.1
 // source: stdlib.proto
 
 package stdlib
@@ -255,7 +255,8 @@ type DocChangeReq struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` //文档id
+	Id     string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`          //文档id
+	Reason int32  `protobuf:"varint,2,opt,name=reason,proto3" json:"reason,omitempty"` //处理原因 1机审通过上架 2人审通过上加  10投诉下架 11过期下架
 }
 
 func (x *DocChangeReq) Reset() {
@@ -297,6 +298,13 @@ func (x *DocChangeReq) GetId() string {
 	return ""
 }
 
+func (x *DocChangeReq) GetReason() int32 {
+	if x != nil {
+		return x.Reason
+	}
+	return 0
+}
+
 type DocChangeResp struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -370,24 +378,25 @@ var file_stdlib_proto_rawDesc = []byte{
 	0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x61, 0x67, 0x65, 0x53, 0x69, 0x7a, 0x65,
 	0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
 	0x74, 0x61, 0x67, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x07,
-	0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x1e, 0x0a, 0x0c,
+	0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x36, 0x0a, 0x0c,
 	0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02,
-	0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x25, 0x0a, 0x0d,
-	0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a,
-	0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74,
-	0x61, 0x74, 0x65, 0x32, 0xb4, 0x01, 0x0a, 0x06, 0x53, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x12, 0x3d,
-	0x0a, 0x08, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x17, 0x2e, 0x73, 0x74, 0x64,
-	0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75,
-	0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63,
-	0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a,
-	0x05, 0x44, 0x6f, 0x63, 0x4f, 0x6e, 0x12, 0x14, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e,
-	0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73,
-	0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52,
-	0x65, 0x73, 0x70, 0x12, 0x35, 0x0a, 0x06, 0x44, 0x6f, 0x63, 0x4f, 0x66, 0x66, 0x12, 0x14, 0x2e,
-	0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65,
-	0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63,
-	0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
-	0x6f, 0x33,
+	0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06,
+	0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x65,
+	0x61, 0x73, 0x6f, 0x6e, 0x22, 0x25, 0x0a, 0x0d, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67,
+	0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01,
+	0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x32, 0xb4, 0x01, 0x0a, 0x06,
+	0x53, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x12, 0x3d, 0x0a, 0x08, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65,
+	0x72, 0x79, 0x12, 0x17, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51,
+	0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x74,
+	0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73,
+	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a, 0x05, 0x44, 0x6f, 0x63, 0x4f, 0x6e, 0x12, 0x14,
+	0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67,
+	0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f,
+	0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x35, 0x0a, 0x06, 0x44,
+	0x6f, 0x63, 0x4f, 0x66, 0x66, 0x12, 0x14, 0x2e, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44,
+	0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x73, 0x74,
+	0x64, 0x6c, 0x69, 0x62, 0x2e, 0x44, 0x6f, 0x63, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65,
+	0x73, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (

+ 1 - 1
rpc/stdlib/stdlibclient/stdlib.go

@@ -14,11 +14,11 @@ import (
 )
 
 type (
+	DocQueryRequest  = stdlib.DocQueryRequest
 	DocQueryResponse = stdlib.DocQueryResponse
 	Doc              = stdlib.Doc
 	DocChangeReq     = stdlib.DocChangeReq
 	DocChangeResp    = stdlib.DocChangeResp
-	DocQueryRequest  = stdlib.DocQueryRequest
 
 	Stdlib interface {
 		DocQuery(ctx context.Context, in *DocQueryRequest) (*DocQueryResponse, error)

+ 29 - 0
rpc/stdlib/test/doc_test.go

@@ -0,0 +1,29 @@
+package test
+
+import (
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlibclient"
+	"context"
+	"github.com/tal-tech/go-zero/core/discov"
+	"github.com/tal-tech/go-zero/zrpc"
+	"log"
+	"testing"
+	"time"
+)
+
+func Test_DocOn(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"192.168.3.240:2379"}, Key: "jydocs.stdlib.rpc"}}))
+	req := &stdlib.DocChangeReq{Id: "123", Reason: 1}
+	res, err := std.DocOn(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res.State)
+}
+func Test_DocOff(t *testing.T) {
+	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	std := stdlibclient.NewStdlib(zrpc.MustNewClient(zrpc.RpcClientConf{Etcd: discov.EtcdConf{Hosts: []string{"192.168.3.240:2379"}, Key: "jydocs.stdlib.rpc"}}))
+	req := &stdlib.DocChangeReq{Id: "123", Reason: 10}
+	res, err := std.DocOff(ctx, req)
+	log.Println("err ", err)
+	log.Println("req ", res.State)
+}

+ 78 - 0
services/stdlib/docChangeService.go

@@ -0,0 +1,78 @@
+package stdlib
+
+import (
+	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
+	"errors"
+	"gorm.io/gorm"
+	"time"
+)
+
+const DocOn = 1
+const DocOff = 0
+
+// 上架文档
+func ChangeDocumentOn(id string, reason int32) error {
+	// 查文档
+	docData := map[string]interface{}{}
+	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0", id).Find(&docData)
+	if rs.Error != nil {
+		return rs.Error
+	} else {
+		if docData["id"] == nil {
+			return errors.New("文档不存在")
+		}
+
+	}
+	// 上架
+	err := jyDocsRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
+		// 更新大库状态为上架 1-上架
+		if err := tx.Exec("update doc set downOrUp=? where id=? ", DocOn, id).Error; err != nil {
+			return err
+		}
+		// 存上架记录
+		date := time.Now().Local().Format("2006-01-02 15:04:05")
+		if err := tx.Exec("insert into doc_change_record (docId,date,downOrUp,reason) values (?,?,?,?)", id, date, DocOn, reason).Error; err != nil {
+			return err
+		}
+		// todo es加数据
+		//if rs := elastic.Save("index", "doc", docData); rs != true {
+		//	return errors.New("发布到检索库失败")
+		//}
+		return nil
+	})
+
+	return err
+}
+
+// 下架文档
+func ChangeDocumentOff(id string, reason int32) error {
+	// 查文档
+	docData := map[string]interface{}{}
+	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0", id).Find(&docData)
+	if rs.Error != nil {
+		return rs.Error
+	} else {
+		if docData["id"] == nil {
+			return errors.New("文档不存在")
+		}
+	}
+	// 下架
+	err := jyDocsRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
+		// 更新大库状态为下架 0-下架
+		if err := tx.Exec("update doc set downOrUp=? where id=? ", DocOff, id).Error; err != nil {
+			return err
+		}
+		// 存下架记录
+		date := time.Now().Local().Format("2006-01-02 15:04:05")
+		if err := tx.Exec("insert into doc_change_record (docId,date,downOrUp,reason) values (?,?,?,?)", id, date, DocOff, reason).Error; err != nil {
+			return err
+		}
+		//todo 从es删除数据
+		//if rs := elastic.DelById("index", "doc", id); rs != true {
+		//	return errors.New("从检索库删除失败")
+		//}
+		return nil
+	})
+
+	return err
+}