| | |
| | | return value[i-1] |
| | | } |
| | | |
| | | func PostAction(sec int, Eurl string, picurl string, ishub string, size int) []byte { |
| | | func PostAction(sec int, Eurl string, picurl string, ishub string, size int, lastT time.Time, curTime time.Time) []byte { |
| | | lastTimeStr := lastT.Format("2006-01-02 15:04:05") |
| | | curTimeStr := curTime.Format("2006-01-02 15:04:05") |
| | | index := "videopersons,personaction" |
| | | url := fmt.Sprintf("%s%s%s", Eurl, index, "/_search") |
| | | startTime := time.Now() |
| | | seccond := strconv.Itoa(sec) |
| | | preSec := "" |
| | | if sec > 60 { |
| | | preSec = "-60s" |
| | | } |
| | | |
| | | sizeStr :="" |
| | | if size <=0 { |
| | | sizeStr = "100" |
| | |
| | | if ishub == "hub" { |
| | | filterArr = append(filterArr,"{\"term\":{\"personIsHub\":\"1\"}}") |
| | | } |
| | | if sec > 60 { |
| | | filterArr = append(filterArr, "{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + seccond + "s\",\"lt\":\"now+8h"+preSec+"\"}}}") |
| | | } |
| | | |
| | | filterArr = append(filterArr, "{\"range\":{\"picDate\":{\"gte\":\""+lastTimeStr+"\",\"lt\":\""+curTimeStr+"\"}}}") |
| | | |
| | | filterStr := "" |
| | | if len(filterArr) >0 { |
| | | filterStr = strings.Join(filterArr, ",") |
| | |
| | | |
| | | }(conn, ech) |
| | | |
| | | tick := time.NewTicker(10 * time.Second) |
| | | |
| | | tick := time.NewTicker(3 * time.Second) |
| | | lastTime := time.Now() |
| | | for { |
| | | select { |
| | | case <-tick.C: |
| | | if !handleMessage(conn, connArr){ |
| | | curTime := time.Now() |
| | | if !handleMessage(conn, connArr, lastTime, curTime){ |
| | | conn.Close() |
| | | return |
| | | } |
| | | lastTime = curTime |
| | | case err := <-ech: |
| | | log.Log.Infoln(err, "remoteAddr ", remoteAddr, " close") |
| | | conn.Close() |
| | |
| | | log.Log.Infoln("Client at " + remoteAddr + " disconnected.") |
| | | } |
| | | |
| | | func handleMessage(conn net.Conn, connArr []net.Conn) bool { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl, *IsHub, *Size) |
| | | func handleMessage(conn net.Conn, connArr []net.Conn,lastT time.Time, curTime time.Time) bool { |
| | | jsonstring := esutil.PostAction(*sec, *Eurl, *Picurl, *IsHub, *Size, lastT, curTime) |
| | | if jsonstring == nil { |
| | | log.Log.Infoln("the data is nil,remoteArr:",conn.RemoteAddr()) |
| | | if _, err := conn.Write([]byte("\000"));err !=nil { |