瀏覽代碼

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

wanghuidong 4 年之前
父節點
當前提交
18f3634aa4

+ 47 - 0
rpc/stdlib/internal/logic/docactivitylogic.go

@@ -0,0 +1,47 @@
+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"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DocActivityLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDocActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocActivityLogic {
+	return &DocActivityLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DocActivityLogic) DocActivity(in *stdlib.DocActivityReq) (*stdlib.DocActivityResp, error) {
+	// todo: add your logic here and delete this line
+	pageNum := 0
+	if int(in.PageNum) <= 0 {
+		pageNum = 0
+	}
+	res, count := stdlibService.DocActivityList(int(in.PageSize), pageNum)
+	docActivityResp := &stdlib.DocActivityResp{Code: 0, Msg: "ok", Total: int32(count)}
+	for _, v := range res {
+		docActivityResp.Docs = append(docActivityResp.Docs, &stdlib.DocActivity{
+			DocId:      v.DocId,
+			DocImg:     v.DocImg,
+			DocTitle:   v.DocTitle,
+			DocSummary: v.DocSummary,
+			ActivityId: int32(v.ActivityId),
+			Price:      int32(v.Price),
+			CostPrice:  int32(v.CostPrice),
+		})
+	}
+	return docActivityResp, nil
+}

+ 30 - 0
rpc/stdlib/internal/logic/docgetchecklogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DocGetCheckLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDocGetCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocGetCheckLogic {
+	return &DocGetCheckLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DocGetCheckLogic) DocGetCheck(in *stdlib.DocGetCheckReq) (*stdlib.DocGetCheckResp, error) {
+	// todo: add your logic here and delete this line
+
+	return &stdlib.DocGetCheckResp{}, nil
+}

+ 30 - 0
rpc/stdlib/internal/logic/docgetcontentlogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
+	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DocGetContentLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDocGetContentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocGetContentLogic {
+	return &DocGetContentLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DocGetContentLogic) DocGetContent(in *stdlib.DocGetCheckReq) (*stdlib.DocGetContentResp, error) {
+	// todo: add your logic here and delete this line
+
+	return &stdlib.DocGetContentResp{}, nil
+}

+ 5 - 8
rpc/stdlib/internal/logic/docofflogic.go

@@ -3,7 +3,7 @@ package logic
 import (
 	stdlibService "app.yhyue.com/moapp/jydocs/services/stdlib"
 	"context"
-	"fmt"
+	"log"
 
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/internal/svc"
 	"app.yhyue.com/moapp/jydocs/rpc/stdlib/stdlib"
@@ -27,11 +27,8 @@ 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
-	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
-	}
+	status := stdlibService.ChangeDocumentOff(in.Id, in.Reason)
+	log.Println(status,"返回值-----------")
+	return &stdlib.DocChangeResp{State: status}, nil
+
 }

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

@@ -5,8 +5,6 @@ import (
 	"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"
 )
 
@@ -26,12 +24,6 @@ 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
-	}
-
+	status := stdlibService.ChangeDocumentOn(in.Id, in.Reason)
+	return &stdlib.DocChangeResp{State: status}, nil
 }

+ 30 - 0
rpc/stdlib/internal/logic/docstatisticslogic.go

@@ -0,0 +1,30 @@
+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"
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type DocStatisticsLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDocStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocStatisticsLogic {
+	return &DocStatisticsLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DocStatisticsLogic) DocStatistics(in *stdlib.DocStatisticsReq) (*stdlib.DocChangeResp, error) {
+	// todo: add your logic here and delete this line
+	state := stdlibService.DocStatistics(in.DocId, int(in.DocStatisticsType))
+	return &stdlib.DocChangeResp{State: state}, nil
+}

+ 20 - 0
rpc/stdlib/internal/server/stdlibserver.go

@@ -35,3 +35,23 @@ func (s *StdlibServer) DocOff(ctx context.Context, in *stdlib.DocChangeReq) (*st
 	l := logic.NewDocOffLogic(ctx, s.svcCtx)
 	return l.DocOff(in)
 }
+
+func (s *StdlibServer) DocStatistics(ctx context.Context, in *stdlib.DocStatisticsReq) (*stdlib.DocChangeResp, error) {
+	l := logic.NewDocStatisticsLogic(ctx, s.svcCtx)
+	return l.DocStatistics(in)
+}
+
+func (s *StdlibServer) DocGetCheck(ctx context.Context, in *stdlib.DocGetCheckReq) (*stdlib.DocGetCheckResp, error) {
+	l := logic.NewDocGetCheckLogic(ctx, s.svcCtx)
+	return l.DocGetCheck(in)
+}
+
+func (s *StdlibServer) DocGetContent(ctx context.Context, in *stdlib.DocGetCheckReq) (*stdlib.DocGetContentResp, error) {
+	l := logic.NewDocGetContentLogic(ctx, s.svcCtx)
+	return l.DocGetContent(in)
+}
+
+func (s *StdlibServer) DocActivity(ctx context.Context, in *stdlib.DocActivityReq) (*stdlib.DocActivityResp, error) {
+	l := logic.NewDocActivityLogic(ctx, s.svcCtx)
+	return l.DocActivity(in)
+}

+ 69 - 12
rpc/stdlib/stdlib.proto

@@ -2,30 +2,33 @@ syntax = "proto3";
 
 package stdlib;
 
-
-
 message DocQueryRequest {
-  string keyWords = 1; //检索词
-  int32 pageNum = 2; //页码
+  int32 pageNum = 1; //页码 
+  int32 pageSize = 2; //每页数量
+  string keyWords = 3; //检索词  文档名检索  模糊
+  repeated string itemArr = 4;  // 分类 []string
+  repeated string tagArr = 5;  // 标签 []string
+  int32 publishTimeSort = 6;  // 发布时间排序 1正序 2倒序
+  int32 downloadSort = 7;		// 下载次数排序 1正序 2倒序
+  int32	viewSort = 8;			// 浏览量排序 1正序 2倒序
 }
 
 message DocQueryResponse {
   int32 code = 1;    //响应代码
-  string message = 2; //响应消息
+  string msg = 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 docId = 1;//文档id
+  string docName = 2;//文档名称
+  int32 docType = 3;//文档类型
+  int32 docFileSize = 4;//文档大小
+  int32 docPageSize = 5;//文档页码数
   string tags = 6;//文档标签
   string userId = 7;//上传人id
+  string docSummary = 8; //摘要
 }
 
 message DocChangeReq {
@@ -37,8 +40,62 @@ message DocChangeResp {
   bool state = 1; //是否成功
 }
 
+message DocStatisticsReq {
+  string docId = 1; //文档id
+  int32 DocStatisticsType = 2; //文档统计类型 1增加下载次数 2增加浏览次数 3评分
+}
+
+message DocGetCheckReq {
+  string docId = 1; //文档id
+  string userId = 2; //用户id
+}
+
+message DocGetCheckResp {
+  int32 code = 1;    //响应代码
+  string msg = 2; //响应消息
+  string docName = 3;//文档名称
+  int32 docType = 4;//文档类型
+  int32 docFileSize = 5;//文档大小
+  int32 docPageSize = 6;//文档页码数
+  string tags = 7;//文档标签
+  string userId = 8;//上传人id
+  string docSummary = 9; //摘要
+}
+
+message DocGetContentResp {
+  int32 code = 1;    //响应代码
+  string msg = 2; //响应消息
+  bytes docContent = 3; //文件内容
+}
+
+message DocActivityReq {
+  int32 pageNum = 1; //页码 
+  int32 pageSize = 2; //每页数量
+}
+
+message DocActivity {
+  string docId = 1; //文档id
+  int32 activityId = 2; //活动id
+  string docTitle = 3; //文档标题
+  string docSummary = 4; //文档摘要
+  string docImg = 5; //文档配图
+  int32 price = 6; //活动价
+  int32 costPrice = 7; //成本价
+}
+
+message DocActivityResp {
+  int32 code = 1;    //响应代码
+  string msg = 2; //响应消息
+  repeated DocActivity docs = 3;//活动文档列表
+  int32 total = 4; //总数
+}
+
 service Stdlib {
   rpc DocQuery(DocQueryRequest) returns(DocQueryResponse); //文档检索
   rpc DocOn(DocChangeReq) returns(DocChangeResp); //文档上架
   rpc DocOff(DocChangeReq) returns(DocChangeResp); //文档下架
+  rpc DocStatistics(DocStatisticsReq) returns(DocChangeResp); //文档浏览次数下载次数处理
+  rpc DocGetCheck(DocGetCheckReq) returns(DocGetCheckResp); //获取文档-检查文档是否可获取,返回页面数据
+  rpc DocGetContent(DocGetCheckReq) returns(DocGetContentResp); //获取文档-页面打开pdf调用查询oss
+  rpc DocActivity(DocActivityReq) returns(DocActivityResp); //活动文档列表
 }

文件差異過大導致無法顯示
+ 797 - 149
rpc/stdlib/stdlib/stdlib.pb.go


+ 36 - 5
rpc/stdlib/stdlibclient/stdlib.go

@@ -14,16 +14,27 @@ import (
 )
 
 type (
-	DocQueryRequest  = stdlib.DocQueryRequest
-	DocQueryResponse = stdlib.DocQueryResponse
-	Doc              = stdlib.Doc
-	DocChangeReq     = stdlib.DocChangeReq
-	DocChangeResp    = stdlib.DocChangeResp
+	Doc               = stdlib.Doc
+	DocChangeReq      = stdlib.DocChangeReq
+	DocChangeResp     = stdlib.DocChangeResp
+	DocGetCheckResp   = stdlib.DocGetCheckResp
+	DocActivity       = stdlib.DocActivity
+	DocActivityResp   = stdlib.DocActivityResp
+	DocQueryRequest   = stdlib.DocQueryRequest
+	DocQueryResponse  = stdlib.DocQueryResponse
+	DocStatisticsReq  = stdlib.DocStatisticsReq
+	DocGetCheckReq    = stdlib.DocGetCheckReq
+	DocGetContentResp = stdlib.DocGetContentResp
+	DocActivityReq    = stdlib.DocActivityReq
 
 	Stdlib interface {
 		DocQuery(ctx context.Context, in *DocQueryRequest) (*DocQueryResponse, error)
 		DocOn(ctx context.Context, in *DocChangeReq) (*DocChangeResp, error)
 		DocOff(ctx context.Context, in *DocChangeReq) (*DocChangeResp, error)
+		DocStatistics(ctx context.Context, in *DocStatisticsReq) (*DocChangeResp, error)
+		DocGetCheck(ctx context.Context, in *DocGetCheckReq) (*DocGetCheckResp, error)
+		DocGetContent(ctx context.Context, in *DocGetCheckReq) (*DocGetContentResp, error)
+		DocActivity(ctx context.Context, in *DocActivityReq) (*DocActivityResp, error)
 	}
 
 	defaultStdlib struct {
@@ -51,3 +62,23 @@ func (m *defaultStdlib) DocOff(ctx context.Context, in *DocChangeReq) (*DocChang
 	client := stdlib.NewStdlibClient(m.cli.Conn())
 	return client.DocOff(ctx, in)
 }
+
+func (m *defaultStdlib) DocStatistics(ctx context.Context, in *DocStatisticsReq) (*DocChangeResp, error) {
+	client := stdlib.NewStdlibClient(m.cli.Conn())
+	return client.DocStatistics(ctx, in)
+}
+
+func (m *defaultStdlib) DocGetCheck(ctx context.Context, in *DocGetCheckReq) (*DocGetCheckResp, error) {
+	client := stdlib.NewStdlibClient(m.cli.Conn())
+	return client.DocGetCheck(ctx, in)
+}
+
+func (m *defaultStdlib) DocGetContent(ctx context.Context, in *DocGetCheckReq) (*DocGetContentResp, error) {
+	client := stdlib.NewStdlibClient(m.cli.Conn())
+	return client.DocGetContent(ctx, in)
+}
+
+func (m *defaultStdlib) DocActivity(ctx context.Context, in *DocActivityReq) (*DocActivityResp, error) {
+	client := stdlib.NewStdlibClient(m.cli.Conn())
+	return client.DocActivity(ctx, in)
+}

+ 15 - 5
rpc/stdlib/test/doc_test.go

@@ -12,18 +12,28 @@ import (
 )
 
 func Test_DocOn(t *testing.T) {
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	ctx, _ := context.WithTimeout(context.Background(), 10*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)
+	if res.State == true {
+		log.Println("req true")
+	} else {
+		log.Println("req false", res)
+	}
 }
 func Test_DocOff(t *testing.T) {
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	ctx, _ := context.WithTimeout(context.Background(), 120*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)
-}
+	if res.State == true {
+		log.Println("req true")
+	} else {
+		log.Println("req false", res)
+	}
+	//log.Println("err ", err)
+	//log.Println("req ", res)
+}

+ 11 - 2
rpc/userlib/internal/logic/docdeletelogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	userLibService "app.yhyue.com/moapp/jydocs/services/userlib"
 	"context"
 
 	"app.yhyue.com/moapp/jydocs/rpc/userlib/internal/svc"
@@ -25,6 +26,14 @@ func NewDocDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocDele
 
 func (l *DocDeleteLogic) DocDelete(in *userlib.UserDeleteRequest) (*userlib.UserDeleteResponse, error) {
 	// todo: add your logic here and delete this line
-
-	return &userlib.UserDeleteResponse{}, nil
+	result := &userlib.UserDeleteResponse{}
+	b := userLibService.UserDocDelete(in.DocId)
+	if b {
+		result.Code = 1
+		result.Message = "删除成功"
+		return result,nil
+	}
+	result.Code = 0
+	result.Message = "删除失败"
+	return result, nil
 }

+ 17 - 0
rpc/userlib/test/userLib_test.go

@@ -36,3 +36,20 @@ func Test_UserDocCollect(t *testing.T) {
 	}
 	log.Print("UserDoc Collect call response:", resp)
 }
+
+func Test_UserDocDelete(t *testing.T)  {
+	client := zrpc.MustNewClient(zrpc.RpcClientConf{
+		Etcd: discov.EtcdConf{
+			Hosts: []string{"192.168.3.240:2379"},
+			Key:   "jydocs.userlib.rpc",
+		},
+	})
+	userLib := userlibclient.NewUserLib(client)
+	resp, err := userLib.DocDelete(context.Background(), &userlibclient.UserDeleteRequest{
+		DocId: "8",
+	})
+	if err != nil {
+		log.Println("UserDoc Collect call error:", err)
+	}
+	log.Print("UserDoc Collect call response:", resp)
+}

+ 29 - 10
services/model/stdlib.go

@@ -25,21 +25,40 @@ type UserMoneyRecord struct {
 	DocSummary       string `json:"docSummary"`
 }
 
+func (ud *UserMoneyRecord) TableName() string {
+	return "doc"
+}
+
 type UserDoc struct {
 	BaseModel
-	UserId        string `json:"user_id"  gorm:"column:userId"`
-	DocId         string `json:"doc_id" gorm:"column:docId"`
-	DocCategory   int    `json:"doc_category" gorm:"column:docCategory"`
-	IsDelete      int    `json:"is_delete" gorm:"column:isDelete"`
-	DocName       string `json:"doc_name" gorm:"column:docName"`
-	DocFileType   int    `json:"doc_file_type" gorm:"column:docFileType"`
-	DocFileSuffix string `json:"doc_file_suffix" gorm:"column:docFileSuffix"`
-	DocFileSize   int    `json:"doc_file_size" gorm:"column:docFileSize"`
-	DocPageSize   int    `json:"doc_page_size" gorm:"column:docPageSize"`
-	DocSummary    string `json:"doc_summary" gorm:"column:docSummary"`
+	UserId          string `json:"user_id"  gorm:"column:userId"`
+	DocId           string `json:"doc_id" gorm:"column:docId"`
+	DocCategory     int    `json:"doc_category" gorm:"column:docCategory"`
+	IsDelete        int    `json:"is_delete" gorm:"column:isDelete"`
+	DocName         string `json:"doc_name" gorm:"column:docName"`
+	DocFileType     int    `json:"doc_file_type" gorm:"column:docFileType"`
+	DocFileSuffix   string `json:"doc_file_suffix" gorm:"column:docFileSuffix"`
+	DocFileSize     int    `json:"doc_file_size" gorm:"column:docFileSize"`
+	DocPageSize     int    `json:"doc_page_size" gorm:"column:docPageSize"`
+	DocSummary      string `json:"doc_summary" gorm:"column:docSummary"`
 	DocSourceUserId string `json:"doc_source_user_id" gorm:"column:docSourceUserId"`
 }
 
 func (ud *UserDoc) TableName() string {
 	return "user_doc"
 }
+
+type DocActivity struct {
+	Id         int    `json:"id" gorm:"primaryKey"`
+	DocId      string `json:"docId"`
+	ActivityId int    `json:"activityId"`
+	DocTitle   string `json:"docTitle"`
+	DocSummary string `json:"docSummary"`
+	DocImg     string `json:"docImg"`
+	Price      int    `json:"price"`
+	CostPrice  int    `json:"costPrice"`
+}
+
+func (ud *DocActivity) TableName() string {
+	return "doc_activity"
+}

+ 18 - 0
services/stdlib/docActivity.go

@@ -0,0 +1,18 @@
+package stdlib
+
+import (
+	"app.yhyue.com/moapp/jydocs/services/model"
+	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
+)
+
+func DocActivityList(pageSize, pageNum int) ([]model.DocActivity, int) {
+	docActivity := []model.DocActivity{}
+	var count int64
+	jyDocsRpcUtil.GetJyDocsDB().Model(&model.DocActivity{}).Count(&count)
+	if count > 0 {
+		jyDocsRpcUtil.GetJyDocsDB().Model(&model.DocActivity{}).Offset(pageNum * pageSize).Limit(pageSize).Find(&docActivity)
+	} else {
+		count = 0
+	}
+	return docActivity, int(count)
+}

+ 35 - 20
services/stdlib/docChangeService.go

@@ -1,9 +1,11 @@
 package stdlib
 
 import (
+	elastic "app.yhyue.com/moapp/jybase/esv7"
 	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
 	"errors"
 	"gorm.io/gorm"
+	"log"
 	"time"
 )
 
@@ -11,17 +13,18 @@ const DocOn = 1
 const DocOff = 0
 
 // 上架文档
-func ChangeDocumentOn(id string, reason int32) error {
+func ChangeDocumentOn(id string, reason int32) bool {
 	// 查文档
 	docData := map[string]interface{}{}
-	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0", id).Find(&docData)
+	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0 and downOrUp=0", id).Find(&docData)
 	if rs.Error != nil {
-		return rs.Error
+		log.Println("上架文档 error:"+id, rs.Error)
+		return false
 	} else {
 		if docData["id"] == nil {
-			return errors.New("文档不存在")
+			log.Println("上架文档 error:"+id, "文档不存在或已经被上架")
+			return false
 		}
-
 	}
 	// 上架
 	err := jyDocsRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
@@ -34,26 +37,33 @@ func ChangeDocumentOn(id string, reason int32) error {
 		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("发布到检索库失败")
-		//}
+		docData["_id"] = docData["id"]
+		// todo es加数据 索引待替换 测试
+		if rs := elastic.Save("doc_lib", "doc", docData); rs != true {
+			return errors.New("发布到检索库失败")
+		}
 		return nil
 	})
-
-	return err
+	if err != nil {
+		log.Println("上架文档 error:"+id, err)
+		return false
+	}
+	log.Println("上架文档成功:"+id)
+	return true
 }
 
 // 下架文档
-func ChangeDocumentOff(id string, reason int32) error {
+func ChangeDocumentOff(id string, reason int32) bool {
 	// 查文档
 	docData := map[string]interface{}{}
-	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0", id).Find(&docData)
+	rs := jyDocsRpcUtil.GetJyDocsDB().Table("doc").Where("id=? and isDelete=0 and downOrUp=1", id).Find(&docData)
 	if rs.Error != nil {
-		return rs.Error
+		log.Println("下架文档 error:"+id, rs.Error)
+		return false
 	} else {
 		if docData["id"] == nil {
-			return errors.New("文档不存在")
+			log.Println("下架文档 error:"+id, "文档不存在或已经被下架")
+			return false
 		}
 	}
 	// 下架
@@ -67,12 +77,17 @@ func ChangeDocumentOff(id string, reason int32) error {
 		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("从检索库删除失败")
-		//}
+		//todo 从es删除数据 索引待替换 及测试
+		if rs := elastic.DelById("doc_lib", "doc", id); rs != true {
+			return errors.New("从检索库删除失败")
+		}
 		return nil
 	})
 
-	return err
+	if err != nil {
+		log.Println("下架文档 error:"+id, err)
+		return false
+	}
+	log.Println("下架文档成功:"+id)
+	return true
 }

+ 36 - 0
services/stdlib/docStatistics.go

@@ -0,0 +1,36 @@
+package stdlib
+
+import (
+	"log"
+	"time"
+
+	elastic "app.yhyue.com/moapp/jybase/esv7"
+	jyDocsRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
+)
+
+func DocStatistics(docId string, dtype int) bool {
+	sqlStr := ""
+	state := false
+	if dtype == 1 { //下载次数增加1
+		sqlStr = "update doc_statistics set downTimes = downTimes + 1,updateDate = ? where docId = ?"
+	} else if dtype == 2 { //浏览次数增加1
+		sqlStr = "update doc_statistics set viewTimes = viewTimes + 1,updateDate = ? where docId = ?"
+	}
+	//mysql
+	log.Println("sql ", sqlStr)
+	updateDate := time.Now().Format("2006-01-02 15:04:05")
+	err := jyDocsRpcUtil.GetJyDocsDB().Exec(sqlStr, updateDate, docId).Error
+	if err != nil {
+		//es
+		data := map[string]interface{}{}
+		jyDocsRpcUtil.GetJyDocsDB().Table("doc_statistics").Where("docId = ?", docId).Find(&data)
+		if len(data) > 0 {
+			//是否缓存
+			//TODO
+			if ok := elastic.UpdateNewDoc("jydocs", "jydocs", data); ok {
+				state = true
+			}
+		}
+	}
+	return state
+}

+ 31 - 0
services/userlib/userDocService.go

@@ -5,6 +5,7 @@ import (
 	docRpcUtil "app.yhyue.com/moapp/jydocs/services/util"
 	"gorm.io/gorm"
 	"log"
+	"time"
 )
 
 func UserDocCollect(userDoc *model.UserDoc, cost int) bool {
@@ -31,3 +32,33 @@ func UserDocCollect(userDoc *model.UserDoc, cost int) bool {
 	}
 	return true
 }
+
+func UserDocDelete(docId string) bool {
+	err := docRpcUtil.GetJyDocsDB().Transaction(func(tx *gorm.DB) error {
+		orm := docRpcUtil.GetJyDocsDB()
+		docData := model.UserDoc{}
+		//查询用户文档详情
+		orm.Select("userId,docId").First(&docData,docId)
+		log.Println(docData.UserId)
+		log.Println(docData.DocId)
+
+
+		//逻辑删除
+		err := docRpcUtil.GetJyDocsDB().Exec("UPDATE user_doc SET isDelete = 1 WHERE id = ?",docId).Error
+		if err != nil {
+			tx.Rollback()
+			return err
+		}
+		//删除记录
+		err = docRpcUtil.GetJyDocsDB().Exec("insert into del_record (docId, userId, date, operate, viewType, source, shareUserId) values (?,?,?,?,?,?,?)",docId,docData.UserId,time.Now(),1,1,1,1).Error
+		if err != nil {
+			tx.Rollback()
+			return err
+		}
+		return nil
+	})
+	if err != nil {
+		return false
+	}
+	return true
+}

+ 2 - 1
services/util/baseInit.go

@@ -1,10 +1,11 @@
 package util
 
 import (
+	"log"
+
 	elastic "app.yhyue.com/moapp/jybase/esv7"
 	"app.yhyue.com/moapp/jybase/mysql"
 	"gorm.io/gorm"
-	"log"
 )
 
 type MysqlDBConfig struct {

部分文件因文件數量過多而無法顯示