|
@@ -6,16 +6,23 @@ import (
|
|
"github.com/tangs-drm/go-tool/log"
|
|
"github.com/tangs-drm/go-tool/log"
|
|
"github.com/tangs-drm/go-tool/dbm"
|
|
"github.com/tangs-drm/go-tool/dbm"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func TimeZero() int64 {
|
|
|
|
+ now := time.Now()
|
|
|
|
+ timeZero := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
|
|
+ return timeZero.UnixNano() / 1e6
|
|
|
|
+}
|
|
|
|
+
|
|
func Record_Mongo(article_id int, ip string) error {
|
|
func Record_Mongo(article_id int, ip string) error {
|
|
info, err := C(VIEW_TIMES).Upsert(bson.M{
|
|
info, err := C(VIEW_TIMES).Upsert(bson.M{
|
|
"article": article_id,
|
|
"article": article_id,
|
|
"ip": ip,
|
|
"ip": ip,
|
|
|
|
+ "time": TimeZero(),
|
|
}, bson.M{
|
|
}, bson.M{
|
|
"$setOnInsert": bson.M{
|
|
"$setOnInsert": bson.M{
|
|
"_id": bson.NewObjectId().Hex(),
|
|
"_id": bson.NewObjectId().Hex(),
|
|
- "time": util.Now(),
|
|
|
|
"attrs": util.Map{},
|
|
"attrs": util.Map{},
|
|
},
|
|
},
|
|
"$set": bson.M{
|
|
"$set": bson.M{
|
|
@@ -34,6 +41,31 @@ func Record_Mongo(article_id int, ip string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func Record_Path_Mongo(path string, ip string) error {
|
|
|
|
+ info, err := C(VIEW_TIMES).Upsert(bson.M{
|
|
|
|
+ "path": path,
|
|
|
|
+ "ip": ip,
|
|
|
|
+ "time": TimeZero(),
|
|
|
|
+ }, bson.M{
|
|
|
|
+ "$setOnInsert": bson.M{
|
|
|
|
+ "_id": bson.NewObjectId().Hex(),
|
|
|
|
+ "attrs": util.Map{},
|
|
|
|
+ },
|
|
|
|
+ "$set": bson.M{
|
|
|
|
+ "lastTime": util.Now(),
|
|
|
|
+ },
|
|
|
|
+ "$inc": bson.M{
|
|
|
|
+ "count": 1,
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Error("[Record_Path_Mongo] record with path(%v), ip(%v), time(%v) error ->(%v)", path, ip, util.Now(), err)
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ log.Debug("[Record_Path_Mongo] record by path(%v), ip(%v), time(%v) success with info(%v)", path, ip, util.Now(), util.S2Json(info))
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
// FindArticleId 根据文章名字查出文章的id
|
|
// FindArticleId 根据文章名字查出文章的id
|
|
func FindArticleId(name string) (util.Map, error) {
|
|
func FindArticleId(name string) (util.Map, error) {
|
|
var sqlString = fmt.Sprintf("SELECT ID FROM posts WHERE SLUG = '%v'", name)
|
|
var sqlString = fmt.Sprintf("SELECT ID FROM posts WHERE SLUG = '%v'", name)
|