feat 修改gorm日志级别
All checks were successful
Build image / build (push) Successful in 6m54s

This commit is contained in:
timerzz 2024-05-15 20:41:42 +08:00
parent 3eeed3d11a
commit 3202eb827b
3 changed files with 19 additions and 4 deletions

View File

@ -11,9 +11,12 @@ import (
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/cors"
"github.com/golang/glog"
"gorm.io/gorm/logger"
"log"
"log/slog"
"os"
"os/signal"
"time"
)
func main() {
@ -28,6 +31,15 @@ func main() {
if err != nil {
glog.Fatalf("初始化数据库失败:%v", err)
}
db.Logger = logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{
SlowThreshold: time.Second,
LogLevel: logger.Warn,
IgnoreRecordNotFoundError: false,
Colorful: true,
},
)
// 代理池
pool := proxy.NewProxyPool(cfg.Proxy.Subscribes)

View File

@ -40,8 +40,8 @@ type Variant struct {
}
type Price struct {
Sales Sales `json:"sales"`
MarkdownDiscPercent float32 `json:"markdownDiscPercent"`
Sales Sales `json:"sales"`
MarkdownDiscPercent int `json:"markdownDiscPercent"`
}
type Sales struct {

View File

@ -5,6 +5,7 @@ import (
"fmt"
coach_client "gitea.timerzz.com/kedaya_haitao/coach-spider/pkg/coach-client"
"gitea.timerzz.com/kedaya_haitao/common/model/product"
"github.com/golang/glog"
"github.com/samber/lo"
"gorm.io/gorm"
"gorm.io/gorm/clause"
@ -72,6 +73,7 @@ func (c *Controller) Crawl() error {
if err = c.saveRespData(resp.PageData.Products); err != nil {
return fmt.Errorf("保存第%d页数据失败: %w", page, err)
}
glog.Infof("第%d页数据保存成功", page)
}
return nil
}
@ -90,13 +92,14 @@ func (c *Controller) saveRespData(list []coach_client.Product) error {
c.Freight = saveFreight
}
products = append(products, productv1.Product{
UpdatedAt: time.Now(),
Name: resp.Name,
Pid: color.VgId,
Color: color.Text,
Link: fmt.Sprintf("%s/%s", "https://www.coachoutlet.com", color.Url),
Image: color.Media.Thumbnail.Src,
Orderable: color.Orderable,
DiscPercent: int(price.Price.MarkdownDiscPercent),
DiscPercent: price.Price.MarkdownDiscPercent,
USPrice: price.Price.Sales.Value,
Freight: c.Freight,
ExchangeRate: c.ExchangeRate,
@ -109,6 +112,6 @@ func (c *Controller) saveRespData(list []coach_client.Product) error {
})
return c.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "pid"}},
DoUpdates: clause.AssignmentColumns([]string{"name", "color", "link", "orderable", "us_price", "cny_price", "cal_mark", "rate", "price_status", "disc_percent"}),
DoUpdates: clause.AssignmentColumns([]string{"name", "color", "link", "orderable", "us_price", "cny_price", "cal_mark", "rate", "price_status", "disc_percent", "updated_at"}),
}).Create(products).Error
}