feat: 植物识别百科ai助手迁移
This commit is contained in:
@@ -3,9 +3,11 @@ package ocr
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
plantPb "sundynix-micro-go/app/plant/rpc/plant"
|
||||
plantModel "sundynix-micro-go/app/plant/model"
|
||||
)
|
||||
|
||||
type GetMyClassifyLogLogic struct {
|
||||
@@ -14,11 +16,53 @@ type GetMyClassifyLogLogic struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
type ClassifyRecordResp struct {
|
||||
List []ClassifyRecordInfo `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
type ClassifyRecordInfo struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"userId"`
|
||||
LogID uint64 `json:"logId"`
|
||||
AllResults plantModel.ResultsArray `json:"allResults"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
CreatedAtStr string `json:"createdAtStr"`
|
||||
}
|
||||
|
||||
func NewGetMyClassifyLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyClassifyLogLogic {
|
||||
return &GetMyClassifyLogLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMyClassifyLogLogic) GetMyClassifyLog() (*plantPb.ClassifyLogListResp, error) {
|
||||
func (l *GetMyClassifyLogLogic) GetMyClassifyLog() (*ClassifyRecordResp, error) {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
return l.svcCtx.PlantRpc.GetMyClassifyLog(l.ctx, &plantPb.GetProfileReq{UserId: userId})
|
||||
|
||||
var records []plantModel.ClassifyRecord
|
||||
var total int64
|
||||
|
||||
db := l.svcCtx.DB.Model(&plantModel.ClassifyRecord{}).Where("user_id = ?", userId)
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := db.Order("created_at desc").Limit(50).Find(&records).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]ClassifyRecordInfo, 0, len(records))
|
||||
for _, og := range records {
|
||||
list = append(list, ClassifyRecordInfo{
|
||||
ID: og.ID,
|
||||
UserID: og.UserID,
|
||||
LogID: og.LogID,
|
||||
AllResults: og.AllResults,
|
||||
CreatedAt: og.CreatedAt.Format(time.RFC3339),
|
||||
CreatedAtStr: og.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
return &ClassifyRecordResp{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user