feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package recomapi
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
FBT_Star string = "star"
|
||||
FBT_Like string = "like"
|
||||
FBT_Read string = "read"
|
||||
)
|
||||
|
||||
type RSItemInfo struct {
|
||||
Comment string `json:"Comment"`
|
||||
ItemId string `json:"ItemId"`
|
||||
Labels []string `json:"Labels"`
|
||||
Timestamp time.Time `json:"Timestamp"`
|
||||
}
|
||||
|
||||
type RSItemInfoList []*RSItemInfo
|
||||
|
||||
type RSUserInfo struct {
|
||||
Comment string `json:"Comment"`
|
||||
UserId string `json:"UserId"`
|
||||
Labels []string `json:"Labels"`
|
||||
Subscribe []string `json:"Subscribe"`
|
||||
Timestamp time.Time `json:"Timestamp"`
|
||||
}
|
||||
|
||||
type RSUserInfoList []*RSUserInfo
|
||||
|
||||
type APIResult struct {
|
||||
RowAffected int64 `json:"RowAffected"`
|
||||
}
|
||||
|
||||
type FeedbackInfo struct {
|
||||
Comment string `json:"Comment"`
|
||||
FeedbackType string `json:"FeedbackType"`
|
||||
ItemId string `json:"ItemId"`
|
||||
Timestamp time.Time `json:"Timestamp"`
|
||||
UserId string `json:"UserId"`
|
||||
}
|
||||
|
||||
type FeedbackInfoList []*FeedbackInfo
|
||||
@@ -0,0 +1,45 @@
|
||||
package recomapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"hkdj-web-server/pub/common/log"
|
||||
"hkdj-web-server/pub/common/srvdef"
|
||||
"hkdj-web-server/pub/common/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AddOneFeedback 添加一个推荐反馈
|
||||
func AddOneFeedback(url string, key string,
|
||||
userId int64, mediaId int64, fbType string, comment string) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
feedBack := &FeedbackInfo{
|
||||
UserId: strconv.FormatInt(userId, 10),
|
||||
ItemId: strconv.FormatInt(mediaId, 10),
|
||||
FeedbackType: fbType,
|
||||
Comment: comment,
|
||||
Timestamp: time.Now(),
|
||||
}
|
||||
return AddManyFeedbacks(url, key, FeedbackInfoList{feedBack})
|
||||
}
|
||||
|
||||
func AddManyFeedbacks(url string, key string, feedbacks FeedbackInfoList) (
|
||||
int64, *srvdef.SrvErr) {
|
||||
reqUrl := url + "/api/feedback"
|
||||
resp := &APIResult{}
|
||||
reqBody, _ := json.Marshal(feedbacks)
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.POSTJsonWithJResp(resp, reqUrl, header, reqBody)
|
||||
if err != nil {
|
||||
log.Error("recomapi:AddManyFeedbacks POSTJsonWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return 0, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:AddManyFeedbacks POSTJsonWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return 0, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
return resp.RowAffected, nil
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package recomapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hkdj-web-server/pub/common/log"
|
||||
"hkdj-web-server/pub/common/srvdef"
|
||||
"hkdj-web-server/pub/common/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InsertOneItem(url string, key string, itemInfo *RSItemInfo) *srvdef.SrvErr {
|
||||
reqUrl := url + "/api/item"
|
||||
resp := &APIResult{}
|
||||
reqBody, _ := json.Marshal(itemInfo)
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.POSTJsonWithJResp(resp, reqUrl, header, reqBody)
|
||||
if err != nil {
|
||||
log.Error("recomapi:InsertOneItem POSTJsonWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:InsertOneItem POSTJsonWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertManyItems(url string, key string, itemInfos RSItemInfoList) *srvdef.SrvErr {
|
||||
reqUrl := url + "/api/items"
|
||||
reqBody, _ := json.Marshal(itemInfos)
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.POSTJsonWithJResp(nil, reqUrl, header, reqBody)
|
||||
if err != nil {
|
||||
log.Error("recomapi:InsertManyItems POSTJsonWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:InsertManyItems POSTJsonWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetOneItem(url string, key string, itemId string) (*RSItemInfo, *srvdef.SrvErr) {
|
||||
reqUrl := fmt.Sprintf("%s/api/item/%s", url, itemId)
|
||||
resp := &RSItemInfo{}
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.GetWithJResp(resp, reqUrl, header, nil)
|
||||
if err != nil {
|
||||
log.Error("recomapi:GetOneItem GetWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return nil, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:GetOneItem GetWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return nil, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
log.Info("Test", log.Any("resp", resp))
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func GetManyItems(url string, key string, cursor string, size int64) (RSItemInfoList, string, *srvdef.SrvErr) {
|
||||
reqUrl := fmt.Sprintf("%s/api/items?n=%d&cursor=%s", url, size, cursor)
|
||||
type Resp struct {
|
||||
Cursor string `json:"Cursor"`
|
||||
Items RSItemInfoList `json:"Items"`
|
||||
}
|
||||
var resp Resp
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.GetWithJResp(&resp, reqUrl, header, nil)
|
||||
if err != nil {
|
||||
log.Error("recomapi:GetOneItem GetWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return nil, "", srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:GetOneItem GetWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return nil, "", srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
return resp.Items, resp.Cursor, nil
|
||||
}
|
||||
|
||||
func DeleteOneItem(url string, key string, itemId string) (int64, *srvdef.SrvErr) {
|
||||
reqUrl := fmt.Sprintf("%s/api/item/%s", url, itemId)
|
||||
resp := &APIResult{}
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.DeleteWithJResp(resp, reqUrl, header, nil)
|
||||
if err != nil {
|
||||
log.Error("recomapi:DeleteOneItem DeleteWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return 0, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:DeleteOneItem DeleteWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return 0, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
return resp.RowAffected, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package recomapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hkdj-web-server/pub/common/log"
|
||||
"hkdj-web-server/pub/common/srvdef"
|
||||
"hkdj-web-server/pub/common/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetRecomItems(url string, key string, userId int64, writeBack string, size int64) (
|
||||
[]int64, *srvdef.SrvErr) {
|
||||
reqUrl := fmt.Sprintf("%s/api/recommend/%d?n=%d&write-back=%s", url, userId, size, writeBack)
|
||||
var resp []string
|
||||
header := map[string]string{"X-API-Key": key}
|
||||
code, err := utils.GetWithJResp(&resp, reqUrl, header, nil)
|
||||
if err != nil {
|
||||
log.Error("recomapi:GetRecomItems GetWithJResp failed",
|
||||
log.Any("reqUrl", reqUrl), log.E(err))
|
||||
return nil, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
if code != http.StatusOK {
|
||||
log.Error("recomapi:GetRecomItems GetWithJResp code error.",
|
||||
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
||||
return nil, srvdef.New(srvdef.Err, "", "")
|
||||
}
|
||||
itemIds := make([]int64, 0)
|
||||
for _, v := range resp {
|
||||
id, err := strconv.ParseInt(v, 10, 64)
|
||||
if err == nil {
|
||||
itemIds = append(itemIds, id)
|
||||
}
|
||||
}
|
||||
return itemIds, nil
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package recomapi
|
||||
Reference in New Issue
Block a user