xuzhiheng 2 anni fa
parent
commit
d5aa3cb661
4 ha cambiato i file con 87 aggiunte e 12 eliminazioni
  1. 2 2
      sqlutil/src/sqlmodel/rules_es.go
  2. 2 0
      src/client/customerRule.go
  3. 73 0
      src/util/jylog.go
  4. 10 10
      src/util/utiltag.go

+ 2 - 2
sqlutil/src/sqlmodel/rules_es.go

@@ -110,9 +110,9 @@ type ExistfieldsObjectMust struct {
 // 字段存在 存在放MustNot,字符串为空忽略
 type ExistfieldsObject struct {
 	Filter struct {
-		Missing struct {
+		Exists struct {
 			Field string `json:"field,omitempty"`
-		} `json:"missing,omitempty"`
+		} `json:"exists,omitempty"`
 	} `json:"filter,omitempty"`
 }
 

+ 2 - 0
src/client/customerRule.go

@@ -318,8 +318,10 @@ func (r *CustomerRule) DemoData() {
 		startTime := time.Now().Unix() - 86400*60
 		endTime := time.Now().Unix()
 		esquery, _ = FilterTimeSql(esquery, startTime, endTime)
+
 		count := Es.Count(InterimIndex, Itype, esquery)
 		esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", 100) + `}`
+		log.Println("esquery ", esquery)
 		data := Es.Get(InterimIndex, Itype, esquery)
 		// count := 0
 		if data != nil && len(*data) > 0 {

+ 73 - 0
src/util/jylog.go

@@ -0,0 +1,73 @@
+package util
+
+/**
+日志文件自动切换,默认保留15天内日志
+**/
+
+import (
+	"log"
+	"os"
+	"path/filepath"
+	"regexp"
+	"time"
+
+	"github.com/go-xweb/xweb"
+	"github.com/robfig/cron"
+)
+
+// 日志格式
+var fileReg = regexp.MustCompile("^(\\d{4}_[0-9_]{14})\\.log$")
+
+// 当前日志文件句柄
+var LogFile *os.File
+
+// 时间格式
+var FMT = "2006_01_02_15_04_05"
+
+// 日志目录
+var LogPath = "./jylog"
+
+func init() {
+	os.Mkdir(LogPath, os.ModePerm)
+	//默认保留15天内的日志,-1为永久保留
+	initLog(15)
+}
+
+func initLog(saveDay int) {
+	go logfile()
+	task := cron.New()
+	task.Start()
+	task.AddFunc("0 0 0 * * ?", func() {
+		go logfile()
+		time.Sleep(50 * time.Second)
+		if saveDay > 0 {
+			filepath.Walk(LogPath, func(path string, info os.FileInfo, err error) error {
+				str := fileReg.FindStringSubmatch(info.Name())
+				if len(str) == 2 {
+					t, er := time.ParseInLocation(FMT, str[1], time.Local)
+					if er == nil {
+						if (time.Now().Unix()-t.Unix())/86400 > int64(saveDay) {
+							log.Println("delete log file:", path, os.Remove(path))
+						}
+					}
+				}
+				return nil
+			})
+		}
+	})
+}
+
+// 创建并切换输出文件
+func logfile() {
+	now := time.Now().Format(FMT)
+	file, _ := os.Create(LogPath + "/" + now + ".log")
+	log.SetOutput(file)
+	xweb.RootApp().Logger.SetOutput(file)
+	go func(file *os.File) {
+		time.Sleep(5 * time.Second)
+		if LogFile != nil {
+			LogFile.Close()
+		}
+		LogFile = file
+	}(file)
+}

+ 10 - 10
src/util/utiltag.go

@@ -423,13 +423,13 @@ func Utiltags(tag map[string]interface{}) string {
 	if len(tab.Sexistfields) > 0 {
 		tmpsfields := strings.Split(tab.Sexistfields, ",")
 		for _, v := range tmpsfields {
-			fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{
+			ffBoolObject.Must = append(ffBoolObject.Must, sql.ExistfieldsObjectMust{
 				ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct {
-					Missing struct {
+					Exists struct {
 						Field string `json:"field,omitempty"`
-					} `json:"missing,omitempty"`
+					} `json:"exists,omitempty"`
 				}{
-					Missing: struct {
+					Exists: struct {
 						Field string `json:"field,omitempty"`
 					}{Field: v},
 				},
@@ -529,11 +529,11 @@ func Utiltags(tag map[string]interface{}) string {
 		if tab.SbidamountFieldExist == 1 {
 			fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{
 				ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct {
-					Missing struct {
+					Exists struct {
 						Field string `json:"field,omitempty"`
-					} `json:"missing,omitempty"`
+					} `json:"exists,omitempty"`
 				}{
-					Missing: struct {
+					Exists: struct {
 						Field string `json:"field,omitempty"`
 					}{Field: "bidamount"},
 				},
@@ -565,11 +565,11 @@ func Utiltags(tag map[string]interface{}) string {
 		if tab.SbudgetFieldExist == 1 {
 			fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{
 				ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct {
-					Missing struct {
+					Exists struct {
 						Field string `json:"field,omitempty"`
-					} `json:"missing,omitempty"`
+					} `json:"exists,omitempty"`
 				}{
-					Missing: struct {
+					Exists: struct {
 						Field string `json:"field,omitempty"`
 					}{Field: "budget"},
 				},