Browse Source

recommend

May1145 1 năm trước cách đây
mục cha
commit
65bde4324c

+ 6 - 4
trading-go/bin/config/config.yml

@@ -8,9 +8,11 @@ mysql:
   password: Cherry1145
   charset: utf8
 redis:
-  addr: localhost:6379
-  password:
-  db: 0
+  addr: "localhost:6379"
+  password: ""
+  db: 1
   poolsize: 20
 time:
-  time: 2023-8-16
+  time: 2023-8-16
+gorse:
+  addr: "http://localhost:8086"

+ 48 - 13
trading-go/bin/docs/docs.go

@@ -271,13 +271,27 @@ const docTemplate = `{
                 }
             }
         },
-        "/chat/from": {
+        "/chat/from/{page}/{pageSize}": {
             "get": {
                 "tags": [
                     "聊天模块"
                 ],
                 "summary": "获取未过期且来源为特定用户的聊天记录",
                 "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
                     {
                         "type": "string",
                         "description": "用户id",
@@ -296,13 +310,27 @@ const docTemplate = `{
                 }
             }
         },
-        "/chat/to": {
+        "/chat/to/{page}/{pageSize}": {
             "get": {
                 "tags": [
                     "聊天模块"
                 ],
                 "summary": "获取未过期且目标为特定用户的聊天记录",
                 "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
                     {
                         "type": "string",
                         "description": "用户id",
@@ -440,6 +468,20 @@ const docTemplate = `{
                         "name": "id",
                         "in": "path",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "访问的用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "访问时间的时间戳",
+                        "name": "date",
+                        "in": "query",
+                        "required": true
                     }
                 ],
                 "responses": {
@@ -452,7 +494,7 @@ const docTemplate = `{
                 }
             }
         },
-        "/goods/recommend/{page}/{pageSize}": {
+        "/goods/recommend": {
             "get": {
                 "produces": [
                     "application/json"
@@ -471,16 +513,9 @@ const docTemplate = `{
                     },
                     {
                         "type": "integer",
-                        "description": "页数",
-                        "name": "page",
-                        "in": "path",
-                        "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "一页的大小",
-                        "name": "pageSize",
-                        "in": "path",
+                        "description": "推荐的数目",
+                        "name": "size",
+                        "in": "query",
                         "required": true
                     }
                 ],

+ 48 - 13
trading-go/bin/docs/swagger.json

@@ -264,13 +264,27 @@
                 }
             }
         },
-        "/chat/from": {
+        "/chat/from/{page}/{pageSize}": {
             "get": {
                 "tags": [
                     "聊天模块"
                 ],
                 "summary": "获取未过期且来源为特定用户的聊天记录",
                 "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
                     {
                         "type": "string",
                         "description": "用户id",
@@ -289,13 +303,27 @@
                 }
             }
         },
-        "/chat/to": {
+        "/chat/to/{page}/{pageSize}": {
             "get": {
                 "tags": [
                     "聊天模块"
                 ],
                 "summary": "获取未过期且目标为特定用户的聊天记录",
                 "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页数",
+                        "name": "page",
+                        "in": "path",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "一页的大小",
+                        "name": "pageSize",
+                        "in": "path",
+                        "required": true
+                    },
                     {
                         "type": "string",
                         "description": "用户id",
@@ -433,6 +461,20 @@
                         "name": "id",
                         "in": "path",
                         "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "访问的用户id",
+                        "name": "uid",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "访问时间的时间戳",
+                        "name": "date",
+                        "in": "query",
+                        "required": true
                     }
                 ],
                 "responses": {
@@ -445,7 +487,7 @@
                 }
             }
         },
-        "/goods/recommend/{page}/{pageSize}": {
+        "/goods/recommend": {
             "get": {
                 "produces": [
                     "application/json"
@@ -464,16 +506,9 @@
                     },
                     {
                         "type": "integer",
-                        "description": "页数",
-                        "name": "page",
-                        "in": "path",
-                        "required": true
-                    },
-                    {
-                        "type": "integer",
-                        "description": "一页的大小",
-                        "name": "pageSize",
-                        "in": "path",
+                        "description": "推荐的数目",
+                        "name": "size",
+                        "in": "query",
                         "required": true
                     }
                 ],

+ 36 - 11
trading-go/bin/docs/swagger.yaml

@@ -306,9 +306,19 @@ paths:
       summary: 与服务端进行websocket连接,请使用postman测试
       tags:
       - 聊天模块
-  /chat/from:
+  /chat/from/{page}/{pageSize}:
     get:
       parameters:
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
       - description: 用户id
         in: query
         name: uid
@@ -322,9 +332,19 @@ paths:
       summary: 获取未过期且来源为特定用户的聊天记录
       tags:
       - 聊天模块
-  /chat/to:
+  /chat/to/{page}/{pageSize}:
     get:
       parameters:
+      - description: 页数
+        in: path
+        name: page
+        required: true
+        type: integer
+      - description: 一页的大小
+        in: path
+        name: pageSize
+        required: true
+        type: integer
       - description: 用户id
         in: query
         name: uid
@@ -436,6 +456,16 @@ paths:
         name: id
         required: true
         type: integer
+      - description: 访问的用户id
+        in: query
+        name: uid
+        required: true
+        type: integer
+      - description: 访问时间的时间戳
+        in: query
+        name: date
+        required: true
+        type: integer
       produces:
       - application/json
       responses:
@@ -446,7 +476,7 @@ paths:
       summary: 获取商品详细信息
       tags:
       - 商品模块
-  /goods/recommend/{page}/{pageSize}:
+  /goods/recommend:
     get:
       parameters:
       - description: 用户id
@@ -454,14 +484,9 @@ paths:
         name: id
         required: true
         type: integer
-      - description: 页数
-        in: path
-        name: page
-        required: true
-        type: integer
-      - description: 一页的大小
-        in: path
-        name: pageSize
+      - description: 推荐的数目
+        in: query
+        name: size
         required: true
         type: integer
       produces:

BIN
trading-go/bin/pics/1694489226Snipaste_2023-09-12_11-19-46.png


BIN
trading-go/bin/pics/1694489322Snipaste_2023-09-12_11-19-46.png


BIN
trading-go/bin/pics/1694494659R-C.jpg


BIN
trading-go/bin/trading-go


+ 1 - 1
trading-go/config/config.yml

@@ -15,4 +15,4 @@ redis:
 time:
   time: 2023-8-16
 gorse:
-  addr: "http://localhost:8086"
+  addr: "http://47.109.143.151:8088"

+ 13 - 2
trading-go/controller/goodscontroller.go

@@ -3,6 +3,7 @@ package controller
 import (
 	"github.com/gin-gonic/gin"
 	"strconv"
+	"time"
 	"trading-go/model"
 	"trading-go/response"
 	"trading-go/util"
@@ -45,6 +46,7 @@ func CreatGoods(c *gin.Context) {
 	}
 	goods := goodsJson.Change()
 	id, err := goods.Create()
+	go util.NewItem(id, uint(time.Now().Unix()), goodsJson.Title, goodsJson.Desc)
 	go util.NewIndex(id, goodsJson.Desc+goodsJson.Title)
 	err = category.Save(id, goodsJson.Categories)
 	if err != nil {
@@ -66,6 +68,9 @@ func DGoods(c *gin.Context) {
 	var goods model.Goods
 	ids := c.Param("id")
 	id, err := strconv.Atoi(ids)
+
+	go util.DelItem(uint(id))
+
 	if err != nil {
 		response.Fail(c.Writer, err.Error(), 500)
 		return
@@ -160,9 +165,15 @@ func ReviseGoods(c *gin.Context) {
 		response.Fail(c.Writer, msg, 500)
 		return
 	}
-	go util.DelIndex(goods.Id)
 	err = goods.Revise()
-	go util.NewIndex(goods.Id, goods.Desc+goods.Title)
+	go func() {
+		util.DelIndex(goods.Id)
+		util.NewIndex(goods.Id, goods.Desc+goods.Title)
+	}()
+	go func() {
+		util.DelItem(goods.Id)
+		util.NewItem(goods.Id, uint(time.Now().Unix()), goods.Title, goods.Desc)
+	}()
 	if err != nil {
 		msg := err.Error()
 		response.Fail(c.Writer, msg, 500)

+ 3 - 0
trading-go/controller/usercontroller.go

@@ -41,6 +41,9 @@ func Register(c *gin.Context) {
 		Phone:  userJ.Phone,
 	}
 	err = user.Register()
+
+	go util.NewUser(uint(id))
+
 	if err != nil {
 		msg := err.Error()
 		response.Fail(c.Writer, msg, 500)

+ 1 - 1
trading-go/docs/docs.go

@@ -1466,7 +1466,7 @@ const docTemplate = `{
 // SwaggerInfo holds exported Swagger Info so clients can modify it
 var SwaggerInfo = &swag.Spec{
 	Version:          "1.0",
-	Host:             "192.168.31.28:8084",
+	Host:             "124.222.126.172:8084",
 	BasePath:         "/WeChatTrading/trading-go",
 	Schemes:          []string{},
 	Title:            "二手交易",

+ 1 - 1
trading-go/docs/swagger.json

@@ -11,7 +11,7 @@
         },
         "version": "1.0"
     },
-    "host": "192.168.31.28:8084",
+    "host": "124.222.126.172:8084",
     "basePath": "/WeChatTrading/trading-go",
     "paths": {
         "/appraise/create": {

+ 1 - 1
trading-go/docs/swagger.yaml

@@ -135,7 +135,7 @@ definitions:
       message:
         type: string
     type: object
-host: 192.168.31.28:8084
+host: 124.222.126.172:8084
 info:
   contact: {}
   description: 一个基于微信小程序的校园二手交易平台的api文档

+ 1 - 1
trading-go/main.go

@@ -15,7 +15,7 @@ import (
 // @license.name Apache 2.0
 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html
 
-// @host 192.168.31.28:8084
+// @host 124.222.126.172:8084
 // @BasePath /WeChatTrading/trading-go
 func main() {
 	r := routine.GetRoutine()

+ 53 - 5
trading-go/util/recommend.go

@@ -15,20 +15,28 @@ func init() {
 
 }
 
-func Recommend(uid, goodsId, tie uint) {
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
-	defer cancel()
+func GetTime(tie uint) string {
 	t := time.Unix(int64(tie), 0)
 	date := t.Format("2006-01-02")
-	_, err := gorse.InsertFeedback(ctx, []client.Feedback{
+	return date
+}
+
+func Recommend(uid, goodsId, tie uint) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*100)
+	defer cancel()
+	date := GetTime(tie)
+	aff, err := gorse.InsertFeedback(ctx, []client.Feedback{
 		{FeedbackType: "star",
 			UserId:    fmt.Sprintf("%d", uid),
 			ItemId:    fmt.Sprintf("%d", goodsId),
 			Timestamp: date},
 	})
 	if err != nil {
-		fmt.Println(err.Error())
+		fmt.Println("[recommend] ======>>> " + err.Error())
+		return
 	}
+
+	fmt.Printf("[recommend] ======>>> %dfeedback success\n", aff)
 }
 
 func GetRecommend(uid uint, cnt int) (goods []string, err error) {
@@ -37,3 +45,43 @@ func GetRecommend(uid uint, cnt int) (goods []string, err error) {
 	category, err := gorse.GetItemRecommendWithCategory(ctx, fmt.Sprintf("%d", uid), "", "", "", 0, cnt)
 	return category, err
 }
+
+func NewUser(uid uint) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+	defer cancel()
+	_, err := gorse.InsertUser(ctx, client.User{UserId: fmt.Sprintf("%d", uid)})
+	if err != nil {
+		fmt.Println("[recommend] ======>>> " + err.Error())
+		return
+	}
+	fmt.Println("[recommend] ======>>> user added")
+}
+
+func NewItem(id uint, t uint, title string, desc string) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+	defer cancel()
+	_, err := gorse.InsertItem(ctx, client.Item{
+		ItemId:     fmt.Sprintf("%d", id),
+		IsHidden:   false,
+		Labels:     []string{title},
+		Categories: nil,
+		Timestamp:  GetTime(t),
+		Comment:    desc,
+	})
+	if err != nil {
+		fmt.Println("[recommend] ======>>> " + err.Error())
+		return
+	}
+	fmt.Println("[recommend] ======>>> item added")
+}
+
+func DelItem(id uint) {
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
+	defer cancel()
+	_, err := gorse.DeleteItem(ctx, fmt.Sprintf("%d", id))
+	if err != nil {
+		fmt.Println("[recommend] ======>>> " + err.Error())
+		return
+	}
+	fmt.Println("[recommend] ======>>> item deleted")
+}