|
@@ -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")
|
|
|
+}
|