xuzhiheng 4 年之前
父節點
當前提交
56b5945822

+ 1 - 1
rpc/stdlib/etc/stdlib.yaml

@@ -1,5 +1,5 @@
 Name: jydocs.stdlib.rpc
-ListenOn: 127.0.0.1:8080
+ListenOn: 192.168.20.36:8080
 JyDocsMysqlDB:
   DriverName: "mysql"
   DataSourceName: "root:Topnet123@tcp(192.168.3.11:3366)/jydocs?charset=utf8mb4&parseTime=true&loc=Local"

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

@@ -2,6 +2,7 @@ package logic
 
 import (
 	"context"
+	"log"
 
 	"app.yhyue.com/moapp/jy_docs/rpc/stdlib/internal/svc"
 	"app.yhyue.com/moapp/jy_docs/rpc/stdlib/stdlib"
@@ -32,6 +33,8 @@ func (l *DocActivityLogic) DocActivity(in *stdlib.DocActivityReq) (*stdlib.DocAc
 	}
 	res, count := stdlibService.DocActivityList(int(in.PageSize), pageNum)
 	docActivityResp := &stdlib.DocActivityResp{Code: 0, Msg: "ok", Total: int32(count)}
+	log.Println("res ", res)
+	log.Println("count ", count)
 	for _, v := range res {
 		docActivityResp.Docs = append(docActivityResp.Docs, &stdlib.DocActivity{
 			DocId:      v.DocId,

+ 2 - 2
rpc/stdlib/test/doc_test.go

@@ -42,7 +42,7 @@ func Test_DocOff(t *testing.T) {
 func Test_DocActivity(t *testing.T) {
 	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.DocActivityReq{PageNum: 0, PageSize: 10}
+	req := &stdlib.DocActivityReq{PageNum: 1, PageSize: 10}
 	res, err := std.DocActivity(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)
@@ -51,7 +51,7 @@ func Test_DocActivity(t *testing.T) {
 func Test_DocStatistics(t *testing.T) {
 	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.DocStatisticsReq{DocId: "111", DocStatisticsType: 1}
+	req := &stdlib.DocStatisticsReq{DocId: "123", DocStatisticsType: 1}
 	res, err := std.DocStatistics(ctx, req)
 	log.Println("err ", err)
 	log.Println("req ", res)

+ 32 - 30
services/model/stdlib.go

@@ -5,29 +5,30 @@ import (
 )
 
 type Doc struct {
-	Id               string    `json:"id" gorm:"id"`
-	UserId           string    `json:"userId" gorm:"column:userId"`
-	DocName          string    `json:"docName" gorm:"column:docName"`
-	DocFileType      int       `json:"docFileType" gorm:"column:docFileType"`
-	DocFileSuffix    string    `json:"docFileSuffix" gorm:"column:docFileSuffix"`
-	DocFileSize      int       `json:"docFileSize" gorm:"column:docFileSize"`
-	DocPageSize      int       `json:"docPageSize" gorm:"column:docPageSize"`
-	DocTags          string    `json:"docTags" gorm:"column:docTags"`
-	DocClassLevelOne string    `json:"docClassLevelOne" gorm:"column:docClassLevelOne"`
-	DocClassLevelTwo string    `json:"docClassLevelTwo" gorm:"column:docClassLevelTwo"`
-	UploadDate       string    `json:"uploadDate" gorm:"column:uploadDate"`
-	IsDelete         int       `json:"isDelete" gorm:"column:isDelete"`
-	OssDocId         string    `json:"ossDocId" gorm:"column:ossDocId"`
-	OssDocUrl        string    `json:"ossDocUrl" gorm:"column:ossDocUrl"`
-	Md5              string    `json:"md5" gorm:"column:md5"`
-	OssPdfId         string    `json:"ossPdfId" gorm:"column:ossPdfId"`
-	OssPdfUrl        string    `json:"ossPdfUrl" gorm:"column:ossPdfUrl"`
-	OssTxtId         string    `json:"ossTxtId" gorm:"column:ossTxtId"`
-	OssTxtUrl        string    `json:"ossTxtUrl" gorm:"column:ossTxtUrl"`
-	Price            int       `json:"price" gorm:"column:price"`
-	DownOrUp         int       `json:"downOrUp" gorm:"column:downOrUp"`
-	DocSummary       string    `json:"docSummary" gorm:"column:docSummary"`
+	Id               string `json:"id" gorm:"id"`
+	UserId           string `json:"userId" gorm:"column:userId"`
+	DocName          string `json:"docName" gorm:"column:docName"`
+	DocFileType      int    `json:"docFileType" gorm:"column:docFileType"`
+	DocFileSuffix    string `json:"docFileSuffix" gorm:"column:docFileSuffix"`
+	DocFileSize      int    `json:"docFileSize" gorm:"column:docFileSize"`
+	DocPageSize      int    `json:"docPageSize" gorm:"column:docPageSize"`
+	DocTags          string `json:"docTags" gorm:"column:docTags"`
+	DocClassLevelOne string `json:"docClassLevelOne" gorm:"column:docClassLevelOne"`
+	DocClassLevelTwo string `json:"docClassLevelTwo" gorm:"column:docClassLevelTwo"`
+	UploadDate       string `json:"uploadDate" gorm:"column:uploadDate"`
+	IsDelete         int    `json:"isDelete" gorm:"column:isDelete"`
+	OssDocId         string `json:"ossDocId" gorm:"column:ossDocId"`
+	OssDocUrl        string `json:"ossDocUrl" gorm:"column:ossDocUrl"`
+	Md5              string `json:"md5" gorm:"column:md5"`
+	OssPdfId         string `json:"ossPdfId" gorm:"column:ossPdfId"`
+	OssPdfUrl        string `json:"ossPdfUrl" gorm:"column:ossPdfUrl"`
+	OssTxtId         string `json:"ossTxtId" gorm:"column:ossTxtId"`
+	OssTxtUrl        string `json:"ossTxtUrl" gorm:"column:ossTxtUrl"`
+	Price            int    `json:"price" gorm:"column:price"`
+	DownOrUp         int    `json:"downOrUp" gorm:"column:downOrUp"`
+	DocSummary       string `json:"docSummary" gorm:"column:docSummary"`
 }
+
 func (ud *Doc) TableName() string {
 	return "doc"
 }
@@ -56,13 +57,14 @@ func (ud *UserDoc) TableName() string {
 
 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"`
+	DocId      string `json:"doc_id" gorm:"column:docId"`
+	ActivityId int    `json:"activity_id" gorm:"column:activityId"`
+	AppId      string `json:"app_id" gorm:"column:appId"`
+	DocTitle   string `json:"doc_title" gorm:"column:docTitle"`
+	DocSummary string `json:"doc_summary" gorm:"column:docSummary"`
+	DocImg     string `json:"doc_img" gorm:"column:docImg"`
+	Price      int    `json:"price" gorm:"column:price"`
+	CostPrice  int    `json:"cost_price" gorm:"column:costPrice"`
 }
 
 func (ud *DocActivity) TableName() string {
@@ -79,4 +81,4 @@ type UserDocData struct {
 
 func (ud *UserDocData) TableName() string {
 	return "user_doc"
-}
+}

+ 6 - 2
services/stdlib/docActivity.go

@@ -1,18 +1,22 @@
 package stdlib
 
 import (
+	"log"
+
 	"app.yhyue.com/moapp/jy_docs/services/model"
 	jyDocsRpcUtil "app.yhyue.com/moapp/jy_docs/services/util"
 )
 
 func DocActivityList(pageSize, pageNum int) ([]model.DocActivity, int) {
-	docActivity := []model.DocActivity{}
+	var docActivity []model.DocActivity
+	// var docs []map[string]interface{}
 	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)
+		jyDocsRpcUtil.GetJyDocsDB().Offset((pageNum - 1) * pageSize).Limit(pageSize).Find(&docActivity)
 	} else {
 		count = 0
 	}
+	log.Println("docActivity ", docActivity)
 	return docActivity, int(count)
 }

+ 1 - 1
services/stdlib/docStatistics.go

@@ -19,7 +19,7 @@ func DocStatistics(docId string, dtype int) bool {
 	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 {
+	if err == nil {
 		state = true
 	}
 	return state