feat 支持蹲库存和历史库存
All checks were successful
Build image / build (push) Successful in 51s

This commit is contained in:
timerzz 2024-12-02 19:07:39 +08:00
parent 43f69144ac
commit 963d36592f
4 changed files with 48 additions and 6 deletions

View File

@ -37,6 +37,7 @@ func main() {
svc := []web.Register{
web.NewProbe(),
service.NewWatcher(stg),
service.NewTracer(stg),
}
for _, s := range svc {

4
go.mod
View File

@ -3,9 +3,10 @@ module gitea.timerzz.com/kedaya_haitao/watcher
go 1.22.2
require (
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8
github.com/gofiber/fiber/v3 v3.0.0-beta.3
github.com/golang/glog v1.2.1
gorm.io/gorm v1.25.10
)
require (
@ -34,5 +35,4 @@ require (
golang.org/x/text v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
gorm.io/gorm v1.25.10 // indirect
)

6
go.sum
View File

@ -1,7 +1,5 @@
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129125918-50b9ed22adb2 h1:gRKzV+KtHoT126BXcaulTarAqmpNgTX9GS6m34NyrRI=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241129125918-50b9ed22adb2/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1 h1:Z396pRoGvXpVYqD2itlvEOxUt1ZHTyQHLbZzKcVFVGI=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241130064301-cd385c31e7f1/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8 h1:AJo3Y3icJb8wcjeSnx6SjkHFdBKYm5lFscEuo6O4dDM=
gitea.timerzz.com/kedaya_haitao/common v0.0.0-20241202091018-277d73739be8/go.mod h1:BIz+IMGznPiyLnV1+Ntw1zf8rEIcbymmGq+EfvDsSgE=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=

43
service/tracer_svc.go Normal file
View File

@ -0,0 +1,43 @@
package service
import (
"gitea.timerzz.com/kedaya_haitao/common/pkg/web"
"gitea.timerzz.com/kedaya_haitao/common/structs/storage"
"github.com/gofiber/fiber/v3"
"gorm.io/gorm"
)
type Tracer struct {
storage *storage.Storage
}
func NewTracer(storage *storage.Storage) *Tracer {
return &Tracer{
storage: storage,
}
}
func (s *Tracer) Registry(r fiber.Router) {
api := r.Group("/api/v2")
api.Get("tracers", s.List)
}
func (s *Tracer) List(c fiber.Ctx) error {
var q storage.GetProviderArticleQuery
if err := c.Bind().Query(&q); err != nil {
return err
}
q.TraceAtsNotNull = true
var query = storage.NewPageListQuery(&q)
if err := c.Bind().Query(query); err != nil {
return err
}
articles, total, err := s.storage.ProviderArticle().List(*query, func(db *gorm.DB) *gorm.DB {
db = db.Preload("HistoryAts")
return db
})
if err != nil {
return err
}
return c.JSON(web.NewResponse(web.NewListResponse(total, articles)))
}