package main

import (
	"log"
	qu "qfw/util"
	"time"
)


func dealWithQYData()map[string]interface{} {


	defer qu.Catch()
	start := int(time.Now().Unix())
	now:=time.Now() //当前天
	lt_time:= time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
	gte_time := lt_time-86400
	q := map[string]interface{}{
		"down_time": map[string]interface{}{
			"$gte":  gte_time,
			"$lt": lt_time,
		},
	}
	sess := qy_mgo.GetMgoConn()
	defer qy_mgo.DestoryMongoConn(sess)

	data := make(map[string]interface{},0)
	//细节才需要遍历
	it := sess.DB(qy_mgo.DbName).C(qy_c_name).Find(&q).Select(map[string]interface{}{
		"site":1,
	}).Iter()
	total:=0
	for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
		tmp = make(map[string]interface{})
	}

	qy_date := qu.FormatDateByInt64(&gte_time, qu.DATEFORMAT)
	data[qy_date] = total
	comeintime :=qu.Int64All(time.Now().Unix())
	save_mgo.Save(save_other_name, map[string]interface{}{
		"name":"企业",
		"num":qu.IntAll(total),
		"comeintime":comeintime,
		"date":qy_date,
	})

	//获取前两天数据
	before_time := lt_time-86400*2
	before_date :=qu.FormatDateByInt64(&before_time, qu.DATEFORMAT)
	//企业数据
	before_qy_data :=save_mgo.FindOne(save_other_name, map[string]interface{}{
		"name":"企业",
		"date":before_date,
	})
	if len(before_qy_data)>1 {
		data[before_date] =qu.IntAll(before_qy_data["num"])
	}
	log.Println("企业变更处理完毕...",int(time.Now().Unix())-start,"秒")

	return data
}




















