You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
692 B
Go
31 lines
692 B
Go
package monkey
|
|
|
|
import (
|
|
"autogo/dbsql"
|
|
"autogo/models"
|
|
"fmt"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func countPage(p models.AppPage, db *gorm.DB) error {
|
|
|
|
if db == nil {
|
|
db, err := dbsql.GetConn(dbsql.DSN)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer dbsql.Close(db)
|
|
}
|
|
db.Table(p.TableName()).Model(models.AppPage{}).Where("product = ? AND page_name = ?", p.Product, p.PageName).Last(&p)
|
|
if p.ID == 0 {
|
|
p.Count = 1
|
|
db.Create(&p)
|
|
return nil
|
|
}
|
|
fmt.Println("计算页面覆盖次数", p.PageName, "->", p.Count+1)
|
|
db.Table(p.TableName()).Model(models.AppPage{}).Where("product = ? AND page_name = ?", p.Product, p.PageName).Update("count", p.Count+1)
|
|
|
|
return nil
|
|
}
|